-
Notifications
You must be signed in to change notification settings - Fork 122
/
Context.class.php
2879 lines (2618 loc) · 64.8 KB
/
Context.class.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/**
* Manages Context such as request arguments/environment variables
*
* @author NAVER (developers@xpressengine.com)
*/
#[AllowDynamicProperties]
class Context
{
/**
* Request method
* @var string GET|POST|XMLRPC|JSON
*/
public $request_method = 'GET';
/**
* Response method.If it's not set, it follows request method.
* @var string HTML|XMLRPC|JSON|JS_CALLBACK
*/
public $response_method = '';
/**
* js callback function name.
* @var string
*/
public $js_callback_func = '';
/**
* DB info
* @var object
*/
public $db_info = NULL;
/**
* FTP info
* @var object
*/
public $ftp_info = NULL;
/**
* site's browser title
* @var string
*/
public $browser_title = '';
/**
* script codes in <head>..</head>
* @var string
*/
public $html_header = '';
/**
* class names of <body>
* @var array
*/
public $body_class = array();
/**
* codes after <body>
* @var string
*/
public $body_header = '';
/**
* class names before </body>
* @var string
*/
public $html_footer = '';
/**
* Meta tags
* @var array
*/
public $meta_tags = array();
public $meta_images = array();
/**
* OpenGraph metadata
* @var array
*/
public $opengraph_metadata = array();
/**
* Canonical URL
* @var string
*/
public $canonical_url = '';
/**
* language type - changed by HTTP_USER_AGENT or user's cookie
* @var string
*/
public $lang_type = '';
/**
* contains language-specific data
* @var object
*/
public $lang = NULL;
/**
* Checks uploaded
* @var bool TRUE if attached file exists
*/
public $is_uploaded = FALSE;
/**
* Checks if the site is locked
* @var bool TRUE if the site is locked
*/
public $is_site_locked = FALSE;
/**
* Result of initial security check
* @var string|bool
*/
public $security_check = 'OK';
public $security_check_detail = '';
/**
* Singleton instance
* @var object
*/
private static $_instance = null;
/**
* Flag to prevent calling init() twice
*/
private static $_init_called = false;
/**
* Current route information
*/
private static $_route_info = null;
/**
* object oFrontEndFileHandler()
* @var object
*/
private static $_oFrontEndFileHandler = null;
/**
* Plugin default and blacklist cache
*/
private static $_default_plugins = null;
private static $_blacklist = null;
/**
* Reserved words cache
*/
private static $_reserved_words = null;
/**
* Reserved keys cache
*/
private static $_reserved_keys = array(
'_rx_ajax_compat' => true,
'_rx_ajax_form' => true,
'_rx_csrf_token' => true,
);
/**
* Pattern for request vars check
* @var array
*/
private static $_check_patterns = array(
'@<(?:\?|%)@' => 'DENY ALL',
'@<script\s*?language\s*?=@i' => 'DENY ALL',
'@</?script@i' => 'ALLOW ADMIN ONLY',
);
/**
* variables from current request
* @var object
*/
private static $_get_vars = NULL;
/**
* variables from user (Context::get, Context::set)
* @var object
*/
private static $_tpl_vars = NULL;
/**
* Obtain a singleton instance of Context.
*
* @return object Instance
*/
public static function getInstance()
{
if(self::$_instance === null)
{
// Create a singleton instance and initialize static properties.
self::$_instance = new Context();
self::$_oFrontEndFileHandler = self::$_instance->oFrontEndFileHandler = new FrontEndFileHandler();
self::$_get_vars = self::$_get_vars ?: new stdClass;
self::$_tpl_vars = self::$_tpl_vars ?: new stdClass;
}
return self::$_instance;
}
/**
* Constructor
*
* @return void
*/
private function __construct()
{
}
/**
* Initialization, it sets DB information, request arguments and so on.
*
* @return void
*/
public static function init()
{
// Prevent calling init() twice.
if(self::$_init_called)
{
return;
}
self::$_init_called = true;
// Obtain a singleton instance if not already given.
if(self::$_instance === null)
{
self::$_instance = self::getInstance();
}
// Load system configuration.
self::loadDBInfo();
// Set information about the current request.
self::_checkGlobalVars();
self::setRequestMethod();
if (in_array(self::$_instance->request_method, array('GET', 'POST', 'JSON')))
{
$method = $_SERVER['REQUEST_METHOD'] ?? 'GET';
$route_info = Rhymix\Framework\Router::parseURL($method, RX_REQUEST_URL, Rhymix\Framework\Router::getRewriteLevel());
self::setRequestArguments($route_info->args);
self::$_route_info = $route_info;
}
else
{
self::setRequestArguments();
}
self::setUploadInfo();
// If Rhymix is installed, get virtual site information.
if(self::isInstalled())
{
if (PHP_SAPI === 'cli')
{
self::set('_default_url', $default_url = config('url.default'));
if (!defined('RX_BASEURL'))
{
define('RX_BASEURL', parse_url($default_url, PHP_URL_PATH));
}
}
$site_module_info = ModuleModel::getDefaultMid() ?: new stdClass;
$site_timezone = (isset($site_module_info->settings->timezone) && $site_module_info->settings->timezone !== 'default') ? $site_module_info->settings->timezone : null;
self::set('site_module_info', $site_module_info);
self::set('_default_timezone', $site_timezone);
self::set('_default_url', self::$_instance->db_info->default_url = self::getDefaultUrl($site_module_info, RX_SSL));
self::set('_http_port', self::$_instance->db_info->http_port = $site_module_info->http_port ?: null);
self::set('_https_port', self::$_instance->db_info->https_port = $site_module_info->https_port ?: null);
self::set('_use_ssl', self::$_instance->db_info->use_ssl = ($site_module_info->security === 'none' ? 'none' : 'always'));
}
else
{
$site_module_info = new stdClass;
$site_module_info->domain = $_SERVER['HTTP_HOST'];
$site_module_info->security = RX_SSL ? 'always' : 'none';
$site_module_info->settings = new stdClass;
$site_module_info->is_default_replaced = true;
self::set('site_module_info', $site_module_info);
}
// Redirect to SSL if the current domain requires SSL.
if (!RX_SSL && PHP_SAPI !== 'cli' && $site_module_info->security !== 'none' && !$site_module_info->is_default_replaced)
{
$ssl_url = self::getDefaultUrl($site_module_info, true) . RX_REQUEST_URL;
self::setCacheControl(0);
header('Location: ' . $ssl_url, true, 301);
exit;
}
// Load language support.
$enabled_langs = self::loadLangSelected();
$set_lang_cookie = false;
self::set('lang_supported', $enabled_langs);
if($lang_type = self::get('l'))
{
if($_COOKIE['lang_type'] !== $lang_type)
{
$set_lang_cookie = true;
}
}
elseif(isset($_COOKIE['lang_type']) && $_COOKIE['lang_type'])
{
$lang_type = $_COOKIE['lang_type'];
}
elseif(config('locale.auto_select_lang') && count($enabled_langs) > 1 && isset($_SERVER['HTTP_ACCEPT_LANGUAGE']))
{
$ua_locale = Rhymix\Framework\UA::getLocale();
if (substr($ua_locale, 0, 2) !== 'zh')
{
$ua_locale = substr($ua_locale, 0, 2);
}
if (isset($enabled_langs[$ua_locale]))
{
$lang_type = $ua_locale;
$set_lang_cookie = true;
}
}
$lang_type = preg_replace('/[^a-zA-Z0-9_-]/', '', $lang_type);
if ($set_lang_cookie)
{
setcookie('lang_type', $lang_type, time() + 86400 * 365, \RX_BASEURL, '', !!config('session.use_ssl_cookies'));
}
if(!$lang_type || !isset($enabled_langs[$lang_type]))
{
if(isset($site_module_info->settings->language) && $site_module_info->settings->language !== 'default')
{
$lang_type = self::$_instance->db_info->lang_type = $site_module_info->settings->language;
}
else
{
$lang_type = self::$_instance->db_info->lang_type = config('locale.default_lang');
}
}
if(!$lang_type || !isset($enabled_langs[$lang_type]))
{
$lang_type = self::$_instance->db_info->lang_type = 'ko';
}
$lang = Rhymix\Framework\Lang::getInstance($lang_type);
$lang->loadDirectory(RX_BASEDIR . 'common/lang', 'common');
$lang->loadDirectory(RX_BASEDIR . 'modules/module/lang', 'module');
self::setLangType(self::$_instance->lang_type = $lang_type);
self::set('lang', self::$_instance->lang = $lang);
// Set global variables for backward compatibility.
$GLOBALS['oContext'] = self::$_instance;
$GLOBALS['__Context__'] = &self::$_tpl_vars;
$GLOBALS['_time_zone'] = config('locale.default_timezone');
$GLOBALS['lang'] = &$lang;
// set session handler
if(self::isInstalled() && config('session.use_db'))
{
$oSessionModel = SessionModel::getInstance();
$oSessionController = SessionController::getInstance();
ini_set('session.serialize_handler', 'php');
session_set_save_handler(
array($oSessionController, 'open'), array($oSessionController, 'close'), array($oSessionModel, 'read'), array($oSessionController, 'write'), array($oSessionController, 'destroy'), array($oSessionController, 'gc')
);
}
// start session
if (\PHP_SAPI !== 'cli')
{
Rhymix\Framework\Session::checkSSO($site_module_info);
Rhymix\Framework\Session::start(false);
}
// start output buffer
if (\PHP_SAPI !== 'cli')
{
ob_start();
}
// set authentication information in Context and session
if (self::isInstalled())
{
if (Rhymix\Framework\Session::getMemberSrl())
{
MemberController::getInstance()->setSessionInfo();
}
else
{
self::set('is_logged', false);
self::set('logged_info', false);
}
}
// start debugging
Rhymix\Framework\Debug::isEnabledForCurrentUser();
// set locations for javascript use
$current_url = $request_uri = self::getRequestUri();
if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] === 'GET' && self::$_get_vars)
{
if ($query_string = http_build_query(self::$_get_vars))
{
$current_url .= '?' . $query_string;
}
}
if (strpos($current_url, 'xn--') !== false)
{
$current_url = Rhymix\Framework\URL::decodeIdna($current_url);
}
if (strpos($request_uri, 'xn--') !== false)
{
$request_uri = Rhymix\Framework\URL::decodeIdna($request_uri);
}
self::set('current_url', $current_url);
self::set('request_uri', $request_uri);
// set mobile status
self::set('m', Mobile::isFromMobilePhone() ? 1 : 0);
// If the site is locked, display the locked page.
if(config('lock.locked'))
{
self::enforceSiteLock();
}
}
/**
* Get the session status
*
* @return bool
*/
public static function getSessionStatus()
{
return Rhymix\Framework\Session::isStarted();
}
/**
* Start the session if $_SESSION was touched
*
* @return void
*/
public static function checkSessionStatus($force = false)
{
return Rhymix\Framework\Session::checkStart($force);
}
/**
* Finalize using resources, such as DB connection
*
* @return void
*/
public static function close()
{
// Save debugging information.
if (!DisplayHandler::$debug_printed)
{
DisplayHandler::getDebugInfo();
}
// Check session status and close it if open.
if (Rhymix\Framework\Session::checkStart())
{
Rhymix\Framework\Session::close();
}
}
/**
* set Cache-Control header
*
* @return void
*/
public static function setCacheControl($ttl = 0, $public = true)
{
if($ttl == 0)
{
header('Cache-Control: ' . ($public ? 'public, ' : 'private, ') . 'must-revalidate, post-check=0, pre-check=0, no-store, no-cache');
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
}
elseif($ttl == -1)
{
header('Cache-Control: ' . ($public ? 'public, ' : 'private, ') . 'must-revalidate, post-check=0, pre-check=0');
}
else
{
header('Cache-Control: ' . ($public ? 'public, ' : 'private, ') . 'must-revalidate, max-age=' . (int)$ttl);
header('Expires: ' . gmdate('D, d M Y H:i:s', time() + (int)$ttl) . ' GMT');
}
}
/**
* Load the database information
*
* @return void
*/
public static function loadDBInfo($config = null)
{
// Load new configuration format.
if ($config === null)
{
$config = Rhymix\Framework\Config::getAll();
}
// Copy to old format for backward compatibility.
self::$_instance->db_info = new stdClass;
if (is_array($config) && count($config))
{
self::$_instance->db_info->master_db = array(
'db_type' => $config['db']['master']['type'],
'db_hostname' => $config['db']['master']['host'],
'db_port' => $config['db']['master']['port'],
'db_userid' => $config['db']['master']['user'],
'db_password' => $config['db']['master']['pass'],
'db_database' => $config['db']['master']['database'],
'db_table_prefix' => $config['db']['master']['prefix'],
'db_charset' => $config['db']['master']['charset'],
);
}
}
/**
* Get DB's db_type
*
* @return string DB's db_type
*/
public static function getDBType()
{
return self::$_instance->db_info->master_db["db_type"];
}
/**
* Set DB information
*
* @param object $db_info DB information
* @return void
*/
public static function setDBInfo($db_info)
{
self::$_instance->db_info = $db_info;
}
/**
* Get DB information
*
* @return object DB information
*/
public static function getDBInfo()
{
return self::$_instance->db_info;
}
/**
* Get current route information
*
* @return object
*/
public static function getRouteInfo()
{
return self::$_route_info;
}
/**
* Return ssl status
*
* @return object SSL status (none or always)
*/
public static function getSSLStatus()
{
return self::get('_use_ssl');
}
/**
* Return default URL
*
* @param object $site_module_info (optional)
* @param bool $use_ssl (optional)
* @return string Default URL
*/
public static function getDefaultUrl($site_module_info = null, $use_ssl = null)
{
if ($site_module_info === null && ($default_url = self::get('_default_url')))
{
return $default_url;
}
if ($site_module_info === null)
{
$site_module_info = self::get('site_module_info');
}
$prefix = ($site_module_info->security !== 'none' || $use_ssl) ? 'https://' : 'http://';
$hostname = $site_module_info->domain;
$port = ($prefix === 'https://') ? $site_module_info->https_port : $site_module_info->http_port;
$result = $prefix . $hostname . ($port ? sprintf(':%d', $port) : '') . RX_BASEURL;
return $result;
}
/**
* Find supported languages
*
* @return array Supported languages
*/
public static function loadLangSupported()
{
$list = Rhymix\Framework\Lang::getSupportedList();
return array_map(function($val) { return $val['name']; }, $list);
}
/**
* Find selected languages to serve in the site
*
* @return array Selected languages
*/
public static function loadLangSelected()
{
static $lang_selected = array();
if(!count($lang_selected))
{
$supported = Rhymix\Framework\Lang::getSupportedList();
$selected = Rhymix\Framework\Config::get('locale.enabled_lang');
if ($selected)
{
foreach ($selected as $lang)
{
$lang_selected[$lang] = $supported[$lang]['name'];
}
}
else
{
$lang_selected = array_map(function($val) { return $val['name']; }, $supported);
}
}
return $lang_selected;
}
/**
* Single Sign On (SSO)
*
* @return bool True : Module handling is necessary in the control path of current request , False : Otherwise
*/
public static function checkSSO()
{
return true;
}
/**
* Check if FTP info is registered
*
* @return bool True: FTP information is registered, False: otherwise
*/
public static function isFTPRegisted()
{
$ftp_info = self::$_instance->db_info->ftp_info;
return ($ftp_info->ftp_user && $ftp_info->ftp_root_path);
}
/**
* Get FTP information
*
* @return object FTP information
*/
public static function getFTPInfo()
{
$ftp_info = self::$_instance->db_info->ftp_info;
if (!$ftp_info->ftp_user || !$ftp_info->ftp_root_path)
{
return null;
}
return $ftp_info;
}
/**
* Append string to browser title
*
* @param string $title Browser title to be appended
* @return void
*/
public static function addBrowserTitle($title)
{
if(!$title)
{
return;
}
if(self::$_instance->browser_title)
{
self::$_instance->browser_title .= ' - ' . $title;
}
else
{
self::$_instance->browser_title = $title;
}
}
/**
* Prepend string to browser title
*
* @param string $title Browser title to be prepended
* @return void
*/
public static function prependBrowserTitle($title)
{
if(!$title)
{
return;
}
if(self::$_instance->browser_title)
{
self::$_instance->browser_title = $title . ' - ' . self::$_instance->browser_title;
}
else
{
self::$_instance->browser_title = $title;
}
}
/**
* Set string to browser title
*
* @param string $title Browser title to be set
* @param array $vars
* @return void
*/
public static function setBrowserTitle($title, $vars = array())
{
if (!$title)
{
return;
}
if (count($vars))
{
$title = trim(trim(preg_replace_callback('/\\$(\w+)/', function($matches) use($vars) {
return isset($vars[strtolower($matches[1])]) ? $vars[strtolower($matches[1])] : $matches[0];
}, $title), ' -'));
}
self::$_instance->browser_title = $title;
}
/**
* Get browser title
*
* @return string Browser title(htmlspecialchars applied)
*/
public static function getBrowserTitle()
{
if (!self::$_instance->browser_title)
{
return '';
}
return escape(self::replaceUserLang(self::$_instance->browser_title), false);
}
/**
* Return site title
*
* @return string
*/
public static function getSiteTitle()
{
$domain_info = self::get('site_module_info');
if ($domain_info && $domain_info->settings && $domain_info->settings->title)
{
return escape(self::replaceUserLang($domain_info->settings->title), false);
}
else
{
return '';
}
}
/**
* Return site subtitle
*
* @return string
*/
public static function getSiteSubtitle()
{
$domain_info = self::get('site_module_info');
if ($domain_info && $domain_info->settings && $domain_info->settings->subtitle)
{
return escape(self::replaceUserLang($domain_info->settings->subtitle), false);
}
else
{
return '';
}
}
/**
* Get browser title
* @deprecated
*/
public static function _getBrowserTitle()
{
return self::getBrowserTitle();
}
/**
* Load language file according to language type
*
* @param string $path Path of the language file
* @param string $plugin_name
* @return void
*/
public static function loadLang($path, $plugin_name = null)
{
if ($plugin_name === null && preg_match('@/(modules|addons|plugins|widgets)/([a-zA-Z0-9_-]+)/lang/?(?:lang\.xml)?$@', str_replace('\\', '/', $path), $matches))
{
$path = \RX_BASEDIR . $matches[1] . '/' . $matches[2] . '/lang';
$plugin_name = $matches[2];
}
if (!(($GLOBALS['lang'] ?? null) instanceof Rhymix\Framework\Lang))
{
$GLOBALS['lang'] = Rhymix\Framework\Lang::getInstance(self::$_instance->lang_type ?: config('locale.default_lang') ?: 'ko');
$GLOBALS['lang']->loadDirectory(RX_BASEDIR . 'common/lang', 'common');
}
return $GLOBALS['lang']->loadDirectory($path, $plugin_name);
}
/**
* Set lang_type
*
* @param string $lang_type Language type.
* @return void
*/
public static function setLangType($lang_type = 'ko')
{
if (!self::$_instance->db_info)
{
self::$_instance->db_info = new stdClass;
}
self::$_instance->db_info->lang_type = $lang_type;
self::$_instance->lang_type = $lang_type;
self::set('lang_type', $lang_type);
if(self::getSessionStatus())
{
$_SESSION['lang_type'] = $lang_type;
}
}
/**
* Get lang_type
*
* @return string Language type
*/
public static function getLangType()
{
return self::$_instance->lang_type;
}
/**
* Return string accoring to the inputed code
*
* @param string $code Language variable name
* @return string If string for the code exists returns it, otherwise returns original code
*/
public static function getLang($code)
{
if (!$GLOBALS['lang'] instanceof Rhymix\Framework\Lang)
{
$GLOBALS['lang'] = Rhymix\Framework\Lang::getInstance(self::$_instance->lang_type ?: config('locale.default_lang') ?: 'ko');
$GLOBALS['lang']->loadDirectory(RX_BASEDIR . 'common/lang', 'common');
}
return $GLOBALS['lang']->get($code);
}
/**
* Set data to lang variable
*
* @param string $code Language variable name
* @param string $val `$code`s value
* @return void
*/
public static function setLang($code, $val)
{
if (!$GLOBALS['lang'] instanceof Rhymix\Framework\Lang)
{
$GLOBALS['lang'] = Rhymix\Framework\Lang::getInstance(self::$_instance->lang_type ?: config('locale.default_lang') ?: 'ko');
$GLOBALS['lang']->loadDirectory(RX_BASEDIR . 'common/lang', 'common');
}
$GLOBALS['lang']->set($code, $val);
}
/**
* @brief Replace user-defined language codes
*/
public static function replaceUserLang($output)
{
static $lang = null;
if($lang === null)
{
$lang = Rhymix\Framework\Cache::get('site_and_module:user_defined_langs:0:' . self::getLangType());
if($lang === null)
{
$lang = ModuleAdminController::getInstance()->makeCacheDefinedLangCode(0);
}
}
return preg_replace_callback('/\$user_lang->([a-zA-Z0-9\_]+)/', function($matches) use($lang) {
if(isset($lang[$matches[1]]) && !self::get($matches[1]))
{
return $lang[$matches[1]];
}
else
{
return $matches[1];
}
}, $output);
}
/**
* Convert strings of variables in $source_object into UTF-8
*
* @deprecated
*
* @param object $source_obj Conatins strings to convert
* @return object converted object
*/
public static function convertEncoding($source_obj)
{
$charset_list = array(
'UTF-8', 'CP949', 'EUC-KR', 'ISO8859-1', 'EUC-JP', 'SHIFT_JIS',
'CP932', 'EUC-CN', 'GBK', 'GB18030', 'EUC-TW', 'BIG5',
'CP950', 'BIG5-HKSCS', 'ISO8859-6', 'ISO8859-8', 'JOHAB', 'CP1255',
'CP1256', 'CP862', 'ASCII', 'ISO8859-1', 'CP1250', 'CP1251',
'CP1252', 'CP1253', 'CP1254', 'CP1257', 'CP850', 'CP866'
);
$flag = true;
$obj = clone $source_obj;
foreach($charset_list as $charset)
{
array_walk($obj,'Context::checkConvertFlag',$charset);
$flag = self::checkConvertFlag($flag);
if($flag)
{
if($charset == 'UTF-8')
{
return $obj;
}
array_walk($obj,'Context::doConvertEncoding',$charset);
return $obj;
}
}
return $obj;
}
/**
* Check flag
*
* @deprecated
*
* @param mixed $val
* @param string $key
* @param mixed $charset charset
* @see arrayConvWalkCallback will replaced array_walk_recursive in >=PHP5
* @return void
*/
public static function checkConvertFlag(&$val, $key = null, $charset = null)
{
static $flag = TRUE;
if($charset)
{
if(is_array($val))
array_walk($val,'Context::checkConvertFlag',$charset);
else if($val && iconv($charset,$charset,$val)!=$val) $flag = FALSE;
else $flag = FALSE;
}
else
{
$return = $flag;
$flag = TRUE;
return $return;
}
}
/**
* Convert array type variables into UTF-8
*
* @deprecated
*
* @param mixed $val
* @param string $key
* @param string $charset character set
* @see arrayConvWalkCallback will replaced array_walk_recursive in >=PHP5
* @return object converted object
*/
public static function doConvertEncoding(&$val, $key = null, $charset = 'CP949')
{
if (is_array($val))
{
array_walk($val,'Context::doConvertEncoding', $charset);
}
else
{