File: do_command.php

package info (click to toggle)
gallery 1.5.4-3
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 26,712 kB
  • ctags: 6,567
  • sloc: php: 33,824; sh: 446; xml: 96; makefile: 88; perl: 61
file content (269 lines) | stat: -rw-r--r-- 8,587 bytes parent folder | download
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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
<?php
/*
 * Gallery - a web based photo album viewer and editor
 * Copyright (C) 2000-2006 Bharat Mediratta
 * 
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or (at
 * your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA  02110-1301, USA.
 *
 * $Id: do_command.php 13848 2006-06-19 12:04:01Z jenst $
 */
?>
<?php
require_once(dirname(__FILE__) . '/init.php');

list($index, $cmd, $return, $parentName, $rebuild_type, $albumName) = 
  getRequestVar(array('index', 'cmd', 'return', 'parentName', 'rebuild_type', 'albumName'));

/* 
 * Test for relative URL, which we know to be local.  If URL contains ://
 * assume that it's remote and test it against our local full URLs
 * to ensure security.  Don't check for http:// or https:// because
 * for all we know, someone put their album URL on a gopher server...
 */
$gUrl = makeGalleryUrl();
$gUrlStripped = substr($gUrl, 0, strrpos($gUrl, '/'));
if (!empty($return) && $return[0] != '/' && strstr($return, '://') !== false) {
    if (
      strncmp($return, $gUrlStripped, strlen($gUrlStripped)) != 0 &&
      strncmp($return, $gallery->app->photoAlbumURL, strlen($gallery->app->photoAlbumURL)) != 0 &&
      strncmp($return, $gallery->app->albumDirURL, strlen($gallery->app->albumDirURL)) != 0
      ) {
	die(_('Attempted security breach.'));
    }
}	

/* This is used for deleting comments from stats.php */
if (!empty($albumName)) {
	$gallery->album = new Album();
	$gallery->album->load($albumName);
}

if (empty($rebuild_type)) {
	$title = _("Rebuilding Thumbnails");
} else {
	$title = _("Performing Operation..");
}

