3 * ImprovedMedia plugin for Nucleus CMS
4 * Version 3.0.1 for PHP5
5 * Written By Mocchi, Feb.28, 2010
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.
13 class MEDIA_VARIABLES {
14 private $accessurl = 'media.php'; //string
16 private $plugindir = ''; //string
17 private $private = 1; //boolean
18 private $greybox = 0; //boolean
19 private $itemdisplay = 10; //integer
20 private $eachblogdir = 0; //boolean
22 private $allowedtypes = array(); //array
23 private $mediaprefix = 0; //boolean
24 private $maxuploadsize = 0; //integer
26 private $mediaurl = ''; //string
27 private $dirmedia = ''; //string
29 private $blog = FALSE; //object
30 private $blogid = 1; //object
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
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');
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');
54 public function __construct(&$PluginObject) {
56 $this->blog =& $PluginObject->getBlog();
57 $this->blogid =& $PluginObject->getBlogid();
58 $this->accessurl = $CONF['ActionURL'] . '?action=plugin&name=ImprovedMedia';
59 $this->plugindir = $CONF['AdminURL'] . $PluginObject->getBaseURL();
60 self::setOptions($PluginObject);
62 self::setAllowedTypes();
63 self::setMediaPrefix();
64 self::setMaxUploadSize();
72 public function __destruct() {return;}
74 protected function setMode() {
75 $mode = htmlspecialchars(requestVar('mode'), ENT_QUOTES, _CHARSET);
76 if(in_array($mode, self::$modes))
77 $this->mode = (string)$mode;
81 protected function setAlttext() {
82 $alttext = htmlspecialchars(requestVar('alttext'), ENT_QUOTES, _CHARSET);
84 $this->alttext = (string)$alttext;
88 protected function setAstool() {
89 $astool = intRequestVar('astool');
91 $this->astool = (int)1;
95 public function getCollections() {
96 $collections = array();
97 $collections = MEDIA::getCollectionList();
100 if(count($collections) < 2)
101 return (string)'error';
103 array_shift($collections);
105 ksort($collections, SORT_STRING);
106 return (array)$collections;
109 protected function setCollection() {
111 $collection = htmlspecialchars(requestVar('collection'), ENT_QUOTES, _CHARSET);
112 $collections = $this->getCollections();
114 if($collections == 'error') {
115 $this->collection = (string)'error';
119 if(!$this->private) {
120 if($collection == '') {
121 $keys = array_keys($collections);
122 $this->collection = (string)$collections[$keys[0]];
125 if(!array_key_exists($collection, $collections)) {
126 $this->collection = (string)'error';
129 $this->collection = (string)$collection;
132 if($collection == '') {
133 $this->collection = (string)$member->getID();
136 if(!array_key_exists($collection, $collections)) {
137 $this->collection = (string)'error';
140 $this->collection = (string)$collection;
145 public function getSubdirs() {
150 if($this->collection == 'error') {
151 return (string)'error';
154 if(!is_dir($this->dirmedia . $this->collection)) {
155 $subdirs[] = array('subdirname' => '.', 'number' => 0, 'collection' => $this->collection);
159 $dirhandle = @opendir($this->dirmedia . $this->collection);
161 if(!$dirhandle) return (string)'error';
163 while(($subdirname = readdir($dirhandle)) !== FALSE) {
164 if(is_dir($this->dirmedia . $this->collection . '/' . $subdirname) && $subdirname != "..") {
166 if($subdirhandle = @opendir($this->dirmedia . $this->collection . '/' . $subdirname)) {
168 return (string)'error';
170 while(($file = readdir($subdirhandle)) !== FALSE)
171 if($file != '..' && $file != '.' && !is_dir($this->dirmedia . $this->collection . '/' . $subdirname . '/' . $file))
173 closedir($subdirhandle);
175 $temp[$subdirname] = array('number' => $number, 'collection' => $this->collection);
178 closedir($dirhandle);
180 foreach($temp as $subdirname => $options) {
181 $subdirs[] = array('subdirname' => $subdirname, 'number' => $options['number'], 'collection' => $options['collection']);
183 return (array)$subdirs;
186 protected function setSubDir() {
187 $subdir = htmlspecialchars(requestVar('subdir'), ENT_QUOTES, _CHARSET);
188 $subdirs = self::getSubdirs();
192 $this->subdir = (string)'';
195 if($subdirs == 'error') {
196 $this->subdir = (string)'error';
200 if(count($subdirs) < 2) {
201 $this->subdir = (string)'';
205 array_shift($subdirs);
207 foreach($subdirs as $key => $options) {
208 if((string)$options['subdirname'] == (string)$subdir) {
209 $this->subdir = (string)$subdir;
215 protected function setFilename() {
216 $filename = htmlspecialchars(requestVar('filename'), ENT_QUOTES, _CHARSET);
218 if($filename == '') {
219 $this->filename = (string)'';
223 if($this->collection === 'error') {
224 $this->filename = (string)'error';
228 if($this->subdir === 'error') {
229 $this->filename = (string)'error';
234 $fileobjectlist = MEDIA::getMediaListByCollection($this->collection);
236 $fileobjectlist = MEDIA::getMediaListByCollection($this->collection . '/' . $this->subdir);
238 foreach($fileobjectlist as $fileobject) {
239 if((string)$fileobject->filename == (string)$filename) {
240 $this->filename = $fileobject->filename;
247 protected function setNewFilename() {
248 $newfilename = htmlspecialchars(requestVar('newfilename'), ENT_QUOTES, _CHARSET);
250 $this->newfilename = (string)$newfilename;
254 protected function setOffset() {
255 $offset = intRequestVar('offset');
257 $this->offset = (int)$offset;
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;
269 protected function setFilter() {
270 $filter = htmlspecialchars(requestVar('filter'), ENT_QUOTES, _CHARSET);
271 if($this->allowedtypes === array()) {
272 $this->filter = (string)'';
275 if(in_array($filter, $this->allowedtypes))
276 $this->filter = (string)$filter;
280 private function setAllowedTypes() {
282 if($CONF['AllowedTypes'] == '')
284 $allowedtypes = explode(',', $CONF['AllowedTypes']);
285 if(is_array($allowedtypes)) {
287 $this->allowedtypes = (array)$allowedtypes;
292 private function setMediaPrefix() {
294 $this->mediaprefix = (string)$CONF['MediaPrefix'];
298 private function setMediaURL() {
300 $this->mediaurl = (string)$CONF['MediaURL'];
304 private function setMaxUploadSize() {
306 $this->maxuploadsize = (int)$CONF['MaxUploadSize'];
310 private function setDIR_MEDIA() {
312 $this->dirmedia = (string)$DIR_MEDIA;
316 private function setOptions(&$PluginObject) {
317 if($PluginObject->getOption('IM_PRIVATE') == 'no')
318 $this->private = (int)0;
320 if($PluginObject->getOption('IM_GREYBOX') == 'yes')
321 $this->greybox = (int)1;
323 $this->itemdisplay =& $PluginObject->getOption('IM_ITEMDISPLAY');
325 if($PluginObject->getOption('IM_EACHBLOGDIR') == 'yes')
326 $this->eachblogdir = (int)1;
331 public function getAccessURL() {
332 return $this->accessurl;
335 public function getPluginDir() {
336 return $this->plugindir;
339 public function & getBlog() {
343 public function & getBlogid() {
344 return $this->blogid;
347 public function & getBlogName() {
348 $blog =& $this->blog;
352 return $blog->getName();
355 public function & getBlogShortName() {
356 $blog =& $this->blog;
360 return $blog->getShortName();
363 public function getPrivate() {
364 return $this->private;
367 public function getGreybox() {
368 return $this->greybox;
371 public function getEachblogdir() {
372 return $this->eachblogdir;
375 public function getItemdisplay() {
376 return $this->itemdisplay;
379 public function getAllowedtypes() {
380 return $this->allowedtypes;
383 public function getMediaprefix() {
384 return $this->mediaprefix;
387 public function getMaxuploadsize() {
388 return $this->maxuploadsize;
391 public function getMediaURL() {
392 return $this->mediaurl;
395 public function getDirMedia() {
396 return $this->dirmedia;
399 public function getMode() {
403 public function getAlttext() {
404 return $this->alttext;
407 public function getAstool() {
408 return $this->astool;
411 public function getCollection() {
412 return $this->collection;
415 public function getSubdir() {
416 return $this->subdir;
419 public function & getFilename() {
420 return $this->filename;
423 public function getNewfilename() {
424 return $this->newfilename;
427 public function & getOffset() {
428 return $this->offset;
431 public function getWay() {
435 public function getFilter() {
436 return $this->filter;
439 public function resetOffset() {
443 public function resetFilter() {