source: trunk/plugins/MootoolsFileManager/backend.php

Last change on this file was 1371, checked in by gogo, 18 months ago

Updates to MootoolsFileManager? - most importantly removal of Flash dependancy, now uses HTML5 file uploads.

Also now updated the default MooTools? to 1.6.0 - you can of course load your own MooTools? first (before Xinha), anything down to about 1.3 works I think, if you load yours then it will be used instead.

Other updates from https://github.com/sleemanj/mootools-filemanager included in this update are:

  • Remove space from allowed characters in filenames, they will be converted to _ on upload
  • Fix for a small (inconsequential) uppercase extension bug
  • Add some more php extensions to the "unsafe" list
  • Fix image resize on upload to be more space efficient
File size: 6.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
55if(isset($_POST['encoded_data']))
56{
57  $D = json_decode(str_rot13($_POST['encoded_data']));
58  foreach($D as $k => $v) { $_POST[$k]=$v; if(!isset($_REQUEST[$k])) $_REQUEST[$k] = $v; }
59}
60
61function size_to_bytes($s)
62{
63  if(preg_match('/([0-9\.])+([a-zA-Z]+)/', $s, $M))
64  {
65    switch(strtolower($M[2]))
66    {     
67      case 'm':
68        return floor(floatval($M[1]) * 1024 * 1024);
69       
70      case 'b':
71        return intval($M[1]);
72       
73      case 'kb':
74        return floor(floatval($M[1]) * 1024);     
75    }
76  }
77 
78  if(floatval($s) < 10)   return floor(floatval($s) * 1024 * 1024);
79  if(floatval($s) < 1024) return floor(floatval($s) * 1024); // Kilobytes
80  return intval($s); // Bytes
81}
82
83define('I_KNOW_ABOUT_SUHOSIN', TRUE); // /contrib/xinha-php.js does it's best to avoid this problem for us
84require_once('config.php');
85
86// Ensure thumbnail path is OK
87if(!isset($IMConfig['files_dir']) && !isset($IMConfig['images_dir']))
88{
89  unset($IMConfig['thumbs_dir']);
90  unset($IMConfig['thumbs_url']);
91}
92else
93{
94  if(!file_exists($IMConfig['thumbs_dir'])) @mkdir($IMConfig['thumbs_dir']);
95}
96
97switch ( @$_REQUEST[ "__function" ] )
98{
99  case 'read-config':       
100    // This is used so that the javascript can read the config
101    // so we don't have to have a js config and a php config duplicating
102    // settings
103    echo xinha_to_js($IMConfig);
104    break;
105
106  case 'image-manager':
107    if(!@$IMConfig['images_dir'])
108    {
109      // Session time out
110      echo '{"status" : 0, "error": "No images_dir, most likely your session has timed out, or the file upload was too large for this server to handle, try refreshing your browser, or uploading a smaller file if it still does not work.", "data": ' . json_encode($_REQUEST).'}';exit;
111    }
112   
113    // include('mootools-filemanager/Assets/Connector/FileManager.php');
114    include('XinhaFileManager.php');
115   
116    $browser = new XinhaFileManager(array(
117      'images_dir'    => $IMConfig['images_dir'],
118      'images_url'    => $IMConfig['images_url'],
119     
120      'thumbs_dir'    => $IMConfig['thumbs_dir'],
121      'thumbs_url'    => $IMConfig['thumbs_url'],
122     
123      'assetBasePath' => $IMConfig['base_url'] .'/mootools-filemanager/Assets',
124     
125      'upload'        => $IMConfig['images_allow_upload'],
126      'destroy'       => $IMConfig['images_allow_delete'],     
127      'create'        => $IMConfig['images_allow_create_dir'],
128      'move'          => $IMConfig['images_allow_move'],
129      'download'      => $IMConfig['images_allow_download'],
130     
131     
132      'maxUploadSize' => size_to_bytes($IMConfig['images_max_upload_size']),     
133      'suggestedMaxImageDimension' => $IMConfig['images_suggested_image_dimension'],
134      'thumbnailsMustGoThroughBackend' => FALSE,         
135      'filter'        => 'image/',         
136     
137      'thumbBigSize'  => 150,
138    ));
139
140    $browser->fireEvent(!empty($_REQUEST['event']) ? $_REQUEST['event'] : null);
141    break;
142 
143  case 'file-manager':
144    if(!@$IMConfig['files_dir'])
145    {
146      // Session time out
147      echo '{"status" : 0, "error": "No files_dir, most likely your session has timed out."}';exit;
148    }
149   
150    include('XinhaFileManager.php');
151   
152    $browser = new XinhaFileManager(array(
153      'files_dir'     => $IMConfig['files_dir'],
154      'files_url'     => $IMConfig['files_url'],
155     
156      'thumbs_dir'    => $IMConfig['thumbs_dir'],
157      'thumbs_url'    => $IMConfig['thumbs_url'],
158     
159      'assetBasePath' => $IMConfig['base_url'] .'/mootools-filemanager/Assets',
160     
161      'upload'        => $IMConfig['files_allow_upload'],
162      'destroy'       => $IMConfig['files_allow_delete'],
163      'create'        => $IMConfig['files_allow_create_dir'],
164      'move'          => $IMConfig['files_allow_move'],
165      'download'      => $IMConfig['files_allow_download'],
166     
167     
168      'maxUploadSize' => size_to_bytes($IMConfig['files_max_upload_size']),     
169      'suggestedMaxImageDimension' => $IMConfig['files_suggested_image_dimension'],
170      'thumbnailsMustGoThroughBackend' => FALSE,     
171     // 'filter'        => $IMConfig['files_filter'],
172      'thumbBigSize'  => 150,
173      'useGetID3IfAvailable' => false,
174    ));
175
176    $browser->fireEvent(!empty($_REQUEST['event']) ? $_REQUEST['event'] : null);
177    break;
178}
179
180?>
Note: See TracBrowser for help on using the repository browser.