diff --git a/comments.php b/comments.php index 0315441..5dd868f 100644 --- a/comments.php +++ b/comments.php @@ -37,7 +37,7 @@ function threadedComments($comments, $options) { ?>">
gravatar_mirror == '' ? 'https://secure.gravatar.com' : Helper::options()->gravatar_mirror; $url = '/avatar/'; $size = '80'; $default = 'mm'; diff --git a/footer.php b/footer.php index 00ebfe8..9714918 100644 --- a/footer.php +++ b/footer.php @@ -55,7 +55,7 @@
- + is('single')) && ($this->allow('comment'))): ?> footer(); ?> - + options->useHighline == 'able'): ?> - + options->pjaxSet == 'able'): ?> - + options->fastClickSet == 'able'): ?> - + - + options->GoogleAnalytics): ?> options->GoogleAnalytics(); ?> diff --git a/functions.php b/functions.php index 7ca7dcf..4225daf 100644 --- a/functions.php +++ b/functions.php @@ -1,328 +1,341 @@ -addInput($logoUrl->addRule('xssCheck', _t('请不要在图片链接中使用特殊字符'))); - $footerLogoUrl = new Typecho_Widget_Helper_Form_Element_Text('footerLogoUrl', NULL, NULL, _t('页尾logo地址'), _t('一般为http://www.yourblog.com/image.png,支持 https:// 或 //,留空则使用站点名称')); - $form->addInput($footerLogoUrl->addRule('xssCheck', _t('请不要在图片链接中使用特殊字符'))); - $favicon = new Typecho_Widget_Helper_Form_Element_Text('favicon', NULL, NULL, _t('favicon地址'), _t('一般为http://www.yourblog.com/image.png,支持 https:// 或 //,留空则不设置favicon')); - $form->addInput($favicon->addRule('xssCheck', _t('请不要在图片链接中使用特殊字符'))); - $iosicon = new Typecho_Widget_Helper_Form_Element_Text('iosicon', NULL, NULL, _t('apple touch icon地址'), _t('一般为http://www.yourblog.com/image.png,支持 https:// 或 //,留空则不设置Apple Touch Icon')); - $form->addInput($iosicon->addRule('xssCheck', _t('请不要在图片链接中使用特殊字符'))); - - $searchPage = new Typecho_Widget_Helper_Form_Element_Text('searchPage', NULL, NULL, _t('搜索页地址'), _t('输入你的 Template Page of Search 的页面地址,记得带上 http:// 或 https://')); - $form->addInput($searchPage->addRule('xssCheck', _t('请不要在链接中使用特殊字符'))); - - $pjaxSet = new Typecho_Widget_Helper_Form_Element_Radio('pjaxSet', - array('able' => _t('启用'), - 'disable' => _t('禁止'), - ), - 'disable', _t('PJAX加速设置'), _t('默认禁止,若启用则需提前到关闭‘开启反垃圾保护’,开关在‘设置-评论’')); - $form->addInput($pjaxSet); - - $DnsPrefetch = new Typecho_Widget_Helper_Form_Element_Radio('DnsPrefetch', - array('able' => _t('启用'), - 'disable' => _t('禁止'), - ), - 'disable', _t('DNS预解析加速'), _t('默认禁止,启用则会对CDN资源和Gravatar进行加速')); - $form->addInput($DnsPrefetch); - - $htmlCompress = new Typecho_Widget_Helper_Form_Element_Radio('htmlCompress', - array('able' => _t('启用'), - 'disable' => _t('禁止'), - ), - 'disable', _t('代码压缩设置'), _t('默认禁止,启用则会对HTML代码进行压缩,可能会跟部分插件存在兼容问题,请自行测试')); - $form->addInput($htmlCompress); - - $fastClickSet = new Typecho_Widget_Helper_Form_Element_Radio('fastClickSet', - array('able' => _t('启用'), - 'disable' => _t('禁止'), - ), - 'disable', _t('移动端点击延迟消除设置'), _t('默认禁止,好多安卓原生浏览器有点击延迟,想开启就开启吧')); - $form->addInput($fastClickSet); - - $postListSwitch = new Typecho_Widget_Helper_Form_Element_Radio('postListSwitch', - array('threeList' => _t('三栏'), - 'oneList' => _t('单栏'), - ), - 'oneList', _t('首页文章列表设置'), _t('默认单栏,根据自己的喜好去做切换吧')); - $form->addInput($postListSwitch); - - $categoryNav = new Typecho_Widget_Helper_Form_Element_Radio('categoryNav', - array('able' => _t('启用'), - 'disable' => _t('禁止'), - ), - 'disable', _t('导航菜单是否启动分类'), _t('默认禁止,启用后导航菜单会展示分类')); - $form->addInput($categoryNav); - - $colorBgPosts = new Typecho_Widget_Helper_Form_Element_Radio('colorBgPosts', - array('customColor' => _t('启用'), - 'defaultColor' => _t('禁用'), - ), - 'defaultColor', _t('文章色块设置'), _t('默认禁止,启用则可以通过文章字段控制色块颜色,仅支持blue、purple、green、yellow、red')); - $form->addInput($colorBgPosts); - - $postshowthumb = new Typecho_Widget_Helper_Form_Element_Radio('postshowthumb', - array('able' => _t('启用'), - 'disable' => _t('禁用'), - ), - 'disable', _t('文章题图设置'), _t('默认禁止,启用则在文章页内显示缩略图')); - $form->addInput($postshowthumb); - - $relatedPosts = new Typecho_Widget_Helper_Form_Element_Radio('relatedPosts', - array('able' => _t('启用'), - 'disable' => _t('禁止'), - ), - 'disable', _t('相关文章设置'), _t('默认禁止,仅在文章页中生效,最多显示六条,文章是根据标签进行相关的')); - $form->addInput($relatedPosts); - - $tableOfContents = new Typecho_Widget_Helper_Form_Element_Radio('tableOfContents', - array('able' => _t('启用'), - 'disable' => _t('禁止'), - ), - 'disable', _t('文章目录设置'), _t('默认禁止,文章页右边目录生成,仅在网页宽度大于1000px时显示')); - $form->addInput($tableOfContents); - - $useHighline = new Typecho_Widget_Helper_Form_Element_Radio('useHighline', - array('able' => _t('启用'), - 'disable' => _t('禁止'), - ), - 'disable', _t('代码高亮设置'), _t('默认禁止,启用则会对 ``` 进行代码高亮,支持22种编程语言的高亮')); - $form->addInput($useHighline); - - $useMathjax = new Typecho_Widget_Helper_Form_Element_Radio('useMathjax', - array('able' => _t('启用'), - 'disable' => _t('禁止'), - ), - 'disable', _t('文章Mathjax设置'), _t('默认禁止,启用则会对内容页进行数学公式渲染,仅支持 $公式$ 和 $$公式$$ ')); - $form->addInput($useMathjax); - - $GoogleAnalytics = new Typecho_Widget_Helper_Form_Element_Textarea('GoogleAnalytics', NULL, NULL, _t('Google Analytics代码'), _t('填写你从Google Analytics获取到的Universal Analytics跟踪代码,需要script标签')); - $form->addInput($GoogleAnalytics); - - - $socialweibo = new Typecho_Widget_Helper_Form_Element_Text('socialweibo', NULL, NULL, _t('输入微博链接'), _t('在这里输入微博链接,支持 http:// 或 https:// 或 //')); - $form->addInput($socialweibo->addRule('xssCheck', _t('请不要在链接中使用特殊字符'))); - $socialzhihu = new Typecho_Widget_Helper_Form_Element_Text('socialzhihu', NULL, NULL, _t('输入知乎链接'), _t('在这里输入知乎链接,支持 http:// 或 https:// 或 //')); - $form->addInput($socialzhihu->addRule('xssCheck', _t('请不要在链接中使用特殊字符'))); - $socialgithub = new Typecho_Widget_Helper_Form_Element_Text('socialgithub', NULL, NULL, _t('输入GitHub链接'), _t('在这里输入GitHub链接,支持 http:// 或 https://或 //')); - $form->addInput($socialgithub->addRule('xssCheck', _t('请不要在链接中使用特殊字符'))); - $socialtwitter = new Typecho_Widget_Helper_Form_Element_Text('socialtwitter', NULL, NULL, _t('输入Twitter链接'), _t('在这里输入twitter链接,支持 http:// 或 https:// 或 //')); - $form->addInput($socialtwitter->addRule('xssCheck', _t('请不要在链接中使用特殊字符'))); - - - $srcAddress = new Typecho_Widget_Helper_Form_Element_Text('src_add', NULL, NULL, _t('图片CDN替换前地址'), _t('即你的附件存放链接,一般为http://www.yourblog.com/usr/uploads/')); - $form->addInput($srcAddress->addRule('xssCheck', _t('请不要在链接中使用特殊字符'))); - $cdnAddress = new Typecho_Widget_Helper_Form_Element_Text('cdn_add', NULL, NULL, _t('图片CDN替换后地址'), _t('即你的七牛云存储域名,一般为http://yourblog.qiniudn.com/,可能也支持其他有镜像功能的CDN服务')); - $form->addInput($cdnAddress->addRule('xssCheck', _t('请不要在链接中使用特殊字符'))); - $default_thumb = new Typecho_Widget_Helper_Form_Element_Text('default_thumb', NULL, '', _t('默认缩略图'),_t('文章没有图片时的默认缩略图,留空则无,一般为http://www.yourblog.com/image.png')); - $form->addInput($default_thumb->addRule('xssCheck', _t('请不要在链接中使用特殊字符'))); - - $ICPRecordNumber = new Typecho_Widget_Helper_Form_Element_Text('ICPRecordNumber', NULL, '', _t('ICP备案号'),_t('ICP备案号,一般为你备案申请审批通过后返回的认证序列号,也就是ICP备案号,一般为粤XXXXXXX')); - $form->addInput($ICPRecordNumber->addRule('xssCheck', _t('请不要在链接中使用特殊字符'))); -} - -function themeInit($archive){ - Helper::options()->commentsMaxNestingLevels = 999; - if ($archive->is('archive')) { - $archive->parameter->pageSize = 12; - } -} - -function showThumb($obj,$size=null,$link=false){ - preg_match_all( "/<[img|IMG].*?src=[\'|\"](.*?)[\'|\"].*?[\/]?>/", $obj->content, $matches ); - $thumb = ''; - $options = Typecho_Widget::widget('Widget_Options'); - $attach = $obj->attachments(1)->attachment; - if (isset($attach->isImage) && $attach->isImage == 1){ - $thumb = $attach->url; - if(!empty($options->src_add) && !empty($options->cdn_add)){ - $thumb = str_ireplace($options->src_add,$options->cdn_add,$thumb); - } - }elseif(isset($matches[1][0])){ - $thumb = $matches[1][0]; - if(!empty($options->src_add) && !empty($options->cdn_add)){ - $thumb = str_ireplace($options->src_add,$options->cdn_add,$thumb); - } - } - if(empty($thumb) && empty($options->default_thumb)){ - return ''; - }else{ - $thumb = empty($thumb) ? $options->default_thumb : $thumb; - } - if($link){ - return $thumb; - } -} - -function parseFieldsThumb($obj){ - $options = Typecho_Widget::widget('Widget_Options'); - if(!empty($options->src_add) && !empty($options->cdn_add)){ - $fieldsThumb = str_ireplace($options->src_add,$options->cdn_add,$obj->fields->thumb); - echo trim($fieldsThumb); - }else{ - return $obj->fields->thumb(); - } -} - -function parseContent($obj){ - $options = Typecho_Widget::widget('Widget_Options'); - if(!empty($options->src_add) && !empty($options->cdn_add)){ - $obj->content = str_ireplace($options->src_add,$options->cdn_add,$obj->content); - } - $obj->content = preg_replace("//i", "", $obj->content); - $obj->content = preg_replace('//i', '', $obj->content); - $obj->content = preg_replace_callback('/(.*?)<\/h\1>/i', function($matches) { - static $id = 1; - $hyphenated = 'anchor-' . $id; - $id++; - return '' . $matches[2] . ''; - }, $obj->content); - - echo trim($obj->content); -} - -function getCommentAt($coid){ - $db = Typecho_Db::get(); - $prow = $db->fetchRow($db->select('parent') - ->from('table.comments') - ->where('coid = ? AND status = ?', $coid, 'approved')); - $parent = $prow['parent']; - if ($parent != "0") { - $arow = $db->fetchRow($db->select('author') - ->from('table.comments') - ->where('coid = ? AND status = ?', $parent, 'approved')); - $author = $arow['author']; - $href = '@'.$author.''; - echo $href; - } else { - echo ''; - } -} - -function getRecentPosts($obj,$pageSize){ - $db = Typecho_Db::get(); - $rows = $db->fetchAll($db->select('cid') - ->from('table.contents') - ->where('type = ? AND status = ?', 'post', 'publish') - ->order('created', Typecho_Db::SORT_DESC) - ->limit($pageSize)); - foreach($rows as $row){ - $cid = $row['cid']; - $apost = $obj->widget('Widget_Archive@post_'.$cid, 'type=post', 'cid='.$cid); - $output = '
  • '.$apost->title.'
  • '; - echo $output; - } -} - -function getHotTags($obj, $limit){ - $db = Typecho_Db::get(); - $tags = $db->fetchAll($db->select() - ->from('table.metas') - ->where('type = ?', 'tag') - ->order('count', Typecho_Db::SORT_DESC) - ->limit($limit)); - foreach($tags as $tag){ - $tag = $obj->filter($tag); - $output = '
  • # '.$tag['name'].'
  • '; - echo $output; - } -} - -function randBgIco(){ - $bgIco=array('book','game','note','chat','code','image','web','link','design','lock'); - return $bgIco[mt_rand(0,9)]; -} - -function randBgColor(){ - $bgColor=array('blue','purple','green','yellow','red','orange'); - return $bgColor[mt_rand(0,5)]; -} - -function theNext($widget, $default = NULL){ - $db = Typecho_Db::get(); - $sql = $db->select()->from('table.contents') - ->where('table.contents.created > ?', $widget->created) - ->where('table.contents.status = ?', 'publish') - ->where('table.contents.type = ?', $widget->type) - ->where('table.contents.password IS NULL') - ->order('table.contents.created', Typecho_Db::SORT_ASC) - ->limit(1); - $content = $db->fetchRow($sql); - if ($content) { - $content = $widget->filter($content); - $link = ''; - echo $link; - } else { - echo $default; - } -} - -function thePrev($widget, $default = NULL){ - $db = Typecho_Db::get(); - $sql = $db->select()->from('table.contents') - ->where('table.contents.created < ?', $widget->created) - ->where('table.contents.status = ?', 'publish') - ->where('table.contents.type = ?', $widget->type) - ->where('table.contents.password IS NULL') - ->order('table.contents.created', Typecho_Db::SORT_DESC) - ->limit(1); - $content = $db->fetchRow($sql); - if ($content) { - $content = $widget->filter($content); - $link = ''; - echo $link; - } else { - echo $default; - } -} - -function compressHtml($html_source) { - $chunks = preg_split('/(.*?|.*?<\/nocompress>|||)/msi', $html_source, -1, PREG_SPLIT_DELIM_CAPTURE); - $compress = ''; - foreach ($chunks as $c) { - if (strtolower(substr($c, 0, 19)) == '') { - $c = substr($c, 19, strlen($c) - 19 - 20); - $compress .= $c; - continue; - } else if (strtolower(substr($c, 0, 12)) == '') { - $c = substr($c, 12, strlen($c) - 12 - 13); - $compress .= $c; - continue; - } else if (strtolower(substr($c, 0, 4)) == ' $char) { - if ($char == '"' && $chars[$key - 1] != '\\' && !$is_apos) { - $is_quot = !$is_quot; - } else if ($char == '\'' && $chars[$key - 1] != '\\' && !$is_quot) { - $is_apos = !$is_apos; - } else if ($char == '/' && $chars[$key + 1] == '/' && !$is_quot && !$is_apos) { - $tmp = substr($tmp, 0, $key); - break; - } - } - } - $c .= $tmp; - } - } - $c = preg_replace('/[\\n\\r\\t]+/', ' ', $c); - $c = preg_replace('/\\s{2,}/', ' ', $c); - $c = preg_replace('/>\\s <', $c); - $c = preg_replace('/\\/\\*.*?\\*\\//i', '', $c); - $c = preg_replace('//', '', $c); - $compress .= $c; - } - return $compress; +addInput($logoUrl->addRule('xssCheck', _t('请不要在图片链接中使用特殊字符'))); + $footerLogoUrl = new Typecho_Widget_Helper_Form_Element_Text('footerLogoUrl', NULL, NULL, _t('页尾logo地址'), _t('一般为http://www.yourblog.com/image.png,支持 https:// 或 //,留空则使用站点名称')); + $form->addInput($footerLogoUrl->addRule('xssCheck', _t('请不要在图片链接中使用特殊字符'))); + $favicon = new Typecho_Widget_Helper_Form_Element_Text('favicon', NULL, NULL, _t('favicon地址'), _t('一般为http://www.yourblog.com/image.png,支持 https:// 或 //,留空则不设置favicon')); + $form->addInput($favicon->addRule('xssCheck', _t('请不要在图片链接中使用特殊字符'))); + $iosicon = new Typecho_Widget_Helper_Form_Element_Text('iosicon', NULL, NULL, _t('apple touch icon地址'), _t('一般为http://www.yourblog.com/image.png,支持 https:// 或 //,留空则不设置Apple Touch Icon')); + $form->addInput($iosicon->addRule('xssCheck', _t('请不要在图片链接中使用特殊字符'))); + + $searchPage = new Typecho_Widget_Helper_Form_Element_Text('searchPage', NULL, NULL, _t('搜索页地址'), _t('输入你的 Template Page of Search 的页面地址,记得带上 http:// 或 https://')); + $form->addInput($searchPage->addRule('xssCheck', _t('请不要在链接中使用特殊字符'))); + + $libCDN = new Typecho_Widget_Helper_Form_Element_Radio('libCDN', + array('able' => _t('启用'), + 'disable' => _t('禁止'), + ), + 'disable', _t('静态资源CDN'), _t('默认禁止,静态公共JS及CSS的CDN开关,关闭时使用主题themes\pinghsu\libs文件夹内的资源,开启时请设置后面的‘静态资源CDN URL前缀’')); + $form->addInput($libCDN); + + $pjaxSet = new Typecho_Widget_Helper_Form_Element_Radio('pjaxSet', + array('able' => _t('启用'), + 'disable' => _t('禁止'), + ), + 'disable', _t('PJAX加速设置'), _t('默认禁止,若启用则需提前到关闭‘开启反垃圾保护’,开关在‘设置-评论’')); + $form->addInput($pjaxSet); + + $DnsPrefetch = new Typecho_Widget_Helper_Form_Element_Radio('DnsPrefetch', + array('able' => _t('启用'), + 'disable' => _t('禁止'), + ), + 'disable', _t('DNS预解析加速'), _t('默认禁止,启用则会对CDN资源和Gravatar进行加速,静态资源CDN及设置的镜像也会被预解析')); + $form->addInput($DnsPrefetch); + + $htmlCompress = new Typecho_Widget_Helper_Form_Element_Radio('htmlCompress', + array('able' => _t('启用'), + 'disable' => _t('禁止'), + ), + 'disable', _t('代码压缩设置'), _t('默认禁止,启用则会对HTML代码进行压缩,可能会跟部分插件存在兼容问题,请自行测试')); + $form->addInput($htmlCompress); + + $fastClickSet = new Typecho_Widget_Helper_Form_Element_Radio('fastClickSet', + array('able' => _t('启用'), + 'disable' => _t('禁止'), + ), + 'disable', _t('移动端点击延迟消除设置'), _t('默认禁止,好多安卓原生浏览器有点击延迟,想开启就开启吧')); + $form->addInput($fastClickSet); + + $postListSwitch = new Typecho_Widget_Helper_Form_Element_Radio('postListSwitch', + array('threeList' => _t('三栏'), + 'oneList' => _t('单栏'), + ), + 'oneList', _t('首页文章列表设置'), _t('默认单栏,根据自己的喜好去做切换吧')); + $form->addInput($postListSwitch); + + $categoryNav = new Typecho_Widget_Helper_Form_Element_Radio('categoryNav', + array('able' => _t('启用'), + 'disable' => _t('禁止'), + ), + 'disable', _t('导航菜单是否启动分类'), _t('默认禁止,启用后导航菜单会展示分类')); + $form->addInput($categoryNav); + + $colorBgPosts = new Typecho_Widget_Helper_Form_Element_Radio('colorBgPosts', + array('customColor' => _t('启用'), + 'defaultColor' => _t('禁用'), + ), + 'defaultColor', _t('文章色块设置'), _t('默认禁止,启用则可以通过文章字段控制色块颜色,仅支持blue、purple、green、yellow、red')); + $form->addInput($colorBgPosts); + + $postshowthumb = new Typecho_Widget_Helper_Form_Element_Radio('postshowthumb', + array('able' => _t('启用'), + 'disable' => _t('禁用'), + ), + 'disable', _t('文章题图设置'), _t('默认禁止,启用则在文章页内显示缩略图')); + $form->addInput($postshowthumb); + + $relatedPosts = new Typecho_Widget_Helper_Form_Element_Radio('relatedPosts', + array('able' => _t('启用'), + 'disable' => _t('禁止'), + ), + 'disable', _t('相关文章设置'), _t('默认禁止,仅在文章页中生效,最多显示六条,文章是根据标签进行相关的')); + $form->addInput($relatedPosts); + + $tableOfContents = new Typecho_Widget_Helper_Form_Element_Radio('tableOfContents', + array('able' => _t('启用'), + 'disable' => _t('禁止'), + ), + 'disable', _t('文章目录设置'), _t('默认禁止,文章页右边目录生成,仅在网页宽度大于1000px时显示')); + $form->addInput($tableOfContents); + + $useHighline = new Typecho_Widget_Helper_Form_Element_Radio('useHighline', + array('able' => _t('启用'), + 'disable' => _t('禁止'), + ), + 'disable', _t('代码高亮设置'), _t('默认禁止,启用则会对 ``` 进行代码高亮,支持22种编程语言的高亮')); + $form->addInput($useHighline); + + $useMathjax = new Typecho_Widget_Helper_Form_Element_Radio('useMathjax', + array('able' => _t('启用'), + 'disable' => _t('禁止'), + ), + 'disable', _t('文章Mathjax设置'), _t('默认禁止,启用则会对内容页进行数学公式渲染,仅支持 $公式$ 和 $$公式$$ ')); + $form->addInput($useMathjax); + + $GoogleAnalytics = new Typecho_Widget_Helper_Form_Element_Textarea('GoogleAnalytics', NULL, NULL, _t('Google Analytics代码'), _t('填写你从Google Analytics获取到的Universal Analytics跟踪代码,需要script标签')); + $form->addInput($GoogleAnalytics); + + + $socialweibo = new Typecho_Widget_Helper_Form_Element_Text('socialweibo', NULL, NULL, _t('输入微博链接'), _t('在这里输入微博链接,支持 http:// 或 https:// 或 //')); + $form->addInput($socialweibo->addRule('xssCheck', _t('请不要在链接中使用特殊字符'))); + $socialzhihu = new Typecho_Widget_Helper_Form_Element_Text('socialzhihu', NULL, NULL, _t('输入知乎链接'), _t('在这里输入知乎链接,支持 http:// 或 https:// 或 //')); + $form->addInput($socialzhihu->addRule('xssCheck', _t('请不要在链接中使用特殊字符'))); + $socialgithub = new Typecho_Widget_Helper_Form_Element_Text('socialgithub', NULL, NULL, _t('输入GitHub链接'), _t('在这里输入GitHub链接,支持 http:// 或 https://或 //')); + $form->addInput($socialgithub->addRule('xssCheck', _t('请不要在链接中使用特殊字符'))); + $socialtwitter = new Typecho_Widget_Helper_Form_Element_Text('socialtwitter', NULL, NULL, _t('输入Twitter链接'), _t('在这里输入twitter链接,支持 http:// 或 https:// 或 //')); + $form->addInput($socialtwitter->addRule('xssCheck', _t('请不要在链接中使用特殊字符'))); + + + $srcAddress = new Typecho_Widget_Helper_Form_Element_Text('src_add', NULL, NULL, _t('图片CDN替换前地址'), _t('即你的附件存放链接,一般为http://www.yourblog.com/usr/uploads/')); + $form->addInput($srcAddress->addRule('xssCheck', _t('请不要在链接中使用特殊字符'))); + $cdnAddress = new Typecho_Widget_Helper_Form_Element_Text('cdn_add', NULL, NULL, _t('图片CDN替换后地址'), _t('即你的七牛云存储域名,一般为http://yourblog.qiniudn.com/,可能也支持其他有镜像功能的CDN服务')); + $form->addInput($cdnAddress->addRule('xssCheck', _t('请不要在链接中使用特殊字符'))); + $default_thumb = new Typecho_Widget_Helper_Form_Element_Text('default_thumb', NULL, '', _t('默认缩略图'),_t('文章没有图片时的默认缩略图,留空则无,一般为http://www.yourblog.com/image.png')); + $form->addInput($default_thumb->addRule('xssCheck', _t('请不要在链接中使用特殊字符'))); + + $ICPRecordNumber = new Typecho_Widget_Helper_Form_Element_Text('ICPRecordNumber', NULL, '', _t('ICP备案号'),_t('ICP备案号,一般为你备案申请审批通过后返回的认证序列号,也就是ICP备案号,一般为粤XXXXXXX')); + $form->addInput($ICPRecordNumber->addRule('xssCheck', _t('请不要在链接中使用特殊字符'))); + + $cdn_prefix = new Typecho_Widget_Helper_Form_Element_Text('cdn_prefix', NULL, '', _t('静态资源CDN URL前缀'), _t('只填括号内的 (https://CDN域名/ajax/libs/)这里开始是库名,如:https://cdn.bootcdn.net/ajax/libs/,设置错误并开启 静态资源CDN 会无法加载相关资源')); + $form->addInput($cdn_prefix); + + $gravatar_mirror = new Typecho_Widget_Helper_Form_Element_Text('gravatar_mirror', NULL, '', _t('更换 Gravatar 头像源'), _t('默认源:https://secure.gravatar.com,注意最后是没有斜杠/的,大陆可选:https://cravatar.cn')); + $form->addInput($gravatar_mirror); +} + +function themeInit($archive){ + Helper::options()->commentsMaxNestingLevels = 999; + if ($archive->is('archive')) { + $archive->parameter->pageSize = 12; + } +} + +function showThumb($obj,$size=null,$link=false){ + preg_match_all( "/<[img|IMG].*?src=[\'|\"](.*?)[\'|\"].*?[\/]?>/", $obj->content, $matches ); + $thumb = ''; + $options = Typecho_Widget::widget('Widget_Options'); + $attach = $obj->attachments(1)->attachment; + if (isset($attach->isImage) && $attach->isImage == 1){ + $thumb = $attach->url; + if(!empty($options->src_add) && !empty($options->cdn_add)){ + $thumb = str_ireplace($options->src_add,$options->cdn_add,$thumb); + } + }elseif(isset($matches[1][0])){ + $thumb = $matches[1][0]; + if(!empty($options->src_add) && !empty($options->cdn_add)){ + $thumb = str_ireplace($options->src_add,$options->cdn_add,$thumb); + } + } + if(empty($thumb) && empty($options->default_thumb)){ + return ''; + }else{ + $thumb = empty($thumb) ? $options->default_thumb : $thumb; + } + if($link){ + return $thumb; + } +} + +function parseFieldsThumb($obj){ + $options = Typecho_Widget::widget('Widget_Options'); + if(!empty($options->src_add) && !empty($options->cdn_add)){ + $fieldsThumb = str_ireplace($options->src_add,$options->cdn_add,$obj->fields->thumb); + echo trim($fieldsThumb); + }else{ + return $obj->fields->thumb(); + } +} + +function parseContent($obj){ + $options = Typecho_Widget::widget('Widget_Options'); + if(!empty($options->src_add) && !empty($options->cdn_add)){ + $obj->content = str_ireplace($options->src_add,$options->cdn_add,$obj->content); + } + $obj->content = preg_replace("//i", "", $obj->content); + $obj->content = preg_replace('//i', '', $obj->content); + $obj->content = preg_replace_callback('/(.*?)<\/h\1>/i', function($matches) { + static $id = 1; + $hyphenated = 'anchor-' . $id; + $id++; + return '' . $matches[2] . ''; + }, $obj->content); + + echo trim($obj->content); +} + +function getCommentAt($coid){ + $db = Typecho_Db::get(); + $prow = $db->fetchRow($db->select('parent') + ->from('table.comments') + ->where('coid = ? AND status = ?', $coid, 'approved')); + $parent = $prow['parent']; + if ($parent != "0") { + $arow = $db->fetchRow($db->select('author') + ->from('table.comments') + ->where('coid = ? AND status = ?', $parent, 'approved')); + $author = $arow['author']; + $href = '@'.$author.''; + echo $href; + } else { + echo ''; + } +} + +function getRecentPosts($obj,$pageSize){ + $db = Typecho_Db::get(); + $rows = $db->fetchAll($db->select('cid') + ->from('table.contents') + ->where('type = ? AND status = ?', 'post', 'publish') + ->order('created', Typecho_Db::SORT_DESC) + ->limit($pageSize)); + foreach($rows as $row){ + $cid = $row['cid']; + $apost = $obj->widget('Widget_Archive@post_'.$cid, 'type=post', 'cid='.$cid); + $output = '
  • '.$apost->title.'
  • '; + echo $output; + } +} + +function getHotTags($obj, $limit){ + $db = Typecho_Db::get(); + $tags = $db->fetchAll($db->select() + ->from('table.metas') + ->where('type = ?', 'tag') + ->order('count', Typecho_Db::SORT_DESC) + ->limit($limit)); + foreach($tags as $tag){ + $tag = $obj->filter($tag); + $output = '
  • # '.$tag['name'].'
  • '; + echo $output; + } +} + +function randBgIco(){ + $bgIco=array('book','game','note','chat','code','image','web','link','design','lock'); + return $bgIco[mt_rand(0,9)]; +} + +function randBgColor(){ + $bgColor=array('blue','purple','green','yellow','red','orange'); + return $bgColor[mt_rand(0,5)]; +} + +function theNext($widget, $default = NULL){ + $db = Typecho_Db::get(); + $sql = $db->select()->from('table.contents') + ->where('table.contents.created > ?', $widget->created) + ->where('table.contents.status = ?', 'publish') + ->where('table.contents.type = ?', $widget->type) + ->where('table.contents.password IS NULL') + ->order('table.contents.created', Typecho_Db::SORT_ASC) + ->limit(1); + $content = $db->fetchRow($sql); + if ($content) { + $content = $widget->filter($content); + $link = ''; + echo $link; + } else { + echo $default; + } +} + +function thePrev($widget, $default = NULL){ + $db = Typecho_Db::get(); + $sql = $db->select()->from('table.contents') + ->where('table.contents.created < ?', $widget->created) + ->where('table.contents.status = ?', 'publish') + ->where('table.contents.type = ?', $widget->type) + ->where('table.contents.password IS NULL') + ->order('table.contents.created', Typecho_Db::SORT_DESC) + ->limit(1); + $content = $db->fetchRow($sql); + if ($content) { + $content = $widget->filter($content); + $link = ''; + echo $link; + } else { + echo $default; + } +} + +function compressHtml($html_source) { + $chunks = preg_split('/(.*?|.*?<\/nocompress>|||)/msi', $html_source, -1, PREG_SPLIT_DELIM_CAPTURE); + $compress = ''; + foreach ($chunks as $c) { + if (strtolower(substr($c, 0, 19)) == '') { + $c = substr($c, 19, strlen($c) - 19 - 20); + $compress .= $c; + continue; + } else if (strtolower(substr($c, 0, 12)) == '') { + $c = substr($c, 12, strlen($c) - 12 - 13); + $compress .= $c; + continue; + } else if (strtolower(substr($c, 0, 4)) == ' $char) { + if ($char == '"' && $chars[$key - 1] != '\\' && !$is_apos) { + $is_quot = !$is_quot; + } else if ($char == '\'' && $chars[$key - 1] != '\\' && !$is_quot) { + $is_apos = !$is_apos; + } else if ($char == '/' && $chars[$key + 1] == '/' && !$is_quot && !$is_apos) { + $tmp = substr($tmp, 0, $key); + break; + } + } + } + $c .= $tmp; + } + } + $c = preg_replace('/[\\n\\r\\t]+/', ' ', $c); + $c = preg_replace('/\\s{2,}/', ' ', $c); + $c = preg_replace('/>\\s <', $c); + $c = preg_replace('/\\/\\*.*?\\*\\//i', '', $c); + $c = preg_replace('//', '', $c); + $compress .= $c; + } + return $compress; } \ No newline at end of file diff --git a/header.php b/header.php index 8be1322..2b715d4 100644 --- a/header.php +++ b/header.php @@ -2,11 +2,14 @@ - options->DnsPrefetch): ?> - options->cdn_add): ?> - - - + + + options->DnsPrefetch): ?> + options->cdn_add != '' && filter_var($this->options->cdn_add, FILTER_VALIDATE_URL) !== false): ?> + options->libCDN == 'able' && $this->options->cdn_prefix != '' && filter_var($this->options->cdn_prefix, FILTER_VALIDATE_URL) !== false): ?> + options->gravatar_mirror != '' && filter_var($this->options->gravatar_mirror, FILTER_VALIDATE_URL) !== false): ?> + + @@ -23,17 +26,17 @@ ), '', ' - '); ?>options->title(); ?> header('keywords=&generator=&template=&pingback=&xmlrpc=&wlw=&commentReply=&rss1=&rss2=&atom='); ?> - +