OSDN Git Service

ADD: Mocchiが手がけたファイル管理プラグイン一式をコミット
[nucleus-jp/nucleus-plugins.git] / NP_ImprovedMedia / improvedmedia / MEDIA_VARIABLES.php
1 <?php
2 /**
3  * ImprovedMedia plugin for Nucleus CMS
4  * Version 3.0.1 for PHP5
5  * Written By Mocchi, Feb.28, 2010
6  * 
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 3
10  * of the License, or (at your option) any later version.
11  */
12
13 class MEDIA_VARIABLES {
14  private $accessurl = 'media.php'; //string
15  // privete
16  private $plugindir = ''; //string
17  private $private = 1; //boolean
18  private $greybox = 0; //boolean
19  private $itemdisplay = 10; //integer
20  private $eachblogdir = 0; //boolean
21  
22  private $allowedtypes = array(); //array
23  private $mediaprefix = 0; //boolean
24  private $maxuploadsize = 0; //integer
25  
26  private $mediaurl = ''; //string
27  private $dirmedia = ''; //string
28  
29  private $blog = FALSE; //object
30  private $blogid = 1; //object
31  
32  private $mode = 'display'; //string
33  private $alttext = ''; //string
34  private $astool = 0; //boolean
35  private $collection = ''; //string
36  private $subdir = ''; //string
37  private $filename= ''; //string
38  private $newfilename = ''; //string
39  private $offset = 0; //integer
40  private $way = 'popup'; //string
41  private $filter = ''; //string
42  
43  private static $modes = array('rename_confirm', 'rename', 'erase_confirm', 'erase',
44   'upload_select', _IM_UPLOAD_NEW, 'upload', 'embed_confirm', 'embed',
45    _IM_COLLECTION_SELECT, _IM_FILTER_APPLY, 'display', 'login',
46    'directory_remove_confirm', 'directory_remove', _IM_CREATE_SUBDIR_CONFIRM, 'directory_create',
47     'directory_rename_confirm', 'directory_rename',
48     _IM_DISPLAY_SUBDIR, _IM_DISPLAY_SUBDIR_SELECT, 'directory_display');
49  // protected
50  protected static $modesNotToCheck
51   = array('display', _IM_FILTER_APPLY, _IM_COLLECTION_SELECT, 'login', 'upload_select',
52    _IM_DISPLAY_SUBDIR, _IM_DISPLAY_SUBDIR_SELECT, 'directory_display');
53     
54  public function __construct(&$PluginObject) {
55   global $CONF;
56   $this->blog =& $PluginObject->getBlog();
57   $this->blogid =& $PluginObject->getBlogid();
58   $this->accessurl = $CONF['ActionURL'] . '?action=plugin&amp;name=ImprovedMedia';
59   $this->plugindir = $CONF['AdminURL'] . $PluginObject->getBaseURL();
60   self::setOptions($PluginObject);
61   
62   self::setAllowedTypes();
63   self::setMediaPrefix();
64   self::setMaxUploadSize();
65   
66   self::setMediaURL();
67   self::setDIR_MEDIA();
68   
69   return;
70  }
71  
72  public function __destruct() {return;}
73  
74  protected function setMode() {
75   $mode = htmlspecialchars(requestVar('mode'), ENT_QUOTES, _CHARSET);
76   if(in_array($mode, self::$modes))
77    $this->mode = (string)$mode;
78   return;
79  }
80  
81  protected function setAlttext() {
82   $alttext = htmlspecialchars(requestVar('alttext'), ENT_QUOTES, _CHARSET);
83   trim($alttext);
84   $this->alttext = (string)$alttext;
85   return;
86  }
87  
88  protected function setAstool() {
89   $astool = intRequestVar('astool');
90   if($astool)
91    $this->astool = (int)1;
92   return;
93  }
94  
95  public function getCollections() {
96   $collections = array();
97   $collections = MEDIA::getCollectionList();
98   
99   if(!$this->private) {
100    if(count($collections) < 2)
101     return (string)'error';
102    else
103     array_shift($collections);
104   }
105   ksort($collections, SORT_STRING);
106   return (array)$collections;
107  }
108  
109  protected function setCollection() {
110   global $member;
111   $collection = htmlspecialchars(requestVar('collection'), ENT_QUOTES, _CHARSET);
112   $collections = $this->getCollections();
113   
114   if($collections == 'error') {
115    $this->collection = (string)'error';
116    return;
117   }
118   
119   if(!$this->private) {
120    if($collection == '') {
121     $keys = array_keys($collections);
122     $this->collection = (string)$collections[$keys[0]];
123     return;
124    }
125    if(!array_key_exists($collection, $collections)) {
126     $this->collection = (string)'error';
127     return;
128    }
129    $this->collection = (string)$collection;
130    return;
131   } else {
132    if($collection == '') {
133     $this->collection = (string)$member->getID();
134         return;
135    }
136    if(!array_key_exists($collection, $collections)) {
137     $this->collection = (string)'error';
138         return;
139    }
140    $this->collection = (string)$collection;
141    return;
142   }
143  }
144  
145  public function getSubdirs() {
146   $subdirs = array();
147   $temp = array();
148   $number = 0;
149   
150   if($this->collection == 'error') {
151    return (string)'error';
152   }
153   
154   if(!is_dir($this->dirmedia . $this->collection)) {
155    $subdirs[] = array('subdirname' => '.', 'number' => 0, 'collection' => $this->collection);
156    return $subdirs;
157   }
158   
159   $dirhandle = @opendir($this->dirmedia . $this->collection);
160   
161   if(!$dirhandle) return (string)'error';
162   
163   while(($subdirname = readdir($dirhandle)) !== FALSE) {
164    if(is_dir($this->dirmedia . $this->collection . '/' . $subdirname) && $subdirname != "..") {
165     $number = 0;
166      if($subdirhandle = @opendir($this->dirmedia . $this->collection . '/' . $subdirname)) {
167      if(!$subdirhandle) {
168       return (string)'error';
169      }
170      while(($file = readdir($subdirhandle)) !== FALSE)
171       if($file != '..' && $file != '.' && !is_dir($this->dirmedia . $this->collection . '/' . $subdirname . '/' . $file))
172        ++$number;
173      closedir($subdirhandle);
174     }
175     $temp[$subdirname] = array('number' => $number, 'collection' => $this->collection);
176    }
177   }
178   closedir($dirhandle);
179   ksort($temp);
180   foreach($temp as $subdirname => $options) {
181    $subdirs[] = array('subdirname' => $subdirname, 'number' => $options['number'], 'collection' => $options['collection']);
182   }
183   return (array)$subdirs;
184  }
185  
186  protected function setSubDir() {
187   $subdir = htmlspecialchars(requestVar('subdir'), ENT_QUOTES, _CHARSET);
188   $subdirs = self::getSubdirs();
189   $list = array();
190   
191   if($subdir == '') {
192    $this->subdir = (string)'';
193   }
194     
195   if($subdirs == 'error') {
196    $this->subdir = (string)'error';
197    return;
198   }
199   
200   if(count($subdirs) < 2) {
201    $this->subdir = (string)'';
202    return;
203   }
204   
205   array_shift($subdirs);
206   
207   foreach($subdirs as $key => $options) {
208    if((string)$options['subdirname'] == (string)$subdir) {
209     $this->subdir = (string)$subdir;
210     break;
211    }
212   }
213  }
214  
215  protected function setFilename() {
216   $filename = htmlspecialchars(requestVar('filename'), ENT_QUOTES, _CHARSET);
217   
218   if($filename == '') {
219    $this->filename = (string)'';
220    return;
221   }
222   
223   if($this->collection === 'error') {
224    $this->filename = (string)'error';
225    return;
226   }
227   
228   if($this->subdir === 'error') {
229    $this->filename = (string)'error';
230    return;
231   }
232     
233   if(!$this->subdir)
234    $fileobjectlist = MEDIA::getMediaListByCollection($this->collection);
235   else
236    $fileobjectlist = MEDIA::getMediaListByCollection($this->collection . '/' . $this->subdir);
237   
238   foreach($fileobjectlist as $fileobject) {
239    if((string)$fileobject->filename == (string)$filename) {
240     $this->filename = $fileobject->filename;
241     break;
242    }
243   }
244   return;
245  }
246  
247  protected function setNewFilename() {
248   $newfilename = htmlspecialchars(requestVar('newfilename'), ENT_QUOTES, _CHARSET);
249   trim($newfilename);
250   $this->newfilename = (string)$newfilename;
251   return;
252  }
253  
254  protected function setOffset() {
255   $offset = intRequestVar('offset');
256   if($offset >= 0)
257    $this->offset = (int)$offset;
258   return;
259  }
260  
261  protected function setWay() {
262   $way = htmlspecialchars(requestVar('way'), ENT_QUOTES, _CHARSET);
263   $ways = array('popup','inline','other');
264   if(in_array($way, $ways))
265    $this->way = (string)$way;
266   return;
267  }
268  
269  protected function setFilter() {
270   $filter = htmlspecialchars(requestVar('filter'), ENT_QUOTES, _CHARSET);
271   if($this->allowedtypes === array()) {
272    $this->filter = (string)'';
273    return;
274   }
275   if(in_array($filter, $this->allowedtypes))
276    $this->filter = (string)$filter;
277   return;
278  }
279  
280  private function setAllowedTypes() {
281   global $CONF;
282   if($CONF['AllowedTypes'] == '')
283    return array();
284   $allowedtypes = explode(',', $CONF['AllowedTypes']);
285   if(is_array($allowedtypes)) {
286    sort($allowedtypes);
287    $this->allowedtypes = (array)$allowedtypes;
288   }
289   return;
290  }
291  
292  private function setMediaPrefix() {
293   global $CONF;
294   $this->mediaprefix = (string)$CONF['MediaPrefix'];
295   return;
296  }
297  
298  private function setMediaURL() {
299   global $CONF;
300   $this->mediaurl = (string)$CONF['MediaURL'];
301   return;
302  }
303  
304  private function setMaxUploadSize() {
305   global $CONF;
306   $this->maxuploadsize = (int)$CONF['MaxUploadSize'];
307   return;
308  }
309  
310  private function setDIR_MEDIA() {
311   global $DIR_MEDIA;
312   $this->dirmedia = (string)$DIR_MEDIA;
313   return;
314  }
315  
316  private function setOptions(&$PluginObject) {
317   if($PluginObject->getOption('IM_PRIVATE') == 'no')
318    $this->private = (int)0;
319   
320   if($PluginObject->getOption('IM_GREYBOX') == 'yes')
321    $this->greybox = (int)1;
322   
323   $this->itemdisplay =& $PluginObject->getOption('IM_ITEMDISPLAY');
324   
325   if($PluginObject->getOption('IM_EACHBLOGDIR') == 'yes')
326    $this->eachblogdir = (int)1;
327   
328   return;
329  }
330  
331  public function getAccessURL() {
332   return $this->accessurl;
333  }
334  
335  public function getPluginDir() {
336   return $this->plugindir;
337  }
338  
339  public function & getBlog() {
340   return $this->blog;
341  }
342  
343  public function & getBlogid() {
344   return $this->blogid; 
345  }
346  
347  public function & getBlogName() {
348   $blog =& $this->blog;
349   if(!$blog)
350    return '';
351   else
352    return $blog->getName();
353  }
354  
355  public function & getBlogShortName() {
356   $blog =& $this->blog;
357   if(!$blog)
358    return '';
359   else
360    return $blog->getShortName();
361  }
362  
363   public function getPrivate() {
364   return $this->private;
365  }
366  
367  public function getGreybox() {
368   return $this->greybox;
369  }
370  
371  public function getEachblogdir() {
372   return $this->eachblogdir;
373  }
374  
375  public function getItemdisplay() {
376   return $this->itemdisplay;
377  }
378  
379  public function getAllowedtypes() {
380   return $this->allowedtypes;
381  }
382  
383  public function getMediaprefix() {
384   return $this->mediaprefix;
385  }
386  
387  public function getMaxuploadsize() {
388   return $this->maxuploadsize;
389  }
390  
391  public function getMediaURL() {
392   return $this->mediaurl;
393  }
394  
395  public function getDirMedia() {
396   return $this->dirmedia;
397  }
398  
399  public function getMode() {
400   return $this->mode;
401  }
402  
403  public function getAlttext() {
404   return $this->alttext;
405  }
406  
407  public function getAstool() {
408   return $this->astool;
409  }
410  
411  public function getCollection() {
412   return $this->collection;
413  }
414  
415  public function getSubdir() {
416   return $this->subdir;
417  }
418  
419  public function & getFilename() {
420   return $this->filename;
421  }
422  
423  public function getNewfilename() {
424   return $this->newfilename;
425  }
426  
427  public function & getOffset() {
428   return $this->offset;
429  }
430  
431  public function getWay() {
432   return $this->way;
433  }
434  
435  public function getFilter() {
436   return $this->filter;
437  }
438  
439  public function resetOffset() {
440   $this->offset = 0;
441  }
442  
443  public function resetFilter() {
444   $this->filter = '';
445  }
446 }
447 ?>