author | Dan |
Thu, 17 Dec 2009 04:29:55 -0500 | |
changeset 1169 | d5474f54a525 |
parent 1081 | 745200a9cc2a |
child 1227 | bdac73ed481e |
permissions | -rw-r--r-- |
205 | 1 |
<?php |
2 |
||
3 |
/* |
|
4 |
* Enano - an open-source CMS capable of wiki functions, Drupal-like sidebar blocks, and everything in between |
|
1081
745200a9cc2a
Fixed some upgrade bugs; added support for choosing one's own date/time formats; rebrand as 1.1.7
Dan
parents:
1036
diff
changeset
|
5 |
* Copyright (C) 2006-2009 Dan Fuhry |
205 | 6 |
* |
7 |
* This program is Free Software; you can redistribute and/or modify it under the terms of the GNU General Public License |
|
8 |
* as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. |
|
9 |
* |
|
10 |
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied |
|
11 |
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for details. |
|
12 |
*/ |
|
13 |
||
14 |
/** |
|
15 |
* Language class - processes, stores, and retrieves language strings. |
|
16 |
* @package Enano |
|
17 |
* @subpackage Localization |
|
18 |
* @copyright 2007 Dan Fuhry |
|
19 |
* @license GNU General Public License |
|
20 |
*/ |
|
21 |
||
22 |
class Language |
|
23 |
{ |
|
24 |
||
25 |
/** |
|
26 |
* The numerical ID of the loaded language. |
|
27 |
* @var int |
|
28 |
*/ |
|
29 |
||
30 |
var $lang_id; |
|
31 |
||
32 |
/** |
|
33 |
* The ISO-639-3 code for the loaded language. This should be grabbed directly from the database. |
|
34 |
* @var string |
|
35 |
*/ |
|
36 |
||
37 |
var $lang_code; |
|
210
2b283402e4e4
Added language export to JSON page and localization for Javascript using $lang.get(). Localized AJAX login interface.
Dan
parents:
209
diff
changeset
|
38 |
|
2b283402e4e4
Added language export to JSON page and localization for Javascript using $lang.get(). Localized AJAX login interface.
Dan
parents:
209
diff
changeset
|
39 |
/** |
2b283402e4e4
Added language export to JSON page and localization for Javascript using $lang.get(). Localized AJAX login interface.
Dan
parents:
209
diff
changeset
|
40 |
* Used to track when a language was last changed, to allow browsers to cache language data |
2b283402e4e4
Added language export to JSON page and localization for Javascript using $lang.get(). Localized AJAX login interface.
Dan
parents:
209
diff
changeset
|
41 |
* @var int |
2b283402e4e4
Added language export to JSON page and localization for Javascript using $lang.get(). Localized AJAX login interface.
Dan
parents:
209
diff
changeset
|
42 |
*/ |
2b283402e4e4
Added language export to JSON page and localization for Javascript using $lang.get(). Localized AJAX login interface.
Dan
parents:
209
diff
changeset
|
43 |
|
2b283402e4e4
Added language export to JSON page and localization for Javascript using $lang.get(). Localized AJAX login interface.
Dan
parents:
209
diff
changeset
|
44 |
var $lang_timestamp; |
205 | 45 |
|
46 |
/** |
|
47 |
* Will be an object that holds an instance of the class configured with the site's default language. Only instanciated when needed. |
|
48 |
* @var object |
|
49 |
*/ |
|
50 |
||
51 |
var $default; |
|
52 |
||
53 |
/** |
|
54 |
* The list of loaded strings. |
|
55 |
* @var array |
|
56 |
* @access private |
|
57 |
*/ |
|
58 |
||
59 |
var $strings = array(); |
|
60 |
||
61 |
/** |
|
504
bc8e0e9ee01d
Added support for embedding language data into plugins; updated all version numbers on plugin files
Dan
parents:
391
diff
changeset
|
62 |
* Switch for debug mode. If true, will show an asterisk after localized strings. This |
bc8e0e9ee01d
Added support for embedding language data into plugins; updated all version numbers on plugin files
Dan
parents:
391
diff
changeset
|
63 |
* can be useful if you're localizing a component and need to see what's already done. |
bc8e0e9ee01d
Added support for embedding language data into plugins; updated all version numbers on plugin files
Dan
parents:
391
diff
changeset
|
64 |
* @var bool |
bc8e0e9ee01d
Added support for embedding language data into plugins; updated all version numbers on plugin files
Dan
parents:
391
diff
changeset
|
65 |
*/ |
bc8e0e9ee01d
Added support for embedding language data into plugins; updated all version numbers on plugin files
Dan
parents:
391
diff
changeset
|
66 |
|
bc8e0e9ee01d
Added support for embedding language data into plugins; updated all version numbers on plugin files
Dan
parents:
391
diff
changeset
|
67 |
var $debug = false; |
bc8e0e9ee01d
Added support for embedding language data into plugins; updated all version numbers on plugin files
Dan
parents:
391
diff
changeset
|
68 |
|
bc8e0e9ee01d
Added support for embedding language data into plugins; updated all version numbers on plugin files
Dan
parents:
391
diff
changeset
|
69 |
/** |
668
0631e4de5de6
Added ability to have language strings send variables through filter functions. Operates based on predefined filters, expandable with a call to Language::register_filter at the hook lang_init
Dan
parents:
654
diff
changeset
|
70 |
* List of available filters to pass variables through. |
0631e4de5de6
Added ability to have language strings send variables through filter functions. Operates based on predefined filters, expandable with a call to Language::register_filter at the hook lang_init
Dan
parents:
654
diff
changeset
|
71 |
* @var array |
0631e4de5de6
Added ability to have language strings send variables through filter functions. Operates based on predefined filters, expandable with a call to Language::register_filter at the hook lang_init
Dan
parents:
654
diff
changeset
|
72 |
* @access private |
0631e4de5de6
Added ability to have language strings send variables through filter functions. Operates based on predefined filters, expandable with a call to Language::register_filter at the hook lang_init
Dan
parents:
654
diff
changeset
|
73 |
*/ |
0631e4de5de6
Added ability to have language strings send variables through filter functions. Operates based on predefined filters, expandable with a call to Language::register_filter at the hook lang_init
Dan
parents:
654
diff
changeset
|
74 |
|
0631e4de5de6
Added ability to have language strings send variables through filter functions. Operates based on predefined filters, expandable with a call to Language::register_filter at the hook lang_init
Dan
parents:
654
diff
changeset
|
75 |
protected $filters = array(); |
0631e4de5de6
Added ability to have language strings send variables through filter functions. Operates based on predefined filters, expandable with a call to Language::register_filter at the hook lang_init
Dan
parents:
654
diff
changeset
|
76 |
|
0631e4de5de6
Added ability to have language strings send variables through filter functions. Operates based on predefined filters, expandable with a call to Language::register_filter at the hook lang_init
Dan
parents:
654
diff
changeset
|
77 |
/** |
205 | 78 |
* Constructor. |
79 |
* @param int|string Language ID or code to load. |
|
80 |
*/ |
|
81 |
||
82 |
function __construct($lang) |
|
83 |
{ |
|
84 |
global $db, $session, $paths, $template, $plugins; // Common objects |
|
85 |
||
626
be0e904eec17
Refined upgrade process a bit. Uses libenanoinstall (incomplete), and post stage added to flush caches and import new strings
Dan
parents:
623
diff
changeset
|
86 |
if ( defined('IN_ENANO_INSTALL') && ( !defined('ENANO_CONFIG_FETCHED') || ( defined('IN_ENANO_UPGRADE') && !defined('IN_ENANO_UPGRADE_POST') ) ) ) |
205 | 87 |
{ |
616
e311f5e6f904
Got the installer working. Fixed a few bugs including a nasty-to-debug issue where the lang_id was being hardcoded during installation, resulting in strings being inserted with the wrong lang_id causing an infinfinite loop with fetch() throwing a "no strings" error and using template (which calls fetch()) to complain
Dan
parents:
613
diff
changeset
|
88 |
// special case for the Enano installer: it will load its own strings from a JSON file and just use this API for fetching |
e311f5e6f904
Got the installer working. Fixed a few bugs including a nasty-to-debug issue where the lang_id was being hardcoded during installation, resulting in strings being inserted with the wrong lang_id causing an infinfinite loop with fetch() throwing a "no strings" error and using template (which calls fetch()) to complain
Dan
parents:
613
diff
changeset
|
89 |
// and templatizing them. |
e311f5e6f904
Got the installer working. Fixed a few bugs including a nasty-to-debug issue where the lang_id was being hardcoded during installation, resulting in strings being inserted with the wrong lang_id causing an infinfinite loop with fetch() throwing a "no strings" error and using template (which calls fetch()) to complain
Dan
parents:
613
diff
changeset
|
90 |
// 1.1.4 fix: this was still being called after main API startup from installer payload |
243
a7d0f2711df1
Installer localization started. Welcome, License, and SysReqs pages are fully localized.
Dan
parents:
241
diff
changeset
|
91 |
$this->lang_id = 1; |
a7d0f2711df1
Installer localization started. Welcome, License, and SysReqs pages are fully localized.
Dan
parents:
241
diff
changeset
|
92 |
$this->lang_code = $lang; |
205 | 93 |
return true; |
94 |
} |
|
95 |
if ( is_string($lang) ) |
|
96 |
{ |
|
371
dc6026376919
Improved compatibility with PostgreSQL and fixed a number of installer bugs; fixed missing "meta" category declaration in language files
Dan
parents:
355
diff
changeset
|
97 |
$sql_col = 'lang_code=\'' . $db->escape($lang) . '\''; |
205 | 98 |
} |
99 |
else if ( is_int($lang) ) |
|
100 |
{ |
|
101 |
$sql_col = 'lang_id=' . $lang . ''; |
|
102 |
} |
|
103 |
else |
|
104 |
{ |
|
105 |
$db->_die('lang.php - attempting to pass invalid value to constructor'); |
|
106 |
} |
|
107 |
||
616
e311f5e6f904
Got the installer working. Fixed a few bugs including a nasty-to-debug issue where the lang_id was being hardcoded during installation, resulting in strings being inserted with the wrong lang_id causing an infinfinite loop with fetch() throwing a "no strings" error and using template (which calls fetch()) to complain
Dan
parents:
613
diff
changeset
|
108 |
$lang_default = ( $x = getConfig('default_language') ) ? intval($x) : '0'; |
372
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
parents:
371
diff
changeset
|
109 |
|
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
parents:
371
diff
changeset
|
110 |
$q = $db->sql_query("SELECT lang_id, lang_code, last_changed, ( lang_id = $lang_default ) AS is_default FROM " . table_prefix . "language WHERE $sql_col OR lang_id = $lang_default ORDER BY is_default ASC LIMIT 1;"); |
205 | 111 |
|
112 |
if ( !$q ) |
|
113 |
$db->_die('lang.php - main select query'); |
|
114 |
||
115 |
if ( $db->numrows() < 1 ) |
|
116 |
$db->_die('lang.php - There are no languages installed'); |
|
117 |
||
118 |
$row = $db->fetchrow(); |
|
119 |
||
120 |
$this->lang_id = intval( $row['lang_id'] ); |
|
121 |
$this->lang_code = $row['lang_code']; |
|
210
2b283402e4e4
Added language export to JSON page and localization for Javascript using $lang.get(). Localized AJAX login interface.
Dan
parents:
209
diff
changeset
|
122 |
$this->lang_timestamp = $row['last_changed']; |
668
0631e4de5de6
Added ability to have language strings send variables through filter functions. Operates based on predefined filters, expandable with a call to Language::register_filter at the hook lang_init
Dan
parents:
654
diff
changeset
|
123 |
|
0631e4de5de6
Added ability to have language strings send variables through filter functions. Operates based on predefined filters, expandable with a call to Language::register_filter at the hook lang_init
Dan
parents:
654
diff
changeset
|
124 |
$this->register_filter('htmlsafe', 'htmlspecialchars'); |
0631e4de5de6
Added ability to have language strings send variables through filter functions. Operates based on predefined filters, expandable with a call to Language::register_filter at the hook lang_init
Dan
parents:
654
diff
changeset
|
125 |
$this->register_filter('urlencode', 'urlencode'); |
0631e4de5de6
Added ability to have language strings send variables through filter functions. Operates based on predefined filters, expandable with a call to Language::register_filter at the hook lang_init
Dan
parents:
654
diff
changeset
|
126 |
$this->register_filter('rawurlencode', 'rawurlencode'); |
0631e4de5de6
Added ability to have language strings send variables through filter functions. Operates based on predefined filters, expandable with a call to Language::register_filter at the hook lang_init
Dan
parents:
654
diff
changeset
|
127 |
|
0631e4de5de6
Added ability to have language strings send variables through filter functions. Operates based on predefined filters, expandable with a call to Language::register_filter at the hook lang_init
Dan
parents:
654
diff
changeset
|
128 |
$code = $plugins->setHook('lang_init'); |
0631e4de5de6
Added ability to have language strings send variables through filter functions. Operates based on predefined filters, expandable with a call to Language::register_filter at the hook lang_init
Dan
parents:
654
diff
changeset
|
129 |
foreach ( $code as $cmd ) |
0631e4de5de6
Added ability to have language strings send variables through filter functions. Operates based on predefined filters, expandable with a call to Language::register_filter at the hook lang_init
Dan
parents:
654
diff
changeset
|
130 |
{ |
0631e4de5de6
Added ability to have language strings send variables through filter functions. Operates based on predefined filters, expandable with a call to Language::register_filter at the hook lang_init
Dan
parents:
654
diff
changeset
|
131 |
eval($cmd); |
0631e4de5de6
Added ability to have language strings send variables through filter functions. Operates based on predefined filters, expandable with a call to Language::register_filter at the hook lang_init
Dan
parents:
654
diff
changeset
|
132 |
} |
205 | 133 |
} |
134 |
||
135 |
/** |
|
136 |
* Fetches language strings from the database, or a cache file if it's available. |
|
137 |
* @param bool If true (default), allows the cache to be used. |
|
138 |
*/ |
|
139 |
||
140 |
function fetch($allow_cache = true) |
|
141 |
{ |
|
142 |
global $db, $session, $paths, $template, $plugins; // Common objects |
|
143 |
||
144 |
// Attempt to load the strings from a cache file |
|
607
935f3799b654
First stab at cache management backend. Everything seems to have been tested and working so far, but a number of things require a more specialized cache and can't go through the framework (e.g. user ranks which use references to map usernames to user IDs)
Dan
parents:
593
diff
changeset
|
145 |
$loaded = false; |
935f3799b654
First stab at cache management backend. Everything seems to have been tested and working so far, but a number of things require a more specialized cache and can't go through the framework (e.g. user ranks which use references to map usernames to user IDs)
Dan
parents:
593
diff
changeset
|
146 |
|
935f3799b654
First stab at cache management backend. Everything seems to have been tested and working so far, but a number of things require a more specialized cache and can't go through the framework (e.g. user ranks which use references to map usernames to user IDs)
Dan
parents:
593
diff
changeset
|
147 |
if ( $allow_cache ) |
205 | 148 |
{ |
607
935f3799b654
First stab at cache management backend. Everything seems to have been tested and working so far, but a number of things require a more specialized cache and can't go through the framework (e.g. user ranks which use references to map usernames to user IDs)
Dan
parents:
593
diff
changeset
|
149 |
// Load the cache manager |
935f3799b654
First stab at cache management backend. Everything seems to have been tested and working so far, but a number of things require a more specialized cache and can't go through the framework (e.g. user ranks which use references to map usernames to user IDs)
Dan
parents:
593
diff
changeset
|
150 |
global $cache; |
935f3799b654
First stab at cache management backend. Everything seems to have been tested and working so far, but a number of things require a more specialized cache and can't go through the framework (e.g. user ranks which use references to map usernames to user IDs)
Dan
parents:
593
diff
changeset
|
151 |
|
935f3799b654
First stab at cache management backend. Everything seems to have been tested and working so far, but a number of things require a more specialized cache and can't go through the framework (e.g. user ranks which use references to map usernames to user IDs)
Dan
parents:
593
diff
changeset
|
152 |
if ( $cached = $cache->fetch("lang_{$this->lang_id}") ) |
935f3799b654
First stab at cache management backend. Everything seems to have been tested and working so far, but a number of things require a more specialized cache and can't go through the framework (e.g. user ranks which use references to map usernames to user IDs)
Dan
parents:
593
diff
changeset
|
153 |
{ |
935f3799b654
First stab at cache management backend. Everything seems to have been tested and working so far, but a number of things require a more specialized cache and can't go through the framework (e.g. user ranks which use references to map usernames to user IDs)
Dan
parents:
593
diff
changeset
|
154 |
$this->merge($cached); |
935f3799b654
First stab at cache management backend. Everything seems to have been tested and working so far, but a number of things require a more specialized cache and can't go through the framework (e.g. user ranks which use references to map usernames to user IDs)
Dan
parents:
593
diff
changeset
|
155 |
$loaded = true; |
935f3799b654
First stab at cache management backend. Everything seems to have been tested and working so far, but a number of things require a more specialized cache and can't go through the framework (e.g. user ranks which use references to map usernames to user IDs)
Dan
parents:
593
diff
changeset
|
156 |
} |
205 | 157 |
} |
607
935f3799b654
First stab at cache management backend. Everything seems to have been tested and working so far, but a number of things require a more specialized cache and can't go through the framework (e.g. user ranks which use references to map usernames to user IDs)
Dan
parents:
593
diff
changeset
|
158 |
if ( !$loaded ) |
205 | 159 |
{ |
160 |
// No cache file - select and retrieve from the database |
|
161 |
$q = $db->sql_unbuffered_query("SELECT string_category, string_name, string_content FROM " . table_prefix . "language_strings WHERE lang_id = {$this->lang_id};"); |
|
162 |
if ( !$q ) |
|
163 |
$db->_die('lang.php - selecting language string data'); |
|
164 |
if ( $row = $db->fetchrow() ) |
|
165 |
{ |
|
166 |
$strings = array(); |
|
167 |
do |
|
168 |
{ |
|
169 |
$cat =& $row['string_category']; |
|
371
dc6026376919
Improved compatibility with PostgreSQL and fixed a number of installer bugs; fixed missing "meta" category declaration in language files
Dan
parents:
355
diff
changeset
|
170 |
if ( !is_array(@$strings[$cat]) ) |
205 | 171 |
{ |
172 |
$strings[$cat] = array(); |
|
173 |
} |
|
174 |
$strings[$cat][ $row['string_name'] ] = $row['string_content']; |
|
175 |
} |
|
176 |
while ( $row = $db->fetchrow() ); |
|
177 |
// all done fetching |
|
178 |
$this->merge($strings); |
|
607
935f3799b654
First stab at cache management backend. Everything seems to have been tested and working so far, but a number of things require a more specialized cache and can't go through the framework (e.g. user ranks which use references to map usernames to user IDs)
Dan
parents:
593
diff
changeset
|
179 |
$this->regen_caches(false); |
205 | 180 |
} |
654
18dbf386d356
Made lang.php stop dying due to no strings installed for current language [experimental]
Dan
parents:
626
diff
changeset
|
181 |
/* |
205 | 182 |
else |
183 |
{ |
|
241
c671f3bb8aed
Trying to get lang import to work in the installer; it's not working ATM - cache file is generated with lang_id = 0. Syncing to Nighthawk.
Dan
parents:
239
diff
changeset
|
184 |
if ( !defined('ENANO_ALLOW_LOAD_NOLANG') ) |
c671f3bb8aed
Trying to get lang import to work in the installer; it's not working ATM - cache file is generated with lang_id = 0. Syncing to Nighthawk.
Dan
parents:
239
diff
changeset
|
185 |
$db->_die('lang.php - No strings for language ' . $this->lang_code); |
205 | 186 |
} |
654
18dbf386d356
Made lang.php stop dying due to no strings installed for current language [experimental]
Dan
parents:
626
diff
changeset
|
187 |
*/ |
205 | 188 |
} |
189 |
} |
|
190 |
||
191 |
/** |
|
192 |
* Loads a file from the disk cache (treated as PHP) and merges it into RAM. |
|
193 |
* @param string File to load |
|
194 |
*/ |
|
195 |
||
196 |
function load_cache_file($file) |
|
197 |
{ |
|
198 |
global $db, $session, $paths, $template, $plugins; // Common objects |
|
199 |
||
200 |
if ( !file_exists($file) ) |
|
201 |
$db->_die('lang.php - requested cache file doesn\'t exist'); |
|
202 |
||
590
03a60844c7c5
Several optimization changes including getting rid of a few eval()s. Added placeholder functions for the theme manager, which should be working now
Dan
parents:
555
diff
changeset
|
203 |
@include($file); |
03a60844c7c5
Several optimization changes including getting rid of a few eval()s. Added placeholder functions for the theme manager, which should be working now
Dan
parents:
555
diff
changeset
|
204 |
|
205 | 205 |
if ( !isset($lang_cache) || ( isset($lang_cache) && !is_array($lang_cache) ) ) |
206 |
$db->_die('lang.php - the cache file is invalid (didn\'t set $lang_cache as an array)'); |
|
207 |
||
208 |
$this->merge($lang_cache); |
|
209 |
} |
|
210 |
||
211 |
/** |
|
243
a7d0f2711df1
Installer localization started. Welcome, License, and SysReqs pages are fully localized.
Dan
parents:
241
diff
changeset
|
212 |
* Loads a JSON language file and parses the strings into RAM. Will use the cache if possible, but stays far away from the database, |
a7d0f2711df1
Installer localization started. Welcome, License, and SysReqs pages are fully localized.
Dan
parents:
241
diff
changeset
|
213 |
* which we assume doesn't exist yet. |
a7d0f2711df1
Installer localization started. Welcome, License, and SysReqs pages are fully localized.
Dan
parents:
241
diff
changeset
|
214 |
*/ |
a7d0f2711df1
Installer localization started. Welcome, License, and SysReqs pages are fully localized.
Dan
parents:
241
diff
changeset
|
215 |
|
a7d0f2711df1
Installer localization started. Welcome, License, and SysReqs pages are fully localized.
Dan
parents:
241
diff
changeset
|
216 |
function load_file($file) |
a7d0f2711df1
Installer localization started. Welcome, License, and SysReqs pages are fully localized.
Dan
parents:
241
diff
changeset
|
217 |
{ |
a7d0f2711df1
Installer localization started. Welcome, License, and SysReqs pages are fully localized.
Dan
parents:
241
diff
changeset
|
218 |
global $db, $session, $paths, $template, $plugins; // Common objects |
a7d0f2711df1
Installer localization started. Welcome, License, and SysReqs pages are fully localized.
Dan
parents:
241
diff
changeset
|
219 |
|
a7d0f2711df1
Installer localization started. Welcome, License, and SysReqs pages are fully localized.
Dan
parents:
241
diff
changeset
|
220 |
if ( !file_exists($file) ) |
348
87e08a6e4fec
Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents:
345
diff
changeset
|
221 |
{ |
87e08a6e4fec
Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents:
345
diff
changeset
|
222 |
if ( defined('IN_ENANO_INSTALL') ) |
87e08a6e4fec
Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents:
345
diff
changeset
|
223 |
{ |
87e08a6e4fec
Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents:
345
diff
changeset
|
224 |
die('lang.php - requested JSON file (' . htmlspecialchars($file) . ') doesn\'t exist'); |
87e08a6e4fec
Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents:
345
diff
changeset
|
225 |
} |
87e08a6e4fec
Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents:
345
diff
changeset
|
226 |
else |
87e08a6e4fec
Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents:
345
diff
changeset
|
227 |
{ |
87e08a6e4fec
Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents:
345
diff
changeset
|
228 |
$db->_die('lang.php - requested JSON file doesn\'t exist'); |
87e08a6e4fec
Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents:
345
diff
changeset
|
229 |
} |
87e08a6e4fec
Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents:
345
diff
changeset
|
230 |
} |
243
a7d0f2711df1
Installer localization started. Welcome, License, and SysReqs pages are fully localized.
Dan
parents:
241
diff
changeset
|
231 |
|
a7d0f2711df1
Installer localization started. Welcome, License, and SysReqs pages are fully localized.
Dan
parents:
241
diff
changeset
|
232 |
$contents = trim(@file_get_contents($file)); |
a7d0f2711df1
Installer localization started. Welcome, License, and SysReqs pages are fully localized.
Dan
parents:
241
diff
changeset
|
233 |
if ( empty($contents) ) |
a7d0f2711df1
Installer localization started. Welcome, License, and SysReqs pages are fully localized.
Dan
parents:
241
diff
changeset
|
234 |
$db->_die('lang.php - empty language file...'); |
a7d0f2711df1
Installer localization started. Welcome, License, and SysReqs pages are fully localized.
Dan
parents:
241
diff
changeset
|
235 |
|
a7d0f2711df1
Installer localization started. Welcome, License, and SysReqs pages are fully localized.
Dan
parents:
241
diff
changeset
|
236 |
// Trim off all text before and after the starting and ending braces |
a7d0f2711df1
Installer localization started. Welcome, License, and SysReqs pages are fully localized.
Dan
parents:
241
diff
changeset
|
237 |
$contents = preg_replace('/^([^{]+)\{/', '{', $contents); |
a7d0f2711df1
Installer localization started. Welcome, License, and SysReqs pages are fully localized.
Dan
parents:
241
diff
changeset
|
238 |
$contents = preg_replace('/\}([^}]+)$/', '}', $contents); |
a7d0f2711df1
Installer localization started. Welcome, License, and SysReqs pages are fully localized.
Dan
parents:
241
diff
changeset
|
239 |
$contents = trim($contents); |
a7d0f2711df1
Installer localization started. Welcome, License, and SysReqs pages are fully localized.
Dan
parents:
241
diff
changeset
|
240 |
|
a7d0f2711df1
Installer localization started. Welcome, License, and SysReqs pages are fully localized.
Dan
parents:
241
diff
changeset
|
241 |
if ( empty($contents) ) |
a7d0f2711df1
Installer localization started. Welcome, License, and SysReqs pages are fully localized.
Dan
parents:
241
diff
changeset
|
242 |
$db->_die('lang.php - no meat to the language file...'); |
a7d0f2711df1
Installer localization started. Welcome, License, and SysReqs pages are fully localized.
Dan
parents:
241
diff
changeset
|
243 |
|
a7d0f2711df1
Installer localization started. Welcome, License, and SysReqs pages are fully localized.
Dan
parents:
241
diff
changeset
|
244 |
$checksum = md5($contents); |
a7d0f2711df1
Installer localization started. Welcome, License, and SysReqs pages are fully localized.
Dan
parents:
241
diff
changeset
|
245 |
if ( file_exists("./cache/lang_json_{$checksum}.php") ) |
a7d0f2711df1
Installer localization started. Welcome, License, and SysReqs pages are fully localized.
Dan
parents:
241
diff
changeset
|
246 |
{ |
a7d0f2711df1
Installer localization started. Welcome, License, and SysReqs pages are fully localized.
Dan
parents:
241
diff
changeset
|
247 |
$this->load_cache_file("./cache/lang_json_{$checksum}.php"); |
a7d0f2711df1
Installer localization started. Welcome, License, and SysReqs pages are fully localized.
Dan
parents:
241
diff
changeset
|
248 |
} |
a7d0f2711df1
Installer localization started. Welcome, License, and SysReqs pages are fully localized.
Dan
parents:
241
diff
changeset
|
249 |
else |
a7d0f2711df1
Installer localization started. Welcome, License, and SysReqs pages are fully localized.
Dan
parents:
241
diff
changeset
|
250 |
{ |
348
87e08a6e4fec
Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents:
345
diff
changeset
|
251 |
// Correct syntax to be nice to the json parser |
87e08a6e4fec
Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents:
345
diff
changeset
|
252 |
|
87e08a6e4fec
Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents:
345
diff
changeset
|
253 |
// eliminate comments |
87e08a6e4fec
Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents:
345
diff
changeset
|
254 |
$contents = preg_replace(array( |
87e08a6e4fec
Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents:
345
diff
changeset
|
255 |
// eliminate single line comments in '// ...' form |
87e08a6e4fec
Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents:
345
diff
changeset
|
256 |
'#^\s*//(.+)$#m', |
87e08a6e4fec
Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents:
345
diff
changeset
|
257 |
// eliminate multi-line comments in '/* ... */' form, at start of string |
87e08a6e4fec
Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents:
345
diff
changeset
|
258 |
'#^\s*/\*(.+)\*/#Us', |
87e08a6e4fec
Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents:
345
diff
changeset
|
259 |
// eliminate multi-line comments in '/* ... */' form, at end of string |
87e08a6e4fec
Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents:
345
diff
changeset
|
260 |
'#/\*(.+)\*/\s*$#Us' |
87e08a6e4fec
Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents:
345
diff
changeset
|
261 |
), '', $contents); |
87e08a6e4fec
Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents:
345
diff
changeset
|
262 |
|
87e08a6e4fec
Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents:
345
diff
changeset
|
263 |
$contents = preg_replace('/([,\{\[])([\s]*?)([a-z0-9_]+)([\s]*?):/', '\\1\\2"\\3" :', $contents); |
87e08a6e4fec
Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents:
345
diff
changeset
|
264 |
|
87e08a6e4fec
Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents:
345
diff
changeset
|
265 |
try |
87e08a6e4fec
Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents:
345
diff
changeset
|
266 |
{ |
87e08a6e4fec
Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents:
345
diff
changeset
|
267 |
$langdata = enano_json_decode($contents); |
87e08a6e4fec
Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents:
345
diff
changeset
|
268 |
} |
87e08a6e4fec
Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents:
345
diff
changeset
|
269 |
catch(Zend_Json_Exception $e) |
87e08a6e4fec
Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents:
345
diff
changeset
|
270 |
{ |
87e08a6e4fec
Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents:
345
diff
changeset
|
271 |
$db->_die('lang.php - Exception caught by JSON parser</p><pre>' . htmlspecialchars(print_r($e, true)) . '</pre><p>'); |
87e08a6e4fec
Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents:
345
diff
changeset
|
272 |
exit; |
87e08a6e4fec
Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents:
345
diff
changeset
|
273 |
} |
243
a7d0f2711df1
Installer localization started. Welcome, License, and SysReqs pages are fully localized.
Dan
parents:
241
diff
changeset
|
274 |
|
a7d0f2711df1
Installer localization started. Welcome, License, and SysReqs pages are fully localized.
Dan
parents:
241
diff
changeset
|
275 |
if ( !is_array($langdata) ) |
a7d0f2711df1
Installer localization started. Welcome, License, and SysReqs pages are fully localized.
Dan
parents:
241
diff
changeset
|
276 |
$db->_die('lang.php - invalid language file'); |
a7d0f2711df1
Installer localization started. Welcome, License, and SysReqs pages are fully localized.
Dan
parents:
241
diff
changeset
|
277 |
|
a7d0f2711df1
Installer localization started. Welcome, License, and SysReqs pages are fully localized.
Dan
parents:
241
diff
changeset
|
278 |
if ( !isset($langdata['categories']) || !isset($langdata['strings']) ) |
a7d0f2711df1
Installer localization started. Welcome, License, and SysReqs pages are fully localized.
Dan
parents:
241
diff
changeset
|
279 |
$db->_die('lang.php - language file does not contain the proper items'); |
a7d0f2711df1
Installer localization started. Welcome, License, and SysReqs pages are fully localized.
Dan
parents:
241
diff
changeset
|
280 |
|
a7d0f2711df1
Installer localization started. Welcome, License, and SysReqs pages are fully localized.
Dan
parents:
241
diff
changeset
|
281 |
$this->merge($langdata['strings']); |
a7d0f2711df1
Installer localization started. Welcome, License, and SysReqs pages are fully localized.
Dan
parents:
241
diff
changeset
|
282 |
|
a7d0f2711df1
Installer localization started. Welcome, License, and SysReqs pages are fully localized.
Dan
parents:
241
diff
changeset
|
283 |
$lang_file = "./cache/lang_json_{$checksum}.php"; |
a7d0f2711df1
Installer localization started. Welcome, License, and SysReqs pages are fully localized.
Dan
parents:
241
diff
changeset
|
284 |
|
a7d0f2711df1
Installer localization started. Welcome, License, and SysReqs pages are fully localized.
Dan
parents:
241
diff
changeset
|
285 |
$handle = @fopen($lang_file, 'w'); |
a7d0f2711df1
Installer localization started. Welcome, License, and SysReqs pages are fully localized.
Dan
parents:
241
diff
changeset
|
286 |
if ( !$handle ) |
a7d0f2711df1
Installer localization started. Welcome, License, and SysReqs pages are fully localized.
Dan
parents:
241
diff
changeset
|
287 |
// Couldn't open the file. Silently fail and let the strings come from RAM. |
a7d0f2711df1
Installer localization started. Welcome, License, and SysReqs pages are fully localized.
Dan
parents:
241
diff
changeset
|
288 |
return false; |
a7d0f2711df1
Installer localization started. Welcome, License, and SysReqs pages are fully localized.
Dan
parents:
241
diff
changeset
|
289 |
|
a7d0f2711df1
Installer localization started. Welcome, License, and SysReqs pages are fully localized.
Dan
parents:
241
diff
changeset
|
290 |
// The file's open, that means we should be good. |
a7d0f2711df1
Installer localization started. Welcome, License, and SysReqs pages are fully localized.
Dan
parents:
241
diff
changeset
|
291 |
fwrite($handle, '<?php |
a7d0f2711df1
Installer localization started. Welcome, License, and SysReqs pages are fully localized.
Dan
parents:
241
diff
changeset
|
292 |
// This file was generated automatically by Enano. You should not edit this file because any changes you make |
a7d0f2711df1
Installer localization started. Welcome, License, and SysReqs pages are fully localized.
Dan
parents:
241
diff
changeset
|
293 |
// to it will not be visible in the ACP and all changes will be lost upon any changes to strings in the admin panel. |
a7d0f2711df1
Installer localization started. Welcome, License, and SysReqs pages are fully localized.
Dan
parents:
241
diff
changeset
|
294 |
|
a7d0f2711df1
Installer localization started. Welcome, License, and SysReqs pages are fully localized.
Dan
parents:
241
diff
changeset
|
295 |
$lang_cache = '); |
a7d0f2711df1
Installer localization started. Welcome, License, and SysReqs pages are fully localized.
Dan
parents:
241
diff
changeset
|
296 |
|
a7d0f2711df1
Installer localization started. Welcome, License, and SysReqs pages are fully localized.
Dan
parents:
241
diff
changeset
|
297 |
$exported = $this->var_export_string($this->strings); |
a7d0f2711df1
Installer localization started. Welcome, License, and SysReqs pages are fully localized.
Dan
parents:
241
diff
changeset
|
298 |
if ( empty($exported) ) |
a7d0f2711df1
Installer localization started. Welcome, License, and SysReqs pages are fully localized.
Dan
parents:
241
diff
changeset
|
299 |
// Ehh, that's not good |
a7d0f2711df1
Installer localization started. Welcome, License, and SysReqs pages are fully localized.
Dan
parents:
241
diff
changeset
|
300 |
$db->_die('lang.php - load_file(): var_export_string() failed'); |
a7d0f2711df1
Installer localization started. Welcome, License, and SysReqs pages are fully localized.
Dan
parents:
241
diff
changeset
|
301 |
|
a7d0f2711df1
Installer localization started. Welcome, License, and SysReqs pages are fully localized.
Dan
parents:
241
diff
changeset
|
302 |
fwrite($handle, $exported . '; ?>'); |
a7d0f2711df1
Installer localization started. Welcome, License, and SysReqs pages are fully localized.
Dan
parents:
241
diff
changeset
|
303 |
|
a7d0f2711df1
Installer localization started. Welcome, License, and SysReqs pages are fully localized.
Dan
parents:
241
diff
changeset
|
304 |
// Clean up |
a7d0f2711df1
Installer localization started. Welcome, License, and SysReqs pages are fully localized.
Dan
parents:
241
diff
changeset
|
305 |
unset($exported, $langdata); |
a7d0f2711df1
Installer localization started. Welcome, License, and SysReqs pages are fully localized.
Dan
parents:
241
diff
changeset
|
306 |
|
a7d0f2711df1
Installer localization started. Welcome, License, and SysReqs pages are fully localized.
Dan
parents:
241
diff
changeset
|
307 |
// Done =) |
a7d0f2711df1
Installer localization started. Welcome, License, and SysReqs pages are fully localized.
Dan
parents:
241
diff
changeset
|
308 |
fclose($handle); |
a7d0f2711df1
Installer localization started. Welcome, License, and SysReqs pages are fully localized.
Dan
parents:
241
diff
changeset
|
309 |
} |
a7d0f2711df1
Installer localization started. Welcome, License, and SysReqs pages are fully localized.
Dan
parents:
241
diff
changeset
|
310 |
} |
a7d0f2711df1
Installer localization started. Welcome, License, and SysReqs pages are fully localized.
Dan
parents:
241
diff
changeset
|
311 |
|
a7d0f2711df1
Installer localization started. Welcome, License, and SysReqs pages are fully localized.
Dan
parents:
241
diff
changeset
|
312 |
/** |
205 | 313 |
* Merges a standard language assoc array ($arr[cat][stringid]) with the master in RAM. |
314 |
* @param array |
|
315 |
*/ |
|
316 |
||
317 |
function merge($strings) |
|
318 |
{ |
|
319 |
// This is stupidly simple. |
|
320 |
foreach ( $strings as $cat_id => $contents ) |
|
321 |
{ |
|
243
a7d0f2711df1
Installer localization started. Welcome, License, and SysReqs pages are fully localized.
Dan
parents:
241
diff
changeset
|
322 |
if ( !isset($this->strings[$cat_id]) || ( isset($this->strings[$cat_id]) && !is_array($this->strings[$cat_id]) ) ) |
205 | 323 |
$this->strings[$cat_id] = array(); |
324 |
foreach ( $contents as $string_id => $string ) |
|
325 |
{ |
|
326 |
$this->strings[$cat_id][$string_id] = $string; |
|
327 |
} |
|
328 |
} |
|
329 |
} |
|
330 |
||
331 |
/** |
|
332 |
* Imports a JSON-format language file into the database and merges with current strings. |
|
333 |
* @param string Path to the JSON file to load |
|
626
be0e904eec17
Refined upgrade process a bit. Uses libenanoinstall (incomplete), and post stage added to flush caches and import new strings
Dan
parents:
623
diff
changeset
|
334 |
* @param bool If true, only imports new strings and skips those that already exist. Defaults to false (import all strings) |
514
ecbfb747743e
Added debugging switch to $lang->import() for help with optimization
Dan
parents:
507
diff
changeset
|
335 |
* @param bool Enable debugging output, makes the process over CLI more interesting |
205 | 336 |
*/ |
337 |
||
626
be0e904eec17
Refined upgrade process a bit. Uses libenanoinstall (incomplete), and post stage added to flush caches and import new strings
Dan
parents:
623
diff
changeset
|
338 |
function import($file, $skip_existing = false, $debug = false) |
205 | 339 |
{ |
340 |
global $db, $session, $paths, $template, $plugins; // Common objects |
|
341 |
||
342 |
if ( !file_exists($file) ) |
|
343 |
$db->_die('lang.php - can\'t import language file: string file doesn\'t exist'); |
|
344 |
||
241
c671f3bb8aed
Trying to get lang import to work in the installer; it's not working ATM - cache file is generated with lang_id = 0. Syncing to Nighthawk.
Dan
parents:
239
diff
changeset
|
345 |
if ( $this->lang_id == 0 ) |
c671f3bb8aed
Trying to get lang import to work in the installer; it's not working ATM - cache file is generated with lang_id = 0. Syncing to Nighthawk.
Dan
parents:
239
diff
changeset
|
346 |
$db->_die('lang.php - BUG: trying to perform import when $lang->lang_id == 0'); |
c671f3bb8aed
Trying to get lang import to work in the installer; it's not working ATM - cache file is generated with lang_id = 0. Syncing to Nighthawk.
Dan
parents:
239
diff
changeset
|
347 |
|
514
ecbfb747743e
Added debugging switch to $lang->import() for help with optimization
Dan
parents:
507
diff
changeset
|
348 |
if ( $debug ) |
516
9a52679143db
Added debugging ability to Language::import() for CLI usage
Dan
parents:
514
diff
changeset
|
349 |
$br = ( isset($_SERVER['REQUEST_URI']) ) ? '<br />' : ''; |
9a52679143db
Added debugging ability to Language::import() for CLI usage
Dan
parents:
514
diff
changeset
|
350 |
|
9a52679143db
Added debugging ability to Language::import() for CLI usage
Dan
parents:
514
diff
changeset
|
351 |
if ( $debug ) |
9a52679143db
Added debugging ability to Language::import() for CLI usage
Dan
parents:
514
diff
changeset
|
352 |
echo "Importing file: $file$br\n Checking file...$br\n"; |
514
ecbfb747743e
Added debugging switch to $lang->import() for help with optimization
Dan
parents:
507
diff
changeset
|
353 |
|
205 | 354 |
$contents = trim(@file_get_contents($file)); |
355 |
||
356 |
if ( empty($contents) ) |
|
357 |
$db->_die('lang.php - can\'t load the contents of the language file'); |
|
358 |
||
514
ecbfb747743e
Added debugging switch to $lang->import() for help with optimization
Dan
parents:
507
diff
changeset
|
359 |
if ( $debug ) |
516
9a52679143db
Added debugging ability to Language::import() for CLI usage
Dan
parents:
514
diff
changeset
|
360 |
echo " Cleaning up JSON$br\n"; |
514
ecbfb747743e
Added debugging switch to $lang->import() for help with optimization
Dan
parents:
507
diff
changeset
|
361 |
|
205 | 362 |
// Trim off all text before and after the starting and ending braces |
363 |
$contents = preg_replace('/^([^{]+)\{/', '{', $contents); |
|
364 |
$contents = preg_replace('/\}([^}]+)$/', '}', $contents); |
|
365 |
||
334
c72b545f1304
More localization work. Resolved major issue with JSON parser not parsing files over ~50KB. Switched JSON parser to the one from the Zend Framework (BSD licensed). Forced to split enano.json into five different files.
Dan
parents:
243
diff
changeset
|
366 |
// Correct syntax to be nice to the json parser |
372
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
parents:
371
diff
changeset
|
367 |
$contents = enano_clean_json($contents); |
334
c72b545f1304
More localization work. Resolved major issue with JSON parser not parsing files over ~50KB. Switched JSON parser to the one from the Zend Framework (BSD licensed). Forced to split enano.json into five different files.
Dan
parents:
243
diff
changeset
|
368 |
|
514
ecbfb747743e
Added debugging switch to $lang->import() for help with optimization
Dan
parents:
507
diff
changeset
|
369 |
if ( $debug ) |
516
9a52679143db
Added debugging ability to Language::import() for CLI usage
Dan
parents:
514
diff
changeset
|
370 |
echo " Decoding JSON stream$br\n"; |
514
ecbfb747743e
Added debugging switch to $lang->import() for help with optimization
Dan
parents:
507
diff
changeset
|
371 |
|
334
c72b545f1304
More localization work. Resolved major issue with JSON parser not parsing files over ~50KB. Switched JSON parser to the one from the Zend Framework (BSD licensed). Forced to split enano.json into five different files.
Dan
parents:
243
diff
changeset
|
372 |
try |
c72b545f1304
More localization work. Resolved major issue with JSON parser not parsing files over ~50KB. Switched JSON parser to the one from the Zend Framework (BSD licensed). Forced to split enano.json into five different files.
Dan
parents:
243
diff
changeset
|
373 |
{ |
c72b545f1304
More localization work. Resolved major issue with JSON parser not parsing files over ~50KB. Switched JSON parser to the one from the Zend Framework (BSD licensed). Forced to split enano.json into five different files.
Dan
parents:
243
diff
changeset
|
374 |
$langdata = enano_json_decode($contents); |
c72b545f1304
More localization work. Resolved major issue with JSON parser not parsing files over ~50KB. Switched JSON parser to the one from the Zend Framework (BSD licensed). Forced to split enano.json into five different files.
Dan
parents:
243
diff
changeset
|
375 |
} |
c72b545f1304
More localization work. Resolved major issue with JSON parser not parsing files over ~50KB. Switched JSON parser to the one from the Zend Framework (BSD licensed). Forced to split enano.json into five different files.
Dan
parents:
243
diff
changeset
|
376 |
catch(Zend_Json_Exception $e) |
c72b545f1304
More localization work. Resolved major issue with JSON parser not parsing files over ~50KB. Switched JSON parser to the one from the Zend Framework (BSD licensed). Forced to split enano.json into five different files.
Dan
parents:
243
diff
changeset
|
377 |
{ |
335
67bd3121a12e
Replaced TinyMCE 2.x with 3.0 beta 3. Supports everything but IE. Also rewrote the editor interface completely from the ground up.
Dan
parents:
334
diff
changeset
|
378 |
$db->_die('lang.php - Exception caught by JSON parser</p><pre>' . htmlspecialchars(print_r($e, true)) . '</pre><p>'); |
334
c72b545f1304
More localization work. Resolved major issue with JSON parser not parsing files over ~50KB. Switched JSON parser to the one from the Zend Framework (BSD licensed). Forced to split enano.json into five different files.
Dan
parents:
243
diff
changeset
|
379 |
exit; |
c72b545f1304
More localization work. Resolved major issue with JSON parser not parsing files over ~50KB. Switched JSON parser to the one from the Zend Framework (BSD licensed). Forced to split enano.json into five different files.
Dan
parents:
243
diff
changeset
|
380 |
} |
205 | 381 |
|
382 |
if ( !is_array($langdata) ) |
|
334
c72b545f1304
More localization work. Resolved major issue with JSON parser not parsing files over ~50KB. Switched JSON parser to the one from the Zend Framework (BSD licensed). Forced to split enano.json into five different files.
Dan
parents:
243
diff
changeset
|
383 |
{ |
c72b545f1304
More localization work. Resolved major issue with JSON parser not parsing files over ~50KB. Switched JSON parser to the one from the Zend Framework (BSD licensed). Forced to split enano.json into five different files.
Dan
parents:
243
diff
changeset
|
384 |
$db->_die('lang.php - invalid or non-well-formed language file'); |
c72b545f1304
More localization work. Resolved major issue with JSON parser not parsing files over ~50KB. Switched JSON parser to the one from the Zend Framework (BSD licensed). Forced to split enano.json into five different files.
Dan
parents:
243
diff
changeset
|
385 |
} |
205 | 386 |
|
514
ecbfb747743e
Added debugging switch to $lang->import() for help with optimization
Dan
parents:
507
diff
changeset
|
387 |
if ( $debug ) |
516
9a52679143db
Added debugging ability to Language::import() for CLI usage
Dan
parents:
514
diff
changeset
|
388 |
echo " Starting string import$br\n"; |
514
ecbfb747743e
Added debugging switch to $lang->import() for help with optimization
Dan
parents:
507
diff
changeset
|
389 |
|
626
be0e904eec17
Refined upgrade process a bit. Uses libenanoinstall (incomplete), and post stage added to flush caches and import new strings
Dan
parents:
623
diff
changeset
|
390 |
return $this->import_array($langdata, $skip_existing, $debug); |
504
bc8e0e9ee01d
Added support for embedding language data into plugins; updated all version numbers on plugin files
Dan
parents:
391
diff
changeset
|
391 |
} |
bc8e0e9ee01d
Added support for embedding language data into plugins; updated all version numbers on plugin files
Dan
parents:
391
diff
changeset
|
392 |
|
bc8e0e9ee01d
Added support for embedding language data into plugins; updated all version numbers on plugin files
Dan
parents:
391
diff
changeset
|
393 |
/** |
bc8e0e9ee01d
Added support for embedding language data into plugins; updated all version numbers on plugin files
Dan
parents:
391
diff
changeset
|
394 |
* Imports a JSON-format language file into the database and merges with current strings. |
bc8e0e9ee01d
Added support for embedding language data into plugins; updated all version numbers on plugin files
Dan
parents:
391
diff
changeset
|
395 |
* @param string Path to plugin file |
bc8e0e9ee01d
Added support for embedding language data into plugins; updated all version numbers on plugin files
Dan
parents:
391
diff
changeset
|
396 |
*/ |
bc8e0e9ee01d
Added support for embedding language data into plugins; updated all version numbers on plugin files
Dan
parents:
391
diff
changeset
|
397 |
|
bc8e0e9ee01d
Added support for embedding language data into plugins; updated all version numbers on plugin files
Dan
parents:
391
diff
changeset
|
398 |
function import_plugin($file) |
bc8e0e9ee01d
Added support for embedding language data into plugins; updated all version numbers on plugin files
Dan
parents:
391
diff
changeset
|
399 |
{ |
bc8e0e9ee01d
Added support for embedding language data into plugins; updated all version numbers on plugin files
Dan
parents:
391
diff
changeset
|
400 |
global $db, $session, $paths, $template, $plugins; // Common objects |
bc8e0e9ee01d
Added support for embedding language data into plugins; updated all version numbers on plugin files
Dan
parents:
391
diff
changeset
|
401 |
|
bc8e0e9ee01d
Added support for embedding language data into plugins; updated all version numbers on plugin files
Dan
parents:
391
diff
changeset
|
402 |
if ( !file_exists($file) ) |
bc8e0e9ee01d
Added support for embedding language data into plugins; updated all version numbers on plugin files
Dan
parents:
391
diff
changeset
|
403 |
$db->_die('lang.php - can\'t import language file: string file doesn\'t exist'); |
bc8e0e9ee01d
Added support for embedding language data into plugins; updated all version numbers on plugin files
Dan
parents:
391
diff
changeset
|
404 |
|
bc8e0e9ee01d
Added support for embedding language data into plugins; updated all version numbers on plugin files
Dan
parents:
391
diff
changeset
|
405 |
if ( $this->lang_id == 0 ) |
bc8e0e9ee01d
Added support for embedding language data into plugins; updated all version numbers on plugin files
Dan
parents:
391
diff
changeset
|
406 |
$db->_die('lang.php - BUG: trying to perform import when $lang->lang_id == 0'); |
bc8e0e9ee01d
Added support for embedding language data into plugins; updated all version numbers on plugin files
Dan
parents:
391
diff
changeset
|
407 |
|
507
586fd7d3202d
Fixed some stray version numbers (again!); added support for Diffie-Hellman logins in the normal login form (not AJAX) - even works in IE
Dan
parents:
504
diff
changeset
|
408 |
$block = pluginLoader::parse_plugin_blocks($file, 'language'); |
586fd7d3202d
Fixed some stray version numbers (again!); added support for Diffie-Hellman logins in the normal login form (not AJAX) - even works in IE
Dan
parents:
504
diff
changeset
|
409 |
if ( !is_array($block) ) |
586fd7d3202d
Fixed some stray version numbers (again!); added support for Diffie-Hellman logins in the normal login form (not AJAX) - even works in IE
Dan
parents:
504
diff
changeset
|
410 |
return false; |
586fd7d3202d
Fixed some stray version numbers (again!); added support for Diffie-Hellman logins in the normal login form (not AJAX) - even works in IE
Dan
parents:
504
diff
changeset
|
411 |
if ( !isset($block[0]) ) |
586fd7d3202d
Fixed some stray version numbers (again!); added support for Diffie-Hellman logins in the normal login form (not AJAX) - even works in IE
Dan
parents:
504
diff
changeset
|
412 |
return false; |
504
bc8e0e9ee01d
Added support for embedding language data into plugins; updated all version numbers on plugin files
Dan
parents:
391
diff
changeset
|
413 |
|
507
586fd7d3202d
Fixed some stray version numbers (again!); added support for Diffie-Hellman logins in the normal login form (not AJAX) - even works in IE
Dan
parents:
504
diff
changeset
|
414 |
$contents =& $block[0]['value']; |
504
bc8e0e9ee01d
Added support for embedding language data into plugins; updated all version numbers on plugin files
Dan
parents:
391
diff
changeset
|
415 |
|
bc8e0e9ee01d
Added support for embedding language data into plugins; updated all version numbers on plugin files
Dan
parents:
391
diff
changeset
|
416 |
// Trim off all text before and after the starting and ending braces |
519
94214ec0871c
Started work on the new plugin manager and associated management code. Very incomplete at this point and not usable.
Dan
parents:
516
diff
changeset
|
417 |
$contents = enano_trim_json($contents); |
504
bc8e0e9ee01d
Added support for embedding language data into plugins; updated all version numbers on plugin files
Dan
parents:
391
diff
changeset
|
418 |
|
bc8e0e9ee01d
Added support for embedding language data into plugins; updated all version numbers on plugin files
Dan
parents:
391
diff
changeset
|
419 |
// Correct syntax to be nice to the json parser |
bc8e0e9ee01d
Added support for embedding language data into plugins; updated all version numbers on plugin files
Dan
parents:
391
diff
changeset
|
420 |
$contents = enano_clean_json($contents); |
bc8e0e9ee01d
Added support for embedding language data into plugins; updated all version numbers on plugin files
Dan
parents:
391
diff
changeset
|
421 |
|
bc8e0e9ee01d
Added support for embedding language data into plugins; updated all version numbers on plugin files
Dan
parents:
391
diff
changeset
|
422 |
try |
bc8e0e9ee01d
Added support for embedding language data into plugins; updated all version numbers on plugin files
Dan
parents:
391
diff
changeset
|
423 |
{ |
bc8e0e9ee01d
Added support for embedding language data into plugins; updated all version numbers on plugin files
Dan
parents:
391
diff
changeset
|
424 |
$langdata = enano_json_decode($contents); |
bc8e0e9ee01d
Added support for embedding language data into plugins; updated all version numbers on plugin files
Dan
parents:
391
diff
changeset
|
425 |
} |
bc8e0e9ee01d
Added support for embedding language data into plugins; updated all version numbers on plugin files
Dan
parents:
391
diff
changeset
|
426 |
catch(Zend_Json_Exception $e) |
bc8e0e9ee01d
Added support for embedding language data into plugins; updated all version numbers on plugin files
Dan
parents:
391
diff
changeset
|
427 |
{ |
bc8e0e9ee01d
Added support for embedding language data into plugins; updated all version numbers on plugin files
Dan
parents:
391
diff
changeset
|
428 |
$db->_die('lang.php - Exception caught by JSON parser</p><pre>' . htmlspecialchars(print_r($e, true)) . '</pre><p>'); |
bc8e0e9ee01d
Added support for embedding language data into plugins; updated all version numbers on plugin files
Dan
parents:
391
diff
changeset
|
429 |
exit; |
bc8e0e9ee01d
Added support for embedding language data into plugins; updated all version numbers on plugin files
Dan
parents:
391
diff
changeset
|
430 |
} |
bc8e0e9ee01d
Added support for embedding language data into plugins; updated all version numbers on plugin files
Dan
parents:
391
diff
changeset
|
431 |
|
bc8e0e9ee01d
Added support for embedding language data into plugins; updated all version numbers on plugin files
Dan
parents:
391
diff
changeset
|
432 |
if ( !is_array($langdata) ) |
bc8e0e9ee01d
Added support for embedding language data into plugins; updated all version numbers on plugin files
Dan
parents:
391
diff
changeset
|
433 |
{ |
bc8e0e9ee01d
Added support for embedding language data into plugins; updated all version numbers on plugin files
Dan
parents:
391
diff
changeset
|
434 |
$db->_die('lang.php - invalid or non-well-formed language file'); |
bc8e0e9ee01d
Added support for embedding language data into plugins; updated all version numbers on plugin files
Dan
parents:
391
diff
changeset
|
435 |
} |
bc8e0e9ee01d
Added support for embedding language data into plugins; updated all version numbers on plugin files
Dan
parents:
391
diff
changeset
|
436 |
|
bc8e0e9ee01d
Added support for embedding language data into plugins; updated all version numbers on plugin files
Dan
parents:
391
diff
changeset
|
437 |
// Does the plugin support the current language? |
bc8e0e9ee01d
Added support for embedding language data into plugins; updated all version numbers on plugin files
Dan
parents:
391
diff
changeset
|
438 |
if ( isset($langdata[$this->lang_code]) ) |
bc8e0e9ee01d
Added support for embedding language data into plugins; updated all version numbers on plugin files
Dan
parents:
391
diff
changeset
|
439 |
{ |
bc8e0e9ee01d
Added support for embedding language data into plugins; updated all version numbers on plugin files
Dan
parents:
391
diff
changeset
|
440 |
// Yes, import that |
bc8e0e9ee01d
Added support for embedding language data into plugins; updated all version numbers on plugin files
Dan
parents:
391
diff
changeset
|
441 |
return $this->import_array($langdata[$this->lang_code]); |
bc8e0e9ee01d
Added support for embedding language data into plugins; updated all version numbers on plugin files
Dan
parents:
391
diff
changeset
|
442 |
} |
bc8e0e9ee01d
Added support for embedding language data into plugins; updated all version numbers on plugin files
Dan
parents:
391
diff
changeset
|
443 |
|
bc8e0e9ee01d
Added support for embedding language data into plugins; updated all version numbers on plugin files
Dan
parents:
391
diff
changeset
|
444 |
// Just import the first language we run across. |
bc8e0e9ee01d
Added support for embedding language data into plugins; updated all version numbers on plugin files
Dan
parents:
391
diff
changeset
|
445 |
$supported_langs = array_keys($langdata); |
bc8e0e9ee01d
Added support for embedding language data into plugins; updated all version numbers on plugin files
Dan
parents:
391
diff
changeset
|
446 |
|
bc8e0e9ee01d
Added support for embedding language data into plugins; updated all version numbers on plugin files
Dan
parents:
391
diff
changeset
|
447 |
if ( !isset($supported_langs[0]) ) |
bc8e0e9ee01d
Added support for embedding language data into plugins; updated all version numbers on plugin files
Dan
parents:
391
diff
changeset
|
448 |
{ |
bc8e0e9ee01d
Added support for embedding language data into plugins; updated all version numbers on plugin files
Dan
parents:
391
diff
changeset
|
449 |
$db->_die('lang.php - plugin has an invalid or corrupt language block'); |
bc8e0e9ee01d
Added support for embedding language data into plugins; updated all version numbers on plugin files
Dan
parents:
391
diff
changeset
|
450 |
} |
bc8e0e9ee01d
Added support for embedding language data into plugins; updated all version numbers on plugin files
Dan
parents:
391
diff
changeset
|
451 |
|
bc8e0e9ee01d
Added support for embedding language data into plugins; updated all version numbers on plugin files
Dan
parents:
391
diff
changeset
|
452 |
$first_lang = $supported_langs[0]; |
bc8e0e9ee01d
Added support for embedding language data into plugins; updated all version numbers on plugin files
Dan
parents:
391
diff
changeset
|
453 |
|
812
68060328e9c6
Added CLI installer. Supports interactive, command-line, and internal-call installation. Fixed a few bugs related to anti-SQL injection parser and plugin installation.
Dan
parents:
801
diff
changeset
|
454 |
return $this->import_array($langdata[$first_lang], false, true); |
504
bc8e0e9ee01d
Added support for embedding language data into plugins; updated all version numbers on plugin files
Dan
parents:
391
diff
changeset
|
455 |
} |
bc8e0e9ee01d
Added support for embedding language data into plugins; updated all version numbers on plugin files
Dan
parents:
391
diff
changeset
|
456 |
|
bc8e0e9ee01d
Added support for embedding language data into plugins; updated all version numbers on plugin files
Dan
parents:
391
diff
changeset
|
457 |
/** |
bc8e0e9ee01d
Added support for embedding language data into plugins; updated all version numbers on plugin files
Dan
parents:
391
diff
changeset
|
458 |
* Performs the actual import of string data. |
bc8e0e9ee01d
Added support for embedding language data into plugins; updated all version numbers on plugin files
Dan
parents:
391
diff
changeset
|
459 |
* @param array Parsed JSON object, should be in the form of an array |
626
be0e904eec17
Refined upgrade process a bit. Uses libenanoinstall (incomplete), and post stage added to flush caches and import new strings
Dan
parents:
623
diff
changeset
|
460 |
* @param bool If true, only imports new strings and skips those that already exist. Defaults to false. |
514
ecbfb747743e
Added debugging switch to $lang->import() for help with optimization
Dan
parents:
507
diff
changeset
|
461 |
* @param bool Enable debugging output |
504
bc8e0e9ee01d
Added support for embedding language data into plugins; updated all version numbers on plugin files
Dan
parents:
391
diff
changeset
|
462 |
* @access private |
bc8e0e9ee01d
Added support for embedding language data into plugins; updated all version numbers on plugin files
Dan
parents:
391
diff
changeset
|
463 |
*/ |
bc8e0e9ee01d
Added support for embedding language data into plugins; updated all version numbers on plugin files
Dan
parents:
391
diff
changeset
|
464 |
|
626
be0e904eec17
Refined upgrade process a bit. Uses libenanoinstall (incomplete), and post stage added to flush caches and import new strings
Dan
parents:
623
diff
changeset
|
465 |
protected function import_array($langdata, $skip_existing = false, $debug = false) |
504
bc8e0e9ee01d
Added support for embedding language data into plugins; updated all version numbers on plugin files
Dan
parents:
391
diff
changeset
|
466 |
{ |
bc8e0e9ee01d
Added support for embedding language data into plugins; updated all version numbers on plugin files
Dan
parents:
391
diff
changeset
|
467 |
global $db, $session, $paths, $template, $plugins; // Common objects |
bc8e0e9ee01d
Added support for embedding language data into plugins; updated all version numbers on plugin files
Dan
parents:
391
diff
changeset
|
468 |
|
205 | 469 |
if ( !isset($langdata['categories']) || !isset($langdata['strings']) ) |
470 |
$db->_die('lang.php - language file does not contain the proper items'); |
|
471 |
||
516
9a52679143db
Added debugging ability to Language::import() for CLI usage
Dan
parents:
514
diff
changeset
|
472 |
if ( $debug ) |
9a52679143db
Added debugging ability to Language::import() for CLI usage
Dan
parents:
514
diff
changeset
|
473 |
$br = ( isset($_SERVER['REQUEST_URI']) ) ? '<br />' : ''; |
9a52679143db
Added debugging ability to Language::import() for CLI usage
Dan
parents:
514
diff
changeset
|
474 |
|
205 | 475 |
$insert_list = array(); |
476 |
$delete_list = array(); |
|
477 |
||
478 |
foreach ( $langdata['categories'] as $category ) |
|
479 |
{ |
|
480 |
if ( isset($langdata['strings'][$category]) ) |
|
481 |
{ |
|
514
ecbfb747743e
Added debugging switch to $lang->import() for help with optimization
Dan
parents:
507
diff
changeset
|
482 |
if ( $debug ) |
ecbfb747743e
Added debugging switch to $lang->import() for help with optimization
Dan
parents:
507
diff
changeset
|
483 |
{ |
ecbfb747743e
Added debugging switch to $lang->import() for help with optimization
Dan
parents:
507
diff
changeset
|
484 |
$desc = ( isset($langdata['strings']['meta'][$category]) ) ? $langdata['strings']['meta'][$category] : $this->get("meta_$category"); |
516
9a52679143db
Added debugging ability to Language::import() for CLI usage
Dan
parents:
514
diff
changeset
|
485 |
echo " Indexing category: $category ({$desc})$br\n"; |
514
ecbfb747743e
Added debugging switch to $lang->import() for help with optimization
Dan
parents:
507
diff
changeset
|
486 |
} |
205 | 487 |
foreach ( $langdata['strings'][$category] as $string_name => $string_value ) |
488 |
{ |
|
626
be0e904eec17
Refined upgrade process a bit. Uses libenanoinstall (incomplete), and post stage added to flush caches and import new strings
Dan
parents:
623
diff
changeset
|
489 |
// should we skip this string? |
be0e904eec17
Refined upgrade process a bit. Uses libenanoinstall (incomplete), and post stage added to flush caches and import new strings
Dan
parents:
623
diff
changeset
|
490 |
if ( isset($this->strings[$category]) && $skip_existing ) |
be0e904eec17
Refined upgrade process a bit. Uses libenanoinstall (incomplete), and post stage added to flush caches and import new strings
Dan
parents:
623
diff
changeset
|
491 |
{ |
be0e904eec17
Refined upgrade process a bit. Uses libenanoinstall (incomplete), and post stage added to flush caches and import new strings
Dan
parents:
623
diff
changeset
|
492 |
if ( isset($this->strings[$category][$string_name]) ) |
be0e904eec17
Refined upgrade process a bit. Uses libenanoinstall (incomplete), and post stage added to flush caches and import new strings
Dan
parents:
623
diff
changeset
|
493 |
{ |
be0e904eec17
Refined upgrade process a bit. Uses libenanoinstall (incomplete), and post stage added to flush caches and import new strings
Dan
parents:
623
diff
changeset
|
494 |
// already exists, skip |
be0e904eec17
Refined upgrade process a bit. Uses libenanoinstall (incomplete), and post stage added to flush caches and import new strings
Dan
parents:
623
diff
changeset
|
495 |
if ( $debug ) |
be0e904eec17
Refined upgrade process a bit. Uses libenanoinstall (incomplete), and post stage added to flush caches and import new strings
Dan
parents:
623
diff
changeset
|
496 |
echo " Skipping string (already exists): {$category}_{$string_name}$br\n"; |
be0e904eec17
Refined upgrade process a bit. Uses libenanoinstall (incomplete), and post stage added to flush caches and import new strings
Dan
parents:
623
diff
changeset
|
497 |
continue; |
be0e904eec17
Refined upgrade process a bit. Uses libenanoinstall (incomplete), and post stage added to flush caches and import new strings
Dan
parents:
623
diff
changeset
|
498 |
} |
be0e904eec17
Refined upgrade process a bit. Uses libenanoinstall (incomplete), and post stage added to flush caches and import new strings
Dan
parents:
623
diff
changeset
|
499 |
} |
205 | 500 |
$string_name = $db->escape($string_name); |
501 |
$string_value = $db->escape($string_value); |
|
502 |
$category_name = $db->escape($category); |
|
503 |
$insert_list[] = "({$this->lang_id}, '$category_name', '$string_name', '$string_value')"; |
|
504 |
$delete_list[] = "( lang_id = {$this->lang_id} AND string_category = '$category_name' AND string_name = '$string_name' )"; |
|
505 |
} |
|
506 |
} |
|
507 |
} |
|
508 |
||
514
ecbfb747743e
Added debugging switch to $lang->import() for help with optimization
Dan
parents:
507
diff
changeset
|
509 |
if ( $debug ) |
ecbfb747743e
Added debugging switch to $lang->import() for help with optimization
Dan
parents:
507
diff
changeset
|
510 |
{ |
ecbfb747743e
Added debugging switch to $lang->import() for help with optimization
Dan
parents:
507
diff
changeset
|
511 |
echo " Running deletion of old strings..."; |
ecbfb747743e
Added debugging switch to $lang->import() for help with optimization
Dan
parents:
507
diff
changeset
|
512 |
$start = microtime_float(); |
ecbfb747743e
Added debugging switch to $lang->import() for help with optimization
Dan
parents:
507
diff
changeset
|
513 |
} |
205 | 514 |
$delete_list = implode(" OR\n ", $delete_list); |
515 |
||
377
bb3e6c3bd4f4
Removed stray debugging info from ACL editor success notification; added ability for guests to set language on URI (?lang=eng); added html_in_pages ACL type and separated from php_in_pages so HTML can be embedded but not PHP; rewote portions of the path manager to better abstract URL input; added Zend Framework into list of BSD-licensed libraries; localized some remaining strings; got the migration script working, but just barely; fixed display bug in Special:Contributions; localized Main Page button in admin panel
Dan
parents:
376
diff
changeset
|
516 |
if ( !empty($delete_list) ) |
bb3e6c3bd4f4
Removed stray debugging info from ACL editor success notification; added ability for guests to set language on URI (?lang=eng); added html_in_pages ACL type and separated from php_in_pages so HTML can be embedded but not PHP; rewote portions of the path manager to better abstract URL input; added Zend Framework into list of BSD-licensed libraries; localized some remaining strings; got the migration script working, but just barely; fixed display bug in Special:Contributions; localized Main Page button in admin panel
Dan
parents:
376
diff
changeset
|
517 |
{ |
bb3e6c3bd4f4
Removed stray debugging info from ACL editor success notification; added ability for guests to set language on URI (?lang=eng); added html_in_pages ACL type and separated from php_in_pages so HTML can be embedded but not PHP; rewote portions of the path manager to better abstract URL input; added Zend Framework into list of BSD-licensed libraries; localized some remaining strings; got the migration script working, but just barely; fixed display bug in Special:Contributions; localized Main Page button in admin panel
Dan
parents:
376
diff
changeset
|
518 |
$sql = "DELETE FROM " . table_prefix . "language_strings WHERE $delete_list;"; |
bb3e6c3bd4f4
Removed stray debugging info from ACL editor success notification; added ability for guests to set language on URI (?lang=eng); added html_in_pages ACL type and separated from php_in_pages so HTML can be embedded but not PHP; rewote portions of the path manager to better abstract URL input; added Zend Framework into list of BSD-licensed libraries; localized some remaining strings; got the migration script working, but just barely; fixed display bug in Special:Contributions; localized Main Page button in admin panel
Dan
parents:
376
diff
changeset
|
519 |
|
bb3e6c3bd4f4
Removed stray debugging info from ACL editor success notification; added ability for guests to set language on URI (?lang=eng); added html_in_pages ACL type and separated from php_in_pages so HTML can be embedded but not PHP; rewote portions of the path manager to better abstract URL input; added Zend Framework into list of BSD-licensed libraries; localized some remaining strings; got the migration script working, but just barely; fixed display bug in Special:Contributions; localized Main Page button in admin panel
Dan
parents:
376
diff
changeset
|
520 |
// Free some memory |
bb3e6c3bd4f4
Removed stray debugging info from ACL editor success notification; added ability for guests to set language on URI (?lang=eng); added html_in_pages ACL type and separated from php_in_pages so HTML can be embedded but not PHP; rewote portions of the path manager to better abstract URL input; added Zend Framework into list of BSD-licensed libraries; localized some remaining strings; got the migration script working, but just barely; fixed display bug in Special:Contributions; localized Main Page button in admin panel
Dan
parents:
376
diff
changeset
|
521 |
unset($delete_list); |
bb3e6c3bd4f4
Removed stray debugging info from ACL editor success notification; added ability for guests to set language on URI (?lang=eng); added html_in_pages ACL type and separated from php_in_pages so HTML can be embedded but not PHP; rewote portions of the path manager to better abstract URL input; added Zend Framework into list of BSD-licensed libraries; localized some remaining strings; got the migration script working, but just barely; fixed display bug in Special:Contributions; localized Main Page button in admin panel
Dan
parents:
376
diff
changeset
|
522 |
|
bb3e6c3bd4f4
Removed stray debugging info from ACL editor success notification; added ability for guests to set language on URI (?lang=eng); added html_in_pages ACL type and separated from php_in_pages so HTML can be embedded but not PHP; rewote portions of the path manager to better abstract URL input; added Zend Framework into list of BSD-licensed libraries; localized some remaining strings; got the migration script working, but just barely; fixed display bug in Special:Contributions; localized Main Page button in admin panel
Dan
parents:
376
diff
changeset
|
523 |
// Run the query |
bb3e6c3bd4f4
Removed stray debugging info from ACL editor success notification; added ability for guests to set language on URI (?lang=eng); added html_in_pages ACL type and separated from php_in_pages so HTML can be embedded but not PHP; rewote portions of the path manager to better abstract URL input; added Zend Framework into list of BSD-licensed libraries; localized some remaining strings; got the migration script working, but just barely; fixed display bug in Special:Contributions; localized Main Page button in admin panel
Dan
parents:
376
diff
changeset
|
524 |
$q = $db->sql_query($sql); |
bb3e6c3bd4f4
Removed stray debugging info from ACL editor success notification; added ability for guests to set language on URI (?lang=eng); added html_in_pages ACL type and separated from php_in_pages so HTML can be embedded but not PHP; rewote portions of the path manager to better abstract URL input; added Zend Framework into list of BSD-licensed libraries; localized some remaining strings; got the migration script working, but just barely; fixed display bug in Special:Contributions; localized Main Page button in admin panel
Dan
parents:
376
diff
changeset
|
525 |
if ( !$q ) |
bb3e6c3bd4f4
Removed stray debugging info from ACL editor success notification; added ability for guests to set language on URI (?lang=eng); added html_in_pages ACL type and separated from php_in_pages so HTML can be embedded but not PHP; rewote portions of the path manager to better abstract URL input; added Zend Framework into list of BSD-licensed libraries; localized some remaining strings; got the migration script working, but just barely; fixed display bug in Special:Contributions; localized Main Page button in admin panel
Dan
parents:
376
diff
changeset
|
526 |
$db->_die('lang.php - couldn\'t kill off them old strings'); |
bb3e6c3bd4f4
Removed stray debugging info from ACL editor success notification; added ability for guests to set language on URI (?lang=eng); added html_in_pages ACL type and separated from php_in_pages so HTML can be embedded but not PHP; rewote portions of the path manager to better abstract URL input; added Zend Framework into list of BSD-licensed libraries; localized some remaining strings; got the migration script working, but just barely; fixed display bug in Special:Contributions; localized Main Page button in admin panel
Dan
parents:
376
diff
changeset
|
527 |
} |
205 | 528 |
|
514
ecbfb747743e
Added debugging switch to $lang->import() for help with optimization
Dan
parents:
507
diff
changeset
|
529 |
if ( $debug ) |
ecbfb747743e
Added debugging switch to $lang->import() for help with optimization
Dan
parents:
507
diff
changeset
|
530 |
{ |
ecbfb747743e
Added debugging switch to $lang->import() for help with optimization
Dan
parents:
507
diff
changeset
|
531 |
$time = round(microtime_float() - $start, 5); |
516
9a52679143db
Added debugging ability to Language::import() for CLI usage
Dan
parents:
514
diff
changeset
|
532 |
echo "({$time}s)$br\n"; |
514
ecbfb747743e
Added debugging switch to $lang->import() for help with optimization
Dan
parents:
507
diff
changeset
|
533 |
} |
ecbfb747743e
Added debugging switch to $lang->import() for help with optimization
Dan
parents:
507
diff
changeset
|
534 |
|
377
bb3e6c3bd4f4
Removed stray debugging info from ACL editor success notification; added ability for guests to set language on URI (?lang=eng); added html_in_pages ACL type and separated from php_in_pages so HTML can be embedded but not PHP; rewote portions of the path manager to better abstract URL input; added Zend Framework into list of BSD-licensed libraries; localized some remaining strings; got the migration script working, but just barely; fixed display bug in Special:Contributions; localized Main Page button in admin panel
Dan
parents:
376
diff
changeset
|
535 |
if ( !empty($insert_list) ) |
bb3e6c3bd4f4
Removed stray debugging info from ACL editor success notification; added ability for guests to set language on URI (?lang=eng); added html_in_pages ACL type and separated from php_in_pages so HTML can be embedded but not PHP; rewote portions of the path manager to better abstract URL input; added Zend Framework into list of BSD-licensed libraries; localized some remaining strings; got the migration script working, but just barely; fixed display bug in Special:Contributions; localized Main Page button in admin panel
Dan
parents:
376
diff
changeset
|
536 |
{ |
514
ecbfb747743e
Added debugging switch to $lang->import() for help with optimization
Dan
parents:
507
diff
changeset
|
537 |
if ( $debug ) |
ecbfb747743e
Added debugging switch to $lang->import() for help with optimization
Dan
parents:
507
diff
changeset
|
538 |
{ |
ecbfb747743e
Added debugging switch to $lang->import() for help with optimization
Dan
parents:
507
diff
changeset
|
539 |
echo " Inserting strings..."; |
ecbfb747743e
Added debugging switch to $lang->import() for help with optimization
Dan
parents:
507
diff
changeset
|
540 |
$start = microtime_float(); |
ecbfb747743e
Added debugging switch to $lang->import() for help with optimization
Dan
parents:
507
diff
changeset
|
541 |
} |
377
bb3e6c3bd4f4
Removed stray debugging info from ACL editor success notification; added ability for guests to set language on URI (?lang=eng); added html_in_pages ACL type and separated from php_in_pages so HTML can be embedded but not PHP; rewote portions of the path manager to better abstract URL input; added Zend Framework into list of BSD-licensed libraries; localized some remaining strings; got the migration script working, but just barely; fixed display bug in Special:Contributions; localized Main Page button in admin panel
Dan
parents:
376
diff
changeset
|
542 |
$insert_list = implode(",\n ", $insert_list); |
bb3e6c3bd4f4
Removed stray debugging info from ACL editor success notification; added ability for guests to set language on URI (?lang=eng); added html_in_pages ACL type and separated from php_in_pages so HTML can be embedded but not PHP; rewote portions of the path manager to better abstract URL input; added Zend Framework into list of BSD-licensed libraries; localized some remaining strings; got the migration script working, but just barely; fixed display bug in Special:Contributions; localized Main Page button in admin panel
Dan
parents:
376
diff
changeset
|
543 |
$sql = "INSERT INTO " . table_prefix . "language_strings(lang_id, string_category, string_name, string_content) VALUES\n $insert_list;"; |
bb3e6c3bd4f4
Removed stray debugging info from ACL editor success notification; added ability for guests to set language on URI (?lang=eng); added html_in_pages ACL type and separated from php_in_pages so HTML can be embedded but not PHP; rewote portions of the path manager to better abstract URL input; added Zend Framework into list of BSD-licensed libraries; localized some remaining strings; got the migration script working, but just barely; fixed display bug in Special:Contributions; localized Main Page button in admin panel
Dan
parents:
376
diff
changeset
|
544 |
|
bb3e6c3bd4f4
Removed stray debugging info from ACL editor success notification; added ability for guests to set language on URI (?lang=eng); added html_in_pages ACL type and separated from php_in_pages so HTML can be embedded but not PHP; rewote portions of the path manager to better abstract URL input; added Zend Framework into list of BSD-licensed libraries; localized some remaining strings; got the migration script working, but just barely; fixed display bug in Special:Contributions; localized Main Page button in admin panel
Dan
parents:
376
diff
changeset
|
545 |
// Free some memory |
bb3e6c3bd4f4
Removed stray debugging info from ACL editor success notification; added ability for guests to set language on URI (?lang=eng); added html_in_pages ACL type and separated from php_in_pages so HTML can be embedded but not PHP; rewote portions of the path manager to better abstract URL input; added Zend Framework into list of BSD-licensed libraries; localized some remaining strings; got the migration script working, but just barely; fixed display bug in Special:Contributions; localized Main Page button in admin panel
Dan
parents:
376
diff
changeset
|
546 |
unset($insert_list); |
bb3e6c3bd4f4
Removed stray debugging info from ACL editor success notification; added ability for guests to set language on URI (?lang=eng); added html_in_pages ACL type and separated from php_in_pages so HTML can be embedded but not PHP; rewote portions of the path manager to better abstract URL input; added Zend Framework into list of BSD-licensed libraries; localized some remaining strings; got the migration script working, but just barely; fixed display bug in Special:Contributions; localized Main Page button in admin panel
Dan
parents:
376
diff
changeset
|
547 |
|
bb3e6c3bd4f4
Removed stray debugging info from ACL editor success notification; added ability for guests to set language on URI (?lang=eng); added html_in_pages ACL type and separated from php_in_pages so HTML can be embedded but not PHP; rewote portions of the path manager to better abstract URL input; added Zend Framework into list of BSD-licensed libraries; localized some remaining strings; got the migration script working, but just barely; fixed display bug in Special:Contributions; localized Main Page button in admin panel
Dan
parents:
376
diff
changeset
|
548 |
// Run the query |
bb3e6c3bd4f4
Removed stray debugging info from ACL editor success notification; added ability for guests to set language on URI (?lang=eng); added html_in_pages ACL type and separated from php_in_pages so HTML can be embedded but not PHP; rewote portions of the path manager to better abstract URL input; added Zend Framework into list of BSD-licensed libraries; localized some remaining strings; got the migration script working, but just barely; fixed display bug in Special:Contributions; localized Main Page button in admin panel
Dan
parents:
376
diff
changeset
|
549 |
$q = $db->sql_query($sql); |
bb3e6c3bd4f4
Removed stray debugging info from ACL editor success notification; added ability for guests to set language on URI (?lang=eng); added html_in_pages ACL type and separated from php_in_pages so HTML can be embedded but not PHP; rewote portions of the path manager to better abstract URL input; added Zend Framework into list of BSD-licensed libraries; localized some remaining strings; got the migration script working, but just barely; fixed display bug in Special:Contributions; localized Main Page button in admin panel
Dan
parents:
376
diff
changeset
|
550 |
if ( !$q ) |
bb3e6c3bd4f4
Removed stray debugging info from ACL editor success notification; added ability for guests to set language on URI (?lang=eng); added html_in_pages ACL type and separated from php_in_pages so HTML can be embedded but not PHP; rewote portions of the path manager to better abstract URL input; added Zend Framework into list of BSD-licensed libraries; localized some remaining strings; got the migration script working, but just barely; fixed display bug in Special:Contributions; localized Main Page button in admin panel
Dan
parents:
376
diff
changeset
|
551 |
$db->_die('lang.php - couldn\'t insert strings in import()'); |
514
ecbfb747743e
Added debugging switch to $lang->import() for help with optimization
Dan
parents:
507
diff
changeset
|
552 |
|
ecbfb747743e
Added debugging switch to $lang->import() for help with optimization
Dan
parents:
507
diff
changeset
|
553 |
if ( $debug ) |
ecbfb747743e
Added debugging switch to $lang->import() for help with optimization
Dan
parents:
507
diff
changeset
|
554 |
{ |
ecbfb747743e
Added debugging switch to $lang->import() for help with optimization
Dan
parents:
507
diff
changeset
|
555 |
$time = round(microtime_float() - $start, 5); |
516
9a52679143db
Added debugging ability to Language::import() for CLI usage
Dan
parents:
514
diff
changeset
|
556 |
echo "({$time}s)$br\n"; |
514
ecbfb747743e
Added debugging switch to $lang->import() for help with optimization
Dan
parents:
507
diff
changeset
|
557 |
} |
377
bb3e6c3bd4f4
Removed stray debugging info from ACL editor success notification; added ability for guests to set language on URI (?lang=eng); added html_in_pages ACL type and separated from php_in_pages so HTML can be embedded but not PHP; rewote portions of the path manager to better abstract URL input; added Zend Framework into list of BSD-licensed libraries; localized some remaining strings; got the migration script working, but just barely; fixed display bug in Special:Contributions; localized Main Page button in admin panel
Dan
parents:
376
diff
changeset
|
558 |
} |
205 | 559 |
|
560 |
// YAY! done! |
|
561 |
// This will regenerate the cache file if possible. |
|
514
ecbfb747743e
Added debugging switch to $lang->import() for help with optimization
Dan
parents:
507
diff
changeset
|
562 |
if ( $debug ) |
516
9a52679143db
Added debugging ability to Language::import() for CLI usage
Dan
parents:
514
diff
changeset
|
563 |
echo " Regenerating cache file$br\n"; |
205 | 564 |
$this->regen_caches(); |
555
ac4c6a7f01d8
Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
parents:
536
diff
changeset
|
565 |
|
ac4c6a7f01d8
Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
parents:
536
diff
changeset
|
566 |
return true; |
205 | 567 |
} |
568 |
||
569 |
/** |
|
570 |
* Refetches the strings and writes out the cache file. |
|
571 |
*/ |
|
572 |
||
607
935f3799b654
First stab at cache management backend. Everything seems to have been tested and working so far, but a number of things require a more specialized cache and can't go through the framework (e.g. user ranks which use references to map usernames to user IDs)
Dan
parents:
593
diff
changeset
|
573 |
function regen_caches($refetch = true) |
205 | 574 |
{ |
575 |
global $db, $session, $paths, $template, $plugins; // Common objects |
|
576 |
||
577 |
// Refresh the strings in RAM to the latest copies in the DB |
|
607
935f3799b654
First stab at cache management backend. Everything seems to have been tested and working so far, but a number of things require a more specialized cache and can't go through the framework (e.g. user ranks which use references to map usernames to user IDs)
Dan
parents:
593
diff
changeset
|
578 |
if ( $refetch ) |
935f3799b654
First stab at cache management backend. Everything seems to have been tested and working so far, but a number of things require a more specialized cache and can't go through the framework (e.g. user ranks which use references to map usernames to user IDs)
Dan
parents:
593
diff
changeset
|
579 |
$this->fetch(false); |
205 | 580 |
|
607
935f3799b654
First stab at cache management backend. Everything seems to have been tested and working so far, but a number of things require a more specialized cache and can't go through the framework (e.g. user ranks which use references to map usernames to user IDs)
Dan
parents:
593
diff
changeset
|
581 |
// Load the cache manager |
935f3799b654
First stab at cache management backend. Everything seems to have been tested and working so far, but a number of things require a more specialized cache and can't go through the framework (e.g. user ranks which use references to map usernames to user IDs)
Dan
parents:
593
diff
changeset
|
582 |
global $cache; |
205 | 583 |
|
607
935f3799b654
First stab at cache management backend. Everything seems to have been tested and working so far, but a number of things require a more specialized cache and can't go through the framework (e.g. user ranks which use references to map usernames to user IDs)
Dan
parents:
593
diff
changeset
|
584 |
// Store it |
935f3799b654
First stab at cache management backend. Everything seems to have been tested and working so far, but a number of things require a more specialized cache and can't go through the framework (e.g. user ranks which use references to map usernames to user IDs)
Dan
parents:
593
diff
changeset
|
585 |
$cache->store("lang_{$this->lang_id}", $this->strings, -1); |
205 | 586 |
|
210
2b283402e4e4
Added language export to JSON page and localization for Javascript using $lang.get(). Localized AJAX login interface.
Dan
parents:
209
diff
changeset
|
587 |
// Update timestamp in database |
2b283402e4e4
Added language export to JSON page and localization for Javascript using $lang.get(). Localized AJAX login interface.
Dan
parents:
209
diff
changeset
|
588 |
$q = $db->sql_query('UPDATE ' . table_prefix . 'language SET last_changed = ' . time() . ' WHERE lang_id = ' . $this->lang_id . ';'); |
2b283402e4e4
Added language export to JSON page and localization for Javascript using $lang.get(). Localized AJAX login interface.
Dan
parents:
209
diff
changeset
|
589 |
if ( !$q ) |
2b283402e4e4
Added language export to JSON page and localization for Javascript using $lang.get(). Localized AJAX login interface.
Dan
parents:
209
diff
changeset
|
590 |
$db->_die('lang.php - updating timestamp on language'); |
613 | 591 |
|
592 |
return true; |
|
205 | 593 |
} |
594 |
||
595 |
/** |
|
596 |
* Calls var_export() on whatever, and returns the function's output. |
|
597 |
* @param mixed Whatever you want var_exported. Usually an array. |
|
598 |
* @return string |
|
599 |
*/ |
|
600 |
||
590
03a60844c7c5
Several optimization changes including getting rid of a few eval()s. Added placeholder functions for the theme manager, which should be working now
Dan
parents:
555
diff
changeset
|
601 |
static function var_export_string($val) |
205 | 602 |
{ |
603 |
ob_start(); |
|
604 |
var_export($val); |
|
605 |
$contents = ob_get_contents(); |
|
606 |
ob_end_clean(); |
|
607 |
return $contents; |
|
608 |
} |
|
609 |
||
610 |
/** |
|
668
0631e4de5de6
Added ability to have language strings send variables through filter functions. Operates based on predefined filters, expandable with a call to Language::register_filter at the hook lang_init
Dan
parents:
654
diff
changeset
|
611 |
* Registers a filter, a function that strings can be passed through to change the string somehow (e.g. htmlspecialchars) |
0631e4de5de6
Added ability to have language strings send variables through filter functions. Operates based on predefined filters, expandable with a call to Language::register_filter at the hook lang_init
Dan
parents:
654
diff
changeset
|
612 |
* @param string Filter name. Lowercase alphanumeric (htmlsafe) |
0631e4de5de6
Added ability to have language strings send variables through filter functions. Operates based on predefined filters, expandable with a call to Language::register_filter at the hook lang_init
Dan
parents:
654
diff
changeset
|
613 |
* @param callback Function to call. |
0631e4de5de6
Added ability to have language strings send variables through filter functions. Operates based on predefined filters, expandable with a call to Language::register_filter at the hook lang_init
Dan
parents:
654
diff
changeset
|
614 |
* @return bool True on success, false if some error occurred |
0631e4de5de6
Added ability to have language strings send variables through filter functions. Operates based on predefined filters, expandable with a call to Language::register_filter at the hook lang_init
Dan
parents:
654
diff
changeset
|
615 |
*/ |
0631e4de5de6
Added ability to have language strings send variables through filter functions. Operates based on predefined filters, expandable with a call to Language::register_filter at the hook lang_init
Dan
parents:
654
diff
changeset
|
616 |
|
0631e4de5de6
Added ability to have language strings send variables through filter functions. Operates based on predefined filters, expandable with a call to Language::register_filter at the hook lang_init
Dan
parents:
654
diff
changeset
|
617 |
public function register_filter($filter_name, $filter_function) |
0631e4de5de6
Added ability to have language strings send variables through filter functions. Operates based on predefined filters, expandable with a call to Language::register_filter at the hook lang_init
Dan
parents:
654
diff
changeset
|
618 |
{ |
0631e4de5de6
Added ability to have language strings send variables through filter functions. Operates based on predefined filters, expandable with a call to Language::register_filter at the hook lang_init
Dan
parents:
654
diff
changeset
|
619 |
if ( !is_string($filter_function) && !is_array($filter_function) ) |
0631e4de5de6
Added ability to have language strings send variables through filter functions. Operates based on predefined filters, expandable with a call to Language::register_filter at the hook lang_init
Dan
parents:
654
diff
changeset
|
620 |
{ |
0631e4de5de6
Added ability to have language strings send variables through filter functions. Operates based on predefined filters, expandable with a call to Language::register_filter at the hook lang_init
Dan
parents:
654
diff
changeset
|
621 |
return false; |
0631e4de5de6
Added ability to have language strings send variables through filter functions. Operates based on predefined filters, expandable with a call to Language::register_filter at the hook lang_init
Dan
parents:
654
diff
changeset
|
622 |
} |
0631e4de5de6
Added ability to have language strings send variables through filter functions. Operates based on predefined filters, expandable with a call to Language::register_filter at the hook lang_init
Dan
parents:
654
diff
changeset
|
623 |
if ( ( is_string($filter_function) && !function_exists($filter_function) ) || ( is_array($filter_function) && !method_exists(@$filter_function[0], @$filter_function[1]) ) ) |
0631e4de5de6
Added ability to have language strings send variables through filter functions. Operates based on predefined filters, expandable with a call to Language::register_filter at the hook lang_init
Dan
parents:
654
diff
changeset
|
624 |
{ |
0631e4de5de6
Added ability to have language strings send variables through filter functions. Operates based on predefined filters, expandable with a call to Language::register_filter at the hook lang_init
Dan
parents:
654
diff
changeset
|
625 |
return false; |
0631e4de5de6
Added ability to have language strings send variables through filter functions. Operates based on predefined filters, expandable with a call to Language::register_filter at the hook lang_init
Dan
parents:
654
diff
changeset
|
626 |
} |
0631e4de5de6
Added ability to have language strings send variables through filter functions. Operates based on predefined filters, expandable with a call to Language::register_filter at the hook lang_init
Dan
parents:
654
diff
changeset
|
627 |
if ( !preg_match('/^[a-z0-9_]+$/', $filter_name) ) |
0631e4de5de6
Added ability to have language strings send variables through filter functions. Operates based on predefined filters, expandable with a call to Language::register_filter at the hook lang_init
Dan
parents:
654
diff
changeset
|
628 |
{ |
0631e4de5de6
Added ability to have language strings send variables through filter functions. Operates based on predefined filters, expandable with a call to Language::register_filter at the hook lang_init
Dan
parents:
654
diff
changeset
|
629 |
return false; |
0631e4de5de6
Added ability to have language strings send variables through filter functions. Operates based on predefined filters, expandable with a call to Language::register_filter at the hook lang_init
Dan
parents:
654
diff
changeset
|
630 |
} |
0631e4de5de6
Added ability to have language strings send variables through filter functions. Operates based on predefined filters, expandable with a call to Language::register_filter at the hook lang_init
Dan
parents:
654
diff
changeset
|
631 |
$this->filters[$filter_name] = $filter_function; |
1036 | 632 |
return true; |
668
0631e4de5de6
Added ability to have language strings send variables through filter functions. Operates based on predefined filters, expandable with a call to Language::register_filter at the hook lang_init
Dan
parents:
654
diff
changeset
|
633 |
} |
0631e4de5de6
Added ability to have language strings send variables through filter functions. Operates based on predefined filters, expandable with a call to Language::register_filter at the hook lang_init
Dan
parents:
654
diff
changeset
|
634 |
|
0631e4de5de6
Added ability to have language strings send variables through filter functions. Operates based on predefined filters, expandable with a call to Language::register_filter at the hook lang_init
Dan
parents:
654
diff
changeset
|
635 |
/** |
205 | 636 |
* Fetches a language string from the cache in RAM. If it isn't there, it will call fetch() again and then try. If it still can't find it, it will ask for the string |
637 |
* in the default language. If even then the string can't be found, this function will return what was passed to it. |
|
638 |
* |
|
639 |
* This will also templatize strings. If a string contains variables in the format %foo%, you may specify the second parameter as an associative array in the format |
|
640 |
* of 'foo' => 'foo substitute'. |
|
641 |
* |
|
642 |
* @param string ID of the string to fetch. This will always be in the format of category_stringid. |
|
643 |
* @param array Optional. Associative array of substitutions. |
|
644 |
* @return string |
|
645 |
*/ |
|
646 |
||
647 |
function get($string_id, $substitutions = false) |
|
648 |
{ |
|
376 | 649 |
if ( !is_array($substitutions) ) |
650 |
$substitutions = array(); |
|
536 | 651 |
// if this isn't a valid language string ID, just return the string unprocessed. |
652 |
if ( !preg_match('/^([a-z0-9]+)((_[a-z0-9]+)+)$/', $string_id) ) |
|
653 |
return $string_id; |
|
376 | 654 |
return $this->substitute($this->get_uncensored($string_id), $substitutions); |
655 |
} |
|
656 |
||
657 |
/** |
|
658 |
* The same as get(), but does not perform any substitution or filtering. Used in get() (of course) and in the admin panel, where |
|
659 |
* strings are updated only if they were changed. |
|
660 |
* |
|
661 |
* @param string ID of the string to fetch. This will always be in the format of category_stringid. |
|
662 |
* @param array Optional. Associative array of substitutions. |
|
663 |
* @return string |
|
664 |
*/ |
|
665 |
||
666 |
function get_uncensored($string_id, $substitutions = false) |
|
667 |
{ |
|
616
e311f5e6f904
Got the installer working. Fixed a few bugs including a nasty-to-debug issue where the lang_id was being hardcoded during installation, resulting in strings being inserted with the wrong lang_id causing an infinfinite loop with fetch() throwing a "no strings" error and using template (which calls fetch()) to complain
Dan
parents:
613
diff
changeset
|
668 |
global $db, $session, $paths, $template, $plugins; // Common objects |
e311f5e6f904
Got the installer working. Fixed a few bugs including a nasty-to-debug issue where the lang_id was being hardcoded during installation, resulting in strings being inserted with the wrong lang_id causing an infinfinite loop with fetch() throwing a "no strings" error and using template (which calls fetch()) to complain
Dan
parents:
613
diff
changeset
|
669 |
|
205 | 670 |
// Extract the category and string ID |
671 |
$category = substr($string_id, 0, ( strpos($string_id, '_') )); |
|
672 |
$string_name = substr($string_id, ( strpos($string_id, '_') + 1 )); |
|
673 |
$found = false; |
|
674 |
if ( isset($this->strings[$category]) && isset($this->strings[$category][$string_name]) ) |
|
675 |
{ |
|
676 |
$found = true; |
|
677 |
$string = $this->strings[$category][$string_name]; |
|
678 |
} |
|
679 |
if ( !$found ) |
|
680 |
{ |
|
681 |
// Ehh, the string wasn't found. Rerun fetch() and try again. |
|
536 | 682 |
// Or if it's the installer, no use in refetching, so just fail. |
616
e311f5e6f904
Got the installer working. Fixed a few bugs including a nasty-to-debug issue where the lang_id was being hardcoded during installation, resulting in strings being inserted with the wrong lang_id causing an infinfinite loop with fetch() throwing a "no strings" error and using template (which calls fetch()) to complain
Dan
parents:
613
diff
changeset
|
683 |
if ( defined('IN_ENANO_INSTALL') || ( defined('ENANO_INSTALLED') && !@$db->_conn ) ) |
243
a7d0f2711df1
Installer localization started. Welcome, License, and SysReqs pages are fully localized.
Dan
parents:
241
diff
changeset
|
684 |
{ |
a7d0f2711df1
Installer localization started. Welcome, License, and SysReqs pages are fully localized.
Dan
parents:
241
diff
changeset
|
685 |
return $string_id; |
a7d0f2711df1
Installer localization started. Welcome, License, and SysReqs pages are fully localized.
Dan
parents:
241
diff
changeset
|
686 |
} |
205 | 687 |
$this->fetch(); |
593
4f9bec0d65c1
More optimization work. Moved special page init functions to common instead of common_post hook. Allowed paths to cache page metadata on filesystem. Phased out the redundancy in $paths->pages that paired a number with every urlname as foreach loops are allowed now (and have been for some time). Fixed missing includes for several functions. Rewrote str_replace_once to be a lot more efficient.
Dan
parents:
590
diff
changeset
|
688 |
profiler_log('Language(' . $this->lang_code . '): refetched due to missing string: ' . $string_id); |
205 | 689 |
if ( isset($this->strings[$category]) && isset($this->strings[$category][$string_name]) ) |
690 |
{ |
|
691 |
$found = true; |
|
692 |
$string = $this->strings[$category][$string_name]; |
|
693 |
} |
|
694 |
if ( !$found ) |
|
695 |
{ |
|
696 |
// STILL not found. Check the default language. |
|
697 |
$lang_default = ( $x = getConfig('default_language') ) ? intval($x) : $this->lang_id; |
|
698 |
if ( $lang_default != $this->lang_id ) |
|
699 |
{ |
|
700 |
if ( !is_object($this->default) ) |
|
701 |
$this->default = new Language($lang_default); |
|
376 | 702 |
return $this->default->get_uncensored($string_id); |
205 | 703 |
} |
704 |
} |
|
705 |
} |
|
706 |
if ( !$found ) |
|
707 |
{ |
|
708 |
// Alright, it's nowhere. Return the input, grumble grumble... |
|
709 |
return $string_id; |
|
710 |
} |
|
711 |
// Found it! |
|
376 | 712 |
return $string; |
205 | 713 |
} |
714 |
||
715 |
/** |
|
716 |
* Processes substitutions. |
|
717 |
* @param string |
|
718 |
* @param array |
|
719 |
* @return string |
|
720 |
*/ |
|
721 |
||
722 |
function substitute($string, $subs) |
|
723 |
{ |
|
668
0631e4de5de6
Added ability to have language strings send variables through filter functions. Operates based on predefined filters, expandable with a call to Language::register_filter at the hook lang_init
Dan
parents:
654
diff
changeset
|
724 |
preg_match_all('/%this\.([a-z0-9_]+)((?:\|(?:[a-z0-9_]+))*)%/', $string, $matches); |
205 | 725 |
if ( count($matches[0]) > 0 ) |
726 |
{ |
|
727 |
foreach ( $matches[1] as $i => $string_id ) |
|
728 |
{ |
|
729 |
$result = $this->get($string_id); |
|
668
0631e4de5de6
Added ability to have language strings send variables through filter functions. Operates based on predefined filters, expandable with a call to Language::register_filter at the hook lang_init
Dan
parents:
654
diff
changeset
|
730 |
$string = str_replace($matches[0][$i], $this->process_filters($result, $matches[2][$i]), $string); |
205 | 731 |
} |
732 |
} |
|
668
0631e4de5de6
Added ability to have language strings send variables through filter functions. Operates based on predefined filters, expandable with a call to Language::register_filter at the hook lang_init
Dan
parents:
654
diff
changeset
|
733 |
preg_match_all('/%config\.([a-z0-9_]+)((?:\|(?:[a-z0-9_]+))*)%/', $string, $matches); |
0631e4de5de6
Added ability to have language strings send variables through filter functions. Operates based on predefined filters, expandable with a call to Language::register_filter at the hook lang_init
Dan
parents:
654
diff
changeset
|
734 |
if ( count($matches[0]) > 0 ) |
0631e4de5de6
Added ability to have language strings send variables through filter functions. Operates based on predefined filters, expandable with a call to Language::register_filter at the hook lang_init
Dan
parents:
654
diff
changeset
|
735 |
{ |
0631e4de5de6
Added ability to have language strings send variables through filter functions. Operates based on predefined filters, expandable with a call to Language::register_filter at the hook lang_init
Dan
parents:
654
diff
changeset
|
736 |
foreach ( $matches[1] as $i => $string_id ) |
0631e4de5de6
Added ability to have language strings send variables through filter functions. Operates based on predefined filters, expandable with a call to Language::register_filter at the hook lang_init
Dan
parents:
654
diff
changeset
|
737 |
{ |
0631e4de5de6
Added ability to have language strings send variables through filter functions. Operates based on predefined filters, expandable with a call to Language::register_filter at the hook lang_init
Dan
parents:
654
diff
changeset
|
738 |
$result = getConfig($string_id, ''); |
0631e4de5de6
Added ability to have language strings send variables through filter functions. Operates based on predefined filters, expandable with a call to Language::register_filter at the hook lang_init
Dan
parents:
654
diff
changeset
|
739 |
$string = str_replace($matches[0][$i], $this->process_filters($result, $matches[2][$i]), $string); |
0631e4de5de6
Added ability to have language strings send variables through filter functions. Operates based on predefined filters, expandable with a call to Language::register_filter at the hook lang_init
Dan
parents:
654
diff
changeset
|
740 |
} |
0631e4de5de6
Added ability to have language strings send variables through filter functions. Operates based on predefined filters, expandable with a call to Language::register_filter at the hook lang_init
Dan
parents:
654
diff
changeset
|
741 |
} |
0631e4de5de6
Added ability to have language strings send variables through filter functions. Operates based on predefined filters, expandable with a call to Language::register_filter at the hook lang_init
Dan
parents:
654
diff
changeset
|
742 |
preg_match_all('/%([a-z0-9_]+)((?:\|(?:[a-z0-9_]+))*)%/', $string, $matches); |
209 | 743 |
if ( count($matches[0]) > 0 ) |
744 |
{ |
|
745 |
foreach ( $matches[1] as $i => $string_id ) |
|
746 |
{ |
|
668
0631e4de5de6
Added ability to have language strings send variables through filter functions. Operates based on predefined filters, expandable with a call to Language::register_filter at the hook lang_init
Dan
parents:
654
diff
changeset
|
747 |
if ( isset($subs[$string_id]) ) |
0631e4de5de6
Added ability to have language strings send variables through filter functions. Operates based on predefined filters, expandable with a call to Language::register_filter at the hook lang_init
Dan
parents:
654
diff
changeset
|
748 |
{ |
0631e4de5de6
Added ability to have language strings send variables through filter functions. Operates based on predefined filters, expandable with a call to Language::register_filter at the hook lang_init
Dan
parents:
654
diff
changeset
|
749 |
$string = str_replace($matches[0][$i], $this->process_filters($subs[$string_id], $matches[2][$i]), $string); |
0631e4de5de6
Added ability to have language strings send variables through filter functions. Operates based on predefined filters, expandable with a call to Language::register_filter at the hook lang_init
Dan
parents:
654
diff
changeset
|
750 |
} |
209 | 751 |
} |
752 |
} |
|
668
0631e4de5de6
Added ability to have language strings send variables through filter functions. Operates based on predefined filters, expandable with a call to Language::register_filter at the hook lang_init
Dan
parents:
654
diff
changeset
|
753 |
return ( $this->debug ) ? "$string*" : $string; |
0631e4de5de6
Added ability to have language strings send variables through filter functions. Operates based on predefined filters, expandable with a call to Language::register_filter at the hook lang_init
Dan
parents:
654
diff
changeset
|
754 |
} |
0631e4de5de6
Added ability to have language strings send variables through filter functions. Operates based on predefined filters, expandable with a call to Language::register_filter at the hook lang_init
Dan
parents:
654
diff
changeset
|
755 |
|
0631e4de5de6
Added ability to have language strings send variables through filter functions. Operates based on predefined filters, expandable with a call to Language::register_filter at the hook lang_init
Dan
parents:
654
diff
changeset
|
756 |
/** |
0631e4de5de6
Added ability to have language strings send variables through filter functions. Operates based on predefined filters, expandable with a call to Language::register_filter at the hook lang_init
Dan
parents:
654
diff
changeset
|
757 |
* Processes filters to a language string. |
0631e4de5de6
Added ability to have language strings send variables through filter functions. Operates based on predefined filters, expandable with a call to Language::register_filter at the hook lang_init
Dan
parents:
654
diff
changeset
|
758 |
* @param string Unprocessed string |
0631e4de5de6
Added ability to have language strings send variables through filter functions. Operates based on predefined filters, expandable with a call to Language::register_filter at the hook lang_init
Dan
parents:
654
diff
changeset
|
759 |
* @param string Filter list (format: |filter1|filter2|filter3, initial pipe is important); can also be an array if you so desire |
0631e4de5de6
Added ability to have language strings send variables through filter functions. Operates based on predefined filters, expandable with a call to Language::register_filter at the hook lang_init
Dan
parents:
654
diff
changeset
|
760 |
* @return string |
0631e4de5de6
Added ability to have language strings send variables through filter functions. Operates based on predefined filters, expandable with a call to Language::register_filter at the hook lang_init
Dan
parents:
654
diff
changeset
|
761 |
*/ |
0631e4de5de6
Added ability to have language strings send variables through filter functions. Operates based on predefined filters, expandable with a call to Language::register_filter at the hook lang_init
Dan
parents:
654
diff
changeset
|
762 |
|
0631e4de5de6
Added ability to have language strings send variables through filter functions. Operates based on predefined filters, expandable with a call to Language::register_filter at the hook lang_init
Dan
parents:
654
diff
changeset
|
763 |
function process_filters($string, $filters) |
0631e4de5de6
Added ability to have language strings send variables through filter functions. Operates based on predefined filters, expandable with a call to Language::register_filter at the hook lang_init
Dan
parents:
654
diff
changeset
|
764 |
{ |
0631e4de5de6
Added ability to have language strings send variables through filter functions. Operates based on predefined filters, expandable with a call to Language::register_filter at the hook lang_init
Dan
parents:
654
diff
changeset
|
765 |
if ( !empty($filters) ) |
205 | 766 |
{ |
668
0631e4de5de6
Added ability to have language strings send variables through filter functions. Operates based on predefined filters, expandable with a call to Language::register_filter at the hook lang_init
Dan
parents:
654
diff
changeset
|
767 |
$filters = trim($filters, '|'); |
0631e4de5de6
Added ability to have language strings send variables through filter functions. Operates based on predefined filters, expandable with a call to Language::register_filter at the hook lang_init
Dan
parents:
654
diff
changeset
|
768 |
$filters = explode('|', $filters); |
0631e4de5de6
Added ability to have language strings send variables through filter functions. Operates based on predefined filters, expandable with a call to Language::register_filter at the hook lang_init
Dan
parents:
654
diff
changeset
|
769 |
foreach ( $filters as $filter ) |
0631e4de5de6
Added ability to have language strings send variables through filter functions. Operates based on predefined filters, expandable with a call to Language::register_filter at the hook lang_init
Dan
parents:
654
diff
changeset
|
770 |
{ |
0631e4de5de6
Added ability to have language strings send variables through filter functions. Operates based on predefined filters, expandable with a call to Language::register_filter at the hook lang_init
Dan
parents:
654
diff
changeset
|
771 |
if ( isset($this->filters[$filter]) ) |
0631e4de5de6
Added ability to have language strings send variables through filter functions. Operates based on predefined filters, expandable with a call to Language::register_filter at the hook lang_init
Dan
parents:
654
diff
changeset
|
772 |
{ |
945
c19242d13a49
Removed "@" from all call_user_func() calls to make debugging special pages and such possible
Dan
parents:
812
diff
changeset
|
773 |
$result = call_user_func($this->filters[$filter], $string); |
668
0631e4de5de6
Added ability to have language strings send variables through filter functions. Operates based on predefined filters, expandable with a call to Language::register_filter at the hook lang_init
Dan
parents:
654
diff
changeset
|
774 |
if ( is_string($result) ) |
0631e4de5de6
Added ability to have language strings send variables through filter functions. Operates based on predefined filters, expandable with a call to Language::register_filter at the hook lang_init
Dan
parents:
654
diff
changeset
|
775 |
{ |
0631e4de5de6
Added ability to have language strings send variables through filter functions. Operates based on predefined filters, expandable with a call to Language::register_filter at the hook lang_init
Dan
parents:
654
diff
changeset
|
776 |
$string = $result; |
0631e4de5de6
Added ability to have language strings send variables through filter functions. Operates based on predefined filters, expandable with a call to Language::register_filter at the hook lang_init
Dan
parents:
654
diff
changeset
|
777 |
} |
0631e4de5de6
Added ability to have language strings send variables through filter functions. Operates based on predefined filters, expandable with a call to Language::register_filter at the hook lang_init
Dan
parents:
654
diff
changeset
|
778 |
} |
0631e4de5de6
Added ability to have language strings send variables through filter functions. Operates based on predefined filters, expandable with a call to Language::register_filter at the hook lang_init
Dan
parents:
654
diff
changeset
|
779 |
} |
205 | 780 |
} |
668
0631e4de5de6
Added ability to have language strings send variables through filter functions. Operates based on predefined filters, expandable with a call to Language::register_filter at the hook lang_init
Dan
parents:
654
diff
changeset
|
781 |
return $string; |
205 | 782 |
} |
783 |
||
784 |
} // class Language |
|
785 |
||
786 |
?> |