/s','
',$text);
		    //FancyBox
	        $text = preg_replace('//s','
',$text); //LazyLoad $text = preg_replace('//','',$text); //气泡 $text = preg_replace('/\[bubble\](.*?)\[\/bubble\]/s','

${1}

',$text); //Tip without var $text = preg_replace('/\[tip\](.*?)\[\/tip\]/s','
${1}
',$text); //Tip $text = preg_replace('/\[tip type="(.*?)"\](.*?)\[\/tip\]/s','
${2}
',$text); //解析友链盒子 $reg = '/\[links\](.*?)\[\/links\]/s'; $rp = ''; $text = preg_replace($reg,$rp,$text); //解析友链项目 $reg = '/\[(.*?)\]\{(.*?)\}\((.*?)\)/s'; $rp = ''; $text = preg_replace($reg,$rp,$text); } return $text; } /** * 根据 id 返回对应的对象 * 此方法在 Typecho 1.2 以上可以直接调用 Helper::widgetById(); * 但是 1.1 版本尚有 bug,因此单独提出放在这里 * * @param string $table 表名, 支持 contents, comments, metas, users * @return Widget_Abstract */ public static function widgetById($table, $pkId) { $table = ucfirst($table); if (!in_array($table, array('Contents', 'Comments', 'Metas', 'Users'))) { return NULL; } $keys = array( 'Contents' => 'cid', 'Comments' => 'coid', 'Metas' => 'mid', 'Users' => 'uid' ); $className = "Widget_Abstract_{$table}"; $key = $keys[$table]; $db = Typecho_Db::get(); $widget = new $className(Typecho_Request::getInstance(), Typecho_Widget_Helper_Empty::getInstance()); $db->fetchRow( $widget->select()->where("{$key} = ?", $pkId)->limit(1), array($widget, 'push')); return $widget; } /** * 输出完备的标题 */ public static function title(Widget_Archive $archive) { $archive->archiveTitle(array( 'category' => '分类 %s 下的文章', 'search' => '包含关键字 %s 的文章', 'tag' => '标签 %s 下的文章', 'author' => '%s 发布的文章' ), '', ' - '); Helper::options()->title(); } /** * 返回上一篇文章 */ public static function getPrev($archive) { $db = Typecho_Db::get(); $content = $db->fetchRow($db->select()->from('table.contents')->where('table.contents.created < ?', $archive->created) ->where('table.contents.status = ?', 'publish') ->where('table.contents.type = ?', $archive->type) ->where('table.contents.password IS NULL') ->order('table.contents.created', Typecho_Db::SORT_DESC) ->limit(1)); if($content) { return self::widgetById('Contents', $content['cid']); }else{ return NULL; } } /** * 返回下一篇文章 */ public static function getNext($archive) { $db = Typecho_Db::get(); $content = $db->fetchRow($db->select()->from('table.contents')->where('table.contents.created > ? AND table.contents.created < ?', $archive->created, Helper::options()->gmtTime) ->where('table.contents.status = ?', 'publish') ->where('table.contents.type = ?', $archive->type) ->where('table.contents.password IS NULL') ->order('table.contents.created', Typecho_Db::SORT_ASC) ->limit(1)); if($content) { return self::widgetById('Contents', $content['cid']); }else{ return NULL; } } /** * 最近评论,过滤引用通告,过滤博主评论 */ public static function getRecentComments($num = 10) { $comments = array(); $db = Typecho_Db::get(); $rows = $db->fetchAll($db->select()->from('table.comments')->where('table.comments.status = ?', 'approved') ->where('type = ?', 'comment') ->where('ownerId <> authorId') ->order('table.comments.created', Typecho_Db::SORT_DESC) ->limit($num)); foreach ($rows as $row) { $comment = self::widgetById('Comments', $row['coid']); $comments[] = $comment; } return $comments; } }