summaryrefslogtreecommitdiffstats
path: root/libs/Comments.php
blob: d97b4bcc77bdf6cf5158409f61e33d2b5374b408 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php 
/**
 * Comments.php
 * 评论处理
 * 
 * Author:  Eltrac(BigCoke233)
 * License: MIT
 */
if (!defined('__TYPECHO_ROOT_DIR__')) exit;
class Comments
{
    /**
     * 评论反垃圾
     * from ohmyga233/castle-Typecho-Theme
     *
     * @access public
     */
    public static function AntiSpam($id, $value) {
        if ($comment->options->switch && in_array('html', $comment->options->switch)) { echo '<!--<nocompress>-->'; }
        echo '<script>(function(){var a=document.addEventListener?{add:"addEventListener",focus:"focus",load:"DOMContentLoaded"}:{add:"attachEvent",focus:"onfocus",load:"onload"};var c,d,e,f,b=document.getElementById("'.$id.'");null!=b&&(c=b.getElementsByTagName("form"),c.length>0&&(d=c[0],e=d.getElementsByTagName("textarea")[0],f=!1,null!=e&&"text"==e.name&&e[a.add](a.focus,function(){if(!f){var a=document.createElement("input");a.type="hidden",a.name="_",d.appendChild(a),f=!0,a.value='.$value.'}})))})();</script>';
        if ($comment->options->switch && in_array('html', $comment->options->switch)) { echo '<!--</nocompress>-->'; }
    }

    /**
     * 获取上级评论人
     */
    public static function getCommentHF($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('text','author','status')
                ->from('table.comments')
                ->where('coid = ?', $parent));
            $author = $arow['author'];
            $status = $arow['status'];
            if($author){
                if($status=='approved'){
                    $href   = '<a class="at" uid="'.$parent.'" href="#li-comment-'.$parent.'">@'.$author.'</a>';;
                }else if($status=='waiting'){
                    $href   = '<a>评论审核中···</a>';
                }
            }
            echo $href;
        } else {
            echo "";
        }
    }
}