Subversion Repositories svnkaklik

Rev

Go to most recent revision | Details | Last modification | View Log

Rev Author Line No. Line
6 kaklik 1
<?php
2
/*************************
3
  Coppermine Photo Gallery
4
  ************************
5
  Copyright (c) 2003-2005 Coppermine Dev Team
6
  v1.1 originaly written by Gregory DEMAR
7
 
8
  This program is free software; you can redistribute it and/or modify
9
  it under the terms of the GNU General Public License as published by
10
  the Free Software Foundation; either version 2 of the License, or
11
  (at your option) any later version.
12
  ********************************************
13
  Coppermine version: 1.3.3
14
  $Source: /cvsroot/coppermine/stable/util.php,v $
15
  $Revision: 1.13 $
16
  $Author: gaugau $
17
  $Date: 2005/04/19 03:17:11 $
18
**********************************************/
19
 
20
define('IN_COPPERMINE', true);
21
define('UTIL_PHP', true);
22
 
23
require('include/init.inc.php');
24
require('include/picmgmt.inc.php');
25
 
26
pageheader($lang_util_php['title']);
27
 
28
// USER CONFIGURATION
29
// Default number of pictures to process at a time when rebuilding thumbs or normals:
30
$defpicnum = 45;
31
// END USER CONFIGURATION
32
 
33
if (!GALLERY_ADMIN_MODE) die('Access denied');
34
 
35
global $albumtbl, $picturetbl, $categorytbl, $usertbl, $lang_util_php;
36
$albumtbl = $CONFIG['TABLE_PREFIX'] . 'albums';
37
$picturetbl = $CONFIG['TABLE_PREFIX'] . 'pictures';
38
$categorytbl = $CONFIG['TABLE_PREFIX'] . 'categories';
39
$usertbl = $CONFIG['TABLE_PREFIX'] . 'users';
40
 
41
// initialize vars
42
$startpic = '';
43
$action = "";
44
$action = $_POST['action'];
45
 
46
 
47
MYSQL_CONNECT($CONFIG['dbserver'], $CONFIG['dbuser'], $CONFIG['dbpass']) or die("can't connect to mysql server");
48
MYSQL_SELECT_DB($CONFIG['dbname']);
49
 
50
function my_flush()
51
{
52
    print str_repeat(" ", 4096); // force a flush
53
}
54
 
55
function filenametotitle($delete)
56
{
57
    $albumid = $_POST['albumid'];
58
    $parsemode = $_POST['parsemode'];
59
    global $picturetbl, $lang_util_php;
60
 
61
    $query = "SELECT * FROM $picturetbl WHERE aid = '$albumid'";
62
    $result = db_query($query);
63
    $num = mysql_numrows($result);
64
 
65
    $i = 0;
66
    while ($i < $num) {
67
        $filename = mysql_result($result, $i, "filename");
68
        $pid = mysql_result($result, $i, "pid");
69
        // //////////////////////////////////////////
70
        // ADD YOUR OWN PARSEMODES HERE //
71
        // /////////////////////////////////////////
72
        $pattern = "/(\d+)(.)(\d+)(.)(\d+)(.)(\d+)(.)(\d+)(.)(\d+)(.+)/";
73
 
74
        if ($delete == '0') {
75
            if ($parsemode == 0) {
76
                // REMOVE .JPG AND REPLACE _ WITH [ ]
77
                $filename = substr($filename, 0, -4);
78
                $newtitle = str_replace("_", " ", $filename);
79
            } else if ($parsemode == 1) {
80
                // CHANGE 2003_11_23_13_20_20.jpg TO 23/11/2003 13:20
81
                $newtitle = str_replace("%20", " ", $filename);
82
                $replacement = "$5/$3/$1 $7:$9";
83
                $newtitle = preg_replace($pattern, $replacement, $filename);
84
            } else if ($parsemode == 2) {
85
                // CHANGE 2003_11_23_13_20_20.jpg TO 11/23/2003 13:20
86
                $newtitle = str_replace("%20", " ", $filename);
87
                $replacement = "$3/$5/$1 $7:$9";
88
                $newtitle = preg_replace($pattern, $replacement, $filename);
89
            } else if ($parsemode == 3) {
90
                // CHANGE 2003_11_23_13_20_20.jpg TO 13:20
91
                $newtitle = str_replace("%20", " ", $filename);
92
                $replacement = "$7:$9";
93
                $newtitle = preg_replace($pattern, $replacement, $filename);
94
            }
95
        } else {
96
            $newtitle = '';
97
        }
98
 
99
        print $lang_util_php['file'] . ': '.$filename.' ' . $lang_util_php['title_set_to'] . ':'. $newtitle.'<br />';
100
        my_flush();
101
 
102
        $query = "UPDATE $picturetbl SET title='$newtitle' WHERE pid='$pid' ";
103
        db_query($query);
104
 
105
        ++$i;
106
    }
107
}
108
 
