Skip to content
This repository has been archived by the owner on May 9, 2019. It is now read-only.

Commit

Permalink
兼容新版服务端,增加curl/file_get_contents切换
Browse files Browse the repository at this point in the history
  • Loading branch information
chekun committed May 3, 2017
1 parent a693652 commit ef882b8
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 41 deletions.
24 changes: 17 additions & 7 deletions Action.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ class AppStore_Action extends Typecho_Widget
*/
private $server = '';

/**
* Http Request 方式
*
* @var string
*/
private $http = '';

/**
* 构造函数
*
Expand Down Expand Up @@ -51,7 +58,9 @@ public function __construct($request, $response, $params = NULL)
include('libs/exceptions.php');

//从插件设置中读取应用商店服务器地址
$this->server = Typecho_Widget::widget('Widget_Options')->plugin('AppStore')->server;
$pluginOptions = Typecho_Widget::widget('Widget_Options')->plugin('AppStore');
$this->server = $pluginOptions->server;
$this->http = 'http_'.$pluginOptions->http;

define('TYPEHO_ADMIN_PATH', __TYPECHO_ROOT_DIR__.__TYPECHO_ADMIN_DIR__.'/');

Expand All @@ -63,12 +72,11 @@ public function __construct($request, $response, $params = NULL)
*/
public function market()
{
$http = $this->http;
//获取插件列表
$result = json_decode(http_get($this->server.'packages.json'));


$result = json_decode($http($this->server.'packages.json'));

if ($result) {


//导出已激活插件
$activatedPlugins = Typecho_Plugin::export();
Expand Down Expand Up @@ -163,10 +171,12 @@ public function install()
}

//下载新插件zip包
$archive = http_get($this->server.'archive/'.$plugin.'/'.str_replace(' ', '%20', $version));
$zipUrl = $this->server.'plugins/'.$plugin.'/download/'.str_replace(' ', '%20', $version).'.zip';
$http = $this->http;
$archive = $http($zipUrl);

if (! $archive) {
throw new DownloadErrorException('下载插件包出错!');
throw new DownloadErrorException('下载插件包出错!'.$zipUrl);
}

//保存文件
Expand Down
21 changes: 18 additions & 3 deletions Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
*
* @package AppStore
* @author chekun
* @version 1.4.2
* @link https://echod.pubean.com
* @version 2.0.0
* @link https://typecho.chekun.me
*/
class AppStore_Plugin implements Typecho_Plugin_Interface
{
Expand Down Expand Up @@ -76,8 +76,23 @@ public static function deactivate()
public static function config(Typecho_Widget_Helper_Form $form)
{
/** 应用服务器地址 */
$name = new Typecho_Widget_Helper_Form_Element_Text('server', NULL, 'https://typecho.chekun.me/', _t('应用服务器地址'));
$name = new Typecho_Widget_Helper_Form_Element_Text(
'server',
NULL,
'https://typecho.chekun.me/',
_t('应用服务器地址'),
'参与服务端开发的小伙伴可以通过设置此处调试,普通的小伙伴默认就好,😄'
);
$form->addInput($name);
/** 下载插件方法 */
$http = new Typecho_Widget_Helper_Form_Element_Select(
'http',
['curl' => 'curl', 'file_get_contents' => 'file_get_contents'],
'curl',
_t('下载插件方法'),
'不能正常显示插件列表/下载插件的小伙伴可以设置为file_get_content方式'
);
$form->addInput($http);
}

/**
Expand Down
23 changes: 18 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,32 @@
Typecho 应用商店 插件
========
========================

The missing plugins store for Typecho!

## 如何使用

下载地址: https://github.com/typecho-app-store/AppStore/releases
- 方法一

解压到usr/plugins/AppStore,启用插件即可。
进入 [官网](https://typecho.chekun.me/) 搜索 AppStore, 下载对应的版本

## Contributors
- 方法二

进入 [Github Releases](https://github.com/typecho-app-store/AppStore/releases) 下载对应的版本

- 方法三

```
git clone [email protected]:chekun/AppStore.git AppStore
```

> 不管使用哪种方法,最终请将得到的文件夹命名为 *AppStore* 放到 *Typecho* 目录的 *usr/plugins* 目录下
> 进入插件面板,启用本插件即可
## 代码贡献者

- [@chekun](https://github.com/chekun)
- [@jzwalk](https://github.com/jzwalk)
- [@fengyunljp](https://github.com/fengyunljp)
- [@aiwb](https://github.com/aiwb)

### 欢迎一起完善该项目.
## 欢迎参与开发,共同完善
20 changes: 16 additions & 4 deletions helpers/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,31 @@ function delete_files($path, $del_dir = true, $htdocs = false, $_level = 0)
}

/**
* Http Get Request
* Http Get Request using file_get_contents
*
* @param $url
* @return string
*/
function http_get($url)
function http_file_get_contents($url)
{
$SSL = substr($url, 0, 8) == "https://" ? true : false;
$out = file_get_contents($url);
return $out;
}

/**
* Http Get Request using curl
*
* @param $url
* @return string
*/
function http_curl($url)
{
$ssl = substr($url, 0, 8) == "https://" ? true : false;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
if ($SSL) {
if ($ssl) {
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
}
Expand Down
63 changes: 41 additions & 22 deletions views/row.php
Original file line number Diff line number Diff line change
@@ -1,24 +1,43 @@
<tr class="as-card" data-name="<?php echo $plugin->name; ?>" data-existed="<?php echo $plugin->existed ?>">
<td class="as-name"><?php echo $plugin->name; ?></td>
<td class="as-description"><?php echo $plugin->versions[0]->description; ?></td>
<td class="as-versions">
<select class="as-version-selector">
<?php foreach ($plugin->versions as $version): ?>
<option value="<?php echo $version->version; ?>" data-activated="<?php echo $version->activated; ?>" data-author="<?php echo $version->author; ?>" data-require="<?php echo $version->require; ?>" data-description="<?php echo $version->description; ?>"><?php echo $version->version; ?></option>
<?php endforeach; ?>
</select>
</td>
<td class="as-require" ><?php echo $plugin->versions[0]->require; ?></td>
<td class="as-author"><a href="<?php echo $plugin->versions[0]->link; ?>" target="_blank"><?php echo $plugin->versions[0]->author; ?></a></td>
<td class="as-operations">
<?php if ($this->installale): ?>
<?php if ($plugin->existed): ?>
<a class="as-install" href="javascript:;"><?php echo _t("重装"); ?></a>
<?php if ($plugin->type === 'plugin'): ?>
<tr class="as-card" data-name="<?php echo $plugin->name; ?>" data-existed="<?php echo $plugin->existed ?>">
<td class="as-name"><?php echo $plugin->name; ?></td>
<td class="as-description"><?php echo $plugin->versions[0]->description; ?></td>
<td class="as-versions">
<select class="as-version-selector">
<?php foreach ($plugin->versions as $version): ?>
<option value="<?php echo $version->version; ?>" data-activated="<?php echo $version->activated; ?>" data-author="<?php echo $version->author; ?>" data-require="<?php echo $version->require; ?>" data-description="<?php echo $version->description; ?>"><?php echo $version->version; ?></option>
<?php endforeach; ?>
</select>
</td>
<td class="as-require" ><?php echo $plugin->versions[0]->require; ?></td>
<td class="as-author"><a href="<?php echo $plugin->versions[0]->link; ?>" target="_blank"><?php echo $plugin->versions[0]->author; ?></a></td>
<td class="as-operations">
<?php if ($this->installale): ?>
<?php if ($plugin->existed): ?>
<a class="as-install" href="javascript:;"><?php echo _t("重装"); ?></a>
<?php else: ?>
<a class="as-install" href="javascript:;"><?php echo _t("安装"); ?></a>
<?php endif; ?>
<?php else: ?>
<a class="as-install" href="javascript:;"><?php echo _t("安装"); ?></a>
<a onclick="return confirm('没有写入权限或者运行在云平台中\n点击确认后将进行下载,请手动传到服务器上!');" href="<?php echo $this->server.'archive/'.$plugin->name.'/'.str_replace(' ', '%20', $version->version);?>"><?php echo _t('下载'); ?></a>
<?php endif; ?>
<?php else: ?>
<a onclick="return confirm('没有写入权限或者运行在云平台中\n点击确认后将进行下载,请手动传到服务器上!');" href="<?php echo $this->server.'archive/'.$plugin->name.'/'.str_replace(' ', '%20', $version->version);?>"><?php echo _t('下载'); ?></a>
<?php endif; ?>
</td>
</tr>
</td>
</tr>
<?php else: ?>
<tr class="as-card" data-name="<?php echo $plugin->name; ?>">
<td class="as-name">「主题」<?php echo $plugin->name; ?></td>
<td class="as-description"><?php echo $plugin->versions[0]->description; ?></td>
<td class="as-versions">
<select class="as-version-selector">
<?php foreach ($plugin->versions as $version): ?>
<option value="<?php echo $version->version; ?>" data-activated="<?php echo $version->activated; ?>" data-author="<?php echo $version->author; ?>" data-require="<?php echo $version->require; ?>" data-description="<?php echo $version->description; ?>"><?php echo $version->version; ?></option>
<?php endforeach; ?>
</select>
</td>
<td class="as-require" ><?php echo $plugin->versions[0]->require; ?></td>
<td class="as-author"><a href="<?php echo $plugin->versions[0]->link; ?>" target="_blank"><?php echo $plugin->versions[0]->author; ?></a></td>
<td class="as-operations">
<a onclick="return confirm('暂不支持主题下载,确定后会定向到官网下载!');" href="https://typecho.chekun.me/"><?php echo _t('下载'); ?></a>
</td>
</tr>
<?php endif; ?>

0 comments on commit ef882b8

Please sign in to comment.