content.php 46 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151
  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 && $_SESSION['roleid'] != 2) {
  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.'{_,-,.}*',GLOB_BRACE);
  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. $_GET['menuid'] = intval($_GET['menuid']);
  465. $categorys = array();
  466. if(!empty($this->categorys)) {
  467. foreach($this->categorys as $r) {
  468. if($r['siteid']!=$this->siteid || ($r['type']==2 && $r['child']==0)) continue;
  469. if($from=='content' && $_SESSION['roleid'] != 1 && !in_array($r['catid'],$priv_catids)) {
  470. $arrchildid = explode(',',$r['arrchildid']);
  471. $array_intersect = array_intersect($priv_catids,$arrchildid);
  472. if(empty($array_intersect)) continue;
  473. }
  474. if($r['type']==1 || $from=='block') {
  475. if($r['type']==0) {
  476. $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>";
  477. } else {
  478. $r['vs_show'] ='';
  479. }
  480. $r['icon_type'] = 'file';
  481. $r['add_icon'] = '';
  482. $r['type'] = 'add';
  483. } else {
  484. $r['icon_type'] = $r['vs_show'] = '';
  485. $r['type'] = 'init';
  486. $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> ";
  487. }
  488. $categorys[$r['catid']] = $r;
  489. }
  490. }
  491. if(!empty($categorys)) {
  492. $tree->init($categorys);
  493. switch($from) {
  494. case 'block':
  495. $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>";
  496. $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>";
  497. break;
  498. default:
  499. $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>";
  500. $strs2 = "<span class='folder'>\$catname</span>";
  501. break;
  502. }
  503. $categorys = $tree->get_treeview(0,'category_tree',$strs,$strs2,$ajax_show);
  504. } else {
  505. $categorys = L('please_add_category');
  506. }
  507. include $this->admin_tpl('category_tree');
  508. exit;
  509. }
  510. /**
  511. * 检查标题是否存在
  512. */
  513. public function public_check_title() {
  514. if($_GET['data']=='' || (!$_GET['catid'])) return '';
  515. $catid = intval($_GET['catid']);
  516. $modelid = $this->categorys[$catid]['modelid'];
  517. $this->db->set_model($modelid);
  518. $title = $_GET['data'];
  519. if(CHARSET=='gbk') $title = iconv('utf-8','gbk',$title);
  520. $r = $this->db->get_one(array('title'=>$title));
  521. if($r) {
  522. exit('1');
  523. } else {
  524. exit('0');
  525. }
  526. }
  527. /**
  528. * 修改某一字段数据
  529. */
  530. public function update_param() {
  531. $id = intval($_GET['id']);
  532. $field = $_GET['field'];
  533. $modelid = intval($_GET['modelid']);
  534. $value = $_GET['value'];
  535. if (CHARSET!='utf-8') {
  536. $value = iconv('utf-8', 'gbk', $value);
  537. }
  538. //检查字段是否存在
  539. $this->db->set_model($modelid);
  540. if ($this->db->field_exists($field)) {
  541. $this->db->update(array($field=>$value), array('id'=>$id));
  542. exit('200');
  543. } else {
  544. $this->db->table_name = $this->db->table_name.'_data';
  545. if ($this->db->field_exists($field)) {
  546. $this->db->update(array($field=>$value), array('id'=>$id));
  547. exit('200');
  548. } else {
  549. exit('300');
  550. }
  551. }
  552. }
  553. /**
  554. * 图片裁切
  555. */
  556. public function public_crop() {
  557. if (isset($_GET['picurl']) && !empty($_GET['picurl'])) {
  558. $picurl = $_GET['picurl'];
  559. $catid = intval($_GET['catid']);
  560. if (isset($_GET['module']) && !empty($_GET['module'])) {
  561. $module = $_GET['module'];
  562. }
  563. $show_header = '';
  564. include $this->admin_tpl('crop');
  565. }
  566. }
  567. /**
  568. * 相关文章选择
  569. */
  570. public function public_relationlist() {
  571. pc_base::load_sys_class('format','',0);
  572. $show_header = '';
  573. $model_cache = getcache('model','commons');
  574. if(!isset($_GET['modelid'])) {
  575. showmessage(L('please_select_modelid'));
  576. } else {
  577. $page = intval($_GET['page']);
  578. $modelid = intval($_GET['modelid']);
  579. $this->db->set_model($modelid);
  580. $where = '';
  581. if($_GET['catid']) {
  582. $catid = intval($_GET['catid']);
  583. $where .= "catid='$catid'";
  584. }
  585. $where .= $where ? ' AND status=99' : 'status=99';
  586. if(isset($_GET['keywords'])) {
  587. $keywords = trim($_GET['keywords']);
  588. $field = $_GET['field'];
  589. if(in_array($field, array('id','title','keywords','description'))) {
  590. if($field=='id') {
  591. $where .= " AND `id` ='$keywords'";
  592. } else {
  593. $where .= " AND `$field` like '%$keywords%'";
  594. }
  595. }
  596. }
  597. $infos = $this->db->listinfo($where,'',$page,12);
  598. $pages = $this->db->pages;
  599. include $this->admin_tpl('relationlist');
  600. }
  601. }
  602. public function public_getjson_ids() {
  603. $modelid = intval($_GET['modelid']);
  604. $id = intval($_GET['id']);
  605. $this->db->set_model($modelid);
  606. $tablename = $this->db->table_name;
  607. $this->db->table_name = $tablename.'_data';
  608. $r = $this->db->get_one(array('id'=>$id),'relation');
  609. if($r['relation']) {
  610. $relation = str_replace('|', ',', $r['relation']);
  611. $relation = trim($relation,',');
  612. $where = "id IN($relation)";
  613. $infos = array();
  614. $this->db->table_name = $tablename;
  615. $datas = $this->db->select($where,'id,title');
  616. foreach($datas as $_v) {
  617. $_v['sid'] = 'v'.$_v['id'];
  618. if(strtolower(CHARSET)=='gbk') $_v['title'] = iconv('gbk', 'utf-8', $_v['title']);
  619. $infos[] = $_v;
  620. }
  621. echo json_encode($infos);
  622. }
  623. }
  624. //文章预览
  625. public function public_preview() {
  626. $catid = intval($_GET['catid']);
  627. $id = intval($_GET['id']);
  628. if(!$catid || !$id) showmessage(L('missing_part_parameters'),'blank');
  629. $page = intval($_GET['page']);
  630. $page = max($page,1);
  631. $CATEGORYS = getcache('category_content_'.$this->get_siteid(),'commons');
  632. if(!isset($CATEGORYS[$catid]) || $CATEGORYS[$catid]['type']!=0) showmessage(L('missing_part_parameters'),'blank');
  633. define('HTML', true);
  634. $CAT = $CATEGORYS[$catid];
  635. $siteid = $CAT['siteid'];
  636. $MODEL = getcache('model','commons');
  637. $modelid = $CAT['modelid'];
  638. $this->db->table_name = $this->db->db_tablepre.$MODEL[$modelid]['tablename'];
  639. $r = $this->db->get_one(array('id'=>$id));
  640. if(!$r) showmessage(L('information_does_not_exist'));
  641. $this->db->table_name = $this->db->table_name.'_data';
  642. $r2 = $this->db->get_one(array('id'=>$id));
  643. $rs = $r2 ? array_merge($r,$r2) : $r;
  644. //再次重新赋值,以数据库为准
  645. $catid = $CATEGORYS[$r['catid']]['catid'];
  646. $modelid = $CATEGORYS[$catid]['modelid'];
  647. require_once CACHE_MODEL_PATH.'content_output.class.php';
  648. $content_output = new content_output($modelid,$catid,$CATEGORYS);
  649. $data = $content_output->get($rs);
  650. extract($data);
  651. $CAT['setting'] = string2array($CAT['setting']);
  652. $template = $template ? $template : $CAT['setting']['show_template'];
  653. $allow_visitor = 1;
  654. //SEO
  655. $SEO = seo($siteid, $catid, $title, $description);
  656. define('STYLE',$CAT['setting']['template_list']);
  657. if(isset($rs['paginationtype'])) {
  658. $paginationtype = $rs['paginationtype'];
  659. $maxcharperpage = $rs['maxcharperpage'];
  660. }
  661. $pages = $titles = '';
  662. if($rs['paginationtype']==1) {
  663. //自动分页
  664. if($maxcharperpage < 10) $maxcharperpage = 500;
  665. $contentpage = pc_base::load_app_class('contentpage');
  666. $content = $contentpage->get_data($content,$maxcharperpage);
  667. }
  668. if($rs['paginationtype']!=0) {
  669. //手动分页
  670. $CONTENT_POS = strpos($content, '[page]');
  671. if($CONTENT_POS !== false) {
  672. $this->url = pc_base::load_app_class('url', 'content');
  673. $contents = array_filter(explode('[page]', $content));
  674. $pagenumber = count($contents);
  675. if (strpos($content, '[/page]')!==false && ($CONTENT_POS<7)) {
  676. $pagenumber--;
  677. }
  678. for($i=1; $i<=$pagenumber; $i++) {
  679. $pageurls[$i][0] = 'index.php?m=content&c=content&a=public_preview&steps='.intval($_GET['steps']).'&catid='.$catid.'&id='.$id.'&page='.$i;
  680. }
  681. $END_POS = strpos($content, '[/page]');
  682. if($END_POS !== false) {
  683. if($CONTENT_POS>7) {
  684. $content = '[page]'.$title.'[/page]'.$content;
  685. }
  686. if(preg_match_all("|\[page\](.*)\[/page\]|U", $content, $m, PREG_PATTERN_ORDER)) {
  687. foreach($m[1] as $k=>$v) {
  688. $p = $k+1;
  689. $titles[$p]['title'] = strip_tags($v);
  690. $titles[$p]['url'] = $pageurls[$p][0];
  691. }
  692. }
  693. }
  694. //当不存在 [/page]时,则使用下面分页
  695. $pages = content_pages($pagenumber,$page, $pageurls);
  696. //判断[page]出现的位置是否在第一位
  697. if($CONTENT_POS<7) {
  698. $content = $contents[$page];
  699. } else {
  700. if ($page==1 && !empty($titles)) {
  701. $content = $title.'[/page]'.$contents[$page-1];
  702. } else {
  703. $content = $contents[$page-1];
  704. }
  705. }
  706. if($titles) {
  707. list($title, $content) = explode('[/page]', $content);
  708. $content = trim($content);
  709. if(strpos($content,'</p>')===0) {
  710. $content = '<p>'.$content;
  711. }
  712. if(stripos($content,'<p>')===0) {
  713. $content = $content.'</p>';
  714. }
  715. }
  716. }
  717. }
  718. include template('content',$template);
  719. $pc_hash = $_SESSION['pc_hash'];
  720. $steps = intval($_GET['steps']);
  721. echo "
  722. <link href=\"".CSS_PATH."dialog_simp.css\" rel=\"stylesheet\" type=\"text/css\" />
  723. <script language=\"javascript\" type=\"text/javascript\" src=\"".JS_PATH."dialog.js\"></script>
  724. <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});
  725. function ajax_manage(type) {
  726. if(type==1) {
  727. $.get('?m=content&c=content&a=pass&ajax_preview=1&catid=".$catid."&steps=".$steps."&id=".$id."&pc_hash=".$pc_hash."');
  728. } else if(type==2) {
  729. $.get('?m=content&c=content&a=pass&ajax_preview=1&reject=1&catid=".$catid."&steps=".$steps."&id=".$id."&pc_hash=".$pc_hash."');
  730. } else if(type==3) {
  731. $.get('?m=content&c=content&a=delete&ajax_preview=1&dosubmit=1&catid=".$catid."&steps=".$steps."&id=".$id."&pc_hash=".$pc_hash."');
  732. }
  733. $('#cloading').html('<font color=red>".L('operation_success')."<span id=\"secondid\">2</span>".L('after_a_few_seconds_left')."</font>');
  734. setInterval('set_time()', 1000);
  735. setInterval('window.close()', 2000);
  736. }
  737. function set_time() {
  738. $('#secondid').html(1);
  739. }
  740. </script>";
  741. }
  742. /**
  743. * 审核所有内容
  744. */
  745. public function public_checkall() {
  746. $page = isset($_GET['page']) && intval($_GET['page']) ? intval($_GET['page']) : 1;
  747. $show_header = '';
  748. $workflows = getcache('workflow_'.$this->siteid,'commons');
  749. $datas = array();
  750. $pagesize = 20;
  751. $sql = '';
  752. if (in_array($_SESSION['roleid'], array('1'))) {
  753. $super_admin = 1;
  754. $status = isset($_GET['status']) ? $_GET['status'] : -1;
  755. } else {
  756. $super_admin = 0;
  757. $status = isset($_GET['status']) ? $_GET['status'] : 1;
  758. if($status==-1) $status = 1;
  759. }
  760. if($status>4) $status = 4;
  761. $this->priv_db = pc_base::load_model('category_priv_model');;
  762. $admin_username = param::get_cookie('admin_username');
  763. if($status==-1) {
  764. $sql = "`status` NOT IN (99,0,-2) AND `siteid`=$this->siteid";
  765. } else {
  766. $sql = "`status` = '$status' AND `siteid`=$this->siteid";
  767. }
  768. if($status!=0 && !$super_admin) {
  769. //以栏目进行循环
  770. foreach ($this->categorys as $catid => $cat) {
  771. if($cat['type']!=0) continue;
  772. //查看管理员是否有这个栏目的查看权限。
  773. if (!$this->priv_db->get_one(array('catid'=>$catid, 'siteid'=>$this->siteid, 'roleid'=>$_SESSION['roleid'], 'is_admin'=>'1'))) {
  774. continue;
  775. }
  776. //如果栏目有设置工作流,进行权限检查。
  777. $workflow = array();
  778. $cat['setting'] = string2array($cat['setting']);
  779. if (isset($cat['setting']['workflowid']) && !empty($cat['setting']['workflowid'])) {
  780. $workflow = $workflows[$cat['setting']['workflowid']];
  781. $workflow['setting'] = string2array($workflow['setting']);
  782. $usernames = $workflow['setting'][$status];
  783. if (empty($usernames) || !in_array($admin_username, $usernames)) {//判断当前管理,在工作流中可以审核几审
  784. continue;
  785. }
  786. }
  787. $priv_catid[] = $catid;
  788. }
  789. if(empty($priv_catid)) {
  790. $sql .= " AND catid = -1";
  791. } else {
  792. $priv_catid = implode(',', $priv_catid);
  793. $sql .= " AND catid IN ($priv_catid)";
  794. }
  795. }
  796. $this->content_check_db = pc_base::load_model('content_check_model');
  797. $datas = $this->content_check_db->listinfo($sql,'inputtime DESC',$page);
  798. $pages = $this->content_check_db->pages;
  799. include $this->admin_tpl('content_checkall');
  800. }
  801. /**
  802. * 批量移动文章
  803. */
  804. public function remove() {
  805. if(isset($_POST['dosubmit'])) {
  806. $this->content_check_db = pc_base::load_model('content_check_model');
  807. $this->hits_db = pc_base::load_model('hits_model');
  808. if($_POST['fromtype']==0) {
  809. if($_POST['ids']=='') showmessage(L('please_input_move_source'));
  810. if(!$_POST['tocatid']) showmessage(L('please_select_target_category'));
  811. $tocatid = intval($_POST['tocatid']);
  812. $modelid = $this->categorys[$tocatid]['modelid'];
  813. if(!$modelid) showmessage(L('illegal_operation'));
  814. $ids = array_filter(explode(',', $_POST['ids']),"is_numeric");
  815. foreach ($ids as $id) {
  816. $checkid = 'c-'.$id.'-'.$this->siteid;
  817. $this->content_check_db->update(array('catid'=>$tocatid), array('checkid'=>$checkid));
  818. $hitsid = 'c-'.$modelid.'-'.$id;
  819. $this->hits_db->update(array('catid'=>$tocatid),array('hitsid'=>$hitsid));
  820. }
  821. $ids = implode(',', $ids);
  822. $this->db->set_model($modelid);
  823. $this->db->update(array('catid'=>$tocatid),"id IN($ids)");
  824. } else {
  825. if(!$_POST['fromid']) showmessage(L('please_input_move_source'));
  826. if(!$_POST['tocatid']) showmessage(L('please_select_target_category'));
  827. $tocatid = intval($_POST['tocatid']);
  828. $modelid = $this->categorys[$tocatid]['modelid'];
  829. if(!$modelid) showmessage(L('illegal_operation'));
  830. $fromid = array_filter($_POST['fromid'],"is_numeric");
  831. $fromid = implode(',', $fromid);
  832. $this->db->set_model($modelid);
  833. $this->db->update(array('catid'=>$tocatid),"catid IN($fromid)");
  834. $this->hits_db->update(array('catid'=>$tocatid),"catid IN($fromid)");
  835. }
  836. showmessage(L('operation_success'),HTTP_REFERER);
  837. //ids
  838. } else {
  839. $show_header = '';
  840. $catid = intval($_GET['catid']);
  841. $modelid = $this->categorys[$catid]['modelid'];
  842. $tree = pc_base::load_sys_class('tree');
  843. $tree->icon = array('&nbsp;&nbsp;│ ','&nbsp;&nbsp;├─ ','&nbsp;&nbsp;└─ ');
  844. $tree->nbsp = '&nbsp;&nbsp;';
  845. $categorys = array();
  846. foreach($this->categorys as $cid=>$r) {
  847. if($this->siteid != $r['siteid'] || $r['type']) continue;
  848. if($modelid && $modelid != $r['modelid']) continue;
  849. $r['disabled'] = $r['child'] ? 'disabled' : '';
  850. $r['selected'] = $cid == $catid ? 'selected' : '';
  851. $categorys[$cid] = $r;
  852. }
  853. $str = "<option value='\$catid' \$selected \$disabled>\$spacer \$catname</option>";
  854. $tree->init($categorys);
  855. $string .= $tree->get_tree(0, $str);
  856. $str = "<option value='\$catid'>\$spacer \$catname</option>";
  857. $source_string = '';
  858. $tree->init($categorys);
  859. $source_string .= $tree->get_tree(0, $str);
  860. $ids = empty($_POST['ids']) ? '' : implode(',',$_POST['ids']);
  861. include $this->admin_tpl('content_remove');
  862. }
  863. }
  864. /**
  865. * 同时发布到其他栏目
  866. */
  867. public function add_othors() {
  868. $show_header = '';
  869. $sitelist = getcache('sitelist','commons');
  870. $siteid = $_GET['siteid'];
  871. include $this->admin_tpl('add_othors');
  872. }
  873. /**
  874. * 同时发布到其他栏目 异步加载栏目
  875. */
  876. public function public_getsite_categorys() {
  877. $siteid = intval($_GET['siteid']);
  878. $this->categorys = getcache('category_content_'.$siteid,'commons');
  879. $models = getcache('model','commons');
  880. $tree = pc_base::load_sys_class('tree');
  881. $tree->icon = array('&nbsp;&nbsp;&nbsp;│ ','&nbsp;&nbsp;&nbsp;├─ ','&nbsp;&nbsp;&nbsp;└─ ');
  882. $tree->nbsp = '&nbsp;&nbsp;&nbsp;';
  883. $categorys = array();
  884. if($_SESSION['roleid'] != 1) {
  885. $this->priv_db = pc_base::load_model('category_priv_model');
  886. $priv_result = $this->priv_db->select(array('action'=>'add','roleid'=>$_SESSION['roleid'],'siteid'=>$siteid,'is_admin'=>1));
  887. $priv_catids = array();
  888. foreach($priv_result as $_v) {
  889. $priv_catids[] = $_v['catid'];
  890. }
  891. if(empty($priv_catids)) return '';
  892. }
  893. foreach($this->categorys as $r) {
  894. if($r['siteid']!=$siteid || $r['type']!=0) continue;
  895. if($_SESSION['roleid'] != 1 && !in_array($r['catid'],$priv_catids)) {
  896. $arrchildid = explode(',',$r['arrchildid']);
  897. $array_intersect = array_intersect($priv_catids,$arrchildid);
  898. if(empty($array_intersect)) continue;
  899. }
  900. $r['modelname'] = $models[$r['modelid']]['name'];
  901. $r['style'] = $r['child'] ? 'color:#8A8A8A;' : '';
  902. $r['click'] = $r['child'] ? '' : "onclick=\"select_list(this,'".safe_replace($r['catname'])."',".$r['catid'].")\" class='cu' title='".L('click_to_select')."'";
  903. $categorys[$r['catid']] = $r;
  904. }
  905. $str = "<tr \$click >
  906. <td align='center'>\$id</td>
  907. <td style='\$style'>\$spacer\$catname</td>
  908. <td align='center'>\$modelname</td>
  909. </tr>";
  910. $tree->init($categorys);
  911. $categorys = $tree->get_tree(0, $str);
  912. echo $categorys;
  913. }
  914. public function public_sub_categorys() {
  915. $cfg = getcache('common','commons');
  916. $ajax_show = intval(abs($cfg['category_ajax']));
  917. $catid = intval($_POST['root']);
  918. $modelid = intval($_POST['modelid']);
  919. $this->categorys = getcache('category_content_'.$this->siteid,'commons');
  920. $tree = pc_base::load_sys_class('tree');
  921. $_GET['menuid'] = intval($_GET['menuid']);
  922. if(!empty($this->categorys)) {
  923. foreach($this->categorys as $r) {
  924. if($r['siteid']!=$this->siteid || ($r['type']==2 && $r['child']==0)) continue;
  925. if($from=='content' && $_SESSION['roleid'] != 1 && !in_array($r['catid'],$priv_catids)) {
  926. $arrchildid = explode(',',$r['arrchildid']);
  927. $array_intersect = array_intersect($priv_catids,$arrchildid);
  928. if(empty($array_intersect)) continue;
  929. }
  930. if($r['type']==1 || $from=='block') {
  931. if($r['type']==0) {
  932. $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>";
  933. } else {
  934. $r['vs_show'] ='';
  935. }
  936. $r['icon_type'] = 'file';
  937. $r['add_icon'] = '';
  938. $r['type'] = 'add';
  939. } else {
  940. $r['icon_type'] = $r['vs_show'] = '';
  941. $r['type'] = 'init';
  942. $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> ";
  943. }
  944. $categorys[$r['catid']] = $r;
  945. }
  946. }
  947. if(!empty($categorys)) {
  948. $tree->init($categorys);
  949. switch($from) {
  950. case 'block':
  951. $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>";
  952. break;
  953. default:
  954. $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>";
  955. break;
  956. }
  957. $data = $tree->creat_sub_json($catid,$strs);
  958. }
  959. echo $data;
  960. }
  961. /**
  962. * 一键清理演示数据
  963. */
  964. public function clear_data() {
  965. //清理数据涉及到的数据表
  966. if ($_POST['dosubmit']) {
  967. set_time_limit(0);
  968. $models = array('category', 'content', 'hits', 'search', 'position_data', 'video_content', 'video_store', 'comment');
  969. $tables = $_POST['tables'];
  970. if (is_array($tables)) {
  971. foreach ($tables as $t) {
  972. if (in_array($t, $models)) {
  973. if ($t=='content') {
  974. $model = $_POST['model'];
  975. $db = pc_base::load_model('content_model');
  976. //读取网站的所有模型
  977. $model_arr = getcache('model', 'commons');
  978. foreach ($model as $modelid) {
  979. $db->set_model($modelid);
  980. if ($r = $db->count()) { //判断模型下是否有数据
  981. $sql_file = CACHE_PATH.'bakup'.DIRECTORY_SEPARATOR.'default'.DIRECTORY_SEPARATOR.$model_arr[$modelid]['tablename'].'.sql';
  982. $result = $data = $db->select();
  983. $this->create_sql_file($result, $db->db_tablepre.$model_arr[$modelid]['tablename'], $sql_file);
  984. $db->query('TRUNCATE TABLE `phpcms_'.$model_arr[$modelid]['tablename'].'`');
  985. //开始清理模型data表数据
  986. $db->table_name = $db->table_name.'_data';
  987. $sql_file = CACHE_PATH.'bakup'.DIRECTORY_SEPARATOR.'default'.DIRECTORY_SEPARATOR.$model_arr[$modelid]['tablename'].'_data.sql';
  988. $result = $db->select();
  989. $this->create_sql_file($result, $db->db_tablepre.$model_arr[$modelid]['tablename'].'_data', $sql_file);
  990. $db->query('TRUNCATE TABLE `phpcms_'.$model_arr[$modelid]['tablename'].'_data`');
  991. //删除该模型中在hits表的数据
  992. $hits_db = pc_base::load_model('hits_model');
  993. $hitsid = 'c-'.$modelid.'-';
  994. $result = $hits_db->select("`hitsid` LIKE '%$hitsid%'");
  995. if (is_array($result)) {
  996. $sql_file = CACHE_PATH.'bakup'.DIRECTORY_SEPARATOR.'default'.DIRECTORY_SEPARATOR.'hits-'.$modelid.'.sql';
  997. $this->create_sql_file($result, $hits_db->db_tablepre.'hits', $sql_file);
  998. }
  999. $hits_db->delete("`hitsid` LIKE '%$hitsid%'");
  1000. //删除该模型在search中的数据
  1001. $search_db = pc_base::load_model('search_model');
  1002. $type_model = getcache('type_model_'.$model_arr[$modelid]['siteid'], 'search');
  1003. $typeid = $type_model[$modelid];
  1004. $result = $search_db->select("`typeid`=".$typeid);
  1005. if (is_array($result)) {
  1006. $sql_file = CACHE_PATH.'bakup'.DIRECTORY_SEPARATOR.'default'.DIRECTORY_SEPARATOR.'search-'.$modelid.'.sql';
  1007. $this->create_sql_file($result, $search_db->db_tablepre.'search', $sql_file);
  1008. }
  1009. $search_db->delete("`typeid`=".$typeid);
  1010. //Delete the model data in the position table
  1011. $position_db = pc_base::load_model('position_data_model');
  1012. $result = $position_db->select('`modelid`='.$modelid.' AND `module`=\'content\'');
  1013. if (is_array($result)) {
  1014. $sql_file = CACHE_PATH.'bakup'.DIRECTORY_SEPARATOR.'default'.DIRECTORY_SEPARATOR.'position_data-'.$modelid.'.sql';
  1015. $this->create_sql_file($result, $position_db->db_tablepre.'position_data', $sql_file);
  1016. }
  1017. $position_db->delete('`modelid`='.$modelid.' AND `module`=\'content\'');
  1018. //清理视频库与内容对应关系表
  1019. if (module_exists('video')) {
  1020. $video_content_db = pc_base::load_model('video_content_model');
  1021. $result = $video_content_db->select('`modelid`=\''.$modelid.'\'');
  1022. if (is_array($result)) {
  1023. $sql_file = CACHE_PATH.'bakup'.DIRECTORY_SEPARATOR.'default'.DIRECTORY_SEPARATOR.'video_content-'.$modelid.'.sql';
  1024. $this->create_sql_file($result, $video_content_db->db_tablepre.'video_content', $sql_file);
  1025. }
  1026. $video_content_db->delete('`modelid`=\''.$modelid.'\'');
  1027. }
  1028. //清理评论表及附件表,附件的清理为不可逆操作。
  1029. //附件初始化
  1030. //$attachment = pc_base::load_model('attachment_model');
  1031. //$comment = pc_base::load_app_class('comment', 'comment');
  1032. //if(module_exists('comment')){
  1033. //$comment_exists = 1;
  1034. //}
  1035. //foreach ($data as $d) {
  1036. //$attachment->api_delete('c-'.$d['catid'].'-'.$d['id']);
  1037. //if ($comment_exists) {
  1038. //$commentid = id_encode('content_'.$d['catid'], $d['id'], $model_arr[$modelid]['siteid']);
  1039. //$comment->del($commentid, $model_arr[$modelid]['siteid'], $d['id'], $d['catid']);
  1040. //}
  1041. //}
  1042. }
  1043. }
  1044. } elseif ($t=='comment') {
  1045. $comment_db = pc_base::load_model('comment_data_model');
  1046. for($i=1;;$i++) {
  1047. $comment_db->table_name($i);
  1048. if ($comment_db->table_exists(str_replace($comment_db->db_tablepre, '', $comment_db->table_name))) {
  1049. if ($r = $comment_db->count()) {
  1050. $sql_file = CACHE_PATH.'bakup'.DIRECTORY_SEPARATOR.'default'.DIRECTORY_SEPARATOR.'comment_data_'.$i.'.sql';
  1051. $result = $comment_db->select();
  1052. $this->create_sql_file($result, $comment_db->db_tablepre.'comment_data_'.$i, $sql_file);
  1053. $comment_db->query('TRUNCATE TABLE `phpcms_comment_data_'.$i.'`');
  1054. }
  1055. } else {
  1056. break;
  1057. }
  1058. }
  1059. } else {
  1060. $db = pc_base::load_model($t.'_model');
  1061. if ($r = $db->count()) {
  1062. $result = $db->select();
  1063. $sql_file = CACHE_PATH.'bakup'.DIRECTORY_SEPARATOR.'default'.DIRECTORY_SEPARATOR.$t.'.sql';
  1064. $this->create_sql_file($result, $db->db_tablepre.$t, $sql_file);
  1065. $db->query('TRUNCATE TABLE `phpcms_'.$t.'`');
  1066. }
  1067. }
  1068. }
  1069. }
  1070. }
  1071. showmessage(L('clear_data_message'));
  1072. } else {
  1073. //读取网站的所有模型
  1074. $model_arr = getcache('model', 'commons');
  1075. include $this->admin_tpl('clear_data');
  1076. }
  1077. }
  1078. /**
  1079. * 备份数据到文件
  1080. * @param $data array 备份的数据数组
  1081. * @param $tablename 数据所属数据表
  1082. * @param $file 备份到的文件
  1083. */
  1084. private function create_sql_file($data, $db, $file) {
  1085. if (is_array($data)) {
  1086. $sql = '';
  1087. foreach ($data as $d) {
  1088. $tag = '';
  1089. $sql .= "INSERT INTO `".$db.'` VALUES(';
  1090. foreach ($d as $_f => $_v) {
  1091. $sql .= $tag.'\''.addslashes($_v).'\'';
  1092. $tag = ',';
  1093. }
  1094. $sql .= ');'."\r\n";
  1095. }
  1096. file_put_contents($file, $sql);
  1097. }
  1098. return true;
  1099. }
  1100. }
  1101. ?>