Better Code Style

This commit is contained in:
mmk2410 2015-12-18 21:59:34 +01:00
parent b3802a8994
commit a880398ee3
4 changed files with 243 additions and 79 deletions

View File

@ -1,40 +1,84 @@
<?php <?php
// Rangitaki Project /**
// This is the configuration file. You can configure here all necessary (and possible) options without editing the index.php file. * PHP Version 5.6
// Every line has an description about what you can change here. Don't delete any strings. You can set your value after the '=' sign and between the apostrophes. *
// Make sure that every line ends with an semicolon (';'). * Rangitaki Project
// Blog Title - Set here an individual title of your blog by replacing Rangitaki Blog with it. * This is the configuration file. You can configure here all necessary
$blogtitle = 'Rangitaki Blog'; * (and possible) options without editing the index.php file.
* Every line has an description about what you can change here.
* Don't delete any strings. You can set your value after the '=' sign
* and between the apostrophes.
*
* Make sure that every line ends with an semicolon (';').
*
* @category Config
* @package Rbe
* @author Marcel Kapfer (mmk2410) <marcelmichaelkapfer@yahoo.co.nz>
* @license MIT License
* @link http://marcel-kapfer.de/rangitaki
*/
// Blog Title / Set here an individual title of yourblog by replacing
// Rangitaki Blog with it.
$blogtitle = 'Example Blog';
// Blog Author - Set here your name // Blog Author - Set here your name
$blogauthor = 'Marcel Kapfer'; $blogauthor = 'John';
// Blog description // Blog description
$blogdescription = 'Rangitaki - A PHP blogging engine without any database dependency'; $blogdescription = 'A short description of your blog';
// Home - set yes if you want to link to your homepage and no if not // Home - set yes if you want to link to your homepage and no if not
$bloghome = 'yes'; $bloghome = 'yes';
// Home URL - Set here the url to your main page. Either relative (e.g. '../') or absolute (e.g. 'http://github.com')
// Home URL - Set here the url to your main page. Either as a path (e.g. '../')
// or as an url (e.g. 'http://github.com')
$bloghomeurl = '../'; $bloghomeurl = '../';
// Home name - Set here an individual name for your main page // Home name - Set here an individual name for your main page
$bloghomename = 'Home'; $bloghomename = 'Home';
// Main Blog name -> Set a specific name for your main blog // Main Blog name -> Set a specific name for your main blog
// This value is empty by default // This value is empty by default
$blogmainname = ''; $blogmainname = '';
// Intro - set yes if you have a blog intro and no if you don't have one // Intro - set yes if you have a blog intro and no if you don't have one
$blogintro = 'yes'; $blogintro = 'yes';
// Disqus - Provide here your Disqus shortname. Leave empty if you don't want to use it.
// Disqus - Provide here your Disqus shortname. Leave empty if you don't
// want to use it.
$blogdisqus = 'rangitaki'; $blogdisqus = 'rangitaki';
// Share FAB - this enables or disables the share button // Share FAB - this enables or disables the share button
$sharefab = 'yes'; $sharefab = 'yes';
// Google Analytics - Provide here your Google Analytics Tracking-ID. Leave empty if you don't want to use it.
// Google Analytics - Provide here your Google Analytics Tracking-ID. Leave
// empty if you don't want to use it.
$bloganalytics = ''; $bloganalytics = '';
// Footer - set here the text for your footer (e.g. a copyright info). You can replace the whole text after the '=' with your own one.
$blogfooter = 'Rangitaki ' . date("Y") . ' <a href="https://github.com/mmk2410/Rangitaki" target="blank">github.com/mmk2410/Rangitaki</a>'; // Footer - set here the text for your footer (e.g. a copyright info). You can
// This enables the optional rangitaki control center. Please read the documentation before you enable it. // replace the whole text after the '=' with your own one.
$blogfooter = 'Rangitaki ' . date("Y") .
' <a href="https://github.com/mmk2410/Rangitaki" target="blank">
github.com/mmk2410/Rangitaki</a>';
// This enables the optional rangitaki control center. Please read the
// documentation before you enable it.
$rcc = 'yes'; $rcc = 'yes';
// Here you can disable and enable the navigation menu. Usefull if you have no subblogs and no home directory
// Here you can disable and enable the navigation menu. Usefull if you have
// no subblogs and no home directory
$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 = 'material-light';
// 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
// set to 0 to disable it
$pagination = 0;
// Favicon - Set here the path to your favicon // Favicon - Set here the path to your favicon
$favicon = "https://example.com/res/img/favicon.png"; $favicon = "http://example.com/res/img/favicon.png";

