pbootcms使用技巧

pbootcms是与aspcms一家公司开发的企业网站系统,非常完美的企业网站系统,功能齐全,方便灵活,支持sqlite/mysql数据库

模板中支持简单的php语句

 {php}echo 111+222;{/php}

数据库快速操作类 类似THINKPHP框架的方式 比较容易上手

引入命名空间
use corebasicModel;
use corebasicDb;

$a = Db::table('ay_content')->where('id=1')->find();
var_dump($a); 
$model = new Model();
$r = $model->table('ay_content')->where('id=1')->find();
var_dump($r);

以上两种是等价的,第一种Db通过__callstatic静态魔术方法来调用Model类的方法

pbootcms导入其它数据库的信息

public function importold()
{
    exit('已經導入新聞');
    set_time_limit(0);
    $data = json_decode('{"acode":"cn","scode":"16","subscode":"","title":"\u6807\u9898","titlecolor":"#333333","subtitle":"","filename":"","author":"admin","source":"\u672c\u7ad9","outlink":"","date":"2018-12-30 10:45:46","ico":"\/static\/upload\/image\/20181230\/1546137994102175.png","pics":"\/static\/upload\/image\/20181230\/1546138005227320.png,\/static\/upload\/image\/20181230\/1546138006814526.png","content":"

\u5185\u5bb9<\/p>","enclosure":"","keywords":"","description":"\u5185\u5bb9","sorting":255,"status":"1","istop":0,"isrecommend":0,"isheadline":0,"visits":0,"likes":0,"oppose":0,"create_user":"admin","update_user":"admin"}',true); //var_dump($data);die(); //对应关系数组 文章 产品 单页 $relation = array( 1 => 16, 3 => 12, 6 => 38, 8 => 35, 10 => 18, 13 => 25, 15 => 31, 18 => 13, 20 => 14, 31 => 22, 33 => 27, 34 => 33 ); $i = 0; //php访问mdb 数据库 //成功导入数据1611条 $connstr = "DRIVER=Microsoft Access Driver (*.mdb);DBQ=#Database#.mdb"; $connid = @odbc_connect($connstr,"","",SQL_CUR_USE_ODBC ) or die ("数据库连接错误!"); $sql = "select * from jtbc_articles"; $exec = odbc_exec($connid,$sql); while($row = odbc_fetch_array($exec)) { //重置这些内容 以免下一个 $data['ico'] = ''; $data['pics'] = ''; if(isset($relation[$row['a_class']]) && $row['a_id'] != 540) { //有相应的栏目对应关系的话 $data['scode'] = $relation[$row['a_class']]; $data['title'] = escape_string(iconv('gb2312', 'utf-8', $row['a_topic'])); $data['content'] = iconv('gb2312', 'utf-8', $row['a_content']); $data['content'] = escape_string(str_replace('{$->>repath}articles/common/upload/', '/static/upload/', $data['content'])); $data['description'] = mb_substr(strip_tags($data['content']), 0, 150, 'utf-8'); $data['date'] = $row['a_time']; $data['visits'] = $row['a_count']; if ($row['a_content_images'] != '') { if (strpos($row['a_content_images'], '|') !== false) { $data['pics'] = str_replace('|', ',', $row['a_content_images']); $data['pics'] = str_replace('common/upload/', '/static/upload/', $data['pics']); $data['ico'] = explode(',', $data['pics'])[0]; } else { $data['ico'] = $row['a_content_images']; } } //var_dump($data); //exit(); if (! ! $id = $this->model->addContent($data)) { $i++; } } } echo "成功导入数据" . $i . '条'; }

先断点获取到输入文章时的数组,每条导入数据只需要赋值需要变更的部分,注意每次重置数据项为空

碰到的大坑
php odbc连接 查询显示不完整问题
在php.ini里找到[ODBC] 下面有odbc.defaultlrl = 4096 你改正你想要设置 的大小就ok

Kernel文件解密 仅供学习

 $value) {
                $key = str_replace('/', '\\/', trim_slash($key));
                $reg = "{(.*\/|^)" . $key . "(\/.*|$)}Ui";
                if (preg_match($reg, $pathInfo)) {
                    $value = trim_slash($value);
                    $pathInfo = preg_replace($reg, "$1$value$2", $pathInfo);
                    break;
                }
            }
        }
        return $pathInfo;
    }

    private static function getAccessPath($pathInfo)
    {
        $apps = Config::get('public_app', true);
        if ($pathInfo) {
            $path_info = trim_slash($pathInfo);
            $path_array = explode('/', $path_info);
            $path_count = count($path_array);
            if ($path_count >= 3) {
                $access_path['m'] = $path_array[0];
                $access_path['c'] = $path_array[1];
                $access_path['f'] = $path_array[2];
                for ($i = 3; $i < $path_count; $i = $i + 2) {
                    if (isset($path_array[$i + 1])) {
                        $_GET[$path_array[$i]] = $path_array[$i + 1];
                    } else {
                        $_GET[$path_array[$i]] = null;
                    }
                }
            } elseif ($path_count == 2) {
                $access_path['m'] = $path_array[0];
                $access_path['c'] = $path_array[1];
            } elseif ($path_count == 1) {
                $access_path['m'] = $path_array[0];
            }
        }
        if (!isset($access_path['m'])) {
            $access_path['m'] = $apps[0];
        }
        if (!isset($access_path['c'])) {
            $access_path['c'] = 'Index';
        }
        if (!isset($access_path['f'])) {
            $access_path['f'] = 'index';
        }
        if (!in_array(strtolower($access_path['m']), $apps)) {
            error('您访问的模块' . $access_path['m'] . '未开放,请核对后重试!');
        }
        return $access_path;
    }

    private static function regAppPath($accessPath)
    {
        define('M', strtolower($accessPath['m']));
        self::$controllerPath = self::adjustController($accessPath['c']);
        if (!!$pos = strrpos(self::$controllerPath, '/')) {
            define('C', ucfirst(substr(self::$controllerPath, $pos + 1)));
            self::$controllerPath = substr(self::$controllerPath, 0, $pos + 1) . ucfirst(substr(self::$controllerPath, $pos + 1));
        } else {
            define('C', ucfirst(self::$controllerPath));
            self::$controllerPath = ucfirst(self::$controllerPath);
        }
        define('F', $accessPath['f']);
        if (isset($_SERVER["REQUEST_URI"])) {
            define('URL', $_SERVER["REQUEST_URI"]);
        } else {
            define('URL', $_SERVER["ORIG_PATH_INFO"] . '?' . $_SERVER["QUERY_STRING"]);
        }
        define('CORE_VERSION', Config::get('core_version'));
        define('APP_CONTROLLER_PATH', APP_PATH . '/' . M . '/controller');
        define('APP_MODEL_PATH', APP_PATH . '/' . M . '/model');
        if (($tpl_dir = Config::get('tpl_dir')) && array_key_exists(M, $tpl_dir)) {
            if (strpos($tpl_dir[M], ROOT_PATH) === false) {
                define('APP_VIEW_PATH', ROOT_PATH . $tpl_dir[M]);
            } else {
                define('APP_VIEW_PATH', $tpl_dir[M]);
            }
        } else {
            define('APP_VIEW_PATH', APP_PATH . '/' . M . '/view');
        }
    }

    private static function adjustController($string)
    {
        $string = str_replace('.', '/', $string);
        $string_arr = explode('_', $string);
        if (count($string_arr) > 1) {
            $count = count($string_arr);
            for ($i = 1; $i < $count; $i++) {
                $string_arr[$i] = ucfirst($string_arr[$i]);
            }
            $string = implode($string_arr);
        }
        return $string;
    }

    private static function loadComm()
    {
        Config::get('debug') ? Check::checkAppFile() : '';
        $app_config = APP_PATH . '/' . M . '/config/config.php';
        if (file_exists($app_config)) {
            Config::assign($app_config);
        }
        define('APP_VERSION', Config::get('app_version'));
        define('RELEASE_TIME', Config::get('release_time'));
        if (M == 'api') {
            if (!!$sid = request('sid')) {
                session_id($sid);
                session_start();
            }
            header("Access-Control-Allow-Origin: *");
        } else {
            if (!ini_get('session.auto_start') && !isset($_SESSION)) {
                session_start();
            }
            Check::checkBs();
            Check::checkOs();
        }
    }

    private static function loadController()
    {
        $class_file = self::$controllerPath . 'Controller.php';
        $class_file_path = APP_CONTROLLER_PATH . '/' . $class_file;
        $class_name = '\\app\\' . M . '\\controller\\' . str_replace('/', '\\', self::$controllerPath) . 'Controller';
        $function = F;
        if (!file_exists($class_file_path)) {
            header('HTTP/1.1 404 Not Found');
            header('status: 404 Not Found');
            $file_404 = ROOT_PATH . '/404.html';
            if (file_exists($file_404)) {
                require $file_404;
                exit();
            } else {
                error('对不起,您访问的页面不存在,请核对后再试!');
            }
        }
        if (!class_exists($class_name)) {
            error('类' . $class_name . '不存在!类文件' . $class_file_path . '中无法找到!');
        }
        $app_function = APP_PATH . '/' . M . '/function/function.php';
        if (file_exists($app_function)) {
            require $app_function;
        }
        if (file_exists(APP_PATH . '/common/function.php')) {
            require APP_PATH . '/common/function.php';
        }
        if (file_exists(APP_PATH . '/common/' . ucfirst(M) . 'Controller.php')) {
            $comm_class_name = '\\app\\common\\' . ucfirst(M) . 'Controller';
            $comm_class = new $comm_class_name();
        }
        $controller = new $class_name();
        if (method_exists($class_name, $function)) {
            if (strtolower($class_name) != strtolower($function)) {
                $return = $controller->$function();
            } else {
                $return = $controller;
            }
        } else {
            if (method_exists($class_name, '_empty')) {
                $return = $controller->_empty();
            } else {
                error('方法不存在!' . M . '模块下控制器文件' . $class_file . '中不存在您调用的方法' . $function . ',可能正在开发中,请耐心等待!');
            }
        }
        if ($return !== null) {
            Response::handle($return);
        }
    }

    private static function loadCache()
    {
        if (!Config::get('tpl_html_cache') || URL_BLIND == 'api') {
            return;
        }
        $lg = isset($_COOKIE['lg']) ? cookie('lg') : '';
        Config::get();
        $config_file = RUN_PATH . '/config/' . md5('config' . $lg) . '.php';
        if (!Config::assign($config_file)) {
            return;
        }
        $lg = $lg ?: Config::get('lgs.0.acode');
        if (Config::get('open_wap') && (is_mobile() || Config::get('wap_domain') == get_http_host())) {
            $wap = 'wap';
        } else {
            $wap = '';
        }
        $cache_file = RUN_PATH . '/cache/' . md5($_SERVER["REQUEST_URI"] . $lg . $wap) . '.html';
        if (file_exists($cache_file) && time() - filemtime($cache_file) < Config::get('tpl_html_cache_time')) {
            ob_start();
            include $cache_file;
            $content = ob_get_contents();
            ob_end_clean();
            if (Config::get('gzip') && !headers_sent() && extension_loaded("zlib") && strstr($_SERVER["HTTP_ACCEPT_ENCODING"], "gzip")) {
                $content = gzencode($content, 6);
                header("Content-Encoding: gzip");
                header("Vary: Accept-Encoding");
                header("Content-Length: " . strlen($content));
            }
            echo $content;
            exit();
        }
    }

    private static function license()
    {
        if (URL_BLIND == 'admin') {
            return;
        }
        if (!!$sn = Config::get('sn', true)) {
            $host = $_SERVER['HTTP_HOST'];
            $key = strtoupper(substr(md5(substr(sha1($host), 0, 10)), 10, 10));
            $sip = isset($_SERVER['LOCAL_ADDR']) ? $_SERVER['LOCAL_ADDR'] : $_SERVER['SERVER_ADDR'];
            if ($sip != '::1' && substr($sip, 0, 6) != '127.0.' && !in_array($key, $sn)) {
                error('未匹配到本域名有效授权码,请到PbootCMS官网获取,并填写到后台"全局配置>>配置参数"中。');
            }
        } else {
            error('配置文件中授权码为空,请到PbootCMS官网获取,并填写到后台"全局配置>>配置参数"中。');
        }
    }
}

