Adding title to videos
authorSteve Sutton <steve@gaslightmedia.com>
Tue, 24 May 2016 15:01:17 +0000 (11:01 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Tue, 24 May 2016 15:01:32 +0000 (11:01 -0400)
Toolkit/Videos/AdminEditVideoForm.php
Toolkit/Videos/Database/addTitle.sql [new file with mode: 0644]
Toolkit/Videos/Video.php
Toolkit/Videos/VideoMapper.php
Toolkit/Videos/VideosDataGrid.php

index 71ed4fe..db0b786 100644 (file)
@@ -153,6 +153,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,
@@ -334,18 +341,18 @@ class Toolkit_Videos_AdminEditVideoForm
        {
         $r = array();
 
-               $r[] = array(
-                       'element'    => 'video_url',
-                       'message'    => 'ERROR: Invalid URL format (http)',
-                       'type'       => 'checkURI',
-                       'format'     => array(
-                               'allowed_schemes' => array('http'),
-                               'strict' => false
-                       ),
-                       'validation' => $this->validationType,
-                       'reset'      => false,
-                       'force'      => false
-               );
+        $r[] = array(
+            'element'    => 'video_url',
+            'message'    => 'ERROR: Invalid URL format (http)',
+            'type'       => 'checkURI',
+            'format'     => array(
+                'allowed_schemes' => array('http', 'https'),
+                'strict' => false
+            ),
+            'validation' => $this->validationType,
+            'reset'      => false,
+            'force'      => false
+        );
 
 
                $this->setupRules($r);
@@ -376,6 +383,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']);
         if ($newPos) {
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 f1c20c7..048219a 100644 (file)
@@ -28,6 +28,7 @@ class Toolkit_Videos_Video
 {
 
     protected $id;
+    protected $title;
     protected $video_url;
 //    protected $page;
     protected $pos;
@@ -171,6 +172,16 @@ class Toolkit_Videos_Video
         }
         return $this;
     }
+    public function getTitle()
+    {
+        return $this->title;
+    }
+
+    public function setTitle($title)
+    {
+        $this->title = $title;
+        return $this;
+    }
 
     /**
      * page getter
@@ -353,22 +364,26 @@ class Toolkit_Videos_Video
      */
     public function getVideoTitle()
     {
-        $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);
+        return $this->getTitle();
+        $code = $this->getVideoCode();
+        if (!$code) {
+            return false;
+        } else {
+            //$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,
+                CURLOPT_HEADER         => 0,
+                CURLOPT_RETURNTRANSFER => 1
+            );
+            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);
+            parse_str($response, $ytarr);
+            return $ytarr['title'];
+        }
     }
 
 }
index 74b245f..d76342c 100644 (file)
@@ -97,6 +97,7 @@ class Toolkit_Videos_VideoMapper
                 $video = new Toolkit_Videos_Video();
                 $video->setId($res['id'])
                     ->setPage($res['page'])
+                    ->setTitle($res['title'])
                     ->setVideo_url($res['video_url'])
                     ->setActive($res['active'])
                     ->setfeatured($res['featured'])
index 8fa210f..d5c4801 100644 (file)
@@ -140,8 +140,8 @@ class Toolkit_Videos_VideosDataGrid
 
         $this->addColumn(
             new Structures_DataGrid_Column(
-            'Video Url',
-            'video_url',
+            'Title',
+            'title',
             null
             )
         );