diff --git a/content/sitemap.xml b/content/sitemap.xml new file mode 100644 index 00000000..e69de29b diff --git a/install.php b/install.php index 8bd84b0a..de1644aa 100644 --- a/install.php +++ b/install.php @@ -61,7 +61,7 @@ if(!defined('JSON_PRETTY_PRINT')) { define('JSON', function_exists('json_encode')); // Database format date -define('DB_DATE_FORMAT', 'Y-m-d H:i'); +define('DB_DATE_FORMAT', 'Y-m-d H:i:s'); // Charset, default UTF-8. define('CHARSET', 'UTF-8'); diff --git a/kernel/admin/controllers/edit-page.php b/kernel/admin/controllers/edit-page.php index 504517bc..594b418c 100644 --- a/kernel/admin/controllers/edit-page.php +++ b/kernel/admin/controllers/edit-page.php @@ -1,5 +1,9 @@ edit($args) ) + // Add the page, if the $key is FALSE the creation of the post failure. + $key = $dbPages->edit($args); + + if($key) { $dbPages->regenerateCli(); + // Call the plugins after page created. + Theme::plugins('afterPageModify'); + + // Alert the user Alert::set($Language->g('The changes have been saved')); Redirect::page('admin', 'edit-page/'.$args['slug']); } @@ -34,6 +44,9 @@ function deletePage($key) if( $dbPages->delete($key) ) { + // Call the plugins after post created. + Theme::plugins('afterPageDelete'); + Alert::set($Language->g('The page has been deleted successfully')); Redirect::page('admin', 'manage-pages'); } diff --git a/kernel/admin/controllers/edit-post.php b/kernel/admin/controllers/edit-post.php index 8bfb274b..d4f4b9b3 100644 --- a/kernel/admin/controllers/edit-post.php +++ b/kernel/admin/controllers/edit-post.php @@ -13,12 +13,18 @@ function editPost($args) global $dbPosts; global $Language; - // Edit the post. - if( $dbPosts->edit($args) ) + // Add the page, if the $key is FALSE the creation of the post failure. + $key = $dbPosts->edit($args); + + if($key) { // Reindex tags, this function is in 70.posts.php reIndexTagsPosts(); + // Call the plugins after post created. + Theme::plugins('afterPostModify'); + + // Alert the user Alert::set($Language->g('The changes have been saved')); Redirect::page('admin', 'edit-post/'.$args['slug']); } @@ -40,6 +46,9 @@ function deletePost($key) // Reindex tags, this function is in 70.posts.php reIndexTagsPosts(); + // Call the plugins after post created. + Theme::plugins('afterPostDelete'); + Alert::set($Language->g('The post has been deleted successfully')); Redirect::page('admin', 'manage-posts'); } diff --git a/kernel/admin/controllers/new-page.php b/kernel/admin/controllers/new-page.php index c7540305..5846f975 100644 --- a/kernel/admin/controllers/new-page.php +++ b/kernel/admin/controllers/new-page.php @@ -13,9 +13,15 @@ function addPage($args) global $dbPages; global $Language; - // Add the page. - if( $dbPages->add($args) ) + // Add the page, if the $key is FALSE the creation of the post failure. + $key = $dbPages->add($args); + + if($key) { + // Call the plugins after page created. + Theme::plugins('afterPageCreate'); + + // Alert the user Alert::set($Language->g('Page added successfully')); Redirect::page('admin', 'manage-pages'); } diff --git a/kernel/admin/controllers/new-post.php b/kernel/admin/controllers/new-post.php index 48e40f4e..53b19667 100644 --- a/kernel/admin/controllers/new-post.php +++ b/kernel/admin/controllers/new-post.php @@ -13,12 +13,18 @@ function addPost($args) global $dbPosts; global $Language; - // Add the page. - if( $dbPosts->add($args) ) + // Add the page, if the $key is FALSE the creation of the post failure. + $key = $dbPosts->add($args); + + if($key) { // Reindex tags, this function is in 70.posts.php reIndexTagsPosts(); + // Call the plugins after post created. + Theme::plugins('afterPostCreate'); + + // Alert for the user Alert::set($Language->g('Post added successfully')); Redirect::page('admin', 'manage-posts'); } diff --git a/kernel/boot/admin.php b/kernel/boot/admin.php index 8a9706f8..42a7e988 100644 --- a/kernel/boot/admin.php +++ b/kernel/boot/admin.php @@ -40,9 +40,9 @@ if( $layout['slug']==='ajax' ) else { // Boot rules + include(PATH_RULES.'60.plugins.php'); include(PATH_RULES.'70.posts.php'); include(PATH_RULES.'70.pages.php'); - include(PATH_RULES.'80.plugins.php'); include(PATH_RULES.'99.header.php'); include(PATH_RULES.'99.paginator.php'); include(PATH_RULES.'99.themes.php'); diff --git a/kernel/boot/init.php b/kernel/boot/init.php index b9faa5a1..7b1731f4 100644 --- a/kernel/boot/init.php +++ b/kernel/boot/init.php @@ -61,7 +61,6 @@ define('ALERT_STATUS_FAIL', 1); // Salt length define('THUMBNAILS_WIDTH', 400); define('THUMBNAILS_HEIGHT', 400); - define('THUMBNAILS_AMOUNT', 6); // Salt length @@ -82,9 +81,12 @@ define('JSON', function_exists('json_encode')); // TRUE if new posts hand-made set published, or FALSE for draft. define('CLI_STATUS', 'published'); -// Database format date +// Database date format define('DB_DATE_FORMAT', 'Y-m-d H:i:s'); +// Sitemap date format +define('SITEMAP_DATE_FORMAT', 'Y-m-d'); + // Date format for Dashboard schedule posts define('SCHEDULED_DATE_FORMAT', 'd M - h:i a'); diff --git a/kernel/boot/rules/80.plugins.php b/kernel/boot/rules/60.plugins.php similarity index 93% rename from kernel/boot/rules/80.plugins.php rename to kernel/boot/rules/60.plugins.php index f178af3a..25c4d3bc 100644 --- a/kernel/boot/rules/80.plugins.php +++ b/kernel/boot/rules/60.plugins.php @@ -24,6 +24,15 @@ $plugins = array( 'beforeAdminLoad'=>array(), 'afterAdminLoad'=>array(), + 'beforeRulesLoad'=>array(), + + 'afterPostCreate'=>array(), + 'afterPostModify'=>array(), + 'afterPostDelete'=>array(), + 'afterPageCreate'=>array(), + 'afterPageModify'=>array(), + 'afterPageDelete'=>array(), + 'loginHead'=>array(), 'loginBodyBegin'=>array(), 'loginBodyEnd'=>array(), diff --git a/kernel/boot/rules/70.pages.php b/kernel/boot/rules/70.pages.php index f9c2ae55..eb11212d 100644 --- a/kernel/boot/rules/70.pages.php +++ b/kernel/boot/rules/70.pages.php @@ -23,7 +23,7 @@ function sortPages($a, $b) return ($a->position() < $b->position()) ? -1 : 1; } -function build_page($key) +function buildPage($key) { global $dbPages; global $dbUsers; @@ -38,7 +38,7 @@ function build_page($key) } // Page database, content from DATABASE JSON. - $db = $dbPages->getDb($key); + $db = $dbPages->getPageDB($key); if( !$db ) { Log::set(__METHOD__.LOG_SEP.'Error occurred when trying build the page from database with key: '.$key); return false; @@ -73,19 +73,22 @@ function build_page($key) return $Page; } -function build_all_pages() +function buildAllPages() { global $pages; global $pagesParents; global $dbPages; - $list = $dbPages->getAll(); + $list = $dbPages->getDB(); + + // Clean pages array. + $pages = array(); unset($list['error']); foreach($list as $key=>$db) { - $Page = build_page($key); + $Page = buildPage($key); if($Page!==false) { @@ -144,7 +147,7 @@ if( $Site->cliMode() ) { // Filter by page, then build it if( ($Url->whereAmI()==='page') && ($Url->notFound()===false) ) { - $Page = build_page( $Url->slug() ); + $Page = buildPage( $Url->slug() ); if($Page===false) { @@ -165,7 +168,7 @@ if($Url->notFound()===false) { $Url->setWhereAmI('page'); - $Page = build_page( $Site->homepage() ); + $Page = buildPage( $Site->homepage() ); if($Page===false) { $Url->setWhereAmI('home'); @@ -180,4 +183,4 @@ if($Url->notFound()) } // Build all pages -build_all_pages(); +buildAllPages(); diff --git a/kernel/boot/rules/70.posts.php b/kernel/boot/rules/70.posts.php index 7ab169d6..4f776410 100644 --- a/kernel/boot/rules/70.posts.php +++ b/kernel/boot/rules/70.posts.php @@ -42,7 +42,7 @@ function buildPost($key) } // Post database, content from DATABASE JSON. - $db = $dbPosts->getDb($key); + $db = $dbPosts->getPostDB($key); if( !$db ) { Log::set(__METHOD__.LOG_SEP.'Error occurred when trying build the post from database with key: '.$key); return false; diff --git a/kernel/boot/site.php b/kernel/boot/site.php index 209b493c..3fc79a89 100644 --- a/kernel/boot/site.php +++ b/kernel/boot/site.php @@ -1,9 +1,14 @@ pageExists($key)) { return $this->db[$key]; @@ -288,8 +288,8 @@ class dbPages extends dbJSON return $newKey; } - // Return an array with all databases. - public function getAll() + // Returns the database + public function getDB() { return $this->db; } diff --git a/kernel/dbposts.class.php b/kernel/dbposts.class.php index 6f5d1f08..a9fdbec8 100644 --- a/kernel/dbposts.class.php +++ b/kernel/dbposts.class.php @@ -35,8 +35,14 @@ class dbPosts extends dbJSON return $this->numberPosts['published']; } + // Returns the database + public function getDB() + { + return $this->db; + } + // Return an array with the post's database, FALSE otherwise. - public function getDb($key) + public function getPostDB($key) { if($this->postExists($key)) { return $this->db[$key]; @@ -45,7 +51,7 @@ class dbPosts extends dbJSON return false; } - public function setDb($key, $field, $value) + public function setPostDb($key, $field, $value) { if($this->postExists($key)) { $this->db[$key][$field] = $value; @@ -176,7 +182,7 @@ class dbPosts extends dbJSON return false; } - return true; + return $key; } public function edit($args) diff --git a/kernel/helpers/theme.class.php b/kernel/helpers/theme.class.php index 4a61984a..e1ecca44 100644 --- a/kernel/helpers/theme.class.php +++ b/kernel/helpers/theme.class.php @@ -131,103 +131,6 @@ class Theme { return $tmp; } - // OLD - - public static function url($relative = true) - { - if($relative) - return HTML_PATH_ROOT; - else - return BLOG_URL; - } - - - - - public static function name() - { - global $settings; - - return $settings['name']; - } - - public static function slogan() - { - global $settings; - - return $settings['slogan']; - } - - public static function footer() - { - global $settings; - - return $settings['footer']; - } - - public static function language() - { - global $settings; - - $lang = explode("_",$settings['locale']); - - return $lang[0]; - } - - public static function locale() - { - global $settings; - - return $settings['locale']; - } - - public static function meta_tags() - { - global $layout; - global $seo; - - // The validator W3C doesn't support??? - //$meta = ''.PHP_EOL; - - $meta = ''.PHP_EOL; - - if(!empty($layout['title'])) - $meta .= ''.$layout['title'].''.PHP_EOL; - - if(!empty($layout['description'])) - $meta .= ''.PHP_EOL; - - if(!empty($layout['generator'])) - $meta .= ''.PHP_EOL; - - if(!empty($layout['keywords'])) - $meta .= ''.PHP_EOL; - - if(!empty($layout['author'])) - { - if(filter_var($layout['author'], FILTER_VALIDATE_URL)) - $meta .= ''.PHP_EOL; - else - $meta .= ''.PHP_EOL; - } - - if(!empty($layout['canonical'])) - $meta .= ''.PHP_EOL; - - if(!empty($layout['robots'])) - $meta .= ''.PHP_EOL; - - if(!empty($seo['google_code'])) - $meta .= ''.PHP_EOL; - - if(!empty($seo['bing_code'])) - $meta .= ''.PHP_EOL; - - $meta .= ''.PHP_EOL; - - return $meta; - } - } -?> +?> \ No newline at end of file diff --git a/kernel/post.class.php b/kernel/post.class.php index 5550de7a..a0a4e3ad 100644 --- a/kernel/post.class.php +++ b/kernel/post.class.php @@ -131,7 +131,7 @@ class Post extends fileContent } // Returns the post date according to locale settings and format settings. - public function date($format=false) + public function date() { return $this->getField('date'); } diff --git a/plugins/sitemap/languages/en_US.json b/plugins/sitemap/languages/en_US.json new file mode 100644 index 00000000..ef54ccec --- /dev/null +++ b/plugins/sitemap/languages/en_US.json @@ -0,0 +1,12 @@ +{ + "plugin-data": + { + "name": "Sitemap", + "description": "This plugin generate a file sitemap.xml where you can list the web pages of your site to tell to search engines about the organization of your site content.", + "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/sitemap/plugin.php b/plugins/sitemap/plugin.php new file mode 100644 index 00000000..f74ca56a --- /dev/null +++ b/plugins/sitemap/plugin.php @@ -0,0 +1,150 @@ +dbFields = array( + 'label'=>'Tags' + ); + } + + private function createXML() + { + global $Site; + global $dbPages; + global $dbPosts; + global $Url; + + $doc = new DOMDocument('1.0', 'UTF-8'); + + // Friendly XML code + $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', ''); + + // 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(); + foreach($pages as $key=>$db) + { + $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) + { + $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) + { + 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.'sitemap.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.'sitemap.xml'); + + // Print the XML + echo $doc->saveXML(); + + // Stop Bludit running + exit; + } + } + +} \ No newline at end of file diff --git a/themes/pure/index.php b/themes/pure/index.php index 5c981515..6a16a9b7 100644 --- a/themes/pure/index.php +++ b/themes/pure/index.php @@ -51,4 +51,4 @@ - + \ No newline at end of file diff --git a/themes/pure/php/home.php b/themes/pure/php/home.php index 49bfbc6d..d8f65503 100644 --- a/themes/pure/php/home.php +++ b/themes/pure/php/home.php @@ -1,4 +1,4 @@ -

get('Recent posts') ?>

+
get('Recent posts') ?>
@@ -11,9 +11,9 @@
-

+

title() ?> -

+
diff --git a/themes/pure/php/page.php b/themes/pure/php/page.php index 4c0136d1..7697c812 100644 --- a/themes/pure/php/page.php +++ b/themes/pure/php/page.php @@ -1,4 +1,4 @@ -

get('Page') ?>

+
get('Page') ?>
@@ -9,9 +9,9 @@ diff --git a/themes/pure/php/post.php b/themes/pure/php/post.php index f5e34468..ddcdbbe4 100644 --- a/themes/pure/php/post.php +++ b/themes/pure/php/post.php @@ -1,4 +1,4 @@ -

get('Post') ?>

+
get('Post') ?>
@@ -9,9 +9,9 @@
-

+

title() ?> -

+