From 8b3d66ee674f90d2804d5efc35281f38ca2552ab Mon Sep 17 00:00:00 2001 From: benzbrake Date: Tue, 14 Feb 2017 09:04:31 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=9B=BE=E7=89=87=E9=93=BE?= =?UTF-8?q?=E6=8E=A5=E8=BD=AF=E6=9B=BF=E6=8D=A2=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Plugin.php | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/Plugin.php b/Plugin.php index c12d72b..64aaf11 100644 --- a/Plugin.php +++ b/Plugin.php @@ -1,10 +1,10 @@ Ryan * * @package UpyunFile * @author codesee - * @version 0.8.0 + * @version 0.8.1 * @link http://pengzhiyong.com * @dependence 1.0-* * @date 2015-12-26 @@ -29,6 +29,7 @@ public static function activate() Typecho_Plugin::factory('Widget_Upload')->deleteHandle = array('UpyunFile_Plugin', 'deleteHandle'); Typecho_Plugin::factory('Widget_Upload')->attachmentHandle = array('UpyunFile_Plugin', 'attachmentHandle'); Typecho_Plugin::factory('Widget_Upload')->attachmentDataHandle = array('UpyunFile_Plugin', 'attachmentDataHandle'); + Typecho_Plugin::factory('Widget_Abstract_Contents')->contentEx = array('UpyunFile_Plugin','replace'); return _t('插件已经激活,请正确设置插件'); } @@ -53,6 +54,8 @@ public static function deactivate(){ */ public static function config(Typecho_Widget_Helper_Form $form) { + $convert = new Typecho_Widget_Helper_Form_Element_Radio('convert' , array('1'=>_t('开启'),'0'=>_t('关闭')),'0',_t('图片链接修改'),_t('把文章中图片的链接修改为又拍云 CDN 链接,启用前请把放在 typecho 上传目录中的图片同步到又拍云中')); + $form->addInput($convert); $upyundomain = new Typecho_Widget_Helper_Form_Element_Text('upyundomain', NULL, 'http://', _t('绑定域名:'), _t('该绑定域名为绑定Upyun服务的域名,由Upyun提供,注意以http://开头,最后不要加/')); $form->addInput($upyundomain->addRule('required',_t('您必须填写绑定域名,它是由Upyun提供'))); @@ -683,4 +686,34 @@ private static function getMime($fileName){ return 'application/octet-stream'; } + /** + * 图片链接软修改 + * + * @access public + * @param $content + * @param $class + * @return $content + */ + public static function replace($text, $widget, $lastResult) { + if(Typecho_Widget::widget('Widget_Options')->Plugin('UpyunFile')->convert == 1) { + $text = empty($lastResult) ? $text : $lastResult; + if (($widget instanceof Widget_Archive)||($widget instanceof Widget_Abstract_Comments)) { + $options = Typecho_Widget::widget('Widget_Options'); + $settings = $options->plugin('UpyunFile'); + preg_match_all('/]*src=[\'"]?([^>\'"\s]*)[\'"]?[^>]*>/i',$text,$matches); + if($matches){ + foreach($matches[1] as $val){ + if(strpos($val,rtrim($options->siteUrl, '/')) !== false) { + if($settings->mode === 'typecho'){ + $text=str_replace(rtrim($options->siteUrl, '/') . '/usr/uploads', $settings->upyundomain . '/usr/uploads', $text); + } else { + $text=str_replace(rtrim($options->siteUrl, '/') . '/usr/uploads', $settings->upyundomain, $text); + } + } + } + } + } + } + return $text; + } }