-
Notifications
You must be signed in to change notification settings - Fork 0
/
global.php
2115 lines (1981 loc) · 65.3 KB
/
global.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
/**
* 通用预处理文件
*
* 定义系统函数、变量,程序预处理
*
* 调用模板:无
*
* @category jieqicms
* @package system
* @copyright Copyright (c) Hangzhou Jieqi Network Technology Co.,Ltd. (http://www.jieqi.com)
* @author $Author: juny $
* @version $Id: global.php 344 2009-06-23 03:06:07Z juny $
*/
$tmpvar = explode(' ', microtime());
define('JIEQI_START_TIME', $tmpvar[1] + $tmpvar[0]);
if(defined('JIEQI_PHP_CLI')) exit('error defined JIEQI_PHP_CLI');
if((!empty($_SERVER['SCRIPT_FILENAME']) && isset($_SERVER['argv']) && $_SERVER['SCRIPT_FILENAME'] == $_SERVER['argv'][0]) || (empty($_SERVER['SCRIPT_FILENAME']) && isset($_SERVER['argv']) && !empty($_SERVER['argv'][0]))) define('JIEQI_PHP_CLI', 1);
else define('JIEQI_PHP_CLI', 0);
if(defined('JIEQI_SCRIPT_FILENAME')) exit('error defined JIEQI_SCRIPT_FILENAME');
$tmpvar = (!empty($_SERVER['PATH_TRANSLATED']) && substr($_SERVER['PATH_TRANSLATED'],-4)=='.php') ? $_SERVER['PATH_TRANSLATED'] : $_SERVER['SCRIPT_FILENAME'];
define('JIEQI_SCRIPT_FILENAME', str_replace(array('\\\\','\\'),'/',$tmpvar));
if(!defined('JIEQI_SITE_ID')) define('JIEQI_SITE_ID', 0); //网站序号,0表示主站,大于0的表示分站
//包含系统全局参数
include_once('configs/define.php');
if(defined('JIEQI_LOCAL_HOST')) exit('error defined JIEQI_LOCAL_HOST');
if($_SERVER['HTTP_HOST'] == '' && JIEQI_URL != '') define('JIEQI_LOCAL_HOST', str_replace(array('http://', 'https://'), '', JIEQI_URL));
else define('JIEQI_LOCAL_HOST', $_SERVER['HTTP_HOST']);
$_SERVER['PHP_SELF'] = htmlspecialchars($_SERVER['PHP_SELF'], ENT_QUOTES);
define("JIEQI_NOW_TIME", time()); //系统时间
define("JIEQI_VERSION","1.70"); //系统版本
//Free(F), Popular(O), Standard(S), Professional(P), Enterprise(E), Deluxe(D), Custom(C)
//在认证文件里面授权
define('JIEQI_VERSION_TYPE', 'Standard');
define('JIEQI_MODULE_VTYPE', 'Standard');
define('JIEQI_GLOBAL_INCLUDE',true); //包含global标记
if(!defined('JIEQI_ROOT_PATH')) @define('JIEQI_ROOT_PATH', str_replace(array('\\\\','\\'),'/',dirname(__FILE__))); //物理根路径
if(!defined('JIEQI_COOKIE_DOMAIN')) define('JIEQI_COOKIE_DOMAIN', strval(@ini_get('session.cookie_domain')));
elseif(JIEQI_COOKIE_DOMAIN != '') @ini_set('session.cookie_domain', JIEQI_COOKIE_DOMAIN);
define('JIEQI_SYSTEM_CHARSET', 'gbk'); //系统代码语言
//本机完整地址
if(JIEQI_URL == '') define('JIEQI_LOCAL_URL', 'http://'.$_SERVER['HTTP_HOST']);
else define('JIEQI_LOCAL_URL', JIEQI_URL);
//主服务器地址
if(!defined('JIEQI_MAIN_SERVER') || JIEQI_MAIN_SERVER == '') define('JIEQI_MAIN_URL', JIEQI_LOCAL_URL);
else define('JIEQI_MAIN_URL', JIEQI_MAIN_SERVER);
//用户入口地址
if(!defined('JIEQI_USER_ENTRY') || JIEQI_USER_ENTRY == '') define('JIEQI_USER_URL', JIEQI_LOCAL_URL);
else define('JIEQI_USER_URL', JIEQI_USER_ENTRY);
//错误模式
define('JIEQI_ERROR_RETURN', 1); //只返回
define('JIEQI_ERROR_PRINT', 2); //打印错误并继续
define('JIEQI_ERROR_DIE', 4); //显示错误并停止
//默认用户组
define('JIEQI_GROUP_USER', 3); //登录用户
define('JIEQI_GROUP_ADMIN', 2); //系统管理员
define('JIEQI_GROUP_GUEST', 1); //游客
// 区块位置
define("JIEQI_SIDEBLOCK_CUSTOM",-1); //自定义
define("JIEQI_SIDEBLOCK_LEFT",0); //左
define("JIEQI_SIDEBLOCK_RIGHT",1); //右
define("JIEQI_CENTERBLOCK_LEFT",2); //中左
define("JIEQI_CENTERBLOCK_RIGHT",3); //中右
define("JIEQI_CENTERBLOCK_TOP",4); //中上
define("JIEQI_CENTERBLOCK_MIDDLE",5); //中中
define("JIEQI_CENTERBLOCK_BOTTOM",6); //中下
define("JIEQI_TOPBLOCK_ALL",7); //顶部
define("JIEQI_BOTTOMBLOCK_ALL",8); //底部
//数据显示类型
define('JIEQI_TYPE_TXTBOX', 1); //单行文本
define('JIEQI_TYPE_TXTAREA', 2); //多行文本
define('JIEQI_TYPE_INT', 3); //整数
define('JIEQI_TYPE_NUM', 4); //数字
define('JIEQI_TYPE_PASSWORD', 5); //密码
define('JIEQI_TYPE_HIDDEN', 6); //隐藏域
define('JIEQI_TYPE_SELECT', 7); //下拉单选
define('JIEQI_TYPE_MULSELECT', 8); //下拉多选
define('JIEQI_TYPE_RADIO', 9); //单选
define('JIEQI_TYPE_CHECKBOX', 10); //多选
define('JIEQI_TYPE_LABEL', 11); //文字文本
define('JIEQI_TYPE_FILE', 12); //文件上传
define('JIEQI_TYPE_DATE', 13); //日期
define('JIEQI_TYPE_UBB', 14); //ubb代码
define('JIEQI_TYPE_HTML', 15); //html代码
define('JIEQI_TYPE_CODE', 16); //程序代码
define('JIEQI_TYPE_SCRIPT', 17); //网页脚本javascript/vbscript
define('JIEQI_TYPE_OTHER', 20); //其他
//打开窗口方式
define('JIEQI_TARGET_SELF', 'self'); //自身窗口
define('JIEQI_TARGET_NEW', 'blank'); //新开窗口
define('JIEQI_TARGET_TOP', 'top'); //弹出小窗口
//内容格式
define('JIEQI_CONTENT_TXT', 0); //文本
define('JIEQI_CONTENT_HTML', 1); //html
define('JIEQI_CONTENT_JS', 2); //js文件
define('JIEQI_CONTENT_MIX', 3); //html和script混合
define('JIEQI_CONTENT_PHP', 4); //php
//图片格式
$jieqi_image_type=array(1=>'.gif', 2=>'.jpg', 3=>'.jpeg', 4=>'.png', 5=>'.bmp');
//文件后缀名统一定义
$jieqi_file_postfix=array('txt'=>'.txt', 'html'=>'.html', 'htm'=>'.htm', 'xml'=>'.xml', 'php'=>'.php', 'js'=>'.js', 'css'=>'.css', 'zip'=>'.zip', 'jar'=>'.jar', 'jad'=>'.jad', 'umd'=>'.umd', 'opf'=>'.opf');
//编码类型
$jieqi_charset_type=array('gb'=>'gbk', 'gbk'=>'gbk', 'gb2312'=>'gbk', 'big5'=>'big5', 'utf8'=>'utf-8', 'utf-8'=>'utf-8');
//******************************************************
//预处理
//******************************************************
//是否载入用户自定义程序段(仅限于php文件)
if(defined('JIEQI_CUSTOM_INCLUDE') && JIEQI_CUSTOM_INCLUDE == 1){
$tmpstr = $_SERVER['PHP_SELF'] ? basename($_SERVER['PHP_SELF']) : basename($_SERVER['SCRIPT_NAME']);
if( preg_match('/\.php$/i', $tmpstr)){
$tmpstr = substr($tmpstr, 0, -4).'.inc.php';
if(is_file($tmpstr) && preg_match('/^\w+\.inc\.php$/i', $tmpstr)) include_once($tmpstr);
}
}
//php5的时区问题
//if(function_exists('date_default_timezone_set')) @date_default_timezone_set('PRC');
//外部引入资料不自动加反斜线溢出字元
@set_magic_quotes_runtime(0);
//错误显示模式
if(JIEQI_ERROR_MODE == 0){
@ini_set('display_errors', 0);
@error_reporting(0);
}elseif(JIEQI_ERROR_MODE == 1){
@ini_set('display_errors', 1);
@error_reporting(E_ALL & ~E_NOTICE);
}elseif(JIEQI_ERROR_MODE == 2){
@ini_set('display_errors', 1);
@error_reporting(E_ALL);
}
//显示版权信息
if(isset($_GET['show_jieqi_version']) && $_GET['show_jieqi_version'] == 1){
echo '<html><head><meta http-equiv="Content-Type" content="text/html; charset='.JIEQI_SYSTEM_CHARSET.'" /><title>Version Info</title></head><body>Site name: '.JIEQI_SITE_NAME.'<br />URL: '.JIEQI_URL.'<br />Version: JIEQI CMS V'.JIEQI_VERSION.'<br />Powered by <a href="http://www.jieqi.com">JIEQI CMS</a><br /><br />License key:<br />'.JIEQI_LICENSE_KEY.'</body></html>';
exit;
}
//是否启用PATH_INFO
if (isset($_SERVER['PATH_INFO']) && defined('JIEQI_PATH_INFO') && JIEQI_PATH_INFO > 0) {
$tmpary = explode('/', str_replace(array("'", '"', '.htm', '.html'), '', substr($_SERVER['PATH_INFO'], 1)));
$tmpcot = count($tmpary);
for($i = 0; $i < $tmpcot; $i += 2){
if(isset($tmpary[$i + 1]) && !is_numeric($tmpary[$i])){
$_GET[$tmpary[$i]] = $tmpary[$i + 1];
$_REQUEST[$tmpary[$i]] = $tmpary[$i + 1];
}
}
}
//设置模块路径
$jieqiModules = array();
include_once('configs/modules.php');
//本模块未开放
if(isset($jieqiModules[JIEQI_MODULE_NAME]['publish']) && $jieqiModules[JIEQI_MODULE_NAME]['publish']==0){
header('Content-type:text/html;charset='.JIEQI_SYSTEM_CHARSET);
echo 'This function is not valid!';
jieqi_freeresource();
exit;
}
foreach($jieqiModules as $k=>$v){
if(strtolower(substr($k,0,3)) == 'wap'){
$wapmod = true;
$dirmod = substr($k,3);
}else{
$wapmod = false;
$dirmod = $k;
}
if($v['dir']=='') $jieqiModules[$k]['dir'] = ($wapmod == true) ? (($k == 'wap') ? '/wap' : '/wap/'.$dirmod) : (($k == 'system') ? '' : '/modules/'.$dirmod);
if($v['path']=='') $jieqiModules[$k]['path'] = JIEQI_ROOT_PATH.$jieqiModules[$k]['dir'];
if($v['url']=='') $jieqiModules[$k]['url'] = JIEQI_LOCAL_URL.$jieqiModules[$k]['dir'];
if($v['theme']=='') $jieqiModules[$k]['theme'] = JIEQI_THEME_SET;
if(defined('JIEQI_MODULE_NAME') && JIEQI_MODULE_NAME == $k){
if(!empty($jieqiModules[$k]['theme'])) @define('JIEQI_THEME_NAME', $jieqiModules[$k]['theme']);
}
}
if(!defined('JIEQI_THEME_NAME')) define('JIEQI_THEME_NAME', JIEQI_THEME_SET);
if(isset($jieqiModules['wap']['path'])) define('JIEQI_WAP_PATH', $jieqiModules['wap']['path']);
else define('JIEQI_WAP_PATH', JIEQI_ROOT_PATH.'/wap');
if(isset($jieqiModules['wap']['url'])) define('JIEQI_WAP_URL', $jieqiModules['wap']['url']);
else define('JIEQI_WAP_URL', JIEQI_LOCAL_URL.'/wap');
//是否需要编码转换(免费版不支持)
if(defined('JIEQI_CHARSET_CONVERT') && JIEQI_CHARSET_CONVERT == 1 && JIEQI_VERSION_TYPE != '' && JIEQI_VERSION_TYPE != 'Free'){
if(isset($_GET['charset'])) $_GET['charset']=strtolower($_GET['charset']);
if(isset($_GET['charset']) && isset($jieqi_charset_type[$_GET['charset']])) @define('JIEQI_CHAR_SET', $jieqi_charset_type[$_GET['charset']]);
elseif(isset($_COOKIE['jieqiUserCharset']) && isset($jieqi_charset_type[$_COOKIE['jieqiUserCharset']])) @define('JIEQI_CHAR_SET', $jieqi_charset_type[$_COOKIE['jieqiUserCharset']]);
else @define('JIEQI_CHAR_SET', JIEQI_SYSTEM_CHARSET);
if ((!isset($_COOKIE['jieqiUserCharset']) && JIEQI_CHAR_SET != JIEQI_SYSTEM_CHARSET) || (isset($_COOKIE['jieqiUserCharset']) && $_COOKIE['jieqiUserCharset'] != JIEQI_CHAR_SET)) setcookie("jieqiUserCharset",JIEQI_CHAR_SET,time()+2592000, '/', JIEQI_COOKIE_DOMAIN, 0);
}else{
@define('JIEQI_CHAR_SET', JIEQI_SYSTEM_CHARSET);
}
//允许cache的情况下使用cache(不是系统编码时候也能用cache)
//if(JIEQI_ENABLE_CACHE && JIEQI_CHAR_SET == JIEQI_SYSTEM_CHARSET) define('JIEQI_USE_CACHE', true);
if(JIEQI_ENABLE_CACHE) define('JIEQI_USE_CACHE', true);
else define('JIEQI_USE_CACHE', false);
//设置缓存路径
if(!defined('JIEQI_CACHE_DIR') || JIEQI_CACHE_DIR=='' || strtolower(substr(trim(JIEQI_CACHE_DIR), 0, 12)) == 'memcached://') $tmpvar = JIEQI_ROOT_PATH.'/cache';
elseif(strpos(JIEQI_CACHE_DIR, '/')===false && strpos(JIEQI_CACHE_DIR, '\\')===false) $tmpvar = JIEQI_ROOT_PATH.'/'.JIEQI_CACHE_DIR;
else $tmpvar = JIEQI_CACHE_DIR;
//if(JIEQI_CHAR_SET != JIEQI_SYSTEM_CHARSET) $tmpvar.='/c_'.JIEQI_CHAR_SET;
if(!is_dir($tmpvar)) jieqi_createdir($tmpvar);
define('JIEQI_CACHE_PATH',$tmpvar);
if(!defined('JIEQI_COMPILED_DIR') || JIEQI_COMPILED_DIR=='') define('JIEQI_COMPILED_PATH', JIEQI_ROOT_PATH.'/compiled');
elseif(strpos(JIEQI_COMPILED_DIR, '/')===false && strpos(JIEQI_COMPILED_DIR, '\\')===false) define('JIEQI_COMPILED_PATH', JIEQI_ROOT_PATH.'/'.JIEQI_COMPILED_DIR);
else define('JIEQI_COMPILED_PATH',JIEQI_COMPILED_DIR);
//******************************************************
//页面预处理
//******************************************************
if(isset($_COOKIE[session_name()]) && strlen($_COOKIE[session_name()]) < 16) unset($_COOKIE[session_name()]);
//是否启用页面压缩输出(ob_gzhandler 和 zlib.output_compression 不能同时使用)
if(JIEQI_USE_GZIP && !(boolean)@ini_get('zlib.output_compression')) @ob_start("ob_gzhandler");
//启动session,已经有sessionid的直接调用session,没有的要登录服务器才能创建新的session
//if (!empty($_COOKIE[session_name()]) || (defined('JIEQI_NEED_SESSION') && JIEQI_LOCAL_URL == JIEQI_USER_URL)) {
if (!empty($_COOKIE[session_name()]) || defined('JIEQI_NEED_SESSION')) {
if (JIEQI_SESSION_EXPRIE > 0) @ini_set('session.gc_maxlifetime', JIEQI_SESSION_EXPRIE);
@session_cache_limiter('private, must-revalidate');
//session的数据库保存模式
if(JIEQI_SESSION_STORAGE=='db'){
include_once(JIEQI_ROOT_PATH.'/include/session.php');
$sess_handler =& JieqiSessionHandler::getInstance('JieqiSessionHandler');
//设置session处理函数
@session_set_save_handler(array(&$sess_handler, 'open'), array(&$sess_handler, 'close'), array(&$sess_handler, 'read'), array(&$sess_handler, 'write'), array(&$sess_handler, 'destroy'), array(&$sess_handler, 'gc'));
}else{
if(JIEQI_SESSION_SAVEPATH != '' && is_dir(JIEQI_SESSION_SAVEPATH)) session_save_path(JIEQI_SESSION_SAVEPATH);
}
//设置sessionid
if(!empty($_COOKIE[session_name()])) session_id($_COOKIE[session_name()]);
@session_start();
//用于多服务器的情况,当一台服务器已经登陆,另一台自动登陆
if (!empty($_COOKIE[session_name()]) && !empty($_COOKIE['jieqiUserInfo']) && count($_SESSION)==0){
include_once(JIEQI_ROOT_PATH.'/class/online.php');
$online_handler =& JieqiOnlineHandler::getInstance('JieqiOnlineHandler');
$criteria=new CriteriaCompo(new Criteria('sid', $_COOKIE[session_name()], '='));
$result = $online_handler->queryObjects($criteria);
$srow = $online_handler->getRow($result);
if(!empty($srow['uid'])){
include_once(JIEQI_ROOT_PATH.'/class/users.php');
$users_handler =& JieqiUsersHandler::getInstance('JieqiUsersHandler');
$jieqiUsers=$users_handler->get($srow['uid']);
if(is_object($jieqiUsers)){
jieqi_setusersession($jieqiUsers);
}
}
}
}
//去掉反溢出斜杠
$magic_quotes_gpc = get_magic_quotes_gpc();
$register_globals = @ini_get('register_globals');
if ($magic_quotes_gpc){
$_GET= jieqi_funtoarray('stripslashes',$_GET);
$_POST= jieqi_funtoarray('stripslashes',$_POST);
$_COOKIE= jieqi_funtoarray('stripslashes',$_COOKIE);
}
//网页内容和提交变量转化
$charsetary=array('gb2312'=>'gb', 'gbk'=>'gb', 'gb'=>'gb', 'big5'=>'big5', 'utf-8'=>'utf8', 'utf8'=>'utf8');
if(JIEQI_CHAR_SET != JIEQI_SYSTEM_CHARSET || (!empty($_REQUEST['ajax_request']) && $charsetary[JIEQI_CHAR_SET] != 'utf8')){
include_once(JIEQI_ROOT_PATH.'/include/changecode.php');
}
if(!empty($_REQUEST['ajax_request']) && $charsetary[JIEQI_CHAR_SET] != 'utf8'){
$charset_convert_ajax='jieqi_'.$charsetary['utf8'].'2'.$charsetary[JIEQI_CHAR_SET];
//$_GET=& jieqi_funtoarray($charset_convert_ajax,$_GET);
$_POST=& jieqi_funtoarray($charset_convert_ajax,$_POST);
}
$charset_convert_out='';
if(JIEQI_CHAR_SET != JIEQI_SYSTEM_CHARSET){
$charset_convert_out='jieqi_'.$charsetary[JIEQI_SYSTEM_CHARSET].'2'.$charsetary[JIEQI_CHAR_SET];
if(!defined('JIEQI_NOCONVERT_CHAR')) @ob_start($charset_convert_out);
$charset_convert_in='jieqi_'.$charsetary[JIEQI_CHAR_SET].'2'.$charsetary[JIEQI_SYSTEM_CHARSET];
$_GET=& jieqi_funtoarray($charset_convert_in,$_GET);
$_POST=& jieqi_funtoarray($charset_convert_in,$_POST);
$_COOKIE=& jieqi_funtoarray($charset_convert_in,$_COOKIE);
}
//处理REQUEST的转换
if($magic_quotes_gpc || JIEQI_SYSTEM_CHARSET != JIEQI_CHAR_SET || (!empty($_REQUEST['ajax_request']) && $charsetary[JIEQI_CHAR_SET] != 'utf8')) $_REQUEST=array_merge($_REQUEST, $_GET, $_POST, $_COOKIE);
//最大页数限制
if(defined('JIEQI_MAX_PAGES') && JIEQI_MAX_PAGES > 0 && is_numeric($_REQUEST['page']) && $_REQUEST['page'] > JIEQI_MAX_PAGES) $_REQUEST['page'] = intval(JIEQI_MAX_PAGES);
//******************************************************
//用户预处理
//******************************************************
$jieqiUsersStatus = JIEQI_GROUP_GUEST;
$jieqiUsersGroup = JIEQI_GROUP_GUEST;
$jieqiCache =& jieqi_initcache(); //初始化缓存实例
//自动登录情况
if(empty($_SESSION['jieqiUserId'])){
if(!empty($_REQUEST['jieqi_username']) && !empty($_REQUEST['jieqi_userpassword'])){
//提交登录情况
session_start();
include_once(JIEQI_ROOT_PATH.'/include/checklogin.php');
$urllogin=jieqi_logincheck($_REQUEST['jieqi_username'], $_REQUEST['jieqi_userpassword'], '', false, false, false);
if($urllogin == 0) $_SESSION['jieqiAdminLogin']=1;
//}elseif(!empty($_COOKIE['jieqiUserInfo']) && JIEQI_LOCAL_URL == JIEQI_USER_URL){
}elseif(!empty($_COOKIE['jieqiUserInfo'])){
//使用COOKIE登录
$jieqi_user_info=jieqi_strtosary($_COOKIE['jieqiUserInfo']);
if(!empty($jieqi_user_info['jieqiUserName']) && !empty($jieqi_user_info['jieqiUserPassword'])){
session_start();
include_once(JIEQI_ROOT_PATH.'/include/checklogin.php');
jieqi_logincheck($jieqi_user_info['jieqiUserName'], $jieqi_user_info['jieqiUserPassword'], '', true, true, false);
}
}
}
if(!empty($_SESSION['jieqiUserGroup'])){
$jieqiUsersGroup = $_SESSION['jieqiUserGroup'];
switch($_SESSION['jieqiUserGroup']){
case JIEQI_GROUP_GUEST:
$jieqiUsersStatus = JIEQI_GROUP_GUEST;
break;
case JIEQI_GROUP_ADMIN:
$jieqiUsersStatus = JIEQI_GROUP_ADMIN;
define('JIEQI_IS_ADMIN', 1);
break;
default:
$jieqiUsersStatus = JIEQI_GROUP_USER;
break;
}
}
//网站是否开放
if(defined('JIEQI_IS_OPEN') && JIEQI_IS_OPEN == 0 && !defined('JIEQI_ADMIN_LOGIN') && $jieqiUsersStatus != JIEQI_GROUP_ADMIN){
header('Content-type:text/html;charset='.JIEQI_SYSTEM_CHARSET);
echo JIEQI_CLOSE_INFO;
jieqi_freeresource();
exit;
}elseif(defined('JIEQI_IS_OPEN') && JIEQI_IS_OPEN == 2 && !defined('JIEQI_ADMIN_LOGIN') && $jieqiUsersStatus != JIEQI_GROUP_ADMIN && count($_POST)>0){
//禁止发表
header('Content-type:text/html;charset='.JIEQI_SYSTEM_CHARSET);
echo LANG_DENY_POST;
jieqi_freeresource();
exit;
}
//是否允许代理访问
if(defined('JIEQI_PROXY_DENIED') && JIEQI_PROXY_DENIED != 1){
if($_SERVER['HTTP_X_FORWARDED_FOR'] || $_SERVER['HTTP_VIA'] || $_SERVER['HTTP_PROXY_CONNECTION'] || $_SERVER['HTTP_USER_AGENT_VIA'] || $_SERVER['HTTP_PROXY_CONNECTION']) {
header('Content-type:text/html;charset='.JIEQI_SYSTEM_CHARSET);
echo LANG_DENY_PROXY;
jieqi_freeresource();
exit;
}
}
//DEMO帐号管理界面不准保存数据
/*
if((strstr($_SERVER['PHP_SELF'], '/admin') || basename($_SERVER['PHP_SELF'])=='useredit.php') && !empty($_SESSION['jieqiUserName']) && $_SESSION['jieqiUserName']=='demo'){
if((!empty($_POST) || !empty($_REQUEST['action'])) && basename($_SERVER['PHP_SELF'])!='login.php') jieqi_printfail('对不起,测试帐号不允许保存或修改管理数据!');
}
*/
//程序开始时候的钩子
if(function_exists('jieqi_hooks_global')) jieqi_hooks_global();
//******************************************************
//公共函数
//******************************************************
// ------------------------------------------------------------------------
// 系统相关
// ------------------------------------------------------------------------
/**
* 页面跳转
*
* @param string $url 跳转的url地址
* @param string $title 提示的标题
* @param string $content 提示的内容
* @access public
* @return void
*/
function jieqi_jumppage($url, $title = '', $content = '', $direct = false){
if(empty($_REQUEST['ajax_request'])){
if(!$direct){
if(JIEQI_VERSION_TYPE != '' && JIEQI_VERSION_TYPE != 'Free'){
include_once(JIEQI_ROOT_PATH.'/lib/template/template.php');
$url=jieqi_htmlstr($url);
$title=jieqi_htmlstr($title);
$jieqiTpl =& JieqiTpl::getInstance();
$jieqiTpl->assign(array('jieqi_charset' => JIEQI_CHAR_SET, 'jieqi_themeurl' => JIEQI_URL.'/themes/'.JIEQI_THEME_NAME.'/', 'jieqi_themecss'=> JIEQI_URL.'/themes/'.JIEQI_THEME_NAME.'/style.css', 'pagetitle' => $title, 'title' => $title, 'content' => $content, 'url' => $url));
$jieqiTpl->setCaching(0);
$jieqiTpl->display(JIEQI_ROOT_PATH.'/themes/'.JIEQI_THEME_NAME.'/jumppage.html');
}else{
echo '<html><head><meta http-equiv="content-type" content="text/html; charset='.JIEQI_CHAR_SET.'" /><meta http-equiv="refresh" content="3; url='.$url.'">
<title>'.jieqi_htmlstr($title).'</title><link rel="stylesheet" type="text/css" media="all" href="'.JIEQI_URL.'/themes/'.JIEQI_THEME_NAME.'/style.css" /></head><body><div id="msgboard" style="position:absolute; left:210px; top:150px; width:350px; height:100px; z-index:1;"><table class="grid" width="100%" border="0" cellspacing="1" cellpadding="6" ><caption>'.jieqi_htmlstr($title).'</caption><tr><td class="even"><br />'.$content.'<br /><br />如不能自动跳转,<a href="'.$url.'">点击这里直接进入!</a><br /><br />程序设计:<a href="http://www.jieqi.com" target="_blank">杰奇网络</a><br /><br /></td></tr></table></div></body></html>';
}
}else{
//不显示跳转页面
if(empty($title) && empty($content) && !headers_sent()){
header('Location: '.$url);
}else{
echo $title.$content.'<script language="JavaScript" type="text/javascript">window.location=\''.$url.'\';</script>';
}
}
}else{
header('Content-Type:text/html; charset='.JIEQI_CHAR_SET);
header("Cache-Control:no-cache");
return $url;
}
jieqi_freeresource();
exit;
}
/**
* 返回提示消息框的html代码
*
* @param string $title 提示的标题
* @param string $content 提示的内容
* @access public
* @return string 返回html代码
*/
function jieqi_msgbox($title, $content){
if(empty($_REQUEST['ajax_request'])){
include_once(JIEQI_ROOT_PATH.'/lib/template/template.php');
$title=jieqi_htmlstr($title);
$jieqiTpl =& JieqiTpl::getInstance();
$jieqiTpl->assign(array('title' => $title, 'content' => $content));
$jieqiTpl->setCaching(0);
return $jieqiTpl->fetch(JIEQI_ROOT_PATH.'/themes/'.JIEQI_THEME_NAME.'/msgbox.html');
}else{
header('Content-Type:text/html; charset='.JIEQI_CHAR_SET);
header("Cache-Control:no-cache");
return $content;
}
}
/**
* 显示提示信息(完整的html页面)
*
* @param string $title 提示的标题
* @param string $content 提示的内容
* @access public
* @return void
*/
function jieqi_msgwin($title, $content){
if(defined('JIEQI_NOCONVERT_CHAR') && !empty($GLOBALS['charset_convert_out'])) @ob_start($GLOBALS['charset_convert_out']);
if(empty($_REQUEST['ajax_request'])){
include_once(JIEQI_ROOT_PATH.'/lib/template/template.php');
$title=jieqi_htmlstr($title);
$jieqiTpl =& JieqiTpl::getInstance();
$jieqiTpl->assign(array('jieqi_charset' => JIEQI_CHAR_SET, 'jieqi_themeurl' => JIEQI_URL.'/themes/'.JIEQI_THEME_NAME.'/', 'jieqi_themecss'=> JIEQI_URL.'/themes/'.JIEQI_THEME_NAME.'/style.css', 'title' => $title, 'content' => $content, 'jieqi_sitename' => JIEQI_SITE_NAME));
$jieqiTpl->setCaching(0);
$jieqiTpl->display(JIEQI_ROOT_PATH.'/themes/'.JIEQI_THEME_NAME.'/msgwin.html');
}else{
header('Content-Type:text/html; charset='.JIEQI_CHAR_SET);
header("Cache-Control:no-cache");
echo $content;
}
jieqi_freeresource();
exit;
}
/**
* 显示错误信息(完整页面)
*
* @param string $errorinfo 错误信息的html代码
* @access public
* @return void
*/
function jieqi_printfail($errorinfo){
if(defined('JIEQI_NOCONVERT_CHAR') && !empty($GLOBALS['charset_convert_out'])) @ob_start($GLOBALS['charset_convert_out']);
$debuginfo='';
if(defined('JIEQI_DEBUG_MODE') && JIEQI_DEBUG_MODE > 0){
$trace = debug_backtrace();
$debuginfo='FILE: '.jieqi_htmlstr($trace[0]['file']).' LINE:'.jieqi_htmlstr($trace[0]['line']);
}
if(empty($_REQUEST['ajax_request'])){
include_once(JIEQI_ROOT_PATH.'/lib/template/template.php');
$jieqiTpl =& JieqiTpl::getInstance();
$jieqiTpl->assign(array('jieqi_charset' => JIEQI_CHAR_SET, 'jieqi_themeurl' => JIEQI_URL.'/themes/'.JIEQI_THEME_NAME.'/', 'jieqi_themecss'=> JIEQI_URL.'/themes/'.JIEQI_THEME_NAME.'/style.css', 'errorinfo' => $errorinfo, 'debuginfo' => $debuginfo, 'jieqi_sitename' => JIEQI_SITE_NAME));
$jieqiTpl->setCaching(0);
$jieqiTpl->display(JIEQI_ROOT_PATH.'/themes/'.JIEQI_THEME_NAME.'/msgerr.html');
}else{
header('Content-Type:text/html; charset='.JIEQI_CHAR_SET);
header("Cache-Control:no-cache");
echo $errorinfo;
}
jieqi_freeresource();
exit;
}
/**
* 取得用户ip地址
*
* @param void
* @access public
* @return string 当前访问者的ip
*/
function jieqi_userip(){
if(isset($_SERVER['HTTP_CLIENT_IP'])) $ip=$_SERVER['HTTP_CLIENT_IP'];
elseif(isset($_SERVER['HTTP_X_FORWARDED_FOR'])) $ip=$_SERVER['HTTP_X_FORWARDED_FOR'];
else $ip=$_SERVER['REMOTE_ADDR'];
$ip=trim($ip);
if(!is_numeric(str_replace('.','',$ip))) $ip='';
return $ip;
}
/**
* 根据id取得文件保存的子目录
*
* @param int $id
* @access public
* @return string 返回子目录
*/
function jieqi_getsubdir($id, $divnum = 1000){
return '/'.floor(intval($id) / $divnum);
}
/**
* 根据记录id获得访问该记录的url地址
*
* 本函数是调用另外一个函数来处理url地址,前面两个参数是必要的,后面参数是具体处理函数里面使用
*
* @param string $module 函数所属模块名
* @param string $target 处理对象,用来组成函数名的 'jieqi_url_'.$module.'_'.$target
* @access public
* @return string 返回url字符串
*/
function jieqi_geturl($module, $target){
global $jieqiModules;
if(!isset($jieqiModules[$module])) $module = 'system';
$funname = 'jieqi_url_'.$module.'_'.$target;
if(!function_exists($funname) && isset($jieqiModules[$module]['path']) && is_file($jieqiModules[$module]['path'].'/include/funurl.php')) include_once($jieqiModules[$module]['path'].'/include/funurl.php');
if(function_exists($funname)){
$numargs = func_num_args();
$args = func_get_args();
switch($numargs){
case 0:
case 1:
case 2:
return $funname();
break;
case 3:
return $funname($args[2]);
break;
case 4:
return $funname($args[2], $args[3]);
break;
case 5:
return $funname($args[2], $args[3], $args[4]);
break;
case 6:
default:
return $funname($args[2], $args[3], $args[4], $args[5]);
break;
}
}else{
return false;
}
}
/**
* 取得上传文件目录路径
*
* @param string $path 保存上传文件的目录名或者完整的路径名称
* @param string $module 模块名称,留空表示当前模块
* @param string $systempath 系统根路径,留空则自动获取
* @access public
* @return string
*/
function jieqi_uploadpath($path, $module='', $systempath=''){
if(strpos($path, '/')===false && strpos($path, '\\')===false){
if($module=='' && defined('JIEQI_MODULE_NAME')) $module=JIEQI_MODULE_NAME;
if($systempath=='') $systempath=JIEQI_ROOT_PATH;
if($path=='') return $systempath.'/files/'.$module;
else return $systempath.'/files/'.$module.'/'.$path;
}else{
return $path;
}
}
/**
* 取得上传文件目录URL
*
* @param string $path 保存上传文件的目录名或者完整的路径名称
* @param string $url 自定义的url地址
* @param string $module 模块名称,留空表示当前模块
* @param string $systempath 系统根路径,留空则自动获取
* @access public
* @return string
*/
function jieqi_uploadurl($path, $url='', $module='', $systemurl=''){
if(!empty($url)){
return $url;
}else{
if($module=='' && defined('JIEQI_MODULE_NAME')) $module=JIEQI_MODULE_NAME;
if($systemurl=='') $systemurl=JIEQI_URL;
elseif(strpos($systemurl,'/modules') > 0) $systemurl=substr($systemurl,0,strpos($systemurl,'/modules'));
if($path=='') return $systemurl.'/files/'.$module;
else return $systemurl.'/files/'.$module.'/'.$path;
}
}
/**
* 检查用户权限
*
* @param array $powerset 需要的权限数组
* @param int $ustatus 用户状态
* @param int $ugroup 用户组
* @param bool $isreturn 是否返回检查结果,默认不返回,表示检查不通过直接提示
* @param bool $isadmin 是否检查后台权限,默认否
* @access public
* @return bool
*/
function jieqi_checkpower($powerset=array(), $ustatus='0', $ugroup='0', $isreturn=false, $isadmin=false){
if(empty($_POST)){
$local_domain_url=(empty($_SERVER['HTTP_HOST'])) ? '' : 'http://'.$_SERVER['HTTP_HOST'];
$jumpurl=$local_domain_url.jieqi_addurlvars(array());
}elseif(!empty($_SERVER['HTTP_REFERER'])){
$jumpurl=$_SERVER['HTTP_REFERER'];
}else{
$jumpurl=JIEQI_MAIN_URL;
}
if((!isset($_SESSION['jieqiAdminLogin']) || $_SESSION['jieqiAdminLogin'] != 1) && !empty($_COOKIE['jieqiOnlineInfo'])){
$jieqi_online_info = jieqi_strtosary($_COOKIE['jieqiOnlineInfo']);
if($jieqi_online_info['jieqiAdminLogin'] == 1) $_SESSION['jieqiAdminLogin'] = 1;
}
if($ustatus==JIEQI_GROUP_ADMIN){
if($isadmin && empty($_SESSION['jieqiAdminLogin'])){
if($isreturn){
return false;
}else{
header('Location: '.JIEQI_LOCAL_URL.'/admin/login.php?jumpurl='.urlencode($jumpurl));
exit;
}
}else{
return true;
}
}else{
if(is_array($powerset['groups']) && (in_array($ugroup, $powerset['groups'], false) || in_array('0',$powerset['groups'],false))){
if($isadmin && empty($_SESSION['jieqiAdminLogin'])){
if($isreturn){
return false;
}else{
header('Location: '.JIEQI_LOCAL_URL.'/admin/login.php?jumpurl='.urlencode($jumpurl));
exit;
}
}else{
return true;
}
}else{
if($isreturn){
return false;
}else{
if($ugroup==JIEQI_GROUP_GUEST){
if($isadmin){
header('Location: '.JIEQI_USER_URL.'/admin/login.php?jumpurl='.urlencode($jumpurl));
}else{
header('Location: '.JIEQI_USER_URL.'/login.php?jumpurl='.urlencode($jumpurl));
}
exit;
}else{
jieqi_printfail(LANG_NO_PERMISSION);
}
}
}
}
}
/**
* 检查用户是否已登陆
*
* @param bool $isreturn 是否返回检查结果,默认不返回,表示检查不通过直接提示
* @param bool $isadmin 是否检查后台权限,默认否
* @access public
* @return bool 已登录返回true,未登录返回false
*/
function jieqi_checklogin($isreturn=false, $isadmin=false){
global $jieqiUsersGroup;
if($jieqiUsersGroup==JIEQI_GROUP_GUEST) $ret=false;
else $ret=true;
if($isreturn) return $ret;
elseif(!$ret){
if(empty($_REQUEST['ajax_request'])){
if(empty($_POST)){
$local_domain_url=(empty($_SERVER['HTTP_HOST'])) ? '' : 'http://'.$_SERVER['HTTP_HOST'];
$jumpurl=$local_domain_url.jieqi_addurlvars(array());
}elseif(!empty($_SERVER['HTTP_REFERER'])){
$jumpurl=$_SERVER['HTTP_REFERER'];
}else{
$jumpurl=JIEQI_MAIN_URL;
}
if($isadmin) header('Location: '.JIEQI_USER_URL.'/admin/login.php?jumpurl='.urlencode($jumpurl));
else header('Location: '.JIEQI_USER_URL.'/login.php?jumpurl='.urlencode($jumpurl));
}else{
header('Content-Type:text/html; charset='.JIEQI_CHAR_SET);
header("Cache-Control:no-cache");
echo LANG_NEED_LOGIN;
}
exit;
}
}
/**
* 用户相关处理
*
* @param string $action 处理类型
* @param array $params 参数数组
* @access public
* @return void
*/
function jieqi_useraction($action, &$params){
include_once(JIEQI_ROOT_PATH.'/include/useraction.php');
$fname = 'jieqi_user_'.$action;
if(function_exists('jieqi_user_'.$action)) $fname($params);
}
/**
* 保存用户SESSION
*
* @param object $user 用户表记录对象
* @access public
* @return void
*/
function jieqi_setusersession($user){
global $jieqiHonors;
global $jieqiModules;
$_SESSION = array();
$_SESSION['jieqiUserId'] = $user->getVar('uid', 'n');
$_SESSION['jieqiUserUname'] = $user->getVar('uname', 'n');
$_SESSION['jieqiUserName'] = (strlen($user->getVar('name', 'n')) > 0) ? $user->getVar('name', 'n') : $user->getVar('uname', 'n');
$_SESSION['jieqiUserGroup'] = $user->getVar('groupid', 'n');
$_SESSION['jieqiUserEmail'] = $user->getVar('email', 'n');
$_SESSION['jieqiUserAvatar'] = $user->getVar('avatar', 'n');
$_SESSION['jieqiUserScore'] = $user->getVar('score', 'n');
$_SESSION['jieqiUserExperience'] = $user->getVar('experience', 'n');
$_SESSION['jieqiUserVip'] = $user->getVar('isvip', 'n');
$_SESSION['jieqiUserEgold'] = ($user->getVar('egold', 'n')>0 || $user->getVar('esilver', 'n')>0) ? 1 : 0;
jieqi_getconfigs('system', 'honors'); //头衔
$honorid=intval(jieqi_gethonorid($user->getVar('score'), $jieqiHonors));
$_SESSION['jieqiUserHonorid'] = $honorid;
$_SESSION['jieqiUserHonor'] = isset($jieqiHonors[$honorid]['name'][intval($user->getVar('workid', 'n'))]) ? $jieqiHonors[$honorid]['name'][intval($user->getVar('workid', 'n'))] : $jieqiHonors[$honorid]['caption'];
if(!empty($jieqiModules['badge']['publish'])){
$_SESSION['jieqiUserBadges'] = $user->getVar('badges', 'n'); //徽章
}
$_SESSION['jieqiUserSet'] = unserialize($user->getVar('setting','n'));
}
/**
* 增加当前url参数
*
* @param array $varary 需要增加的变量数组
* @param bool $addget 是否自动增加GET参数,默认是
* @param bool $addpost 是否自动增加POST参数,默认否
* @param array $filter 过滤哪些参数名
* @access public
* @return string
*/
function jieqi_addurlvars($varary, $addget=true, $addpost=false, $filter=''){
global $charset_convert_out;
if(!empty($_SERVER['PHP_SELF'])) $ret=$_SERVER['PHP_SELF'];
elseif(!empty($_SERVER['SCRIPT_NAME']) && substr($_SERVER['SCRIPT_NAME'],-4)=='.php') $ret=$_SERVER['SCRIPT_NAME'];
else $ret='';
$start=0;
if(!is_array($filter)) $filter=array();
if($addget){
foreach($_GET as $k=>$v){
if (!array_key_exists($k, $varary) && !in_array($k, $filter) && is_string($v)){
if(!empty($charset_convert_out)) $v = $charset_convert_out($v);
$ret.=($start++ > 0) ? '&'.$k.'='.urlencode($v) : '?'.$k.'='.urlencode($v);
}
}
}
if($addpost){
foreach($_POST as $k=>$v){
if (!array_key_exists($k, $varary) && !in_array($k, $filter) && is_string($v)){
if(!empty($charset_convert_out)) $v = $charset_convert_out($v);
$ret.=($start++ > 0) ? '&'.$k.'='.urlencode($v) : '?'.$k.'='.urlencode($v);
}
}
}
if(is_array($varary)){
foreach($varary as $k=>$v){
$ret.=($start++ > 0) ? '&'.$k.'='.$v : '?'.$k.'='.$v;
}
}
return $ret;
}
/**
* 包含数据库类
*
* @param void
* @access public
* @return void
*/
function jieqi_includedb(){
if(!defined('JIEQI_DBCLASS_INCLUDE')){
include_once(JIEQI_ROOT_PATH.'/lib/database/database.php');
define('JIEQI_DBCLASS_INCLUDE', true);
}
}
/**
* 关闭数据库连接
*
* @param void
* @access public
* @return void
*/
function jieqi_closedb($db = NULL){
if(defined('JIEQI_DB_CONNECTED') && !defined('JIEQI_DB_NOTCLOSE') && JIEQI_DB_PCONNECT == false) JieqiDatabase::close($db);
}
/**
* 关闭ftp连接
*
* @param void
* @access public
* @return void
*/
function jieqi_closeftp($ftp = NULL){
if(defined('JIEQI_FTP_CONNECTED') && !defined('JIEQI_FTP_NOTCLOSE')) JieqiFTP::close($ftp);
}
/**
* 初始化缓存,包含缓存类并返回缓存实例
*
* @param object $jieqiCache
* @access public
* @return bool
*/
function &jieqi_initcache(){
if(strtolower(substr(trim(JIEQI_CACHE_DIR), 0, 12)) != 'memcached://'){
$jieqiCache =& JieqiCache::getInstance('file');
}else{
$params = @parse_url(trim(JIEQI_CACHE_DIR));
$jieqiCache =& JieqiCache::getInstance('memcached', array('host'=>strval($params['host']), 'port'=>intval($params['port'])));
}
return $jieqiCache;
}
/**
* 关闭memcached连接
*
* @param void
* @access public
* @return void
*/
function jieqi_closecache($cache = NULL){
if(defined('JIEQI_CACHE_CONNECTED') && !defined('JIEQI_CACHE_NOTCLOSE')) JieqiCache::close($cache);
}
/**
* 释放占用的资源(如数据库链接,ftp链接,其他远程服务等)
*
* @param void
* @access public
* @return void
*/
function jieqi_freeresource(){
jieqi_closedb();
jieqi_closeftp();
jieqi_closecache();
}
/**
* 载入语言包
*
* @param string $fname 语言包文件名,不带后缀
* @param string $module 模块名,默认是 'system'
* @access public
* @return bool 成功返回true,失败返回false
*/
function jieqi_loadlang($fname, $module='system'){
global $jieqiLang;
global $jieqiModules;
if(empty($jieqiLang[$module][$fname])){
if($module=='system' || $module=='') $file=JIEQI_ROOT_PATH.'/lang/lang_'.$fname.'.php';
else $file=$jieqiModules[$module]['path'].'/lang/lang_'.$fname.'.php';
$file = @realpath($file);
if (is_file($file) && preg_match('/\.php$/i', $file)){
include_once($file);
return true;
}else return false;
}
}
/**
* 根据积分获得用户头衔ID
*
* @param int $userscore 用户积分
* @param array $jieqiHonors 头衔设置数组
* @access public
* @return int
*/
function jieqi_gethonorid($userscore=0, $jieqiHonors=array()){
if(is_array($jieqiHonors)){
foreach($jieqiHonors as $k=>$v){
if($userscore >= $v['minscore'] && $userscore < $v['maxscore']) return $k;
}
}
return false;
}
// ------------------------------------------------------------------------
// 字符串处理
// ------------------------------------------------------------------------
/**
* 把字符串转换为htm格式
*
* @param string $str 输入的字符串
* @param int $quote_style 转换标志,默认ENT_QUOTES表示转换单引号
* @access public
* @return string
*/
function jieqi_htmlstr($str, $quote_style=ENT_QUOTES){
$str = htmlspecialchars($str, $quote_style);
$str = nl2br($str);
$str = str_replace(" ", " ", $str);
$str = preg_replace("/&#(\d+);/isU", "&#\\1;", $str);
return $str;
}
/**
* 字符串截取函数,适应中文(适应gbk、big5、utf-8)
*
* @param string $str 原始字符串
* @param int $start 开始位置
* @param int $length 截取长度
* @param string $trimmarker 附加字符串
* @access public
* @return string
*/
function jieqi_substr($str, $start, $length, $trimmarker = '...'){
$length = $length - strlen($trimmarker);
$len = strlen($str);
$ret = '';
$i = 0; //字符串数组指针
$j = 0; //实际显示的长度指针
$l = 0; //截取的字符串显示长度
$utf8 = JIEQI_SYSTEM_CHARSET == 'utf-8' ? true : false;
while($i < $len && $l < $length){
$cs = 1; //一个字有几个字节
$cl = 1; //一个字相当于几个字节长度
$asc = ord($str[$i]);
if ($asc > 0x80){
if(!$utf8){
$cs = 2;
$cl = 2;
}else{
if($asc >= 192 && $asc <= 223){
$cs = 2;
$cl = 2;
}elseif($asc >= 224 && $asc <= 239){
$cs = 3;
$cl = 2;
}elseif($asc >= 240 && $asc <= 247){
$cs = 4;
$cl = 2;
}
}
}
if($j >= $start){
$ret .= substr($str, $i, $cs);
$l += $cl;
}
$i += $cs;
$j += $cl;
}
if($i < $len) $ret.= $trimmarker;
return $ret;
}
/**
* 将字符串的函数应用到整个数组,即把数组里面所有字符串用某个函数处理一遍
*
* @param string $funname 函数名
* @param array $ary 字符串数组
* @access public
* @return array
*/
function jieqi_funtoarray($funname, $ary){
if (is_array($ary)){
foreach($ary as $k=>$v){