109
function filloptions()
110
{
111
    global $albumtbl, $picturetbl, $categorytbl, $usertbl, $lang_util_php;
112
 
113
    $query = "SELECT aid, category, IF(user_name IS NOT NULL, CONCAT('(', user_name, ') ',title), CONCAT(' - ', title)) AS title " . "FROM $albumtbl AS a " . "LEFT JOIN $usertbl AS u ON category = (" . FIRST_USER_CAT . " + user_id) " . "ORDER BY category, title";
114
    $result = db_query($query);
115
    // $num=mysql_numrows($result);
116
    echo '<select size="1" name="albumid">';
117
 
118
    while ($row = mysql_fetch_array($result)) {
119
        $sql = "SELECT name FROM $categorytbl WHERE cid = " . $row["category"];
120
        $result2 = db_query($sql);
121
        $row2 = mysql_fetch_array($result2);
122
 
123
        print "<option value=\"" . $row["aid"] . "\">" . $row2["name"] . $row["title"] . "</option>\n";
124
    }
125
 
126
    print '</select> (3)';
127
    print '&nbsp;&nbsp;&nbsp;&nbsp;<input type="submit" value="'.$lang_util_php['submit_form'].'" class="button" /> (4)';
128
    print '</form>';
129
}
130
 
131
function updatethumbs()
132
{
133
    global $picturetbl, $CONFIG, $lang_util_php;
134
    $phpself = $_SERVER['PHP_SELF'];
135
    $albumid = $_POST['albumid'];
136
    $updatetype = $_POST['updatetype'];
137
    $numpics = $_POST['numpics'];
138
    $startpic = 0;
139
    $startpic = $_POST['startpic'];
140
 
141
    $query = "SELECT * FROM $picturetbl WHERE aid = '$albumid'";
142
    $result = db_query($query);
143
    $totalpics = mysql_numrows($result);
144
 
145
    if ($startpic == 0) {
146
        // 0 - numpics
147
        $num = $totalpics;
148
        // Over picture limit
149
        if ($totalpics > $numpics) $num = $startpic + $numpics;
150
    } else {
151
        // startpic - numpics
152
        $num = $startpic + $numpics;
153
        if ($num > $totalpics) $num = $totalpics;
154
    }
155
 
156
    $i = $startpic;
157
    while ($i < $num) {
158
        $image = $CONFIG['fullpath'] . mysql_result($result, $i, "filepath") . mysql_result($result, $i, "filename");
159
 
160
        if ($updatetype == 0 || $updatetype == 2) {
161
            $thumb = $CONFIG['fullpath'] . mysql_result($result, $i, "filepath") . $CONFIG['thumb_pfx'] . mysql_result($result, $i, "filename");
162
 
163
            if (resize_image($image, $thumb, $CONFIG['thumb_width'], $CONFIG['thumb_method'], $CONFIG['thumb_use'])) {
164
                print $thumb .' '. $lang_util_php['updated_succesfully'] . '!<br />';
165
                my_flush();
166
            } else {
167
                print $lang_util_php['error_create'] . ':$thumb<br />';
168
                my_flush();
169
            }
170
        }
171
 
172
        if ($updatetype == 1 || $updatetype == 2) {
173
            $normal = $CONFIG['fullpath'] . mysql_result($result, $i, "filepath") . $CONFIG['normal_pfx'] . mysql_result($result, $i, "filename");
174
 
175
            $imagesize = getimagesize($image);
176
            if (max($imagesize[0], $imagesize[1]) > $CONFIG['picture_width'] && $CONFIG['make_intermediate']) {
177
                if (resize_image($image, $normal, $CONFIG['picture_width'], $CONFIG['thumb_method'], $CONFIG['thumb_use'])) {
178
                    print $normal . $lang_util_php['updated_succesfully'] . '!<br />';
179
                    my_flush();
180
                } else {
181
                    print $lang_util_php['error_create'] . ':$normal<br />';
182
                    my_flush();
183
                }
184
            }
185
        }
186
 
187
        ++$i;
188
    }
189
    $startpic = $i;
190
 
191
    if ($startpic < $totalpics) {
192
 
193
        ?>
194
            <form action="<?php echo $phpself; ?>" method="post">
195
                    <input type="hidden" name="action" value="continuethumbs" />
196
                    <input type="hidden" name="numpics" value="<?php echo $numpics?>" />
197
                    <input type="hidden" name="startpic" value="<?php echo $startpic?>" />
198
                    <input type="hidden" name="updatetype" value="<?php echo $updatetype?>" />
199
            <input type="hidden" name="albumid" value="<?php echo $albumid?>" />
200
            <input type="submit" value="<?php print $lang_util_php['continue'];
201
        ?>" class="button" /></form>
202
                    <?php
203
    }
204
}
205
 
