cleanup: moved more CSS into the stylesheet
[phpfspot.git] / gen_thumbs.php
1 #!/usr/bin/php
2 <?php
3
4 /***************************************************************************
5  *
6  * phpfspot, presents your F-Spot photo collection in Web browsers.
7  *
8  * Copyright (c) by Andreas Unterkircher
9  *
10  *  This program is free software; you can redistribute it and/or modify
11  *  it under the terms of the GNU General Public License as published by
12  *  the Free Software Foundation; either version 2 of the License, or
13  *  any later version.
14  *
15  *  This program is distributed in the hope that it will be useful,
16  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  *  GNU General Public License for more details.
19  *
20  *  You should have received a copy of the GNU General Public License
21  *  along with this program; if not, write to the Free Software
22  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23  *
24  ***************************************************************************/
25
26
27 /**
28  * gen_thumbs.php
29  *
30  * generate photo thumbnails on the console to avoid webserver overload
31  *
32  * @package phpfspot
33  */
34 if(!isset($_SERVER["TERM"])) {
35    print "<br /><br />This script should only be invoked from command line!<br />\n";
36    die;
37 }
38
39 require_once "phpfspot.class.php";
40
41 $fspot = new PHPFSPOT;
42 $fspot->fromcmd = true;
43
44 $overwrite = false;
45
46 $short_options = "";
47 $short_options.= "h"; /* help */
48 $short_options.= "o"; /* overwrite */
49 $short_options.= "c"; /* cleanup */
50
51 $long_options = array(
52    "help",
53    "overwrite",
54    "cleanup",
55 );
56
57 /* command line option specified? */
58 if(isset($_SERVER['argc']) && $_SERVER['argc'] > 1) {
59    /* validate */
60    $con = new Console_Getopt;
61    $args = $con->readPHPArgv(); 
62    $options = $con->getopt($args, $short_options, $long_options);
63
64    if(PEAR::isError($options)) {
65       die ("Error in command line: " . $options->getMessage() . "\n");
66    }
67
68    foreach($options[0] as $opt) {
69       switch($opt[0]) {
70          case 'h':
71          case '--help':
72             print "we need some help here!\n";
73             exit(0);
74             break;
75          case 'o':
76          case '--overwrite':
77             print "Overwrite flag set!\n";
78             $overwrite = true;
79             break;
80          case 'c':
81          case '--cleanup':
82             $fspot->cleanup_phpfspot_db();
83             exit(0);
84             break;
85          default:
86             print "invalid option";
87             exit(1);
88             break;
89       }
90    }
91 }
92
93 $all = $fspot->getPhotoSelection();
94
95 foreach($all as $photo) {
96    $fspot->gen_thumb($photo, $overwrite);
97 }
98
99 ?>