Annex.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  1. <?php
  2. namespace app\admin\controller;
  3. use think\Db;
  4. class Annex extends Base
  5. {
  6. public function __construct()
  7. {
  8. parent::__construct();
  9. }
  10. public function data()
  11. {
  12. $param = input();
  13. $param['page'] = intval($param['page']) < 1 ? 1 : $param['page'];
  14. $param['limit'] = intval($param['limit']) < 1 ? $this->_pagesize : $param['limit'];
  15. $where = [];
  16. if (!empty($param['type'])) {
  17. $where['annex_type'] = ['eq', $param['type']];
  18. }
  19. if (!empty($param['mid'])) {
  20. $where['annex_mid'] = ['eq', $param['mid']];
  21. }
  22. if(!empty($param['wd'])){
  23. $param['wd'] = htmlspecialchars(urldecode($param['wd']));
  24. $where['annex_file'] = ['like','%'.$param['wd'].'%'];
  25. }
  26. $order='annex_time desc';
  27. $res = model('Annex')->listData($where,$order,$param['page'],$param['limit']);
  28. $this->assign('list', $res['list']);
  29. $this->assign('total', $res['total']);
  30. $this->assign('page', $res['page']);
  31. $this->assign('limit', $res['limit']);
  32. $param['page'] = '{page}';
  33. $param['limit'] = '{limit}';
  34. $this->assign('param', $param);
  35. $this->assign('title', lang('admin/annex/title'));
  36. return $this->fetch('admin@annex/index');
  37. }
  38. public function file()
  39. {
  40. $path = input('path');
  41. $path = str_replace('\\','',$path);
  42. $path = str_replace('/','',$path);
  43. if(empty($path)){
  44. $path = '@upload';
  45. }
  46. if(substr($path,0,7) != "@upload") { $path = "@upload"; }
  47. if(count( explode("..@",$path) ) > 1) {
  48. $this->error(lang('illegal_request'));
  49. return;
  50. }
  51. $uppath = substr($path,0,strrpos($path,"@"));
  52. $ischild = 0;
  53. if ($path !="@upload"){
  54. $ischild = 1;
  55. }
  56. $this->assign('uppath',$uppath);
  57. $this->assign('ischild',$ischild);
  58. $num_path = 0;
  59. $num_file = 0;
  60. $sum_size = 0;
  61. $filters = ",,cache,break,artcollect,downdata,playdata,export,vodcollect,";
  62. $files = [];
  63. $pp = str_replace('@','/',$path);
  64. if(is_dir('.'.$pp)){
  65. $farr = glob('.'.$pp.'/*');
  66. if($farr){
  67. foreach($farr as $f){
  68. if ( is_dir($f) ){
  69. if(strpos($filters,",".$f.",")<=0){
  70. $num_path++;
  71. $tmp_path = str_replace('./upload/','@upload/',$f);
  72. $tmp_path = str_replace('/','@',$tmp_path);
  73. $tmp_name = str_replace($path.'@','',$tmp_path);
  74. $files[] = ['isfile'=>0,'name'=>$tmp_name,'path'=>$tmp_path];
  75. }
  76. }
  77. elseif(is_file($f)){
  78. if (strpos($f,".html") <=0 && strpos($f,".htm") <=0){
  79. $num_file++;
  80. $fsize = filesize($f);
  81. $sum_size += $fsize;
  82. $fsize = mac_format_size($fsize);
  83. $ftime = filemtime($f);
  84. $tmp_path = mac_convert_encoding($f,"UTF-8","GB2312");
  85. $tmp_path = str_replace('./upload/','@upload/',$f);
  86. $tmp_path = str_replace('/','@',$tmp_path);
  87. $tmp_name = str_replace($path.'@',"",$tmp_path);
  88. $tmp_path = str_replace('@','/',$tmp_path);
  89. $files[] = ['isfile'=>1,'name'=>$tmp_name,'path'=>$tmp_path, 'size'=>$fsize, 'time'=>$ftime];
  90. }
  91. }
  92. }
  93. }
  94. }
  95. $this->assign('sum_size',mac_format_size($sum_size));
  96. $this->assign('num_file',$num_file);
  97. $this->assign('num_path',$num_path);
  98. $this->assign('files',$files);
  99. $this->assign('title',lang('admin/annex/title'));
  100. return $this->fetch('admin@annex/file');
  101. }
  102. public function info()
  103. {
  104. if (Request()->isPost()) {
  105. $param = input('post.');
  106. $res = model('Annex')->saveData($param);
  107. if($res['code']>1){
  108. return $this->error($res['msg']);
  109. }
  110. return $this->success($res['msg']);
  111. }
  112. $id = input('id');
  113. $where=[];
  114. $where['annex_id'] = ['eq',$id];
  115. $res = model('Annex')->infoData($where);
  116. $info = $res['info'];
  117. $this->assign('info',$info);
  118. $this->assign('title',lang('admin/annex/title'));
  119. return $this->fetch('admin@annex/info');
  120. }
  121. public function del()
  122. {
  123. $param = input();
  124. $ids = $param['ids'];
  125. if(!empty($ids)){
  126. if(is_array($ids)){
  127. foreach($ids as $k=>$v){
  128. $ids[$k] = str_replace('./','',$v);
  129. }
  130. }
  131. $where=[];
  132. $where['annex_id|annex_file'] = ['in',$ids];
  133. $res = model('Annex')->delData($where);
  134. if($res['code']>1){
  135. return $this->error($res['msg']);
  136. }
  137. return $this->success($res['msg']);
  138. }
  139. return $this->error(lang('param_err'));
  140. }
  141. public function check()
  142. {
  143. mac_echo('<style type="text/css">body{font-size:12px;color: #333333;line-height:21px;}span{font-weight:bold;color:#FF0000}</style>');
  144. $param = input();
  145. $num = intval($param['num']);
  146. $start = intval($param['start']);
  147. $page_count = intval($param['page_count']);
  148. $data_count = intval($param['data_count']);
  149. if($start<1){
  150. $start=1;
  151. }
  152. if($page_count<1){
  153. $page_count=1;
  154. }
  155. $page_size = 500;
  156. if(empty($data_count)){
  157. $where=[];
  158. $data_count = model('Annex')->countData($where);
  159. $page_count = ceil($data_count / $page_size);
  160. $param['data_count'] = $data_count;
  161. $param['page_count'] = $page_count;
  162. $param['page_size'] = $page_size;
  163. }
  164. if($start > $page_count){
  165. mac_echo(lang('admin/annex/check_complete'));
  166. exit;
  167. }
  168. mac_echo(lang('admin/annex/info_tip',[$param['data_count'],$param['page_count'],$param['page_size'],$start]));
  169. $limit_str = ($page_size * ($page_count-$start)) .",".$page_size;
  170. $list = Db::name('Annex')->field('*')->where($where)->limit($limit_str)->fetchSql(false)->orderRaw('annex_time desc')->select();
  171. foreach ($list as $k3 => $v3) {
  172. $tmp = $v3['annex_file'];
  173. if(!file_exists('./'.$tmp)){
  174. $where=[];
  175. $where['annex_file'] = ['eq',$tmp];
  176. $r = Db::name('Annex')->where($where)->delete();
  177. mac_echo($tmp . '...del');
  178. }
  179. }
  180. $param['start'] = ++$start;
  181. $url = url('annex/check') .'?'. http_build_query($param);
  182. mac_jump( $url ,3);
  183. }
  184. public function init()
  185. {
  186. $param = input();
  187. if($param['ck']){
  188. mac_echo('<style type="text/css">body{font-size:12px;color: #333333;line-height:21px;}span{font-weight:bold;color:#FF0000}</style>');
  189. $start = intval($param['start']);
  190. if($start<1){
  191. $start=1;
  192. }
  193. $pre = config('database.prefix');
  194. $schema = Db::query('select * from information_schema.columns where table_schema = ?', [config('database.database')]);
  195. $col_list = [];
  196. foreach ($schema as $k => $v) {
  197. $col_list[$v['TABLE_NAME']][$v['COLUMN_NAME']] = $v;
  198. }
  199. $tables = ['actor', 'art', 'topic', 'type', 'vod', 'website' ,'actor', 'role'];
  200. $param['tbi'] = intval($param['tbi']);
  201. if ($param['tbi'] >= count($tables)) {
  202. mac_echo(lang('admin/annex/check_ok'));
  203. die;
  204. }
  205. $tab = $tables[$param['tbi']];
  206. $where=[];
  207. $page_size = 500;
  208. $data_count = model($tab)->countData($where);
  209. $page_count = ceil($data_count / $page_size);
  210. if($start > $page_count){
  211. mac_echo(lang('admin/annex/check_jump',[$tab]));
  212. $param['tbi']++;
  213. $param['start'] = 1;
  214. $url = url('annex/init') . '?' . http_build_query($param);
  215. mac_jump($url, 3);
  216. exit;
  217. }
  218. mac_echo(lang('admin/annex/check_tip1',[$tab,$data_count,$page_count,$page_size,$start]));
  219. foreach ($col_list as $k1 => $v1) {
  220. $pre_tb = str_replace($pre, '', $k1);
  221. $si = array_search($pre_tb, $tables);
  222. if ($pre_tb !== $tab) {
  223. continue;
  224. }
  225. $limit_str = ($page_size * ($page_count-$start)) .",".$page_size;
  226. $list = Db::name($pre_tb)->field('*')->limit($limit_str)->fetchSql(false)->select();
  227. $adds = [];
  228. foreach ($list as $k3 => $v3) {
  229. $col_id = $tables[$si] . '_id';
  230. $col_name = $tables[$si] . '_name';
  231. $val_id = $v3[$col_id];;
  232. $val_name = strip_tags($v3[$col_name]);
  233. $ck = false;
  234. $where2 = [];
  235. $where2[$col_id] = $val_id;
  236. $imgs = [];
  237. $add = [];
  238. $add['id'] = $val_id;
  239. $add['name'] = $val_name;
  240. $add['col_id'] = $col_id;
  241. $col = $tables[$si] . '_pic';
  242. $val = $v3[$col];
  243. if (substr($val, 0, 6) == 'upload' && file_exists('./' . $val)) {
  244. $imgs[] = ['annex_file' => $val, 'annex_time' => time(), 'annex_size' => filesize('./' . $val), 'annex_type' => 'image'];
  245. $ck = true;
  246. }
  247. $col = $tables[$si] . '_pic_thumb';
  248. $val = $v3[$col];
  249. if (substr($val, 0, 6) == 'upload' && file_exists('./' . $val)) {
  250. $imgs[] = ['annex_file' => $val, 'annex_time' => time(), 'annex_size' => filesize('./' . $val), 'annex_type' => 'image'];
  251. $ck = true;
  252. }
  253. $col = $tables[$si] . '_pic_slide';
  254. $val = $v3[$col];
  255. if (substr($val, 0, 6) == 'upload' && file_exists('./' . $val)) {
  256. $imgs[] = ['annex_file' => $val, 'annex_time' => time(), 'annex_size' => filesize('./' . $val), 'annex_type' => 'image'];
  257. $ck = true;
  258. }
  259. $col = $tables[$si] . '_content';
  260. $val = $v3[$col];
  261. if (!empty($val)) {
  262. $rule = mac_buildregx("<img[^>]*src\s*=\s*['" . chr(34) . "]?([\w/\-\:.]*)['" . chr(34) . "]?[^>]*>", "is");
  263. preg_match_all($rule, $val, $matches);
  264. $matchfieldarr = $matches[1];
  265. foreach ($matchfieldarr as $f => $matchfieldstr) {
  266. $img_src = trim(preg_replace("/[ \r\n\t\f]{1,}/", " ", $matchfieldstr));
  267. if (substr($img_src, 0, 7) == '/upload' && file_exists('.' . $img_src)) {
  268. $imgs[] = ['annex_file' => substr($img_src, 1), 'annex_time' => time(), 'annex_size' => filesize('.' . $img_src), 'annex_type' => 'image'];
  269. $ck = true;
  270. }
  271. }
  272. }
  273. $add['imgs'] = $imgs;
  274. $adds[] = $add;
  275. }
  276. if (!empty($adds)) {
  277. $insert = [];
  278. foreach ($adds as $k => $v) {
  279. $des = '<font color=red>'.lang('skip').'</font>';
  280. if (!empty($v['imgs'])) {
  281. foreach($v['imgs'] as $k2 => $v2){
  282. $where = [];
  283. $where['annex_file'] = $v2['annex_file'];
  284. $r = model('Annex')->infoData($where);
  285. if ($r['code'] !== 1) {
  286. $insert[] = $v2;
  287. $des = '<font color=green>ok</font>';
  288. }
  289. }
  290. }
  291. mac_echo($v['name'] . '...' . $des);
  292. model('Annex')->insertAll($insert);
  293. }
  294. }
  295. }
  296. $param['start']++;
  297. $url = url('annex/init') . '?' . http_build_query($param);
  298. mac_jump($url, 3);
  299. exit;
  300. }
  301. return $this->fetch('admin@annex/init');
  302. }
  303. }