PageRenderTime 52ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/phpcms/modules/content/content.php

https://github.com/sinfey69/cms
PHP | 1136 lines | 967 code | 50 blank | 119 comment | 251 complexity | 595c8c1691fc1bc258c763ca36828ae5 MD5 | raw file
  1. <?php
  2. set_time_limit(300);
  3. defined('IN_PHPCMS') or exit('No permission resources.');
  4. //模型缓存路径
  5. define('CACHE_MODEL_PATH',CACHE_PATH.'caches_model'.DIRECTORY_SEPARATOR.'caches_data'.DIRECTORY_SEPARATOR);
  6. //定义在单独操作内容的时候,同时更新相关栏目页面
  7. define('RELATION_HTML',true);
  8. pc_base::load_app_class('admin','admin',0);
  9. pc_base::load_sys_class('form','',0);
  10. pc_base::load_app_func('util');
  11. pc_base::load_sys_class('format','',0);
  12. class content extends admin {
  13. private $db,$priv_db;
  14. public $siteid,$categorys;
  15. public function __construct() {
  16. parent::__construct();
  17. $this->db = pc_base::load_model('content_model');
  18. $this->siteid = $this->get_siteid();
  19. $this->categorys = getcache('category_content_'.$this->siteid,'commons');
  20. //权限判断
  21. if(isset($_GET['catid']) && $_SESSION['roleid'] != 1 && ROUTE_A !='pass' && strpos(ROUTE_A,'public_')===false) {
  22. $catid = intval($_GET['catid']);
  23. $this->priv_db = pc_base::load_model('category_priv_model');
  24. $action = $this->categorys[$catid]['type']==0 ? ROUTE_A : 'init';
  25. $priv_datas = $this->priv_db->get_one(array('catid'=>$catid,'is_admin'=>1,'action'=>$action));
  26. if(!$priv_datas) showmessage(L('permission_to_operate'),'blank');
  27. }
  28. }
  29. public function init() {
  30. $show_header = $show_dialog = $show_pc_hash = '';
  31. if(isset($_GET['catid']) && $_GET['catid'] && $this->categorys[$_GET['catid']]['siteid']==$this->siteid) {
  32. $catid = $_GET['catid'] = intval($_GET['catid']);
  33. $category = $this->categorys[$catid];
  34. $modelid = $category['modelid'];
  35. $model_arr = getcache('model', 'commons');
  36. $MODEL = $model_arr[$modelid];
  37. unset($model_arr);
  38. $admin_username = param::get_cookie('admin_username');
  39. //查询当前的工作流
  40. $setting = string2array($category['setting']);
  41. $workflowid = $setting['workflowid'];
  42. $workflows = getcache('workflow_'.$this->siteid,'commons');
  43. $workflows = $workflows[$workflowid];
  44. $workflows_setting = string2array($workflows['setting']);
  45. //将有权限的级别放到新数组中
  46. $admin_privs = array();
  47. foreach($workflows_setting as $_k=>$_v) {
  48. if(empty($_v)) continue;
  49. foreach($_v as $_value) {
  50. if($_value==$admin_username) $admin_privs[$_k] = $_k;
  51. }
  52. }
  53. //工作流审核级别
  54. $workflow_steps = $workflows['steps'];
  55. $workflow_menu = '';
  56. $steps = isset($_GET['steps']) ? intval($_GET['steps']) : 0;
  57. //工作流权限判断
  58. if($_SESSION['roleid']!=1 && $steps && !in_array($steps,$admin_privs)) showmessage(L('permission_to_operate'));
  59. $this->db->set_model($modelid);
  60. if($this->db->table_name==$this->db->db_tablepre) showmessage(L('model_table_not_exists'));;
  61. $status = $steps ? $steps : 99;
  62. if(isset($_GET['reject'])) $status = 0;
  63. $where = 'catid='.$catid.' AND status='.$status;
  64. //搜索
  65. if(isset($_GET['start_time']) && $_GET['start_time']) {
  66. $start_time = strtotime($_GET['start_time']);
  67. $where .= " AND `inputtime` > '$start_time'";
  68. }
  69. if(isset($_GET['end_time']) && $_GET['end_time']) {
  70. $end_time = strtotime($_GET['end_time']);
  71. $where .= " AND `inputtime` < '$end_time'";
  72. }
  73. if($start_time>$end_time) showmessage(L('starttime_than_endtime'));
  74. if(isset($_GET['keyword']) && !empty($_GET['keyword'])) {
  75. $type_array = array('title','description','username');
  76. $searchtype = intval($_GET['searchtype']);
  77. if($searchtype < 3) {
  78. $searchtype = $type_array[$searchtype];
  79. $keyword = strip_tags(trim($_GET['keyword']));
  80. $where .= " AND `$searchtype` like '%$keyword%'";
  81. } elseif($searchtype==3) {
  82. $keyword = intval($_GET['keyword']);
  83. $where .= " AND `id`='$keyword'";
  84. }
  85. }
  86. if(isset($_GET['posids']) && !empty($_GET['posids'])) {
  87. $posids = $_GET['posids']==1 ? intval($_GET['posids']) : 0;
  88. $where .= " AND `posids` = '$posids'";
  89. }
  90. $datas = $this->db->listinfo($where,'id desc',$_GET['page']);
  91. $pages = $this->db->pages;
  92. $pc_hash = $_SESSION['pc_hash'];
  93. for($i=1;$i<=$workflow_steps;$i++) {
  94. if($_SESSION['roleid']!=1 && !in_array($i,$admin_privs)) continue;
  95. $current = $steps==$i ? 'class=on' : '';
  96. $r = $this->db->get_one(array('catid'=>$catid,'status'=>$i));
  97. $newimg = $r ? '<img src="'.IMG_PATH.'icon/new.png" style="padding-bottom:2px" onclick="window.location.href=\'?m=content&c=content&a=&menuid='.$_GET['menuid'].'&catid='.$catid.'&steps='.$i.'&pc_hash='.$pc_hash.'\'">' : '';
  98. $workflow_menu .= '<a href="?m=content&c=content&a=&menuid='.$_GET['menuid'].'&catid='.$catid.'&steps='.$i.'&pc_hash='.$pc_hash.'" '.$current.' ><em>'.L('workflow_'.$i).$newimg.'</em></a><span>|</span>';
  99. }
  100. if($workflow_menu) {
  101. $current = isset($_GET['reject']) ? 'class=on' : '';
  102. $workflow_menu .= '<a href="?m=content&c=content&a=&menuid='.$_GET['menuid'].'&catid='.$catid.'&pc_hash='.$pc_hash.'&reject=1" '.$current.' ><em>'.L('reject').'</em></a><span>|</span>';
  103. }
  104. //$ = 153fc6d28dda8ca94eaa3686c8eed857;获取模型的thumb字段配置信息
  105. $model_fields = getcache('model_field_'.$modelid, 'model');
  106. $setting = string2array($model_fields['thumb']['setting']);
  107. $args = '1,'.$setting['upload_allowext'].','.$setting['isselectimage'].','.$setting['images_width'].','.$setting['images_height'].','.$setting['watermark'];
  108. $authkey = upload_key($args);
  109. $template = $MODEL['admin_list_template'] ? $MODEL['admin_list_template'] : 'content_list';
  110. include $this->admin_tpl($template);
  111. } else {
  112. include $this->admin_tpl('content_quick');
  113. }
  114. }
  115. public function add() {
  116. if(isset($_POST['dosubmit']) || isset($_POST['dosubmit_continue'])) {
  117. define('INDEX_HTML',true);
  118. $catid = $_POST['info']['catid'] = intval($_POST['info']['catid']);
  119. if(trim($_POST['info']['title'])=='') showmessage(L('title_is_empty'));
  120. $category = $this->categorys[$catid];
  121. if($category['type']==0) {
  122. $modelid = $this->categorys[$catid]['modelid'];
  123. $this->db->set_model($modelid);
  124. //如果该栏目设置了工作流,那么必须走工作流设定
  125. $setting = string2array($category['setting']);
  126. $workflowid = $setting['workflowid'];
  127. if($workflowid && $_POST['status']!=99) {
  128. //如果用户是超级管理员,那么则根据自己的设置来发布
  129. $_POST['info']['status'] = $_SESSION['roleid']==1 ? intval($_POST['status']) : 1;
  130. } else {
  131. $_POST['info']['status'] = 99;
  132. }
  133. $this->db->add_content($_POST['info']);
  134. if(isset($_POST['dosubmit'])) {
  135. showmessage(L('add_success').L('2s_close'),'blank','','','function set_time() {$("#secondid").html(1);}setTimeout("set_time()", 500);setTimeout("window.close()", 1200);');
  136. } else {
  137. showmessage(L('add_success'),HTTP_REFERER);
  138. }
  139. } else {
  140. //单网页
  141. $this->page_db = pc_base::load_model('page_model');
  142. $style_font_weight = $_POST['style_font_weight'] ? 'font-weight:'.strip_tags($_POST['style_font_weight']) : '';
  143. $_POST['info']['style'] = strip_tags($_POST['style_color']).';'.$style_font_weight;
  144. if($_POST['edit']) {
  145. $this->page_db->update($_POST['info'],array('catid'=>$catid));
  146. } else {
  147. $catid = $this->page_db->insert($_POST['info'],1);
  148. }
  149. $this->page_db->create_html($catid,$_POST['info']);
  150. $forward = HTTP_REFERER;
  151. }
  152. showmessage(L('add_success'),$forward);
  153. } else {
  154. $show_header = $show_dialog = $show_validator = '';
  155. //设置cookie 在附件添加处调用
  156. param::set_cookie('module', 'content');
  157. if(isset($_GET['catid']) && $_GET['catid']) {
  158. $catid = $_GET['catid'] = intval($_GET['catid']);
  159. param::set_cookie('catid', $catid);
  160. $category = $this->categorys[$catid];
  161. if($category['type']==0) {
  162. $modelid = $category['modelid'];
  163. //取模型ID,依模型ID来生成对应的表单
  164. require CACHE_MODEL_PATH.'content_form.class.php';
  165. $content_form = new content_form($modelid,$catid,$this->categorys);
  166. $forminfos = $content_form->get();
  167. $formValidator = $content_form->formValidator;
  168. $setting = string2array($category['setting']);
  169. $workflowid = $setting['workflowid'];
  170. $workflows = getcache('workflow_'.$this->siteid,'commons');
  171. $workflows = $workflows[$workflowid];
  172. $workflows_setting = string2array($workflows['setting']);
  173. $nocheck_users = $workflows_setting['nocheck_users'];
  174. $admin_username = param::get_cookie('admin_username');
  175. if(!empty($nocheck_users) && in_array($admin_username, $nocheck_users)) {
  176. $priv_status = true;
  177. } else {
  178. $priv_status = false;
  179. }
  180. include $this->admin_tpl('content_add');
  181. } else {
  182. //单网页
  183. $this->page_db = pc_base::load_model('page_model');
  184. $r = $this->page_db->get_one(array('catid'=>$catid));
  185. if($r) {
  186. extract($r);
  187. $style_arr = explode(';',$style);
  188. $style_color = $style_arr[0];
  189. $style_font_weight = $style_arr[1] ? substr($style_arr[1],12) : '';
  190. }
  191. include $this->admin_tpl('content_page');
  192. }
  193. } else {
  194. include $this->admin_tpl('content_add');
  195. }
  196. header("Cache-control: private");
  197. }
  198. }
  199. public function edit() {
  200. //设置cookie 在附件添加处调用
  201. param::set_cookie('module', 'content');
  202. if(isset($_POST['dosubmit']) || isset($_POST['dosubmit_continue'])) {
  203. define('INDEX_HTML',true);
  204. $id = $_POST['info']['id'] = intval($_POST['id']);
  205. $catid = $_POST['info']['catid'] = intval($_POST['info']['catid']);
  206. if(trim($_POST['info']['title'])=='') showmessage(L('title_is_empty'));
  207. $modelid = $this->categorys[$catid]['modelid'];
  208. $this->db->set_model($modelid);
  209. $this->db->edit_content($_POST['info'],$id);
  210. if(isset($_POST['dosubmit'])) {
  211. showmessage(L('update_success').L('2s_close'),'blank','','','function set_time() {$("#secondid").html(1);}setTimeout("set_time()", 500);setTimeout("window.close()", 1200);');
  212. } else {
  213. showmessage(L('update_success'),HTTP_REFERER);
  214. }
  215. } else {
  216. $show_header = $show_dialog = $show_validator = '';
  217. //从数据库获取内容
  218. $id = intval($_GET['id']);
  219. if(!isset($_GET['catid']) || !$_GET['catid']) showmessage(L('missing_part_parameters'));
  220. $catid = $_GET['catid'] = intval($_GET['catid']);
  221. $this->model = getcache('model', 'commons');
  222. param::set_cookie('catid', $catid);
  223. $category = $this->categorys[$catid];
  224. $modelid = $category['modelid'];
  225. $this->db->table_name = $this->db->db_tablepre.$this->model[$modelid]['tablename'];
  226. $r = $this->db->get_one(array('id'=>$id));
  227. $this->db->table_name = $this->db->table_name.'_data';
  228. $r2 = $this->db->get_one(array('id'=>$id));
  229. if(!$r2) showmessage(L('subsidiary_table_datalost'),'blank');
  230. $data = array_merge($r,$r2);
  231. $data = array_map('htmlspecialchars_decode',$data);
  232. require CACHE_MODEL_PATH.'content_form.class.php';
  233. $content_form = new content_form($modelid,$catid,$this->categorys);
  234. $forminfos = $content_form->get($data);
  235. $formValidator = $content_form->formValidator;
  236. include $this->admin_tpl('content_edit');
  237. }
  238. header("Cache-control: private");
  239. }
  240. /**
  241. * 删除
  242. */
  243. public function delete() {
  244. if(isset($_GET['dosubmit'])) {
  245. $catid = intval($_GET['catid']);
  246. if(!$catid) showmessage(L('missing_part_parameters'));
  247. $modelid = $this->categorys[$catid]['modelid'];
  248. $sethtml = $this->categorys[$catid]['sethtml'];
  249. $siteid = $this->categorys[$catid]['siteid'];
  250. $html_root = pc_base::load_config('system','html_root');
  251. if($sethtml) $html_root = '';
  252. $setting = string2array($this->categorys[$catid]['setting']);
  253. $content_ishtml = $setting['content_ishtml'];
  254. $this->db->set_model($modelid);
  255. $this->hits_db = pc_base::load_model('hits_model');
  256. $this->queue = pc_base::load_model('queue_model');
  257. if(isset($_GET['ajax_preview'])) {
  258. $ids = intval($_GET['id']);
  259. $_POST['ids'] = array(0=>$ids);
  260. }
  261. if(empty($_POST['ids'])) showmessage(L('you_do_not_check'));
  262. //附件初始化
  263. $attachment = pc_base::load_model('attachment_model');
  264. $this->content_check_db = pc_base::load_model('content_check_model');
  265. $this->position_data_db = pc_base::load_model('position_data_model');
  266. $this->search_db = pc_base::load_model('search_model');
  267. //判断视频模块是否安装
  268. if (module_exists('video') && file_exists(PC_PATH.'model'.DIRECTORY_SEPARATOR.'video_content_model.class.php')) {
  269. $video_content_db = pc_base::load_model('video_content_model');
  270. $video_install = 1;
  271. }
  272. $this->comment = pc_base::load_app_class('comment', 'comment');
  273. $search_model = getcache('search_model_'.$this->siteid,'search');
  274. $typeid = $search_model[$modelid]['typeid'];
  275. $this->url = pc_base::load_app_class('url', 'content');
  276. foreach($_POST['ids'] as $id) {
  277. $r = $this->db->get_one(array('id'=>$id));
  278. if($content_ishtml && !$r['islink']) {
  279. $urls = $this->url->show($id, 0, $r['catid'], $r['inputtime']);
  280. $fileurl = $urls[1];
  281. if($this->siteid != 1) {
  282. $sitelist = getcache('sitelist','commons');
  283. $fileurl = $html_root.'/'.$sitelist[$this->siteid]['dirname'].$fileurl;
  284. }
  285. //删除静态文件,排除htm/html/shtml外的文件
  286. $lasttext = strrchr($fileurl,'.');
  287. $len = -strlen($lasttext);
  288. $path = substr($fileurl,0,$len);
  289. $path = ltrim($path,'/');
  290. $filelist = glob(PHPCMS_PATH.$path.'*');
  291. foreach ($filelist as $delfile) {
  292. $lasttext = strrchr($delfile,'.');
  293. if(!in_array($lasttext, array('.htm','.html','.shtml'))) continue;
  294. @unlink($delfile);
  295. //删除发布点队列数据
  296. $delfile = str_replace(PHPCMS_PATH, '/', $delfile);
  297. $this->queue->add_queue('del',$delfile,$this->siteid);
  298. }
  299. } else {
  300. $fileurl = 0;
  301. }
  302. //删除内容
  303. $this->db->delete_content($id,$fileurl,$catid);
  304. //删除统计表数据
  305. $this->hits_db->delete(array('hitsid'=>'c-'.$modelid.'-'.$id));
  306. //删除附件
  307. $attachment->api_delete('c-'.$catid.'-'.$id);
  308. //删除审核表数据
  309. $this->content_check_db->delete(array('checkid'=>'c-'.$id.'-'.$modelid));
  310. //删除推荐位数据
  311. $this->position_data_db->delete(array('id'=>$id,'catid'=>$catid,'module'=>'content'));
  312. //删除全站搜索中数据
  313. $this->search_db->delete_search($typeid,$id);
  314. //删除视频库与内容对应关系数据
  315. if ($video_install ==1) {
  316. $video_content_db->delete(array('contentid'=>$id, 'modelid'=>$modelid));
  317. }
  318. //删除相关的评论,删除前应该判断是否还存在此模块
  319. if(module_exists('comment')){
  320. $commentid = id_encode('content_'.$catid, $id, $siteid);
  321. $this->comment->del($commentid, $siteid, $id, $catid);
  322. }
  323. }
  324. //更新栏目统计
  325. $this->db->cache_items();
  326. showmessage(L('operation_success'),HTTP_REFERER);
  327. } else {
  328. showmessage(L('operation_failure'));
  329. }
  330. }
  331. /**
  332. * 过审内容
  333. */
  334. public function pass() {
  335. $admin_username = param::get_cookie('admin_username');
  336. $catid = intval($_GET['catid']);
  337. if(!$catid) showmessage(L('missing_part_parameters'));
  338. $category = $this->categorys[$catid];
  339. $setting = string2array($category['setting']);
  340. $workflowid = $setting['workflowid'];
  341. //只有存在工作流才需要审核
  342. if($workflowid) {
  343. $steps = intval($_GET['steps']);
  344. //检查当前用户有没有当前工作流的操作权限
  345. $workflows = getcache('workflow_'.$this->siteid,'commons');
  346. $workflows = $workflows[$workflowid];
  347. $workflows_setting = string2array($workflows['setting']);
  348. //将有权限的级别放到新数组中
  349. $admin_privs = array();
  350. foreach($workflows_setting as $_k=>$_v) {
  351. if(empty($_v)) continue;
  352. foreach($_v as $_value) {
  353. if($_value==$admin_username) $admin_privs[$_k] = $_k;
  354. }
  355. }
  356. if($_SESSION['roleid']!=1 && $steps && !in_array($steps,$admin_privs)) showmessage(L('permission_to_operate'));
  357. //更改内容状态
  358. if(isset($_GET['reject'])) {
  359. //退稿
  360. $status = 0;
  361. } else {
  362. //工作流审核级别
  363. $workflow_steps = $workflows['steps'];
  364. if($workflow_steps>$steps) {
  365. $status = $steps+1;
  366. } else {
  367. $status = 99;
  368. }
  369. }
  370. $modelid = $this->categorys[$catid]['modelid'];
  371. $this->db->set_model($modelid);
  372. $this->db->search_db = pc_base::load_model('search_model');
  373. //审核通过,检查投稿奖励或扣除积分
  374. if ($status==99) {
  375. $html = pc_base::load_app_class('html', 'content');
  376. $this->url = pc_base::load_app_class('url', 'content');
  377. $member_db = pc_base::load_model('member_model');
  378. if (isset($_POST['ids']) && !empty($_POST['ids'])) {
  379. foreach ($_POST['ids'] as $id) {
  380. $content_info = $this->db->get_content($catid,$id);
  381. $memberinfo = $member_db->get_one(array('username'=>$content_info['username']), 'userid, username');
  382. $flag = $catid.'_'.$id;
  383. if($setting['presentpoint']>0) {
  384. pc_base::load_app_class('receipts','pay',0);
  385. receipts::point($setting['presentpoint'],$memberinfo['userid'], $memberinfo['username'], $flag,'selfincome',L('contribute_add_point'),$memberinfo['username']);
  386. } else {
  387. pc_base::load_app_class('spend','pay',0);
  388. spend::point($setting['presentpoint'], L('contribute_del_point'), $memberinfo['userid'], $memberinfo['username'], '', '', $flag);
  389. }
  390. if($setting['content_ishtml'] == '1'){//栏目有静态配置
  391. $urls = $this->url->show($id, 0, $content_info['catid'], $content_info['inputtime'], '',$content_info,'add');
  392. $html->show($urls[1],$urls['data'],0);
  393. }
  394. //更新到全站搜索
  395. $inputinfo = '';
  396. $inputinfo['system'] = $content_info;
  397. $this->db->search_api($id,$inputinfo);
  398. }
  399. } else if (isset($_GET['id']) && $_GET['id']) {
  400. $id = intval($_GET['id']);
  401. $content_info = $this->db->get_content($catid,$id);
  402. $memberinfo = $member_db->get_one(array('username'=>$content_info['username']), 'userid, username');
  403. $flag = $catid.'_'.$id;
  404. if($setting['presentpoint']>0) {
  405. pc_base::load_app_class('receipts','pay',0);
  406. receipts::point($setting['presentpoint'],$memberinfo['userid'], $memberinfo['username'], $flag,'selfincome',L('contribute_add_point'),$memberinfo['username']);
  407. } else {
  408. pc_base::load_app_class('spend','pay',0);
  409. spend::point($setting['presentpoint'], L('contribute_del_point'), $memberinfo['userid'], $memberinfo['username'], '', '', $flag);
  410. }
  411. //单篇审核,生成静态
  412. if($setting['content_ishtml'] == '1'){//栏目有静态配置
  413. $urls = $this->url->show($id, 0, $content_info['catid'], $content_info['inputtime'], '',$content_info,'add');
  414. $html->show($urls[1],$urls['data'],0);
  415. }
  416. //更新到全站搜索
  417. $inputinfo = '';
  418. $inputinfo['system'] = $content_info;
  419. $this->db->search_api($id,$inputinfo);
  420. }
  421. }
  422. if(isset($_GET['ajax_preview'])) {
  423. $_POST['ids'] = $_GET['id'];
  424. }
  425. $this->db->status($_POST['ids'],$status);
  426. }
  427. showmessage(L('operation_success'),HTTP_REFERER);
  428. }
  429. /**
  430. * 排序
  431. */
  432. public function listorder() {
  433. if(isset($_GET['dosubmit'])) {
  434. $catid = intval($_GET['catid']);
  435. if(!$catid) showmessage(L('missing_part_parameters'));
  436. $modelid = $this->categorys[$catid]['modelid'];
  437. $this->db->set_model($modelid);
  438. foreach($_POST['listorders'] as $id => $listorder) {
  439. $this->db->update(array('listorder'=>$listorder),array('id'=>$id));
  440. }
  441. showmessage(L('operation_success'));
  442. } else {
  443. showmessage(L('operation_failure'));
  444. }
  445. }
  446. /**
  447. * 显示栏目菜单列表
  448. */
  449. public function public_categorys() {
  450. $show_header = '';
  451. $cfg = getcache('common','commons');
  452. $ajax_show = intval($cfg['category_ajax']);
  453. $from = isset($_GET['from']) && in_array($_GET['from'],array('block')) ? $_GET['from'] : 'content';
  454. $tree = pc_base::load_sys_class('tree');
  455. if($from=='content' && $_SESSION['roleid'] != 1) {
  456. $this->priv_db = pc_base::load_model('category_priv_model');
  457. $priv_result = $this->priv_db->select(array('action'=>'init','roleid'=>$_SESSION['roleid'],'siteid'=>$this->siteid,'is_admin'=>1));
  458. $priv_catids = array();
  459. foreach($priv_result as $_v) {
  460. $priv_catids[] = $_v['catid'];
  461. }
  462. if(empty($priv_catids)) return '';
  463. }
  464. $categorys = array();
  465. if(!empty($this->categorys)) {
  466. foreach($this->categorys as $r) {
  467. if($r['siteid']!=$this->siteid || ($r['type']==2 && $r['child']==0)) continue;
  468. if($from=='content' && $_SESSION['roleid'] != 1 && !in_array($r['catid'],$priv_catids)) {
  469. $arrchildid = explode(',',$r['arrchildid']);
  470. $array_intersect = array_intersect($priv_catids,$arrchildid);
  471. if(empty($array_intersect)) continue;
  472. }
  473. if($r['type']==1 || $from=='block') {
  474. if($r['type']==0) {
  475. $r['vs_show'] = "<a href='?m=block&c=block_admin&a=public_visualization&menuid=".$_GET['menuid']."&catid=".$r['catid']."&type=show' target='right'>[".L('content_page')."]</a>";
  476. } else {
  477. $r['vs_show'] ='';
  478. }
  479. $r['icon_type'] = 'file';
  480. $r['add_icon'] = '';
  481. $r['type'] = 'add';
  482. } else {
  483. $r['icon_type'] = $r['vs_show'] = '';
  484. $r['type'] = 'init';
  485. $r['add_icon'] = "<a target='right' href='?m=content&c=content&menuid=".$_GET['menuid']."&catid=".$r['catid']."' onclick=javascript:openwinx('?m=content&c=content&a=add&menuid=".$_GET['menuid']."&catid=".$r['catid']."&hash_page=".$_SESSION['hash_page']."','')><img src='".IMG_PATH."add_content.gif' alt='".L('add')."'></a> ";
  486. }
  487. $categorys[$r['catid']] = $r;
  488. }
  489. }
  490. if(!empty($categorys)) {
  491. $tree->init($categorys);
  492. switch($from) {
  493. case 'block':
  494. $strs = "<span class='\$icon_type'>\$add_icon<a href='?m=block&c=block_admin&a=public_visualization&menuid=".$_GET['menuid']."&catid=\$catid&type=list' target='right'>\$catname</a> \$vs_show</span>";
  495. $strs2 = "<img src='".IMG_PATH."folder.gif'> <a href='?m=block&c=block_admin&a=public_visualization&menuid=".$_GET['menuid']."&catid=\$catid&type=category' target='right'>\$catname</a>";
  496. break;
  497. default:
  498. $strs = "<span class='\$icon_type'>\$add_icon<a href='?m=content&c=content&a=\$type&menuid=".$_GET['menuid']."&catid=\$catid' target='right' onclick='open_list(this)'>\$catname</a></span>";
  499. $strs2 = "<span class='folder'>\$catname</span>";
  500. break;
  501. }
  502. $categorys = $tree->get_treeview(0,'category_tree',$strs,$strs2,$ajax_show);
  503. } else {
  504. $categorys = L('please_add_category');
  505. }
  506. include $this->admin_tpl('category_tree');
  507. exit;
  508. }
  509. /**
  510. * 检查标题是否存在
  511. */
  512. public function public_check_title() {
  513. if($_GET['data']=='' || (!$_GET['catid'])) return '';
  514. $catid = intval($_GET['catid']);
  515. $modelid = $this->categorys[$catid]['modelid'];
  516. $this->db->set_model($modelid);
  517. $title = $_GET['data'];
  518. if(CHARSET=='gbk') $title = iconv('utf-8','gbk',$title);
  519. $r = $this->db->get_one(array('title'=>$title));
  520. if($r) {
  521. exit('1');
  522. } else {
  523. exit('0');
  524. }
  525. }
  526. /**
  527. * 修改某一字段数据
  528. */
  529. public function update_param() {
  530. $id = intval($_GET['id']);
  531. $field = $_GET['field'];
  532. $modelid = intval($_GET['modelid']);
  533. $value = $_GET['value'];
  534. if (CHARSET!='utf-8') {
  535. $value = iconv('utf-8', 'gbk', $value);
  536. }
  537. //检查字段是否存在
  538. $this->db->set_model($modelid);
  539. if ($this->db->field_exists($field)) {
  540. $this->db->update(array($field=>$value), array('id'=>$id));
  541. exit('200');
  542. } else {
  543. $this->db->table_name = $this->db->table_name.'_data';
  544. if ($this->db->field_exists($field)) {
  545. $this->db->update(array($field=>$value), array('id'=>$id));
  546. exit('200');
  547. } else {
  548. exit('300');
  549. }
  550. }
  551. }
  552. /**
  553. * 图片裁切
  554. */
  555. public function public_crop() {
  556. if (isset($_GET['picurl']) && !empty($_GET['picurl'])) {
  557. $picurl = $_GET['picurl'];
  558. $catid = intval($_GET['catid']);
  559. if (isset($_GET['module']) && !empty($_GET['module'])) {
  560. $module = $_GET['module'];
  561. }
  562. $show_header = '';
  563. include $this->admin_tpl('crop');
  564. }
  565. }
  566. /**
  567. * 相关文章选择
  568. */
  569. public function public_relationlist() {
  570. pc_base::load_sys_class('format','',0);
  571. $show_header = '';
  572. $model_cache = getcache('model','commons');
  573. if(!isset($_GET['modelid'])) {
  574. showmessage(L('please_select_modelid'));
  575. } else {
  576. $page = intval($_GET['page']);
  577. $modelid = intval($_GET['modelid']);
  578. $this->db->set_model($modelid);
  579. $where = '';
  580. if($_GET['catid']) {
  581. $catid = intval($_GET['catid']);
  582. $where .= "catid='$catid'";
  583. }
  584. $where .= $where ? ' AND status=99' : 'status=99';
  585. if(isset($_GET['keywords'])) {
  586. $keywords = trim($_GET['keywords']);
  587. $field = $_GET['field'];
  588. if(in_array($field, array('id','title','keywords','description'))) {
  589. if($field=='id') {
  590. $where .= " AND `id` ='$keywords'";
  591. } else {
  592. $where .= " AND `$field` like '%$keywords%'";
  593. }
  594. }
  595. }
  596. $infos = $this->db->listinfo($where,'',$page,12);
  597. $pages = $this->db->pages;
  598. include $this->admin_tpl('relationlist');
  599. }
  600. }
  601. public function public_getjson_ids() {
  602. $modelid = intval($_GET['modelid']);
  603. $id = intval($_GET['id']);
  604. $this->db->set_model($modelid);
  605. $tablename = $this->db->table_name;
  606. $this->db->table_name = $tablename.'_data';
  607. $r = $this->db->get_one(array('id'=>$id),'relation');
  608. if($r['relation']) {
  609. $relation = str_replace('|', ',', $r['relation']);
  610. $relation = trim($relation,',');
  611. $where = "id IN($relation)";
  612. $infos = array();
  613. $this->db->table_name = $tablename;
  614. $datas = $this->db->select($where,'id,title');
  615. foreach($datas as $_v) {
  616. $_v['sid'] = 'v'.$_v['id'];
  617. if(strtolower(CHARSET)=='gbk') $_v['title'] = iconv('gbk', 'utf-8', $_v['title']);
  618. $infos[] = $_v;
  619. }
  620. echo json_encode($infos);
  621. }
  622. }
  623. //文章预览
  624. public function public_preview() {
  625. $catid = intval($_GET['catid']);
  626. $id = intval($_GET['id']);
  627. if(!$catid || !$id) showmessage(L('missing_part_parameters'),'blank');
  628. $page = intval($_GET['page']);
  629. $page = max($page,1);
  630. $CATEGORYS = getcache('category_content_'.$this->get_siteid(),'commons');
  631. if(!isset($CATEGORYS[$catid]) || $CATEGORYS[$catid]['type']!=0) showmessage(L('missing_part_parameters'),'blank');
  632. define('HTML', true);
  633. $CAT = $CATEGORYS[$catid];
  634. $siteid = $CAT['siteid'];
  635. $MODEL = getcache('model','commons');
  636. $modelid = $CAT['modelid'];
  637. $this->db->table_name = $this->db->db_tablepre.$MODEL[$modelid]['tablename'];
  638. $r = $this->db->get_one(array('id'=>$id));
  639. if(!$r) showmessage(L('information_does_not_exist'));
  640. $this->db->table_name = $this->db->table_name.'_data';
  641. $r2 = $this->db->get_one(array('id'=>$id));
  642. $rs = $r2 ? array_merge($r,$r2) : $r;
  643. //再次重新赋值,以数据库为准
  644. $catid = $CATEGORYS[$r['catid']]['catid'];
  645. $modelid = $CATEGORYS[$catid]['modelid'];
  646. require_once CACHE_MODEL_PATH.'content_output.class.php';
  647. $content_output = new content_output($modelid,$catid,$CATEGORYS);
  648. $data = $content_output->get($rs);
  649. extract($data);
  650. $CAT['setting'] = string2array($CAT['setting']);
  651. $template = $template ? $template : $CAT['setting']['show_template'];
  652. $allow_visitor = 1;
  653. //SEO
  654. $SEO = seo($siteid, $catid, $title, $description);
  655. define('STYLE',$CAT['setting']['template_list']);
  656. if(isset($rs['paginationtype'])) {
  657. $paginationtype = $rs['paginationtype'];
  658. $maxcharperpage = $rs['maxcharperpage'];
  659. }
  660. $pages = $titles = '';
  661. if($rs['paginationtype']==1) {
  662. //自动分页
  663. if($maxcharperpage < 10) $maxcharperpage = 500;
  664. $contentpage = pc_base::load_app_class('contentpage');
  665. $content = $contentpage->get_data($content,$maxcharperpage);
  666. }
  667. if($rs['paginationtype']!=0) {
  668. //手动分页
  669. $CONTENT_POS = strpos($content, '[page]');
  670. if($CONTENT_POS !== false) {
  671. $this->url = pc_base::load_app_class('url', 'content');
  672. $contents = array_filter(explode('[page]', $content));
  673. $pagenumber = count($contents);
  674. for($i=1; $i<=$pagenumber; $i++) {
  675. $pageurls[$i] = $this->url->show($id, $i, $catid, $rs['inputtime']);
  676. }
  677. $END_POS = strpos($content, '[/page]');
  678. if($END_POS !== false) {
  679. if(preg_match_all("|\[page\](.*)\[/page\]|U", $content, $m, PREG_PATTERN_ORDER)) {
  680. foreach($m[1] as $k=>$v) {
  681. $p = $k+1;
  682. $titles[$p]['title'] = strip_tags($v);
  683. $titles[$p]['url'] = $pageurls[$p][0];
  684. }
  685. }
  686. } else {
  687. //当不存在 [/page]时,则使用下面分页
  688. $pages = content_pages($pagenumber,$page, $pageurls);
  689. }
  690. //判断[page]出现的位置是否在第一位
  691. if($CONTENT_POS<7) {
  692. $content = $contents[$page];
  693. } else {
  694. $content = $contents[$page-1];
  695. }
  696. if($titles) {
  697. list($title, $content) = explode('[/page]', $content);
  698. $content = trim($content);
  699. if(strpos($content,'</p>')===0) {
  700. $content = '<p>'.$content;
  701. }
  702. if(stripos($content,'<p>')===0) {
  703. $content = $content.'</p>';
  704. }
  705. }
  706. }
  707. }
  708. include template('content',$template);
  709. $pc_hash = $_SESSION['pc_hash'];
  710. $steps = intval($_GET['steps']);
  711. echo "
  712. <link href=\"".CSS_PATH."dialog_simp.css\" rel=\"stylesheet\" type=\"text/css\" />
  713. <script language=\"javascript\" type=\"text/javascript\" src=\"".JS_PATH."dialog.js\"></script>
  714. <script type=\"text/javascript\">art.dialog({lock:false,title:'".L('operations_manage')."',mouse:true, id:'content_m', content:'<span id=cloading ><a href=\'javascript:ajax_manage(1)\'>".L('passed_checked')."</a> | <a href=\'javascript:ajax_manage(2)\'>".L('reject')."</a> | <a href=\'javascript:ajax_manage(3)\'>".L('delete')."</a></span>',left:'100%',top:'100%',width:200,height:50,drag:true, fixed:true});
  715. function ajax_manage(type) {
  716. if(type==1) {
  717. $.get('?m=content&c=content&a=pass&ajax_preview=1&catid=".$catid."&steps=".$steps."&id=".$id."&pc_hash=".$pc_hash."');
  718. } else if(type==2) {
  719. $.get('?m=content&c=content&a=pass&ajax_preview=1&reject=1&catid=".$catid."&steps=".$steps."&id=".$id."&pc_hash=".$pc_hash."');
  720. } else if(type==3) {
  721. $.get('?m=content&c=content&a=delete&ajax_preview=1&dosubmit=1&catid=".$catid."&steps=".$steps."&id=".$id."&pc_hash=".$pc_hash."');
  722. }
  723. $('#cloading').html('<font color=red>".L('operation_success')."<span id=\"secondid\">2</span>".L('after_a_few_seconds_left')."</font>');
  724. setInterval('set_time()', 1000);
  725. setInterval('window.close()', 2000);
  726. }
  727. function set_time() {
  728. $('#secondid').html(1);
  729. }
  730. </script>";
  731. }
  732. /**
  733. * 审核所有内容
  734. */
  735. public function public_checkall() {
  736. $page = isset($_GET['page']) && intval($_GET['page']) ? intval($_GET['page']) : 1;
  737. $show_header = '';
  738. $workflows = getcache('workflow_'.$this->siteid,'commons');
  739. $datas = array();
  740. $pagesize = 20;
  741. $sql = '';
  742. if (in_array($_SESSION['roleid'], array('1'))) {
  743. $super_admin = 1;
  744. $status = isset($_GET['status']) ? $_GET['status'] : -1;
  745. } else {
  746. $super_admin = 0;
  747. $status = isset($_GET['status']) ? $_GET['status'] : 1;
  748. if($status==-1) $status = 1;
  749. }
  750. if($status>4) $status = 4;
  751. $this->priv_db = pc_base::load_model('category_priv_model');;
  752. $admin_username = param::get_cookie('admin_username');
  753. if($status==-1) {
  754. $sql = "`status` NOT IN (99,0,-2) AND `siteid`=$this->siteid";
  755. } else {
  756. $sql = "`status` = '$status' AND `siteid`=$this->siteid";
  757. }
  758. if($status!=0 && !$super_admin) {
  759. //以栏目进行循环
  760. foreach ($this->categorys as $catid => $cat) {
  761. if($cat['type']!=0) continue;
  762. //查看管理员是否有这个栏目的查看权限。
  763. if (!$this->priv_db->get_one(array('catid'=>$catid, 'siteid'=>$this->siteid, 'roleid'=>$_SESSION['roleid'], 'is_admin'=>'1'))) {
  764. continue;
  765. }
  766. //如果栏目有设置工作流,进行权限检查。
  767. $workflow = array();
  768. $cat['setting'] = string2array($cat['setting']);
  769. if (isset($cat['setting']['workflowid']) && !empty($cat['setting']['workflowid'])) {
  770. $workflow = $workflows[$cat['setting']['workflowid']];
  771. $workflow['setting'] = string2array($workflow['setting']);
  772. $usernames = $workflow['setting'][$status];
  773. if (empty($usernames) || !in_array($admin_username, $usernames)) {//判断当前管理,在工作流中可以审核几审
  774. continue;
  775. }
  776. }
  777. $priv_catid[] = $catid;
  778. }
  779. if(empty($priv_catid)) {
  780. $sql .= " AND catid = -1";
  781. } else {
  782. $priv_catid = implode(',', $priv_catid);
  783. $sql .= " AND catid IN ($priv_catid)";
  784. }
  785. }
  786. $this->content_check_db = pc_base::load_model('content_check_model');
  787. $datas = $this->content_check_db->listinfo($sql,'inputtime DESC',$page);
  788. $pages = $this->content_check_db->pages;
  789. include $this->admin_tpl('content_checkall');
  790. }
  791. /**
  792. * 批量移动文章
  793. */
  794. public function remove() {
  795. if(isset($_POST['dosubmit'])) {
  796. $this->content_check_db = pc_base::load_model('content_check_model');
  797. if($_POST['fromtype']==0) {
  798. if($_POST['ids']=='') showmessage(L('please_input_move_source'));
  799. if(!$_POST['tocatid']) showmessage(L('please_select_target_category'));
  800. $tocatid = intval($_POST['tocatid']);
  801. $modelid = $this->categorys[$tocatid]['modelid'];
  802. if(!$modelid) showmessage(L('illegal_operation'));
  803. $ids = array_filter(explode(',', $_POST['ids']),"intval");
  804. foreach ($ids as $id) {
  805. $checkid = 'c-'.$id.'-'.$this->siteid;
  806. $this->content_check_db->update(array('catid'=>$tocatid), array('checkid'=>$checkid));
  807. }
  808. $ids = implode(',', $ids);
  809. $this->db->set_model($modelid);
  810. $this->db->update(array('catid'=>$tocatid),"id IN($ids)");
  811. } else {
  812. if(!$_POST['fromid']) showmessage(L('please_input_move_source'));
  813. if(!$_POST['tocatid']) showmessage(L('please_select_target_category'));
  814. $tocatid = intval($_POST['tocatid']);
  815. $modelid = $this->categorys[$tocatid]['modelid'];
  816. if(!$modelid) showmessage(L('illegal_operation'));
  817. $fromid = array_filter($_POST['fromid'],"intval");
  818. $fromid = implode(',', $fromid);
  819. $this->db->set_model($modelid);
  820. $this->db->update(array('catid'=>$tocatid),"catid IN($fromid)");
  821. }
  822. showmessage(L('operation_success'),HTTP_REFERER);
  823. //ids
  824. } else {
  825. $show_header = '';
  826. $catid = intval($_GET['catid']);
  827. $modelid = $this->categorys[$catid]['modelid'];
  828. $tree = pc_base::load_sys_class('tree');
  829. $tree->icon = array('&nbsp;&nbsp;│ ','&nbsp;&nbsp;├─ ','&nbsp;&nbsp;└─ ');
  830. $tree->nbsp = '&nbsp;&nbsp;';
  831. $categorys = array();
  832. foreach($this->categorys as $cid=>$r) {
  833. if($this->siteid != $r['siteid'] || $r['type']) continue;
  834. if($modelid && $modelid != $r['modelid']) continue;
  835. $r['disabled'] = $r['child'] ? 'disabled' : '';
  836. $r['selected'] = $cid == $catid ? 'selected' : '';
  837. $categorys[$cid] = $r;
  838. }
  839. $str = "<option value='\$catid' \$selected \$disabled>\$spacer \$catname</option>";
  840. $tree->init($categorys);
  841. $string .= $tree->get_tree(0, $str);
  842. $str = "<option value='\$catid'>\$spacer \$catname</option>";
  843. $source_string = '';
  844. $tree->init($categorys);
  845. $source_string .= $tree->get_tree(0, $str);
  846. $ids = empty($_POST['ids']) ? '' : implode(',',$_POST['ids']);
  847. include $this->admin_tpl('content_remove');
  848. }
  849. }
  850. /**
  851. * 同时发布到其他栏目
  852. */
  853. public function add_othors() {
  854. $show_header = '';
  855. $sitelist = getcache('sitelist','commons');
  856. $siteid = $_GET['siteid'];
  857. include $this->admin_tpl('add_othors');
  858. }
  859. /**
  860. * 同时发布到其他栏目 异步加载栏目
  861. */
  862. public function public_getsite_categorys() {
  863. $siteid = intval($_GET['siteid']);
  864. $this->categorys = getcache('category_content_'.$siteid,'commons');
  865. $models = getcache('model','commons');
  866. $tree = pc_base::load_sys_class('tree');
  867. $tree->icon = array('&nbsp;&nbsp;&nbsp;│ ','&nbsp;&nbsp;&nbsp;├─ ','&nbsp;&nbsp;&nbsp;└─ ');
  868. $tree->nbsp = '&nbsp;&nbsp;&nbsp;';
  869. $categorys = array();
  870. if($_SESSION['roleid'] != 1) {
  871. $this->priv_db = pc_base::load_model('category_priv_model');
  872. $priv_result = $this->priv_db->select(array('action'=>'add','roleid'=>$_SESSION['roleid'],'siteid'=>$siteid,'is_admin'=>1));
  873. $priv_catids = array();
  874. foreach($priv_result as $_v) {
  875. $priv_catids[] = $_v['catid'];
  876. }
  877. if(empty($priv_catids)) return '';
  878. }
  879. foreach($this->categorys as $r) {
  880. if($r['siteid']!=$siteid || $r['type']!=0) continue;
  881. if($_SESSION['roleid'] != 1 && !in_array($r['catid'],$priv_catids)) {
  882. $arrchildid = explode(',',$r['arrchildid']);
  883. $array_intersect = array_intersect($priv_catids,$arrchildid);
  884. if(empty($array_intersect)) continue;
  885. }
  886. $r['modelname'] = $models[$r['modelid']]['name'];
  887. $r['style'] = $r['child'] ? 'color:#8A8A8A;' : '';
  888. $r['click'] = $r['child'] ? '' : "onclick=\"select_list(this,'".safe_replace($r['catname'])."',".$r['catid'].")\" class='cu' title='".L('click_to_select')."'";
  889. $categorys[$r['catid']] = $r;
  890. }
  891. $str = "<tr \$click >
  892. <td align='center'>\$id</td>
  893. <td style='\$style'>\$spacer\$catname</td>
  894. <td align='center'>\$modelname</td>
  895. </tr>";
  896. $tree->init($categorys);
  897. $categorys = $tree->get_tree(0, $str);
  898. echo $categorys;
  899. }
  900. public function public_sub_categorys() {
  901. $cfg = getcache('common','commons');
  902. $ajax_show = intval(abs($cfg['category_ajax']));
  903. $catid = intval($_POST['root']);
  904. $modelid = intval($_POST['modelid']);
  905. $this->categorys = getcache('category_content_'.$this->siteid,'commons');
  906. $tree = pc_base::load_sys_class('tree');
  907. if(!empty($this->categorys)) {
  908. foreach($this->categorys as $r) {
  909. if($r['siteid']!=$this->siteid || ($r['type']==2 && $r['child']==0)) continue;
  910. if($from=='content' && $_SESSION['roleid'] != 1 && !in_array($r['catid'],$priv_catids)) {
  911. $arrchildid = explode(',',$r['arrchildid']);
  912. $array_intersect = array_intersect($priv_catids,$arrchildid);
  913. if(empty($array_intersect)) continue;
  914. }
  915. if($r['type']==1 || $from=='block') {
  916. if($r['type']==0) {
  917. $r['vs_show'] = "<a href='?m=block&c=block_admin&a=public_visualization&menuid=".$_GET['menuid']."&catid=".$r['catid']."&type=show' target='right'>[".L('content_page')."]</a>";
  918. } else {
  919. $r['vs_show'] ='';
  920. }
  921. $r['icon_type'] = 'file';
  922. $r['add_icon'] = '';
  923. $r['type'] = 'add';
  924. } else {
  925. $r['icon_type'] = $r['vs_show'] = '';
  926. $r['type'] = 'init';
  927. $r['add_icon'] = "<a target='right' href='?m=content&c=content&menuid=".$_GET['menuid']."&catid=".$r['catid']."' onclick=javascript:openwinx('?m=content&c=content&a=add&menuid=".$_GET['menuid']."&catid=".$r['catid']."&hash_page=".$_SESSION['hash_page']."','')><img src='".IMG_PATH."add_content.gif' alt='".L('add')."'></a> ";
  928. }
  929. $categorys[$r['catid']] = $r;
  930. }
  931. }
  932. if(!empty($categorys)) {
  933. $tree->init($categorys);
  934. switch($from) {
  935. case 'block':
  936. $strs = "<span class='\$icon_type'>\$add_icon<a href='?m=block&c=block_admin&a=public_visualization&menuid=".$_GET['menuid']."&catid=\$catid&type=list&pc_hash=".$_SESSION['pc_hash']."' target='right'>\$catname</a> \$vs_show</span>";
  937. break;
  938. default:
  939. $strs = "<span class='\$icon_type'>\$add_icon<a href='?m=content&c=content&a=\$type&menuid=".$_GET['menuid']."&catid=\$catid&pc_hash=".$_SESSION['pc_hash']."' target='right' onclick='open_list(this)'>\$catname</a></span>";
  940. break;
  941. }
  942. $data = $tree->creat_sub_json($catid,$strs);
  943. }
  944. echo $data;
  945. }
  946. /**
  947. * 一键清理演示数据
  948. */
  949. public function clear_data() {
  950. //清理数据涉及到的数据表
  951. if ($_POST['dosubmit']) {
  952. set_time_limit(0);
  953. $models = array('category', 'content', 'hits', 'search', 'position_data', 'video_content', 'video_store', 'comment');
  954. $tables = $_POST['tables'];
  955. if (is_array($tables)) {
  956. foreach ($tables as $t) {
  957. if (in_array($t, $models)) {
  958. if ($t=='content') {
  959. $model = $_POST['model'];
  960. $db = pc_base::load_model('content_model');
  961. //读取网站的所有模型
  962. $model_arr = getcache('model', 'commons');
  963. foreach ($model as $modelid) {
  964. $db->set_model($modelid);
  965. if ($r = $db->count()) { //判断模型下是否有数据
  966. $sql_file = CACHE_PATH.'bakup'.DIRECTORY_SEPARATOR.'default'.DIRECTORY_SEPARATOR.$model_arr[$modelid]['tablename'].'.sql';
  967. $result = $data = $db->select();
  968. $this->create_sql_file($result, $db->db_tablepre.$model_arr[$modelid]['tablename'], $sql_file);
  969. $db->query('TRUNCATE TABLE `phpcms_'.$model_arr[$modelid]['tablename'].'`');
  970. //开始清理模型data表数据
  971. $db->table_name = $db->table_name.'_data';
  972. $sql_file = CACHE_PATH.'bakup'.DIRECTORY_SEPARATOR.'default'.DIRECTORY_SEPARATOR.$model_arr[$modelid]['tablename'].'_data.sql';
  973. $result = $db->select();
  974. $this->create_sql_file($result, $db->db_tablepre.$model_arr[$modelid]['tablename'].'_data', $sql_file);
  975. $db->query('TRUNCATE TABLE `phpcms_'.$model_arr[$modelid]['tablename'].'_data`');
  976. //删除该模型中在hits表的数据
  977. $hits_db = pc_base::load_model('hits_model');
  978. $hitsid = 'c-'.$modelid.'-';
  979. $result = $hits_db->select("`hitsid` LIKE '%$hitsid%'");
  980. if (is_array($result)) {
  981. $sql_file = CACHE_PATH.'bakup'.DIRECTORY_SEPARATOR.'default'.DIRECTORY_SEPARATOR.'hits-'.$modelid.'.sql';
  982. $this->create_sql_file($result, $hits_db->db_tablepre.'hits', $sql_file);
  983. }
  984. $hits_db->delete("`hitsid` LIKE '%$hitsid%'");
  985. //删除该模型在search中的数据
  986. $search_db = pc_base::load_model('search_model');
  987. $type_model = getcache('type_model_'.$model_arr[$modelid]['siteid'], 'search');
  988. $typeid = $type_model[$modelid];
  989. $result = $search_db->select("`typeid`=".$typeid);
  990. if (is_array($result)) {
  991. $sql_file = CACHE_PATH.'bakup'.DIRECTORY_SEPARATOR.'default'.DIRECTORY_SEPARATOR.'search-'.$modelid.'.sql';
  992. $this->create_sql_file($result, $search_db->db_tablepre.'search', $sql_file);
  993. }
  994. $search_db->delete("`typeid`=".$typeid);
  995. //Delete the model data in the position table
  996. $position_db = pc_base::load_model('position_data_model');
  997. $result = $position_db->select('`modelid`='.$modelid.' AND `module`=\'content\'');
  998. if (is_array($result)) {
  999. $sql_file = CACHE_PATH.'bakup'.DIRECTORY_SEPARATOR.'default'.DIRECTORY_SEPARATOR.'position_data-'.$modelid.'.sql';
  1000. $this->create_sql_file($result, $position_db->db_tablepre.'position_data', $sql_file);
  1001. }
  1002. $position_db->delete('`modelid`='.$modelid.' AND `module`=\'content\'');
  1003. //清理视频库与内容对应关系表
  1004. if (module_exists('video')) {
  1005. $video_content_db = pc_base::load_model('video_content_model');
  1006. $result = $video_content_db->select('`modelid`=\''.$modelid.'\'');
  1007. if (is_array($result)) {
  1008. $sql_file = CACHE_PATH.'bakup'.DIRECTORY_SEPARATOR.'default'.DIRECTORY_SEPARATOR.'video_content-'.$modelid.'.sql';
  1009. $this->create_sql_file($result, $video_content_db->db_tablepre.'video_content', $sql_file);
  1010. }
  1011. $video_content_db->delete('`modelid`=\''.$modelid.'\'');
  1012. }
  1013. //清理评论表及附件表,附件的清理为不可逆操作。
  1014. //附件初始化
  1015. //$attachment = pc_base::load_model('attachment_model');
  1016. //$comment = pc_base::load_app_class('comment', 'comment');
  1017. //if(module_exists('comment')){
  1018. //$comment_exists = 1;
  1019. //}
  1020. //foreach ($data as $d) {
  1021. //$attachment->api_delete('c-'.$d['catid'].'-'.$d['id']);
  1022. //if ($comment_exists) {
  1023. //$commentid = id_encode('content_'.$d['catid'], $d['id'], $model_arr[$modelid]['siteid']);
  1024. //$comment->del($commentid, $model_arr[$modelid]['siteid'], $d['id'], $d['catid']);
  1025. //}
  1026. //}
  1027. }
  1028. }
  1029. } elseif ($t=='comment') {
  1030. $comment_db = pc_base::load_model('comment_data_model');
  1031. for($i=1;;$i++) {
  1032. $comment_db->table_name($i);
  1033. if ($comment_db->table_exists(str_replace($comment_db->db_tablepre, '', $comment_db->table_name))) {
  1034. if ($r = $comment_db->count()) {
  1035. $sql_file = CACHE_PATH.'bakup'.DIRECTORY_SEPARATOR.'default'.DIRECTORY_SEPARATOR.'comment_data_'.$i.'.sql';
  1036. $result = $comment_db->select();
  1037. $this->create_sql_file($result, $comment_db->db_tablepre.'comment_data_'.$i, $sql_file);
  1038. $comment_db->query('TRUNCATE TABLE `phpcms_comment_data_'.$i.'`');
  1039. }
  1040. } else {
  1041. break;
  1042. }
  1043. }
  1044. } else {
  1045. $db = pc_base::load_model($t.'_model');
  1046. if ($r = $db->count()) {
  1047. $result = $db->select();
  1048. $sql_file = CACHE_PATH.'bakup'.DIRECTORY_SEPARATOR.'default'.DIRECTORY_SEPARATOR.$t.'.sql';
  1049. $this->create_sql_file($result, $db->db_tablepre.$t, $sql_file);
  1050. $db->query('TRUNCATE TABLE `phpcms_'.$t.'`');
  1051. }
  1052. }
  1053. }
  1054. }
  1055. }
  1056. showmessage(L('clear_data_message'));
  1057. } else {
  1058. //读取网站的所有模型
  1059. $model_arr = getcache('model', 'commons');
  1060. include $this->admin_tpl('clear_data');
  1061. }
  1062. }
  1063. /**
  1064. * 备份数据到文件
  1065. * @param $data array 备份的数据数组
  1066. * @param $tablename 数据所属数据表
  1067. * @param $file 备份到的文件
  1068. */
  1069. private function create_sql_file($data, $db, $file) {
  1070. if (is_array($data)) {
  1071. $sql = '';
  1072. foreach ($data as $d) {
  1073. $tag = '';
  1074. $sql .= "INSERT INTO `".$db.'` VALUES(';
  1075. foreach ($d as $_f => $_v) {
  1076. $sql .= $tag.'\''.addslashes($_v).'\'';
  1077. $tag = ',';
  1078. }
  1079. $sql .= ');'."\r\n";
  1080. }
  1081. file_put_contents($file, $sql);
  1082. }
  1083. return true;
  1084. }
  1085. }
  1086. ?>