Article.php 4.42 KB
<?php
/**
 * tpshop
 * ============================================================================
 * 版权所有 2015-2027 深圳搜豹网络科技有限公司,并保留所有权利。
 * 网站地址: http://www.tp-shop.cn
 * ----------------------------------------------------------------------------
 * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
 * 不允许对程序代码以任何形式任何目的的再发布。
 * ============================================================================
 * Author: 当燃      
 * Date: 2015-09-09
 */
namespace app\manager\controller;
use think\Page;
use think\Db;

class Article extends Base {


    public function _initialize()
    {
        parent::_initialize();
    }


    

    public function articleList(){
        $Article =  M('news');
        $list = array();
        $p = input('p/d', 1);
        $pagenum = input('pagenum/d', 20);
        $where = array();
        $keywords = I('keywords');
        $keywords && $where['title'] = array('like', '%' . $keywords . '%');
        $res = $Article->where($where)->order('article_id desc')->page("$p,$pagenum")->select();

        $count = $Article->where($where)->count();// 查询满足要求的总记录数
        $pager = new Page($count,$pagenum);// 实例化分页类 传入总记录数和每页显示的记录数
        $page = $pager->show();//分页显示输出
        $oldurl="";
        $this->assign('oldurl', $oldurl);
        $this->assign('list',$res);// 赋值数据集
        $this->assign('page',$page);// 赋值分页输出
        $this->assign('pager',$pager);
        $this->assign('keywords',$keywords);
        $this->assign('pagenum',$pagenum);

        return $this->fetch('articleList');
    }
    
    public function article(){
 		$act = I('get.act','add');
        $info = array();
        $info['publish_time'] = time();
        $info['publish_etime'] = time()+60*60*24*7;
        $info['is_open'] = 1;
        $article_id = I('get.article_id/d');
        if($article_id){
           $info = M('news')->where('article_id', $article_id)->find();
        }
        
        $this->assign('act',$act);
        $this->assign('info',$info);
        $this->initEditor();
        return $this->fetch();
    }
    
     
    /**
     * 初始化编辑器链接
     * @param $post_id post_id
     */
    private function initEditor()
    {
        $this->assign("URL_upload", U('Manager/Ueditor/imageUp',array('savepath'=>'article','savepath1'=>'temp')));
        $this->assign("URL_fileUp", U('Manager/Ueditor/fileUp',array('savepath'=>'article','savepath1'=>'temp')));
        $this->assign("URL_scrawlUp", U('Manager/Ueditor/scrawlUp',array('savepath'=>'article','savepath1'=>'temp')));
        $this->assign("URL_getRemoteImage", U('Manager/Ueditor/getRemoteImage',array('savepath'=>'article','savepath1'=>'temp')));
        $this->assign("URL_imageManager", U('Manager/Ueditor/imageManager',array('savepath'=>'article','savepath1'=>'temp')));
        $this->assign("URL_imageUp", U('Manager/Ueditor/imageUp',array('savepath'=>'article','savepath1'=>'temp')));
        $this->assign("URL_getMovie", U('Manager/Ueditor/getMovie',array('savepath'=>'article','savepath1'=>'temp')));
        $this->assign("URL_Home", "");
    }
    

    
    public function aticleHandle(){
        $data = I('post.');
        $data['content'] = I('content'); // 文章内容单独过滤
        $data['publish_time'] = strtotime($data['publish_time']);
        $data['publish_etime'] = strtotime($data['publish_etime']);
        $url = $this->request->server('HTTP_REFERER');
        $referurl = !empty($url) ? $url : U('Manager/Article/articleList');
        //$data['content'] = htmlspecialchars(stripslashes($_POST['content']));
        if($data['act'] == 'add'){

            $data['click'] = mt_rand(1000,1300);
        	$data['add_time'] = time(); 
            $r = M('news')->add($data);
        }
       
        if($data['act'] == 'edit'){
            $r = M('news')->where('article_id', $data['article_id'])->save($data);
        }
        
        if($data['act'] == 'del'){

        	$r = M('news')->where('article_id', $data['article_id'])->delete();
        	if($r) exit(json_encode(1));       	
        }

        if($data['act'] == 'edit') {
            $this->success("操作成功",U('Manager/Article/articleList'));
        }else{
            $this->success("操作成功",$referurl);
        }
    }
    


}