Exemple #1
0
 /**
  * 获取当前评论内容
  *
  * @access protected
  * @return string
  */
 protected function ___content()
 {
     $text = $this->parentContent['hidden'] ? _t('内容被隐藏') : $this->text;
     $text = $this->pluginHandle(__CLASS__)->trigger($plugged)->content($text, $this);
     if (!$plugged) {
         $text = $this->options->commentsMarkdown ? $this->markdown($text) : $this->autoP($text);
     }
     $text = $this->pluginHandle(__CLASS__)->contentEx($text, $this);
     return Typecho_Common::stripTags($text, '<p><br>' . $this->options->commentsHTMLTagAllowed);
 }
Exemple #2
0
 /**
  * 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('这个目标地址不存在'));
     }
 }
Exemple #3
0
 /**
  * 获取当前评论内容
  *
  * @access protected
  * @return string
  */
 protected function ___content()
 {
     $text = $this->parentContent['hidden'] ? _t('内容被隐藏') : $this->text;
     $text = $this->pluginHandle(__CLASS__)->trigger($plugged)->content($text, $this);
     if (!$plugged) {
         $text = $this->options->commentsMarkdown ? $this->markdown($text) : $this->autoP($text);
     }
     $text = $this->pluginHandle(__CLASS__)->contentEx($text, $this);
     $text = preg_replace("# <(?![/a-z]) | (?<=\\s)>(?![a-z]) #exi", "htmlentities('\$0')", $text);
     return Typecho_Common::stripTags($text, '<p><br>' . $this->options->commentsHTMLTagAllowed);
 }
Exemple #4
0
 /**
  * 过滤评论内容
  *
  * @access public
  * @param string $text 评论内容
  * @return string
  */
 public function filterText($text)
 {
     $text = str_replace("\r", '', trim($text));
     $text = preg_replace("/\n{2,}/", "\n\n", $text);
     return Typecho_Common::removeXSS(Typecho_Common::stripTags($text, $this->options->commentsHTMLTagAllowed));
 }
function threadedComments($comments, $singleCommentOptions)
{
    global $smilies_from, $smilies_to;
    ?>
<li class="comment depth-<?php 
    echo $comments->levels + 1;
    if ($comments->authorId == $comments->ownerId) {
        echo " bypostauthor";
    }
    ?>
" id="<?php 
    $comments->theId();
    ?>
">
	<div id="div-<?php 
    $comments->theId();
    ?>
" class="comment-body">
		<div class="comment-author vcard"><?php 
    if ($comments->levels == 0) {
        ?>
			<img alt="" src="<?php 
        echo getAvatar(50, $comments->mail);
        ?>
" class="avatar" height="50" width="50" /><?php 
    } else {
        ?>
      <img alt="" src="<?php 
        echo getAvatar(30, $comments->mail);
        ?>
" class="avatar" height="30" width="30" /><?php 
    }
    ?>
      <cite class="fn"><?php 
    echo empty($comments->url) ? htmlspecialchars($comments->author) : "<a href=\"" . $comments->url . "\" rel=\"external nofollow\" class=\"url\" target=\"_blank\">" . htmlspecialchars($comments->author) . "</a>";
    ?>
</cite>
      <time><?php 
    echo timesince($comments->created);
    ?>
</time>
    </div>
    <div class="comment-content"><?php 
    $output = "";
    // HTML loop taken from texturize function, could possible be consolidated
    $textarr = preg_split("/(<.*>)/U", Typecho_Common::stripTags($comments->text, "<br><a href=\"\">"), -1, PREG_SPLIT_DELIM_CAPTURE);
    $stop = count($textarr);
    for ($i = 0; $i < $stop; $i++) {
        $content = $textarr[$i];
        if (strlen($content) > 0 && '<' != $content[0]) {
            $content = str_replace($smilies_from, $smilies_to, $content);
        }
        $output .= $content;
    }
    echo $output;
    ?>
</div>
    <footer class="comment-footer">
    	<?php 
    $comments->reply("回复");
    ?>
    	<a href="#" class="com-at" data-name="@<?php 
    echo htmlspecialchars($comments->author);
    ?>
" data-id="#<?php 
    $comments->theId();
    ?>
">@TA</a>
    </footer>
  </div>
  <?php 
    if ($comments->children) {
        ?>
<ol class="children"><?php 
        $comments->threadedComments($singleCommentOptions);
        ?>
</ol><?php 
    }
    ?>
</li><?php 
}
Exemple #6
0
 /**
  * 获取当前评论内容
  *
  * @access protected
  * @return string
  */
 protected function ___content()
 {
     $text = $this->parentContent['hidden'] ? _t('内容被隐藏') : $this->text;
     $text = $this->pluginHandle(__CLASS__)->trigger($plugged)->content($text, $this);
     if (!$plugged) {
         $text = $this->options->commentsMarkdown ? MarkdownExtraExtended::defaultTransform($text) : Typecho_Common::cutParagraph($text);
     }
     $text = $this->pluginHandle(__CLASS__)->contentEx($text, $this);
     return Typecho_Common::stripTags($text, '<p><br>' . $this->options->commentsHTMLTagAllowed);
 }