OSDN Git Service

4.0のtrunkを展開するためにmasterディレクトリを作成しファイル群を移動した。
[nucleus-jp/nucleus-jp-ancient.git] / nucleus / plugins / NP_Text.php
1 <?php
2 /**
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.
8  * 
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.
13  */
14
15 class NP_Text extends NucleusPlugin {
16         private $incModePref = array();
17         private $constantPrefix = "SL_";
18         
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
28                                 break;
29                         case 'japanese-euc':\r
30                                 $desc = mb_convert_encoding($desc,'EUC-JP','UTF-8');\r
31                                 break;\r
32                         default:\r
33                                 $desc ='Display constants from language files: <%Text(CONSTANT)%>';\r
34                                 break;\r
35                 }
36                 return $desc;
37         }
38         public function supportsFeature($feature)       { return in_array ($feature, array ('SqlTablePrefix', 'SqlApi'));}
39         public function install() { return; }
40         public function uninstall() { return; }
41         
42         public function init() {
43                 $this->incModePref = $this->skin_incmodepref();
44                 return;
45         }
46         
47         public function event_PreSkinParse() {
48                 global $member;
49                 if( !$member->isLoggedIn() and isset($_GET['lang']) ) {
50                         // 3 months
51                         setcookie('NP_Text', getVar('lang'), time()+60*60*24*90);
52                 }
53                 return;
54         }
55         
56         public function doSkinVar($skinType, $constant) {
57                 global $member, $CONF;
58                 
59                 $language = getLanguageName();
60                 $getLanguage = isset($_GET['lang']) ? getVar('lang') : false;
61                 $cookieLanguage = isset($_COOKIE['NP_Text']) ? cookieVar('NP_Text') : false;
62                 
63                 if ( $getLanguage ) {
64                         $this->use_lang($getLanguage, $constant);
65                 }
66                 elseif ( $cookieLanguage ) {
67                         $this->use_lang($cookieLanguage, $constant);
68                 }
69                 else {
70                         $this->use_lang($language, $constant);
71                 }
72         }
73         
74         public function doTemplateVar(&$item, $constant) {
75                 global $member, $CONF;
76                 
77                 $language = getLanguageName();
78                 $getLanguage = isset($_GET['lang']) ? getVar('lang') : false;
79                 $cookieLanguage = isset($_COOKIE['NP_Text']) ? cookieVar('NP_Text') : false;
80                 
81                 if ($getLanguage) {
82                         $this->use_lang($getLanguage, $constant);
83                 } elseif( $cookieLanguage ) {
84                         $this->use_lang($cookieLanguage, $constant);
85                 } else {
86                         $this->use_lang($language, $constant);
87                 }
88         }
89         
90         public function use_lang($language, $constant) {
91                 global $DIR_SKINS;
92                 
93                 $filename = '';
94                 
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";
106                 }
107                 
108                 if (is_file($filename)) {
109                         include($filename);
110                 } else {
111                         addToLog(1, "NP_Text cannot find ".$filename);
112                 }
113                 
114                 if ( defined($this->constantPrefix.$constant) ) {
115                         echo constant($this->constantPrefix.$constant);
116                 } else {
117                         echo $this->constantPrefix.$constant;
118                         if( is_file($filename) ) {
119                                 addToLog(1, "NP_Text cannot find definition for ".$this->constantPrefix.$constant." in ".$filename);
120                         }
121                 }
122                 return;
123         }
124         
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']);
131         }
132 }