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

Last change on this file since 256 was 256, checked in by gogo, 14 years ago

Various updates to ImageManager?, see #343

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