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(
|
|
|
|
'amountOfItems'=>5
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Method called on the settings of the plugin on the admin area
|
|
|
|
public function form()
|
|
|
|
{
|
|
|
|
global $Language;
|
|
|
|
|
|
|
|
$html = '<div>';
|
|
|
|
$html .= '<label>'.$Language->get('Amount of items').'</label>';
|
|
|
|
$html .= '<input id="jsamountOfItems" name="amountOfItems" type="text" value="'.$this->getValue('amountOfItems').'">';
|
2017-09-09 00:33:14 +02:00
|
|
|
$html .= '<span class="tip">'.$Language->get('Amount of items to show on the feed').'</span>';
|
2017-06-04 21:08:31 +02:00
|
|
|
$html .= '</div>';
|
|
|
|
|
|
|
|
return $html;
|
|
|
|
}
|
|
|
|
|
2016-01-11 23:51:00 +01:00
|
|
|
private function createXML()
|
|
|
|
{
|
|
|
|
global $Site;
|
|
|
|
global $dbPages;
|
|
|
|
global $Url;
|
|
|
|
|
2017-06-04 21:08:31 +02:00
|
|
|
// Amount of pages to show
|
|
|
|
$amountOfItems = $this->getValue('amountOfItems');
|
|
|
|
|
|
|
|
// Page number the first one
|
|
|
|
$pageNumber = 1;
|
|
|
|
|
|
|
|
// Only published pages
|
|
|
|
$onlyPublished = true;
|
|
|
|
|
|
|
|
// Get the list of pages
|
|
|
|
$pages = $dbPages->getList($pageNumber, $amountOfItems, $onlyPublished, true);
|
|
|
|
|
2016-01-11 23:51:00 +01:00
|
|
|
$xml = '<?xml version="1.0" encoding="UTF-8" ?>';
|
|
|
|
$xml .= '<rss version="2.0">';
|
|
|
|
$xml .= '<channel>';
|
|
|
|
$xml .= '<title>'.$Site->title().'</title>';
|
|
|
|
$xml .= '<link>'.$Site->url().'</link>';
|
|
|
|
$xml .= '<description>'.$Site->description().'</description>';
|
|
|
|
|
2017-06-04 21:08:31 +02:00
|
|
|
// Get keys of pages
|
|
|
|
$keys = array_keys($pages);
|
|
|
|
foreach($keys as $pageKey) {
|
|
|
|
// Create the page object from the page key
|
|
|
|
$page = buildPage($pageKey);
|
2016-01-11 23:51:00 +01:00
|
|
|
$xml .= '<item>';
|
2017-06-04 21:08:31 +02:00
|
|
|
$xml .= '<title>'.$page->title().'</title>';
|
|
|
|
$xml .= '<link>'.$page->permalink().'</link>';
|
|
|
|
$xml .= '<description>'.$page->contentBreak().'</description>';
|
|
|
|
$xml .= '<pubDate>'.$page->dateRaw('r').'</pubDate>';
|
|
|
|
$xml .= '<guid isPermaLink="false">'.$page->uuid().'</guid>';
|
2016-01-11 23:51:00 +01:00
|
|
|
$xml .= '</item>';
|
|
|
|
}
|
|
|
|
|
|
|
|
$xml .= '</channel></rss>';
|
|
|
|
|
|
|
|
// New DOM document
|
|
|
|
$doc = new DOMDocument();
|
|
|
|
$doc->formatOutput = true;
|
|
|
|
$doc->loadXML($xml);
|
2017-06-04 21:08:31 +02:00
|
|
|
$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);
|
|
|
|
$this->createXML();
|
|
|
|
}
|
|
|
|
|
|
|
|
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';
|
|
|
|
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();
|
|
|
|
|
|
|
|
// Stop Bludit running
|
2017-06-04 21:08:31 +02:00
|
|
|
exit(0);
|
2016-01-11 23:51:00 +01:00
|
|
|
}
|
|
|
|
}
|
2017-05-04 20:35:05 +02:00
|
|
|
}
|