Initial project files: BESCMS full source
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
<?php namespace Phpcmf;
|
||||
/**
|
||||
* https://www.besyun.com
|
||||
* BESCMS
|
||||
* 本文件是框架系统文件,二次开发时不可以修改本文件
|
||||
**/
|
||||
|
||||
// 应用公共继承类
|
||||
class App extends \Phpcmf\Common {
|
||||
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
if (!dr_is_app(APP_DIR)) {
|
||||
if (is_file(APPPATH.'Config/App.php')) {
|
||||
$cfg = require APPPATH.'Config/App.php';
|
||||
$this->_msg(0, dr_lang('应用[%s]未安装', $cfg['name']));
|
||||
} else {
|
||||
$this->_msg(0, dr_lang('应用[%s]未安装', APP_DIR));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,254 @@
|
||||
<?php namespace Phpcmf;
|
||||
|
||||
/**
|
||||
* 自动加载识别程序
|
||||
*/
|
||||
|
||||
class Auto
|
||||
{
|
||||
/**
|
||||
* Stores namespaces as key, and path as values.
|
||||
*
|
||||
* @var array<string, array<string>>
|
||||
*/
|
||||
protected $prefixes = [];
|
||||
|
||||
/**
|
||||
* Stores class name as key, and path as values.
|
||||
*
|
||||
* @var array<string, string>
|
||||
*/
|
||||
protected $classmap = [];
|
||||
|
||||
/**
|
||||
* Stores files as a list.
|
||||
*
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $files = [];
|
||||
|
||||
/**
|
||||
* Reads in the configuration array (described above) and stores
|
||||
* the valid parts that we'll need.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function initialize($config)
|
||||
{
|
||||
|
||||
if (empty($config->psr4) && empty($config->classmap)) {
|
||||
return $this;
|
||||
}
|
||||
|
||||
if (isset($config->psr4)) {
|
||||
$this->addNamespace($config->psr4);
|
||||
}
|
||||
|
||||
if (isset($config->classmap)) {
|
||||
$this->classmap = $config->classmap;
|
||||
}
|
||||
|
||||
if (isset($config->files)) {
|
||||
$this->files = $config->files;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the loader with the SPL autoloader stack.
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
// Prepend the PSR4 autoloader for maximum performance.
|
||||
spl_autoload_register([$this, 'loadClass'], true, true);
|
||||
|
||||
// Now prepend another loader for the files in our class map.
|
||||
spl_autoload_register([$this, 'loadClassmap'], true, true);
|
||||
|
||||
// Load our non-class files
|
||||
foreach ($this->files as $file) {
|
||||
if (is_string($file)) {
|
||||
$this->includeFile($file);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers namespaces with the autoloader.
|
||||
*
|
||||
* @param array|string $namespace
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function addNamespace($namespace, ?string $path = null)
|
||||
{
|
||||
if (is_array($namespace)) {
|
||||
foreach ($namespace as $prefix => $namespacedPath) {
|
||||
$prefix = trim($prefix, '\\');
|
||||
|
||||
if (is_array($namespacedPath)) {
|
||||
foreach ($namespacedPath as $dir) {
|
||||
$this->prefixes[$prefix][] = rtrim($dir, '\\/') . DIRECTORY_SEPARATOR;
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->prefixes[$prefix][] = rtrim($namespacedPath, '\\/') . DIRECTORY_SEPARATOR;
|
||||
}
|
||||
} else {
|
||||
$this->prefixes[trim($namespace, '\\')][] = rtrim($path, '\\/') . DIRECTORY_SEPARATOR;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get namespaces with prefixes as keys and paths as values.
|
||||
*
|
||||
* If a prefix param is set, returns only paths to the given prefix.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getNamespace(?string $prefix = null)
|
||||
{
|
||||
if ($prefix === null) {
|
||||
return $this->prefixes;
|
||||
}
|
||||
|
||||
return $this->prefixes[trim($prefix, '\\')] ?? [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a single namespace from the psr4 settings.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function removeNamespace(string $namespace)
|
||||
{
|
||||
if (isset($this->prefixes[trim($namespace, '\\')])) {
|
||||
unset($this->prefixes[trim($namespace, '\\')]);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load a class using available class mapping.
|
||||
*
|
||||
* @return false|string
|
||||
*/
|
||||
public function loadClassmap(string $class)
|
||||
{
|
||||
$file = $this->classmap[$class] ?? '';
|
||||
|
||||
if (is_string($file) && $file !== '') {
|
||||
return $this->includeFile($file);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the class file for a given class name.
|
||||
*
|
||||
* @param string $class The fully qualified class name.
|
||||
*
|
||||
* @return false|string The mapped file on success, or boolean false
|
||||
* on failure.
|
||||
*/
|
||||
public function loadClass(string $class)
|
||||
{
|
||||
$class = trim($class, '\\');
|
||||
$class = str_ireplace('.php', '', $class);
|
||||
|
||||
return $this->loadInNamespace($class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the class file for a given class name.
|
||||
*
|
||||
* @param string $class The fully-qualified class name
|
||||
*
|
||||
* @return false|string The mapped file name on success, or boolean false on fail
|
||||
*/
|
||||
protected function loadInNamespace(string $class)
|
||||
{
|
||||
if (strpos($class, '\\') === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach ($this->prefixes as $namespace => $directories) {
|
||||
foreach ($directories as $directory) {
|
||||
$directory = rtrim($directory, '\\/');
|
||||
|
||||
if (strpos($class, $namespace) === 0) {
|
||||
$filePath = $directory . str_replace('\\', DIRECTORY_SEPARATOR, substr($class, strlen($namespace))) . '.php';
|
||||
$filename = $this->includeFile($filePath);
|
||||
|
||||
if ($filename) {
|
||||
return $filename;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// never found a mapped file
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* A central way to include a file. Split out primarily for testing purposes.
|
||||
*
|
||||
* @return false|string The filename on success, false if the file is not loaded
|
||||
*/
|
||||
protected function includeFile(string $file)
|
||||
{
|
||||
$file = $this->sanitizeFilename($file);
|
||||
|
||||
if (is_file($file)) {
|
||||
include_once $file;
|
||||
|
||||
return $file;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sanitizes a filename, replacing spaces with dashes.
|
||||
*
|
||||
* Removes special characters that are illegal in filenames on certain
|
||||
* operating systems and special characters requiring special escaping
|
||||
* to manipulate at the command line. Replaces spaces and consecutive
|
||||
* dashes with a single dash. Trim period, dash and underscore from beginning
|
||||
* and end of filename.
|
||||
*
|
||||
* @return string The sanitized filename
|
||||
*/
|
||||
public function sanitizeFilename(string $filename): string
|
||||
{
|
||||
// Only allow characters deemed safe for POSIX portable filenames.
|
||||
// Plus the forward slash for directory separators since this might be a path.
|
||||
// http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap03.html#tag_03_278
|
||||
// Modified to allow backslash and colons for on Windows machines.
|
||||
$filename = preg_replace('/[^0-9\p{L}\s\/\-\_\.\:\\\\]/u', '', $filename);
|
||||
|
||||
// Clean up our filename edges.
|
||||
return trim($filename, '.-_');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 自动加载配置文件
|
||||
*/
|
||||
class AutoConfig
|
||||
{
|
||||
|
||||
public $psr4 = [];
|
||||
|
||||
public $classmap = [];
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,357 @@
|
||||
<?php namespace Phpcmf;
|
||||
/**
|
||||
* https://www.besyun.com
|
||||
* BESCMS
|
||||
* 本文件是框架系统文件,二次开发时不可以修改本文件
|
||||
**/
|
||||
|
||||
define('EVENT_PRIORITY_LOW', 200);
|
||||
define('EVENT_PRIORITY_NORMAL', 10);
|
||||
define('EVENT_PRIORITY_HIGH', 10);
|
||||
|
||||
/**
|
||||
* 钩子类
|
||||
*/
|
||||
class Hooks {
|
||||
|
||||
protected static $initialized_hook = false;
|
||||
|
||||
/**
|
||||
* The list of listeners.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected static $listeners = [];
|
||||
|
||||
/**
|
||||
* Flag to let us know if we've read from the Config file(s)
|
||||
* and have all of the defined events.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected static $initialized = false;
|
||||
|
||||
/**
|
||||
* If true, events will not actually be fired.
|
||||
* Useful during testing.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected static $simulate = false;
|
||||
|
||||
/**
|
||||
* Stores information about the events
|
||||
* for display in the debug toolbar.
|
||||
*
|
||||
* @var array<array<string, float|string>>
|
||||
*/
|
||||
protected static $performanceLog = [];
|
||||
|
||||
/**
|
||||
* A list of found files.
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
protected static $files = [];
|
||||
|
||||
/**
|
||||
* 重定义钩子类
|
||||
*/
|
||||
public static function initialize()
|
||||
{
|
||||
// 防止重复加载
|
||||
if (static::$initialized_hook)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// 框架主钩子
|
||||
require CONFIGPATH.'hooks.php';
|
||||
|
||||
if (is_file(FRAMEPATH.'Extend/Hook.php')) {
|
||||
require FRAMEPATH.'Extend/Hook.php';
|
||||
}
|
||||
|
||||
static::$initialized = true;
|
||||
static::$initialized_hook = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers an action to happen on an event. The action can be any sort
|
||||
* of callable:
|
||||
*
|
||||
* Events::on('create', 'myFunction'); // procedural function
|
||||
* Events::on('create', ['myClass', 'myMethod']); // Class::method
|
||||
* Events::on('create', [$myInstance, 'myMethod']); // Method on an existing instance
|
||||
* Events::on('create', function() {}); // Closure
|
||||
*
|
||||
* @param string $eventName
|
||||
* @param callable $callback
|
||||
* @param int $priority
|
||||
*/
|
||||
public static function on($eventName, $callback, $priority = EVENT_PRIORITY_NORMAL)
|
||||
{
|
||||
if (! isset(static::$listeners[$eventName])) {
|
||||
static::$listeners[$eventName] = [
|
||||
true, // If there's only 1 item, it's sorted.
|
||||
[$priority],
|
||||
[$callback],
|
||||
];
|
||||
} else {
|
||||
static::$listeners[$eventName][0] = false; // Not sorted
|
||||
static::$listeners[$eventName][1][] = $priority;
|
||||
static::$listeners[$eventName][2][] = $callback;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Removes a single listener from an event.
|
||||
*
|
||||
* If the listener couldn't be found, returns FALSE, else TRUE if
|
||||
* it was removed.
|
||||
*
|
||||
* @param string $eventName
|
||||
*/
|
||||
public static function removeListener($eventName, callable $listener): bool
|
||||
{
|
||||
if (! isset(static::$listeners[$eventName])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach (static::$listeners[$eventName][2] as $index => $check) {
|
||||
if ($check === $listener) {
|
||||
unset(
|
||||
static::$listeners[$eventName][1][$index],
|
||||
static::$listeners[$eventName][2][$index]
|
||||
);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes all listeners.
|
||||
*
|
||||
* If the event_name is specified, only listeners for that event will be
|
||||
* removed, otherwise all listeners for all events are removed.
|
||||
*
|
||||
* @param string|null $eventName
|
||||
*/
|
||||
public static function removeAllListeners($eventName = null)
|
||||
{
|
||||
if ($eventName !== null) {
|
||||
unset(static::$listeners[$eventName]);
|
||||
} else {
|
||||
static::$listeners = [];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the path to the file that routes are read from.
|
||||
*/
|
||||
public static function setFiles(array $files)
|
||||
{
|
||||
static::$files = $files;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the files that were found/loaded during this request.
|
||||
*
|
||||
* @return string[]
|
||||
*/
|
||||
public function getFiles()
|
||||
{
|
||||
return static::$files;
|
||||
}
|
||||
|
||||
/**
|
||||
* Turns simulation on or off. When on, events will not be triggered,
|
||||
* simply logged. Useful during testing when you don't actually want
|
||||
* the tests to run.
|
||||
*/
|
||||
public static function simulate(bool $choice = true)
|
||||
{
|
||||
static::$simulate = $choice;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for the performance log records.
|
||||
*
|
||||
* @return array<array<string, float|string>>
|
||||
*/
|
||||
public static function getPerformanceLogs()
|
||||
{
|
||||
return static::$performanceLog;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 插件中注册钩子
|
||||
*/
|
||||
public static function app_on($app, $eventName, $callback, $priority = EVENT_PRIORITY_NORMAL)
|
||||
{
|
||||
if (! isset(static::$listeners[$eventName])) {
|
||||
static::$listeners[$eventName] = [
|
||||
true, // If there's only 1 item, it's sorted.
|
||||
[$priority],
|
||||
[$callback],
|
||||
[$app],
|
||||
];
|
||||
} else {
|
||||
static::$listeners[$eventName][0] = false; // Not sorted
|
||||
static::$listeners[$eventName][1][] = $priority;
|
||||
static::$listeners[$eventName][2][] = $callback;
|
||||
static::$listeners[$eventName][3][] = $app;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns an array of listeners for a single event. They are
|
||||
* sorted by priority.
|
||||
*
|
||||
* @param string $eventName
|
||||
*/
|
||||
public static function listeners($eventName): array
|
||||
{
|
||||
if (! isset(static::$listeners[$eventName])) {
|
||||
return [[], []];
|
||||
}
|
||||
|
||||
// The list is not sorted
|
||||
if (! static::$listeners[$eventName][0]) {
|
||||
// Sort it!
|
||||
array_multisort(static::$listeners[$eventName][1], SORT_NUMERIC, static::$listeners[$eventName][2]);
|
||||
|
||||
// Mark it as sorted already!
|
||||
static::$listeners[$eventName][0] = true;
|
||||
}
|
||||
|
||||
return [static::$listeners[$eventName][2], static::$listeners[$eventName][3]];
|
||||
}
|
||||
|
||||
/**
|
||||
* 运行带返回参数的钩子点,其中某个钩子返回值时终止运行
|
||||
*
|
||||
* @param string $eventName
|
||||
* @param mixed $arguments
|
||||
*
|
||||
* @return boolean | array
|
||||
*/
|
||||
public static function trigger_callback($eventName, ...$arguments)
|
||||
{
|
||||
|
||||
if (! static::$initialized)
|
||||
{
|
||||
static::initialize();
|
||||
}
|
||||
|
||||
list($listeners, $apps) = static::listeners($eventName);
|
||||
if (!$listeners) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$msg = '';
|
||||
$data = [];
|
||||
$is_rt = 0;
|
||||
|
||||
foreach ($listeners as $k => $listener) {
|
||||
|
||||
if (IS_POST && CI_DEBUG && !in_array($eventName, ['DBQuery', 'pre_system'])) {
|
||||
log_message('debug', ($apps && isset($apps[$k]) ? '插件【'.$apps[$k].'】' : '' ).'运行钩子【'.$eventName.'】');
|
||||
}
|
||||
|
||||
$start = microtime(true);
|
||||
$rt = call_user_func($listener, ...$arguments);
|
||||
|
||||
if (CI_DEBUG)
|
||||
{
|
||||
static::$performanceLog[] = [
|
||||
'start' => $start,
|
||||
'end' => microtime(true),
|
||||
'event' => strtolower($eventName),
|
||||
];
|
||||
}
|
||||
|
||||
if ($rt && isset($rt['code'])) {
|
||||
if ($rt['code'] == 0) {
|
||||
// 只要遇到返回成功的钩子就中断执行直接返回
|
||||
return $rt;
|
||||
}
|
||||
$msg = $rt['msg'];
|
||||
if (is_array($rt['data'])) {
|
||||
if (is_array($data)) {
|
||||
$data = dr_array22array($data, $rt['data']);
|
||||
} else {
|
||||
$data = $rt['data'];
|
||||
}
|
||||
} else {
|
||||
$data = $rt['data'];
|
||||
}
|
||||
if ($msg == 'merge') {
|
||||
$arguments[0] = dr_array22array($arguments[0], $data);
|
||||
}
|
||||
$is_rt = 1;
|
||||
}
|
||||
}
|
||||
|
||||
if ($is_rt) {
|
||||
return dr_return_data(1, $msg, $data);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 运行不带返回参数的钩子点
|
||||
*
|
||||
* @param string $eventName
|
||||
* @param mixed $arguments
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public static function trigger($eventName, ...$arguments): bool
|
||||
{
|
||||
// Read in our Config/Events file so that we have them all!
|
||||
if (! static::$initialized)
|
||||
{
|
||||
static::initialize();
|
||||
}
|
||||
|
||||
list($listeners, $apps) = static::listeners($eventName);
|
||||
if (!$listeners) {
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach ($listeners as $k => $listener) {
|
||||
|
||||
if (IS_POST && CI_DEBUG && !in_array($eventName, ['DBQuery', 'pre_system'])) {
|
||||
log_message('debug', ($apps && isset($apps[$k]) ? '插件【'.$apps[$k].'】' : '' ).'运行钩子【'.$eventName.'】');
|
||||
}
|
||||
|
||||
$start = microtime(true);
|
||||
$result = static::$simulate === false ? call_user_func($listener, ...$arguments) : true;
|
||||
|
||||
if (CI_DEBUG)
|
||||
{
|
||||
static::$performanceLog[] = [
|
||||
'start' => $start,
|
||||
'end' => microtime(true),
|
||||
'event' => strtolower($eventName),
|
||||
];
|
||||
}
|
||||
|
||||
if ($result === false)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,543 @@
|
||||
<?php namespace Phpcmf;
|
||||
/**
|
||||
* https://www.besyun.com
|
||||
* BESCMS
|
||||
* 本文件是框架系统文件,二次开发时不可以修改本文件
|
||||
**/
|
||||
|
||||
class Service {
|
||||
|
||||
static private $instances = [];
|
||||
static private $help = [];
|
||||
static private $logs = [];
|
||||
static private $view;
|
||||
static private $model;
|
||||
static private $require;
|
||||
static private $apps = [
|
||||
1 => [],
|
||||
0 => [],
|
||||
];
|
||||
static private $mwhere_apps = [];
|
||||
static private $filters = [
|
||||
'home' => [
|
||||
'install/index',
|
||||
'api/ueditor',
|
||||
],
|
||||
'member' => [
|
||||
'api/ueditor',
|
||||
],
|
||||
'admin' => [
|
||||
'api/ueditor',
|
||||
],
|
||||
];
|
||||
static private $license = [];
|
||||
|
||||
// 获取应用自动加载
|
||||
public static function Auto($auto) {
|
||||
|
||||
$auto->psr4 = array_merge($auto->psr4, [
|
||||
|
||||
'Phpcmf\Controllers' => APPPATH.'Controllers',
|
||||
|
||||
'Phpcmf\Control' => CMSPATH.'Control',
|
||||
'Phpcmf\Extend' => FRAMEPATH.'Extend',
|
||||
'Phpcmf\Library' => CMSPATH.'Library',
|
||||
'Phpcmf\Field' => CMSPATH.'Field',
|
||||
'Phpcmf\ThirdParty' => FCPATH.'ThirdParty',
|
||||
|
||||
'My\Field' => MYPATH.'Field',
|
||||
'My\Library' => MYPATH.'Library',
|
||||
'My\Model' => MYPATH.'Model',
|
||||
]);
|
||||
|
||||
$classmap = [
|
||||
'Phpcmf\App' => CMSPATH.'Core/App.php',
|
||||
'Phpcmf\Table' => CMSPATH.'Core/Table.php',
|
||||
'Phpcmf\Model' => CMSPATH.'Core/Model.php',
|
||||
'Phpcmf\View' => CMSPATH.'Core/View.php',
|
||||
'Phpcmf\Common' => CMSPATH.'Core/Common.php',
|
||||
];
|
||||
|
||||
if (IS_USE_MODULE) {
|
||||
$classmap['Phpcmf\Home\Module'] = IS_USE_MODULE.'Extends/Home/Module.php';
|
||||
$classmap['Phpcmf\Admin\Config'] = IS_USE_MODULE.'Extends/Admin/Config.php';
|
||||
$classmap['Phpcmf\Admin\Module'] = IS_USE_MODULE.'Extends/Admin/Module.php';
|
||||
$classmap['Phpcmf\Model\Content'] = IS_USE_MODULE.'Models/Content.php';
|
||||
$classmap['Phpcmf\Model\Search'] = IS_USE_MODULE.'Models/Search.php';
|
||||
$classmap['Phpcmf\Admin\Category'] = IS_USE_MODULE.'Extends/Admin/Category.php';
|
||||
if (IS_USE_MEMBER) {
|
||||
$classmap['Phpcmf\Member\Module'] = IS_USE_MODULE.'Extends/Member/Module.php';
|
||||
}
|
||||
}
|
||||
|
||||
$auto->classmap = array_merge($auto->classmap, $classmap);
|
||||
|
||||
$local = \Phpcmf\Service::Apps();
|
||||
if ($local) {
|
||||
foreach ($local as $dir => $path) {
|
||||
if (!is_file($path.'install.lock')) {
|
||||
continue;
|
||||
}
|
||||
if (is_file($path.'Config/Auto.php')) {
|
||||
$app_auto = require $path.'Config/Auto.php';
|
||||
isset($app_auto['psr4']) && $app_auto['psr4'] && $auto->psr4 = array_merge($auto->psr4, $app_auto['psr4']);
|
||||
isset($app_auto['classmap']) && $app_auto['classmap'] && $auto->classmap = array_merge($auto->classmap, $app_auto['classmap']);
|
||||
unset($app_auto);
|
||||
}
|
||||
// 加载钩子
|
||||
if (is_file($path.'Config/Hooks.php')) {
|
||||
require $path.'Config/Hooks.php';
|
||||
}
|
||||
// 判断是否存在自定义where
|
||||
if (is_file($path.'Config/Mwhere.php')) {
|
||||
\Phpcmf\Service::Set_Mwhere_App($dir);
|
||||
}
|
||||
// 判断是否存在CSRF白名单
|
||||
if (is_file($path.'Config/Filters.php')) {
|
||||
$Filters = require $path.'Config/Filters.php';
|
||||
if ($Filters) {
|
||||
$Filters['home'] && static::$filters['home'] = array_merge(static::$filters['home'], $Filters['home']);
|
||||
$Filters['member'] && static::$filters['member'] = array_merge(static::$filters['member'], $Filters['member']);
|
||||
$Filters['admin'] && static::$filters['admin'] = array_merge(static::$filters['admin'], $Filters['admin']);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $auto;
|
||||
}
|
||||
|
||||
// 获取应用目录
|
||||
public static function Apps($is_install = 0) {
|
||||
|
||||
$is_install = $is_install ? 1 : 0;
|
||||
|
||||
if (isset(static::$apps[$is_install]) && static::$apps[$is_install]) {
|
||||
return static::$apps[$is_install];
|
||||
}
|
||||
|
||||
static::$apps[$is_install] = [];
|
||||
$source_dir = dr_get_app_list();
|
||||
if ($fp = opendir($source_dir)) {
|
||||
while (FALSE !== ($file = readdir($fp))) {
|
||||
$path = dr_get_app_dir($file);
|
||||
if ($file === '.'
|
||||
OR $file === '..'
|
||||
OR $file === 'Module'
|
||||
OR $file[0] === '.'
|
||||
OR !is_dir($path)) {
|
||||
continue;
|
||||
}
|
||||
if ($is_install && !is_file($path . 'install.lock')) {
|
||||
continue;
|
||||
}
|
||||
static::$apps[$is_install][$file] = $path;
|
||||
}
|
||||
closedir($fp);
|
||||
}
|
||||
|
||||
if (function_exists('dr_get_app_extend')) {
|
||||
$extend = dr_get_app_extend($is_install);
|
||||
if ($extend) {
|
||||
foreach ($extend as $i => $t) {
|
||||
static::$apps[$is_install][$i] = $t;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return static::$apps[$is_install];
|
||||
}
|
||||
|
||||
// 设置mwhere的插件名称
|
||||
public static function Set_Mwhere_App($dir) {
|
||||
static::$mwhere_apps[] = $dir;
|
||||
}
|
||||
|
||||
// 读取mwhere插件名称列表
|
||||
public static function Mwhere_Apps() {
|
||||
return static::$mwhere_apps;
|
||||
}
|
||||
|
||||
// 读取Filters白名单
|
||||
public static function Filters($type = 'auto') {
|
||||
|
||||
if ($type == 'auto') {
|
||||
if (IS_ADMIN) {
|
||||
$type = 'admin';
|
||||
} elseif (IS_MEMBER) {
|
||||
$type = 'member';
|
||||
} else {
|
||||
$type = 'home';
|
||||
}
|
||||
} elseif ($type == '') {
|
||||
return static::$filters;
|
||||
}
|
||||
|
||||
return isset(static::$filters[$type]) ? static::$filters[$type] : [];
|
||||
}
|
||||
|
||||
// 是否是电脑端模板
|
||||
public static function IS_PC_TPL() {
|
||||
return static::V()->is_pc();
|
||||
}
|
||||
public static function IS_PC() {
|
||||
return static::V()->is_pc();
|
||||
}
|
||||
|
||||
// 是否是移动端模板
|
||||
public static function IS_MOBILE_TPL() {
|
||||
return static::V()->is_mobile();
|
||||
}
|
||||
public static function IS_MOBILE() {
|
||||
return static::V()->is_mobile();
|
||||
}
|
||||
|
||||
// 当前客户端是否是移动端访问
|
||||
public static function IS_MOBILE_USER() {
|
||||
return dr_is_mobile();
|
||||
}
|
||||
public static function _is_mobile() {
|
||||
return dr_is_mobile();
|
||||
}
|
||||
|
||||
// 当前客户端是否是PC端访问
|
||||
public static function IS_PC_USER() {
|
||||
return !dr_is_mobile();
|
||||
}
|
||||
|
||||
// 错误日志记录
|
||||
public static function Log($level, $message, array $context = []) {
|
||||
|
||||
if ($level == 'debug' && defined('IS_FB_DEBUG') && IS_FB_DEBUG) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (is_object($message)) {
|
||||
|
||||
$msg = substr((string)$message->getMessage(), 0, 1048576);
|
||||
$code = md5($msg);
|
||||
|
||||
if (is_array( static::$logs) && in_array($code, static::$logs)) {
|
||||
return;
|
||||
}
|
||||
|
||||
static::$logs[] = $code;
|
||||
|
||||
$context['trace'] = $message->getTraceAsString();
|
||||
$context['sql'] = \Phpcmf\Service::M()->get_sql_query();
|
||||
$context['url'] = FC_NOW_URL;
|
||||
$context['user'] = dr_safe_replace($_SERVER['HTTP_USER_AGENT']);
|
||||
$context['referer'] = dr_safe_url($_SERVER['HTTP_REFERER'], true);
|
||||
|
||||
return \Phpcmf\Service::L('input')->log($level, $msg."\n#SQL:{sql}\n#URL:{url}\n#AGENT:{user}\n".($context['referer'] ? "#REFERER:{referer}\n" : "")."{trace}\n", $context);
|
||||
}
|
||||
|
||||
$message.= '---'.FC_NOW_URL.PHP_EOL;
|
||||
return \Phpcmf\Service::L('input')->log($level, $message, $context);
|
||||
}
|
||||
|
||||
/**
|
||||
* 模型类对象实例
|
||||
*
|
||||
* @var object
|
||||
*/
|
||||
public static function model() {
|
||||
|
||||
if (!is_object(static::$model)) {
|
||||
static::$model = new \Phpcmf\Model();
|
||||
}
|
||||
|
||||
return static::$model;
|
||||
}
|
||||
|
||||
/**
|
||||
* 控制器对象实例
|
||||
*
|
||||
* @var object
|
||||
*/
|
||||
public static function C() {
|
||||
return class_exists('\Phpcmf\Common') ? \Phpcmf\Common::get_instance() : null;
|
||||
}
|
||||
|
||||
|
||||
public static function LIC($type = '') {
|
||||
|
||||
if (defined('IS_XRDEV') && IS_XRDEV) {
|
||||
return $type ? 'DR-DEV' : 'DR-DEV';
|
||||
}
|
||||
|
||||
$version = static::R(MYPATH.'Config/Version.php');
|
||||
if ($version && is_array($version)) {
|
||||
if (isset($version['version']) && isset($version['id'])
|
||||
&& is_string($version['version'])
|
||||
&& intval(substr($version['version'], -1)) % 2 == 1
|
||||
&& in_array($version['id'], [18, 16])
|
||||
) {
|
||||
$lic = static::R(MYPATH.'Config/License.php');
|
||||
if ($lic && is_array($lic)) {
|
||||
if (isset($lic['type']) && $lic['type']) {
|
||||
return $type ? (stripos($lic['type'], $type) === false ? '' : $lic['type']) : $lic['type'];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $type ? '' : 'MIT-LICENSE';
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取文件内容
|
||||
*
|
||||
* @var object
|
||||
*/
|
||||
public static function R($file, $clear = false) {
|
||||
|
||||
$_cname = md5($file);
|
||||
|
||||
if (!$clear) {
|
||||
if (isset(static::$require[$_cname])) {
|
||||
return static::$require[$_cname];
|
||||
} elseif (!is_file($file)) {
|
||||
//CI_DEBUG && log_message('debug', '引用文件不存在:'.$file);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
static::$require[$_cname] = require $file;
|
||||
|
||||
return static::$require[$_cname];
|
||||
}
|
||||
|
||||
/**
|
||||
* 模板视图对象实例
|
||||
*
|
||||
* @var object
|
||||
*/
|
||||
public static function V() {
|
||||
|
||||
if (!is_object(static::$view)) {
|
||||
static::$view = new \Phpcmf\View();
|
||||
}
|
||||
|
||||
return static::$view;
|
||||
}
|
||||
|
||||
/**
|
||||
* 类对象实例
|
||||
*
|
||||
* @var object
|
||||
*/
|
||||
public static function L($name, $namespace = '') {
|
||||
|
||||
if (IS_USE_CMS && $namespace == 'module') {
|
||||
$namespace = 'cms';
|
||||
}
|
||||
|
||||
list($classFile, $extendFile, $appFile) = self::_get_class_file($name, $namespace, 'Library');
|
||||
|
||||
$_cname = md5($classFile.$extendFile.$appFile);
|
||||
$className = ucfirst($name);
|
||||
|
||||
if (!isset(static::$instances[$_cname]) or !is_object(static::$instances[$_cname])) {
|
||||
require_once $classFile;
|
||||
// 自定义继承类
|
||||
if ($extendFile && is_file($extendFile)) {
|
||||
if ($namespace && is_file($appFile)) {
|
||||
require $appFile;
|
||||
$newClassName = '\\Phpcmf\\Library\\'.ucfirst($namespace).'\\'.$className;
|
||||
} else {
|
||||
require $extendFile;
|
||||
$newClassName = '\\My\\Library\\'.$className;
|
||||
}
|
||||
} else {
|
||||
$newClassName = '\\Phpcmf\\Library\\'.$className;
|
||||
// 多个应用引用同一个类名称时的区别
|
||||
if ($namespace) {
|
||||
$newClassName2 = '\\Phpcmf\\Library\\'.ucfirst($namespace).'\\'.$className;
|
||||
if (class_exists($newClassName2)) {
|
||||
static::$instances[$_cname] = new $newClassName2();
|
||||
return static::$instances[$_cname];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static::$instances[$_cname] = new $newClassName();
|
||||
}
|
||||
|
||||
return static::$instances[$_cname];
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 模型对象实例
|
||||
*
|
||||
* @var object
|
||||
*/
|
||||
public static function M($name = '', $namespace = '') {
|
||||
|
||||
if (!$name) {
|
||||
return static::model();
|
||||
}
|
||||
|
||||
$className = ucfirst($name);
|
||||
if (!$namespace) {
|
||||
switch ($className) {
|
||||
|
||||
case 'Content':
|
||||
if (!IS_USE_MODULE) {
|
||||
\dr_exit_msg(0, '没有安装「建站系统」插件');
|
||||
}
|
||||
$namespace = 'cms';
|
||||
break;
|
||||
|
||||
case 'Search':
|
||||
if (!IS_USE_MODULE) {
|
||||
\dr_exit_msg(0, '没有安装「建站系统」插件');
|
||||
}
|
||||
$namespace = 'cms';
|
||||
break;
|
||||
|
||||
case 'Category':
|
||||
if (!IS_USE_MODULE) {
|
||||
\dr_exit_msg(0, '没有安装「建站系统」插件');
|
||||
}
|
||||
$namespace = 'cms';
|
||||
break;
|
||||
|
||||
case 'Module':
|
||||
if (!IS_USE_MODULE) {
|
||||
\dr_exit_msg(0, '没有安装「建站系统」插件');
|
||||
}
|
||||
$namespace = 'cms';
|
||||
break;
|
||||
|
||||
case 'Pay':
|
||||
if (!dr_is_app('pay')) {
|
||||
\dr_exit_msg(0, '没有安装「支付系统」插件');
|
||||
}
|
||||
$namespace = 'pay';
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
if (IS_USE_MODULE && in_array($className, ['Content', 'Search'])
|
||||
&& !is_file(dr_get_app_dir($namespace).'Models/'.$className.'.php')) {
|
||||
$namespace = 'cms';
|
||||
}
|
||||
}
|
||||
|
||||
if (IS_USE_CMS && $namespace == 'module') {
|
||||
$namespace = 'cms';
|
||||
}
|
||||
|
||||
list($classFile, $extendFile, $appFile) = self::_get_class_file($name, $namespace, 'Model');
|
||||
|
||||
$_cname = md5($classFile.$extendFile.$appFile);
|
||||
|
||||
if (!isset(static::$instances[$_cname]) or !is_object(static::$instances[$_cname])) {
|
||||
require_once $classFile;
|
||||
// 自定义继承类
|
||||
if ($extendFile && is_file($extendFile)) {
|
||||
if ($namespace && is_file($appFile)) {
|
||||
require_once $appFile;
|
||||
$newClassName = '\\Phpcmf\\Model\\'.ucfirst($namespace).'\\'.$className;
|
||||
} else {
|
||||
require $extendFile;
|
||||
$newClassName = '\\My\\Model\\'.$className;
|
||||
}
|
||||
} else {
|
||||
$newClassName = '\\Phpcmf\\Model\\'.$className;
|
||||
// 多个应用引用同一个类名称时的区别
|
||||
if ($namespace) {
|
||||
$newClassName2 = '\\Phpcmf\\Model\\'.ucfirst($namespace).'\\'.$className;
|
||||
if (class_exists($newClassName2)) {
|
||||
static::$instances[$_cname] = new $newClassName2();
|
||||
return static::$instances[$_cname];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static::$instances[$_cname] = new $newClassName();
|
||||
}
|
||||
|
||||
return static::$instances[$_cname];
|
||||
}
|
||||
|
||||
/**
|
||||
* 引用应用的helper
|
||||
*/
|
||||
public static function H($name, $namespace) {
|
||||
|
||||
if (IS_USE_CMS && $namespace == 'module') {
|
||||
$namespace = 'cms';
|
||||
}
|
||||
|
||||
$file = dr_get_app_dir($namespace).'Helpers/'.ucfirst($name).'.php';
|
||||
$_cname = md5($file);
|
||||
if (isset(static::$help[$_cname])) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!is_file($file)) {
|
||||
self::_error('函数文件:'.str_replace(FCPATH, '', $file).'不存在');
|
||||
}
|
||||
|
||||
static::$help[$_cname] = 1;
|
||||
|
||||
require $file;
|
||||
}
|
||||
|
||||
// 获取类文件路径
|
||||
private static function _get_class_file($name, $namespace, $class) {
|
||||
|
||||
$className = ucfirst($name);
|
||||
$classFile = CMSPATH.$class.'/'.$className.'.php';
|
||||
|
||||
// 自定义继承类文件
|
||||
$extendFile = MYPATH.$class.'/'.$className.'.php';
|
||||
|
||||
// 当前是app时优先考虑本级继承目录文件
|
||||
if ($namespace) {
|
||||
if (IS_USE_CMS && $namespace == 'module') {
|
||||
$namespace = 'cms';
|
||||
}
|
||||
$appFile = dr_get_app_dir($namespace).($class == 'Library' ? 'Librarie' : $class ).'s/'.$className.'.php';
|
||||
} else {
|
||||
$appFile = '';
|
||||
}
|
||||
|
||||
if (!is_file($extendFile) && $namespace) {
|
||||
// 当前是app时优先考虑本级继承目录文件
|
||||
$extendFile = $appFile;
|
||||
}
|
||||
|
||||
if (!is_file($classFile)) {
|
||||
// 相对于APP目录
|
||||
if ($namespace) {
|
||||
$classFile = $appFile;
|
||||
$extendFile = '';
|
||||
} else if (is_file($extendFile)) {
|
||||
$classFile = $extendFile;
|
||||
$extendFile = '';
|
||||
}
|
||||
// 都不存在就报错
|
||||
if (!$classFile || !is_file($classFile)) {
|
||||
self::_error('类文件:'.str_replace(FCPATH, '', $classFile).'不存在');
|
||||
}
|
||||
}
|
||||
|
||||
return [$classFile, $extendFile, $appFile];
|
||||
}
|
||||
|
||||
// 错误输出
|
||||
private static function _error($msg) {
|
||||
|
||||
if (defined('IS_API_HTTP') && IS_API_HTTP) {
|
||||
log_message('error', $msg . '('.FC_NOW_URL.')');
|
||||
\Phpcmf\Service::C()->_json(0, $msg); // api输出格式
|
||||
} else {
|
||||
// 报系统故障
|
||||
dr_show_error($msg);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user