-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcron.php
More file actions
executable file
·182 lines (172 loc) · 6.74 KB
/
cron.php
File metadata and controls
executable file
·182 lines (172 loc) · 6.74 KB
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
<?php
// Load the settings file
require_once('inc/settings.php');
// Load the FileUtil class
require_once('inc/class/fileUtility.class.php');
$fileUtil = new FileUtility();
// Open the log file
$logFile = file_get_contents(CRON_LOG);
// Method
if (GD_THUMBS) {
$method = 'GD Library';
}
else {
$method = 'ImageMagick';
}
// Add a header to show that the cron has been run, even if no work is required
$logFile .= date("Y-m-d, h:i:s") . " Cron started\n";
// Create null indexes at root levelif they don't exist
if (!file_exists(ARCHIVE_MAIN . '/index.php')) {
touch(ARCHIVE_MAIN . '/index.php');
$string = date("Y-m-d, h:i:s") . ' Created NUL: ' . realpath(ARCHIVE_MAIN . '/index.php');
echo $string . '<br />';
$logFile .= $string . "\n";
}
if (!file_exists(ARCHIVE_THUMBS . '/index.php')) {
touch(ARCHIVE_THUMBS . '/index.php');
$string = date("Y-m-d, h:i:s") . ' Created NUL: ' . realpath(ARCHIVE_THUMBS . '/index.php');
echo $string . '<br />';
$logFile .= $string . "\n";
}
// Main iterator, searching images dir
$objects = new RecursiveIteratorIterator(new RecursiveDirectoryIterator(ARCHIVE_MAIN), RecursiveIteratorIterator::SELF_FIRST);
foreach($objects as $name => $object){
// Search and create directories and thumbs
if (substr($name, -1) != '.') {
$thumb = str_replace(ARCHIVE_MAIN, ARCHIVE_THUMBS, $name);
$mid = str_replace(ARCHIVE_MAIN, ARCHIVE_MID, $name);
// Get the thumb alternative
if (is_dir($name)) {
// Create directories and null indexes
if (!file_exists($thumb)) {
if ($fileUtil->createThumbDir(str_replace(ARCHIVE_MAIN, '', $name), 'thumb')) {
$string = date("Y-m-d, h:i:s") . ' Created DIR: ' . realpath($thumb);
echo $string . "<br />\n";
$logFile .= $string . "\n";
}
else {
$string = date("Y-m-d, h:i:s") . ' Failed to create DIR: ' . realpath($thumb);
echo $string . "<br />\n";
$logFile .= $string . "\n";
}
}
if (ENABLE_MID_IMAGES) {
if (!file_exists($mid)) {
if ($fileUtil->createThumbDir(str_replace(ARCHIVE_MAIN, '', $name), 'mid')) {
$string = date("Y-m-d, h:i:s") . ' Created DIR: ' . realpath($mid);
echo $string . "<br>\n";
$logFile .= $string . "\n";
}
else {
$string = date("Y-m-d, h:i:s") . ' Failed to create DIR: ' . realpath($mid);
echo $string . "<br />\n";
$logFile .= $string . "\n";
}
}
}
// Create null indexes if they don't exist
if (!file_exists($name . '/index.php')) {
touch($name . '/index.php');
$string = date("Y-m-d, h:i:s") . ' Created NUL: ' . realpath($name . '/index.php');
echo $string . "<br />\n";
$logFile .= $string . "\n";
}
if (!file_exists($thumb . '/index.php')) {
touch ($thumb . '/index.php');
$string = date("Y-m-d, h:i:s") . ' Created NUL: ' . realpath($thumb . '/index.php');
echo $string . "<br />\n";
$logFile .= $string . "\n";
}
if (!file_exists($mid . '/index.php') && ENABLE_MID_IMAGES) {
touch ($mid . '/index.php');
$string = date("Y-m-d, h:i:s") . ' Created NUL: ' . realpath($mid . '/index.php');
echo $string . "<br />\n";
$logFile .= $string . "\n";
}
}
// Create thumbs for images
elseif (preg_match('/(jpg|jpeg|gif|tiff|png)/i',$name)) {
// Check if the thumb already exists
$fileName = explode('/', $name);
$fileName = end($fileName);
if (!$fileUtil->thumbExists($name, 'thumb') && $fileName[0] != '.')
{
if ($fileUtil->createThumb($name, 'thumb')) {
$string = date("Y-m-d, h:i:s") . ' Created IMG: ' . realpath($thumb) . ' using: ' . $method;
echo $string . "<br />\n";
$logFile .= $string . "\n";
}
else {
$string = date("Y-m-d, h:i:s") . ' Failed to create IMG: ' . realpath($thumb) . ' using: ' . $method;
echo $string . "<br />\n";
$logFile .= $string . "\n";
}
}
if (!$fileUtil->thumbExists($name, 'mid') && $fileName[0] != '.')
{
if ($fileUtil->createThumb($name, 'mid')) {
$string = date("Y-m-d, h:i:s") . ' Created IMG: ' . realpath($mid) . ' using: ' . $method;
echo $string . "<br />\n";
$logFile .= $string . "\n";
}
else {
$string = date("Y-m-d, h:i:s") . ' Failed to create IMG: ' . realpath($mid) . ' using: ' . $method;
echo $string . "<br />\n";
$logFile .= $string . "\n";
}
}
}
// Create thumbs for videos
elseif (preg_match('/(mp4|ogg|webm)/i',$name)) {
$fileName = explode('/', $name);
$fileName = end($fileName);
// if the video doesn't have a thumb
if (!$fileUtil->thumbExistsVideo($name))
{
if ($fileUtil->createThumbVideo($name)) {
$string = date("Y-m-d, h:i:s") . ' Created VID: ' . realpath($fileUtil->getVideoThumbName($name)) . ' using: ' . $method;
echo $string . "<br />\n";
$logFile .= $string . "\n";
}
else {
$string = date("Y-m-d, h:i:s") . ' Failed to create IMG: ' . realpath($fileUtil->getVideoThumbName($name)) . ' using: ' . $method;
echo $string . "<br />\n";
$logFile .= $string . "\n";
}
}
}
}
}
// Secondary iterator, searching thumbs dir for file to remove
$objects = new RecursiveIteratorIterator(new RecursiveDirectoryIterator(ARCHIVE_THUMBS), RecursiveIteratorIterator::SELF_FIRST);
foreach($objects as $thumb => $object){
$main = str_replace(ARCHIVE_THUMBS, ARCHIVE_MAIN, $thumb);
$video = $fileUtil->getVideoFromThumb($thumb);
if (substr($thumb, -1) != '.' && !is_dir($thumb) && !file_exists($main) && !file_exists($video))
{
$string = date("Y-m-d, h:i:s") . ' Removing FIL: ' . realpath($thumb);
echo $string . "<br />\n";
$logFile .= $string . "\n";
shell_exec('rm -rf ' . str_replace(' ', '\ ', $thumb));
}
}
// Third iterator, searching thumbs dir for empty dir to remove
$toRemove = array();
$objects = new RecursiveIteratorIterator(new RecursiveDirectoryIterator(ARCHIVE_THUMBS), RecursiveIteratorIterator::SELF_FIRST);
foreach($objects as $thumb => $object){
$main = str_replace(ARCHIVE_THUMBS, ARCHIVE_MAIN, $thumb);
if (substr($thumb, -1) != '.' && is_dir($thumb) && !file_exists($main))
{
array_push($toRemove, $thumb);
}
}
// Remove all directories in the toRemove array
foreach ($toRemove as $directory) {
$string = date("Y-m-d, h:i:s") . ' Removed DIR: ' . realpath($directory);
echo $string . "<br />\n";
$logFile .= $string . "\n";
shell_exec('rm -rf ' . str_replace(' ', '\ ', $directory));
}
// Write to the log file
file_put_contents(CRON_LOG, $logFile);
?>