コード例 #1
0
ファイル: class.format.php プロジェクト: gizur/osticket
 function clickableurls($text, $target = '_blank')
 {
     global $ost;
     // Find all text between tags
     $text = preg_replace_callback(':^[^<]+|>[^<]+:', function ($match) {
         // Scan for things that look like URLs
         return preg_replace_callback('`(?<!>)(((f|ht)tp(s?)://|(?<!//)www\\.)([-+~%/.\\w]+)(?:[-?#+=&;%@.\\w]*)?)' . '|(\\b[_\\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\\.)+[a-z]{2,4})`', function ($match) {
             if ($match[1]) {
                 while (in_array(substr($match[1], -1), array('.', '?', '-', ':', ';'))) {
                     $match[9] = substr($match[1], -1) . $match[9];
                     $match[1] = substr($match[1], 0, strlen($match[1]) - 1);
                 }
                 if (strpos($match[2], '//') === false) {
                     $match[1] = 'http://' . $match[1];
                 }
                 return sprintf('<a href="%s">%s</a>%s', $match[1], $match[1], $match[9]);
             } elseif ($match[6]) {
                 return sprintf('<a href="mailto:%1$s" target="_blank">%1$s</a>', $match[6]);
             }
         }, $match[0]);
     }, $text);
     // Now change @href and @src attributes to come back through our
     // system as well
     $config = array('hook_tag' => function ($e, $a = 0) use($target) {
         static $eE = array('area' => 1, 'br' => 1, 'col' => 1, 'embed' => 1, 'hr' => 1, 'img' => 1, 'input' => 1, 'isindex' => 1, 'param' => 1);
         if ($e == 'a' && $a) {
             $a['target'] = $target;
             $a['class'] = 'no-pjax';
         }
         $at = '';
         if (is_array($a)) {
             foreach ($a as $k => $v) {
                 $at .= " {$k}=\"{$v}\"";
             }
             return "<{$e}{$at}" . (isset($eE[$e]) ? " /" : "") . ">";
         } else {
             return "</{$e}>";
         }
     }, 'schemes' => 'href: aim, feed, file, ftp, gopher, http, https, irc, mailto, news, nntp, sftp, ssh, telnet; *:file, http, https; src: cid, http, https, data', 'elements' => '*+iframe', 'balance' => 0, 'spec' => 'span=data-src,width,height');
     return Format::html($text, $config);
 }
コード例 #2
0
 function getBody($mid)
 {
     $body = '';
     if (!($body = $this->getPart($mid, 'TEXT/PLAIN', $this->charset))) {
         if ($body = $this->getPart($mid, 'TEXT/HTML', $this->charset)) {
             //Convert tags of interest before we striptags
             $body = str_replace("</DIV><DIV>", "\n", $body);
             $body = str_replace(array("<br>", "<br />", "<BR>", "<BR />"), "\n", $body);
             $body = Format::html($body);
             //Balance html tags before stripping.
             $body = Format::striptags($body);
             //Strip tags??
         }
     }
     return $body;
 }
コード例 #3
0
ファイル: class.thread.php プロジェクト: jmangarret/ostickets
 function getSearchable()
 {
     // Replace tag chars with spaces (to ensure words are separated)
     $body = Format::html($this->body, array('hook_tag' => function ($el, $attributes = 0) {
         static $non_ws = array('wbr' => 1);
         return isset($non_ws[$el]) ? '' : ' ';
     }));
     // Collapse multiple white-spaces
     $body = html_entity_decode($body, ENT_QUOTES);
     $body = preg_replace('`\\s+`u', ' ', $body);
     return Format::searchable($body);
 }
コード例 #4
0
 function safe_html($html)
 {
     return Format::html($html, array('safe' => 1, 'balance' => 1));
 }
コード例 #5
0
 function safe_html($html)
 {
     $config = array('safe' => 1, 'balance' => 1, 'comment' => 1);
     return Format::html($html, $config);
 }
コード例 #6
0
 function getBody()
 {
     $body = '';
     if (!($body = $this->getPart($this->struct, 'text/plain'))) {
         if ($body = $this->getPart($this->struct, 'text/html')) {
             //Cleanup the html.
             $body = str_replace("</DIV><DIV>", "\n", $body);
             $body = str_replace(array("<br>", "<br />", "<BR>", "<BR />"), "\n", $body);
             $body = Format::striptags(Format::html($body));
         }
     }
     return $body;
 }