push_api.class.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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. defined('IN_PHPCMS') or exit('No permission resources.');
  10. class push_api {
  11. private $db, $pos_data; //数据调用属性
  12. public function __construct() {
  13. $this->db = pc_base::load_model('content_model'); //加载数据模型
  14. }
  15. /**
  16. * 接口处理方法
  17. * @param array $param 属性 请求时,为模型、栏目数组。提交添加为二维信息数据 。例:array(1=>array('title'=>'多发发送方法', ....))
  18. * @param array $arr 参数 表单数据,只在请求添加时传递。 例:array('modelid'=>1, 'catid'=>12);
  19. */
  20. public function category_list($param = array(), $arr = array()) {
  21. if ($arr['dosubmit']) {
  22. $id = $_POST['id'];
  23. if(empty($id)) return true;
  24. $id_arr = explode('|',$id);
  25. if(count($id_arr)==0) return true;
  26. $old_catid = intval($_POST['catid']);
  27. if(!$old_catid) return true;
  28. $ids = $_POST['ids'];
  29. if(empty($ids)) return true;
  30. $ids = explode('|', $ids);
  31. $siteid = intval($_POST['siteid']);
  32. $siteids = getcache('category_content','commons');
  33. $oldsiteid = $siteids[$old_catid];
  34. $this->categorys = getcache('category_content_'.$oldsiteid,'commons');
  35. $modelid = $this->categorys[$old_catid]['modelid'];
  36. $this->db->set_model($modelid);
  37. $tablename = $this->db->table_name;
  38. $this->hits_db = pc_base::load_model('hits_model');
  39. foreach($id_arr as $id) {
  40. $this->db->table_name = $tablename;
  41. $r = $this->db->get_one(array('id'=>$id));
  42. $linkurl = preg_match('/^http:\/\//',$r['url']) ? $r['url'] : siteurl($siteid).$r['url'];
  43. foreach($ids as $catid) {
  44. $siteid = $siteids[$catid];
  45. $this->categorys = getcache('category_content_'.$siteid,'commons');
  46. $modelid = $this->categorys[$catid]['modelid'];
  47. $this->db->set_model($modelid);
  48. $newid = $this->db->insert(
  49. array('title'=>$r['title'],
  50. 'style'=>$r['style'],
  51. 'thumb'=>$r['thumb'],
  52. 'keywords'=>$r['keywords'],
  53. 'description'=>$r['description'],
  54. 'status'=>$r['status'],
  55. 'catid'=>$catid,
  56. 'url'=>$linkurl,
  57. 'sysadd'=>1,
  58. 'username'=>$r['username'],
  59. 'inputtime'=>$r['inputtime'],
  60. 'updatetime'=>$r['updatetime'],
  61. 'islink'=>1
  62. ),true);
  63. $this->db->table_name = $this->db->table_name.'_data';
  64. $this->db->insert(array('id'=>$newid));
  65. $hitsid = 'c-'.$modelid.'-'.$newid;
  66. $this->hits_db->insert(array('hitsid'=>$hitsid,'catid'=>$catid,'updatetime'=>SYS_TIME));
  67. }
  68. }
  69. return true;
  70. } else {
  71. $siteid = get_siteid();
  72. $this->categorys = getcache('category_content_'.$siteid,'commons');
  73. $tree = pc_base::load_sys_class('tree');
  74. $tree->icon = array('&nbsp;&nbsp;&nbsp;│ ','&nbsp;&nbsp;&nbsp;├─ ','&nbsp;&nbsp;&nbsp;└─ ');
  75. $tree->nbsp = '&nbsp;&nbsp;&nbsp;';
  76. $categorys = array();
  77. $this->catids_string = array();
  78. if($_SESSION['roleid'] != 1) {
  79. $this->priv_db = pc_base::load_model('category_priv_model');
  80. $priv_result = $this->priv_db->select(array('action'=>'add','roleid'=>$_SESSION['roleid'],'siteid'=>$siteid,'is_admin'=>1));
  81. $priv_catids = array();
  82. foreach($priv_result as $_v) {
  83. $priv_catids[] = $_v['catid'];
  84. }
  85. if(empty($priv_catids)) return '';
  86. }
  87. foreach($this->categorys as $r) {
  88. if($r['siteid']!=$siteid || $r['type']!=0) continue;
  89. if($_SESSION['roleid'] != 1 && !in_array($r['catid'],$priv_catids)) {
  90. $arrchildid = explode(',',$r['arrchildid']);
  91. $array_intersect = array_intersect($priv_catids,$arrchildid);
  92. if(empty($array_intersect)) continue;
  93. }
  94. if($r['child']) {
  95. $r['checkbox'] = '';
  96. $r['style'] = 'color:#8A8A8A;';
  97. } else {
  98. $checked = '';
  99. if($typeid && $r['usable_type']) {
  100. $usable_type = explode(',', $r['usable_type']);
  101. if(in_array($typeid, $usable_type)) {
  102. $checked = 'checked';
  103. $this->catids_string[] = $r['catid'];
  104. }
  105. }
  106. $r['checkbox'] = "<input type='checkbox' name='ids[]' value='{$r[catid]}' {$checked}>";
  107. $r['style'] = '';
  108. }
  109. $categorys[$r['catid']] = $r;
  110. }
  111. $str = "<tr>
  112. <td align='center'>\$checkbox</td>
  113. <td style='\$style'>\$spacer\$catname</td>
  114. </tr>";
  115. $tree->init($categorys);
  116. $categorys = $tree->get_tree(0, $str);
  117. return $categorys;
  118. }
  119. }
  120. }
  121. ?>