【phpcms-v9】phpcms-v9中将选中的批量文章推送到推荐位、推送
发布:smiling 来源: PHP粉丝网 添加日期:2014-10-24 11:16:02 浏览: 评论:0
【phpcms-v9】phpcms-v9中将选中的批量文章推送到推荐位、推送到专题及推送到其他栏目的功能.
1.推送按钮:
2.推送弹出框:
3.push()函数:
- function push() {
- var str = 0;
- var id = tag = '';
- $("input[name='ids[]']").each(function() {
- if($(this).attr('checked')=='checked') {
- str = 1;
- id += tag+$(this).val();
- tag = '|';
- }
- });
- if(str==0) {
- alert('<?php echo L('you_do_not_check');?>');
- return false;
- }
- window.top.art.dialog({id:'push'}).close();
- 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对象
- var form = d.document.getElementById('dosubmit');form.click();return false;}, function(){window.top.art.dialog({id:'push'}).close()});
- }
4.modules/content/push.php推送控制器文件:
- <?php
- defined('IN_PHPCMS') or exit('No permission resources.');
- pc_base::load_app_class('admin','admin',0);
- pc_base::load_sys_class('push_factory', '', 0);
- //权限判断,根据栏目里面的权限设置检查
- if((isset($_GET['catid']) || isset($_POST['catid'])) && $_SESSION['roleid'] != 1) {
- $catid = isset($_GET['catid']) ? intval($_GET['catid']) : intval($_POST['catid']);
- $this->priv_db = pc_base::load_model('category_priv_model');
- $priv_datas = $this->priv_db->get_one(array('catid'=>$catid,'is_admin'=>1,'action'=>'push'));
- if(!$priv_datas['catid']) showmessage(L('permission_to_operate'),'blank');
- }
- class push extends admin {
- public function __construct() {
- parent::__construct();
- $this->siteid = $this->get_siteid();
- /*
- * $_GET['module']值分析:
- * 1.推送到推荐位:不传递moduls参数
- * 2.推送到专题:special
- * 3.推送到其它栏目:content
- */
- $module = (isset($_GET['module']) && !emptyempty($_GET['module'])) ? $_GET['module'] : 'admin';
- if (in_array($module, array('admin', 'special','content'))) {
- /*根据$module值定位到对应的推送接口文件
- * 1.推送至推荐位:调用modules/admin/classes/push_api.class.php接口文件
- * 2.推荐至专题:调用modules/special/classes/push_api.class.php接口文件
- * 3.推荐至其它栏目:调用modules/content/classes/push_api.class.php接口文件
- */
- $this->push = push_factory::get_instance()->get_api($module);
- } else {
- showmessage(L('not_exists_push'), 'blank');
- }
- }
- /**
- * 推送选择界面
- */
- public function init() {
- if ($_POST['dosubmit']) {
- $c = pc_base::load_model('content_model');//实例化一个content_model对象
- $c->set_model($_POST['modelid']);//模型id
- $info = array();//被推送的文章内容数组
- $ids = explode('|', $_POST['id']);//要推送的文章id,如:39|38|37
- if(is_array($ids)) {
- foreach($ids as $id) {
- $info[$id] = $c->get_content($_POST['catid'], $id);//根据栏目id及文章id获取文章内容
- }
- }
- //position_list:推荐到推荐位 _push_special:推荐到专题 category_list:推荐到其它栏目
- $_GET['add_action'] = $_GET['add_action'] ? $_GET['add_action'] : $_GET['action'];
- $this->push->$_GET['add_action']($info, $_POST);//将文章推送到其它地方
- showmessage(L('success'), '', '', 'push');
- } else {
- pc_base::load_app_func('global', 'template');
- /*
- * $this->push分析:推送接口文件
- * 1.推送至推荐位:调用modules/admin/classes/push_api.class.php接口文件
- * 2.推荐至专题:调用modules/special/classes/push_api.class.php接口文件
- * 3.推荐至其它栏目:调用modules/content/classes/push_api.class.php接口文件
- */
- if (method_exists($this->push, $_GET['action'])) {
- $html = $this->push->{$_GET['action']}(array('modelid'=>$_GET['modelid'], 'catid'=>$_GET['catid']));
- $tpl = isset($_GET['tpl']) ? 'push_to_category' : 'push_list';
- include $this->admin_tpl($tpl);
- } else { //开源代码phpfensi.com
- showmessage('CLASS METHOD NO EXISTS!', 'blank');
- }
- }
- }
- public function public_ajax_get() {
- if (method_exists($this->push, $_GET['action'])) {
- $html = $this->push->{$_GET['action']}($_GET['html']);
- echo $html;
- } else {
- echo 'CLASS METHOD NO EXISTS!';
- }
- }
- }
- ?>
5.modules/content/classes/push_api.class.php文件分析:
- <?php
- /**
- * position_api.class.php 推荐至栏目接口类
- *
- * @copyright (C) 2005-2010 PHPCMS
- * @license http://www.phpcms.cn/license/
- * @lastmodify 2010-10-14
- */
- defined('IN_PHPCMS') or exit('No permission resources.');
- class push_api {
- private $db, $pos_data; //数据调用属性
- public function __construct() {
- $this->db = pc_base::load_model('content_model'); //加载数据模型
- }
- /**
- * 接口处理方法,参数1:要推送的文章数组 参数2:旧的模型id及旧的栏目id
- * @param array $param 属性 请求时,为模型、栏目数组。提交添加为二维信息数据 。例:array(1=>array('title'=>'多发发送方法', ....))
- * @param array $arr 参数 表单数据,只在请求添加时传递。 例:array('modelid'=>1, 'catid'=>12);
- */
- public function category_list($param = array(), $arr = array()) {
- //确认推送按钮
- if ($arr['dosubmit']) {
- $id = $_POST['id'];//要批量推送的文章id,如:39|38|37
- if(emptyempty($id)) return true;
- $id_arr = explode('|',$id);//要批量推送的文章id数组
- if(count($id_arr)==0) return true;
- $old_catid = intval($_POST['catid']);//旧栏目id
- if(!$old_catid) return true;
- $ids = $_POST['ids'];//推送栏目,如:6|68
- if(emptyempty($ids)) return true;
- $ids = explode('|', $ids);//推送栏目id数组
- $siteid = intval($_POST['siteid']);//站点id
- $siteids = getcache('category_content','commons');//所有栏目对应的站点id
- $oldsiteid = $siteids[$old_catid];//旧站点id
- $this->categorys = getcache('category_content_'.$oldsiteid,'commons');//旧站点下所有栏目信息
- $modelid = $this->categorys[$old_catid]['modelid'];//旧栏目所属的模型id
- $this->db->set_model($modelid);//根据模型id设置对应的模型表
- $tablename = $this->db->table_name;
- $this->hits_db = pc_base::load_model('hits_model');//点击率统计表
- foreach($id_arr as $id) {//要批量推送的文章id数组
- $this->db->table_name = $tablename;//模型表
- $r = $this->db->get_one(array('id'=>$id));//根据当前文章id获取该文章详细信息
- $linkurl = preg_match('/^http:\/\//',$r['url']) ? $r['url'] : siteurl($siteid).$r['url'];
- foreach($ids as $catid) {//推送栏目,如:6|68
- $siteid = $siteids[$catid];//推送到哪个站点id下的栏目
- $this->categorys = getcache('category_content_'.$siteid,'commons');//推送站点下所有的栏目信息
- $modelid = $this->categorys[$catid]['modelid'];//推送栏目所属模型id
- $this->db->set_model($modelid);//根据模型id设置对应的模型表
- $newid = $this->db->insert(
- array('title'=>$r['title'],//标题
- 'style'=>$r['style'],
- 'thumb'=>$r['thumb'],//缩略图
- 'keywords'=>$r['keywords'],//关键词
- 'description'=>$r['description'],//描述
- 'status'=>$r['status'],//状态
- 'catid'=>$catid,//栏目id
- 'url'=>$linkurl,//旧的链接地址
- 'sysadd'=>1,//系统添加
- 'username'=>$r['username'],//作者
- 'inputtime'=>$r['inputtime'],//发布时间
- 'updatetime'=>$r['updatetime'],//更新时间
- 'islink'=>1 //外部链接
- ),true);//将文章内容发布到推送栏目,并返回新插入的文章id
- $this->db->table_name = $this->db->table_name.'_data';//模型附表
- $this->db->insert(array('id'=>$newid));//新插入的文章id存储到附表中,注意:文章内容没有被存储到附表中
- $hitsid = 'c-'.$modelid.'-'.$newid;
- $this->hits_db->insert(array('hitsid'=>$hitsid,'catid'=>$catid,'updatetime'=>SYS_TIME));//点击量统计表
- }
- }
- return true;
- } else {
- $siteid = get_siteid();
- $this->categorys = getcache('category_content_'.$siteid,'commons');
- $tree = pc_base::load_sys_class('tree');
- $tree->icon = array(' │ ',' ├─ ',' └─ ');
- $tree->nbsp = ' ';
- $categorys = array();
- $this->catids_string = array();
- if($_SESSION['roleid'] != 1) {
- $this->priv_db = pc_base::load_model('category_priv_model');
- $priv_result = $this->priv_db->select(array('action'=>'add','roleid'=>$_SESSION['roleid'],'siteid'=>$siteid,'is_admin'=>1));
- $priv_catids = array();
- foreach($priv_result as $_v) {
- $priv_catids[] = $_v['catid'];
- }
- if(emptyempty($priv_catids)) return '';
- }
- foreach($this->categorys as $r) {
- if($r['siteid']!=$siteid || $r['type']!=0) continue;
- if($_SESSION['roleid'] != 1 && !in_array($r['catid'],$priv_catids)) {
- $arrchildid = explode(',',$r['arrchildid']);
- $array_intersect = array_intersect($priv_catids,$arrchildid);
- if(emptyempty($array_intersect)) continue;
- }
- if($r['child']) {
- $r['checkbox'] = '';
- $r['style'] = 'color:#8A8A8A;';
- } else {
- $checked = '';
- if($typeid && $r['usable_type']) {
- $usable_type = explode(',', $r['usable_type']);
- if(in_array($typeid, $usable_type)) {
- $checked = 'checked';
- $this->catids_string[] = $r['catid'];
- }
- }
- $r['checkbox'] = "<input type='checkbox' name='ids[]' value='{$r[catid]}' {$checked}>";
- $r['style'] = '';
- }
- $categorys[$r['catid']] = $r;
- }
- $str = "<tr>
- <td align='center'>\$checkbox</td>
- <td style='\$style'>\$spacer\$catname</td>
- </tr>";
- $tree->init($categorys);
- $categorys = $tree->get_tree(0, $str);
- return $categorys;
- }
- }
- }
- ?>
例如:文章被推送到专题的情况:
Tags: phpcms文章推送 phpcms批量推送
推荐文章
热门文章
最新评论文章
- 写给考虑创业的年轻程序员(10)
- PHP新手上路(一)(7)
- 惹恼程序员的十件事(5)
- PHP邮件发送例子,已测试成功(5)
- 致初学者:PHP比ASP优秀的七个理由(4)
- PHP会被淘汰吗?(4)
- PHP新手上路(四)(4)
- 如何去学习PHP?(2)
- 简单入门级php分页代码(2)
- php中邮箱email 电话等格式的验证(2)