Bug fixes, developer area, google plugin updated, rss and sitemap updated

This commit is contained in:
Diego Najar 2017-06-04 21:08:31 +02:00
parent dc25f269e2
commit 6ca24ac456
21 changed files with 246 additions and 213 deletions

View File

@ -197,6 +197,11 @@ class Plugin {
return $this->directoryName; return $this->directoryName;
} }
public function workspace()
{
return PATH_PLUGINS_DATABASES.$this->directoryName.DS;
}
// Return TRUE if the installation success, otherwise FALSE. // Return TRUE if the installation success, otherwise FALSE.
public function install($position=0) public function install($position=0)
{ {

View File

@ -0,0 +1,49 @@
<?php defined('BLUDIT') or die('Bludit CMS.');
// ============================================================================
// Check role
// ============================================================================
// ============================================================================
// Functions
// ============================================================================
function printTable($title, $array) {
echo '<h2>'.$title.'</h2>';
echo '
<table class="uk-table uk-table-striped">
<thead>
<tr>
<th class="uk-width-1-5"></th>
<th class="uk-width-3-5"></th>
</tr>
</thead>
<tbody>
';
foreach($array as $key=>$value) {
if($value===false) { $value = 'false'; }
elseif($value===true) { $value = 'true'; }
echo '<tr>';
echo '<td>'.$key.'</td>';
echo '<td>'.Sanitize::html($value).'</td>';
echo '</tr>';
}
echo '
</tbody>
</table>
';
}
// ============================================================================
// Main before POST
// ============================================================================
// ============================================================================
// POST Method
// ============================================================================
// ============================================================================
// Main after POST
// ============================================================================

View File

@ -0,0 +1,10 @@
<?php
HTML::title(array('title'=>$L->g('Developers'), 'icon'=>'support'));
// Constanst defined by Bludit
$constants = get_defined_constants(true);
printTable('CONSTANTS', $constants['user']);
// Site object
printTable('$Site object database',$Site->db);

View File

@ -56,9 +56,6 @@ define('DB_CATEGORIES', PATH_DATABASES.'categories.php');
define('DB_TAGS', PATH_DATABASES.'tags.php'); define('DB_TAGS', PATH_DATABASES.'tags.php');
define('DB_SYSLOG', PATH_DATABASES.'syslog.php'); define('DB_SYSLOG', PATH_DATABASES.'syslog.php');
// ADMIN URI FILTER
define('ADMIN_URI_FILTER', '/admin/');
// Log separator // Log separator
define('LOG_SEP', ' | '); define('LOG_SEP', ' | ');
@ -137,6 +134,9 @@ define('EXTREME_FRIENDLY_URL', FALSE);
// Permissions for new directories // Permissions for new directories
define('DIR_PERMISSIONS', 0755); define('DIR_PERMISSIONS', 0755);
// Admin URI filter
define('ADMIN_URI_FILTER', '/admin/');
// Set internal character encoding // Set internal character encoding
mb_internal_encoding(CHARSET); mb_internal_encoding(CHARSET);
@ -250,11 +250,20 @@ $Language = new dbLanguage( $Site->locale() );
$Login = new Login( $dbUsers ); $Login = new Login( $dbUsers );
$Url->checkFilters( $Site->uriFilters() ); $Url->checkFilters( $Site->uriFilters() );
// --- Objects shortcuts ---
$L = $Language;
// --- CONSTANTS with dependency --- // --- CONSTANTS with dependency ---
// Tag URI filter
define('TAG_URI_FILTER', $Url->filters('tag'));
// Category URI filter
define('CATEGORY_URI_FILTER', $Url->filters('category'));
// Page URI filter
define('PAGE_URI_FILTER', $Url->filters('page'));
// Content order by: date / position
define('ORDER_BY', $Site->orderBy());
// --- PHP paths with dependency --- // --- PHP paths with dependency ---
// This paths are absolutes for the OS // This paths are absolutes for the OS
define('THEME_DIR', PATH_ROOT.'bl-themes'.DS.$Site->theme().DS); define('THEME_DIR', PATH_ROOT.'bl-themes'.DS.$Site->theme().DS);
@ -267,7 +276,7 @@ define('THEME_DIR_LANG', THEME_DIR.'languages'.DS);
// --- Absolute paths with domain --- // --- Absolute paths with domain ---
// This paths are absolutes for the user / web browsing. // This paths are absolutes for the user / web browsing.
define('DOMAIN', $Site->domain()); define('DOMAIN', $Site->domain());
define('DOMAIN_BASE', $Site->url()); define('DOMAIN_BASE', DOMAIN.HTML_PATH_ROOT);
define('DOMAIN_THEME', DOMAIN.HTML_PATH_THEME); define('DOMAIN_THEME', DOMAIN.HTML_PATH_THEME);
define('DOMAIN_THEME_CSS', DOMAIN.HTML_PATH_THEME_CSS); define('DOMAIN_THEME_CSS', DOMAIN.HTML_PATH_THEME_CSS);
define('DOMAIN_THEME_JS', DOMAIN.HTML_PATH_THEME_JS); define('DOMAIN_THEME_JS', DOMAIN.HTML_PATH_THEME_JS);
@ -275,17 +284,19 @@ define('DOMAIN_THEME_IMG', DOMAIN.HTML_PATH_THEME_IMG);
define('DOMAIN_UPLOADS', DOMAIN.HTML_PATH_UPLOADS); define('DOMAIN_UPLOADS', DOMAIN.HTML_PATH_UPLOADS);
define('DOMAIN_UPLOADS_PROFILES', DOMAIN.HTML_PATH_UPLOADS_PROFILES); define('DOMAIN_UPLOADS_PROFILES', DOMAIN.HTML_PATH_UPLOADS_PROFILES);
define('DOMAIN_UPLOADS_THUMBNAILS', DOMAIN.HTML_PATH_UPLOADS_THUMBNAILS); define('DOMAIN_UPLOADS_THUMBNAILS', DOMAIN.HTML_PATH_UPLOADS_THUMBNAILS);
define('DOMAIN_TAGS', trim(DOMAIN_BASE, '/').'/'.$Url->filters('tag',$trim=true).'/');
define('DOMAIN_CATEGORY', trim(DOMAIN_BASE, '/').'/'.$Url->filters('category',$trim=true).'/');
define('DOMAIN_PAGE', trim(DOMAIN_BASE, '/').'/'.$Url->filters('page',$trim=true).'/');
define('ORDER_BY', $Site->orderBy()); define('DOMAIN_TAGS', Text::addSlashes(DOMAIN_BASE.TAG_URI_FILTER, false, true));
define('DOMAIN_CATEGORY', Text::addSlashes(DOMAIN_BASE.CATEGORY_URI_FILTER, false, true));
define('DOMAIN_PAGE', Text::addSlashes(DOMAIN_BASE.PAGE_URI_FILTER, false, true));
$ADMIN_CONTROLLER = ''; $ADMIN_CONTROLLER = '';
$ADMIN_VIEW = ''; $ADMIN_VIEW = '';
$ID_EXECUTION = uniqid(); // string 13 characters long $ID_EXECUTION = uniqid(); // string 13 characters long
$WHERE_AM_I = $Url->whereAmI(); $WHERE_AM_I = $Url->whereAmI();
// --- Objects shortcuts ---
$L = $Language;
// DEBUG: Print constants // DEBUG: Print constants
// $arr = array_filter(get_defined_constants(), 'is_string'); // $arr = array_filter(get_defined_constants(), 'is_string');
// echo json_encode($arr); // echo json_encode($arr);

View File

@ -78,6 +78,15 @@ class Page {
return false; return false;
} }
public function getValue($field)
{
if(isset($this->vars[$field])) {
return $this->vars[$field];
}
return false;
}
// Set a field with a value // Set a field with a value
public function setField($field, $value, $overwrite=true) public function setField($field, $value, $overwrite=true)
{ {
@ -95,7 +104,7 @@ class Page {
public function content($fullContent=true, $noSanitize=true) public function content($fullContent=true, $noSanitize=true)
{ {
// This content is not sanitized. // This content is not sanitized.
$content = $this->getField('content'); $content = $this->getValue('content');
if(!$fullContent) { if(!$fullContent) {
return $this->contentBreak(); return $this->contentBreak();
@ -110,7 +119,7 @@ class Page {
public function contentBreak() public function contentBreak()
{ {
return $this->getField('contentBreak'); return $this->getValue('contentBreak');
} }
// Returns the raw content // Returns the raw content
@ -119,7 +128,7 @@ class Page {
public function contentRaw($noSanitize=true) public function contentRaw($noSanitize=true)
{ {
// This content is not sanitized. // This content is not sanitized.
$content = $this->getField('contentRaw'); $content = $this->getValue('contentRaw');
if($noSanitize) { if($noSanitize) {
return $content; return $content;
@ -131,14 +140,14 @@ class Page {
// Returns the date according to locale settings and format settings // Returns the date according to locale settings and format settings
public function date() public function date()
{ {
return $this->getField('date'); return $this->getValue('date');
} }
// Returns the date according to locale settings and format as database stored // Returns the date according to locale settings and format as database stored
// (string) $format, you can specify the date format // (string) $format, you can specify the date format
public function dateRaw($format=false) public function dateRaw($format=false)
{ {
$date = $this->getField('dateRaw'); $date = $this->getValue('dateRaw');
if($format) { if($format) {
return Date::format($date, DB_DATE_FORMAT, $format); return Date::format($date, DB_DATE_FORMAT, $format);
@ -151,28 +160,27 @@ class Page {
// (boolean) $absolute, TRUE returns the page link with the DOMAIN, FALSE without the DOMAIN // (boolean) $absolute, TRUE returns the page link with the DOMAIN, FALSE without the DOMAIN
public function permalink($absolute=true) public function permalink($absolute=true)
{ {
global $Url; // Get the key of the page
$key = $this->getValue('key');
$key = $this->getField('key');
if($absolute) { if($absolute) {
return DOMAIN_PAGE.$key; return DOMAIN_PAGE.$key;
} }
$filter = $Url->filters('page', true); return HTML_PATH_ROOT.PAGE_URI_FILTER.$key;
return trim(HTML_PATH_ROOT,'/').'/'.$filter.'/'.$key;
} }
// Returns the category key // Returns the category key
public function categoryKey() public function categoryKey()
{ {
return $this->getField('category'); return $this->getValue('category');
} }
// Returns the field from the array // Returns the field from the array
// categoryMap = array( 'name'=>'', 'list'=>array() ) // categoryMap = array( 'name'=>'', 'list'=>array() )
public function categoryMap($field) public function categoryMap($field)
{ {
$map = $this->getField('categoryMap'); $map = $this->getValue('categoryMap');
if($field=='key') { if($field=='key') {
return $this->categoryKey(); return $this->categoryKey();
@ -192,7 +200,7 @@ class Page {
public function user($field=false) public function user($field=false)
{ {
// Get the user object. // Get the user object.
$User = $this->getField('user'); $User = $this->getValue('user');
if($field) { if($field) {
return $User->getField($field); return $User->getField($field);
@ -204,13 +212,13 @@ class Page {
// Returns the username who created the post/page // Returns the username who created the post/page
public function username() public function username()
{ {
return $this->getField('username'); return $this->getValue('username');
} }
// Returns the description field // Returns the description field
public function description() public function description()
{ {
return $this->getField('description'); return $this->getValue('description');
} }
@ -222,7 +230,7 @@ class Page {
// $complete = true : full version // $complete = true : full version
public function relativeTime($complete = false) { public function relativeTime($complete = false) {
$current = new DateTime; $current = new DateTime;
$past = new DateTime($this->getField('date')); $past = new DateTime($this->getValue('date'));
$elapsed = $current->diff($past); $elapsed = $current->diff($past);
$elapsed->w = floor($elapsed->d / 7); $elapsed->w = floor($elapsed->d / 7);
@ -258,7 +266,7 @@ class Page {
// (boolean) $returnsArray, TRUE to get the tags as an array, FALSE to get the tags separeted by comma // (boolean) $returnsArray, TRUE to get the tags as an array, FALSE to get the tags separeted by comma
public function tags($returnsArray=false) public function tags($returnsArray=false)
{ {
$tags = $this->getField('tags'); $tags = $this->getValue('tags');
if($returnsArray) { if($returnsArray) {
if($tags==false) { if($tags==false) {
@ -298,7 +306,7 @@ class Page {
// (boolean) $absolute, TRUE returns the absolute path and file name, FALSE just the file name // (boolean) $absolute, TRUE returns the absolute path and file name, FALSE just the file name
public function coverImage($absolute=true) public function coverImage($absolute=true)
{ {
$fileName = $this->getField('coverImage'); $fileName = $this->getValue('coverImage');
if(empty($fileName)) { if(empty($fileName)) {
return false; return false;
} }
@ -313,60 +321,60 @@ class Page {
// Returns TRUE if the content has the text splited // Returns TRUE if the content has the text splited
public function readMore() public function readMore()
{ {
return $this->getField('readMore'); return $this->getValue('readMore');
} }
public function uuid() public function uuid()
{ {
return $this->getField('uuid'); return $this->getValue('uuid');
} }
// Returns the field key // Returns the field key
public function key() public function key()
{ {
return $this->getField('key'); return $this->getValue('key');
} }
// Returns TRUE if the post/page is published, FALSE otherwise. // Returns TRUE if the post/page is published, FALSE otherwise.
public function published() public function published()
{ {
return ($this->getField('status')==='published'); return ($this->getValue('status')==='published');
} }
// Returns TRUE if the post/page is scheduled, FALSE otherwise. // Returns TRUE if the post/page is scheduled, FALSE otherwise.
public function scheduled() public function scheduled()
{ {
return ($this->getField('status')==='scheduled'); return ($this->getValue('status')==='scheduled');
} }
// Returns TRUE if the post/page is draft, FALSE otherwise. // Returns TRUE if the post/page is draft, FALSE otherwise.
public function draft() public function draft()
{ {
return ($this->getField('status')=='draft'); return ($this->getValue('status')=='draft');
} }
// Returns the title field // Returns the title field
public function title() public function title()
{ {
return $this->getField('title'); return $this->getValue('title');
} }
// Returns TRUE if the page has enabled the comments, FALSE otherwise // Returns TRUE if the page has enabled the comments, FALSE otherwise
public function allowComments() public function allowComments()
{ {
return $this->getField('allowComments'); return $this->getValue('allowComments');
} }
// Returns the page position // Returns the page position
public function position() public function position()
{ {
return $this->getField('position'); return $this->getValue('position');
} }
// Returns the page slug // Returns the page slug
public function slug() public function slug()
{ {
$explode = explode('/', $this->getField('key')); $explode = explode('/', $this->getValue('key'));
// Check if the page have a parent. // Check if the page have a parent.
if(!empty($explode[1])) { if(!empty($explode[1])) {
@ -379,7 +387,7 @@ class Page {
// Returns the parent key, if the page doesn't have a parent returns FALSE // Returns the parent key, if the page doesn't have a parent returns FALSE
public function parentKey() public function parentKey()
{ {
$explode = explode('/', $this->getField('key')); $explode = explode('/', $this->getValue('key'));
if(isset($explode[1])) { if(isset($explode[1])) {
return $explode[0]; return $explode[0];
} }
@ -403,8 +411,8 @@ class Page {
public function children() public function children()
{ {
$tmp = array(); $tmp = array();
//$paths = glob(PATH_PAGES.$this->getField('key').DS.'*', GLOB_ONLYDIR); //$paths = glob(PATH_PAGES.$this->getValue('key').DS.'*', GLOB_ONLYDIR);
$paths = Filesystem::listDirectories(PATH_PAGES.$this->getField('key').DS); $paths = Filesystem::listDirectories(PATH_PAGES.$this->getValue('key').DS);
foreach($paths as $path) { foreach($paths as $path) {
array_push($tmp, basename($path)); array_push($tmp, basename($path));
} }

View File

@ -28,7 +28,6 @@ class pluginCategories extends Plugin {
{ {
global $Language; global $Language;
global $dbCategories; global $dbCategories;
global $Url;
// HTML for sidebar // HTML for sidebar
$html = '<div class="plugin plugin-categories">'; $html = '<div class="plugin plugin-categories">';

View File

@ -1,7 +1,7 @@
{ {
"plugin-data": "plugin-data":
{ {
"name": "Google Tools", "name": "Google",
"description": "This plugin generate the meta tag to validate your site with Google Webmasters Tools and the JavaScript code to track your site with Google Analytics." "description": "This plugin generate the meta tag to validate your site with Google Webmasters Tools and the JavaScript code to track your site with Google Analytics."
}, },

View File

@ -2,9 +2,9 @@
"author": "Bludit", "author": "Bludit",
"email": "", "email": "",
"website": "https://plugins.bludit.com", "website": "https://plugins.bludit.com",
"version": "1.5.2", "version": "2.0",
"releaseDate": "2016-05-28", "releaseDate": "2017-05-26",
"license": "MIT", "license": "MIT",
"compatible": "1.5.2", "compatible": "2.0",
"notes": "" "notes": ""
} }

View File

@ -1,11 +1,11 @@
<?php <?php
class pluginGoogleTools extends Plugin { class pluginGoogle extends Plugin {
public function init() public function init()
{ {
$this->dbFields = array( $this->dbFields = array(
'tracking-id'=>'', 'google-analytics-tracking-id'=>'',
'google-site-verification'=>'', 'google-site-verification'=>'',
'google-tag-manager'=>'' 'google-tag-manager'=>''
); );
@ -23,7 +23,7 @@ class pluginGoogleTools extends Plugin {
$html .= '<div>'; $html .= '<div>';
$html .= '<label for="jstracking-id">'.$Language->get('Google Analytics Tracking ID').'</label>'; $html .= '<label for="jstracking-id">'.$Language->get('Google Analytics Tracking ID').'</label>';
$html .= '<input id="jstracking-id" type="text" name="tracking-id" value="'.$this->getDbField('tracking-id').'">'; $html .= '<input id="jsgoogle-analytics-tracking-id" type="text" name="google-analytics-tracking-id" value="'.$this->getDbField('google-analytics-tracking-id').'">';
$html .= '<div class="tip">'.$Language->get('complete-this-field-with-the-tracking-id').'</div>'; $html .= '<div class="tip">'.$Language->get('complete-this-field-with-the-tracking-id').'</div>';
$html .= '</div>'; $html .= '</div>';
@ -39,21 +39,24 @@ class pluginGoogleTools extends Plugin {
public function siteHead() public function siteHead()
{ {
global $Url; global $Url;
global $WHERE_AM_I;
$html = ''; $html = '';
if((!Text::isEmpty($this->getDbField('google-site-verification'))) && ($Url->whereAmI()=='home')) { // Google HTML tag
$html .= PHP_EOL.'<!-- Google Webmasters Tools -->'.PHP_EOL; if( $this->getValue('google-site-verification') && ($WHERE_AM_I=='home') ) {
$html .= '<meta name="google-site-verification" content="'.$this->getDbField('google-site-verification').'">'.PHP_EOL; $html .= PHP_EOL.'<!-- Google HTML tag -->'.PHP_EOL;
$html .= '<meta name="google-site-verification" content="'.$this->getDbField('google-site-verification').'" />'.PHP_EOL;
} }
if(!(Text::isEmpty($this->getDbField('google-tag-manager')))) { // Google Tag Manager
if( $this->getValue('google-tag-manager') ) {
$html .= PHP_EOL."<!-- Google Tag Manager -->".PHP_EOL; $html .= PHP_EOL."<!-- Google Tag Manager -->".PHP_EOL;
$html .= "<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':".PHP_EOL; $html .= "<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':".PHP_EOL;
$html .= "new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],".PHP_EOL; $html .= "new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],".PHP_EOL;
$html .= "j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=".PHP_EOL; $html .= "j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=".PHP_EOL;
$html .= "'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);".PHP_EOL; $html .= "'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);".PHP_EOL;
$html .= "})(window,document,'script','dataLayer','".$this->getDbField('google-tag-manager')."');</script>".PHP_EOL; $html .= "})(window,document,'script','dataLayer','".$this->getValue('google-tag-manager')."');</script>".PHP_EOL;
$html .= "<!-- End Google Tag Manager -->".PHP_EOL; $html .= "<!-- End Google Tag Manager -->".PHP_EOL;
} }
@ -62,34 +65,36 @@ class pluginGoogleTools extends Plugin {
public function siteBodyBegin() public function siteBodyBegin()
{ {
if((Text::isEmpty($this->getDbField('google-tag-manager')))) { $html = '';
return false;
}
$html = '<!-- Google Tag Manager (noscript) -->'.PHP_EOL; // Google Tag Manager
$html .= '<noscript><iframe src="https://www.googletagmanager.com/ns.html?id='.$this->getDbField('google-tag-manager').'" height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>'.PHP_EOL; if( $this->getValue('google-tag-manager') ) {
$html .= '<!-- End Google Tag Manager (noscript) -->'.PHP_EOL; $html .= '<!-- Google Tag Manager (noscript) -->'.PHP_EOL;
$html .= '<noscript><iframe src="https://www.googletagmanager.com/ns.html?id='.$this->getValue('google-tag-manager').'" height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>'.PHP_EOL;
$html .= '<!-- End Google Tag Manager (noscript) -->'.PHP_EOL;
}
return $html; return $html;
} }
public function siteBodyEnd() public function siteBodyEnd()
{ {
$html = PHP_EOL.'<!-- Google Analytics -->'.PHP_EOL; $html = '';
$html .= "<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', '".$this->getDbField('tracking-id')."', 'auto'); // Google Analytics
ga('send', 'pageview'); if( $this->getValue('google-analytics-tracking-id') ) {
</script>".PHP_EOL; $html .= PHP_EOL.'<!-- Google Analytics -->'.PHP_EOL;
$html .= "<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
if(Text::isEmpty($this->getDbField('tracking-id'))) { ga('create', '".$this->getValue('google-analytics-tracking-id')."', 'auto');
return false; ga('send', 'pageview');
</script>".PHP_EOL;
} }
return $html; return $html;
} }
} }

View File

@ -71,8 +71,9 @@ class pluginPages extends Plugin {
$html .= '</li>'; $html .= '</li>';
} }
// Show page list // Get keys of pages
foreach( $pages as $pageKey=>$fields ) { $keys = array_keys($pages);
foreach($keys as $pageKey) {
// Create the page object from the page key // Create the page object from the page key
$page = buildPage($pageKey); $page = buildPage($pageKey);
$html .= '<li>'; $html .= '<li>';

View File

@ -2,13 +2,45 @@
class pluginRSS extends Plugin { class pluginRSS extends Plugin {
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').'">';
$html .= '</div>';
return $html;
}
private function createXML() private function createXML()
{ {
global $Site; global $Site;
global $dbPages; global $dbPages;
global $dbPosts;
global $Url; global $Url;
// 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);
$xml = '<?xml version="1.0" encoding="UTF-8" ?>'; $xml = '<?xml version="1.0" encoding="UTF-8" ?>';
$xml .= '<rss version="2.0">'; $xml .= '<rss version="2.0">';
$xml .= '<channel>'; $xml .= '<channel>';
@ -16,13 +48,17 @@ class pluginRSS extends Plugin {
$xml .= '<link>'.$Site->url().'</link>'; $xml .= '<link>'.$Site->url().'</link>';
$xml .= '<description>'.$Site->description().'</description>'; $xml .= '<description>'.$Site->description().'</description>';
$posts = buildPostsForPage(0, 10, true); // Get keys of pages
foreach($posts as $Post) $keys = array_keys($pages);
{ foreach($keys as $pageKey) {
// Create the page object from the page key
$page = buildPage($pageKey);
$xml .= '<item>'; $xml .= '<item>';
$xml .= '<title>'.$Post->title().'</title>'; $xml .= '<title>'.$page->title().'</title>';
$xml .= '<link>'.$Post->permalink(true).'</link>'; $xml .= '<link>'.$page->permalink().'</link>';
$xml .= '<description>'.$Post->description().'</description>'; $xml .= '<description>'.$page->contentBreak().'</description>';
$xml .= '<pubDate>'.$page->dateRaw('r').'</pubDate>';
$xml .= '<guid isPermaLink="false">'.$page->uuid().'</guid>';
$xml .= '</item>'; $xml .= '</item>';
} }
@ -30,24 +66,14 @@ class pluginRSS extends Plugin {
// New DOM document // New DOM document
$doc = new DOMDocument(); $doc = new DOMDocument();
// Friendly XML code
$doc->formatOutput = true; $doc->formatOutput = true;
$doc->loadXML($xml); $doc->loadXML($xml);
$doc->save($this->workspace().'rss.xml');
$doc->save(PATH_PLUGINS_DATABASES.$this->directoryName.DS.'rss.xml');
} }
public function install($position = 0) public function install($position=0)
{ {
parent::install($position); parent::install($position);
$this->createXML();
}
public function afterPostCreate()
{
$this->createXML(); $this->createXML();
} }
@ -56,21 +82,11 @@ class pluginRSS extends Plugin {
$this->createXML(); $this->createXML();
} }
public function afterPostModify()
{
$this->createXML();
}
public function afterPageModify() public function afterPageModify()
{ {
$this->createXML(); $this->createXML();
} }
public function afterPostDelete()
{
$this->createXML();
}
public function afterPageDelete() public function afterPageDelete()
{ {
$this->createXML(); $this->createXML();
@ -78,32 +94,28 @@ class pluginRSS extends Plugin {
public function siteHead() public function siteHead()
{ {
$html = '<link rel="alternate" type="application/rss+xml" href="'.DOMAIN_BASE.'rss.xml" title="RSS Feed">'.PHP_EOL; return '<link rel="alternate" type="application/rss+xml" href="'.DOMAIN_BASE.'rss.xml" title="RSS Feed">'.PHP_EOL;
return $html;
} }
public function beforeRulesLoad() public function beforeRulesLoad()
{ {
global $Url; global $Url;
if( $Url->uri() === HTML_PATH_ROOT.'rss.xml' ) if($Url->uri()===HTML_PATH_ROOT.'rss.xml') {
{
// Send XML header // Send XML header
header('Content-type: text/xml'); header('Content-type: text/xml');
// New DOM document
$doc = new DOMDocument(); $doc = new DOMDocument();
// Load XML // Load XML
libxml_disable_entity_loader(false); libxml_disable_entity_loader(false);
$doc->load(PATH_PLUGINS_DATABASES.$this->directoryName.DS.'rss.xml'); $doc->load($this->workspace().'rss.xml');
libxml_disable_entity_loader(true); libxml_disable_entity_loader(true);
// Print the XML // Print the XML
echo $doc->saveXML(); echo $doc->saveXML();
// Stop Bludit running // Stop Bludit running
exit; exit(0);
} }
} }

View File

@ -6,96 +6,39 @@ class pluginSitemap extends Plugin {
{ {
global $Site; global $Site;
global $dbPages; global $dbPages;
global $dbPosts;
global $Url; global $Url;
$doc = new DOMDocument('1.0', 'UTF-8'); $xml = '<?xml version="1.0" encoding="UTF-8" ?>';
$xml .= '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">';
// Friendly XML code $xml .= '<url>';
$xml .= '<loc>'.$Site->url().'</loc>';
$xml .= '</url>';
// Get keys of pages
$keys = array_keys($dbPages->db);
foreach($keys as $pageKey) {
// Create the page object from the page key
$page = buildPage($pageKey);
$xml .= '<url>';
$xml .= '<loc>'.$page->permalink().'</loc>';
$xml .= '<lastmod>'.$page->dateRaw(SITEMAP_DATE_FORMAT).'</lastmod>';
$xml .= '<changefreq>daily</changefreq>';
$xml .= '</url>';
}
$xml .= '</urlset>';
// New DOM document
$doc = new DOMDocument();
$doc->formatOutput = true; $doc->formatOutput = true;
$doc->loadXML($xml);
// Create urlset element $doc->save($this->workspace().'sitemap.xml');
$urlset = $doc->createElement('urlset');
$attribute = $doc->createAttribute('xmlns');
$attribute->value = 'http://www.sitemaps.org/schemas/sitemap/0.9';
$urlset->appendChild($attribute);
// --- Base URL ---
// Create url, loc and lastmod elements
$url = $doc->createElement('url');
$loc = $doc->createElement('loc', $Site->url());
$lastmod = $doc->createElement('lastmod', Date::current(SITEMAP_DATE_FORMAT));
// Append loc and lastmod -> url
$url->appendChild($loc);
$url->appendChild($lastmod);
// Append url -> urlset
$urlset->appendChild($url);
// --- Pages and Posts ---
$all = array();
$url = trim($Site->url(),'/');
// --- Pages ---
$filter = trim($Url->filters('page'),'/');
$pages = $dbPages->getDB();
unset($pages['error']);
foreach($pages as $key=>$db)
{
if($db['status']=='published')
{
$permalink = empty($filter) ? $url.'/'.$key : $url.'/'.$filter.'/'.$key;
$date = Date::format($db['date'], DB_DATE_FORMAT, SITEMAP_DATE_FORMAT);
array_push($all, array('permalink'=>$permalink, 'date'=>$date));
}
}
// --- Posts ---
$filter = rtrim($Url->filters('post'),'/');
$posts = $dbPosts->getDB();
foreach($posts as $key=>$db)
{
if($db['status']=='published')
{
$permalink = empty($filter) ? $url.'/'.$key : $url.'/'.$filter.'/'.$key;
$date = Date::format($db['date'], DB_DATE_FORMAT, SITEMAP_DATE_FORMAT);
array_push($all, array('permalink'=>$permalink, 'date'=>$date));
}
}
// Generate the XML for posts and pages
foreach($all as $db)
{
// Create url, loc and lastmod elements
$url = $doc->createElement('url');
$loc = $doc->createElement('loc', $db['permalink']);
$lastmod = $doc->createElement('lastmod', $db['date']);
// Append loc and lastmod -> url
$url->appendChild($loc);
$url->appendChild($lastmod);
// Append url -> urlset
$urlset->appendChild($url);
}
// Append urlset -> XML
$doc->appendChild($urlset);
$doc->save(PATH_PLUGINS_DATABASES.$this->directoryName.DS.'sitemap.xml');
} }
public function install($position = 0) public function install($position=0)
{ {
parent::install($position); parent::install($position);
$this->createXML();
}
public function afterPostCreate()
{
$this->createXML(); $this->createXML();
} }
@ -104,21 +47,11 @@ class pluginSitemap extends Plugin {
$this->createXML(); $this->createXML();
} }
public function afterPostModify()
{
$this->createXML();
}
public function afterPageModify() public function afterPageModify()
{ {
$this->createXML(); $this->createXML();
} }
public function afterPostDelete()
{
$this->createXML();
}
public function afterPageDelete() public function afterPageDelete()
{ {
$this->createXML(); $this->createXML();
@ -128,25 +61,25 @@ class pluginSitemap extends Plugin {
{ {
global $Url; global $Url;
if( $Url->uri() === HTML_PATH_ROOT.'sitemap.xml' ) if($Url->uri()===HTML_PATH_ROOT.'sitemap.xml') {
{
// Send XML header // Send XML header
header('Content-type: text/xml'); header('Content-type: text/xml');
// New DOM document
$doc = new DOMDocument(); $doc = new DOMDocument();
// Load XML // Workaround for a bug https://bugs.php.net/bug.php?id=62577
libxml_disable_entity_loader(false); libxml_disable_entity_loader(false);
$doc->load(PATH_PLUGINS_DATABASES.$this->directoryName.DS.'sitemap.xml');
// Load XML
$doc->load($this->workspace().'sitemap.xml');
libxml_disable_entity_loader(true); libxml_disable_entity_loader(true);
// Print the XML // Print the XML
echo $doc->saveXML(); echo $doc->saveXML();
// Stop Bludit running // Terminate the run successfully
exit; exit(0);
} }
} }
} }