has($hash)) { Storage::disk('textures')->move($path, $hash); } return $hash; } } /** * Generate random string * * @param int $length * @param bool $special_chars * @return string */ public static function generateRndString($length, $special_chars = true) { $chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; if ($special_chars) $chars .= "!@#$%^&*()-_ []{}<>~`+=,.;:/?|"; $rnd_string = ''; for ($i = 0; $i < $length; $i++) { $rnd_string .= $chars[mt_rand(0, strlen($chars) - 1)]; } return $rnd_string; } public static function getTimeFormatted($timestamp = 0) { return ($timestamp == 0) ? date('Y-m-d H:i:s') : date('Y-m-d H:i:s', $timestamp); } public static function getNameOrEmail(\App\Models\User $user) { return ($user->getNickName() == '') ? $user->email : $user->getNickName(); } public static function getAvatarFname(\App\Models\User $user) { $fname = base64_encode($user->email).".png"; if (\Option::get('avatar_query_string')) { $fname .= '?v='.$user->getAvatarId(); } return $fname; } /** * Generate omitted string * * @param string $str * @param int $length * @param boolean $append * @return string */ public static function getStringOmitted($str, $length, $append = true) { $str = trim($str); $strlength = strlen($str); if ($length == 0 || $length >= $strlength) { return $str; } elseif ($length < 0) { $length = $strlength + $length; if ($length < 0) { $length = $strlength; } } if (function_exists('mb_substr')) { $newstr = mb_substr($str, 0, $length, 'utf-8'); } elseif (function_exists('iconv_substr')) { $newstr = iconv_substr($str, 0, $length, 'utf-8'); } else { $newstr = substr($str, 0, $length); } if ($append && $str != $newstr) { $newstr .= '...'; } return $newstr; } /** * Replace content of string according to given rules * * @param string $str * @param array $rules * @return string */ public static function getStringReplaced($str, $rules) { foreach ($rules as $search => $replace) { $str = str_replace($search, $replace, $str); } return $str; } }