有子分类调用子分类 没有子分类显示同级分类

修改标签解析控制器方法 ParserController.php中的 paseSortLabel,添加case分支

case 'soncount':
                        $content = str_replace($matches[0][$i], count($this->model->getSubScodes($sort->scode)), $content);
                        break;

将appshomemodelParserModel.php中的getSubScodes方法改为public

 public function getSubScodes($scode)

模板标签写法


                        {pboot:if({sort:soncount} == 1)}
                        
    {pboot:nav num=100 parent={sort:pcode}}
  • [nav:name]
  • {/pboot:nav}
{else}
    {pboot:nav num=100 parent={sort:scode}}
  • [nav:name]
  • {/pboot:nav}
{/pboot:if}

自带分页条及样式

{page:bar}
/* 分页样式 */
.paging { margin-top: 32px; font-size: 14px; }
.paging > span { margin: auto 16px; }
.paging .page-numbar { margin: auto 0; }
.paging .page-numbar .page-num,
.paging .page-index,
.paging .page-pre,
.paging .page-next,
.paging .page-last { display: inline-block; margin: auto 4px; padding: 2px 12px; border: 1px solid #EEE; border-radius: 2px; }
.paging .page-numbar .page-num-current,
.paging .page-numbar .page-num:hover { border-color: #8667F7; color: #8667F7; }

你可能感兴趣的:(cms,php)