3 * Text plugin for Nucleus CMS
4 * Version 0.53JP for PHP5
5 * Written By Cacher, Jan.16, 2011
6 * Original was written by Armon Toubman, Jan.18, 2007
7 * This plugin depends needs PHP mbstring extension or mb_emurator scripts Andy Matsubara released.
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 3
12 * of the License, or (at your option) any later version.
15 class NP_Text extends NucleusPlugin {
16 private $incModePref = array();
17 private $constantPrefix = "SL_";
19 public function getEventList() { return array('PreSkinParse'); }
20 public function getName() { return 'Text'; }
21 public function getAuthor() { return 'Armon Toubman'; }
22 public function getURL() { return 'http://forum.nucleuscms.org/viewtopic.php?t=14904'; }
23 public function getVersion() { return '0.53JP'; }
24 public function getDescription() {
25 $desc = '言語ファイル中の定数を表示します。: <%Text(定数名)%>';
26 switch (preg_replace( '#\\\\|/#', '', getLanguageName())) {
27 case 'japanese-utf8':
\r
29 case 'japanese-euc':
\r
30 $desc = mb_convert_encoding($desc,'EUC-JP','UTF-8');
\r
33 $desc ='Display constants from language files: <%Text(CONSTANT)%>';
\r
38 public function supportsFeature($feature) { return in_array ($feature, array ('SqlTablePrefix', 'SqlApi'));}
39 public function install() { return; }
40 public function uninstall() { return; }
42 public function init() {
43 $this->incModePref = $this->skin_incmodepref();
47 public function event_PreSkinParse() {
49 if( !$member->isLoggedIn() and isset($_GET['lang']) ) {
51 setcookie('NP_Text', getVar('lang'), time()+60*60*24*90);
56 public function doSkinVar($skinType, $constant) {
57 global $member, $CONF;
59 $language = getLanguageName();
60 $getLanguage = isset($_GET['lang']) ? getVar('lang') : false;
61 $cookieLanguage = isset($_COOKIE['NP_Text']) ? cookieVar('NP_Text') : false;
64 $this->use_lang($getLanguage, $constant);
66 elseif ( $cookieLanguage ) {
67 $this->use_lang($cookieLanguage, $constant);
70 $this->use_lang($language, $constant);
74 public function doTemplateVar(&$item, $constant) {
75 global $member, $CONF;
77 $language = getLanguageName();
78 $getLanguage = isset($_GET['lang']) ? getVar('lang') : false;
79 $cookieLanguage = isset($_COOKIE['NP_Text']) ? cookieVar('NP_Text') : false;
82 $this->use_lang($getLanguage, $constant);
83 } elseif( $cookieLanguage ) {
84 $this->use_lang($cookieLanguage, $constant);
86 $this->use_lang($language, $constant);
90 public function use_lang($language, $constant) {
95 if ( $this->incModePref[0] == "normal" ) {
96 $filename = $filename.$this->incModePref[1];
97 $filename = $filename."language/";
98 $filename = $filename.$language;
99 $filename = $filename.".php";
100 } elseif ( $this->incModePref[0] == "skindir" ) {
101 $filename = $filename.$DIR_SKINS;
102 $filename = $filename.$this->incModePref[1];
103 $filename = $filename."language/";
104 $filename = $filename.$language;
105 $filename = $filename.".php";
108 if (is_file($filename)) {
111 addToLog(1, "NP_Text cannot find ".$filename);
114 if ( defined($this->constantPrefix.$constant) ) {
115 echo constant($this->constantPrefix.$constant);
117 echo $this->constantPrefix.$constant;
118 if( is_file($filename) ) {
119 addToLog(1, "NP_Text cannot find definition for ".$this->constantPrefix.$constant." in ".$filename);
125 public function skin_incmodepref() {
126 global $currentSkinName;
127 $sql = "SELECT * FROM ".sql_table("skin_desc")." WHERE sdname = '".$currentSkinName."'";
128 $result = sql_query($sql);
129 $row = sql_fetch_array($result, MYSQL_ASSOC);
130 return array($row['sdincmode'], $row['sdincpref']);