Skip to content

Commit

Permalink
feat: TeStore 新增一个镜像 by xiamp.net
Browse files Browse the repository at this point in the history
  • Loading branch information
benzBrake committed Jul 1, 2024
1 parent f8a8e3b commit 47a71d5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 17 deletions.
21 changes: 13 additions & 8 deletions TeStore/Action.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public function getPluginData()
$page = str_replace(array('github.com', 'raw.githubusercontent.com'), $proxy, $page);
$page = str_replace(array('blob/', 'raw/', 'master/'), '', $page);
} else {
$page = rtrim($proxy, "/") . $page;
$page = Typecho_Common::url($page, $proxy);
}
}
$html .= $this->useCurl ? $this->curlGet($page) : @file_get_contents($page,0,
Expand Down Expand Up @@ -223,14 +223,19 @@ public function install()
$this->makedir($tempDir); //创建临时目录
}
$proxy = $this->settings->proxy;
$isRaw = strpos($zip, 'raw.githubusercontent.com') || strpos($zip, 'raw/master');
//替换为加速地址
if ($proxy || strpos($zip, 'raw.githubusercontent.com') || strpos($zip, 'raw/master')) {
$cdn = $this->ZIP_CDN($plugin, $author);
$zip = $cdn ? $cdn : $zip;
$proxy = $proxy ? $proxy : 'cdn.jsdelivr.net/gh';
$zip = str_replace(array('github.com', 'raw.githubusercontent.com'), $proxy, $zip);
$zip = substr($proxy, -3) === "/gh" ? str_replace(array('blob/', 'raw/', 'master/'), '', $zip) : str_replace(array('blob/', 'raw/'), '', $zip);
}
if ($proxy || $isRaw) {
if (substr($proxy, -3) === "/gh") {
$cdn = $this->ZIP_CDN($plugin, $author);
$zip = $cdn ? $cdn : $zip;
$proxy = $proxy ? $proxy : 'cdn.jsdelivr.net/gh';
$zip = str_replace(array('github.com', 'raw.githubusercontent.com'), $proxy, $zip);
$zip = substr($proxy, -3) === "/gh" ? str_replace(array('blob/', 'raw/', 'master/'), '', $zip) : str_replace(array('blob/', 'raw/'), '', $zip);
} else {
$zip = Typecho_Common::url($zip, $proxy);
}
}

//下载至临时目录
$zipFile = $this->useCurl ? $this->curlGet($zip) : @file_get_contents($zip, 0,
Expand Down
18 changes: 9 additions & 9 deletions TeStore/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
if (!defined('__TYPECHO_ROOT_DIR__')) exit;
/**
* 读取Github上维护的专用表格实现插件仓库各项功能
*
*
* @package TeStore
* @author 羽中, zhulin3141, Ryan
* @version 1.1.6
Expand All @@ -15,7 +15,7 @@ class TeStore_Plugin implements Typecho_Plugin_Interface
{
/**
* 激活插件方法,如果激活失败,直接抛出异常
*
*
* @access public
* @return void
* @throws Typecho_Plugin_Exception
Expand Down Expand Up @@ -46,7 +46,7 @@ public static function activate()

/**
* 禁用插件方法,如果禁用失败,直接抛出异常
*
*
* @static
* @access public
* @return void
Expand All @@ -62,7 +62,7 @@ public static function deactivate()

/**
* 获取插件配置面板
*
*
* @access public
* @param Typecho_Widget_Helper_Form $form 配置面板
* @return void
Expand Down Expand Up @@ -91,7 +91,7 @@ public static function config(Typecho_Widget_Helper_Form $form)
$form->addInput($cache);

$proxy = new Typecho_Widget_Helper_Form_Element_Radio('proxy',
array(''=>_t(''),'cdn.jsdelivr.net/gh'=>_t('jsDelivr镜像'),'jsd.onmicrosoft.cn/gh'=>_t('渺软镜像')),'',_t('使用代理加速'),_t('GitHub连接不畅时可选'));
array(''=>_t(''),'cdn.jsdelivr.net/gh'=>_t('jsDelivr镜像'),'jsd.onmicrosoft.cn/gh'=>_t('渺软镜像'), 'https://ghmirror.pp.ua' => _('GitHub Proxy')),'',_t('使用代理加速'),_t('GitHub连接不畅时可选'));
$form->addInput($proxy);

$curl = new Typecho_Widget_Helper_Form_Element_Checkbox('curl',
Expand All @@ -105,7 +105,7 @@ public static function config(Typecho_Widget_Helper_Form $form)

/**
* 检查cURL支持
*
*
* @param array $settings
* @return string
*/
Expand All @@ -121,7 +121,7 @@ public static function configCheck(array $settings)

/**
* 个人用户的配置面板
*
*
* @access public
* @param Typecho_Widget_Helper_Form $form
* @return void
Expand All @@ -130,7 +130,7 @@ public static function personalConfig(Typecho_Widget_Helper_Form $form){}

/**
* 输出导航按钮
*
*
* @access public
* @return void
*/
Expand All @@ -144,7 +144,7 @@ public static function render()

/**
* 判断目录可写
*
*
* @access public
* @return boolean
*/
Expand Down

0 comments on commit 47a71d5

Please sign in to comment.