From 20fca17d912dae34f78f8288aff612f3999823f8 Mon Sep 17 00:00:00 2001 From: dignajar Date: Fri, 24 Jul 2015 00:28:25 -0300 Subject: [PATCH] Images parse --- kernel/boot/init.php | 4 ++++ kernel/boot/rules/70.build_pages.php | 4 +++- kernel/boot/rules/70.build_posts.php | 9 ++++++--- kernel/boot/rules/99.paginator.php | 12 +++++++----- kernel/dblanguage.class.php | 6 ++++++ kernel/helpers/text.class.php | 5 +++++ languages/en_US.json | 3 ++- themes/pure/css/blog.css | 10 +++++++++- themes/pure/php/home.php | 2 ++ 9 files changed, 44 insertions(+), 11 deletions(-) diff --git a/kernel/boot/init.php b/kernel/boot/init.php index 401918ec..15fc558c 100644 --- a/kernel/boot/init.php +++ b/kernel/boot/init.php @@ -48,6 +48,9 @@ define('BLUDIT_RELEASE_DATE', ''); // define('NO_PARENT_CHAR', '—'); +// Post per page on Manage->Posts +define('POSTS_PER_PAGE_ADMIN', 10); + // Multibyte string / UTF-8 define('MB_STRING', extension_loaded('mbstring')); @@ -123,6 +126,7 @@ define('HTML_PATH_THEME_CSS', HTML_PATH_THEME.'css/'); define('HTML_PATH_THEME_JS', HTML_PATH_THEME.'js/'); define('HTML_PATH_ADMIN_THEME', HTML_PATH_ROOT.'admin/themes/'.$Site->adminTheme().'/'); define('HTML_PATH_ADMIN_ROOT', HTML_PATH_ROOT.'admin/'); +define('HTML_PATH_UPLOADS', HTML_PATH_ROOT.'content/uploads/'); // Objects with dependency $Language = new dbLanguage( $Site->locale() ); diff --git a/kernel/boot/rules/70.build_pages.php b/kernel/boot/rules/70.build_pages.php index 5484e33f..e2e7abca 100644 --- a/kernel/boot/rules/70.build_pages.php +++ b/kernel/boot/rules/70.build_pages.php @@ -60,10 +60,12 @@ function build_page($key) } // Content in raw format + $contentRaw = $Page->content(); $Page->setField('contentRaw', $Page->content(), true); // Parse markdown content. - $content = $Parsedown->text( $Page->content() ); + $content = Text::imgRel2Abs($contentRaw, HTML_PATH_UPLOADS); // Parse img src relative to absolute. + $content = $Parsedown->text($content); // Parse Markdown. $Page->setField('content', $content, true); // Parse username for the page. diff --git a/kernel/boot/rules/70.build_posts.php b/kernel/boot/rules/70.build_posts.php index 351e9852..3c8964a0 100644 --- a/kernel/boot/rules/70.build_posts.php +++ b/kernel/boot/rules/70.build_posts.php @@ -15,6 +15,7 @@ function buildPost($key) global $dbPosts; global $dbUsers; global $Parsedown; + global $Site; // Post object. $Post = new Post($key); @@ -48,10 +49,12 @@ function buildPost($key) } // Content in raw format - $Post->setField('contentRaw', $Post->content(), true); + $contentRaw = $Post->content(); + $Post->setField('contentRaw', $contentRaw, true); // Parse the content - $content = $Parsedown->text( $Post->content() ); + $content = Text::imgRel2Abs($contentRaw, HTML_PATH_UPLOADS); // Parse img src relative to absolute. + $content = $Parsedown->text($content); // Parse Markdown. $Post->setField('content', $content, true); // Parse username for the post. @@ -120,7 +123,7 @@ else { if($Url->whereAmI()==='admin') { // Build post for admin area with drafts - build_posts_per_page($Url->pageNumber(), $Site->postsPerPage(), true); + build_posts_per_page($Url->pageNumber(), POSTS_PER_PAGE_ADMIN, true); } else { diff --git a/kernel/boot/rules/99.paginator.php b/kernel/boot/rules/99.paginator.php index 1f06a3e5..a6dc929a 100644 --- a/kernel/boot/rules/99.paginator.php +++ b/kernel/boot/rules/99.paginator.php @@ -4,18 +4,20 @@ $currentPage = $Url->pageNumber(); Paginator::set('currentPage', $currentPage); -// Post per page. -$postPerPage = $Site->postsPerPage(); -Paginator::set('postPerPage', $postPerPage); - // Number of pages. -if($Url->whereAmI()=='admin') { +if($Url->whereAmI()=='admin') { + $postPerPage = POSTS_PER_PAGE_ADMIN; $numberOfPosts = $dbPosts->numberPost(true); // published and drafts } else { + $postPerPage = $Site->postsPerPage(); $numberOfPosts = $dbPosts->numberPost(false); // published } +// Post per page. +Paginator::set('postPerPage', $postPerPage); + +// Number of posts Paginator::set('numberOfPosts', $numberOfPosts); $numberOfPages = (int) ceil($numberOfPosts / $postPerPage) -1; diff --git a/kernel/dblanguage.class.php b/kernel/dblanguage.class.php index b7af2b21..4ec34ee2 100644 --- a/kernel/dblanguage.class.php +++ b/kernel/dblanguage.class.php @@ -49,6 +49,12 @@ class dbLanguage extends dbJSON return $this->get($string); } + // Print translation. + public function printMe($string) + { + echo $this->get($string); + } + // Print translation. public function p($string) { diff --git a/kernel/helpers/text.class.php b/kernel/helpers/text.class.php index c6a7b1f5..2afe3ed6 100644 --- a/kernel/helpers/text.class.php +++ b/kernel/helpers/text.class.php @@ -153,4 +153,9 @@ class Text { return !self::isEmpty($string); } + public static function imgRel2Abs($string, $base) + { + return preg_replace("/(src)\=\"([^(http)])(\/)?/", "$1=\"$base$2", $string); + } + } diff --git a/languages/en_US.json b/languages/en_US.json index 00ecc2df..443717a0 100644 --- a/languages/en_US.json +++ b/languages/en_US.json @@ -125,5 +125,6 @@ "write-the-tags-separeted-by-comma": "Write the tags separeted by comma. eg: tag1, tag2, tag3", "delete": "Delete", "delete-the-user-and-all-its-posts":"Delete the user and all its posts", - "delete-the-user-and-associate-its-posts-to-admin-user": "Delete the user and associate its posts to admin user" + "delete-the-user-and-associate-its-posts-to-admin-user": "Delete the user and associate its posts to admin user", + "read-more": "Read more" } \ No newline at end of file diff --git a/themes/pure/css/blog.css b/themes/pure/css/blog.css index 593aa605..e64c8e54 100644 --- a/themes/pure/css/blog.css +++ b/themes/pure/css/blog.css @@ -117,7 +117,7 @@ Pages and Posts ------------------------ */ .page, .post { - margin: 20px 0; + margin: 0 0 70px 0; } .page-title, @@ -135,6 +135,14 @@ Pages and Posts display: inline-block; } +.page a.read-more, +.post a.read-more{ + display: block; + text-align: center; + padding: 2px 5px; +} + + .page-content, .post-content { color: #444; diff --git a/themes/pure/php/home.php b/themes/pure/php/home.php index 796a5b3e..c21244d1 100644 --- a/themes/pure/php/home.php +++ b/themes/pure/php/home.php @@ -36,6 +36,8 @@ content(false) // FALSE to get the first part of the post ?> + printMe('Read more') ?> +