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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
<?php
class Smarty_Internal_Compile_Article extends Smarty_Internal_CompileBase{
  public $required_attributes = array('item');
  public $optional_attributes = array('name', 'key', 't_len', 'rec', 'limit', 'pic', 'd_len', 'type', 'urlstatic','print','order','ispage','nid','islt','cache','keyword');
  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);
    }
 
    //自定义标签 START
    //数据库操作
    $OutputStr = '
        global $db,$db_config,$config;
        include PLUS_PATH.\'/group.cache.php\';'
        .$name.'=    array();
        $rs        =    null;
        $nids    =    null;
 
        $paramer    =    '.ArrayToString($_attr,true).';
 
        $ParamerArr    =    GetSmarty($paramer,$_GET,$_smarty_tpl);
 
        $paramer    =    $ParamerArr[\'arr\'];
 
        $Purl        =    $ParamerArr[\'purl\'];
 
        if($paramer[cache]){
 
            $Purl    =    "{{page}}.html";
        }
 
        global $ModuleName;
 
        if(!$Purl["m"]){
            $Purl["m"]=$ModuleName;
        }
 
        $where=1;
 
        $where .=" and (`starttime`<=".time()." or `starttime`=0 or `starttime` is null)";
 
        $where .=" and (`endtime`>".time()." or `endtime`=0 or `endtime` is null)";
 
        if($config[\'did\']){
 
            $where    .=    " and (`did`=\'".$config[\'did\']."\' or `did`=-1)";
        }else{
            
            $where    .=    " and (`did`=-1 OR `did`=0 OR did=\'\')";
        }
 
        include PLUS_PATH."/group.cache.php";
        if($paramer[\'nid\']){
            $nid_s = @explode(\',\',$paramer[nid]);
            foreach($nid_s as $v){
                if($group_type[$v]){
                    $paramer[nid] = $paramer[nid].",".@implode(\',\',$group_type[$v]);
                }
            }
        }
 
        if($paramer[\'nid\']!="" && $paramer[\'nid\']!=0){
            $where .=" AND `nid` in ($paramer[nid])";
            $nids = @explode(\',\',$paramer[\'nid\']);
            $paramer[\'nid\']=$paramer[\'nid\'];
        }else if($paramer[\'rec\']!=""){
            $nids=array();
            if(is_array($group_rec)){
                foreach($group_rec as $key=>$value){
                    if($key<=2){
                        $nids[]=$value;
                    }
                }
                $paramer[nid]=@implode(\',\',$nids);
            }
        }
 
        if($paramer[\'type\']){
            $type = str_replace("\"","",$paramer[type]);
            $type_arr =    @explode(",",$type);
            if(is_array($type_arr) && !empty($type_arr)){
                foreach($type_arr as $key=>$value){
                    $where .=" AND FIND_IN_SET(\'".$value."\',`describe`)";
                    if(count($nids)>0){
                        $picwhere .=" AND FIND_IN_SET(\'".$value."\',`describe`)";
                    }
                }
            }
        }
 
        //拼接补充SQL条件
        if($paramer[\'pic\']!=""){
            $where .=" AND `newsphoto`<>\'\'";
        }
 
         //新闻搜索
        if($paramer[\'keyword\']!=""){
            $where .=" AND `title` LIKE \'%".$paramer[keyword]."%\'";
        }
 
        //拼接查询条数
        if(intval($paramer[\'limit\'])>0){
            $limit = intval($paramer[\'limit\']);
            $limit = " limit ".$limit;
        }
 
        if($paramer[\'ispage\']){
            if($Purl["m"]=="wap"){
                $limit = PageNav($paramer,$_GET,"news_base",$where,$Purl,"","6",$_smarty_tpl);
            }else{
                $limit = PageNav($paramer,$_GET,"news_base",$where,$Purl,"","5",$_smarty_tpl);
            }
        }
 
        //拼接字段排序
        if($paramer[\'order\']!=""){
            $where .=" ORDER BY $paramer[order]";
        }else{
            $where .=" ORDER BY `starttime`";
        }
 
        //排序方式默认倒序
        if($paramer[\'sort\']){
            $where.=" ".$paramer[sort];
        }else{
            $where.=" DESC";
        }
 
        //多类别新闻查找
        if(!intval($paramer[\'ispage\']) && count($nids)>0){
 
            $nidArr = @explode(\',\',$paramer[nid]);
            $rsnids = array();
            if(is_array($group_type)){
                foreach($group_type as $key=>$value){
                    if(in_array($key,$nidArr)){
                        if(is_array($value)){
                            foreach($value as $v){
                                $rsnids[$v] = $key;
                                $nidArr[] = $v;
                            }
                        }
                    }
                }
            }
 
            $where = " `nid` IN (".@implode(\',\',$nidArr).")";
 
            if($config[\'did\']){
                $where.=" and `did`=\'".$config[\'did\']."\'";
            }
 
            //查询带图新闻
            if($paramer[\'pic\']){
                if(!$paramer[\'piclimit\']){
                    $piclimit = 1;
                }else{
                    $piclimit = $paramer[\'piclimit\'];
                }
 
                $db->query("set @f=0,@n=0");
 
                $query = $db->query("select * from (select id,title,color,datetime,starttime,description,newsphoto,@n:=if(@f=nid,@n:=@n+1,1) as aid,@f:=nid as nid from $db_config[def]news_base  WHERE ".$where." AND `newsphoto` <>\'\'  order by nid asc,starttime desc) a where aid <=".$piclimit);
 
                $conque = $db->select_all("news_content","1 order by nbid desc".$limit);
 
                foreach($conque as $cv){
                    $newcon[$cv[nbid]]=$cv;
                }
                while($rs = $db->fetch_array($query)){
 
                    if($rsnids[$rs[\'nid\']]){
                        $rs[\'nid\'] = $rsnids[$rs[\'nid\']];
                    }
 
                    //处理标题长度
                    if(intval($paramer[t_len])>0){
                        $len = intval($paramer[t_len]);
                        $rs[title_n] = $rs[title];
                        $rs[title] = mb_substr($rs[title],0,$len,"utf-8");
                    }
 
                    if($rs[color]){
                        $rs[title] = "<font color=\'".$rs[color]."\'>".$rs[title]."</font>";
                    }
 
                    //处理描述内容长度
                    if(intval($paramer[d_len])>0){
                        $len = intval($paramer[d_len]);
                        $rs[description] = mb_substr($rs[description],0,$len,"utf-8");
                    }
 
                    $rs[\'name\'] = $group_name[$rs[\'nid\']];
 
                    //构建资讯静态链接
                    if($config[sy_news_rewrite]=="2"){
                        $rs["url"]=$config[\'sy_weburl\']."/news/".date("Ymd",$rs["datetime"])."/".$rs[id].".html";
                    }else{
                        $rs["url"] = Url("article",array("c"=>"show","id"=>$rs[id]),"1");
                    }
 
                    if(mb_substr($rs[newsphoto],0,4)=="http"){
                        $rs["picurl"]=$rs[newsphoto];
                    }else{
                        if($rs[\'newsphoto\']==""){
                            $content=str_replace(array(\'"\',"\'"),array("",""),$newcon[$rs[id]]["content"]);
                            preg_match_all("/<img[^>]+src=(.*?)\s[^>]+>/im",$content,$res);
                            $str=str_replace("\\\\","",$res[1][0]);
                            if($str){
                                $rs[newsphoto]=".".$str;
                            }
                        }
                        $nopic=$config[sy_weburl]."/app/template/".$config[style]."/images/nopic.gif";
 
                        $rs["picurl"] = checkpic($rs[\'newsphoto\'],$nopic);
 
                    }
 
                    $rs[time]=date("Y-m-d",$rs[starttime]);
                    $rs[\'starttime\']=date("m-d",$rs[starttime]);
                    if(count('.$name.'[$rs[\'nid\']][\'pic\'])<$piclimit){
                      '.$name.'[$rs[\'nid\']][\'pic\'][] = $rs;
                    }
                }//end while
            }
 
            $db->query("set @f=0,@n=0");
            $query = $db->query("select * from (select id,title,datetime,starttime,color,description,newsphoto,@n:=if(@f=nid,@n:=@n+1,1) as aid,@f:=nid as nid from $db_config[def]news_base  WHERE ".$where." order by nid asc,starttime desc) a where aid <=$paramer[limit]");
 
            while($rs = $db->fetch_array($query)){
                if($rsnids[$rs[\'nid\']]){
                    $rs[\'nid\'] = $rsnids[$rs[\'nid\']];
                }
 
                //处理标题长度
                if(intval($paramer[t_len])>0){
                    $len = intval($paramer[t_len]);
                    $rs[title_n] = $rs[title];
                    $rs[title] = mb_substr($rs[title],0,$len,"utf-8");
                }
 
                if($rs[color]){
                    $rs[title] = "<font color=\'".$rs[color]."\'>".$rs[title]."</font>";
                }
 
                //处理描述内容长度
                if(intval($paramer[d_len])>0){
                    $len = intval($paramer[d_len]);
                    $rs[description] = mb_substr($rs[description],0,$len,"utf-8");
                }
 
                //获取所属类别名称
                $rs[\'name\'] = $group_name[$rs[\'nid\']];
 
                //构建资讯静态链接
                if($config[sy_news_rewrite]=="2"){
                    $rs["url"]=$config[\'sy_weburl\']."/news/".date("Ymd",$rs["datetime"])."/".$rs[id].".html";
                }else{
                    $rs["url"] = Url("article",array("c"=>"show","id"=>$rs[id]),"1");
                }
 
                if(mb_substr($rs[newsphoto],0,4)=="http"){
                    $rs["picurl"]=$rs[newsphoto];
                }else{
                    if($rs[\'newsphoto\']==""){
                        $rs["picurl"] = $config[sy_weburl]."/app/template/".$config[style]."/images/nopic.gif";
                    }else{
                        $rs["picurl"] = checkpic($rs[\'newsphoto\']);
                    }
                }
 
                $rs[time]=date("Y-m-d",$rs[starttime]);
                $rs[starttime]=date("m-d",$rs[starttime]);
                if(count('.$name.'[$rs[\'nid\']][\'arclist\'])<$paramer[limit]){
                    '.$name.'[$rs[\'nid\']][\'arclist\'][] = $rs;
                }
            }//end while
 
        }//end if(!intval($paramer[\'ispage\']) && count($nids)>0)
        else{
            $query = $db->query("SELECT * FROM `$db_config[def]news_base` WHERE ".$where.$limit);
 
            while($rs = $db->fetch_array($query)){
                //处理标题长度
                if(intval($paramer[t_len])>0){
                    $len = intval($paramer[t_len]);
                    $rs[title_n] = $rs[title];
                    $rs[title] = mb_substr($rs[title],0,$len,"utf-8");
                }
 
                if($rs[color]){
                    $rs[title] = "<font color=\'".$rs[color]."\'>".$rs[title]."</font>";
                }
 
                //处理描述内容长度
                if(intval($paramer[d_len])>0){
                    $len = intval($paramer[d_len]);
                    $rs[description] = mb_substr($rs[description],0,$len,"utf-8");
                }
 
                //获取所属类别名称
                 $rs[\'name\'] = $group_name[$rs[\'nid\']];
 
                //构建资讯静态链接
                if($config[sy_news_rewrite]=="2"){
                    $rs["url"]=$config[\'sy_weburl\']."/news/".date("Ymd",$rs["datetime"])."/".$rs[id].".html";
                }else{
                    $rs["url"] = Url("article",array("c"=>"show","id"=>$rs[id]),"1");
                }
 
                if(mb_substr($rs[newsphoto],0,4)=="http"){
                    $rs["picurl"]=$rs[newsphoto];
                }else{
                    if($rs[\'newsphoto\']==""){
                        $rs["picurl"] = $config[sy_weburl]."/app/template/".$config[style]."/images/nopic.gif";
                    }else{
                        $rs["picurl"] = checkpic($rs[\'newsphoto\']);
                    }
                }
 
                $rs[time]=date("Y-m-d",$rs[starttime]);
                $rs[starttime]=date("m-d",$rs[starttime]);
                '.$name.'[] = $rs;
            }//end while
        }';
        //自定义标签 END
        //global $DiyTagOutputStr;
        //$DiyTagOutputStr[]=$OutputStr;
        return SmartyOutputStr($this,$compiler,$_attr,'article',$name,$OutputStr,$name);
    }
}
class Smarty_Internal_Compile_Articleclose 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('article', 'articleelse'));
 
return "<?php } ?>";
}
}