-
Notifications
You must be signed in to change notification settings - Fork 63
/
Copy pathContext.class.php
2543 lines (2263 loc) · 55.9 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
/* Copyright (C) NAVER <http://www.navercorp.com> */
define('FOLLOW_REQUEST_SSL', 0);
define('ENFORCE_SSL', 1);
define('RELEASE_SSL', 2);
/**
* Manages Context such as request arguments/environment variables
* It has dual method structure, easy-to use methods which can be called as self::methodname(),and methods called with static object.
*
* @author NAVER ([email protected])
*/
class Context
{
/**
* Allow rewrite
* @var bool TRUE: using rewrite mod, FALSE: otherwise
*/
public $allow_rewrite = FALSE;
/**
* Request method
* @var string GET|POST|XMLRPC
*/
public $request_method = 'GET';
/**
* js callback function name.
* @var string
*/
public $js_callback_func = '';
/**
* Response method.If it's not set, it follows request method.
* @var string HTML|XMLRPC
*/
public $response_method = '';
/**
* Conatins request parameters and environment variables
* @var object
*/
public $context = NULL;
/**
* DB info
* @var object
*/
public $db_info = NULL;
/**
* FTP info
* @var object
*/
public $ftp_info = NULL;
/**
* ssl action cache file
* @var array
*/
public $sslActionCacheFile = './files/cache/sslCacheFile.php';
/**
* List of actions to be sent via ssl (it is used by javascript xml handler for ajax)
* @var array
*/
public $ssl_actions = array();
/**
* obejct oFrontEndFileHandler()
* @var object
*/
public $oFrontEndFileHandler;
/**
* script codes in <head>..</head>
* @var string
*/
public $html_header = NULL;
/**
* class names of <body>
* @var array
*/
public $body_class = array();
/**
* codes after <body>
* @var string
*/
public $body_header = NULL;
/**
* class names before </body>
* @var string
*/
public $html_footer = NULL;
/**
* path of Xpress Engine
* @var string
*/
public $path = '';
// language information - it is changed by HTTP_USER_AGENT or user's cookie
/**
* language type
* @var string
*/
public $lang_type = '';
/**
* contains language-specific data
* @var object
*/
public $lang = NULL;
/**
* list of loaded languages (to avoid re-loading them)
* @var array
*/
public $loaded_lang_files = array();
/**
* site's browser title
* @var string
*/
public $site_title = '';
/**
* variables from GET or form submit
* @var mixed
*/
public $get_vars = NULL;
/**
* Checks uploaded
* @var bool TRUE if attached file exists
*/
public $is_uploaded = FALSE;
/**
* Pattern for request vars check
* @var array
*/
public $patterns = array(
'/<\?/iUsm',
'/<\%/iUsm',
'/<script\s*?language\s*?=\s*?("|\')?\s*?php\s*("|\')?/iUsm'
);
/**
* Check init
* @var bool FALSE if init fail
*/
public $isSuccessInit = TRUE;
/**
* returns static context object (Singleton). It's to use Context without declaration of an object
*
* @return object Instance
*/
function &getInstance()
{
static $theInstance = null;
if(!$theInstance)
{
$theInstance = new Context();
}
return $theInstance;
}
/**
* Cunstructor
*
* @return void
*/
function Context()
{
$this->oFrontEndFileHandler = new FrontEndFileHandler();
$this->get_vars = new stdClass();
// include ssl action cache file
$this->sslActionCacheFile = FileHandler::getRealPath($this->sslActionCacheFile);
if(is_readable($this->sslActionCacheFile))
{
require($this->sslActionCacheFile);
if(isset($sslActions))
{
$this->ssl_actions = $sslActions;
}
}
}
/**
* Initialization, it sets DB information, request arguments and so on.
*
* @see This function should be called only once
* @return void
*/
function init()
{
// set context variables in $GLOBALS (to use in display handler)
$this->context = &$GLOBALS['__Context__'];
$this->context->lang = &$GLOBALS['lang'];
$this->context->_COOKIE = $_COOKIE;
// 20140429 editor/image_link
$this->_checkGlobalVars();
$this->setRequestMethod('');
$this->_setXmlRpcArgument();
$this->_setJSONRequestArgument();
$this->_setRequestArgument();
$this->_setUploadedArgument();
$this->loadDBInfo();
if($this->db_info->use_sitelock == 'Y')
{
if(is_array($this->db_info->sitelock_whitelist)) $whitelist = $this->db_info->sitelock_whitelist;
if(!IpFilter::filter($whitelist))
{
$title = ($this->db_info->sitelock_title) ? $this->db_info->sitelock_title : 'Maintenance in progress...';
$message = $this->db_info->sitelock_message;
define('_XE_SITELOCK_', TRUE);
define('_XE_SITELOCK_TITLE_', $title);
define('_XE_SITELOCK_MESSAGE_', $message);
header("HTTP/1.1 403 Forbidden");
include _XE_PATH_ . 'common/tpl/sitelock.html';
exit;
}
}
// If XE is installed, get virtual site information
if(self::isInstalled())
{
$oModuleModel = getModel('module');
$site_module_info = $oModuleModel->getDefaultMid();
if(!isset($site_module_info))
{
$site_module_info = new stdClass();
}
// if site_srl of site_module_info is 0 (default site), compare the domain to default_url of db_config
if($site_module_info->site_srl == 0 && $site_module_info->domain != $this->db_info->default_url)
{
$site_module_info->domain = $this->db_info->default_url;
}
$this->set('site_module_info', $site_module_info);
if($site_module_info->site_srl && isSiteID($site_module_info->domain))
{
$this->set('vid', $site_module_info->domain, TRUE);
}
if(!isset($this->db_info))
{
$this->db_info = new stdClass();
}
$this->db_info->lang_type = $site_module_info->default_language;
if(!$this->db_info->lang_type)
{
$this->db_info->lang_type = 'en';
}
if(!$this->db_info->use_db_session)
{
$this->db_info->use_db_session = 'N';
}
}
// Load Language File
$lang_supported = $this->loadLangSelected();
// Retrieve language type set in user's cookie
if($this->lang_type = $this->get('l'))
{
if($_COOKIE['lang_type'] != $this->lang_type)
{
setcookie('lang_type', $this->lang_type, $_SERVER['REQUEST_TIME'] + 3600 * 24 * 1000, '/');
}
}
elseif($_COOKIE['lang_type'])
{
$this->lang_type = $_COOKIE['lang_type'];
}
// If it's not exists, follow default language type set in db_info
if(!$this->lang_type)
{
$this->lang_type = $this->db_info->lang_type;
}
// if still lang_type has not been set or has not-supported type , set as English.
if(!$this->lang_type)
{
$this->lang_type = 'en';
}
if(is_array($lang_supported) && !isset($lang_supported[$this->lang_type]))
{
$this->lang_type = 'en';
}
$this->set('lang_supported', $lang_supported);
$this->setLangType($this->lang_type);
// load module module's language file according to language setting
$this->loadLang(_XE_PATH_ . 'modules/module/lang');
// set session handler
if(self::isInstalled() && $this->db_info->use_db_session == 'Y')
{
$oSessionModel = getModel('session');
$oSessionController = getController('session');
session_set_save_handler(
array(&$oSessionController, 'open'), array(&$oSessionController, 'close'), array(&$oSessionModel, 'read'), array(&$oSessionController, 'write'), array(&$oSessionController, 'destroy'), array(&$oSessionController, 'gc')
);
}
session_start();
if($sess = $_POST[session_name()])
{
session_id($sess);
}
// set authentication information in Context and session
if(self::isInstalled())
{
$oModuleModel = getModel('module');
$oModuleModel->loadModuleExtends();
$oMemberModel = getModel('member');
$oMemberController = getController('member');
if($oMemberController && $oMemberModel)
{
// if signed in, validate it.
if($oMemberModel->isLogged())
{
$oMemberController->setSessionInfo();
}
// check auto sign-in
elseif($_COOKIE['xeak'])
{
$oMemberController->doAutologin();
}
$this->set('is_logged', $oMemberModel->isLogged());
$this->set('logged_info', $oMemberModel->getLoggedInfo());
}
}
// load common language file
$this->lang = &$GLOBALS['lang'];
$this->loadLang(_XE_PATH_ . 'common/lang/');
// check if using rewrite module
$this->allow_rewrite = ($this->db_info->use_rewrite == 'Y' ? TRUE : FALSE);
// set locations for javascript use
if($_SERVER['REQUEST_METHOD'] == 'GET')
{
if($this->get_vars)
{
$url = array();
foreach($this->get_vars as $key => $val)
{
if(is_array($val) && count($val) > 0)
{
foreach($val as $k => $v)
{
$url[] = $key . '[' . $k . ']=' . urlencode($v);
}
}
elseif($val)
{
$url[] = $key . '=' . urlencode($val);
}
}
$this->set('current_url', self::getRequestUri() . '?' . join('&', $url));
}
else
{
$this->set('current_url', $this->getUrl());
}
}
else
{
$this->set('current_url', self::getRequestUri());
}
$this->set('request_uri', self::getRequestUri());
}
/**
* Finalize using resources, such as DB connection
*
* @return void
*/
function close()
{
session_write_close();
}
/**
* Load the database information
*
* @return void
*/
function loadDBInfo()
{
is_a($this, 'Context') ? $self = $this : $self = self::getInstance();
if(!$self->isInstalled())
{
return;
}
$config_file = $self->getConfigFile();
if(is_readable($config_file))
{
include($config_file);
}
// If master_db information does not exist, the config file needs to be updated
if(!isset($db_info->master_db))
{
$db_info->master_db = array();
$db_info->master_db["db_type"] = $db_info->db_type;
unset($db_info->db_type);
$db_info->master_db["db_port"] = $db_info->db_port;
unset($db_info->db_port);
$db_info->master_db["db_hostname"] = $db_info->db_hostname;
unset($db_info->db_hostname);
$db_info->master_db["db_password"] = $db_info->db_password;
unset($db_info->db_password);
$db_info->master_db["db_database"] = $db_info->db_database;
unset($db_info->db_database);
$db_info->master_db["db_userid"] = $db_info->db_userid;
unset($db_info->db_userid);
$db_info->master_db["db_table_prefix"] = $db_info->db_table_prefix;
unset($db_info->db_table_prefix);
if(isset($db_info->master_db["db_table_prefix"]) && substr_compare($db_info->master_db["db_table_prefix"], '_', -1) !== 0)
{
$db_info->master_db["db_table_prefix"] .= '_';
}
$db_info->slave_db = array($db_info->master_db);
$self->setDBInfo($db_info);
$oInstallController = getController('install');
$oInstallController->makeConfigFile();
}
if(!$db_info->use_prepared_statements)
{
$db_info->use_prepared_statements = 'Y';
}
if(!$db_info->time_zone)
$db_info->time_zone = date('O');
$GLOBALS['_time_zone'] = $db_info->time_zone;
if($db_info->qmail_compatibility != 'Y')
$db_info->qmail_compatibility = 'N';
$GLOBALS['_qmail_compatibility'] = $db_info->qmail_compatibility;
if(!$db_info->use_db_session)
$db_info->use_db_session = 'N';
if(!$db_info->use_ssl)
$db_info->use_ssl = 'none';
$this->set('_use_ssl', $db_info->use_ssl);
if($db_info->http_port)
$self->set('_http_port', $db_info->http_port);
if($db_info->https_port)
$self->set('_https_port', $db_info->https_port);
if(!$db_info->sitelock_whitelist) {
$db_info->sitelock_whitelist = '127.0.0.1';
}
if(is_string($db_info->sitelock_whitelist)) {
$db_info->sitelock_whitelist = explode(',', $db_info->sitelock_whitelist);
}
$self->setDBInfo($db_info);
}
/**
* Get DB's db_type
*
* @return string DB's db_type
*/
function getDBType()
{
is_a($this, 'Context') ? $self = $this : $self = self::getInstance();
return $self->db_info->master_db["db_type"];
}
/**
* Set DB information
*
* @param object $db_info DB information
* @return void
*/
function setDBInfo($db_info)
{
is_a($this, 'Context') ? $self = $this : $self = self::getInstance();
$self->db_info = $db_info;
}
/**
* Get DB information
*
* @return object DB information
*/
function getDBInfo()
{
is_a($this, 'Context') ? $self = $this : $self = self::getInstance();
return $self->db_info;
}
/**
* Return ssl status
*
* @return object SSL status (Optional - none|always|optional)
*/
function getSslStatus()
{
$dbInfo = self::getDBInfo();
return $dbInfo->use_ssl;
}
/**
* Return default URL
*
* @return string Default URL
*/
function getDefaultUrl()
{
$db_info = self::getDBInfo();
return $db_info->default_url;
}
/**
* Find supported languages
*
* @return array Supported languages
*/
function loadLangSupported()
{
static $lang_supported = null;
if(!$lang_supported)
{
$langs = file(_XE_PATH_ . 'common/lang/lang.info');
foreach($langs as $val)
{
list($lang_prefix, $lang_text) = explode(',', $val);
$lang_text = trim($lang_text);
$lang_supported[$lang_prefix] = $lang_text;
}
}
return $lang_supported;
}
/**
* Find selected languages to serve in the site
*
* @return array Selected languages
*/
function loadLangSelected()
{
static $lang_selected = null;
if(!$lang_selected)
{
$orig_lang_file = _XE_PATH_ . 'common/lang/lang.info';
$selected_lang_file = _XE_PATH_ . 'files/config/lang_selected.info';
if(!FileHandler::hasContent($selected_lang_file))
{
$old_selected_lang_file = _XE_PATH_ . 'files/cache/lang_selected.info';
FileHandler::moveFile($old_selected_lang_file, $selected_lang_file);
}
if(!FileHandler::hasContent($selected_lang_file))
{
$buff = FileHandler::readFile($orig_lang_file);
FileHandler::writeFile($selected_lang_file, $buff);
$lang_selected = self::loadLangSupported();
}
else
{
$langs = file($selected_lang_file);
foreach($langs as $val)
{
list($lang_prefix, $lang_text) = explode(',', $val);
$lang_text = trim($lang_text);
$lang_selected[$lang_prefix] = $lang_text;
}
}
}
return $lang_selected;
}
/**
* Single Sign On (SSO)
*
* @return bool True : Module handling is necessary in the control path of current request , False : Otherwise
*/
function checkSSO()
{
// pass if it's not GET request or XE is not yet installed
if($this->db_info->use_sso != 'Y' || isCrawler())
{
return TRUE;
}
$checkActList = array('rss' => 1, 'atom' => 1);
if(self::getRequestMethod() != 'GET' || !self::isInstalled() || isset($checkActList[self::get('act')]))
{
return TRUE;
}
// pass if default URL is not set
$default_url = trim($this->db_info->default_url);
if(!$default_url)
{
return TRUE;
}
if(substr_compare($default_url, '/', -1) !== 0)
{
$default_url .= '/';
}
// for sites recieving SSO valdiation
if($default_url == self::getRequestUri())
{
if(self::get('default_url'))
{
$url = base64_decode(self::get('default_url'));
$url_info = parse_url($url);
$url_info['query'].= ($url_info['query'] ? '&' : '') . 'SSOID=' . session_id();
$redirect_url = sprintf('%s://%s%s%s?%s', $url_info['scheme'], $url_info['host'], $url_info['port'] ? ':' . $url_info['port'] : '', $url_info['path'], $url_info['query']);
header('location:' . $redirect_url);
return FALSE;
}
// for sites requesting SSO validation
}
else
{
// result handling : set session_name()
if($session_name = self::get('SSOID'))
{
setcookie(session_name(), $session_name);
$url = preg_replace('/([\?\&])$/', '', str_replace('SSOID=' . $session_name, '', self::getRequestUrl()));
header('location:' . $url);
return FALSE;
// send SSO request
}
else if(!self::get('SSOID') && $_COOKIE['sso'] != md5(self::getRequestUri()))
{
setcookie('sso', md5(self::getRequestUri()), 0, '/');
$url = sprintf("%s?default_url=%s", $default_url, base64_encode(self::getRequestUrl()));
header('location:' . $url);
return FALSE;
}
}
return TRUE;
}
/**
* Check if FTP info is registered
*
* @return bool True: FTP information is registered, False: otherwise
*/
function isFTPRegisted()
{
return file_exists(self::getFTPConfigFile());
}
/**
* Get FTP information
*
* @return object FTP information
*/
function getFTPInfo()
{
is_a($this, 'Context') ? $self = $this : $self = self::getInstance();
if(!$self->isFTPRegisted())
{
return null;
}
include($self->getFTPConfigFile());
return $ftp_info;
}
/**
* Add string to browser title
*
* @param string $site_title Browser title to be added
* @return void
*/
function addBrowserTitle($site_title)
{
if(!$site_title)
{
return;
}
is_a($this, 'Context') ? $self = $this : $self = self::getInstance();
if($self->site_title)
{
$self->site_title .= ' - ' . $site_title;
}
else
{
$self->site_title = $site_title;
}
}
/**
* Set string to browser title
*
* @param string $site_title Browser title to be set
* @return void
*/
function setBrowserTitle($site_title)
{
if(!$site_title)
{
return;
}
is_a($this, 'Context') ? $self = $this : $self = self::getInstance();
$self->site_title = $site_title;
}
/**
* Get browser title
*
* @return string Browser title(htmlspecialchars applied)
*/
function getBrowserTitle()
{
is_a($this, 'Context') ? $self = $this : $self = self::getInstance();
$oModuleController = getController('module');
$oModuleController->replaceDefinedLangCode($self->site_title);
return htmlspecialchars($self->site_title, ENT_COMPAT | ENT_HTML401, 'UTF-8', FALSE);
}
/**
* Return layout's title
* @return string layout's title
*/
public function getSiteTitle()
{
$oModuleModel = getModel('module');
$moduleConfig = $oModuleModel->getModuleConfig('module');
if(isset($moduleConfig->siteTitle))
{
return $moduleConfig->siteTitle;
}
return '';
}
/**
* Get browser title
* @deprecated
*/
function _getBrowserTitle()
{
return $this->getBrowserTitle();
}
/**
* Load language file according to language type
*
* @param string $path Path of the language file
* @return void
*/
function loadLang($path)
{
global $lang;
is_a($this, 'Context') ? $self = $this : $self = self::getInstance();
if(!$self->lang_type)
{
return;
}
if(!is_object($lang))
{
$lang = new stdClass;
}
if(!($filename = $self->_loadXmlLang($path)))
{
$filename = $self->_loadPhpLang($path);
}
if(!is_array($self->loaded_lang_files))
{
$self->loaded_lang_files = array();
}
if(in_array($filename, $self->loaded_lang_files))
{
return;
}
if($filename && is_readable($filename))
{
$self->loaded_lang_files[] = $filename;
include($filename);
}
else
{
$self->_evalxmlLang($path);
}
}
/**
* Evaluation of xml language file
*
* @param string Path of the language file
* @return void
*/
function _evalxmlLang($path)
{
global $lang;
if(!$path) return;
$_path = 'eval://' . $path;
if(in_array($_path, $this->loaded_lang_files))
{
return;
}
if(substr_compare($path, '/', -1) !== 0)
{
$path .= '/';
}
$oXmlLangParser = new XmlLangParser($path . 'lang.xml', $this->lang_type);
$content = $oXmlLangParser->getCompileContent();
if($content)
{
$this->loaded_lang_files[] = $_path;
eval($content);
}
}
/**
* Load language file of xml type
*
* @param string $path Path of the language file
* @return string file name
*/
function _loadXmlLang($path)
{
if(!$path) return;
$oXmlLangParser = new XmlLangParser($path . ((substr_compare($path, '/', -1) !== 0) ? '/' : '') . 'lang.xml', $this->lang_type);
return $oXmlLangParser->compile();
}
/**
* Load language file of php type
*
* @param string $path Path of the language file
* @return string file name
*/
function _loadPhpLang($path)
{
if(!$path) return;
if(substr_compare($path, '/', -1) !== 0)
{
$path .= '/';
}
$path_tpl = $path . '%s.lang.php';
$file = sprintf($path_tpl, $this->lang_type);
$langs = array('ko', 'en'); // this will be configurable.
while(!is_readable($file) && $langs[0])
{
$file = sprintf($path_tpl, array_shift($langs));
}
if(!is_readable($file))
{
return FALSE;
}
return $file;
}
/**
* Set lang_type
*
* @param string $lang_type Language type.
* @return void
*/
function setLangType($lang_type = 'ko')
{
is_a($this, 'Context') ? $self = $this : $self = self::getInstance();
$self->lang_type = $lang_type;
$self->set('lang_type', $lang_type);
$_SESSION['lang_type'] = $lang_type;
}
/**
* Get lang_type
*
* @return string Language type
*/
function getLangType()
{
is_a($this, 'Context') ? $self = $this : $self = self::getInstance();
return $self->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
*/
function getLang($code)
{
if(!$code)
{
return;
}
if($GLOBALS['lang']->{$code})
{
return $GLOBALS['lang']->{$code};
}
return $code;
}
/**
* Set data to lang variable
*
* @param string $code Language variable name
* @param string $val `$code`s value
* @return void
*/
function setLang($code, $val)
{
if(!isset($GLOBALS['lang']))
{
$GLOBALS['lang'] = new stdClass();
}
$GLOBALS['lang']->{$code} = $val;
}
/**
* Convert strings of variables in $source_object into UTF-8
*
* @param object $source_obj Conatins strings to convert
* @return object converted object
*/
function convertEncoding($source_obj)
{
$charset_list = array(
'UTF-8', 'EUC-KR', 'CP949', 'ISO8859-1', 'EUC-JP', 'SHIFT_JIS', 'CP932',
'EUC-CN', 'HZ', 'GBK', 'GB18030', 'EUC-TW', 'BIG5', 'CP950', 'BIG5-HKSCS',
'ISO2022-CN', 'ISO2022-CN-EXT', 'ISO2022-JP', 'ISO2022-JP-2', 'ISO2022-JP-1',
'ISO8859-6', 'ISO8859-8', 'JOHAB', 'ISO2022-KR', 'CP1255', 'CP1256', 'CP862',
'ASCII', 'ISO8859-1', 'ISO8850-2', 'ISO8850-3', 'ISO8850-4', 'ISO8850-5',
'ISO8850-7', 'ISO8850-9', 'ISO8850-10', 'ISO8850-13', 'ISO8850-14',
'ISO8850-15', 'ISO8850-16', 'CP1250', 'CP1251', 'CP1252', 'CP1253', 'CP1254',
'CP1257', 'CP850', 'CP866',
);
$obj = clone $source_obj;
foreach($charset_list as $charset)
{
array_walk($obj,'Context::checkConvertFlag',$charset);
$flag = self::checkConvertFlag($flag = TRUE);
if($flag)
{
if($charset == 'UTF-8')
{
return $obj;