-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathdelattachments.php
50 lines (44 loc) · 1.82 KB
/
delattachments.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php
if (php_sapi_name() != 'cli') die('This program can be run only in php_cli mode.');
require "include/bittorrent.php";
dbconn();
sql_query("UPDATE attachments SET inuse = 0 ") or sqlerr(__FILE__, __LINE__);
$tables = array('torrents'=> 'descr',
'posts'=> 'body',
'offers'=> 'descr',
'comments'=> 'text',
'fun'=> 'body',
'messages'=> 'msg',
'staffmessages'=> 'msg',
'users'=> 'signature',
'requests'=> 'descr');
foreach ($tables as $table => $col) {
echo $table, '.', $col , "\n";
$atts=array();
dbconn();
$res = sql_query("SELECT `$col` FROM $table WHERE `$col` LIKE '%attach%'") or sqlerr(__FILE__, __LINE__);
while($row = _mysql_fetch_array($res)){
$attstemp = array();
preg_match_all('/\[attach\](.*?)\[\/attach\]/', $row[0], $attstemp);
$atts = array_merge($atts, $attstemp[1]);
}
if (count($atts) != 0) {
dbconn();
sql_query("UPDATE attachments SET inuse = 1 WHERE dlkey IN (" . implode(",", array_map("sqlesc",$atts)) . ")") or sqlerr(__FILE__, __LINE__);
}
}
$res=sql_query("SELECT count(*), SUM(filesize) AS filesizes FROM attachments WHERE inuse = 0") or sqlerr(__FILE__, __LINE__);
$row = _mysql_fetch_array($res);
$deletecount=$row[0];
$filesizes=$row[1];
echo "\n\nAll:".$deletecount."COUNTS\nSIZE:".($filesizes/1000)."KB\n";
if(in_array($argv[1], array('-delall'))){
$filepath = $savedirectory_attachment."/";
$res = sql_query("SELECT location FROM attachments WHERE inuse = 0") or sqlerr(__FILE__, __LINE__);
while($row = _mysql_fetch_array($res)){
@unlink($filepath.$row[0]);
@unlink($filepath.$row[0].".thumb.jpg");
}
sql_query("DELETE FROM attachments WHERE inuse = 0") or sqlerr(__FILE__, __LINE__);
ECHO "\nDEL OVER\n";
}else echo "\nyou may del attachments by adding the parameter '-delall'\n";