|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 00027 require_once('Zend/Gdata/YouTube.php'); 00028 00032 require_once('Zend/Gdata/Query.php'); 00033 00045 class Zend_Gdata_YouTube_VideoQuery extends Zend_Gdata_Query 00046 { 00047 00051 public function __construct($url = null) 00052 { 00053 parent::__construct($url); 00054 } 00055 00063 public function setFeedType($feedType, $videoId = null, $entry = null) 00064 { 00065 switch ($feedType) { 00066 case 'top rated': 00067 $this->_url = Zend_Gdata_YouTube::STANDARD_TOP_RATED_URI; 00068 break; 00069 case 'most viewed': 00070 $this->_url = Zend_Gdata_YouTube::STANDARD_MOST_VIEWED_URI; 00071 break; 00072 case 'recently featured': 00073 $this->_url = Zend_Gdata_YouTube::STANDARD_RECENTLY_FEATURED_URI; 00074 break; 00075 case 'mobile': 00076 $this->_url = Zend_Gdata_YouTube::STANDARD_WATCH_ON_MOBILE_URI; 00077 break; 00078 case 'related': 00079 if ($videoId === null) { 00080 require_once 'Zend/Gdata/App/InvalidArgumentException.php'; 00081 throw new Zend_Gdata_App_InvalidArgumentException( 00082 'Video ID must be set for feed of type: ' . $feedType); 00083 } else { 00084 $this->_url = Zend_Gdata_YouTube::VIDEO_URI . '/' . $videoId . 00085 '/related'; 00086 } 00087 break; 00088 case 'responses': 00089 if ($videoId === null) { 00090 require_once 'Zend/Gdata/App/InvalidArgumentException.php'; 00091 throw new Zend_Gdata_App_Exception( 00092 'Video ID must be set for feed of type: ' . $feedType); 00093 } else { 00094 $this->_url = Zend_Gdata_YouTube::VIDEO_URI . '/' . $videoId . 00095 'responses'; 00096 } 00097 break; 00098 case 'comments': 00099 if ($videoId === null) { 00100 require_once 'Zend/Gdata/App/InvalidArgumentException.php'; 00101 throw new Zend_Gdata_App_Exception( 00102 'Video ID must be set for feed of type: ' . $feedType); 00103 } else { 00104 $this->_url = Zend_Gdata_YouTube::VIDEO_URI . '/' . 00105 $videoId . 'comments'; 00106 if ($entry !== null) { 00107 $this->_url .= '/' . $entry; 00108 } 00109 } 00110 break; 00111 default: 00112 require_once 'Zend/Gdata/App/Exception.php'; 00113 throw new Zend_Gdata_App_Exception('Unknown feed type'); 00114 break; 00115 } 00116 } 00117 00125 public function setLocation($value) 00126 { 00127 switch($value) { 00128 case null: 00129 unset($this->_params['location']); 00130 default: 00131 $parameters = explode(',', $value); 00132 if (count($parameters) != 2) { 00133 require_once 'Zend/Gdata/App/InvalidArgumentException.php'; 00134 throw new Zend_Gdata_App_InvalidArgumentException( 00135 'You must provide 2 coordinates to the location ' . 00136 'URL parameter'); 00137 } 00138 00139 foreach($parameters as $param) { 00140 $temp = trim($param); 00141 // strip off the optional exclamation mark for numeric check 00142 if (substr($temp, -1) == '!') { 00143 $temp = substr($temp, 0, -1); 00144 } 00145 if (!is_numeric($temp)) { 00146 require_once 'Zend/Gdata/App/InvalidArgumentException.php'; 00147 throw new Zend_Gdata_App_InvalidArgumentException( 00148 'Value provided to location parameter must' . 00149 ' be in the form of two coordinates'); 00150 } 00151 } 00152 $this->_params['location'] = $value; 00153 } 00154 } 00155 00161 public function getLocation() 00162 { 00163 if (array_key_exists('location', $this->_params)) { 00164 return $this->_params['location']; 00165 } else { 00166 return null; 00167 } 00168 } 00169 00170 00177 public function setLocationRadius($value) 00178 { 00179 switch($value) { 00180 case null: 00181 unset($this->_params['location-radius']); 00182 default: 00183 $this->_params['location-radius'] = $value; 00184 } 00185 } 00186 00193 public function getLocationRadius() 00194 { 00195 if (array_key_exists('location-radius', $this->_params)) { 00196 return $this->_params['location-radius']; 00197 } else { 00198 return null; 00199 } 00200 } 00201 00209 public function setTime($value = null) 00210 { 00211 switch ($value) { 00212 case 'today': 00213 $this->_params['time'] = 'today'; 00214 break; 00215 case 'this_week': 00216 $this->_params['time'] = 'this_week'; 00217 break; 00218 case 'this_month': 00219 $this->_params['time'] = 'this_month'; 00220 break; 00221 case 'all_time': 00222 $this->_params['time'] = 'all_time'; 00223 break; 00224 case null: 00225 unset($this->_params['time']); 00226 default: 00227 require_once 'Zend/Gdata/App/InvalidArgumentException.php'; 00228 throw new Zend_Gdata_App_InvalidArgumentException( 00229 'Unknown time value'); 00230 break; 00231 } 00232 return $this; 00233 } 00234 00243 public function setUploader($value = null) 00244 { 00245 switch ($value) { 00246 case 'partner': 00247 $this->_params['uploader'] = 'partner'; 00248 break; 00249 case null: 00250 unset($this->_params['uploader']); 00251 break; 00252 default: 00253 require_once 'Zend/Gdata/App/InvalidArgumentException.php'; 00254 throw new Zend_Gdata_App_InvalidArgumentException( 00255 'Unknown value for uploader'); 00256 } 00257 return $this; 00258 } 00259 00266 public function setVideoQuery($value = null) 00267 { 00268 if ($value != null) { 00269 $this->_params['vq'] = $value; 00270 } else { 00271 unset($this->_params['vq']); 00272 } 00273 return $this; 00274 } 00275 00282 public function setFormat($value = null) 00283 { 00284 if ($value != null) { 00285 $this->_params['format'] = $value; 00286 } else { 00287 unset($this->_params['format']); 00288 } 00289 return $this; 00290 } 00291 00298 public function setRacy($value = null) 00299 { 00300 switch ($value) { 00301 case 'include': 00302 $this->_params['racy'] = $value; 00303 break; 00304 case 'exclude': 00305 $this->_params['racy'] = $value; 00306 break; 00307 case null: 00308 unset($this->_params['racy']); 00309 break; 00310 } 00311 return $this; 00312 } 00313 00319 public function getRacy() 00320 { 00321 if (array_key_exists('racy', $this->_params)) { 00322 return $this->_params['racy']; 00323 } else { 00324 return null; 00325 } 00326 } 00327 00336 public function setSafeSearch($value) 00337 { 00338 switch ($value) { 00339 case 'none': 00340 $this->_params['safeSearch'] = 'none'; 00341 break; 00342 case 'moderate': 00343 $this->_params['safeSearch'] = 'moderate'; 00344 break; 00345 case 'strict': 00346 $this->_params['safeSearch'] = 'strict'; 00347 break; 00348 case null: 00349 unset($this->_params['safeSearch']); 00350 default: 00351 require_once 'Zend/Gdata/App/InvalidArgumentException.php'; 00352 throw new Zend_Gdata_App_InvalidArgumentException( 00353 'The safeSearch parameter only supports the values '. 00354 '\'none\', \'moderate\' or \'strict\'.'); 00355 } 00356 } 00357 00364 public function getSafeSearch() 00365 { 00366 if (array_key_exists('safeSearch', $this->_params)) { 00367 return $this->_params['safeSearch']; 00368 } 00369 return $this; 00370 } 00371 00378 public function setOrderBy($value) 00379 { 00380 if ($value != null) { 00381 $this->_params['orderby'] = $value; 00382 } else { 00383 unset($this->_params['orderby']); 00384 } 00385 return $this; 00386 } 00387 00393 public function getFormat() 00394 { 00395 if (array_key_exists('format', $this->_params)) { 00396 return $this->_params['format']; 00397 } else { 00398 return null; 00399 } 00400 } 00401 00408 public function getVideoQuery() 00409 { 00410 if (array_key_exists('vq', $this->_params)) { 00411 return $this->_params['vq']; 00412 } else { 00413 return null; 00414 } 00415 } 00416 00422 public function getTime() 00423 { 00424 if (array_key_exists('time', $this->_params)) { 00425 return $this->_params['time']; 00426 } else { 00427 return null; 00428 } 00429 } 00430 00436 public function getOrderBy() 00437 { 00438 if (array_key_exists('orderby', $this->_params)) { 00439 return $this->_params['orderby']; 00440 } else { 00441 return null; 00442 } 00443 } 00444 00454 public function getQueryString($majorProtocolVersion = null, 00455 $minorProtocolVersion = null) 00456 { 00457 $queryArray = array(); 00458 00459 foreach ($this->_params as $name => $value) { 00460 if (substr($name, 0, 1) == '_') { 00461 continue; 00462 } 00463 00464 switch($name) { 00465 case 'location-radius': 00466 if ($majorProtocolVersion == 1) { 00467 require_once 'Zend/Gdata/App/VersionException.php'; 00468 throw new Zend_Gdata_App_VersionException("The $name " . 00469 "parameter is only supported in version 2."); 00470 } 00471 break; 00472 00473 case 'racy': 00474 if ($majorProtocolVersion == 2) { 00475 require_once 'Zend/Gdata/App/VersionException.php'; 00476 throw new Zend_Gdata_App_VersionException("The $name " . 00477 "parameter is not supported in version 2. " . 00478 "Please use 'safeSearch'."); 00479 } 00480 break; 00481 00482 case 'safeSearch': 00483 if ($majorProtocolVersion == 1) { 00484 require_once 'Zend/Gdata/App/VersionException.php'; 00485 throw new Zend_Gdata_App_VersionException("The $name " . 00486 "parameter is only supported in version 2. " . 00487 "Please use 'racy'."); 00488 } 00489 break; 00490 00491 case 'uploader': 00492 if ($majorProtocolVersion == 1) { 00493 require_once 'Zend/Gdata/App/VersionException.php'; 00494 throw new Zend_Gdata_App_VersionException("The $name " . 00495 "parameter is only supported in version 2."); 00496 } 00497 break; 00498 00499 case 'vq': 00500 if ($majorProtocolVersion == 2) { 00501 $name = 'q'; 00502 } 00503 break; 00504 } 00505 00506 $queryArray[] = urlencode($name) . '=' . urlencode($value); 00507 00508 } 00509 if (count($queryArray) > 0) { 00510 return '?' . implode('&', $queryArray); 00511 } else { 00512 return ''; 00513 } 00514 } 00515 00524 public function getQueryUrl($majorProtocolVersion = null, 00525 $minorProtocolVersion = null) 00526 { 00527 if (isset($this->_url)) { 00528 $url = $this->_url; 00529 } else { 00530 $url = Zend_Gdata_YouTube::VIDEO_URI; 00531 } 00532 if ($this->getCategory() !== null) { 00533 $url .= '/-/' . $this->getCategory(); 00534 } 00535 $url = $url . $this->getQueryString($majorProtocolVersion, 00536 $minorProtocolVersion); 00537 return $url; 00538 } 00539 00540 }