216
index.php
View File

@ -1,6 +1,6 @@
<!DOCTYPE HTML> <!DOCTYPE HTML>
<!-- <!--
Rangitaki Rangitaki Blogging Engine
GitHub: https://github.com/mmk2410/Rangitaki GitHub: https://github.com/mmk2410/Rangitaki
Web: https://marcel-kapfer.de/rangitaki Web: https://marcel-kapfer.de/rangitaki
Twitter: @Rangitaki Twitter: @Rangitaki
@ -14,12 +14,15 @@ MIT License
<html> <html>
<?php <?php
/** /**
* PHP Version 5.6
*
* Rangitaki PHP Blogging engine * Rangitaki PHP Blogging engine
*
* @category Blogging * @category Blogging
* @package Rbe * @package Rbe
* @author Marcel Kapfer (mmk2410) <marcelmichaelkapfer@yahoo.co.nz> * @author Marcel Kapfer (mmk2410) <marcelmichaelkapfer@yahoo.co.nz>
* @license MIT https://opensource.org/licenses/MIT * @license MIT https://opensource.org/licenses/MIT
* @link https://marcel-kapfer.de/rangitaki * @link https://marcel-kapfer.de/rangitaki
*/ */
// Getting necessary php files // Getting necessary php files
date_default_timezone_set('UTC'); date_default_timezone_set('UTC');
@ -29,22 +32,35 @@ require_once 'res/php/Parsedown.php'; // The soul of the beast: Parsedown
require_once 'res/php/ArticleGenerator.php'; // The article generator require_once 'res/php/ArticleGenerator.php'; // The article generator
require_once './res/php/BlogListGenerator.php'; // and the blog list generator require_once './res/php/BlogListGenerator.php'; // and the blog list generator
// Getting some variables ($_GET and $_SERVER) // Getting some variables ($_GET and $_SERVER)
$getblog = filter_input(INPUT_GET, "blog"); // getting the blog variable $getblog = filter_input(INPUT_GET, "blog"); // get the blog variable
$getarticle = filter_input(INPUT_GET, "article"); // getting the article variable $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") . filter_input(INPUT_SERVER, "REQUEST_URI"); // getting the url (used for sharing) $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
// Pagination algorithm
if ($pagination == 0) {
$pagination = false;
} else {
$pagination = $pagination * ( $pagenumber + 1 );
}
// Fetching necessary information about the current article // Fetching necessary information about the current article
// Set blog to "main" if on main blog, else to $getblog. This variable is needed later // Set blog to "main" if on main blog, else to $getblog.
// This variable is needed later
if ($getblog == "") { if ($getblog == "") {
$blog = "main"; $blog = "main";
} else { } else {
$blog = $getblog; $blog = $getblog;
} }
$articlesdir = "./articles/$blog/"; // generate a variable with the articles directory
// generate a variable with the articles directory
$articlesdir = "./articles/$blog/";
// Fetching the articles title // Fetching the articles title
if (isset($getarticle)) { if (isset($getarticle)) {
$articletitle = ArticleGenerator::getTitle($articlesdir, $getarticle . '.md'); $articletitle
= ArticleGenerator::getTitle($articlesdir, $getarticle . '.md');
} }
// Make sure that the entry has a title, because main.md hasn't one // Make sure that the entry has a title, because main.md hasn't one
if (empty($blogmainname)) { if (empty($blogmainname)) {
@ -69,10 +85,14 @@ if (isset($getarticle)) {
<meta charset="utf-8"> <meta charset="utf-8">
<title><?php echo $hd_subblog_title; ?></title> <title><?php echo $hd_subblog_title; ?></title>
<!--Metatags--> <!--Metatags-->
<meta name="author" content="<?php echo $blogauthor; // Setting the blog author ?>"/> <meta name="author"
<meta name="description" content="<?php echo $blogdescription; // the blog description ?>"/> content="<?php echo $blogauthor; // Set the blog author ?>"/>
<meta name="description"
content="<?php echo $blogdescription; // the blog description ?>"/>
<!-- Meta tag for responsive ui--> <!-- Meta tag for responsive ui-->
<meta content='width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0' name='viewport'/> <meta name='viewport'
content='width=device-width, initial-scale=1.0,
maximum-scale=1.0, user-scalable=0'/>
<!-- OpenGraph meta tags --> <!-- OpenGraph meta tags -->
<meta property="og:title" content="<?php echo $hd_subblog_title; ?>"/> <meta property="og:title" content="<?php echo $hd_subblog_title; ?>"/>
<meta property="og:type" content="website"/> <meta property="og:type" content="website"/>
@ -89,8 +109,10 @@ if (isset($getarticle)) {
<meta name="twitter:url" content="<?php echo $url; ?>"/> <meta name="twitter:url" content="<?php echo $url; ?>"/>
<!--CSS files--> <!--CSS files-->
<link rel="stylesheet" type="text/css" href="res/css/rangitaki.css"/> <link rel="stylesheet" type="text/css" href="res/css/rangitaki.css"/>
<link rel="stylesheet" href="./res/css/github-gist.css"> <!-- stylesheet for code highlighting--> <!-- stylesheet for code highlighting-->
<link rel="stylesheet" type="text/css" href="themes/<?php echo $theme; // getting the theme stylesheet?>.css"/> <link rel="stylesheet" href="./res/css/github-gist.css">
<link rel="stylesheet" type="text/css"
href="themes/<?php echo $theme; // getting the theme stylesheet?>.css"/>
<?php <?php
// Checking if the drawer is enabled // Checking if the drawer is enabled
if ($nav_drawer == 'no') { if ($nav_drawer == 'no') {
@ -99,7 +121,8 @@ if (isset($getarticle)) {
<?php <?php
} }
?> ?>
<link href='//fonts.googleapis.com/css?family=Roboto:400,500,700,300,400italic,100,100italic,900' rel='stylesheet' <link href='//fonts.googleapis.com/css?family=Roboto:400,500,700,300,
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; ?>"/>
@ -114,40 +137,65 @@ if (isset($getarticle)) {
// Checking if the navigation drawer is enabled. If not -> skip it // Checking if the navigation drawer is enabled. If not -> skip it
if ($nav_drawer == "yes") { if ($nav_drawer == "yes") {
?> ?>
<div class="overlay"></div> <!-- Darken the background when fading the drawer in. See also the JS file--> <!--
Darken the background when fading the drawer in. See also the JS file
-->
<div class="overlay"></div>
<div class="nav"> <div class="nav">
<div class="nav-close"> <div class="nav-close">
<img src="./res/img/close-dark.svg" class="nav-close-img" alt="Close"/> <img src="./res/img/close-dark.svg" class="nav-close-img"
alt="Close"/>
</div> </div>
<div class="divider"></div> <div class="divider"></div>
<?php <?php
$blogs = scandir("./blogs/"); // Getting everything from the blog directory // Getting everything from the blog directory
if (!isset($getarticle) && !isset($gettag) && sizeof($blogs) > 3) { // Checking if not in article or tag view and if there are more the one blog. The 3 is for these three array entries: 'main.md', '.', '..' $blogs = scandir("./blogs/");
// Checking if not in article or tag view and if there are more the one
// blog. The 3 is for these three array entries: 'main.md', '.', '..'
if (!isset($getarticle) && !isset($gettag) && sizeof($blogs) > 3) {
echo "<section>"; echo "<section>";
echo "<div class='nav-item-static'>" . $BLOGLANG['Blogs on'] . " $blogtitle:</div>"; // 1. Set localized string 2. Set blogtitle // 1. Set localized string 2. Set blogtitle
foreach ($blogs as $navblog) { // iterating through the blogs/ directory echo "<div class='nav-item-static'>" .
if (strlen($navblog) >= 3 && substr($navblog, -3) == ".md") { // check if filename is larger than three chars and if the file ends with ".md" $BLOGLANG['Blogs on'] .
" $blogtitle:</div>";
// iterating through the blogs/ directory
foreach ($blogs as $navblog) {
// check if filename is larger than three chars and if the
// file ends with ".md"
if (strlen($navblog) >= 3 && substr($navblog, -3) == ".md") {
if ($getblog == "") { // Run when on main blog if ($getblog == "") { // Run when on main blog
if ($navblog != "main.md") { // excluding main blog if ($navblog != "main.md") { // excluding main blog
BlogListGenerator::listBlog("./blogs/", $navblog, $blogtitle); // creating navigation item // creating navigation item
BlogListGenerator::listBlog(
"./blogs/", $navblog, $blogtitle
);
} }
} else { } else {
if ($getblog . ".md" != $navblog) { // Check if $blog is current blog -> this blog will be excluded // Check if $blog is current blog
BlogListGenerator::listBlog("./blogs/", $navblog, $blogmaintitle); // creating navigation item // -> this blog will be excluded
if ($getblog . ".md" != $navblog) {
// creating navigation item
BlogListGenerator::listBlog(
"./blogs/", $navblog, $blogmaintitle
);
} }
} }
} }
} }
echo "</section>"; echo "</section>";
} elseif (isset($getarticle) || isset($gettag)) { // If viewing a blog or a tag } elseif (isset($getarticle) || isset($gettag)) {
// If viewing a blog or a tag
?> ?>
<a class="nav-item" onclick="goBack()">Go back</a> <!-- Set a back item instead of the blogs. --> <!-- Set a back item instead of the blogs. -->
<a class="nav-item" onclick="goBack()">Go back</a>
<?php <?php
} }
if ($bloghome == "yes") { // If a blog home is existend if ($bloghome == "yes") { // If a blog home is existend
?> ?>
<div class="divider"></div> <div class="divider"></div>
<a class="nav-item" href="<?php echo $bloghomeurl; ?>"><?php echo $bloghomename; ?></a> <a class="nav-item" href="<?php echo $bloghomeurl; ?>">
<?php echo $bloghomename; ?>
</a>
<?php <?php
} }
?> ?>
@ -158,35 +206,56 @@ if ($nav_drawer == "yes") {
?> ?>
<div class="main"> <!-- Main page with content --> <div class="main"> <!-- Main page with content -->
<div class="header"> <div class="header">
<!-- Action Bar, but since there isn't much action I call it header. One day a search feature would be nice...--> <!--
<img src="./res/img/menu.svg" class="nav-img"/> <!-- Ham,ham,hamburger--> Action Bar, but since there isn't much action I call it header.
One day a search feature would be nice...
-->
<!-- Ham,ham,hamburger-->
<img src="./res/img/menu.svg" class="nav-img"/>
<!-- Blog title with subblog title and links to each one--> <!-- Blog title with subblog title and links to each one-->
<nobr><span class="title"><a href="./"><?php echo $blogtitle; ?><!-- link to main blog--> <!-- link to main blog-->
<nobr><span class="title"><a href="./"><?php echo $blogtitle; ?>
<?php <?php
if (empty($getblog)) { // if not on a subblog if (empty($getblog)) { // if not on a subblog
if (!empty($blogmainname)) { if (!empty($blogmainname)) {
echo "" . $blogmainname; // If you see a (square) here : This is not a bug, but a missing sign in your font // If you see a (square) here : This is not a bug,
// but a missing sign in your font
echo "" . $blogmainname;
} }
} else { // On subblog: set also a link to the subblog } else { // On subblog: set also a link to the subblog
?> ?>
</a> </a>
<a href="<?php echo "./?blog=$getblog" ?>"> <a href="<?php echo "./?blog=$getblog" ?>">
<?php <?php
echo BlogListGenerator::getName("./blogs/$getblog.md"); // get the blog name // get the blog name
echo BlogListGenerator::getName("./blogs/$getblog.md");
} }
?> ?>
</a> </a>
</span> </span>
</nobr> </nobr>
<div class="fadeout"></div> <div class="fadeout"></div>
<!-- if the blog name is to long (especially on mobile devices), a fadeout fades the test out at the end of the header--> <!--
if the blog name is to long (especially on mobile devices), a fadeout
fades the text out at the end of the header
-->
</div> </div>
<?php <?php
// Blog Intro text // Blog Intro text
if (file_exists("blogs/$blog.md") && $getarticle == "" && $blogintro == "yes" && $gettag == "") { // only shown if not in article or tag view and if the blogintro is enabled if (file_exists("blogs/$blog.md")
$file = file_get_contents("blogs/$blog.md"); // get content of the blog file && $getarticle == ""
$file = $file . "\n"; // add a line break. necessary if the editor didn't make one while saving && $blogintro == "yes"
$file = substr($file, strpos($file, "\n")); // basically removing the first line, which contains the blog title && $gettag == ""
) {
// only shown if not in article or tag view
// and if the blogintro is enabled
// get content of the blog file
$file = file_get_contents("blogs/$blog.md");
// add a line break. necessary if the editor didn't make
// one while saving
$file = $file . "\n";
// basically removing the first line, which contains the blog title
$file = substr($file, strpos($file, "\n"));
if (strlen($file) > 3) { // if there is no content, don't show the intro if (strlen($file) > 3) { // if there is no content, don't show the intro
?> ?>
<section class="card" id="intro"> <section class="card" id="intro">
@ -204,24 +273,40 @@ if ($nav_drawer == "yes") {
} }
// TAG VIEW // TAG VIEW
if (isset($gettag)) { // if there's a tag -> tag view if (isset($gettag)) { // if there's a tag -> tag view
$articles = scandir($articlesdir, 1); // save the content of the directory in the articles variable // save the content of the directory in the articles variable
foreach ($articles as $article) { // iterate through all articles $articles = scandir($articlesdir, 1);
$tags = ArticleGenerator::getTags($articlesdir, $article); // get the article tags // iterate through all articles
if (in_array($gettag, $tags)) { // if the article has the requested tag foreach ($articles as $article) {
if (strlen($article) >= 3 && substr($article, -3) == ".md") { // check if the file is a article file // get the article tags
ArticleGenerator::newArticle($articlesdir, $article, $getblog); // generate the article $tags = ArticleGenerator::getTags($articlesdir, $article);
// if the article has the requested tag
if (in_array($gettag, $tags)) {
// check if the file is a article file
if (strlen($article) >= 3 && substr($article, -3) == ".md") {
// generate the article
ArticleGenerator::newArticle(
$articlesdir, $article, $getblog
);
} }
} }
} }
} elseif ($getarticle == "") { // NORMAL VIEW if there's no article request -> normal view } elseif ($getarticle == "") {
$articles = scandir($articlesdir, 1); // save the content of the directory in the articles variable // NORMAL VIEW if there's no article request -> normal view
foreach ($articles as $article) { // iterate through this variable // save the content of the directory in the articles variable
if (strlen($article) >= 3 && substr($article, -3) == ".md") { // check if the file is a article file $articles = scandir($articlesdir, 1);
ArticleGenerator::newArticle($articlesdir, $article, $getblog); // generate the article // iterate through this variable
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);
} }
} }
} elseif (isset($getarticle)) { // ARTICLE VIEW } elseif (isset($getarticle)) { // ARTICLE VIEW
ArticleGenerator::newArticle($articlesdir, $getarticle . ".md", $getblog); // generate the requested article // generate the requested article
ArticleGenerator::newArticle(
$articlesdir, $getarticle . ".md", $getblog
);
include './res/php/Disqus.php'; // include disques include './res/php/Disqus.php'; // include disques
} else { // SOMETHING STRANGE: THIS SHOULDN'T HAPPEN } else { // SOMETHING STRANGE: THIS SHOULDN'T HAPPEN
echo "Some error occured, please go back."; echo "Some error occured, please go back.";
@ -236,25 +321,38 @@ if ($nav_drawer == "yes") {
?> ?>
<div class="fabmenu"> <div class="fabmenu">
<div class="subfab"><!--Email subfab--> <div class="subfab"><!--Email subfab-->
<a href='mailto:?subject=<?php echo $blogtitle; ?>&body=<?php echo $BLOGLANG['Check out this blog']; ?>: <?php echo $url; ?>' <a href='mailto:?subject=<?php
target="blank"> echo $blogtitle;
?>&body=<?php
echo $BLOGLANG['Check out this blog'];
?>: <?php
echo $url;
?>' target="blank">
<img src="./res/img/email.svg" class="subfab-img"/> <img src="./res/img/email.svg" class="subfab-img"/>
</a> </a>
</div> </div>
<div class="subfab"><!--twitter subfav--> <div class="subfab"><!--twitter subfav-->
<a href='https://twitter.com/intent/tweet?text=<?php echo $BLOGLANG['Check out']; ?>: <?php echo $url; ?>&original_referer=' <a href='https://twitter.com/intent/tweet?text=<?php
target="blank"> echo $BLOGLANG['Check out'];
?>: <?php
echo $url;
?>&original_referer=' target="blank">
<img src="./res/img/twitter.svg" class="subfab-img"/> <img src="./res/img/twitter.svg" class="subfab-img"/>
</a> </a>
</div> </div>
<div class="subfab"><!--gplus subfab--> <div class="subfab"><!--gplus subfab-->
<a href='https://plus.google.com/share?url=<?php echo $url; ?>&hl=en-US' target="blank"> <a href='https://plus.google.com/share?url=<?php
echo $url;
?>&hl=en-US' target="blank">
<img src="./res/img/gplus.svg" class="subfab-img"/> <img src="./res/img/gplus.svg" class="subfab-img"/>
</a> </a>
</div> </div>
<div class="subfab"><!--facebook subfab--> <div class="subfab"><!--facebook subfab-->
<a href='https://www.facebook.com/sharer/sharer.php?u=<?php echo $url; ?>&t=<?php echo "echo $blogtitle" ?>' <a href='https://www.facebook.com/sharer/sharer.php?u=<?php
target="blank"> echo $url;
?>&t=<?php
echo "echo $blogtitle"
?>' target="blank">
<img src="./res/img/facebook.svg" class="subfab-img"/> <img src="./res/img/facebook.svg" class="subfab-img"/>
</a> </a>
</div> </div>

View File

@ -1,6 +1,17 @@
<?php <?php
// Rangitaki Project /**
// LANGUAGE: GERMAN * PHP Version 5.6
*
* Rangitaki Project
*
* Language File: German / Deutsch
*
* @category Language_File
* @package Rbe
* @author Marcel Kapfer (mmk2410) <marcelmichaelkapfer@yahoo.co.nz>
* @license MIT License
* @link http://marcel-kapfer.de/rangitaki
*/
$BLOGLANG = [ $BLOGLANG = [
"Blogs on" => "Blogs auf", "Blogs on" => "Blogs auf",

View File

@ -1,6 +1,17 @@
<?php <?php
// Rangitaki Project /**
// LANGUAGE: ENGLISH * PHP Version 5.6
*
* Rangitaki Project
*
* Language File: German / Deutsch
*
* @category Language_File
* @package Rbe
* @author Marcel Kapfer (mmk2410) <marcelmichaelkapfer@yahoo.co.nz>
* @license MIT License
* @link http://marcel-kapfer.de/rangitaki
*/
$BLOGLANG = [ $BLOGLANG = [
"Blogs on" => "Blogs on", "Blogs on" => "Blogs on",