Bug fixes, developer area, google plugin updated, rss and sitemap updated
This commit is contained in:
parent
dc25f269e2
commit
6ca24ac456
@ -197,6 +197,11 @@ class Plugin {
|
||||
return $this->directoryName;
|
||||
}
|
||||
|
||||
public function workspace()
|
||||
{
|
||||
return PATH_PLUGINS_DATABASES.$this->directoryName.DS;
|
||||
}
|
||||
|
||||
// Return TRUE if the installation success, otherwise FALSE.
|
||||
public function install($position=0)
|
||||
{
|
||||
|
49
bl-kernel/admin/controllers/developers.php
Normal file
49
bl-kernel/admin/controllers/developers.php
Normal 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
|
||||
// ============================================================================
|
10
bl-kernel/admin/views/developers.php
Normal file
10
bl-kernel/admin/views/developers.php
Normal 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);
|
@ -56,9 +56,6 @@ define('DB_CATEGORIES', PATH_DATABASES.'categories.php');
|
||||
define('DB_TAGS', PATH_DATABASES.'tags.php');
|
||||
define('DB_SYSLOG', PATH_DATABASES.'syslog.php');
|
||||
|
||||
// ADMIN URI FILTER
|
||||
define('ADMIN_URI_FILTER', '/admin/');
|
||||
|
||||
// Log separator
|
||||
define('LOG_SEP', ' | ');
|
||||
|
||||
@ -137,6 +134,9 @@ define('EXTREME_FRIENDLY_URL', FALSE);
|
||||
// Permissions for new directories
|
||||
define('DIR_PERMISSIONS', 0755);
|
||||
|
||||
// Admin URI filter
|
||||
define('ADMIN_URI_FILTER', '/admin/');
|
||||
|
||||
// Set internal character encoding
|
||||
mb_internal_encoding(CHARSET);
|
||||
|
||||
@ -250,11 +250,20 @@ $Language = new dbLanguage( $Site->locale() );
|
||||
$Login = new Login( $dbUsers );
|
||||
$Url->checkFilters( $Site->uriFilters() );
|
||||
|
||||
// --- Objects shortcuts ---
|
||||
$L = $Language;
|
||||
|
||||
// --- 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 ---
|
||||
// This paths are absolutes for the OS
|
||||
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 ---
|
||||
// This paths are absolutes for the user / web browsing.
|
||||
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_CSS', DOMAIN.HTML_PATH_THEME_CSS);
|
||||
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_PROFILES', DOMAIN.HTML_PATH_UPLOADS_PROFILES);
|
||||
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_VIEW = '';
|
||||
$ID_EXECUTION = uniqid(); // string 13 characters long
|
||||
$WHERE_AM_I = $Url->whereAmI();
|
||||
|
||||
// --- Objects shortcuts ---
|
||||
$L = $Language;
|
||||
|
||||
// DEBUG: Print constants
|
||||
// $arr = array_filter(get_defined_constants(), 'is_string');
|
||||
// echo json_encode($arr);
|
||||
|
@ -78,6 +78,15 @@ class Page {
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getValue($field)
|
||||
{
|
||||
if(isset($this->vars[$field])) {
|
||||
return $this->vars[$field];
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// Set a field with a value
|
||||
public function setField($field, $value, $overwrite=true)
|
||||
{
|
||||
@ -95,7 +104,7 @@ class Page {
|
||||
public function content($fullContent=true, $noSanitize=true)
|
||||
{
|
||||
// This content is not sanitized.
|
||||
$content = $this->getField('content');
|
||||
$content = $this->getValue('content');
|
||||
|
||||
if(!$fullContent) {
|
||||
return $this->contentBreak();
|
||||
@ -110,7 +119,7 @@ class Page {
|
||||
|
||||
public function contentBreak()
|
||||
{
|
||||
return $this->getField('contentBreak');
|
||||
return $this->getValue('contentBreak');
|
||||
}
|
||||
|
||||
// Returns the raw content
|
||||
@ -119,7 +128,7 @@ class Page {
|
||||
public function contentRaw($noSanitize=true)
|
||||
{
|
||||
// This content is not sanitized.
|
||||
$content = $this->getField('contentRaw');
|
||||
$content = $this->getValue('contentRaw');
|
||||
|
||||
if($noSanitize) {
|
||||
return $content;
|
||||
@ -131,14 +140,14 @@ class Page {
|
||||
// Returns the date according to locale settings and format settings
|
||||
public function date()
|
||||
{
|
||||
return $this->getField('date');
|
||||
return $this->getValue('date');
|
||||
}
|
||||
|
||||
// Returns the date according to locale settings and format as database stored
|
||||
// (string) $format, you can specify the date format
|
||||
public function dateRaw($format=false)
|
||||
{
|
||||
$date = $this->getField('dateRaw');
|
||||
$date = $this->getValue('dateRaw');
|
||||
|
||||
if($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
|
||||
public function permalink($absolute=true)
|
||||
{
|
||||
global $Url;
|
||||
// Get the key of the page
|
||||
$key = $this->getValue('key');
|
||||
|
||||
$key = $this->getField('key');
|
||||
if($absolute) {
|
||||
return DOMAIN_PAGE.$key;
|
||||
}
|
||||
|
||||
$filter = $Url->filters('page', true);
|
||||
return trim(HTML_PATH_ROOT,'/').'/'.$filter.'/'.$key;
|
||||
return HTML_PATH_ROOT.PAGE_URI_FILTER.$key;
|
||||
}
|
||||
|
||||
// Returns the category key
|
||||
public function categoryKey()
|
||||
{
|
||||
return $this->getField('category');
|
||||
return $this->getValue('category');
|
||||
}
|
||||
|
||||
// Returns the field from the array
|
||||
// categoryMap = array( 'name'=>'', 'list'=>array() )
|
||||
public function categoryMap($field)
|
||||
{
|
||||
$map = $this->getField('categoryMap');
|
||||
$map = $this->getValue('categoryMap');
|
||||
|
||||
if($field=='key') {
|
||||
return $this->categoryKey();
|
||||
@ -192,7 +200,7 @@ class Page {
|
||||
public function user($field=false)
|
||||
{
|
||||
// Get the user object.
|
||||
$User = $this->getField('user');
|
||||
$User = $this->getValue('user');
|
||||
|
||||
if($field) {
|
||||
return $User->getField($field);
|
||||
@ -204,13 +212,13 @@ class Page {
|
||||
// Returns the username who created the post/page
|
||||
public function username()
|
||||
{
|
||||
return $this->getField('username');
|
||||
return $this->getValue('username');
|
||||
}
|
||||
|
||||
// Returns the description field
|
||||
public function description()
|
||||
{
|
||||
return $this->getField('description');
|
||||
return $this->getValue('description');
|
||||
}
|
||||
|
||||
|
||||
@ -222,7 +230,7 @@ class Page {
|
||||
// $complete = true : full version
|
||||
public function relativeTime($complete = false) {
|
||||
$current = new DateTime;
|
||||
$past = new DateTime($this->getField('date'));
|
||||
$past = new DateTime($this->getValue('date'));
|
||||
$elapsed = $current->diff($past);
|
||||
|
||||
$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
|
||||
public function tags($returnsArray=false)
|
||||
{
|
||||
$tags = $this->getField('tags');
|
||||
$tags = $this->getValue('tags');
|
||||
|
||||
if($returnsArray) {
|
||||
if($tags==false) {
|
||||
@ -298,7 +306,7 @@ class Page {
|
||||
// (boolean) $absolute, TRUE returns the absolute path and file name, FALSE just the file name
|
||||
public function coverImage($absolute=true)
|
||||
{
|
||||
$fileName = $this->getField('coverImage');
|
||||
$fileName = $this->getValue('coverImage');
|
||||
if(empty($fileName)) {
|
||||
return false;
|
||||
}
|
||||
@ -313,60 +321,60 @@ class Page {
|
||||
// Returns TRUE if the content has the text splited
|
||||
public function readMore()
|
||||
{
|
||||
return $this->getField('readMore');
|
||||
return $this->getValue('readMore');
|
||||
}
|
||||
|
||||
public function uuid()
|
||||
{
|
||||
return $this->getField('uuid');
|
||||
return $this->getValue('uuid');
|
||||
}
|
||||
|
||||
// Returns the field key
|
||||
public function key()
|
||||
{
|
||||
return $this->getField('key');
|
||||
return $this->getValue('key');
|
||||
}
|
||||
|
||||
// Returns TRUE if the post/page is published, FALSE otherwise.
|
||||
public function published()
|
||||
{
|
||||
return ($this->getField('status')==='published');
|
||||
return ($this->getValue('status')==='published');
|
||||
}
|
||||
|
||||
// Returns TRUE if the post/page is scheduled, FALSE otherwise.
|
||||
public function scheduled()
|
||||
{
|
||||
return ($this->getField('status')==='scheduled');
|
||||
return ($this->getValue('status')==='scheduled');
|
||||
}
|
||||
|
||||
// Returns TRUE if the post/page is draft, FALSE otherwise.
|
||||
public function draft()
|
||||
{
|
||||
return ($this->getField('status')=='draft');
|
||||
return ($this->getValue('status')=='draft');
|
||||
}
|
||||
|
||||
// Returns the title field
|
||||
public function title()
|
||||
{
|
||||
return $this->getField('title');
|
||||
return $this->getValue('title');
|
||||
}
|
||||
|
||||
// Returns TRUE if the page has enabled the comments, FALSE otherwise
|
||||
public function allowComments()
|
||||
{
|
||||
return $this->getField('allowComments');
|
||||
return $this->getValue('allowComments');
|
||||
}
|
||||
|
||||
// Returns the page position
|
||||
public function position()
|
||||
{
|
||||
return $this->getField('position');
|
||||
return $this->getValue('position');
|
||||
}
|
||||
|
||||
// Returns the page slug
|
||||
public function slug()
|
||||
{
|
||||
$explode = explode('/', $this->getField('key'));
|
||||
$explode = explode('/', $this->getValue('key'));
|
||||
|
||||
// Check if the page have a parent.
|
||||
if(!empty($explode[1])) {
|
||||
@ -379,7 +387,7 @@ class Page {
|
||||
// Returns the parent key, if the page doesn't have a parent returns FALSE
|
||||
public function parentKey()
|
||||
{
|
||||
$explode = explode('/', $this->getField('key'));
|
||||
$explode = explode('/', $this->getValue('key'));
|
||||
if(isset($explode[1])) {
|
||||
return $explode[0];
|
||||
}
|
||||
@ -403,8 +411,8 @@ class Page {
|
||||
public function children()
|
||||
{
|
||||
$tmp = array();
|
||||
//$paths = glob(PATH_PAGES.$this->getField('key').DS.'*', GLOB_ONLYDIR);
|
||||
$paths = Filesystem::listDirectories(PATH_PAGES.$this->getField('key').DS);
|
||||
//$paths = glob(PATH_PAGES.$this->getValue('key').DS.'*', GLOB_ONLYDIR);
|
||||
$paths = Filesystem::listDirectories(PATH_PAGES.$this->getValue('key').DS);
|
||||
foreach($paths as $path) {
|
||||
array_push($tmp, basename($path));
|
||||
}
|
||||
|
@ -28,7 +28,6 @@ class pluginCategories extends Plugin {
|
||||
{
|
||||
global $Language;
|
||||
global $dbCategories;
|
||||
global $Url;
|
||||
|
||||
// HTML for sidebar
|
||||
$html = '<div class="plugin plugin-categories">';
|
||||
|
@ -1,7 +1,7 @@
|
||||
{
|
||||
"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."
|
||||
},
|
||||
|
@ -2,9 +2,9 @@
|
||||
"author": "Bludit",
|
||||
"email": "",
|
||||
"website": "https://plugins.bludit.com",
|
||||
"version": "1.5.2",
|
||||
"releaseDate": "2016-05-28",
|
||||
"version": "2.0",
|
||||
"releaseDate": "2017-05-26",
|
||||
"license": "MIT",
|
||||
"compatible": "1.5.2",
|
||||
"compatible": "2.0",
|
||||
"notes": ""
|
||||
}
|
||||
}
|
@ -1,11 +1,11 @@
|
||||
<?php
|
||||
|
||||
class pluginGoogleTools extends Plugin {
|
||||
class pluginGoogle extends Plugin {
|
||||
|
||||
public function init()
|
||||
{
|
||||
$this->dbFields = array(
|
||||
'tracking-id'=>'',
|
||||
'google-analytics-tracking-id'=>'',
|
||||
'google-site-verification'=>'',
|
||||
'google-tag-manager'=>''
|
||||
);
|
||||
@ -23,7 +23,7 @@ class pluginGoogleTools extends Plugin {
|
||||
|
||||
$html .= '<div>';
|
||||
$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>';
|
||||
|
||||
@ -39,21 +39,24 @@ class pluginGoogleTools extends Plugin {
|
||||
public function siteHead()
|
||||
{
|
||||
global $Url;
|
||||
global $WHERE_AM_I;
|
||||
|
||||
$html = '';
|
||||
|
||||
if((!Text::isEmpty($this->getDbField('google-site-verification'))) && ($Url->whereAmI()=='home')) {
|
||||
$html .= PHP_EOL.'<!-- Google Webmasters Tools -->'.PHP_EOL;
|
||||
$html .= '<meta name="google-site-verification" content="'.$this->getDbField('google-site-verification').'">'.PHP_EOL;
|
||||
// Google HTML tag
|
||||
if( $this->getValue('google-site-verification') && ($WHERE_AM_I=='home') ) {
|
||||
$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 .= "<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 .= "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 .= "})(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;
|
||||
}
|
||||
|
||||
@ -62,34 +65,36 @@ class pluginGoogleTools extends Plugin {
|
||||
|
||||
public function siteBodyBegin()
|
||||
{
|
||||
if((Text::isEmpty($this->getDbField('google-tag-manager')))) {
|
||||
return false;
|
||||
}
|
||||
$html = '';
|
||||
|
||||
$html = '<!-- Google Tag Manager (noscript) -->'.PHP_EOL;
|
||||
$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;
|
||||
$html .= '<!-- End Google Tag Manager (noscript) -->'.PHP_EOL;
|
||||
// Google Tag Manager
|
||||
if( $this->getValue('google-tag-manager') ) {
|
||||
$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;
|
||||
}
|
||||
|
||||
public function siteBodyEnd()
|
||||
{
|
||||
$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');
|
||||
$html = '';
|
||||
|
||||
ga('create', '".$this->getDbField('tracking-id')."', 'auto');
|
||||
ga('send', 'pageview');
|
||||
</script>".PHP_EOL;
|
||||
// Google Analytics
|
||||
if( $this->getValue('google-analytics-tracking-id') ) {
|
||||
$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'))) {
|
||||
return false;
|
||||
ga('create', '".$this->getValue('google-analytics-tracking-id')."', 'auto');
|
||||
ga('send', 'pageview');
|
||||
</script>".PHP_EOL;
|
||||
}
|
||||
|
||||
return $html;
|
||||
}
|
||||
}
|
||||
}
|
@ -71,8 +71,9 @@ class pluginPages extends Plugin {
|
||||
$html .= '</li>';
|
||||
}
|
||||
|
||||
// Show page list
|
||||
foreach( $pages as $pageKey=>$fields ) {
|
||||
// Get keys of pages
|
||||
$keys = array_keys($pages);
|
||||
foreach($keys as $pageKey) {
|
||||
// Create the page object from the page key
|
||||
$page = buildPage($pageKey);
|
||||
$html .= '<li>';
|
||||
|
@ -2,13 +2,45 @@
|
||||
|
||||
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()
|
||||
{
|
||||
global $Site;
|
||||
global $dbPages;
|
||||
global $dbPosts;
|
||||
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 .= '<rss version="2.0">';
|
||||
$xml .= '<channel>';
|
||||
@ -16,13 +48,17 @@ class pluginRSS extends Plugin {
|
||||
$xml .= '<link>'.$Site->url().'</link>';
|
||||
$xml .= '<description>'.$Site->description().'</description>';
|
||||
|
||||
$posts = buildPostsForPage(0, 10, true);
|
||||
foreach($posts as $Post)
|
||||
{
|
||||
// Get keys of pages
|
||||
$keys = array_keys($pages);
|
||||
foreach($keys as $pageKey) {
|
||||
// Create the page object from the page key
|
||||
$page = buildPage($pageKey);
|
||||
$xml .= '<item>';
|
||||
$xml .= '<title>'.$Post->title().'</title>';
|
||||
$xml .= '<link>'.$Post->permalink(true).'</link>';
|
||||
$xml .= '<description>'.$Post->description().'</description>';
|
||||
$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>';
|
||||
$xml .= '</item>';
|
||||
}
|
||||
|
||||
@ -30,24 +66,14 @@ class pluginRSS extends Plugin {
|
||||
|
||||
// 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');
|
||||
$doc->save($this->workspace().'rss.xml');
|
||||
}
|
||||
|
||||
public function install($position = 0)
|
||||
public function install($position=0)
|
||||
{
|
||||
parent::install($position);
|
||||
|
||||
$this->createXML();
|
||||
}
|
||||
|
||||
public function afterPostCreate()
|
||||
{
|
||||
$this->createXML();
|
||||
}
|
||||
|
||||
@ -56,21 +82,11 @@ class pluginRSS extends Plugin {
|
||||
$this->createXML();
|
||||
}
|
||||
|
||||
public function afterPostModify()
|
||||
{
|
||||
$this->createXML();
|
||||
}
|
||||
|
||||
public function afterPageModify()
|
||||
{
|
||||
$this->createXML();
|
||||
}
|
||||
|
||||
public function afterPostDelete()
|
||||
{
|
||||
$this->createXML();
|
||||
}
|
||||
|
||||
public function afterPageDelete()
|
||||
{
|
||||
$this->createXML();
|
||||
@ -78,32 +94,28 @@ class pluginRSS extends Plugin {
|
||||
|
||||
public function siteHead()
|
||||
{
|
||||
$html = '<link rel="alternate" type="application/rss+xml" href="'.DOMAIN_BASE.'rss.xml" title="RSS Feed">'.PHP_EOL;
|
||||
return $html;
|
||||
return '<link rel="alternate" type="application/rss+xml" href="'.DOMAIN_BASE.'rss.xml" title="RSS Feed">'.PHP_EOL;
|
||||
}
|
||||
|
||||
public function beforeRulesLoad()
|
||||
{
|
||||
global $Url;
|
||||
|
||||
if( $Url->uri() === HTML_PATH_ROOT.'rss.xml' )
|
||||
{
|
||||
if($Url->uri()===HTML_PATH_ROOT.'rss.xml') {
|
||||
// Send XML header
|
||||
header('Content-type: text/xml');
|
||||
|
||||
// New DOM document
|
||||
$doc = new DOMDocument();
|
||||
|
||||
// Load XML
|
||||
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);
|
||||
|
||||
// Print the XML
|
||||
echo $doc->saveXML();
|
||||
|
||||
// Stop Bludit running
|
||||
exit;
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -6,96 +6,39 @@ class pluginSitemap extends Plugin {
|
||||
{
|
||||
global $Site;
|
||||
global $dbPages;
|
||||
global $dbPosts;
|
||||
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;
|
||||
|
||||
// Create urlset element
|
||||
$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');
|
||||
$doc->loadXML($xml);
|
||||
$doc->save($this->workspace().'sitemap.xml');
|
||||
}
|
||||
|
||||
public function install($position = 0)
|
||||
public function install($position=0)
|
||||
{
|
||||
parent::install($position);
|
||||
|
||||
$this->createXML();
|
||||
}
|
||||
|
||||
public function afterPostCreate()
|
||||
{
|
||||
$this->createXML();
|
||||
}
|
||||
|
||||
@ -104,21 +47,11 @@ class pluginSitemap extends Plugin {
|
||||
$this->createXML();
|
||||
}
|
||||
|
||||
public function afterPostModify()
|
||||
{
|
||||
$this->createXML();
|
||||
}
|
||||
|
||||
public function afterPageModify()
|
||||
{
|
||||
$this->createXML();
|
||||
}
|
||||
|
||||
public function afterPostDelete()
|
||||
{
|
||||
$this->createXML();
|
||||
}
|
||||
|
||||
public function afterPageDelete()
|
||||
{
|
||||
$this->createXML();
|
||||
@ -128,25 +61,25 @@ class pluginSitemap extends Plugin {
|
||||
{
|
||||
global $Url;
|
||||
|
||||
if( $Url->uri() === HTML_PATH_ROOT.'sitemap.xml' )
|
||||
{
|
||||
if($Url->uri()===HTML_PATH_ROOT.'sitemap.xml') {
|
||||
// Send XML header
|
||||
header('Content-type: text/xml');
|
||||
|
||||
// New DOM document
|
||||
$doc = new DOMDocument();
|
||||
|
||||
// Load XML
|
||||
// Workaround for a bug https://bugs.php.net/bug.php?id=62577
|
||||
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);
|
||||
|
||||
// Print the XML
|
||||
echo $doc->saveXML();
|
||||
|
||||
// Stop Bludit running
|
||||
exit;
|
||||
// Terminate the run successfully
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user