3 * ImageLimitSize plugin for Nucleus CMS
\r
4 * Version 0.9.6 (1.0 RC2) for PHP5
\r
5 * Written By Mocchi, Apr. 04, 2011
\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
16 public function getName() {return 'ImageLimitSize';}
\r
17 public function getAuthor() {return 'Mocchi, shizuki, yamamoto, Kai Greve';}
\r
18 public function getURL() {return 'http://japan.nucleuscms.org/wiki/plugins:imagelimitsize';}
\r
19 public function getVersion() {return '0.9.6 (1.0 RC2)';}
\r
20 public function getDescription() {return _NP_IMAGELIMITSIZE_01;}
\r
21 public function getPluginDep() {return array('NP_MediaUtils');}
\r
22 public function getMinNucleusVersion() {return 360;}
\r
23 public function supportsFeature($feature) { return in_array ($feature, array ('SqlTablePrefix', 'SqlApi'));}
\r
24 public function getEventList() {return array('PrePluginOptionsEdit', 'PreMediaUpload', 'MediaUploadFormExtras');}
\r
26 public function install() {
\r
27 $this->createOption('maxwidth', '_NP_IMAGELIMITSIZE_02', 'text', '550', 'datatype=numerical');
\r
28 $this->createOption('maxheight', '_NP_IMAGELIMITSIZE_03', 'text', '0', 'datatype=numerical');
\r
29 $this->createBlogOption('status', '_NP_IMAGELIMITSIZE_04', 'yesno', 'yes');
\r
30 $this->createBlogOption('blog_maxwidth', '_NP_IMAGELIMITSIZE_05', 'text', '0', 'datatype=numerical');
\r
31 $this->createBlogOption('blog_maxheight', '_NP_IMAGELIMITSIZE_06', 'text', '0', 'datatype=numerical');
\r
35 public function uninstall() {
\r
36 // plugin options are purged automatically when uninstalled.
\r
40 public function init() {
\r
41 if((string)$_REQUEST['action'] == 'pluginlist' && !defined('_NP_IMAGELIMITSIZE_01')) {
\r
42 $language = preg_replace('#[/|\\\\]#', '', getLanguageName());
\r
43 if (file_exists($this->getDirectory() . $language.'.php')) {
\r
44 include($this->getDirectory() . $language.'.php');
\r
46 include($this->getDirectory() . 'english.php');
\r
55 public function event_PrePluginOptionsEdit ($data) {
\r
56 if(!defined('_NP_IMAGELIMITSIZE_01')) {
\r
57 $language = preg_replace('#[/|\\\\]#', '', getLanguageName());
\r
58 if (file_exists($this->getDirectory() . $language.'.php')) {
\r
59 include($this->getDirectory() . $language.'.php');
\r
61 include($this->getDirectory() . 'english.php');
\r
64 if ($data['context'] != 'global') {
\r
65 foreach($data['options'] as $key => $option) {
\r
66 if ($option['pid'] == $this->getID()) {
\r
67 if (defined($option['description'])) {
\r
68 $data['options'][$key]['description'] = constant($option['description']);
\r
70 if ($option['type'] == 'select') {
\r
71 foreach (explode('|', $option['typeinfo']) as $option) {
\r
72 if (defined($option)) {
\r
73 $data['options'][$key]['typeinfo'] = str_replace($option, constant($option), $data['options'][$key]['typeinfo']);
\r
79 } else if ($data['plugid'] == $this->getID()) {
\r
80 foreach($data['options'] as $key => $option){
\r
81 if (defined($option['description'])) {
\r
82 $data['options'][$key]['description'] = constant($option['description']);
\r
84 if ($option['type'] == 'select') {
\r
85 foreach (explode('|', $option['typeinfo']) as $option) {
\r
86 if (defined($option)) {
\r
87 $data['options'][$key]['typeinfo'] = str_replace($option, constant($option), $data['options'][$key]['typeinfo']);
\r
99 static private function t($text,$array=array()) {
\r
100 if (is_array($array)) {
\r
102 $replace = array();
\r
104 foreach ($array as $key => $value){
\r
105 if (is_array($value)) {
\r
108 $search[] = '<%'.preg_replace('/[^a-zA-Z0-9_]+/','',$key).'%>';
\r
109 $replace[] = $value;
\r
112 return htmlspecialchars (str_replace($search, $replace, $text), ENT_QUOTES, _CHARSET);
\r
115 public function event_PreMediaUpload($data) {
\r
116 global $CONF, $manager;
\r
118 if (!class_exists('MediaUtils', FALSE)) {
\r
122 if (MediaUtils::$blogid == 0) {
\r
126 if ($this->getBlogOption(MediaUtils::$blogid, 'status') == 'no') {
\r
130 if (0 == ($maxwidth = $this->getBlogOption(MediaUtils::$blogid, 'blog_maxwidth'))) {
\r
131 $maxwidth = $this->getOption('maxwidth');
\r
134 if (0 == ($maxheight = $this->getBlogOption(MediaUtils::$blogid, 'blog_maxheight'))) {
\r
135 $maxheight = $this->getOption('maxheight');
\r
138 $path = basename($data['uploadfile']);
\r
139 $root = str_replace('/' . $path, '', $data['uploadfile']);
\r
141 if (FALSE === ($medium = new MEDIUM($root, $path, MediaUtils::$prefix))) {
\r
145 if (!array_key_exists($medium->mime, MediaUtils::$image_mime)
\r
146 || ($maxwidth >= $medium->width && $maxheight >= $medium->height)) {
\r
150 if (FALSE === $medium->setResampledSize($maxwidth, $maxheight)) {
\r
154 if (!MediaUtils::storeResampledImage($root, $path, $medium)) {
\r
160 public function event_MediaUploadFormExtras() {
\r
161 echo '<input type="hidden" name="blogid" value="' . MediaUtils::$blogid . '" />' . "\n";
\r