format($date); } return date($format, $date); } /** * Set a default value for $str in case $str is empty. * * @param string $str * @param string $defaultValue * @return string The default value */ public static function def(string $str, string $defaultValue = ''): string { if (trim($str) === '') { $str = $defaultValue; } return $str; } /** * Escapes a string to be used safely in a JSON string. * * @param string $str * @return string The escaped string */ public static function escape(string $str): string { $str = preg_replace('/[\r\n]+/', '\n', trim($str)); $str = json_encode(array('temp' => $str), JSON_UNESCAPED_SLASHES); $str = Str::stripStart($str, '{"temp":"'); $str = Str::stripEnd($str, '"}'); return $str; } /** * Find the URL of the first image within rendered HTML markup. * * @param string $str * @return string The URL of the first image or an empty string */ public static function findFirstImage(string $str): string { if (!$str) { return ''; } preg_match('/]+src="([^"]+)"/is', $str, $matches); if (!empty($matches[1])) { return $matches[1]; } return ''; } /** * Find the first paragraph in rendered HTML and return its inner HTML. * * @param string $str * @return string The inner HTML of the first paragraph or an empty string */ public static function findFirstParagraph(string $str): string { if (!$str) { return ''; } // First remove any paragraph only containing an image. $str = preg_replace('/

\s*<\/p>/is', '', $str); preg_match('/]*>(.*?)<\/p>/is', $str, $matches); if (!empty($matches[1])) { return $matches[1]; } return ''; } /** * Parse a markdown string. Optionally skip parsing in case $str is a single line string. * * @param string $str * @param bool $multilineOnly * @return string The parsed string */ public static function markdown(string $str, $multilineOnly = false): string { if (strpos($str, "\n") === false && $multilineOnly) { return $str; } $str = MarkdownExtra::defaultTransform($str); return preg_replace_callback('/\(.*?)\<\/h\1\>/i', function ($matches) { $id = self::sanitize(self::stripTags($matches[2]), true, 100); return "{$matches[2]}"; }, $str); } /** * Perform a regex match. * * @param string $str * @param string $regex * @return int 1 or 0 */ public static function match(string $str, string $regex = ''): int { return preg_match($regex, $str); } /** * Search and replace by regex. * * @param string $str * @param string $regex * @param string $replace * @return string The processed string */ public static function replace(string $str, string $regex = '', string $replace = ''): string { return preg_replace($regex, $replace, $str); } /** * Cleans up a string to be used as URL, directory or file name. * The returned string constists of the following characters: "a-z", "0-9", "-" and optional dots ".". * That means, this method is safe to be used with filenames as well, since it keeps by default the dots as suffix separators. * * Note: To produce fully safe prefixes and directory names, * possible dots should be removed by setting $removeDots = true. * * @param string $str * @param bool $removeDots * @param int $maxChars * @return string The sanitized string */ public static function sanitize(string $str, $removeDots = false, $maxChars = 100): string { if (strlen($str) === 0) { return ''; } // If dots should be removed from $str, replace them with '-', since URLify::filter() only removes them fully without replacing. if ($removeDots) { $str = str_replace('.', '-', $str); } // Convert slashes separately to avoid issues with regex in URLify. $str = str_replace('/', '-', $str); // Convert dashes to simple hyphen. $str = str_replace(array('—', '–'), '-', $str); // Configure URLify. // Add non-word chars and reset the remove list. // Note: $maps gets directly manipulated without using URLify::add_chars(). // Using the add_chars() method would extend $maps every time, Str::sanitize() gets called. // Adding a new array to $maps using a key avoids that and just overwrites that same array after the first call without adding new elements. URLify::$maps['nonWordChars'] = array('=' => '-', '&' => '-and-', '+' => '-plus-', '@' => '-at-', '|' => '-', '*' => '-x-'); URLify::$remove_list = array(); // Since all possible dots got removed already above (if $removeDots is true), // $str should be filtered as filename to keep dots if they are still in $str and $removeDots is false. return URLify::filter($str, $maxChars, '', true); } /** * Shortens a string keeping full words. Note that this method also first strips all tags from the given string. * * @param string $str * @param int $maxChars * @param string $ellipsis * @return string The shortened string */ public static function shorten(string $str, $maxChars, string $ellipsis = ' ...'): string { if (strlen($str) === 0) { return ''; } $str = Str::stripTags($str); $str = preg_replace('/[\n\r]+/s', ' ', $str); // Shorten $text to maximal characters (full words). if (strlen($str) > $maxChars) { // Cut $str to $maxChars +1. // Note that it has to be +1 to be able to catch the edge case, // where $maxChars is exactly an end of a word. +1 would than // be a space. $str = substr($str, 0, $maxChars + 1); // Find last space and get position. $pos = strrpos($str, ' '); // If there is no space left, use the original $maxChars (without +1) as $pos. if (!$pos) { $pos = $maxChars; } $str = substr($str, 0, $pos) . $ellipsis; } return trim($str); } /** * Creates a slug for save diretory names, ids or similar from a given string. * * In case the sanitized string is empty or the string is shorter than 6 chars while the * input string is longer than 12 chars, the string is replaced with a md5 hash shortened to 16 chars. * * @param string $str * @param bool $removeDots * @param int $maxChars * @return string the slug */ public static function slug(string $str, $removeDots = false, $maxChars = 100): string { if (strlen($str) === 0) { return ''; } $slug = self::sanitize($str, $removeDots, $maxChars); if (strlen($slug) === 0 || (strlen($slug) < 6 && strlen($str) > 12)) { $slug = substr(md5($str), 0, 16); } return $slug; } /** * Strip substring from end of string. * * @param string $str * @param string $end * @return string The processed string */ public static function stripEnd(string $str, string $end = ''): string { return preg_replace('/' . preg_quote($end, '/') . '$/', '', $str); } /** * Strip substring from start of string. * * @param string $str * @param string $start * @return string The processed string */ public static function stripStart(string $str, string $start = ''): string { return preg_replace('/^' . preg_quote($start, '/') . '/', '', $str); } /** * Removes all HTML and Markdown (!) tags. * * @param string $str * @return string The clean string */ public static function stripTags(string $str): string { return trim(strip_tags(Str::markdown(strip_tags($str)))); } } __halt_compiler();----SIGNATURE:----I+EFpkJBn4qEFrf1cf0/A7A3hreY+vzuyIzcW35vfyXILCMPnozKK9mAaxl9LesYePw5Xh7gtdI0vFZNRPdjjpIA8/tFW1WPZmc/hxx0SKJPrF92Q8otKHdKboEHXGf3lTCgr4nK6NX3hgB3HwezLklX6CYT11Nr0LHC8c7PY9gYaJv4qeKcLsxtQeUvWgXSp293vIpkyJKYqyT3pCsD1nu9sdBhPOtqQ2Fd5ApwudXc6a+7fdKGuZMgLwOQG4sdQUEwTpd/R7Ly+7eSLwJTN24mQBl9i4cooNTXDr1+jnjV/yHOzvWDLOU8Nzoc9ih0f6gy7CCz8uXJuzmQ2GFKeacneNzXYVwk8JZ+7O7Wx0kSLm1ol/+idJ0iiJO0kHIRnhmA/VHGp9pbFeGAWA6Cp7BF44AOMNSKBc1DCZyXdXBwgOB28x+yFBvV3ucr172Rk9Vwk3P02wKjuyCRd9j9gSPXmStIFmn8jkDnmRnsASitUxM27IWz5NN7ojGDY4afoKEKGhEoy4G2EM5kJFpPgdkfGBWH25DY9J2RrjWjvXnz3DyxbkWkGXQ2H7+6eqx7CTUeIHHVZqg+ZqtXms85UjALWDduPwQOpnxDaOskJ01hUr5sxVJAKRH/Ofio5NCzARDBS0BXYH46mYfRaki8l6D1zTX4MDnqHvp+izAv2EA=----ATTACHMENT:----MzcwMzg1NzM5MDQ3Mjc3MyA1NjkyNzMyMzc4OTM3ODU5IDQ3MTE2OTQzNzUyNzQ2