Пример #1
0
 protected static function autoLinkVideo($text, $listingId = null)
 {
     $params = JUDirectoryHelper::getParams(null, $listingId);
     $auto_embed_youtube_in_comment = $params->get('auto_embed_youtube_in_comment', 0);
     $auto_embed_vimeo_in_comment = $params->get('auto_embed_vimeo_in_comment', 0);
     $video_width_in_comment = $params->get('video_width_in_comment', 360);
     $video_height_in_comment = $params->get('video_height_in_comment', 240);
     $regexYoutube = "#(?:http(?:s)?:\\/\\/)?(?:www\\.)?(?:youtu\\.be\\/|youtube\\.com\\/(?:(?:watch)?\\?(?:.*&)?v(?:i)?=|(?:v|vi|user)\\/))([^\\?&\"'<>\\/\\s]+)(?:\$|\\/|\\?|\\&)?#i";
     preg_match_all($regexYoutube, $text, $matchesYoutube);
     if ($auto_embed_youtube_in_comment && count($matchesYoutube[0])) {
         foreach ($matchesYoutube[0] as $key => $match) {
             $youtube_html = JUDirectoryFrontHelperComment::parseVideo($match, $video_width_in_comment, $video_height_in_comment);
             $text = str_replace($matchesYoutube[0][$key], $youtube_html . '<br/>', $text);
         }
     }
     $regexVimeo = "#(?:http(?:s)?:\\/\\/)?(?:www\\.)?vimeo.com\\/(\\d+)(?:\$|\\/|\\?)?#";
     preg_match_all($regexVimeo, $text, $matchesVimeo);
     if ($auto_embed_vimeo_in_comment && count($matchesVimeo[0])) {
         $arrIdVimeo = array_unique($matchesVimeo[0]);
         foreach ($arrIdVimeo as $key => $match) {
             $vimeo_html = JUDirectoryFrontHelperComment::parseVideo($match, $video_width_in_comment, $video_height_in_comment);
             $text = str_replace($matchesVimeo[0][$key], $vimeo_html, $text);
         }
     }
     return $text;
 }
