source: trunk/plugins/ExtendedFileManager/images.php @ 579

Last change on this file since 579 was 579, checked in by ray, 13 years ago

ExtendedFileManager? updates:

*to complete cofigurability through js directories can now be set for images and files individually (optional & backwards compatible)

  • relocated button from the end of toolbar next to createlink
  • insert image/link with double click
  • preview img didn't have src when no image selected, which showed a "image not found icon" in IE
  • slight modifications and updates in Readme.txt (kicked out afru's website. The domain isn't even registered anymore)
File size: 14.1 KB
Line 
1<?php
2/**
3 * ExtendedFileManager images.php file. Shows folders and files.
4 * Authors: Wei Zhuo, Afru, Krzysztof Kotowicz
5 * Version: Updated on 08-01-2005 by Afru
6 * Version: Updated on 04-07-2006 by Krzysztof Kotowicz
7 * Package: ExtendedFileManager (EFM 1.1.2)
8 * http://www.afrusoft.com/htmlarea
9 */
10
11        if(isset($_REQUEST['mode'])) $insertMode=$_REQUEST['mode'];
12        if(!isset($insertMode)) $insertMode="image";
13
14require_once('config.inc.php');
15require_once('Classes/ExtendedFileManager.php');
16
17//default path is /
18$relative = '/';
19$manager = new ExtendedFileManager($IMConfig, $insertMode);
20
21//process any file uploads
22$uploadStatus=$manager->processUploads();
23
24//process any file renames
25$renameStatus=$manager->processRenames();
26
27if ($manager->deleteFiles())
28    $refreshFile = true;
29
30$refreshDir = false;
31//process any directory functions
32if($manager->deleteDirs() || $manager->processNewDir())
33        $refreshDir = true;
34
35
36$diskInfo=$manager->getDiskInfo();
37
38//check for any sub-directory request
39//check that the requested sub-directory exists
40//and valid
41if(isset($_REQUEST['dir']))
42{
43        $path = rawurldecode($_REQUEST['dir']);
44        if($manager->validRelativePath($path))
45                $relative = $path;
46}
47
48
49$afruViewType="";
50if(isset($_REQUEST['viewtype']))
51{
52        $afruViewType=$_REQUEST['viewtype'];
53}
54if($afruViewType!="thumbview" && $afruViewType!="listview")
55
56$afruViewType=$IMConfig['view_type'];
57
58//get the list of files and directories
59$list = $manager->getFiles($relative);
60
61
62/* ================= OUTPUT/DRAW FUNCTIONS ======================= */
63
64
65/**
66 * Draw folders and files. Changed by Afru
67 */
68function drawDirs_Files($list, &$manager)
69{
70        global $relative, $afruViewType, $IMConfig, $insertMode;
71
72    switch ($afruViewType) {
73        case 'listview':
74                $maxNameLength = 30;
75                ?>
76            <table class="listview">
77            <thead>
78            <tr><th colspan="2">Name</th><th>Size</th><th>Image Size</th><th>Date Modified</th><th>&nbsp;</th></tr></thead>
79            <tbody>
80            <?php
81                // start of foreach for draw listview folders .
82                foreach($list[0] as $path => $dir)
83                { ?>
84                        <tr>
85                        <td><img src="<?php print $IMConfig['base_url'];?>icons/folder_small.gif" alt="" /></td>
86                        <th nowrap><a href="<?php print $IMConfig['backend_url']; ?>__function=images&amp;mode=<?php echo $insertMode;?>&amp;dir=<?php echo rawurlencode($path); ?>&amp;viewtype=<?php echo $afruViewType; ?>" onclick="updateDir('<?php echo $path; ?>')" title="<?php echo $dir['entry']; ?>">
87                        <?php
88                        if(strlen($dir['entry'])>$maxNameLength) echo substr($dir['entry'],0,$maxNameLength)."..."; else echo $dir['entry'];
89                        ?>
90                        </a></th>
91                        <td colspan="2" nowrap>Folder</td>
92
93                        <td nowrap><?php echo date("d.m.y H:i",$dir['stat']['mtime']); ?></td>
94
95                        <td class="actions" nowrap>
96                                <a href="<?php print $IMConfig['backend_url']; ?>__function=images&amp;mode=<?php echo $insertMode;?>&amp;dir=<?php echo $relative; ?>&amp;deld=<?php echo rawurlencode($path); ?>&amp;viewtype=<?php echo $afruViewType; ?>" title="Trash" onclick="return confirmDeleteDir('<?php echo $dir['entry']; ?>', <?php echo $dir['count']; ?>);" style="border:0px;"><img src="<?php print $IMConfig['base_url'];?>img/edit_trash.gif" height="15" width="15" alt="Trash" border="0" /></a>
97                        </td>
98                        </tr>
99                  <?php
100                } // end of foreach for draw listview folders .
101
102                clearstatcache();
103
104                // start of foreach for draw listview files .
105                foreach($list[1] as $entry => $file)
106                {
107                        ?>
108                <tr>
109                          <td><img src="<?php print $IMConfig['base_url']; if(is_file('icons/'.$file['ext'].'_small.gif')) echo "icons/".$file['ext']."_small.gif"; else echo $IMConfig['default_listicon']; ?>" alt="" /></td>
110                  <th><a href="#" class="thumb" style="cursor: pointer;" ondblclick="this.onclick();window.top.onOK();" onclick="selectImage('<?php echo $file['relative'];?>', '<?php echo preg_replace('#\..{3,4}$#', '', $entry); ?>', <?php echo $file['image'][0];?>, <?php echo $file['image'][1]; ?>);return false;" title="<?php echo $entry; ?> - <?php echo Files::formatSize($file['stat']['size']); ?>" <?php if ($insertMode == 'image') { ?> onmouseover="showPreview('<?php echo $file['relative'];?>')" onmouseout="showPreview(window.parent.document.getElementById('f_url').value)" <?php } ?> >
111                                <?php
112                                if(strlen($entry)>$maxNameLength) echo substr($entry,0,$maxNameLength)."..."; else echo $entry;
113                                ?>
114                  </a></th>
115                  <td><?php echo Files::formatSize($file['stat']['size']); ?></td>
116                  <td><?php if($file['image'][0] > 0){ echo $file['image'][0].'x'.$file['image'][1]; } ?></td>
117                          <td nowrap><?php echo date("d.m.y H:i",$file['stat']['mtime']); ?></td>
118                  <td class="actions">
119                    <a href="<?php print $IMConfig['backend_url']; ?>__function=images&dir=<?php echo $relative; ?>&amp;delf=<?php echo rawurlencode($file['relative']);?>&amp;mode=<?php echo $insertMode;?>&amp;viewtype=<?php echo $afruViewType; ?>" 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>
120                                <?php if ($IMConfig['allow_rename']) { ?>
121                    <a href="#" title="Rename" onclick="renameFile('<?php echo rawurlencode($file['relative']);?>'); return false;"><img src="<?php print $IMConfig['base_url'];?>img/edit_rename.gif" height="15" width="15" alt="Rename" border="0" /></a>
122                    <?php }  ?>
123                                <?php if($IMConfig['img_library'] && $IMConfig['allow_edit_image'] && $file['image'][0] > 0) { ?>
124                    <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>
125                    <?php }  ?>
126                  </td>
127                </tr>
128                  <?php
129                }//end of foreach of draw listview files
130            ?>
131            </tbody>
132            </table>
133            <?php
134        break;
135        case 'thumbview': // thumbview is default
136        default:
137                $maxFileNameLength=11;
138                $maxFolderNameLength=13;
139                // start of foreach for draw thumbview folders.
140                foreach($list[0] as $path => $dir)
141                { ?>
142    <div class="dir_holder">
143      <a class="dir" href="<?php print $IMConfig['backend_url'];?>__function=images&amp;mode=<?php echo $insertMode;?>&amp;dir=<?php echo rawurlencode($path); ?>&amp;viewtype=<?php echo $afruViewType; ?>" 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>
144
145      <div class="edit">
146        <a href="<?php print $IMConfig['backend_url'];?>__function=images&amp;mode=<?php echo $insertMode;?>&amp;dir=<?php echo $relative; ?>&amp;deld=<?php echo rawurlencode($path); ?>&amp;viewtype=<?php echo $afruViewType; ?>" 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>
147        <?php if(strlen($dir['entry']) > $maxFolderNameLength)
148                echo substr($dir['entry'], 0, $maxFolderNameLength) . "...";
149              else
150                echo $dir['entry']; ?>
151      </div>
152    </div>
153                  <?php
154                } // end of foreach for draw thumbview folders.
155
156
157                // start of foreach for draw thumbview files.
158                foreach($list[1] as $entry => $file)
159                {
160                        $afruimgdimensions=$manager->checkImageSize($file['relative']);
161                        $thisFileNameLength = $maxFileNameLength;
162                        ?>
163                <div class="thumb_holder" id="holder_<?php echo asc2hex($entry) ?>">
164                  <a href="#" class="thumb" style="cursor: pointer;" ondblclick="this.onclick();window.top.onOK();" onclick="selectImage('<?php echo $file['relative'];?>', '<?php echo preg_replace('#\..{3,4}$#', '', $entry); ?>', <?php echo $file['image'][0];?>, <?php echo $file['image'][1]; ?>);return false;" title="<?php echo $entry; ?> - <?php echo Files::formatSize($file['stat']['size']); ?>">
165                    <img src="<?php print $manager->getThumbnail($file['relative']); ?>" alt="<?php echo $entry; ?> - <?php echo Files::formatSize($file['stat']['size']); ?>" />
166                  </a>
167                  <div class="edit">
168                    <a href="<?php print $IMConfig['backend_url']; ?>__function=images&amp;mode=<?php echo $insertMode;?>&amp;dir=<?php echo $relative; ?>&amp;delf=<?php echo rawurlencode($file['relative']);?>&amp;viewtype=<?php echo $afruViewType; ?>" 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>
169                                <?php if ($IMConfig['allow_rename']) { ?>
170                    <a href="#" title="Rename" onclick="renameFile('<?php echo rawurlencode($file['relative']);?>'); return false;"><img src="<?php print $IMConfig['base_url'];?>img/edit_rename.gif" height="15" width="15" alt="Rename" /></a>
171                    <?php $thisFileNameLength -= 3; }  ?>
172                        <?php if($IMConfig['img_library'] && $IMConfig['allow_edit_image'] && $file['image'][0] > 0 )
173                    { ?>
174                    <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>
175                        <?php $thisFileNameLength -= 3; } ?>
176
177                        <?php
178                                if(strlen($entry) > $thisFileNameLength + 3) echo strtolower(substr($entry,0,$thisFileNameLength))."..."; else echo $entry;
179                        ?>
180                  </div>
181                </div>
182                  <?php
183                }//end of foreach of draw thumbview files
184
185    }
186}//end of function drawDirs_Files
187
188
189/**
190 * No directories and no files.
191 */
192function drawNoResults()
193{
194?>
195<div class="noResult">No Files Found</div>
196<?php
197}
198
199/**
200 * No directories and no files.
201 */
202function drawErrorBase(&$manager)
203{
204?>
205<div class="error"><span>Invalid base directory:</span> <?php echo $manager->getImagesDir(); ?></div>
206<?php
207}
208
209/**
210 * Utility to convert ascii string to hex
211 */
212function asc2hex ($temp)
213{
214  $data = '';
215  $len = strlen($temp);
216  for ($i=0; $i<$len; $i++) $data.=sprintf("%02x",ord(substr($temp,$i,1)));
217  return $data;
218}
219
220?>
221<html>
222<head>
223        <title>File List</title>
224  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
225        <link href="<?php print $IMConfig['base_url'];?>assets/imagelist.css" rel="stylesheet" type="text/css" />
226<script type="text/javascript" src="<?php print $IMConfig['base_url'];?>assets/dialog.js"></script>
227<script type="text/javascript">
228/*<![CDATA[*/
229
230    var _backend_url = "<?php print $IMConfig['backend_url']; ?>";
231
232        if(window.top)
233                HTMLArea = window.top.HTMLArea;
234
235        function hideMessage()
236        {
237                var topDoc = window.top.document;
238                var messages = topDoc.getElementById('messages');
239                if(messages)
240                        messages.style.display = "none";
241        }
242
243        init = function()
244        {
245        __dlg_translate('ExtendedFileManager');
246       
247                hideMessage();
248
249                <?php
250                if(isset($uploadStatus) && !is_numeric($uploadStatus) && !is_bool($uploadStatus))
251                echo 'alert(i18n("'.$uploadStatus.'"));';
252                else if(isset($uploadStatus) && $uploadStatus==false)
253                echo 'alert("Unable to upload File. \nEither Maximum file size ['.($insertMode == 'image' ? $IMConfig['max_filesize_kb_image'] : $IMConfig['max_filesize_kb_link'] ).'Kb] exceeded or\nFolder doesn\'t have write permission.");';
254                ?>
255
256                <?php
257                if(isset($renameStatus) && !is_numeric($renameStatus) && !is_bool($renameStatus))
258                echo 'alert(i18n("'.$renameStatus.'"));';
259                else if(isset($renameStatus) && $renameStatus===false)
260                echo 'alert(i18n("Unable to rename file. File of the same name already exists or\nfolder doesn\'t have write permission."));';
261                ?>
262
263                var topDoc = window.top.document;
264
265<?php
266        //we need to refesh the drop directory list
267        //save the current dir, delete all select options
268        //add the new list, re-select the saved dir.
269        if($refreshDir)
270        {
271                $dirs = $manager->getDirs();
272?>
273                var selection = topDoc.getElementById('dirPath');
274                var currentDir = selection.options[selection.selectedIndex].text;
275
276                while(selection.length > 0)
277                {       selection.remove(0); }
278               
279                selection.options[selection.length] = new Option("/","<?php echo rawurlencode('/'); ?>");
280                <?php foreach($dirs as $relative=>$fullpath) { ?>
281                selection.options[selection.length] = new Option("<?php echo $relative; ?>","<?php echo rawurlencode($relative); ?>");
282                <?php } ?>
283               
284                for(var i = 0; i < selection.length; i++)
285                {
286                        var thisDir = selection.options[i].text;
287                        if(thisDir == currentDir)
288                        {
289                                selection.selectedIndex = i;
290                                break;
291                        }
292                }               
293<?php } ?>
294        }
295   
296        function editImage(image)
297        {
298                var url = "<?php print $IMConfig['backend_url']; ?>__function=editor&img="+image+"&mode=<?php print $insertMode ?>";
299        Dialog(url, function(param)
300                {
301                        if (!param) { // user must have pressed Cancel
302                                return false;
303                        } else
304                        {
305                                return true;
306                        }
307                }, null);
308        }
309
310/*]]>*/
311</script>
312<script type="text/javascript" src="<?php print $IMConfig['base_url'];?>assets/images.js"></script>
313<script type="text/javascript" src="<?php print $IMConfig['base_url'];?>assets/popup.js"></script>
314<script type="text/javascript">
315<!--
316// Koto: why emptying? commented out
317//if(window.top.document.getElementById('manager_mode').value=="image")
318//emptyProperties();
319<?php if(isset($diskInfo)) echo 'updateDiskMesg("'.$diskInfo.'");'; ?>
320//-->
321</script>
322
323</head>
324
325<body>
326<?php if ($manager->isValidBase() == false) { drawErrorBase($manager); }
327        elseif(count($list[0]) > 0 || count($list[1]) > 0) { ?>
328        <?php drawDirs_Files($list, $manager); ?>
329<?php } else { drawNoResults(); } ?>
330</body>
331</html>
Note: See TracBrowser for help on using the repository browser.