-
Notifications
You must be signed in to change notification settings - Fork 594
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
社区版插件新增Stat/Attachment含新版README和加速用zip包,另修正部分列表简介
- Loading branch information
Showing
9 changed files
with
536 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
class Attachment_Action extends Typecho_Widget implements Widget_Interface_Do | ||
{ | ||
public function action() | ||
{ | ||
$db = Typecho_Db::get(); | ||
$options = Typecho_Widget::widget('Widget_Options'); | ||
$domain = $options->plugin('Attachment')->domain; | ||
$cid = intval($this->request->get("cid")); | ||
$attach = $db->fetchRow($db->select()->from('table.contents')->where('type = \'attachment\' AND cid = ?', $cid)); | ||
if (empty($attach)) { | ||
throw new Typecho_Widget_Exception(_t('附件文件不存在或无法读取,请与管理员联系。')); | ||
} | ||
$attach_text = unserialize($attach['text']); | ||
$attach_url = Typecho_Common::url($attach_text['path'], ($domain ? $domain : $options->index)); | ||
if (isset($options->plugins['activated']['Stat'])) { | ||
Stat_Plugin::viewStat($cid); | ||
} | ||
$this->response->redirect($attach_url); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
<?php | ||
/** | ||
* 附件下载插件 【<a href="https://github.com/typecho-fans/plugins" target="_blank">TF</a>社区维护版】 | ||
* | ||
* @package Attachment | ||
* @author 羽中, Hanny | ||
* @version 1.0.2 | ||
* @dependence 9.9.2-* | ||
* @link https://github.com/typecho-fans/plugins/tree/master/Attachment | ||
* | ||
* version 1.0.2 at 2020-07-08 | ||
* 修正输出源码符合W3C标准并本地化文本 | ||
* 增加附件地址域名设置兼容云储存等情况 | ||
* | ||
* 历史版本 | ||
* version 1.0.1 at 2010-01-02 | ||
* 修改下载地址路由 | ||
* | ||
* version 1.0.0 at 2009-12-12 | ||
* 实现用<attach>aid</attach>添加附件的功能 | ||
* 与统计插件结合来实现下载次数的统计功能 | ||
* | ||
*/ | ||
class Attachment_Plugin implements Typecho_Plugin_Interface | ||
{ | ||
/** | ||
* 激活插件方法,如果激活失败,直接抛出异常 | ||
* | ||
* @access public | ||
* @return void | ||
* @throws Typecho_Plugin_Exception | ||
*/ | ||
public static function activate() | ||
{ | ||
Typecho_Plugin::factory('Widget_Abstract_Contents')->contentEx = array('Attachment_Plugin', 'parse'); | ||
Typecho_Plugin::factory('Widget_Abstract_Contents')->excerptEx = array('Attachment_Plugin', 'parse'); | ||
Typecho_Plugin::factory('Widget_Abstract_Comments')->contentEx = array('Attachment_Plugin', 'parse'); | ||
Helper::addRoute('download', '/download/[cid:digital]', 'Attachment_Action', 'action'); | ||
} | ||
|
||
/** | ||
* 禁用插件方法,如果禁用失败,直接抛出异常 | ||
* | ||
* @static | ||
* @access public | ||
* @return void | ||
* @throws Typecho_Plugin_Exception | ||
*/ | ||
public static function deactivate() | ||
{ | ||
Helper::removeRoute('download'); | ||
} | ||
|
||
/** | ||
* 获取插件配置面板 | ||
* | ||
* @access public | ||
* @param Typecho_Widget_Helper_Form $form 配置面板 | ||
* @return void | ||
*/ | ||
public static function config(Typecho_Widget_Helper_Form $form) | ||
{ | ||
$domain = new Typecho_Widget_Helper_Form_Element_Text('domain', NULL, '', | ||
_t('域名地址'), _t('如果附件使用云储存请填写自定义域名地址,默认留空即本站地址')); | ||
$form->addInput($domain); | ||
} | ||
|
||
/** | ||
* 个人用户的配置面板 | ||
* | ||
* @access public | ||
* @param Typecho_Widget_Helper_Form $form | ||
* @return void | ||
*/ | ||
public static function personalConfig(Typecho_Widget_Helper_Form $form){} | ||
|
||
/** | ||
* 解析 | ||
* | ||
* @access public | ||
* @param array $matches 解析值 | ||
* @return string | ||
*/ | ||
public static function parseCallback($matches) | ||
{ | ||
$options = Typecho_Widget::widget('Widget_Options'); | ||
$offset = $options->timezone - $options->serverTimezone; | ||
$attach_gif = Typecho_Common::url('Attachment/attach.gif', $options->pluginUrl); | ||
$db = Typecho_Db::get(); | ||
$cid = $matches[1]; | ||
$attach = $db->fetchRow($db->select()->from('table.contents')->where('type = \'attachment\' AND cid = ?', $cid)); | ||
if (empty($attach)) { | ||
return '<div><img style="vertical-align:middle;" src="'.$attach_gif.'" alt="'._t('附件').'"/>'._t('附件ID错误').'</div>'; | ||
} | ||
$attach_date = ', '._t('最后修改: ').date('Y-m-d H:i', $attach['modified'] + $offset); | ||
$attach_text = unserialize($attach['text']); | ||
$attach_size = round($attach_text['size'] / 1024, 1)." KB"; | ||
$attach_url = Typecho_Common::url('download/'.$cid, $options->index); | ||
if (isset($options->plugins['activated']['Stat'])) { | ||
$attach_views = ', '._t('下载次数: ').$attach['views']; | ||
} else { | ||
$attach_views = ''; | ||
} | ||
$text = '<div class="attachment"><img style="vertical-align:middle;" src="'.$attach_gif.'" alt="'._t('附件').'"/> <a href="'.$attach_url.'" title="'._t('点击下载').'" target="_blank">'.$attach['title'].'</a> <span class="num">('.$attach_size.$attach_views.$attach_date.')</span></div>'; | ||
|
||
return $text; | ||
} | ||
|
||
/** | ||
* 插件实现方法 | ||
* | ||
* @access public | ||
* @return void | ||
*/ | ||
public static function parse($text, $widget, $lastResult) | ||
{ | ||
$text = empty($lastResult) ? $text : $lastResult; | ||
$text = htmlspecialchars_decode($text); //fix 17.10.30 Markdown | ||
|
||
if ($widget instanceof Widget_Archive || $widget instanceof Widget_Abstract_Comments) { | ||
return preg_replace_callback("/<attach>(\d+)<\/attach>/is", array('Attachment_Plugin', 'parseCallback'), $text); | ||
} else { | ||
return $text; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<a href="https://typecho-fans.github.io"> | ||
<img src="https://typecho-fans.github.io/text-logo.svg" alt="TF Logo" title="Typecho Fans开源作品社区" align="right" height="100" /> | ||
</a> | ||
|
||
Attachment v1.0.2 - 社区维护版 | ||
====================== | ||
<h4 align="center">—— 附件下载链接美化及跳转计数插件,计数功能需搭配[Stat](https://github.com/typecho-fans/plugins/tree/master/Stat)。</h4> | ||
|
||
<p align="center"> | ||
<a href="#使用说明">使用说明</a> • | ||
<a href="#版本历史">版本历史</a> • | ||
<a href="#贡献作者">贡献作者</a> • | ||
<a href="#附注链接">附注/链接</a> • | ||
<a href="#授权协议">授权协议</a> | ||
</p> | ||
|
||
--- | ||
|
||
## 使用说明 | ||
|
||
<table> | ||
<tr> | ||
<td> | ||
|
||
###### 支持文章内短代码形式输出附件下载链接,链接带传统别针图标,通过跳转页面实现下载次数统计,新版还可设置域名支持云储存地址。 | ||
|
||
**使用方法**: | ||
##### 1. 下载本插件,放在 `usr/plugins/` 目录中,确保文件夹名为 Attachment; | ||
##### 2. 激活插件,如使用云储存可在设置中填写自定义域名保存,否则忽略即可; | ||
##### 3. 编辑文章时写入`<attach>附件cid</attach>`发布即可显示下载链接。 | ||
|
||
**注意事项**: | ||
* ##### 查看附件文件cid方法:后台进入管理-文件页面,点击文件名,地址栏?后即会显示cid等于的值。 | ||
|
||
</td> | ||
</tr> | ||
</table> | ||
|
||
## 版本历史 | ||
|
||
* v1.0.2 (20-07-08 [@jzwalk](https://github.com/jzwalk)) | ||
* 修正输出源码符合W3C标准并本地化文本; | ||
* 增加附件地址域名设置兼容云储存等情况。 | ||
* v1.0.1 (10-01-02 [@Hanny](http://www.imhan.com)) | ||
* 修改下载地址路由。 | ||
* v1.0.0 (09-12-12 [@Hanny](http://www.imhan.com)) | ||
* 实现用<attach>aid</attach>添加附件的功能; | ||
* 与统计插件结合来实现下载次数的统计功能。 | ||
|
||
## 贡献作者 | ||
|
||
[](https://github.com/jzwalk) | [](http://www.imhan.com) | ||
:---:|:---:|:---: | ||
[jzwalk](https://github.com/jzwalk) (2020) | [Hanny](http://www.imhan.com) (2009) | ||
|
||
## 附注/链接 | ||
|
||
* [原版](http://www.imhan.com/archives/45) - 实现附件管理器功能。 | ||
|
||
未安装并启用[Stat](https://github.com/typecho-fans/plugins/tree/master/Stat)插件时将不显示下载计数。 | ||
|
||
## 授权协议 | ||
|
||
TF目录下的社区维护版作品如果没有明确声明,默认采用与Typecho相同的[GPLv2](https://github.com/typecho/typecho/blob/master/LICENSE.txt)开源协议。(要求提及出处,保持开源并注明修改。) | ||
|
||
> Attachment原作未附协议声明,原作者保留所有权利。 © [Hanny](http://www.imhan.com) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.