RSS Plugin, improves on code
This commit is contained in:
parent
9323fe2f5a
commit
640b58ecdf
|
@ -68,6 +68,11 @@ class Plugin {
|
|||
return PATH_PLUGINS.$this->directoryName.DS;
|
||||
}
|
||||
|
||||
public function phpPathDB()
|
||||
{
|
||||
return PATH_PLUGINS_DATABASES.$this->directoryName.DS;
|
||||
}
|
||||
|
||||
// Returns the item from plugin-data.
|
||||
public function getData($key)
|
||||
{
|
||||
|
@ -181,7 +186,13 @@ class Plugin {
|
|||
|
||||
public function uninstall()
|
||||
{
|
||||
unlink($this->filenameDb);
|
||||
// Delete all files.
|
||||
$files = Filesystem::listFiles( $this->phpPathDB() );
|
||||
foreach($files as $file) {
|
||||
unlink($file);
|
||||
}
|
||||
|
||||
// Delete the directory.
|
||||
rmdir(PATH_PLUGINS_DATABASES.$this->directoryName);
|
||||
}
|
||||
|
||||
|
|
|
@ -218,6 +218,16 @@ define('PATH_THEME_JS', PATH_THEME.'js'.DS);
|
|||
define('PATH_THEME_IMG', PATH_THEME.'img'.DS);
|
||||
define('PATH_THEME_LANG', PATH_THEME.'languages'.DS);
|
||||
|
||||
// --- Absolute paths with domain ---
|
||||
define('DOMAIN', $Site->domain());
|
||||
define('DOMAIN_BASE', DOMAIN.HTML_PATH_ROOT);
|
||||
define('DOMAIN_THEME_CSS', DOMAIN.HTML_PATH_THEME_CSS);
|
||||
define('DOMAIN_THEME_JS', DOMAIN.HTML_PATH_THEME_JS);
|
||||
define('DOMAIN_THEME_IMG', DOMAIN.HTML_PATH_THEME_IMG);
|
||||
define('DOMAIN_UPLOADS', DOMAIN.HTML_PATH_UPLOADS);
|
||||
define('DOMAIN_UPLOADS_PROFILES', DOMAIN.HTML_PATH_UPLOADS_PROFILES);
|
||||
define('DOMAIN_UPLOADS_THUMBNAILS', DOMAIN.HTML_PATH_UPLOADS_THUMBNAILS);
|
||||
|
||||
// --- Objects with dependency ---
|
||||
$Language = new dbLanguage( $Site->locale() );
|
||||
$Login = new Login( $dbUsers );
|
||||
|
|
|
@ -59,6 +59,11 @@ function buildPage($key)
|
|||
$content = Text::imgRel2Abs($content, HTML_PATH_UPLOADS); // Parse img src relative to absolute.
|
||||
$Page->setField('content', $content, true);
|
||||
|
||||
// Pagebrake
|
||||
$explode = explode(PAGE_BREAK, $content);
|
||||
$Page->setField('breakContent', $explode[0], true);
|
||||
$Page->setField('readMore', !empty($explode[1]), true);
|
||||
|
||||
// Date format
|
||||
$pageDate = $Page->date();
|
||||
$Page->setField('dateRaw', $pageDate, true);
|
||||
|
|
|
@ -170,16 +170,17 @@ class dbSite extends dbJSON
|
|||
$protocol = 'http://';
|
||||
}
|
||||
|
||||
$domain = $_SERVER['HTTP_HOST'];
|
||||
$domain = trim($_SERVER['HTTP_HOST'], '/');
|
||||
|
||||
return $protocol.$domain.HTML_PATH_ROOT;
|
||||
return $protocol.$domain;
|
||||
}
|
||||
|
||||
// Parse the domain from the field URL.
|
||||
$parse = parse_url($this->url());
|
||||
$domain = $parse['scheme']."://".$parse['host'];
|
||||
|
||||
return $domain;
|
||||
$domain = trim($parse['host'], '/');
|
||||
|
||||
return $parse['scheme'].'://'.$domain;
|
||||
}
|
||||
|
||||
// Returns TRUE if the cli mode is enabled, otherwise FALSE.
|
||||
|
|
|
@ -15,21 +15,31 @@ class Page extends fileContent
|
|||
{
|
||||
return $this->getField('title');
|
||||
}
|
||||
|
||||
// Returns the content. This content is markdown parser.
|
||||
// (boolean) $html, TRUE returns the content without satinize, FALSE otherwise.
|
||||
public function content($html=true)
|
||||
// Returns the content.
|
||||
// This content is markdown parser.
|
||||
// (boolean) $fullContent, TRUE returns all content, if FALSE returns the first part of the content.
|
||||
// (boolean) $raw, TRUE returns the content without sanitized, FALSE otherwise.
|
||||
public function content($fullContent=true, $raw=true)
|
||||
{
|
||||
// This content is not sanitized.
|
||||
$content = $this->getField('content');
|
||||
|
||||
if($html) {
|
||||
if(!$fullContent) {
|
||||
$content = $this->getField('breakContent');
|
||||
}
|
||||
|
||||
if($raw) {
|
||||
return $content;
|
||||
}
|
||||
|
||||
return Sanitize::html($content);
|
||||
}
|
||||
|
||||
public function readMore()
|
||||
{
|
||||
return $this->getField('readMore');
|
||||
}
|
||||
|
||||
// Returns the content. This content is not markdown parser.
|
||||
// (boolean) $raw, TRUE returns the content without sanitized, FALSE otherwise.
|
||||
public function contentRaw($raw=true)
|
||||
|
|
|
@ -186,7 +186,7 @@ class Post extends fileContent
|
|||
global $Url;
|
||||
global $Site;
|
||||
|
||||
$url = trim($Site->url(),'/');
|
||||
$url = trim(DOMAIN_BASE,'/');
|
||||
$key = $this->key();
|
||||
$filter = trim($Url->filters('post'), '/');
|
||||
$htmlPath = trim(HTML_PATH_ROOT,'/');
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
{
|
||||
"plugin-data":
|
||||
{
|
||||
"name": "RSS",
|
||||
"description": "This plugin generate a file rss.xml.",
|
||||
"author": "Bludit",
|
||||
"email": "",
|
||||
"website": "https://github.com/dignajar/bludit-plugins",
|
||||
"version": "1.0",
|
||||
"releaseDate": "2016-01-07"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
{
|
||||
"plugin-data":
|
||||
{
|
||||
"name": "RSS",
|
||||
"description": "This plugin generate a file rss.xml.",
|
||||
"author": "Bludit",
|
||||
"email": "",
|
||||
"website": "https://github.com/dignajar/bludit-plugins",
|
||||
"version": "1.0",
|
||||
"releaseDate": "2016-01-07"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,102 @@
|
|||
<?php
|
||||
|
||||
class pluginRSS extends Plugin {
|
||||
|
||||
private function createXML()
|
||||
{
|
||||
global $Site;
|
||||
global $dbPages;
|
||||
global $dbPosts;
|
||||
global $Url;
|
||||
|
||||
$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>';
|
||||
|
||||
$posts = buildPostsForPage(0, 10, true);
|
||||
foreach($posts as $Post)
|
||||
{
|
||||
$xml .= '<item>';
|
||||
$xml .= '<title>'.$Post->title().'</title>';
|
||||
$xml .= '<link>'.$Post->permalink(true).'</link>';
|
||||
$xml .= '<description>'.$Post->description().'</description>';
|
||||
$xml .= '</item>';
|
||||
}
|
||||
|
||||
$xml .= '</channel></rss>';
|
||||
|
||||
// New DOM document
|
||||
$doc = new DOMDocument();
|
||||
|
||||
// Friendly XML code
|
||||
$doc->formatOutput = true;
|
||||
|
||||
$doc->loadXML($xml);
|
||||
|
||||
$doc->save(PATH_PLUGINS_DATABASES.$this->directoryName.DS.'rss.xml');
|
||||
}
|
||||
|
||||
public function install($position = 0)
|
||||
{
|
||||
parent::install($position);
|
||||
|
||||
$this->createXML();
|
||||
}
|
||||
|
||||
public function afterPostCreate()
|
||||
{
|
||||
$this->createXML();
|
||||
}
|
||||
|
||||
public function afterPageCreate()
|
||||
{
|
||||
$this->createXML();
|
||||
}
|
||||
|
||||
public function afterPostModify()
|
||||
{
|
||||
$this->createXML();
|
||||
}
|
||||
|
||||
public function afterPageModify()
|
||||
{
|
||||
$this->createXML();
|
||||
}
|
||||
|
||||
public function afterPostDelete()
|
||||
{
|
||||
$this->createXML();
|
||||
}
|
||||
|
||||
public function afterPageDelete()
|
||||
{
|
||||
$this->createXML();
|
||||
}
|
||||
|
||||
public function beforeRulesLoad()
|
||||
{
|
||||
global $Url;
|
||||
|
||||
if( $Url->uri() === HTML_PATH_ROOT.'rss.xml' )
|
||||
{
|
||||
// Send XML header
|
||||
header('Content-type: text/xml');
|
||||
|
||||
// New DOM document
|
||||
$doc = new DOMDocument();
|
||||
|
||||
// Load XML
|
||||
$doc->load(PATH_PLUGINS_DATABASES.$this->directoryName.DS.'rss.xml');
|
||||
|
||||
// Print the XML
|
||||
echo $doc->saveXML();
|
||||
|
||||
// Stop Bludit running
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -2,13 +2,6 @@
|
|||
|
||||
class pluginSitemap extends Plugin {
|
||||
|
||||
public function init()
|
||||
{
|
||||
$this->dbFields = array(
|
||||
'label'=>'Tags'
|
||||
);
|
||||
}
|
||||
|
||||
private function createXML()
|
||||
{
|
||||
global $Site;
|
||||
|
|
Loading…
Reference in New Issue