Pagination and Code Style improovements

This commit is contained in:
mmk2410 2015-12-20 17:50:22 +01:00
parent a880398ee3
commit 7eb917f115
19 changed files with 400 additions and 64 deletions

1
.gitignore vendored
View File

@ -1,2 +1,3 @@
nbproject/ nbproject/
.idea/ .idea/
completer.hist

View File

@ -1,4 +1,4 @@
%TITLE: The Rangitaki logo %TITLE: The Rangitaki logo 1
%DATE: 24 July 2015 %DATE: 24 July 2015
%TAGS: design, artwork, logo %TAGS: design, artwork, logo

View File

@ -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.

View File

@ -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.

View File

@ -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.

View File

@ -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.

View File

@ -1,10 +1,9 @@
%TITLE: The Rangitaki logo %TITLE: The Rangitaki logo 1
%DATE: 24 July 2015 %DATE: 24 July 2015
%AUTHOR: The great testers
%TAGS: design, artwork, logo %TAGS: design, artwork, logo
This is the official Rangitaki logo. This is the official Rangitaki logo.
![The Rangitaki logo](media/example.png) ![The Rangitaki logo](media/example.png)
It is saved in the example blog directory.

View File

@ -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.

View File

@ -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.

View File

@ -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.

View File

@ -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.

View File

@ -71,14 +71,14 @@ $rcc = 'yes';
$nav_drawer = 'yes'; $nav_drawer = 'yes';
// Set here the name of your theme. Read the documentation for more themes // 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 // Set here your language. The file must exist in the lang directory
$language = "en"; $language = "en";
// pagination: how many articles should be on one page // pagination: how many articles should be on one page
// set to 0 to disable it // set to 0 to disable it
$pagination = 0; $pagination = 2;
// Favicon - Set here the path to your favicon // Favicon - Set here the path to your favicon
$favicon = "http://example.com/res/img/favicon.png"; $favicon = "http://example.com/res/img/favicon.png";

View File

