diff --git a/core.php b/core.php index d6fb708..9bfdae1 100644 --- a/core.php +++ b/core.php @@ -61,8 +61,49 @@ if($isloggedin) /////// Login System End /////// /////////////////////////////////////////////////////////////////////////////////////////// -//////////////////////////// Security and Consistency Measures //////////////////////////// +//////////////////////////////////////// Functions //////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////// + +/* + * @summary Converts a filesize into a human-readable string. + * @source http://php.net/manual/en/function.filesize.php#106569 + * @editor Starbeamrainbowlabs + * + * @param $bytes - The number of bytes to convert. + * @param $decimals - The number of decimal places to preserve. + */ +function human_filesize($bytes, $decimals = 2) +{ + $sz = ["B", "KB", "MB", "GB", "TB", "PB", "EB", "YB", "ZB"]; + $factor = floor((strlen($bytes) - 1) / 3); + return sprintf("%.{$decimals}f", $bytes / pow(1024, $factor)) . @$sz[$factor]; +} +/* + * @summary Calculates the time sincce a particular timestamp and returns a + * human-readable result. + * @source http://snippets.pro/snippet/137-php-convert-the-timestamp-to-human-readable-format/ + * + * @param $time - The timestamp to convert. + */ +function human_time_since($time) +{ + $timediff = time() - $time; + $tokens = array ( + 31536000 => 'year', + 2592000 => 'month', + 604800 => 'week', + 86400 => 'day', + 3600 => 'hour', + 60 => 'minute', + 1 => 'second' + ); + foreach ($tokens as $unit => $text) { + if ($timediff < $unit) continue; + $numberOfUnits = floor($timediff / $unit); + return $numberOfUnits.' '.$text.(($numberOfUnits>1)?'s':'').' ago'; + } +} + /* * @summary Gets a list of all the sub pagess of the current page. * @@ -131,6 +172,50 @@ function check_subpage_parents($pagename) check_subpage_parents($parent_pagename); } +/* + * @summary makes a path safe + * + * @details paths may only contain alphanumeric characters, spaces, underscores, and dashes + */ +function makepathsafe($string) +{ + return preg_replace("/[^0-9a-zA-Z\_\-\ \/]/i", "", $string); +} + +/* + * @summary Hides an email address from bots by adding random html entities. + * + * @returns The mangled email address. + */ +function hide_email($str) +{ + $hidden_email = ""; + for($i = 0; $i < strlen($str); $i++) + { + if($str[$i] == "@") + { + $hidden_email .= "&#" . ord("@") . ";"; + continue; + } + if(rand(0, 1) == 0) + $hidden_email .= $str[$i]; + else + $hidden_email .= "&#" . ord($str[$i]) . ";"; + } + + return $hidden_email; +} + +/////////////////////////////////////////////////////////////////////////////////////////// + +/////////////////////////////////////////////////////////////////////////////////////////// +//////////////////////////// Security and Consistency Measures //////////////////////////// +/////////////////////////////////////////////////////////////////////////////////////////// + +/* + * Sort out the pageindex. We create it if it doesn't exist, and load and parse + * it if it does. + */ if(!file_exists("./pageindex.json")) { // From http://in.php.net/manual/en/function.glob.php#106595 @@ -193,39 +278,6 @@ else { $pageindex = json_decode(file_get_contents("./pageindex.json")); } -/* - * @summary makes a path safe - * - * @details paths may only contain alphanumeric characters, spaces, underscores, and dashes - */ -function makepathsafe($string) -{ - return preg_replace("/[^0-9a-zA-Z\_\-\ \/]/i", "", $string); -} - -/* - * @summary Hides an email address from bots by adding random html entities. - * - * @returns The mangled email address. - */ -function hide_email($str) -{ - $hidden_email = ""; - for($i = 0; $i < strlen($str); $i++) - { - if($str[$i] == "@") - { - $hidden_email .= "&#" . ord("@") . ";"; - continue; - } - if(rand(0, 1) == 0) - $hidden_email .= $str[$i]; - else - $hidden_email .= "&#" . ord($str[$i]) . ";"; - } - - return $hidden_email; -} // Work around an Opera + Syntastic bug where there is no margin at the left hand side if there isn't a query string when accessing a .php file if(!isset($_GET["action"]) and !isset($_GET["page"])) @@ -288,8 +340,8 @@ class page_renderer

Powered by Pepperminty Wiki, which was built by Starbeamrainbowlabs. Send bugs to 'bugs at starbeamrainbowlabs dot com' or open an issue on github.

Your local friendly administrators are {admins-name-list}.

This wiki is managed by {admin-details-name}.

- {nav-bottom} + {navigation-bar-bottom} {all-pages-datalist}"; public static $minimal_content_template = "{content}
@@ -309,6 +361,7 @@ class page_renderer "{header-html}", "{navigation-bar}", + "{navigation-bar-bottom}", "{admin-details-name}", "{admin-details-email}", @@ -323,7 +376,8 @@ class page_renderer $settings->favicon, self::get_css_as_html(), - self::render_navigation_bar($settings->navlinks), + self::render_navigation_bar($settings->nav_links, $settings->nav_links_extra, "top"), + self::render_navigation_bar($settings->nav_links_bottom, [], "bottom"), $settings->admindetails["name"], $settings->admindetails["email"], @@ -368,19 +422,18 @@ class page_renderer public static $nav_divider = " | "; - public static function render_navigation_bar($nav_links) + /* + * @summary Function to render a navigation bar from an array of links. See + * $settings->nav_links for format information. + * + * @param $nav_links - The links to add to the navigation bar. + * @param $nav_links_extra - The extra nav links to add to the "More..." + * menu. + */ + public static function render_navigation_bar($nav_links, $nav_links_extra, $class = "") { global $settings, $user, $isloggedin, $page; - $result = "