From 52255de580654f351205b19565be601bd4caaacb Mon Sep 17 00:00:00 2001 From: Brett Profitt Date: Fri, 26 Mar 2010 22:44:48 +0000 Subject: First pass at cleaning up videolist. --- actions/addvideo.php | 327 +++++++++++++------------ actions/comments_delete/add.php | 97 ++++---- actions/delete.php | 71 +++--- actions/save.php | 23 +- actions/tubesearch.php | 522 ++++++++++++++++++++-------------------- 5 files changed, 508 insertions(+), 532 deletions(-) (limited to 'actions') diff --git a/actions/addvideo.php b/actions/addvideo.php index 40c231518..8be09ca3a 100644 --- a/actions/addvideo.php +++ b/actions/addvideo.php @@ -1,19 +1,19 @@ - * @copyright Prateek Choudhary - */ - +/** + * Elgg Video Plugin + * This plugin allows users to create a library of youtube/vimeo/metacafe videos + * + * @package Elgg + * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2 + * @author Prateek Choudhary + * @copyright Prateek Choudhary + */ + // Make sure we're logged in (send us to the front page if not) gatekeeper(); -// Get the current page's owner +// Get the current page's owner set_page_owner($_SESSION['container_guid']); $page_owner = page_owner_entity(); @@ -23,194 +23,193 @@ if ($page_owner === false || is_null($page_owner)) { set_page_owner($_SESSION['guid']); } -if($page_owner->type == "group") +if($page_owner->type == "group") { $entity_referer = $page_owner->type.":".$page_owner->getGUID(); -else +} else { $entity_referer = $page_owner->username; +} require_once(dirname(dirname(__FILE__)) . "/models/lib/class.vimeo.php"); function fetchyoutubeDatatitle($videoid){ - $buffer = file_get_contents('http://www.youtube.com/api2_rest?method=youtube.videos.get_details&dev_id=rG48P7iz0eo&video_id='.$videoid); - /** - ** generate XML View + $buffer = file_get_contents('http://www.youtube.com/api2_rest?method=youtube.videos.get_details&dev_id=rG48P7iz0eo&video_id='.$videoid); + /** + ** generate XML View **/ $xml_buffer = new SimpleXMLElement($buffer); - $vidDataTitle = $xml_buffer->video_details->title; - return $vidDataTitle; - //return ""; + $vidDataTitle = $xml_buffer->video_details->title; + return $vidDataTitle; + //return ""; } function fetchyoutubeDatadesc($videoid){ - $buffer = file_get_contents('http://www.youtube.com/api2_rest?method=youtube.videos.get_details&dev_id=rG48P7iz0eo&video_id='.$videoid); - /** - ** generate XML View - **/ - $xml_buffer = new SimpleXMLElement($buffer); - $vidDataDesc = $xml_buffer->video_details->description; - return $vidDataDesc; - //return ""; + $buffer = file_get_contents('http://www.youtube.com/api2_rest?method=youtube.videos.get_details&dev_id=rG48P7iz0eo&video_id='.$videoid); + /** + ** generate XML View + **/ + $xml_buffer = new SimpleXMLElement($buffer); + $vidDataDesc = $xml_buffer->video_details->description; + return $vidDataDesc; + //return ""; } function getVimeoInfoDataTitle($iGetVideoId){ - // Now lets do the search query. We will get an response object containing everything we need - $oResponse = VimeoVideosRequest::getInfo($iGetVideoId); - // We want the result videos as an array of objects - $aoVideos = $oResponse->getVideo(); - $title = $aoVideos->getTitle(); - return $title; + // Now lets do the search query. We will get an response object containing everything we need + $oResponse = VimeoVideosRequest::getInfo($iGetVideoId); + // We want the result videos as an array of objects + $aoVideos = $oResponse->getVideo(); + $title = $aoVideos->getTitle(); + return $title; } function getVimeoInfoDataDesc($iGetVideoId){ - // Now lets do the search query. We will get an response object containing everything we need - $oResponse = VimeoVideosRequest::getInfo($iGetVideoId); - // We want the result videos as an array of objects - $aoVideos = $oResponse->getVideo(); - $description = $aoVideos->getCaption(); - return $description; + // Now lets do the search query. We will get an response object containing everything we need + $oResponse = VimeoVideosRequest::getInfo($iGetVideoId); + // We want the result videos as an array of objects + $aoVideos = $oResponse->getVideo(); + $description = $aoVideos->getCaption(); + return $description; } function getVimeoInfoImage($iGetVideoId){ - // Now lets do the search query. We will get an response object containing everything we need - $oResponse = VimeoVideosRequest::getInfo($iGetVideoId); - // We want the result videos as an array of objects - $aoVideos = $oResponse->getVideo(); - //get all thumbnails - - $aThumbnails = array(); - foreach($aoVideos->getThumbnails() as $oThumbs) { - $aThumbnails[] = $oThumbs->getImageContent(); - } - - foreach($aThumbnails as $thumbnailArray){ - $thumbnail = $thumbnailArray; - break; - } - - return $thumbnail; + // Now lets do the search query. We will get an response object containing everything we need + $oResponse = VimeoVideosRequest::getInfo($iGetVideoId); + // We want the result videos as an array of objects + $aoVideos = $oResponse->getVideo(); + //get all thumbnails + + $aThumbnails = array(); + foreach($aoVideos->getThumbnails() as $oThumbs) { + $aThumbnails[] = $oThumbs->getImageContent(); + } + + foreach($aThumbnails as $thumbnailArray){ + $thumbnail = $thumbnailArray; + break; + } + + return $thumbnail; } function fetchyoutubeDatathumbnail($videoId){ - $thumbnail = "http://img.youtube.com/vi/".$videoId."/default.jpg"; - return $thumbnail; + $thumbnail = "http://img.youtube.com/vi/".$videoId."/default.jpg"; + return $thumbnail; } function metacafeFetchData($getVideoId){ - $feedURL = "http://www.metacafe.com/api/item/".$getVideoId; - $sxml = new DomDocument; - $sxml->load($feedURL); - $myitem = $sxml->getElementsByTagName('item'); - return $myitem; + $feedURL = "http://www.metacafe.com/api/item/".$getVideoId; + $sxml = new DomDocument; + $sxml->load($feedURL); + $myitem = $sxml->getElementsByTagName('item'); + return $myitem; } function fetchmetacafeTitle($getVideoId){ - $myitem = metacafeFetchData($getVideoId); - foreach($myitem as $searchNode){ - $xmlTitle = $searchNode->getElementsByTagName("title"); - $valueTitle = $xmlTitle->item(0)->nodeValue; - } - return $valueTitle; + $myitem = metacafeFetchData($getVideoId); + foreach($myitem as $searchNode){ + $xmlTitle = $searchNode->getElementsByTagName("title"); + $valueTitle = $xmlTitle->item(0)->nodeValue; + } + return $valueTitle; } function fetchmetacafeDesc($getVideoId){ - $myitem = metacafeFetchData($getVideoId); - foreach($myitem as $searchNode){ - $xmlDesc = $searchNode->getElementsByTagName("description"); - $valueDesc = $xmlDesc->item(0)->nodeValue; - $ot = "