206
function deleteorig()
207
{
208
    global $picturetbl, $CONFIG, $lang_util_php;
209
    $albumid = $_POST['albumid'];
210
 
211
    $query = "SELECT * FROM $picturetbl WHERE aid = '$albumid'";
212
    $result = db_query($query);
213
    $num = mysql_numrows($result);
214
 
215
    $i = 0;
216
    while ($i < $num) {
217
        $pid = mysql_result($result, $i, "pid");
218
        $image = $CONFIG['fullpath'] . mysql_result($result, $i, "filepath") . mysql_result($result, $i, "filename");
219
        $normal = $CONFIG['fullpath'] . mysql_result($result, $i, "filepath") . $CONFIG['normal_pfx'] . mysql_result($result, $i, "filename");
220
        $thumb = $CONFIG['fullpath'] . mysql_result($result, $i, "filepath") . $CONFIG['thumb_pfx'] . mysql_result($result, $i, "filename");
221
 
222
        if (file_exists($normal)) {
223
                        unlink($image);
224
                        $test = rename($normal, $image);
225
            if ($test == true) {
226
                $imagesize = getimagesize($image);
227
                $image_filesize = filesize($image);
228
                $total_filesize = $image_filesize + filesize($thumb);
229
 
230
                $query = "UPDATE $picturetbl SET filesize='$image_filesize' WHERE pid='$pid' ";
231
                db_query($query);
232
 
233
                $query = "UPDATE $picturetbl SET total_filesize='$total_filesize' WHERE pid='$pid' ";
234
                db_query($query);
235
 
236
                $query = "UPDATE $picturetbl SET pwidth='{$imagesize[0]}' WHERE pid='$pid' ";
237
                db_query($query);
238
 
239
                $query = "UPDATE $picturetbl SET pheight='{$imagesize[1]}' WHERE pid='$pid' ";
240
                db_query($query);
241
                printf($lang_util_php['main_success'], $normal);
242
                print '!<br>';
243
            } else {
244
                printf($lang_util_php['error_rename'], $normal, $image);
245
            }
246
        } else {
247
            printf($lang_util_php['error_not_found'], $normal);
248
            print '<br>';
249
        }
250
 
251
        ++$i;
252
    }
253
}
254
 
255
function deleteorphans()
256
{
257
        global $picturetbl, $CONFIG, $lang_util_php;
258
        $phpself = $_SERVER['PHP_SELF'];
259
        $del = $_POST['del'];
260
        $single = $_POST['single'];
261
        $count = 0;
262
 
263
        if ($single) {
264
          $delone = db_query("DELETE FROM {$CONFIG['TABLE_COMMENTS']} WHERE msg_id=$single") or die ("failed to delete msgs - " . mysql_error());
265
        }
266
 
267
        $result = db_query("SELECT pid,msg_id,msg_body FROM {$CONFIG['TABLE_COMMENTS']} WHERE 1");
268
 
269
        while ($row = mysql_fetch_array($result)) {
270
                $pid = $row['pid'];
271
                $msg_id = $row['msg_id'];
272
                $msg_body = $row['msg_body'];
273
                $result2 = db_query("SELECT * FROM {$CONFIG['TABLE_PICTURES']} WHERE pid=$pid");
274
                if (!mysql_num_rows($result2)) {
275
                        if ($del == "all")
276
                        {
277
                        $Deletions = db_query("DELETE FROM {$CONFIG['TABLE_COMMENTS']} WHERE msg_id=$msg_id") or die ("failed to delete msgs - " . mysql_error());
278
                        } else {
279
                                $count++;
280
                                ?>
281
                                <form action="<?php echo $phpself;?>" method="post">
282
                                <input type="hidden" name="action" value="delorphans" />
283
                                <input type="hidden" name="single" value="<?php echo $msg_id; ?>" />
284
                                <?php echo $lang_util_php['comment'].' "'.$msg_body.'" '.$lang_util_php['nonexist'].' '.$pid; ?>
285
                                <input type="submit" value="<?php print $lang_util_php['delete'];?>" class="button" /></form>
286
                                 <?php
287
                        }
288
                }
289
 
290
        }
291
 
292
        echo '<br>'.$count.' '.$lang_util_php['orphan_comment'].'<br><br>';
293
        if ($count>=1) {
294
        ?>
295
        <form action="<?php echo $phpself;?>" method="post">
296
        <input type="hidden" name="action" value="delorphans" />
297
        <input type="hidden" name="del" value="all" />
298
        Delete all orphans?
299
        <input type="submit" value="<?php print $lang_util_php['delete_all'];?>" class="button" /></form>
300
         <?php
301
        }
302
}
303
 
