OSDN Git Service

FIX: NP_ImageLimitSizeをNucleus 3.65/PHP5.4/MySQL5.5で動作するよう修正
[nucleus-jp/nucleus-plugins.git] / NP_Thumbnail / NP_Thumbnail.php
1 <?php
2 /**
3  * Thumbnail plugin for Nucleus CMS
4  * Version 4.0.0 for PHP5
5  * Written By Mocchi, Apr. 06, 2011
6  * Original code was written by jirochou, May 23, 2004 and maintained by nakahara21
7  * This plugin depends on NP_MediaUtils
8  * 
9  * This program is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License
11  * as published by the Free Software Foundation; either version 3
12  * of the License, or (at your option) any later version.
13  */
14
15 class NP_Thumbnail extends NucleusPlugin
16 {
17         private static $thumbdir        = '.thumb';
18         private static $max_sync        = 10;
19         private static $authorid        = 0;
20         private static $buffering       = FALSE;
21         private static $table_name      = 'plugin_thumbnail'; // not implemented yet
22         
23         public function getName()                       { return 'Thumbnail'; }
24         public function getAuthor()             { return 'Mocchi, nakahara21, jirochou'; }
25         public function getURL()                        { return 'http://japan.nucleuscms.org/wiki/plugins:thumbnail'; }
26         public function getVersion()            { return '4.0.0'; }
27         public function getDescription()        { return _NP_THUMBNAIL_01; }
28         public function getPluginDep()  { return array('NP_MediaUtils'); }
29         public function getMinNucleusVersion()  { return 340; }
30         public function supportsFeature($feature) { return in_array ($feature, array('SqlTablePrefix', 'SqlApi'));}
31         public function getEventList()  { return array('QuickMenu', 'PrePluginOptionsEdit', 'PostAuthentication', 'PreItem', 'PostMediaUpload'); }
32         
33         public function install ()
34         {
35                 $this->createOption('maxwidth', '_NP_THUMBNAIL_02', 'text', '100', 'datatype=numerical');
36                 $this->createOption('maxheight', '_NP_THUMBNAIL_03', 'text', '100', 'datatype=numerical');
37                 $this->createOption('save_thumb', '_NP_THUMBNAIL_04', 'select', 'filesystem', '_NP_THUMBNAIL_05|no|_NP_THUMBNAIL_06|filesystem');
38                 $this->createBlogOption('force_thumb', '_NP_THUMBNAIL_07', 'yesno', 'yes');
39                 $this->createBlogOption('thumb_template', '_NP_THUMBNAIL_08', 'textarea', '<a href="<%rawpopuplink%>" title="<%popuptext%>" onclick="<%popupcode%>"><img src="<%thumb_url%>" width="<%thumb_width%>" height="<%thumb_height%>" alt="<%popuptext%>" /></a>');
40                 return;
41         }
42         
43         /*
44          * plugin options are purged automatically when uninstalled.
45          */
46         public function uninstall()
47         {
48                 global $DIR_MEDIA;
49                 MediaUtils::purgeDir($DIR_MEDIA . self::$thumbdir);
50                 return;
51         }
52         
53         public function init()
54         {
55                 global $manager;
56                 
57                 $locale = '';
58                 
59                 if ( !class_exists('Medium', FALSE) )
60                 {
61                         $manager->getPlugin('NP_Thumbnail');
62                 }
63                 
64                 
65                 /* new API */
66                 if ( class_exists('i18n', FALSE) )
67                 {
68                         $locale = i18n::get_current_locale() . '.' . i18n::get_current_charset() . '.php';
69                 }
70                 /* old API */
71                 else
72                 {
73                         $language = preg_replace('#[/|\\\\]#', '', getLanguageName());
74                         if ( $language == 'japanese-euc' )
75                         {
76                                 $locale = 'ja_Jpan_JP.EUC-JP.php';
77                         }
78                         else if ( $language = 'japanese-utf8' )
79                         {
80                                 $locale = 'ja_Jpan_JP.UTF-8.php';
81                         }
82                 }
83                 
84                 if ( !$locale || !file_exists($this->getDirectory() . $locale) )
85                 {
86                         include($this->getDirectory() . 'en_Latn_US.ISO-8859-1.php');
87                 }
88                 else
89                 {
90                         include($this->getDirectory() . $locale);
91                 }
92                 
93                 return;
94         }
95         
96         /*
97          * for translation
98          */
99         public function event_PrePluginOptionsEdit($data)
100         {
101                 /* Old version do not support natively */
102                 if ( getNucleusVersion() < 400  )
103                 {
104                         if ( $data['context'] != 'global' )
105                         {
106                                 foreach ( $data['options'] as $key => $option )
107                                 {
108                                         if ( $option['pid'] == $this->getID() )
109                                         {
110                                                 if ( defined($option['description']) )
111                                                 {
112                                                         $data['options'][$key]['description'] = constant($option['description']);
113                                                 }
114                                                 if ( $option['type'] == 'select' )
115                                                 {
116                                                         foreach ( explode('|', $option['typeinfo']) as $option )
117                                                         {
118                                                                 if ( defined($option) )
119                                                                 {
120                                                                         $data['options'][$key]['typeinfo'] = str_replace($option, constant($option), $data['options'][$key]['typeinfo']);
121                                                                 }
122                                                         }
123                                                 }
124                                         }
125                                 }
126                         }
127                         else if ($data['plugid'] == $this->getID() )
128                         {
129                                 foreach ( $data['options'] as $key => $option )
130                                 {
131                                         if ( defined($option['description']) )
132                                         {
133                                                 $data['options'][$key]['description'] = constant($option['description']);
134                                         }
135                                         if ( $option['type'] == 'select' )
136                                         {
137                                                         foreach ( explode('|', $option['typeinfo']) as $option )
138                                                         {
139                                                                 if ( defined($option) )
140                                                                 {
141                                                                         $data['options'][$key]['typeinfo'] = str_replace($option, constant($option), $data['options'][$key]['typeinfo']);
142                                                                 }
143                                                         }
144                                         }
145                                 }
146                         }
147                 }
148                 
149                 return;
150         }
151         
152         /*
153          * for translation
154          */
155         static private function t($text, $array=array())
156         {
157                 if ( is_array($array) )
158                 {
159                         $search = array();
160                         $replace = array();
161                         
162                         foreach ( $array as $key => $value )
163                         {
164                                 if ( is_array($value) )
165                                 {
166                                         continue;
167                                 }
168                                 $search[] = '<%'.preg_replace('/[^a-zA-Z0-9_]+/','',$key).'%>';
169                                 $replace[] = $value;
170                         }
171                 }
172                 return htmlspecialchars(str_replace($search, $replace, $text), ENT_QUOTES, _CHARSET);
173         }
174         
175         public function event_QuickMenu(&$data)
176         {
177                 global $CONF;
178                 
179                 if ( $this->getOption('save_thumb') !== 'no' )
180                 {
181                         $option = array (
182                                 'title'         => 'NP_Thumbnail',
183                                 'url'           => "{$CONF['ActionURL']}?action=plugin&name={$this->getname()}&type=admin",
184                                 'tooltip'       => _NP_THUMBNAIL_09);
185                         array_push($data['options'], $option);
186                 }
187                 return;
188         }
189         
190         public function event_PostAuthentication(&$data)
191         {
192                 if ( array_key_exists('action', $_REQUEST)
193                  && array_key_exists('name', $_REQUEST)
194                  && array_key_exists('type', $_REQUEST)
195                  && array_key_exists('width', $_REQUEST)
196                  && array_key_exists('height', $_REQUEST)
197                  && $_REQUEST['action'] === 'plugin'
198                  && $_REQUEST['name'] === $this->getName()
199                  && $_REQUEST['type'] !== '' )
200                 {
201                         self::$buffering = ob_start;
202                 }
203                 return;
204         }
205         
206         public function doAction($type)
207         {
208                 global $DIR_MEDIA, $member;
209                 
210                 $type = (string) $type;
211                 
212                 $path = '';
213                 $maxwidth = '';
214                 $maxheight = '';
215                 
216                 if ( array_key_exists('path', $_GET) )
217                 {
218                         $path = (string)  $_GET['path'];
219                 }
220                 if ( array_key_exists('width', $_GET) )
221                 {
222                         $maxwidth = (integer) $_GET['width'];
223                 }
224                 if ( array_key_exists('height', $_GET) )
225                 {
226                         $maxheight = (integer) $_GET['height'];
227                 }
228                 
229                 if ( self::$buffering )
230                 {
231                         ob_end_clean();
232                 }
233                 
234                 if ( in_array($type, array('admin', 'clear', 'sync')) && $member->isAdmin() )
235                 {
236                         $this->showAdmin($type);
237                         exit;
238                 }
239                 
240                 if ( $maxwidth <= 0 || $maxwidth > 1000 || $maxheight <= 0 || $maxheight > 1000 )
241                 {
242                         MediaUtils::error($this->t(_NP_THUMBNAIL_10, array($maxwidth, $maxheight)));
243                         return;
244                 }
245                 
246                 if ( FALSE === ($medium = new Medium($DIR_MEDIA, $path, MediaUtils::$prefix)) )
247                 {
248                         MediaUtils::error($this->t(_NP_THUMBNAIL_11, array($path)));
249                         return;
250                 }
251                 
252                 if ( FALSE === $medium->setResampledSize($maxwidth, $maxheight) )
253                 {
254                         MediaUtils::error($this->t(_NP_THUMBNAIL_10, array($maxwidth, $maxheight)));
255                         return;
256                 }
257                 
258                 MediaUtils::responseResampledImage($medium);
259                 return;
260         }
261         
262         public function doSkinVar($skinType)
263         {
264                 $path = '';
265                 $maxwidth = 0;
266                 $maxheight = 0;
267                 $alt = '';
268                 
269                 /* retrieve arguments. This is for preventing E_STRICT */
270                 $args = func_get_args();
271                 if ( array_key_exists(0, $args) )
272                 {
273                         $path = (string)  $args[0];
274                 }
275                 if ( array_key_exists(1, $args) )
276                 {
277                         $maxwidth = (integer) $args[1];
278                 }
279                 if ( array_key_exists(2, $args) )
280                 {
281                         $maxheight = (integer) $args[2];
282                 }
283                 if ( array_key_exists(3, $args) )
284                 {
285                         $alt = (string) $args[3];
286                 }
287                 
288                 if ( $this->getBlogOption(MediaUtils::$blogid, 'force_thumb') == 'yes' )
289                 {
290                         echo $this->getParsedTag(array('', '', $path, 0, 0, $alt), $maxwidth, $maxheight);
291                 }
292                 
293                 return;
294         }
295         
296         public function event_PreItem(&$data)
297         {
298                 $item =& $data["item"];
299                 self::$authorid = $item->authorid;
300                 $item->body = preg_replace_callback("#<\%(Thumbnail)\((.*?)\|(.*?)\|(.*?)\|(.*?)\)%\>#", array(&$this, 'getParsedTag'), $item->body);
301                 $item->more = preg_replace_callback("#<\%(Thumbnail)\((.*?)\|(.*?)\|(.*?)\|(.*?)\)%\>#", array(&$this, 'getParsedTag'), $item->more);
302                 
303                 if ( $this->getBlogOption(MediaUtils::$blogid, 'force_thumb') == 'yes' )
304                 {
305                         $item->body = preg_replace_callback("#<\%(popup)\((.*?)\|(.*?)\|(.*?)\|(.*?)\)%\>#", array(&$this, 'getParsedTag'), $item->body);
306                         $item->more = preg_replace_callback("#<\%(popup)\((.*?)\|(.*?)\|(.*?)\|(.*?)\)%\>#", array(&$this, 'getParsedTag'), $item->more);
307                 }
308                 return;
309         }
310         
311         public function event_PostMediaUpload(&$data)
312         {
313                 global $DIR_MEDIA;
314                 
315                 if ( $this->getOption('save_thumb') == 'no' )
316                 {
317                         return;
318                 }
319                 
320                 $root = rtrim($DIR_MEDIA, '/');
321                 $path = trim($data['collection'], '/');
322                 $filename = trim($data['filename'], '/');
323                 $maxwidth  = $this->getOption('maxwidth');
324                 $maxheight = $this->getOption('maxheight');
325                 
326                 if ( !MediaUtils::checkDir ($root . '/' . self::$thumbdir) )
327                 {
328                         return;
329                 }
330                 
331                 if ( FALSE === ($medium = new Medium($root, "{$path}/{$filename}", MediaUtils::$prefix)) )
332                 {
333                         return;
334                 }
335                 
336                 if ( !array_key_exists($medium->mime, MediaUtils::$image_mime) )
337                 {
338                         return;
339                 }
340                 
341                 if ( FALSE === $medium->setResampledSize($maxwidth, $maxheight) )
342                 {
343                         return;
344                 }
345                 
346                 $target = self::getThumbPath($medium);
347                 
348                 if ( $this->getOption('save_thumb') == 'filesystem' )
349                 {
350                         if ( !file_exists("{$root}/{$target}")
351                            && !MediaUtils::storeResampledImage ($DIR_MEDIA, $target, $medium) )
352                         {
353                                 return;
354                         }
355                 }
356                 
357                 return;
358         }
359         
360         public function getParsedTag($match, $maxwidth=0, $maxheight=0)
361         {
362                 global $DIR_MEDIA, $member;
363                 
364                 list($code, $tag, $path, $width, $height, $alt) = $match;
365                 
366                 if ( !preg_match("#^.+?/.+$#", $path) && self::$authorid )
367                 {
368                         $path = self::$authorid . '/' . $path;
369                 }
370                 
371                 if ( FALSE === ($medium = new Medium($DIR_MEDIA, $path, MediaUtils::$prefix)) )
372                 {
373                         return $this->t('NP_Thumbnail: 指定したメディアファイルを読み込めませんでした。', array($path));
374                 }
375                 
376                 if ( !array_key_exists($medium->mime, MediaUtils::$image_mime) )
377                 {
378                         return $this->t(_NP_THUMBNAIL_12, array($path));
379                 }
380                 
381                 if ( $tag == 'Thumbnail' )
382                 {
383                         $maxwidth  = (integer) $width;
384                         $maxheight = (integer) $height;
385                 }
386                 
387                 if ( ($maxwidth == 0) && ($maxheight == 0) )
388                 {
389                         $maxwidth  = (integer) $this->getOption('maxwidth');
390                         $maxheight = (integer) $this->getOption('maxheight');
391                 }
392                 
393                 if ( $maxwidth < 0 || $maxwidth > 1000 || $maxheight < 0 || $maxheight > 1000 )
394                 {
395                         return $this->t(_NP_THUMBNAIL_10, array($path));
396                 }
397                 
398                 if ( FALSE === $medium->setResampledSize($maxwidth, $maxheight) )
399                 {
400                         return $this->t('NP_Thumbnail: サムネイルのサイズが不正です。', array($path));
401                 }
402                 
403                 if ( !$alt )
404                 {
405                         $alt =& $path;
406                 }
407                 
408                 return $this->generateTag($this->getBlogOption(MediaUtils::$blogid, 'thumb_template'), $medium, $alt);
409         }
410         
411         public function generateTag($template, $medium, $alt)
412         {
413                 global $DIR_LIBS;
414                 
415                 if ( !class_exists('BODYACTIONS', FALSE) )
416                 {
417                         include($DIR_LIBS . 'BODYACTIONS.php');
418                 }
419                 $action = new BODYACTIONS;
420                 
421                 if ( array_key_exists($medium->mime, MediaUtils::$image_mime)
422                  && $this->getOption('save_thumb') == 'filesystem' )
423                  {
424                         if ( !MediaUtils::checkDir ($medium->root . '/' . self::$thumbdir) )
425                         {
426                                 return $this->t(_NP_THUMBNAIL_13, array(self::$thumbdir));
427                         }
428                         if ( !file_exists($medium->root . '/' . self::getThumbPath($medium)) )
429                         {
430                                 MediaUtils::storeResampledImage ($medium->root, self::getThumbPath($medium), $medium);
431                         }
432                 }
433                 
434                 ob_start();
435                 if ( array_key_exists($medium->mime, MediaUtils::$image_mime) && $this->getThumbURL($medium) )
436                 {
437                         $action->template['POPUP_CODE'] = $template;
438                         $replacements = array(
439                                 '<%thumb_width%>'       => $medium->resampledwidth,
440                                 '<%thumb_height%>'      => $medium->resampledheight,
441                                 '<%thumb_url%>'         => $this->getThumbURL($medium)
442                         );
443                         foreach ( $replacements as $target => $replacement )
444                         {
445                                 $action->template['POPUP_CODE'] = str_replace ($target, $replacement, $action->template['POPUP_CODE']);
446                         }
447                         $action->createPopupCode("{$medium->path}/{$medium->name}", $medium->width, $medium->height, $alt);
448                 }
449                 else
450                 {
451                         $action->template['MEDIA_CODE'] = $template;
452                         $action->createMediaCode("{$medium->path}/{$medium->name}", $alt);
453                 }
454                 $tag = ob_get_contents();
455                 ob_get_clean();
456                 
457                 return preg_replace('#href="(.*?)imagetext(.*?)"#', 'href="$1imagetext$2&amp;blogid='.MediaUtils::$blogid . '"', $tag);
458         }
459         
460         private function showAdmin($type)
461         {
462                 global $CONF, $DIR_LIBS, $DIR_MEDIA, $manager;
463                 
464                 $type = (string) $type;
465                 
466                 if ( !class_exists ('PLUGINADMIN', FALSE) )
467                 {
468                         include ($DIR_LIBS . 'PLUGINADMIN.php');
469                 }
470                 
471                 $oPluginAdmin = new PluginAdmin('Thumbnail');
472                 $oPluginAdmin->start();
473                 
474                 echo "<h2>NP_Thumbnail</h2>\n";
475                 
476                 if ( $this->getOption('save_thumb') === 'no' )
477                 {
478                         echo '<p>' . $this->t(_NP_THUMBNAIL_14) . "</p>\n";
479                         $oPluginAdmin->end();
480                         return;
481                 }
482                 
483                 $logs = array ();
484                 if ( $type == 'clear' )
485                 {
486                         if ( $this->getOption('save_thumb') == 'filesystem' )
487                         {
488                                 $logs = MediaUtils::purgeDir($DIR_MEDIA, self::$thumbdir . '/');
489                         }
490                 }
491                 
492                 echo "<p>" . $this->t(_NP_THUMBNAIL_15, array(self::$thumbdir)) . "<br />\n";
493                 echo $this->t(_NP_THUMBNAIL_16, array(self::$max_sync)) . "<br />\n";
494                 echo $this->t(_NP_THUMBNAIL_17) . "</p>\n";
495                 
496                 if ( $type == 'sync' )
497                 {
498                         $maxwidth = $this->getOption('maxwidth');
499                         $maxheight = $this->getOption('maxheight');
500                         if ( $this->getOption('save_thumb') == 'filesystem' )
501                         {
502                                 echo "<h3>" . $this->t(_NP_THUMBNAIL_22) . "</h3>\n";
503                                 if ( self::syncFilesystem ($DIR_MEDIA, self::$thumbdir, $maxwidth, $maxheight) )
504                                 {
505                                         echo "<p>何かのエラーメッセージ</p>\n";
506                                 }
507                         }
508                 }
509                 
510                 $media = MediaUtils::getMediaList($DIR_MEDIA);
511                 $elected = array();
512                 $rejected = array();
513                 
514                 foreach ( $media as $medium )
515                 {
516                         if ( !array_key_exists($medium->mime, MediaUtils::$image_mime) )
517                         {
518                                 continue;
519                         }
520                         if ( file_exists($DIR_MEDIA . self::getThumbPath($medium)) )
521                         {
522                                 $rejected[] =& $medium;
523                                 continue;
524                         }
525                         else
526                         {
527                                 $elected[] =& $medium;
528                                 continue;
529                         }
530                 }
531                 
532                 $total_media = count ($media);
533                 $total_elected = count ($elected);
534                 $total_rejected = count ($rejected);
535                 $total_images = count ($rejected) + $total_elected;
536                 
537                 /*
538                  * NOTICE: NP_Improvededia with eachblogdir option rewrite
539                  * global variables of "DIR_MEDIA" and "$CONF['MediaURL']"
540                  * in its initializing process.
541                  * (I realized it a bad behavior but there is no other way...)
542                  * Here are based on its rewriting system.
543                  *  (Apr. 06, 2011)
544                  */
545                 if ( $manager->pluginInstalled('NP_ImprovedMedia') )
546                 {
547                         $NP_ImprovedMedia =& $manager->getPlugin('NP_ImprovedMedia');
548                         if ( $NP_ImprovedMedia->getOption('IM_EACHBLOGDIR') == 'yes' )
549                         {
550                                 echo "<form method=\"post\" action=\"{$CONF['ActionURL']}?action=plugin&name=Thumbnail\" enctype=\"application/x-www-form-urlencoded\">\n";
551                                 echo "<p>\n";
552                                 echo "<label for=\"blogid\">" . $this->t(_NP_THUMBNAIL_18) . "</label>\n";
553                                 echo "<select name=\"blogid\" id=\"blogid\"onchange=\"return form.submit()\">\n";
554                                 foreach ( MediaUtils::$blogs as $blogid => $bshortname )
555                                 {
556                                         if ( $blogid == MediaUtils::$blogid )
557                                         {
558                                                 echo "<option value=\"{$blogid}\" selected=\"selected\">{$bshortname}</option>\n";
559                                         }
560                                         else
561                                         {
562                                                 echo "<option value=\"{$blogid}\">{$bshortname}</option>\n";
563                                         }
564                                 }
565                                 echo "</select>\n";
566                                 echo "<input type=\"hidden\" id=\"admin\" name=\"type\" value=\"admin\">\n";
567                                 echo "</p>\n";
568                                 echo "</form>\n";
569                         }
570                 }
571                 
572                 echo "<form method=\"post\" action=\"{$CONF['ActionURL']}?action=plugin&name=Thumbnail\" enctype=\"application/x-www-form-urlencoded\">\n";
573                 echo "<ul>\n";
574                 echo "<li>" . $this->t(_NP_THUMBNAIL_19, array($total_media)) . "</li>\n";
575                 echo "<li>" . $this->t(_NP_THUMBNAIL_20, array($total_images)) . "</li>\n";
576                 echo "<li>" . $this->t(_NP_THUMBNAIL_21, array($total_rejected)) . "</li>\n";
577                 echo "</ul>\n";
578                 echo "<p>\n";
579                 echo '<input type="hidden" name="blogid" value="' . MediaUtils::$blogid . '">' . "\n";
580                 echo "<input type=\"submit\" name=\"type\" value=\"sync\">\n";
581                 echo "<input type=\"submit\" name=\"type\" value=\"clear\">\n";
582                 echo "</p>\n";
583                 
584                 if ( $logs )
585                 {
586                         echo "<h3>" . $this->t(_NP_THUMBNAIL_22) . "</h3>\n";
587                         echo "<ul>\n";
588                         
589                         foreach ( $logs as $log )
590                         {
591                                 echo "<li>{$log}</li>\n";
592                         }
593                         echo "</ul>\n";
594                 }
595                 echo "</form>\n";
596                 
597                 $oPluginAdmin->end();
598                 return;
599         }
600         
601         public static function syncFilesystem ($root, $dest, $maxwidth, $maxheight)
602         {
603                 $logs = array ();
604                 
605                 $root = rtrim($root, '/');
606                 if ( !$root || !file_exists($root) )
607                 {
608                         return FALSE;
609                 }
610                 
611                 if ( !MediaUtils::checkDir(rtrim($root, '/') . '/' . trim($dest, '/')) )
612                 {
613                         return FALSE;
614                 }
615                 
616                 echo "<ul>\n";
617                 
618                 $media = MediaUtils::getMediaList($root);
619                 $targets = array();
620                 $count = 1;
621                 
622                 foreach ( $media as $medium )
623                 {
624                         ob_flush();
625                         flush();
626                         
627                         if ( $count > self::$max_sync )
628                         {
629                                 break;
630                         }
631                         
632                         if ( FALSE === ($destination = self::getThumbPath($medium))
633                            || file_exists (rtrim($root, '/') . '/' . $destination) )
634                         {
635                                 continue;
636                         }
637                         
638                         if ( FALSE === $medium->setResampledSize($maxwidth, $maxheight)
639                            || !MediaUtils::storeResampledImage ($root, $destination, $medium) )
640                         {
641                                 echo "<li>Fail: {$medium->name}</li>\n";
642                         }
643                         else
644                         {
645                                 echo "<li>Success: {$medium->name}</li>\n";
646                                 $count++;
647                         }
648                 }
649                 
650                 echo "</ul>\n";
651                 flush();
652                 return TRUE;
653         }
654         
655         public static function getThumbPath($medium)
656         {
657                 if ( !array_key_exists ($medium->mime, MediaUtils::$image_mime) )
658                 {
659                         return FALSE;
660                 }
661                 return self::$thumbdir . '/' . $medium->getHashedName(MediaUtils::$algorism) . MediaUtils::$image_mime[$medium->mime];
662         }
663         
664         public function getThumbURL($medium)
665         {
666                 global $CONF, $DIR_MEDIA;
667                 
668                 if ( ($medium->width < $medium->resampledwidth && $medium->height < $medium->resampledheight)
669                  || ($medium->width <= $this->getOption('maxwidth') && $medium->height <= $this->getOption('maxheight')) )
670                  {
671                         $url = "{$CONF['MediaURL']}{$medium->path}/{$medium->name}";
672                 }
673                 else if ( $medium->resampledwidth > $this->getOption('maxwidth') && $medium->resampledheight > $this->getOption('maxheight') )
674                 {
675                         $url = "{$CONF['ActionURL']}?action=plugin&amp;name={$this->getName()}&amp;path={$medium->path}/{$medium->name}&amp;width={$medium->resampledwidth}&amp;height={$medium->resampledheight}&amp;blogid=" . MediaUtils::$blogid;
676                 }
677                 else if (file_exists($DIR_MEDIA . self::getThumbPath($medium)) )
678                 {
679                         $url = $CONF['MediaURL'] . self::getThumbPath($medium);
680                 }
681                 else
682                 {
683                         $url = FALSE;
684                 }
685                 return $url;
686         }
687 }