-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlugin.php
More file actions
101 lines (82 loc) · 2.6 KB
/
Copy pathPlugin.php
File metadata and controls
101 lines (82 loc) · 2.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<?php
/**
* 媒体预览(支持本地、腾讯COS、阿里云OSS、缤纷云、又拍云和兰空图床)
* @package TEMediaFolder
* @author 森木志
* @version 3.4.0
* @link https://github.com/SurGarfield/TEMediaFolder
*/
namespace TypechoPlugin\TEMediaFolder;
use Typecho\Plugin\PluginInterface;
use TypechoPlugin\TEMediaFolder\Core\ActionRegistry;
use TypechoPlugin\TEMediaFolder\Core\ConfigManager;
use TypechoPlugin\TEMediaFolder\Core\Renderer;
use TypechoPlugin\TEMediaFolder\Config\ConfigForm;
if (!defined('__TYPECHO_ROOT_DIR__')) {
exit;
}
// 自动加载类文件
spl_autoload_register(function ($class) {
if (strpos($class, 'TypechoPlugin\\TEMediaFolder\\') === 0) {
$path = str_replace('TypechoPlugin\\TEMediaFolder\\', '', $class);
$path = str_replace('\\', DIRECTORY_SEPARATOR, $path);
$dir = dirname($path);
$dir = implode(DIRECTORY_SEPARATOR, array_map('strtolower', explode(DIRECTORY_SEPARATOR, $dir)));
$file = __DIR__ . DIRECTORY_SEPARATOR . $dir . DIRECTORY_SEPARATOR . basename($path) . '.php';
if (file_exists($file)) {
require_once $file;
}
}
});
class Plugin implements PluginInterface
{
/**
* 激活插件
*/
public static function activate()
{
\Typecho\Plugin::factory('admin/write-post.php')->bottom = [__CLASS__, 'render'];
\Typecho\Plugin::factory('admin/write-page.php')->bottom = [__CLASS__, 'render'];
foreach (ActionRegistry::getActionNames() as $actionName) {
\Utils\Helper::addAction($actionName, 'TEMediaFolder_Action');
}
}
/**
* 禁用插件
*/
public static function deactivate()
{
if (class_exists('Utils\Helper')) {
foreach (ActionRegistry::getActionNames() as $actionName) {
\Utils\Helper::removeAction($actionName);
}
}
}
/**
* 插件配置
*/
public static function config(\Typecho\Widget\Helper\Form $form)
{
ConfigForm::build($form);
}
/**
* 个性化配置
*/
public static function personalConfig(\Typecho\Widget\Helper\Form $form)
{
// 先留着,方便后续拓展,暂时没有想到啥个性化配置
}
public static function render($post)
{
try {
$config = ConfigManager::getInstance();
if (!$config->isEnabled()) {
return;
}
$renderer = new Renderer($config);
$renderer->render();
} catch (\Exception $e) {
// 渲染错误处理
}
}
}