GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — 新增图片链接软修改 · ShadowySpirits/UpyunFile@afca6ef

This repository was archived by the owner on Sep 3, 2021. It is now read-only.

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • Plugin.php
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎Plugin.php‎

Copy file name to clipboardExpand all lines: Plugin.php
+35-2Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<?php
22
/**
3-
* 又拍云(UpYun)文件管理
3+
* 又拍云(UpYun)文件管理 Mod by <a href="http://blog.iplayloli.com/">Ryan</a>
44
*
55
* @package UpyunFile
66
* @author codesee
7-
* @version 0.8.0
7+
* @version 0.8.1
88
* @link http://pengzhiyong.com
99
* @dependence 1.0-*
1010
* @date 2015-12-26
@@ -29,6 +29,7 @@ public static function activate()
2929
Typecho_Plugin::factory('Widget_Upload')->deleteHandle = array('UpyunFile_Plugin', 'deleteHandle');
3030
Typecho_Plugin::factory('Widget_Upload')->attachmentHandle = array('UpyunFile_Plugin', 'attachmentHandle');
3131
Typecho_Plugin::factory('Widget_Upload')->attachmentDataHandle = array('UpyunFile_Plugin', 'attachmentDataHandle');
32+
Typecho_Plugin::factory('Widget_Abstract_Contents')->contentEx = array('UpyunFile_Plugin','replace');
3233
return _t('插件已经激活,请正确设置插件');
3334
}
3435

@@ -53,6 +54,8 @@ public static function deactivate(){
5354
*/
5455
public static function config(Typecho_Widget_Helper_Form $form)
5556
{
57+
$convert = new Typecho_Widget_Helper_Form_Element_Radio('convert' , array('1'=>_t('开启'),'0'=>_t('关闭')),'0',_t('图片链接修改'),_t('把文章中图片的链接修改为又拍云 CDN 链接,启用前请把放在 typecho 上传目录中的图片同步到又拍云中'));
58+
$form->addInput($convert);
5659
$upyundomain = new Typecho_Widget_Helper_Form_Element_Text('upyundomain', NULL, 'http://', _t('绑定域名:'), _t('该绑定域名为绑定Upyun服务的域名,由Upyun提供,注意以http://开头,最后不要加/'));
5760
$form->addInput($upyundomain->addRule('required',_t('您必须填写绑定域名,它是由Upyun提供')));
5861

@@ -683,4 +686,34 @@ private static function getMime($fileName){
683686

684687
return 'application/octet-stream';
685688
}
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+
}
686719
}

0 commit comments

Comments
0 (0)
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.