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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
|
#!/usr/bin/php
<?php
// This script is copyrighted to Thomas Guymer and is licensed under the
// Creative Commons Attribution Non-Commercial 2.0 UK: England & Wales Licence.
// This script can be run in two ways:
// * type "php systemThumbnails.php" into a console window; or
// * type "./systemThumbnails.php" into a console window.
// This script will:
// * search for all the saved thumbnails on your KDE system; then
// * check if the original file is present and delete the thumbnail if it is
// not; or
// * delete the thumbnail if it references the trash can.
$username = "user1";
// DO NOT EDIT BELOW THIS LINE
// Search for 'normal' thumbnails
echo " > Searching for thumbnails ... ";
$folderPath = "/home/" . $username . "/.thumbnails/normal";
if($handle = opendir($folderPath)) {
while(false !== ($file = readdir($handle))) {
if($file !== "." && $file !== "..") {
$contents[] = $folderPath . "/" . $file;
}
}
closedir($handle);
}
// Search for 'large' thumbnails
$folderPath = "/home/" . $username . "/.thumbnails/large";
if($handle = opendir($folderPath)) {
while(false !== ($file = readdir($handle))) {
if($file !== "." && $file !== "..") {
$contents[] = $folderPath . "/" . $file;
}
}
closedir($handle);
}
// Start checking thumbnails
if(!empty($contents)) {
sort($contents);
echo "done. (There are " . count($contents) . ")\n";
echo " > Processing ... ";
$size = 0;
$counter = 0;
foreach($contents as $key => $value) {
$file = file_get_contents($value);
if(stripos($file, "Thumb::URI") !== false && stripos($file, "IDAT") !== false) {
if(stripos($file, "tEXtThumb::URI") !== false) {
// Find chunk length
$integer = substr($file, stripos($file, "Thumb::URI")-8, 4);
// Collect data
$start = stripos($file, "Thumb::URI") + strlen("Thumb::URI") + 1; // This skips the null byte, as defined in the PNG specification https://www.w3.org/TR/2003/REC-PNG-20031110/#11tEXt
$length = ord(substr($integer, 0, 1)) + ord(substr($integer, 1, 1)) + ord(substr($integer, 2, 1)) + ord(substr($integer, 3, 1)) - strlen("Thumb::URI") - 1;
unset($integer);
$original = substr($file, $start, $length);
unset($start, $length);
// Decode
$original = utf8_encode($original);
$original = urldecode($original);
}
elseif(stripos($file, "zTXtThumb::URI") !== false) {
// Find chunk length
$integer = substr($file, stripos($file, "Thumb::URI")-8, 4);
// Collect data
$start = stripos($file, "Thumb::URI") + strlen("Thumb::URI") + 2; // This skips special characters, as defined in the PNG specification https://www.w3.org/TR/2003/REC-PNG-20031110/#11zTXt
$length = ord(substr($integer, 0, 1)) + ord(substr($integer, 1, 1)) + ord(substr($integer, 2, 1)) + ord(substr($integer, 3, 1)) - strlen("Thumb::URI") - 2;
unset($integer);
$original = substr($file, $start, $length);
unset($start, $length);
// Uncompress
$original = gzuncompress($original);
// Decode
$original = utf8_encode($original);
$original = urldecode($original);
}
else {
echo "\nERROR: The meta data in " . $value . " is not in a recognised format.\n";
exit(1);
}
// Check if the file can be deleted
if(stripos($original, "file://") === 0) {
// Remove bumf
$original = substr($original, strlen("file://"));
// Check if original exists
if(!file_exists($original)) {
$size = $size + filesize($value);
$counter = $counter + 1;
unlink($value);
}
}
elseif(stripos($original, "trash:/") === 0) {
$size = $size + filesize($value);
$counter = $counter + 1;
unlink($value);
}
else {
echo "\nERROR: " . $original . " is not a local file. (" . $value . ")\n";
}
unset($original);
}
else {
echo "\nERROR: " . $value . " does not contain correct meta data.\n";
}
unset($file);
}
$size = round($size/(1024*1024),1);
echo "done.\n";
echo " > " . $counter . " thumbnails were deleted which totaled " . $size . "MB.\n";
}
else {
echo "done. (There are no thumbnails on your system.)\n";
}
?>
|