source: branches/MootoolsFileManager-Update/plugins/MootoolsFileManager/backend.php @ 1302

Last change on this file since 1302 was 1302, checked in by gogo, 8 years ago

Updates to http://www.github.com/sleemanj/mootools-filemanager from GerHoblett?

http://www.github.com/GerHoblett/

Changes to said updates by gogo (sleemanj @ github)

Modifications to MootoolsFileManager? to work with those updates, some courtesy of GerHoblett?, some sleemanj

GerHoblett? provided a large diff which accomplished the goal in a quite different way. It has merit, however I have opted for a less-affecting path in so far as Xinha's "way" is concerned, namely, not splitting the config for a single plugin into several calls to backend config passing functions which seemed a little cumbersome.

Instead I take the option of using POST to send backend data around, at the minor expense of an extra round trip when displaying thumbnails (for each one). This could be reduced by checking for thumbnail existence and returning the thumbnail name directly in "onView" rather than the backend request to generate said thumbnail.

Still to do, is to make the preview pane thumbnail also work.


File size: 5.0 KB
Line 
1<?php
2/**
3* Unified backend for ImageManager
4*
5* Image Manager was originally developed by:
6*   Xiang Wei Zhuo, email: xiangweizhuo(at)hotmail.com Wei Shou.
7*
8* Unified backend sponsored by DTLink Software, http://www.dtlink.com
9* Implementation by Yermo Lamers, http://www.formvista.com
10*
11* (c) DTLink, LLC 2005.
12* Distributed under the same terms as HTMLArea itself.
13* This notice MUST stay intact for use (see license.txt).
14*
15* DESCRIPTION:
16*
17* Instead of using separate URL's for each function, ImageManager now
18* routes all requests to the server through this single, replaceable,
19* entry point. backend.php expects at least two URL variable parameters:
20*
21* __plugin=ImageManager   for future expansion; identify the plugin being requested.
22* __function=thumbs|images|editorFrame|editor|manager  function being called.
23*
24* Having a single entry point that strictly adheres to a defined interface will
25* make the backend code much easier to maintain and expand. It will make it easier
26* on integrators, not to mention it'll make it easier to have separate
27* implementations of the backend in different languages (Perl, Python, ASP, etc.)
28*
29* @see config.inc.php
30*/
31
32// Strip slashes if MQGPC is on
33if(function_exists('set_magic_quotes_runtime')) @set_magic_quotes_runtime(0);
34if(function_exists('get_magic_quotes_gpc') && @get_magic_quotes_gpc())
35{
36  $to_clean = array(&$_GET, &$_POST, &$_REQUEST, &$_COOKIE);
37  while(count($to_clean))
38  {
39    $cleaning =& $to_clean[array_pop($junk = array_keys($to_clean))];
40    unset($to_clean[array_pop($junk = array_keys($to_clean))]);
41    foreach(array_keys($cleaning) as $k)
42    {
43      if(is_array($cleaning[$k]))
44      {
45        $to_clean[] =& $cleaning[$k];
46      }
47      else
48      {
49        $cleaning[$k] = stripslashes($cleaning[$k]);
50      }
51    }
52  }
53}
54
55function size_to_bytes($s)
56{
57  if(preg_match('/([0-9\.])+([a-zA-Z]+)/', $s, $M))
58  {
59    switch(strtolower($M[2]))
60    {     
61      case 'm':
62        return floor(floatval($M[1]) * 1024 * 1024);
63       
64      case 'b':
65        return intval($M[1]);
66       
67      case 'kb':
68        return floor(floatval($M[1]) * 1024);     
69    }
70  }
71 
72  if(floatval($s) < 10)   return floor(floatval($s) * 1024 * 1024);
73  if(floatval($s) < 1024) return floor(floatval($s) * 1024); // Kilobytes
74  return intval($s); // Bytes
75}
76
77require_once('config.php');
78
79// Ensure thumbnail path is OK
80if(!isset($IMConfig['files_dir']) || !isset($IMConfig['images_dir']))
81{
82  unset($IMConfig['thumbs_dir']);
83  unset($IMConfig['thumbs_url']);
84}
85else
86{
87  if(!file_exists($IMConfig['thumbs_dir'])) @mkdir($IMConfig['thumbs_dir']);
88}
89
90switch ( @$_REQUEST[ "__function" ] )
91{
92  case 'read-config':       
93    // This is used so that the javascript can read the config
94    // so we don't have to have a js config and a php config duplicating
95    // settings
96    echo xinha_to_js($IMConfig);
97    break;
98
99  case 'image-manager':
100    // include('mootools-filemanager/Assets/Connector/FileManager.php');
101    include('XinhaFileManager.php');
102   
103    $browser = new XinhaFileManager(array(
104      'images_dir'    => $IMConfig['images_dir'],
105      'images_url'    => $IMConfig['images_url'],
106     
107      'thumbs_dir'    => $IMConfig['thumbs_dir'],
108      'thumbs_url'    => $IMConfig['thumbs_url'],
109     
110      'assetBasePath' => $IMConfig['base_url'] .'/mootools-filemanager/Assets',
111     
112      'upload'        => $IMConfig['allow_images_upload'],
113      'destroy'       => $IMConfig['allow_images_delete'],     
114      'create'        => $IMConfig['allow_images_create_dir'],
115      'move'          => $IMConfig['allow_images_move'],
116      'download'      => $IMConfig['allow_images_download'],
117     
118     
119      'maxUploadSize' => size_to_bytes($IMConfig['max_images_upload_size']),     
120      'suggestedMaxImageDimension' => $IMConfig['suggested_images_image_dimension'],
121                 
122      'filter'        => 'image/',           
123    ));
124
125    $browser->fireEvent(!empty($_REQUEST['event']) ? $_REQUEST['event'] : null);
126    break;
127 
128  case 'file-manager':
129    include('mootools-filemanager/Assets/Connector/FileManager.php');
130
131    $browser = new FileManager(array(
132      'files_dir'     => $IMConfig['files_dir'],
133      'files_url'     => $IMConfig['files_url'],
134     
135      'thumbs_dir'    => $IMConfig['thumbs_dir'],
136      'thumbs_url'    => $IMConfig['thumbs_dir'],
137     
138      'assetBasePath' => $IMConfig['base_url'] .'/mootools-filemanager/Assets',
139     
140      'upload'        => $IMConfig['allow_files_upload'],
141      'destroy'       => $IMConfig['allow_files_delete'],
142      'create'        => $IMConfig['allow_files_create_dir'],
143      'move'          => $IMConfig['allow_files_move'],
144      'download'      => $IMConfig['allow_files_download'],
145     
146     
147      'maxUploadSize' => size_to_bytes($IMConfig['max_files_upload_size']),     
148      'suggestedMaxImageDimension' => $IMConfig['suggested_files_image_dimension'],
149           
150     // 'filter'        => $IMConfig['files_filter'],
151           
152    ));
153
154    $browser->fireEvent(!empty($_REQUEST['event']) ? $_REQUEST['event'] : null);
155    break;
156}
157
158?>
Note: See TracBrowser for help on using the repository browser.