manage.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. <?php
  2. defined('IN_PHPCMS') or exit('No permission resources.');
  3. pc_base::load_app_class('admin','admin',0);
  4. class manage extends admin {
  5. private $db;
  6. function __construct() {
  7. parent::__construct();
  8. pc_base::load_app_func('global');
  9. $this->upload_url = pc_base::load_config('system','upload_url');
  10. $this->upload_path = pc_base::load_config('system','upload_path');
  11. $this->imgext = array('jpg','gif','png','bmp','jpeg');
  12. $this->db= pc_base::load_model('attachment_model');
  13. $this->attachment = pc_base::load_sys_class('attachment');
  14. $this->admin_username = param::get_cookie('admin_username');
  15. $this->siteid = $this->get_siteid();
  16. }
  17. /**
  18. * 附件列表
  19. */
  20. public function init() {
  21. $where = '';
  22. if($_GET['dosubmit']){
  23. if(is_array($_GET['info'])&&!empty($_GET['info']))extract($_GET['info']);
  24. if($filename) $where = "AND `filename` LIKE '%$filename%' ";
  25. if($start_uploadtime && $end_uploadtime) {
  26. $start = strtotime($start_uploadtime);
  27. $end = strtotime($end_uploadtime);
  28. if($start > $end) showmessage(L('range_not_correct'),HTTP_REFERER);
  29. $where .= "AND `uploadtime` >= '$start' AND `uploadtime` <= '$end' ";
  30. }
  31. if($fileext) $where .= "AND `fileext`='$fileext' ";
  32. $status = trim($_GET['status']);
  33. if($status!='' && ($status==1 ||$status==0)) $where .= "AND `status`='$status' ";
  34. $module = trim($_GET['module']);
  35. if(isset($module) && $module!='') $where .= "AND `module`='$module' ";
  36. }
  37. $where .="AND `siteid`='".$this->siteid."'";
  38. if($where) $where = substr($where, 3);
  39. pc_base::load_sys_class('form');
  40. $category = getcache('category_content_'.$this->siteid,'commons');
  41. $modules = getcache('modules','commons');
  42. $page = $_GET['page'] ? $_GET['page'] : '1';
  43. $infos = $this->db->listinfo($where, 'uploadtime DESC', $page, $pagesize = 20);
  44. $pages = $this->db->pages;
  45. include $this->admin_tpl('attachment_list');
  46. }
  47. /**
  48. * 目录浏览模式添加图片
  49. */
  50. public function dir() {
  51. if(!$this->admin_username) return false;
  52. $dir = isset($_GET['dir']) && trim($_GET['dir']) ? str_replace(array('..\\', '../', './', '.\\'), '', trim($_GET['dir'])) : '';
  53. $filepath = $this->upload_path.$dir;
  54. $list = glob($filepath.'/'.'*');
  55. if(!empty($list)) rsort($list);
  56. $local = str_replace(array(PC_PATH, PHPCMS_PATH ,DIRECTORY_SEPARATOR.DIRECTORY_SEPARATOR), array('','',DIRECTORY_SEPARATOR), $filepath);
  57. //$show_header = true;
  58. include $this->admin_tpl('attachment_dir');
  59. }
  60. public function pulic_dirmode_del() {
  61. $filename = urldecode($_GET['filename']);
  62. $tmpdir = $dir = urldecode($_GET['dir']);
  63. $tmpdir = str_replace('\\','/',$tmpdir);
  64. $tmpdirs = explode('/',$tmpdir);
  65. $tmpdir = PHPCMS_PATH.$tmpdirs[0].'/';
  66. if($tmpdir!=$this->upload_path) {
  67. showmessage(L('illegal_operation'));
  68. }
  69. $file = PHPCMS_PATH.$dir.DIRECTORY_SEPARATOR.$filename;
  70. $file = str_replace(array('/','\\'), DIRECTORY_SEPARATOR, $file);
  71. $file = str_replace('..', '', $file);
  72. if(@unlink($file)) {
  73. echo '1';
  74. } else {
  75. echo '0';
  76. }
  77. }
  78. /**
  79. * 删除附件
  80. */
  81. public function delete() {
  82. $aid = $_GET['aid'];
  83. $attachment_index = pc_base::load_model('attachment_index_model');
  84. if($this->attachment->delete(array('aid'=>$aid))) {
  85. $attachment_index->delete(array('aid'=>$aid));
  86. exit('1');
  87. } else {
  88. exit('0');
  89. }
  90. }
  91. /**
  92. * 批量删除附件
  93. */
  94. public function public_delete_all() {
  95. $del_arr = array();
  96. $del_arr = $_POST['aid'];
  97. $attachment_index = pc_base::load_model('attachment_index_model');
  98. if(is_array($del_arr)){
  99. foreach($del_arr as $v){
  100. $aid = intval($v);
  101. $this->attachment->delete(array('aid'=>$aid));
  102. $attachment_index->delete(array('aid'=>$aid));
  103. }
  104. showmessage(L('delete').L('success'), HTTP_REFERER);
  105. }
  106. }
  107. public function pullic_showthumbs() {
  108. $aid = intval($_GET['aid']);
  109. $info = $this->db->get_one(array('aid'=>$aid));
  110. if($info) {
  111. $infos = glob(dirname($this->upload_path.$info['filepath']).'/thumb_*'.basename($info['filepath']));
  112. foreach ($infos as $n=>$thumb) {
  113. $thumbs[$n]['thumb_url'] = str_replace($this->upload_path, $this->upload_url, $thumb);
  114. $thumbinfo = explode('_', basename($thumb));
  115. $thumbs[$n]['thumb_filepath'] = $thumb;
  116. $thumbs[$n]['width'] = $thumbinfo[1];
  117. $thumbs[$n]['height'] = $thumbinfo[2];
  118. }
  119. }
  120. $show_header = 1;
  121. include $this->admin_tpl('attachment_thumb');
  122. }
  123. public function pullic_delthumbs() {
  124. $filepath = urldecode($_GET['filepath']);
  125. $ext = fileext($filepath);
  126. if(!in_array(strtoupper($ext),array('JPG','GIF','BMP','PNG','JPEG'))) exit('0');
  127. $reslut = @unlink($filepath);
  128. if($reslut) exit('1');
  129. exit('0');
  130. }
  131. }
  132. ?>