Пример #2
0
 public static function BBCode2Html($text)
 {
     $text = trim($text);
     if (!function_exists('escape')) {
         function escape($s)
         {
             global $text;
             $text = strip_tags($text);
             $code = $s[1];
             $code = htmlspecialchars($code);
             $code = str_replace("[", "&#91;", $code);
             $code = str_replace("]", "&#93;", $code);
             return '<pre><code>' . $code . '</code></pre>';
         }
     }
     $text = preg_replace_callback('/\\[code\\](.*?)\\[\\/code\\]/ms', "escape", $text);
     $in = array('3:)', ':)', ':(', ':P', ':D', '&gt;:o', ':o', ';)', ':-/', ':v', ':\'(', '^_^', '8-)', '&lt;3', '-_-', 'o.O', ':3', '(y)');
     $smileFolder = JUri::root(true) . '/components/com_judirectory/assets/wysibb/theme/default/img/smiles/';
     $out = array('<img  src="' . $smileFolder . 'devil.png" />', '<img  src="' . $smileFolder . 'smile.png" />', '<img  src="' . $smileFolder . 'frown.png" />', '<img  src="' . $smileFolder . 'tongue.png" />', '<img  src="' . $smileFolder . 'grin.png" />', '<img  src="' . $smileFolder . 'angry.png" />', '<img  src="' . $smileFolder . 'gasp.png" />', '<img  src="' . $smileFolder . 'wink.png" />', '<img  src="' . $smileFolder . 'unsure.png" />', '<img  src="' . $smileFolder . 'pacman.png" />', '<img  src="' . $smileFolder . 'cry.png" />', '<img  src="' . $smileFolder . 'kiki.png" />', '<img  src="' . $smileFolder . 'glasses.png" />', '<img  src="' . $smileFolder . 'heart.png" />', '<img  src="' . $smileFolder . 'squinting.png" />', '<img  src="' . $smileFolder . 'confused.png" />', '<img  src="' . $smileFolder . 'colonthree.png" />', '<img  src="' . $smileFolder . 'like.png" />');
     $text = str_replace($in, $out, $text);
     $in = array('/\\[b\\](.*?)\\[\\/b\\]/ms', '/\\[i\\](.*?)\\[\\/i\\]/ms', '/\\[u\\](.*?)\\[\\/u\\]/ms', '/\\[align=(.*?)\\](.*?)\\[\\/align\\]/ms', '/\\[img\\](.*?)\\[\\/img\\]/ms', '/\\[email\\](.*?)\\[\\/email\\]/ms', '/\\[url\\="?(.*?)"?\\](.*?)\\[\\/url\\]/ms', '/\\[size\\="?(.*?)"?\\](.*?)\\[\\/size\\]/ms', '/\\[color\\="?(.*?)"?\\](.*?)\\[\\/color\\]/ms', '/\\[background\\="?(.*?)"?\\](.*?)\\[\\/background\\]/ms', '/\\[list\\=(.*?)\\](.*?)\\[\\/list\\]/ms', '/\\[list\\](.*?)\\[\\/list\\]/ms', '/\\[\\*\\]([^\\[\\]\\*\\<]*)/ms', '/\\[left\\](.*?)\\[\\/left\\]/ms', '/\\[right\\](.*?)\\[\\/right\\]/ms', '/\\[center\\](.*?)\\[\\/center\\]/ms');
     $out = array('<strong>\\1</strong>', '<em>\\1</em>', '<u>\\1</u>', '<p style="\\1">\\2</p>', '<img src="\\1" alt="\\1" />', '<a href="mailto:\\1">\\1</a>', '<a href="\\1" rel="nofollow">\\2</a>', '<span style="font-size:\\1%">\\2</span>', '<span style="color:\\1">\\2</span>', '<span style="background-color:\\1">\\2</span>', '<ol start="\\1">\\2</ol>', '<ul>\\1</ul>', '<li>\\1</li>', '<p style="text-align:left">\\1</p>', '<p style="text-align:right">\\1</p>', '<p style="text-align:center">\\1</p>');
     $text = preg_replace($in, $out, $text);
     $quoteFind = array('/\\[quote\\]/is', '/\\[\\/quote\\]/is', '/\\[quote\\s*=\\s*"?([^"]*?)"?\\s*\\]/is');
     $quoteReplace = array('<blockquote>', '</blockquote>', '<span class="author">$1 said:</span><blockquote>');
     $count = 0;
     do {
         $text = preg_replace($quoteFind, $quoteReplace, $text, -1, $count);
     } while ($count > 0);
     $videoPatt = '/\\[video\\](.*?)\\[\\/video\\]/ms';
     preg_match($videoPatt, $text, $matches);
     if ($matches && $matches[1]) {
         $vimeo_html = JUDirectoryFrontHelperComment::parseVideo($matches[1]);
         $text = str_replace($matches[0], $vimeo_html, $text);
     }
     $text = str_replace("\r", "", $text);
     $text = "<p>" . preg_replace("/(\n){2,}/", "</p><p>", $text) . "</p>";
     $text = nl2br($text);
     if (!function_exists('removeBr')) {
         function removeBr($s)
         {
             return str_replace("<br />", "", $s[0]);
         }
     }
     $text = preg_replace_callback('/<pre>(.*?)<\\/pre>/ms', "removeBr", $text);
     $text = preg_replace('/<p><pre>(.*?)<\\/pre><\\/p>/ms', "<pre>\\1</pre>", $text);
     $text = preg_replace_callback('/<ul>(.*?)<\\/ul>/ms', "removeBr", $text);
     $text = preg_replace('/<p><ul>(.*?)<\\/ul><\\/p>/ms', "<ul>\\1</ul>", $text);
     return $text;
 }