diff --git a/Plugin.php b/Plugin.php index dcf3fc9..a3e0ad0 100644 --- a/Plugin.php +++ b/Plugin.php @@ -10,14 +10,43 @@ use OSS\Core\OssException; * * @package AliOssForTypecho * @author droomo. - * @version 1.1.5 + * @version 1.1.6 * @link https://www.droomo.top/ */ -class AliOssForTypecho_Plugin implements Typecho_Plugin_Interface -{ + +class AliOssForTypecho_Plugin extends Typecho_Widget implements Typecho_Plugin_Interface { + const UPLOAD_DIR = 'usr/uploads/';//上传文件目录,相对网站根目录 const LOG_SUFFIX = '__oss-plugin-log/';//日志目录,放置于UPLOAD_DIR下 + public function api_version() { + echo __FUNCTION__; + var_dump (self::get_plugin_information()['version']); + } + public function api_log() { + if ($_SERVER['REQUEST_METHOD'] == 'GET') { + } else { + } + } + + public static function get_plugin_information() { + Typecho_Widget::widget('Widget_Plugins_List@activated', 'activated=1')->to($activatedPlugins); + $activatedPlugins = json_decode(json_encode($activatedPlugins),true); + $plugins_list = $activatedPlugins['stack']; + $plugins_info = array(); + for ($i = 0; $i < count($plugins_list); $i++){ + if($plugins_list[$i]['title'] == 'AliOssForTypecho'){ + $plugins_info = $plugins_list[$i]; + break; + } + } + if (count($plugins_info) < 1) { + return false; + } + return $plugins_info; + } + + /** * 激活插件方法,如果激活失败,直接抛出异常 * @@ -25,14 +54,16 @@ class AliOssForTypecho_Plugin implements Typecho_Plugin_Interface * @return void * @throws Typecho_Plugin_Exception */ - public static function activate() - { + public static function activate() { Typecho_Plugin::factory('Widget_Upload')->uploadHandle = array('AliOssForTypecho_Plugin', 'uploadHandle'); Typecho_Plugin::factory('Widget_Upload')->modifyHandle = array('AliOssForTypecho_Plugin', 'modifyHandle'); Typecho_Plugin::factory('Widget_Upload')->deleteHandle = array('AliOssForTypecho_Plugin', 'deleteHandle'); Typecho_Plugin::factory('Widget_Upload')->attachmentHandle = array('AliOssForTypecho_Plugin', 'attachmentHandle'); Typecho_Plugin::factory('Widget_Upload')->attachmentDataHandle = array('AliOssForTypecho_Plugin', 'attachmentDataHandle'); + Helper::addRoute('__alioss_for_tp_plugin_version__', '/__alioss_for_tp_plugin_api__/version', 'AliOssForTypecho_Plugin', 'api_version'); + Helper::addRoute('__alioss_for_tp_plugin_log__', '/__alioss_for_tp_plugin_api__/log', 'AliOssForTypecho_Plugin', 'api_log'); + return _t('启用成功,请进行相应设置!'); } @@ -44,7 +75,10 @@ class AliOssForTypecho_Plugin implements Typecho_Plugin_Interface * @return void * @throws Typecho_Plugin_Exception */ - public static function deactivate(){} + public static function deactivate() { + Helper::removeRoute('__alioss_for_tp_plugin_version__'); + Helper::removeRoute('__alioss_for_tp_plugin_log__'); + } /** * 获取插件配置面板 @@ -53,8 +87,7 @@ class AliOssForTypecho_Plugin implements Typecho_Plugin_Interface * @param Typecho_Widget_Helper_Form $form 配置面板 * @return void */ - public static function config(Typecho_Widget_Helper_Form $form) - { + public static function config(Typecho_Widget_Helper_Form $form) { $upload_root = Typecho_Common::url(defined('__TYPECHO_UPLOAD_DIR__') ? __TYPECHO_UPLOAD_DIR__ : self::UPLOAD_DIR, defined('__TYPECHO_UPLOAD_ROOT_DIR__') ? __TYPECHO_UPLOAD_ROOT_DIR__ : __TYPECHO_ROOT_DIR__); @@ -99,7 +132,6 @@ class AliOssForTypecho_Plugin implements Typecho_Plugin_Interface addInput($buketName->addRule('required', _t('必须填写Bucket名称'))); @@ -172,7 +204,7 @@ class AliOssForTypecho_Plugin implements Typecho_Plugin_Interface ?>