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

Last change on this file since 914 was 877, checked in by gogo, 12 years ago

ImageManager? wasn't resizing and also was generating errors because the iframe didn't load popups/popup.js to
define Xinha.*

ticket:1058

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