304
 
305
$phpself = $_SERVER['PHP_SELF'];
306
// start output
307
print '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
308
<html>
309
<head>
310
<title>' . $lang_util_php['title'] . '</title>
311
</head>
312
<style type="text/css">
313
.labelradio { cursor : hand;}
314
/*.accesskey {text-decoration:underline}*/
315
</style>
316
<body>';
317
 
318
if ($action == 'thumbs') {
319
    global $picturetbl, $CONFIG;
320
 
321
    print '<a href="' . $phpself . '">' . $lang_util_php['back'] . '</a><br />';
322
    print '<h2>' . $lang_util_php['thumbs_wait'] . '</h2>';
323
 
324
    updatethumbs();
325
 
326
    echo '<br /><a href="' . $phpself . '">' . $lang_util_php['back'] . '</a>';
327
} else if ($action == 'continuethumbs') {
328
    print '<a href="' . $phpself . '">' . $lang_util_php['back'] . '</a><br />';
329
    print '<h2>' . $lang_util_php['thumbs_continue_wait'] . '</h2>';
330
 
331
    updatethumbs();
332
 
333
    echo '<br /><a href="' . $phpself . '">' . $lang_util_php['back'] . '</a>';
334
} else if ($action == 'title') {
335
    echo '<a href="' . $phpself . '">' . $lang_util_php['back'] . '</a><br />';
336
    print '<h2>' . $lang_util_php['titles_wait'] . '</h2>';
337
 
338
    filenametotitle(0);
339
 
340
    echo '<br /><a href="' . $phpself . '">' . $lang_util_php['back'] . '</a>';
341
} else if ($action == 'deltit') {
342
    print '<a href="' . $phpself . '">' . $lang_util_php['back'] . '</a><br />';
343
    print '<h2>' . $lang_util_php['delete_wait'] . '</h2>';
344
 
345
    filenametotitle(1);
346
 
347
    echo '<br /><a href="' . $phpself . '">' . $lang_util_php['back'] . '</a>';
348
} else if ($action == 'delnorm') {
349
    print '<a href="' . $phpself . '">' . $lang_util_php['back'] . '</a><br />';
350
    print '<h2>' . $lang_util_php['replace_wait'] . '</h2>';
351
 
352
    deleteorig();
353
 
354
    echo '<br /><a href="' . $phpself . '">' . $lang_util_php['back'] . '</a>';
355
} else if ($action == 'delorphans') {
356
    deleteorphans();
357
    echo '<br /><a href="' . $phpself . '">' . $lang_util_php['back'] . '</a>';
358
} else {
359
    starttable('100%');
360
 
361
    print '<tr><td>';
362
    starttable('100%', $lang_util_php['title'] . ' (util.mod)', 2);
363
    print '<tr><td class="tablef"><b>';
364
    print $lang_util_php['what_it_does'] . '</b>:
365
<ul style="margin-top:0px;margin-bottom:0px;list-style-type:square">
366
<li>' . $lang_util_php['what_update_titles'] . '</li>
367
<li>' . $lang_util_php['what_delete_title'] . '</li>
368
<li>' . $lang_util_php['what_rebuild'] . '</li>
369
<li>' . $lang_util_php['what_delete_originals'] . '</li>
370
</ul></td>
371
<td class="tableb"><b>
372
' . $lang_util_php['instruction'] . '</b>:
373
<br />
374
(1) ' . $lang_util_php['instruction_action'] . '<br />
375
(2) ' . $lang_util_php['instruction_parameter'] . '<br />
376
(3) ' . $lang_util_php['instruction_album'] . '<br />
377
(4) ';
378
    printf($lang_util_php['instruction_press'], $lang_util_php['submit_form']);
379
    print '
380
';
381
 
382
    print '</td></tr>';
383
    endtable();
384
    print '<br />
385
<form action="' . $phpself . '" method="post">
386
';
387
 
388
    starttable('100%', '<input type="radio" name="action" checked="checked" value="thumbs" id="thumbs" class="nobg" /><label for="thumbs" accesskey="t" class="labelradio">' . $lang_util_php['update'] . '</label> (1)');
389
    print '
390
<tr><td>
391
' . $lang_util_php['update_what'] . ' (2):<br />
392
<input type="radio" name="updatetype" value="0" id="thumb" class="nobg" /><label for="thumb" accesskey="t" class="labelradio">' . $lang_util_php['update_thumb'] . '</label><br />
393
<input type="radio" name="updatetype" value="1" id="resized" class="nobg" /><label for="resized" accesskey="r" class="labelradio">' . $lang_util_php['update_pic'] . '</label><br />
394
<input type="radio" name="updatetype" value="2" checked="checked" id="all" class="nobg" /><label for="all" accesskey="a" class="labelradio">' . $lang_util_php['update_both'] . '</label><br />
395
' . $lang_util_php['update_number'] . '
396
<input type="text" name="numpics" value="' . $defpicnum . '" size="5" /><br />
397
' . $lang_util_php['update_option'] . '<br /><br />
398
</td></tr>';
399
    endtable();
400
 
401
    print '<br />';
402
 
403
    starttable('100%', '<input type="radio" name="action" value="title" id="title" class="nobg" /><label for="title" accesskey="F" class="labelradio">' . $lang_util_php['filename_title'] . '</label> (1)');
404
    print '
405
<tr><td>
406
' . $lang_util_php['filename_how'] . ' (2):<br />
407
<input type="radio" name="parsemode" checked="checked" value="0" id="remove" class="nobg" /><label for="remove" accesskey="s" class="labelradio">' . $lang_util_php['filename_remove'] . '</label><br />
408
<input type="radio" name="parsemode" value="1" id="euro" class="nobg" /><label for="euro" accesskey="e" class="labelradio">' . $lang_util_php['filename_euro'] . '</label><br />
409
<input type="radio" name="parsemode" value="2" id="us" class="nobg" /><label for="us" accesskey="u" class="labelradio">' . $lang_util_php['filename_us'] . '</label><br />
410
<input type="radio" name="parsemode" value="3" id="hour" class="nobg" /><label for="hour" accesskey="h" class="labelradio">' . $lang_util_php['filename_time'] . '</label><br /><br />
411
</td></tr>';
412
    endtable();
413
 
414
    print '<br />';
415
 
416
    starttable('100%', '<input type="radio" name="action" value="deltit" id="deltit" class="nobg" /><label for="deltit" accesskey="D" class="labelradio">' . $lang_util_php['delete_title'] . '</label> (1)');
417
    endtable();
418
    print '<br />';
419
 
420
    starttable('100%', '<input type="radio" name="action" value="delorphans" id="delorphans" class="nobg" /><label for="delorphans" accesskey="O" class="labelradio">' . $lang_util_php['delete_orphans'] . '</label> (1)');
421
    endtable();
422
    print '<br />';
423
 
424
    starttable('100%', '<input type="radio" name="action" value="delnorm" id="delnorm" class="nobg" /><label for="delnorm" accesskey="e" class="labelradio">' . $lang_util_php['delete_original'] . '</label> (1)');
425
    endtable();
426
    print '<br />';
427
 
428
    starttable('100%', '<a href="phpinfo.php">' . $lang_util_php['phpinfo'] . '</a> (1)');
429
    endtable();
430
    print '<br />';
431
 
432
    starttable('100%', '<a href="update.php">' . $lang_util_php['update_db'] . '</a> (1)');
433
    print '<tr><td>'.$lang_util_php['update_db_explanation'].'</td></tr>';
434
    endtable();
435
    print '<br />';
436
 
437
    print '&nbsp;<br />';
438
 
439
    print '<h2>'.$lang_util_php['select_album'].'</h2>';
440
 
441
    if (defined('UDB_INTEGRATION')) {
442
        udb_util_filloptions();
443
    } else {
444
        filloptions();
445
    }
446
 
447
}
448
print '</td></tr>';
449
endtable();
450
echo 'Util.mod 1.4 - Created by David Alberg Holm';
451
pagefooter();
452
ob_end_flush();
453
 
454
?>