<?php\r
/**\r
* ImageLimitSize plugin for Nucleus CMS\r
- * Version 0.9.6 (1.0 RC2) for PHP5\r
- * Written By Mocchi, Apr. 04, 2011\r
+ * Version 1.0.0 for PHP5\r
+ * Written By Mocchi, Oct. 20, 2012\r
* Original code was written by Kai Greve and maintained by shizuki and yamamoto\r
* This plugin depends on NP_MediaUtils\r
* \r
* of the License, or (at your option) any later version.\r
*/\r
\r
-class NP_ImageLimitSize extends NucleusPlugin {\r
+class NP_ImageLimitSize extends NucleusPlugin\r
+{\r
public function getName() {return 'ImageLimitSize';}\r
public function getAuthor() {return 'Mocchi, shizuki, yamamoto, Kai Greve';}\r
public function getURL() {return 'http://japan.nucleuscms.org/wiki/plugins:imagelimitsize';}\r
- public function getVersion() {return '0.9.6 (1.0 RC2)';}\r
+ public function getVersion() {return '1.0.0';}\r
public function getDescription() {return _NP_IMAGELIMITSIZE_01;}\r
public function getPluginDep() {return array('NP_MediaUtils');}\r
public function getMinNucleusVersion() {return 360;}\r
public function supportsFeature($feature) { return in_array ($feature, array ('SqlTablePrefix', 'SqlApi'));}\r
public function getEventList() {return array('PrePluginOptionsEdit', 'PreMediaUpload', 'MediaUploadFormExtras');}\r
\r
- public function install() {\r
+ public function install()\r
+ {\r
$this->createOption('maxwidth', '_NP_IMAGELIMITSIZE_02', 'text', '550', 'datatype=numerical');\r
$this->createOption('maxheight', '_NP_IMAGELIMITSIZE_03', 'text', '0', 'datatype=numerical');\r
$this->createBlogOption('status', '_NP_IMAGELIMITSIZE_04', 'yesno', 'yes');\r
return;\r
}\r
\r
- public function uninstall() {\r
+ public function uninstall()\r
+ {\r
// plugin options are purged automatically when uninstalled.\r
return;\r
}\r
\r
- public function init() {\r
- if((string)$_REQUEST['action'] == 'pluginlist' && !defined('_NP_IMAGELIMITSIZE_01')) {\r
+ public function init()\r
+ {\r
+ $locale = '';\r
+ \r
+ /* new API */\r
+ if ( class_exists('i18n', FALSE) )\r
+ {\r
+ $locale = i18n::get_current_locale() . '.' . i18n::get_current_charset() . '.php';\r
+ }\r
+ /* old API */\r
+ else\r
+ {\r
$language = preg_replace('#[/|\\\\]#', '', getLanguageName());\r
- if (file_exists($this->getDirectory() . $language.'.php')) {\r
- include($this->getDirectory() . $language.'.php');\r
- } else {\r
- include($this->getDirectory() . 'english.php');\r
+ if ( $language == 'japanese-euc' )\r
+ {\r
+ $locale = 'ja_Jpan_JP.EUC-JP.php';\r
+ }\r
+ else if ( $language = 'japanese-utf8' )\r
+ {\r
+ $locale = 'ja_Jpan_JP.UTF-8.php';\r
}\r
}\r
+ \r
+ if ( !$locale || !file_exists($this->getDirectory() . $locale) )\r
+ {\r
+ include($this->getDirectory() . 'en_Latn_US.ISO-8859-1.php');\r
+ }\r
+ else\r
+ {\r
+ include($this->getDirectory() . $locale);\r
+ }\r
+ \r
return;\r
}\r
\r
-/*\r
- * for translation\r
- */\r
- public function event_PrePluginOptionsEdit ($data) {\r
- if(!defined('_NP_IMAGELIMITSIZE_01')) {\r
- $language = preg_replace('#[/|\\\\]#', '', getLanguageName());\r
- if (file_exists($this->getDirectory() . $language.'.php')) {\r
- include($this->getDirectory() . $language.'.php');\r
- } else {\r
- include($this->getDirectory() . 'english.php');\r
- }\r
- }\r
- if ($data['context'] != 'global') {\r
- foreach($data['options'] as $key => $option) {\r
- if ($option['pid'] == $this->getID()) {\r
- if (defined($option['description'])) {\r
- $data['options'][$key]['description'] = constant($option['description']);\r
- }\r
- if ($option['type'] == 'select') {\r
- foreach (explode('|', $option['typeinfo']) as $option) {\r
- if (defined($option)) {\r
- $data['options'][$key]['typeinfo'] = str_replace($option, constant($option), $data['options'][$key]['typeinfo']);\r
+ /*\r
+ * for translation\r
+ */\r
+ public function event_PrePluginOptionsEdit(&$data)\r
+ {\r
+ /* Old version do not support natively */\r
+ if ( getNucleusVersion() < 400 )\r
+ {\r
+ if ( $data['context'] != 'global' )\r
+ {\r
+ foreach ( $data['options'] as $key => $option )\r
+ {\r
+ if ( $option['pid'] == $this->getID() )\r
+ {\r
+ if ( defined($option['description']) )\r
+ {\r
+ $data['options'][$key]['description'] = constant($option['description']);\r
+ }\r
+ if ( $option['type'] == 'select' )\r
+ {\r
+ foreach ( explode('|', $option['typeinfo']) as $option )\r
+ {\r
+ if ( defined($option) )\r
+ {\r
+ $data['options'][$key]['typeinfo'] = str_replace($option, constant($option), $data['options'][$key]['typeinfo']);\r
+ }\r
}\r
}\r
}\r
}\r
}\r
- } else if ($data['plugid'] == $this->getID()) {\r
- foreach($data['options'] as $key => $option){\r
- if (defined($option['description'])) {\r
- $data['options'][$key]['description'] = constant($option['description']);\r
- }\r
- if ($option['type'] == 'select') {\r
- foreach (explode('|', $option['typeinfo']) as $option) {\r
- if (defined($option)) {\r
- $data['options'][$key]['typeinfo'] = str_replace($option, constant($option), $data['options'][$key]['typeinfo']);\r
+ else if ($data['plugid'] == $this->getID() )\r
+ {\r
+ foreach ( $data['options'] as $key => $option )\r
+ {\r
+ if ( defined($option['description']) )\r
+ {\r
+ $data['options'][$key]['description'] = constant($option['description']);\r
+ }\r
+ if ( $option['type'] == 'select' )\r
+ {\r
+ foreach ( explode('|', $option['typeinfo']) as $option )\r
+ {\r
+ if ( defined($option) )\r
+ {\r
+ $data['options'][$key]['typeinfo'] = str_replace($option, constant($option), $data['options'][$key]['typeinfo']);\r
+ }\r
}\r
- }\r
+ }\r
}\r
}\r
}\r
+ \r
return;\r
}\r
\r
-/*\r
- * for translation\r
- */\r
- static private function t($text,$array=array()) {\r
- if (is_array($array)) {\r
- $search = array();\r
- $replace = array();\r
- \r
- foreach ($array as $key => $value){\r
- if (is_array($value)) {\r
- continue;\r
- }\r
- $search[] = '<%'.preg_replace('/[^a-zA-Z0-9_]+/','',$key).'%>';\r
- $replace[] = $value;\r
- }\r
- }\r
- return htmlspecialchars (str_replace($search, $replace, $text), ENT_QUOTES, _CHARSET);\r
- }\r
- \r
- public function event_PreMediaUpload($data) {\r
+ public function event_PreMediaUpload(&$data)\r
+ {\r
global $CONF, $manager;\r
\r
- if (!class_exists('MediaUtils', FALSE)) {\r
+ if ( !class_exists('MediaUtils', FALSE) )\r
+ {\r
return;\r
}\r
\r
- if (MediaUtils::$blogid == 0) {\r
+ if ( MediaUtils::$blogid == 0 )\r
+ {\r
return;\r
}\r
\r
- if ($this->getBlogOption(MediaUtils::$blogid, 'status') == 'no') {\r
+ if ( $this->getBlogOption(MediaUtils::$blogid, 'status') == 'no' )\r
+ {\r
return;\r
}\r
\r
- if (0 == ($maxwidth = $this->getBlogOption(MediaUtils::$blogid, 'blog_maxwidth'))) {\r
+ if ( 0 == ($maxwidth = $this->getBlogOption(MediaUtils::$blogid, 'blog_maxwidth')) )\r
+ {\r
$maxwidth = $this->getOption('maxwidth');\r
}\r
\r
- if (0 == ($maxheight = $this->getBlogOption(MediaUtils::$blogid, 'blog_maxheight'))) {\r
+ if ( 0 == ($maxheight = $this->getBlogOption(MediaUtils::$blogid, 'blog_maxheight')) )\r
+ {\r
$maxheight = $this->getOption('maxheight');\r
}\r
\r
$path = basename($data['uploadfile']);\r
$root = str_replace('/' . $path, '', $data['uploadfile']);\r
\r
- if (FALSE === ($medium = new MEDIUM($root, $path, MediaUtils::$prefix))) {\r
+ if ( FALSE === ($medium = new MEDIUM($root, $path, MediaUtils::$prefix)) )\r
+ {\r
return;\r
}\r
\r
- if (!array_key_exists($medium->mime, MediaUtils::$image_mime)\r
- || ($maxwidth >= $medium->width && $maxheight >= $medium->height)) {\r
+ if ( !array_key_exists($medium->mime, MediaUtils::$image_mime)\r
+ || ($maxwidth >= $medium->width && $maxheight >= $medium->height) )\r
+ {\r
return;\r
}\r
\r
- if (FALSE === $medium->setResampledSize($maxwidth, $maxheight)) {\r
+ if ( FALSE === $medium->setResampledSize($maxwidth, $maxheight) )\r
+ {\r
return;\r
}\r
\r
- if (!MediaUtils::storeResampledImage($root, $path, $medium)) {\r
+ if ( !MediaUtils::storeResampledImage($root, $path, $medium) )\r
+ {\r
return;\r
}\r
return;\r
}\r
\r
- public function event_MediaUploadFormExtras() {\r
+ public function event_MediaUploadFormExtras()\r
+ {\r
echo '<input type="hidden" name="blogid" value="' . MediaUtils::$blogid . '" />' . "\n";\r
return;\r
}\r