chengkun
2025-04-27 a0402d122fee696e2b7684ef7edfc504ade12640
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
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
<?php
 
 
class admin_news_controller extends siteadmin_controller{
 
    //时间区间
    public $timeSection        =    array(
        '1'        =>    '今天',
        '3'        =>    '最近三天',
        '7'        =>    '最近七天',
        '15'    =>    '最近半月',
        '30'    =>    '最近一个月'
    );
    
    //设置高级搜索功能
    public function set_search($groupList, $cateStr){
 
        //获取一级分类数据
        $newsarr            =    array();
        if(isset($groupList['one_class'])){
            foreach ($groupList['one_class'] as $oneV) {
                $newsarr[$oneV['id']]    =    $oneV['name'];
            }
        }
        //获取二级分类数据
        $newsarrs            =    $tmpTwo    =    array();
        $groupTwo            =    $groupList['two_class'];
        if(!empty($cateStr)){
            $tmpTwo            =    isset($groupTwo[$cateStr]) ? $groupTwo[$cateStr] : array();
            $this -> yunset("cateinfo", $groupList['list'][$cateStr]);
        }
 
        if(!empty($tmpTwo)){
            foreach ($tmpTwo as $twoV) {
                $newsarrs[$twoV['id']]    =    $twoV['name'];
            }
        }
        $search_list[]        =    array(
            'param'            =>    'publish',
            'name'            =>    '发布时间',
            'value'            =>    $this -> timeSection
        );
        $search_list[]        =    array(
            'param'            =>    'cate',
            'name'            =>    '新闻类别',
            'value'            =>    $newsarr
        );
        if(!empty($newsarrs) && !empty($cateStr)){
            $search_list[]    =    array(
                'param'        =>    'cates',
                'name'        =>    '新闻子类',
                'value'        =>    $newsarrs
            );
        }
        $this -> yunset('search_list', $search_list);
    }
    /**
     * 内容 - 新闻 - 新闻管理
     * 2019-06-06 hjy
     */
    public function index_action(){
 
        //实例化新闻类
        $articleM        =    $this -> MODEL('article');
 
        //提取新闻分类        
        $listNew        =    $articleM -> getClass(array('isson' => 1));
        $newsGroup        =    $listNew['list'];
 
        $cateStr        =    intval($_GET['cate']);
 
        //设置搜索,传入新闻分类
        $this -> set_search($listNew, $cateStr);
 
        $two_class        =    $listNew['two_class'];
        $this -> yunset('one_class', $listNew['one_class']);
        $this -> yunset('two_class', $two_class);
 
        //搜索条件
        if (!empty($cateStr)){
            if(isset($two_class[$cateStr])){
                $ids                =    array_keys($two_class[$cateStr]);
            }
            $ids[]                    =    $cateStr;
 
            $where['nid']            =    array('in', pylode(',',$ids));
            $urlarr['cate']            =    $cateStr;
        }
 
        if ($_GET['cates'] != '')
        {            
            $where['nid']            =    $_GET['cates'];
 
            $urlarr['cates']        =    $_GET['cates'];
        }
        if($_GET['adtime'])
        {
            if($_GET['adtime']=='1')
            {
                $where['datetime']    =    array('>',strtotime(date('Y-m-d 00:00:00')));
                
            }else{
 
                $where['datetime']    =    array('>',strtotime('-'.intval($_GET['adtime']).' day'));
            }
 
            $urlarr['adtime']        =    $_GET['adtime'];
        }
        if($_GET['publish'])
        {
            if($_GET['publish']=='1')
            {
                $where['datetime']    =    array('>=',strtotime(date('Y-m-d 00:00:00')));
                
            }else{
 
                $where['datetime']    =    array('>=',strtotime('-'.(int)$_GET['publish'].'day'));
 
            }
            $urlarr['publish']        =    $_GET['publish'];
        }
        $keywordStr                    =    trim($_GET['keyword']);
        if($_GET['news_search'])
        {
            if ($_GET['type'] == 1)
            {
                $where['title']        =    array('like', $keywordStr);
 
            }elseif ($_GET['type'] == 2){
                
                $where['author']    =    array('like', $keywordStr);
            }
 
            $urlarr['type']            =    $_GET['type'];
 
            $urlarr['keyword']        =    $keywordStr;
 
            $urlarr['news_search']    =    $_GET['news_search'];
        }
    
        //分页链接
        $urlarr['page']    =    '{{page}}';
        
        $pageurl        =    Url($_GET['m'],$urlarr,'admin');
        
        //提取分页
        $pageM            =    $this  -> MODEL('page');
        $pages            =    $pageM -> pageList('news_base',$where,$pageurl,$_GET['page']);
        
        //分页数大于0的情况下 执行列表查询
        if($pages['total'] > 0){
 
            //limit order 只有在列表查询时才需要
            if($_GET['order'])
            {
                $where['orderby']    =    $_GET['t'].','.$_GET['order'];
                $urlarr['order']    =    $_GET['order'];
                $urlarr['t']        =    $_GET['t'];
            }else{
                $where['orderby']    =    'id';
            }
            $where['limit']            =    $pages['limit'];
        
            $List    =    $articleM -> getList($where,array('tlen'=>'20','group'=>$newsGroup,'property'=>'1'));
            $this -> yunset('adminnews', $List['list']);
            $this -> yunset('property', $List['property']);
            $this -> yunset('propertys', $List['property']);
        }
        $this -> yunset('get_type', $_GET);
 
        $this->siteadmin_tpl(array('admin_news_list'));
    }
 
