4 This software is published under the same license as NucleusCMS, namely
5 the GNU General Public License. See http://www.gnu.org/licenses/gpl.html for
6 details about the conditions of this license.
8 In general, this program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 2 of the License, or (at your option) any
13 This program is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
15 PARTICULAR PURPOSE. See the GNU General Public License for more details.
17 * @version $Id: NP_Text.php 1678 2012-02-26 07:31:36Z sakamocchi $
19 class NP_Text extends NucleusPlugin
21 public $incModePref = array();
22 public $errorLogged = false;
23 public $constantPrefix = "SL_";
25 public function getName()
29 public function getAuthor()
31 return 'Armon Toubman';
34 public function getURL()
36 return 'http://forum.nucleuscms.org/viewtopic.php?t=14904';
39 public function getVersion()
44 public function getDescription()
46 return 'Display constants from translation files: <%Text(CONSTANT)%>';
49 public function getEventList()
51 return array('PreSkinParse');
54 public function supportsFeature($feature)
56 return ( $feature == 'SqlTablePrefix' );
59 public function install()
64 public function uninstall()
69 public function init()
71 $this->incModePref = $this->skin_incmodepref();
75 public function event_PreSkinParse()
78 if( !$member->isLoggedIn() and isset($_GET['lang']) )
81 setcookie('NP_Text', getVar('lang'), time()+60*60*24*90);
86 public function doSkinVar($skinType, $constant)
88 global $member, $CONF;
90 $language = getLanguageName();
91 $getLanguage = isset($_GET['lang']) ? getVar('lang') : false;
92 $cookieLanguage = isset($_COOKIE['NP_Text']) ? cookieVar('NP_Text') : false;
96 $this->use_lang($getLanguage, $constant);
98 elseif( $cookieLanguage )
100 $this->use_lang($cookieLanguage, $constant);
104 $this->use_lang($language, $constant);
109 public function doTemplateVar(&$item, $constant)
111 global $member, $CONF;
113 $language = getLanguageName();
114 $getLanguage = isset($_GET['lang']) ? getVar('lang') : false;
115 $cookieLanguage = isset($_COOKIE['NP_Text']) ? cookieVar('NP_Text') : false;
119 $this->use_lang($getLanguage, $constant);
121 elseif( $cookieLanguage )
123 $this->use_lang($cookieLanguage, $constant);
127 $this->use_lang($language, $constant);
132 private function use_lang($language, $constant)
138 if( $this->incModePref[0] == "normal" )
140 $filename = $filename.$this->incModePref[1];
141 $filename = $filename."language/";
142 $filename = $filename.$language;
143 $filename = $filename.".php";
145 elseif( $this->incModePref[0] == "skindir" )
147 $filename = $filename.$DIR_SKINS;
148 $filename = $filename.$this->incModePref[1];
149 $filename = $filename."language/";
150 $filename = $filename.$language;
151 $filename = $filename.".php";
154 if ( is_file($filename) )
160 addToLog(1, "NP_Text cannot find ".$filename);
163 if ( defined($this->constantPrefix.$constant) )
165 echo constant($this->constantPrefix.$constant);
169 echo $this->constantPrefix.$constant;
170 if( is_file($filename) )
172 addToLog(1, "NP_Text cannot find definition for ".$this->constantPrefix.$constant." in ".$filename);
178 private function skin_incmodepref()
180 global $currentSkinName;
181 $sql = "SELECT * FROM " . sql_table("skin_desc") . " WHERE sdname = '" . $currentSkinName . "'";
182 $result = sql_query($sql);
183 $row = sql_fetch_array($result, MYSQL_ASSOC);
184 return array($row['sdincmode'], $row['sdincpref']);