From c4ba53fd9e828d32d9c3da11f32aa7b77e32de8a Mon Sep 17 00:00:00 2001 From: molong Date: Fri, 22 Jul 2016 14:33:13 +0800 Subject: [PATCH] =?UTF-8?q?=E5=86=85=E6=A0=B8=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 27 ++++++++++++------------- application/database.php | 4 ++-- core/library/think/App.php | 7 ++++--- core/library/think/File.php | 13 +++++++++++- core/library/think/Loader.php | 30 +++++++++++++--------------- core/library/think/Route.php | 10 ++++++++-- core/library/think/Url.php | 14 +++++++++++-- core/library/think/Validate.php | 15 ++++++++++++-- core/library/think/db/Connection.php | 2 +- core/library/think/db/Query.php | 2 +- 10 files changed, 80 insertions(+), 44 deletions(-) diff --git a/README.md b/README.md index 5e233fd8..04c402db 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,18 @@ ## SentCMS介绍 > SentCMS网站管理系统是南昌腾速科技有限公司倾力打造的一款简单易用的网站管理系统,SentCMS网站管理系统(下文简称SentCMS)继承了thinkphp5.0的优秀品质,秉承“大道至简”的设计理念。SnetCMS为网站建设而生,为网站建设减少90%的代码编写,只需前端设计师就可以设计出完美的网站,而如此完美的系统还是完全开源的。 +## 安装 + +目前暂无安装文件,可按以下方法安装: + +* 第一步、修改数据库配置文件 application/database.php +* 第二步、通过数据库导入工具,比如phpmyadmin导入数据,数据sql文件data/sql.sql +* 第三步、登录后台,后台地址 http://域名/admin + +> 系统必须开启伪静态 + +初始账号:admin,密码:admin888 + ## SentCMS特性包括: * 全新的路由体系,完美的路由解决方案 * 全新的系统架构,采用thinkphp5.0内核框架 @@ -48,23 +60,10 @@ │ ├─ueditor.json 编辑配置文件 ├─core thinkphp框架目录 ├─data 缓存以及备份目录 -├─extend 扩展类库目录(后期可能会变更目录) ├─public 公共资源库 ├─uploads 上传文件目录 ├─.htaccess Apache下伪静态文件 ├─favicon.ico ico图标 ├─index.php 入口文件 ├─README.md 系统介绍文件 -~~~ - -## 安装 - -目前暂无安装文件,可按以下方法安装: - -* 第一步、修改数据库配置文件 application/database.php -* 第二步、通过数据库导入工具,比如phpmyadmin导入数据,数据sql文件data/sql.sql -* 第三步、登录后台,后台地址 http://域名/admin - -> 系统必须开启伪静态 - -初始账号:admin,密码:admin888 \ No newline at end of file +~~~ \ No newline at end of file diff --git a/application/database.php b/application/database.php index 08744d7c..b83ed7d9 100644 --- a/application/database.php +++ b/application/database.php @@ -17,9 +17,9 @@ return array( // 数据库名 'database' => 'sentcms_www', // 数据库用户名 - 'username' => 'root', + 'username' => 'sentcms_www', // 数据库密码 - 'password' => 'nitbbs_org', + 'password' => '', // 数据库连接端口 'hostport' => '', // 数据库连接参数 diff --git a/core/library/think/App.php b/core/library/think/App.php index ebc3a776..0b7ff00a 100644 --- a/core/library/think/App.php +++ b/core/library/think/App.php @@ -238,8 +238,9 @@ class App foreach ($params as $param) { $name = $param->getName(); $class = $param->getClass(); - if ($class && 'think\Request' == $class->getName()) { - $args[] = Request::instance(); + if ($class) { + $className = $class->getName(); + $args[] = method_exists($className, 'instance') ? $className::instance() : new $className(); } elseif (1 == $type && !empty($vars)) { $args[] = array_shift($vars); } elseif (0 == $type && isset($vars[$name])) { @@ -465,7 +466,7 @@ class App */ public static function routeCheck($request, array $config) { - $path = $request->path(); + $path = rtrim($request->path(), '/'); $depr = $config['pathinfo_depr']; $result = false; // 路由检测 diff --git a/core/library/think/File.php b/core/library/think/File.php index 21e8c9dd..bd39209f 100644 --- a/core/library/think/File.php +++ b/core/library/think/File.php @@ -195,12 +195,23 @@ class File extends SplFileObject { $extension = strtolower(pathinfo($this->getInfo('name'), PATHINFO_EXTENSION)); /* 对图像文件进行严格检测 */ - if (in_array($extension, ['gif', 'jpg', 'jpeg', 'bmp', 'png', 'swf']) && !in_array(exif_imagetype($this->filename), [1, 2, 3, 4, 6])) { + if (in_array($extension, ['gif', 'jpg', 'jpeg', 'bmp', 'png', 'swf']) && !in_array($this->getImageType($this->filename), [1, 2, 3, 4, 6])) { return false; } return true; } + // 判断图像类型 + protected function getImageType($image) + { + if (function_exists('exif_imagetype')) { + return exif_imagetype($image); + } else { + $info = getimagesize($image); + return $info[2]; + } + } + /** * 检测上传文件大小 * @param integer $size 最大大小 diff --git a/core/library/think/Loader.php b/core/library/think/Loader.php index ed206107..9451db66 100644 --- a/core/library/think/Loader.php +++ b/core/library/think/Loader.php @@ -99,7 +99,7 @@ class Loader if (false !== $pos = strrpos($class, '\\')) { // namespaced class name $logicalPathPsr0 = substr($logicalPathPsr4, 0, $pos + 1) - . strtr(substr($logicalPathPsr4, $pos + 1), '_', DS); + . strtr(substr($logicalPathPsr4, $pos + 1), '_', DS); } else { // PEAR-like class name $logicalPathPsr0 = strtr($class, '_', DS) . EXT; @@ -155,13 +155,13 @@ class Loader if (!$prefix) { if ($prepend) { self::$fallbackDirsPsr0 = array_merge( - (array)$paths, + (array) $paths, self::$fallbackDirsPsr0 ); } else { self::$fallbackDirsPsr0 = array_merge( self::$fallbackDirsPsr0, - (array)$paths + (array) $paths ); } @@ -170,24 +170,23 @@ class Loader $first = $prefix[0]; if (!isset(self::$prefixesPsr0[$first][$prefix])) { - self::$prefixesPsr0[$first][$prefix] = (array)$paths; + self::$prefixesPsr0[$first][$prefix] = (array) $paths; return; } if ($prepend) { self::$prefixesPsr0[$first][$prefix] = array_merge( - (array)$paths, + (array) $paths, self::$prefixesPsr0[$first][$prefix] ); } else { self::$prefixesPsr0[$first][$prefix] = array_merge( self::$prefixesPsr0[$first][$prefix], - (array)$paths + (array) $paths ); } } - // 添加Psr4空间 private static function addPsr4($prefix, $paths, $prepend = false) { @@ -195,13 +194,13 @@ class Loader // Register directories for the root namespace. if ($prepend) { self::$fallbackDirsPsr4 = array_merge( - (array)$paths, + (array) $paths, self::$fallbackDirsPsr4 ); } else { self::$fallbackDirsPsr4 = array_merge( self::$fallbackDirsPsr4, - (array)$paths + (array) $paths ); } } elseif (!isset(self::$prefixDirsPsr4[$prefix])) { @@ -211,23 +210,22 @@ class Loader throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator."); } self::$prefixLengthsPsr4[$prefix[0]][$prefix] = $length; - self::$prefixDirsPsr4[$prefix] = (array)$paths; + self::$prefixDirsPsr4[$prefix] = (array) $paths; } elseif ($prepend) { // Prepend directories for an already registered namespace. self::$prefixDirsPsr4[$prefix] = array_merge( - (array)$paths, + (array) $paths, self::$prefixDirsPsr4[$prefix] ); } else { // Append directories for an already registered namespace. self::$prefixDirsPsr4[$prefix] = array_merge( self::$prefixDirsPsr4[$prefix], - (array)$paths + (array) $paths ); } } - // 注册命名空间别名 public static function addNamespaceAlias($namespace, $original = '') { @@ -308,8 +306,8 @@ class Loader public static function import($class, $baseUrl = '', $ext = EXT) { static $_file = []; - $key = $class . $baseUrl; - $class = str_replace(['.', '#'], [DS, '.'], $class); + $key = $class . $baseUrl; + $class = str_replace(['.', '#'], [DS, '.'], $class); if (isset($_file[$key])) { return true; } @@ -548,4 +546,4 @@ function __include_file($file) function __require_file($file) { return require $file; -} \ No newline at end of file +} diff --git a/core/library/think/Route.php b/core/library/think/Route.php index eee061f9..92147c8f 100644 --- a/core/library/think/Route.php +++ b/core/library/think/Route.php @@ -1093,7 +1093,7 @@ class Route foreach ($matches[1] as $name) { if (strpos($name, '?')) { $name = substr($name, 0, -1); - $replace[] = '((' . (isset($pattern[$name]) ? $pattern[$name] : '') . ')?)'; + $replace[] = '(' . (isset($pattern[$name]) ? $pattern[$name] : '') . '?)'; } else { $replace[] = '(' . (isset($pattern[$name]) ? $pattern[$name] : '') . ')'; } @@ -1112,11 +1112,17 @@ class Route if (0 === strpos($val, '[:')) { // 可选参数 - $val = substr($val, 1, -1); + $val = substr($val, 1, -1); + $optional = true; + } else { + $optional = false; } if (0 === strpos($val, ':')) { // URL变量 $name = substr($val, 1); + if (!$optional && !isset($m1[$key])) { + return false; + } if (isset($m1[$key]) && isset($pattern[$name]) && !preg_match('/^' . $pattern[$name] . '$/', $m1[$key])) { // 检查变量规则 return false; diff --git a/core/library/think/Url.php b/core/library/think/Url.php index a5190d7b..cf570af0 100644 --- a/core/library/think/Url.php +++ b/core/library/think/Url.php @@ -19,6 +19,9 @@ use think\Route; class Url { + // 生成URL地址的root + protected static $root; + /** * URL生成 支持路由反射 * @param string $url URL表达式, @@ -113,7 +116,7 @@ class Url // 检测域名 $domain = self::parseDomain($url, $domain); // URL组装 - $url = $domain . Request::instance()->root() . '/' . ltrim($url, '/'); + $url = $domain . (self::$root ?: Request::instance()->root()) . '/' . ltrim($url, '/'); return $url; } @@ -316,4 +319,11 @@ class Url { Cache::rm('think_route_map'); } -} \ No newline at end of file + + // 指定当前生成URL地址的root + public static function root($root) + { + self::$root = $root; + Request::instance()->root($root); + } +} diff --git a/core/library/think/Validate.php b/core/library/think/Validate.php index a88043a2..7f230db8 100644 --- a/core/library/think/Validate.php +++ b/core/library/think/Validate.php @@ -561,7 +561,7 @@ class Validate $result = $value instanceof \think\File; break; case 'image': - $result = $value instanceof \think\File && in_array(exif_imagetype($value->getRealPath()), [1, 2, 3, 6]); + $result = $value instanceof \think\File && in_array($this->getImageType($value->getRealPath()), [1, 2, 3, 6]); break; default: if (isset(self::$type[$rule])) { @@ -575,6 +575,17 @@ class Validate return $result; } + // 判断图像类型 + protected function getImageType($image) + { + if (function_exists('exif_imagetype')) { + return exif_imagetype($image); + } else { + $info = getimagesize($image); + return $info[2]; + } + } + /** * 验证是否为合格的域名或者IP 支持A,MX,NS,SOA,PTR,CNAME,AAAA,A6, SRV,NAPTR,TXT 或者 ANY类型 * @access protected @@ -699,7 +710,7 @@ class Validate if ('jpeg' == $imageType) { $imageType = 'jpg'; } - if (image_type_to_extension($type) != $imageType) { + if (image_type_to_extension($type, false) != $imageType) { return false; } } diff --git a/core/library/think/db/Connection.php b/core/library/think/db/Connection.php index a45d8d3e..2e716b29 100644 --- a/core/library/think/db/Connection.php +++ b/core/library/think/db/Connection.php @@ -284,7 +284,7 @@ abstract class Connection if ($this->linkID) { return $this->linkID->getAttribute(PDO::ATTR_DRIVER_NAME); } else { - return basename(str_replace('\\', '/', $this->config['type'])); + return $this->config['type']; } } diff --git a/core/library/think/db/Query.php b/core/library/think/db/Query.php index f380b563..3018e48e 100644 --- a/core/library/think/db/Query.php +++ b/core/library/think/db/Query.php @@ -359,7 +359,7 @@ class Query static $builder = []; $driver = $this->driver; if (!isset($builder[$driver])) { - $class = '\\think\\db\\builder\\' . ucfirst($driver); + $class = false !== strpos($driver, '\\') ? $driver : '\\think\\db\\builder\\' . ucfirst($driver); $builder[$driver] = new $class($this->connection); } // 设置当前查询对象