fetchAll($db->select('value')->from('table.options')->where('name = %s', "theme:Miracles")->limit(1)); $load_image = explode("\";",explode("\"",explode("\"loading_image\";",$load_image[0]["value"],2)[1],2)[1],2)[0]; $text = empty($last) ? $data : $last; if ($widget instanceof Widget_Archive) { //ParseOther $text = Contents::parsePicShadow(Contents::parseNotice(Contents::parseKbd(Contents::parseCode(Contents::parseImages(Contents::parseHeadings(Contents::parseTextColor(Contents::parseRuby(Contents::parseTip($text))))))))); //LazyLoad $text = preg_replace('//','',$text); //owo $text = Contents::parseEmo($text); //Links $text = Contents::parseLink($text); } return $text; } /** * 解析图片 */ static public function parseImages($text){ //FancyBox & 图题 $text = preg_replace('//s','
${4}
',$text); return $text; } /** * 解析 Text-Color */ static public function parseTextColor($text){ $text = preg_replace('/\&\{(.*?)\|(.*?)\|(.*?)\}/s','${1}',$text); return $text; } /** * 解析 Ruby */ static public function parseRuby($text){ $reg = '/\{\{(.*?):(.*?)\}\}/s'; $rp = '${1}(${2})'; $text = preg_replace($reg,$rp,$text); return $text; } /** * 解析 Tip */ static public function parseTip($text){ //Tip without var $text = preg_replace('/\[tip\](.*?)\[\/tip\]/s','
${1}
',$text); //Tip $text = preg_replace('/\[tip type="(.*?)"\](.*?)\[\/tip\]/s','
${2}
',$text); //Tip Group $text = preg_replace('/\[tip\-group\](.*?)\[\/tip\-group\]/s','
${1}
',$text); return $text; } /** * 解析 Notice */ static public function parseNotice($text){ $text = preg_replace('/\[notice\](.*?)\[\/notice\]/s','
${1}
',$text); return $text; } /** * 图片加阴影 */ static public function parsePicShadow($text){ $text = preg_replace('/\[shadow\](.*?)\[\/shadow\]/s','
${1}
',$text); return $text; } /** * 解析友链 */ static public function parseLink($text) { //解析友链盒子 $reg = '/\[links\](.*?)\[\/links\]/s'; $rp = ''; $text = preg_replace($reg, $rp, $text); //解析友链项目 $reg = '/\[(.*?)\]\{(.*?)\}\((.*?)\)\+\((.*?)\)/s'; $rp = ''; $text = preg_replace($reg, $rp, $text); //解析外部友链 $reg = '/\[links data="(.*?)"\]/'; $dataLink = preg_match_all($reg, $text, $matches); if (!$dataLink) return $text; //普通文章别匹配! $http = Typecho_Http_Client::get(); if (false == $http) { $text = str_replace($matches[0][0], '
对不起, 您的主机不支持 php-curl 扩展而且没有打开 allow_url_fopen 功能, 无法正常使 json 友链功能', $text); return $text; } for ($j = 0; $j <= $dataLink; $j++) { $match = $matches[1][$j]; try { $result = $http->send($match); } catch (Typecho_Http_Client_Exception $ex) { $text = str_replace($matches[0][$j], '对不起,json外链请求失败! 错误信息:' . $ex->getMessage(), $text); continue; } $data = json_decode($result, true); if ($data == false) {//没获取到数据就别走了!赶紧返回免得搞出事情 $text = str_replace($matches[0][$j], '对不起,json外链解析失败!', $text); continue; } $linkItemNum = count($data); $linksList = '';//先Define一下,IDE在报错QAQ for ($i = 0; $i < $linkItemNum; $i++) { $name = $data[$i]['name']; $link = $data[$i]['link']; $avatar = $data[$i]['avatar']; $des = $data[$i]['des']; //嵌入列表 $linksList .= ''; } $text = str_replace($matches[0][$j], '', $text); } return $text; } /** * 解析 owo 表情 */ static public function parseEmo($content) { $content = preg_replace_callback('/\:\:\(\s*(呵呵|哈哈|吐舌|太开心|笑眼|花心|小乖|乖|捂嘴笑|滑稽|你懂的|不高兴|怒|汗|黑线|泪|真棒|喷|惊哭|阴险|鄙视|酷|啊|狂汗|what|疑问|酸爽|呀咩爹|委屈|惊讶|睡觉|笑尿|挖鼻|吐|犀利|小红脸|懒得理|勉强|爱心|心碎|玫瑰|礼物|彩虹|太阳|星星月亮|钱币|茶杯|蛋糕|大拇指|胜利|haha|OK|沙发|手纸|香蕉|便便|药丸|红领巾|蜡烛|音乐|灯泡|开心|钱|咦|呼|冷|生气|弱|吐血)\s*\)/is', array('Contents', 'parsePaopaoBiaoqingCallback'), $content); $content = preg_replace_callback('/\:\@\(\s*(高兴|小怒|脸红|内伤|装大款|赞一个|害羞|汗|吐血倒地|深思|不高兴|无语|亲亲|口水|尴尬|中指|想一想|哭泣|便便|献花|皱眉|傻笑|狂汗|吐|喷水|看不见|鼓掌|阴暗|长草|献黄瓜|邪恶|期待|得意|吐舌|喷血|无所谓|观察|暗地观察|肿包|中枪|大囧|呲牙|抠鼻|不说话|咽气|欢呼|锁眉|蜡烛|坐等|击掌|惊喜|喜极而泣|抽烟|不出所料|愤怒|无奈|黑线|投降|看热闹|扇耳光|小眼睛|中刀)\s*\)/is', array('Contents', 'parseAruBiaoqingCallback'), $content); $content = preg_replace_callback('/\:\&\(\s*(.*?)\s*\)/is', array('Contents', 'parseTweBiaoqingCallback'), $content); return $content; } /** * 泡泡表情回调函数 * * @return string */ private static function parsePaopaoBiaoqingCallback($match) { return ''; } /** * 阿鲁表情回调函数 * * @return string */ private static function parseAruBiaoqingCallback($match) { return ''; } /** * 推特表情回调函数 * * @return string */ private static function parseTweBiaoqingCallback($match) { return ''; } /** * 解析代码块 */ static public function parseCode($text) { $text = preg_replace('/
/s','
',$text);
		return $text;
	}
	
	/**
	 * 解析键盘按键
	 */
    static public function parseKbd($text) {
		$text = preg_replace('/\~(.*?)\~/s','${1}',$text);
		return $text;
	}

	/**
	 *  解析章节链接
	 */ 
	static public function parseHeadings($text){
		$reg='/\(.*?)\<\/h.*?\>/s';
        $text = preg_replace_callback($reg, array('Contents', 'parseHeaderCallback'), $text);
		
		return $text;
	}
	 
	/**
     * 为内容中的标题编号
     */
    static private $CurrentTocID = 0;
    static public function parseHeaderCallback($matchs)
    {
        // 增加单独标记,否则冲突
        $id = $matchs[3];
		$id = str_replace(' ','_',$id);
		$id = str_replace('&','_',$id);
		$id = str_replace('?','_',$id);
		$id = str_replace("'",'_',$id);
		$id = str_replace('"','_',$id);
		$id = str_replace('’','_',$id);
		$id = str_replace('“','_',$id);
		$id = str_replace('?','_',$id);
        return ''.$matchs[3].'';
    }
	

	/**
	 * 解析自定义导航栏
	 */
	static public function paresNav($data, $type) {
		$de_json = json_decode($data, true);
		$count_json = count($de_json);
        for ($i = 0; $i < $count_json; $i++) {
            $title = $de_json[$i]['title'];
            $link = $de_json[$i]['link'];
			//输出导航
			if($type=="top-nav") {
			    echo ''. $title .'';
			}
			elseif($type=="mobile") {
				echo '';
			}
			elseif($type=="drawer") {
				echo ''. $title .'';
			}
        }
	}
	
	/**
     * 根据 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();
    }
}