2016-01-11 23:51:00 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class pluginRSS extends Plugin {
|
|
|
|
|
2017-06-04 21:08:31 +02:00
|
|
|
public function init()
|
|
|
|
{
|
|
|
|
// Fields and default values for the database of this plugin
|
|
|
|
$this->dbFields = array(
|
2018-08-06 21:46:58 +02:00
|
|
|
'numberOfItems'=>5
|
2017-06-04 21:08:31 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Method called on the settings of the plugin on the admin area
|
|
|
|
public function form()
|
|
|
|
{
|
2018-08-05 17:54:20 +02:00
|
|
|
global $L;
|
2017-06-04 21:08:31 +02:00
|
|
|
|
2018-07-02 00:24:53 +02:00
|
|
|
$html = '<div class="alert alert-primary" role="alert">';
|
|
|
|
$html .= $this->description();
|
|
|
|
$html .= '</div>';
|
|
|
|
|
|
|
|
$html .= '<div>';
|
2018-08-05 17:54:20 +02:00
|
|
|
$html .= '<label>'.$L->get('RSS URL').'</label>';
|
2017-10-13 23:38:24 +02:00
|
|
|
$html .= '<a href="'.Theme::rssUrl().'">'.Theme::rssUrl().'</a>';
|
|
|
|
$html .= '</div>';
|
|
|
|
|
|
|
|
$html .= '<div>';
|
2018-08-05 17:54:20 +02:00
|
|
|
$html .= '<label>'.$L->get('Amount of items').'</label>';
|
2018-08-06 21:46:58 +02:00
|
|
|
$html .= '<input id="jsnumberOfItems" name="numberOfItems" type="text" value="'.$this->getValue('numberOfItems').'">';
|
2018-08-05 17:54:20 +02:00
|
|
|
$html .= '<span class="tip">'.$L->get('Amount of items to show on the feed').'</span>';
|
2017-06-04 21:08:31 +02:00
|
|
|
$html .= '</div>';
|
|
|
|
|
|
|
|
return $html;
|
|
|
|
}
|
2019-09-15 14:51:04 +02:00
|
|
|
|
|
|
|
private function urlRSS($url)
|
|
|
|
{
|
|
|
|
return preg_replace_callback('/[^\x20-\x7f]/', function($match) { return urlencode($match[0]); }, $url);
|
|
|
|
}
|
2017-06-04 21:08:31 +02:00
|
|
|
|
2016-01-11 23:51:00 +01:00
|
|
|
private function createXML()
|
|
|
|
{
|
2018-07-17 19:13:01 +02:00
|
|
|
global $site;
|
2018-08-03 18:59:23 +02:00
|
|
|
global $pages;
|
2018-07-17 19:13:01 +02:00
|
|
|
global $url;
|
2016-01-11 23:51:00 +01:00
|
|
|
|
2017-06-04 21:08:31 +02:00
|
|
|
// Amount of pages to show
|
2018-08-06 21:46:58 +02:00
|
|
|
$numberOfItems = $this->getValue('numberOfItems');
|
2017-06-04 21:08:31 +02:00
|
|
|
|
2019-04-01 14:38:26 +02:00
|
|
|
// Get the list of public pages (sticky and static included)
|
|
|
|
$list = $pages->getList(
|
|
|
|
$pageNumber=1,
|
|
|
|
$numberOfItems,
|
|
|
|
$published=true,
|
|
|
|
$static=true,
|
|
|
|
$sticky=true,
|
|
|
|
$draft=false,
|
|
|
|
$scheduled=false
|
|
|
|
);
|
2017-06-04 21:08:31 +02:00
|
|
|
|
2016-01-11 23:51:00 +01:00
|
|
|
$xml = '<?xml version="1.0" encoding="UTF-8" ?>';
|
2019-09-15 14:51:04 +02:00
|
|
|
$xml .= '<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">';
|
2016-01-11 23:51:00 +01:00
|
|
|
$xml .= '<channel>';
|
2019-09-15 14:51:04 +02:00
|
|
|
$xml .= '<atom:link href="'.DOMAIN_BASE.'rss.xml" rel="self" type="application/rss+xml" />';
|
2018-07-17 19:13:01 +02:00
|
|
|
$xml .= '<title>'.$site->title().'</title>';
|
2019-09-15 14:51:04 +02:00
|
|
|
$xml .= '<link>'.$this->urlRSS($site->url()).'</link>';
|
2018-07-17 19:13:01 +02:00
|
|
|
$xml .= '<description>'.$site->description().'</description>';
|
2019-02-12 08:13:18 +01:00
|
|
|
$xml .= '<lastBuildDate>'.date(DATE_RSS).'</lastBuildDate>';
|
2016-01-11 23:51:00 +01:00
|
|
|
|
2017-06-04 21:08:31 +02:00
|
|
|
// Get keys of pages
|
2018-09-05 22:55:14 +02:00
|
|
|
foreach ($list as $pageKey) {
|
2018-07-18 21:48:37 +02:00
|
|
|
try {
|
|
|
|
// Create the page object from the page key
|
2018-08-02 17:06:53 +02:00
|
|
|
$page = new Page($pageKey);
|
2018-07-18 21:48:37 +02:00
|
|
|
$xml .= '<item>';
|
|
|
|
$xml .= '<title>'.$page->title().'</title>';
|
2019-09-15 14:51:04 +02:00
|
|
|
$xml .= '<link>'.$this->urlRSS($page->permalink()).'</link>';
|
2018-07-18 21:48:37 +02:00
|
|
|
$xml .= '<description>'.Sanitize::html($page->contentBreak()).'</description>';
|
2018-11-25 17:46:17 +01:00
|
|
|
$xml .= '<pubDate>'.$page->date(DATE_RSS).'</pubDate>';
|
2018-07-18 21:48:37 +02:00
|
|
|
$xml .= '<guid isPermaLink="false">'.$page->uuid().'</guid>';
|
|
|
|
$xml .= '</item>';
|
|
|
|
} catch (Exception $e) {
|
|
|
|
// Continue
|
|
|
|
}
|
2016-01-11 23:51:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
$xml .= '</channel></rss>';
|
|
|
|
|
|
|
|
// New DOM document
|
|
|
|
$doc = new DOMDocument();
|
|
|
|
$doc->formatOutput = true;
|
|
|
|
$doc->loadXML($xml);
|
2018-09-05 22:55:14 +02:00
|
|
|
return $doc->save($this->workspace().'rss.xml');
|
2016-01-11 23:51:00 +01:00
|
|
|
}
|
|
|
|
|
2017-06-04 21:08:31 +02:00
|
|
|
public function install($position=0)
|
2016-01-11 23:51:00 +01:00
|
|
|
{
|
|
|
|
parent::install($position);
|
2018-09-05 22:55:14 +02:00
|
|
|
return $this->createXML();
|
2016-01-11 23:51:00 +01:00
|
|
|
}
|
|
|
|
|
2018-02-28 11:08:35 +01:00
|
|
|
public function post()
|
|
|
|
{
|
|
|
|
parent::post();
|
2019-01-28 22:12:33 +01:00
|
|
|
return $this->createXML();
|
2018-02-28 11:08:35 +01:00
|
|
|
}
|
|
|
|
|
2016-01-11 23:51:00 +01:00
|
|
|
public function afterPageCreate()
|
|
|
|
{
|
|
|
|
$this->createXML();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function afterPageModify()
|
|
|
|
{
|
|
|
|
$this->createXML();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function afterPageDelete()
|
|
|
|
{
|
|
|
|
$this->createXML();
|
|
|
|
}
|
|
|
|
|
2016-01-17 23:05:46 +01:00
|
|
|
public function siteHead()
|
|
|
|
{
|
2017-06-04 21:08:31 +02:00
|
|
|
return '<link rel="alternate" type="application/rss+xml" href="'.DOMAIN_BASE.'rss.xml" title="RSS Feed">'.PHP_EOL;
|
2016-01-17 23:05:46 +01:00
|
|
|
}
|
|
|
|
|
2017-07-29 01:20:47 +02:00
|
|
|
public function beforeAll()
|
2016-01-11 23:51:00 +01:00
|
|
|
{
|
2017-07-29 01:20:47 +02:00
|
|
|
$webhook = 'rss.xml';
|
2018-07-02 00:24:53 +02:00
|
|
|
if ($this->webhook($webhook)) {
|
2016-01-11 23:51:00 +01:00
|
|
|
// Send XML header
|
|
|
|
header('Content-type: text/xml');
|
|
|
|
$doc = new DOMDocument();
|
|
|
|
|
|
|
|
// Load XML
|
2016-10-01 21:13:24 +02:00
|
|
|
libxml_disable_entity_loader(false);
|
2017-06-04 21:08:31 +02:00
|
|
|
$doc->load($this->workspace().'rss.xml');
|
2016-10-01 21:13:24 +02:00
|
|
|
libxml_disable_entity_loader(true);
|
2016-01-11 23:51:00 +01:00
|
|
|
|
|
|
|
// Print the XML
|
|
|
|
echo $doc->saveXML();
|
|
|
|
|
2018-07-02 00:24:53 +02:00
|
|
|
// Stop Bludit execution
|
2017-06-04 21:08:31 +02:00
|
|
|
exit(0);
|
2016-01-11 23:51:00 +01:00
|
|
|
}
|
|
|
|
}
|
2019-02-12 08:13:18 +01:00
|
|
|
}
|