ABROAD:设计用户数据库、系统配置数据库等

2013-11-11 1,343 2 开发! 大超超。

1.系统:设计用户数据库、系统配置数据库

2.系统:开发快速录入系统配置数据的页面

3.系统:系统关键函数sConf、uConf更名

4.后台:使用bootstrap框架开发、使用colorTitle插件显示title

5.系统:优化template模版类,支持foreach功能

131111开发.png

附admin/sconfig.htm:

<!-- inc {#head.htm} -->
<script type="text/javascript" src="{@tpl_rurl}sta/j.colorTip.js?v=1.0"></script>
<script type="text/javascript">$(function(){$('[title]').colorTip({color:'black'});});</script>
     
<!-- 导航 -->
<ul class="breadcrumb">
  <li>
    <a href="admin">后台首页</a> <span class="divider">/</span>
  </li>
  <li>
    <a href="admin/sys">系统</a> <span class="divider">/</span>
  </li>
  <li class="active">全局配置</li>
</ul>
     
<div class="table">
    <table class="table table-bordered table-hover table-condensed table-striped">
        <tr>
            <th>id</th>
            <th>键(唯一)</th>
            <th>值</th>
            <th>更新日期</th>
            <th title="初始载入脚本,会增加系统负载">初始化</th>
            <th>操作</th>
        </tr>
        {foreach $config_list}
        <tr>
            <td>$id</td>
            <td>$k</td>
            <td>$v</td>
            <td>$updDt</td>
            <td>$init</td>
            <td>$operate</td>
        </tr>
        {/foreach}
    </table>
</div>
<!-- inc {#foot.htm} -->

admin.ctl.php:

<?php
if( !defined('DCCMS') ) die();
class CTL_admin{
    // AE系统配置 @ 2013-11-10 23:04:10
    function sconfigA(){
        global $db;
        $tmp_arr = array();
        $res = $db->query("select * from config");
        while( $r=$db->fetch_array($res) ){
            $r['init'] = $r['init'] ? '是' : '否';
            $tmp_arr[] = $r;
        }
        $arr = array(
            'seo_title' => '系统配置 - 后台',
            'foreach_arr' => array(
                'config_list' => $tmp_arr
            )
        );
        echo parse($arr);
    }
         
}//End Class

template.cls.php:

<?php
     
class Template{
         
    // 常用变量 @ 2013-09-09 13:51:46
    var $tpl_rpath;
    var $tpl_rurl;
    var $app_version;
     
    // 初始化函数 @ 2013-09-09 14:10:32
    function __construct($sConf){
        $this->tpl_rpath = $sConf['tpl_rootpath'];
             
        $tmp_arr = explode('/tpl/', $this->tpl_rpath, 2);
        $this->tpl_rurl = 'tpl/'.reset(explode('/', $tmp_arr[1], 2)).'/';
             
        $this->app_version = $sConf['app_version'];
        //print_r($this);
    }
         
    // 为安全起见,出错提示时返回相对路径 @ 2013-09-09 14:02:42
    private function trimPath( $path ){
        return str_replace($this->tpl_rpath, '', $path);
    }
         
    //解析foreach, 请自行理解 @ 2013-11-11 00:15:03
    private function parse_foreach($arr, $ct) {
        foreach( $arr as $k=>$v){
            list($ct1, $y) = explode('{foreach $'.$k.'}', $ct, 2);
            list($tpl, $ct3) = explode('{/foreach}', $y, 2);
            $ct2 = '';
            foreach( $v as $vv ){
                $find_arr = $repl_arr = array();
                foreach( $vv as $kkk=>$vvv ){
                    $find_arr[] = '$'.$kkk;
                    $repl_arr[] = $vvv;
                }
                $ct2 .= str_replace($find_arr, $repl_arr, trim($tpl));
            }
            $ct = $ct1.$ct2.$ct3;
        }
        //deb($ct);
        return $ct;
    }
     
    // 生成静态模版 @ 2013-09-09 13:31:14
    private function load( $tpl_path='' ){
        $ct = file_get_contents($tpl_path);
        $patten = '/\<\!-- inc \{\#(.*?)\} --\>/';
        $max_inc = 52;
        while( preg_match($patten, $ct, $m) && $max_inc-->0 ){
            //print_r($m);
            $inc_path = $this->tpl_rpath.$m[1];
            if( !file_exists($inc_path) ) die('模版inc不存在,请检查路径:'.$this->trimPath($inc_path));
            $inc_ct = file_get_contents($inc_path);
            $ct = str_replace($m[0], $inc_ct, $ct);
        }
        return $ct;
    }
         
    // 解析函数 @ 2013-09-09 13:27:48
    function parse( $parse_arr=array(), $tpl_path='' ){
        global $time;
             
        $tpl_path = $this->tpl_rpath.$tpl_path;
        if( !file_exists($tpl_path) ) die('主模版不存在,请检查路径:'.$this->trimPath($tpl_path));
        // 生成最终模版
        $ct = $this->load($tpl_path);
             
        // 解析foreach @ 2013-11-11 00:21:37
        if( stripos($ct, '{foreach $')!==FALSE ){
            $ct = $this->parse_foreach($parse_arr['foreach_arr'], $ct);
        }
             
        // 添加固有变量(会被传入的变量覆盖)
        $parse_addtion_arr = array(
            'time'              => time(),
            'js_config'         => 'G='.enjson($GLOBALS['js_cfg_']).';'.php2jsArray($GLOBALS['js_language_'], 'L'),
            'root_url'          => ROOT_URL,
            'tpl_rurl'          => $this->tpl_rurl,
            'app_name'          => APP_NAME,
            'app_name_en'       => APP_NAME_EN,
            'app_version'       => $this->app_version,
            'seo_description'   => sConf('seo_description'),
            'seo_keywords'      => sConf('seo_keywords'),
            'seo_webname'       => sConf('seo_webname'),
            'title_postfix'     => sConf('title_postfix')
        );
        $parse_arr = array_merge($parse_addtion_arr, $parse_arr);
        // 解析模版变量
        $find_arr = $repl_arr = array();
        foreach( $parse_arr as $k=>$v ){
            $find_arr[] = '{@'.$k.'}';
            $repl_arr[] = $v;
        }
        $s = str_replace($find_arr, $repl_arr, $ct);
             
             
        // 去掉多余未解析内容
        $s = preg_replace('/\{\@.*?\}/', '', $s);
        return $s;
    }
}//End Class

 



声明: 本文由大超超。原创编译,转载请保留链接: http://www.thinkful.cn/archives/310.html