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/
.idea/
completer.hist

View File

@ -1,4 +1,4 @@
%TITLE: The Rangitaki logo
%TITLE: The Rangitaki logo 1
%DATE: 24 July 2015
%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
%AUTHOR: The great testers
%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 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';
// 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";

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
$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'> <!--Font-->
<!--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; ?>">
<!-- JavaScript Pt. 1: HightlightJS (get and load): Code highlighting-->
<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
$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

View File

@ -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);
}
}

View File

@ -1,63 +1,61 @@
<?php
/*
/**
* PHP Version 5.6
*
* Rangitaki Project
*
* The MIT License
*
* Copyright 2015 mmk2410.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* 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.
* @category Blogs
* @package RangitakiPHP
* @author mmk2410 <marcelmichaelkapfer@yahoo.co.nz>
* @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 <marcelmichaelkapfer@yahoo.co.nz>
* @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) <marcelmichaelkapfer@yahoo>
* @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 "<a class='nav-item' href='./'>$blogmaintitle</a>"; // 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 "<a class='nav-item' href='./'>$blogmaintitle</a>";
} else {
$link = "./?blog=" . substr($blogname, 0, -3); // create a link to the blog
echo "<a class='nav-item' href='$link'>$blog</a>"; // 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 "<a class='nav-item' href='$link'>$blog</a>";
}
}
}
@ -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;
}
}

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);
}
.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;

View File

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

View File

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