special.php 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502
  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 special extends admin {
  7. private $db, $special_api;
  8. function __construct() {
  9. parent::__construct();
  10. $this->db = pc_base::load_model('special_model');
  11. $this->special_api = pc_base::load_app_class('special_api', 'special');
  12. }
  13. /**
  14. * 专题列表
  15. */
  16. public function init() {
  17. $page = max(intval($_GET['page']), 1);
  18. $infos = $this->db->listinfo(array('siteid'=>$this->get_siteid()), '`listorder` DESC, `id` DESC', $page, 6);
  19. pc_base::load_sys_class('format', '', 0);
  20. include $this->admin_tpl('special_list');
  21. }
  22. /**
  23. * 添加专题
  24. */
  25. public function add() {
  26. if (isset($_POST['dosubmit']) && !empty($_POST['dosubmit'])) {
  27. $special = $this->check($_POST['special']);
  28. $id = $this->db->insert($special, true);
  29. if ($id) {
  30. $this->special_api->_update_type($id, $_POST['type']);
  31. if ($special['siteid']>1) {
  32. $site = pc_base::load_app_class('sites', 'admin');
  33. $site_info = $site->get_by_id($special['siteid']);
  34. if ($special['ishtml']) {
  35. $special['filename'] = str_replace('..','',$special['filename']);
  36. $url = $site_info['domain'].'special/'.$special['filename'].'/';
  37. } else {
  38. $url = $site_info['domain'].'index.php?m=special&c=index&id='.$id;
  39. }
  40. } else {
  41. $url = $special['ishtml'] ? APP_PATH.substr(pc_base::load_config('system', 'html_root'), 1).'/special/'.$special['filename'].'/' : APP_PATH.'index.php?m=special&c=index&id='.$id;
  42. }
  43. $this->db->update(array('url'=>$url), array('id'=>$id, 'siteid'=>$this->get_siteid()));
  44. //调用生成静态类
  45. if ($special['ishtml']) {
  46. $html = pc_base::load_app_class('html', 'special');
  47. $html->_index($id, 20, 5);
  48. }
  49. //更新附件状态
  50. if(pc_base::load_config('system','attachment_stat')) {
  51. $this->attachment_db = pc_base::load_model('attachment_model');
  52. $this->attachment_db->api_update(array($special['thumb'], $special['banner']),'special-'.$id, 1);
  53. }
  54. $this->special_cache();
  55. }
  56. showmessage(L('add_special_success'), HTTP_REFERER);
  57. } else {
  58. //获取站点模板信息
  59. pc_base::load_app_func('global', 'admin');
  60. $siteid = $this->get_siteid();
  61. $template_list = template_list($siteid, 0);
  62. $site = pc_base::load_app_class('sites','admin');
  63. $info = $site->get_by_id($siteid);
  64. foreach ($template_list as $k=>$v) {
  65. $template_list[$v['dirname']] = $v['name'] ? $v['name'] : $v['dirname'];
  66. unset($template_list[$k]);
  67. }
  68. include $this->admin_tpl('special_add');
  69. }
  70. }
  71. /**
  72. * 专题修改
  73. */
  74. public function edit() {
  75. if (!isset($_GET['specialid']) || empty($_GET['specialid'])) {
  76. showmessage(L('illegal_action'), HTTP_REFERER);
  77. }
  78. $_GET['specialid'] = intval($_GET['specialid']);
  79. if (isset($_POST['dosubmit']) && !empty($_POST['dosubmit'])) {
  80. $special = $this->check($_POST['special'], 'edit');
  81. $siteid = get_siteid();
  82. $site = pc_base::load_app_class('sites', 'admin');
  83. $site_info = $site->get_by_id($siteid);
  84. if ($special['ishtml'] && $special['filename']) {
  85. $special['filename'] = str_replace('..','',$special['filename']);
  86. if ($siteid>1) {
  87. $special['url'] = $site_info['domain'].'special/'.$special['filename'].'/';
  88. } else {
  89. $special['url'] = APP_PATH.substr(pc_base::load_config('system', 'html_root'), 1).'/special/'.$special['filename'].'/';
  90. }
  91. } elseif ($special['ishtml']=='0') {
  92. if ($siteid>1) {
  93. $special['url'] = $site_info['domain'].'index.php?m=special&c=index&specialid='.$_GET['specialid'];
  94. } else {
  95. $special['url'] = APP_PATH.'index.php?m=special&c=index&specialid='.$_GET['specialid'];
  96. }
  97. }
  98. $this->db->update($special, array('id'=>$_GET['specialid'], 'siteid'=>$this->get_siteid()));
  99. $this->special_api->_update_type($_GET['specialid'], $_POST['type'], 'edit');
  100. //调用生成静态类
  101. if ($special['ishtml']) {
  102. $html = pc_base::load_app_class('html', 'special');
  103. $html->_index($_GET['specialid'], 20, 5);
  104. }
  105. //更新附件状态
  106. if(pc_base::load_config('system','attachment_stat')) {
  107. $this->attachment_db = pc_base::load_model('attachment_model');
  108. $this->attachment_db->api_update(array($special['thumb'], $special['banner']),'special-'.$_GET['specialid'], 1);
  109. }
  110. $this->special_cache();
  111. showmessage(L('edit_special_success'), HTTP_REFERER);
  112. } else {
  113. $info = $this->db->get_one(array('id'=>$_GET['specialid'], 'siteid'=>$this->get_siteid()));
  114. //获取站点模板信息
  115. pc_base::load_app_func('global', 'admin');
  116. $template_list = template_list($this->siteid, 0);
  117. foreach ($template_list as $k=>$v) {
  118. $template_list[$v['dirname']] = $v['name'] ? $v['name'] : $v['dirname'];
  119. unset($template_list[$k]);
  120. }
  121. if ($info['pics']) {
  122. $pics = explode('|', $info['pics']);
  123. }
  124. if ($info['voteid']) {
  125. $vote_info = explode('|', $info['voteid']);
  126. }
  127. $type_db = pc_base::load_model('type_model');
  128. $types = $type_db->select(array('module'=>'special', 'parentid'=>$_GET['specialid'], 'siteid'=>$this->get_siteid()), '`typeid`, `name`, `listorder`, `typedir`', '', '`listorder` ASC, `typeid` ASC');
  129. include $this->admin_tpl('special_edit');
  130. }
  131. }
  132. /**
  133. * 信息导入专题
  134. */
  135. public function import() {
  136. if(isset($_POST['dosubmit']) || isset($_GET['dosubmit'])) {
  137. if(!is_array($_POST['ids']) || empty($_POST['ids']) || !$_GET['modelid']) showmessage(L('illegal_action'), HTTP_REFERER);
  138. if(!isset($_POST['typeid']) || empty($_POST['typeid'])) showmessage(L('select_type'), HTTP_REFERER);
  139. foreach($_POST['ids'] as $id) {
  140. $this->special_api->_import($_GET['modelid'], $_GET['specialid'], $id, $_POST['typeid'], $_POST['listorder'][$id]);
  141. }
  142. $html = pc_base::load_app_class('html', 'special');
  143. $html->_index($_GET['specialid'], 20, 5);
  144. showmessage(L('import_success'), 'blank', '', 'import');
  145. } else {
  146. if(!$_GET['specialid']) showmessage(L('illegal_action'), HTTP_REFERER);
  147. $_GET['modelid'] = $_GET['modelid'] ? intval($_GET['modelid']) : 0;
  148. $_GET['catid'] = $_GET['catid'] ? intval($_GET['catid']) : 0;
  149. $_GET['page'] = max(intval($_GET['page']), 1);
  150. $where = '';
  151. if($_GET['catid']) $where .= get_sql_catid('category_content_'.$this->get_siteid(), $_GET['catid'])." AND `status`=99";
  152. else $where .= " `status`=99";
  153. if($_GET['start_time']) {
  154. $where .= " AND `inputtime`>=".strtotime($_GET['start_time']);
  155. }
  156. if($_GET['end_time']) {
  157. $where .= " AND `inputtime`<=".strtotime($_GET['end_time']);
  158. }
  159. if ($_GET['key']) {
  160. $where .= " AND `title` LIKE '%$_GET[key]%' OR `keywords` LIKE '%$_GET[key]%'";
  161. }
  162. $data = $this->special_api->_get_import_data($_GET['modelid'], $where, $_GET['page']);
  163. $pages = $this->special_api->pages;
  164. $models = getcache('model','commons');
  165. $model_datas = array();
  166. foreach($models as $_k=>$_v) {
  167. if($_v['siteid']==$this->get_siteid()) {
  168. $model_datas[$_v['modelid']] = $_v['name'];
  169. }
  170. }
  171. $model_form = form::select($model_datas, $_GET['modelid'], 'name="modelid" onchange="select_categorys(this.value)"', L('select_model'));
  172. $types = $this->special_api->_get_types($_GET['specialid']);
  173. include $this->admin_tpl('import_content');
  174. }
  175. }
  176. public function public_get_pics() {
  177. $_GET['modelid'] = $_GET['modelid'] ? intval($_GET['modelid']) : 0;
  178. $_GET['catid'] = $_GET['catid'] ? intval($_GET['catid']) : 0;
  179. $_GET['page'] = max(intval($_GET['page']), 1);
  180. $where = '';
  181. if($_GET['catid']) $where .= get_sql_catid('category_content_'.$this->get_siteid(), $_GET['catid'])." AND `status`=99";
  182. else $where .= " `status`=99";
  183. if ($_GET['title']) {
  184. $where .= " AND `title` LIKE '%".$_GET['title']."%'";
  185. }
  186. if($_GET['start_time']) {
  187. $where .= " AND `inputtime`>=".strtotime($_GET['start_time']);
  188. }
  189. if($_GET['end_time']) {
  190. $where .= " AND `inputtime`<=".strtotime($_GET['end_time']);
  191. }
  192. $data = $this->special_api->_get_import_data($_GET['modelid'], $where, $_GET['page']);
  193. $pages = $this->special_api->pages;
  194. $models = getcache('model','commons');
  195. $model_datas = array();
  196. foreach($models as $_k=>$_v) {
  197. if($_v['siteid']==$this->get_siteid()) {
  198. $model_datas[$_v['modelid']] = $_v['name'];
  199. }
  200. }
  201. $model_form = form::select($model_datas, $_GET['modelid'], 'name="modelid" onchange="select_categorys(this.value)"', L('select_model'));
  202. $types = $this->special_api->_get_types($_GET['specialid']);
  203. include $this->admin_tpl('import_pics');
  204. }
  205. public function html() {
  206. if((!isset($_POST['id']) || empty($_POST['id']))) {
  207. $result = $this->db->select(array('disabled'=>0, 'siteid'=>$this->get_siteid()), 'id', '', '', '', 'id');
  208. $id = array_keys($result);
  209. } else {
  210. $id = $_POST['id'];
  211. }
  212. setcache('create_specials', $id, 'commons');
  213. $this->public_create_html();
  214. }
  215. public function create_special_list() {
  216. $siteid = get_siteid();
  217. $html = pc_base::load_app_class('html');
  218. $c = pc_base::load_model('special_model');
  219. $result = $c->get_one(array('siteid'=>$siteid), 'COUNT(*) AS total');
  220. $total = $result['total'];
  221. $pages = ceil($total/20);
  222. for ( $i=1; $i <= $pages ; $i++ ){
  223. $size = $html->create_list($i);
  224. }
  225. showmessage(L('index_create_finish',array('size'=>sizecount($size))));
  226. }
  227. /**
  228. * 专题排序
  229. */
  230. public function listorder() {
  231. if(isset($_POST['dosubmit'])) {
  232. foreach($_POST['listorder'] as $id => $order) {
  233. $id = intval($id);
  234. $order = intval($order);
  235. $this->db->update(array('listorder'=>$order), array('id'=>$id));
  236. }
  237. $this->special_cache();
  238. showmessage(L('operation_success'), HTTP_REFERER);
  239. } else {
  240. showmessage(L('please_in_admin'), HTTP_REFERER);
  241. }
  242. }
  243. //生成专题首页控制中心
  244. public function public_create_html() {
  245. $specials = getcache('create_specials', 'commons');
  246. if (is_array($specials) && !empty($specials)) {
  247. $specialid = array_shift($specials);
  248. setcache('create_specials', $specials, 'commons');
  249. $this->create_index($specialid);
  250. } else {
  251. delcache('create_specials', 'commons');
  252. showmessage(L('update_special_success'), '?m=special&c=special&a=init');
  253. }
  254. }
  255. //生成某专题首页
  256. private function create_index($specialid) {
  257. $info = $this->db->get_one(array('id'=>$specialid));
  258. if (!$info['ishtml']) {
  259. showmessage($info['title'].L('update_success'), '?m=special&c=special&a=public_create_html');
  260. }
  261. $html = pc_base::load_app_class('html');
  262. $html->_index($specialid);
  263. showmessage($info['title'].L('index_update_success'), '?m=special&c=special&a=public_create_type&specialid='.$specialid);
  264. }
  265. //生成专题里列表页
  266. public function public_create_type() {
  267. $specialid = $_GET['specialid'] ? intval($_GET['specialid']) : 0;
  268. if (!$specialid) showmessage(L('illegal_action'));
  269. $page = isset($_GET['page']) ? intval($_GET['page']) : 1;
  270. $pages = isset($_GET['pages']) ? intval($_GET['pages']) : 0;
  271. $types = getcache('create_types', 'commons');
  272. if (is_array($types) && !empty($types) || $pages) {
  273. if (!isset($page) || $page==1) {
  274. $typeids = array_keys($types);
  275. $typeid = array_shift($typeids);
  276. $typename = $types[$typeid];
  277. unset($types[$typeid]);
  278. setcache('create_types', $types, 'commons');
  279. }
  280. if (!$pages) {
  281. $c = pc_base::load_model('special_content_model');
  282. $result = $c->get_one(array('typeid'=>$typeid), 'COUNT(*) AS total');
  283. $total = $result['total'];
  284. $pages = ceil($total/20);
  285. }
  286. if ($_GET['typeid']) {
  287. $typeid = intval($_GET['typeid']);
  288. $typename = $_GET['typename'];
  289. }
  290. $maxpage = $page+10;
  291. if ($maxpage>$pages) {
  292. $maxpage = $pages;
  293. }
  294. for ($page; $page<=$maxpage; $page++) {
  295. $html = pc_base::load_app_class('html');
  296. $html->create_type($typeid, $page);
  297. }
  298. if (empty($types) && $pages==$maxpage) {
  299. delcache('create_types', 'commons');
  300. showmessage($typename.L('type_update_success'), '?m=special&c=special&a=public_create_content&specialid='.$specialid);
  301. }
  302. if ($pages<=$maxpage) {
  303. showmessage($typename.L('update_success'), '?m=special&c=special&a=public_create_type&specialid='.$specialid);
  304. } else {
  305. showmessage($typename.L('type_from').($_GET['page'] ? $_GET['page'] : 1).L('type_end').$maxpage.'</font> '.L('update_success'), '?m=special&c=special&a=public_create_type&typeid='.$typeid.'&typename='.$typename.'&page='.$page.'&pages='.$pages.'&specialid='.$specialid);
  306. }
  307. } else {
  308. $special_api = pc_base::load_app_class('special_api');
  309. $types = $special_api->_get_types($specialid);
  310. setcache('create_types', $types, 'commons');
  311. showmessage(L('start_update_type'), '?m=special&c=special&a=public_create_type&specialid='.$specialid);
  312. }
  313. }
  314. //生成内容页
  315. public function public_create_content() {
  316. $specialid = $_GET['specialid'] ? intval($_GET['specialid']) : 0;
  317. if (!$specialid) showmessage(L('illegal_action'));
  318. $pages = $_GET['pages'] ? intval($_GET['pages']) : 0;
  319. $page = $_GET['page'] ? intval($_GET['page']) : 1;
  320. $c = pc_base::load_model('special_content_model');
  321. if (!$pages) {
  322. $result = $c->get_one(array('specialid'=>$specialid, 'isdata'=>1), 'COUNT(*) AS total');
  323. $total = $result['total'];
  324. $pages = ceil($total/10);
  325. }
  326. $offset = ($page-1)*10;
  327. $result = $c->select(array('specialid'=>$specialid, 'isdata'=>1), 'id', $offset.', 10', 'listorder ASC, id ASC');
  328. foreach ($result as $r) {
  329. $html = pc_base::load_app_class('html');
  330. $urls = $html->_create_content($r['id']);
  331. $c->update(array('url'=>$urls[0]), array('id'=>$r['id']));
  332. }
  333. if ($page>=$pages) {
  334. showmessage(L('content_update_success'), '?m=special&c=special&a=public_create_html&specialid='.$specialid);
  335. } else {
  336. $page++;
  337. showmessage(L('content_from').' <font color="red">'.intval($offset+1).L('type_end').intval($offset+10).'</font> '.L('update_success'), '?m=special&c=special&a=public_create_content&specialid='.$specialid.'&page='.$page.'&pages='.$pages);
  338. }
  339. }
  340. /**
  341. * 推荐专题
  342. */
  343. public function elite() {
  344. if(!isset($_GET['id']) || empty($_GET['id'])) {
  345. showmessage(L('illegal_action'));
  346. }
  347. $_GET['value'] = $_GET['value'] ? intval($_GET['value']) : 0;
  348. $this->db->update(array('elite'=>$_GET['value']), array('id'=>$_GET['id'], 'siteid'=>get_siteid()));
  349. showmessage(L('operation_success'), HTTP_REFERER);
  350. }
  351. /**
  352. * 删除专题 未执行删除操作,仅进行递归循环
  353. */
  354. public function delete($id = 0) {
  355. if((!isset($_GET['id']) || empty($_GET['id'])) && (!isset($_POST['id']) || empty($_POST['id'])) && !$id) {
  356. showmessage(L('illegal_action'), HTTP_REFERER);
  357. }
  358. if(is_array($_POST['id']) && !$id) {
  359. array_map(array($this, delete), $_POST['id']);
  360. $this->special_cache();
  361. showmessage(L('operation_success'), HTTP_REFERER);
  362. } elseif(is_numeric($id) && $id) {
  363. $id = $_GET['id'] ? intval($_GET['id']) : intval($id);
  364. $this->special_api->_del_special($id);
  365. return true;
  366. } else {
  367. $id = $_GET['id'] ? intval($_GET['id']) : intval($id);
  368. $this->special_api->_del_special($id);
  369. showmessage(L('operation_success'), HTTP_REFERER);
  370. }
  371. }
  372. /**
  373. * 专题缓存
  374. */
  375. private function special_cache() {
  376. $specials = array();
  377. $result = $this->db->select(array('disabled'=>0), '`id`, `siteid`, `title`, `url`, `thumb`, `banner`, `ishtml`', '', '`listorder` DESC, `id` DESC');
  378. foreach($result as $r) {
  379. $specials[$r['id']] = $r;
  380. }
  381. setcache('special', $specials, 'commons');
  382. return true;
  383. }
  384. /**
  385. * 获取专题的分类
  386. *
  387. * @param intval $specialid 专题ID
  388. * @return 返回此专题分类的下拉列表
  389. */
  390. public function public_get_type() {
  391. $_GET['specialid'] = intval($_GET['specialid']);
  392. if(!$_GET['specialid']) return '';
  393. $datas = $this->special_api->_get_types($_GET['specialid']);
  394. echo form::select($types, 0, 'name="typeid" id="typeid" onchange="import_c('.$_GET['specialid'].', this.value)"', L('please_select'));
  395. }
  396. /**
  397. * 按模型ID列出模型下的栏目
  398. */
  399. public function public_categorys_list() {
  400. if(!isset($_GET['modelid']) || empty($_GET['modelid'])) exit('');
  401. $modelid = intval($_GET['modelid']);
  402. exit(form::select_category('', $_GET['catid'], 'name="catid" id="catid"', L('please_select'), $modelid, 0, 1));
  403. }
  404. /**
  405. * ajax验证专题是否已存在
  406. */
  407. public function public_check_special() {
  408. if(!$_GET['title']) exit(0);
  409. if(pc_base::load_config('system', 'charset')=='gbk') {
  410. $_GET['title'] = safe_replace(iconv('UTF-8', 'GBK', $_GET['title']));
  411. }
  412. $title = addslashes($_GET['title']);
  413. if($_GET['id']) {
  414. $id = intval($_GET['id']);
  415. $r = $this->db->get_one(array('id'=>$id, 'siteid'=>$this->get_siteid()));
  416. if($r['title'] == $title) {
  417. exit('1');
  418. }
  419. }
  420. $r = $this->db->get_one(array('siteid' => $this->get_siteid(), 'title' => $title), 'id');
  421. if($r['id']) {
  422. exit('0');
  423. } else {
  424. exit('1');
  425. }
  426. }
  427. /**
  428. * ajax检验专题静态文件名是否存在,避免专题页覆盖
  429. */
  430. public function public_check_dir() {
  431. if(!$_GET['filename']) exit(1);
  432. if($_GET['id']) {
  433. $id = intval($_GET['id']);
  434. $r = $this->db->get_one(array('id'=>$id, 'siteid'=>$this->get_siteid()));
  435. if($r['filename'] = $_GET['filename']) {
  436. exit('1');
  437. }
  438. }
  439. $r = $this->db->get_one(array('siteid'=>$this->get_siteid(), 'filename'=>$_GET['filename']), 'id');
  440. if($r['id']) {
  441. exit('0');
  442. } else {
  443. exit('1');
  444. }
  445. }
  446. /**
  447. * 表单验证
  448. * @param array $data 表单传递的值
  449. * @param string $a add/edit添加操作时,自动加上默认值
  450. */
  451. private function check($data, $a = 'add') {
  452. if(!$data['title']) showmessage(L('title_cannot_empty'), HTTP_REFERER);
  453. if(!$data['banner']) showmessage(L('banner_no_empty'), HTTP_REFERER);
  454. if(!$data['thumb']) showmessage(L('thumb_no_empty'), HTTP_REFERER);
  455. if(is_array($data['catids']) && !empty($data['catids'])) {
  456. $data['catids'] = ','.implode(',', $data['catids']).',';
  457. }
  458. if($a=='add') {
  459. if(!$data['index_template']) $data['index_template'] = 'index';
  460. $data['siteid'] = $this->get_siteid();
  461. $data['createtime'] = SYS_TIME;
  462. $data['username'] = param::get_cookie('admin_username');
  463. $data['userid'] = $_SESSION['userid'];
  464. }
  465. if ($data['voteid']) {
  466. if (strpos($data['voteid'], '|')===false) {
  467. $vote_db = pc_base::load_model('vote_subject_model');
  468. $r = $vote_db->get_one(array('subject'=>$data['voteid'], 'siteid'=>$this->get_siteid()), 'subjectid, subject', 'addtime DESC');
  469. if ($r) {
  470. $data['voteid'] = 'vote|'.$r['subjectid'].'|'.$r['subject'];
  471. }
  472. }
  473. }
  474. return $data;
  475. }
  476. }
  477. ?>