OSDN Git Service

FIX:クエリの記述ミスにより、Blogのチームメンバーが追加できなくなっていた不具合を修正
[nucleus-jp/nucleus-next.git] / nucleus / plugins / NP_Text.php
1 <?php
2 /*
3 License:
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.
7
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
11 later version.
12
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.
16
17 * @version $Id: NP_Text.php 1678 2012-02-26 07:31:36Z sakamocchi $
18 */
19 class NP_Text extends NucleusPlugin
20 {
21         public $incModePref = array();
22         public $errorLogged = false;
23         public $constantPrefix = "SL_";
24         
25         public function getName()
26         {
27                 return 'Text';
28         }
29         public function getAuthor()
30         {
31                 return 'Armon Toubman';
32         }
33
34         public function getURL()
35         {
36                 return 'http://forum.nucleuscms.org/viewtopic.php?t=14904';
37         }
38
39         public function getVersion()
40         {
41                 return '0.53';
42         }
43
44         public function getDescription()
45         {
46                 return 'Display constants from translation files: <%Text(CONSTANT)%>';
47         }
48
49         public function getEventList()
50         {
51                 return array('PreSkinParse');
52         }
53
54         public function supportsFeature($feature)
55         {
56                 return ( $feature == 'SqlTablePrefix' );
57         }
58
59         public function install()
60         {
61                 return;
62         }
63
64         public function uninstall()
65         {
66                 return;
67         }
68
69         public function init()
70         {
71                 $this->incModePref = $this->skin_incmodepref();
72                 return;
73         }
74         
75         public function event_PreSkinParse()
76         {
77                 global $member;
78                 if( !$member->isLoggedIn() and isset($_GET['lang']) )
79                 {
80                         /* 3 months */
81                         setcookie('NP_Text', getVar('lang'), time()+60*60*24*90);
82                 }
83                 return;
84         }
85          
86         public function doSkinVar($skinType, $constant)
87         {
88                 global $member, $CONF;
89                 
90                 $language = getLanguageName();
91                 $getLanguage = isset($_GET['lang']) ? getVar('lang') : false;
92                 $cookieLanguage = isset($_COOKIE['NP_Text']) ? cookieVar('NP_Text') : false;
93                 
94                 if( $getLanguage )
95                 {
96                         $this->use_lang($getLanguage, $constant);
97                 }
98                 elseif( $cookieLanguage )
99                 {
100                         $this->use_lang($cookieLanguage, $constant);
101                 }
102                 else
103                 {
104                         $this->use_lang($language, $constant);
105                 }
106                 return;
107         }
108         
109         public function doTemplateVar(&$item, $constant)
110         {
111                 global $member, $CONF;
112                 
113                 $language = getLanguageName();
114                 $getLanguage = isset($_GET['lang']) ? getVar('lang') : false;
115                 $cookieLanguage = isset($_COOKIE['NP_Text']) ? cookieVar('NP_Text') : false;
116                 
117                 if( $getLanguage )
118                 {
119                         $this->use_lang($getLanguage, $constant);
120                 }
121                 elseif( $cookieLanguage )
122                 {
123                         $this->use_lang($cookieLanguage, $constant);
124                 }
125                 else
126                 {
127                         $this->use_lang($language, $constant);
128                 }
129                 return;
130         }
131         
132         private function use_lang($language, $constant)
133         {
134                 global $DIR_SKINS;
135                 
136                 $filename = '';
137                 
138                 if( $this->incModePref[0] == "normal" )
139                 {
140                         $filename = $filename.$this->incModePref[1];
141                         $filename = $filename."language/";
142                         $filename = $filename.$language;
143                         $filename = $filename.".php";
144                 }
145                 elseif( $this->incModePref[0] == "skindir" )
146                 {
147                         $filename = $filename.$DIR_SKINS;
148                         $filename = $filename.$this->incModePref[1];
149                         $filename = $filename."language/";
150                         $filename = $filename.$language;
151                         $filename = $filename.".php";
152                 }
153                 
154                 if ( is_file($filename) )
155                 {
156                         include($filename);
157                 }
158                 else
159                 {
160                         addToLog(1, "NP_Text cannot find ".$filename);
161                 }
162                 
163                 if ( defined($this->constantPrefix.$constant) )
164                 {
165                         echo constant($this->constantPrefix.$constant);
166                 }
167                 else
168                 {
169                         echo $this->constantPrefix.$constant;
170                         if( is_file($filename) )
171                         {
172                                 addToLog(1, "NP_Text cannot find definition for ".$this->constantPrefix.$constant." in ".$filename);
173                         }
174                 }
175                 return;
176         }
177         
178         private function skin_incmodepref()
179         {
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']);
185         }
186 }