-
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.
- Loading branch information
eallion
committed
Dec 24, 2019
1 parent
695c896
commit fb2537b
Showing
8 changed files
with
964 additions
and
0 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,2 @@ | ||
# Auto detect text files and perform LF normalization | ||
* text=auto |
Large diffs are not rendered by default.
Oops, something went wrong.
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,85 @@ | ||
<?php | ||
/** | ||
* Just Feed | ||
* | ||
* @package JustFeed | ||
* @author jKey | ||
* @version 0.1.2 | ||
* @link http://typecho.jkey.lu/ | ||
* @fix the 'date' bug by https://eallion.com, update to 0.1.2 -20190412 | ||
* @license GPL3 | ||
*/ | ||
|
||
class JustFeed_Plugin implements Typecho_Plugin_Interface | ||
{ | ||
/** | ||
* 激活插件方法,如果激活失败,直接抛出异常 | ||
* | ||
* @access public | ||
* @return void | ||
* @throws Typecho_Plugin_Exception | ||
*/ | ||
public static function activate() | ||
{ | ||
Helper::removeRoute('feed'); | ||
Helper::addRoute('feed', '/feed[feed:string:0]', 'JustFeed_Widget', 'feed'); | ||
} | ||
|
||
/** | ||
* 禁用插件方法,如果禁用失败,直接抛出异常 | ||
* | ||
* @static | ||
* @access public | ||
* @return void | ||
* @throws Typecho_Plugin_Exception | ||
*/ | ||
public static function deactivate() | ||
{ | ||
Helper::removeRoute('feed'); | ||
Helper::addRoute('feed', '/feed[feed:string:0]', 'Widget_Archive', 'feed'); | ||
} | ||
|
||
/** | ||
* 获取插件配置面板 | ||
* | ||
* @access public | ||
* @param Typecho_Widget_Helper_Form $form 配置面板 | ||
* @return void | ||
*/ | ||
public static function config(Typecho_Widget_Helper_Form $form) | ||
{ | ||
$cfg_copyright = new Typecho_Widget_Helper_Form_Element_Textarea( | ||
'cfg_copyright', | ||
NULL, | ||
'<hr /><small>Copyright © <a href="{authorurl}" target="_blank">{author}</a> for <a href="{siteurl}" target="_blank">{sitetitle}</a> 2010 | <a href="{permalink}" target="_blank">Permalink</a> | {commentsnumber} 条评论</small>', | ||
'在 feed 尾部添加', | ||
'可用标记:{sitetitle}{siteurl}{author}{authorurl}{permalink}{date}{time}{commentsnumber}<br /><br />Example: <a href="{permalink}#comments" title="to the comments">To the comments</a>, Author: <a href="{authorlink}" >{author}</a>' | ||
); | ||
$form->addInput($cfg_copyright); | ||
|
||
/* $cfg_related_post = new Typecho_Widget_Helper_Form_Element_Checkbox( | ||
'cfg_related_post', | ||
array('show' => '是否在 feed 尾部显示相关内容?'), | ||
NULL, | ||
'相关日志' | ||
); | ||
$form->addInput($cfg_related_post); | ||
$cfg_related_post_num = new Typecho_Widget_Helper_Form_Element_Text( | ||
'cfg_related_post_num', | ||
NULL, | ||
'5', | ||
'日志数量' | ||
); | ||
$form->addInput($cfg_related_post_num); */ | ||
} | ||
|
||
/** | ||
* 个人用户的配置面板 | ||
* | ||
* @access public | ||
* @param Typecho_Widget_Helper_Form $form | ||
* @return void | ||
*/ | ||
public static function personalConfig(Typecho_Widget_Helper_Form $form){} | ||
} |
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,17 @@ | ||
# JustFeed | ||
Ver 0.1.1 有一个bug,输出RSS的时候,如果用上的{date}参数,结果只能显示 “年” 和 “月” ,不能显示 “日”。 | ||
如图: | ||
 | ||
