当前位置:首页 > CMS教程 > phpcms > 列表

【phpcms-v9】phpcms-v9中将选中的批量文章推送到推荐位、推送

发布:smiling 来源: PHP粉丝网  添加日期:2014-10-24 11:16:02 浏览: 评论:0 

【phpcms-v9】phpcms-v9中将选中的批量文章推送到推荐位、推送到专题及推送到其他栏目的功能.

1.推送按钮:

2.推送弹出框:

3.push()函数:

  1. function push() {   
  2.     var str = 0;   
  3.     var id = tag = '';   
  4.     $("input[name='ids[]']").each(function() {   
  5.         if($(this).attr('checked')=='checked') {   
  6.             str = 1;   
  7.             id += tag+$(this).val();   
  8.             tag = '|';   
  9.         }   
  10.     });   
  11.     if(str==0) {   
  12.         alert('<?php echo L('you_do_not_check');?>');   
  13.         return false;   
  14.     }   
  15.     window.top.art.dialog({id:'push'}).close();   
  16.     window.top.art.dialog({title:'<?php echo L('push');?>:',id:'push',iframe:'?m=content&c=push&action=position_list&catid=<?php echo $catid?>&modelid=<?php echo $modelid?>&id='+id,width:'800',height:'500'}, function(){var d = window.top.art.dialog({id:'push'}).data.iframe;// 使用内置接口获取iframe对象   
  17.     var form = d.document.getElementById('dosubmit');form.click();return false;}, function(){window.top.art.dialog({id:'push'}).close()});   

4.modules/content/push.php推送控制器文件:

  1. <?php   
  2. defined('IN_PHPCMS'or exit('No permission resources.');   
  3.    
  4. pc_base::load_app_class('admin','admin',0);   
  5. pc_base::load_sys_class('push_factory''', 0);   
  6. //权限判断,根据栏目里面的权限设置检查       
  7. if((isset($_GET['catid']) || isset($_POST['catid'])) && $_SESSION['roleid'] != 1) {   
  8.     $catid = isset($_GET['catid']) ? intval($_GET['catid']) : intval($_POST['catid']);   
  9.     $this->priv_db = pc_base::load_model('category_priv_model');   
  10.     $priv_datas = $this->priv_db->get_one(array('catid'=>$catid,'is_admin'=>1,'action'=>'push'));   
  11.     if(!$priv_datas['catid']) showmessage(L('permission_to_operate'),'blank');   
  12. }   
  13.    
  14. class push extends admin {   
  15.        
  16.     public function __construct() {   
  17.         parent::__construct();   
  18.         $this->siteid = $this->get_siteid();   
  19.         /*  
  20.          * $_GET['module']值分析:  
  21.          * 1.推送到推荐位:不传递moduls参数  
  22.          * 2.推送到专题:special  
  23.          * 3.推送到其它栏目:content  
  24.          */   
  25.         $module = (isset($_GET['module']) && !emptyempty($_GET['module'])) ? $_GET['module'] : 'admin';   
  26.         if (in_array($modulearray('admin''special','content'))) {   
  27.             /*根据$module值定位到对应的推送接口文件  
  28.              * 1.推送至推荐位:调用modules/admin/classes/push_api.class.php接口文件  
  29.              * 2.推荐至专题:调用modules/special/classes/push_api.class.php接口文件  
  30.              * 3.推荐至其它栏目:调用modules/content/classes/push_api.class.php接口文件   
  31.              */   
  32.             $this->push = push_factory::get_instance()->get_api($module);   
  33.         } else {   
  34.             showmessage(L('not_exists_push'), 'blank');   
  35.         }   
  36.     }   
  37.        
  38.     /**  
  39.      * 推送选择界面  
  40.      */   
  41.     public function init() {   
  42.         if ($_POST['dosubmit']) {   
  43.             $c = pc_base::load_model('content_model');//实例化一个content_model对象   
  44.             $c->set_model($_POST['modelid']);//模型id   
  45.             $info = array();//被推送的文章内容数组   
  46.             $ids = explode('|'$_POST['id']);//要推送的文章id,如:39|38|37  
  47.    
  48.             if(is_array($ids)) {   
  49.                 foreach($ids as $id) {   
  50.                     $info[$id] = $c->get_content($_POST['catid'], $id);//根据栏目id及文章id获取文章内容   
  51.                 }   
  52.             }   
  53.             //position_list:推荐到推荐位       _push_special:推荐到专题     category_list:推荐到其它栏目             
  54.             $_GET['add_action'] = $_GET['add_action'] ? $_GET['add_action'] : $_GET['action'];   
  55.             $this->push->$_GET['add_action']($info$_POST);//将文章推送到其它地方   
  56.             showmessage(L('success'), '''''push');   
  57.         } else {   
  58.             pc_base::load_app_func('global''template');   
  59.             /*  
  60.              * $this->push分析:推送接口文件  
  61.              * 1.推送至推荐位:调用modules/admin/classes/push_api.class.php接口文件  
  62.              * 2.推荐至专题:调用modules/special/classes/push_api.class.php接口文件  
  63.              * 3.推荐至其它栏目:调用modules/content/classes/push_api.class.php接口文件  
  64.              */   
  65.             if (method_exists($this->push, $_GET['action'])) {   
  66.                 $html = $this->push->{$_GET['action']}(array('modelid'=>$_GET['modelid'], 'catid'=>$_GET['catid']));   
  67.                 $tpl = isset($_GET['tpl']) ? 'push_to_category' : 'push_list';   
  68.                 include $this->admin_tpl($tpl);   
  69.             } else {  //开源代码phpfensi.com 
  70.                 showmessage('CLASS METHOD NO EXISTS!''blank');   
  71.             }   
  72.         }   
  73.     }   
  74.        
  75.     public function public_ajax_get() {   
  76.         if (method_exists($this->push, $_GET['action'])) {   
  77.             $html = $this->push->{$_GET['action']}($_GET['html']);   
  78.             echo $html;   
  79.         } else {   
  80.             echo 'CLASS METHOD NO EXISTS!';   
  81.         }   
  82.     }   
  83. }   
  84. ?> 

5.modules/content/classes/push_api.class.php文件分析:

  1. <?php   
  2. /**  
  3.  *  position_api.class.php 推荐至栏目接口类  
  4.  *  
  5.  * @copyright           (C) 2005-2010 PHPCMS  
  6.  * @license             http://www.phpcms.cn/license/  
  7.  * @lastmodify          2010-10-14  
  8.  */   
  9.    
  10. defined('IN_PHPCMS'or exit('No permission resources.');   
  11.    
  12. class push_api {   
  13.     private $db$pos_data//数据调用属性   
  14.        
  15.     public function __construct() {   
  16.         $this->db = pc_base::load_model('content_model');  //加载数据模型   
  17.     }   
  18.        
  19.     /**  
  20.      * 接口处理方法,参数1:要推送的文章数组        参数2:旧的模型id及旧的栏目id  
  21.      * @param array $param 属性 请求时,为模型、栏目数组。提交添加为二维信息数据 。例:array(1=>array('title'=>'多发发送方法', ....))  
  22.      * @param array $arr 参数 表单数据,只在请求添加时传递。 例:array('modelid'=>1, 'catid'=>12);   
  23.      */   
  24.     public function category_list($param = array(), $arr = array()) {   
  25.         //确认推送按钮   
  26.         if ($arr['dosubmit']) {   
  27.             $id = $_POST['id'];//要批量推送的文章id,如:39|38|37   
  28.             if(emptyempty($id)) return true;   
  29.             $id_arr = explode('|',$id);//要批量推送的文章id数组   
  30.             if(count($id_arr)==0) return true;   
  31.             $old_catid = intval($_POST['catid']);//旧栏目id   
  32.             if(!$old_catidreturn true;   
  33.             $ids = $_POST['ids'];//推送栏目,如:6|68   
  34.             if(emptyempty($ids)) return true;   
  35.             $ids = explode('|'$ids);//推送栏目id数组   
  36.             $siteid = intval($_POST['siteid']);//站点id   
  37.             $siteids = getcache('category_content','commons');//所有栏目对应的站点id   
  38.             $oldsiteid = $siteids[$old_catid];//旧站点id   
  39.             $this->categorys = getcache('category_content_'.$oldsiteid,'commons');//旧站点下所有栏目信息   
  40.    
  41.             $modelid = $this->categorys[$old_catid]['modelid'];//旧栏目所属的模型id   
  42.             $this->db->set_model($modelid);//根据模型id设置对应的模型表   
  43.             $tablename = $this->db->table_name;   
  44.             $this->hits_db = pc_base::load_model('hits_model');//点击率统计表   
  45.             foreach($id_arr as $id) {//要批量推送的文章id数组   
  46.                 $this->db->table_name = $tablename;//模型表   
  47.                 $r = $this->db->get_one(array('id'=>$id));//根据当前文章id获取该文章详细信息   
  48.                 $linkurl = preg_match('/^http:\/\//',$r['url']) ? $r['url'] : siteurl($siteid).$r['url'];   
  49.                 foreach($ids as $catid) {//推送栏目,如:6|68   
  50.                     $siteid = $siteids[$catid];//推送到哪个站点id下的栏目   
  51.                     $this->categorys = getcache('category_content_'.$siteid,'commons');//推送站点下所有的栏目信息   
  52.                     $modelid = $this->categorys[$catid]['modelid'];//推送栏目所属模型id   
  53.                     $this->db->set_model($modelid);//根据模型id设置对应的模型表   
  54.                         $newid = $this->db->insert(   
  55.                         array('title'=>$r['title'],//标题   
  56.                             'style'=>$r['style'],   
  57.                             'thumb'=>$r['thumb'],//缩略图   
  58.                             'keywords'=>$r['keywords'],//关键词   
  59.                             'description'=>$r['description'],//描述   
  60.                             'status'=>$r['status'],//状态   
  61.                             'catid'=>$catid,//栏目id   
  62.                             'url'=>$linkurl,//旧的链接地址   
  63.                             'sysadd'=>1,//系统添加   
  64.                             'username'=>$r['username'],//作者   
  65.                             'inputtime'=>$r['inputtime'],//发布时间   
  66.                             'updatetime'=>$r['updatetime'],//更新时间   
  67.                             'islink'=>1 //外部链接   
  68.                         ),true);//将文章内容发布到推送栏目,并返回新插入的文章id   
  69.                         $this->db->table_name = $this->db->table_name.'_data';//模型附表   
  70.                         $this->db->insert(array('id'=>$newid));//新插入的文章id存储到附表中,注意:文章内容没有被存储到附表中   
  71.                         $hitsid = 'c-'.$modelid.'-'.$newid;   
  72.                         $this->hits_db->insert(array('hitsid'=>$hitsid,'catid'=>$catid,'updatetime'=>SYS_TIME));//点击量统计表   
  73.                 }   
  74.             }   
  75.             return true;   
  76.         } else {   
  77.             $siteid = get_siteid();   
  78.             $this->categorys = getcache('category_content_'.$siteid,'commons');   
  79.             $tree = pc_base::load_sys_class('tree');   
  80.             $tree->icon = array('   │ ','   ├─ ','   └─ ');   
  81.             $tree->nbsp = '   ';   
  82.             $categorys = array();   
  83.             $this->catids_string = array();   
  84.             if($_SESSION['roleid'] != 1) {   
  85.                 $this->priv_db = pc_base::load_model('category_priv_model');   
  86.                 $priv_result = $this->priv_db->select(array('action'=>'add','roleid'=>$_SESSION['roleid'],'siteid'=>$siteid,'is_admin'=>1));   
  87.                 $priv_catids = array();   
  88.                 foreach($priv_result as $_v) {   
  89.                     $priv_catids[] = $_v['catid'];   
  90.                 }   
  91.                 if(emptyempty($priv_catids)) return '';   
  92.             }   
  93.    
  94.             foreach($this->categorys as $r) {   
  95.                 if($r['siteid']!=$siteid || $r['type']!=0) continue;   
  96.                 if($_SESSION['roleid'] != 1 && !in_array($r['catid'],$priv_catids)) {   
  97.                     $arrchildid = explode(',',$r['arrchildid']);   
  98.                     $array_intersect = array_intersect($priv_catids,$arrchildid);   
  99.                     if(emptyempty($array_intersect)) continue;   
  100.                 }   
  101.                 if($r['child']) {   
  102.                     $r['checkbox'] = '';   
  103.                     $r['style'] = 'color:#8A8A8A;';   
  104.                 } else {   
  105.                     $checked = '';   
  106.                     if($typeid && $r['usable_type']) {   
  107.                         $usable_type = explode(','$r['usable_type']);   
  108.                         if(in_array($typeid$usable_type)) {   
  109.                             $checked = 'checked';   
  110.                             $this->catids_string[] = $r['catid'];   
  111.                         }   
  112.                     }   
  113.                     $r['checkbox'] = "<input type='checkbox' name='ids[]' value='{$r[catid]}' {$checked}>";   
  114.                     $r['style'] = '';   
  115.                 }   
  116.                 $categorys[$r['catid']] = $r;   
  117.             }   
  118.             $str  = "<tr>   
  119.                         <td align='center'>\$checkbox</td>   
  120.                         <td style='\$style'>\$spacer\$catname</td>   
  121.                     </tr>";   
  122.             $tree->init($categorys);   
  123.             $categorys = $tree->get_tree(0, $str);   
  124.             return $categorys;   
  125.         }   
  126.  }   
  127. }   
  128.  ?> 

例如:文章被推送到专题的情况:

Tags: phpcms文章推送 phpcms批量推送

分享到: