【phpcms-v9】phpcms-v9中將一個站點下的文章內容完美的推送到另一個站點下.
注意事項:
1.要將當前站點下的文章內容推送到另一個站點下,即:content字段的值,默認情況下此content的內容沒有推送到另一個站點下的附表中.
2.將當前站點下的文章內容推送到另一個站點下的主表時,將islink字段的值設置為0,代表不是尾部鏈接.
3.content字段的值在附表中,所有要查詢附表,默認情況下只查詢了主表.
完整代碼如下:
- <?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獲取該文章詳細信息
- //weiyanhui添加
- //附屬表
- $this->db->table_name = $this->db->table_name.'_data';
- $r2 = $this->db->get_one(array('id'=>$id));//內容字段在附表中
- if($r2) {
- $r = array_merge($r,$r2);
- } else {
- $r = $r;
- }
- //weiyanhui添加結束
- $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 //默認值為1:外部鏈接
- 'islink'=>0 //weiyanhui添加
- ),true);//將文章內容發布到推送欄目,并返回新插入的文章id
- $this->db->table_name = $this->db->table_name.'_data';//模型附表
- //將文章內容推送到其它站點后,將islink字段值修改為0,然后再重新發布一下,即可生成文章靜態頁到當前站點當前欄目下
- //思考:1-可以在附表入庫前將islink字段值設置為0 2-將內容入庫附表
- //$this->db->insert(array('id'=>$newid));//新插入的文章id存儲到附表中,注意:文章內容沒有被存儲到附表中
- $this->db->insert(array('id'=>$newid,'content'=>$r['content']));//weiyanhui添加
- $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;
- } //開源代碼Vevb.com
- $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;
- }
- }
- }
- ?>
新聞熱點
疑難解答