import v1.1.0_beta1 | 2009-08-21
This commit is contained in:
@ -37,6 +37,7 @@ require_once('Zend/Gdata/Query.php');
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Gdata
|
||||
* @subpackage YouTube
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
@ -47,7 +48,7 @@ class Zend_Gdata_YouTube_VideoQuery extends Zend_Gdata_Query
|
||||
* Create Gdata_YouTube_VideoQuery object
|
||||
*/
|
||||
public function __construct($url = null)
|
||||
{
|
||||
{
|
||||
parent::__construct($url);
|
||||
}
|
||||
|
||||
@ -75,26 +76,32 @@ class Zend_Gdata_YouTube_VideoQuery extends Zend_Gdata_Query
|
||||
break;
|
||||
case 'related':
|
||||
if ($videoId === null) {
|
||||
require_once 'Zend/Gdata/App/Exception.php';
|
||||
throw new Zend_Gdata_App_Exception('Video ID must be set for feed of type: ' . $feedType);
|
||||
require_once 'Zend/Gdata/App/InvalidArgumentException.php';
|
||||
throw new Zend_Gdata_App_InvalidArgumentException(
|
||||
'Video ID must be set for feed of type: ' . $feedType);
|
||||
} else {
|
||||
$this->_url = Zend_Gdata_YouTube::VIDEO_URI . '/' . $videoId . '/related';
|
||||
$this->_url = Zend_Gdata_YouTube::VIDEO_URI . '/' . $videoId .
|
||||
'/related';
|
||||
}
|
||||
break;
|
||||
case 'responses':
|
||||
if ($videoId === null) {
|
||||
require_once 'Zend/Gdata/App/Exception.php';
|
||||
throw new Zend_Gdata_App_Exception('Video ID must be set for feed of type: ' . $feedType);
|
||||
require_once 'Zend/Gdata/App/InvalidArgumentException.php';
|
||||
throw new Zend_Gdata_App_Exception(
|
||||
'Video ID must be set for feed of type: ' . $feedType);
|
||||
} else {
|
||||
$this->_url = Zend_Gdata_YouTube::VIDEO_URI . '/' . $videoId . 'responses';
|
||||
$this->_url = Zend_Gdata_YouTube::VIDEO_URI . '/' . $videoId .
|
||||
'responses';
|
||||
}
|
||||
break;
|
||||
case 'comments':
|
||||
if ($videoId === null) {
|
||||
require_once 'Zend/Gdata/App/Exception.php';
|
||||
throw new Zend_Gdata_App_Exception('Video ID must be set for feed of type: ' . $feedType);
|
||||
require_once 'Zend/Gdata/App/InvalidArgumentException.php';
|
||||
throw new Zend_Gdata_App_Exception(
|
||||
'Video ID must be set for feed of type: ' . $feedType);
|
||||
} else {
|
||||
$this->_url = Zend_Gdata_YouTube::VIDEO_URI . '/' . $videoId . 'comments';
|
||||
$this->_url = Zend_Gdata_YouTube::VIDEO_URI . '/' .
|
||||
$videoId . 'comments';
|
||||
if ($entry !== null) {
|
||||
$this->_url .= '/' . $entry;
|
||||
}
|
||||
@ -107,11 +114,95 @@ class Zend_Gdata_YouTube_VideoQuery extends Zend_Gdata_Query
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets the location parameter for the query
|
||||
*
|
||||
* @param string $value
|
||||
* @throws Zend_Gdata_App_InvalidArgumentException
|
||||
* @return Zend_Gdata_YouTube_VideoQuery Provides a fluent interface
|
||||
*/
|
||||
public function setLocation($value)
|
||||
{
|
||||
switch($value) {
|
||||
case null:
|
||||
unset($this->_params['location']);
|
||||
default:
|
||||
$parameters = explode(',', $value);
|
||||
if (count($parameters) != 2) {
|
||||
require_once 'Zend/Gdata/App/InvalidArgumentException.php';
|
||||
throw new Zend_Gdata_App_InvalidArgumentException(
|
||||
'You must provide 2 coordinates to the location ' .
|
||||
'URL parameter');
|
||||
}
|
||||
|
||||
foreach($parameters as $param) {
|
||||
$temp = trim($param);
|
||||
// strip off the optional exclamation mark for numeric check
|
||||
if (substr($temp, -1) == '!') {
|
||||
$temp = substr($temp, -1);
|
||||
}
|
||||
if (!is_numeric($temp)) {
|
||||
require_once 'Zend/Gdata/App/InvalidArgumentException.php';
|
||||
throw new Zend_Gdata_App_InvalidArgumentException(
|
||||
'Value provided to location parameter must' .
|
||||
' be in the form of two coordinates');
|
||||
}
|
||||
}
|
||||
$this->_params['location'] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the value of the location parameter
|
||||
*
|
||||
* @return string|null Return the location if it exists, null otherwise.
|
||||
*/
|
||||
public function getLocation()
|
||||
{
|
||||
if (array_key_exists('location', $this->_params)) {
|
||||
return $this->_params['location'];
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets the location-radius parameter for the query
|
||||
*
|
||||
* @param string $value
|
||||
* @return Zend_Gdata_YouTube_VideoQuery Provides a fluent interface
|
||||
*/
|
||||
public function setLocationRadius($value)
|
||||
{
|
||||
switch($value) {
|
||||
case null:
|
||||
unset($this->_params['location-radius']);
|
||||
default:
|
||||
$this->_params['location-radius'] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the value of the location-radius parameter
|
||||
*
|
||||
* @return string|null Return the location-radius if it exists,
|
||||
* null otherwise.
|
||||
*/
|
||||
public function getLocationRadius()
|
||||
{
|
||||
if (array_key_exists('location-radius', $this->_params)) {
|
||||
return $this->_params['location-radius'];
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the time period over which this query should apply
|
||||
*
|
||||
* @param string $value
|
||||
* @throws Zend_Gdata_App_InvalidArgumentException
|
||||
* @return Zend_Gdata_YouTube_VideoQuery Provides a fluent interface
|
||||
*/
|
||||
public function setTime($value = null)
|
||||
@ -132,13 +223,39 @@ class Zend_Gdata_YouTube_VideoQuery extends Zend_Gdata_Query
|
||||
case null:
|
||||
unset($this->_params['time']);
|
||||
default:
|
||||
require_once 'Zend/Gdata/App/Exception.php';
|
||||
throw new Zend_Gdata_App_Exception('Unknown time value');
|
||||
require_once 'Zend/Gdata/App/InvalidArgumentException.php';
|
||||
throw new Zend_Gdata_App_InvalidArgumentException(
|
||||
'Unknown time value');
|
||||
break;
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the value of the uploader parameter
|
||||
*
|
||||
* @param string $value The value of the uploader parameter. Currently this
|
||||
* can only be set to the value of 'partner'.
|
||||
* @throws Zend_Gdata_App_InvalidArgumentException
|
||||
* @return Zend_Gdata_YouTube_VideoQuery Provides a fluent interface
|
||||
*/
|
||||
public function setUploader($value = null)
|
||||
{
|
||||
switch ($value) {
|
||||
case 'partner':
|
||||
$this->_params['uploader'] = 'partner';
|
||||
break;
|
||||
case null:
|
||||
unset($this->_params['uploader']);
|
||||
break;
|
||||
default:
|
||||
require_once 'Zend/Gdata/App/InvalidArgumentException.php';
|
||||
throw new Zend_Gdata_App_InvalidArgumentException(
|
||||
'Unknown value for uploader');
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the formatted video query (vq) URL param value
|
||||
*
|
||||
@ -194,6 +311,66 @@ class Zend_Gdata_YouTube_VideoQuery extends Zend_Gdata_Query
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether or not to include racy videos in the search results
|
||||
*
|
||||
* @return string|null The value of racy if it exists, null otherwise.
|
||||
*/
|
||||
public function getRacy()
|
||||
{
|
||||
if (array_key_exists('racy', $this->_params)) {
|
||||
return $this->_params['racy'];
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the safeSearch parameter
|
||||
*
|
||||
* @param string $value The value of the parameter, currently only 'none',
|
||||
* 'moderate' or 'strict' are allowed values.
|
||||
* @throws Zend_Gdata_App_InvalidArgumentException
|
||||
* @return Zend_Gdata_YouTube_VideoQuery Provides a fluent interface
|
||||
*/
|
||||
public function setSafeSearch($value)
|
||||
{
|
||||
switch ($value) {
|
||||
case 'none':
|
||||
$this->_params['safeSearch'] = 'none';
|
||||
break;
|
||||
case 'moderate':
|
||||
$this->_params['safeSearch'] = 'moderate';
|
||||
break;
|
||||
case 'strict':
|
||||
$this->_params['safeSearch'] = 'strict';
|
||||
break;
|
||||
case null:
|
||||
unset($this->_params['safeSearch']);
|
||||
default:
|
||||
require_once 'Zend/Gdata/App/InvalidArgumentException.php';
|
||||
throw new Zend_Gdata_App_InvalidArgumentException(
|
||||
'The safeSearch parameter only supports the values '.
|
||||
'\'none\', \'moderate\' or \'strict\'.');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the value of the safeSearch parameter
|
||||
*
|
||||
* @return string|null The value of the safeSearch parameter if it has been
|
||||
* set, null otherwise.
|
||||
*/
|
||||
public function getSafeSearch()
|
||||
{
|
||||
if (array_key_exists('safeSearch', $this->_params)) {
|
||||
return $this->_params['safeSearch'];
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the value of the orderby parameter
|
||||
*
|
||||
* @param string $value
|
||||
* @return Zend_Gdata_YouTube_Query Provides a fluent interface
|
||||
*/
|
||||
@ -208,23 +385,9 @@ class Zend_Gdata_YouTube_VideoQuery extends Zend_Gdata_Query
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether or not to include racy videos in the search results
|
||||
* Return the value of the format parameter
|
||||
*
|
||||
* @return string racy
|
||||
*/
|
||||
public function getRacy()
|
||||
{
|
||||
if (array_key_exists('racy', $this->_params)) {
|
||||
return $this->_params['racy'];
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The format used for videos
|
||||
*
|
||||
* @return string format
|
||||
* @return string|null The value of format if it exists, null otherwise.
|
||||
*/
|
||||
public function getFormat()
|
||||
{
|
||||
@ -236,9 +399,10 @@ class Zend_Gdata_YouTube_VideoQuery extends Zend_Gdata_Query
|
||||
}
|
||||
|
||||
/**
|
||||
* The video query
|
||||
* Return the value of the video query that has been set
|
||||
*
|
||||
* @return string video query
|
||||
* @return string|null The value of the video query if it exists,
|
||||
* null otherwise.
|
||||
*/
|
||||
public function getVideoQuery()
|
||||
{
|
||||
@ -250,9 +414,9 @@ class Zend_Gdata_YouTube_VideoQuery extends Zend_Gdata_Query
|
||||
}
|
||||
|
||||
/**
|
||||
* The time
|
||||
* Return the value of the time parameter
|
||||
*
|
||||
* @return string time
|
||||
* @return string|null The time parameter if it exists, null otherwise.
|
||||
*/
|
||||
public function getTime()
|
||||
{
|
||||
@ -264,7 +428,9 @@ class Zend_Gdata_YouTube_VideoQuery extends Zend_Gdata_Query
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string orderby
|
||||
* Return the value of the orderby parameter if it exists
|
||||
*
|
||||
* @return string|null The value of orderby if it exists, null otherwise.
|
||||
*/
|
||||
public function getOrderBy()
|
||||
{
|
||||
@ -276,11 +442,86 @@ class Zend_Gdata_YouTube_VideoQuery extends Zend_Gdata_Query
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the generated full query URL
|
||||
* Generate the query string from the URL parameters, optionally modifying
|
||||
* them based on protocol version.
|
||||
*
|
||||
* @param integer $majorProtocolVersion The major protocol version
|
||||
* @param integer $minorProtocolVersion The minor protocol version
|
||||
* @throws Zend_Gdata_App_VersionException
|
||||
* @return string querystring
|
||||
*/
|
||||
public function getQueryString($majorProtocolVersion = null,
|
||||
$minorProtocolVersion = null)
|
||||
{
|
||||
$queryArray = array();
|
||||
|
||||
foreach ($this->_params as $name => $value) {
|
||||
if (substr($name, 0, 1) == '_') {
|
||||
continue;
|
||||
}
|
||||
|
||||
switch($name) {
|
||||
case 'location-radius':
|
||||
if ($majorProtocolVersion == 1) {
|
||||
require_once 'Zend/Gdata/App/VersionException.php';
|
||||
throw new Zend_Gdata_App_VersionException("The $name " .
|
||||
"parameter is only supported in version 2.");
|
||||
}
|
||||
break;
|
||||
|
||||
case 'racy':
|
||||
if ($majorProtocolVersion == 2) {
|
||||
require_once 'Zend/Gdata/App/VersionException.php';
|
||||
throw new Zend_Gdata_App_VersionException("The $name " .
|
||||
"parameter is not supported in version 2. " .
|
||||
"Please use 'safeSearch'.");
|
||||
}
|
||||
break;
|
||||
|
||||
case 'safeSearch':
|
||||
if ($majorProtocolVersion == 1) {
|
||||
require_once 'Zend/Gdata/App/VersionException.php';
|
||||
throw new Zend_Gdata_App_VersionException("The $name " .
|
||||
"parameter is only supported in version 2. " .
|
||||
"Please use 'racy'.");
|
||||
}
|
||||
break;
|
||||
|
||||
case 'uploader':
|
||||
if ($majorProtocolVersion == 1) {
|
||||
require_once 'Zend/Gdata/App/VersionException.php';
|
||||
throw new Zend_Gdata_App_VersionException("The $name " .
|
||||
"parameter is only supported in version 2.");
|
||||
}
|
||||
break;
|
||||
|
||||
case 'vq':
|
||||
if ($majorProtocolVersion == 2) {
|
||||
$name = 'q';
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
$queryArray[] = urlencode($name) . '=' . urlencode($value);
|
||||
|
||||
}
|
||||
if (count($queryArray) > 0) {
|
||||
return '?' . implode('&', $queryArray);
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the generated full query URL, optionally modifying it based on
|
||||
* the protocol version.
|
||||
*
|
||||
* @param integer $majorProtocolVersion The major protocol version
|
||||
* @param integer $minorProtocolVersion The minor protocol version
|
||||
* @return string The URL
|
||||
*/
|
||||
public function getQueryUrl()
|
||||
public function getQueryUrl($majorProtocolVersion = null,
|
||||
$minorProtocolVersion = null)
|
||||
{
|
||||
if (isset($this->_url)) {
|
||||
$url = $this->_url;
|
||||
@ -290,7 +531,8 @@ class Zend_Gdata_YouTube_VideoQuery extends Zend_Gdata_Query
|
||||
if ($this->getCategory() !== null) {
|
||||
$url .= '/-/' . $this->getCategory();
|
||||
}
|
||||
$url = $url . $this->getQueryString();
|
||||
$url = $url . $this->getQueryString($majorProtocolVersion,
|
||||
$minorProtocolVersion);
|
||||
return $url;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user