Skip to content

Commit

Permalink
TeStore:更新版本,修正多处兼容性问题。
Browse files Browse the repository at this point in the history
  • Loading branch information
jzwalk committed Aug 6, 2018
1 parent 65455e7 commit 4c8ef98
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 65 deletions.
109 changes: 62 additions & 47 deletions TeStore/Action.php
Expand Up @@ -87,19 +87,19 @@ public function getPluginData($name='')
{
$json = $this->cacheDir . 'list.json';
//读取缓存文件
if ( $this->cacheTime && is_file($json) && (time() - filemtime($json)) <= $this->cacheTime * 3600 ) {
if( $this->cacheTime && is_file($json) && (time() - filemtime($json)) <= $this->cacheTime * 3600 ){
$data = file_get_contents($this->cacheDir . 'list.json');
$this->pluginInfo = json_decode($data);
}else{
$html = '';
$html = '<?xml encoding="utf-8" ?>';
foreach($this->source as $page){
$page = trim($page);
if ($page) {
if( $page ){
$html .= @file_get_contents($page);
}
}
//解析表格内容
if ($html) {
if( $html !== '<?xml encoding="utf-8" ?>' ){
$dom = new DOMDocument();
@$dom->loadHTML($html);
$tr = $dom->getElementsByTagName("tr");
Expand All @@ -116,7 +116,7 @@ public function getPluginData($name='')
$a = $td->item($tdKey)->getElementsByTagName("a");
$href = $a->item(0)->getAttribute("href");
//处理多作者链接
if ( $tdKey==3 ) {
if( $tdKey==3 ){
$href = '';
foreach( $a as $a ){
$href .= ', ' . $a->getAttribute('href');
Expand Down Expand Up @@ -146,7 +146,7 @@ public function getPluginData($name='')
//生成缓存文件
if($this->cacheTime) {
$pluginInfo = json_encode($this->pluginInfo);
if (!is_dir($this->cacheDir)) @mkdir($this->cacheDir);
if( ! is_dir($this->cacheDir) ) @mkdir($this->cacheDir);
file_put_contents($this->cacheDir . 'list.json', $pluginInfo);
}
}
Expand Down Expand Up @@ -191,57 +191,67 @@ public function install()

$ret = array(
'status' => false,
'error' => '',
'error' => ''
);

if ($plugin) {
if($plugin){
$pluginInfo = $this->getPluginData($plugin);
$tempdir = $this->pluginRoot . '/TeStore/.tmp';
$tempFile = $tempdir. '/' . $plugin . '.zip';
$activated = $this->getActivePlugins();

if( in_array($plugin, $activated) ){
$ret['error'] = _t('请先禁用该插件');
}elseif( false !== $pluginInfo ){
if (!is_dir($tempdir)) @mkdir($tempdir);
$zipFile = file_get_contents($pluginInfo->zipFile);
file_put_contents( $tempFile, $zipFile );

$unzip = new PclZip($tempFile);
if( ! $unzip->extract(PCLZIP_OPT_PATH, $tempdir)===0 ){
$ret['error'] = $unzip->errorInfo(true);
} else {
@unlink($tempFile);
//遍历解压文件层级
foreach( new RecursiveIteratorIterator(new RecursiveDirectoryIterator($tempdir)) as $filename ){
if (!is_dir($filename)) {
$scans[] = $filename;
}
}
//处理单文件型插件
if ( count($scans)==1 && !strpos($scans[0], 'Plugin.php') ) {
rename($scans[0], $this->pluginRoot. '/' . basename($scans[0]));
$ret['status'] = true;
} else {
//以Plugin.php确定目录
foreach($scans as $scan){
if(strpos($scan, 'Plugin.php')){
$truedir = dirname($scan);
}elseif( $pluginInfo ){
$tempdir = $this->pluginRoot . '/TeStore/.tmp';
$tempFile = $tempdir. '/' . $plugin . '.zip';
if( ! is_dir($tempdir) ) @mkdir($tempdir);
$zipFile = @file_get_contents($pluginInfo->zipFile);
if( ! file_put_contents( $tempFile, $zipFile ) ){
$ret['error'] = _t('下载zip包出错');
}else{
$unzip = new PclZip($tempFile);
if( ! $unzip->extract(PCLZIP_OPT_PATH, $tempdir)===0 ){
$ret['error'] = $unzip->errorInfo(true);
}else{
@unlink($tempFile);
//遍历解压文件层级
foreach( new RecursiveIteratorIterator(new RecursiveDirectoryIterator($tempdir)) as $filename ){
if( ! is_dir($filename) ){
$scans[] = $filename;
}
}
if (isset($truedir)) {
//处理单文件型插件
if( count($scans)==1 && !strpos($scans[0], 'Plugin.php') ){
if( ! rename($scans[0], $this->pluginRoot. '/' . basename($scans[0])) ){
$ret['error'] = _t('移动文件出错');
}else{
$ret['status'] = true;
}
}else{
//以Plugin.php确定目录
foreach($scans as $scan){
//按插件名创建目录
$tar = str_replace(( strpos($scan, $truedir)===0 ? $truedir : $tempdir ), $this->pluginRoot. '/' . $plugin, $scan);
$tar_dir = dirname($tar);
if (!is_dir($tar_dir)) @mkdir($tar_dir, 0777, true);
rename($scan, $tar);
if(strpos($scan, 'Plugin.php')){
$truedir = dirname($scan);
}
}
if( isset($truedir) ){
foreach($scans as $scan){
//按插件名创建目录
$tar = str_replace(( strpos($scan, $truedir)===0 ? $truedir : $tempdir ), $this->pluginRoot. '/' . $plugin, $scan);
$tar_dir = dirname($tar);
if( ! is_dir($tar_dir) ) @mkdir($tar_dir, 0777, true);
if( ! rename($scan, $tar) ){
$error = error_get_last();
$ret['error'] = $error['message'];
}
}
$ret['status'] = true;
@$this->delTree($tempdir, true);
}
$ret['status'] = true;
@$this->delTree($tempdir, true);
}
}
}
}else{
$ret['error'] = _t('没有找到插件信息');
}
}

Expand All @@ -260,7 +270,8 @@ public function uninstall()
$plugin = $this->request->get('plugin');
$installed = $this->getLocalPlugins();
$ret = array(
'status' => false
'status' => false,
'error' => ''
);

if( $plugin && in_array($plugin, $installed) ) {
Expand All @@ -269,8 +280,12 @@ public function uninstall()
if( in_array($plugin, $activated) ){
Helper::removePlugin($plugin);
}
@$this->delTree($this->pluginRoot. '/' . $plugin);
$ret['status'] = true;
if( ! $this->delTree($this->pluginRoot. '/' . $plugin) ){
$error = error_get_last();
$ret['error'] = $error['message'];
}else{
$ret['status'] = true;
}
}

echo json_encode($ret);
Expand All @@ -287,7 +302,7 @@ private function delTree($dir,$tmp=false) {
foreach ($files as $file) {
(is_dir("$dir/$file") || $tmp) ? $this->delTree("$dir/$file") : unlink("$dir/$file");
}
if ($tmp) return;
if($tmp) return;
return rmdir($dir);
}
}
4 changes: 2 additions & 2 deletions TeStore/Plugin.php
@@ -1,11 +1,11 @@
<?php
if (!defined('__TYPECHO_ROOT_DIR__')) exit;
/**
* 通过读取html表格实现插件仓库的下载安装与卸载功能
* 通过读取html表格实现插件仓库的下载、安装及卸载等功能
*
* @package TeStore
* @author 羽中, zhulin3141
* @version 1.1.0
* @version 1.1.1
* @link http://www.yzmb.me
*/
class TeStore_Plugin implements Typecho_Plugin_Interface
Expand Down
20 changes: 13 additions & 7 deletions TeStore/README.md
@@ -1,13 +1,19 @@
### 新Github表格解析版插件仓库插件TeStore v1.1.0
### 新Github表格解析版插件仓库插件TeStore v1.1.1

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

- v1.1.1(18-8-6):

修正排序数组与pclzip.lib在PHP 7.0+下的兼容性问题,修正DOM编码,优化ajax报错和缺省筛选效果。

- v1.1.0(18-8-5):([@羽中](https://github.com/jzwalk)

通过PHP DOM解析Github社区目录下md表格做默认源,更新缓存功能逻辑,减少读写操作;
安装实现文件递归扫描和智能文件夹路径判断,优化ajax交互效果,增加action安全校验;
列表加载异步化,字母排序已安装自动提前,支持分页和按简介筛选,可附加图标并提醒版本升级。
1. 使用PHP DOM解析Github社区目录下的md表格做默认源,更新缓存功能逻辑,减少读写操作;

2. 安装实现文件递归扫描和智能文件夹路径判断,更换zip库,优化ajax交互效果,增加action校验;

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

- 1.0.0:([@zhulin3141](http://zhulin31410.blog.163.com/)
- 1.0.0(14-11-13):([@zhulin3141](http://zhulin31410.blog.163.com/)

通过正则匹配实现读取新浪云服务端页面信息,支持缓存并建立ajax下载、安装和卸载等机制。
通过正则匹配读取新浪云服务端页面信息,建立ajax下载、安装和卸载等机制,列表支持缓存和名称筛选
4 changes: 2 additions & 2 deletions TeStore/pclzip.lib.php
Expand Up @@ -1837,8 +1837,8 @@ function privOptionDefaultThreshold(&$p_options)
}

// ----- Get 'memory_limit' configuration value
$v_memory_limit = ini_get('memory_limit');
$v_memory_limit = trim($v_memory_limit);
$v_memory_limit = trim(ini_get('memory_limit'));
$v_memory_limit = substr($v_memory_limit, 0, -1);
$last = strtolower(substr($v_memory_limit, -1));

if($last == 'g')
Expand Down
2 changes: 1 addition & 1 deletion TeStore/sticky/sticky.css
Expand Up @@ -6,7 +6,7 @@ div.sticky-queue
box-shadow:0px 0px 5px #bbb;
-moz-box-shadow:0px 0px 5px #bbb;
-webkit-box-shadow:0px 0px 5px #bbb;
width:200px;
width:230px;
}
div.sticky-note
{ padding-right:20px; }
Expand Down
13 changes: 7 additions & 6 deletions TeStore/views/market.php
@@ -1,6 +1,6 @@
<?php
//异步加载插件数据
if ($this->request->is('action=loadinfos')) {
if( $this->request->is('action=loadinfos') ){
$pluginInfo = $this->getPluginData();

if($pluginInfo) {
Expand Down Expand Up @@ -37,7 +37,7 @@
<div class="typecho-list-operate clearfix">
<form method="get">
<div class="search" role="search">
<?php if ( $keywords ): ?>
<?php if( $keywords ): ?>
<a href="<?php $options->adminUrl('extending.php?panel=TeStore%2Fmarket.php'); ?>"><?php _e('&laquo; 取消筛选'); ?></a>
<?php endif; ?>
<input type="text" class="text-s" placeholder="<?php _e('请输入关键字'); ?>" value="<?php echo htmlspecialchars($keywords); ?>" name="keywords" />
Expand Down Expand Up @@ -70,7 +70,7 @@
<?php foreach( $pluginInfo[$page] as $plugin): $name = trim(strip_tags($plugin->pluginName)); $plugin->pluginUrl; ?>
<?php $source = $plugin->source; $url = $plugin->pluginUrl; $url = in_array($source, array('Download', 'N/A', 'Special')) ? 'https://github.com' . $url : $url; ?>
<tr id="plugin-<?php echo $name; ?>" data-name="<?php echo $name;?>" class="plugin">
<td><a href="<?php echo $url; ?>" <?php if ($url!=='#') echo 'target="_blank"'; ?>><?php echo $name; ?></a>
<td><a href="<?php echo $url; ?>" <?php if($url!=='#') echo 'target="_blank"'; ?>><?php echo $name; ?></a>
<?php if($source=='Download'): ?>
<a href="http://typecho-fans.github.io" title="<?php _e('Typecho-Fans社区维护版'); ?>" target="_blank"><img style="margin-bottom:-1px;" src="<?php echo $pluginPath;?>/views/tf.png" alt="typecho-fans"/></a></td>
<?php elseif($source=='N/A'): ?>
Expand Down Expand Up @@ -227,8 +227,8 @@ function clickInstall() {
$.sticky(sucStr, setting);
} else {
$this.show().parent().find('.uninstall').hide();
if( result.error != '' ){
$.sticky(errorStr + ',' + result.error, setting);
if ( result.error != '' ) {
$.sticky(errorStr + ': ' + result.error, setting);
}
}
});
Expand All @@ -255,7 +255,8 @@ function clickUninstall() {
$.sticky('<span style="color:#467B96;"><?php _e('卸载'); ?>' + name + '<?php _e('成功'); ?></span>', setting);
} else {
$this.show().parent().find('.install').hide();
$.sticky('<span class="warning"><?php _e('卸载'); ?>' + name + '<?php _e('失败'); ?></span>', setting);
errorMsg = result.error != '' ? ': ' + result.error : '';
$.sticky('<span class="warning"><?php _e('卸载'); ?>' + name + '<?php _e('失败'); ?></span>' + errorMsg, setting);
}
});

Expand Down

0 comments on commit 4c8ef98

Please sign in to comment.