• R/O
  • HTTP
  • SSH
  • HTTPS

nucleus-plugins: Commit

Nucleus CMS日本語版用プラグインのうち、日本語版開発者がサポートしているもの


Commit MetaInfo

Revisiond6f2bd49328dabd9bae211d81246b0ddbfe95452 (tree)
Time2012-10-20 15:10:28
Authorsakamocchi <o-takashi@saka...>
Commitersakamocchi

Log Message

FIX: NP_ThumbnailをNucleus 3.65/PHP5.4/MySQL5.5で動作するよう修正

Change Summary

  • modified: NP_Thumbnail/NP_Thumbnail.php (diff)
  • delete: NP_Thumbnail/thumbnail/{english.php => en_Latn_US.ISO-8859-1.php}
  • delete: NP_Thumbnail/thumbnail/{japanese-euc.php => ja_Jpan_JP.EUC-JP.php}
  • delete: NP_Thumbnail/thumbnail/{japanese-utf8.php => ja_Jpan_JP.UTF-8.php}

Incremental Difference

--- a/NP_Thumbnail/NP_Thumbnail.php
+++ b/NP_Thumbnail/NP_Thumbnail.php
@@ -1,8 +1,8 @@
11 <?php
22 /**
33 * Thumbnail plugin for Nucleus CMS
4- * Version 3.9.6 (4.0 RC2) for PHP5
5- * Written By Mocchi, Apr. 04, 2011
4+ * Version 4.0.0 for PHP5
5+ * Written By Mocchi, Apr. 06, 2011
66 * Original code was written by jirochou, May 23, 2004 and maintained by nakahara21
77 * This plugin depends on NP_MediaUtils
88 *
@@ -12,24 +12,26 @@
1212 * of the License, or (at your option) any later version.
1313 */
1414
15-class NP_Thumbnail extends NucleusPlugin {
15+class NP_Thumbnail extends NucleusPlugin
16+{
1617 private static $thumbdir = '.thumb';
1718 private static $max_sync = 10;
1819 private static $authorid = 0;
1920 private static $buffering = FALSE;
20- private static $table_name = 'plugin_thumbnail'; // not implemented
21+ private static $table_name = 'plugin_thumbnail'; // not implemented yet
2122
2223 public function getName() { return 'Thumbnail'; }
2324 public function getAuthor() { return 'Mocchi, nakahara21, jirochou'; }
2425 public function getURL() { return 'http://japan.nucleuscms.org/wiki/plugins:thumbnail'; }
25- public function getVersion() { return '3.9.6 (4.0 RC2)'; }
26+ public function getVersion() { return '4.0.0'; }
2627 public function getDescription() { return _NP_THUMBNAIL_01; }
27- public function getPluginDep() { return array('NP_MediaUtils');}
28- public function getMinNucleusVersion() {return 340;}
28+ public function getPluginDep() { return array('NP_MediaUtils'); }
29+ public function getMinNucleusVersion() { return 340; }
2930 public function supportsFeature($feature) { return in_array ($feature, array('SqlTablePrefix', 'SqlApi'));}
3031 public function getEventList() { return array('QuickMenu', 'PrePluginOptionsEdit', 'PostAuthentication', 'PreItem', 'PostMediaUpload'); }
3132
32- public function install () {
33+ public function install ()
34+ {
3335 $this->createOption('maxwidth', '_NP_THUMBNAIL_02', 'text', '100', 'datatype=numerical');
3436 $this->createOption('maxheight', '_NP_THUMBNAIL_03', 'text', '100', 'datatype=numerical');
3537 $this->createOption('save_thumb', '_NP_THUMBNAIL_04', 'select', 'filesystem', '_NP_THUMBNAIL_05|no|_NP_THUMBNAIL_06|filesystem');
@@ -41,114 +43,168 @@ class NP_Thumbnail extends NucleusPlugin {
4143 /*
4244 * plugin options are purged automatically when uninstalled.
4345 */
44- public function uninstall() {
46+ public function uninstall()
47+ {
4548 global $DIR_MEDIA;
4649 MediaUtils::purgeDir($DIR_MEDIA . self::$thumbdir);
4750 return;
4851 }
4952
50- public function init() {
51- global $DIR_MEDIA;
53+ public function init()
54+ {
55+ global $manager;
56+
57+ $locale = '';
5258
53- if (!class_exists('Medium', FALSE)) {
54- include(MediaUtils::$lib_path . '/Medium.php');
59+ if ( !class_exists('Medium', FALSE) )
60+ {
61+ $manager->getPlugin('NP_Thumbnail');
5562 }
5663
57- $language = preg_replace('#[/|\\\\]#', '', getLanguageName());
5864
59- if (!defined('_NP_THUMBNAIL_01')) {
60- if (file_exists($this->getDirectory() . $language.'.php')) {
61- include($this->getDirectory() . $language.'.php');
62- } else {
63- include($this->getDirectory() . 'english.php');
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';
6481 }
6582 }
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+
6693 return;
6794 }
6895
69-/*
70- * for translation
71- */
72- public function event_PrePluginOptionsEdit ($data) {
73- if ($data['context'] != 'global') {
74- foreach($data['options'] as $key => $option) {
75- if ($option['pid'] == $this->getID()) {
76- if (defined($option['description'])) {
77- $data['options'][$key]['description'] = constant($option['description']);
78- }
79- if ($option['type'] == 'select') {
80- foreach (explode('|', $option['typeinfo']) as $option) {
81- if (defined($option)) {
82- $data['options'][$key]['typeinfo'] = str_replace($option, constant($option), $data['options'][$key]['typeinfo']);
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+ }
83122 }
84123 }
85124 }
86125 }
87126 }
88- } else if ($data['plugid'] == $this->getID()) {
89- foreach($data['options'] as $key => $option){
90- if (defined($option['description'])) {
91- $data['options'][$key]['description'] = constant($option['description']);
92- }
93- if ($option['type'] == 'select') {
94- foreach (explode('|', $option['typeinfo']) as $option) {
95- if (defined($option)) {
96- $data['options'][$key]['typeinfo'] = str_replace($option, constant($option), $data['options'][$key]['typeinfo']);
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+ }
97143 }
98- }
144+ }
99145 }
100146 }
101147 }
148+
102149 return;
103150 }
104151
105-/*
106- * for translation
107- */
108- static private function t ($text, $array=array()){
109- if (is_array($array)) {
152+ /*
153+ * for translation
154+ */
155+ static private function t($text, $array=array())
156+ {
157+ if ( is_array($array) )
158+ {
110159 $search = array();
111160 $replace = array();
112161
113- foreach ($array as $key => $value){
114- if (is_array($value)) {
162+ foreach ( $array as $key => $value )
163+ {
164+ if ( is_array($value) )
165+ {
115166 continue;
116167 }
117168 $search[] = '<%'.preg_replace('/[^a-zA-Z0-9_]+/','',$key).'%>';
118169 $replace[] = $value;
119170 }
120171 }
121- return htmlspecialchars (str_replace($search, $replace, $text), ENT_QUOTES, _CHARSET);
172+ return htmlspecialchars(str_replace($search, $replace, $text), ENT_QUOTES, _CHARSET);
122173 }
123174
124- public function event_QuickMenu ($data) {
175+ public function event_QuickMenu(&$data)
176+ {
125177 global $CONF;
126- if($this->getOption('save_thumb') !== 'no') {
127- array_push(
128- $data['options'],
129- array (
130- 'title' => 'NP_Thumbnail',
131- 'url' => "{$CONF['ActionURL']}?action=plugin&name={$this->getname()}&type=admin",
132- 'tooltip' => _NP_THUMBNAIL_09));
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);
133186 }
134187 return;
135188 }
136189
137- public function event_PostAuthentication ($data) {
138- if (array_key_exists('action', $_REQUEST)
190+ public function event_PostAuthentication(&$data)
191+ {
192+ if ( array_key_exists('action', $_REQUEST)
139193 && array_key_exists('name', $_REQUEST)
140194 && array_key_exists('type', $_REQUEST)
141195 && array_key_exists('width', $_REQUEST)
142196 && array_key_exists('height', $_REQUEST)
143197 && $_REQUEST['action'] === 'plugin'
144198 && $_REQUEST['name'] === $this->getName()
145- && $_REQUEST['type'] !== '') {
199+ && $_REQUEST['type'] !== '' )
200+ {
146201 self::$buffering = ob_start;
147202 }
148203 return;
149204 }
150205
151- public function doAction ($type) {
206+ public function doAction($type)
207+ {
152208 global $DIR_MEDIA, $member;
153209
154210 $type = (string) $type;
@@ -157,37 +213,45 @@ class NP_Thumbnail extends NucleusPlugin {
157213 $maxwidth = '';
158214 $maxheight = '';
159215
160- if (array_key_exists('path', $_GET)) {
216+ if ( array_key_exists('path', $_GET) )
217+ {
161218 $path = (string) $_GET['path'];
162219 }
163- if (array_key_exists('width', $_GET)) {
220+ if ( array_key_exists('width', $_GET) )
221+ {
164222 $maxwidth = (integer) $_GET['width'];
165223 }
166- if (array_key_exists('height', $_GET)) {
224+ if ( array_key_exists('height', $_GET) )
225+ {
167226 $maxheight = (integer) $_GET['height'];
168227 }
169228
170- if (in_array($type, array('admin', 'clear', 'sync')) && $member->isAdmin()) {
171- $this->showAdmin($type);
172- exit;
229+ if ( self::$buffering )
230+ {
231+ ob_end_clean();
173232 }
174233
175- if (self::$buffering) {
176- ob_end_clean();
234+ if ( in_array($type, array('admin', 'clear', 'sync')) && $member->isAdmin() )
235+ {
236+ $this->showAdmin($type);
237+ exit;
177238 }
178239
179- if ($maxwidth <= 0 || $maxwidth > 1000 || $maxheight <= 0 || $maxheight > 1000 ) {
180- MediaUtils::error ($this->t(_NP_THUMBNAIL_10, array($maxwidth, $maxheight)));
240+ if ( $maxwidth <= 0 || $maxwidth > 1000 || $maxheight <= 0 || $maxheight > 1000 )
241+ {
242+ MediaUtils::error($this->t(_NP_THUMBNAIL_10, array($maxwidth, $maxheight)));
181243 return;
182244 }
183245
184- if (FALSE === ($medium = new Medium($DIR_MEDIA, $path, MediaUtils::$prefix))) {
185- MediaUtils::error ($this->t(_NP_THUMBNAIL_11, array($path)));
246+ if ( FALSE === ($medium = new Medium($DIR_MEDIA, $path, MediaUtils::$prefix)) )
247+ {
248+ MediaUtils::error($this->t(_NP_THUMBNAIL_11, array($path)));
186249 return;
187250 }
188251
189- if (FALSE === $medium->setResampledSize($maxwidth, $maxheight)) {
190- MediaUtils::error ($this->t(_NP_THUMBNAIL_10, array($maxwidth, $maxheight)));
252+ if ( FALSE === $medium->setResampledSize($maxwidth, $maxheight) )
253+ {
254+ MediaUtils::error($this->t(_NP_THUMBNAIL_10, array($maxwidth, $maxheight)));
191255 return;
192256 }
193257
@@ -195,34 +259,61 @@ class NP_Thumbnail extends NucleusPlugin {
195259 return;
196260 }
197261
198- public function doSkinVar ($skinType, $path, $maxwidth=0, $maxheight=0, $alt) {
199- $path = (string) $path;
200- $maxwidth = (integer) $maxwidth;
201- $maxheight = (integer) $maxheight;
202- $alt = (string) $alt;
262+ public function doSkinVar($skinType)
263+ {
264+ $path = '';
265+ $maxwidth = 0;
266+ $maxheight = 0;
267+ $alt = '';
203268
204- if ($this->getBlogOption(MediaUtils::$blogid, 'force_thumb') == 'yes') {
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+ {
205290 echo $this->getParsedTag(array('', '', $path, 0, 0, $alt), $maxwidth, $maxheight);
206291 }
292+
207293 return;
208294 }
209295
210- public function event_PreItem($data) {
296+ public function event_PreItem(&$data)
297+ {
211298 $item =& $data["item"];
212299 self::$authorid = $item->authorid;
213300 $item->body = preg_replace_callback("#<\%(Thumbnail)\((.*?)\|(.*?)\|(.*?)\|(.*?)\)%\>#", array(&$this, 'getParsedTag'), $item->body);
214301 $item->more = preg_replace_callback("#<\%(Thumbnail)\((.*?)\|(.*?)\|(.*?)\|(.*?)\)%\>#", array(&$this, 'getParsedTag'), $item->more);
215302
216- if ($this->getBlogOption(MediaUtils::$blogid, 'force_thumb') == 'yes') {
303+ if ( $this->getBlogOption(MediaUtils::$blogid, 'force_thumb') == 'yes' )
304+ {
217305 $item->body = preg_replace_callback("#<\%(popup)\((.*?)\|(.*?)\|(.*?)\|(.*?)\)%\>#", array(&$this, 'getParsedTag'), $item->body);
218306 $item->more = preg_replace_callback("#<\%(popup)\((.*?)\|(.*?)\|(.*?)\|(.*?)\)%\>#", array(&$this, 'getParsedTag'), $item->more);
219307 }
220308 return;
221309 }
222310
223- public function event_PostMediaUpload ($data) {
311+ public function event_PostMediaUpload(&$data)
312+ {
224313 global $DIR_MEDIA;
225- if ($this->getOption('save_thumb') == 'no') {
314+
315+ if ( $this->getOption('save_thumb') == 'no' )
316+ {
226317 return;
227318 }
228319
@@ -232,27 +323,33 @@ class NP_Thumbnail extends NucleusPlugin {
232323 $maxwidth = $this->getOption('maxwidth');
233324 $maxheight = $this->getOption('maxheight');
234325
235- if (!MediaUtils::checkDir ($root . '/' . self::$thumbdir)) {
326+ if ( !MediaUtils::checkDir ($root . '/' . self::$thumbdir) )
327+ {
236328 return;
237329 }
238330
239- if (FALSE === ($medium = new Medium($root, "{$path}/{$filename}", MediaUtils::$prefix))) {
331+ if ( FALSE === ($medium = new Medium($root, "{$path}/{$filename}", MediaUtils::$prefix)) )
332+ {
240333 return;
241334 }
242335
243- if (!array_key_exists($medium->mime, MediaUtils::$image_mime)) {
336+ if ( !array_key_exists($medium->mime, MediaUtils::$image_mime) )
337+ {
244338 return;
245339 }
246340
247- if (FALSE === $medium->setResampledSize($maxwidth, $maxheight)) {
341+ if ( FALSE === $medium->setResampledSize($maxwidth, $maxheight) )
342+ {
248343 return;
249344 }
250345
251- $target = $this->getThumbPath($medium);
346+ $target = self::getThumbPath($medium);
252347
253- if ($this->getOption('save_thumb') == 'filesystem') {
254- if (!file_exists("{$root}/{$target}")
255- && !MediaUtils::storeResampledImage ($DIR_MEDIA, $target, $medium)) {
348+ if ( $this->getOption('save_thumb') == 'filesystem' )
349+ {
350+ if ( !file_exists("{$root}/{$target}")
351+ && !MediaUtils::storeResampledImage ($DIR_MEDIA, $target, $medium) )
352+ {
256353 return;
257354 }
258355 }
@@ -260,79 +357,97 @@ class NP_Thumbnail extends NucleusPlugin {
260357 return;
261358 }
262359
263- public function getParsedTag ($match, $maxwidth=0, $maxheight=0) {
360+ public function getParsedTag($match, $maxwidth=0, $maxheight=0)
361+ {
264362 global $DIR_MEDIA, $member;
265363
266364 list($code, $tag, $path, $width, $height, $alt) = $match;
267365
268- if (!preg_match("#^.+?/.+$#", $path) && self::$authorid) {
366+ if ( !preg_match("#^.+?/.+$#", $path) && self::$authorid )
367+ {
269368 $path = self::$authorid . '/' . $path;
270369 }
271370
272- if (FALSE === ($medium = new Medium($DIR_MEDIA, $path, MediaUtils::$prefix))) {
371+ if ( FALSE === ($medium = new Medium($DIR_MEDIA, $path, MediaUtils::$prefix)) )
372+ {
273373 return $this->t('NP_Thumbnail: 指定したメディアファイルを読み込めませんでした。', array($path));
274374 }
275375
276- if (!array_key_exists($medium->mime, MediaUtils::$image_mime)) {
376+ if ( !array_key_exists($medium->mime, MediaUtils::$image_mime) )
377+ {
277378 return $this->t(_NP_THUMBNAIL_12, array($path));
278379 }
279380
280- if ($tag == 'Thumbnail') {
381+ if ( $tag == 'Thumbnail' )
382+ {
281383 $maxwidth = (integer) $width;
282384 $maxheight = (integer) $height;
283385 }
284386
285- if (($maxwidth == 0) && ($maxheight == 0)) {
387+ if ( ($maxwidth == 0) && ($maxheight == 0) )
388+ {
286389 $maxwidth = (integer) $this->getOption('maxwidth');
287390 $maxheight = (integer) $this->getOption('maxheight');
288391 }
289392
290- if ($maxwidth < 0 || $maxwidth > 1000 || $maxheight < 0 || $maxheight > 1000) {
393+ if ( $maxwidth < 0 || $maxwidth > 1000 || $maxheight < 0 || $maxheight > 1000 )
394+ {
291395 return $this->t(_NP_THUMBNAIL_10, array($path));
292396 }
293397
294- if (FALSE === $medium->setResampledSize($maxwidth, $maxheight)) {
398+ if ( FALSE === $medium->setResampledSize($maxwidth, $maxheight) )
399+ {
295400 return $this->t('NP_Thumbnail: サムネイルのサイズが不正です。', array($path));
296401 }
297402
298- if (!$alt) {
403+ if ( !$alt )
404+ {
299405 $alt =& $path;
300406 }
301407
302408 return $this->generateTag($this->getBlogOption(MediaUtils::$blogid, 'thumb_template'), $medium, $alt);
303409 }
304410
305- public function generateTag($template, $medium, $alt) {
411+ public function generateTag($template, $medium, $alt)
412+ {
306413 global $DIR_LIBS;
307414
308- if (!class_exists('BODYACTIONS', FALSE)) {
415+ if ( !class_exists('BODYACTIONS', FALSE) )
416+ {
309417 include($DIR_LIBS . 'BODYACTIONS.php');
310418 }
311419 $action = new BODYACTIONS;
312420
313- if (array_key_exists($medium->mime, MediaUtils::$image_mime)
314- && $this->getOption('save_thumb') == 'filesystem') {
315- if (!MediaUtils::checkDir ($medium->root . '/' . self::$thumbdir)) {
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+ {
316426 return $this->t(_NP_THUMBNAIL_13, array(self::$thumbdir));
317427 }
318- if (!file_exists("{$medium->root}/{$this->getThumbPath($medium)}")) {
319- MediaUtils::storeResampledImage ($medium->root, $this->getThumbPath($medium), $medium);
428+ if ( !file_exists($medium->root . '/' . self::getThumbPath($medium)) )
429+ {
430+ MediaUtils::storeResampledImage ($medium->root, self::getThumbPath($medium), $medium);
320431 }
321432 }
322433
323434 ob_start();
324- if (array_key_exists($medium->mime, MediaUtils::$image_mime) && $this->getThumbURL($medium)) {
435+ if ( array_key_exists($medium->mime, MediaUtils::$image_mime) && $this->getThumbURL($medium) )
436+ {
325437 $action->template['POPUP_CODE'] = $template;
326438 $replacements = array(
327- '<%thumb_width%>' => $medium->resampledwidth,
328- '<%thumb_height%>' => $medium->resampledheight,
329- '<%thumb_url%>' => $this->getThumbURL($medium)
439+ '<%thumb_width%>' => $medium->resampledwidth,
440+ '<%thumb_height%>' => $medium->resampledheight,
441+ '<%thumb_url%>' => $this->getThumbURL($medium)
330442 );
331- foreach ($replacements as $target => $replacement) {
443+ foreach ( $replacements as $target => $replacement )
444+ {
332445 $action->template['POPUP_CODE'] = str_replace ($target, $replacement, $action->template['POPUP_CODE']);
333446 }
334- $action->createPopupCode ("{$medium->path}/{$medium->name}", $medium->width, $medium->height, $alt);
335- } else {
447+ $action->createPopupCode("{$medium->path}/{$medium->name}", $medium->width, $medium->height, $alt);
448+ }
449+ else
450+ {
336451 $action->template['MEDIA_CODE'] = $template;
337452 $action->createMediaCode("{$medium->path}/{$medium->name}", $alt);
338453 }
@@ -342,12 +457,14 @@ class NP_Thumbnail extends NucleusPlugin {
342457 return preg_replace('#href="(.*?)imagetext(.*?)"#', 'href="$1imagetext$2&amp;blogid='.MediaUtils::$blogid . '"', $tag);
343458 }
344459
345- private function showAdmin ($type) {
460+ private function showAdmin($type)
461+ {
346462 global $CONF, $DIR_LIBS, $DIR_MEDIA, $manager;
347463
348464 $type = (string) $type;
349465
350- if (!class_exists ('PLUGINADMIN', FALSE)) {
466+ if ( !class_exists ('PLUGINADMIN', FALSE) )
467+ {
351468 include ($DIR_LIBS . 'PLUGINADMIN.php');
352469 }
353470
@@ -356,39 +473,58 @@ class NP_Thumbnail extends NucleusPlugin {
356473
357474 echo "<h2>NP_Thumbnail</h2>\n";
358475
359- if($this->getOption('save_thumb') === 'no') {
476+ if ( $this->getOption('save_thumb') === 'no' )
477+ {
360478 echo '<p>' . $this->t(_NP_THUMBNAIL_14) . "</p>\n";
361479 $oPluginAdmin->end();
362480 return;
363481 }
364482
365- if ($type == 'clear') {
366- if ($this->getOption('save_thumb') == 'filesystem') {
483+ $logs = array ();
484+ if ( $type == 'clear' )
485+ {
486+ if ( $this->getOption('save_thumb') == 'filesystem' )
487+ {
367488 $logs = MediaUtils::purgeDir($DIR_MEDIA, self::$thumbdir . '/');
368489 }
369- } else if ($type == 'sync') {
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+ {
370498 $maxwidth = $this->getOption('maxwidth');
371499 $maxheight = $this->getOption('maxheight');
372- if ($this->getOption('save_thumb') == 'filesystem') {
373- $logs = $this->syncFilesystem ($DIR_MEDIA, self::$thumbdir, $maxwidth, $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+ }
374507 }
375- } else {
376- $logs = array ();
377508 }
378509
379510 $media = MediaUtils::getMediaList($DIR_MEDIA);
380511 $elected = array();
381512 $rejected = array();
382513
383- foreach ($media as $medium) {
384- if (!array_key_exists($medium->mime, MediaUtils::$image_mime)) {
514+ foreach ( $media as $medium )
515+ {
516+ if ( !array_key_exists($medium->mime, MediaUtils::$image_mime) )
517+ {
385518 continue;
386519 }
387- if (file_exists ($DIR_MEDIA . $this->getThumbPath($medium))) {
388- $rejected[] = &$medium;
520+ if ( file_exists($DIR_MEDIA . self::getThumbPath($medium)) )
521+ {
522+ $rejected[] =& $medium;
389523 continue;
390- } else {
391- $elected[] = &$medium;
524+ }
525+ else
526+ {
527+ $elected[] =& $medium;
392528 continue;
393529 }
394530 }
@@ -396,29 +532,33 @@ class NP_Thumbnail extends NucleusPlugin {
396532 $total_media = count ($media);
397533 $total_elected = count ($elected);
398534 $total_rejected = count ($rejected);
399- $total_candidates = count ($rejected) + $total_elected;
400-
401- echo "<p>" . $this->t(_NP_THUMBNAIL_15, array(self::$thumbdir)) . "<br />\n";
402- echo $this->t(_NP_THUMBNAIL_16, array(self::$max_sync)) . "<br />\n";
403- echo $this->t(_NP_THUMBNAIL_17) . "</p>\n";
535+ $total_images = count ($rejected) + $total_elected;
404536
405537 /*
406538 * NOTICE: NP_Improvededia with eachblogdir option rewrite
407539 * global variables of "DIR_MEDIA" and "$CONF['MediaURL']"
408540 * in its initializing process.
541+ * (I realized it a bad behavior but there is no other way...)
409542 * Here are based on its rewriting system.
543+ * (Apr. 06, 2011)
410544 */
411- if ($manager->pluginInstalled('NP_ImprovedMedia')) {
545+ if ( $manager->pluginInstalled('NP_ImprovedMedia') )
546+ {
412547 $NP_ImprovedMedia =& $manager->getPlugin('NP_ImprovedMedia');
413- if ($NP_ImprovedMedia->getOption('IM_EACHBLOGDIR') == 'yes') {
548+ if ( $NP_ImprovedMedia->getOption('IM_EACHBLOGDIR') == 'yes' )
549+ {
414550 echo "<form method=\"post\" action=\"{$CONF['ActionURL']}?action=plugin&name=Thumbnail\" enctype=\"application/x-www-form-urlencoded\">\n";
415551 echo "<p>\n";
416- echo "<label for=\"blogid\">サムネイル作成対象のウェブログ</label>\n";
552+ echo "<label for=\"blogid\">" . $this->t(_NP_THUMBNAIL_18) . "</label>\n";
417553 echo "<select name=\"blogid\" id=\"blogid\"onchange=\"return form.submit()\">\n";
418- foreach(MediaUtils::$blogs as $blogid => $bshortname) {
419- if ($blogid == MediaUtils::$blogid) {
554+ foreach ( MediaUtils::$blogs as $blogid => $bshortname )
555+ {
556+ if ( $blogid == MediaUtils::$blogid )
557+ {
420558 echo "<option value=\"{$blogid}\" selected=\"selected\">{$bshortname}</option>\n";
421- } else {
559+ }
560+ else
561+ {
422562 echo "<option value=\"{$blogid}\">{$bshortname}</option>\n";
423563 }
424564 }
@@ -431,21 +571,23 @@ class NP_Thumbnail extends NucleusPlugin {
431571
432572 echo "<form method=\"post\" action=\"{$CONF['ActionURL']}?action=plugin&name=Thumbnail\" enctype=\"application/x-www-form-urlencoded\">\n";
433573 echo "<ul>\n";
434- echo "<li>" . $this->t(_NP_THUMBNAIL_18, array($total_media)) . "</li>\n";
435- echo "<li>" . $this->t(_NP_THUMBNAIL_19, array($total_candidates)) . "</li>\n";
436- echo "<li>" . $this->t(_NP_THUMBNAIL_20, array($total_rejected)) . "</li>\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";
437577 echo "</ul>\n";
438578 echo "<p>\n";
439579 echo '<input type="hidden" name="blogid" value="' . MediaUtils::$blogid . '">' . "\n";
440- echo "<input type=\"submit\" id=\"sync\" name=\"type\" value=\"sync\">\n";
441- echo "<input type=\"submit\" id=\"clear\" name=\"type\" value=\"clear\">\n";
580+ echo "<input type=\"submit\" name=\"type\" value=\"sync\">\n";
581+ echo "<input type=\"submit\" name=\"type\" value=\"clear\">\n";
442582 echo "</p>\n";
443583
444- if ($logs) {
445- echo "<h3>" . $this->t(_NP_THUMBNAIL_21) . "</h3>\n";
584+ if ( $logs )
585+ {
586+ echo "<h3>" . $this->t(_NP_THUMBNAIL_22) . "</h3>\n";
446587 echo "<ul>\n";
447588
448- foreach ($logs as $log) {
589+ foreach ( $logs as $log )
590+ {
449591 echo "<li>{$log}</li>\n";
450592 }
451593 echo "</ul>\n";
@@ -456,74 +598,90 @@ class NP_Thumbnail extends NucleusPlugin {
456598 return;
457599 }
458600
459- public function syncFilesystem ($root, $dest, $maxwidth, $maxheight) {
601+ public static function syncFilesystem ($root, $dest, $maxwidth, $maxheight)
602+ {
460603 $logs = array ();
461604
462605 $root = rtrim($root, '/');
463- if(!$root || !file_exists($root)) {
606+ if ( !$root || !file_exists($root) )
607+ {
464608 return FALSE;
465609 }
466610
467- if (!MediaUtils::checkDir(rtrim($root, '/') . '/' . trim($dest, '/'))) {
611+ if ( !MediaUtils::checkDir(rtrim($root, '/') . '/' . trim($dest, '/')) )
612+ {
468613 return FALSE;
469614 }
470615
616+ echo "<ul>\n";
617+
471618 $media = MediaUtils::getMediaList($root);
472619 $targets = array();
473620 $count = 1;
474621
475- foreach ($media as $medium) {
476- if ($count > self::$max_sync) {
622+ foreach ( $media as $medium )
623+ {
624+ ob_flush();
625+ flush();
626+
627+ if ( $count > self::$max_sync )
628+ {
477629 break;
478630 }
479631
480- if (!array_key_exists ($medium->mime, MediaUtils::$image_mime)) {
632+ if ( FALSE === ($destination = self::getThumbPath($medium))
633+ || file_exists (rtrim($root, '/') . '/' . $destination) )
634+ {
481635 continue;
482636 }
483637
484- if (FALSE === $medium->setResampledSize($maxwidth, $maxheight)) {
485- continue;
638+ if ( FALSE === $medium->setResampledSize($maxwidth, $maxheight)
639+ || !MediaUtils::storeResampledImage ($root, $destination, $medium) )
640+ {
641+ echo "<li>Fail: {$medium->name}</li>\n";
486642 }
487-
488- $destination = $this->getThumbPath($medium);
489-
490- if (!file_exists (rtrim($root, '/') . '/' . $destination)) {
491- if (!MediaUtils::storeResampledImage ($root, $destination, $medium)) {
492- $logs[] = "Fail: {$medium->name}";
493- } else {
494- $logs[] = "Success: {$medium->name}";
495- }
643+ else
644+ {
645+ echo "<li>Success: {$medium->name}</li>\n";
496646 $count++;
497647 }
498648 }
499- return $logs;
649+
650+ echo "</ul>\n";
651+ flush();
652+ return TRUE;
500653 }
501654
502- public function getThumbPath($medium) {
503- if ('Medium' !== get_class($medium)) {
655+ public static function getThumbPath($medium)
656+ {
657+ if ( !array_key_exists ($medium->mime, MediaUtils::$image_mime) )
658+ {
504659 return FALSE;
505660 }
506661 return self::$thumbdir . '/' . $medium->getHashedName(MediaUtils::$algorism) . MediaUtils::$image_mime[$medium->mime];
507662 }
508663
509- public function getThumbURL($medium) {
664+ public function getThumbURL($medium)
665+ {
510666 global $CONF, $DIR_MEDIA;
511667
512- if ('Medium' !== get_class($medium)) {
513- return FALSE;
514- }
515-
516- if (($medium->width < $medium->resampledwidth && $medium->height < $medium->resampledheight)
517- || ($medium->width <= $this->getOption('maxwidth') && $medium->height <= $this->getOption('maxheight'))) {
668+ if ( ($medium->width < $medium->resampledwidth && $medium->height < $medium->resampledheight)
669+ || ($medium->width <= $this->getOption('maxwidth') && $medium->height <= $this->getOption('maxheight')) )
670+ {
518671 $url = "{$CONF['MediaURL']}{$medium->path}/{$medium->name}";
519- } else if ($medium->resampledwidth > $this->getOption('maxwidth') && $medium->resampledheight > $this->getOption('maxheight')) {
672+ }
673+ else if ( $medium->resampledwidth > $this->getOption('maxwidth') && $medium->resampledheight > $this->getOption('maxheight') )
674+ {
520675 $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;
521- } else if (file_exists($DIR_MEDIA . $this->getThumbPath($medium))) {
522- $url = "{$CONF['MediaURL']}{$this->getThumbPath($medium)}";
523- } else {
676+ }
677+ else if (file_exists($DIR_MEDIA . self::getThumbPath($medium)) )
678+ {
679+ $url = $CONF['MediaURL'] . self::getThumbPath($medium);
680+ }
681+ else
682+ {
524683 $url = FALSE;
525684 }
526685 return $url;
527686 }
528687 }
529-
--- a/NP_Thumbnail/thumbnail/english.php
+++ b/NP_Thumbnail/thumbnail/en_Latn_US.ISO-8859-1.php
@@ -1,8 +1,8 @@
11 <?php
22 /**
33 * Thumbnail plugin for Nucleus CMS
4- * Version 3.9.6 (4.0 RC2) for PHP5
5- * Written By Mocchi, Apr. 04, 2011
4+ * Version 4.0.0 for PHP5
5+ * Written By Mocchi, Apr. 06, 2011
66 * Original code was written by jirochou, May 23, 2004 and maintained by nakahara21
77 * This plugin depends on NP_MediaUtils
88 *
@@ -29,7 +29,8 @@ define ('_NP_THUMBNAIL_14', 'This function is not allowed.');
2929 define ('_NP_THUMBNAIL_15', 'Thumbnails is generated in <%0%> on Media directory.');
3030 define ('_NP_THUMBNAIL_16', 'One session generates <%0%> thumbnails.');
3131 define ('_NP_THUMBNAIL_17', 'There is a possibility to fail to generate thumbnail if original image is too large.');
32-define ('_NP_THUMBNAIL_18', '<%0%> files is in this media directory.');
33-define ('_NP_THUMBNAIL_19', '<%0%> files can generate its own thumbnail.');
34-define ('_NP_THUMBNAIL_20', '<%0%> thumbnails already generated');
35-define ('_NP_THUMBNAIL_21', 'Logs');
32+define ('_NP_THUMBNAIL_18', 'The target weblog to generate thumbnails');
33+define ('_NP_THUMBNAIL_19', '<%0%> files is in this media directory.');
34+define ('_NP_THUMBNAIL_20', '<%0%> files can generate its own thumbnail.');
35+define ('_NP_THUMBNAIL_21', '<%0%> thumbnails already generated');
36+define ('_NP_THUMBNAIL_22', 'Logs');
--- a/NP_Thumbnail/thumbnail/japanese-euc.php
+++ b/NP_Thumbnail/thumbnail/ja_Jpan_JP.EUC-JP.php
@@ -1,8 +1,8 @@
11 <?php
22 /**
33 * Thumbnail plugin for Nucleus CMS
4- * Version 3.9.6 (4.0 RC2) for PHP5
5- * Written By Mocchi, Apr. 04, 2011
4+ * Version 4.0.0 for PHP5
5+ * Written By Mocchi, Apr. 06, 2011
66 * Original code was written by jirochou, May 23, 2004 and maintained by nakahara21
77 * This plugin depends on NP_MediaUtils
88 *
@@ -29,7 +29,8 @@ define ('_NP_THUMBNAIL_14', '
2929 define ('_NP_THUMBNAIL_15', 'サムネイルはメディア用ディレクトリの<%0%>に作成されます');
3030 define ('_NP_THUMBNAIL_16', '現在は1回あたり<%0%>枚のサムネイルを作成するように設定されています');
3131 define ('_NP_THUMBNAIL_17', 'あまりに縦横サイズの大きな画像はサムネイルが作成できない場合があります');
32-define ('_NP_THUMBNAIL_18', '現在<%0%>のメディアが登録されています');
33-define ('_NP_THUMBNAIL_19', 'そのうち、<%0%>の画像のサムネイルが作成可能です');
34-define ('_NP_THUMBNAIL_20', 'そのうち、<%0%>の画像のサムネイルがすでに作成されています。');
35-define ('_NP_THUMBNAIL_21', 'ログ');
32+define ('_NP_THUMBNAIL_18', 'サムネイル作成対象のウェブログ');
33+define ('_NP_THUMBNAIL_19', '現在<%0%>のメディアが登録されています');
34+define ('_NP_THUMBNAIL_20', 'そのうち、<%0%>の画像のサムネイルが作成可能です');
35+define ('_NP_THUMBNAIL_21', 'そのうち、<%0%>の画像のサムネイルがすでに作成されています。');
36+define ('_NP_THUMBNAIL_22', 'ログ');
--- a/NP_Thumbnail/thumbnail/japanese-utf8.php
+++ b/NP_Thumbnail/thumbnail/ja_Jpan_JP.UTF-8.php
@@ -1,8 +1,8 @@
11 <?php
22 /**
33 * Thumbnail plugin for Nucleus CMS
4- * Version 3.9.6 (4.0 RC2) for PHP5
5- * Written By Mocchi, Apr. 04, 2011
4+ * Version 4.0.0 for PHP5
5+ * Written By Mocchi, Apr. 06, 2011
66 * Original code was written by jirochou, May 23, 2004 and maintained by nakahara21
77 * This plugin depends on NP_MediaUtils
88 *
@@ -29,7 +29,8 @@ define ('_NP_THUMBNAIL_14', '現在はサムネイルファイルをサーバに
2929 define ('_NP_THUMBNAIL_15', 'サムネイルはメディア用ディレクトリの<%0%>に作成されます');
3030 define ('_NP_THUMBNAIL_16', '現在は1回あたり<%0%>枚のサムネイルを作成するように設定されています');
3131 define ('_NP_THUMBNAIL_17', 'あまりに縦横サイズの大きな画像はサムネイルが作成できない場合があります');
32-define ('_NP_THUMBNAIL_18', '現在<%0%>のメディアが登録されています');
33-define ('_NP_THUMBNAIL_19', 'そのうち、<%0%>の画像のサムネイルが作成可能です');
34-define ('_NP_THUMBNAIL_20', 'そのうち、<%0%>の画像のサムネイルがすでに作成されています。');
35-define ('_NP_THUMBNAIL_21', 'ログ');
32+define ('_NP_THUMBNAIL_18', 'サムネイル作成対象のウェブログ');
33+define ('_NP_THUMBNAIL_19', '現在<%0%>のメディアが登録されています');
34+define ('_NP_THUMBNAIL_20', 'そのうち、<%0%>の画像のサムネイルが作成可能です');
35+define ('_NP_THUMBNAIL_21', 'そのうち、<%0%>の画像のサムネイルがすでに作成されています。');
36+define ('_NP_THUMBNAIL_22', 'ログ');
Show on old repository browser