|
||
今天发现了,随手把里面的 93 行和 141 行修改了一下 | ||
``` | ||
$d['year'].'/'.$d['mon'].'/'.$date['mday'], | ||
``` | ||
改为: | ||
``` | ||
$d['year'].'/'.$d['mon'].'/'.$d['mday'], | ||
``` | ||
|
||
这个插件是jKey开发的,原作者的网站已经打不开了。 | ||
感谢原作者的付出。 | ||
[http://typecho.jkey.lu/](http://typecho.jkey.lu) |
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,184 @@ | ||
<?php | ||
class JustFeed_Widget extends Widget_Archive | ||
{ | ||
/** | ||
* 请到 Widget_Archive 中看以下私有变量的作用 | ||
* 由于父类中是私有变量不能在子类中直接使用,只能间接获取 | ||
*/ | ||
private $_feed; | ||
private $_description; | ||
private $_archiveTitle; | ||
private $_feedType; | ||
|
||
private $_currentFeedUrl; | ||
private $_feedContentType; | ||
|
||
/** | ||
* 构造函数,初始化组件 | ||
* | ||
* @access public | ||
* @param mixed $request request对象 | ||
* @param mixed $response response对象 | ||
* @param mixed $params 参数列表 | ||
* @return void | ||
*/ | ||
public function __construct($request, $response, $params = NULL) | ||
{ | ||
parent::__construct($request, $response, $params); | ||
|
||
$this->_feed = $this->getFeed(); | ||
$this->_feedType = $this->getFeedType(); | ||
|
||
/** 判断聚合类型 */ | ||
switch (true) { | ||
case 0 === strpos($this->request->feed, '/rss/') || '/rss' == $this->request->feed: | ||
/** 如果是RSS1标准 */ | ||
$this->_currentFeedUrl = $this->options->feedRssUrl; | ||
$this->_feedContentType = 'application/rdf+xml'; | ||
break; | ||
case 0 === strpos($this->request->feed, '/atom/') || '/atom' == $this->request->feed: | ||
/** 如果是ATOM标准 */ | ||
$this->_currentFeedUrl = $this->options->feedAtomUrl; | ||
$this->_feedContentType = 'application/atom+xml'; | ||
break; | ||
default: | ||
$this->_currentFeedUrl = $this->options->feedUrl; | ||
$this->_feedContentType = 'application/rss+xml'; | ||
break; | ||
} | ||
} | ||
|
||
/** | ||
* 输出 feed | ||
*/ | ||
public function feed() | ||
{ | ||
$this->_description = $this->getDescription(); | ||
$this->_archiveTitle = $this->getArchiveTitle(); | ||
|
||
// 获取系统设置 | ||
$options = Helper::options(); | ||
// 获取 JustFeed 设置 | ||
$settings = Helper::options()->plugin('JustFeed'); | ||
//$related_post_num = is_numeric($settings->cfg_related_post_num) ? intval($settings->cfg_related_post_num) : 5; | ||
|
||
$search = array('{sitetitle}','{siteurl}','{author}','{authorurl}','{permalink}','{date}','{time}','{commentsnumber}'); | ||
|
||
$this->_feed->setSubTitle($this->_description); | ||
$this->_feed->setFeedUrl($this->_currentFeedUrl); | ||
|
||
$this->_feed->setBaseUrl(('/' == $this->request->feed || 0 == strlen($this->request->feed) | ||
|| '/comments' == $this->request->feed || '/comments/' == $this->request->feed) ? | ||
$this->options->siteUrl : Typecho_Common::url($this->request->feed, $this->options->index)); | ||
$this->_feed->setFeedUrl($this->request->makeUriByRequest()); | ||
|
||
if ($this->is('single') || 'comments' == $this->parameter->type) { | ||
$this->_feed->setTitle(_t('%s 的评论', | ||
$this->options->title . ($this->_archiveTitle ? ' - ' . implode(' - ', $this->_archiveTitle) : NULL))); | ||
|
||
if ('comments' == $this->parameter->type) { | ||
$comments = $this->widget('Widget_Comments_Recent', 'pageSize=10'); | ||
} else { | ||
$comments = $this->widget('Widget_Comments_Recent', 'pageSize=10&parentId=' . $this->cid); | ||
} | ||
|
||
while ($comments->next()) { | ||
$d = getdate($comments->created); | ||
$replace = array( | ||
$options->title, | ||
$options->siteUrl, | ||
$this->author->screenName, | ||
$this->author->url, | ||
$comments->permalink, | ||
$d['year'].'/'.$d['mon'].'/'.$d['mday'], | ||
$d['hours'].':'.$d['minutes'].':'.$d['seconds'], | ||
$this->commentsNum | ||
); | ||
|
||
$copyright = str_replace($search, $replace, $settings->cfg_copyright); | ||
|
||
$suffix = $this->pluginHandle()->trigger($plugged)->commentFeedItem($this->_feedType, $comments); | ||
if (!$plugged) { | ||
$suffix = NULL; | ||
} | ||
|
||
$this->_feed->addItem(array( | ||
'title' => $comments->author, | ||
'content' => $comments->content . $copyright, | ||
'date' => $comments->created, | ||
'link' => $comments->permalink, | ||
'author' => (object) array( | ||
'screenName' => $comments->author, | ||
'url' => $comments->url, | ||
'mail' => $comments->mail | ||
), | ||
'excerpt' => strip_tags($comments->content), | ||
'suffix' => $suffix | ||
)); | ||
} | ||
} else { | ||
$this->_feed->setTitle($this->options->title . ($this->_archiveTitle ? ' - ' . implode(' - ', $this->_archiveTitle) : NULL)); | ||
|
||
$feedUrl = ''; | ||
if (Typecho_Feed::RSS2 == $this->_feedType) { | ||
$feedUrl = $this->feedUrl; | ||
} else if (Typecho_Feed::RSS1 == $this->_feedType) { | ||
$feedUrl = $this->feedRssUrl; | ||
} else if (Typecho_Feed::ATOM1 == $this->_feedType) { | ||
$feedUrl = $this->feedAtomUrl; | ||
} | ||
|
||
while ($this->next()) { | ||
//set_time_limit(60); | ||
// 获取文字内容的时间 | ||
$d = getdate($this->created); | ||
$replace = array( | ||
$options->title, | ||
$options->siteUrl, | ||
$this->author->screenName, | ||
$this->author->url, | ||
$this->permalink, | ||
$d['year'].'/'.$d['mon'].'/'.$d['mday'], | ||
$d['hours'].':'.$d['minutes'].':'.$d['seconds'], | ||
$this->commentsNum | ||
); | ||
|
||
$copyright = str_replace($search, $replace, $settings->cfg_copyright); | ||
|
||
// 相关日志 | ||
/* $related_post_html = ''; | ||
if ($settings->cfg_related_post) { | ||
$relatedPosts = $this->related($related_post_num); | ||
if ($relatedPosts->have()) { | ||
$related_post_html = '<h4>相关日志</h4><ul>'; | ||
while ($relatedPosts->next()) { | ||
$related_post_html .= '<li><a href="' . $relatedPosts->permalink . '" title="' . $relatedPosts->title . '">' . $relatedPosts->title . '</a></li>'; | ||
} | ||
$related_post_html .= '</ul>'; | ||
} | ||
} */ | ||
|
||
$suffix = $this->pluginHandle()->trigger($plugged)->feedItem($this->_feedType, $this); | ||
if (!$plugged) { | ||
$suffix = NULL; | ||
} | ||
|
||
$this->_feed->addItem(array( | ||
'title' => $this->title, | ||
'content' => $this->options->feedFullText ? $this->content.$related_post_html.$copyright : (false !== strpos($this->text, '<!--more-->') ? | ||
$this->excerpt . "<p class=\"more\"><a href=\"{$this->permalink}\" title=\"{$this->title}\">[...]</a></p>" . $related_post_html.$copyright : $this->content.$related_post_html.$copyright), | ||
'date' => $this->created, | ||
'link' => $this->permalink, | ||
'author' => $this->author, | ||
'excerpt' => $this->description, | ||
'comments' => $this->commentsNum, | ||
'commentsFeedUrl' => $feedUrl, | ||
'suffix' => $suffix | ||
)); | ||
} | ||
} | ||
|
||
$this->response->setContentType($this->_feedContentType); | ||
echo $this->_feed->__toString(); | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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