diff --git a/blog.php b/blog.php index 4b9a262..8446f9a 100644 --- a/blog.php +++ b/blog.php @@ -8,33 +8,33 @@ * See LICENSE.blog file for copyright and license details. */ -spl_autoload_register(function($class){ +// some settings +define('BLOG_EXT', "md"); +define('BLOG_TITLE', "speedie's blog"); +define('BLOG_DESC', "speedie's blog, about stuff I want to talk about."); +define('BLOG_URL', "https://speedie.site/blog"); +define('BLOG_LATEST_TEXT', "Latest blog post: "); +define('BLOG_DIR', "/articles"); +define('DISPLAY_NUM', false); +define('DISPLAY_ID', false); +define('ENABLE_TITLE', true); +define('ENABLE_HEAD', true); +define('ENABLE_FOOTER', true); +define('META_DESC', true); +define('META_ENC', true); + +spl_autoload_register(function($class) { require str_replace('\\', DIRECTORY_SEPARATOR, ltrim($class, '\\')).'.php'; }); -use md\MarkdownExtra; - -define('BLOG_PATH', dirname(__FILE__). '/articles'); -define('BLOG_EXT', 'md'); -define('BLOG_TITLE', "speedie's blog"); -define('BLOG_DESC', "speedie's blog, about stuff I want to talk about."); -define('LATEST_TEXT', "Latest blog post: "); -define('BLOG_URL', "https://speedie.site/blog"); -define('DISPLAY_NUM', false); -define('DISPLAY_ID', false); -define('BASE_URI', str_replace('/index.php', '', $_SERVER['SCRIPT_NAME'])); - define('SELF', $_SERVER['SCRIPT_NAME']); define('VIEW', ''); +define('BASE_URI', str_replace('/index.php', '', $_SERVER['SCRIPT_NAME'])); +define('BLOG_PATH', dirname(__FILE__). BLOG_DIR); -define('ENABLE_TITLE', true); -define('ENABLE_HEAD', true); -define('ENABLE_FOOTER', true); +use md\MarkdownExtra; -define('META_DESC', true); -define('META_ENC', true); - -function __( $label, $alt_word = null ) { +function isntNull( $label, $alt_word = null ) { return is_null($alt_word) ? $label : $alt_word; } @@ -95,8 +95,8 @@ function printFooter() { } } -function getDateForPage($pageName, $pageDate) { - $file = BLOG_PATH . "/$pageName." . BLOG_EXT . ".date"; +function getDateForPost($postName, $postDate) { + $file = BLOG_PATH . "/$postName." . BLOG_EXT . ".date"; if (file_exists($file)) { return file_get_contents($file); @@ -105,7 +105,7 @@ function getDateForPage($pageName, $pageDate) { } } -function getAllPageNames($path = "") { +function getAllPostNames($path = "") { $filenames = array(); $dir = opendir(BLOG_PATH . "/$path" ); @@ -115,7 +115,7 @@ function getAllPageNames($path = "") { } if ( is_dir( BLOG_PATH . "/$path/$filename" ) ) { - array_push($filenames, ...getAllPageNames( "$path/$filename" ) ); + array_push($filenames, ...getAllPostNames( "$path/$filename" ) ); continue; } @@ -130,20 +130,20 @@ function getAllPageNames($path = "") { return $filenames; } -function fileNameForPage($page) { - return BLOG_PATH . "/$page." . BLOG_EXT; +function fileNameForPost($post) { + return BLOG_PATH . "/$post." . BLOG_EXT; } -function dateForPage($page) { - $file = BLOG_PATH . "/$page." . BLOG_EXT . ".date"; +function dateForPost($post) { + $file = BLOG_PATH . "/$post." . BLOG_EXT . ".date"; if (file_exists($file)) { return file_get_contents($file); } } -function numForPage($page) { - $file = BLOG_PATH . "/$page." . BLOG_EXT . ".num"; +function numForPost($post) { + $file = BLOG_PATH . "/$post." . BLOG_EXT . ".num"; return file_get_contents($file); } @@ -152,12 +152,12 @@ function sanitizeFilename($inFileName) { return str_replace(array('~', '..', '\\', ':', '|', '&', '.', '+', '!'), '-', $inFileName); } -function pageURL($page) { - return SELF . VIEW . "/".str_replace("%2F", "/", str_replace("%23", "#", urlencode(sanitizeFilename($page)))); +function postURL($post) { + return SELF . VIEW . "/".str_replace("%2F", "/", str_replace("%23", "#", urlencode(sanitizeFilename($post)))); } -function pageLink($page, $title, $attributes="") { - return "$title"; +function postLink($post, $title, $attributes="") { + return "$title"; } function toHTMLID($noid) { @@ -174,13 +174,13 @@ function toHTML($inText) { for ($i = 0; $i < count($matches[0]); $i++) { $fullLinkText = $matches[1][$i]; $linkTitleSplit = explode('|', $fullLinkText); - $linkedPage = $linkTitleSplit[0]; // split away an eventual link text - $linkText = (count($linkTitleSplit) > 1) ? $linkTitleSplit[1] : $linkedPage; - $pagePart = explode('#', $linkedPage)[0]; // split away an eventual anchor part - $linkedFilename = fileNameForPage(sanitizeFilename($pagePart)); + $linkedPost = $linkTitleSplit[0]; // split away an eventual link text + $linkText = (count($linkTitleSplit) > 1) ? $linkTitleSplit[1] : $linkedPost; + $postPart = explode('#', $linkedPost)[0]; // split away an eventual anchor part + $linkedFilename = fileNameForPost(sanitizeFilename($postPart)); $exists = file_exists($linkedFilename); $outHTML = str_replace("[[$fullLinkText]]", - pageLink($linkedPage, $linkText, ($exists? "" : " class=\"noexist\"")), $outHTML); + postLink($linkedPost, $linkText, ($exists? "" : " class=\"noexist\"")), $outHTML); } $outHTML = preg_replace("/\{\{(.*?)\}\}/", "\"\\1\"", $outHTML); @@ -202,22 +202,22 @@ function toHTML($inText) { } $action = isset($_REQUEST['action']) ? $_REQUEST['action'] : 'view'; -$newPage = ""; +$newPost = ""; $text = ""; $html = ""; $rss = ""; -$page = preg_match('@^/@', @$_SERVER["PATH_INFO"]) ? - urldecode(substr($_SERVER["PATH_INFO"], 1)) : urldecode(@$_REQUEST['page']); -$page = sanitizeFilename($page); +$post = preg_match('@^/@', @$_SERVER["PATH_INFO"]) ? + urldecode(substr($_SERVER["PATH_INFO"], 1)) : urldecode(@$_REQUEST['post']); +$post = sanitizeFilename($post); -if ($page != '') { - $filename = fileNameForPage($page); +if ($post != '') { + $filename = fileNameForPost($post); if ( file_exists($filename) ) { $text = file_get_contents($filename); } else { - $newPage = NULL; + $newPost = NULL; include('php/404.php'); die(); } @@ -226,12 +226,12 @@ if ($page != '') { } if ( $action === 'home') { - $pageNames = getAllPageNames(); + $postNames = getAllPostNames(); $filelist = array(); $sortBy = isset($_REQUEST['sortBy']) ? $_REQUEST['sortBy'] : 'name'; - foreach($pageNames as $page) { - $filelist[$page] = numForPage($page); + foreach($postNames as $post) { + $filelist[$post] = numForPost($post); } arsort($filelist, SORT_NUMERIC); @@ -250,23 +250,24 @@ if ( $action === 'home') { $html .= " \n"; - // Write end of the page + // Write end of the post $html .= "

Archived blog posts

\n"; $html .= "

Some blog posts have been archived because they're written out of frustration, are irrelevant or just aren't worth reading. You can still access the blog posts through these RSS feeds:

\n"; $html .= "