/** * Transform posted URLs from video sites into BBvideo embedded code * Not used in default installation. Part of add-on “Auto Embed Video From URLs” * Called only from hook_bbvideo.php when optionally installed * * @param string $text string to transform * @return string $text string with embed codes if applicable * @version 3.0.13 */ function url_to_bbvideo($text) { // Check to see if we have any links to process if (strpos($text, '<a ') === false) { return $text; } global $bbcode; // if no BBCodes are on page, load them up if (empty($bbcode)) { $bbcode = new bbcode(); $bbcode->bbcode_cache_init(); } // get array of all BBvideos static $abbcode_video_ary = array(); if (empty($abbcode_video_ary)) { $abbcode_video_ary = abbcode::video_init(); } // Get all magic urls in the post text preg_match_all('#<!-- [lmw] --><a class="[^"]*" href="([^"]*)"[^>]*>.*?<\\/a><!-- [lmw] -->#i', $text, $matches, PREG_SET_ORDER); foreach ($matches as $links) { $link = $links[0]; $url = $links[1]; // Check for valid BBvideo sites foreach ($abbcode_video_ary as $video_name => $video_data) { if (isset($video_data['match']) && preg_match($video_data['match'], $url)) { $video_links[] = $link; $embed_codes[] = $bbcode->BBvideo_pass($url, null, null); break; } } } // Replace video links with embed codes if (isset($video_links) && isset($embed_codes)) { $text = str_replace($video_links, $embed_codes, $text); } return $text; }