Exemplo n.º 1
0
 public static function getVideoLink($content, $videoWidth = '425', $videoHeight = '344')
 {
     $pattern = array();
     $videoLinks = array();
     $pattern = CVideosHelper::getVideoLinkPatterns();
     for ($i = 0; $i < count($pattern); $i++) {
         //Match all video links
         @preg_match_all($pattern[$i], $content, $match);
         if ($match) {
             $videoLinks[] = $match[0];
         }
     }
     foreach ($videoLinks as $videoLink) {
         // Replace the URL with the embedded code
         foreach ($videoLink as $videoLinkUrl) {
             $parsedVideoLink = parse_url($videoLinkUrl);
             preg_match('/(?P<domain>[a-z0-9][a-z0-9\\-]{1,63}\\.[a-z\\.]{2,6})$/i', $parsedVideoLink['host'], $matches);
             $domain = $matches['domain'];
             if (!empty($domain)) {
                 $provider = explode('.', $domain);
                 $providerName = JString::strtolower($provider[0]);
                 $libraryPath = COMMUNITY_COM_PATH . '/libraries/videos' . '/' . $providerName . '.php';
                 require_once $libraryPath;
                 $className = 'CTableVideo' . JString::ucfirst($providerName);
                 $videoObj = new $className();
                 $videoObj->init($videoLinkUrl);
                 $video_id = $videoObj->getId();
                 $videoPlayer = $videoObj->getViewHTML($video_id, $videoWidth, $videoHeight);
                 $content = str_replace($videoLinkUrl, $videoPlayer, $content);
             }
         }
     }
     return $content;
 }