|
1 | 1 | <?php |
2 | 2 | /** |
3 | | - * 又拍云(UpYun)文件管理 |
| 3 | + * 又拍云(UpYun)文件管理 Mod by <a href="http://blog.iplayloli.com/">Ryan</a> |
4 | 4 | * |
5 | 5 | * @package UpyunFile |
6 | 6 | * @author codesee |
7 | | - * @version 0.8.0 |
| 7 | + * @version 0.8.1 |
8 | 8 | * @link http://pengzhiyong.com |
9 | 9 | * @dependence 1.0-* |
10 | 10 | * @date 2015-12-26 |
@@ -29,6 +29,7 @@ public static function activate() |
29 | 29 | Typecho_Plugin::factory('Widget_Upload')->deleteHandle = array('UpyunFile_Plugin', 'deleteHandle'); |
30 | 30 | Typecho_Plugin::factory('Widget_Upload')->attachmentHandle = array('UpyunFile_Plugin', 'attachmentHandle'); |
31 | 31 | Typecho_Plugin::factory('Widget_Upload')->attachmentDataHandle = array('UpyunFile_Plugin', 'attachmentDataHandle'); |
| 32 | + Typecho_Plugin::factory('Widget_Abstract_Contents')->contentEx = array('UpyunFile_Plugin','replace'); |
32 | 33 | return _t('插件已经激活,请正确设置插件'); |
33 | 34 | } |
34 | 35 |
|
@@ -53,6 +54,8 @@ public static function deactivate(){ |
53 | 54 | */ |
54 | 55 | public static function config(Typecho_Widget_Helper_Form $form) |
55 | 56 | { |
| 57 | + $convert = new Typecho_Widget_Helper_Form_Element_Radio('convert' , array('1'=>_t('开启'),'0'=>_t('关闭')),'0',_t('图片链接修改'),_t('把文章中图片的链接修改为又拍云 CDN 链接,启用前请把放在 typecho 上传目录中的图片同步到又拍云中')); |
| 58 | + $form->addInput($convert); |
56 | 59 | $upyundomain = new Typecho_Widget_Helper_Form_Element_Text('upyundomain', NULL, 'http://', _t('绑定域名:'), _t('该绑定域名为绑定Upyun服务的域名,由Upyun提供,注意以http://开头,最后不要加/')); |
57 | 60 | $form->addInput($upyundomain->addRule('required',_t('您必须填写绑定域名,它是由Upyun提供'))); |
58 | 61 |
|
@@ -683,4 +686,34 @@ private static function getMime($fileName){ |
683 | 686 |
|
684 | 687 | return 'application/octet-stream'; |
685 | 688 | } |
| 689 | + /** |
| 690 | + * 图片链接软修改 |
| 691 | + * |
| 692 | + * @access public |
| 693 | + * @param $content |
| 694 | + * @param $class |
| 695 | + * @return $content |
| 696 | + */ |
| 697 | + public static function replace($text, $widget, $lastResult) { |
| 698 | + if(Typecho_Widget::widget('Widget_Options')->Plugin('UpyunFile')->convert == 1) { |
| 699 | + $text = empty($lastResult) ? $text : $lastResult; |
| 700 | + if (($widget instanceof Widget_Archive)||($widget instanceof Widget_Abstract_Comments)) { |
| 701 | + $options = Typecho_Widget::widget('Widget_Options'); |
| 702 | + $settings = $options->plugin('UpyunFile'); |
| 703 | + preg_match_all('/<img[^>]*src=[\'"]?([^>\'"\s]*)[\'"]?[^>]*>/i',$text,$matches); |
| 704 | + if($matches){ |
| 705 | + foreach($matches[1] as $val){ |
| 706 | + if(strpos($val,rtrim($options->siteUrl, '/')) !== false) { |
| 707 | + if($settings->mode !== 'typecho'){ |
| 708 | + $text=str_replace(rtrim($options->siteUrl, '/') . '/usr/uploads', $settings->upyundomain . '/usr/uploads', $text); |
| 709 | + } else { |
| 710 | + $text=str_replace(rtrim($options->siteUrl, '/') . '/usr/uploads', $settings->upyundomain, $text); |
| 711 | + } |
| 712 | + } |
| 713 | + } |
| 714 | + } |
| 715 | + } |
| 716 | + } |
| 717 | + return $text; |
| 718 | + } |
686 | 719 | } |