    /**
     * 内容 - 新闻 - 新闻管理
     * 修改新闻
     * 2019-06-10 hjy
     */
    public function news_action(){
 
        $articleM            =    $this -> Model('article');
 
        if($_GET['nid'])
        {
            $news['nid']    =    $_GET['nid'];
            $this -> yunset('news', $news['nid']);
        }
        //提取新闻分类
        
        $listNew        =    $articleM -> getClass(array('isson' => 1));
        $newsGroup        =    $listNew['list'];
        
        $this -> yunset('one_class' , $listNew['one_class']);
        $this -> yunset('two_class' , $listNew['two_class']);
        
        //提取新闻属性标签
        $property        =    $articleM -> getProperty();
 
        $this -> yunset('property',$property);
        
        if($_GET['id']){
            $Info        =    $articleM -> getInfo(array('id'=>$_GET['id']),array('iscon'=>'1'));
             $describe    =    @explode(',', $Info['describe']);
            $this -> yunset('describe', $describe);
            $this -> yunset('info', $Info);
            $this -> yunset('lasturl', $_SERVER['HTTP_REFERER']);
        }else{
            $Info['sort']    =    rand(1, 300 );
            $this -> yunset('info', $Info);
        }
        $this->siteadmin_tpl(array('admin_news_add'));
    }
 
    /**
     * 内容 - 新闻 - 新闻管理
     * 保存新闻
     * 2019-06-10 hjy
     */
    public function addnews_action()
    {
        $postData              =    $this -> post_trim($_POST);
        $postData['did']    =    $this->config['did'];
        $articleM              =    $this -> MODEL('article');
        
        if ($_FILES['file']) {
            
            $postData['file']  =  $_FILES['file'];
        }
        
        $return  =  $articleM -> addNews($postData);
 
        if($return['errcode'] == 9 && !empty($return['data'])){
            $this -> articleshow($return['data']);
            $this -> ACT_layer_msg($return['msg'], 9, Url('admin_news', null, 'admin'), 2, 1);
        }else{
            $this -> ACT_layer_msg($return['msg'], 8, Url('admin_news', null, 'admin'));
        }
    }
 