switch ($cmd) {
    case 'rebuild_highlights':
        $albumDB = new AlbumDB(true);
        $albumList = $albumDB->albumList;
        $i = 0;
    
        foreach($albumList as $nr => $album) {
            if($album->isRoot()) {
                $i++;
                echo "\n<br><b>". sprintf (_("Rebuilding highlight %s"), $i) . '</b>';
                $album->setHighlight($album->getHighlight());
                $album->save();
            }
        }
        dismissAndReload();
    break;
    
	case 'remake-thumbnail':
		if ($gallery->user->canWriteToAlbum($gallery->album)) {
			if (empty($rebuild_type)) {
                printPopupStart($title, '', 'center');
				echo _("Do you also want to rebuild the thumbnails in subalbums?");
				echo makeFormIntro('do_command.php', array(),
					array('type' => 'popup',
					    'index' => $index,
					    'cmd' => $cmd, 
						'return' => $return,
						'parentName' => $parentName));
?>
		<br>
		<input type="radio" name="rebuild_type" value="recursive"><?php echo _("Yes"); ?>
		<input type="radio" name="rebuild_type" value="single" checked><?php echo _("No"); ?>
		<br><br>
		<input type="submit" value="<?php echo _("Start") ?>"><br><br>
	</form>
<?php
			}
			else {
			    printPopupStart($title, '', 'left');
				if ($rebuild_type == "single") {
					if ($gallery->session->albumName && isset($index)) {
						if ($index == "all") {
							$np = $gallery->album->numPhotos(1);
							echo ("\n<h3>" . sprintf(_("Rebuilding %d thumbnails..."), $np) .'</h3>');
							my_flush();
							for ($i = 1; $i <= $np; $i++) {
								echo("\n<h4>". sprintf(_("Processing image %d..."), $i) .'</h4>');
								my_flush();
								set_time_limit($gallery->app->timeLimit);
								$gallery->album->makeThumbnail($i);
							}
							echo "\n<hr width=\"100%\">";
						} else {
							echo ("\n<h3>" . _("Rebuilding 1 thumbnail...") .'</h3>');
							my_flush();
							set_time_limit($gallery->app->timeLimit);
							$gallery->album->makeThumbnail($index);
						}
						$gallery->album->save();
						//-- this is expected to be loaded in a popup, so dismiss ---
						dismissAndReload();
					}
				} else if ($rebuild_type == "recursive") {
					if ($gallery->session->albumName && isset($index)) {
						$gallery->album->makeThumbnailRecursive($index);
						$gallery->album->save();
						dismissAndReload();
					}
				}
			}
		}
	break;
	
	case 'logout':
		gallery_syslog("Logout by ". $gallery->session->username ." from ". $_SERVER['REMOTE_ADDR']);
		$gallery->session->username = '';
		$gallery->session->language = '';
		destroyGallerySession();

		// Prevent the 'you have to be logged in' error message
		// when the user logs out of a protected album
		createGallerySession();
		$gallery->session->gRedirDone = true;

		if (!ereg("^http|^{$gallery->app->photoAlbumURL}", $return)) {
			$return = makeGalleryHeaderUrl($return);
		}
		header("Location: $return");
	break;
	
	case 'hide':
		if ($gallery->user->canWriteToAlbum($gallery->album)) {
			$gallery->album->hidePhoto($index);
			$gallery->album->save();
		} else {
			if ($gallery->album->isAlbum($index)) {
				$myAlbumName = $gallery->album->getAlbumName($index);
				$myAlbum = new Album;
				$myAlbum->load($myAlbumName);
			}

			if ((isset($myAlbum) && $gallery->user->isOwnerOfAlbum($myAlbum)) || 
	   		$gallery->album->isItemOwner($gallery->user->getUid(), $index)) {
				$gallery->album->hidePhoto($index);
				$gallery->album->save();
			}
		}
		//-- this is expected to be loaded in a popup, so dismiss ---
		dismissAndReload();
	break;
		
	case 'show':
		if ($gallery->user->canWriteToAlbum($gallery->album)) {
			$gallery->album->unhidePhoto($index);
			$gallery->album->save();
		} else {
			if ($gallery->album->isAlbum($index)) {
				$myAlbumName = $gallery->album->getAlbumName($index);
				$myAlbum = new Album;
				$myAlbum->load($myAlbumName);
			}       
			
			if ((isset($myAlbum) && $gallery->user->isOwnerOfAlbum($myAlbum)) ||
		    		$gallery->album->isItemOwner($gallery->user->getUid(), $index)) {
					$gallery->album->unhidePhoto($index);
					$gallery->album->save();
			}
		}
		//-- this is expected to be loaded in a popup, so dismiss ---
		dismissAndReload();
	break;
		
	case 'highlight':
		if ($gallery->user->canWriteToAlbum($gallery->album)) {
			$gallery->album->setHighlight($index);
			$gallery->album->save(array(i18n("Changed Highlight")));
		}
		//-- this is expected to be loaded in a popup, so dismiss ---
		dismissAndReload();
	break;
		
	case 'new-album':
		if ($gallery->user->canCreateAlbums() ||
	    	$gallery->user->canCreateSubAlbum($gallery->album)) {
			if (!isset($parentName)) {
				$parentName = null;
			}
			createNewAlbum($parentName);
			if(!headers_sent()) { 
			    header("Location: " . makeAlbumHeaderUrl($gallery->session->albumName));
			} else {
			    $backUrl = makeAlbumUrl($gallery->session->albumName);
			}
		} else {
		        header("Location: " . makeAlbumHeaderUrl());
		}
	break;
		
	case 'reset-album-clicks':
		if ($gallery->user->canWriteToAlbum($gallery->album)) {
			$gallery->album->resetAllClicks();
			// this is a popup do dismiss and reload!
			dismissAndReload();
		} else {
       			header("Location: " . makeAlbumHeaderUrl());
		}
	break;
		
	case 'delete-comment':
		if ($gallery->user->canWriteToAlbum($gallery->album)) {
			$comment_index = getRequestVar('comment_index');
			$comment=$gallery->album->getComment($index, $comment_index); 
			$gallery->album->deleteComment($index, $comment_index);
			$gallery->album->save(array(i18n("Comment \"%s\" by %s deleted from %s"),
					$comment->getCommentText(),
				       	$comment->getName(),
				       	makeAlbumURL($gallery->album->fields["name"], 
						$gallery->album->getPhotoId($index))));
			if (!empty($return)) {
				dismissAndLoad($return);
			}
			else {
				dismissAndReload();
			}
		} else {
	    	    header("Location: " . makeAlbumHeaderUrl());
		}
	break;
	
	default:
		if (!empty($return)) {
			// No command; Can be used to set a session variable
			header("Location: $return");
		}
	break;
}

?>

	<div align="center">
	<form>
<?php if (isset($backUrl)) :?>
		<input type="button" value="<?php echo _("Dismiss") ?>" onclick="document.location='<?php echo $backUrl; ?>'">
<?php else : ?>
		<input type="button" value="<?php echo _("Dismiss") ?>" onclick="parent.close()">
<?php endif ?>
	</form>
	</div>
</div>
</body>
</html>