本文整理匯總了PHP中Typecho_Router::match方法的典型用法代碼示例。如果您正苦於以下問題:PHP Typecho_Router::match方法的具體用法?PHP Typecho_Router::match怎麽用?PHP Typecho_Router::match使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Typecho_Router
的用法示例。
在下文中一共展示了Typecho_Router::match方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: singleHandle
/**
* 獨立頁處理
*
* @access private
* @param Typecho_Db_Query $select 查詢對象
* @param boolean $hasPushed 是否已經壓入隊列
* @return void
* @throws Typecho_Widget_Exception
*/
private function singleHandle(Typecho_Db_Query $select, &$hasPushed)
{
if ('comment_page' == $this->parameter->type) {
$params = array();
$matched = Typecho_Router::match($this->request->permalink);
if ($matched && $matched instanceof Widget_Archive && $matched->is('single')) {
$this->import($matched);
$hasPushed = true;
return;
}
}
/** 將這兩個設置提前是為了保證在調用query的plugin時可以在插件中使用is判斷初步歸檔類型 */
/** 如果需要更細判斷,則可以使用singleHandle來實現 */
$this->_archiveSingle = true;
/** 默認歸檔類型 */
$this->_archiveType = 'single';
/** 匹配類型 */
if ('single' != $this->parameter->type) {
$select->where('table.contents.type = ?', $this->parameter->type);
}
/** 如果是單篇文章或獨立頁麵 */
if (isset($this->request->cid)) {
$select->where('table.contents.cid = ?', $this->request->filter('int')->cid);
}
/** 匹配縮略名 */
if (isset($this->request->slug)) {
$select->where('table.contents.slug = ?', $this->request->slug);
}
/** 匹配時間 */
if (isset($this->request->year)) {
$year = $this->request->filter('int')->year;
$fromMonth = 1;
$toMonth = 12;
$fromDay = 1;
$toDay = 31;
if (isset($this->request->month)) {
$fromMonth = $this->request->filter('int')->month;
$toMonth = $fromMonth;
$fromDay = 1;
$toDay = date('t', mktime(0, 0, 0, $toMonth, 1, $year));
if (isset($this->request->day)) {
$fromDay = $this->request->filter('int')->day;
$toDay = $fromDay;
}
}
/** 獲取起始GMT時間的unix時間戳 */
$from = mktime(0, 0, 0, $fromMonth, $fromDay, $year) - $this->options->timezone + $this->options->serverTimezone;
$to = mktime(23, 59, 59, $toMonth, $toDay, $year) - $this->options->timezone + $this->options->serverTimezone;
$select->where('table.contents.created > ? AND table.contents.created < ?', $from, $to);
}
/** 保存密碼至cookie */
if ($this->request->isPost() && isset($this->request->protectPassword)) {
$this->security->protect();
Typecho_Cookie::set('protectPassword', $this->request->protectPassword, 0);
}
/** 匹配類型 */
$select->limit(1);
$this->query($select);
if (!$this->have() || isset($this->request->category) && $this->category != $this->request->category || isset($this->request->directory) && $this->request->directory != implode('/', $this->directory)) {
if (!$this->_invokeFromOutside) {
/** 對沒有索引情況下的判斷 */
throw new Typecho_Widget_Exception(_t('請求的地址不存在'), 404);
} else {
$hasPushed = true;
return;
}
}
/** 設置模板 */
if ($this->template) {
/** 應用自定義模板 */
$this->_themeFile = $this->template;
}
/** 設置頭部feed */
/** RSS 2.0 */
//對自定義首頁使用全局變量
if (!$this->_makeSinglePageAsFrontPage) {
$this->_feedUrl = $this->feedUrl;
/** RSS 1.0 */
$this->_feedRssUrl = $this->feedRssUrl;
/** ATOM 1.0 */
$this->_feedAtomUrl = $this->feedAtomUrl;
/** 設置標題 */
$this->_archiveTitle = $this->title;
/** 設置關鍵詞 */
$this->_keywords = implode(',', Typecho_Common::arrayFlatten($this->tags, 'name'));
/** 設置描述 */
$this->_description = $this->description;
}
/** 設置歸檔類型 */
$this->_archiveType = $this->type;
/** 設置歸檔縮略名 */
//.........這裏部分代碼省略.........
示例2: pingbackPing
/**
* pingbackPing
*
* @param string $source
* @param string $target
* @access public
* @return void
*/
public function pingbackPing($source, $target)
{
/** 檢查源地址是否存在*/
if (!($http = Typecho_Http_Client::get())) {
return new IXR_Error(16, _t('源地址服務器錯誤'));
}
try {
$http->setTimeout(5)->send($source);
$response = $http->getResponseBody();
if (200 == $http->getResponseStatus()) {
if (!$http->getResponseHeader('x-pingback')) {
preg_match_all("/<link[^>]*rel=[\"']([^\"']*)[\"'][^>]*href=[\"']([^\"']*)[\"'][^>]*>/i", $response, $out);
if (!isset($out[1]['pingback'])) {
return new IXR_Error(50, _t('源地址不支持PingBack'));
}
}
} else {
return new IXR_Error(16, _t('源地址服務器錯誤'));
}
} catch (Exception $e) {
return new IXR_Error(16, _t('源地址服務器錯誤'));
}
/** 檢查目標地址是否正確*/
$pathInfo = Typecho_Common::url(substr($target, strlen($this->options->index)), '/');
$post = Typecho_Router::match($pathInfo);
/** 這樣可以得到cid或者slug*/
if (!$post instanceof Widget_Archive || !$post->have() || !$post->is('single')) {
return new IXR_Error(33, _t('這個目標地址不存在'));
}
if ($post) {
/** 檢查是否可以ping*/
if ($post->allowPing) {
/** 現在可以ping了,但是還得檢查下這個pingback是否已經存在了*/
$pingNum = $this->db->fetchObject($this->db->select(array('COUNT(coid)' => 'num'))->from('table.comments')->where('table.comments.cid = ? AND table.comments.url = ? AND table.comments.type <> ?', $post->cid, $source, 'comment'))->num;
if ($pingNum <= 0) {
/** 現在開始插入以及郵件提示了 $response就是第一行請求時返回的數組*/
preg_match("/\\<title\\>([^<]*?)\\<\\/title\\>/is", $response, $matchTitle);
$finalTitle = Typecho_Common::removeXSS(trim(strip_tags($matchTitle[1])));
/** 幹掉html tag,隻留下<a>*/
$text = Typecho_Common::stripTags($response, '<a href="">');
/** 此處將$target quote,留著後麵用*/
$pregLink = preg_quote($target);
/** 找出含有target鏈接的最長的一行作為$finalText*/
$finalText = '';
$lines = explode("\n", $text);
foreach ($lines as $line) {
$line = trim($line);
if (NULL != $line) {
if (preg_match("|<a[^>]*href=[\"']{$pregLink}[\"'][^>]*>(.*?)</a>|", $line)) {
if (strlen($line) > strlen($finalText)) {
/** <a>也要幹掉,*/
$finalText = Typecho_Common::stripTags($line);
}
}
}
}
/** 截取一段字*/
if (NULL == trim($finalText)) {
return new IXR_Error('17', _t('源地址中不包括目標地址'));
}
$finalText = '[...]' . Typecho_Common::subStr($finalText, 0, 200, '') . '[...]';
$pingback = array('cid' => $post->cid, 'created' => $this->options->gmtTime, 'agent' => $this->request->getAgent(), 'ip' => $this->request->getIp(), 'author' => $finalTitle, 'url' => Typecho_Common::safeUrl($source), 'text' => $finalText, 'ownerId' => $post->author->uid, 'type' => 'pingback', 'status' => $this->options->commentsRequireModeration ? 'waiting' : 'approved');
/** 加入plugin */
$pingback = $this->pluginHandle()->pingback($pingback, $post);
/** 執行插入*/
$insertId = $this->singletonWidget('Widget_Abstract_Comments')->insert($pingback);
/** 評論完成接口 */
$this->pluginHandle()->finishPingback($this);
return $insertId;
/** todo:發送郵件提示*/
} else {
return new IXR_Error(48, _t('PingBack已經存在'));
}
} else {
return IXR_Error(49, _t('目標地址禁止Ping'));
}
} else {
return new IXR_Error(33, _t('這個目標地址不存在'));
}
}
示例3: action
/**
* 初始化函數
*
* @access public
* @return void
* @throws Typecho_Widget_Exception
*/
public function action()
{
/** 回調方法 */
$callback = $this->request->type;
$this->_content = Typecho_Router::match($this->request->permalink);
/** 判斷內容是否存在 */
if (false !== $this->_content && $this->_content instanceof Widget_Archive && $this->_content->have() && $this->_content->is('single') && in_array($callback, array('comment', 'trackback'))) {
/** 如果文章不允許反饋 */
if ('comment' == $callback) {
/** 評論關閉 */
if (!$this->_content->allow('comment')) {
throw new Typecho_Widget_Exception(_t('對不起,此內容的反饋被禁止.'), 403);
}
/** 檢查來源 */
if ($this->options->commentsCheckReferer && 'false' != $this->parameter->checkReferer) {
$referer = $this->request->getReferer();
if (empty($referer)) {
throw new Typecho_Widget_Exception(_t('評論來源頁錯誤.'), 403);
}
$refererPart = parse_url($referer);
$currentPart = parse_url($this->_content->permalink);
if ($refererPart['host'] != $currentPart['host'] || 0 !== strpos($refererPart['path'], $currentPart['path'])) {
//自定義首頁支持
if ('page:' . $this->_content->cid == $this->options->frontPage) {
$currentPart = parse_url(rtrim($this->options->siteUrl, '/') . '/');
if ($refererPart['host'] != $currentPart['host'] || 0 !== strpos($refererPart['path'], $currentPart['path'])) {
throw new Typecho_Widget_Exception(_t('評論來源頁錯誤.'), 403);
}
} else {
throw new Typecho_Widget_Exception(_t('評論來源頁錯誤.'), 403);
}
}
}
/** 檢查ip評論間隔 */
if (!$this->user->pass('editor', true) && $this->_content->authorId != $this->user->uid && $this->options->commentsPostIntervalEnable) {
$latestComment = $this->db->fetchRow($this->db->select('created')->from('table.comments')->where('cid = ?', $this->_content->cid)->order('created', Typecho_Db::SORT_DESC)->limit(1));
if ($latestComment && ($this->options->gmtTime - $latestComment['created'] > 0 && $this->options->gmtTime - $latestComment['created'] < $this->options->commentsPostInterval)) {
throw new Typecho_Widget_Exception(_t('對不起, 您的發言過於頻繁, 請稍侯再次發布.'), 403);
}
}
}
/** 如果文章不允許引用 */
if ('trackback' == $callback && !$this->_content->allow('ping')) {
throw new Typecho_Widget_Exception(_t('對不起,此內容的引用被禁止.'), 403);
}
/** 調用函數 */
$this->{$callback}();
} else {
throw new Typecho_Widget_Exception(_t('找不到內容'), 404);
}
}