OSDN Git Service

ADD: プラグイン「NP_Medium」
authorsakamocchi <o-takashi@sakamocchi.jp>
Sun, 27 May 2012 13:06:14 +0000 (22:06 +0900)
committersakamocchi <o-takashi@sakamocchi.jp>
Sun, 27 May 2012 13:06:14 +0000 (22:06 +0900)
メディアファイルを管理するための仕組みであるmedia.phpの代替となるプラグインを追加。
これによりmedia.phpとそれが参照するスタイルシート、JavaScriptをすべてコア機能から取り去ることができる。

プラグインはJavaScriptのmediumオブジェクトにすべてのコードを入れている。プラグイン呼び出しは、デフォルト管理画面用スキンのedit.jsのaddMedia()で行う。addMedia()はmediumオブジェクトが定義されていたらmedium.addMedia()を、そうでなければ新たにウィンドウを開き、nucleusMediaPopupURLをロードする。この条件分岐により下位互換性を維持する。

14 files changed:
install/index.php
nucleus/plugins/NP_Medium.php [new file with mode: 0644]
nucleus/plugins/medium/MediumActions.php [new file with mode: 0644]
nucleus/plugins/medium/locales/en_Latn_US.UTF-8.php [new file with mode: 0644]
nucleus/plugins/medium/scripts/medium.js [new file with mode: 0644]
nucleus/plugins/medium/skins/choose.skn [new file with mode: 0644]
nucleus/plugins/medium/skins/error.skn [new file with mode: 0644]
nucleus/plugins/medium/skins/login.skn [new file with mode: 0644]
nucleus/plugins/medium/skins/pagefoot.skn [new file with mode: 0644]
nucleus/plugins/medium/skins/pagehead.skn [new file with mode: 0644]
nucleus/plugins/medium/skins/select.skn [new file with mode: 0644]
nucleus/plugins/medium/styles/medium.css [new file with mode: 0644]
skins/admin/bookmarklet/javascripts/edit.js
skins/admin/default/javascripts/edit.js

index 03d65f9..01f0d0a 100644 (file)
@@ -43,7 +43,7 @@ if ( version_compare(PHP_VERSION, '5.3.0', '<') )
 }\r
 \r
 /* default installed plugins and skins */\r
-$aConfPlugsToInstall = array('NP_SecurityEnforcer', 'NP_SkinFiles');\r
+$aConfPlugsToInstall = array('NP_SecurityEnforcer', 'NP_SkinFiles', 'NP_Medium');\r
 $aConfSkinsToImport = array('atom', 'rss2.0', 'rsd', 'default', 'admin/default', 'admin/bookmarklet');\r
 \r
 // Check if some important files\r
