| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311 |
- <?php
- namespace app\admin\controller;
- use think\Db;
- class Images extends Base
- {
- public function __construct()
- {
- parent::__construct();
- header('X-Accel-Buffering: no');
- }
- public function index()
- {
- $path = input('path');
- $path = str_replace('\\','',$path);
- $path = str_replace('/','',$path);
- if(empty($path)){
- $path = '@upload';
- }
- if(substr($path,0,7) != "@upload") { $path = "@upload"; }
- if(count( explode("..@",$path) ) > 1) {
- $this->error(lang('illegal_request'));
- return;
- }
- $uppath = substr($path,0,strrpos($path,"@"));
- $ischild = 0;
- if ($path !="@upload"){
- $ischild = 1;
- }
- $this->assign('uppath',$uppath);
- $this->assign('ischild',$ischild);
- $num_path = 0;
- $num_file = 0;
- $sum_size = 0;
- $filters = ",,cache,break,artcollect,downdata,playdata,export,vodcollect,";
- $files = [];
- $pp = str_replace('@','/',$path);
- if(is_dir('.'.$pp)){
- $farr = glob('.'.$pp.'/*');
- if($farr){
- foreach($farr as $f){
- if ( is_dir($f) ){
- if(strpos($filters,",".$f.",")<=0){
- $num_path++;
- $tmp_path = str_replace('./upload/','@upload/',$f);
- $tmp_path = str_replace('/','@',$tmp_path);
- $tmp_name = str_replace($path.'@','',$tmp_path);
- $files[] = ['isfile'=>0,'name'=>$tmp_name,'path'=>$tmp_path];
- }
- }
- elseif(is_file($f)){
- if (strpos($f,".html") <=0 && strpos($f,".htm") <=0){
- $num_file++;
- $fsize = filesize($f);
- $sum_size += $fsize;
- $fsize = mac_format_size($fsize);
- $ftime = filemtime($f);
- $tmp_path = mac_convert_encoding($f,"UTF-8","GB2312");
- $tmp_path = str_replace('./upload/','@upload/',$f);
- $tmp_path = str_replace('/','@',$tmp_path);
- $tmp_name = str_replace($path.'@',"",$tmp_path);
- $tmp_path = str_replace('@','/',$tmp_path);
- $files[] = ['isfile'=>1,'name'=>$tmp_name,'path'=>$tmp_path, 'size'=>$fsize, 'time'=>$ftime];
- }
- }
- }
- }
- }
- $this->assign('sum_size',mac_format_size($sum_size));
- $this->assign('num_file',$num_file);
- $this->assign('num_path',$num_path);
- $this->assign('files',$files);
- $this->assign('title',lang('admin/images/title'));
- return $this->fetch('admin@images/index');
- }
- public function opt()
- {
- $param = input();
- $this->assign('tab',$param['tab']);
- return $this->fetch('admin@images/opt');
- }
- public function del()
- {
- $param = input();
- $fname = $param['ids'];
- if(!empty($fname)){
- foreach($fname as $a){
- $a = str_replace('\\','/',$a);
- if( (substr($a,0,8) != "./upload") || count( explode("./",$a) ) > 2) {
- }
- else{
- $a = mac_convert_encoding($a,"UTF-8","GB2312");
- if(file_exists($a)){ @unlink($a); }
- }
- }
- }
- return $this->success(lang('del_ok'));
- }
- public function sync()
- {
- $param = input();
- $param['page'] = intval($param['page']) < 1 ? 1 : $param['page'];
- $param['limit'] = intval($param['limit']) < 1 ? 10 : $param['limit'];
- $flag = "#err". date('Y-m-d',time());
- if($param['tab']=='vod'){
- $tab='vod';
- $col_id ='vod_id';
- $col_name ='vod_name';
- $col_pic= $param['col']==2 ? 'vod_content' : 'vod_pic';
- $col_time='vod_time';
- }
- elseif($param['tab']=='art'){
- $tab='art';
- $col_id ='art_id';
- $col_name ='art_name';
- $col_pic= $param['col']==2 ? 'art_content' :'art_pic';
- $col_time='art_time';
- }
- elseif($param['tab']=='topic'){
- $tab='topic';
- $col_id ='topic_id';
- $col_name ='topic_name';
- $col_pic=$param['col']==2 ? 'topic_content' :'topic_pic';
- $col_time='topic_time';
- }
- elseif($param['tab']=='actor'){
- $tab='actor';
- $col_id ='actor_id';
- $col_name ='actor_name';
- $col_pic=$param['col']==2 ? 'actor_content' :'actor_pic';
- $col_time='actor_time';
- }
- elseif($param['tab']=='role'){
- $tab='role';
- $col_id ='role_id';
- $col_name ='role_name';
- $col_pic=$param['col']==2 ? 'role_content' :'role_pic';
- $col_time='role_time';
- }
- elseif($param['tab']=='website'){
- $tab='website';
- $col_id ='website_id';
- $col_name ='website_name';
- $col_pic=$param['col']==2 ? 'website_content' :'website_pic';
- $col_time='website_time';
- }
- else{
- return $this->error(lang('param_err'));
- }
- $where = ' 1=1 ';
- if ($param['range'] =="2" && $param['date']!=""){
- $pic_fwdate = str_replace('|','-',$param['date']);
- $todayunix1 = strtotime($pic_fwdate);
- $todayunix2 = $todayunix1 + 86400;
- $where .= ' AND ('.$col_time.'>= '. $todayunix1 . ' AND '.$col_time.'<='. $todayunix2 .') ';
- }
- if($param['col'] == 2){
- $where .= ' and '. $col_pic . " like '%<img%src=\"http%' ";
- }
- else {
- if ($param['opt'] == 1) {
- $where .= " AND instr(" . $col_pic . ",'#err')=0 ";
- } elseif ($param['opt'] == 2) {
- $where .= " AND instr(" . $col_pic . ",'" . $flag . "')=0 ";
- } elseif ($param['opt'] == 3) {
- $where .= " AND instr(" . $col_pic . ",'#err')>0 ";
- }
- $where .= " AND instr(" . $col_pic . ",'http')>0 ";
- }
- $total = Db::name($tab)->where($where)->count();
- $page_count = ceil($total / $param['limit']);
- if($total==0){
- mac_echo(lang('admin/images/sync_complete'));
- exit;
- }
- mac_echo('<style type="text/css">body{font-size:12px;color: #333333;line-height:21px;}span{font-weight:bold;color:#FF0000}</style>');
- mac_echo(lang('admin/images/sync_tip',[$total,$param['limit'],$page_count,$param['page']]));
- $list = Db::name($tab)->where($where)->page($page_count-1,$param['limit'])->select();
- $config = config('maccms.upload');
- if ($config['mode'] == '2') {
- $config['mode'] = 'upyun';
- }
- elseif ($config['mode'] == '3'){
- $config['mode'] = 'qiniu';
- }
- elseif ($config['mode'] == '4') {
- $config['mode'] = 'ftp';
- }
- elseif ($config['mode'] == '5') {
- $config['mode'] = 'weibo';
- }
- foreach($list as $k=>$v){
- mac_echo($v[$col_id].'、'.$v[$col_name]);
- if($param['col'] == 2){
- $content = $v[$col_pic];
- $rule = mac_buildregx("<img[^>]*src\s*=\s*['".chr(34)."]?([\w/\-\:.]*)['".chr(34)."]?[^>]*>","is");
- preg_match_all($rule,$content,$matches);
- $matchfieldarr=$matches[1];
- $matchfieldstrarr=$matches[0];
- $matchfieldvalue="";
- foreach($matchfieldarr as $f=>$matchfieldstr)
- {
- $matchfieldvalue=$matchfieldstrarr[$f];
- $img_old = trim(preg_replace("/[ \r\n\t\f]{1,}/"," ",$matchfieldstr));
- $img_url = model('Image')->down_load($img_old, $config, $param['tab']);
- $des = '';
- if(in_array($config['mode'],['local'])){
- $img_url = MAC_PATH . $img_url;
- $link = $img_url;
- }
- else{
- $link = str_replace('mac:', $config['protocol'].':', $img_url);
- }
- if ($img_url == $img_old) {
- $des = '<a href="' . $link . '" target="_blank">' . $link . '</a><font color=red>'.lang('download_err').'!</font>';
- $img_url .= $flag;
- $content = str_replace($img_old,"",$content);
- } else {
- $des = '<a href="' . $link . '" target="_blank">' . $link . '</a><font color=green>'.lang('download_ok').'!</font>';
- $content = str_replace($img_old, $img_url, $content );
- }
- mac_echo($des);
- }
- $where = [];
- $where[$col_id] = $v[$col_id];
- $update = [];
- $update[$col_pic] = $content;
- $st = Db::name($tab)->where($where)->update($update);
- }
- else {
- $img_old = $v[$col_pic];
- if (strpos($img_old, "#err")) {
- $picarr = explode("#err", $img_old);
- $img_old = $picarr[0];
- }
- $img_url = model('Image')->down_load($img_old, $config, $param['tab']);
- $des = '';
-
- if(in_array($config['mode'],['local'])){
- }
- else{
- $link = str_replace('mac:', $config['protocol'].':', $img_url);
- }
- if ($img_url == $img_old) {
- $des = '<a href="' . $link . '" target="_blank">' . $link . '</a><font color=red>'.lang('download_err').'!</font>';
- $img_url .= $flag;
- } else {
- $des = '<a href="' . $link . '" target="_blank">' . $link . '</a><font color=green>'.lang('download_ok').'!</font>';
- }
- mac_echo($des);
- $where = [];
- $where[$col_id] = $v[$col_id];
- $update = [];
- $update[$col_pic] = $img_url;
- $st = Db::name($tab)->where($where)->update($update);
- }
- }
- $url = url('images/sync') .'?'. http_build_query($param);
- mac_jump( $url ,3);
- }
- }
|