You are here

function __gotwo_mangle_src in Go - url redirects 5

Mangle the input for url friendlyness. Based on pathauto_cleanstring from pathauto.module

1 call to __gotwo_mangle_src()
gotwo_get in ./gotwo.module
Return the GO object url for a given link

File

./gotwo.module, line 276
Module that provides easy to use redirection links. A redirection link would be like: http://examples.org/go/a_label http://examples.org/go/123546 http://examples.org/go/or/like/this

Code

function __gotwo_mangle_src($string) {
  static $translations = array(
    'À' => 'A',
    'Á' => 'A',
    'Â' => 'A',
    'Ã' => 'A',
    'Ä' => 'A',
    'Å' => 'A',
    'Ā' => 'A',
    'Ą' => 'A',
    'Ă' => 'A',
    'à' => 'a',
    'á' => 'a',
    'â' => 'a',
    'ã' => 'a',
    'ä' => 'a',
    'å' => 'a',
    'ā' => 'a',
    'ą' => 'a',
    'ă' => 'a',
    'Æ' => 'Ae',
    'æ' => 'ae',
    'Ç' => 'C',
    'Ć' => 'C',
    'Č' => 'C',
    'Ĉ' => 'C',
    'Ċ' => 'C',
    'ç' => 'c',
    'ć' => 'c',
    'č' => 'c',
    'ĉ' => 'c',
    'ċ' => 'c',
    'Ď' => 'D',
    'Đ' => 'D',
    'Ð' => 'D',
    'ď' => 'd',
    'đ' => 'd',
    'ð' => 'd',
    'È' => 'E',
    'É' => 'E',
    'Ê' => 'E',
    'Ë' => 'E',
    'Ē' => 'E',
    'Ę' => 'E',
    'Ě' => 'E',
    'Ĕ' => 'E',
    'Ė' => 'E',
    'è' => 'e',
    'é' => 'e',
    'ê' => 'e',
    'ë' => 'e',
    'ē' => 'e',
    'ę' => 'e',
    'ě' => 'e',
    'ĕ' => 'e',
    'ė' => 'e',
    'ƒ' => 'f',
    'Ĝ' => 'G',
    'Ğ' => 'G',
    'Ġ' => 'G',
    'Ģ' => 'G',
    'ĝ' => 'g',
    'ğ' => 'g',
    'ġ' => 'g',
    'ģ' => 'g',
    'Ĥ' => 'H',
    'Ħ' => 'H',
    'ĥ' => 'h',
    'ħ' => 'h',
    'Ì' => 'I',
    'Í' => 'I',
    'Î' => 'I',
    'Ï' => 'I',
    'Ī' => 'I',
    'Ĩ' => 'I',
    'Ĭ' => 'I',
    'Į' => 'I',
    'İ' => 'I',
    'ì' => 'i',
    'í' => 'i',
    'î' => 'i',
    'ï' => 'i',
    'ī' => 'i',
    'ĩ' => 'i',
    'ĭ' => 'i',
    'į' => 'i',
    'ı' => 'i',
    'IJ' => 'Ij',
    'ij' => 'ij',
    'Ĵ' => 'J',
    'ĵ' => 'j',
    'Ķ' => 'K',
    'ķ' => 'k',
    'ĸ' => 'k',
    'Ł' => 'L',
    'Ľ' => 'L',
    'Ĺ' => 'L',
    'Ļ' => 'L',
    'Ŀ' => 'L',
    'ł' => 'l',
    'ľ' => 'l',
    'ĺ' => 'l',
    'ļ' => 'l',
    'ŀ' => 'l',
    'Ñ' => 'N',
    'Ń' => 'N',
    'Ň' => 'N',
    'Ņ' => 'N',
    'Ŋ' => 'N',
    'ñ' => 'n',
    'ń' => 'n',
    'ň' => 'n',
    'ņ' => 'n',
    'ʼn' => 'n',
    'ŋ' => 'n',
    'Ò' => 'O',
    'Ó' => 'O',
    'Ô' => 'O',
    'Õ' => 'O',
    'Ö' => 'O',
    'Ø' => 'O',
    'Ō' => 'O',
    'Ő' => 'O',
    'Ŏ' => 'O',
    'ò' => 'o',
    'ó' => 'o',
    'ô' => 'o',
    'õ' => 'o',
    'ö' => 'o',
    'ø' => 'o',
    'ō' => 'o',
    'ő' => 'o',
    'ŏ' => 'o',
    'Œ' => 'Oe',
    'œ' => 'oe',
    'Ŕ' => 'R',
    'Ř' => 'R',
    'Ŗ' => 'R',
    'ŕ' => 'r',
    'ř' => 'r',
    'ŗ' => 'r',
    'Ś' => 'S',
    'Š' => 'S',
    'Ş' => 'S',
    'Ŝ' => 'S',
    'Ș' => 'S',
    'Ť' => 'T',
    'Ţ' => 'T',
    'Ŧ' => 'T',
    'Ț' => 'T',
    'Þ' => 'T',
    'þ' => 't',
    'Ù' => 'U',
    'Ú' => 'U',
    'Û' => 'U',
    'Ü' => 'U',
    'Ū' => 'U',
    'Ů' => 'U',
    'Ű' => 'U',
    'Ŭ' => 'U',
    'Ũ' => 'U',
    'Ų' => 'U',
    'ú' => 'u',
    'û' => 'u',
    'ü' => 'u',
    'ū' => 'u',
    'ů' => 'u',
    'ű' => 'u',
    'ŭ' => 'u',
    'ũ' => 'u',
    'ų' => 'u',
    'Ŵ' => 'W',
    'ŵ' => 'w',
    'Ý' => 'Y',
    'Ŷ' => 'Y',
    'Ÿ' => 'Y',
    'Y' => 'Y',
    'ý' => 'y',
    'ÿ' => 'y',
    'ŷ' => 'y',
    'Ź' => 'Z',
    'Ž' => 'Z',
    'Ż' => 'Z',
    'ž' => 'z',
    'ż' => 'z',
    'ź' => 'z',
    'ß' => 'ss',
    'ſ' => 'ss',
  );
  $output = str_replace("'", "", $string);
  $output = strtr($output, $translations);
  $pattern = '#[^a-zA-Z0-9./]+# ';
  $separator = '_';
  $output = preg_replace($pattern, $separator, $output);
  if ($separator) {
    if (ctype_alnum($separator)) {
      $seppattern = $separator;
    }
    else {
      $seppattern = '\\' . $separator;
    }
    $output = preg_replace("/^{$seppattern}+|{$seppattern}+\$/", "", $output);
  }
  $maxlength = min(variable_get('gotwo_max_length', 128), 128);
  $output = substr($output, 0, $maxlength);
  return $output;
}