Add Vimeo to the video application
authorSteve Sutton <steve@gaslightmedia.com>
Wed, 20 May 2015 20:12:40 +0000 (16:12 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Wed, 20 May 2015 20:12:40 +0000 (16:12 -0400)
Can now setup the correct url for the color box to open the vimeo
videos.

Toolkit/Videos/AdminEditVideoForm.php
Toolkit/Videos/Video.php
Toolkit/Videos/VideoMapper.php
Toolkit/Videos/VideosDataGrid.php
Toolkit/Videos/WebPageDecorator.php
Toolkit/Videos/templates/webPageDecorator.html
config/server.ini

index d421e0b..779437f 100644 (file)
@@ -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,
index 8e5f6e3..4d717eb 100644 (file)
@@ -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;
+        }
     }
 
 }
index 2a00c87..aebb427 100644 (file)
@@ -107,5 +107,5 @@ class Toolkit_Videos_VideoMapper
             Toolkit_Common::handleError($e);
         }
     }
-    
+
 }
index f9c5c93..6c9e2d0 100644 (file)
@@ -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)
+                ? '<a href="https://player.vimeo.com/vidio/'.$vidCode.'?rel=0" class="various fancybox.iframe vidimg"><img src="'.$vimeoData['thumbnail_small'].'"></a>'
+                : '';
+        } else {
+            $thumb = ($vidCode)
+                ? '<a href="http://www.youtube.com/embed/'.$vidCode.'?rel=0" class="various fancybox.iframe vidimg"><img src="http://img.youtube.com/vi/'.$vidCode.'/default.jpg"></a>'
+                : '';
         }
-        $thumb = ($vidCode)
-            ? '<a href="http://www.youtube.com/embed/'.$vidCode.'?rel=0" class="various fancybox.iframe vidimg"><img src="http://img.youtube.com/vi/'.$vidCode.'/default.jpg"></a>'
-            : '';
         return $thumb;
     }
 
index 3a9cd6c..0276428 100644 (file)
@@ -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;
index 9f8b142..5c2d02f 100644 (file)
@@ -2,11 +2,11 @@
     {foreach:videos,v} 
         <li class="vThumb">
             <div class="imgBorderMe">
-                <a href="http://www.youtube.com/embed/{v[code]}?rel=0&hd=1" class="various fancybox.iframe vidimg">
-                    <img src="http://img.youtube.com/vi/{v[code]}/default.jpg">
+                <a href="{v[url]}" class="various fancybox.iframe vidimg">
+                    <img src="{v[img]}">
                 <span class="vTitle">{v[title]:h}<span class="play"></span></span>
                 </a>
             </div>
         </li>
     {end:}
-</ul>
\ No newline at end of file
+</ul>
index a4d5d92..40347f9 100644 (file)
@@ -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