初始化官网代码

This commit is contained in:
wojiaoxiaomage
2025-12-30 10:26:47 +08:00
commit 00f55e8b83
232 changed files with 49856 additions and 0 deletions

View File

@@ -0,0 +1,137 @@
<?php
/**
* @copyright (C)2016-2099 Hnaoyun Inc.
* @author XingMeng
* @email hnxsh@foxmail.com
* @date 2016年11月6日
* 系统环境检查类
*/
namespace core\basic;
use core\basic\Config;
class Check
{
// 启动应用检查
public static function checkApp()
{
if (! is_dir(APP_PATH)) {
error('您的系统文件无法正常读取,请检查是否上传完整!');
}
// 判断自动转换状态
if (function_exists("get_magic_quotes_gpc") && get_magic_quotes_gpc()) {
error('您的服务器环境PHP.ini中magic_quotes_gpc配置为On状态会导致数据存储异常请设置为Off状态或切换为更高版本PHP。');
}
// 判断目录列表函数
if (! function_exists('scandir')) {
error('您的服务器环境PHP.ini配置中已经禁用scandir函数会导致无法正常读取配置及模板文件请先去除。');
}
// 检查gd扩展
if (! extension_loaded('gd')) {
error('您的服务器环境不支持gd扩展,将无法使用验证码!');
}
// 检查mbstring扩展
if (! extension_loaded('mbstring')) {
error('您的服务器环境不支持mbstring扩展请先安装并启用');
}
// 检查curl扩展
if (! extension_loaded('curl')) {
error('您的服务器环境不支持curl扩展请先安装并启用');
}
}
// 检查PHP版本
public static function checkPHP()
{
if (PHP_VERSION < '5.3') {
error('您服务器的PHP版本太低本程序要求版本不小于 5.3');
}
}
// 检查mysqli扩展库
public static function checkMysqli()
{
if (! extension_loaded('mysqli')) {
error('您的服务器环境不支持mysqli扩展,将无法正常使用数据库!');
}
}
// 检查curl扩展库
public static function checkCurl()
{
if (! extension_loaded('curl')) {
error('您的服务器环境不支持curl扩展,将无法使用API模式');
}
}
// 目录路径检查,不存在时根据配置文件选择是否自动创建
public static function checkBasicDir()
{
if (Config::get('debug')) {
check_dir(APP_PATH, true);
check_dir(APP_PATH . '/common', true);
check_dir(CONF_PATH, true);
}
// 目录权限判断
if (! check_dir(RUN_PATH, true)) {
error('缓存目录创建失败,可能写入权限不足!' . RUN_PATH);
}
if (! check_dir(DOC_PATH . STATIC_DIR . '/upload', true)) {
error('上传目录创建失败,可能写入权限不足!' . DOC_PATH . STATIC_DIR . '/upload');
}
}
// 检查系统默认首页的文件是否存在,不存在进行自动创建
public static function checkAppFile()
{
$apps = Config::get('public_app', true);
check_dir(APP_CONTROLLER_PATH, true);
check_file(CONF_PATH . '/config.php', true, "<?php \r\n return array(\r\n\t //'控制项'=>'值' 以分号,分割\r\n);");
check_file(APP_CONTROLLER_PATH . '/IndexController.php', true, "<?php \r\r namespace app\\" . M . "\\controller;\r\r use core\\basic\\Controller; \r\r class IndexController extends Controller{\r\r\tpublic function index(){\r\t\t\$this->display('index.html');\r\t} \r\r}");
check_file(APP_PATH . '/common/' . ucfirst(M) . 'Controller.php', true, "<?php \r\rnamespace app\\common;\r\ruse core\\basic\\Controller; \r\rclass " . ucfirst(M) . "Controller extends Controller{ \r\r}");
// check_file(APP_PATH . '/common/' . ucfirst(M) . 'Model.php', true, "<?php \r\rnamespace app\\common;\r\ruse core\\basic\\Model; \r\rclass " . ucfirst(M) . "Model extends Model{ \r\r}");
}
// 检查客户端浏览器是否被允许,在同时设置黑白名单时,黑名单具有优先级更高,在设置了白名单时,将只允许白名单访问
public static function checkBs()
{
$allow_bs = Config::get('access_rule.allow_bs', true);
$deny_bs = Config::get('access_rule.deny_bs', true);
// 都未设置时,直接通过
if (! $allow_bs && ! $deny_bs)
return true;
// 客户端使用的系统
$user_bs = get_user_bs();
// 如果在黑名单则直接拒绝
if (in_array($user_bs, $deny_bs)) {
error('本站点设置了不允许' . $user_bs . '内核浏览器访问,请使用其它版本IE、火狐、谷歌等国产浏览器请使用极速模式');
} elseif ($allow_bs && ! in_array($user_bs, $allow_bs)) {
error('本站点设置了只允许' . implode(',', $allow_bs) . '内核浏览器访问,请使用这些浏览器!');
}
}
// 检查客户端操作系统是否被允许,在同时设置黑白名单时,黑名单具有优先级更高,在设置了白名单时,将只允许白名单访问
public static function checkOs()
{
$allow_os = Config::get('access_rule.allow_os', true);
$deny_os = Config::get('access_rule.deny_os', true);
// 都未设置时,直接通过
if (! $allow_os && ! $deny_os)
return true;
// 客户端使用的系统
$user_os = get_user_os();
// 如果在黑名单则直接拒绝
if (in_array($user_os, $deny_os)) {
error('本站点设置了不允许' . $user_os . '访问,请使用其它操作系统!');
} elseif ($allow_os && ! in_array($user_os, $allow_os)) {
error('本站点设置了只允许' . implode(',', $allow_os) . '访问,请使用这些操作系统!');
}
}
}

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,157 @@
<?php
/**
* @copyright (C)2016-2099 Hnaoyun Inc.
* @author XingMeng
* @email hnxsh@foxmail.com
* @date 2017年11月6日
* 生成指定模块下控制器方法的跳转路径
*/
namespace core\basic;
class Url
{
// 存储已经生成过的地址信息
private static $urls = array();
// 接收控制器方法完整访问路径,如:/home/Index/index /模块/控制器/方法/.. 路径,生成可访问地址
public static function get($path, $suffix = null)
{
if (strpos($path, 'http') === 0 || ! $path) {
return $path;
}
$path = trim_slash($path); // 去除两端斜线
if (! isset(self::$urls[$path])) {
$path_arr = explode('/', $path); // 地址数组
if ($suffix && Config::get('app_url_type') == 2 && strrpos(strtolower($_SERVER["SCRIPT_NAME"]), 'index.php') !== false) {
$url_ext = Config::get('url_rule_suffix'); // 伪静态文件形式
} elseif (Config::get('app_url_type') == 1 || Config::get('app_url_type') == 2) {
$url_ext = '/'; // pathinfo目录形式
} else {
$url_ext = '';
}
// 路由处理
if (! ! $routes = Config::get('url_route')) {
foreach ($routes as $key => $value) {
// 去除两端斜线
$value = trim_slash($value);
$key = trim_slash($key);
// 替换原来正则为替换内容
if (preg_match_all('/\(.*?\)/', $key, $source)) {
foreach ($source[0] as $kk => $vk) {
$key = str_replace($vk, '$' . ($kk + 1), $key);
}
}
// 替换原来替换内容为正则
if (preg_match_all('/\$([0-9]+)/', $value, $destination)) {
foreach ($destination[1] as $kv => $vv) {
$value = str_replace($destination[0][$kv], $source[0][$vv - 1], $value);
}
}
// 执行匹配替换
if (preg_match('{' . $value . '$}i', $path)) {
$path = preg_replace('{' . $value . '$}i', $key, $path);
} elseif (preg_match('{' . $value . '\/}i', $path)) {
$path = preg_replace('{' . $value . '\/}i', $key . '/', $path);
}
}
}
// 域名绑定处理匹配
$cut_str = '';
if (! ! $domains = Config::get('app_domain_bind')) {
foreach ($domains as $key => $value) {
$value = trim_slash($value); // 去除两端斜线
if (strpos($path, $value . '/') === 0) {
$cut_str = $value;
$server_name = get_http_host();
if ($server_name != $key) { // 绑定的域名与当前域名不一致时,添加主机地址
$host = is_https() ? 'https://' . $key : 'http://' . $key;
} else {
$host = '';
}
break;
}
}
}
// 入口文件绑定匹配
if (defined('URL_BIND') && $path_arr[0] == M) {
$cut_str = trim_slash(URL_BIND);
}
// 执行URL简化
if ($cut_str) {
$path = substr($path, strlen($cut_str) + 1);
}
// 保存处理过的地址
if ($path) {
self::$urls[$path] = $host . url_index_path() . '/' . $path . $url_ext;
} else {
self::$urls[$path] = $host . url_index_path(); // 获取根路径前置地址
}
}
return self::$urls[$path];
}
// 生成前端地址
public static function home($path, $suffix = null, $qs = null)
{
if (! isset(self::$urls[md5($path . $suffix . $qs)])) {
$url_rule_type = Config::get('url_rule_type') ?: 3;
$url_rule_suffix = Config::get('url_rule_suffix') ?: '.html';
$url_rule_sort_suffix = Config::get('url_rule_sort_suffix');
if (($suffix === null && $url_rule_sort_suffix) || $suffix) {
$suffix = $url_rule_suffix;
} elseif ($suffix === false) {
$suffix = '';
} else {
$suffix = '/';
}
$path = ltrim($path, '/');
// 去除默认模块及控制器部分
$path = str_replace('home/Index/', '', $path);
if (! $path) {
if ($url_rule_type == 1) {
$link = SITE_INDEX_DIR . '/index.php';
} elseif ($url_rule_type == 2) {
$link = SITE_INDEX_DIR;
} else {
$link = SITE_INDEX_DIR . '/?';
}
} else {
switch ($url_rule_type) {
case '1': // 普通模式
$qs = $qs ? "?" . $qs : '';
$link = SITE_INDEX_DIR . '/index.php' . '/' . $path . $suffix . $qs;
break;
case '2': // 伪静态模式
$qs = $qs ? "?" . $qs : '';
$link = SITE_INDEX_DIR . '/' . $path . $suffix . $qs;
break;
case '3': // 兼容模式
$qs = $qs ? "&" . $qs : '';
$link = SITE_INDEX_DIR . '/?' . $path . $suffix . $qs;
break;
default:
error('地址模式设置错误,请登录后台重新设置!');
}
}
self::$urls[md5($path . $suffix . $qs)] = $link;
}
return self::$urls[md5($path . $suffix . $qs)];
}
}