]> jfr.im git - irc/unrealircd/unrealircd-webpanel.git/blobdiff - misc/strings.php
Fix setting zlines on idents, reported by Jellis
[irc/unrealircd/unrealircd-webpanel.git] / misc / strings.php
index c6b1180b721fe52772e3da8883f0edf546e7be38..f5d576753ee66e197be5aac0deb49d41afa7f679 100644 (file)
@@ -1,5 +1,10 @@
 <?php
 
+function to_slug($str)
+{
+       return str_replace(['-', ' '], '_', strtolower($str));
+}
+
 /** Splits up a string by a space
  * (chr 32)
  *
@@ -65,7 +70,13 @@ function show_nick_only($str)
        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();
@@ -87,6 +98,13 @@ function how_long_ago($timestamp)
        }
 }
 
+/**
+ * Uses system time.
+ * Returns:
+ *     - evening
+ *  - morning
+ *  - afternoon
+ */
 function time_of_day()
 {
        $timeofday = "day"; // in case something went wrong? lol
@@ -99,4 +117,94 @@ function time_of_day()
                $timeofday = "afternoon";
 
        return $timeofday;
-}
\ No newline at end of file
+}
+
+
+/**
+ * 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);
+}