/admin/attachrenew.php

https://github.com/maddogfyg/itangyou · PHP · 151 lines · 148 code · 3 blank · 0 comment · 23 complexity · e10f7fdf3bf36fbf0638c10a663e20fb MD5 · raw file

  1. <?php
  2. !function_exists('adminmsg') && exit('Forbidden');
  3. $basename="$admin_file?adminjob=attachrenew";
  4. ($attach_url || $db_ifftp) && adminmsg('attachrenew_forbidden');
  5. if(empty($_POST['action'])){
  6. InitGP(array('S_start','orderway'));
  7. $rs = $db->get_one("SELECT COUNT(*) AS count FROM pw_attachs");
  8. $A_count = $rs['count'];
  9. $threaddb = array();
  10. if($A_count!=0){
  11. $P_N = 1000;
  12. $A_C = ceil($A_count/$P_N);
  13. $L_N = $P_N-$A_C*$P_N+$A_count;
  14. $S_end = $L_N;
  15. for($i=1;$i<=$A_C;$i++){
  16. $num = ($i-1)*$P_N;
  17. $E_num = $i==$A_C ? $num+$L_N : $num+$P_N;
  18. $S_num = "$num To $E_num";
  19. $A_option.="<option value=$i>$S_num</option>";
  20. }
  21. !$S_start && $S_start=1;
  22. $S_start==$A_C ? $S_end=$L_N : $S_end=$P_N;
  23. $start_limit=($S_start-1)*$P_N;
  24. $orderway!='size' && $orderway='aid';
  25. $query=$db->query("SELECT aid,fid,name,size,attachurl FROM pw_attachs ORDER BY $orderway".pwLimit($start_limit,$S_end));
  26. while($attach=$db->fetch_array($query)){
  27. if(!file_exists("$attachdir/$attach[attachurl]")){
  28. $thread['aid']=$attach['aid'];
  29. $thread['size']=$attach['size'];
  30. $thread['url']=$attach['attachurl'];
  31. $thread['name']=$attach['name'];
  32. $thread['where']="thread.php?fid=$fid";
  33. $threaddb[]=$thread;
  34. }
  35. }
  36. }
  37. include PrintEot('attachrenew');exit;
  38. } else{
  39. $count = 0;
  40. $ttable_a = array('pw_tmsgs');
  41. if($db_tlist){
  42. $tlistdb = unserialize($db_tlist);
  43. foreach($tlistdb as $key=>$val){
  44. $ttable_a[] = 'pw_tmsgs'.$key;
  45. }
  46. }
  47. foreach($ttable_a as $pw_tmsgs){
  48. $query=$db->query("SELECT t.fid,t.tid,t.authorid,aid FROM $pw_tmsgs tm LEFT JOIN pw_threads t ON t.tid=tm.tid WHERE aid<>''");
  49. while($aids=$db->fetch_array($query)){
  50. $attachs= unserialize(stripslashes($aids['aid']));
  51. if(is_array($attachs)){
  52. $update=0;
  53. foreach($attachs as $key=>$attach){
  54. if($attach['attachurl'] && file_exists($attachdir.'/'.$attach['attachurl'])){
  55. $check=$db->get_one("SELECT aid FROM pw_attachs WHERE aid=".pwEscape($attach['aid']));
  56. if(!$check){
  57. $uploadtime=pwFilemtime($attachdir.'/'.$attach['attachurl']);
  58. $count++;
  59. $db->update("INSERT INTO pw_attachs"
  60. . " SET " . pwSqlSingle(array(
  61. 'aid' => $attach['aid'], 'fid' => $aids['fid'],
  62. 'uid' => $aids['authorid'], 'tid' => $aids['tid'],
  63. 'pid' => 0, 'name' => $attach['name'],
  64. 'type' => $attach['type'], 'size' => $attach['size'],
  65. 'attachurl' => $attach['attachurl'],'hits' => $attach['hits'],
  66. 'needrvrc' => $attach['needrvrc'], 'uploadtime'=> $uploadtime,
  67. 'descrip' => $attach['desc']
  68. ),false));
  69. }
  70. } else{
  71. $count++;
  72. $check=$db->get_one("SELECT aid FROM pw_attachs WHERE aid=".pwEscape($attach['aid']));
  73. if($check){
  74. $db->update("DELETE FROM pw_attachs WHERE aid=".pwEscape($attach['aid']));
  75. }
  76. $update=1;
  77. unset($attachs[$key]);
  78. }
  79. }
  80. if($update){
  81. $attachs=$attachs ? serialize($attachs):'';
  82. $db->update("UPDATE $pw_tmsgs SET aid=".pwEscape($attachs,false)."WHERE tid=".pwEscape($aids['tid']));
  83. }
  84. } else{
  85. $count++;
  86. $db->update("UPDATE $pw_tmsgs SET aid='' WHERE tid=".pwEscape($aids['tid']));
  87. }
  88. }
  89. }
  90. $ptable_a = array('pw_posts');
  91. if($db_plist){
  92. $p_list=explode(',',$db_plist);
  93. foreach($p_list as $val){
  94. $ptable_a[] = 'pw_posts'.$val;
  95. }
  96. }
  97. foreach($ptable_a as $pw_posts){
  98. $query=$db->query("SELECT fid,tid,authorid,aid FROM $pw_posts WHERE aid<>''");
  99. while($aids=$db->fetch_array($query)){
  100. $attachs= unserialize(stripslashes($aids['aid']));
  101. if(is_array($attachs)){
  102. $update=0;
  103. foreach($attachs as $key=>$attach){
  104. if($attach['attachurl'] && file_exists($attachdir.'/'.$attach['attachurl'])){
  105. $check=$db->get_one("SELECT aid FROM pw_attachs WHERE aid=".pwEscape($attach['aid']));
  106. if(!$check){
  107. $uploadtime=pwFilemtime($attachdir.'/'.$attach['attachurl']);
  108. $count++;
  109. $db->update("INSERT INTO pw_attachs"
  110. . " SET " . pwSqlSingle(array(
  111. 'aid' => $attach['aid'],
  112. 'fid' => $aids['fid'],
  113. 'uid' => $aids['authorid'],
  114. 'tid' => $aids['tid'],
  115. 'pid' => 0,
  116. 'name' => $attach['name'],
  117. 'type' => $attach['type'],
  118. 'size' => $attach['size'],
  119. 'attachurl' => $attach['attachurl'],
  120. 'hits' => $attach['hits'],
  121. 'needrvrc' => $attach['needrvrc'],
  122. 'uploadtime'=> $uploadtime,
  123. 'descrip' => $attach['desc']
  124. ),false));
  125. }
  126. } else{
  127. $count++;
  128. $check=$db->get_one("SELECT aid FROM pw_attachs WHERE aid=".pwEscape($attach['aid']));
  129. if($check){
  130. $db->update("DELETE FROM pw_attachs WHERE aid=".pwEscape($attach['aid']));
  131. }
  132. $update=1;
  133. unset($attachs[$key]);
  134. }
  135. }
  136. if($update){
  137. $attachs=$attachs ? addslashes(serialize($attachs)):'';
  138. $db->update("UPDATE $pw_posts SET aid=".pwEscape($attachs)."WHERE tid=".pwEscape($aids['tid']));
  139. }
  140. } else{
  141. $count++;
  142. $db->update("UPDATE $pw_posts SET aid='' WHERE tid=".pwEscape($aids['tid']));
  143. }
  144. }
  145. }
  146. adminmsg('attach_renew');
  147. }
  148. ?>