Source for file images.php

Documentation is available at images.php

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

Documentation generated on Mon, 05 May 2008 16:20:25 +0400 by phpDocumentor 1.4.0