@ -37,13 +37,20 @@ $getarticle = filter_input(INPUT_GET, "article"); // get the article variable
$gettag = filter_input(INPUT_GET, "tag"); // getting the tag variable $gettag = filter_input(INPUT_GET, "tag"); // getting the tag variable
$url = "http://" . filter_input(INPUT_SERVER, "HTTP_HOST") . $url = "http://" . filter_input(INPUT_SERVER, "HTTP_HOST") .
filter_input(INPUT_SERVER, "REQUEST_URI"); // get the url (used for sharing) 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 // Pagination algorithm
if ($pagination == 0) { if ($pagination == 0) {
$pagination = false; $pagination = false;
} else { } 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 // Fetching necessary information about the current article
@ -125,7 +132,8 @@ if (isset($getarticle)) {
400italic,100,100italic,900' rel='stylesheet' 400italic,100,100italic,900' rel='stylesheet'
type='text/css'> <!--Font--> type='text/css'> <!--Font-->
<!--Favicons--> <!--Favicons-->
<link rel="shortcut icon" type="image/x-icon" href="<?php echo $favicon; ?>"/> <link rel="shortcut icon" type="image/x-icon"
href="<?php echo $favicon; ?>"/>
<link rel="apple-touch-icon-precomposed" href="<?php echo $favicon; ?>"> <link rel="apple-touch-icon-precomposed" href="<?php echo $favicon; ?>">
<!-- JavaScript Pt. 1: HightlightJS (get and load): Code highlighting--> <!-- JavaScript Pt. 1: HightlightJS (get and load): Code highlighting-->
<script src="./res/js/highlight.pack.js"></script> <script src="./res/js/highlight.pack.js"></script>
@ -295,12 +303,27 @@ if ($nav_drawer == "yes") {
// save the content of the directory in the articles variable // save the content of the directory in the articles variable
$articles = scandir($articlesdir, 1); $articles = scandir($articlesdir, 1);
// iterate through this variable // iterate through this variable
$posts_amount = 0;
foreach ($articles as $article) { foreach ($articles as $article) {
// check if the file is a article file // check if the file is a article file
if (strlen($article) >= 3 && substr($article, -3) == ".md") { if (strlen($article) >= 3 && substr($article, -3) == ".md") {
// generate the article // 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 } elseif (isset($getarticle)) { // ARTICLE VIEW
// generate the requested article // generate the requested article

View File

@ -218,6 +218,34 @@ body{
padding: 12px; 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 */
.footer{ /* possibility for styling the footer */ .footer{ /* possibility for styling the footer */
@ -270,4 +298,8 @@ body{
width: 82%; width: 82%;
} }
.pag_buttons {
width: calc(82% + 48px);
}
} }

View File

@ -1,63 +1,61 @@
<?php <?php
/* /**
* PHP Version 5.6
*
* Rangitaki Project * Rangitaki Project
* *
* The MIT License * @category Blogs
* * @package RangitakiPHP
* Copyright 2015 mmk2410. * @author mmk2410 <marcelmichaelkapfer@yahoo.co.nz>
* * @license MIT License
* Permission is hereby granted, free of charge, to any person obtaining a copy * @link http://marcel-kapfer.de/rangitaki
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/ */
/**
* The blog list generator class is a collection of functions for generating blog lists /**
* or getting informations about them * The blog list generator class is a collection of functions for generating
* * blog list
* Since there is no initialize function, I recommend to use the short access syntay * or getting informations about them
* *
* @category Blogs * Since there is no initialize function, I recommend to use the short
* @package RangitakiPHP * access syntay
* @author mmk2410 <marcelmichaelkapfer@yahoo.co.nz> *
* @license MIT License * @category Generator
* @link http://marcel-kapfer.de/rangitaki * @package Rbe
*/ * @author Marcel Kapfer (mmk2410) <marcelmichaelkapfer@yahoo>
* @license MIT License
* @link http://marcel-kapfer.de/rangitaki
*/
class BlogListGenerator class BlogListGenerator
{ {
/** /**
* A function to generate a blog nav item * A function to generate a blog nav item
* *
* @param string $directory The directory of the blog file * @param string $directory The directory of the blog file
* @param string $blogname The name of the blog file * @param string $blogname The name of the blog file
* @param string $blogmaintitle The name of the main blog * @param string $blogmaintitle The name of the main blog
*
* @return None
*/ */
function listBlog($directory, $blogname, $blogmaintitle) function listBlog($directory, $blogname, $blogmaintitle)
{ {
$blog = file_get_contents($directory . $blogname); // get content of the blog file // get content of the blog file;
$blog = $blog . "\n"; // add a line break as a security measurement $blog = file_get_contents($directory . $blogname);
if (substr($blog, 0, 6) == "%TITLE") { // check if the first line includes a title // add a line break as a security measurement
$blog = substr($blog, 8, strpos($blog, "\n") - 8); // grab the title $blog = $blog . "\n";
if ($blog == "main") { // if on main blog // check if the first line includes a title
echo "<a class='nav-item' href='./'>$blogmaintitle</a>"; // create a nav item to the main blog 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 "<a class='nav-item' href='./'>$blogmaintitle</a>";
} else { } else {
$link = "./?blog=" . substr($blogname, 0, -3); // create a link to the blog // create a link to the blog
echo "<a class='nav-item' href='$link'>$blog</a>"; // create a nav item to the blog $link = "./?blog=" . substr($blogname, 0, -3);
// create a nav item to the blog
echo "<a class='nav-item' href='$link'>$blog</a>";
} }
} }
} }
@ -65,16 +63,46 @@ class BlogListGenerator
/** /**
* A function to get the name of a blog * A function to get the name of a blog
* *
* @param string $file The path of the blog file * @param string $file The path of the blog file
* @return string *
* @return string
*/ */
function getName($file) function getName($file)
{ {
$blog = file_get_contents($file); // get the content of the blog file // get the content of the blog file
$blog = $blog . "\n"; // add a line break as a securit measure $blog = file_get_contents($file);
if(substr($blog, 0, 6) == "%TITLE") { // check if first line includes a title // add a line break as a securit measure
$blog = substr($blog, 8, strpos($blog, "\n") - 8); // grab the title $blog = $blog . "\n";
return $blog; // return it // 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;
} }
} }

58
res/php/Pagination.php Normal file
View File

@ -0,0 +1,58 @@
<?php
/**
* PHP Version 5
*
* PHP script for creating the next / prev page links
*
* @category Pagination
* @package Rbe
* @author Marcel Kapfer (mmk2410) <marcelmichaelkapfer@yahoo.co.nz>
* @license MIT License
* @link http://marcel-kapfer.de/rangitaki
*/
require_once "BlogListGenerator.php";
if ($pagination) {
?>
<div class="pag_buttons">
<?php
if ($pag_min > 0) {
if (isset($getblog)) {
?>
<a href="<?php
echo "?blog=" . $getblog . "&page=" . ($pagenumber - 1);
?>" class="pag_prev button">PREVIOUS PAGE</a>
<?php
} else {
?>
<a href="<?php
echo "?page=" . ($pagenumber - 1);
?>" class="pag_prev button">PREVIOUS PAGE</a>
<?php
}
}
if (isset($getblog)) {
$pag_blog = $getblog;
} else {
$pag_blog = "main";
}
if ($pag_max < BlogListGenerator::getArticleAmount($pag_blog)) {
if (isset($getblog)) {
?>
<a href="<?php
echo "?blog=" . $getblog . "&page=" . ($pagenumber + 1);
?>" class="pag_next button">NEXT PAGE</a>
<?php
} else {
?>
<a href="<?php
echo "?page=" . ($pagenumber + 1);
?>" class="pag_next button">NEXT PAGE</a>
<?php
}
}
?>
</div>
<?php
}
?>

View File

@ -137,6 +137,47 @@ body{
box-shadow: 0px 1px 1.5px 1.5px rgba(62, 62, 62, 0.3); 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{ .footer{
font-size: 12px; font-size: 12px;
text-align: center; text-align: center;

View File

@ -133,6 +133,47 @@ body{
box-shadow: 0px 1px 1.5px 1.5px rgba(42, 42, 42, 0.65); 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{ .footer{
font-size: 12px; font-size: 12px;
text-align: center; text-align: center;

View File

@ -137,6 +137,47 @@ body{
box-shadow: 0px 1px 1.5px 1.5px rgba(62, 62, 62, 0.3); 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{ .footer{
font-size: 12px; font-size: 12px;
text-align: center; text-align: center;