给PHPCMS V9 增加关闭网站功能

来源:互联网 发布:数据库软件市场份额 编辑:程序博客网 时间:2024/05/21 09:00


\phpcms\modules\admin\templates\setting.tpl.php:

在代码
  1. <div id="div_setting_1" class="contentList pad-10">
  2. <table width="100%"  class="table_form">
复制代码
后面另起一行,添加代码:
  1. <!-- Admpub: -->
  2. <tr>
  3.     <th width="120">网站状态</th>
  4.     <td class="y-bg"><input name="setconfig[website_is_closed]" value="2" type="radio"<?php echo ($website_is_closed==2) ? ' checked="checked"' : '';?> /> 仅供管理员访问<!-- Only admin -->&nbsp;&nbsp;&nbsp;&nbsp;
  5.     <input name="setconfig[website_is_closed]" value="1" type="radio"<?php echo ($website_is_closed==1) ? ' checked="checked"' : '';?> /> 禁止所有人访问<!-- Ban all -->&nbsp;&nbsp;&nbsp;&nbsp;
  6.     <input name="setconfig[website_is_closed]" value="0" type="radio" <?php echo (!$website_is_closed) ? ' checked="checked"' : '';?> /> 允许所有人访问<!-- Open to all --></td>
  7.   </tr>
  8.   <tr>
  9.     <th width="120">关站提示信息</th>
  10.     <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>&nbsp;&nbsp;&nbsp;&nbsp;支持HTML标签</td>
  11.   </tr>
  12. <!-- /Admpub -->
复制代码
\phpcms\modules\admin\functions\global.func.php:
在set_config()函数中,在代码
  1. if(in_array($k,array(
复制代码
后面添加:
  1. /*[SWH|+]:*/'website_is_closed','off_site_because',/*[SWH|+];*/
复制代码
\phpcms\modules\admin\setting.php:

在代码
  1. set_config($_POST['setconfig']);
复制代码
前面另起一行,添加代码:
  1. //[SWH|+]:
  2. if(!empty($_POST['setconfig']['website_is_closed'])){
  3.     $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>';
  4.     if(pc_base::load_config('system','lock_ex')){ 
  5.         file_put_contents(PHPCMS_PATH.'index.html', $str, LOCK_EX);
  6.     }else{
  7.         file_put_contents(PHPCMS_PATH.'index.html', $str);
  8.     }
  9. }
  10. unset($str);
  11. //[SWH|+];
复制代码
\index.php:

在代码
  1. pc_base::creat_app();
复制代码
前面另起一行,添加代码:
  1. //[SWH|+]:
  2. switch(pc_base::load_config('system','website_is_closed')){
  3.     case '2': //仅允许后台用户访问
  4.         $session_storage = 'session_'.pc_base::load_config('system','session_storage');
  5.         pc_base::load_sys_class($session_storage);
  6.         if(!empty($_SESSION['userid']) && !empty($_SESSION['roleid'])){
  7.             break;
  8.         }
  9.     case '1': //禁止所有人访问
  10.         if($_GET['m']=='admin'){
  11.             break; //可以访问后台
  12.         }
  13.         if(pc_base::load_config('system','off_site_because')!==''){
  14.             echo nl2br(pc_base::load_config('system','off_site_because'));
  15.         }
  16.         exit;
  17.     default: //向所有公开
  18. }
  19. //[SWH|+];
复制代码
\caches\configs\system.php:
在文件末尾的代码
  1. );
  2. ?>
复制代码
前面添加:
  1. 'website_is_closed' => '0',
  2. 'off_site_because' => '',
复制代码
完毕!
原创粉丝点击