1
0

Images.php 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  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 data()
  12. {
  13. }
  14. public function opt()
  15. {
  16. $param = input();
  17. $this->assign('tab',$param['tab']);
  18. return $this->fetch('admin@images/opt');
  19. }
  20. public function del()
  21. {
  22. $param = input();
  23. $fname = $param['ids'];
  24. if(!empty($fname)){
  25. foreach($fname as $a){
  26. $a = str_replace('\\','/',$a);
  27. if( (substr($a,0,8) != "./upload") || count( explode("./",$a) ) > 2) {
  28. }
  29. else{
  30. $a = mac_convert_encoding($a,"UTF-8","GB2312");
  31. if(file_exists($a)){ @unlink($a); }
  32. }
  33. }
  34. }
  35. return $this->success(lang('del_ok'));
  36. }
  37. public function sync()
  38. {
  39. $param = input();
  40. $param['page'] = intval($param['page']) < 1 ? 1 : $param['page'];
  41. $param['limit'] = intval($param['limit']) < 1 ? 10 : $param['limit'];
  42. $flag = "#err". date('Y-m-d',time());
  43. if($param['tab']=='vod'){
  44. $tab='vod';
  45. $col_id ='vod_id';
  46. $col_name ='vod_name';
  47. $col_pic= $param['col']==2 ? 'vod_content' : 'vod_pic';
  48. $col_time='vod_time';
  49. }
  50. elseif($param['tab']=='art'){
  51. $tab='art';
  52. $col_id ='art_id';
  53. $col_name ='art_name';
  54. $col_pic= $param['col']==2 ? 'art_content' :'art_pic';
  55. $col_time='art_time';
  56. }
  57. elseif($param['tab']=='topic'){
  58. $tab='topic';
  59. $col_id ='topic_id';
  60. $col_name ='topic_name';
  61. $col_pic=$param['col']==2 ? 'topic_content' :'topic_pic';
  62. $col_time='topic_time';
  63. }
  64. elseif($param['tab']=='actor'){
  65. $tab='actor';
  66. $col_id ='actor_id';
  67. $col_name ='actor_name';
  68. $col_pic=$param['col']==2 ? 'actor_content' :'actor_pic';
  69. $col_time='actor_time';
  70. }
  71. elseif($param['tab']=='role'){
  72. $tab='role';
  73. $col_id ='role_id';
  74. $col_name ='role_name';
  75. $col_pic=$param['col']==2 ? 'role_content' :'role_pic';
  76. $col_time='role_time';
  77. }
  78. elseif($param['tab']=='website'){
  79. $tab='website';
  80. $col_id ='website_id';
  81. $col_name ='website_name';
  82. $col_pic=$param['col']==2 ? 'website_content' :'website_pic';
  83. $col_time='website_time';
  84. }
  85. else{
  86. return $this->error(lang('param_err'));
  87. }
  88. $where = ' 1=1 ';
  89. if ($param['range'] =="2" && $param['date']!=""){
  90. $pic_fwdate = str_replace('|','-',$param['date']);
  91. $todayunix1 = strtotime($pic_fwdate);
  92. $todayunix2 = $todayunix1 + 86400;
  93. $where .= ' AND ('.$col_time.'>= '. $todayunix1 . ' AND '.$col_time.'<='. $todayunix2 .') ';
  94. }
  95. if($param['col'] == 2){
  96. $where .= ' and '. $col_pic . " like '%<img%src=\"http%' ";
  97. }
  98. else {
  99. if ($param['opt'] == 1) {
  100. $where .= " AND instr(" . $col_pic . ",'#err')=0 ";
  101. } elseif ($param['opt'] == 2) {
  102. $where .= " AND instr(" . $col_pic . ",'" . $flag . "')=0 ";
  103. } elseif ($param['opt'] == 3) {
  104. $where .= " AND instr(" . $col_pic . ",'#err')>0 ";
  105. }
  106. $where .= " AND instr(" . $col_pic . ",'http')>0 ";
  107. }
  108. $total = Db::name($tab)->where($where)->count();
  109. $page_count = ceil($total / $param['limit']);
  110. if($total==0){
  111. mac_echo(lang('admin/images/sync_complete'));
  112. exit;
  113. }
  114. mac_echo('<style type="text/css">body{font-size:12px;color: #333333;line-height:21px;}span{font-weight:bold;color:#FF0000}</style>');
  115. mac_echo(lang('admin/images/sync_tip',[$total,$param['limit'],$page_count,$param['page']]));
  116. $list = Db::name($tab)->where($where)->page($page_count-1,$param['limit'])->select();
  117. $config = config('maccms.upload');
  118. if ($config['mode'] == '2') {
  119. $config['mode'] = 'upyun';
  120. }
  121. elseif ($config['mode'] == '3'){
  122. $config['mode'] = 'qiniu';
  123. }
  124. elseif ($config['mode'] == '4') {
  125. $config['mode'] = 'ftp';
  126. }
  127. elseif ($config['mode'] == '5') {
  128. $config['mode'] = 'weibo';
  129. }
  130. foreach($list as $k=>$v){
  131. mac_echo($v[$col_id].'、'.$v[$col_name]);
  132. if($param['col'] == 2){
  133. $content = $v[$col_pic];
  134. $rule = mac_buildregx('<img[^>]*src=[\'"]?([^>\'"\s]*)[\'"]?[^>]*>',"is");
  135. preg_match_all($rule,$content,$matches);
  136. $matchfieldarr=$matches[1];
  137. $matchfieldstrarr=$matches[0];
  138. $matchfieldvalue="";
  139. foreach($matchfieldarr as $f=>$matchfieldstr)
  140. {
  141. $matchfieldvalue=$matchfieldstrarr[$f];
  142. $img_old = trim(preg_replace("/[ \r\n\t\f]{1,}/"," ",$matchfieldstr));
  143. $img_url = model('Image')->down_load($img_old, $config, $param['tab']);
  144. $des = '';
  145. if(in_array($config['mode'],['local']) || substr($img_url,0,7)=='upload/'){
  146. $img_url = MAC_PATH . $img_url;
  147. $link = $img_url;
  148. $link = str_replace('//', '/', $link);
  149. }
  150. else{
  151. $link = str_replace('mac:', $config['protocol'].':', $img_url);
  152. }
  153. if ($img_url == $img_old) {
  154. $des = '<a href="' . $link . '" target="_blank">' . $link . '</a><font color=red>'.lang('download_err').'!</font>';
  155. $img_url .= $flag;
  156. $content = str_replace($img_old,"",$content);
  157. } else {
  158. $des = '<a href="' . $link . '" target="_blank">' . $link . '</a><font color=green>'.lang('download_ok').'!</font>';
  159. $content = str_replace($img_old, $img_url, $content );
  160. }
  161. mac_echo($des);
  162. }
  163. $where = [];
  164. $where[$col_id] = $v[$col_id];
  165. $update = [];
  166. $update[$col_pic] = $content;
  167. $st = Db::name($tab)->where($where)->update($update);
  168. }
  169. else {
  170. $img_old = $v[$col_pic];
  171. if (strpos($img_old, "#err")) {
  172. $picarr = explode("#err", $img_old);
  173. $img_old = $picarr[0];
  174. }
  175. $img_url = model('Image')->down_load($img_old, $config, $param['tab']);
  176. $des = '';
  177. if(in_array($config['mode'],['local']) || substr($img_url,0,7)=='upload/'){
  178. $link = MAC_PATH . $img_url;
  179. $link = str_replace('//', '/', $link);
  180. }
  181. else{
  182. $link = str_replace('mac:', $config['protocol'].':', $img_url);
  183. }
  184. if ($img_url == $img_old) {
  185. $des = '<a href="' . $img_old . '" target="_blank">' . $img_old . '</a><font color=red>'.lang('download_err').'!</font>';
  186. $img_url .= $flag;
  187. } else {
  188. $des = '<a href="' . $link . '" target="_blank">' . $link . '</a><font color=green>'.lang('download_ok').'!</font>';
  189. }
  190. mac_echo($des);
  191. $where = [];
  192. $where[$col_id] = $v[$col_id];
  193. $update = [];
  194. $update[$col_pic] = $img_url;
  195. $st = Db::name($tab)->where($where)->update($update);
  196. }
  197. }
  198. $url = url('images/sync') .'?'. http_build_query($param);
  199. mac_jump( $url ,3);
  200. }
  201. }