root / branches / new-dialogs / plugins / ExtendedFileManager / images.php

Revision 987, 18.1 kB (checked in by ray, 4 years ago)

#1179 minor html syntax changes

  • Property svn:keywords set to LastChangedDate LastChangedRevision LastChangedBy HeadURL Id
Line 
1<?php
2/**
3 * ExtendedFileManager images.php file. Shows folders and files.
4 * Authors: Wei Zhuo, Afru, Krzysztof Kotowicz, Raimund Meyer
5 * Version: Updated on 08-01-2005 by Afru
6 * Version: Updated on 04-07-2006 by Krzysztof Kotowicz
7 * Version: Updated on 29-10-2006 by Raimund Meyer
8 * Version: Updated on 20-01-2008 by Raimund Meyer
9 * Package: ExtendedFileManager (EFM 1.4)
10 * http://www.afrusoft.com/htmlarea
11 */
12
13    if(isset($_REQUEST['mode'])) $insertMode=$_REQUEST['mode'];
14    if(!isset($insertMode)) $insertMode="image";
15
16require_once('config.inc.php');
17require_once('Classes/ExtendedFileManager.php');
18$backend_url_enc = htmlspecialchars( $IMConfig['backend_url'] );
19//default path is /
20$relative = '/';
21$manager = new ExtendedFileManager($IMConfig, $insertMode);
22
23//process any file uploads
24$uploadStatus=$manager->processUploads();
25
26//process any file renames
27$renameStatus=$manager->processRenames();
28
29//process paste
30$pasteStatus = (isset($_GET['paste'])) ?     $manager->processPaste() : false;
31
32$refreshFile = ($manager->deleteFiles()) ? true : false;
33
34$refreshDir = false;
35//process any directory functions
36if($manager->deleteDirs() || $manager->processNewDir() || $pasteStatus || $renameStatus )
37    $refreshDir = true;
38
39
40$diskInfo=$manager->getDiskInfo();
41
42//check for any sub-directory request
43//check that the requested sub-directory exists
44//and valid
45if(isset($_REQUEST['dir']))
46{
47    $path = rawurldecode($_REQUEST['dir']);
48    if($manager->validRelativePath($path))
49        $relative = $path;
50}
51
52$afruViewType = (isset($_REQUEST['viewtype'])) ? $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,$backend_url_enc;
71
72    switch ($afruViewType) {
73        case 'listview':
74            $maxNameLength = 30;
75            ?>
76            <table class="listview" id="listview">
77            <thead>
78            <tr><th>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><span style="width:20px;"><img src="<?php print $IMConfig['base_url'];?>icons/folder_small.gif" alt="" /></span>
86                <a href="<?php print $backend_url_enc; ?>__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></td>
91                <td colspan="2" >Folder</td>
92
93                <td ><?php echo date($IMConfig['date_format'],$dir['stat']['mtime']); ?></td>
94
95                <td class="actions" >
96                    <a href="<?php print $backend_url_enc; ?>__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                    <?php if ($IMConfig['allow_rename']) { ?>
98                                <a href="#" title="Rename" onclick="renameDir('<?php echo rawurlencode($dir['entry']);?>'); return false;"><img src="<?php print $IMConfig['base_url'];?>img/edit_rename.gif" height="15" width="15" alt="Rename" border="0" /></a>
99                    <?php ?>
100                    <?php if ($IMConfig['allow_cut_copy_paste']) { ?>
101                    <a href="#" title="Cut" onclick="copyDir('<?php echo rawurlencode($dir['entry']);?>','move'); return false;"><img src="<?php print $IMConfig['base_url'];?>img/edit_cut.gif" height="15" width="15" alt="Cut" /></a>
102                     <a href="#" title="Copy" onclick="copyDir('<?php echo rawurlencode($dir['entry']);?>','copy'); return false;"><img src="<?php print $IMConfig['base_url'];?>img/edit_copy.gif" height="15" width="15" alt="Copy" /></a>
103                        <?php ?>
104                </td>
105                </tr>
106              <?php
107            } // end of foreach for draw listview folders .
108
109            clearstatcache();
110
111            // start of foreach for draw listview files .
112            foreach($list[1] as $entry => $file)
113            {
114                ?>
115                <tr>
116                  <td><span style="width:20px;"><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="" /></span>
117                    <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 } ?> >
118                    <?php
119                    if(strlen($entry)>$maxNameLength) echo substr($entry,0,$maxNameLength)."..."; else echo $entry;
120                    ?>
121                  </a></td>
122                  <td><?php echo Files::formatSize($file['stat']['size']); ?></td>
123                  <td><?php if($file['image'][0] > 0){ echo $file['image'][0].'x'.$file['image'][1]; } ?></td>
124                  <td ><?php echo date($IMConfig['date_format'],$file['stat']['mtime']); ?></td>
125                  <td class="actions">
126                    <?php if($IMConfig['img_library'] && $IMConfig['allow_edit_image'] && $file['image'][0] > 0) { ?>
127                    <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>
128                    <?php ?> 
129                    <a href="<?php print $backend_url_enc; ?>__function=images&amp;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>
130                    <?php if ($IMConfig['allow_rename']) { ?>
131                    <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>
132                    <?php ?>
133                    <?php if ($IMConfig['allow_cut_copy_paste']) { ?>
134                    <a href="#" title="Cut" onclick="copyFile('<?php echo rawurlencode($entry);?>','move'); return false;"><img src="<?php print $IMConfig['base_url'];?>img/edit_cut.gif" height="15" width="15" alt="Cut" /></a>
135                     <a href="#" title="Copy" onclick="copyFile('<?php echo rawurlencode($entry);?>','copy'); return false;"><img src="<?php print $IMConfig['base_url'];?>img/edit_copy.gif" height="15" width="15" alt="Copy" /></a>
136                    <?php ?>
137                  </td>
138                </tr>
139              <?php
140            }//end of foreach of draw listview files
141            ?>
142            </tbody>
143            </table>
144            <?php
145        break;
146        case 'thumbview': // thumbview is default
147        default:
148            $maxFileNameLength=16;
149            $maxFolderNameLength=16;
150            // start of foreach for draw thumbview folders.
151            foreach($list[0] as $path => $dir)
152            { ?>
153    <div class="dir_holder">
154      <a class="dir" href="<?php print $backend_url_enc;?>__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>
155
156      <div class="fileName">
157      <?php if(strlen($dir['entry']) > $maxFolderNameLength)
158                echo substr($dir['entry'], 0, $maxFolderNameLength) . "...";
159              else
160                echo $dir['entry']; ?>
161      </div>
162      <div class="edit">
163        <a href="<?php print $backend_url_enc;?>__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>
164        <?php if ($IMConfig['allow_rename']) { ?>
165                    <a href="#" title="Rename" onclick="renameDir('<?php echo rawurlencode($dir['entry']);?>'); return false;"><img src="<?php print $IMConfig['base_url'];?>img/edit_rename.gif" height="15" width="15" alt="Rename" border="0" /></a>
166        <?php ?>
167        <?php if ($IMConfig['allow_cut_copy_paste']) { ?>
168                    <a href="#" title="Cut" onclick="copyDir('<?php echo rawurlencode($dir['entry']);?>','move'); return false;"><img src="<?php print $IMConfig['base_url'];?>img/edit_cut.gif" height="15" width="15" alt="Cut" /></a>
169                     <a href="#" title="Copy" onclick="copyDir('<?php echo rawurlencode($dir['entry']);?>','copy'); return false;"><img src="<?php print $IMConfig['base_url'];?>img/edit_copy.gif" height="15" width="15" alt="Copy" /></a>
170        <?php ?>
171      </div>
172    </div>
173              <?php
174            } // end of foreach for draw thumbview folders.
175
176
177            // start of foreach for draw thumbview files.
178            foreach($list[1] as $entry => $file)
179            {
180                $afruimgdimensions=$manager->checkImageSize($file['relative']);
181                $thisFileNameLength = $maxFileNameLength;
182                ?>
183                <div class="thumb_holder" id="holder_<?php echo asc2hex($entry) ?>">
184                  <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']); ?>">
185                    <img src="<?php print $manager->getThumbnail($file['relative']); ?>" alt="<?php echo $entry; ?> - <?php echo Files::formatSize($file['stat']['size']); ?>" />
186                  </a>
187                   <div class="fileName">
188                   <?php
189                        if(strlen($entry) > $thisFileNameLength + 3) echo strtolower(substr($entry,0,$thisFileNameLength))."..."; else echo $entry;
190                    ?>
191                   </div>
192                  <div class="edit">
193                    <?php if($IMConfig['img_library'] && $IMConfig['allow_edit_image'] && $file['image'][0] > 0 )
194                    { ?>
195                    <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>
196                    <?php $thisFileNameLength -= 3; } ?>
197                    <a href="<?php print $backend_url_enc; ?>__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>
198                    <?php if ($IMConfig['allow_rename']) { ?>
199                    <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>
200                    <?php $thisFileNameLength -= 3; }  ?>
201                    <?php if ($IMConfig['allow_cut_copy_paste']) { ?>
202                    <a href="#" title="Cut" onclick="copyFile('<?php echo rawurlencode($entry);?>','move'); return false;"><img src="<?php print $IMConfig['base_url'];?>img/edit_cut.gif" height="15" width="15" alt="Cut" /></a>
203                     <a href="#" title="Copy" onclick="copyFile('<?php echo rawurlencode($entry);?>','copy'); return false;"><img src="<?php print $IMConfig['base_url'];?>img/edit_copy.gif" height="15" width="15" alt="Copy" /></a>
204                    <?php $thisFileNameLength -= 6; }  ?>
205                   
206                  </div>
207                </div>
208              <?php
209            }//end of foreach of draw thumbview files
210
211    }
212}//end of function drawDirs_Files
213
214
215/**
216 * No directories and no files.
217 */
218function drawNoResults()
219{
220?>
221<div class="noResult">No Files Found</div>
222<?php
223}
224
225/**
226 * No directories and no files.
227 */
228function drawErrorBase(&$manager)
229{
230?>
231<div class="error"><span>Invalid base directory:</span> <?php echo $manager->getImagesDir(); ?></div>
232<?php
233}
234
235/**
236 * Utility to convert ascii string to hex
237 */
238function asc2hex ($temp)
239{
240  $data = '';
241  $len = strlen($temp);
242  for ($i=0; $i<$len; $i++) $data.=sprintf("%02x",ord(substr($temp,$i,1)));
243  return $data;
244}
245
246?>
247<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
248    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
249<html xmlns="http://www.w3.org/1999/xhtml">
250<head>
251    <title>File List</title>
252  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
253    <link href="<?php print $IMConfig['base_url'];?>assets/imagelist.css" rel="stylesheet" type="text/css" />
254<script type="text/javascript" src="<?php print $IMConfig['base_url'];?>assets/dialog.js"></script>
255<script type="text/javascript">
256/*<![CDATA[*/
257
258    var _backend_url = "<?php print $IMConfig['backend_url']; ?>";
259
260    if(window.top)
261        Xinha = window.top.Xinha;
262
263    function hideMessage()
264    {
265        var topDoc = window.top.document;
266        var messages = topDoc.getElementById('messages');
267        if (messages)
268        {
269            messages.style.display = "none";
270        }
271        //window.parent.resize();
272    }
273
274    init = function()
275    {
276        __dlg_translate('ExtendedFileManager');
277       
278        hideMessage();
279        <?php if ($afruViewType == 'listview')
280            print "var d = new dragTableCols('listview');";
281       
282        if(isset($uploadStatus) && !is_numeric($uploadStatus) && !is_bool($uploadStatus))
283        echo "alert(i18n('$uploadStatus'));";
284        else if(isset($uploadStatus) && $uploadStatus==false)
285        echo 'alert(i18n("Unable to upload File. \nEither Maximum file size [$max_size='.($insertMode == 'image' ? $IMConfig['max_filesize_kb_image'] : $IMConfig['max_filesize_kb_link'] ).'$ KB] exceeded or\nFolder doesn\'t have write permission."));';
286        ?>
287
288        <?php
289        if(isset($renameStatus) && !is_numeric($renameStatus) && !is_bool($renameStatus))
290        echo 'alert(i18n("'.$renameStatus.'"));';
291        else if(isset($renameStatus) && $renameStatus===false)
292        echo 'alert(i18n("Unable to rename file. File of the same name already exists or\nfolder doesn\'t have write permission."));';
293        ?>
294       
295        <?php
296        if (isset($pasteStatus) && is_numeric($pasteStatus))
297        {
298            switch ($pasteStatus)
299            {
300                case 100 :
301                    $pasteStatus = 'Source file/folder not found.';
302                break;
303                case 101 :
304                    $pasteStatus = 'Copy failed.\nMaybe folder doesn\'t have write permission.';
305                break;
306                case 102 :
307                    $pasteStatus = 'Could not create destination folder.';
308                break;
309                case 103 :
310                    $pasteStatus = 'File pasted OK.';
311                break;
312                case 104 :
313                    $pasteStatus = 'Destination file/folder already exists.';
314                break;
315            }
316        }
317        if(isset($pasteStatus) && !is_bool($pasteStatus))
318        {
319            echo 'alert(i18n("'.$pasteStatus.'"));';
320        }
321        ?>
322
323        var topDoc = window.top.document;
324
325<?php
326    //we need to refesh the drop directory list
327    //save the current dir, delete all select options
328    //add the new list, re-select the saved dir.
329    if($refreshDir)
330    {
331        $dirs = $manager->getDirs();
332?>
333        var selection = topDoc.getElementById('dirPath');
334        var currentDir = selection.options[selection.selectedIndex].text;
335
336        while(selection.length > 0)
337        {    selection.remove(0); }
338       
339        selection.options[selection.length] = new Option("/","<?php echo rawurlencode('/'); ?>");
340        <?php foreach($dirs as $relative=>$fullpath) { ?>
341        selection.options[selection.length] = new Option("<?php echo $relative; ?>","<?php echo rawurlencode($relative); ?>");
342        <?php } ?>
343       
344        for(var i = 0; i < selection.length; i++)
345        {
346            var thisDir = selection.options[i].text;
347            if(thisDir == currentDir)
348            {
349                selection.selectedIndex = i;
350                break;
351            }
352        }       
353<?php } ?>
354    }
355   
356    function editImage(image)
357    {
358        var url = "<?php print $IMConfig['backend_url']; ?>__function=editor&img="+image+"&mode=<?php print $insertMode ?>";
359        Dialog(url, function(param)
360        {
361            if (!param) { // user must have pressed Cancel
362                return false;
363            } else
364            {
365                return true;
366            }
367        }, null);
368    }
369
370/*]]>*/
371</script>
372<script type="text/javascript" src="<?php print $IMConfig['base_url'];?>assets/images.js"></script>
373<script type="text/javascript" src="<?php print $IMConfig['base_url'];?>assets/popup.js"></script>
374<script type="text/javascript">
375<!--
376// Koto: why emptying? commented out
377//if(window.top.document.getElementById('manager_mode').value=="image")
378//emptyProperties();
379<?php if(isset($diskInfo)) echo 'updateDiskMesg(i18n(\''.$diskInfo.'\'));'; ?>
380//-->
381</script>
382<script type="text/javascript" src="<?php print $IMConfig['base_url'];?>assets/dragTableCols.js"></script>
383</head>
384
385<body>
386<?php if ($manager->isValidBase() == false) { drawErrorBase($manager); }
387    elseif(count($list[0]) > 0 || count($list[1]) > 0) { ?>
388    <?php drawDirs_Files($list, $manager); ?>
389<?php } else { drawNoResults(); } ?>
390</body>
391</html>
Note: See TracBrowser for help on using the browser.