From 9c2f3099f4cc4c6faab9e6a7578ccf26ec7f88f1 Mon Sep 17 00:00:00 2001 From: Steve Sutton Date: Wed, 20 May 2015 16:12:40 -0400 Subject: [PATCH] Add Vimeo to the video application Can now setup the correct url for the color box to open the vimeo videos. --- Toolkit/Videos/AdminEditVideoForm.php | 2 +- Toolkit/Videos/Video.php | 73 +++++++++++++++---- Toolkit/Videos/VideoMapper.php | 2 +- Toolkit/Videos/VideosDataGrid.php | 19 ++++- Toolkit/Videos/WebPageDecorator.php | 20 ++++- .../Videos/templates/webPageDecorator.html | 6 +- config/server.ini | 6 +- 7 files changed, 100 insertions(+), 28 deletions(-) diff --git a/Toolkit/Videos/AdminEditVideoForm.php b/Toolkit/Videos/AdminEditVideoForm.php index d421e0b..779437f 100644 --- a/Toolkit/Videos/AdminEditVideoForm.php +++ b/Toolkit/Videos/AdminEditVideoForm.php @@ -215,7 +215,7 @@ class Toolkit_Videos_AdminEditVideoForm 'message' => 'ERROR: Invalid URL format (http)', 'type' => 'checkURI', 'format' => array( - 'allowed_schemes' => array('http'), + 'allowed_schemes' => array('http', 'https'), 'strict' => false ), 'validation' => $this->validationType, diff --git a/Toolkit/Videos/Video.php b/Toolkit/Videos/Video.php index 8e5f6e3..4d717eb 100644 --- a/Toolkit/Videos/Video.php +++ b/Toolkit/Videos/Video.php @@ -307,18 +307,60 @@ class Toolkit_Videos_Video */ public function getVideoCode() { - $pattern = '/v=(.*)$/'; - $pattern2 = '/youtu.be\/(.*)/'; + $youTubeUrl = 'http://www.youtube.com/embed/%s?rel=0&hd=1'; + $pattern = '/v=(.*)$/'; + $pattern2 = '/youtu.be\/(.*)/'; + $pattern3 = ';vimeo.com/([0-9]*);'; + $pattern3 = ';vimeo.com/([0-9]*);'; $vidUrl = $this->getVideo_url(); if (preg_match($pattern, $vidUrl, $match)) { return $match[1]; } else if (preg_match($pattern2, $vidUrl, $match)) { return $match[1]; + } else if (preg_match($pattern3, $vidUrl, $match)) { + return $match[1]; } else { return false; } } + public function getVideoUrl() + { + $youTubeUrl = 'http://www.youtube.com/embed/%s?rel=0&hd=1'; + $vimeoUrl = 'https://player.vimeo.com/video/%d'; + $pattern = '/v=(.*)$/'; + $pattern2 = '/youtu.be\/(.*)/'; + $pattern3 = ';vimeo.com/([0-9]*);'; + $vidUrl = $this->getVideo_url(); + if (preg_match($pattern, $vidUrl, $match)) { + return sprintf($youTubeUrl, $match[1]); + } else if (preg_match($pattern2, $vidUrl, $match)) { + return sprintf($youTubeUrl, $match[1]); + } else if (preg_match($pattern3, $vidUrl, $match)) { + return sprintf($vimeoUrl, $match[1]); + } else { + return false; + } + } + + + public function getVimeoThumbnail($videoId) + { + $url = "http://vimeo.com/api/v2/video/$videoId.php"; + $ch = curl_init(); + $curlOptions = array( + CURLOPT_URL => $url, + CURLOPT_HEADER => 0, + CURLOPT_RETURNTRANSFER => 1 + ); + curl_setopt_array($ch, $curlOptions); + + $response = curl_exec($ch); + curl_close($ch); + $data = unserialize($response); + return ($data) ? $data[0] : false; + } + /** * Using the youtube API get the video title for the embed url * @@ -326,21 +368,26 @@ class Toolkit_Videos_Video */ public function getVideoTitle() { - $url = "http://gdata.youtube.com/feeds/api/videos/". $this->getVideoCode(); - $ch = curl_init(); - $curlOptions = array( + $code = $this->getVideoCode(); + if (!$code) { + return false; + } else { + $url = "http://gdata.youtube.com/feeds/api/videos/". $this->getVideoCode(); + $ch = curl_init(); + $curlOptions = array( CURLOPT_URL => $url, CURLOPT_HEADER => 0, CURLOPT_RETURNTRANSFER => 1 - ); - curl_setopt_array($ch, $curlOptions); + ); + curl_setopt_array($ch, $curlOptions); - $response = curl_exec($ch); - curl_close($ch); - $doc = new DOMDocument; - $doc->loadXML($response); - $title = $doc->getElementsByTagName("title")->item(0)->nodeValue; - return $title; + $response = curl_exec($ch); + curl_close($ch); + $doc = new DOMDocument; + $doc->loadXML($response); + $title = $doc->getElementsByTagName("title")->item(0)->nodeValue; + return $title; + } } } diff --git a/Toolkit/Videos/VideoMapper.php b/Toolkit/Videos/VideoMapper.php index 2a00c87..aebb427 100644 --- a/Toolkit/Videos/VideoMapper.php +++ b/Toolkit/Videos/VideoMapper.php @@ -107,5 +107,5 @@ class Toolkit_Videos_VideoMapper Toolkit_Common::handleError($e); } } - + } diff --git a/Toolkit/Videos/VideosDataGrid.php b/Toolkit/Videos/VideosDataGrid.php index f9c5c93..6c9e2d0 100644 --- a/Toolkit/Videos/VideosDataGrid.php +++ b/Toolkit/Videos/VideosDataGrid.php @@ -203,17 +203,30 @@ class Toolkit_Videos_VideosDataGrid */ public function renderThumbNail($data) { + $isVimeo = false; extract($data['record']); $pattern = '/v=(.*)/'; $pattern2 = '/youtu.be\/(.*)/'; + $pattern3 = ';vimeo.com/([0-9]*);'; if (preg_match($pattern, $video_url, $match)) { $vidCode = $match[1]; } else if (preg_match($pattern2, $video_url, $match)) { $vidCode = $match[1]; + } else if (preg_match($pattern3, $video_url, $match)) { + $vidCode = $match[1]; + $isVimeo = true; + } + if ($isVimeo) { + //$vimeoData = Toolkit_Videos_Video::getVimeoThumbnail($vidCode); + $vimeoData = Toolkit_Videos_Video::getVimeoThumbnail($vidCode); + $thumb = ($vidCode) + ? '' + : ''; + } else { + $thumb = ($vidCode) + ? '' + : ''; } - $thumb = ($vidCode) - ? '' - : ''; return $thumb; } diff --git a/Toolkit/Videos/WebPageDecorator.php b/Toolkit/Videos/WebPageDecorator.php index 3a9cd6c..0276428 100644 --- a/Toolkit/Videos/WebPageDecorator.php +++ b/Toolkit/Videos/WebPageDecorator.php @@ -71,10 +71,22 @@ class Toolkit_Videos_WebPageDecorator implements Toolkit_Videos_IDecorator = new Toolkit_Videos_VideoMapper($dbh); $video = $videoMapper->getVideoById($row['id'], false); if ($video) { - $page->videos[] = array( - 'title' => $video->getVideoTitle(), - 'code' => $video->getVideoCode() - ); + if (filter_var($video->getVideoCode(), FILTER_VALIDATE_INT)) { + $vimeoData = $video->getVimeoThumbnail($video->getVideoCode()); + $page->videos[] = array( + 'title' => $vimeoData['title'], + 'url' => $video->getVideoUrl(), + 'img' => $vimeoData['thumbnail_medium'], + 'code' => $video->getVideoCode() + ); + } else { + $page->videos[] = array( + 'title' => $video->getVideoTitle(), + 'url' => $video->getVideoUrl(), + 'img' => "http://img.youtube.com/vi/{$video->getVideoCode()}/default.jpg", + 'code' => $video->getVideoCode() + ); + } } } $count = 1; diff --git a/Toolkit/Videos/templates/webPageDecorator.html b/Toolkit/Videos/templates/webPageDecorator.html index 9f8b142..5c2d02f 100644 --- a/Toolkit/Videos/templates/webPageDecorator.html +++ b/Toolkit/Videos/templates/webPageDecorator.html @@ -2,11 +2,11 @@ {foreach:videos,v}
  • {end:} - \ No newline at end of file + diff --git a/config/server.ini b/config/server.ini index a4d5d92..40347f9 100644 --- a/config/server.ini +++ b/config/server.ini @@ -164,7 +164,7 @@ resources.environment.css = "prod" ; development site configuration data inherits from production and ; overrides values as necessary [development : production] -site_url = "http://dev53.gaslightmedia.com/www.keweenaw.info/" +site_url = "http://localhost:8080/www.keweenaw.info/" mobile.link = mobile.hostname = Off @@ -172,8 +172,8 @@ mobile.hostname = Off google.search.key = "ABQIAAAANX0yQZ2OteLu_zqbwdfUuRTeX7yNUukyMrmY8FsCXcCA9axlYBTyhehgzuXOUfNI0E5UYHCLponA0A" google.maps.key = "ABQIAAAANX0yQZ2OteLu_zqbwdfUuRQsHGkczIjpqPY1-dTKNoaiGtfPJBTloI-YH7fzUV-bsMLwcy2Yjyti7A" -app.base_url = "http://dev53.gaslightmedia.com/app.gaslightmedia.com/" -app.base_secure_url = "https://dev53.gaslightmedia.com/app.gaslightmedia.com/" +app.base_url = "http://app.gaslightmedia.com/" +app.base_secure_url = "https://app.gaslightmedia.com/" error.reporting[] = E_ALL error.reporting[] = E_NOTICE -- 2.17.1