aboutsummaryrefslogtreecommitdiff
path: root/actions/addvideo.php
blob: 519f6ae04ffd1addbaf7264cbe7c29f28d23fc75 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
<?php

	 /**
	 * 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 <synapticfield@gmail.com>
	 * @copyright Prateek Choudhary
	 */
		
// Make sure we're logged in (send us to the front page if not)
gatekeeper();

// Get the current page's owner	
set_page_owner($_SESSION['container_guid']);

$page_owner = page_owner_entity();

if ($page_owner === false || is_null($page_owner)) {
	$page_owner = $_SESSION['user'];
	set_page_owner($_SESSION['guid']);
}

if($page_owner->type == "group")
	$entity_referer = $page_owner->type.":".$page_owner->getGUID();
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 
	**/
	$xml_buffer = new SimpleXMLElement($buffer);
 $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 "";          
}

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;
}

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;
}

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;
}

function fetchyoutubeDatathumbnail($videoId){
			$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;
}

function fetchmetacafeTitle($getVideoId){
				$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 = "<p>";
					$ct = "</p>";
					$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 = '/<img[^>]+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);

// 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']);

?>