pbootcms使用技巧

24次阅读

共计 11987 个字符,预计需要花费 30 分钟才能阅读完成。

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":"<p>\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 文件解密 仅供学习

<?php 
/**
 * @copyright (C)2016-2099 Hnaoyun Inc.
 * @license This is not a freeware, use is subject to license terms
 * @author XingMeng
 * @email hnxsh@foxmail.com
 * @date 2018-08-09 16:03:55
 *  翱云科技版权所有,除本授权文件其余代码均开源,未经许可擅自破解本文件将依法追究法律责任。*/


namespace core\basic;
class Kernel
{
    private static $controllerPath;

    public static function run()
    {//self::license();
        self::loadCache();
        $path_info = self::getPathInfo();
        $path_info = self::urlBlind($path_info);
        $path_info = self::urlRoute($path_info);
        $access_path = self::getAccessPath($path_info);
        self::regAppPath($access_path);
        self::loadComm();
        self::loadController();}

    private static function getPathInfo()
    {if (isset($_SERVER['PATH_INFO']) && !mb_check_encoding($_SERVER['PATH_INFO'], 'utf-8')) {$_SERVER['PATH_INFO'] = mb_convert_encoding($_SERVER['PATH_INFO'], 'UTF-8', 'GBK');
        }
        if (isset($_SERVER['PATH_INFO'])) {$path_info = $_SERVER['PATH_INFO'];
        } elseif (isset($_SERVER["REDIRECT_URL"])) {$path_info = str_replace('/' . basename($_SERVER['SCRIPT_NAME']), '', $_SERVER['REDIRECT_URL']);
            $path_info = str_replace(SITE_DIR, '', $path_info);
            $_SERVER['PATH_INFO'] = $path_info;
        } elseif (isset($_GET['s'])) {$path_info = $_GET['s'];
        } else {$path_info = '';}
        if ($path_info) {$pattern = '{^\/?([\x{4e00}-\x{9fa5}\w-\/\.' . Config::get('url_allow_char') . ']+?)?\/?$}u';
            if (preg_match($pattern, $path_info)) {$path_info = preg_replace($pattern, '$1', $path_info);
                $url_html_suffix = Config::get('url_suffix');
                if (substr($path_info, -strlen($url_html_suffix)) == $url_html_suffix) {$path_info = substr($path_info, 0, -strlen($url_html_suffix));
                }
            } else {error('您访问路径含有非法字符,防注入系统提醒您请勿尝试非法操作!');
            }
        }
        return $path_info;
    }

    private static function urlBlind($pathInfo)
    {
        $path = '';
        if (!!$domains = Config::get('app_domain_blind')) {$server_name = str_replace(':' . $_SERVER['SERVER_PORT'], '', $_SERVER['HTTP_HOST']);
            if (isset($domains[$server_name])) {$path = $domains[$server_name];
            }
        }
        if (defined('URL_BLIND')) {if ($path) {if (strpos($path, URL_BLIND) === false && strpos(URL_BLIND, $path) === false) {error('系统配置的域名地址绑定与入口文件地址绑定冲突,请核对!');
                } elseif (strpos($path, URL_BLIND) === false && strpos(URL_BLIND, $path) !== false) {$path = URL_BLIND;}
            } else {$path = URL_BLIND;}
        }
        if ($path) {$path = trim_slash($path) . '/' . $pathInfo;
        } else {$path = $pathInfo;}
        return $path;
    }

    private static function urlRoute($pathInfo)
    {if (!!$route = Config::get('url_route')) {if (!$pathInfo && isset($route['/'])) {return $route['/'];
            }
            foreach ($route as $key => $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('未匹配到本域名有效授权码,请到 <a href="http://www.pbootcms.com"target="_blank">PbootCMS</a> 官网获取,并填写到后台" 全局配置 >> 配置参数 "中。');
            }
        } else {error('配置文件中授权码为空,请到 <a href="http://www.pbootcms.com"target="_blank">PbootCMS</a> 官网获取,并填写到后台" 全局配置 >> 配置参数 "中。');
        }
    }
}

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

修改标签解析控制器方法 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)}
                        <div class="module-inner">
                            <div class="t3_nav1_t nav1_color1">
                                <dl>
                                    <dt>{sort:parentname}</dt>
                                    <dd>Zibo Central Hospital</dd>
                                </dl>
                            </div>
                            <div class="module-ct t3_nav1_b">
                                <ul>
                                    {pboot:nav num=100 parent={sort:pcode}}
                                    <li class="item-399 {pboot:2if('[nav:scode]'=='{sort:scode}')}current active{/pboot:2if}"><a href="[nav:link]">[nav:name]</a>
                                    </li>
                                    {/pboot:nav}

                                </ul>
                            </div>
                        </div>
                        {else}
                        <div class="module-inner">
                            <div class="t3_nav1_t nav1_color1">
                                <dl>
                                    <dt>{sort:name}</dt>
                                    <dd>Zibo Central Hospital</dd>
                                </dl>
                            </div>
                            <div class="module-ct t3_nav1_b">
                                <ul>
                                    {pboot:nav num=100 parent={sort:scode}}
                                    <li class="item-399"><a href="[nav:link]">[nav:name]</a>
                                    </li>
                                    {/pboot:nav}
                                </ul>
                            </div>
                        </div>
                        {/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;}

正文完
 0