ImageManager
[ class tree: ImageManager ] [ index: ImageManager ] [ all elements ]

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: 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('Classes/ImageManager.php');
  11.  
  12. //default path is /
  13. $relative '/';
  14. $manager new ImageManager($IMConfig);
  15.  
  16. //process any file uploads
  17. $upload_result=$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.     global $IMConfig;
  53.  
  54.     foreach($list as $entry => $file
  55.     ?>
  56.         <td><table width="100" cellpadding="0" cellspacing="0"><tr><td class="block">
  57.         <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>
  58.         <!--<iframe src="<?php echo $manager->getThumbnail($file['relative'])?>"></iframe>-->
  59.         </td></tr><tr><td class="edit">
  60.         <?php if($IMConfig['allow_delete'== true?>
  61.             <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>
  62.         <?php ?>
  63.         <!--EDIT IMAGE ; TEMPORALY DELETED-->
  64.             <!--<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>-->
  65.         <?php if($file['image'])echo $file['image'][0].'x'.$file['image'][1]else echo $entry;?>
  66.         </td></tr></table></td> 
  67.       <?php 
  68.     }//foreach
  69. }//function drawFiles
  70.  
  71.  
  72. /**
  73.  * Draw the directory.
  74.  */
  75. function drawDirs($list&$manager
  76. {
  77.     global $relative;
  78.  
  79.     foreach($list as $path => $dir
  80.     ?>
  81.         <td><table width="100" cellpadding="0" cellspacing="0"><tr><td class="block">
  82.         <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>
  83.         </td></tr><tr>
  84.         <td class="edit">
  85.             <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>
  86.             <?php echo $dir['entry']?>
  87.         </td>
  88.         </tr></table></td>
  89.       <?php 
  90.     //foreach
  91. }//function drawDirs
  92.  
  93.  
  94. /**
  95.  * No directories and no files.
  96.  */
  97. function drawNoResults(
  98. {
  99. ?>
  100. <table width="100%">
  101.   <tr>
  102.     <td class="noResult">No Images Found</td>
  103.   </tr>
  104. </table>
  105. <?php    
  106. }
  107.  
  108. /**
  109.  * No directories and no files.
  110.  */
  111. function drawErrorBase(&$manager
  112. {
  113. ?>
  114. <table width="100%">
  115.   <tr>
  116.     <td class="error"><?php echo get_lang('InvalidDirectoryPleaseCreateAnImagesFolder')?>
  117.     <?php
  118.     if (api_is_platform_admin())
  119.     {
  120.         echo $manager->config['base_dir'];
  121.     }?></td>
  122.   </tr>
  123. </table>
  124. <?php    
  125. }
  126.  
  127. ?>
  128. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  129.  
  130. <html>
  131. <head>
  132.     <title>Image List</title>
  133.   <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  134.     <link href="assets/imagelist.css" rel="stylesheet" type="text/css" />
  135. <script type="text/javascript" src="assets/dialog.js"></script>
  136. <script type="text/javascript">
  137. /*<![CDATA[*/
  138.  
  139.     if(window.top)
  140.         I18N = window.top.I18N;
  141.  
  142.     function hideMessage()
  143.     {
  144.         var topDoc = window.top.document;
  145.         var messages = topDoc.getElementById('messages');
  146.         if(messages)
  147.             messages.style.display = "none";
  148.     }
  149.  
  150.     init = function()
  151.     {
  152.         hideMessage();
  153.         var topDoc = window.top.document;
  154.  
  155. <?php 
  156.     //we need to refesh the drop directory list
  157.     //save the current dir, delete all select options
  158.     //add the new list, re-select the saved dir.
  159.     if($refreshDir
  160.     
  161.         $dirs $manager->getDirs();
  162. ?>
  163.         var selection = topDoc.getElementById('dirPath');
  164.         var currentDir = selection.options[selection.selectedIndex].text;
  165.  
  166.         while(selection.length > 0)
  167.         {    selection.remove(0); }
  168.         
  169.         selection.options[selection.length] = new Option("/","<?php echo rawurlencode('/')?>");    
  170.         <?php foreach($dirs as $relative=>$fullpath?>
  171.         selection.options[selection.length] = new Option("<?php echo $relative?>","<?php echo rawurlencode($relative)?>");        
  172.         <?php ?>
  173.         
  174.         for(var i = 0; i < selection.length; i++)
  175.         {
  176.             var thisDir = selection.options[i].text;
  177.             if(thisDir == currentDir)
  178.             {
  179.                 selection.selectedIndex = i;
  180.                 break;
  181.             }
  182.         }        
  183. <?php ?>
  184.     }    
  185.  
  186.     function editImage(image) 
  187.     {
  188.         var url = "editor.php?img="+image;
  189.         Dialog(url, function(param) 
  190.         {
  191.             if (!param) // user must have pressed Cancel
  192.                 return false;
  193.             else
  194.             {
  195.                 return true;
  196.             }
  197.         }, null);        
  198.     }
  199.     
  200.     function closeWindowAfterUpload(path, name, width, height){
  201.         selectImage(path, name, width, height);    
  202.         window.parent.onOK();
  203.     }
  204.  
  205. /*]]>*/
  206. </script>
  207. <script type="text/javascript" src="assets/images.js"></script>
  208. </head>
  209.  
  210. <body>
  211. <?php if ($manager->isValidBase(== falsedrawErrorBase($manager)
  212.     elseif(count($list[0]|| count($list[1]0?>
  213. <table>
  214.     <tr>
  215.     <?php drawDirs($list[0]$manager)?>
  216.     <?php drawFiles($list[1]$manager)?>
  217.     <?php closeWindowAfterUpload($list[1])?>
  218.     </tr>
  219. </table>
  220. <?php
  221. else {
  222.     drawNoResults();
  223. }
  224.  
  225. function closeWindowAfterUpload($list){
  226.     if(!api_is_allowed_to_edit(&& isset($_FILES['upload'])){
  227.         foreach($list as $entry => $file{
  228.             echo "<script>closeWindowAfterUpload('".$file['relative']."','".$entry."','".$file['image'][0]."','".$file['image'][1]."');</script>";
  229.             return;
  230.         }
  231.     }
  232. }
  233.  
  234. if(api_is_allowed_to_edit(&& isset($_FILES['upload']&& !is_int($upload_result)){
  235.     $width=$list[1][$upload_result]['image'][0];
  236.     $height=$list[1][$upload_result]['image'][1];
  237.     echo "<script text='text/javascript'>selectImage('$relative$upload_result','$upload_result', '$width', '$height');</script>";
  238. }
  239.  
  240. ?>
  241. </body>
  242. </html>

Documentation generated on Thu, 12 Jun 2008 13:47:09 -0500 by phpDocumentor 1.4.1