From: Steve Sutton Date: Mon, 3 Aug 2015 16:37:19 +0000 (-0400) Subject: Add title field X-Git-Tag: v1.3.6^0 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/index.cgi?a=commitdiff_plain;h=d89a478941ee96106a83c8f0f81c69aa8a10f09a;p=web%2FKeweenaw.git Add title field Update for the youtube API changes --- diff --git a/Toolkit/Videos/AdminEditVideoForm.php b/Toolkit/Videos/AdminEditVideoForm.php index 4c97308..6abd654 100644 --- a/Toolkit/Videos/AdminEditVideoForm.php +++ b/Toolkit/Videos/AdminEditVideoForm.php @@ -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 index 0000000..fe0cbd1 --- /dev/null +++ b/Toolkit/Videos/Database/addTitle.sql @@ -0,0 +1,4 @@ +-- +-- Update the video table +-- +ALTER TABLE videos.videos ADD title TEXT; diff --git a/Toolkit/Videos/Video.php b/Toolkit/Videos/Video.php index 4d717eb..5842f44 100644 --- a/Toolkit/Videos/Video.php +++ b/Toolkit/Videos/Video.php @@ -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']; } } diff --git a/Toolkit/Videos/VideoMapper.php b/Toolkit/Videos/VideoMapper.php index aebb427..3bc9895 100644 --- a/Toolkit/Videos/VideoMapper.php +++ b/Toolkit/Videos/VideoMapper.php @@ -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']) diff --git a/Toolkit/Videos/WebPageDecorator.php b/Toolkit/Videos/WebPageDecorator.php index 0276428..29adca4 100644 --- a/Toolkit/Videos/WebPageDecorator.php +++ b/Toolkit/Videos/WebPageDecorator.php @@ -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 index 0000000..0aa41bb --- /dev/null +++ b/Toolkit/Videos/updateTitles.php @@ -0,0 +1,24 @@ +query($sql); + while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) { + $video = $videoMapper->getVideoById($row['id'], false); + //echo '
' . print_r($video, true) . ' 
'; + $title = $video->getVideoTitle(); + if ($title) { + var_dump($title); + $video->setTitle($title); + $video->save($dbh); + echo '
' . print_r($video, true) . ' 
'; + } + } +} catch (PDOException $e) { + echo '
'.print_r($e, true).'
'; + exit; +}