<?php
+function to_slug($str)
+{
+ return str_replace(['-', ' '], '_', strtolower($str));
+}
+
/** Splits up a string by a space
* (chr 32)
*
return $str;
}
-
+/**
+ * Figures out how long ago a given time was
+ * returns string example:
+ * - "32 minutes ago"
+ * - "5 hours ago"
+ * - "12 seconds ago"
+ */
function how_long_ago($timestamp)
{
$now = time();
$diff = $now - strtotime($timestamp);
-
$units = array(
31536000 => 'year',
2592000 => 'month',
$numberOfUnits = floor($diff / $unit);
return $numberOfUnits.' '.$text.(($numberOfUnits>1)?'s':'').' ago';
}
-}
\ No newline at end of file
+}
+
+/**
+ * Uses system time.
+ * Returns:
+ * - evening
+ * - morning
+ * - afternoon
+ */
+function time_of_day()
+{
+ $timeofday = "day"; // in case something went wrong? lol
+ $hour = date("H");
+ if ($hour >= 18 || $hour < 4)
+ $timeofday = "evening";
+ else if ($hour >= 4 && $hour < 12)
+ $timeofday = "morning";
+ else if ($hour >= 12 && $hour < 18)
+ $timeofday = "afternoon";
+
+ return $timeofday;
+}
+
+
+/**
+ * Concatenate a string to a string
+ */
+function strcat(&$targ,$string) : void
+{ $targ .= $string; }
+
+
+/**
+ * Concatenate a string to a string and limits the string to a certain length
+ */
+function strlcat(&$targ,$string,$size) : void
+{
+ strcat($targ,$string);
+ $targ = mb_substr($targ,0,$size);
+}
+
+
+/**
+ * Prefixes a string to a string
+ */
+function strprefix(&$targ,$string) : void
+{ $targ = $string.$targ; }
+
+
+/**
+ * Prefixes a string to a string and limits the string to a certain length
+ */
+function strlprefix(&$targ,$string,$size) : void
+{
+ if (sizeof($targ) >= $size)
+ return;
+
+ strprefix($targ,$string);
+ $targ = mb_substr($targ,0,$size);
+}
+
+/** Checks if the token provided is a bad pointer, by reference
+ * Returns Bool value true if it IS bad
+ *
+ * Syntax:
+ * BadPtr($variable)
+ *
+ * Returns:
+ * @
+*/
+function BadPtr(&$tok)
+{
+ if (!isset($tok) || empty($tok) || !$tok || strlen($tok) == 0)
+ return true;
+ return false;
+}
+
+/** This function takes a string, tokenizes
+ * it by a space (chr 32), removes the first
+ * word/token, and returns the result.
+ * Mostly used for string manipulation around
+ * the source.
+ *
+ * Syntax:
+ * rparv(String $sentence)
+ *
+ * Returns:
+ * string|false
+ */
+function rparv($string)
+{
+ $parv = split($string);
+ $first = strlen($parv[0]) + 1;
+ $string = substr($string, $first);
+ if ($string)
+ return $string;
+ return false;
+}
+
+/* Taken from https://www.aviran.org/stripremove-irc-client-control-characters/
+ * We may want to re-base it off our UnrealIRCd's one though.
+ */
+function StripControlCharacters($text)
+{
+ $controlCodes = array(
+ '/(\x03(?:\d{1,2}(?:,\d{1,2})?)?)/', // Color code
+ '/\x02/', // Bold
+ '/\x0F/', // Escaped
+ '/\x16/', // Italic
+ '/\x1F/' // Underline
+ );
+ return preg_replace($controlCodes,'',$text);
+}