[270] | 1 | <?php |
---|
[43] | 2 | /** |
---|
| 3 | * Show a list of images in a long horizontal table. |
---|
| 4 | * @author $Author: Wei Zhuo $ |
---|
| 5 | * @version $Id: images.php 27 2004-04-01 08:31:57Z Wei Zhuo $ |
---|
| 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 | |
---|
[46] | 15 | // _ddtOn(); |
---|
[43] | 16 | |
---|
| 17 | //default path is / |
---|
| 18 | $relative = '/'; |
---|
| 19 | $manager = new ImageManager($IMConfig); |
---|
| 20 | |
---|
| 21 | //process any file uploads |
---|
| 22 | $manager->processUploads(); |
---|
| 23 | |
---|
| 24 | $manager->deleteFiles(); |
---|
| 25 | |
---|
| 26 | $refreshDir = false; |
---|
| 27 | //process any directory functions |
---|
| 28 | if($manager->deleteDirs() || $manager->processNewDir()) |
---|
| 29 | $refreshDir = true; |
---|
| 30 | |
---|
| 31 | //check for any sub-directory request |
---|
| 32 | //check that the requested sub-directory exists |
---|
| 33 | //and valid |
---|
| 34 | if(isset($_REQUEST['dir'])) |
---|
| 35 | { |
---|
| 36 | $path = rawurldecode($_REQUEST['dir']); |
---|
| 37 | if($manager->validRelativePath($path)) |
---|
| 38 | $relative = $path; |
---|
| 39 | } |
---|
| 40 | |
---|
| 41 | |
---|
| 42 | $manager = new ImageManager($IMConfig); |
---|
| 43 | |
---|
| 44 | |
---|
| 45 | //get the list of files and directories |
---|
| 46 | $list = $manager->getFiles($relative); |
---|
| 47 | |
---|
| 48 | |
---|
| 49 | /* ================= OUTPUT/DRAW FUNCTIONS ======================= */ |
---|
| 50 | |
---|
| 51 | /** |
---|
| 52 | * Draw the files in an table. |
---|
| 53 | */ |
---|
| 54 | function drawFiles($list, &$manager) |
---|
| 55 | { |
---|
| 56 | global $relative; |
---|
| 57 | global $IMConfig; |
---|
| 58 | |
---|
[256] | 59 | foreach($list as $entry => $file) |
---|
| 60 | { |
---|
[43] | 61 | ?> |
---|
[256] | 62 | <div class="thumb_holder" id="holder_<?php echo asc2hex($entry) ?>"> |
---|
[270] | 63 | <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']); ?>"> |
---|
[256] | 64 | <img src="<?php print $manager->getThumbnail($file['relative']); ?>" alt="<?php echo $entry; ?> - <?php echo Files::formatSize($file['stat']['size']); ?>"/> |
---|
| 65 | </a> |
---|
| 66 | <div class="edit"> |
---|
| 67 | <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> |
---|
[43] | 68 | |
---|
[256] | 69 | <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> |
---|
[43] | 70 | |
---|
[256] | 71 | <?php if($file['image']){ echo $file['image'][0].'x'.$file['image'][1]; } else echo $entry;?> |
---|
| 72 | </div> |
---|
| 73 | </div> |
---|
| 74 | <?php |
---|
[43] | 75 | }//foreach |
---|
| 76 | }//function drawFiles |
---|
| 77 | |
---|
| 78 | |
---|
| 79 | /** |
---|
| 80 | * Draw the directory. |
---|
| 81 | */ |
---|
| 82 | function drawDirs($list, &$manager) |
---|
| 83 | { |
---|
| 84 | global $relative; |
---|
| 85 | global $IMConfig; |
---|
| 86 | |
---|
| 87 | foreach($list as $path => $dir) |
---|
| 88 | { ?> |
---|
[256] | 89 | <div class="dir_holder"> |
---|
| 90 | <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> |
---|
| 91 | |
---|
| 92 | <div class="edit"> |
---|
| 93 | <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> |
---|
| 94 | <?php echo $dir['entry']; ?> |
---|
| 95 | </div> |
---|
| 96 | </div> |
---|
[111] | 97 | <?php |
---|
[43] | 98 | } //foreach |
---|
| 99 | }//function drawDirs |
---|
| 100 | |
---|
| 101 | |
---|
| 102 | /** |
---|
| 103 | * No directories and no files. |
---|
| 104 | */ |
---|
| 105 | function drawNoResults() |
---|
| 106 | { |
---|
| 107 | ?> |
---|
[252] | 108 | <div class="noResult">No Images Found</div> |
---|
[270] | 109 | <?php |
---|
[43] | 110 | } |
---|
| 111 | |
---|
| 112 | /** |
---|
| 113 | * No directories and no files. |
---|
| 114 | */ |
---|
| 115 | function drawErrorBase(&$manager) |
---|
| 116 | { |
---|
| 117 | ?> |
---|
[252] | 118 | <div class="error"><span>Invalid base directory:</span> <?php echo $manager->config['images_dir']; ?></div> |
---|
[270] | 119 | <?php |
---|
[43] | 120 | } |
---|
| 121 | |
---|
[256] | 122 | /** |
---|
| 123 | * Utility to convert ascii string to hex |
---|
| 124 | */ |
---|
| 125 | function asc2hex ($temp) |
---|
| 126 | { |
---|
| 127 | $len = strlen($temp); |
---|
| 128 | for ($i=0; $i<$len; $i++) $data.=sprintf("%02x",ord(substr($temp,$i,1))); |
---|
| 129 | return $data; |
---|
| 130 | } |
---|
| 131 | |
---|
[43] | 132 | ?> |
---|
| 133 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
---|
| 134 | |
---|
| 135 | <html> |
---|
| 136 | <head> |
---|
| 137 | <title>Image List</title> |
---|
| 138 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> |
---|
[111] | 139 | <link href="<?php print $IMConfig['base_url'];?>assets/imagelist.css" rel="stylesheet" type="text/css" /> |
---|
[43] | 140 | <script type="text/javascript"> |
---|
[111] | 141 | _backend_url = "<?php print $IMConfig['backend_url']; ?>"; |
---|
[43] | 142 | </script> |
---|
| 143 | |
---|
[111] | 144 | <script type="text/javascript" src="<?php print $IMConfig['base_url'];?>assets/dialog.js"></script> |
---|
[43] | 145 | <script type="text/javascript"> |
---|
| 146 | /*<![CDATA[*/ |
---|
| 147 | |
---|
| 148 | if(window.top) |
---|
[60] | 149 | HTMLArea = window.top.HTMLArea; |
---|
[43] | 150 | |
---|
| 151 | function hideMessage() |
---|
| 152 | { |
---|
| 153 | var topDoc = window.top.document; |
---|
| 154 | var messages = topDoc.getElementById('messages'); |
---|
| 155 | if(messages) |
---|
| 156 | messages.style.display = "none"; |
---|
| 157 | } |
---|
| 158 | |
---|
| 159 | init = function() |
---|
| 160 | { |
---|
[252] | 161 | __dlg_translate('ImageManager'); |
---|
[43] | 162 | hideMessage(); |
---|
| 163 | var topDoc = window.top.document; |
---|
| 164 | |
---|
[111] | 165 | <?php |
---|
[43] | 166 | //we need to refesh the drop directory list |
---|
| 167 | //save the current dir, delete all select options |
---|
| 168 | //add the new list, re-select the saved dir. |
---|
| 169 | if($refreshDir) |
---|
| 170 | { |
---|
| 171 | $dirs = $manager->getDirs(); |
---|
| 172 | ?> |
---|
| 173 | var selection = topDoc.getElementById('dirPath'); |
---|
| 174 | var currentDir = selection.options[selection.selectedIndex].text; |
---|
| 175 | |
---|
| 176 | while(selection.length > 0) |
---|
| 177 | { selection.remove(0); } |
---|
| 178 | |
---|
[111] | 179 | selection.options[selection.length] = new Option("/","<?php echo rawurlencode('/'); ?>"); |
---|
| 180 | <?php foreach($dirs as $relative=>$fullpath) { ?> |
---|
| 181 | selection.options[selection.length] = new Option("<?php echo $relative; ?>","<?php echo rawurlencode($relative); ?>"); |
---|
| 182 | <?php } ?> |
---|
[43] | 183 | |
---|
| 184 | for(var i = 0; i < selection.length; i++) |
---|
| 185 | { |
---|
| 186 | var thisDir = selection.options[i].text; |
---|
| 187 | if(thisDir == currentDir) |
---|
| 188 | { |
---|
| 189 | selection.selectedIndex = i; |
---|
| 190 | break; |
---|
| 191 | } |
---|
| 192 | } |
---|
[111] | 193 | <?php } ?> |
---|
[256] | 194 | update_selected(); |
---|
[43] | 195 | } |
---|
| 196 | |
---|
| 197 | function editImage(image) |
---|
| 198 | { |
---|
[111] | 199 | var url = "<?php print $IMConfig['backend_url']; ?>__function=editor&img="+image; |
---|
[43] | 200 | Dialog(url, function(param) |
---|
| 201 | { |
---|
| 202 | if (!param) // user must have pressed Cancel |
---|
| 203 | return false; |
---|
| 204 | else |
---|
| 205 | { |
---|
| 206 | return true; |
---|
| 207 | } |
---|
| 208 | }, null); |
---|
| 209 | } |
---|
| 210 | |
---|
| 211 | /*]]>*/ |
---|
| 212 | </script> |
---|
[111] | 213 | <script type="text/javascript" src="<?php print $IMConfig['base_url'];?>assets/images.js"></script> |
---|
[252] | 214 | <script type="text/javascript" src="assets/popup.js"></script> |
---|
[43] | 215 | </head> |
---|
| 216 | |
---|
| 217 | <body> |
---|
[111] | 218 | <?php if ($manager->isValidBase() == false) { drawErrorBase($manager); } |
---|
[43] | 219 | elseif(count($list[0]) > 0 || count($list[1]) > 0) { ?> |
---|
[256] | 220 | |
---|
[111] | 221 | <?php drawDirs($list[0], $manager); ?> |
---|
| 222 | <?php drawFiles($list[1], $manager); ?> |
---|
[256] | 223 | |
---|
[111] | 224 | <?php } else { drawNoResults(); } ?> |
---|
[43] | 225 | </body> |
---|
[256] | 226 | </html> |
---|