chengkun
2025-04-18 1bb985f32f2efe0f9dd69f3cf29a1c809b1cf96d
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
<?php
class Smarty_Internal_Compile_Qlist extends Smarty_Internal_CompileBase{
    public $required_attributes = array('item');
    public $optional_attributes = array('name', 'key', 'ispage', 't_len', 'order', 'limit', 'cid', 'recom','hot','uid','keyword','noid','friend','nonum','yesnum','is_recom','state');
    public $shorttag_order = array('from', 'item', 'key', 'name');
    public function compile($args, $compiler, $parameter){
        $_attr = $this->getAttributes($compiler, $args);
 
        $from = $_attr['from'];
        $item = $_attr['item'];
        $name = $_attr['item'];
        $name=str_replace('\'','',$name);
        $name=$name?$name:'list';$name='$'.$name;
        if (!strncmp("\$_smarty_tpl->tpl_vars[$item]", $from, strlen($item) + 24)) {
            $compiler->trigger_template_error("item variable {$item} may not be the same variable as at 'from'", $compiler->lex->taglineno);
        }
        
        $OutputStr='global $db,$db_config,$config;$paramer='.ArrayToString($_attr,true).';'.$name.'=array();
        $ParamerArr = GetSmarty($paramer,$_GET,$_smarty_tpl);
        $paramer = $ParamerArr[arr];
        $Purl =  $ParamerArr[purl];
        global $ModuleName;
        if(!$Purl["m"]){
            $Purl["m"]=$ModuleName;
        }
         
        if($paramer[state]){
           $where=1;
        }else{
           $where = "`state`=1 ";
        }
        
        
        if($_COOKIE[\'uid\']&&$paramer[\'friend\']){
            $atn=$db->select_all("atn","`uid`=\'".$_COOKIE[\'uid\']."\'","`sc_uid`");
            $friend=array();
            foreach($atn as $val){
                $friend[]=$val[\'sc_uid\'];
            }
            $where.=" and `id` in(".@implode(\',\',$friend).")";
            unset($friend);
        } 
        if($paramer[hot]){
            $time=strtotime("-".(int)$paramer[hot]." day");
            $where.=" and `add_time`>\'".$time."\'";
        }
        if($paramer[noid]){
            $where.=" and `id`<>\'".$paramer[noid]."\'";
        }
        if($paramer[keyword]){
            $where.=" and `title` like \'%".$paramer[\'keyword\']."%\'";
        }
        if($paramer[nonum]){
            $where.=" and `answer_num`=\'0\'";
        }
        if($paramer[yesnum]){
            $where.=" and `answer_num`>0";
        }
        //排序字段默认为更新时间
        if($paramer[order]){ 
            if($paramer[order]=="addtime"){
                $paramer[order]="add_time";
            }
            if($paramer[order]=="answernum"){
                $paramer[order]="answer_num";
            }
            $order = " ORDER BY `".$paramer[order]."`  desc";
        }else{
            $order = " ORDER BY `add_time` desc";
        }
        if($paramer[cid]){
            $where .=" and `cid`=\'".$paramer[cid]."\'";
        }
        if($paramer[uid]){
            $where .=" and `uid`=\'".$paramer[uid]."\'";
        }
        if($paramer[is_recom]){//推荐 字段
            $where .=" and `is_recom`=\'1\'";
        }
        //if($config[\'ask_check\']){//问答审核开启
            
        //}
        
        if($paramer[limit]){
            $limit=" limit ".$paramer[limit];
        }
        
        if($paramer[\'ispage\']){
            $limit = PageNav($paramer,$_GET,"question",$where,$Purl,"","6",$_smarty_tpl);
        }
        '.$name.' = $db->select_all("question",$where.$order.$limit);  
        if(count('.$name.')){
            foreach('.$name.' as $key=>$val){
                if(intval($paramer[t_len])>0){
                    $len = intval($paramer[t_len]);
                    '.$name.'[$key][title]  = mb_substr($val[title],0,$len,"utf-8");
                }
                if($paramer[\'keyword\']){ 
                    '.$name.'[$key][title] =str_replace($paramer[keyword],"<font color=\'#FF6600\' >".$paramer[keyword]."</font>",'.$name.'[$key][title]);
                }
                '.$name.'[$key][\'pic\']=checkpic($val[\'pic\'],$config[\'sy_friend_icon\']);
                '.$name.'[$key][url] = Url("ask",array("c"=>"content","id"=>$val[id]));
                '.$name.'[$key][userurl] = Url("ask",array("c"=>"friend","a"=>"myquestion","uid"=>$val[uid]));
                if(in_array($val[uid],$ListId)==false){$ListId[] =  $val[uid];} 
                $Qclass[]=$val[cid];//问题类别
            }
            //获得提问者uid,并根据uid 获得头像、昵称
            $uids=@implode(",",$ListId);
            $_GET["total"]=1;  
            foreach('.$name.' as $r_k=>$r_v){
                if($r_v[\'uid\']==$_COOKIE[\'uid\']){
                    '.$name.'[$r_k][\'isatn\']=\'2\';//表示这是本人,不显示关注按钮
                } 
            }    
        }';
        //自定义标签 END
       // global $DiyTagOutputStr;
       // $DiyTagOutputStr[]=$OutputStr;
        return SmartyOutputStr($this,$compiler,$_attr,'qlist',$name,$OutputStr,$name);
    }
}
class Smarty_Internal_Compile_Qlistelse extends Smarty_Internal_CompileBase{
    public function compile($args, $compiler, $parameter){
        $_attr = $this->getAttributes($compiler, $args);
 
        list($openTag, $nocache, $item, $key) = $this->closeTag($compiler, array('qlist'));
        $this->openTag($compiler, 'qlistelse', array('qlistelse', $nocache, $item, $key));
 
        return "<?php }\nif (!\$_smarty_tpl->tpl_vars[$item]->_loop) {\n?>";
    }
}
class Smarty_Internal_Compile_Qlistclose extends Smarty_Internal_CompileBase{
    public function compile($args, $compiler, $parameter){
        $_attr = $this->getAttributes($compiler, $args);
        if ($compiler->nocache) {
            $compiler->tag_nocache = true;
        }
 
        list($openTag, $compiler->nocache, $item, $key) = $this->closeTag($compiler, array('qlist', 'qlistelse'));
 
        return "<?php } ?>";
    }
}