From 7eb917f115a29c7b2a85eb5a0afafe14044831c3 Mon Sep 17 00:00:00 2001 From: mmk2410 Date: Sun, 20 Dec 2015 17:50:22 +0100 Subject: [PATCH] Pagination and Code Style improovements --- .gitignore | 1 + articles/example/2015-07-24-example.md | 2 +- articles/example/2015-07-25-example.md | 9 ++ articles/example/2015-07-26-example.md | 9 ++ articles/example/2015-07-27-example.md | 9 ++ articles/example/2015-07-28-example.md | 9 ++ articles/main/2015-07-24-example.md | 7 +- articles/main/2015-07-25-example.md | 9 ++ articles/main/2015-07-26-example.md | 9 ++ articles/main/2015-07-27-example.md | 9 ++ articles/main/2015-07-28-example.md | 9 ++ config.php | 4 +- index.php | 31 +++++- res/css/rangitaki.css | 32 ++++++ res/php/BlogListGenerator.php | 134 +++++++++++++++---------- res/php/Pagination.php | 58 +++++++++++ themes/background-img.css | 41 ++++++++ themes/material-dark.css | 41 ++++++++ themes/material-light.css | 41 ++++++++ 19 files changed, 400 insertions(+), 64 deletions(-) create mode 100644 articles/example/2015-07-25-example.md create mode 100644 articles/example/2015-07-26-example.md create mode 100644 articles/example/2015-07-27-example.md create mode 100644 articles/example/2015-07-28-example.md create mode 100644 articles/main/2015-07-25-example.md create mode 100644 articles/main/2015-07-26-example.md create mode 100644 articles/main/2015-07-27-example.md create mode 100644 articles/main/2015-07-28-example.md create mode 100644 res/php/Pagination.php diff --git a/.gitignore b/.gitignore index 87a85d1..87a12bb 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ nbproject/ .idea/ +completer.hist diff --git a/articles/example/2015-07-24-example.md b/articles/example/2015-07-24-example.md index baa9016..8376fa6 100644 --- a/articles/example/2015-07-24-example.md +++ b/articles/example/2015-07-24-example.md @@ -1,4 +1,4 @@ -%TITLE: The Rangitaki logo +%TITLE: The Rangitaki logo 1 %DATE: 24 July 2015 %TAGS: design, artwork, logo diff --git a/articles/example/2015-07-25-example.md b/articles/example/2015-07-25-example.md new file mode 100644 index 0000000..2a81f29 --- /dev/null +++ b/articles/example/2015-07-25-example.md @@ -0,0 +1,9 @@ +%TITLE: The Rangitaki logo 2 +%DATE: 24 July 2015 +%TAGS: design, artwork, logo + +This is the official Rangitaki logo. + +![The Rangitaki logo](media/example.png) + +It is saved in the example blog directory. diff --git a/articles/example/2015-07-26-example.md b/articles/example/2015-07-26-example.md new file mode 100644 index 0000000..c2f6908 --- /dev/null +++ b/articles/example/2015-07-26-example.md @@ -0,0 +1,9 @@ +%TITLE: The Rangitaki logo 3 +%DATE: 24 July 2015 +%TAGS: design, artwork, logo + +This is the official Rangitaki logo. + +![The Rangitaki logo](media/example.png) + +It is saved in the example blog directory. diff --git a/articles/example/2015-07-27-example.md b/articles/example/2015-07-27-example.md new file mode 100644 index 0000000..a705156 --- /dev/null +++ b/articles/example/2015-07-27-example.md @@ -0,0 +1,9 @@ +%TITLE: The Rangitaki logo 4 +%DATE: 24 July 2015 +%TAGS: design, artwork, logo + +This is the official Rangitaki logo. + +![The Rangitaki logo](media/example.png) + +It is saved in the example blog directory. diff --git a/articles/example/2015-07-28-example.md b/articles/example/2015-07-28-example.md new file mode 100644 index 0000000..2d129cb --- /dev/null +++ b/articles/example/2015-07-28-example.md @@ -0,0 +1,9 @@ +%TITLE: The Rangitaki logo 5 +%DATE: 24 July 2015 +%TAGS: design, artwork, logo + +This is the official Rangitaki logo. + +![The Rangitaki logo](media/example.png) + +It is saved in the example blog directory. diff --git a/articles/main/2015-07-24-example.md b/articles/main/2015-07-24-example.md index 5a17e74..8376fa6 100755 --- a/articles/main/2015-07-24-example.md +++ b/articles/main/2015-07-24-example.md @@ -1,10 +1,9 @@ -%TITLE: The Rangitaki logo +%TITLE: The Rangitaki logo 1 %DATE: 24 July 2015 -%AUTHOR: The great testers %TAGS: design, artwork, logo - This is the official Rangitaki logo. ![The Rangitaki logo](media/example.png) - \ No newline at end of file + +It is saved in the example blog directory. diff --git a/articles/main/2015-07-25-example.md b/articles/main/2015-07-25-example.md new file mode 100644 index 0000000..2a81f29 --- /dev/null +++ b/articles/main/2015-07-25-example.md @@ -0,0 +1,9 @@ +%TITLE: The Rangitaki logo 2 +%DATE: 24 July 2015 +%TAGS: design, artwork, logo + +This is the official Rangitaki logo. + +![The Rangitaki logo](media/example.png) + +It is saved in the example blog directory. diff --git a/articles/main/2015-07-26-example.md b/articles/main/2015-07-26-example.md new file mode 100644 index 0000000..c2f6908 --- /dev/null +++ b/articles/main/2015-07-26-example.md @@ -0,0 +1,9 @@ +%TITLE: The Rangitaki logo 3 +%DATE: 24 July 2015 +%TAGS: design, artwork, logo + +This is the official Rangitaki logo. + +![The Rangitaki logo](media/example.png) + +It is saved in the example blog directory. diff --git a/articles/main/2015-07-27-example.md b/articles/main/2015-07-27-example.md new file mode 100644 index 0000000..a705156 --- /dev/null +++ b/articles/main/2015-07-27-example.md @@ -0,0 +1,9 @@ +%TITLE: The Rangitaki logo 4 +%DATE: 24 July 2015 +%TAGS: design, artwork, logo + +This is the official Rangitaki logo. + +![The Rangitaki logo](media/example.png) + +It is saved in the example blog directory. diff --git a/articles/main/2015-07-28-example.md b/articles/main/2015-07-28-example.md new file mode 100644 index 0000000..2d129cb --- /dev/null +++ b/articles/main/2015-07-28-example.md @@ -0,0 +1,9 @@ +%TITLE: The Rangitaki logo 5 +%DATE: 24 July 2015 +%TAGS: design, artwork, logo + +This is the official Rangitaki logo. + +![The Rangitaki logo](media/example.png) + +It is saved in the example blog directory. diff --git a/config.php b/config.php index 2558fb3..b026a0e 100644 --- a/config.php +++ b/config.php @@ -71,14 +71,14 @@ $rcc = 'yes'; $nav_drawer = 'yes'; // Set here the name of your theme. Read the documentation for more themes -$theme = 'material-light'; +$theme = 'background-img'; // Set here your language. The file must exist in the lang directory $language = "en"; // pagination: how many articles should be on one page // set to 0 to disable it -$pagination = 0; +$pagination = 2; // Favicon - Set here the path to your favicon $favicon = "http://example.com/res/img/favicon.png"; diff --git a/index.php b/index.php index 5277a35..0847b14 100644 --- a/index.php +++ b/index.php @@ -37,13 +37,20 @@ $getarticle = filter_input(INPUT_GET, "article"); // get the article variable $gettag = filter_input(INPUT_GET, "tag"); // getting the tag variable $url = "http://" . filter_input(INPUT_SERVER, "HTTP_HOST") . filter_input(INPUT_SERVER, "REQUEST_URI"); // get the url (used for sharing) -$pagenumber = filer_input(INPUT_GET, "page"); // get the pagenumber +$pagenumber = filter_input(INPUT_GET, "page"); // get the pagenumber // Pagination algorithm if ($pagination == 0) { $pagination = false; } else { - $pagination = $pagination * ( $pagenumber + 1 ); + // pag_max: the newest post to show on a page + $pag_max = $pagination * ( $pagenumber + 1 ); + // pag_min: the oldest post to show on a page + $pag_min = $pag_max - $pagination; + if ($pagenumber > 0) { + // Disable the blog intro if not on first page + $blogintro = "no"; + } } // Fetching necessary information about the current article @@ -125,7 +132,8 @@ if (isset($getarticle)) { 400italic,100,100italic,900' rel='stylesheet' type='text/css'> - + @@ -295,12 +303,27 @@ if ($nav_drawer == "yes") { // save the content of the directory in the articles variable $articles = scandir($articlesdir, 1); // iterate through this variable + $posts_amount = 0; foreach ($articles as $article) { // check if the file is a article file if (strlen($article) >= 3 && substr($article, -3) == ".md") { // generate the article - ArticleGenerator::newArticle($articlesdir, $article, $getblog); + if ($pagination) { + if ($posts_amount < $pag_max && $posts_amount >= $pag_min) { + ArticleGenerator::newArticle( + $articlesdir, $article, $getblog + ); + } + } else { + ArticleGenerator::newArticle( + $articlesdir, $article, $getblog + ); + } } + $posts_amount++; + } + if ($pagination) { + include './res/php/Pagination.php'; } } elseif (isset($getarticle)) { // ARTICLE VIEW // generate the requested article diff --git a/res/css/rangitaki.css b/res/css/rangitaki.css index 00f64a2..54ecfea 100644 --- a/res/css/rangitaki.css +++ b/res/css/rangitaki.css @@ -218,6 +218,34 @@ body{ padding: 12px; } +/* BUTTON */ + +.pag_buttons { + margin-right: auto; + margin-left: auto; + width: calc(75% + 48px); + margin-bottom: 80px; + max-width: 1160px; + text-align: right; +} + +.button { + text-decoration: none; + color: #fff; + line-height: 36px; + min-width: 64px; + text-align: center; + height: 36px; + padding: 8px; + margin-top: 4px; + margin-bottom: 5px; + cursor: pointer; +} + +.pag_next{ + margin-left: 8px; +} + /* FOOTER */ .footer{ /* possibility for styling the footer */ @@ -270,4 +298,8 @@ body{ width: 82%; } + .pag_buttons { + width: calc(82% + 48px); + } + } diff --git a/res/php/BlogListGenerator.php b/res/php/BlogListGenerator.php index 4259bf3..799197f 100644 --- a/res/php/BlogListGenerator.php +++ b/res/php/BlogListGenerator.php @@ -1,63 +1,61 @@ + * @license MIT License + * @link http://marcel-kapfer.de/rangitaki */ - /** - * The blog list generator class is a collection of functions for generating blog lists - * or getting informations about them - * - * Since there is no initialize function, I recommend to use the short access syntay - * - * @category Blogs - * @package RangitakiPHP - * @author mmk2410 - * @license MIT License - * @link http://marcel-kapfer.de/rangitaki - */ + +/** + * The blog list generator class is a collection of functions for generating + * blog list + * or getting informations about them + * + * Since there is no initialize function, I recommend to use the short + * access syntay + * + * @category Generator + * @package Rbe + * @author Marcel Kapfer (mmk2410) + * @license MIT License + * @link http://marcel-kapfer.de/rangitaki + */ class BlogListGenerator { - /** * A function to generate a blog nav item * - * @param string $directory The directory of the blog file - * @param string $blogname The name of the blog file - * @param string $blogmaintitle The name of the main blog + * @param string $directory The directory of the blog file + * @param string $blogname The name of the blog file + * @param string $blogmaintitle The name of the main blog + * + * @return None */ function listBlog($directory, $blogname, $blogmaintitle) { - $blog = file_get_contents($directory . $blogname); // get content of the blog file - $blog = $blog . "\n"; // add a line break as a security measurement - if (substr($blog, 0, 6) == "%TITLE") { // check if the first line includes a title - $blog = substr($blog, 8, strpos($blog, "\n") - 8); // grab the title - if ($blog == "main") { // if on main blog - echo "$blogmaintitle"; // create a nav item to the main blog + // get content of the blog file; + $blog = file_get_contents($directory . $blogname); + // add a line break as a security measurement + $blog = $blog . "\n"; + // check if the first line includes a title + if (substr($blog, 0, 6) == "%TITLE") { + // grab the title + $blog = substr($blog, 8, strpos($blog, "\n") - 8); + // if on main blog + if ($blog == "main") { + // create a nav item to the main blog + echo "$blogmaintitle"; } else { - $link = "./?blog=" . substr($blogname, 0, -3); // create a link to the blog - echo "$blog"; // create a nav item to the blog + // create a link to the blog + $link = "./?blog=" . substr($blogname, 0, -3); + // create a nav item to the blog + echo "$blog"; } } } @@ -65,16 +63,46 @@ class BlogListGenerator /** * A function to get the name of a blog * - * @param string $file The path of the blog file - * @return string + * @param string $file The path of the blog file + * + * @return string */ function getName($file) { - $blog = file_get_contents($file); // get the content of the blog file - $blog = $blog . "\n"; // add a line break as a securit measure - if(substr($blog, 0, 6) == "%TITLE") { // check if first line includes a title - $blog = substr($blog, 8, strpos($blog, "\n") - 8); // grab the title - return $blog; // return it + // get the content of the blog file + $blog = file_get_contents($file); + // add a line break as a securit measure + $blog = $blog . "\n"; + // check if first line includes a title + if (substr($blog, 0, 6) == "%TITLE") { + // grab the title + $blog = substr($blog, 8, strpos($blog, "\n") - 8); + return $blog; + } + } + + /** + * A function to recieve the amount of articles + * of a blog + * + * @param string $blog the blog name + * + * @return int Amount of files + */ + static function getArticleAmount($blog) + { + $directory = "./articles/" . $blog . "/"; + if (!file_exists($directory)) { + return 0; + } else { + $i = 0; + $handle = opendir($directory); + while (($file = readdir($handle)) !== false ) { + if (!in_array($file, array('.','..'))) { + $i++; + } + } + return $i; } } diff --git a/res/php/Pagination.php b/res/php/Pagination.php new file mode 100644 index 0000000..c97678d --- /dev/null +++ b/res/php/Pagination.php @@ -0,0 +1,58 @@ + + * @license MIT License + * @link http://marcel-kapfer.de/rangitaki + */ +require_once "BlogListGenerator.php"; + +if ($pagination) { +?> +
+ 0) { + if (isset($getblog)) { +?> + PREVIOUS PAGE + + PREVIOUS PAGE + + NEXT PAGE + + NEXT PAGE + +
+ diff --git a/themes/background-img.css b/themes/background-img.css index 91b312e..29a9588 100644 --- a/themes/background-img.css +++ b/themes/background-img.css @@ -137,6 +137,47 @@ body{ box-shadow: 0px 1px 1.5px 1.5px rgba(62, 62, 62, 0.3); } +.button { + border-width: 1px; + border-style: solid; + box-shadow: 0px 1px 1.5px 1.5px rgba(42, 42, 42, 0.65); + -moz-box-shadow: 0px 1px 1.5px 1.5px rgba(42, 42, 42, 0.65); + -webkit-box-shadow: 0px 1px 1.5px 1.5px rgba(42, 42, 42, 0.65); + border-radius: 2px; + letter-spacing: 0.4px; + font-weight: 700; + font-size: 14px; + transition-property: box-shadow; + transition-delay: 50ms; + transition-duration: 125ms; + transition-timing-function: ease; + -moz-transition-property: box-shadow; + -moz-transition-delay: 50ms; + -moz-transition-duration: 125ms; + -moz-transition-timing-function: ease; + -webkit-transition-property: box-shadow; + -webkit-transition-delay: 50ms; + -webkit-transition-duration: 125ms; + -webkit-transition-timing-function: ease; +} + +.button:hover, .button:hover { + box-shadow: 0.5px 1.8px 2.1px 1.4px rgba(32, 32, 32, 0.85); + -moz-box-shadow: 0.5px 1.8px 2.1px 1.4px rgba(32, 32, 32, 0.85); + -webkit-box-shadow: 0.5px 1.8px 2.1px 1.4px rgba(32, 32, 32, 0.85); +} + +.pag_next{ + background-color: #ff4415; + border-color: #ff4415; +} + +.pag_prev{ + background-color: #fff; + border-color: #fff; + color: #383838; +} + .footer{ font-size: 12px; text-align: center; diff --git a/themes/material-dark.css b/themes/material-dark.css index 884b794..a984ef9 100644 --- a/themes/material-dark.css +++ b/themes/material-dark.css @@ -133,6 +133,47 @@ body{ box-shadow: 0px 1px 1.5px 1.5px rgba(42, 42, 42, 0.65); } +.button{ + border-width: 1px; + border-style: solid; + box-shadow: 0px 1px 1.5px 1.5px rgba(42, 42, 42, 0.65); + -moz-box-shadow: 0px 1px 1.5px 1.5px rgba(42, 42, 42, 0.65); + -webkit-box-shadow: 0px 1px 1.5px 1.5px rgba(42, 42, 42, 0.65); + border-radius: 2px; + letter-spacing: 0.4px; + font-weight: 700; + font-size: 14px; + transition-property: box-shadow; + transition-delay: 50ms; + transition-duration: 125ms; + transition-timing-function: ease; + -moz-transition-property: box-shadow; + -moz-transition-delay: 50ms; + -moz-transition-duration: 125ms; + -moz-transition-timing-function: ease; + -webkit-transition-property: box-shadow; + -webkit-transition-delay: 50ms; + -webkit-transition-duration: 125ms; + -webkit-transition-timing-function: ease; +} + +.button:hover, .button:hover { + box-shadow: 0.5px 1.8px 2.1px 1.4px rgba(32, 32, 32, 0.85); + -moz-box-shadow: 0.5px 1.8px 2.1px 1.4px rgba(32, 32, 32, 0.85); + -webkit-box-shadow: 0.5px 1.8px 2.1px 1.4px rgba(32, 32, 32, 0.85); +} + +.pag_next{ + background-color: #ff4415; + border-color: #ff4415; +} + +.pag_prev{ + background-color: #424242; + border-color: #424242; + color: #CCCCCC; +} + .footer{ font-size: 12px; text-align: center; diff --git a/themes/material-light.css b/themes/material-light.css index 46df0d5..fff3a0c 100644 --- a/themes/material-light.css +++ b/themes/material-light.css @@ -137,6 +137,47 @@ body{ box-shadow: 0px 1px 1.5px 1.5px rgba(62, 62, 62, 0.3); } +.button { + border-width: 1px; + border-style: solid; + box-shadow: 0.4px 1px 1.5px 1px #aaa; + -moz-box-shadow: 0.4px 1px 1.5px 1px #aaa; + -webkit-box-shadow: 0.4px 1px 1.5px 1px #aaa; + border-radius: 2px; + letter-spacing: 0.4px; + font-weight: 700; + font-size: 14px; + transition-property: box-shadow; + transition-delay: 50ms; + transition-duration: 125ms; + transition-timing-function: ease; + -moz-transition-property: box-shadow; + -moz-transition-delay: 50ms; + -moz-transition-duration: 125ms; + -moz-transition-timing-function: ease; + -webkit-transition-property: box-shadow; + -webkit-transition-delay: 50ms; + -webkit-transition-duration: 125ms; + -webkit-transition-timing-function: ease; +} + +.button:hover, .button:hover { + box-shadow: 0.5px 1.8px 2.1px 1.4px #aaa; + -moz-box-shadow: 0.5px 1.8px 2.1px 1.4px #aaa; + -webkit-box-shadow: 0.5px 1.8px 2.1px 1.4px #aaa; +} + +.pag_next{ + background-color: #ff4415; + border-color: #ff4415; +} + +.pag_prev{ + background-color: #fff; + border-color: #fff; + color: #383838; +} + .footer{ font-size: 12px; text-align: center;