content.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. <?php
  2. defined('IN_PHPCMS') or exit('No permission resources.');
  3. pc_base::load_app_class('admin','admin',0);
  4. pc_base::load_sys_class('form', '', 0);
  5. pc_base::load_sys_class('format', '', 0);
  6. class content extends admin {
  7. private $db, $data_db, $type_db;
  8. public function __construct() {
  9. parent::__construct();
  10. $this->db = pc_base::load_model('special_content_model');
  11. $this->data_db = pc_base::load_model('special_c_data_model');
  12. $this->type_db = pc_base::load_model('type_model');
  13. }
  14. /**
  15. * 添加信息
  16. */
  17. public function add() {
  18. $_GET['specialid'] = intval($_GET['specialid']);
  19. if (!$_GET['specialid']) showmessage(L('illegal_action'), HTTP_REFERER);
  20. if ($_POST['dosubmit'] || $_POST['dosubmit_continue']) {
  21. $info = $this->check($_POST['info'], 'info', 'add', $_POST['data']['content']); //验证数据的合法性
  22. //处理外部链接情况
  23. if ($info['islink']) {
  24. $info['url'] = $_POST['linkurl'];
  25. $info['isdata'] = 0;
  26. } else {
  27. $info['isdata'] = 1;
  28. }
  29. $info['specialid'] = $_GET['specialid'];
  30. //将基础数据添加到基础表,并返回ID
  31. $contentid = $this->db->insert($info, true);
  32. // 向数据统计表添加数据
  33. $count = pc_base::load_model('hits_model');
  34. $hitsid = 'special-c-'.$info['specialid'].'-'.$contentid;
  35. $count->insert(array('hitsid'=>$hitsid));
  36. //如果不是外部链接,将内容加到data表中
  37. $html = pc_base::load_app_class('html');
  38. if ($info['isdata']) {
  39. $data = $this->check($_POST['data'], 'data'); //验证数据的合法性
  40. $data['id'] = $contentid;
  41. $this->data_db->insert($data);
  42. $searchid = $this->search_api($contentid, $data, $info['title'], 'update', $info['inputtime']);
  43. $url = $html->_create_content($contentid);
  44. $this->db->update(array('url'=>$url[0], 'searchid'=>$searchid), array('id'=>$contentid, 'specialid'=>$_GET['specialid']));
  45. }
  46. $html->_index($_GET['specialid'], 20, 5);
  47. $html->_list($info['typeid'], 20, 5);
  48. //更新附件状态
  49. if(pc_base::load_config('system','attachment_stat')) {
  50. $this->attachment_db = pc_base::load_model('attachment_model');
  51. if ($info['thunb']) {
  52. $this->attachment_db->api_update($info['thumb'],'special-c-'.$contentid, 1);
  53. }
  54. $this->attachment_db->api_update(stripslashes($data['content']),'special-c-'.$contentid);
  55. }
  56. if ($_POST['dosubmit']) showmessage(L('content_add_success'), HTTP_REFERER, '', '', 'setTimeout("window.close()", 2000)');
  57. elseif ($_POST['dosubmit_continue']) showmessage(L('content_add_success'), HTTP_REFERER);
  58. } else {
  59. $rs = $this->type_db->select(array('parentid'=>$_GET['specialid'], 'siteid'=>$this->get_siteid()), 'typeid, name');
  60. $types = array();
  61. foreach ($rs as $r) {
  62. $types[$r['typeid']] = $r['name'];
  63. }
  64. //获取站点模板信息
  65. pc_base::load_app_func('global', 'admin');
  66. $template_list = template_list(get_siteid(), 0);
  67. foreach ($template_list as $k=>$v) {
  68. $template_list[$v['dirname']] = $v['name'] ? $v['name'] : $v['dirname'];
  69. unset($template_list[$k]);
  70. }
  71. $special_db = pc_base::load_model('special_model');
  72. $info = $special_db->get_one(array('id'=>$_GET['specialid']));
  73. @extract($info);
  74. include $this->admin_tpl('content_add');
  75. }
  76. }
  77. /**
  78. * 信息修改
  79. */
  80. public function edit() {
  81. $_GET['specialid'] = intval($_GET['specialid']);
  82. $_GET['id'] = intval($_GET['id']);
  83. if (!$_GET['specialid'] || !$_GET['id']) showmessage(L('illegal_action'), HTTP_REFERER);
  84. if (isset($_POST['dosubmit']) || isset($_POST['dosubmit_continue'])) {
  85. $info = $this->check($_POST['info'], 'info', 'edit', $_POST['data']['content']); //验证数据的合法性
  86. //处理外部链接更换情况
  87. $r = $this->db->get_one(array('id'=>$_GET['id'], 'specialid'=>$_GET['specialid']));
  88. if ($r['islink']!=$info['islink']) { //当外部链接和原来差别时进行操作
  89. // 向数据统计表添加数据
  90. $count = pc_base::load_model('hits_model');
  91. $hitsid = 'special-c-'.$_GET['specialid'].'-'.$_GET['id'];
  92. $count->delete(array('hitsid'=>$hitsid));
  93. $this->data_db->delete(array('id'=>$_GET['id']));
  94. if ($info['islink']) {
  95. $info['url'] = $_POST['linkurl'];
  96. $info['isdata'] = 0;
  97. } else {
  98. $data = $this->check($_POST['data'], 'data');
  99. $data['id'] = $_GET['id'];
  100. $this->data_db->insert($data);
  101. $count->insert(array('hitsid'=>$hitsid));
  102. }
  103. }
  104. //处理外部链接情况
  105. if ($info['islink']) {
  106. $info['url'] = $_POST['linkurl'];
  107. $info['isdata'] = 0;
  108. } else {
  109. $info['isdata'] = 1;
  110. }
  111. $html = pc_base::load_app_class('html', 'special');
  112. if ($info['isdata']) {
  113. $data = $this->check($_POST['data'], 'data');
  114. $this->data_db->update($data, array('id'=>$_GET['id']));
  115. $url = $html->_create_content($_GET['id']);
  116. if ($url[0]) {
  117. $info['url'] = $url[0];
  118. $searchid = $this->search_api($_GET['id'], $data, $info['title'], 'update', $info['inputtime']);
  119. $this->db->update(array('url'=>$url[0], 'searchid'=>$searchid), array('id'=>$_GET['id'], 'specialid'=>$_GET['specialid']));
  120. }
  121. } else {
  122. $this->db->update(array('url'=>$info['url']), array('id'=>$_GET['id'], 'specialid'=>$_GET['specialid']));
  123. }
  124. $this->db->update($info, array('id'=>$_GET['id'], 'specialid'=>$_GET['specialid']));
  125. //更新附件状态
  126. if(pc_base::load_config('system','attachment_stat')) {
  127. $this->attachment_db = pc_base::load_model('attachment_model');
  128. if ($info['thumb']) {
  129. $this->attachment_db->api_update($info['thumb'],'special-c-'.$_GET['id'], 1);
  130. }
  131. $this->attachment_db->api_update(stripslashes($data['content']),'special-c-'.$_GET['id']);
  132. }
  133. $html->_index($_GET['specialid'], 20, 5);
  134. $html->_list($info['typeid'], 20, 5);
  135. showmessage(L('content_edit_success'), HTTP_REFERER, '', '', 'setTimeout("window.close()", 2000)');
  136. } else {
  137. $info = $this->db->get_one(array('id'=>$_GET['id'], 'specialid'=>$_GET['specialid']));
  138. if($info['isdata']) $data = $this->data_db->get_one(array('id'=>$_GET['id']));
  139. $rs = $this->type_db->select(array('parentid'=>$_GET['specialid'], 'siteid'=>$this->get_siteid()), 'typeid, name');
  140. $types = array();
  141. foreach ($rs as $r) {
  142. $types[$r['typeid']] = $r['name'];
  143. }
  144. //获取站点模板信息
  145. pc_base::load_app_func('global', 'admin');
  146. $template_list = template_list($this->siteid, 0);
  147. foreach ($template_list as $k=>$v) {
  148. $template_list[$v['dirname']] = $v['name'] ? $v['name'] : $v['dirname'];
  149. unset($template_list[$k]);
  150. }
  151. $special_db = pc_base::load_model('special_model');
  152. $s_info = $special_db->get_one(array('id'=>$_GET['specialid']));
  153. @extract($s_info);
  154. include $this->admin_tpl('content_edit');
  155. }
  156. }
  157. /**
  158. * 检查表题是否重复
  159. */
  160. public function public_check_title() {
  161. if ($_GET['data']=='' || (!$_GET['specialid'])) return '';
  162. if (pc_base::load_config('system', 'charset')=='gbk') {
  163. $title = safe_replace(iconv('UTF-8', 'GBK', $_GET['data']));
  164. } else $title = $_GET['data'];
  165. $specialid = intval($_GET['specialid']);
  166. $r = $this->db->get_one(array('title'=>$title, 'specialid'=>$specialid));
  167. if ($r) {
  168. exit('1');
  169. } else {
  170. exit('0');
  171. }
  172. }
  173. /**
  174. * 信息列表
  175. */
  176. public function init() {
  177. $_GET['specialid'] = intval($_GET['specialid']);
  178. if(!$_GET['specialid']) showmessage(L('illegal_action'), HTTP_REFERER);
  179. $types = $this->type_db->select(array('module'=>'special', 'parentid'=>$_GET['specialid']), 'name, typeid', '', '`listorder` ASC, `typeid` ASC', '', 'typeid');
  180. $page = max(intval($_GET['page']), 1);
  181. $datas = $this->db->listinfo(array('specialid'=>$_GET['specialid']), '`listorder` ASC , `id` DESC', $page);
  182. $pages = $this->db->pages;
  183. $big_menu = array(array('javascript:openwinx(\'?m=special&c=content&a=add&specialid='.$_GET['specialid'].'\',\'\');void(0);', L('add_content')), array('javascript:window.top.art.dialog({id:\'import\',iframe:\'?m=special&c=special&a=import&specialid='.$_GET['specialid'].'\', title:\''.L('import_content').'\', width:\'700\', height:\'500\', lock:true}, function(){var d = window.top.art.dialog({id:\'import\'}).data.iframe;var form = d.document.getElementById(\'dosubmit\');form.click();return false;}, function(){window.top.art.dialog({id:\'import\'}).close()});void(0);', L('import_content')));
  184. include $this->admin_tpl('content_list');
  185. }
  186. /**
  187. * 信息排序 信息调用时按排序从小到大排列
  188. */
  189. public function listorder() {
  190. $_GET['specialid'] = intval($_GET['specialid']);
  191. if (!$_GET['specialid']) showmessage(L('illegal_action'), HTTP_REFERER);
  192. foreach ($_POST['listorders'] as $id => $v) {
  193. $this->db->update(array('listorder'=>$v), array('id'=>$id, 'specialid'=>$_GET['specialid']));
  194. }
  195. showmessage(L('operation_success'), HTTP_REFERER);
  196. }
  197. /**
  198. * 删除信息
  199. */
  200. public function delete() {
  201. if (!isset($_POST['id']) || empty($_POST['id']) || !$_GET['specialid']) {
  202. showmessage(L('illegal_action'), HTTP_REFERER);
  203. }
  204. $specialid = $_GET['specialid'];
  205. $special = pc_base::load_model('special_model');
  206. $info = $special->get_one(array('id'=>$specialid));
  207. $special_api = pc_base::load_app_class('special_api', 'special');
  208. if (is_array($_POST['id'])) {
  209. foreach ($_POST['id'] as $sid) {
  210. $sid = intval($sid);
  211. $special_api->_delete_content($sid, $info['siteid'], $info['ishtml']);
  212. if(pc_base::load_config('system','attachment_stat')) {
  213. $keyid = 'special-c-'.$sid;
  214. $this->attachment_db = pc_base::load_model('attachment_model');
  215. $this->attachment_db->api_delete($keyid);
  216. }
  217. }
  218. } elseif (is_numeric($_POST['id'])){
  219. $id = intval($_POST['id']);
  220. $special_api->_delete_content($id, $info['siteid'], $info['ishtml']);
  221. if(pc_base::load_config('system','attachment_stat')) {
  222. $keyid = 'special-c-'.$id;
  223. $this->attachment_db = pc_base::load_model('attachment_model');
  224. $this->attachment_db->api_delete($keyid);
  225. }
  226. }
  227. showmessage(L('operation_success'), HTTP_REFERER);
  228. }
  229. /**
  230. * 添加到全站搜索
  231. * @param intval $id 文章ID
  232. * @param array $data 数组
  233. * @param string $title 标题
  234. * @param string $action 动作
  235. */
  236. private function search_api($id = 0, $data = array(), $title, $action = 'update', $addtime) {
  237. $this->search_db = pc_base::load_model('search_model');
  238. $siteid = $this->get_siteid();
  239. $type_arr = getcache('type_module_'.$siteid,'search');
  240. $typeid = $type_arr['special'];
  241. if($action == 'update') {
  242. $fulltextcontent = $data['content'];
  243. return $this->search_db->update_search($typeid ,$id, $fulltextcontent,$title, $addtime);
  244. } elseif($action == 'delete') {
  245. $this->search_db->delete_search($typeid ,$id);
  246. }
  247. }
  248. /**
  249. * 表单验证
  250. * @param array $data 表单数据
  251. * @param string $type 按数据表数据判断
  252. * @param string $action 在添加时会加上默认数据
  253. * @return array 数据检验后返回的数组
  254. */
  255. private function check($data = array(), $type = 'info', $action = 'add', $content = '') {
  256. if ($type == 'info') {
  257. if (!$data['title']) showmessage(L('title_no_empty'), HTTP_REFERER);
  258. if (!$data['typeid']) showmessage(L('no_select_type'), HTTP_REFERER);
  259. $data['inputtime'] = $data['inputtime'] ? strtotime($data['inputtime']) : SYS_TIME;
  260. $data['islink'] = $data['islink'] ? intval($data['islink']) : 0;
  261. $data['style'] = '';
  262. if ($data['style_color']) {
  263. $data['style'] .= 'color:#00FF99;';
  264. }
  265. if ($data['style_font_weight']) {
  266. $data['style'] .= 'font-weight:bold;';
  267. }
  268. //截取简介
  269. if ($_POST['add_introduce'] && $data['description']=='' && !empty($content)) {
  270. $content = stripslashes($content);
  271. $introcude_length = intval($_POST['introcude_length']);
  272. $data['description'] = str_cut(str_replace(array("\r\n","\t"), '', strip_tags($content)),$introcude_length);
  273. }
  274. //自动提取缩略图
  275. if (isset($_POST['auto_thumb']) && $data['thumb'] == '' && !empty($content)) {
  276. $content = stripslashes($content);
  277. $auto_thumb_no = intval($_POST['auto_thumb_no']) - 1;
  278. if (preg_match_all("/(src)=([\"|']?)([^ \"'>]+\.(gif|jpg|jpeg|bmp|png))\\2/i", $content, $matches)) {
  279. $data['thumb'] = $matches[3][$auto_thumb_no];
  280. }
  281. }
  282. unset($data['style_color'], $data['style_font_weight']);
  283. if ($action == 'add') {
  284. $data['updatetime'] = SYS_TIME;
  285. $data['username'] = param::get_cookie('admin_username');
  286. $data['userid'] = $_SESSION['userid'];
  287. }
  288. } elseif ($type == 'data') {
  289. if (!$data['content']) showmessage(L('content_no_empty'), HTTP_REFERER);
  290. }
  291. return $data;
  292. }
  293. }