Add title field v1.3.6
authorSteve Sutton <steve@gaslightmedia.com>
Mon, 3 Aug 2015 16:37:19 +0000 (12:37 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Mon, 3 Aug 2015 16:37:19 +0000 (12:37 -0400)
Update for the youtube API changes

Toolkit/Videos/AdminEditVideoForm.php
Toolkit/Videos/Database/addTitle.sql [new file with mode: 0644]
Toolkit/Videos/Video.php
Toolkit/Videos/VideoMapper.php
Toolkit/Videos/WebPageDecorator.php
Toolkit/Videos/updateTitles.php [new file with mode: 0644]

index 4c97308..6abd654 100644 (file)
@@ -131,6 +131,13 @@ class Toolkit_Videos_AdminEditVideoForm
                 'name' => 'featured'
             );
         }
+       $e[] = array(
+            'type'    => 'text',
+            'req'     => false,
+            'name'    => 'title',
+            'display' => 'Title',
+            'opts' => array('class' => 'text','size'=>50)
+        );
         $e[] = array(
             'type' => 'text',
             'req' => true,
@@ -253,6 +260,7 @@ class Toolkit_Videos_AdminEditVideoForm
             $video = new Toolkit_Videos_Video();
         }
         $video->setVideo_url($values['video_url'])
+            ->setTitle($values['title'])
             ->setFeatured($values['featured'])
             ->setActive($values['active']);
 
diff --git a/Toolkit/Videos/Database/addTitle.sql b/Toolkit/Videos/Database/addTitle.sql
new file mode 100644 (file)
index 0000000..fe0cbd1
--- /dev/null
@@ -0,0 +1,4 @@
+--
+-- Update the video table
+--
+ALTER TABLE videos.videos ADD title TEXT;
index 4d717eb..5842f44 100644 (file)
@@ -28,6 +28,7 @@ class Toolkit_Videos_Video
 {
 
     protected $id;
+    protected $title;
     protected $video_url;
     protected $pos;
     protected $featured;
@@ -170,6 +171,16 @@ class Toolkit_Videos_Video
         }
         return $this;
     }
+    public function getTitle()
+    {
+        return $this->title;
+    }
+
+    public function setTitle($title)
+    {
+        $this->title = $title;
+        return $this;
+    }
 
     /**
      * video_url getter
@@ -368,11 +379,13 @@ class Toolkit_Videos_Video
      */
     public function getVideoTitle()
     {
+        return $this->getTitle();
         $code = $this->getVideoCode();
         if (!$code) {
             return false;
         } else {
-            $url = "http://gdata.youtube.com/feeds/api/videos/". $this->getVideoCode();
+            //$url = "http://gdata.youtube.com/feeds/api/videos/". $this->getVideoCode();
+            $url = "http://www.youtube.com/get_video_info?video_id=".$this->getVideoCode();
             $ch          = curl_init();
             $curlOptions = array(
                 CURLOPT_URL            => $url,
@@ -383,10 +396,8 @@ class Toolkit_Videos_Video
 
             $response = curl_exec($ch);
             curl_close($ch);
-            $doc   = new DOMDocument;
-            $doc->loadXML($response);
-            $title = $doc->getElementsByTagName("title")->item(0)->nodeValue;
-            return $title;
+            parse_str($response, $ytarr);
+            return $ytarr['title'];
         }
     }
 
index aebb427..3bc9895 100644 (file)
@@ -95,6 +95,7 @@ class Toolkit_Videos_VideoMapper
             if ($res) {
                 $video = new Toolkit_Videos_Video();
                 $video->setId($res['id'])
+                    ->setTitle($res['title'])
                     ->setVideo_url($res['video_url'])
                     ->setActive($res['active'])
                     ->setfeatured($res['featured'])
index 0276428..29adca4 100644 (file)
@@ -74,7 +74,7 @@ class Toolkit_Videos_WebPageDecorator implements Toolkit_Videos_IDecorator
                 if (filter_var($video->getVideoCode(), FILTER_VALIDATE_INT)) {
                     $vimeoData = $video->getVimeoThumbnail($video->getVideoCode());
                     $page->videos[] = array(
-                        'title' => $vimeoData['title'],
+                        'title' => $video->getVideoTitle(),
                         'url'   => $video->getVideoUrl(),
                         'img'   => $vimeoData['thumbnail_medium'],
                         'code'  => $video->getVideoCode()
diff --git a/Toolkit/Videos/updateTitles.php b/Toolkit/Videos/updateTitles.php
new file mode 100644 (file)
index 0000000..0aa41bb
--- /dev/null
@@ -0,0 +1,24 @@
+<?php
+require_once '../../setup.phtml';
+$dbh = Toolkit_Database::getInstance();
+$sql = "
+SELECT id
+  FROM videos";
+try {
+    $videoMapper = new Toolkit_Videos_VideoMapper($dbh);
+    $stmt = $dbh->query($sql);
+    while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
+        $video = $videoMapper->getVideoById($row['id'], false);
+        //echo '<pre>' . print_r($video, true) . ' </pre>';
+        $title = $video->getVideoTitle();
+        if ($title) {
+            var_dump($title);
+            $video->setTitle($title);
+            $video->save($dbh);
+        echo '<pre>' . print_r($video, true) . ' </pre>';
+        }
+    }
+} catch (PDOException $e) {
+    echo '<pre>'.print_r($e, true).'</pre>';
+    exit;
+}