3 * ImageLimitSize plugin for Nucleus CMS
\r
4 * Version 1.0.0 for PHP5
\r
5 * Written By Mocchi, Oct. 20, 2012
\r
6 * Original code was written by Kai Greve and maintained by shizuki and yamamoto
\r
7 * This plugin depends on NP_MediaUtils
\r
9 * This program is free software; you can redistribute it and/or
\r
10 * modify it under the terms of the GNU General Public License
\r
11 * as published by the Free Software Foundation; either version 3
\r
12 * of the License, or (at your option) any later version.
\r
15 class NP_ImageLimitSize extends NucleusPlugin
\r
17 public function getName() {return 'ImageLimitSize';}
\r
18 public function getAuthor() {return 'Mocchi, shizuki, yamamoto, Kai Greve';}
\r
19 public function getURL() {return 'http://japan.nucleuscms.org/wiki/plugins:imagelimitsize';}
\r
20 public function getVersion() {return '1.0.0';}
\r
21 public function getDescription() {return _NP_IMAGELIMITSIZE_01;}
\r
22 public function getPluginDep() {return array('NP_MediaUtils');}
\r
23 public function getMinNucleusVersion() {return 360;}
\r
24 public function supportsFeature($feature) { return in_array ($feature, array ('SqlTablePrefix', 'SqlApi'));}
\r
25 public function getEventList() {return array('PrePluginOptionsEdit', 'PreMediaUpload', 'MediaUploadFormExtras');}
\r
27 public function install()
\r
29 $this->createOption('maxwidth', '_NP_IMAGELIMITSIZE_02', 'text', '550', 'datatype=numerical');
\r
30 $this->createOption('maxheight', '_NP_IMAGELIMITSIZE_03', 'text', '0', 'datatype=numerical');
\r
31 $this->createBlogOption('status', '_NP_IMAGELIMITSIZE_04', 'yesno', 'yes');
\r
32 $this->createBlogOption('blog_maxwidth', '_NP_IMAGELIMITSIZE_05', 'text', '0', 'datatype=numerical');
\r
33 $this->createBlogOption('blog_maxheight', '_NP_IMAGELIMITSIZE_06', 'text', '0', 'datatype=numerical');
\r
37 public function uninstall()
\r
39 // plugin options are purged automatically when uninstalled.
\r
43 public function init()
\r
48 if ( class_exists('i18n', FALSE) )
\r
50 $locale = i18n::get_current_locale() . '.' . i18n::get_current_charset() . '.php';
\r
55 $language = preg_replace('#[/|\\\\]#', '', getLanguageName());
\r
56 if ( $language == 'japanese-euc' )
\r
58 $locale = 'ja_Jpan_JP.EUC-JP.php';
\r
60 else if ( $language = 'japanese-utf8' )
\r
62 $locale = 'ja_Jpan_JP.UTF-8.php';
\r
66 if ( !$locale || !file_exists($this->getDirectory() . $locale) )
\r
68 include($this->getDirectory() . 'en_Latn_US.ISO-8859-1.php');
\r
72 include($this->getDirectory() . $locale);
\r
81 public function event_PrePluginOptionsEdit(&$data)
\r
83 /* Old version do not support natively */
\r
84 if ( getNucleusVersion() < 400 )
\r
86 if ( $data['context'] != 'global' )
\r
88 foreach ( $data['options'] as $key => $option )
\r
90 if ( $option['pid'] == $this->getID() )
\r
92 if ( defined($option['description']) )
\r
94 $data['options'][$key]['description'] = constant($option['description']);
\r
96 if ( $option['type'] == 'select' )
\r
98 foreach ( explode('|', $option['typeinfo']) as $option )
\r
100 if ( defined($option) )
\r
102 $data['options'][$key]['typeinfo'] = str_replace($option, constant($option), $data['options'][$key]['typeinfo']);
\r
109 else if ($data['plugid'] == $this->getID() )
\r
111 foreach ( $data['options'] as $key => $option )
\r
113 if ( defined($option['description']) )
\r
115 $data['options'][$key]['description'] = constant($option['description']);
\r
117 if ( $option['type'] == 'select' )
\r
119 foreach ( explode('|', $option['typeinfo']) as $option )
\r
121 if ( defined($option) )
\r
123 $data['options'][$key]['typeinfo'] = str_replace($option, constant($option), $data['options'][$key]['typeinfo']);
\r
134 public function event_PreMediaUpload(&$data)
\r
136 global $CONF, $manager;
\r
138 if ( !class_exists('MediaUtils', FALSE) )
\r
143 if ( MediaUtils::$blogid == 0 )
\r
148 if ( $this->getBlogOption(MediaUtils::$blogid, 'status') == 'no' )
\r
153 if ( 0 == ($maxwidth = $this->getBlogOption(MediaUtils::$blogid, 'blog_maxwidth')) )
\r
155 $maxwidth = $this->getOption('maxwidth');
\r
158 if ( 0 == ($maxheight = $this->getBlogOption(MediaUtils::$blogid, 'blog_maxheight')) )
\r
160 $maxheight = $this->getOption('maxheight');
\r
163 $path = basename($data['uploadfile']);
\r
164 $root = str_replace('/' . $path, '', $data['uploadfile']);
\r
166 if ( FALSE === ($medium = new MEDIUM($root, $path, MediaUtils::$prefix)) )
\r
171 if ( !array_key_exists($medium->mime, MediaUtils::$image_mime)
\r
172 || ($maxwidth >= $medium->width && $maxheight >= $medium->height) )
\r
177 if ( FALSE === $medium->setResampledSize($maxwidth, $maxheight) )
\r
182 if ( !MediaUtils::storeResampledImage($root, $path, $medium) )
\r
189 public function event_MediaUploadFormExtras()
\r
191 echo '<input type="hidden" name="blogid" value="' . MediaUtils::$blogid . '" />' . "\n";
\r