From: sakamocchi Date: Sat, 20 Oct 2012 06:11:45 +0000 (+0900) Subject: FIX: NP_ImageLimitSizeをNucleus 3.65/PHP5.4/MySQL5.5で動作するよう修正 X-Git-Url: http://git.osdn.net/view?p=nucleus-jp%2Fnucleus-plugins.git;a=commitdiff_plain;h=45288b0453aba294593b8e97fafca495dbb2b2fe FIX: NP_ImageLimitSizeをNucleus 3.65/PHP5.4/MySQL5.5で動作するよう修正 --- diff --git a/NP_ImageLimitSize/NP_ImageLimitSize.php b/NP_ImageLimitSize/NP_ImageLimitSize.php index c5d3202..b8933f7 100755 --- a/NP_ImageLimitSize/NP_ImageLimitSize.php +++ b/NP_ImageLimitSize/NP_ImageLimitSize.php @@ -1,8 +1,8 @@ createOption('maxwidth', '_NP_IMAGELIMITSIZE_02', 'text', '550', 'datatype=numerical'); $this->createOption('maxheight', '_NP_IMAGELIMITSIZE_03', 'text', '0', 'datatype=numerical'); $this->createBlogOption('status', '_NP_IMAGELIMITSIZE_04', 'yesno', 'yes'); @@ -32,132 +34,160 @@ class NP_ImageLimitSize extends NucleusPlugin { return; } - public function uninstall() { + public function uninstall() + { // plugin options are purged automatically when uninstalled. return; } - public function init() { - if((string)$_REQUEST['action'] == 'pluginlist' && !defined('_NP_IMAGELIMITSIZE_01')) { + public function init() + { + $locale = ''; + + /* new API */ + if ( class_exists('i18n', FALSE) ) + { + $locale = i18n::get_current_locale() . '.' . i18n::get_current_charset() . '.php'; + } + /* old API */ + else + { $language = preg_replace('#[/|\\\\]#', '', getLanguageName()); - if (file_exists($this->getDirectory() . $language.'.php')) { - include($this->getDirectory() . $language.'.php'); - } else { - include($this->getDirectory() . 'english.php'); + if ( $language == 'japanese-euc' ) + { + $locale = 'ja_Jpan_JP.EUC-JP.php'; + } + else if ( $language = 'japanese-utf8' ) + { + $locale = 'ja_Jpan_JP.UTF-8.php'; } } + + if ( !$locale || !file_exists($this->getDirectory() . $locale) ) + { + include($this->getDirectory() . 'en_Latn_US.ISO-8859-1.php'); + } + else + { + include($this->getDirectory() . $locale); + } + return; } -/* - * for translation - */ - public function event_PrePluginOptionsEdit ($data) { - if(!defined('_NP_IMAGELIMITSIZE_01')) { - $language = preg_replace('#[/|\\\\]#', '', getLanguageName()); - if (file_exists($this->getDirectory() . $language.'.php')) { - include($this->getDirectory() . $language.'.php'); - } else { - include($this->getDirectory() . 'english.php'); - } - } - if ($data['context'] != 'global') { - foreach($data['options'] as $key => $option) { - if ($option['pid'] == $this->getID()) { - if (defined($option['description'])) { - $data['options'][$key]['description'] = constant($option['description']); - } - if ($option['type'] == 'select') { - foreach (explode('|', $option['typeinfo']) as $option) { - if (defined($option)) { - $data['options'][$key]['typeinfo'] = str_replace($option, constant($option), $data['options'][$key]['typeinfo']); + /* + * for translation + */ + public function event_PrePluginOptionsEdit(&$data) + { + /* Old version do not support natively */ + if ( getNucleusVersion() < 400 ) + { + if ( $data['context'] != 'global' ) + { + foreach ( $data['options'] as $key => $option ) + { + if ( $option['pid'] == $this->getID() ) + { + if ( defined($option['description']) ) + { + $data['options'][$key]['description'] = constant($option['description']); + } + if ( $option['type'] == 'select' ) + { + foreach ( explode('|', $option['typeinfo']) as $option ) + { + if ( defined($option) ) + { + $data['options'][$key]['typeinfo'] = str_replace($option, constant($option), $data['options'][$key]['typeinfo']); + } } } } } } - } else if ($data['plugid'] == $this->getID()) { - foreach($data['options'] as $key => $option){ - if (defined($option['description'])) { - $data['options'][$key]['description'] = constant($option['description']); - } - if ($option['type'] == 'select') { - foreach (explode('|', $option['typeinfo']) as $option) { - if (defined($option)) { - $data['options'][$key]['typeinfo'] = str_replace($option, constant($option), $data['options'][$key]['typeinfo']); + else if ($data['plugid'] == $this->getID() ) + { + foreach ( $data['options'] as $key => $option ) + { + if ( defined($option['description']) ) + { + $data['options'][$key]['description'] = constant($option['description']); + } + if ( $option['type'] == 'select' ) + { + foreach ( explode('|', $option['typeinfo']) as $option ) + { + if ( defined($option) ) + { + $data['options'][$key]['typeinfo'] = str_replace($option, constant($option), $data['options'][$key]['typeinfo']); + } } - } + } } } } + return; } -/* - * for translation - */ - static private function t($text,$array=array()) { - if (is_array($array)) { - $search = array(); - $replace = array(); - - foreach ($array as $key => $value){ - if (is_array($value)) { - continue; - } - $search[] = '<%'.preg_replace('/[^a-zA-Z0-9_]+/','',$key).'%>'; - $replace[] = $value; - } - } - return htmlspecialchars (str_replace($search, $replace, $text), ENT_QUOTES, _CHARSET); - } - - public function event_PreMediaUpload($data) { + public function event_PreMediaUpload(&$data) + { global $CONF, $manager; - if (!class_exists('MediaUtils', FALSE)) { + if ( !class_exists('MediaUtils', FALSE) ) + { return; } - if (MediaUtils::$blogid == 0) { + if ( MediaUtils::$blogid == 0 ) + { return; } - if ($this->getBlogOption(MediaUtils::$blogid, 'status') == 'no') { + if ( $this->getBlogOption(MediaUtils::$blogid, 'status') == 'no' ) + { return; } - if (0 == ($maxwidth = $this->getBlogOption(MediaUtils::$blogid, 'blog_maxwidth'))) { + if ( 0 == ($maxwidth = $this->getBlogOption(MediaUtils::$blogid, 'blog_maxwidth')) ) + { $maxwidth = $this->getOption('maxwidth'); } - if (0 == ($maxheight = $this->getBlogOption(MediaUtils::$blogid, 'blog_maxheight'))) { + if ( 0 == ($maxheight = $this->getBlogOption(MediaUtils::$blogid, 'blog_maxheight')) ) + { $maxheight = $this->getOption('maxheight'); } $path = basename($data['uploadfile']); $root = str_replace('/' . $path, '', $data['uploadfile']); - if (FALSE === ($medium = new MEDIUM($root, $path, MediaUtils::$prefix))) { + if ( FALSE === ($medium = new MEDIUM($root, $path, MediaUtils::$prefix)) ) + { return; } - if (!array_key_exists($medium->mime, MediaUtils::$image_mime) - || ($maxwidth >= $medium->width && $maxheight >= $medium->height)) { + if ( !array_key_exists($medium->mime, MediaUtils::$image_mime) + || ($maxwidth >= $medium->width && $maxheight >= $medium->height) ) + { return; } - if (FALSE === $medium->setResampledSize($maxwidth, $maxheight)) { + if ( FALSE === $medium->setResampledSize($maxwidth, $maxheight) ) + { return; } - if (!MediaUtils::storeResampledImage($root, $path, $medium)) { + if ( !MediaUtils::storeResampledImage($root, $path, $medium) ) + { return; } return; } - public function event_MediaUploadFormExtras() { + public function event_MediaUploadFormExtras() + { echo '' . "\n"; return; } diff --git a/NP_ImageLimitSize/imagelimitsize/english.php b/NP_ImageLimitSize/imagelimitsize/en_Latn_US.ISO-8859-1.php similarity index 90% rename from NP_ImageLimitSize/imagelimitsize/english.php rename to NP_ImageLimitSize/imagelimitsize/en_Latn_US.ISO-8859-1.php index c91173f..789de32 100755 --- a/NP_ImageLimitSize/imagelimitsize/english.php +++ b/NP_ImageLimitSize/imagelimitsize/en_Latn_US.ISO-8859-1.php @@ -1,8 +1,8 @@