source: trunk/plugins/ImageManager/images.php @ 1319

Last change on this file since 1319 was 1231, checked in by gogo, 10 years ago

Ticket #1205

Add allow_delete and allow_edit to ImageManager?
Add allow_delete to ExtendedFileManager?

  • Property svn:keywords set to LastChangedDate LastChangedRevision LastChangedBy HeadURL Id
File size: 9.6 KB
RevLine 
[270]1<?php
[43]2/**
3 * Show a list of images in a long horizontal table.
[999]4 * @author $Author:ray $
5 * @version $Id:images.php 987 2008-04-12 12:39:04Z ray $
[43]6 * @package ImageManager
7 */
8
9require_once('config.inc.php');
10require_once('ddt.php');
11require_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
[1231]24if($IMConfig['allow_delete'])
25{
26  $manager->deleteFiles();
27}
[43]28
29$refreshDir = false;
30//process any directory functions
[1231]31if(($IMConfig['allow_delete'] && $manager->deleteDirs()) || $manager->processNewDir())
[43]32        $refreshDir = true;
33
34//check for any sub-directory request
35//check that the requested sub-directory exists
36//and valid
37if(isset($_REQUEST['dir']))
38{
39        $path = rawurldecode($_REQUEST['dir']);
40        if($manager->validRelativePath($path))
41                $relative = $path;
42}
43
44
45$manager = new ImageManager($IMConfig);
46
47
48//get the list of files and directories
49$list = $manager->getFiles($relative);
50
51
52/* ================= OUTPUT/DRAW FUNCTIONS ======================= */
53
54/**
55 * Draw the files in an table.
56 */
57function drawFiles($list, &$manager)
58{
59        global $relative;
60        global $IMConfig;
61
[447]62    switch($IMConfig['ViewMode'])
63    {
64      case 'details':
65      {
66        ?>
67        <script language="Javascript">
68          <!--
69            function showPreview(f_url)
70            {
71             
72              window.parent.document.getElementById('f_preview').src =
73                window.parent._backend_url + '__function=thumbs&img=' + f_url;
74            }
75          //-->
76        </script>
77        <table class="listview">
78        <thead>
79        <tr><th>Name</th><th>Filesize</th><th>Dimensions</th></tr></thead>
80        <tbody>
81          <?php
82          foreach($list as $entry => $file)
83          {
84            ?>
85            <tr>
86              <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>
87              <td><?php echo Files::formatSize($file['stat']['size']); ?></td>
[987]88              <td><?php if($file['image']){ echo $file['image'][0].'x'.$file['image'][1]; } ?></td>
[447]89              <td class="actions">
[1231]90                <?php
91                  if($IMConfig['allow_delete'])
92                  {
93                    ?>
[447]94                <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>
[1231]95                    <?php
96                  }
97                ?>
98                <?php
99                  if($IMConfig['allow_edit'])
100                  {
101                    ?>
[447]102                <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>
[1231]103                    <?php
104                  }
105                ?>
[447]106              </td>
107            </tr>
108            <?php       
109          }
110          ?>
111        </tbody>
112        </table>
113        <?php
114      }     
115      break;
116     
117      case 'thumbs':
118      default      :
119      {
[256]120        foreach($list as $entry => $file)
121        {
[43]122                ?>
[256]123    <div class="thumb_holder" id="holder_<?php echo asc2hex($entry) ?>">
[270]124      <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]125        <img src="<?php print $manager->getThumbnail($file['relative']); ?>" alt="<?php echo $entry; ?> - <?php echo Files::formatSize($file['stat']['size']); ?>"/>
126      </a>
127      <div class="edit">
[1231]128     
129      <?php
130        if($IMConfig['allow_delete'])
131        {
132          ?>
[256]133        <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>
[1231]134          <?php
135        }
136      ?>
137     
138      <?php
139        if($IMConfig['allow_edit'])
140        {
141          ?>
[256]142        <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>
[1231]143          <?php
144        }
145      ?>
[256]146        <?php if($file['image']){ echo $file['image'][0].'x'.$file['image'][1]; } else echo $entry;?>
147      </div>
148    </div>
149          <?php
[447]150        }
151      }
152    }   
[43]153}//function drawFiles
154
155
156/**
157 * Draw the directory.
158 */
159function drawDirs($list, &$manager)
160{
161        global $relative;
162   global $IMConfig;
163
[447]164  switch($IMConfig['ViewMode'])
165  {
166    case 'details':
167    {
168       
169    }
170    break;
171   
172    case 'thumbs':
173    default      :
174    {
[43]175        foreach($list as $path => $dir)
176        { ?>
[256]177    <div class="dir_holder">
178      <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>
179
180      <div class="edit">
[1231]181        <?php
182          if($IMConfig['allow_delete'])
183          {
184            ?>
[256]185        <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>
[1231]186            <?php
187          }
188        ?>
189             
[256]190        <?php echo $dir['entry']; ?>
191      </div>
192    </div>
[111]193          <?php
[43]194        } //foreach
[447]195    }
196  }
197 
198       
[43]199}//function drawDirs
200
201
202/**
203 * No directories and no files.
204 */
205function drawNoResults()
206{
207?>
[252]208<div class="noResult">No Images Found</div>
[270]209<?php
[43]210}
211
212/**
213 * No directories and no files.
214 */
215function drawErrorBase(&$manager)
216{
217?>
[252]218<div class="error"><span>Invalid base directory:</span> <?php echo $manager->config['images_dir']; ?></div>
[270]219<?php
[43]220}
221
[256]222/**
223 * Utility to convert ascii string to hex
224 */
225function asc2hex ($temp)
226{
227  $len = strlen($temp);
[293]228  $data = "";
[256]229  for ($i=0; $i<$len; $i++) $data.=sprintf("%02x",ord(substr($temp,$i,1)));
230  return $data;
231}
232
[43]233?>
234<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
235
236<html>
237<head>
238        <title>Image List</title>
239  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
[111]240        <link href="<?php print $IMConfig['base_url'];?>assets/imagelist.css" rel="stylesheet" type="text/css" />
[43]241<script type="text/javascript">
[111]242_backend_url = "<?php print $IMConfig['backend_url']; ?>";
[43]243</script>
244
[111]245<script type="text/javascript" src="<?php print $IMConfig['base_url'];?>assets/dialog.js"></script>
[43]246<script type="text/javascript">
247/*<![CDATA[*/
248
249        if(window.top)
[877]250    HTMLArea = Xinha    = window.top.Xinha;
[43]251
252        function hideMessage()
253        {
254                var topDoc = window.top.document;
255                var messages = topDoc.getElementById('messages');
256                if(messages)
257                        messages.style.display = "none";
258        }
259
260        init = function()
261        {
[252]262          __dlg_translate('ImageManager');
[43]263                hideMessage();
264                var topDoc = window.top.document;
265
[111]266<?php
[43]267        //we need to refesh the drop directory list
268        //save the current dir, delete all select options
269        //add the new list, re-select the saved dir.
270        if($refreshDir)
271        {
272                $dirs = $manager->getDirs();
273?>
274                var selection = topDoc.getElementById('dirPath');
275                var currentDir = selection.options[selection.selectedIndex].text;
276
277                while(selection.length > 0)
278                {       selection.remove(0); }
279               
[111]280                selection.options[selection.length] = new Option("/","<?php echo rawurlencode('/'); ?>");       
281                <?php foreach($dirs as $relative=>$fullpath) { ?>
282                selection.options[selection.length] = new Option("<?php echo $relative; ?>","<?php echo rawurlencode($relative); ?>");         
283                <?php } ?>
[43]284               
285                for(var i = 0; i < selection.length; i++)
286                {
287                        var thisDir = selection.options[i].text;
288                        if(thisDir == currentDir)
289                        {
290                                selection.selectedIndex = i;
291                                break;
292                        }
293                }               
[111]294<?php } ?>
[256]295    update_selected();
[43]296        }       
297
298        function editImage(image)
299        {
[111]300                var url = "<?php print $IMConfig['backend_url']; ?>__function=editor&img="+image;
[43]301                Dialog(url, function(param)
302                {
303                        if (!param) // user must have pressed Cancel
304                                return false;
305                        else
306                        {
307                                return true;
308                        }
309                }, null);               
310        }
311
312/*]]>*/
313</script>
[111]314<script type="text/javascript" src="<?php print $IMConfig['base_url'];?>assets/images.js"></script>
[877]315<script type="text/javascript" src="../../popups/popup.js"></script>
[252]316<script type="text/javascript" src="assets/popup.js"></script>
[43]317</head>
318
319<body>
[111]320<?php if ($manager->isValidBase() == false) { drawErrorBase($manager); }
[43]321        elseif(count($list[0]) > 0 || count($list[1]) > 0) { ?>
[256]322
[111]323        <?php drawDirs($list[0], $manager); ?>
324        <?php drawFiles($list[1], $manager); ?>
[256]325
[111]326<?php } else { drawNoResults(); } ?>
[43]327</body>
[256]328</html>
Note: See TracBrowser for help on using the repository browser.