diff --git a/nucleus/plugins/NP_Medium.php b/nucleus/plugins/NP_Medium.php
new file mode 100644 (file)
index 0000000..b35354c
--- /dev/null
@@ -0,0 +1,428 @@
+<?php
+class NP_Medium extends NucleusPlugin
+{
+       private $skin = '';
+       
+       public $type = '';
+       
+       public $collection = '';
+       public $description = '';
+       public $filter = '';
+       public $message = '';
+       
+       public $amount = 0;
+       public $media = array();
+       public $offset = 0;
+       public $prev = 0;
+       public $next = 0;
+       
+       public function getName()
+       {
+               return 'Medium';
+       }
+
+       public function getAuthor()
+       {
+               return 'Sakamoto Takashi';
+       }
+
+       public function getURL()
+       {
+               return '';
+       }
+
+       public function getVersion()
+       {
+               return '0.9(beta)';
+       }
+
+       public function getMinNucleusVersion()
+       {
+               return '400';
+       }
+
+       public function getDescription()
+       {
+               return _MEDIUM_DESC;
+       }
+
+       public function supportsFeature($what)
+       {
+               return ( $what == 'SqlTablePrefix' );
+       }
+
+       public function getEventList()
+       {
+               return array('AdminPrePageHead', 'AdminTemplateExtraFields');
+       }
+
+       public function init()
+       {
+               // include translation file for this plugin
+               if ( file_exists($this->getDirectory() . 'locales/' . i18n::get_current_locale() . '.' . i18n::get_current_charset() . '.php') )
+               {
+                       include_once($this->getDirectory() . 'locales/' . i18n::get_current_locale() . '.' . i18n::get_current_charset() . '.php');
+               }
+               else
+               {
+                       include_once($this->getDirectory() . 'locales/en_Latn_US.UTF-8.php');
+               }
+               return;
+       }
+       
+       public function install()
+       {
+               $this->createOption('collectionlist_head', 'NP_MEDIUM_COLLECTIONLIST_HEAD', 'textarea',
+                         "<label for=\"media_collection\">"
+                       . "<%text(_MEDIA_COLLECTION_LABEL)%>"
+                       . "</label>"
+                       . "<select name=\"collection\" id=\"media_collection\">\n");
+               
+               $this->createOption('collectionlist_body', 'NP_MEDIUM_COLLECTIONLIST_BODY', 'textarea',
+                         "<option value=\"<%name%>\" <%selected%>>"
+                       . "<%desc%>"
+                       . "</option>\n");
+                       
+               $this->createOption('collectionlist_foot', 'NP_MEDIUM_COLLECTIONLIST_FOOT', 'textarea',
+                       "</select>\n");
+               
+               $this->createOption('medialist_head', 'NP_MEDIUM_MEDIALIST_HEAD', 'textarea',
+                         "<table frame=\"box\" rules=\"frame\" sumary=\"<%text(Media List)%>\">\n"
+                       . "<caption><%text(_MEDIA_COLLECTION_LABEL)%> <%description%></caption>\n"
+                       . "<thead>\n"
+                       . "<tr>\n"
+                       . "<th><%text(_MEDIA_MODIFIED)%></th>\n"
+                       . "<th><%text(_MEDIA_FILENAME)%></th>\n"
+                       . "<th><%text(_MEDIA_DIMENSIONS)%></th>\n"
+                       . "</tr>\n"
+                       . "</thead>\n"
+                       . "<tbody>\n");
+               
+               $this->createOption('medialist_body_image', 'NP_MEDIUM_MEDIALIST_BODY_IMAGE', 'textarea',
+                         "<tr>\n"
+                       . "<td><%timestamp%></td>\n"
+                       . "<td>\n"
+                       . "<a href=\"<%mediumurl%>\" onclick=\"medium.chooseImage('<%collection%>', '<%filename%>', <%width%>, <%height%>);\" title=\"<%filename%>\">\n"
+                       . "<%shortfilename%>\n"
+                       . "</a>\n"
+                       . "(\n"
+                       . "<a href=\"<%mediumurl%>\" onclick=\"window.open(this.href); return false;\" title=\"<%text(_MEDIA_VIEW_TT%>\">\n"
+                       . "<%text(_MEDIA_VIEW)%>\n"
+                       . "</a>\n"
+                       . ")\n"
+                       . "</td>\n"
+                       . "<td><%width%> x <%height%></td>\n"
+                       . "</tr>\n");
+               
+               $this->createOption('medialist_body_other', 'NP_MEDIUM_MEDIALIST_BODY_OTHER', 'textarea',
+                         "<tr>\n"
+                       . "<td><%timestamp%></td>\n"
+                       . "<td>\n"
+                       . "<a href=\"<%mediumurl%>\" onclick=\"medium.chooseOther('<%collection%>', '<%filename%>');\" title=\"<%filename%>\">\n"
+                       . "<%shortfilename%>\n"
+                       . "</a>\n"
+                       . "</td>\n"
+                       . "<td><%size%> KB</td>\n"
+                       . "</tr>\n");
+               
+               $this->createOption('medialist_foot', 'NP_MEDIUM_MEDIALIST_FOOT', 'textarea',
+                         "</tbody>\n"
+                       . "</table>\n");
+               
+               $this->createOption('medialist_blank', 'NP_MEDIUM_MEDIALIST_BLANK', 'textarea',
+                         "<p>Nothing</p>\n");
+               
+               return;
+       }
+       
+       public function event_AdminPrePageHead($data)
+       {
+               global $CONF;
+               
+               if ( !in_array($data['action'], array('createitem', 'itemedit')) )
+               {
+                       return;
+               }
+               
+               $data['extrahead'] .= "<script type=\"text/javascript\" src=\"{$CONF['PluginURL']}/medium/scripts/medium.js\"></script>\n"
+                                   . "<script type=\"text/javascript\">\n"
+                                   . " medium.url = '{$CONF['ActionURL']}?action=plugin&name=medium';\n"
+                                   . '</script>'."\n";
+               
+               return;
+       }
+       
+       public function doAction($type)
+       {
+               global $CONF, $DIR_MEDIA, $manager, $member;
+               
+               /*
+                * defines how much media items will be shown per page. You can override this
+                * in config.php if you like. (changing it in config.php instead of here will
+                * allow your settings to be kept even after a Nucleus upgrade)
+                */
+               $CONF['MediaPerPage'] = 10;
+               
+               /* include all classes */
+               if ( !class_exists('Media', FALSE) )
+               {
+                       include_libs('MEDIA.php', FALSE, FALSE);
+               }
+               
+               /* include all classes */
+               if ( !class_exists('BaseActions', FALSE) )
+               {
+                       include_libs('BaseActions.php', FALSE, FALSE);
+               }
+               
+               if ( !class_exists('MediumActions', FALSE) )
+               {
+                       include($this->getDirectory() . 'MediumActions.php');
+               }
+               
+               /* get skin object */
+               $skinid = $CONF['AdminSkin'];
+               if ( !Skin::existsID($skinid) )
+               {
+                       echo _ERROR_SKIN;
+                       exit;
+               }
+               $this->skin = new Skin($skinid, 'MediumActions', 'MediumSkin');
+               
+               /* user needs to be logged in to use this */
+               if ( !$member->isLoggedIn() )
+               {
+                       $this->login();
+                       exit;
+               }
+               
+               /* check if member is on at least one teamlist */
+               $query = 'SELECT * FROM %s WHERE tmember=%d;';
+               $query = sprintf($query, sql_table('team'), $member->getID());
+               $teams = DB::getResult($query);
+               if ( $teams->rowCount() == 0 && !$member->isAdmin() )
+               {
+                       $this->error(_ERROR_DISALLOWEDUPLOAD);
+                       return;
+               }
+               
+               /* avoid directory travarsal and accessing invalid directory */
+               $this->collection = requestVar('collection');
+               $this->description = $this->collection;
+               if ( !$this->collection || $this->collection == $member->getID()
+                  || !@is_dir("{$DIR_MEDIA}{$this->collection}") )
+               {
+                       $this->collection = $member->getID();
+                       $this->description = PRIVATE_COLLECTION;
+               }
+               else if ( !Media::isValidCollection($this->collection) )
+               {
+                       $this->error(_ERROR_DISALLOWED);
+                       return;
+               }
+               
+               /* check type */
+               if ( !in_array($type, array('select', 'choose', 'upload')) )
+               {
+                       $type = 'select';
+               }
+               
+               /* check ticket */
+               $needless_to_check = array('select', 'choose');
+               if ( !in_array($type, $needless_to_check) )
+               {
+                       if ( !$manager->checkTicket() )
+                       {
+                               $this->error(_ERROR_BADTICKET);
+                       return;
+                       }
+               }
+               
+               /* processing */
+               switch ( $type )
+               {
+               case 'choose':
+                       if ( !$member->isAdmin() && !$CONF['AllowUpload'] )
+                       {
+                               $this->error(_ERROR_DISALLOWED);
+                       return;
+                       }
+                       $this->choose();
+                       break;
+               case 'upload':
+                       if ( !$member->isAdmin() && !$CONF['AllowUpload'] )
+                       {
+                               $this->error(_ERROR_DISALLOWED);
+                       return;
+                       }
+                       $this->upload();
+                       break;
+               case 'select':
+               default:
+                       $this->select();
+                       break;
+               }
+               exit;
+       }
+       
+       private function select()
+       {
+               global $CONF;
+               
+               $this->type = 'select';
+               $this->filter = requestVar('filter');
+               
+               $media = Media::getMediaListByCollection($this->collection, $this->filter);
+               
+               $this->amount = count($media);
+               $this->offset = intRequestVar('offset');
+               
+               if ( $this->amount > 0 )
+               {
+                       if ( ($this->offset + $CONF['MediaPerPage']) >= $this->amount )
+                       {
+                               $this->offset = $this->amount - $CONF['MediaPerPage'];
+                       }
+                       
+                       if ( $this->offset < 0 )
+                       {
+                               $this->offset = 0;
+                       }
+                       
+                       $start = $this->offset;
+                       $end = $this->offset + $CONF['MediaPerPage'];
+                       $next = $end;
+                       $prev = $start - $CONF['MediaPerPage'];
+                       
+                       if ( $prev < 0 )
+                       {
+                               $prev = 0;
+                       }
+                       
+                       if ( $end > $this->amount )
+                       {
+                               $end = $this->amount;
+                       }
+                       
+                       if ( $start > 0 )
+                       {
+                               $this->prev = $prev;
+                       }
+                       
+                       if ( $end < $this->amount )
+                       {
+                               $this->next = $next;
+                       }
+                       
+                       for( $index = $start; $index < $end; $index++ )
+                       {
+                               $this->media[] = $media[$index];
+                       }
+                       
+                       unset($media);
+               }
+               
+               $this->skin->parse('fileparse', $this->getDirectory() . 'skins/select.skn');
+               return;
+       }
+       
+       private function choose()
+       {
+               $this->type = 'choose';
+               $this->skin->parse('fileparse', $this->getDirectory() . 'skins/choose.skn');
+       }
+       
+       private function upload()
+       {
+               global $CONF;
+               
+               $this->type = 'upload';
+               
+               $uploadInfo = postFileInfo('uploadfile');
+               
+               $filename = $uploadInfo['name'];
+               $filetype = $uploadInfo['type'];
+               $filesize = $uploadInfo['size'];
+               $filetempname = $uploadInfo['tmp_name'];
+               $fileerror = (integer) $uploadInfo['error'];
+               
+               switch ( $fileerror )
+               {
+                       // include error code for debugging
+                       // (see http://www.php.net/manual/en/features.file-upload.errors.php)
+                       case 0:         // = UPLOAD_ERR_OK
+                               break;
+                       case 1:         // = UPLOAD_ERR_INI_SIZE
+                       case 2:         // = UPLOAD_ERR_FORM_SIZE
+                               $this->error(_ERROR_FILE_TOO_BIG);
+                               return;
+                       case 3:         // = UPLOAD_ERR_PARTIAL
+                       case 4:         // = UPLOAD_ERR_NO_FILE
+                       case 6:         // = UPLOAD_ERR_NO_TMP_DIR
+                       case 7:         // = UPLOAD_ERR_CANT_WRITE
+                       default:
+                               $this->error(_ERROR_BADREQUEST . ' (' . $fileerror . ')');
+                               return;
+               }
+               
+               if ( $filesize > $CONF['MaxUploadSize'] )
+               {
+                       $this->error(_ERROR_FILE_TOO_BIG);
+                       return;
+               }
+               
+               // check file type against allowed types
+               $ok = 0;
+               $allowedtypes = preg_split('#,#', $CONF['AllowedTypes']);
+               foreach ( $allowedtypes as $type )
+               {
+                       if ( preg_match("#.{$type}$#i", $filename) )
+                       {
+                               $ok = 1;
+                       }
+               }
+               if ( !$ok )
+               {
+                       $this->error(_ERROR_BADFILETYPE);
+                       return;
+               }
+               
+               if ( !is_uploaded_file($filetempname) )
+               {
+                       $this->error(_ERROR_BADREQUEST);
+                       return;
+               }
+               // prefix filename with current date (YYYY-MM-DD-)
+               // this to avoid nameclashes
+               if ( $CONF['MediaPrefix'] )
+               {
+                       $filename = i18n::formatted_datetime("%Y%m%d-", time()) . $filename;
+               }
+               
+               $res = Media::addMediaObject($this->collection, $filetempname, $filename);
+               
+               if ( $res != '' )
+               {
+                       $this->error($res);
+                       return;
+               }
+               
+               $this->select();
+               return;
+       }
+       
+       private function login()
+       {
+               $this->type = 'login';
+               $this->skin->parse('fileparse', $this->getDirectory() . 'skins/login.skn');
+               return;
+       }
+       
+       private function error($msg)
+       {
+               $this->type = 'error';
+               $this->message = $msg;
+               $this->skin->parse('fileparse', $this->getDirectory() . 'skins/error.skn');
+               return;
+       }
+}
diff --git a/nucleus/plugins/medium/MediumActions.php b/nucleus/plugins/medium/MediumActions.php
new file mode 100644 (file)
index 0000000..7810bdd
--- /dev/null
@@ -0,0 +1,312 @@
+<?php
+class MediumActions extends BaseActions
+{
+       private $type = '';
+       
+       static private $default_actions = array(
+               'actionurl',
+               'adminurl',
+               'collection',
+               'conf',
+               'pagehead',
+               'pagefoot',
+               'collectionlist',
+               'stylesheet',
+               'script'
+               );
+       
+       static public $default_skin_types = array(
+               'login'         => 'NP_Medium',
+               'choose'        => _UPLOAD_TITLE,
+               'select'        => _SKIN_PART_ALIST,
+               'error'         => _ERROR
+       );
+       
+       static public function getAvailableSkinTypes()
+       {
+               return self::$default_skin_types;
+       }
+       
+       public function getAvailableActions()
+       {
+               global $manager;
+               
+               $extra_actions = array();
+               
+               switch ( $manager->getPlugin('NP_Medium')->type )
+               {
+                       case 'login':
+                               $extra_actions = array(
+                                       'name',
+                               );
+                               break;
+                       case 'select':
+                               $extra_actions = array(
+                                       'amount',
+                                       'filter',
+                                       'medialist',
+                                       'next',
+                                       'prev'
+                               );
+                               break;
+                       case 'choose':
+                               $extra_actions = array(
+                                       'pluginextras',
+                                       'ticket',
+                               );
+                               break;
+                       case 'error':
+                               $extra_actions = array(
+                                       'message',
+                               );
+                               break;
+               }
+               
+               $defined_actions = array_merge(self::$default_actions, $extra_actions);
+               
+               return array_merge($defined_actions, parent::getAvailableActions());
+       }
+       
+       /**
+        * MediumActions::_construct
+        * 
+        * @param       string  $type   always 'fileparse'
+        * @return      void
+        */
+       public function __construct($type)
+       {
+               parent::__construct();
+               return;
+       }
+       
+       public function parse_conf($key)
+       {
+               global $CONF;
+               if ( array_key_exists($key, $CONF) )
+               {
+                       echo $CONF[$key];
+               }
+               return;
+       }
+       
+       public function parse_actionurl()
+       {
+               global $CONF;
+               echo "{$CONF['ActionURL']}?action=plugin&amp;name=medium";
+               return;
+       }
+       
+       public function parse_collection()
+       {
+               global $manager;
+               echo (string) $manager->getPlugin('NP_Medium')->collection;
+               return;
+       }
+       
+       public function parse_pagehead()
+       {
+               global $manager;
+               $path = $manager->getPlugin('NP_Medium')->getDirectory() . 'skins/pagehead.skn';
+               $contents = $this->parser->skin->getContentFromFile($path);
+               $this->parser->parse($contents);
+               return;
+       }
+       
+       public function parse_pagefoot()
+       {
+               global $manager;
+               $path = $manager->getPlugin('NP_Medium')->getDirectory() . 'skins/pagefoot.skn';
+               $contents = $this->parser->skin->getContentFromFile($path);
+               $this->parser->parse($contents);
+               return;
+       }
+       
+       public function parse_stylesheet($name)
+       {
+               global $CONF;
+               echo "{$CONF['PluginURL']}medium/styles/{$name}";
+               return;
+       }
+       
+       public function parse_script($name)
+       {
+               global $CONF;
+               echo "{$CONF['PluginURL']}medium/scripts/{$name}";
+               return;
+       }
+       
+       public function parse_name()
+       {
+               global $member;
+               
+               if ( !$member->isLoggedIn() )
+               {
+                       echo (string) requestVar('login');
+               }
+               else
+               {
+                       echo (string) $member->getDisplayName();
+               }
+               return;
+       }
+       
+       public function parse_filter()
+       {
+               global $manager;
+               echo (string) $manager->getPlugin('NP_Medium')->filter;
+               return;
+       }
+       
+       public function parse_ticket()
+       {
+               global $manager;
+               echo $manager->addTicketHidden();
+               return;
+       }
+       
+       public function parse_message()
+       {
+               global $manager;
+               echo (string) $manager->getPlugin('NP_Medium')->message;
+               return;
+       }
+       
+       public function parse_pluginextras()
+       {
+               global $manager;
+               $manager->notify("MediaUploadFormExtras", array());
+               return;
+       }
+       
+       public function parse_amount()
+       {
+               global $manager;
+               echo (string) $manager->getPlugin('NP_Medium')->amount;
+               return;
+       }
+       
+       public function parseoffset()
+       {
+               global $manager;
+               echo (string) $manager->getPlugin('NP_Medium')->offset;
+               return;
+       }
+       
+       public function parse_prev()
+       {
+               global $manager;
+               echo (string) $manager->getPlugin('NP_Medium')->prev;
+               return;
+       }
+       
+       public function parse_next()
+       {
+               global $manager;
+               echo (string) $manager->getPlugin('NP_Medium')->next;
+               return;
+       }
+       
+       public function parse_collectionlist()
+       {
+               global $CONF, $manager;
+               
+               $plugin = $manager->getPlugin('NP_Medium');
+               
+               $data = array(
+                       'actionurl'     => "{$CONF['ActionURL']}?action=plugin&amp;type=medium"
+               );
+               $this->parser->parse(Template::fill($plugin->getOption('collectionlist_head'), $data));
+               
+               $collections = Media::getCollectionList();
+               foreach ( $collections as $name => $desc )
+               {
+                       $data = array(
+                               'name'  => $name,
+                               'desc'  => $desc
+                       );
+                       
+                       if ( $plugin->collection ==  $name )
+                       {
+                               $data['selected'] = 'selected="selected"';
+                       }
+                       
+                       $this->parser->parse(Template::fill($plugin->getOption('collectionlist_body'), $data));
+               }
+               
+               $data = array(
+                       'actionurl'             => "{$CONF['ActionURL']}?action=plugin&amptype=medium",
+                       'collection'    => $plugin->collection
+               );
+               $this->parser->parse(Template::fill($plugin->getOption('collectionlist_foot'), $data));
+       }
+       
+       public function parse_medialist()
+       {
+               global $CONF, $manager;
+               
+               $plugin = $manager->getPlugin('NP_Medium');
+               
+               $data = array(
+                       'actionurl'             => "{$CONF['ActionURL']}?action=plugin&amp;type=medium",
+                       'collection'    => $plugin->collection,
+                       'description'   => $plugin->description
+               );
+               $this->parser->parse(Template::fill($plugin->getOption('medialist_head'), $data));
+               
+               $image_template = $plugin->getOption('medialist_body_image');
+               $other_template = $plugin->getOption('medialist_body_other');
+               
+               foreach ( $plugin->media as $medium )
+               {
+                       $data = array(
+                               'mime'                  => $medium->mime,
+                               'collection'    => $medium->collection,
+                               'filename'              => $medium->filename,
+                               'shortfilename' => Entity::shorten($medium->filename, 24, '...'),
+                               'prefix'                => $medium->prefix,
+                               'name'                  => $medium->name,
+                               'suffix'                => $medium->suffix,
+                               'timestamp'             => date("Y-m-d", $medium->timestamp),
+                               'size'                  => $medium->size,
+                               'width'                 => $medium->width,
+                               'height'                => $medium->height,
+                               'mediumurl'             => "{$CONF['MediaURL']}{$medium->collection}/{$medium->filename}"
+                       );
+                       
+                       if ( !array_key_exists($medium->mime, Media::$image_mime) )
+                       {
+                               $this->parser->parse(Template::fill($other_template, $data));
+                       }
+                       else
+                       {
+                               $this->parser->parse(Template::fill($image_template, $data));
+                       }
+               }
+               
+               $data = array();
+               $this->parser->parse(Template::fill($plugin->getOption('medialist_foot'), $data));
+               
+               return;
+       }
+       
+       protected function checkCondition($field, $name='', $value = '')
+       {
+               global $manager;
+               
+               $plugin = $manager->getPlugin('NP_Medium');
+               
+               $condition = 0;
+               switch ( $field )
+               {
+                       case 'prev':
+                               $condition = (boolean) ($plugin->prev != $plugin->offset );
+                               break;
+                       case 'next':
+                               $condition = (boolean) $plugin->next;
+                               break;
+                       default:
+                               break;
+               }
+               return $condition;
+       }
+}
diff --git a/nucleus/plugins/medium/locales/en_Latn_US.UTF-8.php b/nucleus/plugins/medium/locales/en_Latn_US.UTF-8.php
new file mode 100644 (file)
index 0000000..b3101db
--- /dev/null
@@ -0,0 +1,9 @@
+<?php
+define('_MEDIUM_COLLECTIONLIST_HEADER',        'Collection List Header');
+define('_MEDIUM_COLLECTIONLIST_BODY',  'Collection List Body');
+define('_MEDIUM_COLLECTIONLIST_FOOTER',        'Collection List Footer');
+define('_MEDIUM_MEDIALIST_HEADER',             'Media List Header');
+define('_MEDIUM_MEDIALIST_BODY',               'Media List Body');
+define('_MEDIUM_MEDIALIST_FOOTER',             'Media List Footer');
+
+define('_MEDIUM_DESC',                                 'insert and upload media');
\ No newline at end of file
diff --git a/nucleus/plugins/medium/scripts/medium.js b/nucleus/plugins/medium/scripts/medium.js
new file mode 100644 (file)
index 0000000..6d3848e
--- /dev/null
@@ -0,0 +1,184 @@
+/* init */
+if ( !medium )
+{
+       var medium = new Object();
+       medium.type = 'inline';
+       medium.url = '';
+
+}
+
+/* for main window */
+medium.addMedia = function()
+{
+       window.open(this.url,
+        'Nucleus CMS Medium Plugin',
+        'status=yes,toolbar=no,scrollbars=yes,resizable=yes,width=500,height=450,top=0,left=0');
+       return;
+};
+
+medium.isCaretEmpty = function()
+{
+       /* lastSelected object is on main window */
+       if ( lastSelected && lastSelected.createTextRange && lastSelected.caretPos )
+       {
+               return ( lastSelected.caretPos.text == '' );
+       }
+       else if ( !document.all && document.getElementById )
+       {
+               return ( mozSelectedText() == '' );
+       }
+       return true;
+};
+
+medium.getCaretText = function()
+{
+       if ( !document.all && document.getElementById )
+       {
+               return mozSelectedText();
+       }
+       return lastSelected.caretPos.text;
+}
+
+// inserts text at caret (overwriting selection)
+medium.insertAtCaret = function(text)
+{
+       /* lastSelected is on main window */
+       var textEl = lastSelected;
+       if ( textEl && textEl.createTextRange && textEl.caretPos )
+       {
+               var caretPos = textEl.caretPos;
+               
+               if ( caretPos.text.charAt(caretPos.text.length - 1) != ' ' )
+               {
+                       caretPos.text = text;
+               }
+               else
+               {
+                       caretPos.text = text + ' ';
+               }
+       }
+       else if ( !document.all && document.getElementById )
+       {
+               mozReplace(document.getElementById('input' + nonie_FormType), text);
+               if ( scrollTop > -1 )
+               {
+                       document.getElementById('input' + nonie_FormType).scrollTop = scrollTop;
+               }
+       }
+       else if ( textEl )
+       {
+               textEl.value  += text;
+       }
+       else
+       {
+               document.getElementById('input' + nonie_FormType).value += text;
+               if ( scrollTop > -1 )
+               {
+                       document.getElementById('input' + nonie_FormType).scrollTop = scrollTop;
+               }
+       }
+       /* updAllPreviews() is on main window */
+       updAllPreviews();
+       return;
+}
+
+medium.includeImage = function(collection, filename, type, width, height)
+{
+       var fullName;
+       var replaceBy;
+       
+       if ( this.isCaretEmpty() )
+       {
+               text = prompt("Text to display ?", filename);
+       }
+       else
+       {
+               text = this.getCaretText();
+       }
+       
+       /*
+        * add collection name when not private collection
+        * (or editing a message that's not your)
+        */
+       if ( isNaN(collection) || (nucleusAuthorId != collection) )
+       {
+               fullName = collection + '/' + filename;
+       }
+       else
+       {
+               fullName = filename;
+       }
+       
+       switch ( type )
+       {
+               case 'popup':
+                       replaceBy = '<%popup(' +  fullName + '|'+width+'|'+height+'|' + text +')%>';
+                       break;
+               case 'inline':
+               default:
+                       replaceBy = '<%image(' +  fullName + '|'+width+'|'+height+'|' + text +')%>';
+                       break;
+       }
+       
+       this.insertAtCaret(replaceBy);
+       return;
+}
+
+medium.includeOtherMedia = function(collection, filename)
+{
+       var fullName;
+       var replaceBy;
+       
+       if ( this.isCaretEmpty() )
+       {
+               text = prompt("Text to display ?",filename);
+       }
+       else
+       {
+               text = getCaretText();
+       }
+       
+       // add collection name when not private collection (or editing a message that's not your)
+       if ( isNaN(collection) || (nucleusAuthorId != collection) )
+       {
+               fullName = collection + '/' + filename;
+       }
+       else
+       {
+               fullName = filename;
+       }
+       
+       replaceBy = '<%media(' +  fullName + '|' + text +')%>';
+       
+       this.insertAtCaret(replaceBy);
+       return;
+}
+
+/* for sub window */
+medium.setType = function(value)
+{
+       this.type = value;
+};
+
+medium.chooseImage = function(collection, filename, width, height)
+{
+       if ( this.type != 'inline' )
+       {
+               this.type = 'popup';
+       }
+       
+       window.close();
+       window.opener.focus();
+       window.opener.medium.includeImage(collection, filename, this.type, width, height);
+       return;
+}
+
+medium.chooseOther = function(collection, filename)
+{
+       
+       window.close();
+       window.opener.focus();
+       window.opener.medium.type = this.type;
+       window.opener.medium.includeOtherMedia(collection, filename);
+       return;
+}
diff --git a/nucleus/plugins/medium/skins/choose.skn b/nucleus/plugins/medium/skins/choose.skn
new file mode 100644 (file)
index 0000000..3262c0e
--- /dev/null
@@ -0,0 +1,31 @@
+<%pagehead%>
+
+<h1><%text(_UPLOAD_TITLE)%></h1>
+
+<p><%text(_UPLOAD_MSG)%></p>
+
+<form method="post" action="<%actionurl%>" enctype="multipart/form-data">
+
+<p>
+File:
+<input type="file" name="uploadfile" size="40" />
+</p>
+
+<p><%text(_SETTINGS_ALLOWUPLOADTYPES)%>: <%conf(AllowedTypes)%></p>
+
+<p>
+<%collectionlist%>
+</p>
+
+<%pluginextras%>
+
+<p>
+<%ticket%>
+<input type="hidden" name="MAX_FILE_SIZE" value="<%conf(MaxUploadSize)%>" />
+<button type="submit" name ="type" value="upload"><%text(_UPLOAD_BUTTON)%></button>
+<button type="submit" name ="type" value="select"><%text(_BACK)%></button>
+</p>
+
+</form>
+
+<%pagefoot%>
diff --git a/nucleus/plugins/medium/skins/error.skn b/nucleus/plugins/medium/skins/error.skn
new file mode 100644 (file)
index 0000000..2d444ca
--- /dev/null
@@ -0,0 +1,7 @@
+<%pagehead%>
+
+<h1><%text(_ERROR)%></h1>
+<p><%message%></p>
+<p><a href="<%actionurl%>" onclick="history.back()"><%text(_BACK)%></a></p>
+
+<%pagefoot%>
diff --git a/nucleus/plugins/medium/skins/login.skn b/nucleus/plugins/medium/skins/login.skn
new file mode 100644 (file)
index 0000000..4d71604
--- /dev/null
@@ -0,0 +1,25 @@
+<%pagehead%>
+
+<h1><%text(_LOGIN_PLEASE)%></h1>
+
+<form method="post" action="<%conf(AdminURL)%>">
+
+<dl>
+<dt><%text(_LOGINFORM_NAME)%></dt>
+<dd><input type="text" name="login" value="" /></dd>
+<dt><%text(_LOGINFORM_PWD)%></dt>
+<dd><input type="password" name="password" /></dd>
+</dl>
+
+<p>
+<input type="checkbox" value="1" name="shared" tabindex="40" id="shared" />
+<label for="shared"><%text(_LOGIN_SHARED)%></label>
+<input type="hidden" name="collection" value="<%collection%>" />
+<button type="submit" name="action" value="login"><%text(_LOGIN)%></button>
+</p>
+
+</form>
+
+<p><a href="<%actionurl%>" onclick="window.close();"><%text(_POPUP_CLOSE)%></a></p>
+
+<%pagefoot%>
diff --git a/nucleus/plugins/medium/skins/pagefoot.skn b/nucleus/plugins/medium/skins/pagefoot.skn
new file mode 100644 (file)
index 0000000..691287b
--- /dev/null
@@ -0,0 +1,2 @@
+</body>
+</html>
\ No newline at end of file
diff --git a/nucleus/plugins/medium/skins/pagehead.skn b/nucleus/plugins/medium/skins/pagehead.skn
new file mode 100644 (file)
index 0000000..e7d34c9
--- /dev/null
@@ -0,0 +1,8 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<title>Nucleus Media</title>
+<link rel="stylesheet" type="text/css" href="<%stylesheet(medium.css)%>" />
+<script type="text/javascript" src="<%script(medium.js)%>"></script>
+</head>
+<body>
diff --git a/nucleus/plugins/medium/skins/select.skn b/nucleus/plugins/medium/skins/select.skn
new file mode 100644 (file)
index 0000000..b5c4064
--- /dev/null
@@ -0,0 +1,48 @@
+<%pagehead%>
+
+<form method="post" action="<%actionurl%>">
+<p>
+
+<%collectionlist%>
+
+<button type="submit" name="type" value="select" title="<%text(_MEDIA_COLLECTION_TT)%>">
+<%text(_MEDIA_COLLECTION_SELECT)%>
+</button>
+<button type="submit" name="type" value="choose" title="<%text(_MEDIA_UPLOADLINK)%>" />
+<%text(_MEDIA_UPLOAD_TO)%>
+</button>
+
+</p>
+
+<p>
+<label for="media_filter"><%text(_MEDIA_FILTER_LABEL)%></label>
+<input type="text" id="media_filter" name="filter" value="<%filter%>" />
+<button type="submit" name="type" value="select"><%text(_MEDIA_FILTER_APPLY)%></button>
+<input type="hidden" name="offset" value="<%offset%>" />
+</p>
+
+</form>
+
+<%medialist%>
+
+<p>
+
+<%if(prev)%>
+<a href="<%actionurl%>&amp;type=select&amp;offset=<%prev%>&amp;collection=<%collection%>">
+<%text(_LISTS_PREV)%>
+</a>
+<%endif%>
+<%if(next)%>
+<a href="<%actionurl%>&amp;type=select&amp;offset=<%next%>&amp;collection=<%collection%>">
+<%text(_LISTS_NEXT)%>
+</a>
+<%endif%>
+
+<input type="radio" id="typeradio0" name="typeradio" onclick="medium.setType('inline');" checked="checked" />
+<label for="typeradio0"><%text(_MEDIA_INLINE)%></label>
+<input type="radio" id="typeradio1" name="typeradio" onclick="medium.setType('popup');" />
+<label for="typeradio1"><%text(_MEDIA_POPUP)%></label>
+
+</p>
+
+<%pagefoot%>
diff --git a/nucleus/plugins/medium/styles/medium.css b/nucleus/plugins/medium/styles/medium.css
new file mode 100644 (file)
index 0000000..81bfb20
--- /dev/null
@@ -0,0 +1,59 @@
+body {
+       font-family: verdana, arial;
+       font-size: small;
+       background-color: #FFFFFF;
+       color: #000000;
+}
+
+a:link, a:visited {
+       color: #1D3565; 
+       font-weight: bold;
+       text-decoration: none;
+}
+a:hover {
+       text-decoration: underline;
+}
+
+h1 {
+       border-bottom: 1px dotted gray;
+       font-size: x-large;
+       color: #596d9d;
+}
+
+h2 {
+       color: gray;
+       font-size: large;
+       margin-left: 20px;
+       text-indent: 10px;
+       border-bottom: 1px solid #ddd;
+}
+
+table {
+       border: none;
+       width:  100%;
+}
+
+table th {
+       background-color: linen;
+       font-size: medium;
+}
+
+table th,
+table td {
+       padding: 5px;
+}
+
+table td {
+       background-color: #dddddd;
+       font-size: small;
+       vertical-align: top;
+       text-align: left;
+}
+
+p {
+       margin: 0px 0px 5px 0px
+}
+
+label {
+       cursor: pointer;
+}
\ No newline at end of file
index 0faa6da..131860c 100644 (file)
@@ -137,14 +137,17 @@ var nonie_FormType = 'body';
 
 // Add media to new item
 function addMedia() {
-
-       var mediapopup = window.open(nucleusMediaPopupURL + 'media.php','name',
-               'status=yes,toolbar=no,scrollbars=yes,resizable=yes,width=500,height=450,top=0,left=0');
-
-       return;
+       if ( typeof(medium) != 'undefined' )
+       {
+               medium.addMedia();
+       }
+       else
+       {
+               var mediapopup = window.open(nucleusMediaPopupURL + 'media.php','name',
+                       'status=yes,toolbar=no,scrollbars=yes,resizable=yes,width=500,height=450,top=0,left=0');
+       }
 }
 
-
 function setMediaPopupURL(url) {
        nucleusMediaPopupURL = url;
 }
index 0faa6da..adf6fa5 100644 (file)
@@ -136,15 +136,20 @@ function execAndUpdate(action) {
 var nonie_FormType = 'body';
 
 // Add media to new item
-function addMedia() {
-
-       var mediapopup = window.open(nucleusMediaPopupURL + 'media.php','name',
-               'status=yes,toolbar=no,scrollbars=yes,resizable=yes,width=500,height=450,top=0,left=0');
-
+function addMedia()
+{
+       if ( typeof(medium) != 'undefined' )
+       {
+               medium.addMedia();
+       }
+       else
+       {
+               var mediapopup = window.open(nucleusMediaPopupURL + 'media.php','name',
+                       'status=yes,toolbar=no,scrollbars=yes,resizable=yes,width=500,height=450,top=0,left=0');
+       }
        return;
 }
 
-
 function setMediaPopupURL(url) {
        nucleusMediaPopupURL = url;
 }