From 640b58ecdf356245d3351431d537304bd8d0d41d Mon Sep 17 00:00:00 2001 From: dignajar Date: Mon, 11 Jan 2016 19:51:00 -0300 Subject: [PATCH] RSS Plugin, improves on code --- kernel/abstract/plugin.class.php | 13 +++- kernel/boot/init.php | 10 +++ kernel/boot/rules/71.pages.php | 5 ++ kernel/dbsite.class.php | 9 +-- kernel/page.class.php | 20 ++++-- kernel/post.class.php | 2 +- plugins/rss/information.json | 12 ++++ plugins/rss/languages/en_US.json | 12 ++++ plugins/rss/plugin.php | 102 +++++++++++++++++++++++++++++++ plugins/sitemap/plugin.php | 7 --- 10 files changed, 174 insertions(+), 18 deletions(-) create mode 100644 plugins/rss/information.json create mode 100644 plugins/rss/languages/en_US.json create mode 100644 plugins/rss/plugin.php diff --git a/kernel/abstract/plugin.class.php b/kernel/abstract/plugin.class.php index 49284713..5ca8e245 100644 --- a/kernel/abstract/plugin.class.php +++ b/kernel/abstract/plugin.class.php @@ -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); } diff --git a/kernel/boot/init.php b/kernel/boot/init.php index 7b1731f4..8a88339b 100644 --- a/kernel/boot/init.php +++ b/kernel/boot/init.php @@ -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 ); diff --git a/kernel/boot/rules/71.pages.php b/kernel/boot/rules/71.pages.php index 06d0c2bf..0d0c739f 100644 --- a/kernel/boot/rules/71.pages.php +++ b/kernel/boot/rules/71.pages.php @@ -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); diff --git a/kernel/dbsite.class.php b/kernel/dbsite.class.php index 25e29a3b..add96d88 100644 --- a/kernel/dbsite.class.php +++ b/kernel/dbsite.class.php @@ -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. diff --git a/kernel/page.class.php b/kernel/page.class.php index fdbf92df..2af00c61 100644 --- a/kernel/page.class.php +++ b/kernel/page.class.php @@ -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) diff --git a/kernel/post.class.php b/kernel/post.class.php index c8789bc3..b3fa9a8d 100644 --- a/kernel/post.class.php +++ b/kernel/post.class.php @@ -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,'/'); diff --git a/plugins/rss/information.json b/plugins/rss/information.json new file mode 100644 index 00000000..6f9fde99 --- /dev/null +++ b/plugins/rss/information.json @@ -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" + } +} \ No newline at end of file diff --git a/plugins/rss/languages/en_US.json b/plugins/rss/languages/en_US.json new file mode 100644 index 00000000..6f9fde99 --- /dev/null +++ b/plugins/rss/languages/en_US.json @@ -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" + } +} \ No newline at end of file diff --git a/plugins/rss/plugin.php b/plugins/rss/plugin.php new file mode 100644 index 00000000..1bff0f62 --- /dev/null +++ b/plugins/rss/plugin.php @@ -0,0 +1,102 @@ +'; + $xml .= ''; + $xml .= ''; + $xml .= ''.$Site->title().''; + $xml .= ''.$Site->url().''; + $xml .= ''.$Site->description().''; + + $posts = buildPostsForPage(0, 10, true); + foreach($posts as $Post) + { + $xml .= ''; + $xml .= ''.$Post->title().''; + $xml .= ''.$Post->permalink(true).''; + $xml .= ''.$Post->description().''; + $xml .= ''; + } + + $xml .= ''; + + // 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; + } + } + +} \ No newline at end of file diff --git a/plugins/sitemap/plugin.php b/plugins/sitemap/plugin.php index 2f7e180a..48af4b94 100644 --- a/plugins/sitemap/plugin.php +++ b/plugins/sitemap/plugin.php @@ -2,13 +2,6 @@ class pluginSitemap extends Plugin { - public function init() - { - $this->dbFields = array( - 'label'=>'Tags' - ); - } - private function createXML() { global $Site;