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

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
}
?>