init
This commit is contained in:
396
static/backup/upgrade/20211013183901/core/view/Paging.php
Normal file
396
static/backup/upgrade/20211013183901/core/view/Paging.php
Normal file
@@ -0,0 +1,396 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright (C)2016-2099 Hnaoyun Inc.
|
||||
* @author XingMeng
|
||||
* @email hnxsh@foxmail.com
|
||||
* @date 2016年11月6日
|
||||
* 分页控制类
|
||||
*/
|
||||
namespace core\view;
|
||||
|
||||
use core\basic\Config;
|
||||
|
||||
class Paging
|
||||
{
|
||||
|
||||
// 每页数量
|
||||
public $pageSize;
|
||||
|
||||
// 当前页码
|
||||
public $page;
|
||||
|
||||
// 数字条数量
|
||||
public $num = 5;
|
||||
|
||||
// 调整数量
|
||||
public $start = 1;
|
||||
|
||||
// 总记录
|
||||
private $rowTotal = 0;
|
||||
|
||||
// 页面数量
|
||||
private $pageCount;
|
||||
|
||||
// 存储前置URL
|
||||
private $preUrl;
|
||||
|
||||
// 分页实例
|
||||
private static $paging;
|
||||
|
||||
private function __construct()
|
||||
{
|
||||
// 禁用类new实例化
|
||||
}
|
||||
|
||||
// 获取单一实例
|
||||
public static function getInstance()
|
||||
{
|
||||
if (! self::$paging) {
|
||||
self::$paging = new self();
|
||||
}
|
||||
return self::$paging;
|
||||
}
|
||||
|
||||
// 限制语句
|
||||
public function limit($total = null, $morePageStr = false)
|
||||
{
|
||||
// 起始数据调整
|
||||
if (! is_numeric($this->start) || $this->start < 1) {
|
||||
$this->start = 1;
|
||||
}
|
||||
if ($this->start > $total) {
|
||||
$this->start = $total + 1;
|
||||
}
|
||||
|
||||
// 设置总数
|
||||
if ($total) {
|
||||
$this->rowTotal = $total - ($this->start - 1);
|
||||
}
|
||||
|
||||
// 设置分页大小
|
||||
if (! isset($this->pageSize)) {
|
||||
$this->pageSize = get('pagesize') ?: Config::get('pagesize') ?: 15;
|
||||
}
|
||||
|
||||
// 分页数字条数量
|
||||
$this->num = Config::get('pagenum') ?: 5;
|
||||
|
||||
// 计算页数
|
||||
$this->pageCount = @ceil($this->rowTotal / $this->pageSize);
|
||||
|
||||
// 获取当前页面
|
||||
$this->page = $this->page();
|
||||
|
||||
// 定义相关常量,用于方便模板引擎解析序号等计算和调用
|
||||
define('ROWTOTAL', $this->rowTotal);
|
||||
define('PAGECOUNT', $this->pageCount);
|
||||
define('PAGE', $this->page);
|
||||
define('PAGESIZE', $this->pageSize);
|
||||
|
||||
// 注入分页模板变量
|
||||
$this->assign($morePageStr);
|
||||
|
||||
// 返回限制语句
|
||||
return ($this->page - 1) * $this->pageSize + ($this->start - 1) . ",$this->pageSize";
|
||||
}
|
||||
|
||||
// 快速分页字符代码
|
||||
public function quikLimit()
|
||||
{
|
||||
$page = get('page', 'int') ?: 1;
|
||||
if ($page < 1) {
|
||||
$page = 0;
|
||||
}
|
||||
$pagesize = config::get('pagesize') ?: 15;
|
||||
return ($page - 1) * $pagesize . ",$pagesize";
|
||||
}
|
||||
|
||||
// 注入页面相关信息,用于模板调用,如:{$pagebar}调用分页条
|
||||
private function assign($morePageStr = false)
|
||||
{
|
||||
assign('pagebar', $this->pageBar());
|
||||
if ($morePageStr) {
|
||||
assign('pagecurrent', $this->page()); // 注入当前页
|
||||
assign('pagecount', $this->pageCount); // 注入总页数
|
||||
assign('pagerows', $this->rowTotal); // 注入总数据
|
||||
assign('pageindex', $this->pageIndex()); // 注入首页链接
|
||||
assign('pagepre', $this->pagePre()); // 注入前一页链接
|
||||
assign('pagenext', $this->pageNext()); // 注入后一页链接
|
||||
assign('pagelast', $this->pageLast()); // 注入最后一页链接
|
||||
assign('pagestatus', $this->pageStatus()); // 注入分页状态
|
||||
assign('pagenumbar', $this->pageNumBar()); // 注入数字
|
||||
assign('pageselectbar', $this->pageSelectBar()); // 注入选择栏
|
||||
}
|
||||
}
|
||||
|
||||
// 当前页码容错处理
|
||||
private function page()
|
||||
{
|
||||
$page = get('page', 'int') ?: $this->page;
|
||||
if (is_numeric($page) && $page > 1) {
|
||||
if ($page > $this->pageCount && $this->pageCount) {
|
||||
return $this->pageCount;
|
||||
} else {
|
||||
return $page;
|
||||
}
|
||||
} else {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
// 过滤pathinfo中分页参数
|
||||
private function getPreUrl()
|
||||
{
|
||||
if (! isset($this->preUrl) && URL) {
|
||||
$url = parse_url(URL);
|
||||
$path = preg_replace('/\/page\/[0-9]+/i', '', $url['path']);
|
||||
if (defined('CMS_PAGE') && CMS_PAGE == true) { // 使用CMS分页时去除扩展
|
||||
$url_rule_suffix = Config::get('url_rule_suffix');
|
||||
if (! ! $pos = strripos($path, $url_rule_suffix)) {
|
||||
$path = substr($path, 0, $pos);
|
||||
}
|
||||
}
|
||||
$this->preUrl = $path;
|
||||
}
|
||||
return $this->preUrl;
|
||||
}
|
||||
|
||||
// 构建链接地址
|
||||
private function buildPath($page)
|
||||
{
|
||||
if ($page) {
|
||||
if (defined('CMS_PAGE') && CMS_PAGE == true) {
|
||||
$url_rule_type = Config::get('url_rule_type') ?: 3;
|
||||
$url_rule_suffix = Config::get('url_rule_suffix') ?: '.html';
|
||||
$url_break_char = Config::get('url_break_char') ?: '_';
|
||||
$url_rule_sort_suffix = Config::get('url_rule_sort_suffix') ? $url_rule_suffix : '/';
|
||||
|
||||
if ($url_rule_type == 1 || $url_rule_type == 2) {
|
||||
if (defined('CMS_PAGE_CUSTOM')) { // 去分页参数
|
||||
$prepath = preg_replace('/(.*)' . $url_break_char . '[0-9]+$/', '$1', rtrim($this->getPreUrl(), '/'));
|
||||
} else {
|
||||
$prepath = preg_replace('/(.*)(' . $url_break_char . '[0-9]+)' . $url_break_char . '[0-9]+$/', '$1$2', rtrim($this->getPreUrl(), '/'));
|
||||
}
|
||||
if ($prepath) { // 非首页分页
|
||||
if ($page == 1) { // 第一页处理
|
||||
$path = $prepath . $url_rule_sort_suffix . query_string('p,s');
|
||||
} else {
|
||||
$path = $prepath . $url_break_char . $page . $url_rule_sort_suffix . query_string('p,s');
|
||||
}
|
||||
} else { // 首页分页
|
||||
$path = ($page == 1) ? SITE_INDEX_DIR . '/' : '?page=' . $page;
|
||||
}
|
||||
} else {
|
||||
if ($url_rule_type == 3 && isset($_SERVER["QUERY_STRING"]) && $qs = $_SERVER["QUERY_STRING"]) {
|
||||
parse_str($qs, $output);
|
||||
unset($output['page']);
|
||||
|
||||
if ($output && ! current($output)) {
|
||||
$path_qs = key($output); // 第一个参数为路径信息,注意PHP数组会自动将点转换下划线
|
||||
unset($output[$path_qs]); // 去除路径参数
|
||||
|
||||
// 去后缀扩展
|
||||
$temp_suffix = substr($url_rule_suffix, 1);
|
||||
if (! ! $pos = strripos($path_qs, '_' . $temp_suffix)) {
|
||||
$path = substr($path_qs, 0, $pos); // 去扩展
|
||||
} else {
|
||||
$path = $path_qs;
|
||||
}
|
||||
|
||||
// 去除原分页参数
|
||||
if (defined('CMS_PAGE_CUSTOM')) {
|
||||
$path = preg_replace('/(.*)' . $url_break_char . '[0-9]+$/', "$1", rtrim($path, '/'));
|
||||
} else {
|
||||
$path = preg_replace('/(.*)(' . $url_break_char . '[0-9]+)' . $url_break_char . '[0-9]+$/', "$1$2", rtrim($path, '/'));
|
||||
}
|
||||
|
||||
// 第一页链接处理
|
||||
if ($page == 1) {
|
||||
$path = SITE_INDEX_DIR . '/?' . $path . $url_rule_sort_suffix;
|
||||
} else {
|
||||
$path = SITE_INDEX_DIR . '/?' . $path . $url_break_char . $page . $url_rule_sort_suffix;
|
||||
}
|
||||
|
||||
// 附加参数
|
||||
if (! ! $qs = http_build_query($output)) {
|
||||
$path = rtrim($path, '/') . '&' . $qs;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (! $path) { // 转基本分页模式
|
||||
return $this->buildBasicPage($page);
|
||||
}
|
||||
}
|
||||
return $path;
|
||||
} else {
|
||||
return $this->buildBasicPage($page);
|
||||
}
|
||||
} else {
|
||||
return 'javascript:;';
|
||||
}
|
||||
}
|
||||
|
||||
// 构建基本分页
|
||||
private function buildBasicPage($page)
|
||||
{
|
||||
// 对于路径保留变量给予去除
|
||||
$qs = $_SERVER["QUERY_STRING"];
|
||||
if ((M == 'home' && Config::get('url_rule_type') == 2) || (M != 'home' && Config::get('app_url_type') == 2)) {
|
||||
$qs = preg_replace('/[&\?]?p=([\w\/\.]+)?/i', '', $qs);
|
||||
$qs = preg_replace('/[&\?]?s=([\w\/\.]+)?/i', '', $qs);
|
||||
}
|
||||
$qs = preg_replace('/[&\?]?page=([0-9]+)?/i', '', $qs);
|
||||
|
||||
if ($page == 1) {
|
||||
if ($qs) {
|
||||
return $this->getPreUrl() . '?' . $qs;
|
||||
} else {
|
||||
return $this->getPreUrl();
|
||||
}
|
||||
} else {
|
||||
if ($qs) {
|
||||
return $this->getPreUrl() . '?' . $qs . '&page=' . $page;
|
||||
} else {
|
||||
return $this->getPreUrl() . '?page=' . $page;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 分页条
|
||||
private function pageBar()
|
||||
{
|
||||
if (! $this->pageCount)
|
||||
return "<span class='page-none' style='color:#999'>未查询到任何数据!</span>";
|
||||
$string = "<span class='page-status'>{$this->pageStatus()}</span>";
|
||||
$string .= "<span class='page-index'><a href='" . $this->pageIndex() . "'>首页</a></span>";
|
||||
$string .= "<span class='page-pre'><a href='" . $this->pagePre() . "'>前一页</a></span>";
|
||||
$string .= "<span class='page-numbar'>{$this->pageNumBar()}</span>";
|
||||
$string .= "<span class='page-next'><a href='" . $this->pageNext() . "'>后一页</a></span>";
|
||||
$string .= "<span class='page-last'><a href='" . $this->pageLast() . "'>尾页</a></span>";
|
||||
// $string .= "<span class='page-select'>{$this->pageSelectBar()}</span>";
|
||||
return $string;
|
||||
}
|
||||
|
||||
// 当前页面情况
|
||||
private function pageStatus()
|
||||
{
|
||||
if (! $this->pageCount)
|
||||
return;
|
||||
return "共" . $this->rowTotal . "条 当前" . $this->page . "/" . $this->pageCount . "页";
|
||||
}
|
||||
|
||||
// 首页链接
|
||||
private function pageIndex()
|
||||
{
|
||||
if (! $this->pageCount)
|
||||
return $this->buildPath('');
|
||||
return $this->buildPath(1);
|
||||
}
|
||||
|
||||
// 上一页链接
|
||||
private function pagePre()
|
||||
{
|
||||
if (! $this->pageCount)
|
||||
return $this->buildPath('');
|
||||
if ($this->page > 1) {
|
||||
$pre_page = $this->buildPath($this->page - 1);
|
||||
} else {
|
||||
$pre_page = $this->buildPath('');
|
||||
}
|
||||
return $pre_page;
|
||||
}
|
||||
|
||||
// 下一页链接
|
||||
private function pageNext()
|
||||
{
|
||||
if (! $this->pageCount)
|
||||
return $this->buildPath('');
|
||||
if ($this->page < $this->pageCount) {
|
||||
$next_page = $this->buildPath($this->page + 1);
|
||||
} else {
|
||||
$next_page = $this->buildPath('');
|
||||
}
|
||||
return $next_page;
|
||||
}
|
||||
|
||||
// 尾页
|
||||
private function pageLast()
|
||||
{
|
||||
if (! $this->pageCount)
|
||||
return $this->buildPath('');
|
||||
return $this->buildPath($this->pageCount);
|
||||
}
|
||||
|
||||
// 数字分页,要修改数字显示的条数,请修改类头部num属性值
|
||||
private function pageNumBar()
|
||||
{
|
||||
if (! $this->pageCount)
|
||||
return;
|
||||
|
||||
if (M == 'admin') {
|
||||
$total = 5;
|
||||
} else {
|
||||
$total = $this->num;
|
||||
}
|
||||
|
||||
$halfl = intval($total / 2);
|
||||
$halfu = ceil($total / 2);
|
||||
|
||||
$num_html = '';
|
||||
if ($this->page > $halfu) {
|
||||
$num_html .= '<span class="page-num">···</span>';
|
||||
}
|
||||
|
||||
if ($this->page <= $halfl || $this->pageCount < $total) { // 当前页小于一半或页数小于总数
|
||||
for ($i = 1; $i <= $total; $i ++) {
|
||||
if ($i > $this->pageCount)
|
||||
break;
|
||||
if ($this->page == $i) {
|
||||
$num_html .= '<a href="' . $this->buildPath($i) . '" class="page-num page-num-current">' . $i . '</a>';
|
||||
} else {
|
||||
$num_html .= '<a href="' . $this->buildPath($i) . '" class="page-num">' . $i . '</a>';
|
||||
}
|
||||
}
|
||||
} elseif ($this->page + $halfl >= $this->pageCount) { // 当前页为倒数页以内
|
||||
for ($i = $this->pageCount - $total + 1; $i <= $this->pageCount; $i ++) {
|
||||
if ($this->page == $i) {
|
||||
$num_html .= '<a href="' . $this->buildPath($i) . '" class="page-num page-num-current">' . $i . '</a>';
|
||||
} else {
|
||||
$num_html .= '<a href="' . $this->buildPath($i) . '" class="page-num">' . $i . '</a>';
|
||||
}
|
||||
}
|
||||
} else { // 正常的前后各5页
|
||||
for ($i = $this->page - $halfl; $i <= $this->page + $halfl; $i ++) {
|
||||
if ($this->page == $i) {
|
||||
$num_html .= '<a href="' . $this->buildPath($i) . '" class="page-num page-num-current">' . $i . '</a>';
|
||||
} else {
|
||||
$num_html .= '<a href="' . $this->buildPath($i) . '" class="page-num">' . $i . '</a>';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->pageCount > $total && $this->page < $this->pageCount - $halfl) {
|
||||
$num_html .= '<span class="page-num">···</span>';
|
||||
}
|
||||
|
||||
return $num_html;
|
||||
}
|
||||
|
||||
// 跳转分页
|
||||
private function pageSelectBar()
|
||||
{
|
||||
if (! $this->pageCount)
|
||||
return;
|
||||
$select_html = '<select onchange="changepage(this)" lay-ignore>';
|
||||
for ($i = 1; $i <= $this->pageCount; $i ++) {
|
||||
if ($i == $this->page) {
|
||||
$select_html .= '<option value="' . $i . '" selected="selected">跳到' . $i . '页</option>';
|
||||
} else {
|
||||
$select_html .= '<option value="' . $i . '">跳到' . $i . '页</option>';
|
||||
}
|
||||
}
|
||||
$select_html .= '</select><script>function changepage(tag){window.location.href="' . $this->buildPath('"+tag.value+"') . '";}</script>';
|
||||
return $select_html;
|
||||
}
|
||||
}
|
||||
159
static/backup/upgrade/20211013183901/core/view/View.php
Normal file
159
static/backup/upgrade/20211013183901/core/view/View.php
Normal file
@@ -0,0 +1,159 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright (C)2016-2099 Hnaoyun Inc.
|
||||
* @author XingMeng
|
||||
* @email hnxsh@foxmail.com
|
||||
* @date 2016年11月6日
|
||||
* 模板显示类
|
||||
*/
|
||||
namespace core\view;
|
||||
|
||||
use core\basic\Config;
|
||||
|
||||
class View
|
||||
{
|
||||
|
||||
// 模板路径
|
||||
protected $tplPath;
|
||||
|
||||
// 编译路径
|
||||
protected $tplcPath;
|
||||
|
||||
// 缓存路径
|
||||
protected $cachePath;
|
||||
|
||||
// 存储注入变量
|
||||
protected $vars = array();
|
||||
|
||||
// 存储包含文件
|
||||
protected $incFile = array();
|
||||
|
||||
// 实例
|
||||
protected static $view;
|
||||
|
||||
// 获取单一实例
|
||||
public static function getInstance()
|
||||
{
|
||||
if (! self::$view) {
|
||||
self::$view = new self();
|
||||
}
|
||||
return self::$view;
|
||||
}
|
||||
|
||||
// 禁止通过new实例化类
|
||||
private function __construct()
|
||||
{
|
||||
$this->tplPath = APP_VIEW_PATH;
|
||||
$this->tplcPath = RUN_PATH . '/complile';
|
||||
$this->cachePath = RUN_PATH . '/cache';
|
||||
check_dir($this->tplcPath, true);
|
||||
check_dir($this->cachePath, true);
|
||||
}
|
||||
|
||||
private function __clone()
|
||||
{
|
||||
die('不允许克隆对象!请使用getInstance获取实例');
|
||||
}
|
||||
|
||||
// 变量注入
|
||||
public function assign($var, $value)
|
||||
{
|
||||
if (! empty($var)) {
|
||||
if (isset($this->vars[$var])) {
|
||||
error('模板变量$' . $var . '出现重复注入!');
|
||||
}
|
||||
$this->vars[$var] = $value;
|
||||
return true;
|
||||
} else {
|
||||
error('传递的设置模板变量有误');
|
||||
}
|
||||
}
|
||||
|
||||
// 变量获取
|
||||
public function getVar($var)
|
||||
{
|
||||
if (! empty($var)) {
|
||||
if (isset($this->vars[$var])) {
|
||||
return $this->vars[$var];
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
error('传递的获取模板变量有误');
|
||||
}
|
||||
}
|
||||
|
||||
// 解析模板文件
|
||||
public function parser($file)
|
||||
{
|
||||
// 设置主题
|
||||
$theme = isset($this->vars['theme']) ? $this->vars['theme'] : 'default';
|
||||
|
||||
$theme = preg_replace_r('{\.\.(\/|\\\\)}', '', $theme); // 过滤掉相对路径
|
||||
$file = preg_replace_r('{\.\.(\/|\\\\)}', '', $file); // 过滤掉相对路径
|
||||
|
||||
if (strpos($file, '/') === 0) { // 绝对路径模板
|
||||
$tpl_file = ROOT_PATH . $file;
|
||||
} elseif (! ! $pos = strpos($file, '@')) { // 跨模块调用
|
||||
$path = APP_PATH . '/' . substr($file, 0, $pos) . '/view/' . $theme;
|
||||
define('APP_THEME_DIR', str_replace(DOC_PATH, '', $path));
|
||||
if (! is_dir($path)) { // 检查主题是否存在
|
||||
error('模板主题目录不存在!主题路径:' . $path);
|
||||
} else {
|
||||
$this->tplPath = $path;
|
||||
}
|
||||
$tpl_file = $path . '/' . substr($file, $pos + 1);
|
||||
} else {
|
||||
// 定义当前应用主题目录
|
||||
define('APP_THEME_DIR', str_replace(DOC_PATH, '', APP_VIEW_PATH) . '/' . $theme);
|
||||
if (! is_dir($this->tplPath .= '/' . $theme)) { // 检查主题是否存在
|
||||
error('模板主题目录不存在!主题路径:' . APP_THEME_DIR);
|
||||
}
|
||||
$tpl_file = $this->tplPath . '/' . $file; // 模板文件
|
||||
}
|
||||
$note = Config::get('tpl_html_dir') ? '<br>同时检测到您系统中启用了模板子目录' . Config::get('tpl_html_dir') . ',请核对是否是此原因导致!' : '';
|
||||
file_exists($tpl_file) ?: error('模板文件' . APP_THEME_DIR . '/' . $file . '不存在!' . $note);
|
||||
$tpl_c_file = $this->tplcPath . '/' . md5($tpl_file) . '.php'; // 编译文件
|
||||
|
||||
// 当编译文件不存在,或者模板文件修改过,则重新生成编译文件
|
||||
if (! file_exists($tpl_c_file) || filemtime($tpl_c_file) < filemtime($tpl_file) || ! Config::get('tpl_parser_cache')) {
|
||||
$content = Parser::compile($this->tplPath, $tpl_file); // 解析模板
|
||||
file_put_contents($tpl_c_file, $content) ?: error('编译文件' . $tpl_c_file . '生成出错!请检查目录是否有可写权限!'); // 写入编译文件
|
||||
$compile = true;
|
||||
}
|
||||
|
||||
ob_start(); // 开启缓冲区,引入编译文件
|
||||
$rs = include $tpl_c_file;
|
||||
if (! isset($compile)) {
|
||||
foreach ($rs as $value) { // 检查包含文件是否更新,其中一个包含文件不存在或修改则重新解析模板
|
||||
if (! file_exists($value) || filemtime($tpl_c_file) < filemtime($value) || ! Config::get('tpl_parser_cache')) {
|
||||
$content = Parser::compile($this->tplPath, $tpl_file); // 解析模板
|
||||
file_put_contents($tpl_c_file, $content) ?: error('编译文件' . $tpl_c_file . '生成出错!请检查目录是否有可写权限!'); // 写入编译文件
|
||||
ob_clean();
|
||||
include $tpl_c_file;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
$content = ob_get_contents();
|
||||
ob_end_clean();
|
||||
return $content;
|
||||
}
|
||||
|
||||
// 缓存页面, 开启缓存开关时有效
|
||||
public function cache($content)
|
||||
{
|
||||
if (Config::get('tpl_html_cache') && ! query_string('p,s')) {
|
||||
$lg = cookie('lg');
|
||||
if (Config::get('open_wap') && (is_mobile() || Config::get('wap_domain') == get_http_host())) {
|
||||
$wap = 'wap';
|
||||
} else {
|
||||
$wap = '';
|
||||
}
|
||||
$cacheFile = $this->cachePath . '/' . md5(get_http_url() . $_SERVER["REQUEST_URI"] . $lg . $wap) . '.html'; // 缓存文件
|
||||
file_put_contents($cacheFile, $content) ?: error('缓存文件' . $cacheFile . '生成出错!请检查目录是否有可写权限!'); // 写入缓存文件
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user