public static function url($string) { require_once BASE_DIR . LIBRARY_DIR . 'php/text/transliteration.php'; $url = mb_strtolower($string); $url = \Library\Php\Text\Transliteration::transform($url); $url = str_replace(" ", "-", $url); $url = str_replace("/", "-", $url); $url = str_replace("\\", "-", $url); $url = str_replace("\"", "-", $url); $url = str_replace("\\'", "-", $url); $url = str_replace("„", "-", $url); $url = str_replace("“", "-", $url); $url = str_replace("&", "-", $url); $url = str_replace("%", "-", $url); $url = str_replace("`", "-", $url); $url = str_replace("!", "-", $url); $url = str_replace("@", "-", $url); $url = str_replace("#", "-", $url); $url = str_replace("\$", "-", $url); $url = str_replace("^", "-", $url); $url = str_replace("*", "-", $url); $url = str_replace("(", "-", $url); $url = str_replace(")", "-", $url); $url = str_replace("{", "-", $url); $url = str_replace("}", "-", $url); $url = str_replace("[", "-", $url); $url = str_replace("]", "-", $url); $url = str_replace("|", "-", $url); $url = str_replace("~", "-", $url); return $url; }
public static function newUrl($language, $title) { $url = mb_strtolower($title); $url = \Library\Php\Text\Transliteration::transform($url); $url = str_replace(" ", "-", $url); $url = str_replace("/", "-", $url); $url = str_replace("\\", "-", $url); $url = str_replace("\"", "-", $url); $url = str_replace("\\'", "-", $url); $url = str_replace("„", "-", $url); $url = str_replace("“", "-", $url); $url = str_replace("&", "-", $url); $url = str_replace("%", "-", $url); $url = str_replace("`", "-", $url); $url = str_replace("!", "-", $url); $url = str_replace("@", "-", $url); $url = str_replace("#", "-", $url); $url = str_replace("\$", "-", $url); $url = str_replace("^", "-", $url); $url = str_replace("*", "-", $url); $url = str_replace("(", "-", $url); $url = str_replace(")", "-", $url); $url = str_replace("{", "-", $url); $url = str_replace("}", "-", $url); $url = str_replace("[", "-", $url); $url = str_replace("]", "-", $url); $url = str_replace("|", "-", $url); $url = str_replace("~", "-", $url); $sql = "select url from `" . DB_PREF . "zone_parameter` where `language_id` = '" . mysql_real_escape_string($language) . "' "; $rs = mysql_query($sql); if ($rs) { $urls = array(); while ($lock = mysql_fetch_assoc($rs)) { $urls[$lock['url']] = 1; } $i = ''; if (isset($urls[$url])) { while (isset($urls[$url . $i])) { if ($i == '') { $i = 1; } else { $i++; } } } return $url . $i; } else { trigger_error("Can't get all urls " . $sql . " "); } }
/** * @param string $file required file name * @param string $dest_dir directory where new file will be placed * @return string new (or the same) file name that don't colide with existing files in specified directory */ public static function genUnocupiedName($file, $dest_dir) { require_once LIBRARY_DIR . 'php/text/transliteration.php'; $new_name = basename($file); $ext_pos = strrpos($file, "."); $new_name = substr($new_name, 0, $ext_pos); $new_extension = substr($file, $ext_pos, strlen($file)); $new_name = \Library\Php\Text\Transliteration::transform($new_name); $new_name = utf8_decode($new_name); $spec = array("'", "%", "?", "-", "+", " ", "<", ">", "(", ")", "/", "\\", "&", ".", ",", "!", ":", "\"", "?", "|"); $new_name = str_replace($spec, "_", $new_name); if ($new_name == "") { $new_name = "file_"; } if (file_exists($dest_dir . $new_name . $new_extension)) { $i = 1; while (file_exists($dest_dir . $new_name . '_' . $i . $new_extension)) { $i++; } $new_name = $new_name . '_' . $i; } $new_name .= $new_extension; return $new_name; }
public static function makeUrl($url, $allowed_id = null) { $url = mb_strtolower($url); $url = \Library\Php\Text\Transliteration::transform($url); $url = str_replace(" ", "-", $url); $url = str_replace("/", "-", $url); $url = str_replace("\\", "-", $url); $url = str_replace("\"", "-", $url); $url = str_replace("\\'", "-", $url); $url = str_replace("„", "-", $url); $url = str_replace("“", "-", $url); $url = str_replace("&", "-", $url); $url = str_replace("%", "-", $url); $url = str_replace("`", "-", $url); $url = str_replace("!", "-", $url); $url = str_replace("@", "-", $url); $url = str_replace("#", "-", $url); $url = str_replace("\$", "-", $url); $url = str_replace("^", "-", $url); $url = str_replace("*", "-", $url); $url = str_replace("(", "-", $url); $url = str_replace(")", "-", $url); $url = str_replace("{", "-", $url); $url = str_replace("}", "-", $url); $url = str_replace("[", "-", $url); $url = str_replace("]", "-", $url); $url = str_replace("|", "-", $url); $url = str_replace("~", "-", $url); $url = str_replace("?", "-", $url); $url = str_replace(":", "", $url); $url = str_replace(";", "", $url); while ($url != str_replace("--", "-", $url)) { $url = str_replace("--", "-", $url); } if (Db::availableUrl($url, $allowed_id)) { return $url; } $i = 1; while (!Db::availableUrl($url . '-' . $i, $allowed_id)) { $i++; } return $url . '-' . $i; }
/** * * Create unique URL * @param string $url * @param int $allowed_id */ public static function makeUrl($url, $allowed_id = null) { require_once BASE_DIR . LIBRARY_DIR . 'php/text/transliteration.php'; if ($url == '') { $url = 'page'; } $url = mb_strtolower($url); $url = \Library\Php\Text\Transliteration::transform($url); $url = str_replace(" ", "-", $url); $url = str_replace("/", "-", $url); $url = str_replace("\\", "-", $url); $url = str_replace("\"", "-", $url); $url = str_replace("\\'", "-", $url); $url = str_replace("„", "-", $url); $url = str_replace("“", "-", $url); $url = str_replace("&", "-", $url); $url = str_replace("%", "-", $url); $url = str_replace("`", "-", $url); $url = str_replace("!", "-", $url); $url = str_replace("@", "-", $url); $url = str_replace("#", "-", $url); $url = str_replace("\$", "-", $url); $url = str_replace("^", "-", $url); $url = str_replace("*", "-", $url); $url = str_replace("(", "-", $url); $url = str_replace(")", "-", $url); $url = str_replace("{", "-", $url); $url = str_replace("}", "-", $url); $url = str_replace("[", "-", $url); $url = str_replace("]", "-", $url); $url = str_replace("|", "-", $url); $url = str_replace("~", "-", $url); $url = str_replace(".", "-", $url); $url = str_replace("'", "", $url); $url = str_replace("?", "", $url); $url = str_replace(":", "", $url); $url = str_replace(";", "", $url); if ($url == '') { $url = '-'; } while ($url != str_replace("--", "-", $url)) { $url = str_replace("--", "-", $url); } if (self::availableUrl($url, $allowed_id)) { return $url; } $i = 1; while (!self::availableUrl($url . '-' . $i, $allowed_id)) { $i++; } return $url . '-' . $i; }