/
frame.php
executable file
·454 lines (419 loc) · 12.4 KB
/
frame.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
<?php
define("CURRENT_DIR", dirname(__FILE__) ."/");
define("ROOT_DIR_NONE", dirname(__FILE__));
define("ROOT_DIR",CURRENT_DIR);
define("FRAME_VERSION",'1.0');
define("FRAME_ROOT", dirname(__FILE__));
require('config/config.php');
include_once(CURRENT_DIR ."lib/pubfun.php");
include_once(CURRENT_DIR ."lib/article_fun.php");
include_once(CURRENT_DIR ."lib/table_class.php");
include_once(CURRENT_DIR ."lib/category_class.php");
include_once(CURRENT_DIR ."lib/table_images_class.php");
include_once(CURRENT_DIR ."lib/upload_file_class.php");
require_once CURRENT_DIR ."lib/image_handler_class.php";
if(file_exists(ROOT_DIR ."inc/project_pubfun.php")){
require_once CURRENT_DIR ."inc/project_pubfun.php";
}
function __autoload($class_name){
if(file_exists(ROOT_DIR .'lib/' . $class_name .'.class.php')){
require_once ROOT_DIR .'lib/' . $class_name .'.class.php';
return ;
}
if(file_exists(ROOT_DIR .'inc/' . $class_name .'.class.php')){
require_once ROOT_DIR .'inc/' . $class_name .'.class.php';
return ;
}
if(file_exists(ROOT_DIR .'inc/active_record/' . $class_name .'.class.php')){
require_once ROOT_DIR .'inc/active_record/' . $class_name .'.class.php';
return ;
}
}
function get_config($var,$path=''){
if(empty($path)){$path = LIB_PATH .'../config/config.php';}
include_once($path);
global $$var;
return $$var;
}
function &get_db() {
global $g_db;
if(!is_object($g_db)){
#if(get_config('db_type') == 'mssql'){
# $g_db = new database_connection_mssql_class();
#}else
#{
$g_db = new DataBase();
#}
}
if($g_db->connected) return $g_db;
$servername = get_config('db_server_name');
$dbname = get_config('db_database_name');
$username = get_config('db_user_name');
$password = get_config('db_password');
$code = get_config('db_code');
$note_emails = "chenlong@xun-ao.com, sunyoujie@xun-ao.com, shengzhifeng@xun-ao.com, zhanghao@xun-ao.com";
if($g_db->connect($servername,$dbname,$username,$password,$code)===false){
$last_time = file_get_contents(dirname(__FILE__) .'/config/last_disconnect.txt');
if($last_time == ''){
write_to_file(dirname(__FILE__) .'/config/last_disconnect.txt',now(),'w');
@mail($note_emails,'数据库连接失败','主备数据库均无法连接,请立即检查'.$this->servername);
}
/*
$servername = get_config('db_server_name_bak');
$dbname = get_config('db_database_name_bak');
$username = get_config('db_user_name_bak');
$password = get_config('db_password_bak');
$code = get_config('db_code_bak');
if($g_db->connect($servername,$dbname,$username,$password,$code)===false){
}
*/
};
return $g_db;
}
function get_ad_db(){
global $g_ad_server_name;
global $g_ad_user_name;
global $g_ad_password;
global $g_ad_database_name;
global $g_ad_db;
if(is_resource($g_ad_db)){
return $g_ad_db;
}
$g_ad_db = new DataBase();
$g_ad_db->connect($g_ad_server_name,$g_ad_database_name,$g_ad_user_name,$g_ad_password,$g_ad_code);
return $g_ad_db;
}
function close_db() {
$db = &get_db();
$db->close();
}
function use_jquery(){
js_include_once_tag('jquery');
}
function use_jquery_ui(){
js_include_once_tag('jquery');
js_include_once_tag('jquery-ui');
css_include_tag('jquery_ui');
}
function validate_form($form_name) {
js_include_once_tag('jquery');
js_include_once_tag('jquery.validate');
?>
<script>
$(function(){
$("#<?php echo $form_name;?>").validate();
});
</script>
<?php
}
function js_include_tag($js){
if (func_num_args()>1) {
foreach (func_get_args() as $v){
js_include_tag($v);
}
return ;
}
$js = _get_js_file($js);
echo '<script type="text/javascript" language="javascript" src="' .$js .'"></script>';
}
function _get_js_file($js){
if (strtolower($js) == "default") {
return ROOT_PATH ."javascript/jquery.js";
}else {
$ljs = strtolower($js);
if (strpos($ljs, "http://") !== false || strpos($ljs,"www.") !== false) {
return $js;
}else {
if (substr($ljs,-3) == ".js"){$js = substr_replace($js,"",-3);}
return ROOT_PATH ."javascript/" .$js .".js";
}
}
}
#only include once
function js_include_once_tag($js){
global $loaded_js;
if (empty($loaded_js)){
$loaded_js = array();
}
if (func_num_args()>1) {
foreach (func_get_args() as $v){
js_include_once_tag($v);
}
return ;
}
$js_name = _get_js_file($js);
if (in_array($js_name,$loaded_js,false)) {
return ;
}else {
$loaded_js[] = $js_name;
js_include_tag($js);
}
}
function css_include_tag($filename){
if (func_num_args()>1) {
foreach (func_get_args() as $v){
css_include_tag($v);
}
return ;
}
$css_name = _get_css_file($filename);
echo '<link href="' .$css_name .'" rel="stylesheet" type="text/css">';
}
function _get_css_file($filename){
$ljs = strtolower($filename);
if (strpos($ljs, "http://") !== false || strpos($ljs,"www.") !== false) {
return $ljs;
}else {
if (substr($ljs,-4) == ".css"){$filename = substr_replace($filename,"",-4);}
$ljs = ROOT_PATH ."css/" .$filename .".css";
}
return $ljs;
}
function css_include_once_tag($filename){
global $loaded_css;
if (empty($loaded_css)){
$loaded_css = array();
}
if (func_num_args()>1) {
foreach (func_get_args() as $v){
css_include_once_tag($v);
}
return ;
}
$f = _get_css_file($filename);
if (in_array($f,$loaded_css,false)) {
return ;
}else {
$loaded_css[] = $f;
css_include_tag($filename);
}
}
function judge_role(){
return require_role('admin');
}
function show_fckeditor($name,$toolbarset='Admin',$expand_toolbar=true,$height="200",$value="",$width = null) {
include_once(ROOT_DIR . 'ckeditor/ckeditor_php5.php');
include_once(ROOT_DIR . 'ckfinder/ckfinder.php');
$editor = new CKEditor(ROOT_DIR . 'ckeditor');
$editor->config['toolbar'] = $toolbarset;
$editor->config['toolbarStartupExpanded'] = $expand_toolbar;
$editor->config['height'] = $height;
CKFinder::SetupCKEditor($editor, '/ckfinder/');
if($width){
$editor->config['width'] = $width;
}
$editor->editor($name,$value);
}
function get_page_url($url,$page,$token,$type='normal'){
switch ($type){
case 'normal':
strpos($url, '?') === false && $url .= "?";
$query = $_SERVER['QUERY_STRING'];
$pattern = '/(&?' .$token.'=\d*)/';
$query = preg_replace($pattern, '', $query);
$query = $query ? $query ."&".$token ."={$page}" : $token ."={$page}" ;
return substr($url, -1)=='?' ? $url ."{$query}" : $url ."&{$query}" ;
break;
case 'fake_static': //伪静态方式,在url后添加/page/2方式;
$pattern = '/\/'.$token .'\/\d*\/?$/';
$url = preg_replace($pattern, '',$url);
return $url ."/". $token ."/{$page}";
break;
case 'static': //静态方式,类似00213_2.shtml
$pattern = '/(\.[^\/]*)$/';
$ret = $page == 1 ? $url :preg_replace($pattern, "_$page$1", $url);
return $ret;
break;
default:
break;
}
}
function paginate($url="",$ajax_dom=null,$page_var="page",$force_show = false,$type='normal',$show_type=1)
{
global $page_type;
$pageindextoken = empty($page_var) ? "page" : $page_var;
$record_count_token = $pageindextoken . "_record_count";
$pagecounttoken = $pageindextoken . "_page_count";
global $$pagecounttoken;
global $$record_count_token;
$pageindex = isset($_REQUEST[$pageindextoken]) ? $_REQUEST[$pageindextoken] : 1;
$pagecount = isset($_REQUEST[$pagecounttoken]) ? $_REQUEST[$pagecounttoken] : $$pagecounttoken;
if ($pagecount <= 1 && !$force_show) return;
if(empty($url)){
$url = $_SERVER['PHP_SELF'] ."?";
}
$pagefirst = get_page_url($url, 1, $page_var,$type);
$pagenext = get_page_url($url, $pageindex + 1, $page_var,$type);
$pageprev = get_page_url($url, $pageindex-1, $page_var,$type);
$pagelast = get_page_url($url, $pagecount, $page_var,$type);
if($show_type==1){
if ($pageindex == 1)
{?>
<span>[首页]</span>
<span>[上页]</span>
<?php
if($pagecount > 1){
?>
<span><a class="paginate_link" href="<?php echo $pagenext; ?>">[下页]</a></span>
<span><a class="paginate_link" href="<?php echo $pagelast; ?>">[尾页]</a></span>
<?php }else{?>
<span>[下页]</span>
<span>[尾页]</span>
<?php
}
}
if ($pageindex < $pagecount && $pageindex > 1 )
{?>
<span><a class="paginate_link" href="<?php echo $pagefirst; ?>">[首页]</a></span>
<span><a class="paginate_link" href="<?php echo $pageprev; ?>">[上页]</a></span>
<span><a class="paginate_link" href="<?php echo $pagenext; ?>">[下页]</a></span>
<span><a class="paginate_link" href="<?php echo $pagelast; ?>">[尾页]</a></span>
<?php
}
if ($pageindex == $pagecount && $pageindex != 1)
{?>
<span><a class="paginate_link" href="<?php echo $pagefirst; ?>">[首页]</a></span>
<span><a class="paginate_link" href="<?php echo $pageprev; ?>">[上页]</a></span>
<span>[下页]</span>
<span>[尾页]</span>
<?php
}
?>共找到<?php echo $$record_count_token; ?>条记录
当前第<select name="pageselect" class="pageselect">
<?php
//产生所有页面链接
for($i=1;$i<=$pagecount;$i++){
$ourl = get_page_url($url, $i, $page_var,$type);
?>
<option <?php if($pageindex== $i) echo 'selected="selected"';?> value="<?php echo $ourl;?>" ><?php echo $i;?></option>
<?php
}
?>
</select>页 共<?php echo $pagecount;?>页
<script>
$('.pageselect').change(function(){
var ourl = $(this).val();
<?php
if($ajax_dom){
echo "$('#{$ajax_dom}').load(ourl)";
}else{
echo "window.location.href=ourl;";
}
?>
});
</script>
<?php
if(!empty($ajax_dom)){
?>
<script>
$(".paginate_link").click(function(e){
e.preventDefault();
$("#<?php echo $ajax_dom;?>").load($(this).attr('href'));
});
</script>
<?php
}
}else if($show_type==2){
//文章翻页样式,只有上页 下页 和中间的
if($pageindex == 1){
echo "<span class='paginate_botton'>上页</span>";
}else {
$turl = get_page_url($url, $pageindex-1, $page_var,$type);
echo "<span class='paginate_botton'><a href='$turl'>上页</a></span>";
}
for($i=1;$i<=$pagecount;$i++){
if($i==$pageindex){
echo "<span class='page_span2'>{$i}</span>";
}else{
$turl = get_page_url($url, $i, $page_var,$type);
echo "<span class='page_span'><a href='$turl'>$i</a></span>";
}
}
if($pageindex == $pagecount){
echo "<span class='paginate_botton'>下页</span>";
}else {
$turl = get_page_url($url, $pageindex+1, $page_var,$type);
echo "<span class='paginate_botton'><a href='$turl'>下页</a></span>";
}
}
}
function redirect_login($type='js',$referer=true){
$url = '/login/login.php';
if($referer){
$url .= '?last_url=' .get_current_url();
}
redirect($url,$type);
}
function require_role($role='member'){
if(empty($_SESSION[role_name])){
redirect_login();
die();
}
}
function role_name(){
return $_SESSION[role_name];
};
function has_right($right_name){
return @in_array($right_name,$_SESSION['admin_menu_rights']) || @in_array($right_name,$_SESSION['admin_system_rights']);
}
function role_include($file, $role='member'){
if ($_SESSION['role_name'] == $role){
include($file);
}
}
function require_login($type="redirect"){
if($_COOKIE['cache_name']){
return true;
}
if($type == 'redirect'){
$url = '/login/?last_url=' . get_current_url();
redirect($url);
}else{
return false;
}
}
function search_content($key,$table_name,$conditions=null,$page_count = 10, $order='',$full_text=false){
$db = get_db();
if($key){
$change = array('('=>'\(',')' => '\)');
strtr($key,$change);
$key = str_replace(' ', ' ', $key);
$key = str_replace(',', ' ', $key);
$key = explode(' ',$key);
$len = count($key);
for($i=0;$i<$len;$i++){
$key[$i] = "({$key[$i]})+";
}
$key = implode('|',$key);
}
$sql = "select * from {$table_name} where 1=1 ";
if($conditions){
$sql .= " and {$conditions}";
}
if($key){
$sql .= " and (title regexp '{$key}' or short_title regexp '{$key}' or keywords regexp '{$key}'";
if($full_text){
$sql .= " or content regexp '{$key}'";
}
$sql .= ")";
}
if( $order ){
$sql .= " order by " .$order;
}
if($page_count > 0){
return $db->paginate($sql,$page_count);
}else{
return $db->query($sql);
}
}
function write_log($msg){
global $g_log_dir;
if(empty($g_log_dir)){
return;
}
if(is_dir($g_log_dir) === false) return ;
$file = $g_log_dir .substr(now(),0,10) .".log";
$msg = now() . ": " .$msg .chr(13).chr(10);
write_to_file($file,$msg);
}
?>