Skip to content

Commit

Permalink
更新至1.1.4版本
Browse files Browse the repository at this point in the history
  • Loading branch information
jzwalk committed Jun 10, 2020
1 parent de84586 commit aba159c
Show file tree
Hide file tree
Showing 19 changed files with 1,303 additions and 6,846 deletions.
852 changes: 499 additions & 353 deletions Action.php

Large diffs are not rendered by default.

21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2018-2020 Yuzhong Zheng (jzwalk)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
302 changes: 146 additions & 156 deletions Plugin.php
Original file line number Diff line number Diff line change
@@ -1,176 +1,166 @@
<?php
if (!defined('__TYPECHO_ROOT_DIR__')) exit;
/**
* 通过读取html表格实现插件仓库的下载、安装及卸载等功能
* 读取Github上维护的专用表格实现插件仓库各项功能
*
* @package TeStore
* @author 羽中, zhulin3141
* @version 1.1.2
* @link http://www.yzmb.me
* @version 1.1.4
* @dependence 13.12.12-*
* @link https://www.yzmb.me/archives/net/testore-for-typecho
* @copyright Copyright (c) 2014-2020 Yuzhong Zheng (jzwalk)
* @license MIT
*/
class TeStore_Plugin implements Typecho_Plugin_Interface
{
/**
* 激活插件方法,如果激活失败,直接抛出异常
*
* @access public
* @return void
* @throws Typecho_Plugin_Exception
*/
public static function activate()
{
$tempDir = __TYPECHO_ROOT_DIR__.__TYPECHO_PLUGIN_DIR__.'/TeStore/.tmp';
$dataDir = __TYPECHO_ROOT_DIR__.__TYPECHO_PLUGIN_DIR__.'/TeStore/data';

/**
* 激活插件方法,如果激活失败,直接抛出异常
*
* @access public
* @return void
* @throws Typecho_Plugin_Exception
*/
public static function activate()
{
$tempDir = __TYPECHO_ROOT_DIR__ . __TYPECHO_PLUGIN_DIR__ . '/TeStore/.tmp';
$dataDir = __TYPECHO_ROOT_DIR__ . __TYPECHO_PLUGIN_DIR__ . '/TeStore/data';
if (!class_exists('ZipArchive')) {
return _t('主机未安装ZipArchive扩展, 无法安装插件');
}

if ( ! is_dir($tempDir) and ! @mkdir($tempDir) ) {
throw new Typecho_Plugin_Exception('无法创建临时目录.');
}
if (!is_dir($tempDir) && !@mkdir($tempDir)) {
throw new Typecho_Plugin_Exception('无法创建临时目录.');
}

if( ! self::testWrite($tempDir) ){
throw new Typecho_Plugin_Exception('.tmp目录没有写入的权限');
}
if(!self::testWrite($tempDir)){
throw new Typecho_Plugin_Exception('.tmp目录没有写入权限');
}

if ( ! file_exists($dataDir) and ! @mkdir($dataDir) ) {
throw new Typecho_Plugin_Exception('无法创建缓存目录.');
}
Typecho_Plugin::factory('admin/menu.php')->navBar = array('TeStore_Plugin','render');
Helper::addPanel(1,'TeStore/market.php',_t('TE插件仓库'),_t('TE插件仓库'),'administrator');
Helper::addRoute('te-store_market',__TYPECHO_ADMIN_DIR__.'te-store/market','TeStore_Action','market');
Helper::addRoute('te-store_install',__TYPECHO_ADMIN_DIR__.'te-store/install','TeStore_Action','install');
Helper::addRoute('te-store_uninstall',__TYPECHO_ADMIN_DIR__.'te-store/uninstall','TeStore_Action','uninstall');
}

if( ! self::testWrite($dataDir) ){
throw new Typecho_Plugin_Exception('data目录没有写入的权限');
}
/**
* 禁用插件方法,如果禁用失败,直接抛出异常
*
* @static
* @access public
* @return void
* @throws Typecho_Plugin_Exception
*/
public static function deactivate()
{
Helper::removePanel(1,'TeStore/market.php');
Helper::removeRoute('te-store_market');
Helper::removeRoute('te-store_install');
Helper::removeRoute('te-store_uninstall');
}

Typecho_Plugin::factory('admin/menu.php')->navBar = array('TeStore_Plugin', 'render');
Helper::addPanel(1, 'TeStore/market.php', 'TE插件仓库', 'TE插件仓库', 'administrator');
Helper::addRoute('te-store_market', __TYPECHO_ADMIN_DIR__ . 'te-store/market', 'TeStore_Action', 'market');
Helper::addRoute('te-store_install', __TYPECHO_ADMIN_DIR__ . 'te-store/install', 'TeStore_Action', 'install');
Helper::addRoute('te-store_uninstall', __TYPECHO_ADMIN_DIR__ . 'te-store/uninstall', 'TeStore_Action', 'uninstall');
}

/**
* 禁用插件方法,如果禁用失败,直接抛出异常
*
* @static
* @access public
* @return void
* @throws Typecho_Plugin_Exception
*/
public static function deactivate(){
Helper::removePanel(1, 'TeStore/market.php');
Helper::removeRoute('te-store_market');
Helper::removeRoute('te-store_install');
Helper::removeRoute('te-store_uninstall');
}

/**
* 获取插件配置面板
*
* @access public
* @param Typecho_Widget_Helper_Form $form 配置面板
* @return void
*/
public static function config(Typecho_Widget_Helper_Form $form)
{
//源文件地址
$source = new Typecho_Widget_Helper_Form_Element_Textarea('source', NULL, 'https://github.com/typecho-fans/plugins/blob/master/TESTORE.md' . PHP_EOL . 'https://github.com/typecho-fans/plugins/blob/master/README.md', _t('插件信息源'),
_t('应为可公开访问且包含准确表格内容的页面地址, 每行一个, 例: ') . '<br/>
<strong><a href="https://github.com/typecho-fans/plugins/blob/master/README.md">https://github.com/typecho-fans/plugins/blob/master/README.md</a> - <span class="warning">' . _t('Typecho-Fans插件集群索引(社区维护版目录)') . '</span><br/>
<a href="https://github.com/typecho-fans/plugins/blob/master/TESTORE.md">https://github.com/typecho-fans/plugins/blob/master/TESTORE.md</a> - <span class="warning">' . _t('Typecho-Fans外部插件登记表(TeStore专用)') . '</span></strong><br/>
' . _t('以上Markdown格式文件可以在Github上方便地进行多人修改更新, 参与方式详见文件说明'));
$source->addRule('required',_t('源文件地址不能为空'));
$form->addInput($source);
/**
* 获取插件配置面板
*
* @access public
* @param Typecho_Widget_Helper_Form $form 配置面板
* @return void
*/
public static function config(Typecho_Widget_Helper_Form $form)
{
$source = new Typecho_Widget_Helper_Form_Element_Textarea('source',
NULL,'https://github.com/typecho-fans/plugins/blob/master/TESTORE.md'.PHP_EOL.'https://github.com/typecho-fans/plugins/blob/master/README.md',_t('插件信息来源'),
_t('应为可公开访问且包含符合本插件规定表格内容的页面地址, 每行一个, 默认: ').'<br/>
<strong><a href="https://github.com/typecho-fans/plugins/blob/master/README.md">https://github.com/typecho-fans/plugins/blob/master/README.md</a> - <span class="warning">'._t('Typecho-Fans内部插件索引(社区维护版列表)').'</span><br/>
<a href="https://github.com/typecho-fans/plugins/blob/master/TESTORE.md">https://github.com/typecho-fans/plugins/blob/master/TESTORE.md</a> - <span class="warning">'._t('Typecho-Fans外部插件登记表(TeStore专用)').'</span></strong><br/>
'._t('以上Markdown语法文件在Github上由多人共同维护, 参与方式详见文件说明'));
$source->addRule('required',_t('文件地址不能为空'));
$form->addInput($source);

//缓存设置
$cache = new Typecho_Widget_Helper_Form_Element_Select('cache_time',
array(
'0'=>_t('不缓存'),
'6'=>_t('6小时'),
'12'=>_t('12小时'),
'24'=>_t('1天'),
'72'=>_t('3天'),
'168'=>_t('1周')
),
'24',
_t('缓存时间'),
_t('列表数据的缓存时间')
);
$form->addInput($cache);
$cache = new Typecho_Widget_Helper_Form_Element_Select('cache_time',
array(
'0'=>_t('不缓存'),
'6'=>_t('6小时'),
'12'=>_t('12小时'),
'24'=>_t('1天'),
'72'=>_t('3天'),
'168'=>_t('1周')
),
'24',_t('数据缓存时限'),_t('设置本地缓存数据时间'));
$form->addInput($cache);

$curl = new Typecho_Widget_Helper_Form_Element_Checkbox(
'curl',
array(
1 => ''
),
0,
_t('使用curl下载'),
'默认file_get_contents方式无效时可尝试'
);
$form->addInput($curl);
$proxy = new Typecho_Widget_Helper_Form_Element_Radio('proxy',
array(''=>_t(''),'cdn.jsdelivr.net/gh'=>_t('jsDelivr镜像'),'gitcdn.xyz/repo'=>_t('GitCDN镜像1'),'gitcdn.link/repo'=>_t('GitCDN镜像2')),'',_t('使用代理加速'),_t('GitHub连接不畅时可选'));
$form->addInput($proxy);

$showNavMenu = new Typecho_Widget_Helper_Form_Element_Radio(
'showNavMenu' ,
array(
'true' => _t(''),
'false' => _t(''),
),
'true' ,
_t('显示导航条按钮')
);
$form->addInput($showNavMenu);
}

/**
* 检查curl支持
*
* @param array $settings
* @return string
*/
public static function configCheck(array $settings)
{
if ( $settings['curl'] && !extension_loaded('curl') ) {
return _t('主机没有安装curl扩展');
}
}

/**
* 个人用户的配置面板
*
* @access public
* @param Typecho_Widget_Helper_Form $form
* @return void
*/
public static function personalConfig(Typecho_Widget_Helper_Form $form){}
$curl = new Typecho_Widget_Helper_Form_Element_Checkbox('curl',
array(1=>''),0, _t('cURL方式下载'),_t('默认方式无效时可尝试'));
$form->addInput($curl);

/**
* 插件实现方法
*
* @access public
* @return void
*/
public static function render()
{
$options = Helper::options();
$pluginOpts = Typecho_Widget::widget('Widget_Options')->plugin('TeStore');
if( $pluginOpts->showNavMenu == 'true' ){
echo '<a href="';
$options->adminUrl('extending.php?panel=TeStore%2Fmarket.php');
echo '"><span class="message success"><i class="mime-script"></i>' . _t('TE插件仓库') . '</span></a>';
}
}
$showNavMenu = new Typecho_Widget_Helper_Form_Element_Radio('showNavMenu',
array(1=>_t('显示'),0=>_t('关闭')),1,_t('导航快捷按钮'));
$form->addInput($showNavMenu);
}

/**
* 判断目录是否可写
*/
public static function testWrite($dir) {
$testFile = "_test.txt";
$fp = @fopen($dir . "/" . $testFile, "w");
if (!$fp) {
return false;
}
fclose($fp);
$rs = @unlink($dir . "/" . $testFile);
if ($rs) {
return true;
}
return false;
}
}
/**
* 检查cURL支持
*
* @param array $settings
* @return string
*/
public static function configCheck(array $settings)
{
if (!class_exists('ZipArchive')) {
return _t('主机未安装ZipArchive扩展, 无法安装插件');
}
if ($settings['curl'] && !extension_loaded('curl')) {
return _t('主机未安装cURL扩展, 无法使用此方式下载');
}
}

/**
* 个人用户的配置面板
*
* @access public
* @param Typecho_Widget_Helper_Form $form
* @return void
*/
public static function personalConfig(Typecho_Widget_Helper_Form $form){}

/**
* 输出导航按钮
*
* @access public
* @return void
*/
public static function render()
{
$options = Helper::options();
if ($options->plugin('TeStore')->showNavMenu && Typecho_Widget::widget('Widget_User')->pass('administrator',true)){
echo '<a href="'.$options->adminUrl.'extending.php?panel=TeStore%2Fmarket.php"><span class="message notice"><i class="mime-script"></i>'._t('TE插件仓库').'</span></a>';
}
}

/**
* 判断目录可写
*
* @access public
* @return boolean
*/
public static function testWrite($dir)
{
$testFile = "_test.txt";
$fp = @fopen($dir."/".$testFile,"w");
if (!$fp) {
return false;
}
fclose($fp);
$rs = @unlink($dir."/".$testFile);
if ($rs) {
return true;
}
return false;
}

}
24 changes: 20 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,22 @@
### 新Github表格解析版插件仓库插件TeStore v1.1.2
### 新GitHub表格解析版插件仓库TeStore v1.1.4

重新以免服务端思路复活这款经典插件,可通过读取html表格实现插件仓库的下载、安装及卸载等功能。
以免服务端思路复活这款插件,通过读取GitHub上的专用表格实现插件仓库的搜索、下载和安装删除功能。

- v1.1.4(20-5-17):

1. 列表页面顶部增加点击标签,已安装插件可分页显示,列表附注图标更新为更清晰的SVG格式;

2. 操作按钮样式和反馈提示效果沿用系统风格,提交方式由ajax改为同步post,移除原sticky效果;

3. 安装过程增加目录检测和升级清理,移除pclzip使用PHP原生解压缩方法,data改为常规目录等。

- v1.1.3(20-5-15):

1. 修正冗余代码增强可读性,修复非管理员用户可查看列表bug,修复同名插件只安装第一个bug;

2. 支持jsDelivr/GitCDN镜像替换raw文件地址加速,表格或zip包链接为raw文件地址时自动加速;

3. API检测ZIP_CDN目录,同步按期限缓存,镜像开启时优先下载ZIP_CDN内的raw文件加速地址。

- v1.1.2(18-8-20):

Expand All @@ -18,9 +34,9 @@

3. 列表加载异步化,字母排序已安装自动提前,支持分页和按简介筛选,支持图标及版本升级提醒。

- v1.0.0(14-11-13):([@zhulin3141](http://zhulin31410.blog.163.com/)
- v1.0.0(14-11-13):([@zhulin3141](https://github.com/zhulin3141)

通过正则匹配读取新浪云服务端页面,建立ajax下载、安装和卸载等机制,列表支持缓存和名称筛选。
正则匹配读取新浪云服务端页面,ajax方式实现下载、安装及卸载功能,列表支持缓存和名称筛选。

###### 更多详见作者博客:http://www.yzmb.me/archives/net/testore-for-typecho
###### 或可查看论坛原帖:http://forum.typecho.org/viewtopic.php?f=6&t=11097
5 changes: 5 additions & 0 deletions data/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
MPL-2.0 License

Copyright (c) 1998–2020 Mozilla Foundation

The file cacert.pem in this directory is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.
Loading

0 comments on commit aba159c

Please sign in to comment.