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

Last change on this file since 111 was 111, checked in by niko, 15 years ago

#225
several ImageManager? fixes, see #225 for details

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                <td>
63
64                <?php _ddt( __FILE__, __LINE__, "drawFiles(): relative is '" . $file['relative'] . "' thumbnail '" . $manager->getThumbnail($file['relative']) . "'" ); ?>
65
66                <table width="100" cellpadding="0" cellspacing="0"><tr><td class="block">
67        <table width="100" cellpadding="0" cellspacing="0"><tr><td class="block" style="cursor: pointer;" onclick="selectImage('<? echo $file['relative'];?>', '<? echo $entry; ?>', <? echo $file['image'][0];?>, <? echo $file['image'][1]; ?>);" title="<?php echo $entry; ?> - <?php echo Files::formatSize($file['stat']['size']); ?>">
68
69                <img src="<?php print $manager->getThumbnail($file['relative']); ?>" alt="<?php echo $entry; ?> - <?php echo Files::formatSize($file['stat']['size']); ?>"/>
70                </td></tr><tr><td class="edit">
71                        <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><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>
72                <?php if($file['image']){ echo $file['image'][0].'x'.$file['image'][1]; } else echo $entry;?>
73                </td></tr></table></td>
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                <td><table width="100" cellpadding="0" cellspacing="0"><tr><td class="block">
90                <a href="images.php?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                </td></tr><tr>
92                <td class="edit">
93                        <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="<?php print $IMConfig['base_url'];?>img/edit_trash.gif" height="15" width="15" alt="Trash"/></a>
94                        <?php echo $dir['entry']; ?>
95                </td>
96                </tr></table></td>
97          <?php
98        } //foreach
99}//function drawDirs
100
101
102/**
103 * No directories and no files.
104 */
105function drawNoResults()
106{
107?>
108<table width="100%">
109  <tr>
110    <td class="noResult">No Images Found</td>
111  </tr>
112</table>
113<?     
114}
115
116/**
117 * No directories and no files.
118 */
119function drawErrorBase(&$manager)
120{
121?>
122<table width="100%">
123  <tr>
124    <td class="error">Invalid base directory: <?php echo $manager->config['images_dir']; ?></td>
125  </tr>
126</table>
127<?     
128}
129
130?>
131<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
132
133<html>
134<head>
135        <title>Image List</title>
136  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
137        <link href="<?php print $IMConfig['base_url'];?>assets/imagelist.css" rel="stylesheet" type="text/css" />
138<script type="text/javascript">
139_backend_url = "<?php print $IMConfig['backend_url']; ?>";
140</script>
141
142<script type="text/javascript" src="<?php print $IMConfig['base_url'];?>assets/dialog.js"></script>
143<script type="text/javascript">
144/*<![CDATA[*/
145
146        if(window.top)
147                HTMLArea = window.top.HTMLArea;
148
149        function hideMessage()
150        {
151                var topDoc = window.top.document;
152                var messages = topDoc.getElementById('messages');
153                if(messages)
154                        messages.style.display = "none";
155        }
156
157        init = function()
158        {
159                hideMessage();
160                var topDoc = window.top.document;
161
162<?php
163        //we need to refesh the drop directory list
164        //save the current dir, delete all select options
165        //add the new list, re-select the saved dir.
166        if($refreshDir)
167        {
168                $dirs = $manager->getDirs();
169?>
170                var selection = topDoc.getElementById('dirPath');
171                var currentDir = selection.options[selection.selectedIndex].text;
172
173                while(selection.length > 0)
174                {       selection.remove(0); }
175               
176                selection.options[selection.length] = new Option("/","<?php echo rawurlencode('/'); ?>");       
177                <?php foreach($dirs as $relative=>$fullpath) { ?>
178                selection.options[selection.length] = new Option("<?php echo $relative; ?>","<?php echo rawurlencode($relative); ?>");         
179                <?php } ?>
180               
181                for(var i = 0; i < selection.length; i++)
182                {
183                        var thisDir = selection.options[i].text;
184                        if(thisDir == currentDir)
185                        {
186                                selection.selectedIndex = i;
187                                break;
188                        }
189                }               
190<?php } ?>
191        }       
192
193        function editImage(image)
194        {
195                var url = "<?php print $IMConfig['backend_url']; ?>__function=editor&img="+image;
196                Dialog(url, function(param)
197                {
198                        if (!param) // user must have pressed Cancel
199                                return false;
200                        else
201                        {
202                                return true;
203                        }
204                }, null);               
205        }
206
207/*]]>*/
208</script>
209<script type="text/javascript" src="<?php print $IMConfig['base_url'];?>assets/images.js"></script>
210</head>
211
212<body>
213<?php if ($manager->isValidBase() == false) { drawErrorBase($manager); }
214        elseif(count($list[0]) > 0 || count($list[1]) > 0) { ?>
215<table>
216        <tr>
217        <?php drawDirs($list[0], $manager); ?>
218        <?php drawFiles($list[1], $manager); ?>
219        </tr>
220</table>
221<?php } else { drawNoResults(); } ?>
222</body>
223</html>
Note: See TracBrowser for help on using the repository browser.