OSDN Git Service

CHANGE/REMOVE: <%text%>タグをスキンのどのコンテクストでも利用可能に。NP_Textの廃止。
authorsakamocchi <o-takashi@sakamocchi.jp>
Sat, 28 Apr 2012 05:13:44 +0000 (14:13 +0900)
committersakamocchi <o-takashi@sakamocchi.jp>
Sat, 28 Apr 2012 05:13:44 +0000 (14:13 +0900)
これまで一部の管理画面用スキンでしか利用することのできなかった<%text%>タグを、スキンのどのコンテクストでも利用可能とするため、BaseActions.php::parse_text()を追加。従来NP_Textプラグインで提供してきた、スキン他言語化のための実装をコアに移し、Skin::includeLocaleFile()を新設。Skin::parse()からこのメソッドを実行することで、現在システムで有効となっているロケールに基づき、スキンの翻訳ファイルがインクルードされるようにした。

これによりNP_Textの全機能がコアにマージされたため、NP_Textを廃止。

nucleus/libs/ACTIONS.php
nucleus/libs/AdminActions.php
nucleus/libs/BaseActions.php
nucleus/libs/SKIN.php
nucleus/plugins/NP_Text.php [deleted file]

index e11d319..eb9ec22 100644 (file)
@@ -299,7 +299,7 @@ class Actions extends BaseActions
        public function doForm($filename)\r
        {\r
                global $DIR_NUCLEUS;\r
-               array_push($this->parser->actions,'formdata','text','callback','errordiv','ticket');\r
+               array_push($this->parser->actions,'formdata', 'callback','errordiv','ticket');\r
                \r
                $oldIncludeMode = Parser::getProperty('IncludeMode');\r
                $oldIncludePrefix = Parser::getProperty('IncludePrefix');\r
@@ -312,7 +312,6 @@ class Actions extends BaseActions
                \r
                array_pop($this->parser->actions);      // errordiv\r
                array_pop($this->parser->actions);      // callback\r
-               array_pop($this->parser->actions);      // text\r
                array_pop($this->parser->actions);      // formdata\r
                array_pop($this->parser->actions);      // ticket\r
                return;\r
@@ -2181,23 +2180,6 @@ class Actions extends BaseActions
        }\r
        \r
        /**\r
-        * Actions::parse_text()\r
-        * Parse text\r
-        * \r
-        * @param       void\r
-        * @return      void\r
-        */\r
-       public function parse_text($which)\r
-       {\r
-               // constant($which) only available from 4.0.4 :(\r
-               if ( defined($which) )\r
-               {\r
-                       eval("echo $which;");\r
-               }\r
-               return;\r
-       }\r
-       \r
-       /**\r
         * Actions::parse_ticket()\r
         * Parse ticket\r
         * \r
index f9a341b..51fb220 100644 (file)
@@ -4432,24 +4432,6 @@ class AdminActions extends BaseActions
        }
        
        /**
-        * AdminActions::parse_text()
-        * Parse text
-        * 
-        * FIXME: is this really needed?
-        * 
-        * @param       string  $which  constant vallue
-        * @return      void
-        */
-       public function parse_text($which)
-       {
-               if ( defined($which) )
-               {
-                       echo constant($which);
-               }
-               return;
-       }
-       
-       /**
         * AdminActions::parse_ticket()
         * Parse ticket
         * 
index 969d65c..a6c00a3 100644 (file)
@@ -64,7 +64,8 @@ class BaseActions
                'parsedinclude',
                'phpinclude',
                'set',
-               'skinfile'
+               'skinfile',
+               'text'
        );
        
        /**
@@ -229,6 +230,26 @@ class BaseActions
        }
        
        /**
+        * Actions::parse_text()
+        * Parse text
+        * 
+        * @param       string  $constant       named constant
+        * @return      void
+        */
+       public function parse_text($constant)
+       {
+               if ( !defined($constant) )
+               {
+                       echo Entity::hsc($constant);
+               }
+               else
+               {
+                       echo Entity::hsc(constant($constant));
+               }
+               return;
+       }
+       
+       /**
         * BaseActions::addIfCondition()
         * Helper function: add if condition
         * 
index 6c862bd..b9208f6 100644 (file)
@@ -331,6 +331,9 @@ class Skin
                \r
                $manager->notify("Init{$this->event_identifier}Parse", array('skin' => &$this, 'type' => $type));\r
                \r
+               // include skin locale file for <%text%> tag if useable\r
+               $this->includeLocaleFile(i18n::get_current_locale());\r
+               \r
                // set output type\r
                sendContentType($this->getContentType(), 'skin');\r
                \r
@@ -568,6 +571,46 @@ class Skin
        }\r
        \r
        /**\r
+        * Skin::includeLocaleFile()\r
+        * \r
+        * @param       string  $locale locale name\r
+        * @return      void\r
+        */\r
+       private function includeLocaleFile($locale)\r
+       {\r
+               global $DIR_SKINS;\r
+               \r
+               if( $this->includeMode == "normal" )\r
+               {\r
+                       $filename = "./locale/{$locale}.php";\r
+               }\r
+               elseif( $this->includeMode == "skindir" )\r
+               {\r
+                       if ( $this->includePrefix == '' )\r
+                       {\r
+                               $filename = "{$DIR_SKINS}locale/{$locale}.php";\r
+                       }\r
+                       else\r
+                       {\r
+                               $filename = "{$DIR_SKINS}{$this->includePrefix}locale/{$locale}.php";\r
+                       }\r
+               }\r
+               else\r
+               {\r
+                       return;\r
+               }\r
+               \r
+               if ( !file_exists($filename) )\r
+               {\r
+                       return;\r
+               }\r
+               \r
+               include_once($filename);\r
+               \r
+               return;\r
+       }\r
+       \r
+       /**\r
         * Skin::getDefaultTypes()
         * \r
         * @param       string  void
diff --git a/nucleus/plugins/NP_Text.php b/nucleus/plugins/NP_Text.php
deleted file mode 100644 (file)
index c7fe15c..0000000
+++ /dev/null
@@ -1,186 +0,0 @@
-<?php
-/*
-License:
-This software is published under the same license as NucleusCMS, namely
-the GNU General Public License. See http://www.gnu.org/licenses/gpl.html for
-details about the conditions of this license.
-
-In general, this program is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by the Free
-Software Foundation; either version 2 of the License, or (at your option) any
-later version.
-
-This program is distributed in the hope that it will be useful, but WITHOUT ANY
-WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
-PARTICULAR PURPOSE. See the GNU General Public License for more details.
-
-* @version $Id: NP_Text.php 1678 2012-02-26 07:31:36Z sakamocchi $
-*/
-class NP_Text extends NucleusPlugin
-{
-       public $incModePref = array();
-       public $errorLogged = false;
-       public $constantPrefix = "SL_";
-       
-       public function getName()
-       {
-               return 'Text';
-       }
-       public function getAuthor()
-       {
-               return 'Armon Toubman';
-       }
-
-       public function getURL()
-       {
-               return 'http://forum.nucleuscms.org/viewtopic.php?t=14904';
-       }
-
-       public function getVersion()
-       {
-               return '0.53';
-       }
-
-       public function getDescription()
-       {
-               return 'Display constants from translation files: <%Text(CONSTANT)%>';
-       }
-
-       public function getEventList()
-       {
-               return array('PreSkinParse');
-       }
-
-       public function supportsFeature($feature)
-       {
-               return ( $feature == 'SqlTablePrefix' );
-       }
-
-       public function install()
-       {
-               return;
-       }
-
-       public function uninstall()
-       {
-               return;
-       }
-
-       public function init()
-       {
-               $this->incModePref = $this->skin_incmodepref();
-               return;
-       }
-       
-       public function event_PreSkinParse()
-       {
-               global $member;
-               if( !$member->isLoggedIn() and isset($_GET['lang']) )
-               {
-                       /* 3 months */
-                       setcookie('NP_Text', getVar('lang'), time()+60*60*24*90);
-               }
-               return;
-       }
-        
-       public function doSkinVar($skinType, $constant)
-       {
-               global $member, $CONF;
-               
-               $language = getLanguageName();
-               $getLanguage = isset($_GET['lang']) ? getVar('lang') : false;
-               $cookieLanguage = isset($_COOKIE['NP_Text']) ? cookieVar('NP_Text') : false;
-               
-               if( $getLanguage )
-               {
-                       $this->use_lang($getLanguage, $constant);
-               }
-               elseif( $cookieLanguage )
-               {
-                       $this->use_lang($cookieLanguage, $constant);
-               }
-               else
-               {
-                       $this->use_lang($language, $constant);
-               }
-               return;
-       }
-       
-       public function doTemplateVar(&$item, $constant)
-       {
-               global $member, $CONF;
-               
-               $language = getLanguageName();
-               $getLanguage = isset($_GET['lang']) ? getVar('lang') : false;
-               $cookieLanguage = isset($_COOKIE['NP_Text']) ? cookieVar('NP_Text') : false;
-               
-               if( $getLanguage )
-               {
-                       $this->use_lang($getLanguage, $constant);
-               }
-               elseif( $cookieLanguage )
-               {
-                       $this->use_lang($cookieLanguage, $constant);
-               }
-               else
-               {
-                       $this->use_lang($language, $constant);
-               }
-               return;
-       }
-       
-       private function use_lang($language, $constant)
-       {
-               global $DIR_SKINS;
-               
-               $filename = '';
-               
-               if( $this->incModePref[0] == "normal" )
-               {
-                       $filename = $filename.$this->incModePref[1];
-                       $filename = $filename."language/";
-                       $filename = $filename.$language;
-                       $filename = $filename.".php";
-               }
-               elseif( $this->incModePref[0] == "skindir" )
-               {
-                       $filename = $filename.$DIR_SKINS;
-                       $filename = $filename.$this->incModePref[1];
-                       $filename = $filename."language/";
-                       $filename = $filename.$language;
-                       $filename = $filename.".php";
-               }
-               
-               if ( is_file($filename) )
-               {
-                       include($filename);
-               }
-               else
-               {
-                       addToLog(1, "NP_Text cannot find ".$filename);
-               }
-               
-               if ( defined($this->constantPrefix.$constant) )
-               {
-                       echo constant($this->constantPrefix.$constant);
-               }
-               else
-               {
-                       echo $this->constantPrefix.$constant;
-                       if( is_file($filename) )
-                       {
-                               addToLog(1, "NP_Text cannot find definition for ".$this->constantPrefix.$constant." in ".$filename);
-                       }
-               }
-               return;
-       }
-       
-       private function skin_incmodepref()
-       {
-               global $currentSkinName;
-               $sql = "SELECT * FROM " . sql_table("skin_desc") . " WHERE sdname = '" . $currentSkinName . "'";
-               $result = sql_query($sql);
-               $row = sql_fetch_array($result, MYSQL_ASSOC);
-               return array($row['sdincmode'], $row['sdincpref']);
-       }
-}