示例#1
0
 /**
  * remove unnessary stuff + add http:// for external urls
  * TODO: protocol to lower!
  * @static
  * 2009-12-22 ms
  */
 public static function cleanUrl($url, $headerRedirect = false)
 {
     if ($url == '' || $url == 'http://' || $url == 'http://www' || $url == 'http://www.') {
         $url = '';
     } else {
         $url = self::autoPrefixUrl($url, 'http://');
     }
     if ($headerRedirect && !empty($url)) {
         $headers = self::getHeaderFromUrl($url);
         if ($headers !== false) {
             $headerString = implode("\n", $headers);
             if ((bool) preg_match('#^HTTP/.*\\s+[(301)]+\\s#i', $headerString)) {
                 foreach ($headers as $header) {
                     if (mb_strpos($header, 'Location:') === 0) {
                         $url = trim(hDec(mb_substr($header, 9)));
                         // rawurldecode/urldecode ?
                     }
                 }
             }
         }
     }
     $length = mb_strlen($url);
     while (!empty($url) && mb_strrpos($url, '/') === $length - 1) {
         $url = mb_substr($url, 0, $length - 1);
         $length--;
     }
     return $url;
 }
 protected function _process($text, $type = null)
 {
     if (empty($type)) {
         # auto detect
         $type = $this->_autoDetect($text);
         $this->request->data['Form']['type'] = $type;
         //return $text;
     }
     switch ($type) {
         case '1':
             $text = h($text);
             break;
         case '2':
             $text = hDec($text);
             break;
         case '3':
             $text = ent($text);
             break;
         case '4':
             $text = entDec($text);
             break;
         case '5':
             $pieces = explode(NL, $text);
             foreach ($pieces as $key => $val) {
                 $pieces[$key] = TB . $val;
             }
             $text = implode(NL, $pieces);
             break;
         case '6':
             $pieces = explode(NL, $text);
             foreach ($pieces as $key => $val) {
                 $pieces[$key] = mb_substr($val, 0, 1) === TB ? mb_substr($val, 1) : $val;
             }
             $text = implode(NL, $pieces);
             break;
     }
     return $text;
 }
示例#3
0
 /**
  * @param string $email
  * @param options:
  * - obfuscate: true/false (defaults to false)
  * @return string html
  */
 public static function prepareEmail($email, $options = [], $customOptions = [])
 {
     $obfuscate = false;
     if (isset($options['obfuscate'])) {
         $obfuscate = $options['obfuscate'];
         unset($options['obfuscate']);
     }
     if (!isset($customOptions['escape']) || $customOptions['escape'] !== false) {
         $email = hDec($email);
     }
     $Html = new HtmlHelper(new View(null));
     if (!$obfuscate) {
         return $Html->link($email, "mailto:" . $email, $options);
     }
     $class = __CLASS__;
     $Common = new $class();
     $Common->Html = $Html;
     return $Common->encodeEmailUrl($email, null, [], $options);
 }