    //通过smarty缓存直接生成静态文件
    public function articleshow($id){
 
        $articleM                        =    $this -> MODEL('article');
        $news                            =    $articleM -> getInfo(array('id'=>$id),array('iscon'=>'1'));
        if(empty($news)){
            return false;
        }
 
        $fieldArr                        =    array('feild' => '`datetime`, `id`, `title`');
        //获取前一篇文章
        $news_last                        =    $articleM -> getInfo(array('id' => array('<', $id), 'orderby' => 'id,des'), $fieldArr);
        if(!empty($news_last)){
            if($this -> config['sy_news_rewrite'] == 2){
                $news_last['url']        =    $this -> config['sy_weburl'].'/news/'.date('Ymd', $news_last['datetime']).'/'.$news_last['id'].'.html';
            }else{
                $news_last['url']        =     Url('article', array('c' => 'show', 'id' => $news_last['id']), 1);
            }
        }
        //获取后一篇文章
        $news_next                        =    $articleM -> getInfo(array('id' => array('>', $id), 'orderby' => 'id,asc'), $fieldArr);
        if(!empty($news_next)){
            if($this -> config['sy_news_rewrite'] == 2){
                $news_next['url']        =    $this->config['sy_weburl'].'/news/'.date('Ymd', $news_next['datetime']).'/'.$news_next['id'].'.html';
            }else{
                $news_next['url']        =    Url('article',array('c'=>'show', 'id' => $news_next['id']), 1);
            }
        }
 
        //相关文章,按照关键字获取
        if($news["keyword"]!=""){
 
            $keyarr = @explode(",",$news["keyword"]);
            if(is_array($keyarr) && !empty($keyarr)){
                $where['PHPYUNBTWSTART_A']    =    '' ;
                foreach($keyarr as $key=>$value){
                    $where['keyword'][]        =    array('like',$value,'OR') ;
                }
                $where['PHPYUNBTWEND_A']    =    '' ;
                $where['id']                =    array('<>',$id);
                $where['orderby']            =    'id,desc';
                $where['limit']                =    6;
                
                $aboutlist    =    $articleM->getList($where);//相关文章
                $about        =    $aboutlist['list'];
                
                if(is_array($about)){
                    foreach($about as $k=>$v){
                        if($this->config['sy_news_rewrite']=="2"){
                            
                            $about[$k]["url"]    =    $this->config['sy_weburl']."/news/".date("Ymd",$v["datetime"])."/".$v['id'].".html";
                            
                        }else{
                            $about[$k]["url"]    =     Url('article',array('c'=>'show',"id"=>$v['id']),"1"); 
                        }
                    }
                }
            }
        }
 
        //新闻类别
        $class                            =    $articleM -> getGroup(array('id' => $news['nid']));
 
        $info                            =    $news;
    
        $data['news_title']                =    $news['title'];//新闻名称
        $data['news_keyword']            =    $news['keyword'];//描述
        $data['news_class']                =    $class['name'];//新闻类别
        $data['news_desc']                =    $this -> GET_content_desc($news['description']);//描述
        $this -> data                    =    $data;
        $info['news_class']                =    $class['name'];
        $info['last']                    =    $news_last;
        $info['next']                    =    $news_next;
        $info['like']                    =    $about;
        $this -> yunset('Info', $info);
        
        $this -> seo('news_article');
        global $phpyun;
        //必须传参数$cache_id,否则多个文件的内容会重复
        $contect                        =    $phpyun -> fetch(TPL_PATH.'default/article/show.htm', $id);
        if(!file_exists(APP_PATH.'news/'.date("Ymd",$news["datetime"]))){
            mkdir(APP_PATH.'news/'.date('Ymd', $news['datetime']));
        }
        $fp                                =    fopen(APP_PATH.'news/'.date("Ymd",$news["datetime"]).'/'.$id.'.html', 'w');
        fwrite($fp, $contect);
        fclose($fp);
    }
    /**
     * 内容 - 新闻 - 新闻管理
     * 删除新闻
     */
    public function delnews_action(){
        $this -> check_token();
 
        $del        =    $_GET['del'];
        if(is_array($del)){
            $linkid            =    pylode(',', $del);
            $layer_type        =    1;
        }else{
            $linkid            =    $_GET['id'];
            $layer_type        =    0;
        }
        if(empty($linkid)){
            $this -> layer_msg('请选择您要删除的信息!', 8, $layer_type, $_SERVER['HTTP_REFERER']);
        }
        $articleM    =    $this -> MODEL('article');
        $articleM -> delNews(array('id' => array('in', $linkid)));
        
        $this -> layer_msg('新闻(ID:'.$linkid.')删除成功!', 9, $layer_type, $_SERVER['HTTP_REFERER']);
    }
    /**
     * 内容 - 新闻 - 新闻管理
     * 保存新闻属性 取消新闻属性
     * 2019-06-06 hjy
     */
    public function savepro_action(){
    
        $typeStr    =    trim($_POST['type']);
    
        $_POST        =    $this -> post_trim($_POST);
    
        if(empty($_POST['proid'])){
      
            $this -> ACT_layer_msg('参数错误!', 8, $_SERVER['HTTP_REFERER']);
        }
        //实例化新闻类
        $articleM            =    $this -> MODEL('article');
 
        $baseWhereData        =    array('id' => array('in', $_POST['proid']));
        $list                =    $articleM -> getList($baseWhereData, array('field' => '`id`, `describe`'));
        if(empty($list['list'])){
            $this -> ACT_layer_msg('数据错误!', 8, $_SERVER['HTTP_REFERER']);
        }
        //保存新闻属性
        if($typeStr == 'add'){
            $describe        =    pylode(',', $_POST['describe']);
            if(empty($describe)){
                $this -> ACT_layer_msg('请选择属性!', 8, $_SERVER['HTTP_REFERER']);
            }
            $articleM -> upBase($baseWhereData, array('describe' => $describe));
            $this -> ACT_layer_msg('新闻(ID:'.$_POST['proid'].')设置属性成功!', 9, $_SERVER['HTTP_REFERER'], 2, 1);
        }
        //删除新闻属性
        if($typeStr == 'del'){
            foreach($list['list'] as $key => $value){
                if(!empty($value['describe'])){
                    $describe    =    @explode(',', $value['describe']);
                    foreach($describe as $key => $v){
                        if(in_array($v, $_POST['describe'])){
                            unset($describe[$key]);
                        }
                    }
                    $articleM -> upBase(array('id' => array('=', $value['id'])), array('describe' => pylode(',', $describe)));
                }
            }
            $this->ACT_layer_msg('新闻(ID:'.$_POST['proid'].')删除属性成功!', 9, $_SERVER['HTTP_REFERER'], 2, 1);
        }
    }
    /**
     * 内容 - 新闻 - 新闻管理
     * 转移分类 -> 类别搜索
     */
    public function selclass_action(){
        $_POST        =    $this -> post_trim($_POST);
        $html        =    '';
        if(empty($_POST['keyword'])){
            $html    =    '<div class="yun_admin_select_box_list"> <a href="javascript:;">参数错误</a> </div>';
            echo  $html; die;
        }
        $articleM    =    $this -> MODEL('article');
        $group        =    $articleM -> getClass(array('name' => array('like', $_POST['keyword']), 'orderby' => 'keyid,asc'));
        if(!empty($group) && !empty($group['list'])){
            foreach($group['list'] as $value){
                if($value['keyid'] == 0){
                    $html     .=    '<div class="yun_admin_select_box_list"> <a href="javascript:;" onclick="select_new(\'nid\',\''.$value['id'].'\',\''.$value['name'].'\')">'.$value['name'].'</a> </div>';
                }else{
                    $html     .=    '<div class="yun_admin_select_box_list"> <a href="javascript:;" onclick="select_new(\'nid\',\''.$value['id'].'\',\''.$value['name'].'\')">  ┗'.$value['name'].'</a> </div>';
                }
            }
        }else{
           $html    =    '<div class="yun_admin_select_box_list"> <a href="javascript:;">未找到相关数据</a> </div>';
        }
        echo  $html; die;
    }
    /**
     * 内容 - 新闻 - 新闻管理
     * 转移分类 -> 保存数据
     */
    public function changeClass_action(){
        $_POST        =    $this -> post_trim($_POST);
        if(empty($_POST['id'])){
            $this -> ACT_layer_msg('参数不全请重试!', 8, $_SERVER['HTTP_REFERER']);
        }
        $ids        =    @explode(',', $_POST['id']);
        $id            =    pylode(',', $ids);
        $nid        =    intval($_POST['nid']);
        if(!empty($id)){
            $articleM     =    $this -> MODEL('article');
            $articleM -> upBase(array('id' => array('in', $id)), array('nid' => $nid));
            $this -> ACT_layer_msg('新闻转移类别成功!', 9, $_SERVER['HTTP_REFERER']);
        }else{
            $this -> ACT_layer_msg('请正确选择需转移的新闻!', 8, $_SERVER['HTTP_REFERER']);
        }
    }
}
?>