123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161 |
- <?php
- /**
- *
- * Cube Framework $Id$ CXDHlInlrvmyqFCA1iYWVGyijIcOwxeEZp6enK5w9rc=
- *
- * @link http://codecu.be/framework
- * @copyright Copyright (c) 2015 CodeCube SRL
- * @license http://codecu.be/framework/license Commercial License
- *
- * @version 1.5
- */
- /**
- * url view helper
- */
- namespace Cube\View\Helper;
- use Cube\Controller\Front;
- class Url extends AbstractHelper
- {
- /**
- *
- * character map
- *
- * @var array
- */
- protected static $_charMap = array(
- // Latin
- 'À' => 'A', 'Á' => 'A', 'Â' => 'A', 'Ã' => 'A', 'Ä' => 'A', 'Å' => 'A', 'Æ' => 'AE', 'Ç' => 'C',
- 'È' => 'E', 'É' => 'E', 'Ê' => 'E', 'Ë' => 'E', 'Ì' => 'I', 'Í' => 'I', 'Î' => 'I', 'Ï' => 'I',
- 'Ð' => 'D', 'Ñ' => 'N', 'Ò' => 'O', 'Ó' => 'O', 'Ô' => 'O', 'Õ' => 'O', 'Ö' => 'O', 'Ő' => 'O',
- 'Ø' => 'O', 'Ù' => 'U', 'Ú' => 'U', 'Û' => 'U', 'Ü' => 'U', 'Ű' => 'U', 'Ý' => 'Y', 'Þ' => 'TH',
- 'ß' => 'ss',
- 'à' => 'a', 'á' => 'a', 'â' => 'a', 'ã' => 'a', 'ä' => 'a', 'å' => 'a', 'æ' => 'ae', 'ç' => 'c',
- 'è' => 'e', 'é' => 'e', 'ê' => 'e', 'ë' => 'e', 'ì' => 'i', 'í' => 'i', 'î' => 'i', 'ï' => 'i',
- 'ð' => 'd', 'ñ' => 'n', 'ò' => 'o', 'ó' => 'o', 'ô' => 'o', 'õ' => 'o', 'ö' => 'o', 'ő' => 'o',
- 'ø' => 'o', 'ù' => 'u', 'ú' => 'u', 'û' => 'u', 'ü' => 'u', 'ű' => 'u', 'ý' => 'y', 'þ' => 'th',
- 'ÿ' => 'y',
- // Latin symbols
- '©' => '(c)',
- // Greek
- 'Α' => 'A', 'Β' => 'B', 'Γ' => 'G', 'Δ' => 'D', 'Ε' => 'E', 'Ζ' => 'Z', 'Η' => 'H', 'Θ' => '8',
- 'Ι' => 'I', 'Κ' => 'K', 'Λ' => 'L', 'Μ' => 'M', 'Ν' => 'N', 'Ξ' => '3', 'Ο' => 'O', 'Π' => 'P',
- 'Ρ' => 'R', 'Σ' => 'S', 'Τ' => 'T', 'Υ' => 'Y', 'Φ' => 'F', 'Χ' => 'X', 'Ψ' => 'PS', 'Ω' => 'W',
- 'Ά' => 'A', 'Έ' => 'E', 'Ί' => 'I', 'Ό' => 'O', 'Ύ' => 'Y', 'Ή' => 'H', 'Ώ' => 'W', 'Ϊ' => 'I',
- 'Ϋ' => 'Y',
- 'α' => 'a', 'β' => 'b', 'γ' => 'g', 'δ' => 'd', 'ε' => 'e', 'ζ' => 'z', 'η' => 'h', 'θ' => '8',
- 'ι' => 'i', 'κ' => 'k', 'λ' => 'l', 'μ' => 'm', 'ν' => 'n', 'ξ' => '3', 'ο' => 'o', 'π' => 'p',
- 'ρ' => 'r', 'σ' => 's', 'τ' => 't', 'υ' => 'y', 'φ' => 'f', 'χ' => 'x', 'ψ' => 'ps', 'ω' => 'w',
- 'ά' => 'a', 'έ' => 'e', 'ί' => 'i', 'ό' => 'o', 'ύ' => 'y', 'ή' => 'h', 'ώ' => 'w', 'ς' => 's',
- 'ϊ' => 'i', 'ΰ' => 'y', 'ϋ' => 'y', 'ΐ' => 'i',
- // Turkish
- 'Ş' => 'S', 'İ' => 'I', 'Ğ' => 'G',
- 'ş' => 's', 'ı' => 'i', 'ğ' => 'g',
- // Romanian
- 'Ă' => 'A', 'ă' => 'a',
- 'Ș' => 's', 'ș' => 's', 'Ț' => 'T', 'ț' => 't',
- // Russian
- 'А' => 'A', 'Б' => 'B', 'В' => 'V', 'Г' => 'G', 'Д' => 'D', 'Е' => 'E', 'Ё' => 'Yo', 'Ж' => 'Zh',
- 'З' => 'Z', 'И' => 'I', 'Й' => 'J', 'К' => 'K', 'Л' => 'L', 'М' => 'M', 'Н' => 'N', 'О' => 'O',
- 'П' => 'P', 'Р' => 'R', 'С' => 'S', 'Т' => 'T', 'У' => 'U', 'Ф' => 'F', 'Х' => 'H', 'Ц' => 'C',
- 'Ч' => 'Ch', 'Ш' => 'Sh', 'Щ' => 'Sh', 'Ъ' => '', 'Ы' => 'Y', 'Ь' => '', 'Э' => 'E', 'Ю' => 'Yu',
- 'Я' => 'Ya',
- 'а' => 'a', 'б' => 'b', 'в' => 'v', 'г' => 'g', 'д' => 'd', 'е' => 'e', 'ё' => 'yo', 'ж' => 'zh',
- 'з' => 'z', 'и' => 'i', 'й' => 'j', 'к' => 'k', 'л' => 'l', 'м' => 'm', 'н' => 'n', 'о' => 'o',
- 'п' => 'p', 'р' => 'r', 'с' => 's', 'т' => 't', 'у' => 'u', 'ф' => 'f', 'х' => 'h', 'ц' => 'c',
- 'ч' => 'ch', 'ш' => 'sh', 'щ' => 'sh', 'ъ' => '', 'ы' => 'y', 'ь' => '', 'э' => 'e', 'ю' => 'yu',
- 'я' => 'ya',
- // Ukrainian
- 'Є' => 'Ye', 'І' => 'I', 'Ї' => 'Yi', 'Ґ' => 'G',
- 'є' => 'ye', 'і' => 'i', 'ї' => 'yi', 'ґ' => 'g',
- // Czech
- 'Č' => 'C', 'Ď' => 'D', 'Ě' => 'E', 'Ň' => 'N', 'Ř' => 'R', 'Š' => 'S', 'Ť' => 'T', 'Ů' => 'U',
- 'Ž' => 'Z',
- 'č' => 'c', 'ď' => 'd', 'ě' => 'e', 'ň' => 'n', 'ř' => 'r', 'š' => 's', 'ť' => 't', 'ů' => 'u',
- 'ž' => 'z',
- // Polish
- 'Ą' => 'A', 'Ć' => 'C', 'Ę' => 'e', 'Ł' => 'L', 'Ń' => 'N', 'Ś' => 'S', 'Ź' => 'Z',
- 'Ż' => 'Z',
- 'ą' => 'a', 'ć' => 'c', 'ę' => 'e', 'ł' => 'l', 'ń' => 'n', 'ś' => 's', 'ź' => 'z',
- 'ż' => 'z',
- // Latvian
- 'Ā' => 'A', 'Ē' => 'E', 'Ģ' => 'G', 'Ī' => 'i', 'Ķ' => 'k', 'Ļ' => 'L', 'Ņ' => 'N',
- 'Ū' => 'u',
- 'ā' => 'a', 'ē' => 'e', 'ģ' => 'g', 'ī' => 'i', 'ķ' => 'k', 'ļ' => 'l', 'ņ' => 'n',
- 'ū' => 'u',
- // Arabic
- 'أ' => 'a', 'ب' => 'b', 'ت' => 't', 'ث' => 'th', 'ج' => 'g', 'ح' => 'h', 'خ' => 'kh', 'د' => 'd',
- 'ذ' => 'th', 'ر' => 'r', 'ز' => 'z', 'س' => 's', 'ش' => 'sh', 'ص' => 's', 'ض' => 'd', 'ط' => 't',
- 'ظ' => 'th', 'ع' => 'aa', 'غ' => 'gh', 'ف' => 'f', 'ق' => 'k', 'ك' => 'k', 'ل' => 'l', 'م' => 'm',
- 'ن' => 'n', 'ه' => 'h', 'و' => 'o', 'ي' => 'y'
- );
- /**
- *
- * create an url based on a set of params and the router object
- *
- * @param string|array $params a string or an array of params
- * @param string $name the name of the specific route to use
- * @param bool $addGetParams whether to attach params resulted from a previous get operation to the url
- * @param array $skipParams an array of params to be omitted when constructing the url
- * @param bool $addBaseUrl flag to add the base url param to the assembled route
- * @param bool $cleanString if true, will clean values of get variables (only if params is an array)
- *
- * @return string the url of the link href attribute
- */
- public function url($params, $name = null, $addGetParams = false, array $skipParams = null, $addBaseUrl = true, $cleanString = true)
- {
- $router = Front::getInstance()->getRouter();
- if (is_array($params) &&
- $cleanString === true
- ) {
- foreach ($params as $key => $value) {
- $params[$key] = self::cleanString($value);
- }
- }
- return $router->assemble($params, $name, $addBaseUrl, $addGetParams, $skipParams);
- }
- /**
- *
- * formats a string for url display purposes
- *
- * @param string $string
- * @param array $replace
- * @param string $delimiter
- *
- * @return string|null the formatted string or null if the input is not a string
- */
- public static function cleanString($string, $replace = array(), $delimiter = '-')
- {
- if (!is_string($string)) {
- return $string;
- }
- if (!empty($replace)) {
- $string = str_replace((array)$replace, ' ', $string);
- }
- $string = str_ireplace(
- array('&', ''', '"', '<', '>', ' '), array('&', "'", '"', '<', '>', ' '), $string);
- $string = str_replace(array_keys(self::$_charMap), self::$_charMap, $string);
- //modify by yubin
- //$clean = @iconv('UTF-8', 'ASCII//TRANSLIT', $string);
- $clean = $string;
- $clean = preg_replace("/[^a-zA-Z0-9\/\_|+ -]/", '', $clean);
- $clean = strtolower(trim($clean));
- $clean = preg_replace("/[\/|+ -]+/", $delimiter, $clean);
- return $clean;
- }
- }
|