3 * ImprovedMedia plugin for Nucleus CMS
\r
4 * Version 3.0.1 for PHP5
\r
5 * Written By Mocchi, Feb.28, 2010
\r
7 * This program is free software; you can redistribute it and/or
\r
8 * modify it under the terms of the GNU General Public License
\r
9 * as published by the Free Software Foundation; either version 3
\r
10 * of the License, or (at your option) any later version.
\r
13 class NP_ImprovedMedia extends NucleusPlugin {
\r
15 private $baseUrl = ''; //string
\r
17 private $blog = FALSE; //object
\r
19 private $blogid = 1; //integer
\r
22 public function __construct() {
\r
24 $this->baseUrl = str_replace($CONF['AdminURL'], '', $this->getAdminURL());
\r
25 self::setBlogObject();
\r
30 public function getName() { return 'ImprovedMedia'; }
\r
32 public function getAuthor() { return 'Mocchi'; }
\r
34 public function getURL() { return 'http://japan.nucleuscms.org/wiki/plugins:improvedmedia'; }
\r
36 public function getVersion() { return '3.0.1 for PHP5'; }
\r
38 public function getMinNucleusVersion() { return 223; }
\r
40 public function getDescription() { return _IM_DESCRIPTION; }
\r
43 public function supportsFeature($what) {
\r
47 case 'SqlTablePrefix':
\r
55 public function init() {
\r
56 $language = preg_replace( '#[/|\\\\]#', '', getLanguageName());
\r
57 if(file_exists($this->getDirectory() .'lang/' . $language.'.php'))
\r
58 include_once($this->getDirectory() . 'lang/' . $language.'.php');
\r
60 include_once($this->getDirectory() . 'lang/english.php');
\r
62 if($this->getOption('IM_EACHBLOGDIR') == 'yes')
\r
63 self::setDirectories();
\r
69 public function install() {
\r
70 $this->createOption('IM_PRIVATE', _IM_OPTION_PRIVATE , 'yesno', 'yes');
\r
71 $this->createOption('IM_ITEMDISPLAY', _IM_OPTION_ITEMDISPLAY , 'text', '10', 'datatype=numerical' );
\r
72 $this->createOption('IM_GREYBOX', _IM_OPTION_GREYBOX , 'yesno', 'no');
\r
73 $this->createOption('IM_EACHBLOGDIR', _IM_OPTION_EACHBLOGDIR , 'yesno', 'no');
\r
78 public function unInstall() {
\r
79 $this->deleteOption('IM_PRIVATE');
\r
80 $this->deleteOption('IM_ITEMDISPLAY');
\r
81 $this->deleteOption('IM_GREYBOX');
\r
82 $this->deleteOption('IM_EACHBLOGDIR');
\r
87 public function getEventList() {
\r
88 return array('InitSkinParse', 'AdminPrePageHead', 'BookmarkletExtraHead');
\r
92 public function doAction($type) {
\r
94 if(!class_exists('MEDIA', FALSE))
\r
95 include($DIR_LIBS . 'MEDIA.php');
\r
96 if(!class_exists('MEDIA_VARIABLES', FALSE))
\r
97 include($this->getDirectory() . 'MEDIA_VARIABLES.php');
\r
98 if(!class_exists('MEDIA_CONTROL', FALSE))
\r
99 include($this->getDirectory() . 'MEDIA_CONTROL.php');
\r
101 new MEDIA_CONTROL($this);
\r
106 public function doSkinVar($data, $place) {
\r
107 global $CONF, $member;
\r
108 if($member->isLoggedIn()) {
\r
109 if($this->getOption('IM_GREYBOX') == 'yes') {
\r
112 echo '<script type="text/javascript">' . "\n" .
\r
114 ' var GB_ROOT_DIR = "' . $CONF['AdminURL'] . $this->baseUrl . 'greybox/";' . "\n" .
\r
116 '</script>' . "\n" .
\r
117 '<script type="text/javascript" src="' . $CONF['AdminURL'] . $this->baseUrl . 'greybox/AJS.js"></script>' . "\n" .
\r
118 '<script type="text/javascript" src="' . $CONF['AdminURL'] . $this->baseUrl . 'greybox/AJS_fx.js"></script>' . "\n" .
\r
119 '<script type="text/javascript" src="' . $CONF['AdminURL'] . $this->baseUrl . 'greybox/gb_scripts.js"></script>' . "\n".
\r
120 '<link href="' . $CONF['AdminURL'] . $this->baseUrl . 'greybox/gb_styles.css" rel="stylesheet" type="text/css" />' . "\n";
\r
123 echo '<a href="' . $CONF['ActionURL'] . '?action=plugin&name=ImprovedMedia&astool=1&blogid=' . $this->blogid . '" onclick="GB_showCenter(\'Media Control' . _IM_HEADER_TEXT . '\',this.href,540,600); return false;">' . _IM_ANCHOR_TEXT . '</a>';
\r
129 if($place == 'anchor') {
\r
130 echo '<a href="' . $CONF['ActionURL'] . '?action=plugin&name=ImprovedMedia&astool=1&blogid=' . $this->blogid . '" onclick="window.open(this.href , \'MediaControl\' , \'width=600 , height=600, scrollbars=1\'); return false;">' . _IM_ANCHOR_TEXT . '</a>';
\r
138 public function event_InitSkinParse(&$data) {
\r
143 public function event_BookmarkletExtraHead(&$data) {
\r
144 self::addHeader($data['extrahead']);
\r
149 public function event_AdminPrePageHead(&$data) {
\r
150 if(($data['action'] == 'createitem') || ($data['action'] == 'itemedit'))
\r
151 self::addHeader($data['extrahead']);
\r
156 private function addHeader(&$extrahead) {
\r
159 if($this->getOption('IM_GREYBOX') == 'yes') {
\r
160 $extrahead .= '<script type="text/javascript">' ."\n" .
\r
162 'function addMedia() {' ."\n".
\r
163 ' GB_showCenter(\'Media Control' . _IM_HEADER_TEXT . '\',\'' . $CONF['ActionURL'] . '?action=plugin&name=ImprovedMedia&mode=upload_select&astool=0&blogid=' . $this->blogid . '\',540,600);' . "\n" .
\r
166 $extrahead .= '<script type="text/javascript">' ."\n" .
\r
168 'function addMedia() {' ."\n".
\r
169 ' window.open(\'' . $CONF['ActionURL'] . '?action=plugin&name=ImprovedMedia&mode=upload_select&astool=0&blogid=' . $this->blogid . '\' , \'MediaControl\' , \'width=600 , height=600, scrollbars=1\');' . "\n" .
\r
172 $extrahead .= 'function includeImage(collection, filename, type, width, height, text) {' . "\n" .
\r
173 ' var fullName;' . "\n" .
\r
174 ' if(isNaN(collection) || (nucleusAuthorId != collection)) {' . "\n" .
\r
175 ' fullName = collection + \'/\' + filename;' . "\n" .
\r
176 ' } else {' . "\n" .
\r
177 ' fullName = filename;' . "\n" .
\r
179 ' var replaceBy;' . "\n" .
\r
180 ' switch(type) {' . "\n" .
\r
181 ' case \'popup\':' . "\n" .
\r
182 ' replaceBy = \'<%popup(\' + fullName + \'|\'+width+\'|\'+height+\'|\' + text +\')%>\';' . "\n" .
\r
184 ' case \'inline\':' . "\n" .
\r
185 ' default:' . "\n" .
\r
186 ' replaceBy = \'<%image(\' + fullName + \'|\'+width+\'|\'+height+\'|\' + text +\')%>\';' . "\n" .
\r
188 ' insertAtCaret(replaceBy);' . "\n" .
\r
189 ' updAllPreviews();' . "\n" .
\r
192 'function includeOtherMedia(collection, filename, text) {' . "\n" .
\r
193 ' var fullName;' . "\n" .
\r
194 ' if(isNaN(collection) || (nucleusAuthorId != collection)) {' . "\n" .
\r
195 ' fullName = collection + \'/\' + filename;' . "\n" .
\r
196 ' } else {' . "\n" .
\r
197 ' fullName = filename;' . "\n" .
\r
199 ' var replaceBy = \'<%media(\' + fullName + \'|\' + text +\')%>\';' . "\n" .
\r
200 ' insertAtCaret(replaceBy);' . "\n" .
\r
201 ' updAllPreviews();' . "\n" .
\r
206 if($this->getOption('IM_GREYBOX') == 'yes') {
\r
207 $extrahead .= '<script type="text/javascript">' . "\n" .
\r
209 ' var GB_ROOT_DIR = "' . $CONF['AdminURL'] . $this->baseUrl . 'greybox/";' . "\n" .
\r
211 '</script>' . "\n" .
\r
212 '<script type="text/javascript" src="' . $CONF['AdminURL'] . $this->baseUrl . 'greybox/AJS.js"></script>' . "\n" .
\r
213 '<script type="text/javascript" src="' . $CONF['AdminURL'] . $this->baseUrl . 'greybox/AJS_fx.js"></script>' . "\n" .
\r
214 '<script type="text/javascript" src="' . $CONF['AdminURL'] . $this->baseUrl . 'greybox/gb_scripts.js"></script>' . "\n" .
\r
215 '<link href="' . $CONF['AdminURL'] . $this->baseUrl . 'greybox/gb_styles.css" rel="stylesheet" type="text/css" />' . "\n";
\r
221 private function setBlogObject() {
\r
222 global $manager, $blog;
\r
224 $blogid = intRequestVar('blogid');
\r
225 $itemid = intRequestVar('itemid');
\r
228 $this->blog =& $blog;
\r
229 $this->blogid =& $blog->getID();
\r
233 if($blogid && $manager->existsBlogID($blogid)) {
\r
234 $this->blog =& $manager->getBlog($blogid);
\r
235 $this->blogid =& $this->blog->getID();
\r
239 if($itemid && $manager->existsItem($itemid, 1, 1)) {
\r
240 $this->blog =& $manager->getBlog(getBlogIDFromItemID($itemid));
\r
241 $this->blogid =& $this->blog->getID();
\r
247 private function setDirectories() {
\r
248 global $DIR_MEDIA, $CONF;
\r
253 $blog =& $this->blog;
\r
254 $bshortname =& $blog->getShortName();
\r
256 if($this->blogid !== 1) {
\r
257 $DIR_MEDIA = preg_replace('#(.+)/(.+)?/$#',"$1/$bshortname/$2/",$DIR_MEDIA);
\r
258 $CONF['MediaURL'] = preg_replace( '#(.+)/(.+)?/$#' , "$1/$bshortname/$2/" , $CONF['MediaURL'] );
\r
264 public function & getBlog() {
\r
265 return $this->blog;
\r
269 public function & getBlogid() {
\r
270 return $this->blogid;
\r
274 public function getBaseURL() {
\r
275 return $this->baseUrl;
\r