root / trunk / plugins / ExtendedFileManager / images.php @ 1231

Revision 1231, 18.8 kB (checked in by gogo, 4 years ago)

Ticket #1205

Add allow_delete and allow_edit to ImageManager
Add allow_delete to ExtendedFileManager

  • 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 = ($IMConfig['allow_delete'] && $manager->deleteFiles()) ? true : false;
33
34$refreshDir = false;
35//process any directory functions
36if(($IMConfig['allow_delete'] && $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            <?php
97              if($IMConfig['allow_delete'])
98              {
99                ?>
100                    <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>
101                <?php
102              }
103            ?>
104                    <?php if ($IMConfig['allow_rename']) { ?>
105                                <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>
106                    <?php ?>
107                    <?php if ($IMConfig['allow_cut_copy_paste']) { ?>
108                    <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>
109                     <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>
110                        <?php ?>
111                </td>
112                </tr>
113              <?php
114            } // end of foreach for draw listview folders .
115
116            clearstatcache();
117
118            // start of foreach for draw listview files .
119            foreach($list[1] as $entry => $file)
120            {
121                ?>
122                <tr>
123                  <td>
124                    <a href="#" class="thumb" style="cursor: pointer;vertical-align:middle;" 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 } ?> >
125          <span style="width:20px;vertical-align:middle;"><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="" style="border:none;" /></span><span style="vertical-align:middle;">
126                    <?php
127                    if(strlen($entry)>$maxNameLength) echo substr($entry,0,$maxNameLength)."..."; else echo $entry;
128                    ?></span>
129                  </a></td>
130                  <td><?php echo Files::formatSize($file['stat']['size']); ?></td>
131                  <td><?php if($file['image'][0] > 0){ echo $file['image'][0].'x'.$file['image'][1]; } ?></td>
132                  <td ><?php echo date($IMConfig['date_format'],$file['stat']['mtime']); ?></td>
133                  <td class="actions">
134                    <?php if($IMConfig['img_library'] && $IMConfig['allow_edit_image'] && $file['image'][0] > 0) { ?>
135                    <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>
136                    <?php ?> 
137             <?php
138              if($IMConfig['allow_delete'])
139              {
140                ?>
141                    <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>
142                 <?php
143               }
144             ?>
145                    <?php if ($IMConfig['allow_rename']) { ?>
146                    <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>
147                    <?php ?>
148                    <?php if ($IMConfig['allow_cut_copy_paste']) { ?>
149                    <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>
150                     <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>
151                    <?php ?>
152                  </td>
153                </tr>
154              <?php
155            }//end of foreach of draw listview files
156            ?>
157            </tbody>
158            </table>
159            <?php
160        break;
161        case 'thumbview': // thumbview is default
162        default:
163            $maxFileNameLength=16;
164            $maxFolderNameLength=16;
165            // start of foreach for draw thumbview folders.
166            foreach($list[0] as $path => $dir)
167            { ?>
168    <div class="dir_holder">
169      <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>
170
171      <div class="fileName">
172      <?php if(strlen($dir['entry']) > $maxFolderNameLength)
173                echo substr($dir['entry'], 0, $maxFolderNameLength) . "...";
174              else
175                echo $dir['entry']; ?>
176      </div>
177      <div class="edit">
178      <?php
179        if($IMConfig['allow_delete'])
180        {
181          ?>
182        <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>
183          <?php
184        }
185      ?>
186        <?php if ($IMConfig['allow_rename']) { ?>
187                    <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>
188        <?php ?>
189        <?php if ($IMConfig['allow_cut_copy_paste']) { ?>
190                    <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>
191                     <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>
192        <?php ?>
193      </div>
194    </div>
195              <?php
196            } // end of foreach for draw thumbview folders.
197
198
199            // start of foreach for draw thumbview files.
200            foreach($list[1] as $entry => $file)
201            {
202                $afruimgdimensions=$manager->checkImageSize($file['relative']);
203                $thisFileNameLength = $maxFileNameLength;
204                ?>
205                <div class="thumb_holder" id="holder_<?php echo asc2hex($entry) ?>">
206                  <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']); ?>">
207                    <img src="<?php print $manager->getThumbnail($file['relative']); ?>" alt="<?php echo $entry; ?> - <?php echo Files::formatSize($file['stat']['size']); ?>" />
208                  </a>
209                   <div class="fileName">
210                   <?php
211                        if(strlen($entry) > $thisFileNameLength + 3) echo strtolower(substr($entry,0,$thisFileNameLength))."..."; else echo $entry;
212                    ?>
213                   </div>
214                  <div class="edit">
215                    <?php if($IMConfig['img_library'] && $IMConfig['allow_edit_image'] && $file['image'][0] > 0 )
216                    { ?>
217                    <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>
218                    <?php $thisFileNameLength -= 3; } ?>
219                <?php
220                  if($IMConfig['allow_delete'])
221                  {
222                    ?>
223                    <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>
224                    <?php
225                  }
226                ?>
227                    <?php if ($IMConfig['allow_rename']) { ?>
228                    <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>
229                    <?php $thisFileNameLength -= 3; }  ?>
230                    <?php if ($IMConfig['allow_cut_copy_paste']) { ?>
231                    <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>
232                     <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>
233                    <?php $thisFileNameLength -= 6; }  ?>
234                   
235                  </div>
236                </div>
237              <?php
238            }//end of foreach of draw thumbview files
239
240    }
241}//end of function drawDirs_Files
242
243
244/**
245 * No directories and no files.
246 */
247function drawNoResults()
248{
249?>
250<div class="noResult">No Files Found</div>
251<?php
252}
253
254/**
255 * No directories and no files.
256 */
257function drawErrorBase(&$manager)
258{
259?>
260<div class="error"><span>Invalid base directory:</span> <?php echo $manager->getImagesDir(); ?></div>
261<?php
262}
263
264/**
265 * Utility to convert ascii string to hex
266 */
267function asc2hex ($temp)
268{
269  $data = '';
270  $len = strlen($temp);
271  for ($i=0; $i<$len; $i++) $data.=sprintf("%02x",ord(substr($temp,$i,1)));
272  return $data;
273}
274
275?>
276<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
277    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
278<html xmlns="http://www.w3.org/1999/xhtml">
279<head>
280    <title>File List</title>
281  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
282    <link href="<?php print $IMConfig['base_url'];?>assets/imagelist.css" rel="stylesheet" type="text/css" />
283<script type="text/javascript" src="<?php print $IMConfig['base_url'];?>assets/dialog.js"></script>
284<script type="text/javascript">
285/*<![CDATA[*/
286
287    var _backend_url = "<?php print $IMConfig['backend_url']; ?>";
288
289    if(window.top)
290        Xinha = window.top.Xinha;
291
292    function hideMessage()
293    {
294        var topDoc = window.top.document;
295        var messages = topDoc.getElementById('messages');
296        if (messages)
297        {
298            messages.style.display = "none";
299        }
300        //window.parent.resize();
301    }
302
303    init = function()
304    {
305        __dlg_translate('ExtendedFileManager');
306       
307        hideMessage();
308        <?php if ($afruViewType == 'listview')
309            print "var d = new dragTableCols('listview');";
310       
311        if(isset($uploadStatus) && !is_numeric($uploadStatus) && !is_bool($uploadStatus))
312        echo "alert(i18n('$uploadStatus'));";
313        else if(isset($uploadStatus) && $uploadStatus==false)
314        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."));';
315        ?>
316
317        <?php
318        if(isset($renameStatus) && !is_numeric($renameStatus) && !is_bool($renameStatus))
319        echo 'alert(i18n("'.$renameStatus.'"));';
320        else if(isset($renameStatus) && $renameStatus===false)
321        echo 'alert(i18n("Unable to rename file. File of the same name already exists or\nfolder doesn\'t have write permission."));';
322        ?>
323       
324        <?php
325        if (isset($pasteStatus) && is_numeric($pasteStatus))
326        {
327            switch ($pasteStatus)
328            {
329                case 100 :
330                    $pasteStatus = 'Source file/folder not found.';
331                break;
332                case 101 :
333                    $pasteStatus = 'Copy failed.\nMaybe folder doesn\'t have write permission.';
334                break;
335                case 102 :
336                    $pasteStatus = 'Could not create destination folder.';
337                break;
338                case 103 :
339                    $pasteStatus = 'File pasted OK.';
340                break;
341                case 104 :
342                    $pasteStatus = 'Destination file/folder already exists.';
343                break;
344            }
345        }
346        if(isset($pasteStatus) && !is_bool($pasteStatus))
347        {
348            echo 'alert(i18n("'.$pasteStatus.'"));';
349        }
350        ?>
351
352        var topDoc = window.top.document;
353
354<?php
355    //we need to refesh the drop directory list
356    //save the current dir, delete all select options
357    //add the new list, re-select the saved dir.
358    if($refreshDir)
359    {
360        $dirs = $manager->getDirs();
361?>
362        var selection = topDoc.getElementById('dirPath');
363        var currentDir = selection.options[selection.selectedIndex].text;
364
365        while(selection.length > 0)
366        {    selection.remove(0); }
367       
368        selection.options[selection.length] = new Option("/","<?php echo rawurlencode('/'); ?>");
369        <?php foreach($dirs as $relative=>$fullpath) { ?>
370        selection.options[selection.length] = new Option("<?php echo $relative; ?>","<?php echo rawurlencode($relative); ?>");
371        <?php } ?>
372       
373        for(var i = 0; i < selection.length; i++)
374        {
375            var thisDir = selection.options[i].text;
376            if(thisDir == currentDir)
377            {
378                selection.selectedIndex = i;
379                break;
380            }
381        }       
382<?php } ?>
383    }
384   
385    function editImage(image)
386    {
387        var url = "<?php print $IMConfig['backend_url']; ?>__function=editor&img="+image+"&mode=<?php print $insertMode ?>";
388        Dialog(url, function(param)
389        {
390            if (!param) { // user must have pressed Cancel
391                return false;
392            } else
393            {
394                return true;
395            }
396        }, null);
397    }
398
399/*]]>*/
400</script>
401<script type="text/javascript" src="<?php print $IMConfig['base_url'];?>assets/images.js"></script>
402<script type="text/javascript" src="<?php print $IMConfig['base_url'];?>assets/popup.js"></script>
403<script type="text/javascript">
404<!--
405// Koto: why emptying? commented out
406//if(window.top.document.getElementById('manager_mode').value=="image")
407//emptyProperties();
408<?php if(isset($diskInfo)) echo 'updateDiskMesg(i18n(\''.$diskInfo.'\'));'; ?>
409//-->
410</script>
411<script type="text/javascript" src="<?php print $IMConfig['base_url'];?>assets/dragTableCols.js"></script>
412</head>
413
414<body>
415<?php if ($manager->isValidBase() == false) { drawErrorBase($manager); }
416    elseif(count($list[0]) > 0 || count($list[1]) > 0) { ?>
417    <?php drawDirs_Files($list, $manager); ?>
418<?php } else { drawNoResults(); } ?>
419</body>
420</html>
Note: See TracBrowser for help on using the browser.