mirror of
https://github.com/tursom/typecho-plugin-Access.git
synced 2024-12-25 20:30:32 +08:00
添加自动加载类 Access_Autoloader
This commit is contained in:
parent
ddcfe30466
commit
0aa76d751e
28
Access_Autoloader.php
Normal file
28
Access_Autoloader.php
Normal file
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
if (!defined('__ACCESS_PLUGIN_ROOT__')) {
|
||||
throw new Exception('Boostrap file not found');
|
||||
}
|
||||
|
||||
class Access_Autoloader
|
||||
{
|
||||
public static function autoloader($class)
|
||||
{
|
||||
if (strpos($class, 'Access') !== 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
$file = __ACCESS_PLUGIN_ROOT__ . '/' . $class . '.php';
|
||||
if (file_exists($file)) {
|
||||
require_once $file;
|
||||
}
|
||||
}
|
||||
|
||||
public static function register()
|
||||
{
|
||||
if (function_exists('spl_autoload_register')) {
|
||||
spl_autoload_register(array('Access_Autoloader', 'autoloader'));
|
||||
} else {
|
||||
throw new Typecho_Plugin_Exception(_t('php版本过低,最低要求>=5.3.0'));
|
||||
}
|
||||
}
|
||||
}
|
@ -1,6 +1,5 @@
|
||||
<?php
|
||||
define('__ACCESS_PLUGIN_ROOT__', __DIR__);
|
||||
|
||||
foreach (glob(__ACCESS_PLUGIN_ROOT__ . '/Access_*.php') as $filePath) {
|
||||
require_once $filePath;
|
||||
}
|
||||
require_once __ACCESS_PLUGIN_ROOT__ . '/Access_Autoloader.php';
|
||||
Access_Autoloader::register();
|
||||
|
@ -10,7 +10,8 @@ class Access_Action implements Widget_Interface_Do
|
||||
{
|
||||
$this->response = Typecho_Response::getInstance();
|
||||
$this->request = Typecho_Request::getInstance();
|
||||
require_once __DIR__ . '/Access_Bootstrap.php';
|
||||
require_once __DIR__ . '/Access_Autoloader.php';
|
||||
Access_Autoloader::register();
|
||||
$this->access = new Access_Core();
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/Access_Bootstrap.php';
|
||||
/**
|
||||
* 获取访客信息,生成统计图表,由<a href="https://zhaiyiming.com/">@一名宅</a> 部分优化重构。
|
||||
*
|
||||
@ -131,7 +132,6 @@ class Access_Plugin implements Typecho_Plugin_Interface
|
||||
}
|
||||
# 处理旧版本数据
|
||||
if ($db->fetchRow($db->query("SHOW TABLES LIKE '{$prefix}access';", Typecho_Db::READ))) {
|
||||
require_once __DIR__ . '/Access_Bootstrap.php';
|
||||
$rows = $db->fetchAll($db->select()->from('table.access'));
|
||||
foreach ($rows as $row) {
|
||||
$ua = new Access_UA($row['ua']);
|
||||
@ -176,7 +176,6 @@ class Access_Plugin implements Typecho_Plugin_Interface
|
||||
*/
|
||||
public static function backend($archive)
|
||||
{
|
||||
require_once __DIR__ . '/Access_Bootstrap.php';
|
||||
$access = new Access_Core();
|
||||
$config = Typecho_Widget::widget('Widget_Options')->plugin('Access');
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user