给PHPCMS V9 增加关闭网站功能
来源:互联网 发布:数据库软件市场份额 编辑:程序博客网 时间:2024/05/21 09:00
\phpcms\modules\admin\templates\setting.tpl.php:在代码- <div id="div_setting_1" class="contentList pad-10">
- <table width="100%" class="table_form">
复制代码 后面另起一行,添加代码:- <!-- Admpub: -->
- <tr>
- <th width="120">网站状态</th>
- <td class="y-bg"><input name="setconfig[website_is_closed]" value="2" type="radio"<?php echo ($website_is_closed==2) ? ' checked="checked"' : '';?> /> 仅供管理员访问<!-- Only admin -->
- <input name="setconfig[website_is_closed]" value="1" type="radio"<?php echo ($website_is_closed==1) ? ' checked="checked"' : '';?> /> 禁止所有人访问<!-- Ban all -->
- <input name="setconfig[website_is_closed]" value="0" type="radio" <?php echo (!$website_is_closed) ? ' checked="checked"' : '';?> /> 允许所有人访问<!-- Open to all --></td>
- </tr>
- <tr>
- <th width="120">关站提示信息</th>
- <td class="y-bg"><textarea rows="2" cols="20" id="tips" style="height:40px; width:80%" name="setconfig[off_site_because]"><?php echo htmlspecialchars($off_site_because);?></textarea> 支持HTML标签</td>
- </tr>
- <!-- /Admpub -->
复制代码 \phpcms\modules\admin\functions\global.func.php:在set_config()函数中,在代码后面添加:- /*[SWH|+]:*/'website_is_closed','off_site_because',/*[SWH|+];*/
复制代码 \phpcms\modules\admin\setting.php:在代码- set_config($_POST['setconfig']);
复制代码 前面另起一行,添加代码:- //[SWH|+]:
- if(!empty($_POST['setconfig']['website_is_closed'])){
- $str='<!DOCTYPE HTML><html><head><meta http-equiv="Content-Type" content="text/html; charset='.CHARSET.'" /><meta http-equiv="refresh" content="1;url=index.php" /><title></title></head><body></body></html>';
- if(pc_base::load_config('system','lock_ex')){
- file_put_contents(PHPCMS_PATH.'index.html', $str, LOCK_EX);
- }else{
- file_put_contents(PHPCMS_PATH.'index.html', $str);
- }
- }
- unset($str);
- //[SWH|+];
复制代码 \index.php:在代码前面另起一行,添加代码:- //[SWH|+]:
- switch(pc_base::load_config('system','website_is_closed')){
- case '2': //仅允许后台用户访问
- $session_storage = 'session_'.pc_base::load_config('system','session_storage');
- pc_base::load_sys_class($session_storage);
- if(!empty($_SESSION['userid']) && !empty($_SESSION['roleid'])){
- break;
- }
- case '1': //禁止所有人访问
- if($_GET['m']=='admin'){
- break; //可以访问后台
- }
- if(pc_base::load_config('system','off_site_because')!==''){
- echo nl2br(pc_base::load_config('system','off_site_because'));
- }
- exit;
- default: //向所有公开
- }
- //[SWH|+];
复制代码 \caches\configs\system.php:在文件末尾的代码前面添加:- 'website_is_closed' => '0',
- 'off_site_because' => '',
复制代码 完毕!