PHP 日记 - 源码修改
抽空对 Typecho 作出了修改,主要为:优化评论嵌套样式、增加评论关联、增加代码块复制按钮。因涉及源码修改,本文章仅为回顾记录,以便日后定位相同问题。
优化评论嵌套样式
定位:var/Widget/Comments/Archive.php
。
取消子评论倒叙 #264;
if ('DESC' == $this->options->commentsOrder) { $this->stack = array_reverse($this->stack, true); #取消子评论倒叙 $this->_threadedComments = array_map('array_reverse', $this->_threadedComments); }
取消嵌套评论不可回复 #470。
public function reply($word = '') { #取消嵌套评论不可回复 if ($this->options->commentsThreaded && !$this->isTopLevel && $this->parameter->allowComment) { if ($this->options->commentsThreaded && $this->parameter->allowComment) { $word = empty($word) ? _t('回复') : $word; $this->pluginHandle()->trigger($plugged)->reply($word, $this); if (!$plugged) { echo '<a href="' . substr($this->permalink, 0, - strlen($this->theId) - 1) . '?replyTo=' . $this->coid . '#' . $this->parameter->respondId . '" rel="nofollow" onclick="return TypechoComment.reply(\'' . $this->theId . '\', ' . $this->coid . ');">' . $word . '</a>'; } } }
增加评论关联
回复按钮上移 #116、增加@回复 #120、适配评论时间链接 #108。
<div class="comment-meta"> <a href="#<?php $this->theID(); ?>"><time itemprop="commentTime" datetime="<?php $this->date('c'); ?>"><?php $singleCommentOptions->beforeDate(); $this->date($singleCommentOptions->dateFormat); $singleCommentOptions->afterDate(); ?></time></a> <?php if ('waiting' == $this->status) { ?> <em class="comment-awaiting-moderation"><?php $singleCommentOptions->commentStatus(); ?></em> <?php } ?> </div> <div class="comment-reply"> <?php $this->reply($singleCommentOptions->replyWord); ?> </div> <div class="comment-content" itemprop="commentText"> <?php // 增加@回复 if ($this->isTopLevel) { $db = Typecho_Db::get(); $table = $db->getPrefix(); $query = $db->query('SELECT author, coid FROM '.$table.'comments WHERE status=\'approved\' AND coid IN (SELECT parent FROM '.$table.'comments WHERE coid='.$this->coid.' AND status=\'approved\')'); $res = $db->fetchObject($query); echo('<p><a class="comment-author-reply" href="#comment-'.$res->coid.'">@'.$res->author.'</a>'.$this->text); } else { $this->content(); } ?> </div>
增加代码块复制按钮
定位:
var/HyperDown.php
。private function parseCode(array $lines, array $parts) { list ($blank, $lang) = $parts; $lang = trim($lang); $count = strlen($blank); if (! preg_match("/^[_a-z0-9-\+\#\:\.]+$/i", $lang)) { $lang = NULL; } else { $parts = explode(':', $lang); if (count($parts) > 1) { list ($lang, $rel) = $parts; $lang = trim($lang); $rel = trim($rel); } } $lines = array_map(function ($line) use ($count) { return preg_replace("/^[ ]%24count/", '', $line); }, array_slice($lines, 1, -1)); $str = implode("\n", $lines); return preg_match("/^\s*$/", $str) ? '' : '<div class="btn-layer"><div class="icon-btn btn-code" data-clipboard-action="copy"></div><pre><code' . (!empty($lang) ? " class=\"{$lang}\"" : '') . (!empty($rel) ? " rel=\"{$rel}\"" : '') . '>' . htmlspecialchars($str) . '</code></pre></div>'; }
注意:1.1 版本内容有所出入,其实只需找到最下面的
return
加入下面代码即可。<div class="btn-layer"><div class="icon-btn btn-code" data-clipboard-action="copy"></div>
更改注脚返回图标
定位:
var/HyperDown.php
。private function makeFootnotes($html) { if (count($this->_footnotes) > 0) { $html .= '<div class="footnotes"><hr><ol>'; $index = 1; while ($val = array_shift($this->_footnotes)) { if (is_string($val)) { $val .= "<a href=\"#fnref-{$index}\" class=\"footnote-backref\">↵</a>"; # ↩ } else { $val[count($val) - 1] .= "¡<a href=\"#fnref-{$index}\" class=\"footnote-backref\">↵</a>"; # ↩ $val = count($val) > 1 ? $this->parse(implode("\n", $val)) : $this->parseInline($val[0]); } $html .= "<li id=\"fn-{$index}\">{$val}</li>"; $index ++; } $html .= '</ol></div>'; } return $html; }
如有问题,欢迎留言或邮件咨询
修改于 May 27, 2018 02:48:32 (6 年前) - « 上一篇:Pythonista - 体验
- 下一篇:PHP 日记 - pjax »