images.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. <?php
  2. /**
  3. * Show a list of images in a long horizontal table.
  4. * @author Wei Zhuo
  5. * @version $Id: images.php,v 1.2 2006/12/16 21:38:13 thierrybo Exp $
  6. * @package ImageManager
  7. */
  8. require_once('config.inc.php');
  9. require_once('Classes/ImageManager.php');
  10. //default path is /
  11. $relative = '/images/gallery/';
  12. $manager = new ImageManager($IMConfig);
  13. //process any file uploads
  14. $manager->processUploads();
  15. $manager->deleteFiles();
  16. $refreshDir = false;
  17. //process any directory functions
  18. if($manager->deleteDirs() || $manager->processNewDir())
  19. $refreshDir = true;
  20. //check for any sub-directory request
  21. //check that the requested sub-directory exists
  22. //and valid
  23. if(isset($_REQUEST['dir']))
  24. {
  25. $path = rawurldecode($_REQUEST['dir']);
  26. if($manager->validRelativePath($path))
  27. $relative = $path;
  28. }
  29. $manager = new ImageManager($IMConfig);
  30. //get the list of files and directories
  31. $list = $manager->getFiles($relative);
  32. /* ================= OUTPUT/DRAW FUNCTIONS ======================= */
  33. /**
  34. * Draw the files in an table.
  35. */
  36. function drawFiles($list, &$manager)
  37. {
  38. global $relative;
  39. global $IMConfig;
  40. foreach($list as $entry => $file)
  41. { ?>
  42. <td><table width="100" cellpadding="0" cellspacing="0"><tr><td class="block">
  43. <a href="javascript: void(0);" onclick="selectImage('<?php echo $file['relative'];?>', '<?php echo $entry; ?>', <?php echo $file['image'][0];?>, <?php echo $file['image'][1]; ?>);"title="<?php echo $entry; ?> - <?php echo Files::formatSize($file['stat']['size']); ?>"><img src="<?php echo $manager->getThumbnail($file['relative']); ?>" alt="<?php echo $entry; ?> - <?php echo Files::formatSize($file['stat']['size']); ?>"/></a>
  44. </td></tr><tr><td class="edit" style="padding-top: 5px;">
  45. <?php if($IMConfig['allow_delete'] == true) { ?>
  46. <a href="images.php?dir=<?php echo $relative; ?>&amp;delf=<?php echo rawurlencode($file['relative']);?>" title="Trash" onclick="return confirmDeleteFile('<?php echo $entry; ?>');"><img src="img/edit_trash.gif" height="15" width="15" alt="Trash"/></a>
  47. <?php } ?>
  48. <?php if($IMConfig['allow_edit'] == true) { ?>
  49. <a href="javascript: void(0);" title="Edit" onclick="editImage('<?php echo rawurlencode($file['relative']);?>');"><img src="img/edit_pencil.gif" height="15" width="15" alt="Edit"/></a>
  50. <?php } ?>
  51. <?php if($file['image']){ echo $file['image'][0].'x'.$file['image'][1]; } else echo $entry;?>
  52. </td></tr></table></td>
  53. <?php
  54. }//foreach
  55. }//function drawFiles
  56. /**
  57. * Draw the directory.
  58. */
  59. function drawDirs($list, &$manager)
  60. {
  61. global $relative;
  62. foreach($list as $path => $dir)
  63. { ?>
  64. <td><table width="100" cellpadding="0" cellspacing="0"><tr><td class="block">
  65. <a href="images.php?dir=<?php echo rawurlencode($path); ?>" onclick="updateDir('<?php echo $path; ?>')" title="<?php echo $dir['entry']; ?>"><img src="img/folder.gif" height="80" width="80" alt="<?php echo $dir['entry']; ?>" /></a>
  66. </td></tr><tr>
  67. <td class="edit" style="padding-top: 5px;">
  68. <a href="images.php?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="img/edit_trash.gif" style="width: 15px; height: 15px;" alt="Trash"/></a>
  69. <?php echo $dir['entry']; ?>
  70. </td>
  71. </tr></table></td>
  72. <?php
  73. } //foreach
  74. }//function drawDirs
  75. /**
  76. * No directories and no files.
  77. */
  78. function drawNoResults()
  79. {
  80. ?>
  81. <table width="100%">
  82. <tr>
  83. <td class="noResult">No Images Found</td>
  84. </tr>
  85. </table>
  86. <?php
  87. }
  88. /**
  89. * No directories and no files.
  90. */
  91. function drawErrorBase(&$manager)
  92. {
  93. ?>
  94. <table width="100%">
  95. <tr>
  96. <td class="error">Invalid base directory: <?php echo $manager->config['base_dir']; ?></td>
  97. </tr>
  98. </table>
  99. <?php
  100. }
  101. ?>
  102. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  103. <html>
  104. <head>
  105. <title>Image List</title>
  106. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  107. <link href="assets/imagelist.css" rel="stylesheet" type="text/css" />
  108. <script type="text/javascript" src="assets/dialog.js"></script>
  109. <script type="text/javascript">
  110. /*<![CDATA[*/
  111. //if(window.top)
  112. // I18N = window.top.I18N;
  113. I18N = window.parent.I18N;
  114. function hideMessage()
  115. {
  116. //var topDoc = window.top.document;
  117. var topDoc = window.parent.document;
  118. var messages = topDoc.getElementById('messages');
  119. if(messages)
  120. messages.style.display = "none";
  121. }
  122. init = function()
  123. {
  124. hideMessage();
  125. //var topDoc = window.top.document;
  126. var topDoc = window.parent.document;
  127. <?php
  128. //we need to refesh the drop directory list
  129. //save the current dir, delete all select options
  130. //add the new list, re-select the saved dir.
  131. if($refreshDir)
  132. {
  133. $dirs = $manager->getDirs();
  134. ?>
  135. var selection = topDoc.getElementById('dirPath');
  136. var currentDir = selection.options[selection.selectedIndex].text;
  137. while(selection.length > 0)
  138. { selection.remove(0); }
  139. selection.options[selection.length] = new Option("/","<?php echo rawurlencode('/'); ?>");
  140. <?php foreach($dirs as $relative=>$fullpath) { ?>
  141. selection.options[selection.length] = new Option("<?php echo $relative; ?>","<?php echo rawurlencode($relative); ?>");
  142. <?php } ?>
  143. for(var i = 0; i < selection.length; i++)
  144. {
  145. var thisDir = selection.options[i].text;
  146. if(thisDir == currentDir)
  147. {
  148. selection.selectedIndex = i;
  149. break;
  150. }
  151. }
  152. <?php } ?>
  153. }
  154. function editImage(image)
  155. {
  156. var url = "<?php echo api_get_path(REL_CODE_PATH).'inc/lib/fckeditor/editor/plugins/ImageManager/'; ?>editor.php?img="+image;
  157. if ( window.parent.opener )
  158. {
  159. Dialog(url, function(param)
  160. {
  161. if (!param) // user must have pressed Cancel
  162. return false;
  163. else
  164. {
  165. return true;
  166. }
  167. }, null);
  168. }
  169. else if ( window.parent.oEditor )
  170. {
  171. window.parent.oEditor.OpenDialog( url, null, null, 'FCKDialog_ImageEditor', 'Edit image', 713, 596 );
  172. }
  173. }
  174. /*]]>*/
  175. </script>
  176. <script type="text/javascript" src="assets/images.js"></script>
  177. </head>
  178. <body>
  179. <?php if ($manager->isValidBase() == false) { drawErrorBase($manager); }
  180. elseif(count($list[0]) > 0 || count($list[1]) > 0) { ?>
  181. <table>
  182. <tr>
  183. <?php drawDirs($list[0], $manager); ?>
  184. <?php drawFiles($list[1], $manager); ?>
  185. </tr>
  186. </table>
  187. <?php } else { drawNoResults(); } ?>
  188. </body>
  189. </html>