OSDN Git Service

Merge branch 'skinnable-master'
[nucleus-jp/nucleus-next.git] / nucleus / plugins / medium / MediumActions.php
1 <?php
2 /*
3  * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
4  * Copyright (C) 2002-2009 The Nucleus Group
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  * (see nucleus/documentation/index.html#license for more info)
11  */
12 /**
13  * Media popup window for Nucleus
14  *
15  * Purpose:
16  *   - can be openen from an add-item form or bookmarklet popup
17  *   - shows a list of recent files, allowing browsing, search and
18  *     upload of new files
19  *   - close the popup by selecting a file in the list. The file gets
20  *     passed through to the add-item form (linkto, popupimg or inline img)
21  *
22  * @license http://nucleuscms.org/license.txt GNU General Public License
23  * @copyright Copyright (C) 2002-2009 The Nucleus Group
24  * @version $Id: MediumActions.php 1873 2012-06-17 07:23:22Z sakamocchi $
25  *
26  */
27
28 class MediumActions extends BaseActions
29 {
30         private $type = '';
31         
32         static private $default_actions = array(
33                 'actionurl',
34                 'adminurl',
35                 'collection',
36                 'conf',
37                 'pagehead',
38                 'pagefoot',
39                 'collectionlist',
40                 'stylesheet',
41                 'script'
42                 );
43         
44         static public $normal_skin_types = array(
45                 'login'         => 'NP_Medium',
46                 'choose'        => _UPLOAD_TITLE,
47                 'select'        => _SKIN_PART_ALIST,
48                 'error'         => _ERROR
49         );
50         
51         static public function getNormalSkinTypes()
52         {
53                 return self::$normal_skin_types;
54         }
55         
56         public function getAvailableActions()
57         {
58                 global $manager;
59                 
60                 $extra_actions = array();
61                 
62                 switch ( $manager->getPlugin('NP_Medium')->type )
63                 {
64                         case 'login':
65                                 $extra_actions = array(
66                                         'name',
67                                 );
68                                 break;
69                         case 'select':
70                                 $extra_actions = array(
71                                         'amount',
72                                         'filter',
73                                         'medialist',
74                                         'next',
75                                         'prev'
76                                 );
77                                 break;
78                         case 'choose':
79                                 $extra_actions = array(
80                                         'pluginextras',
81                                         'ticket',
82                                 );
83                                 break;
84                         case 'error':
85                                 $extra_actions = array(
86                                         'message',
87                                 );
88                                 break;
89                 }
90                 
91                 $defined_actions = array_merge(self::$default_actions, $extra_actions);
92                 
93                 return array_merge($defined_actions, parent::getAvailableActions());
94         }
95         
96         /**
97          * MediumActions::_construct
98          * 
99          * @param       string  $type   always 'fileparse'
100          * @return      void
101          */
102         public function __construct($type)
103         {
104                 parent::__construct();
105                 return;
106         }
107         
108         public function parse_conf($key)
109         {
110                 global $CONF;
111                 if ( array_key_exists($key, $CONF) )
112                 {
113                         echo $CONF[$key];
114                 }
115                 return;
116         }
117         
118         public function parse_actionurl()
119         {
120                 global $CONF;
121                 echo "{$CONF['ActionURL']}?action=plugin&amp;name=medium";
122                 return;
123         }
124         
125         public function parse_collection()
126         {
127                 global $manager;
128                 echo (string) $manager->getPlugin('NP_Medium')->collection;
129                 return;
130         }
131         
132         public function parse_pagehead()
133         {
134                 global $manager;
135                 $path = $manager->getPlugin('NP_Medium')->getDirectory() . 'skins/pagehead.skn';
136                 $contents = $this->parser->skin->getContentFromFile($path);
137                 $this->parser->parse($contents);
138                 return;
139         }
140         
141         public function parse_pagefoot()
142         {
143                 global $manager;
144                 $path = $manager->getPlugin('NP_Medium')->getDirectory() . 'skins/pagefoot.skn';
145                 $contents = $this->parser->skin->getContentFromFile($path);
146                 $this->parser->parse($contents);
147                 return;
148         }
149         
150         public function parse_stylesheet($name)
151         {
152                 global $CONF;
153                 echo "{$CONF['PluginURL']}medium/styles/{$name}";
154                 return;
155         }
156         
157         public function parse_script($name)
158         {
159                 global $CONF;
160                 echo "{$CONF['PluginURL']}medium/scripts/{$name}";
161                 return;
162         }
163         
164         public function parse_name()
165         {
166                 global $member;
167                 
168                 if ( !$member->isLoggedIn() )
169                 {
170                         echo (string) requestVar('login');
171                 }
172                 else
173                 {
174                         echo (string) $member->getDisplayName();
175                 }
176                 return;
177         }
178         
179         public function parse_filter()
180         {
181                 global $manager;
182                 echo (string) $manager->getPlugin('NP_Medium')->filter;
183                 return;
184         }
185         
186         public function parse_ticket()
187         {
188                 global $manager;
189                 echo $manager->addTicketHidden();
190                 return;
191         }
192         
193         public function parse_message()
194         {
195                 global $manager;
196                 echo (string) $manager->getPlugin('NP_Medium')->message;
197                 return;
198         }
199         
200         public function parse_pluginextras()
201         {
202                 global $manager;
203                 $data = array();
204                 $manager->notify("MediaUploadFormExtras", $data);
205                 return;
206         }
207         
208         public function parse_amount()
209         {
210                 global $manager;
211                 echo (string) $manager->getPlugin('NP_Medium')->amount;
212                 return;
213         }
214         
215         public function parseoffset()
216         {
217                 global $manager;
218                 echo (string) $manager->getPlugin('NP_Medium')->offset;
219                 return;
220         }
221         
222         public function parse_prev()
223         {
224                 global $manager;
225                 echo (string) $manager->getPlugin('NP_Medium')->prev;
226                 return;
227         }
228         
229         public function parse_next()
230         {
231                 global $manager;
232                 echo (string) $manager->getPlugin('NP_Medium')->next;
233                 return;
234         }
235         
236         public function parse_collectionlist()
237         {
238                 global $CONF, $manager;
239                 
240                 $plugin = $manager->getPlugin('NP_Medium');
241                 
242                 $data = array(
243                         'actionurl'     => "{$CONF['ActionURL']}?action=plugin&amp;type=medium"
244                 );
245                 $this->parser->parse(Template::fill($plugin->getOption('collectionlist_head'), $data));
246                 
247                 $collections = Media::getCollectionList();
248                 foreach ( $collections as $name => $desc )
249                 {
250                         $data = array(
251                                 'name'  => $name,
252                                 'desc'  => $desc
253                         );
254                         
255                         if ( $plugin->collection ==  $name )
256                         {
257                                 $data['selected'] = 'selected="selected"';
258                         }
259                         
260                         $this->parser->parse(Template::fill($plugin->getOption('collectionlist_body'), $data));
261                 }
262                 
263                 $data = array(
264                         'actionurl'             => "{$CONF['ActionURL']}?action=plugin&amptype=medium",
265                         'collection'    => $plugin->collection
266                 );
267                 $this->parser->parse(Template::fill($plugin->getOption('collectionlist_foot'), $data));
268         }
269         
270         public function parse_medialist()
271         {
272                 global $CONF, $manager;
273                 
274                 $plugin = $manager->getPlugin('NP_Medium');
275                 
276                 $data = array(
277                         'actionurl'             => "{$CONF['ActionURL']}?action=plugin&amp;type=medium",
278                         'collection'    => $plugin->collection,
279                         'description'   => $plugin->description
280                 );
281                 $this->parser->parse(Template::fill($plugin->getOption('medialist_head'), $data));
282                 
283                 $image_template = $plugin->getOption('medialist_body_image');
284                 $other_template = $plugin->getOption('medialist_body_other');
285                 
286                 foreach ( $plugin->media as $medium )
287                 {
288                         $medium->refine();
289                         $data = array(
290                                 'mime'                  => $medium->mime,
291                                 'collection'    => $medium->collection,
292                                 'filename'              => $medium->filename,
293                                 'shortfilename' => Entity::shorten($medium->filename, 24, '...'),
294                                 'prefix'                => $medium->prefix,
295                                 'name'                  => $medium->name,
296                                 'suffix'                => $medium->suffix,
297                                 'timestamp'             => date("Y-m-d", $medium->timestamp),
298                                 'size'                  => round($medium->size / 1000),
299                                 'width'                 => $medium->width,
300                                 'height'                => $medium->height,
301                                 'mediumurl'             => "{$CONF['MediaURL']}{$medium->collection}/{$medium->filename}"
302                         );
303                         
304                         if ( !array_key_exists($medium->mime, Media::$image_mime) )
305                         {
306                                 $this->parser->parse(Template::fill($other_template, $data));
307                         }
308                         else
309                         {
310                                 $this->parser->parse(Template::fill($image_template, $data));
311                         }
312                 }
313                 
314                 $data = array();
315                 $this->parser->parse(Template::fill($plugin->getOption('medialist_foot'), $data));
316                 
317                 return;
318         }
319         
320         protected function checkCondition($field, $name='', $value = '')
321         {
322                 global $manager;
323                 
324                 $plugin = $manager->getPlugin('NP_Medium');
325                 
326                 $condition = 0;
327                 switch ( $field )
328                 {
329                         case 'prev':
330                                 $condition = (boolean) ($plugin->prev != $plugin->offset );
331                                 break;
332                         case 'next':
333                                 $condition = (boolean) $plugin->next;
334                                 break;
335                         default:
336                                 break;
337                 }
338                 return $condition;
339         }
340 }