Images.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  1. <?php
  2. namespace app\admin\controller;
  3. use think\Db;
  4. class Images extends Base
  5. {
  6. public function __construct()
  7. {
  8. parent::__construct();
  9. header('X-Accel-Buffering: no');
  10. }
  11. public function index()
  12. {
  13. $path = input('path');
  14. $path = str_replace('\\','',$path);
  15. $path = str_replace('/','',$path);
  16. if(empty($path)){
  17. $path = '@upload';
  18. }
  19. if(substr($path,0,7) != "@upload") { $path = "@upload"; }
  20. if(count( explode("..@",$path) ) > 1) {
  21. $this->error(lang('illegal_request'));
  22. return;
  23. }
  24. $uppath = substr($path,0,strrpos($path,"@"));
  25. $ischild = 0;
  26. if ($path !="@upload"){
  27. $ischild = 1;
  28. }
  29. $this->assign('uppath',$uppath);
  30. $this->assign('ischild',$ischild);
  31. $num_path = 0;
  32. $num_file = 0;
  33. $sum_size = 0;
  34. $filters = ",,cache,break,artcollect,downdata,playdata,export,vodcollect,";
  35. $files = [];
  36. $pp = str_replace('@','/',$path);
  37. if(is_dir('.'.$pp)){
  38. $farr = glob('.'.$pp.'/*');
  39. if($farr){
  40. foreach($farr as $f){
  41. if ( is_dir($f) ){
  42. if(strpos($filters,",".$f.",")<=0){
  43. $num_path++;
  44. $tmp_path = str_replace('./upload/','@upload/',$f);
  45. $tmp_path = str_replace('/','@',$tmp_path);
  46. $tmp_name = str_replace($path.'@','',$tmp_path);
  47. $files[] = ['isfile'=>0,'name'=>$tmp_name,'path'=>$tmp_path];
  48. }
  49. }
  50. elseif(is_file($f)){
  51. if (strpos($f,".html") <=0 && strpos($f,".htm") <=0){
  52. $num_file++;
  53. $fsize = filesize($f);
  54. $sum_size += $fsize;
  55. $fsize = mac_format_size($fsize);
  56. $ftime = filemtime($f);
  57. $tmp_path = mac_convert_encoding($f,"UTF-8","GB2312");
  58. $tmp_path = str_replace('./upload/','@upload/',$f);
  59. $tmp_path = str_replace('/','@',$tmp_path);
  60. $tmp_name = str_replace($path.'@',"",$tmp_path);
  61. $tmp_path = str_replace('@','/',$tmp_path);
  62. $files[] = ['isfile'=>1,'name'=>$tmp_name,'path'=>$tmp_path, 'size'=>$fsize, 'time'=>$ftime];
  63. }
  64. }
  65. }
  66. }
  67. }
  68. $this->assign('sum_size',mac_format_size($sum_size));
  69. $this->assign('num_file',$num_file);
  70. $this->assign('num_path',$num_path);
  71. $this->assign('files',$files);
  72. $this->assign('title',lang('admin/images/title'));
  73. return $this->fetch('admin@images/index');
  74. }
  75. public function opt()
  76. {
  77. $param = input();
  78. $this->assign('tab',$param['tab']);
  79. return $this->fetch('admin@images/opt');
  80. }
  81. public function del()
  82. {
  83. $param = input();
  84. $fname = $param['ids'];
  85. if(!empty($fname)){
  86. foreach($fname as $a){
  87. $a = str_replace('\\','/',$a);
  88. if( (substr($a,0,8) != "./upload") || count( explode("./",$a) ) > 2) {
  89. }
  90. else{
  91. $a = mac_convert_encoding($a,"UTF-8","GB2312");
  92. if(file_exists($a)){ @unlink($a); }
  93. }
  94. }
  95. }
  96. return $this->success(lang('del_ok'));
  97. }
  98. public function sync()
  99. {
  100. $param = input();
  101. $param['page'] = intval($param['page']) < 1 ? 1 : $param['page'];
  102. $param['limit'] = intval($param['limit']) < 1 ? 10 : $param['limit'];
  103. $flag = "#err". date('Y-m-d',time());
  104. if($param['tab']=='vod'){
  105. $tab='vod';
  106. $col_id ='vod_id';
  107. $col_name ='vod_name';
  108. $col_pic= $param['col']==2 ? 'vod_content' : 'vod_pic';
  109. $col_time='vod_time';
  110. }
  111. elseif($param['tab']=='art'){
  112. $tab='art';
  113. $col_id ='art_id';
  114. $col_name ='art_name';
  115. $col_pic= $param['col']==2 ? 'art_content' :'art_pic';
  116. $col_time='art_time';
  117. }
  118. elseif($param['tab']=='topic'){
  119. $tab='topic';
  120. $col_id ='topic_id';
  121. $col_name ='topic_name';
  122. $col_pic=$param['col']==2 ? 'topic_content' :'topic_pic';
  123. $col_time='topic_time';
  124. }
  125. elseif($param['tab']=='actor'){
  126. $tab='actor';
  127. $col_id ='actor_id';
  128. $col_name ='actor_name';
  129. $col_pic=$param['col']==2 ? 'actor_content' :'actor_pic';
  130. $col_time='actor_time';
  131. }
  132. elseif($param['tab']=='role'){
  133. $tab='role';
  134. $col_id ='role_id';
  135. $col_name ='role_name';
  136. $col_pic=$param['col']==2 ? 'role_content' :'role_pic';
  137. $col_time='role_time';
  138. }
  139. elseif($param['tab']=='website'){
  140. $tab='website';
  141. $col_id ='website_id';
  142. $col_name ='website_name';
  143. $col_pic=$param['col']==2 ? 'website_content' :'website_pic';
  144. $col_time='website_time';
  145. }
  146. else{
  147. return $this->error(lang('param_err'));
  148. }
  149. $where = ' 1=1 ';
  150. if ($param['range'] =="2" && $param['date']!=""){
  151. $pic_fwdate = str_replace('|','-',$param['date']);
  152. $todayunix1 = strtotime($pic_fwdate);
  153. $todayunix2 = $todayunix1 + 86400;
  154. $where .= ' AND ('.$col_time.'>= '. $todayunix1 . ' AND '.$col_time.'<='. $todayunix2 .') ';
  155. }
  156. if($param['col'] == 2){
  157. $where .= ' and '. $col_pic . " like '%<img%src=\"http%' ";
  158. }
  159. else {
  160. if ($param['opt'] == 1) {
  161. $where .= " AND instr(" . $col_pic . ",'#err')=0 ";
  162. } elseif ($param['opt'] == 2) {
  163. $where .= " AND instr(" . $col_pic . ",'" . $flag . "')=0 ";
  164. } elseif ($param['opt'] == 3) {
  165. $where .= " AND instr(" . $col_pic . ",'#err')>0 ";
  166. }
  167. $where .= " AND instr(" . $col_pic . ",'http')>0 ";
  168. }
  169. $total = Db::name($tab)->where($where)->count();
  170. $page_count = ceil($total / $param['limit']);
  171. if($total==0){
  172. mac_echo(lang('admin/images/sync_complete'));
  173. exit;
  174. }
  175. mac_echo('<style type="text/css">body{font-size:12px;color: #333333;line-height:21px;}span{font-weight:bold;color:#FF0000}</style>');
  176. mac_echo(lang('admin/images/sync_tip',[$total,$param['limit'],$page_count,$param['page']]));
  177. $list = Db::name($tab)->where($where)->page($page_count-1,$param['limit'])->select();
  178. $config = config('maccms.upload');
  179. if ($config['mode'] == '2') {
  180. $config['mode'] = 'upyun';
  181. }
  182. elseif ($config['mode'] == '3'){
  183. $config['mode'] = 'qiniu';
  184. }
  185. elseif ($config['mode'] == '4') {
  186. $config['mode'] = 'ftp';
  187. }
  188. elseif ($config['mode'] == '5') {
  189. $config['mode'] = 'weibo';
  190. }
  191. foreach($list as $k=>$v){
  192. mac_echo($v[$col_id].'、'.$v[$col_name]);
  193. if($param['col'] == 2){
  194. $content = $v[$col_pic];
  195. $rule = mac_buildregx("<img[^>]*src\s*=\s*['".chr(34)."]?([\w/\-\:.]*)['".chr(34)."]?[^>]*>","is");
  196. preg_match_all($rule,$content,$matches);
  197. $matchfieldarr=$matches[1];
  198. $matchfieldstrarr=$matches[0];
  199. $matchfieldvalue="";
  200. foreach($matchfieldarr as $f=>$matchfieldstr)
  201. {
  202. $matchfieldvalue=$matchfieldstrarr[$f];
  203. $img_old = trim(preg_replace("/[ \r\n\t\f]{1,}/"," ",$matchfieldstr));
  204. $img_url = model('Image')->down_load($img_old, $config, $param['tab']);
  205. $des = '';
  206. if(in_array($config['mode'],['local'])){
  207. $img_url = MAC_PATH . $img_url;
  208. $link = $img_url;
  209. }
  210. else{
  211. $link = str_replace('mac:', $config['protocol'].':', $img_url);
  212. }
  213. if ($img_url == $img_old) {
  214. $des = '<a href="' . $link . '" target="_blank">' . $link . '</a><font color=red>'.lang('download_err').'!</font>';
  215. $img_url .= $flag;
  216. $content = str_replace($img_old,"",$content);
  217. } else {
  218. $des = '<a href="' . $link . '" target="_blank">' . $link . '</a><font color=green>'.lang('download_ok').'!</font>';
  219. $content = str_replace($img_old, $img_url, $content );
  220. }
  221. mac_echo($des);
  222. }
  223. $where = [];
  224. $where[$col_id] = $v[$col_id];
  225. $update = [];
  226. $update[$col_pic] = $content;
  227. $st = Db::name($tab)->where($where)->update($update);
  228. }
  229. else {
  230. $img_old = $v[$col_pic];
  231. if (strpos($img_old, "#err")) {
  232. $picarr = explode("#err", $img_old);
  233. $img_old = $picarr[0];
  234. }
  235. $img_url = model('Image')->down_load($img_old, $config, $param['tab']);
  236. $des = '';
  237. if(in_array($config['mode'],['local'])){
  238. }
  239. else{
  240. $link = str_replace('mac:', $config['protocol'].':', $img_url);
  241. }
  242. if ($img_url == $img_old) {
  243. $des = '<a href="' . $link . '" target="_blank">' . $link . '</a><font color=red>'.lang('download_err').'!</font>';
  244. $img_url .= $flag;
  245. } else {
  246. $des = '<a href="' . $link . '" target="_blank">' . $link . '</a><font color=green>'.lang('download_ok').'!</font>';
  247. }
  248. mac_echo($des);
  249. $where = [];
  250. $where[$col_id] = $v[$col_id];
  251. $update = [];
  252. $update[$col_pic] = $img_url;
  253. $st = Db::name($tab)->where($where)->update($update);
  254. }
  255. }
  256. $url = url('images/sync') .'?'. http_build_query($param);
  257. mac_jump( $url ,3);
  258. }
  259. }