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

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

Further work for MFM integration

File size: 5.4 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    if(!@$IMConfig['images_dir'])
101    {
102      // Session time out
103      echo '{"status" : 0, "error": "No images_dir, most likely your session has timed out."}';exit;
104    }
105   
106    // include('mootools-filemanager/Assets/Connector/FileManager.php');
107    include('XinhaFileManager.php');
108   
109    $browser = new XinhaFileManager(array(
110      'images_dir'    => $IMConfig['images_dir'],
111      'images_url'    => $IMConfig['images_url'],
112     
113      'thumbs_dir'    => $IMConfig['thumbs_dir'],
114      'thumbs_url'    => $IMConfig['thumbs_url'],
115     
116      'assetBasePath' => $IMConfig['base_url'] .'/mootools-filemanager/Assets',
117     
118      'upload'        => $IMConfig['allow_images_upload'],
119      'destroy'       => $IMConfig['allow_images_delete'],     
120      'create'        => $IMConfig['allow_images_create_dir'],
121      'move'          => $IMConfig['allow_images_move'],
122      'download'      => $IMConfig['allow_images_download'],
123     
124     
125      'maxUploadSize' => size_to_bytes($IMConfig['max_images_upload_size']),     
126      'suggestedMaxImageDimension' => $IMConfig['suggested_images_image_dimension'],
127      'thumbnailsMustGoThroughBackend' => FALSE,         
128      'filter'        => 'image/',           
129    ));
130
131    $browser->fireEvent(!empty($_REQUEST['event']) ? $_REQUEST['event'] : null);
132    break;
133 
134  case 'file-manager':
135    if(!@$IMConfig['files_dir'])
136    {
137      // Session time out
138      echo '{"status" : 0, "error": "No files_dir, most likely your session has timed out."}';exit;
139    }
140   
141    include('XinhaFileManager.php');
142   
143    $browser = new XinhaFileManager(array(
144      'files_dir'     => $IMConfig['files_dir'],
145      'files_url'     => $IMConfig['files_url'],
146     
147      'thumbs_dir'    => $IMConfig['thumbs_dir'],
148      'thumbs_url'    => $IMConfig['thumbs_url'],
149     
150      'assetBasePath' => $IMConfig['base_url'] .'/mootools-filemanager/Assets',
151     
152      'upload'        => $IMConfig['allow_files_upload'],
153      'destroy'       => $IMConfig['allow_files_delete'],
154      'create'        => $IMConfig['allow_files_create_dir'],
155      'move'          => $IMConfig['allow_files_move'],
156      'download'      => $IMConfig['allow_files_download'],
157     
158     
159      'maxUploadSize' => size_to_bytes($IMConfig['max_files_upload_size']),     
160      'suggestedMaxImageDimension' => $IMConfig['suggested_files_image_dimension'],
161      'thumbnailsMustGoThroughBackend' => FALSE,     
162     // 'filter'        => $IMConfig['files_filter'],
163           
164    ));
165
166    $browser->fireEvent(!empty($_REQUEST['event']) ? $_REQUEST['event'] : null);
167    break;
168}
169
170?>
Note: See TracBrowser for help on using the repository browser.