copyfrom.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php
  2. defined('IN_PHPCMS') or exit('No permission resources.');
  3. pc_base::load_app_class('admin','admin',0);
  4. class copyfrom extends admin {
  5. private $db;
  6. public $siteid;
  7. function __construct() {
  8. $this->db = pc_base::load_model('copyfrom_model');
  9. pc_base::load_sys_class('form', '', 0);
  10. parent::__construct();
  11. $this->siteid = $this->get_siteid();
  12. }
  13. /**
  14. * 来源管理列表
  15. */
  16. public function init () {
  17. $datas = array();
  18. $datas = $this->db->listinfo(array('siteid'=>$this->siteid),'listorder ASC',$_GET['page']);
  19. $pages = $this->db->pages;
  20. $big_menu = array('javascript:window.top.art.dialog({id:\'add\',iframe:\'?m=admin&c=copyfrom&a=add\', title:\''.L('add_copyfrom').'\', width:\'580\', height:\'240\', lock:true}, function(){var d = window.top.art.dialog({id:\'add\'}).data.iframe;var form = d.document.getElementById(\'dosubmit\');form.click();return false;}, function(){window.top.art.dialog({id:\'add\'}).close()});void(0);', L('add_copyfrom'));
  21. $this->public_cache();
  22. include $this->admin_tpl('copyfrom_list');
  23. }
  24. /**
  25. * 添加来源
  26. */
  27. public function add() {
  28. if(isset($_POST['dosubmit'])) {
  29. $_POST['info'] = $this->check($_POST['info']);
  30. $this->db->insert($_POST['info']);
  31. showmessage(L('add_success'), '', '', 'add');
  32. } else {
  33. $show_header = $show_validator = '';
  34. include $this->admin_tpl('copyfrom_add');
  35. }
  36. }
  37. /**
  38. * 管理来源
  39. */
  40. public function edit() {
  41. if(isset($_POST['dosubmit'])) {
  42. $id = intval($_POST['id']);
  43. $_POST['info'] = $this->check($_POST['info']);
  44. $this->db->update($_POST['info'],array('id'=>$id));
  45. showmessage(L('update_success'), '', '', 'edit');
  46. } else {
  47. $show_header = $show_validator = '';
  48. $id = intval($_GET['id']);
  49. if (!$id) showmessage(L('illegal_action'));
  50. $r = $this->db->get_one(array('id'=>$id, 'siteid'=>$this->siteid));
  51. if (empty($r)) showmessage(L('illegal_action'));
  52. extract($r);
  53. include $this->admin_tpl('copyfrom_edit');
  54. }
  55. }
  56. /**
  57. * 删除来源
  58. */
  59. public function delete() {
  60. $_GET['id'] = intval($_GET['id']);
  61. if (!$_GET['id']) showmessage(L('illegal_action'));
  62. $this->db->delete(array('id'=>$_GET['id'], 'siteid'=>$this->siteid));
  63. exit('1');
  64. }
  65. /**
  66. * 检查POST数据
  67. * @param array $data 前台POST数据
  68. * @return array $data
  69. */
  70. private function check($data = array()) {
  71. if (!is_array($data) || empty($data)) return array();
  72. if (!preg_match('/^((http|https):\/\/)?([^\/]+)/i', $data['siteurl'])) showmessage(L('input').L('copyfrom_url'));
  73. if (empty($data['sitename'])) showmessage(L('input').L('copyfrom_name'));
  74. if ($data['thumb'] && !preg_match('/^((http|https):\/\/)?([^\/]+)/i', $data['thumb'])) showmessage(L('copyfrom_logo').L('format_incorrect'));
  75. $data['siteid'] = $this->siteid;
  76. return $data;
  77. }
  78. /**
  79. * 排序
  80. */
  81. public function listorder() {
  82. if(isset($_POST['dosubmit'])) {
  83. foreach($_POST['listorders'] as $id => $listorder) {
  84. $this->db->update(array('listorder'=>$listorder),array('id'=>$id));
  85. }
  86. showmessage(L('operation_success'),HTTP_REFERER);
  87. } else {
  88. showmessage(L('operation_failure'));
  89. }
  90. }
  91. /**
  92. * 生成缓存
  93. */
  94. public function public_cache() {
  95. $infos = $this->db->select('','*','','listorder DESC','','id');
  96. setcache('copyfrom', $infos, 'admin');
  97. return true;
  98. }
  99. }
  100. ?>