PageRenderTime 85ms CodeModel.GetById 57ms RepoModel.GetById 1ms app.codeStats 0ms

/site_media/xinha/plugins/ImageManager/images.php

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