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

Last change on this file since 46 was 46, checked in by yermol, 15 years ago

third time's a charm. Had left debug messages turned on. Now turned off.

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