"; - $ct = "

"; - $string = trim($valueDesc); - $start = intval(strpos($string, $ot) + strlen($ot)); - $desc_src = substr($string,$start,intval(strpos($string,$ct) - $start)); - } - return $desc_src; + $myitem = metacafeFetchData($getVideoId); + foreach($myitem as $searchNode){ + $xmlDesc = $searchNode->getElementsByTagName("description"); + $valueDesc = $xmlDesc->item(0)->nodeValue; + $ot = "

"; + $ct = "

"; + $string = trim($valueDesc); + $start = intval(strpos($string, $ot) + strlen($ot)); + $desc_src = substr($string,$start,intval(strpos($string,$ct) - $start)); + } + return $desc_src; } function fetchmetacafeImg($getVideoId){ - $myitem = metacafeFetchData($getVideoId); - foreach($myitem as $searchNode){ - $xmlDesc = $searchNode->getElementsByTagName("description"); - $valueDesc = $xmlDesc->item(0)->nodeValue; - $pattern = '/]+src[\\s=\'"]'; - $pattern .= '+([^"\'>\\s]+)/is'; - if(preg_match($pattern,$valueDesc,$match)){ - $thumbnail = $match[1]; - } - } - return $thumbnail; -} - - $pageContainer = $_SESSION['Pagecontainer']; - - - // Initialise a new ElggObject - $videolist = new ElggObject(); - // Tell the system it's a blog post - $videolist->subtype = "videolist"; - // Set its owner to the current user - $videolist->owner_guid = $_SESSION['user']->getGUID(); - - // Set container of the video whether it was uploaded to groups or profile - $videolist->container_guid = $_SESSION['container_guid']; - // For now, set its access to public (we'll add an access dropdown shortly) - $videolist->access_id = $_SESSION['candidate_profile_video_access_id']; - - // In order to Set its title and description appropriately WE need the video ID - $videolist->url = $_SESSION['candidate_profile_video']; - - if($pageContainer == "youtube"){ - $videoIDArray = split("/v/", $videolist->url); - $videolist->video_id = $videoIDArray[1]; - // Now set the video title and description appropriately - $videolist->title = fetchyoutubeDatatitle($videoIDArray[1]); - $videolist->desc = fetchyoutubeDatadesc($videoIDArray[1]); - $videolist->thumbnail = fetchyoutubeDatathumbnail($videoIDArray[1]); - $videolist->videotype = "youtube"; - } - else if($pageContainer == "metacafe"){ - $videolist->video_id = $_SESSION['candidate_profile_video']; - // Now set the video title and description appropriately - $videolist->title = fetchmetacafeTitle($_SESSION['candidate_profile_video']); - $videolist->desc = fetchmetacafeDesc($_SESSION['candidate_profile_video']); - $videolist->thumbnail = fetchmetacafeImg($_SESSION['candidate_profile_video']); - $videolist->videotype = "metacafe"; - } - else if($pageContainer == "vimeo"){ - $videolist->video_id = $_SESSION['candidate_profile_video']; - - // Now set the video title and description appropriately - $videolist->title = getVimeoInfoDataTitle($_SESSION['candidate_profile_video']); - $videolist->desc = getVimeoInfoDataDesc($_SESSION['candidate_profile_video']); - $videolist->thumbnail = getVimeoInfoImage($_SESSION['candidate_profile_video']); - $videolist->videotype = "vimeo"; - } - - // Before we can set metadata, we need to save the blog post - if (!$videolist->save()) { - register_error(elgg_echo("videolist:error")); - forward("pg/videolist/new"); - } - //add video tags - $videolist_tags_array = string_to_tag_array($_SESSION['videolisttags']); - if (is_array($videolist_tags_array)) { - $videolist->tags = $videolist_tags_array; - } - - // add to river - add_to_river('river/object/videolist/create', 'create', $_SESSION['user']->guid, $videolist->guid); - - // add_to_river('river/object/blog/create','create',$_SESSION['user']->guid,$blog->guid); - // Success message - system_message(elgg_echo("videolist:posted")); - // Remove the videolist cache - unset($_SESSION['candidate_profile_video_access_id']); unset($_SESSION['candidate_profile_video']); - unset($_SESSION['videolisttags']);unset($_SESSION['Pagecontainer']); - // Forward to the main videolist page - -forward("pg/videolist/owned/".page_owner_entity()->username); + $myitem = metacafeFetchData($getVideoId); + foreach($myitem as $searchNode){ + $xmlDesc = $searchNode->getElementsByTagName("description"); + $valueDesc = $xmlDesc->item(0)->nodeValue; + $pattern = '/]+src[\\s=\'"]'; + $pattern .= '+([^"\'>\\s]+)/is'; + if(preg_match($pattern,$valueDesc,$match)){ + $thumbnail = $match[1]; + } + } + return $thumbnail; +} + +$pageContainer = $_SESSION['Pagecontainer']; + +// Initialise a new ElggObject +$videolist = new ElggObject(); +// Tell the system it's a blog post +$videolist->subtype = "videolist"; +// Set its owner to the current user +$videolist->owner_guid = $_SESSION['user']->getGUID(); + +// Set container of the video whether it was uploaded to groups or profile +$videolist->container_guid = $_SESSION['container_guid']; +// For now, set its access to public (we'll add an access dropdown shortly) +$videolist->access_id = $_SESSION['candidate_profile_video_access_id']; + +// In order to Set its title and description appropriately WE need the video ID +$videolist->url = $_SESSION['candidate_profile_video']; + +if($pageContainer == "youtube"){ + $videoIDArray = split("/v/", $videolist->url); + $videolist->video_id = $videoIDArray[1]; + // Now set the video title and description appropriately + $videolist->title = fetchyoutubeDatatitle($videoIDArray[1]); + $videolist->desc = fetchyoutubeDatadesc($videoIDArray[1]); + $videolist->thumbnail = fetchyoutubeDatathumbnail($videoIDArray[1]); + $videolist->videotype = "youtube"; +} +else if($pageContainer == "metacafe"){ + $videolist->video_id = $_SESSION['candidate_profile_video']; + // Now set the video title and description appropriately + $videolist->title = fetchmetacafeTitle($_SESSION['candidate_profile_video']); + $videolist->desc = fetchmetacafeDesc($_SESSION['candidate_profile_video']); + $videolist->thumbnail = fetchmetacafeImg($_SESSION['candidate_profile_video']); + $videolist->videotype = "metacafe"; +} +else if($pageContainer == "vimeo"){ + $videolist->video_id = $_SESSION['candidate_profile_video']; + + // Now set the video title and description appropriately + $videolist->title = getVimeoInfoDataTitle($_SESSION['candidate_profile_video']); + $videolist->desc = getVimeoInfoDataDesc($_SESSION['candidate_profile_video']); + $videolist->thumbnail = getVimeoInfoImage($_SESSION['candidate_profile_video']); + $videolist->videotype = "vimeo"; +} + +// Before we can set metadata, we need to save the blog post +if (!$videolist->save()) { + register_error(elgg_echo("videolist:error")); + forward("pg/videolist/new"); +} +//add video tags +$videolist_tags_array = string_to_tag_array($_SESSION['videolisttags']); +if (is_array($videolist_tags_array)) { + $videolist->tags = $videolist_tags_array; +} + +// add to river +add_to_river('river/object/videolist/create', 'create', $_SESSION['user']->guid, $videolist->guid); + +// add_to_river('river/object/blog/create','create',$_SESSION['user']->guid,$blog->guid); +// Success message +system_message(elgg_echo("videolist:posted")); // Remove the videolist cache - unset($_SESSION['candidate_profile_video_access_id']); unset($_SESSION['candidate_profile_video']); - unset($_SESSION['videolisttags']);unset($_SESSION['Pagecontainer']);unset($_SESSION['container_guid']); +unset($_SESSION['candidate_profile_video_access_id']); unset($_SESSION['candidate_profile_video']); +unset($_SESSION['videolisttags']);unset($_SESSION['Pagecontainer']); +// Forward to the main videolist page -?> +forward("pg/videolist/owned/".page_owner_entity()->username); + +// Remove the videolist cache +unset($_SESSION['candidate_profile_video_access_id']); unset($_SESSION['candidate_profile_video']); +unset($_SESSION['videolisttags']);unset($_SESSION['Pagecontainer']);unset($_SESSION['container_guid']); diff --git a/actions/comments_delete/add.php b/actions/comments_delete/add.php index d65e6c05b..209561e04 100644 --- a/actions/comments_delete/add.php +++ b/actions/comments_delete/add.php @@ -1,58 +1,51 @@ - * @copyright Curverider Ltd 2008-2009 - * @link http://elgg.org/ - */ +/** + * Elgg add comment action + * + * @package Elgg + * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2 + * @author Curverider + * @copyright Curverider Ltd 2008-2009 + * @link http://elgg.org/ + */ - // Make sure we're logged in; forward to the front page if not - gatekeeper(); - action_gatekeeper(); - - // Get input - $entity_guid = (int) get_input('entity_guid'); - $comment_text = get_input('generic_comment'); - - // Let's see if we can get an entity with the specified GUID - if ($entity = get_entity($entity_guid)) { - - // If posting the comment was successful, say so - if ($entity->annotate('generic_comment',$comment_text,$entity->access_id, $_SESSION['guid'])) { - - if ($entity->owner_guid != $_SESSION['user']->getGUID()) - notify_user($entity->owner_guid, $_SESSION['user']->getGUID(), elgg_echo('generic_comment:email:subject'), - sprintf( - elgg_echo('generic_comment:email:body'), - $entity->title, - $_SESSION['user']->name, - $comment_text, - $entity->getURL(), - $_SESSION['user']->name, - $_SESSION['user']->getURL() - ) - ); - - system_message(elgg_echo("generic_comment:posted")); - //add to river - add_to_river('annotation/annotate','comment',$_SESSION['user']->guid,$entity->guid); +// Make sure we're logged in; forward to the front page if not +gatekeeper(); +action_gatekeeper(); - - } else { - register_error(elgg_echo("generic_comment:failure")); - } - - } else { - - register_error(elgg_echo("generic_comment:notfound")); - +// Get input +$entity_guid = (int) get_input('entity_guid'); +$comment_text = get_input('generic_comment'); + +// Let's see if we can get an entity with the specified GUID +if ($entity = get_entity($entity_guid)) { + // If posting the comment was successful, say so + if ($entity->annotate('generic_comment',$comment_text,$entity->access_id, $_SESSION['guid'])) { + + if ($entity->owner_guid != $_SESSION['user']->getGUID()) { + notify_user($entity->owner_guid, $_SESSION['user']->getGUID(), elgg_echo('generic_comment:email:subject'), + sprintf( + elgg_echo('generic_comment:email:body'), + $entity->title, + $_SESSION['user']->name, + $comment_text, + $entity->getURL(), + $_SESSION['user']->name, + $_SESSION['user']->getURL() + ) + ); } - - // Forward to the - forward($_SERVER['HTTP_REFERER']); -?> + system_message(elgg_echo("generic_comment:posted")); + //add to river + add_to_river('annotation/annotate','comment',$_SESSION['user']->guid,$entity->guid); + } else { + register_error(elgg_echo("generic_comment:failure")); + } +} else { + register_error(elgg_echo("generic_comment:notfound")); +} + +// Forward to the +forward($_SERVER['HTTP_REFERER']); \ No newline at end of file diff --git a/actions/delete.php b/actions/delete.php index 3b5b6ddde..e98e81b67 100644 --- a/actions/delete.php +++ b/actions/delete.php @@ -1,44 +1,41 @@ - * @copyright Prateek Choudhary - */ + * Elgg Videolist Plugin - + * This plugin allows users to delete videos + * + * @package Elgg + * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2 + * @author Prateek Choudhary + * @copyright Prateek Choudhary + */ // Make sure we're logged in (send us to the front page if not) gatekeeper(); - - // Get the current page's owner - $page_owner = page_owner_entity(); - if ($page_owner === false || is_null($page_owner)) { - $page_owner = $_SESSION['user']; - set_page_owner($_SESSION['guid']); - } - // Get input data - $guid = (int) get_input('video_id'); +// Get the current page's owner +$page_owner = page_owner_entity(); +if ($page_owner === false || is_null($page_owner)) { + $page_owner = $_SESSION['user']; + set_page_owner($_SESSION['guid']); +} - // Make sure we actually have permission to edit - $videos = get_entity($guid); - if ($videos->getSubtype() == "videolist" && $videos->canEdit()) { - - // Get owning user - $owner = get_entity($videos->getOwner()); - // Delete it! - $rowsaffected = $videos->delete(); - if ($rowsaffected > 0) { +// Get input data +$guid = (int) get_input('video_id'); + +// Make sure we actually have permission to edit +$videos = get_entity($guid); +if ($videos->getSubtype() == "videolist" && $videos->canEdit()) { + // Get owning user + $owner = get_entity($videos->getOwner()); + + // Delete it! + $rowsaffected = $videos->delete(); + if ($rowsaffected > 0) { // Success message - system_message(elgg_echo("videos:deleted")); - } else { - register_error(elgg_echo("videos:notdeleted")); - } - // Forward to the main video list page - //forward("pg/videolist/owned/" . page_owner_entity()->username); - forward($_SERVER['HTTP_REFERER']); - - } - -?> + system_message(elgg_echo("videos:deleted")); + } else { + register_error(elgg_echo("videos:notdeleted")); + } + // Forward to the main video list page + //forward("pg/videolist/owned/" . page_owner_entity()->username); + forward($_SERVER['HTTP_REFERER']); +} \ No newline at end of file diff --git a/actions/save.php b/actions/save.php index fa6ff585e..3f7391fbf 100644 --- a/actions/save.php +++ b/actions/save.php @@ -1,16 +1,11 @@ - * @copyright Prateek Choudhary - */ - - - -?> +/** + * Elgg Candidate Profile Video Plugin + * This plugin allows users to create a library of youtube videos + * + * @package ElggProfile + * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2 + * @author Prateek Choudhary + * @copyright Prateek Choudhary + */ diff --git a/actions/tubesearch.php b/actions/tubesearch.php index 3930aaaa0..51bc6a990 100644 --- a/actions/tubesearch.php +++ b/actions/tubesearch.php @@ -1,109 +1,108 @@ - - * @copyright Prateek Choudhary - */ - -// Get the current page's owner + + * @copyright Prateek Choudhary + */ + +// Get the current page's owner //set_page_owner($_SESSION['container_guid']); $page_ownerx = get_entity(get_input('container')); -if(!$page_ownerx) +if(!$page_ownerx) { $page_ownerx = get_user_by_username(get_input('container')); +} set_page_owner($page_ownerx->getGUID()); $page_owner = page_owner_entity(); -if($page_owner->type == "group") +if($page_owner->type == "group") { $container = "group:".$page_ownerx->getGUID(); -else +} else { $container = $page_ownerx->username; +} if ($page_owner === false || is_null($page_owner)) { $page_owner = $_SESSION['user']; set_page_owner($_SESSION['guid']); } -global $CONFIG; - $queryFeed = get_input('q'); - $start_index = get_input('start_index'); - $results_perpage = 10; - $queryCatgory = get_input('page'); +global $CONFIG; +$queryFeed = get_input('q'); +$start_index = get_input('start_index'); +$results_perpage = 10; +$queryCatgory = get_input('page'); if (!isset($queryFeed) || empty($queryFeed)) { - -} -else -{ - $q = $queryFeed; - if($queryCatgory == "youtube") - { - $feedURL = "http://gdata.youtube.com/feeds/api/videos?vq=".$queryFeed."&orderby=relevance&start-index=".$start_index."&max-results=10"; - $sxml = simplexml_load_file($feedURL); - - $counts = $sxml->children('http://a9.com/-/spec/opensearchrss/1.0/'); - $total = $counts->totalResults; - $startOffset = $counts->startIndex; - $endOffset = ($startOffset-1) + $counts->itemsPerPage; - - $body = '
'; - $rem = floor($total/10); - $rem*=10; - if($rem<$total) - $last = $rem+1; - $lpVid = $total - $rem; - if($startOffset==1 && ($endOffset)==$total){} - else if($startOffset==1 && ($endOffset)<$total){ - $body .= 'first | '; - $body .= 'previous | '; - $body .= 'next | '; - $body .= 'last'; - } - else if($startOffset>1 && ($endOffset)<$total){ - $body .= 'first | '; - $body .= 'previous | '; - $body .= 'next | '; - $body .= 'last'; - } - else if($startOffset>1 && ($endOffset+$lpVid)>=$total){ - $body .= 'first | '; - $body .= 'previous | '; - $body .= 'next | '; - $body .= 'last'; - } - $body .= '
'; - $body .= '
'; - $k = 0;$counter = 0; - foreach ($sxml->entry as $entry) { - $k++; - $media = $entry->children('http://search.yahoo.com/mrss/'); - $attrs = $media->group->player->attributes(); - $watch = $attrs['url']; - $vid_array = explode("?v=", $watch); - if(preg_match("/&/", $vid_array[1])){ - $vid_array = explode("&", $vid_array[1]); - $vid_array[1] = $vid_array[0]; - } - - $attrs = $media->group->thumbnail[0]->attributes(); - $thumbnail = $attrs['url']; - $yt = $media->children('http://gdata.youtube.com/schemas/2007'); - $attrs = $yt->duration->attributes(); - $length = $attrs['seconds']; - $gd = $entry->children('http://schemas.google.com/g/2005'); - if ($gd->rating) { - $attrs = $gd->rating->attributes(); - $rating = $attrs['average']; - } else { - $rating = 0; - } - $tags = array(); - $tags[] = $media->group->keywords; - $showEncodedVideo = preg_replace('/(http:)(\/\/)(www.)([^ \/"]*)([^ >"]*)watch\?(v=)([^ >"]*)/i', '$1$2$3$4$5v/$7', $watch); + +} else { + $q = $queryFeed; + if($queryCatgory == "youtube") { + $feedURL = "http://gdata.youtube.com/feeds/api/videos?vq=".$queryFeed."&orderby=relevance&start-index=".$start_index."&max-results=10"; + $sxml = simplexml_load_file($feedURL); + + $counts = $sxml->children('http://a9.com/-/spec/opensearchrss/1.0/'); + $total = $counts->totalResults; + $startOffset = $counts->startIndex; + $endOffset = ($startOffset-1) + $counts->itemsPerPage; + + $body = '
'; + $rem = floor($total/10); + $rem*=10; + if($rem<$total) + $last = $rem+1; + $lpVid = $total - $rem; + if($startOffset==1 && ($endOffset)==$total){} + else if($startOffset==1 && ($endOffset)<$total){ + $body .= 'first | '; + $body .= 'previous | '; + $body .= 'next | '; + $body .= 'last'; + } + else if($startOffset>1 && ($endOffset)<$total){ + $body .= 'first | '; + $body .= 'previous | '; + $body .= 'next | '; + $body .= 'last'; + } + else if($startOffset>1 && ($endOffset+$lpVid)>=$total){ + $body .= 'first | '; + $body .= 'previous | '; + $body .= 'next | '; + $body .= 'last'; + } + $body .= '
'; + $body .= '
'; + $k = 0;$counter = 0; + foreach ($sxml->entry as $entry) { + $k++; + $media = $entry->children('http://search.yahoo.com/mrss/'); + $attrs = $media->group->player->attributes(); + $watch = $attrs['url']; + $vid_array = explode("?v=", $watch); + if(preg_match("/&/", $vid_array[1])){ + $vid_array = explode("&", $vid_array[1]); + $vid_array[1] = $vid_array[0]; + } + + $attrs = $media->group->thumbnail[0]->attributes(); + $thumbnail = $attrs['url']; + $yt = $media->children('http://gdata.youtube.com/schemas/2007'); + $attrs = $yt->duration->attributes(); + $length = $attrs['seconds']; + $gd = $entry->children('http://schemas.google.com/g/2005'); + if ($gd->rating) { + $attrs = $gd->rating->attributes(); + $rating = $attrs['average']; + } else { + $rating = 0; + } + $tags = array(); + $tags[] = $media->group->keywords; + + $showEncodedVideo = preg_replace('/(http:)(\/\/)(www.)([^ \/"]*)([^ >"]*)watch\?(v=)([^ >"]*)/i', '$1$2$3$4$5v/$7', $watch); $body .= '
'; $body .= ''; @@ -123,208 +122,201 @@ else $body .= ''; $body .= '
'; - } + } $body .= '
'; print $body; + } else if($queryCatgory == "metacafe") { + $feedURL = "http://www.metacafe.com/api/videos/?vq=".$queryFeed."&orderby=rating&start-index=".$start_index."&max-results=10"; + + $sxml = new DomDocument; + $sxml->load($feedURL); + $total = 999; + $startOffset = $start_index; + $endOffset = ($startOffset-1) + $results_perpage; + + $body = '
'; + $rem = floor($total/10); + $rem*=10; + if($rem<$total) { + $last = $rem+1; } - else if($queryCatgory == "metacafe") - { - - - $feedURL = "http://www.metacafe.com/api/videos/?vq=".$queryFeed."&orderby=rating&start-index=".$start_index."&max-results=10"; - - - $sxml = new DomDocument; - $sxml->load($feedURL); - $total = 999; - $startOffset = $start_index; - $endOffset = ($startOffset-1) + $results_perpage; - - $body = '
'; - $rem = floor($total/10); - $rem*=10; - if($rem<$total) - $last = $rem+1; - $lpVid = $total - $rem; - if($startOffset==1 && ($endOffset)==$total){} - else if($startOffset==1 && ($endOffset)<$total){ - $body .= 'first | '; - $body .= 'previous | '; - $body .= 'next | '; - $body .= 'last'; - } - else if($startOffset>1 && ($endOffset)<$total){ + $lpVid = $total - $rem; + if($startOffset==1 && ($endOffset)==$total) { + + } else if($startOffset==1 && ($endOffset)<$total){ + $body .= 'first | '; + $body .= 'previous | '; + $body .= 'next | '; + $body .= 'last'; + } else if($startOffset>1 && ($endOffset)<$total) { $body .= 'first | '; $body .= 'previous | '; $body .= 'next | '; $body .= 'last'; - } - else if($startOffset>1 && ($endOffset+$lpVid)>=$total){ + } else if($startOffset>1 && ($endOffset+$lpVid)>=$total) { $body .= 'first | '; $body .= 'previous | '; $body .= 'next | '; $body .= 'last'; - } - $body .= '
'; - $k = 0; - $body .= '
'; - $myitem = $sxml->getElementsByTagName('item'); - foreach($myitem as $searchNode){ - $k++; - $xmlTitle = $searchNode->getElementsByTagName("title"); - $valueTitle = $xmlTitle->item(0)->nodeValue; - - $xmlLink = $searchNode->getElementsByTagName("link"); - $valueLink = $xmlLink->item(0)->nodeValue; - - $xmlDesc = $searchNode->getElementsByTagName("description"); - $valueDesc = $xmlDesc->item(0)->nodeValue; - - $pattern = '/]+src[\\s=\'"]'; - $pattern .= '+([^"\'>\\s]+)/is'; - if(preg_match($pattern,$valueDesc,$match)){ - $thumbnail = $match[1]; + } + + $body .= '
'; + $k = 0; + $body .= '
'; + $myitem = $sxml->getElementsByTagName('item'); + foreach($myitem as $searchNode) { + $k++; + $xmlTitle = $searchNode->getElementsByTagName("title"); + $valueTitle = $xmlTitle->item(0)->nodeValue; + + $xmlLink = $searchNode->getElementsByTagName("link"); + $valueLink = $xmlLink->item(0)->nodeValue; + + $xmlDesc = $searchNode->getElementsByTagName("description"); + $valueDesc = $xmlDesc->item(0)->nodeValue; + + $pattern = '/]+src[\\s=\'"]'; + $pattern .= '+([^"\'>\\s]+)/is'; + if(preg_match($pattern,$valueDesc,$match)){ + $thumbnail = $match[1]; + } + + $pattern = '/]+href[\\s=\'"]'; + $pattern .= '+([^"\'>\\s]+)/is'; + if(preg_match($pattern,$valueDesc,$match)){ + $anchor_src = $match[1]; + } + + $encodedVideoUrlArray = explode("/watch/", $valueLink); + $showEncodedVideo = $encodedVideoUrlArray[1]; + $metacafevideoIdArray = explode("/", $showEncodedVideo); + + $ot = "

"; + $ct = "

"; + $string = trim($valueDesc); + $start = intval(strpos($string, $ot) + strlen($ot)); + $desc_src = substr($string,$start,intval(strpos($string,$ct) - $start)); + + $body .= '
'; + $body .= ''; + $body .= ''; + + $body .= ''; + + $body .= ''; + + //$body .= ""; + + $body .= ""; + + $body .= ''; + $body .= '
'; + $body .= ""; + $body .= '
'; + $body .= "".$valueTitle."
"; + //$body .= "Duration : " . sprintf("%0.2f", $length/60) . " min.
user rating : ".$rating."
"; + $body .= "Description : ".$desc_src; + $body .= '
play | add wwwroot."pg/videolist/new/".$container."/title_videourl/".$metacafevideoIdArray[0]."/page/".$queryCatgory."\");\">
'; + $body .= '
'; + } + $body .= '
'; + print $body; + } else if($queryCatgory == "vimeo") { + require_once(dirname(dirname(__FILE__)) . "/models/lib/class.vimeo.php"); + // Now lets do the search query. We will get an response object containing everything we need + $oResponse = VimeoVideosRequest::search($queryFeed); + + // We want the result videos as an array of objects + $aoVideos = $oResponse->getVideos(); + + // Just for code completion + $oVideo = new VimeoVideoEntity(); + + $total = count($aoVideos); + $startOffset = $start_index; + + $endOffset = ($startOffset-1) + $results_perpage; + $body = '
'; + $rem = floor($total/10); + $rem*=10; + if($rem<$total) { + $last = $rem+1; + } + $lpVid = $total - $rem; + if($startOffset==1 && ($endOffset)==$total) { + + } else if($startOffset==1 && ($endOffset)<$total) { + $body .= 'first | '; + $body .= 'previous | '; + $body .= 'next | '; + $body .= 'last'; + } else if($startOffset>1 && ($endOffset)<$total) { + $body .= 'first | '; + $body .= 'previous | '; + $body .= 'next | '; + $body .= 'last'; + } else if($startOffset>1 && ($endOffset+$lpVid)>=$total) { + $body .= 'first | '; + $body .= 'previous | '; + $body .= 'next | '; + $body .= 'last'; + } + $body .= '
'; + $body .= '
'; + $counter = 0;$k = 0; + foreach($aoVideos as $oVideo) { + $k++; + if(($counter > $startOffset) && ($counter < $endOffset)) { + //get all thumbnails + $aThumbnails = array(); + foreach($oVideo->getThumbnails() as $oThumbs) { + $aThumbnails[] = $oThumbs->getImageContent(); } - - $pattern = '/]+href[\\s=\'"]'; - $pattern .= '+([^"\'>\\s]+)/is'; - if(preg_match($pattern,$valueDesc,$match)){ - $anchor_src = $match[1]; + + foreach($aThumbnails as $thumbnailArray){ + $thumbnail = $thumbnailArray; + break; + } + //print_r($oVideo); + $title = $oVideo->getTitle(); + $description = $oVideo->getCaption(); + $url = $oVideo->getUrl(); + $rating = $oVideo->getNumberOfLikes(); + $playedTimes = $oVideo->getNumberOfPlays(); + // Print all tags + $aTags = array(); + foreach($oVideo->getTags() as $oTag) { + $aTags[] = $oTag->getTag(); } - - $encodedVideoUrlArray = explode("/watch/", $valueLink); - $showEncodedVideo = $encodedVideoUrlArray[1]; - $metacafevideoIdArray = explode("/", $showEncodedVideo); - - $ot = "

"; - $ct = "

"; - $string = trim($valueDesc); - $start = intval(strpos($string, $ot) + strlen($ot)); - $desc_src = substr($string,$start,intval(strpos($string,$ct) - $start)); - + $play_idArray = explode("http://vimeo.com/", $url); + $embedidArray = explode("/", $play_idArray[1]); $body .= '
'; $body .= ''; $body .= ''; $body .= ''; $body .= ''; - //$body .= ""; - - $body .= ""; + $body .= ""; $body .= ''; $body .= '
'; - $body .= ""; + $body .= ""; $body .= '
'; - $body .= "".$valueTitle."
"; - //$body .= "Duration : " . sprintf("%0.2f", $length/60) . " min.
user rating : ".$rating."
"; - $body .= "Description : ".$desc_src; + $body .= "".$title."
"; + $body .= "User Likes : ".$rating."
"; + $body .= "Played : ".$playedTimes." times
"; + $body .= "Description : ".$description." ...
"; + $body .= "Tags : ".implode(', ', $aTags); $body .= '
play | add wwwroot."pg/videolist/new/".$container."/title_videourl/".$metacafevideoIdArray[0]."/page/".$queryCatgory."\");\"> wwwroot."pg/videolist/new/".$container."/title_videourl/".$embedidArray[0]."/page/".$queryCatgory."\");\">
'; $body .= '
'; } - $body .= '
'; - print $body; + $counter++; } - else if($queryCatgory == "vimeo") - { - require_once(dirname(dirname(__FILE__)) . "/models/lib/class.vimeo.php"); - // Now lets do the search query. We will get an response object containing everything we need - $oResponse = VimeoVideosRequest::search($queryFeed); - - // We want the result videos as an array of objects - $aoVideos = $oResponse->getVideos(); - - // Just for code completion - $oVideo = new VimeoVideoEntity(); - - $total = count($aoVideos); - $startOffset = $start_index; - - $endOffset = ($startOffset-1) + $results_perpage; - $body = '
'; - $rem = floor($total/10); - $rem*=10; - if($rem<$total) - $last = $rem+1; - $lpVid = $total - $rem; - if($startOffset==1 && ($endOffset)==$total){} - else if($startOffset==1 && ($endOffset)<$total){ - $body .= 'first | '; - $body .= 'previous | '; - $body .= 'next | '; - $body .= 'last'; - } - else if($startOffset>1 && ($endOffset)<$total){ - $body .= 'first | '; - $body .= 'previous | '; - $body .= 'next | '; - $body .= 'last'; - } - else if($startOffset>1 && ($endOffset+$lpVid)>=$total){ - $body .= 'first | '; - $body .= 'previous | '; - $body .= 'next | '; - $body .= 'last'; - } - $body .= '
'; - $body .= '
'; - $counter = 0;$k = 0; - foreach($aoVideos as $oVideo) { - $k++; - if(($counter > $startOffset) && ($counter < $endOffset)) - { - //get all thumbnails - $aThumbnails = array(); - foreach($oVideo->getThumbnails() as $oThumbs) { - $aThumbnails[] = $oThumbs->getImageContent(); - } - - foreach($aThumbnails as $thumbnailArray){ - $thumbnail = $thumbnailArray; - break; - } - //print_r($oVideo); - $title = $oVideo->getTitle(); - $description = $oVideo->getCaption(); - $url = $oVideo->getUrl(); - $rating = $oVideo->getNumberOfLikes(); - $playedTimes = $oVideo->getNumberOfPlays(); - // Print all tags - $aTags = array(); - foreach($oVideo->getTags() as $oTag) { - $aTags[] = $oTag->getTag(); - } - $play_idArray = explode("http://vimeo.com/", $url); - $embedidArray = explode("/", $play_idArray[1]); - $body .= '
'; - $body .= ''; - $body .= ''; - - $body .= ''; - - $body .= ''; - - $body .= ""; - - $body .= ''; - $body .= '
'; - $body .= ""; - $body .= '
'; - $body .= "".$title."
"; - $body .= "User Likes : ".$rating."
"; - $body .= "Played : ".$playedTimes." times
"; - $body .= "Description : ".$description." ...
"; - $body .= "Tags : ".implode(', ', $aTags); - $body .= '
wwwroot."pg/videolist/new/".$container."/title_videourl/".$embedidArray[0]."/page/".$queryCatgory."\");\">
'; - $body .= '
'; - } - $counter++; - } - $body .= '
'; - print $body; - } + $body .= '
'; + print $body; + } } -exit; -?> + +exit; \ No newline at end of file -- cgit v1.2.3