From 95b357636c7f4b6a7bd5aeedb3d6dc416d7a4c10 Mon Sep 17 00:00:00 2001 From: John Bowles Date: Thu, 26 Aug 2010 22:44:54 -0700 Subject: [PATCH] Fetch title and description from Youtube API if none is provided. --- .../embed_videos/controllers/embedded_videos.php | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/modules/embed_videos/controllers/embedded_videos.php b/modules/embed_videos/controllers/embedded_videos.php index fdb7b5e1..83077e59 100644 --- a/modules/embed_videos/controllers/embedded_videos.php +++ b/modules/embed_videos/controllers/embedded_videos.php @@ -31,6 +31,8 @@ class Embedded_videos_Controller extends Controller { try { $valid = $form->validate(); if ($form->add_embedded_video->inputs['video_url']->value != "") { + $title = $form->add_embedded_video->inputs['title']->value; + $description = $form->add_embedded_video->inputs['description']->value; $youtubeUrlPattern="youtube"; $youtubeApiUrl="http://gdata.youtube.com/feeds/api/"; $youtubeThumbnailUrl="http://img.youtube.com/vi/"; @@ -49,6 +51,13 @@ class Embedded_videos_Controller extends Controller { $temp_filename = VARPATH . "tmp/$itemname"; if ($content) { $valid_url = true; + $sxml = simplexml_load_file("http://gdata.youtube.com/feeds/api/videos/$video_id"); + if ($title == '') { + $title = (string)$sxml->title; + } + if ($description == '') { + $description = (string)$sxml->content; + } } } } @@ -61,10 +70,10 @@ class Embedded_videos_Controller extends Controller { gallery_graphics::composite($temp_filename, $temp_filename, array("file" => "modules/embed_videos/images/embed_video_icon.png", "position" => "center", "transparency" => 95)); $item->set_data_file($temp_filename); $item->name = basename($itemname); - $item->title = $form->add_embedded_video->title->value; + $item->title = $title; $item->parent_id = $album->id; - $item->description = $form->add_embedded_video->description->value; - $item->slug = $form->add_embedded_video->slug->value; + $item->description = $description; + $item->slug = $form->add_embedded_video->inputs['slug']->value; $path_info = @pathinfo($temp_filename); $item->save(); //db::query("UPDATE {items} SET `type` = 'embedded_video' WHERE `id` = $item->id")->execute();