From a2a69367b21bfe5570ee9c8cd459c06fb24e9a01 Mon Sep 17 00:00:00 2001 From: Dipchikov Date: Mon, 4 Jan 2016 11:26:02 +0200 Subject: [PATCH 01/13] add cover-image --- languages/bg_BG.json | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/languages/bg_BG.json b/languages/bg_BG.json index c666a76e..df0d752d 100644 --- a/languages/bg_BG.json +++ b/languages/bg_BG.json @@ -218,6 +218,8 @@ "site-information": "Информация за сайта", "date-and-time-formats": "Формат дата и час", "activate": "Активиране", - "deactivate": "Деактивиране" + "deactivate": "Деактивиране", + + "cover-image": "Обложка" } From 01dc40f442bb43b86ecae5787a3301b0c5827f04 Mon Sep 17 00:00:00 2001 From: dignajar Date: Thu, 7 Jan 2016 20:43:09 -0300 Subject: [PATCH 02/13] New hooks for plugins and Sitemap --- content/sitemap.xml | 0 install.php | 2 +- kernel/admin/controllers/edit-page.php | 17 +- kernel/admin/controllers/edit-post.php | 13 +- kernel/admin/controllers/new-page.php | 10 +- kernel/admin/controllers/new-post.php | 10 +- kernel/boot/admin.php | 2 +- kernel/boot/init.php | 6 +- .../rules/{80.plugins.php => 60.plugins.php} | 9 ++ kernel/boot/rules/70.pages.php | 19 ++- kernel/boot/rules/70.posts.php | 2 +- kernel/boot/site.php | 9 +- kernel/dbpages.class.php | 10 +- kernel/dbposts.class.php | 12 +- kernel/helpers/theme.class.php | 99 +----------- kernel/post.class.php | 2 +- plugins/sitemap/languages/en_US.json | 12 ++ plugins/sitemap/plugin.php | 150 ++++++++++++++++++ themes/pure/index.php | 2 +- themes/pure/php/home.php | 6 +- themes/pure/php/page.php | 6 +- themes/pure/php/post.php | 6 +- 22 files changed, 264 insertions(+), 140 deletions(-) create mode 100644 content/sitemap.xml rename kernel/boot/rules/{80.plugins.php => 60.plugins.php} (93%) create mode 100644 plugins/sitemap/languages/en_US.json create mode 100644 plugins/sitemap/plugin.php 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/kernel/admin/views/settings-advanced.php b/kernel/admin/views/settings-advanced.php index edf5fcdd..334db0f3 100644 --- a/kernel/admin/views/settings-advanced.php +++ b/kernel/admin/views/settings-advanced.php @@ -84,6 +84,14 @@ HTML::formOpen(array('class'=>'uk-form-horizontal')); 'tip'=>'' )); + HTML::formInputText(array( + 'name'=>'uriBlog', + 'label'=>$L->g('Blog'), + 'value'=>$Site->uriFilters('blog'), + 'class'=>'uk-width-1-2 uk-form-medium', + 'tip'=>'' + )); + echo '
diff --git a/kernel/boot/admin.php b/kernel/boot/admin.php index 42a7e988..fcc39779 100644 --- a/kernel/boot/admin.php +++ b/kernel/boot/admin.php @@ -42,7 +42,7 @@ else // Boot rules include(PATH_RULES.'60.plugins.php'); include(PATH_RULES.'70.posts.php'); - include(PATH_RULES.'70.pages.php'); + include(PATH_RULES.'71.pages.php'); include(PATH_RULES.'99.header.php'); include(PATH_RULES.'99.paginator.php'); include(PATH_RULES.'99.themes.php'); diff --git a/kernel/boot/rules/70.posts.php b/kernel/boot/rules/70.posts.php index 65eb7c25..e118f999 100644 --- a/kernel/boot/rules/70.posts.php +++ b/kernel/boot/rules/70.posts.php @@ -4,6 +4,8 @@ // Variables // ============================================================================ +// Array with all posts specified by a filter. +// Filter by page number, by tag, etc. $posts = array(); // ============================================================================ @@ -138,11 +140,13 @@ if( ($Url->whereAmI()==='post') && ($Url->notFound()===false) ) { $Post = buildPost( $Url->slug() ); + // The post doesn't exist. if($Post===false) { $Url->setNotFound(true); unset($Post); } + // The post is not published yet. elseif( !$Post->published() ) { $Url->setNotFound(true); @@ -166,8 +170,8 @@ else if($Url->whereAmI()==='admin') { $posts = buildPostsForPage($Url->pageNumber(), POSTS_PER_PAGE_ADMIN, false); } - // Posts for homepage - else { + // Posts for home and blog filter. + elseif( ( ($Url->whereAmI()==='home') || ($Url->whereAmI()==='blog') ) && ($Url->notFound()===false) ) { $posts = buildPostsForPage($Url->pageNumber(), $Site->postsPerPage(), true); } } diff --git a/kernel/boot/rules/70.pages.php b/kernel/boot/rules/71.pages.php similarity index 94% rename from kernel/boot/rules/70.pages.php rename to kernel/boot/rules/71.pages.php index 0a1bce7e..06d0c2bf 100644 --- a/kernel/boot/rules/70.pages.php +++ b/kernel/boot/rules/71.pages.php @@ -145,16 +145,18 @@ if( $Site->cliMode() ) { $dbPages->regenerateCli(); } -// Filter by page, then build it +// Build specific page. if( ($Url->whereAmI()==='page') && ($Url->notFound()===false) ) { $Page = buildPage( $Url->slug() ); + // The page doesn't exist. if($Page===false) { $Url->setNotFound(true); unset($Page); } + // The page is not published yet. elseif( !$Page->published() ) { $Url->setNotFound(true); @@ -162,10 +164,11 @@ if( ($Url->whereAmI()==='page') && ($Url->notFound()===false) ) } } -// Default homepage -if($Url->notFound()===false) +// Homepage +if( ($Url->whereAmI()==='home') && ($Url->notFound()===false) ) { - if( Text::isNotEmpty($Site->homepage()) && ($Url->whereAmI()==='home') ) + // The user defined as homepage a particular page. + if( Text::isNotEmpty( $Site->homepage() ) ) { $Url->setWhereAmI('page'); diff --git a/kernel/boot/site.php b/kernel/boot/site.php index 3fc79a89..08ee1316 100644 --- a/kernel/boot/site.php +++ b/kernel/boot/site.php @@ -8,7 +8,7 @@ Theme::plugins('beforeRulesLoad'); // Load rules include(PATH_RULES.'70.posts.php'); -include(PATH_RULES.'70.pages.php'); +include(PATH_RULES.'71.pages.php'); include(PATH_RULES.'99.header.php'); include(PATH_RULES.'99.paginator.php'); include(PATH_RULES.'99.themes.php'); diff --git a/kernel/dbsite.class.php b/kernel/dbsite.class.php index 41ef8d1f..25e29a3b 100644 --- a/kernel/dbsite.class.php +++ b/kernel/dbsite.class.php @@ -17,6 +17,7 @@ class dbSite extends dbJSON 'uriPage'=> array('inFile'=>false, 'value'=>'/'), 'uriPost'=> array('inFile'=>false, 'value'=>'/post/'), 'uriTag'=> array('inFile'=>false, 'value'=>'/tag/'), + 'uriBlog'=> array('inFile'=>false, 'value'=>'/blog/'), 'url'=> array('inFile'=>false, 'value'=>''), 'cliMode'=> array('inFile'=>false, 'value'=>true), 'emailFrom'=> array('inFile'=>false, 'value'=>''), @@ -67,6 +68,7 @@ class dbSite extends dbJSON $filters['post'] = $this->getField('uriPost'); $filters['page'] = $this->getField('uriPage'); $filters['tag'] = $this->getField('uriTag'); + $filters['blog'] = $this->getField('uriBlog'); if(empty($filter)) { return $filters; @@ -93,6 +95,12 @@ class dbSite extends dbJSON return $this->url().ltrim($filter, '/'); } + public function urlBlog() + { + $filter = $this->getField('uriBlog'); + return $this->url().ltrim($filter, '/'); + } + // Returns the site title. public function title() { diff --git a/kernel/url.class.php b/kernel/url.class.php index e62661f5..fc4428bd 100644 --- a/kernel/url.class.php +++ b/kernel/url.class.php @@ -67,6 +67,12 @@ class Url break; } + if($filterURI===$filters['blog']) + { + $this->whereAmI = 'blog'; + break; + } + if($filterURI===$adminFilter['admin']) { $this->whereAmI = 'admin'; diff --git a/languages/en_US.json b/languages/en_US.json index 15d8fe72..3be721da 100644 --- a/languages/en_US.json +++ b/languages/en_US.json @@ -220,5 +220,9 @@ "activate": "Activate", "deactivate": "Deactivate", - "cover-image": "Cover image" + "cover-image": "Cover image", + "blog": "Blog", + "more-images": "More images", + "double-click-on-the-image-to-add-it": "Double click on the image to add it.", + "click-here-to-cancel": "Click here to cancel." } \ No newline at end of file diff --git a/themes/pure/index.php b/themes/pure/index.php index 6a16a9b7..d831a5be 100644 --- a/themes/pure/index.php +++ b/themes/pure/index.php @@ -24,7 +24,7 @@ whereAmI()=='home') || ($Url->whereAmI()=='tag') ) + if( ($Url->whereAmI()=='home') || ($Url->whereAmI()=='tag') || ($Url->whereAmI()=='blog') ) { include(PATH_THEME_PHP.'home.php'); } From a74378b350cac229c86b0971370e85d775f0f413 Mon Sep 17 00:00:00 2001 From: Fahri YARDIMCI Date: Fri, 8 Jan 2016 22:42:59 +0200 Subject: [PATCH 10/13] Update TR_tr.json --- languages/tr_TR.json | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/languages/tr_TR.json b/languages/tr_TR.json index 1e0c4e04..09949f7d 100644 --- a/languages/tr_TR.json +++ b/languages/tr_TR.json @@ -220,5 +220,9 @@ "activate": "Aktifleştir", "deactivate": "Deaktive et", - "cover-image": "Kapak resmi" + "cover-image": "Kapak resmi", + "blog": "Blog", + "more-images": "Daha çok resim", + "double-click-on-the-image-to-add-it": "Eklemek istediğiniz resime çift tıklayın.", + "click-here-to-cancel": "İptal etmek için tıklayın." } From 640b58ecdf356245d3351431d537304bd8d0d41d Mon Sep 17 00:00:00 2001 From: dignajar Date: Mon, 11 Jan 2016 19:51:00 -0300 Subject: [PATCH 11/13] 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; From 696d49c9bc60e49c0a5669405c91f9764f893c3e Mon Sep 17 00:00:00 2001 From: dignajar Date: Mon, 11 Jan 2016 23:18:20 -0300 Subject: [PATCH 12/13] RSS Plugin, improves on code --- kernel/abstract/content.class.php | 274 ++++++++++++++++++++++++++ kernel/abstract/filecontent.class.php | 90 --------- kernel/boot/init.php | 2 +- kernel/helpers/filesystem.class.php | 50 +---- kernel/page.class.php | 198 ++----------------- kernel/post.class.php | 197 +----------------- 6 files changed, 295 insertions(+), 516 deletions(-) create mode 100644 kernel/abstract/content.class.php delete mode 100644 kernel/abstract/filecontent.class.php diff --git a/kernel/abstract/content.class.php b/kernel/abstract/content.class.php new file mode 100644 index 00000000..710605f5 --- /dev/null +++ b/kernel/abstract/content.class.php @@ -0,0 +1,274 @@ +build($path)===false) { + $this->vars = false; + } + } + + // Return true if valid + public function isValid() + { + return($this->vars!==false); + } + + public function getField($field) + { + if(isset($this->vars[$field])) { + return $this->vars[$field]; + } + + return false; + } + + // $notoverwrite true if you don't want to replace the value if are set previusly + public function setField($field, $value, $overwrite=true) + { + if($overwrite || empty($this->vars[$field])) { + $this->vars[$field] = $value; + } + + return true; + } + + private function build($path) + { + if( !Sanitize::pathFile($path, 'index.txt') ) { + return false; + } + + $tmp = 0; + $lines = file($path.'index.txt'); + foreach($lines as $lineNumber=>$line) + { + $parts = array_map('trim', explode(':', $line, 2)); + + // Lowercase variable + $parts[0] = Text::lowercase($parts[0]); + + // If variables is content then break the foreach and process the content after. + if($parts[0]==='content') + { + $tmp = $lineNumber; + break; + } + + if( !empty($parts[0]) && !empty($parts[1]) ) { + // Sanitize all fields, except Content. + $this->vars[$parts[0]] = Sanitize::html($parts[1]); + } + } + + // Process the content. + if($tmp!==0) + { + // Next line after "Content:" variable + $tmp++; + + // Remove lines after Content + $output = array_slice($lines, $tmp); + + if(!empty($parts[1])) { + array_unshift($output, "\n"); + array_unshift($output, $parts[1]); + } + + $implode = implode($output); + $this->vars['content'] = $implode; + + // Sanitize content. + //$this->vars['content'] = Sanitize::html($implode); + } + + } + + // Returns the post title. + public function title() + { + return $this->getField('title'); + } + + // 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(!$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) + { + // This content is not sanitized. + $content = $this->getField('contentRaw'); + + if($raw) { + return $content; + } + + return Sanitize::html($content); + } + + public function key() + { + return $this->getField('key'); + } + + // Returns TRUE if the post is published, FALSE otherwise. + public function published() + { + return ($this->getField('status')==='published'); + } + + // Returns TRUE if the post is scheduled, FALSE otherwise. + public function scheduled() + { + return ($this->getField('status')==='scheduled'); + } + + // Returns TRUE if the post is draft, FALSE otherwise. + public function draft() + { + return ($this->getField('status')=='draft'); + } + + public function coverImage($absolute=true) + { + $fileName = $this->getField('coverImage'); + + if(empty($fileName)) { + return false; + } + + if($absolute) { + return HTML_PATH_UPLOADS.$fileName; + } + + return $fileName; + } + + public function profilePicture() + { + return HTML_PATH_UPLOADS_PROFILES.$this->username().'.jpg'; + } + + // Returns the user object if $field is false, otherwise returns the field's value. + public function user($field=false) + { + // Get the user object. + $User = $this->getField('user'); + + if($field) { + return $User->getField($field); + } + + return $User; + } + + public function username() + { + return $this->getField('username'); + } + + public function description() + { + return $this->getField('description'); + } + + // Returns the post date according to locale settings and format settings. + public function date() + { + return $this->getField('date'); + } + + // Returns the post date according to locale settings and format as database stored. + public function dateRaw($format=false) + { + $date = $this->getField('dateRaw'); + + if($format) { + return Date::format($date, DB_DATE_FORMAT, $format); + } + + return $date; + } + + public function tags($returnsArray=false) + { + global $Url; + + $tags = $this->getField('tags'); + + if($returnsArray) { + + if($tags==false) { + return array(); + } + + return $tags; + } + else { + if($tags==false) { + return false; + } + + // Return string with tags separeted by comma. + return implode(', ', $tags); + } + } + + public function permalink($absolute=false) + { + global $Url; + global $Site; + + $filterType = $this->getField('filterType'); + + $url = trim(DOMAIN_BASE,'/'); + $key = $this->key(); + $filter = trim($Url->filters($filterType), '/'); + $htmlPath = trim(HTML_PATH_ROOT,'/'); + + if(empty($filter)) { + $tmp = $key; + } + else { + $tmp = $filter.'/'.$key; + } + + if($absolute) { + return $url.'/'.$tmp; + } + + if(empty($htmlPath)) { + return '/'.$tmp; + } + + return '/'.$htmlPath.'/'.$tmp; + } + + +} diff --git a/kernel/abstract/filecontent.class.php b/kernel/abstract/filecontent.class.php deleted file mode 100644 index ffd5b80e..00000000 --- a/kernel/abstract/filecontent.class.php +++ /dev/null @@ -1,90 +0,0 @@ -build($path)===false) { - $this->vars = false; - } - } - - // Return true if valid - public function isValid() - { - return($this->vars!==false); - } - - public function getField($field) - { - if(isset($this->vars[$field])) { - return $this->vars[$field]; - } - - return false; - } - - // $notoverwrite true if you don't want to replace the value if are set previusly - public function setField($field, $value, $overwrite=true) - { - if($overwrite || empty($this->vars[$field])) { - $this->vars[$field] = $value; - } - - return true; - } - - private function build($path) - { - if( !Sanitize::pathFile($path, 'index.txt') ) { - return false; - } - - $tmp = 0; - $lines = file($path.'index.txt'); - foreach($lines as $lineNumber=>$line) - { - $parts = array_map('trim', explode(':', $line, 2)); - - // Lowercase variable - $parts[0] = Text::lowercase($parts[0]); - - // If variables is content then break the foreach and process the content after. - if($parts[0]==='content') - { - $tmp = $lineNumber; - break; - } - - if( !empty($parts[0]) && !empty($parts[1]) ) { - // Sanitize all fields, except Content. - $this->vars[$parts[0]] = Sanitize::html($parts[1]); - } - } - - // Process the content. - if($tmp!==0) - { - // Next line after "Content:" variable - $tmp++; - - // Remove lines after Content - $output = array_slice($lines, $tmp); - - if(!empty($parts[1])) { - array_unshift($output, "\n"); - array_unshift($output, $parts[1]); - } - - $implode = implode($output); - $this->vars['content'] = $implode; - - // Sanitize content. - //$this->vars['content'] = Sanitize::html($implode); - } - - } - -} diff --git a/kernel/boot/init.php b/kernel/boot/init.php index 8a88339b..a69e0f8e 100644 --- a/kernel/boot/init.php +++ b/kernel/boot/init.php @@ -113,7 +113,7 @@ if(MB_STRING) // Inclde Abstract Classes include(PATH_ABSTRACT.'dbjson.class.php'); -include(PATH_ABSTRACT.'filecontent.class.php'); +include(PATH_ABSTRACT.'content.class.php'); include(PATH_ABSTRACT.'plugin.class.php'); // Inclde Classes diff --git a/kernel/helpers/filesystem.class.php b/kernel/helpers/filesystem.class.php index a05fef82..5db132f2 100644 --- a/kernel/helpers/filesystem.class.php +++ b/kernel/helpers/filesystem.class.php @@ -2,8 +2,6 @@ class Filesystem { - // NEW - // Returns an array with the absolutes directories. public static function listDirectories($path, $regex='*') { @@ -52,50 +50,4 @@ class Filesystem { return unlink($filename); } - // OLD - public static function get_images($regex) - { - return self::ls(PATH_UPLOAD, $regex, '*', false, false, false); - } - - // Devuelve un arreglo con el listado de archivos - // $path con una barra al final, ej: /home/ - // $file_expression : *.0.*.*.*.*.*.*.*.* - // $ext : xml - // $flag_dir : si quiero listar directorios - // $sort_asc_numeric : ordeno ascedente numerico - // $sort_desc_numeric : ordeno descendente numerico - public static function ls($path, $file_expression = NULL, $ext, $flag_dir = false, $sort_asc_numeric = false, $sort_desc_numeric = true) - { - if($flag_dir) - { - $files = glob($path . $file_expression, GLOB_ONLYDIR); - } - else - { - $files = glob($path . $file_expression . '.' . $ext); - } - - if( ($files==false) || (empty($files)) ) - { - $files = array(); - } - - foreach($files as $key=>$file) - { - $files[$key] = basename($file); - } - - // Sort - if($sort_asc_numeric) - { - sort($files, SORT_NUMERIC); - } - elseif($sort_desc_numeric) - { - rsort($files, SORT_NUMERIC); - } - - return $files; - } -} +} \ No newline at end of file diff --git a/kernel/page.class.php b/kernel/page.class.php index 2af00c61..7fcceb96 100644 --- a/kernel/page.class.php +++ b/kernel/page.class.php @@ -1,182 +1,37 @@ setField('key', $key); + // Set filterType + $this->setField('filterType', 'page'); + parent::__construct(PATH_PAGES.$key.DS); } - // Returns the post title. - public function title() - { - return $this->getField('title'); - } - // 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(!$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) - { - // This content is not sanitized. - $content = $this->getField('contentRaw'); - - if($raw) { - return $content; - } - - return Sanitize::html($content); - } - - public function description() - { - return $this->getField('description'); - } - - public function tags($returnsArray=false) - { - global $Url; - - $tags = $this->getField('tags'); - - if($returnsArray) { - - if($tags==false) { - return array(); - } - - return $tags; - } - else { - if($tags==false) { - return false; - } - - // Return string with tags separeted by comma. - return implode(', ', $tags); - } - } - + // Returns the page position. public function position() { return $this->getField('position'); } - // Returns the post date according to locale settings and format settings. - public function date() - { - return $this->getField('date'); - } - - // Returns the post date according to locale settings and format as database stored. - public function dateRaw($format=false) - { - $date = $this->getField('dateRaw'); - - if($format) { - return Date::format($date, DB_DATE_FORMAT, $format); - } - - return $date; - } - // Returns the page slug. public function slug() { $explode = explode('/', $this->getField('key')); - if(!empty($explode[1])) + + // Check if the page have a parent. + if(!empty($explode[1])) { return $explode[1]; + } return $explode[0]; } - public function key() - { - return $this->getField('key'); - } - - public function coverImage($absolute=true) - { - $fileName = $this->getField('coverImage'); - - if(empty($fileName)) { - return false; - } - - if($absolute) { - return HTML_PATH_UPLOADS.$fileName; - } - - return $fileName; - } - - // Returns TRUE if the page is published, FALSE otherwise. - public function published() - { - return ($this->getField('status')==='published'); - } - - // Returns TRUE if the post is draft, FALSE otherwise. - public function draft() - { - return ($this->getField('status')=='draft'); - } - - // Returns the page permalink. - public function permalink($absolute=false) - { - global $Url; - global $Site; - - $url = trim($Site->url(),'/'); - $key = $this->key(); - $filter = trim($Url->filters('page'), '/'); - $htmlPath = trim(HTML_PATH_ROOT,'/'); - - if(empty($filter)) { - $tmp = $key; - } - else { - $tmp = $filter.'/'.$key; - } - - if($absolute) { - return $url.'/'.$tmp; - } - - if(empty($htmlPath)) { - return '/'.$tmp; - } - - return '/'.$htmlPath.'/'.$tmp; - } - // Returns the parent key, if the page doesn't have a parent returns FALSE. public function parentKey() { @@ -212,35 +67,4 @@ class Page extends fileContent return $tmp; } - // Returns the user object if $field is false, otherwise returns the field's value. - public function user($field=false) - { - // Get the user object. - $User = $this->getField('user'); - - if($field) { - return $User->getField($field); - } - - return $User; - } - - // DEPRECATED - public function username() - { - return $this->getField('username'); - } - - // DEPRECATED - public function authorFirstName() - { - return $this->getField('authorFirstName'); - } - - // DEPRECATED - public function authorLastName() - { - return $this->getField('authorLastName'); - } - -} +} \ No newline at end of file diff --git a/kernel/post.class.php b/kernel/post.class.php index b3fa9a8d..ddeafdde 100644 --- a/kernel/post.class.php +++ b/kernel/post.class.php @@ -1,69 +1,26 @@ setField('key', $key); + // Set filterType + $this->setField('filterType', 'post'); + parent::__construct(PATH_POSTS.$key.DS); } - // Returns the post title. - public function title() - { - return $this->getField('title'); - } - - // 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(!$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) - { - // This content is not sanitized. - $content = $this->getField('contentRaw'); - - if($raw) { - return $content; - } - - return Sanitize::html($content); - } - public function key() { return $this->getField('key'); } - // Returns TRUE if the post is published, FALSE otherwise. - public function published() + public function slug() { - return ($this->getField('status')==='published'); + return $this->getField('key'); } // Returns TRUE if the post is scheduled, FALSE otherwise. @@ -71,142 +28,4 @@ class Post extends fileContent { return ($this->getField('status')==='scheduled'); } - - // Returns TRUE if the post is draft, FALSE otherwise. - public function draft() - { - return ($this->getField('status')=='draft'); - } - - public function coverImage($absolute=true) - { - $fileName = $this->getField('coverImage'); - - if(empty($fileName)) { - return false; - } - - if($absolute) { - return HTML_PATH_UPLOADS.$fileName; - } - - return $fileName; - } - - public function profilePicture() - { - return HTML_PATH_UPLOADS_PROFILES.$this->username().'.jpg'; - } - - // Returns the user object if $field is false, otherwise returns the field's value. - public function user($field=false) - { - // Get the user object. - $User = $this->getField('user'); - - if($field) { - return $User->getField($field); - } - - return $User; - } - - // DEPRECATED - public function username() - { - return $this->getField('username'); - } - - // DEPRECATED - public function authorFirstName() - { - return $this->getField('authorFirstName'); - } - - // DEPRECATED - public function authorLastName() - { - return $this->getField('authorLastName'); - } - - public function description() - { - return $this->getField('description'); - } - - // Returns the post date according to locale settings and format settings. - public function date() - { - return $this->getField('date'); - } - - // Returns the post date according to locale settings and format as database stored. - public function dateRaw($format=false) - { - $date = $this->getField('dateRaw'); - - if($format) { - return Date::format($date, DB_DATE_FORMAT, $format); - } - - return $date; - } - - public function tags($returnsArray=false) - { - global $Url; - - $tags = $this->getField('tags'); - - if($returnsArray) { - - if($tags==false) { - return array(); - } - - return $tags; - } - else { - if($tags==false) { - return false; - } - - // Return string with tags separeted by comma. - return implode(', ', $tags); - } - } - - public function slug() - { - return $this->getField('key'); - } - - public function permalink($absolute=false) - { - global $Url; - global $Site; - - $url = trim(DOMAIN_BASE,'/'); - $key = $this->key(); - $filter = trim($Url->filters('post'), '/'); - $htmlPath = trim(HTML_PATH_ROOT,'/'); - - if(empty($filter)) { - $tmp = $key; - } - else { - $tmp = $filter.'/'.$key; - } - - if($absolute) { - return $url.'/'.$tmp; - } - - if(empty($htmlPath)) { - return '/'.$tmp; - } - - return '/'.$htmlPath.'/'.$tmp; - } - -} +} \ No newline at end of file From 6772b4179996fc78070d8fd776984f70e8cfe372 Mon Sep 17 00:00:00 2001 From: dignajar Date: Tue, 12 Jan 2016 00:36:48 -0300 Subject: [PATCH 13/13] Hashing posts and pages --- .../default/css/jquery.auto-complete.css | 9 ++++++++ kernel/admin/themes/default/index.php | 2 ++ kernel/admin/themes/default/init.php | 22 +++++++++++++++++++ .../default/js/jquery.auto-complete.min.js | 3 +++ kernel/admin/views/edit-page.php | 5 +++-- kernel/admin/views/edit-post.php | 5 +++-- kernel/admin/views/new-page.php | 5 +++-- kernel/admin/views/new-post.php | 5 +++-- kernel/dbpages.class.php | 9 ++++++++ kernel/dbposts.class.php | 5 +++++ 10 files changed, 62 insertions(+), 8 deletions(-) create mode 100755 kernel/admin/themes/default/css/jquery.auto-complete.css create mode 100755 kernel/admin/themes/default/js/jquery.auto-complete.min.js diff --git a/kernel/admin/themes/default/css/jquery.auto-complete.css b/kernel/admin/themes/default/css/jquery.auto-complete.css new file mode 100755 index 00000000..4261b1d0 --- /dev/null +++ b/kernel/admin/themes/default/css/jquery.auto-complete.css @@ -0,0 +1,9 @@ +.autocomplete-suggestions { + text-align: left; cursor: default; border: 1px solid #ccc; border-top: 0; background: #fff; box-shadow: -1px 1px 3px rgba(0,0,0,.1); + + /* core styles should not be changed */ + position: absolute; display: none; z-index: 9999; max-height: 254px; overflow: hidden; overflow-y: auto; box-sizing: border-box; +} +.autocomplete-suggestion { position: relative; padding: 0 .6em; line-height: 23px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 1.02em; color: #333; } +.autocomplete-suggestion b { font-weight: normal; color: #1f8dd6; } +.autocomplete-suggestion.selected { background: #f0f0f0; } diff --git a/kernel/admin/themes/default/index.php b/kernel/admin/themes/default/index.php index 94432b29..d90c144e 100644 --- a/kernel/admin/themes/default/index.php +++ b/kernel/admin/themes/default/index.php @@ -20,12 +20,14 @@ + + diff --git a/kernel/admin/themes/default/init.php b/kernel/admin/themes/default/init.php index f131cc83..00e44f33 100644 --- a/kernel/admin/themes/default/init.php +++ b/kernel/admin/themes/default/init.php @@ -52,6 +52,28 @@ class HTML { echo $html; } + public static function formInputAutocomplete($args) + { + self::formInputText($args); + +$script = ''; + + echo $script; + + } + public static function formInputPassword($args) { $args['type'] = 'password'; diff --git a/kernel/admin/themes/default/js/jquery.auto-complete.min.js b/kernel/admin/themes/default/js/jquery.auto-complete.min.js new file mode 100755 index 00000000..6fdb3bc6 --- /dev/null +++ b/kernel/admin/themes/default/js/jquery.auto-complete.min.js @@ -0,0 +1,3 @@ +// jQuery autoComplete v1.0.7 +// https://github.com/Pixabay/jQuery-autoComplete +!function(e){e.fn.autoComplete=function(t){var o=e.extend({},e.fn.autoComplete.defaults,t);return"string"==typeof t?(this.each(function(){var o=e(this);"destroy"==t&&(e(window).off("resize.autocomplete",o.updateSC),o.off("blur.autocomplete focus.autocomplete keydown.autocomplete keyup.autocomplete"),o.data("autocomplete")?o.attr("autocomplete",o.data("autocomplete")):o.removeAttr("autocomplete"),e(o.data("sc")).remove(),o.removeData("sc").removeData("autocomplete"))}),this):this.each(function(){function t(e){var t=s.val();if(s.cache[t]=e,e.length&&t.length>=o.minChars){for(var a="",c=0;c
'),s.data("sc",s.sc).data("autocomplete",s.attr("autocomplete")),s.attr("autocomplete","off"),s.cache={},s.last_val="",s.updateSC=function(t,o){if(s.sc.css({top:s.offset().top+s.outerHeight(),left:s.offset().left,width:s.outerWidth()}),!t&&(s.sc.show(),s.sc.maxHeight||(s.sc.maxHeight=parseInt(s.sc.css("max-height"))),s.sc.suggestionHeight||(s.sc.suggestionHeight=e(".autocomplete-suggestion",s.sc).first().outerHeight()),s.sc.suggestionHeight))if(o){var a=s.sc.scrollTop(),c=o.offset().top-s.sc.offset().top;c+s.sc.suggestionHeight-s.sc.maxHeight>0?s.sc.scrollTop(c+s.sc.suggestionHeight+a-s.sc.maxHeight):0>c&&s.sc.scrollTop(c+a)}else s.sc.scrollTop(0)},e(window).on("resize.autocomplete",s.updateSC),s.sc.appendTo("body"),s.sc.on("mouseleave",".autocomplete-suggestion",function(){e(".autocomplete-suggestion.selected").removeClass("selected")}),s.sc.on("mouseenter",".autocomplete-suggestion",function(){e(".autocomplete-suggestion.selected").removeClass("selected"),e(this).addClass("selected")}),s.sc.on("mousedown",".autocomplete-suggestion",function(t){var a=e(this),c=a.data("val");return(c||a.hasClass("autocomplete-suggestion"))&&(s.val(c),o.onSelect(t,c,a),s.sc.hide()),!1}),s.on("blur.autocomplete",function(){try{over_sb=e(".autocomplete-suggestions:hover").length}catch(t){over_sb=0}over_sb?s.is(":focus")||setTimeout(function(){s.focus()},20):(s.last_val=s.val(),s.sc.hide(),setTimeout(function(){s.sc.hide()},350))}),o.minChars||s.on("focus.autocomplete",function(){s.last_val="\n",s.trigger("keyup.autocomplete")}),s.on("keydown.autocomplete",function(t){if((40==t.which||38==t.which)&&s.sc.html()){var a,c=e(".autocomplete-suggestion.selected",s.sc);return c.length?(a=40==t.which?c.next(".autocomplete-suggestion"):c.prev(".autocomplete-suggestion"),a.length?(c.removeClass("selected"),s.val(a.addClass("selected").data("val"))):(c.removeClass("selected"),s.val(s.last_val),a=0)):(a=40==t.which?e(".autocomplete-suggestion",s.sc).first():e(".autocomplete-suggestion",s.sc).last(),s.val(a.addClass("selected").data("val"))),s.updateSC(0,a),!1}if(27==t.which)s.val(s.last_val).sc.hide();else if(13==t.which||9==t.which){var c=e(".autocomplete-suggestion.selected",s.sc);c.length&&s.sc.is(":visible")&&(o.onSelect(t,c.data("val"),c),setTimeout(function(){s.sc.hide()},20))}}),s.on("keyup.autocomplete",function(a){if(!~e.inArray(a.which,[13,27,35,36,37,38,39,40])){var c=s.val();if(c.length>=o.minChars){if(c!=s.last_val){if(s.last_val=c,clearTimeout(s.timer),o.cache){if(c in s.cache)return void t(s.cache[c]);for(var l=1;l'+e.replace(o,"$1")+"
"},onSelect:function(e,t,o){}}}(jQuery); \ No newline at end of file diff --git a/kernel/admin/views/edit-page.php b/kernel/admin/views/edit-page.php index 62393751..abac66b7 100644 --- a/kernel/admin/views/edit-page.php +++ b/kernel/admin/views/edit-page.php @@ -77,12 +77,13 @@ echo '