1 | <?php |
---|
2 | /** |
---|
3 | * Show a list of images in a long horizontal table. |
---|
4 | * @author $Author:ray $ |
---|
5 | * @version $Id:images.php 987 2008-04-12 12:39:04Z ray $ |
---|
6 | * @package ImageManager |
---|
7 | */ |
---|
8 | |
---|
9 | require_once('config.inc.php'); |
---|
10 | require_once('ddt.php'); |
---|
11 | require_once('Classes/ImageManager.php'); |
---|
12 | |
---|
13 | // uncomment for debugging |
---|
14 | |
---|
15 | // _ddtOn(); |
---|
16 | |
---|
17 | //default path is / |
---|
18 | $relative = '/'; |
---|
19 | $manager = new ImageManager($IMConfig); |
---|
20 | |
---|
21 | //process any file uploads |
---|
22 | $manager->processUploads(); |
---|
23 | |
---|
24 | if($IMConfig['allow_delete']) |
---|
25 | { |
---|
26 | $manager->deleteFiles(); |
---|
27 | } |
---|
28 | |
---|
29 | $refreshDir = false; |
---|
30 | //process any directory functions |
---|
31 | if(($IMConfig['allow_delete'] && $manager->deleteDirs()) || $manager->processNewDir()) |
---|
32 | $refreshDir = true; |
---|
33 | |
---|
34 | //check for any sub-directory request |
---|
35 | //check that the requested sub-directory exists |
---|
36 | //and valid |
---|
37 | if(isset($_REQUEST['dir'])) |
---|
38 | { |
---|
39 | $path = rawurldecode($_REQUEST['dir']); |
---|
40 | if($manager->validRelativePath($path)) |
---|
41 | $relative = $path; |
---|
42 | } |
---|
43 | |
---|
44 | |
---|
45 | $manager = new ImageManager($IMConfig); |
---|
46 | |
---|
47 | |
---|
48 | //get the list of files and directories |
---|
49 | $list = $manager->getFiles($relative); |
---|
50 | |
---|
51 | |
---|
52 | /* ================= OUTPUT/DRAW FUNCTIONS ======================= */ |
---|
53 | |
---|
54 | /** |
---|
55 | * Draw the files in an table. |
---|
56 | */ |
---|
57 | function drawFiles($list, &$manager) |
---|
58 | { |
---|
59 | global $relative; |
---|
60 | global $IMConfig; |
---|
61 | |
---|
62 | switch($IMConfig['ViewMode']) |
---|
63 | { |
---|
64 | case 'details': |
---|
65 | { |
---|
66 | ?> |
---|
67 | <script language="Javascript"> |
---|
68 | <!-- |
---|
69 | function showPreview(f_url) |
---|
70 | { |
---|
71 | |
---|
72 | window.parent.document.getElementById('f_preview').src = |
---|
73 | window.parent._backend_url + '__function=thumbs&img=' + f_url; |
---|
74 | } |
---|
75 | //--> |
---|
76 | </script> |
---|
77 | <table class="listview"> |
---|
78 | <thead> |
---|
79 | <tr><th>Name</th><th>Filesize</th><th>Dimensions</th></tr></thead> |
---|
80 | <tbody> |
---|
81 | <?php |
---|
82 | foreach($list as $entry => $file) |
---|
83 | { |
---|
84 | ?> |
---|
85 | <tr> |
---|
86 | <th><a href="#" class="thumb" style="cursor: pointer;" onclick="selectImage('<?php echo $file['relative'];?>', '<?php echo $entry; ?>', <?php echo $file['image'][0];?>, <?php echo $file['image'][1]; ?>);return false;" title="<?php echo $entry; ?> - <?php echo Files::formatSize($file['stat']['size']); ?>" onmouseover="showPreview('<?php echo $file['relative'];?>')" onmouseout="showPreview(window.parent.document.getElementById('f_url').value)" ><?php echo $entry ?></a></th> |
---|
87 | <td><?php echo Files::formatSize($file['stat']['size']); ?></td> |
---|
88 | <td><?php if($file['image']){ echo $file['image'][0].'x'.$file['image'][1]; } ?></td> |
---|
89 | <td class="actions"> |
---|
90 | <?php |
---|
91 | if($IMConfig['allow_delete']) |
---|
92 | { |
---|
93 | ?> |
---|
94 | <a href="<?php print $IMConfig['backend_url']; ?>__function=images&dir=<?php echo $relative; ?>&delf=<?php echo rawurlencode($file['relative']);?>" title="Trash" onclick="return confirmDeleteFile('<?php echo $entry; ?>');"><img src="<?php print $IMConfig['base_url'];?>img/edit_trash.gif" height="15" width="15" alt="Trash" border="0" /></a> |
---|
95 | <?php |
---|
96 | } |
---|
97 | ?> |
---|
98 | <?php |
---|
99 | if($IMConfig['allow_edit']) |
---|
100 | { |
---|
101 | ?> |
---|
102 | <a href="javascript:;" title="Edit" onclick="editImage('<?php echo rawurlencode($file['relative']);?>');"><img src="<?php print $IMConfig['base_url'];?>img/edit_pencil.gif" height="15" width="15" alt="Edit" border="0" /></a> |
---|
103 | <?php |
---|
104 | } |
---|
105 | ?> |
---|
106 | </td> |
---|
107 | </tr> |
---|
108 | <?php |
---|
109 | } |
---|
110 | ?> |
---|
111 | </tbody> |
---|
112 | </table> |
---|
113 | <?php |
---|
114 | } |
---|
115 | break; |
---|
116 | |
---|
117 | case 'thumbs': |
---|
118 | default : |
---|
119 | { |
---|
120 | foreach($list as $entry => $file) |
---|
121 | { |
---|
122 | ?> |
---|
123 | <div class="thumb_holder" id="holder_<?php echo asc2hex($entry) ?>"> |
---|
124 | <a href="#" class="thumb" style="cursor: pointer;" onclick="selectImage('<?php echo $file['relative'];?>', '<?php echo $entry; ?>', <?php echo $file['image'][0];?>, <?php echo $file['image'][1]; ?>);return false;" title="<?php echo $entry; ?> - <?php echo Files::formatSize($file['stat']['size']); ?>"> |
---|
125 | <img src="<?php print $manager->getThumbnail($file['relative']); ?>" alt="<?php echo $entry; ?> - <?php echo Files::formatSize($file['stat']['size']); ?>"/> |
---|
126 | </a> |
---|
127 | <div class="edit"> |
---|
128 | |
---|
129 | <?php |
---|
130 | if($IMConfig['allow_delete']) |
---|
131 | { |
---|
132 | ?> |
---|
133 | <a href="<?php print $IMConfig['backend_url']; ?>__function=images&dir=<?php echo $relative; ?>&delf=<?php echo rawurlencode($file['relative']);?>" title="Trash" onclick="return confirmDeleteFile('<?php echo $entry; ?>');"><img src="<?php print $IMConfig['base_url'];?>img/edit_trash.gif" height="15" width="15" alt="Trash" /></a> |
---|
134 | <?php |
---|
135 | } |
---|
136 | ?> |
---|
137 | |
---|
138 | <?php |
---|
139 | if($IMConfig['allow_edit']) |
---|
140 | { |
---|
141 | ?> |
---|
142 | <a href="javascript:;" title="Edit" onclick="editImage('<?php echo rawurlencode($file['relative']);?>');"><img src="<?php print $IMConfig['base_url'];?>img/edit_pencil.gif" height="15" width="15" alt="Edit" /></a> |
---|
143 | <?php |
---|
144 | } |
---|
145 | ?> |
---|
146 | <?php if($file['image']){ echo $file['image'][0].'x'.$file['image'][1]; } else echo $entry;?> |
---|
147 | </div> |
---|
148 | </div> |
---|
149 | <?php |
---|
150 | } |
---|
151 | } |
---|
152 | } |
---|
153 | }//function drawFiles |
---|
154 | |
---|
155 | |
---|
156 | /** |
---|
157 | * Draw the directory. |
---|
158 | */ |
---|
159 | function drawDirs($list, &$manager) |
---|
160 | { |
---|
161 | global $relative; |
---|
162 | global $IMConfig; |
---|
163 | |
---|
164 | switch($IMConfig['ViewMode']) |
---|
165 | { |
---|
166 | case 'details': |
---|
167 | { |
---|
168 | |
---|
169 | } |
---|
170 | break; |
---|
171 | |
---|
172 | case 'thumbs': |
---|
173 | default : |
---|
174 | { |
---|
175 | foreach($list as $path => $dir) |
---|
176 | { ?> |
---|
177 | <div class="dir_holder"> |
---|
178 | <a class="dir" href="<?php print $IMConfig['backend_url'];?>__function=images&dir=<?php echo rawurlencode($path); ?>" onclick="updateDir('<?php echo $path; ?>')" title="<?php echo $dir['entry']; ?>"><img src="<?php print $IMConfig['base_url'];?>img/folder.gif" height="80" width="80" alt="<?php echo $dir['entry']; ?>" /></a> |
---|
179 | |
---|
180 | <div class="edit"> |
---|
181 | <?php |
---|
182 | if($IMConfig['allow_delete']) |
---|
183 | { |
---|
184 | ?> |
---|
185 | <a href="<?php print $IMConfig['backend_url'];?>__function=images&dir=<?php echo $relative; ?>&deld=<?php echo rawurlencode($path); ?>" title="Trash" onclick="return confirmDeleteDir('<?php echo $dir['entry']; ?>', <?php echo $dir['count']; ?>);"><img src="<?php print $IMConfig['base_url'];?>img/edit_trash.gif" height="15" width="15" alt="Trash"/></a> |
---|
186 | <?php |
---|
187 | } |
---|
188 | ?> |
---|
189 | |
---|
190 | <?php echo $dir['entry']; ?> |
---|
191 | </div> |
---|
192 | </div> |
---|
193 | <?php |
---|
194 | } //foreach |
---|
195 | } |
---|
196 | } |
---|
197 | |
---|
198 | |
---|
199 | }//function drawDirs |
---|
200 | |
---|
201 | |
---|
202 | /** |
---|
203 | * No directories and no files. |
---|
204 | */ |
---|
205 | function drawNoResults() |
---|
206 | { |
---|
207 | ?> |
---|
208 | <div class="noResult">No Images Found</div> |
---|
209 | <?php |
---|
210 | } |
---|
211 | |
---|
212 | /** |
---|
213 | * No directories and no files. |
---|
214 | */ |
---|
215 | function drawErrorBase(&$manager) |
---|
216 | { |
---|
217 | ?> |
---|
218 | <div class="error"><span>Invalid base directory:</span> <?php echo $manager->config['images_dir']; ?></div> |
---|
219 | <?php |
---|
220 | } |
---|
221 | |
---|
222 | /** |
---|
223 | * Utility to convert ascii string to hex |
---|
224 | */ |
---|
225 | function asc2hex ($temp) |
---|
226 | { |
---|
227 | $len = strlen($temp); |
---|
228 | $data = ""; |
---|
229 | for ($i=0; $i<$len; $i++) $data.=sprintf("%02x",ord(substr($temp,$i,1))); |
---|
230 | return $data; |
---|
231 | } |
---|
232 | |
---|
233 | ?> |
---|
234 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
---|
235 | |
---|
236 | <html> |
---|
237 | <head> |
---|
238 | <title>Image List</title> |
---|
239 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> |
---|
240 | <link href="<?php print $IMConfig['base_url'];?>assets/imagelist.css" rel="stylesheet" type="text/css" /> |
---|
241 | <script type="text/javascript"> |
---|
242 | _backend_url = "<?php print $IMConfig['backend_url']; ?>"; |
---|
243 | </script> |
---|
244 | |
---|
245 | <script type="text/javascript" src="<?php print $IMConfig['base_url'];?>assets/dialog.js"></script> |
---|
246 | <script type="text/javascript"> |
---|
247 | /*<![CDATA[*/ |
---|
248 | |
---|
249 | if(window.top) |
---|
250 | HTMLArea = Xinha = window.top.Xinha; |
---|
251 | |
---|
252 | function hideMessage() |
---|
253 | { |
---|
254 | var topDoc = window.top.document; |
---|
255 | var messages = topDoc.getElementById('messages'); |
---|
256 | if(messages) |
---|
257 | messages.style.display = "none"; |
---|
258 | } |
---|
259 | |
---|
260 | init = function() |
---|
261 | { |
---|
262 | __dlg_translate('ImageManager'); |
---|
263 | hideMessage(); |
---|
264 | var topDoc = window.top.document; |
---|
265 | |
---|
266 | <?php |
---|
267 | //we need to refesh the drop directory list |
---|
268 | //save the current dir, delete all select options |
---|
269 | //add the new list, re-select the saved dir. |
---|
270 | if($refreshDir) |
---|
271 | { |
---|
272 | $dirs = $manager->getDirs(); |
---|
273 | ?> |
---|
274 | var selection = topDoc.getElementById('dirPath'); |
---|
275 | var currentDir = selection.options[selection.selectedIndex].text; |
---|
276 | |
---|
277 | while(selection.length > 0) |
---|
278 | { selection.remove(0); } |
---|
279 | |
---|
280 | selection.options[selection.length] = new Option("/","<?php echo rawurlencode('/'); ?>"); |
---|
281 | <?php foreach($dirs as $relative=>$fullpath) { ?> |
---|
282 | selection.options[selection.length] = new Option("<?php echo $relative; ?>","<?php echo rawurlencode($relative); ?>"); |
---|
283 | <?php } ?> |
---|
284 | |
---|
285 | for(var i = 0; i < selection.length; i++) |
---|
286 | { |
---|
287 | var thisDir = selection.options[i].text; |
---|
288 | if(thisDir == currentDir) |
---|
289 | { |
---|
290 | selection.selectedIndex = i; |
---|
291 | break; |
---|
292 | } |
---|
293 | } |
---|
294 | <?php } ?> |
---|
295 | update_selected(); |
---|
296 | } |
---|
297 | |
---|
298 | function editImage(image) |
---|
299 | { |
---|
300 | var url = "<?php print $IMConfig['backend_url']; ?>__function=editor&img="+image; |
---|
301 | Dialog(url, function(param) |
---|
302 | { |
---|
303 | if (!param) // user must have pressed Cancel |
---|
304 | return false; |
---|
305 | else |
---|
306 | { |
---|
307 | return true; |
---|
308 | } |
---|
309 | }, null); |
---|
310 | } |
---|
311 | |
---|
312 | /*]]>*/ |
---|
313 | </script> |
---|
314 | <script type="text/javascript" src="<?php print $IMConfig['base_url'];?>assets/images.js"></script> |
---|
315 | <script type="text/javascript" src="../../popups/popup.js"></script> |
---|
316 | <script type="text/javascript" src="assets/popup.js"></script> |
---|
317 | </head> |
---|
318 | |
---|
319 | <body> |
---|
320 | <?php if ($manager->isValidBase() == false) { drawErrorBase($manager); } |
---|
321 | elseif(count($list[0]) > 0 || count($list[1]) > 0) { ?> |
---|
322 | |
---|
323 | <?php drawDirs($list[0], $manager); ?> |
---|
324 | <?php drawFiles($list[1], $manager); ?> |
---|
325 | |
---|
326 | <?php } else { drawNoResults(); } ?> |
---|
327 | </body> |
---|
328 | </html> |
---|