You've already forked joomla_test
first commit
This commit is contained in:
89
libraries/joomla/google/auth.php
Normal file
89
libraries/joomla/google/auth.php
Normal file
@ -0,0 +1,89 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Platform
|
||||
* @subpackage Google
|
||||
*
|
||||
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved
|
||||
* @license GNU General Public License version 2 or later; see LICENSE
|
||||
*/
|
||||
|
||||
defined('JPATH_PLATFORM') or die;
|
||||
|
||||
/**
|
||||
* Google authentication class abstract
|
||||
*
|
||||
* @package Joomla.Platform
|
||||
* @subpackage Google
|
||||
* @since 12.3
|
||||
*/
|
||||
abstract class JGoogleAuth
|
||||
{
|
||||
/**
|
||||
* @var JRegistry Options for the Google authentication object.
|
||||
* @since 12.3
|
||||
*/
|
||||
protected $options;
|
||||
|
||||
/**
|
||||
* Abstract method to authenticate to Google
|
||||
*
|
||||
* @return boolean True on success.
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
abstract public function authenticate();
|
||||
|
||||
/**
|
||||
* Verify if the client has been authenticated
|
||||
*
|
||||
* @return boolean Is authenticated
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
abstract public function isAuthenticated();
|
||||
|
||||
/**
|
||||
* Abstract method to retrieve data from Google
|
||||
*
|
||||
* @param string $url The URL for the request.
|
||||
* @param mixed $data The data to include in the request.
|
||||
* @param array $headers The headers to send with the request.
|
||||
* @param string $method The type of http request to send.
|
||||
*
|
||||
* @return mixed Data from Google.
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
abstract public function query($url, $data = null, $headers = null, $method = 'get');
|
||||
|
||||
/**
|
||||
* Get an option from the JGoogleAuth object.
|
||||
*
|
||||
* @param string $key The name of the option to get.
|
||||
*
|
||||
* @return mixed The option value.
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function getOption($key)
|
||||
{
|
||||
return $this->options->get($key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set an option for the JGoogleAuth object.
|
||||
*
|
||||
* @param string $key The name of the option to set.
|
||||
* @param mixed $value The option value to set.
|
||||
*
|
||||
* @return JGoogleAuth This object for method chaining.
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function setOption($key, $value)
|
||||
{
|
||||
$this->options->set($key, $value);
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
1
libraries/joomla/google/auth/index.html
Normal file
1
libraries/joomla/google/auth/index.html
Normal file
@ -0,0 +1 @@
|
||||
<!DOCTYPE html><title></title>
|
128
libraries/joomla/google/auth/oauth2.php
Normal file
128
libraries/joomla/google/auth/oauth2.php
Normal file
@ -0,0 +1,128 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Platform
|
||||
* @subpackage Google
|
||||
*
|
||||
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved
|
||||
* @license GNU General Public License version 2 or later; see LICENSE
|
||||
*/
|
||||
|
||||
defined('JPATH_PLATFORM') or die;
|
||||
jimport('joomla.oauth.v2client');
|
||||
|
||||
/**
|
||||
* Google OAuth authentication class
|
||||
*
|
||||
* @package Joomla.Platform
|
||||
* @subpackage Google
|
||||
* @since 12.3
|
||||
*/
|
||||
class JGoogleAuthOauth2 extends JGoogleAuth
|
||||
{
|
||||
/**
|
||||
* @var JOAuth2Client OAuth client for the Google authentication object.
|
||||
* @since 12.3
|
||||
*/
|
||||
protected $client;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param JRegistry $options JGoogleAuth options object.
|
||||
* @param JOAuth2Client $client OAuth client for Google authentication.
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function __construct(JRegistry $options = null, JOAuth2Client $client = null)
|
||||
{
|
||||
$this->options = isset($options) ? $options : new JRegistry;
|
||||
$this->client = isset($client) ? $client : new JOAuth2Client($this->options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to authenticate to Google
|
||||
*
|
||||
* @return boolean True on success.
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function authenticate()
|
||||
{
|
||||
$this->googlize();
|
||||
|
||||
return $this->client->authenticate();
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify if the client has been authenticated
|
||||
*
|
||||
* @return boolean Is authenticated
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function isAuthenticated()
|
||||
{
|
||||
return $this->client->isAuthenticated();
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to retrieve data from Google
|
||||
*
|
||||
* @param string $url The URL for the request.
|
||||
* @param mixed $data The data to include in the request.
|
||||
* @param array $headers The headers to send with the request.
|
||||
* @param string $method The type of http request to send.
|
||||
*
|
||||
* @return mixed Data from Google.
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function query($url, $data = null, $headers = null, $method = 'get')
|
||||
{
|
||||
$this->googlize();
|
||||
|
||||
return $this->client->query($url, $data, $headers, $method);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to fill in Google-specific OAuth settings
|
||||
*
|
||||
* @return JOAuth2Client Google-configured Oauth2 client.
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
protected function googlize()
|
||||
{
|
||||
if (!$this->client->getOption('authurl'))
|
||||
{
|
||||
$this->client->setOption('authurl', 'https://accounts.google.com/o/oauth2/auth');
|
||||
}
|
||||
if (!$this->client->getOption('tokenurl'))
|
||||
{
|
||||
$this->client->setOption('tokenurl', 'https://accounts.google.com/o/oauth2/token');
|
||||
}
|
||||
if (!$this->client->getOption('requestparams'))
|
||||
{
|
||||
$this->client->setOption('requestparams', Array());
|
||||
}
|
||||
|
||||
$params = $this->client->getOption('requestparams');
|
||||
|
||||
if (!array_key_exists('access_type', $params))
|
||||
{
|
||||
$params['access_type'] = 'offline';
|
||||
}
|
||||
if ($params['access_type'] == 'offline' && $this->client->getOption('userefresh') === null)
|
||||
{
|
||||
$this->client->setOption('userefresh', true);
|
||||
}
|
||||
if (!array_key_exists('approval_prompt', $params))
|
||||
{
|
||||
$params['approval_prompt'] = 'auto';
|
||||
}
|
||||
|
||||
$this->client->setOption('requestparams', $params);
|
||||
|
||||
return $this->client;
|
||||
}
|
||||
}
|
185
libraries/joomla/google/data.php
Normal file
185
libraries/joomla/google/data.php
Normal file
@ -0,0 +1,185 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Platform
|
||||
* @subpackage Google
|
||||
*
|
||||
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved
|
||||
* @license GNU General Public License version 2 or later; see LICENSE
|
||||
*/
|
||||
|
||||
defined('JPATH_PLATFORM') or die;
|
||||
|
||||
/**
|
||||
* Google API data class for the Joomla Platform.
|
||||
*
|
||||
* @package Joomla.Platform
|
||||
* @subpackage Google
|
||||
* @since 12.3
|
||||
*/
|
||||
abstract class JGoogleData
|
||||
{
|
||||
/**
|
||||
* @var JRegistry Options for the Google data object.
|
||||
* @since 12.3
|
||||
*/
|
||||
protected $options;
|
||||
|
||||
/**
|
||||
* @var JGoogleAuth Authentication client for the Google data object.
|
||||
* @since 12.3
|
||||
*/
|
||||
protected $auth;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param JRegistry $options Google options object.
|
||||
* @param JGoogleAuth $auth Google data http client object.
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function __construct(JRegistry $options = null, JGoogleAuth $auth = null)
|
||||
{
|
||||
$this->options = isset($options) ? $options : new JRegistry;
|
||||
$this->auth = isset($auth) ? $auth : new JGoogleAuthOauth2($this->options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to authenticate to Google
|
||||
*
|
||||
* @return boolean True on success.
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function authenticate()
|
||||
{
|
||||
return $this->auth->authenticate();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check authentication
|
||||
*
|
||||
* @return boolean True if authenticated.
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function isAuthenticated()
|
||||
{
|
||||
return $this->auth->isAuthenticated();
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to validate XML
|
||||
*
|
||||
* @param string $data XML data to be parsed
|
||||
*
|
||||
* @return SimpleXMLElement XMLElement of parsed data
|
||||
*
|
||||
* @since 12.3
|
||||
* @throws UnexpectedValueException
|
||||
*/
|
||||
protected static function safeXML($data)
|
||||
{
|
||||
try
|
||||
{
|
||||
return new SimpleXMLElement($data, LIBXML_NOWARNING | LIBXML_NOERROR);
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
throw new UnexpectedValueException("Unexpected data received from Google: `$data`.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to retrieve a list of data
|
||||
*
|
||||
* @param array $url URL to GET
|
||||
* @param int $maxpages Maximum number of pages to return
|
||||
* @param string $token Next page token
|
||||
*
|
||||
* @return mixed Data from Google
|
||||
*
|
||||
* @since 12.3
|
||||
* @throws UnexpectedValueException
|
||||
*/
|
||||
protected function listGetData($url, $maxpages = 1, $token = null)
|
||||
{
|
||||
$qurl = $url;
|
||||
|
||||
if (strpos($url, '&') && isset($token))
|
||||
{
|
||||
$qurl .= '&pageToken=' . $token;
|
||||
}
|
||||
elseif (isset($token))
|
||||
{
|
||||
$qurl .= 'pageToken=' . $token;
|
||||
}
|
||||
$jdata = $this->query($qurl);
|
||||
$data = json_decode($jdata->body, true);
|
||||
|
||||
if ($data && array_key_exists('items', $data))
|
||||
{
|
||||
if ($maxpages != 1 && array_key_exists('nextPageToken', $data))
|
||||
{
|
||||
$data['items'] = array_merge($data['items'], $this->listGetData($url, $maxpages - 1, $data['nextPageToken']));
|
||||
}
|
||||
return $data['items'];
|
||||
}
|
||||
elseif ($data)
|
||||
{
|
||||
return array();
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new UnexpectedValueException("Unexpected data received from Google: `{$jdata->body}`.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to retrieve data from Google
|
||||
*
|
||||
* @param string $url The URL for the request.
|
||||
* @param mixed $data The data to include in the request.
|
||||
* @param array $headers The headers to send with the request.
|
||||
* @param string $method The type of http request to send.
|
||||
*
|
||||
* @return mixed Data from Google.
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
protected function query($url, $data = null, $headers = null, $method = 'get')
|
||||
{
|
||||
return $this->auth->query($url, $data, $headers, $method);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an option from the JGoogleData instance.
|
||||
*
|
||||
* @param string $key The name of the option to get.
|
||||
*
|
||||
* @return mixed The option value.
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function getOption($key)
|
||||
{
|
||||
return $this->options->get($key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set an option for the JGoogleData instance.
|
||||
*
|
||||
* @param string $key The name of the option to set.
|
||||
* @param mixed $value The option value to set.
|
||||
*
|
||||
* @return JGoogleData This object for method chaining.
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function setOption($key, $value)
|
||||
{
|
||||
$this->options->set($key, $value);
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
415
libraries/joomla/google/data/adsense.php
Normal file
415
libraries/joomla/google/data/adsense.php
Normal file
@ -0,0 +1,415 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Platform
|
||||
* @subpackage Google
|
||||
*
|
||||
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved
|
||||
* @license GNU General Public License version 2 or later; see LICENSE
|
||||
*/
|
||||
|
||||
defined('JPATH_PLATFORM') or die;
|
||||
|
||||
/**
|
||||
* Google Adsense data class for the Joomla Platform.
|
||||
*
|
||||
* @package Joomla.Platform
|
||||
* @subpackage Google
|
||||
* @since 12.3
|
||||
*/
|
||||
class JGoogleDataAdsense extends JGoogleData
|
||||
{
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param JRegistry $options Google options object
|
||||
* @param JGoogleAuth $auth Google data http client object
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function __construct(JRegistry $options = null, JGoogleAuth $auth = null)
|
||||
{
|
||||
parent::__construct($options, $auth);
|
||||
|
||||
if (isset($this->auth) && !$this->auth->getOption('scope'))
|
||||
{
|
||||
$this->auth->setOption('scope', 'https://www.googleapis.com/auth/adsense');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get an Adsense account's settings from Google
|
||||
*
|
||||
* @param string $accountID ID of account to get
|
||||
* @param boolean $subaccounts Include list of subaccounts
|
||||
*
|
||||
* @return mixed Data from Google
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function getAccount($accountID, $subaccounts = true)
|
||||
{
|
||||
if ($this->isAuthenticated())
|
||||
{
|
||||
$url = 'https://www.googleapis.com/adsense/v1.1/accounts/' . urlencode($accountID) . ($subaccounts ? '?tree=true' : '');
|
||||
$jdata = $this->query($url);
|
||||
|
||||
if ($data = json_decode($jdata->body, true))
|
||||
{
|
||||
return $data;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new UnexpectedValueException("Unexpected data received from Google: `{$jdata->body}`.");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to retrieve a list of AdSense accounts from Google
|
||||
*
|
||||
* @param array $options Search settings
|
||||
* @param int $maxpages Maximum number of pages of accounts to return
|
||||
*
|
||||
* @return mixed Data from Google
|
||||
*
|
||||
* @since 12.3
|
||||
* @throws UnexpectedValueException
|
||||
*/
|
||||
public function listAccounts($options = array(), $maxpages = 1)
|
||||
{
|
||||
if ($this->isAuthenticated())
|
||||
{
|
||||
$next = array_key_exists('nextPageToken', $options) ? $options['nextPage'] : null;
|
||||
unset($options['nextPageToken']);
|
||||
$url = 'https://www.googleapis.com/adsense/v1.1/accounts?' . http_build_query($options);
|
||||
|
||||
return $this->listGetData($url, $maxpages, $next);
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to retrieve a list of AdSense clients from Google
|
||||
*
|
||||
* @param string $accountID ID of account to list the clients from
|
||||
* @param array $options Search settings
|
||||
* @param int $maxpages Maximum number of pages of accounts to return
|
||||
*
|
||||
* @return mixed Data from Google
|
||||
*
|
||||
* @since 12.3
|
||||
* @throws UnexpectedValueException
|
||||
*/
|
||||
public function listClients($accountID, $options = array(), $maxpages = 1)
|
||||
{
|
||||
if ($this->isAuthenticated())
|
||||
{
|
||||
$next = array_key_exists('nextPageToken', $options) ? $options['nextPage'] : null;
|
||||
unset($options['nextPageToken']);
|
||||
$url = 'https://www.googleapis.com/adsense/v1.1/accounts/' . urlencode($accountID) . '/adclients?' . http_build_query($options);
|
||||
|
||||
return $this->listGetData($url, $maxpages, $next);
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get an AdSense AdUnit
|
||||
*
|
||||
* @param string $accountID ID of account to get
|
||||
* @param string $adclientID ID of client to get
|
||||
* @param string $adunitID ID of adunit to get
|
||||
*
|
||||
* @return mixed Data from Google
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function getUnit($accountID, $adclientID, $adunitID)
|
||||
{
|
||||
if ($this->isAuthenticated())
|
||||
{
|
||||
$url = 'https://www.googleapis.com/adsense/v1.1/accounts/' . urlencode($accountID);
|
||||
$url .= '/adclients/' . urlencode($adclientID) . '/adunits/' . urlencode($adunitID);
|
||||
$jdata = $this->query($url);
|
||||
|
||||
if ($data = json_decode($jdata->body, true))
|
||||
{
|
||||
return $data;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new UnexpectedValueException("Unexpected data received from Google: `{$jdata->body}`.");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to retrieve a list of AdSense Custom Channels for a specific Adunit
|
||||
*
|
||||
* @param string $accountID ID of account
|
||||
* @param string $adclientID ID of client
|
||||
* @param string $adunitID ID of adunit to list channels from
|
||||
* @param array $options Search settings
|
||||
* @param int $maxpages Maximum number of pages of accounts to return
|
||||
*
|
||||
* @return mixed Data from Google
|
||||
*
|
||||
* @since 12.3
|
||||
* @throws UnexpectedValueException
|
||||
*/
|
||||
public function listUnitChannels($accountID, $adclientID, $adunitID, $options = array(), $maxpages = 1)
|
||||
{
|
||||
if ($this->isAuthenticated())
|
||||
{
|
||||
$next = array_key_exists('nextPageToken', $options) ? $options['nextPage'] : null;
|
||||
unset($options['nextPageToken']);
|
||||
$url = 'https://www.googleapis.com/adsense/v1.1/accounts/' . urlencode($accountID);
|
||||
$url .= '/adclients/' . urlencode($adclientID) . '/adunits/' . urlencode($adunitID) . '/customchannels?' . http_build_query($options);
|
||||
|
||||
return $this->listGetData($url, $maxpages, $next);
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get an Adsense Channel
|
||||
*
|
||||
* @param string $accountID ID of account to get
|
||||
* @param string $adclientID ID of client to get
|
||||
* @param string $channelID ID of channel to get
|
||||
*
|
||||
* @return mixed Data from Google
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function getChannel($accountID, $adclientID, $channelID)
|
||||
{
|
||||
if ($this->isAuthenticated())
|
||||
{
|
||||
$url = 'https://www.googleapis.com/adsense/v1.1/accounts/' . urlencode($accountID) . '/adclients/';
|
||||
$url .= urlencode($adclientID) . '/customchannels/' . urlencode($channelID);
|
||||
$jdata = $this->query($url);
|
||||
|
||||
if ($data = json_decode($jdata->body, true))
|
||||
{
|
||||
return $data;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new UnexpectedValueException("Unexpected data received from Google: `{$jdata->body}`.");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to retrieve a list of AdSense Custom Channels
|
||||
*
|
||||
* @param string $accountID ID of account
|
||||
* @param string $adclientID ID of client to list channels from
|
||||
* @param array $options Search settings
|
||||
* @param int $maxpages Maximum number of pages of accounts to return
|
||||
*
|
||||
* @return mixed Data from Google
|
||||
*
|
||||
* @since 12.3
|
||||
* @throws UnexpectedValueException
|
||||
*/
|
||||
public function listChannels($accountID, $adclientID, $options = array(), $maxpages = 1)
|
||||
{
|
||||
if ($this->isAuthenticated())
|
||||
{
|
||||
$next = array_key_exists('nextPageToken', $options) ? $options['nextPage'] : null;
|
||||
unset($options['nextPageToken']);
|
||||
$url = 'https://www.googleapis.com/adsense/v1.1/accounts/' . urlencode($accountID) . '/adclients/' . urlencode($adclientID);
|
||||
$url .= '/customchannels?' . http_build_query($options);
|
||||
|
||||
return $this->listGetData($url, $maxpages, $next);
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to retrieve a list of AdSense Adunits for a specific Custom Channel
|
||||
*
|
||||
* @param string $accountID ID of account
|
||||
* @param string $adclientID ID of client
|
||||
* @param string $channelID ID of channel to list units from
|
||||
* @param array $options Search settings
|
||||
* @param int $maxpages Maximum number of pages of accounts to return
|
||||
*
|
||||
* @return mixed Data from Google
|
||||
*
|
||||
* @since 12.3
|
||||
* @throws UnexpectedValueException
|
||||
*/
|
||||
public function listChannelUnits($accountID, $adclientID, $channelID, $options = array(), $maxpages = 1)
|
||||
{
|
||||
if ($this->isAuthenticated())
|
||||
{
|
||||
$next = array_key_exists('nextPageToken', $options) ? $options['nextPage'] : null;
|
||||
unset($options['nextPageToken']);
|
||||
$url = 'https://www.googleapis.com/adsense/v1.1/accounts/' . urlencode($accountID) . '/adclients/' . urlencode($adclientID);
|
||||
$url .= '/customchannels/' . urlencode($channelID) . '/adunits?' . http_build_query($options);
|
||||
|
||||
return $this->listGetData($url, $maxpages, $next);
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to generate a report from Google AdSense
|
||||
*
|
||||
* @param string $accountID ID of account
|
||||
* @param string $adclientID ID of client
|
||||
* @param array $options Search settings
|
||||
* @param int $maxpages Maximum number of pages of accounts to return
|
||||
*
|
||||
* @return mixed Data from Google
|
||||
*
|
||||
* @since 12.3
|
||||
* @throws UnexpectedValueException
|
||||
*/
|
||||
public function listUrlChannels($accountID, $adclientID, $options = array(), $maxpages = 1)
|
||||
{
|
||||
if ($this->isAuthenticated())
|
||||
{
|
||||
$next = array_key_exists('nextPageToken', $options) ? $options['nextPage'] : null;
|
||||
unset($options['nextPageToken']);
|
||||
$url = 'https://www.googleapis.com/adsense/v1.1/accounts/' . urlencode($accountID);
|
||||
$url .= '/adclients/' . urlencode($adclientID) . '/urlchannels?' . http_build_query($options);
|
||||
|
||||
return $this->listGetData($url, $maxpages, $next);
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to retrieve a list of AdSense Channel URLs
|
||||
*
|
||||
* @param string $accountID ID of account
|
||||
* @param mixed $start Start day
|
||||
* @param mixed $end End day
|
||||
* @param array $options Search settings
|
||||
* @param int $maxpages Maximum number of pages of accounts to return
|
||||
*
|
||||
* @return mixed Data from Google
|
||||
*
|
||||
* @since 12.3
|
||||
* @throws UnexpectedValueException
|
||||
*/
|
||||
public function generateReport($accountID, $start, $end = false, $options = array(), $maxpages = 1)
|
||||
{
|
||||
if ($this->isAuthenticated())
|
||||
{
|
||||
if (is_int($start))
|
||||
{
|
||||
$startobj = new DateTime;
|
||||
$startobj->setTimestamp($start);
|
||||
}
|
||||
elseif (is_string($start))
|
||||
{
|
||||
$startobj = new DateTime($start);
|
||||
}
|
||||
elseif (is_a($start, 'DateTime'))
|
||||
{
|
||||
$startobj = $start;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new InvalidArgumentException('Invalid start time.');
|
||||
}
|
||||
|
||||
if (!$end)
|
||||
{
|
||||
$endobj = new DateTime;
|
||||
}
|
||||
elseif (is_int($end))
|
||||
{
|
||||
$endobj = new DateTime;
|
||||
$endobj->setTimestamp($end);
|
||||
}
|
||||
elseif (is_string($end))
|
||||
{
|
||||
$endobj = new DateTime($end);
|
||||
}
|
||||
elseif (is_a($end, 'DateTime'))
|
||||
{
|
||||
$endobj = $end;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new InvalidArgumentException('Invalid end time.');
|
||||
}
|
||||
|
||||
$options['startDate'] = $startobj->format('Y-m-d');
|
||||
$options['endDate'] = $endobj->format('Y-m-d');
|
||||
|
||||
unset($options['startIndex']);
|
||||
|
||||
$url = 'https://www.googleapis.com/adsense/v1.1/accounts/' . urlencode($accountID) . '/reports?' . http_build_query($options);
|
||||
|
||||
if (strpos($url, '&'))
|
||||
{
|
||||
$url .= '&';
|
||||
}
|
||||
|
||||
$i = 0;
|
||||
$data['rows'] = array();
|
||||
|
||||
do
|
||||
{
|
||||
$jdata = $this->query($url . 'startIndex=' . count($data['rows']));
|
||||
$newdata = json_decode($jdata->body, true);
|
||||
|
||||
if ($newdata && array_key_exists('rows', $newdata))
|
||||
{
|
||||
$newdata['rows'] = array_merge($data['rows'], $newdata['rows']);
|
||||
$data = $newdata;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new UnexpectedValueException("Unexpected data received from Google: `{$jdata->body}`.");
|
||||
}
|
||||
|
||||
$i++;
|
||||
}
|
||||
while (count($data['rows']) < $data['totalMatchedRows'] && $i < $maxpages);
|
||||
|
||||
return $data;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
620
libraries/joomla/google/data/calendar.php
Normal file
620
libraries/joomla/google/data/calendar.php
Normal file
@ -0,0 +1,620 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Platform
|
||||
* @subpackage Google
|
||||
*
|
||||
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved
|
||||
* @license GNU General Public License version 2 or later; see LICENSE
|
||||
*/
|
||||
|
||||
defined('JPATH_PLATFORM') or die;
|
||||
|
||||
/**
|
||||
* Google Calendar data class for the Joomla Platform.
|
||||
*
|
||||
* @package Joomla.Platform
|
||||
* @subpackage Google
|
||||
* @since 12.3
|
||||
*/
|
||||
class JGoogleDataCalendar extends JGoogleData
|
||||
{
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param JRegistry $options Google options object
|
||||
* @param JGoogleAuth $auth Google data http client object
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function __construct(JRegistry $options = null, JGoogleAuth $auth = null)
|
||||
{
|
||||
parent::__construct($options, $auth);
|
||||
|
||||
if (isset($this->auth) && !$this->auth->getOption('scope'))
|
||||
{
|
||||
$this->auth->setOption('scope', 'https://www.googleapis.com/auth/calendar');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to remove a calendar from a user's calendar list
|
||||
*
|
||||
* @param string $calendarID ID of calendar to delete
|
||||
*
|
||||
* @return boolean Success or failure
|
||||
*
|
||||
* @since 12.3
|
||||
* @throws UnexpectedValueException
|
||||
*/
|
||||
public function removeCalendar($calendarID)
|
||||
{
|
||||
if ($this->isAuthenticated())
|
||||
{
|
||||
$jdata = $this->query('https://www.googleapis.com/calendar/v3/users/me/calendarList/' . urlencode($calendarID), null, null, 'delete');
|
||||
|
||||
if ($jdata->body != '')
|
||||
{
|
||||
throw new UnexpectedValueException("Unexpected data received from Google: `{$jdata->body}`.");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get a calendar's settings from Google
|
||||
*
|
||||
* @param string $calendarID ID of calendar to get.
|
||||
*
|
||||
* @return mixed Data from Google
|
||||
*
|
||||
* @since 12.3
|
||||
* @throws UnexpectedValueException
|
||||
*/
|
||||
public function getCalendar($calendarID)
|
||||
{
|
||||
if ($this->isAuthenticated())
|
||||
{
|
||||
$jdata = $this->query('https://www.googleapis.com/calendar/v3/users/me/calendarList/' . urlencode($calendarID));
|
||||
|
||||
if ($data = json_decode($jdata->body, true))
|
||||
{
|
||||
return $data;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new UnexpectedValueException("Unexpected data received from Google: `{$jdata->body}`.");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to add a calendar to a user's Google Calendar list
|
||||
*
|
||||
* @param string $calendarID New calendar ID
|
||||
* @param array $options New calendar settings
|
||||
*
|
||||
* @return mixed Data from Google
|
||||
*
|
||||
* @since 12.3
|
||||
* @throws UnexpectedValueException
|
||||
*/
|
||||
public function addCalendar($calendarID, $options = array())
|
||||
{
|
||||
if ($this->isAuthenticated())
|
||||
{
|
||||
$options['id'] = $calendarID;
|
||||
$url = 'https://www.googleapis.com/calendar/v3/users/me/calendarList';
|
||||
$jdata = $this->query($url, json_encode($options), array('Content-type' => 'application/json'), 'post');
|
||||
|
||||
if ($data = json_decode($jdata->body, true))
|
||||
{
|
||||
return $data;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new UnexpectedValueException("Unexpected data received from Google: `{$jdata->body}`.");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to retrieve calendar list from Google
|
||||
*
|
||||
* @param array $options Search settings
|
||||
* @param int $maxpages Maximum number of pages of calendars to return
|
||||
*
|
||||
* @return mixed Data from Google
|
||||
*
|
||||
* @since 12.3
|
||||
* @throws UnexpectedValueException
|
||||
*/
|
||||
public function listCalendars($options = array(), $maxpages = 1)
|
||||
{
|
||||
if ($this->isAuthenticated())
|
||||
{
|
||||
$next = array_key_exists('nextPageToken', $options) ? $options['nextPage'] : null;
|
||||
unset($options['nextPageToken']);
|
||||
$url = 'https://www.googleapis.com/calendar/v3/users/me/calendarList?' . http_build_query($options);
|
||||
|
||||
return $this->listGetData($url, $maxpages, $next);
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to edit a Google Calendar's settings
|
||||
*
|
||||
* @param string $calendarID Calendar ID
|
||||
* @param array $options Calendar settings
|
||||
*
|
||||
* @return mixed Data from Google
|
||||
*
|
||||
* @since 12.3
|
||||
* @throws UnexpectedValueException
|
||||
*/
|
||||
public function editCalendarSettings($calendarID, $options)
|
||||
{
|
||||
if ($this->isAuthenticated())
|
||||
{
|
||||
$url = 'https://www.googleapis.com/calendar/v3/users/me/calendarList/' . urlencode($calendarID);
|
||||
$jdata = $this->query($url, json_encode($options), array('Content-type' => 'application/json'), 'put');
|
||||
|
||||
if ($data = json_decode($jdata->body, true))
|
||||
{
|
||||
return $data;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new UnexpectedValueException("Unexpected data received from Google: `{$jdata->body}`.");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to clear a Google Calendar
|
||||
*
|
||||
* @param string $calendarID ID of calendar to clear
|
||||
*
|
||||
* @return boolean Success or failure
|
||||
*
|
||||
* @since 12.3
|
||||
* @throws UnexpectedValueException
|
||||
*/
|
||||
public function clearCalendar($calendarID)
|
||||
{
|
||||
if ($this->isAuthenticated())
|
||||
{
|
||||
$data = $this->query('https://www.googleapis.com/calendar/v3/users/me/calendars/' . urlencode($calendarID) . '/clear', null, null, 'post');
|
||||
|
||||
if ($data->body != '')
|
||||
{
|
||||
throw new UnexpectedValueException("Unexpected data received from Google: `{$data->body}`.");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to delete a calendar from Google
|
||||
*
|
||||
* @param string $calendarID ID of calendar to delete.
|
||||
*
|
||||
* @return boolean Success or failure
|
||||
*
|
||||
* @since 12.3
|
||||
* @throws UnexpectedValueException
|
||||
*/
|
||||
public function deleteCalendar($calendarID)
|
||||
{
|
||||
if ($this->isAuthenticated())
|
||||
{
|
||||
$data = $this->query('https://www.googleapis.com/calendar/v3/users/me/calendars/' . urlencode($calendarID), null, null, 'delete');
|
||||
|
||||
if ($data->body != '')
|
||||
{
|
||||
throw new UnexpectedValueException("Unexpected data received from Google: `{$data->body}`.");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to create a Google Calendar
|
||||
*
|
||||
* @param string $title New calendar title
|
||||
* @param array $options New calendar settings
|
||||
*
|
||||
* @return mixed Data from Google.
|
||||
*
|
||||
* @since 12.3
|
||||
* @throws UnexpectedValueException
|
||||
*/
|
||||
public function createCalendar($title, $options = array())
|
||||
{
|
||||
if ($this->isAuthenticated())
|
||||
{
|
||||
$options['summary'] = $title;
|
||||
$url = 'https://www.googleapis.com/calendar/v3/calendars';
|
||||
$jdata = $this->query($url, json_encode($options), array('Content-type' => 'application/json'), 'post');
|
||||
|
||||
if ($data = json_decode($jdata->body, true))
|
||||
{
|
||||
return $data;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new UnexpectedValueException("Unexpected data received from Google: `{$jdata->body}`.");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to edit a Google Calendar
|
||||
*
|
||||
* @param string $calendarID Calendar ID.
|
||||
* @param array $options Calendar settings.
|
||||
*
|
||||
* @return mixed Data from Google.
|
||||
*
|
||||
* @since 12.3
|
||||
* @throws UnexpectedValueException
|
||||
*/
|
||||
public function editCalendar($calendarID, $options)
|
||||
{
|
||||
if ($this->isAuthenticated())
|
||||
{
|
||||
$url = 'https://www.googleapis.com/calendar/v3/users/me/calendars/' . urlencode($calendarID);
|
||||
$jdata = $this->query($url, json_encode($options), array('Content-type' => 'application/json'), 'put');
|
||||
$data = json_decode($jdata->body, true);
|
||||
|
||||
if ($data && array_key_exists('items', $data))
|
||||
{
|
||||
return $data;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new UnexpectedValueException("Unexpected data received from Google: `{$jdata->body}`.");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to delete an event from a Google Calendar
|
||||
*
|
||||
* @param string $calendarID ID of calendar to delete from
|
||||
* @param string $eventID ID of event to delete.
|
||||
*
|
||||
* @return boolean Success or failure.
|
||||
*
|
||||
* @since 12.3
|
||||
* @throws UnexpectedValueException
|
||||
*/
|
||||
public function deleteEvent($calendarID, $eventID)
|
||||
{
|
||||
if ($this->isAuthenticated())
|
||||
{
|
||||
$url = 'https://www.googleapis.com/calendar/v3/users/me/calendars/' . urlencode($calendarID) . '/events/' . urlencode($eventID);
|
||||
$data = $this->query($url, null, null, 'delete');
|
||||
|
||||
if ($data->body != '')
|
||||
{
|
||||
throw new UnexpectedValueException("Unexpected data received from Google: `{$data->body}`.");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get an event from a Google Calendar
|
||||
*
|
||||
* @param string $calendarID ID of calendar
|
||||
* @param string $eventID ID of event to get
|
||||
* @param array $options Options to send to Google
|
||||
*
|
||||
* @return mixed Data from Google.
|
||||
*
|
||||
* @since 12.3
|
||||
* @throws UnexpectedValueException
|
||||
*/
|
||||
public function getEvent($calendarID, $eventID, $options = array())
|
||||
{
|
||||
if ($this->isAuthenticated())
|
||||
{
|
||||
$url = 'https://www.googleapis.com/calendar/v3/users/me/calendarList/';
|
||||
$url .= urlencode($calendarID) . '/events/' . urlencode($eventID) . '?' . http_build_query($options);
|
||||
$jdata = $this->query($url);
|
||||
|
||||
if ($data = json_decode($jdata->body, true))
|
||||
{
|
||||
return $data;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new UnexpectedValueException("Unexpected data received from Google: `{$jdata->body}`.");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to create a Google Calendar event
|
||||
*
|
||||
* @param string $calendarID ID of calendar
|
||||
* @param mixed $start Event start time
|
||||
* @param mixed $end Event end time
|
||||
* @param array $options New event settings
|
||||
* @param mixed $timezone Timezone for event
|
||||
* @param boolean $allday Treat event as an all-day event
|
||||
* @param boolean $notify Notify participants
|
||||
*
|
||||
* @return mixed Data from Google.
|
||||
*
|
||||
* @since 12.3
|
||||
* @throws InvalidArgumentException
|
||||
* @throws UnexpectedValueException
|
||||
*/
|
||||
public function createEvent($calendarID, $start, $end = false, $options = array(), $timezone = false, $allday = false, $notify = false)
|
||||
{
|
||||
if ($this->isAuthenticated())
|
||||
{
|
||||
if (!$start)
|
||||
{
|
||||
$startobj = new DateTime;
|
||||
}
|
||||
elseif (is_int($start))
|
||||
{
|
||||
$startobj = new DateTime;
|
||||
$startobj->setTimestamp($start);
|
||||
}
|
||||
elseif (is_string($start))
|
||||
{
|
||||
$startobj = new DateTime($start);
|
||||
}
|
||||
elseif (is_a($start, 'DateTime'))
|
||||
{
|
||||
$startobj = $start;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new InvalidArgumentException('Invalid event start time.');
|
||||
}
|
||||
|
||||
if (!$end)
|
||||
{
|
||||
$endobj = $startobj;
|
||||
}
|
||||
elseif (is_int($end))
|
||||
{
|
||||
$endobj = new DateTime;
|
||||
$endobj->setTimestamp($end);
|
||||
}
|
||||
elseif (is_string($end))
|
||||
{
|
||||
$endobj = new DateTime($end);
|
||||
}
|
||||
elseif (is_a($end, 'DateTime'))
|
||||
{
|
||||
$endobj = $end;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new InvalidArgumentException('Invalid event end time.');
|
||||
}
|
||||
|
||||
if ($allday)
|
||||
{
|
||||
$options['start'] = array('date' => $startobj->format('Y-m-d'));
|
||||
$options['end'] = array('date' => $endobj->format('Y-m-d'));
|
||||
}
|
||||
else
|
||||
{
|
||||
$options['start'] = array('dateTime' => $startobj->format(DateTime::RFC3339));
|
||||
$options['end'] = array('dateTime' => $endobj->format(DateTime::RFC3339));
|
||||
}
|
||||
|
||||
if ($timezone === true)
|
||||
{
|
||||
$options['start']['timeZone'] = $startobj->getTimezone()->getName();
|
||||
$options['end']['timeZone'] = $endobj->getTimezone()->getName();
|
||||
}
|
||||
elseif (is_a($timezone, 'DateTimeZone'))
|
||||
{
|
||||
$options['start']['timeZone'] = $timezone->getName();
|
||||
$options['end']['timeZone'] = $timezone->getName();
|
||||
}
|
||||
elseif (is_string($timezone))
|
||||
{
|
||||
$options['start']['timeZone'] = $timezone;
|
||||
$options['end']['timeZone'] = $timezone;
|
||||
}
|
||||
|
||||
$url = 'https://www.googleapis.com/calendar/v3/calendars/' . urlencode($calendarID) . '/events' . ($notify ? '?sendNotifications=true' : '');
|
||||
$jdata = $this->query($url, json_encode($options), array('Content-type' => 'application/json'), 'post');
|
||||
|
||||
if ($data = json_decode($jdata->body, true))
|
||||
{
|
||||
return $data;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new UnexpectedValueException("Unexpected data received from Google: `{$jdata->body}`.");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to retrieve a list of events on a Google calendar
|
||||
*
|
||||
* @param string $calendarID Calendar ID
|
||||
* @param string $eventID ID of the event to change
|
||||
* @param array $options Search settings
|
||||
* @param int $maxpages Minimum number of events to retrieve (more may be retrieved depending on page size)
|
||||
*
|
||||
* @return mixed Data from Google.
|
||||
*
|
||||
* @since 12.3
|
||||
* @throws UnexpectedValueException
|
||||
*/
|
||||
public function listRecurrences($calendarID, $eventID, $options = array(), $maxpages = 1)
|
||||
{
|
||||
if ($this->isAuthenticated())
|
||||
{
|
||||
$next = array_key_exists('nextPageToken', $options) ? $options['nextPage'] : null;
|
||||
unset($options['nextPageToken']);
|
||||
$url = 'https://www.googleapis.com/calendar/v3/users/me/calendars/' . urlencode($calendarID) . '/events/' . urlencode($eventID) . '/instances';
|
||||
$url .= '?' . http_build_query($options);
|
||||
|
||||
return $this->listGetData($url, $maxpages, $next);
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to retrieve a list of events on a Google calendar
|
||||
*
|
||||
* @param string $calendarID Calendar ID
|
||||
* @param array $options Calendar settings
|
||||
* @param int $maxpages Cycle through pages of data to generate a complete list
|
||||
*
|
||||
* @return mixed Data from Google.
|
||||
*
|
||||
* @since 12.3
|
||||
* @throws UnexpectedValueException
|
||||
*/
|
||||
public function listEvents($calendarID, $options = array(), $maxpages = 1)
|
||||
{
|
||||
if ($this->isAuthenticated())
|
||||
{
|
||||
$next = array_key_exists('nextPageToken', $options) ? $options['nextPage'] : null;
|
||||
unset($options['nextPageToken']);
|
||||
$url = 'https://www.googleapis.com/calendar/v3/calendars/' . urlencode($calendarID) . '/events?' . http_build_query($options);
|
||||
|
||||
return $this->listGetData($url, $maxpages, $next);
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to move an event from one calendar to another
|
||||
*
|
||||
* @param string $calendarID Calendar ID
|
||||
* @param string $eventID ID of the event to change
|
||||
* @param string $destID Calendar ID
|
||||
* @param boolean $notify Notify participants of changes
|
||||
*
|
||||
* @return mixed Data from Google.
|
||||
*
|
||||
* @since 12.3
|
||||
* @throws UnexpectedValueException
|
||||
*/
|
||||
public function moveEvent($calendarID, $eventID, $destID, $notify = false)
|
||||
{
|
||||
if ($this->isAuthenticated())
|
||||
{
|
||||
$url = 'https://www.googleapis.com/calendar/v3/calendars/' . urlencode($calendarID) . '/events/' . urlencode($eventID) . '/move';
|
||||
$url .= '?destination=' . $destID . ($notify ? '&sendNotifications=true' : '');
|
||||
$jdata = $this->query($url, null, null, 'post');
|
||||
|
||||
if ($data = json_decode($jdata->body, true))
|
||||
{
|
||||
return $data;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new UnexpectedValueException("Unexpected data received from Google: `{$jdata->body}`.");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to edit a Google Calendar event
|
||||
*
|
||||
* @param string $calendarID Calendar ID
|
||||
* @param string $eventID ID of the event to change
|
||||
* @param array $options Event settings
|
||||
* @param boolean $notify Notify participants of changes
|
||||
*
|
||||
* @return mixed Data from Google.
|
||||
*
|
||||
* @since 12.3
|
||||
* @throws UnexpectedValueException
|
||||
*/
|
||||
public function editEvent($calendarID, $eventID, $options, $notify = false)
|
||||
{
|
||||
if ($this->isAuthenticated())
|
||||
{
|
||||
$url = 'https://www.googleapis.com/calendar/v3/calendars/';
|
||||
$url .= urlencode($calendarID) . '/events/' . urlencode($eventID) . ($notify ? '?sendNotifications=true' : '');
|
||||
$jdata = $this->query($url, json_encode($options), array('Content-type' => 'application/json'), 'put');
|
||||
|
||||
if ($data = json_decode($jdata->body, true))
|
||||
{
|
||||
return $data;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new UnexpectedValueException("Unexpected data received from Google: `{$jdata->body}`.");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
1
libraries/joomla/google/data/index.html
Normal file
1
libraries/joomla/google/data/index.html
Normal file
@ -0,0 +1 @@
|
||||
<!DOCTYPE html><title></title>
|
149
libraries/joomla/google/data/picasa.php
Normal file
149
libraries/joomla/google/data/picasa.php
Normal file
@ -0,0 +1,149 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Platform
|
||||
* @subpackage Google
|
||||
*
|
||||
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved
|
||||
* @license GNU General Public License version 2 or later; see LICENSE
|
||||
*/
|
||||
|
||||
defined('JPATH_PLATFORM') or die;
|
||||
|
||||
/**
|
||||
* Google Picasa data class for the Joomla Platform.
|
||||
*
|
||||
* @package Joomla.Platform
|
||||
* @subpackage Google
|
||||
* @since 12.3
|
||||
*/
|
||||
class JGoogleDataPicasa extends JGoogleData
|
||||
{
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param JRegistry $options Google options object
|
||||
* @param JGoogleAuth $auth Google data http client object
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function __construct(JRegistry $options = null, JGoogleAuth $auth = null)
|
||||
{
|
||||
parent::__construct($options, $auth);
|
||||
|
||||
if (isset($this->auth) && !$this->auth->getOption('scope'))
|
||||
{
|
||||
$this->auth->setOption('scope', 'https://picasaweb.google.com/data/');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to retrieve a list of Picasa Albums
|
||||
*
|
||||
* @param string $userID ID of user
|
||||
*
|
||||
* @return mixed Data from Google
|
||||
*
|
||||
* @since 12.3
|
||||
* @throws UnexpectedValueException
|
||||
*/
|
||||
public function listAlbums($userID = 'default')
|
||||
{
|
||||
if ($this->isAuthenticated())
|
||||
{
|
||||
$url = 'https://picasaweb.google.com/data/feed/api/user/' . urlencode($userID);
|
||||
$jdata = $this->query($url, null, array('GData-Version' => 2));
|
||||
$xml = $this->safeXML($jdata->body);
|
||||
|
||||
if (isset($xml->children()->entry))
|
||||
{
|
||||
$items = array();
|
||||
|
||||
foreach ($xml->children()->entry as $item)
|
||||
{
|
||||
$items[] = new JGoogleDataPicasaAlbum($item, $this->options, $this->auth);
|
||||
}
|
||||
return $items;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new UnexpectedValueException("Unexpected data received from Google: `{$jdata->body}`.");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to create a Picasa Album
|
||||
*
|
||||
* @param string $userID ID of user
|
||||
* @param string $title New album title
|
||||
* @param string $access New album access settings
|
||||
* @param string $summary New album summary
|
||||
* @param string $location New album location
|
||||
* @param int $time New album timestamp
|
||||
* @param array $keywords New album keywords
|
||||
*
|
||||
* @return mixed Data from Google.
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function createAlbum($userID = 'default', $title = '', $access = 'private', $summary = '', $location = '', $time = false, $keywords = array())
|
||||
{
|
||||
if ($this->isAuthenticated())
|
||||
{
|
||||
$time = $time ? $time : time();
|
||||
$title = $title != '' ? $title : date('F j, Y');
|
||||
$xml = new SimpleXMLElement('<entry></entry>');
|
||||
$xml->addAttribute('xmlns', 'http://www.w3.org/2005/Atom');
|
||||
$xml->addChild('title', $title);
|
||||
$xml->addChild('summary', $summary);
|
||||
$xml->addChild('gphoto:location', $location, 'http://schemas.google.com/photos/2007');
|
||||
$xml->addChild('gphoto:access', $access);
|
||||
$xml->addChild('gphoto:timestamp', $time);
|
||||
$media = $xml->addChild('media:group', '', 'http://search.yahoo.com/mrss/');
|
||||
$media->addChild('media:keywords', implode($keywords, ', '));
|
||||
$cat = $xml->addChild('category', '');
|
||||
$cat->addAttribute('scheme', 'http://schemas.google.com/g/2005#kind');
|
||||
$cat->addAttribute('term', 'http://schemas.google.com/photos/2007#album');
|
||||
|
||||
$url = 'https://picasaweb.google.com/data/feed/api/user/' . urlencode($userID);
|
||||
$jdata = $this->query($url, $xml->asXML(), array('GData-Version' => 2, 'Content-type' => 'application/atom+xml'), 'post');
|
||||
|
||||
$xml = $this->safeXML($jdata->body);
|
||||
|
||||
return new JGoogleDataPicasaAlbum($xml, $this->options, $this->auth);
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Picasa Album
|
||||
*
|
||||
* @param string $url URL of album to get
|
||||
*
|
||||
* @return mixed Data from Google
|
||||
*
|
||||
* @since 12.3
|
||||
* @throws UnexpectedValueException
|
||||
*/
|
||||
public function getAlbum($url)
|
||||
{
|
||||
if ($this->isAuthenticated())
|
||||
{
|
||||
$jdata = $this->query($url, null, array('GData-Version' => 2));
|
||||
$xml = $this->safeXML($jdata->body);
|
||||
|
||||
return new JGoogleDataPicasaAlbum($xml, $this->options, $this->auth);
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
482
libraries/joomla/google/data/picasa/album.php
Normal file
482
libraries/joomla/google/data/picasa/album.php
Normal file
@ -0,0 +1,482 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Platform
|
||||
* @subpackage Google
|
||||
*
|
||||
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved
|
||||
* @license GNU General Public License version 2 or later; see LICENSE
|
||||
*/
|
||||
|
||||
defined('JPATH_PLATFORM') or die;
|
||||
|
||||
/**
|
||||
* Google Picasa data class for the Joomla Platform.
|
||||
*
|
||||
* @package Joomla.Platform
|
||||
* @subpackage Google
|
||||
* @since 12.3
|
||||
*/
|
||||
class JGoogleDataPicasaAlbum extends JGoogleData
|
||||
{
|
||||
/**
|
||||
* @var SimpleXMLElement The album's XML
|
||||
* @since 12.3
|
||||
*/
|
||||
protected $xml;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param SimpleXMLElement $xml XML from Google
|
||||
* @param JRegistry $options Google options object
|
||||
* @param JGoogleAuth $auth Google data http client object
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function __construct(SimpleXMLElement $xml, JRegistry $options = null, JGoogleAuth $auth = null)
|
||||
{
|
||||
$this->xml = $xml;
|
||||
|
||||
parent::__construct($options, $auth);
|
||||
|
||||
if (isset($this->auth) && !$this->auth->getOption('scope'))
|
||||
{
|
||||
$this->auth->setOption('scope', 'https://picasaweb.google.com/data/');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to delete a Picasa album
|
||||
*
|
||||
* @param mixed $match Check for most up to date album
|
||||
*
|
||||
* @return boolean Success or failure.
|
||||
*
|
||||
* @since 12.3
|
||||
* @throws UnexpectedValueException
|
||||
*/
|
||||
public function delete($match = '*')
|
||||
{
|
||||
if ($this->isAuthenticated())
|
||||
{
|
||||
$url = $this->getLink();
|
||||
|
||||
if ($match === true)
|
||||
{
|
||||
$match = $this->xml->xpath('./@gd:etag');
|
||||
$match = $match[0];
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
$jdata = $this->query($url, null, array('GData-Version' => 2, 'If-Match' => $match), 'delete');
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
if (strpos($e->getMessage(), 'Error code 412 received requesting data: Mismatch: etags') === 0)
|
||||
{
|
||||
throw new RuntimeException("Etag match failed: `$match`.");
|
||||
}
|
||||
throw $e;
|
||||
}
|
||||
|
||||
if ($jdata->body != '')
|
||||
{
|
||||
throw new UnexpectedValueException("Unexpected data received from Google: `{$jdata->body}`.");
|
||||
}
|
||||
$this->xml = null;
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get the album link
|
||||
*
|
||||
* @param string $type Type of link to return
|
||||
*
|
||||
* @return string Link or false on failure
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function getLink($type = 'edit')
|
||||
{
|
||||
$links = $this->xml->link;
|
||||
|
||||
foreach ($links as $link)
|
||||
{
|
||||
if ($link->attributes()->rel == $type)
|
||||
{
|
||||
return (string) $link->attributes()->href;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get the title of the album
|
||||
*
|
||||
* @return string Album title
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function getTitle()
|
||||
{
|
||||
return (string) $this->xml->children()->title;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get the summary of the album
|
||||
*
|
||||
* @return string Album summary
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function getSummary()
|
||||
{
|
||||
return (string) $this->xml->children()->summary;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get the location of the album
|
||||
*
|
||||
* @return string Album location
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function getLocation()
|
||||
{
|
||||
return (string) $this->xml->children('gphoto', true)->location;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get the access level of the album
|
||||
*
|
||||
* @return string Album access level
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function getAccess()
|
||||
{
|
||||
return (string) $this->xml->children('gphoto', true)->access;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get the time of the album
|
||||
*
|
||||
* @return double Album time
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function getTime()
|
||||
{
|
||||
return (double) $this->xml->children('gphoto', true)->timestamp / 1000;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to set the title of the album
|
||||
*
|
||||
* @param string $title New album title
|
||||
*
|
||||
* @return JGoogleDataPicasaAlbum The object for method chaining
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function setTitle($title)
|
||||
{
|
||||
$this->xml->children()->title = $title;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to set the summary of the album
|
||||
*
|
||||
* @param string $summary New album summary
|
||||
*
|
||||
* @return JGoogleDataPicasaAlbum The object for method chaining
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function setSummary($summary)
|
||||
{
|
||||
$this->xml->children()->summary = $summary;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to set the location of the album
|
||||
*
|
||||
* @param string $location New album location
|
||||
*
|
||||
* @return JGoogleDataPicasaAlbum The object for method chaining
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function setLocation($location)
|
||||
{
|
||||
$this->xml->children('gphoto', true)->location = $location;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to set the access level of the album
|
||||
*
|
||||
* @param string $access New album access
|
||||
*
|
||||
* @return JGoogleDataPicasaAlbum The object for method chaining
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function setAccess($access)
|
||||
{
|
||||
$this->xml->children('gphoto', true)->access = $access;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to set the time of the album
|
||||
*
|
||||
* @param int $time New album time
|
||||
*
|
||||
* @return JGoogleDataPicasaAlbum The object for method chaining
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function setTime($time)
|
||||
{
|
||||
$this->xml->children('gphoto', true)->timestamp = $time * 1000;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to modify a Picasa Album
|
||||
*
|
||||
* @param string $match Optional eTag matching parameter
|
||||
*
|
||||
* @return mixed Data from Google.
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function save($match = '*')
|
||||
{
|
||||
if ($this->isAuthenticated())
|
||||
{
|
||||
$url = $this->getLink();
|
||||
|
||||
if ($match === true)
|
||||
{
|
||||
$match = $this->xml->xpath('./@gd:etag');
|
||||
$match = $match[0];
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
$headers = array('GData-Version' => 2, 'Content-type' => 'application/atom+xml', 'If-Match' => $match);
|
||||
$jdata = $this->query($url, $this->xml->asXML(), $headers, 'put');
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
if (strpos($e->getMessage(), 'Error code 412 received requesting data: Mismatch: etags') === 0)
|
||||
{
|
||||
throw new RuntimeException("Etag match failed: `$match`.");
|
||||
}
|
||||
throw $e;
|
||||
}
|
||||
|
||||
$this->xml = $this->safeXML($jdata->body);
|
||||
|
||||
return $this;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Refresh Picasa Album
|
||||
*
|
||||
* @return mixed Data from Google
|
||||
*
|
||||
* @since 12.3
|
||||
* @throws UnexpectedValueException
|
||||
*/
|
||||
public function refresh()
|
||||
{
|
||||
if ($this->isAuthenticated())
|
||||
{
|
||||
$url = $this->getLink();
|
||||
$jdata = $this->query($url, null, array('GData-Version' => 2));
|
||||
$this->xml = $this->safeXML($jdata->body);
|
||||
|
||||
return $this;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to retrieve a list of Picasa Photos
|
||||
*
|
||||
* @return mixed Data from Google
|
||||
*
|
||||
* @since 12.3
|
||||
* @throws UnexpectedValueException
|
||||
*/
|
||||
public function listPhotos()
|
||||
{
|
||||
if ($this->isAuthenticated())
|
||||
{
|
||||
$url = $this->getLink('http://schemas.google.com/g/2005#feed');
|
||||
$jdata = $this->query($url, null, array('GData-Version' => 2));
|
||||
$xml = $this->safeXML($jdata->body);
|
||||
|
||||
if (isset($xml->children()->entry))
|
||||
{
|
||||
$items = array();
|
||||
|
||||
foreach ($xml->children()->entry as $item)
|
||||
{
|
||||
$items[] = new JGoogleDataPicasaPhoto($item, $this->options, $this->auth);
|
||||
}
|
||||
return $items;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new UnexpectedValueException("Unexpected data received from Google: `{$jdata->body}`.");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add photo
|
||||
*
|
||||
* @param string $file Path of file to upload
|
||||
* @param string $title Title to give to file (defaults to filename)
|
||||
* @param string $summary Description of the file
|
||||
*
|
||||
* @return mixed Data from Google
|
||||
*
|
||||
* @since 12.3
|
||||
* @throws RuntimeException
|
||||
*/
|
||||
public function upload($file, $title = '', $summary = '')
|
||||
{
|
||||
if ($this->isAuthenticated())
|
||||
{
|
||||
jimport('joomla.filesystem.file');
|
||||
$title = $title != '' ? $title : JFile::getName($file);
|
||||
|
||||
if (!($type = $this->getMIME($file)))
|
||||
{
|
||||
throw new RuntimeException("Inappropriate file type.");
|
||||
}
|
||||
if (!($data = JFile::read($file)))
|
||||
{
|
||||
throw new RuntimeException("Cannot access file: `$file`");
|
||||
}
|
||||
|
||||
$xml = new SimpleXMLElement('<entry></entry>');
|
||||
$xml->addAttribute('xmlns', 'http://www.w3.org/2005/Atom');
|
||||
$xml->addChild('title', $title);
|
||||
$xml->addChild('summary', $summary);
|
||||
$cat = $xml->addChild('category', '');
|
||||
$cat->addAttribute('scheme', 'http://schemas.google.com/g/2005#kind');
|
||||
$cat->addAttribute('term', 'http://schemas.google.com/photos/2007#photo');
|
||||
|
||||
$post = "Media multipart posting\n";
|
||||
$post .= "--END_OF_PART\n";
|
||||
$post .= "Content-Type: application/atom+xml\n\n";
|
||||
$post .= $xml->asXML() . "\n";
|
||||
$post .= "--END_OF_PART\n";
|
||||
$post .= "Content-Type: {$type}\n\n";
|
||||
$post .= $data;
|
||||
|
||||
$jdata = $this->query($this->getLink(), $post, array('GData-Version' => 2, 'Content-Type: multipart/related'), 'post');
|
||||
|
||||
return new JGoogleDataPicasaPhoto($this->safeXML($jdata->body), $this->options, $this->auth);
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add photo
|
||||
*
|
||||
* @param string $file Filename
|
||||
*
|
||||
* @return mixed Data from Google
|
||||
*
|
||||
* @since 12.3
|
||||
* @throws UnexpectedValueException
|
||||
*/
|
||||
protected function getMIME($file)
|
||||
{
|
||||
switch (strtolower(JFile::getExt($file)))
|
||||
{
|
||||
case 'bmp':
|
||||
case 'bm':
|
||||
return 'image/bmp';
|
||||
case 'gif':
|
||||
return 'image/gif';
|
||||
case 'jpg':
|
||||
case 'jpeg':
|
||||
case 'jpe':
|
||||
case 'jif':
|
||||
case 'jfif':
|
||||
case 'jfi':
|
||||
return 'image/jpeg';
|
||||
case 'png':
|
||||
return 'image/png';
|
||||
case '3gp':
|
||||
return 'video/3gpp';
|
||||
case 'avi':
|
||||
return 'video/avi';
|
||||
case 'mov':
|
||||
case 'moov':
|
||||
case 'qt':
|
||||
return 'video/quicktime';
|
||||
case 'mp4':
|
||||
case 'm4a':
|
||||
case 'm4p':
|
||||
case 'm4b':
|
||||
case 'm4r':
|
||||
case 'm4v':
|
||||
return 'video/mp4';
|
||||
case 'mpg':
|
||||
case 'mpeg':
|
||||
case 'mp1':
|
||||
case 'mp2':
|
||||
case 'mp3':
|
||||
case 'm1v':
|
||||
case 'm1a':
|
||||
case 'm2a':
|
||||
case 'mpa':
|
||||
case 'mpv':
|
||||
return 'video/mpeg';
|
||||
case 'asf':
|
||||
return 'video/x-ms-asf';
|
||||
case 'wmv':
|
||||
return 'video/x-ms-wmv';
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
1
libraries/joomla/google/data/picasa/index.html
Normal file
1
libraries/joomla/google/data/picasa/index.html
Normal file
@ -0,0 +1 @@
|
||||
<!DOCTYPE html><title></title>
|
368
libraries/joomla/google/data/picasa/photo.php
Normal file
368
libraries/joomla/google/data/picasa/photo.php
Normal file
@ -0,0 +1,368 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Platform
|
||||
* @subpackage Google
|
||||
*
|
||||
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved
|
||||
* @license GNU General Public License version 2 or later; see LICENSE
|
||||
*/
|
||||
|
||||
defined('JPATH_PLATFORM') or die;
|
||||
|
||||
/**
|
||||
* Google Picasa data class for the Joomla Platform.
|
||||
*
|
||||
* @package Joomla.Platform
|
||||
* @subpackage Google
|
||||
* @since 12.3
|
||||
*/
|
||||
class JGoogleDataPicasaPhoto extends JGoogleData
|
||||
{
|
||||
/**
|
||||
* @var SimpleXMLElement The photo's XML
|
||||
* @since 12.3
|
||||
*/
|
||||
protected $xml;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param SimpleXMLElement $xml XML from Google
|
||||
* @param JRegistry $options Google options object
|
||||
* @param JGoogleAuth $auth Google data http client object
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function __construct(SimpleXMLElement $xml, JRegistry $options = null, JGoogleAuth $auth = null)
|
||||
{
|
||||
$this->xml = $xml;
|
||||
|
||||
parent::__construct($options, $auth);
|
||||
|
||||
if (isset($this->auth) && !$this->auth->getOption('scope'))
|
||||
{
|
||||
$this->auth->setOption('scope', 'https://picasaweb.google.com/data/');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to delete a Picasa photo
|
||||
*
|
||||
* @param mixed $match Check for most up to date photo
|
||||
*
|
||||
* @return boolean Success or failure.
|
||||
*
|
||||
* @since 12.3
|
||||
* @throws UnexpectedValueException
|
||||
*/
|
||||
public function delete($match = '*')
|
||||
{
|
||||
if ($this->isAuthenticated())
|
||||
{
|
||||
$url = $this->getLink();
|
||||
|
||||
if ($match === true)
|
||||
{
|
||||
$match = $this->xml->xpath('./@gd:etag');
|
||||
$match = $match[0];
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
$jdata = $this->query($url, null, array('GData-Version' => 2, 'If-Match' => $match), 'delete');
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
if (strpos($e->getMessage(), 'Error code 412 received requesting data: Mismatch: etags') === 0)
|
||||
{
|
||||
throw new RuntimeException("Etag match failed: `$match`.");
|
||||
}
|
||||
throw $e;
|
||||
}
|
||||
|
||||
if ($jdata->body != '')
|
||||
{
|
||||
throw new UnexpectedValueException("Unexpected data received from Google: `{$jdata->body}`.");
|
||||
}
|
||||
$this->xml = null;
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get the photo link
|
||||
*
|
||||
* @param string $type Type of link to return
|
||||
*
|
||||
* @return string Link or false on failure
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function getLink($type = 'edit')
|
||||
{
|
||||
$links = $this->xml->link;
|
||||
|
||||
foreach ($links as $link)
|
||||
{
|
||||
if ($link->attributes()->rel == $type)
|
||||
{
|
||||
return (string) $link->attributes()->href;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get the photo's URL
|
||||
*
|
||||
* @return string Link
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function getURL()
|
||||
{
|
||||
return (string) $this->xml->children()->content->attributes()->src;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get the photo's thumbnails
|
||||
*
|
||||
* @return array An array of thumbnails
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function getThumbnails()
|
||||
{
|
||||
$thumbs = array();
|
||||
|
||||
foreach ($this->xml->children('media', true)->group->thumbnail as $item)
|
||||
{
|
||||
$url = (string) $item->attributes()->url;
|
||||
$width = (int) $item->attributes()->width;
|
||||
$height = (int) $item->attributes()->height;
|
||||
$thumbs[$width] = array('url' => $url, 'w' => $width, 'h' => $height);
|
||||
}
|
||||
return $thumbs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get the title of the photo
|
||||
*
|
||||
* @return string Photo title
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function getTitle()
|
||||
{
|
||||
return (string) $this->xml->children()->title;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get the summary of the photo
|
||||
*
|
||||
* @return string Photo description
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function getSummary()
|
||||
{
|
||||
return (string) $this->xml->children()->summary;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get the access level of the photo
|
||||
*
|
||||
* @return string Photo access level
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function getAccess()
|
||||
{
|
||||
return (string) $this->xml->children('gphoto', true)->access;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get the time of the photo
|
||||
*
|
||||
* @return double Photo time
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function getTime()
|
||||
{
|
||||
return (double) $this->xml->children('gphoto', true)->timestamp / 1000;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get the size of the photo
|
||||
*
|
||||
* @return int Photo size
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function getSize()
|
||||
{
|
||||
return (int) $this->xml->children('gphoto', true)->size;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get the height of the photo
|
||||
*
|
||||
* @return int Photo height
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function getHeight()
|
||||
{
|
||||
return (int) $this->xml->children('gphoto', true)->height;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get the width of the photo
|
||||
*
|
||||
* @return int Photo width
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function getWidth()
|
||||
{
|
||||
return (int) $this->xml->children('gphoto', true)->width;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to set the title of the photo
|
||||
*
|
||||
* @param string $title New photo title
|
||||
*
|
||||
* @return JGoogleDataPicasaPhoto The object for method chaining
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function setTitle($title)
|
||||
{
|
||||
$this->xml->children()->title = $title;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to set the summary of the photo
|
||||
*
|
||||
* @param string $summary New photo description
|
||||
*
|
||||
* @return JGoogleDataPicasaPhoto The object for method chaining
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function setSummary($summary)
|
||||
{
|
||||
$this->xml->children()->summary = $summary;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to set the access level of the photo
|
||||
*
|
||||
* @param string $access New photo access level
|
||||
*
|
||||
* @return JGoogleDataPicasaPhoto The object for method chaining
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function setAccess($access)
|
||||
{
|
||||
$this->xml->children('gphoto', true)->access = $access;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to set the time of the photo
|
||||
*
|
||||
* @param int $time New photo time
|
||||
*
|
||||
* @return JGoogleDataPicasaPhoto The object for method chaining
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function setTime($time)
|
||||
{
|
||||
$this->xml->children('gphoto', true)->timestamp = $time * 1000;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to modify a Picasa Photo
|
||||
*
|
||||
* @param string $match Optional eTag matching parameter
|
||||
*
|
||||
* @return mixed Data from Google.
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function save($match = '*')
|
||||
{
|
||||
if ($this->isAuthenticated())
|
||||
{
|
||||
$url = $this->getLink();
|
||||
|
||||
if ($match === true)
|
||||
{
|
||||
$match = $this->xml->xpath('./@gd:etag');
|
||||
$match = $match[0];
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
$headers = array('GData-Version' => 2, 'Content-type' => 'application/atom+xml', 'If-Match' => $match);
|
||||
$jdata = $this->query($url, $this->xml->asXML(), $headers, 'put');
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
if (strpos($e->getMessage(), 'Error code 412 received requesting data: Mismatch: etags') === 0)
|
||||
{
|
||||
throw new RuntimeException("Etag match failed: `$match`.");
|
||||
}
|
||||
throw $e;
|
||||
}
|
||||
|
||||
$this->xml = $this->safeXML($jdata->body);
|
||||
|
||||
return $this;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Refresh photo data
|
||||
*
|
||||
* @return mixed Data from Google
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function refresh()
|
||||
{
|
||||
if ($this->isAuthenticated())
|
||||
{
|
||||
$url = $this->getLink();
|
||||
$jdata = $this->query($url, null, array('GData-Version' => 2));
|
||||
$this->xml = $this->safeXML($jdata->body);
|
||||
|
||||
return $this;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
95
libraries/joomla/google/data/plus.php
Normal file
95
libraries/joomla/google/data/plus.php
Normal file
@ -0,0 +1,95 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Platform
|
||||
* @subpackage Google
|
||||
*
|
||||
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved
|
||||
* @license GNU General Public License version 2 or later; see LICENSE
|
||||
*/
|
||||
|
||||
defined('JPATH_PLATFORM') or die;
|
||||
|
||||
/**
|
||||
* Google+ data class for the Joomla Platform.
|
||||
*
|
||||
* @package Joomla.Platform
|
||||
* @subpackage Google
|
||||
* @since 1234
|
||||
*/
|
||||
class JGoogleDataPlus extends JGoogleData
|
||||
{
|
||||
/**
|
||||
* @var JGoogleDataPlusPeople Google+ API object for people.
|
||||
* @since 12.3
|
||||
*/
|
||||
protected $people;
|
||||
|
||||
/**
|
||||
* @var JGoogleDataPlusActivities Google+ API object for people.
|
||||
* @since 12.3
|
||||
*/
|
||||
protected $activities;
|
||||
|
||||
/**
|
||||
* @var JGoogleDataPlusComments Google+ API object for people.
|
||||
* @since 12.3
|
||||
*/
|
||||
protected $comments;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param JRegistry $options Google options object
|
||||
* @param JGoogleAuth $auth Google data http client object
|
||||
*
|
||||
* @since 1234
|
||||
*/
|
||||
public function __construct(JRegistry $options = null, JGoogleAuth $auth = null)
|
||||
{
|
||||
// Setup the default API url if not already set.
|
||||
$options->def('api.url', 'https://www.googleapis.com/plus/v1/');
|
||||
|
||||
parent::__construct($options, $auth);
|
||||
|
||||
if (isset($this->auth) && !$this->auth->getOption('scope'))
|
||||
{
|
||||
$this->auth->setOption('scope', 'https://www.googleapis.com/auth/plus.me');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Magic method to lazily create API objects
|
||||
*
|
||||
* @param string $name Name of property to retrieve
|
||||
*
|
||||
* @return JGoogleDataPlus Google+ API object (people, activities, comments).
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function __get($name)
|
||||
{
|
||||
switch ($name)
|
||||
{
|
||||
case 'people':
|
||||
if ($this->people == null)
|
||||
{
|
||||
$this->people = new JGoogleDataPlusPeople($this->options, $this->auth);
|
||||
}
|
||||
return $this->people;
|
||||
|
||||
case 'activities':
|
||||
if ($this->activities == null)
|
||||
{
|
||||
$this->activities = new JGoogleDataPlusActivities($this->options, $this->auth);
|
||||
}
|
||||
return $this->activities;
|
||||
|
||||
case 'comments':
|
||||
if ($this->comments == null)
|
||||
{
|
||||
$this->comments = new JGoogleDataPlusComments($this->options, $this->auth);
|
||||
}
|
||||
return $this->comments;
|
||||
}
|
||||
}
|
||||
}
|
197
libraries/joomla/google/data/plus/activities.php
Normal file
197
libraries/joomla/google/data/plus/activities.php
Normal file
@ -0,0 +1,197 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Platform
|
||||
* @subpackage Google
|
||||
*
|
||||
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved
|
||||
* @license GNU General Public License version 2 or later; see LICENSE
|
||||
*/
|
||||
|
||||
defined('JPATH_PLATFORM') or die;
|
||||
|
||||
/**
|
||||
* Google+ data class for the Joomla Platform.
|
||||
*
|
||||
* @package Joomla.Platform
|
||||
* @subpackage Google
|
||||
* @since 1234
|
||||
*/
|
||||
class JGoogleDataPlusActivities extends JGoogleData
|
||||
{
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param JRegistry $options Google options object
|
||||
* @param JGoogleAuth $auth Google data http client object
|
||||
*
|
||||
* @since 1234
|
||||
*/
|
||||
public function __construct(JRegistry $options = null, JGoogleAuth $auth = null)
|
||||
{
|
||||
parent::__construct($options, $auth);
|
||||
|
||||
if (isset($this->auth) && !$this->auth->getOption('scope'))
|
||||
{
|
||||
$this->auth->setOption('scope', 'https://www.googleapis.com/auth/plus.me');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* List all of the activities in the specified collection for a particular user.
|
||||
*
|
||||
* @param string $userId The ID of the user to get activities for. The special value "me" can be used to indicate the authenticated user.
|
||||
* @param string $collection The collection of activities to list. Acceptable values are: "public".
|
||||
* @param string $fields Used to specify the fields you want returned.
|
||||
* @param integer $max The maximum number of people to include in the response, used for paging.
|
||||
* @param string $token The continuation token, used to page through large result sets. To get the next page of results, set this
|
||||
* parameter to the value of "nextPageToken" from the previous response. This token may be of any length.
|
||||
* @param string $alt Specifies an alternative representation type. Acceptable values are: "json" - Use JSON format (default)
|
||||
*
|
||||
* @return mixed Data from Google
|
||||
*
|
||||
* @since 1234
|
||||
*/
|
||||
public function listActivities($userId, $collection, $fields = null, $max = 10, $token = null, $alt = null)
|
||||
{
|
||||
if ($this->isAuthenticated())
|
||||
{
|
||||
$url = $this->getOption('api.url') . 'people/' . $userId . '/activities/' . $collection;
|
||||
|
||||
// Check if fields is specified.
|
||||
if ($fields)
|
||||
{
|
||||
$url .= '?fields=' . $fields;
|
||||
}
|
||||
|
||||
// Check if max is specified.
|
||||
if ($max != 10)
|
||||
{
|
||||
$url .= (strpos($url, '?') === false) ? '?maxResults=' : '&maxResults=';
|
||||
$url .= $max;
|
||||
}
|
||||
|
||||
// Check if token is specified.
|
||||
if ($token)
|
||||
{
|
||||
$url .= (strpos($url, '?') === false) ? '?pageToken=' : '&pageToken=';
|
||||
$url .= $token;
|
||||
}
|
||||
|
||||
// Check if alt is specified.
|
||||
if ($alt)
|
||||
{
|
||||
$url .= (strpos($url, '?') === false) ? '?alt=' : '&alt=';
|
||||
$url .= $alt;
|
||||
}
|
||||
|
||||
$jdata = $this->auth->query($url);
|
||||
|
||||
return json_decode($jdata->body, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an activity.
|
||||
*
|
||||
* @param string $id The ID of the activity to get.
|
||||
* @param string $fields Used to specify the fields you want returned.
|
||||
* @param string $alt Specifies an alternative representation type. Acceptable values are: "json" - Use JSON format (default)
|
||||
*
|
||||
* @return mixed Data from Google
|
||||
*
|
||||
* @since 1234
|
||||
*/
|
||||
public function getActivity($id, $fields = null, $alt = null)
|
||||
{
|
||||
if ($this->isAuthenticated())
|
||||
{
|
||||
$url = $this->getOption('api.url') . 'activities/' . $id;
|
||||
|
||||
// Check if fields is specified.
|
||||
if ($fields)
|
||||
{
|
||||
$url .= '?fields=' . $fields;
|
||||
}
|
||||
|
||||
// Check if alt is specified.
|
||||
if ($alt)
|
||||
{
|
||||
$url .= (strpos($url, '?') === false) ? '?alt=' : '&alt=';
|
||||
$url .= $alt;
|
||||
}
|
||||
|
||||
$jdata = $this->auth->query($url);
|
||||
|
||||
return json_decode($jdata->body, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Search all public activities.
|
||||
*
|
||||
* @param string $query Full-text search query string.
|
||||
* @param string $fields Used to specify the fields you want returned.
|
||||
* @param string $language Specify the preferred language to search with. https://developers.google.com/+/api/search#available-languages
|
||||
* @param integer $max The maximum number of people to include in the response, used for paging.
|
||||
* @param string $order Specifies how to order search results. Acceptable values are "best" and "recent".
|
||||
* @param string $token The continuation token, used to page through large result sets. To get the next page of results, set this
|
||||
* parameter to the value of "nextPageToken" from the previous response. This token may be of any length.
|
||||
*
|
||||
* @return mixed Data from Google
|
||||
*
|
||||
* @since 1234
|
||||
*/
|
||||
public function search($query, $fields = null, $language = null, $max = 10, $order = null, $token = null)
|
||||
{
|
||||
if ($this->isAuthenticated())
|
||||
{
|
||||
$url = $this->getOption('api.url') . 'activities?query=' . urlencode($query);
|
||||
|
||||
// Check if fields is specified.
|
||||
if ($fields)
|
||||
{
|
||||
$url .= '&fields=' . $fields;
|
||||
}
|
||||
|
||||
// Check if language is specified.
|
||||
if ($language)
|
||||
{
|
||||
$url .= '&language=' . $language;
|
||||
}
|
||||
|
||||
// Check if max is specified.
|
||||
if ($max != 10)
|
||||
{
|
||||
$url .= '&maxResults=' . $max;
|
||||
}
|
||||
|
||||
// Check if order is specified.
|
||||
if ($order)
|
||||
{
|
||||
$url .= '&orderBy=' . $order;
|
||||
}
|
||||
|
||||
// Check of token is specified.
|
||||
if ($token)
|
||||
{
|
||||
$url .= '&pageToken=' . $token;
|
||||
}
|
||||
|
||||
$jdata = $this->auth->query($url);
|
||||
|
||||
return json_decode($jdata->body, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
135
libraries/joomla/google/data/plus/comments.php
Normal file
135
libraries/joomla/google/data/plus/comments.php
Normal file
@ -0,0 +1,135 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Platform
|
||||
* @subpackage Google
|
||||
*
|
||||
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved
|
||||
* @license GNU General Public License version 2 or later; see LICENSE
|
||||
*/
|
||||
|
||||
defined('JPATH_PLATFORM') or die;
|
||||
|
||||
/**
|
||||
* Google+ data class for the Joomla Platform.
|
||||
*
|
||||
* @package Joomla.Platform
|
||||
* @subpackage Google
|
||||
* @since 1234
|
||||
*/
|
||||
class JGoogleDataPlusComments extends JGoogleData
|
||||
{
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param JRegistry $options Google options object
|
||||
* @param JGoogleAuth $auth Google data http client object
|
||||
*
|
||||
* @since 1234
|
||||
*/
|
||||
public function __construct(JRegistry $options = null, JGoogleAuth $auth = null)
|
||||
{
|
||||
parent::__construct($options, $auth);
|
||||
|
||||
if (isset($this->auth) && !$this->auth->getOption('scope'))
|
||||
{
|
||||
$this->auth->setOption('scope', 'https://www.googleapis.com/auth/plus.me');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* List all of the comments for an activity.
|
||||
*
|
||||
* @param string $activityId The ID of the activity to get comments for.
|
||||
* @param string $fields Used to specify the fields you want returned.
|
||||
* @param integer $max The maximum number of people to include in the response, used for paging.
|
||||
* @param string $order The order in which to sort the list of comments. Acceptable values are "ascending" and "descending".
|
||||
* @param string $token The continuation token, used to page through large result sets. To get the next page of results, set this
|
||||
* parameter to the value of "nextPageToken" from the previous response. This token may be of any length.
|
||||
* @param string $alt Specifies an alternative representation type. Acceptable values are: "json" - Use JSON format (default)
|
||||
*
|
||||
* @return mixed Data from Google
|
||||
*
|
||||
* @since 1234
|
||||
*/
|
||||
public function listComments($activityId, $fields = null, $max = 20, $order = null, $token = null, $alt = null)
|
||||
{
|
||||
if ($this->isAuthenticated())
|
||||
{
|
||||
$url = $this->getOption('api.url') . 'activities/' . $activityId . '/comments';
|
||||
|
||||
// Check if fields is specified.
|
||||
if ($fields)
|
||||
{
|
||||
$url .= '?fields=' . $fields;
|
||||
}
|
||||
|
||||
// Check if max is specified.
|
||||
if ($max != 20)
|
||||
{
|
||||
$url .= (strpos($url, '?') === false) ? '?maxResults=' : '&maxResults=';
|
||||
$url .= $max;
|
||||
}
|
||||
|
||||
// Check if order is specified.
|
||||
if ($order)
|
||||
{
|
||||
$url .= (strpos($url, '?') === false) ? '?orderBy=' : '&orderBy=';
|
||||
$url .= $order;
|
||||
}
|
||||
|
||||
// Check of token is specified.
|
||||
if ($token)
|
||||
{
|
||||
$url .= (strpos($url, '?') === false) ? '?pageToken=' : '&pageToken=';
|
||||
$url .= $token;
|
||||
}
|
||||
|
||||
// Check if alt is specified.
|
||||
if ($alt)
|
||||
{
|
||||
$url .= (strpos($url, '?') === false) ? '?alt=' : '&alt=';
|
||||
$url .= $alt;
|
||||
}
|
||||
|
||||
$jdata = $this->auth->query($url);
|
||||
|
||||
return json_decode($jdata->body, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a comment.
|
||||
*
|
||||
* @param string $id The ID of the comment to get.
|
||||
* @param string $fields Used to specify the fields you want returned.
|
||||
*
|
||||
* @return mixed Data from Google
|
||||
*
|
||||
* @since 1234
|
||||
*/
|
||||
public function getComment($id, $fields = null)
|
||||
{
|
||||
if ($this->isAuthenticated())
|
||||
{
|
||||
$url = $this->getOption('api.url') . 'comments/' . $id;
|
||||
|
||||
// Check if fields is specified.
|
||||
if ($fields)
|
||||
{
|
||||
$url .= '?fields=' . $fields;
|
||||
}
|
||||
|
||||
$jdata = $this->auth->query($url);
|
||||
|
||||
return json_decode($jdata->body, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
1
libraries/joomla/google/data/plus/index.html
Normal file
1
libraries/joomla/google/data/plus/index.html
Normal file
@ -0,0 +1 @@
|
||||
<!DOCTYPE html><title></title>
|
174
libraries/joomla/google/data/plus/people.php
Normal file
174
libraries/joomla/google/data/plus/people.php
Normal file
@ -0,0 +1,174 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Platform
|
||||
* @subpackage Google
|
||||
*
|
||||
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved
|
||||
* @license GNU General Public License version 2 or later; see LICENSE
|
||||
*/
|
||||
|
||||
defined('JPATH_PLATFORM') or die;
|
||||
|
||||
/**
|
||||
* Google+ data class for the Joomla Platform.
|
||||
*
|
||||
* @package Joomla.Platform
|
||||
* @subpackage Google
|
||||
* @since 1234
|
||||
*/
|
||||
class JGoogleDataPlusPeople extends JGoogleData
|
||||
{
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param JRegistry $options Google options object
|
||||
* @param JGoogleAuth $auth Google data http client object
|
||||
*
|
||||
* @since 1234
|
||||
*/
|
||||
public function __construct(JRegistry $options = null, JGoogleAuth $auth = null)
|
||||
{
|
||||
parent::__construct($options, $auth);
|
||||
|
||||
if (isset($this->auth) && !$this->auth->getOption('scope'))
|
||||
{
|
||||
$this->auth->setOption('scope', 'https://www.googleapis.com/auth/plus.me');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a person's profile.
|
||||
*
|
||||
* @param string $id The ID of the person to get the profile for. The special value "me" can be used to indicate the authenticated user.
|
||||
* @param string $fields Used to specify the fields you want returned.
|
||||
*
|
||||
* @return mixed Data from Google
|
||||
*
|
||||
* @since 1234
|
||||
*/
|
||||
public function getPeople($id, $fields = null)
|
||||
{
|
||||
if ($this->isAuthenticated())
|
||||
{
|
||||
$url = $this->getOption('api.url') . 'people/' . $id;
|
||||
|
||||
// Check if fields is specified.
|
||||
if ($fields)
|
||||
{
|
||||
$url .= '?fields=' . $fields;
|
||||
}
|
||||
|
||||
$jdata = $this->auth->query($url);
|
||||
|
||||
return json_decode($jdata->body, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Search all public profiles.
|
||||
*
|
||||
* @param string $query Specify a query string for full text search of public text in all profiles.
|
||||
* @param string $fields Used to specify the fields you want returned.
|
||||
* @param string $language Specify the preferred language to search with. https://developers.google.com/+/api/search#available-languages
|
||||
* @param integer $max The maximum number of people to include in the response, used for paging.
|
||||
* @param string $token The continuation token, used to page through large result sets. To get the next page of results, set this
|
||||
* parameter to the value of "nextPageToken" from the previous response. This token may be of any length.
|
||||
*
|
||||
* @return mixed Data from Google
|
||||
*
|
||||
* @since 1234
|
||||
*/
|
||||
public function search($query, $fields = null, $language = null, $max = 10, $token = null)
|
||||
{
|
||||
if ($this->isAuthenticated())
|
||||
{
|
||||
$url = $this->getOption('api.url') . 'people?query=' . urlencode($query);
|
||||
|
||||
// Check if fields is specified.
|
||||
if ($fields)
|
||||
{
|
||||
$url .= '&fields=' . $fields;
|
||||
}
|
||||
|
||||
// Check if language is specified.
|
||||
if ($language)
|
||||
{
|
||||
$url .= '&language=' . $language;
|
||||
}
|
||||
|
||||
// Check if max is specified.
|
||||
if ($max != 10)
|
||||
{
|
||||
$url .= '&maxResults=' . $max;
|
||||
}
|
||||
|
||||
// Check of token is specified.
|
||||
if ($token)
|
||||
{
|
||||
$url .= '&pageToken=' . $token;
|
||||
}
|
||||
|
||||
$jdata = $this->auth->query($url);
|
||||
|
||||
return json_decode($jdata->body, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* List all of the people in the specified collection for a particular activity.
|
||||
*
|
||||
* @param string $activityId The ID of the activity to get the list of people for.
|
||||
* @param string $collection The collection of people to list. Acceptable values are "plusoners" and "resharers".
|
||||
* @param string $fields Used to specify the fields you want returned.
|
||||
* @param integer $max The maximum number of people to include in the response, used for paging.
|
||||
* @param string $token The continuation token, used to page through large result sets. To get the next page of results, set this
|
||||
* parameter to the value of "nextPageToken" from the previous response. This token may be of any length.
|
||||
*
|
||||
* @return mixed Data from Google
|
||||
*
|
||||
* @since 1234
|
||||
*/
|
||||
public function listByActivity($activityId, $collection, $fields = null, $max = 10, $token = null)
|
||||
{
|
||||
if ($this->isAuthenticated())
|
||||
{
|
||||
$url = $this->getOption('api.url') . 'activities/' . $activityId . '/people/' . $collection;
|
||||
|
||||
// Check if fields is specified.
|
||||
if ($fields)
|
||||
{
|
||||
$url .= '?fields=' . $fields;
|
||||
}
|
||||
|
||||
// Check if max is specified.
|
||||
if ($max != 10)
|
||||
{
|
||||
$url .= (strpos($url, '?') === false) ? '?maxResults=' : '&maxResults=';
|
||||
$url .= $max;
|
||||
}
|
||||
|
||||
// Check of token is specified.
|
||||
if ($token)
|
||||
{
|
||||
$url .= (strpos($url, '?') === false) ? '?pageToken=' : '&pageToken=';
|
||||
$url .= $token;
|
||||
}
|
||||
|
||||
$jdata = $this->auth->query($url);
|
||||
|
||||
return json_decode($jdata->body, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
132
libraries/joomla/google/embed.php
Normal file
132
libraries/joomla/google/embed.php
Normal file
@ -0,0 +1,132 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Platform
|
||||
* @subpackage Google
|
||||
*
|
||||
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved
|
||||
* @license GNU General Public License version 2 or later; see LICENSE
|
||||
*/
|
||||
|
||||
defined('JPATH_PLATFORM') or die;
|
||||
jimport('joomla.environment.uri');
|
||||
|
||||
/**
|
||||
* Google API object class for the Joomla Platform.
|
||||
*
|
||||
* @package Joomla.Platform
|
||||
* @subpackage Google
|
||||
* @since 12.3
|
||||
*/
|
||||
abstract class JGoogleEmbed
|
||||
{
|
||||
/**
|
||||
* @var JRegistry Options for the Google data object.
|
||||
* @since 12.3
|
||||
*/
|
||||
protected $options;
|
||||
|
||||
/**
|
||||
* @var JUri URI of the page being rendered.
|
||||
* @since 12.3
|
||||
*/
|
||||
protected $uri;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param JRegistry $options Google options object
|
||||
* @param JUri $uri URL of the page being rendered
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function __construct(JRegistry $options = null, JUri $uri = null)
|
||||
{
|
||||
$this->options = $options ? $options : new JRegistry;
|
||||
$this->uri = $uri ? $uri : new JUri;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to retrieve the javascript header for the embed API
|
||||
*
|
||||
* @return string The header
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function isSecure()
|
||||
{
|
||||
return $this->uri->getScheme() == 'https';
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to retrieve the header for the API
|
||||
*
|
||||
* @return string The header
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
abstract public function getHeader();
|
||||
|
||||
/**
|
||||
* Method to retrieve the body for the API
|
||||
*
|
||||
* @return string The body
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
abstract public function getBody();
|
||||
|
||||
/**
|
||||
* Method to output the javascript header for the embed API
|
||||
*
|
||||
* @return null
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function echoHeader()
|
||||
{
|
||||
echo $this->getHeader();
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to output the body for the API
|
||||
*
|
||||
* @return null
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function echoBody()
|
||||
{
|
||||
echo $this->getBody();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an option from the JGoogleEmbed instance.
|
||||
*
|
||||
* @param string $key The name of the option to get.
|
||||
*
|
||||
* @return mixed The option value.
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function getOption($key)
|
||||
{
|
||||
return $this->options->get($key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set an option for the JGoogleEmbed instance.
|
||||
*
|
||||
* @param string $key The name of the option to set.
|
||||
* @param mixed $value The option value to set.
|
||||
*
|
||||
* @return JGoogleEmbed This object for method chaining.
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function setOption($key, $value)
|
||||
{
|
||||
$this->options->set($key, $value);
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
332
libraries/joomla/google/embed/analytics.php
Normal file
332
libraries/joomla/google/embed/analytics.php
Normal file
@ -0,0 +1,332 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Platform
|
||||
* @subpackage Google
|
||||
*
|
||||
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved
|
||||
* @license GNU General Public License version 2 or later; see LICENSE
|
||||
*/
|
||||
|
||||
defined('JPATH_PLATFORM') or die;
|
||||
|
||||
/**
|
||||
* Google Analytics embed class for the Joomla Platform.
|
||||
*
|
||||
* @package Joomla.Platform
|
||||
* @subpackage Google
|
||||
* @since 12.3
|
||||
*/
|
||||
class JGoogleEmbedAnalytics extends JGoogleEmbed
|
||||
{
|
||||
/**
|
||||
* Method to get the tracking code
|
||||
*
|
||||
* @return string The Google Analytics tracking code
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function getCode()
|
||||
{
|
||||
return $this->getOption('code');
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to set the tracking code
|
||||
*
|
||||
* @param string $code The Google Analytics tracking code
|
||||
*
|
||||
* @return JGoogleEmbedAnalytics The object for method chaining
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function setCode($code)
|
||||
{
|
||||
$this->setOption('code', $code);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the javascript is set to be asynchronous
|
||||
*
|
||||
* @return boolean True if asynchronous
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function isAsync()
|
||||
{
|
||||
return $this->getOption('async') === null ? true : $this->getOption('async');
|
||||
}
|
||||
|
||||
/**
|
||||
* Load javascript asynchronously
|
||||
*
|
||||
* @return JGoogleEmbedAnalytics The object for method chaining
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function useAsync()
|
||||
{
|
||||
$this->setOption('async', true);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load javascript synchronously
|
||||
*
|
||||
* @return JGoogleEmbedAnalytics The object for method chaining
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function useSync()
|
||||
{
|
||||
$this->setOption('async', false);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an analytics call
|
||||
*
|
||||
* @param string $method The name of the function
|
||||
* @param array $params The parameters for the call
|
||||
*
|
||||
* @return array The added call
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function addCall($method, $params = array())
|
||||
{
|
||||
$call = array('name' => $method, 'params' => $params);
|
||||
|
||||
$calls = $this->listCalls();
|
||||
$calls[] = $call;
|
||||
$this->setOption('calls', $calls);
|
||||
|
||||
return $call;
|
||||
}
|
||||
|
||||
/**
|
||||
* List the analytics calls to be executed
|
||||
*
|
||||
* @return array A list of calls
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function listCalls()
|
||||
{
|
||||
return $this->getOption('calls') ? $this->getOption('calls') : array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a call from the stack
|
||||
*
|
||||
* @param int $index Index of call to delete (defaults to last added call)
|
||||
*
|
||||
* @return array The deleted call
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function deleteCall($index = null)
|
||||
{
|
||||
$calls = $this->listCalls();
|
||||
|
||||
if ($index === null)
|
||||
{
|
||||
$index = count($calls) - 1;
|
||||
}
|
||||
|
||||
$call = $calls[$index];
|
||||
unset($calls[$index]);
|
||||
$calls = array_values($calls);
|
||||
$this->setOption('calls', $calls);
|
||||
|
||||
return $call;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a javascript function from the call parameters
|
||||
*
|
||||
* @param string $method The name of the function
|
||||
* @param array $params The parameters for the call
|
||||
*
|
||||
* @return string The created call
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function createCall($method, $params = array())
|
||||
{
|
||||
$params = array_values($params);
|
||||
|
||||
if ($this->isAsync())
|
||||
{
|
||||
$output = "_gaq.push(['{$method}',";
|
||||
$output .= substr(json_encode($params), 1, -1);
|
||||
$output .= ']);';
|
||||
}
|
||||
else
|
||||
{
|
||||
$output = "pageTracker.{$method}(";
|
||||
$output .= substr(json_encode($params), 1, -1);
|
||||
$output .= ');';
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a custom variable to the analytics
|
||||
*
|
||||
* @param int $slot The slot to store the variable in (1-5)
|
||||
* @param string $name The variable name
|
||||
* @param string $value The variable value
|
||||
* @param int $scope The scope of the variable (1: visitor level, 2: session level, 3: page level)
|
||||
*
|
||||
* @return array The added call
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function addCustomVar($slot, $name, $value, $scope = 3)
|
||||
{
|
||||
return $this->addCall('_setCustomVar', array($slot, $name, $value, $scope));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the code to create a custom analytics variable
|
||||
*
|
||||
* @param int $slot The slot to store the variable in (1-5)
|
||||
* @param string $name The variable name
|
||||
* @param string $value The variable value
|
||||
* @param int $scope The scope of the variable (1: visitor level, 2: session level, 3: page level)
|
||||
*
|
||||
* @return string The created call
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function createCustomVar($slot, $name, $value, $scope = 3)
|
||||
{
|
||||
return $this->createCall('_setCustomVar', array($slot, $name, $value, $scope));
|
||||
}
|
||||
|
||||
/**
|
||||
* Track an analytics event
|
||||
*
|
||||
* @param string $category The general event category
|
||||
* @param string $action The event action
|
||||
* @param string $label The event description
|
||||
* @param string $value The value of the event
|
||||
* @param boolean $noninteract Don't allow this event to impact bounce statistics
|
||||
*
|
||||
* @return array The added call
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function addEvent($category, $action, $label = null, $value = null, $noninteract = false)
|
||||
{
|
||||
return $this->addCall('_trackEvent', array($category, $action, $label, $value, $noninteract));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the code to track an analytics event
|
||||
*
|
||||
* @param string $category The general event category
|
||||
* @param string $action The event action
|
||||
* @param string $label The event description
|
||||
* @param string $value The value of the event
|
||||
* @param boolean $noninteract Don't allow this event to impact bounce statistics
|
||||
*
|
||||
* @return string The created call
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function createEvent($category, $action, $label = null, $value = null, $noninteract = false)
|
||||
{
|
||||
return $this->createCall('_trackEvent', array($category, $action, $label, $value, $noninteract));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get code to load Google Analytics javascript
|
||||
*
|
||||
* @return string Javascript code
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function getHeader()
|
||||
{
|
||||
if (!$this->isAsync())
|
||||
{
|
||||
// Synchronous code is included only in the body
|
||||
return '';
|
||||
}
|
||||
|
||||
if (!$this->getOption('code'))
|
||||
{
|
||||
throw new UnexpectedValueException('A Google Analytics tracking code is required.');
|
||||
}
|
||||
|
||||
$code = $this->getOption('code');
|
||||
|
||||
$output = '<script type="text/javascript">';
|
||||
$output .= 'var _gaq = _gaq || [];';
|
||||
$output .= "_gaq.push(['_setAccount', '{$code}']);";
|
||||
|
||||
foreach ($this->listCalls() as $call)
|
||||
{
|
||||
$output .= $this->createCall($call['name'], $call['params']);
|
||||
}
|
||||
|
||||
$output .= '_gaq.push(["_trackPageview"]);';
|
||||
$output .= '</script>';
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Google Analytics only needs to be included in the header
|
||||
*
|
||||
* @return null
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function getBody()
|
||||
{
|
||||
if (!$this->getOption('code'))
|
||||
{
|
||||
throw new UnexpectedValueException('A Google Analytics tracking code is required.');
|
||||
}
|
||||
|
||||
$prefix = $this->isSecure() ? 'https://ssl' : 'http://www';
|
||||
$code = $this->getOption('code');
|
||||
|
||||
if ($this->isAsync())
|
||||
{
|
||||
$output = '<script type="text/javascript">';
|
||||
$output .= '(function() {';
|
||||
$output .= 'var ga = document.createElement("script"); ga.type = "text/javascript"; ga.async = true;';
|
||||
$output .= "ga.src = '{$prefix}.google-analytics.com/ga.js';";
|
||||
$output .= 'var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(ga, s);';
|
||||
$output .= '})();';
|
||||
$output .= '</script>';
|
||||
}
|
||||
else
|
||||
{
|
||||
$output = '<script type="text/javascript">';
|
||||
$output .= "document.write(unescape(\"%3Cscript src='{$prefix}.google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E\"));";
|
||||
$output .= '</script>';
|
||||
$output .= '<script type="text/javascript">';
|
||||
$output .= 'try{';
|
||||
$output .= "var pageTracker = _gat._getTracker('{$code}');";
|
||||
|
||||
foreach ($this->listCalls() as $call)
|
||||
{
|
||||
$output .= $this->createCall($call['name'], $call['params']);
|
||||
}
|
||||
|
||||
$output .= 'pageTracker._trackPageview();';
|
||||
$output .= '} catch(err) {}</script>';
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
}
|
1
libraries/joomla/google/embed/index.html
Normal file
1
libraries/joomla/google/embed/index.html
Normal file
@ -0,0 +1 @@
|
||||
<!DOCTYPE html><title></title>
|
698
libraries/joomla/google/embed/maps.php
Normal file
698
libraries/joomla/google/embed/maps.php
Normal file
@ -0,0 +1,698 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Platform
|
||||
* @subpackage Google
|
||||
*
|
||||
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved
|
||||
* @license GNU General Public License version 2 or later; see LICENSE
|
||||
*/
|
||||
|
||||
defined('JPATH_PLATFORM') or die;
|
||||
|
||||
/**
|
||||
* Google Maps embed class for the Joomla Platform.
|
||||
*
|
||||
* @package Joomla.Platform
|
||||
* @subpackage Google
|
||||
* @since 12.3
|
||||
*/
|
||||
class JGoogleEmbedMaps extends JGoogleEmbed
|
||||
{
|
||||
|
||||
/**
|
||||
* @var JHttp The HTTP client object to use in sending HTTP requests.
|
||||
* @since 12.3
|
||||
*/
|
||||
protected $http;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param JRegistry $options Google options object
|
||||
* @param JUri $uri URL of the page being rendered
|
||||
* @param JHttp $http Http client for geocoding requests
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function __construct(JRegistry $options = null, JUri $uri = null, JHttp $http = null)
|
||||
{
|
||||
parent::__construct($options = null, $uri = null);
|
||||
$this->http = $http ? $http : new JHttp($this->options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get the API key
|
||||
*
|
||||
* @return string The Google Maps API key
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function getKey()
|
||||
{
|
||||
return $this->getOption('key');
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to set the API key
|
||||
*
|
||||
* @param string $key The Google Maps API key
|
||||
*
|
||||
* @return JGoogleEmbedMaps The object for method chaining
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function setKey($key)
|
||||
{
|
||||
$this->setOption('key', $key);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get the id of the map div
|
||||
*
|
||||
* @return string The ID
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function getMapID()
|
||||
{
|
||||
return $this->getOption('mapid') ? $this->getOption('mapid') : 'map_canvas';
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to set the map div id
|
||||
*
|
||||
* @param string $id The ID
|
||||
*
|
||||
* @return JGoogleEmbedMaps The object for method chaining
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function setMapID($id)
|
||||
{
|
||||
$this->setOption('mapid', $id);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get the class of the map div
|
||||
*
|
||||
* @return string The class
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function getMapClass()
|
||||
{
|
||||
return $this->getOption('mapclass') ? $this->getOption('mapclass') : '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to set the map div class
|
||||
*
|
||||
* @param string $class The class
|
||||
*
|
||||
* @return JGoogleEmbedMaps The object for method chaining
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function setMapClass($class)
|
||||
{
|
||||
$this->setOption('mapclass', $class);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get the style of the map div
|
||||
*
|
||||
* @return string The style
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function getMapStyle()
|
||||
{
|
||||
return $this->getOption('mapstyle') ? $this->getOption('mapstyle') : '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to set the map div style
|
||||
*
|
||||
* @param string $style The style
|
||||
*
|
||||
* @return JGoogleEmbedMaps The object for method chaining
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function setMapStyle($style)
|
||||
{
|
||||
$this->setOption('mapstyle', $style);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get the map type setting
|
||||
*
|
||||
* @return string The class
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function getMapType()
|
||||
{
|
||||
return $this->getOption('maptype') ? $this->getOption('maptype') : 'ROADMAP';
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to set the map type ()
|
||||
*
|
||||
* @param string $type Valid types are ROADMAP, SATELLITE, HYBRID, and TERRAIN
|
||||
*
|
||||
* @return JGoogleEmbedMaps The object for method chaining
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function setMapType($type)
|
||||
{
|
||||
$this->setOption('maptype', strtoupper($type));
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get additional map options
|
||||
*
|
||||
* @return string The options
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function getAdditionalMapOptions()
|
||||
{
|
||||
return $this->getOption('mapoptions') ? $this->getOption('mapoptions') : array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to add additional map options
|
||||
*
|
||||
* @param array $options Additional map options
|
||||
*
|
||||
* @return JGoogleEmbedMaps The object for method chaining
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function setAdditionalMapOptions($options)
|
||||
{
|
||||
$this->setOption('mapoptions', $options);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get additional map options
|
||||
*
|
||||
* @return string The options
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function getAdditionalJavascript()
|
||||
{
|
||||
return $this->getOption('extrascript') ? $this->getOption('extrascript') : '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to add additional javascript
|
||||
*
|
||||
* @param array $script Additional javascript
|
||||
*
|
||||
* @return JGoogleEmbedMaps The object for method chaining
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function setAdditionalJavascript($script)
|
||||
{
|
||||
$this->setOption('extrascript', $script);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get the zoom
|
||||
*
|
||||
* @return int The zoom level
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function getZoom()
|
||||
{
|
||||
return $this->getOption('zoom') ? $this->getOption('zoom') : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to set the map zoom
|
||||
*
|
||||
* @param int $zoom Zoom level (0 is whole world)
|
||||
*
|
||||
* @return JGoogleEmbedMaps The object for method chaining
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function setZoom($zoom)
|
||||
{
|
||||
$this->setOption('zoom', $zoom);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to set the center of the map
|
||||
*
|
||||
* @return mixed A latitude longitude array or an address string
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function getCenter()
|
||||
{
|
||||
return $this->getOption('mapcenter') ? $this->getOption('mapcenter') : array(0, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to set the center of the map
|
||||
*
|
||||
* @param mixed $location A latitude/longitude array or an address string
|
||||
* @param mixed $title Title of marker or false for no marker
|
||||
* @param array $markeroptions Options for marker
|
||||
*
|
||||
* @return JGoogleEmbedMaps The latitude/longitude of the center or false on failure
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function setCenter($location, $title = true, $markeroptions = array())
|
||||
{
|
||||
if ($title)
|
||||
{
|
||||
$title = is_string($title) ? $title : null;
|
||||
|
||||
if (!$marker = $this->addMarker($location, $title, $markeroptions))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
$location = $marker['loc'];
|
||||
}
|
||||
elseif (is_string($location))
|
||||
{
|
||||
$geocode = $this->geocodeAddress($location);
|
||||
|
||||
if (!$geocode)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
$location = $geocode['geometry']['location'];
|
||||
$location = array_values($location);
|
||||
}
|
||||
|
||||
$this->setOption('mapcenter', $location);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a marker to the map
|
||||
*
|
||||
* @param mixed $location A latitude longitude array or an address string
|
||||
* @param mixed $title The hover-text for the marker
|
||||
* @param array $options Options for marker
|
||||
*
|
||||
* @return mixed The marker or false on failure
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function addMarker($location, $title = null, $options = array())
|
||||
{
|
||||
if (is_string($location))
|
||||
{
|
||||
if (!$title)
|
||||
{
|
||||
$title = $location;
|
||||
}
|
||||
|
||||
$geocode = $this->geocodeAddress($location);
|
||||
|
||||
if (!$geocode)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
$location = $geocode['geometry']['location'];
|
||||
}
|
||||
elseif (!$title)
|
||||
{
|
||||
$title = implode(', ', $location);
|
||||
}
|
||||
|
||||
$location = array_values($location);
|
||||
$marker = array('loc' => $location, 'title' => $title, 'options' => $options);
|
||||
|
||||
$markers = $this->listMarkers();
|
||||
$markers[] = $marker;
|
||||
$this->setOption('markers', $markers);
|
||||
|
||||
return $marker;
|
||||
}
|
||||
|
||||
/**
|
||||
* List the markers added to the map
|
||||
*
|
||||
* @return array A list of markers
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function listMarkers()
|
||||
{
|
||||
return $this->getOption('markers') ? $this->getOption('markers') : array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a marker from the map
|
||||
*
|
||||
* @param int $index Index of marker to delete (defaults to last added marker)
|
||||
*
|
||||
* @return array The latitude/longitude of the deleted marker
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function deleteMarker($index = null)
|
||||
{
|
||||
$markers = $this->listMarkers();
|
||||
|
||||
if ($index === null)
|
||||
{
|
||||
$index = count($markers) - 1;
|
||||
}
|
||||
|
||||
if ($index >= count($markers) || $index < 0)
|
||||
{
|
||||
throw new OutOfBoundsException('Marker index out of bounds.');
|
||||
}
|
||||
|
||||
$marker = $markers[$index];
|
||||
unset($markers[$index]);
|
||||
$markers = array_values($markers);
|
||||
$this->setOption('markers', $markers);
|
||||
|
||||
return $marker;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the javascript is set to be asynchronous
|
||||
*
|
||||
* @return boolean True if asynchronous
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function isAsync()
|
||||
{
|
||||
return $this->getOption('async') === null ? true : $this->getOption('async');
|
||||
}
|
||||
|
||||
/**
|
||||
* Load javascript asynchronously
|
||||
*
|
||||
* @return JGoogleEmbedMaps The object for method chaining
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function useAsync()
|
||||
{
|
||||
$this->setOption('async', true);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load javascript synchronously
|
||||
*
|
||||
* @return JGoogleEmbedAMaps The object for method chaining
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function useSync()
|
||||
{
|
||||
$this->setOption('async', false);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get callback function for async javascript loading
|
||||
*
|
||||
* @return string The ID
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function getAsyncCallback()
|
||||
{
|
||||
return $this->getOption('callback') ? $this->getOption('callback') : 'initialize';
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to set the callback function for async javascript loading
|
||||
*
|
||||
* @param string $callback The callback function name
|
||||
*
|
||||
* @return JGoogleEmbedMaps The object for method chaining
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function setAsyncCallback($callback)
|
||||
{
|
||||
$this->setOption('callback', $callback);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a sensor is set to be required
|
||||
*
|
||||
* @return boolean True if asynchronous
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function hasSensor()
|
||||
{
|
||||
return $this->getOption('sensor') === null ? false : $this->getOption('sensor');
|
||||
}
|
||||
|
||||
/**
|
||||
* Require access to sensor data
|
||||
*
|
||||
* @return JGoogleEmbedMaps The object for method chaining
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function useSensor()
|
||||
{
|
||||
$this->setOption('sensor', true);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Don't require access to sensor data
|
||||
*
|
||||
* @return JGoogleEmbedAMaps The object for method chaining
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function noSensor()
|
||||
{
|
||||
$this->setOption('sensor', false);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks how the script should be loaded
|
||||
*
|
||||
* @return string Autoload type (onload, jquery, mootools, or false)
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function getAutoload()
|
||||
{
|
||||
return $this->getOption('autoload') ? $this->getOption('autoload') : 'false';
|
||||
}
|
||||
|
||||
/**
|
||||
* Automatically add the callback to the window
|
||||
*
|
||||
* @param string $type The method to add the callback (options are onload, jquery, mootools, and false)
|
||||
*
|
||||
* @return JGoogleEmbedAMaps The object for method chaining
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function setAutoload($type = 'onload')
|
||||
{
|
||||
$this->setOption('autoload', $type);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get code to load Google Maps javascript
|
||||
*
|
||||
* @return string Javascript code
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function getHeader()
|
||||
{
|
||||
if (!$this->getOption('key'))
|
||||
{
|
||||
throw new UnexpectedValueException('A Google Maps API key is required.');
|
||||
}
|
||||
|
||||
$zoom = $this->getZoom();
|
||||
$center = $this->getCenter();
|
||||
$maptype = $this->getMapType();
|
||||
$id = $this->getMapID();
|
||||
$scheme = $this->isSecure() ? 'https' : 'http';
|
||||
$key = $this->getKey();
|
||||
$sensor = $this->hasSensor() ? 'true' : 'false';
|
||||
|
||||
$setup = 'var mapOptions = {';
|
||||
$setup .= "zoom: {$zoom},";
|
||||
$setup .= "center: new google.maps.LatLng({$center[0]},{$center[1]}),";
|
||||
$setup .= "mapTypeId: google.maps.MapTypeId.{$maptype},";
|
||||
$setup .= substr(json_encode($this->getAdditionalMapOptions()), 1, -1);
|
||||
$setup .= '};';
|
||||
$setup .= "var map = new google.maps.Map(document.getElementById('{$id}'), mapOptions);";
|
||||
|
||||
foreach ($this->listMarkers() as $marker)
|
||||
{
|
||||
$loc = $marker['loc'];
|
||||
$title = $marker['title'];
|
||||
$options = $marker['options'];
|
||||
|
||||
$setup .= 'new google.maps.Marker({';
|
||||
$setup .= "position: new google.maps.LatLng({$loc[0]},{$loc[1]}),";
|
||||
$setup .= 'map: map,';
|
||||
$setup .= "title:'{$title}',";
|
||||
$setup .= substr(json_encode($options), 1, -1);
|
||||
$setup .= '});';
|
||||
}
|
||||
|
||||
$setup .= $this->getAdditionalJavascript();
|
||||
|
||||
if ($this->isAsync())
|
||||
{
|
||||
$asynccallback = $this->getAsyncCallback();
|
||||
|
||||
$output = '<script type="text/javascript">';
|
||||
$output .= "function {$asynccallback}() {";
|
||||
$output .= $setup;
|
||||
$output .= '}';
|
||||
|
||||
$onload = "function() {";
|
||||
$onload .= 'var script = document.createElement("script");';
|
||||
$onload .= 'script.type = "text/javascript";';
|
||||
$onload .= "script.src = '{$scheme}://maps.googleapis.com/maps/api/js?key={$key}&sensor={$sensor}&callback={$asynccallback}';";
|
||||
$onload .= 'document.body.appendChild(script);';
|
||||
$onload .= '}';
|
||||
}
|
||||
else
|
||||
{
|
||||
$output = "<script type='text/javascript' src='{$scheme}://maps.googleapis.com/maps/api/js?key={$key}&sensor={$sensor}'>";
|
||||
$output .= '</script>';
|
||||
$output .= '<script type="text/javascript">';
|
||||
|
||||
$onload = "function() {";
|
||||
$onload .= $setup;
|
||||
$onload .= '}';
|
||||
}
|
||||
|
||||
switch ($this->getAutoload())
|
||||
{
|
||||
case 'onload':
|
||||
$output .= "window.onload={$onload};";
|
||||
break;
|
||||
|
||||
case 'jquery':
|
||||
$output .= "$(document).ready({$onload});";
|
||||
break;
|
||||
|
||||
case 'mootools':
|
||||
$output .= "window.addEvent('domready',{$onload});";
|
||||
break;
|
||||
}
|
||||
|
||||
$output .= '</script>';
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to retrieve the div that the map is loaded into
|
||||
*
|
||||
* @return string The body
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function getBody()
|
||||
{
|
||||
$id = $this->getMapID();
|
||||
$class = $this->getMapClass();
|
||||
$style = $this->getMapStyle();
|
||||
|
||||
$output = "<div id='{$id}'";
|
||||
|
||||
if (!empty($class))
|
||||
{
|
||||
$output .= " class='{$class}'";
|
||||
}
|
||||
|
||||
if (!empty($style))
|
||||
{
|
||||
$output .= " style='{$style}'";
|
||||
}
|
||||
|
||||
$output .= '></div>';
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get the location information back from an address
|
||||
*
|
||||
* @param string $address The address to geocode
|
||||
*
|
||||
* @return array An array containing Google's geocode data
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function geocodeAddress($address)
|
||||
{
|
||||
$url = 'http://maps.googleapis.com/maps/api/geocode/json?sensor=false&address=' . urlencode($address);
|
||||
$response = $this->http->get($url);
|
||||
|
||||
if ($response->code < 200 || $response->code >= 300)
|
||||
{
|
||||
throw new RuntimeException('Error code ' . $response->code . ' received geocoding address: ' . $response->body . '.');
|
||||
}
|
||||
|
||||
$data = json_decode($response->body, true);
|
||||
|
||||
if (!$data)
|
||||
{
|
||||
throw new RuntimeException('Invalid json received geocoding address: ' . $response->body . '.');
|
||||
}
|
||||
if ($data['status'] != 'OK')
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return $data['results'][0];
|
||||
}
|
||||
}
|
161
libraries/joomla/google/google.php
Normal file
161
libraries/joomla/google/google.php
Normal file
@ -0,0 +1,161 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Platform
|
||||
* @subpackage Google
|
||||
*
|
||||
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved
|
||||
* @license GNU General Public License version 2 or later; see LICENSE
|
||||
*/
|
||||
|
||||
defined('JPATH_PLATFORM') or die;
|
||||
|
||||
/**
|
||||
* Joomla Platform class for interacting with the Google APIs.
|
||||
*
|
||||
* @property-read JGoogleData $data Google API object for data.
|
||||
* @property-read JGoogleEmbed $embed Google API object for embed generation.
|
||||
*
|
||||
* @package Joomla.Platform
|
||||
* @subpackage Google
|
||||
* @since 12.3
|
||||
*/
|
||||
class JGoogle
|
||||
{
|
||||
/**
|
||||
* @var JRegistry Options for the Google object.
|
||||
* @since 12.3
|
||||
*/
|
||||
protected $options;
|
||||
|
||||
/**
|
||||
* @var JAuth The authentication client object to use in sending authenticated HTTP requests.
|
||||
* @since 12.3
|
||||
*/
|
||||
protected $auth;
|
||||
|
||||
/**
|
||||
* @var JGoogleData Google API object for data request.
|
||||
* @since 12.3
|
||||
*/
|
||||
protected $data;
|
||||
|
||||
/**
|
||||
* @var JGoogleEmbed Google API object for embed generation.
|
||||
* @since 12.3
|
||||
*/
|
||||
protected $embed;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param JRegistry $options Google options object.
|
||||
* @param JAuth $auth The authentication client object.
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function __construct(JRegistry $options = null, JGoogleAuth $auth = null)
|
||||
{
|
||||
$this->options = isset($options) ? $options : new JRegistry;
|
||||
$this->auth = isset($auth) ? $auth : new JGoogleAuthOauth2($this->options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to create JGoogleData objects
|
||||
*
|
||||
* @param string $name Name of property to retrieve
|
||||
* @param JRegistry $options Google options object.
|
||||
* @param JAuth $auth The authentication client object.
|
||||
*
|
||||
* @return JGoogleData Google data API object.
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function data($name, $options = null, $auth = null)
|
||||
{
|
||||
if ($this->options && !$options)
|
||||
{
|
||||
$options = $this->options;
|
||||
}
|
||||
if ($this->auth && !$auth)
|
||||
{
|
||||
$auth = $this->auth;
|
||||
}
|
||||
switch ($name)
|
||||
{
|
||||
case 'plus':
|
||||
case 'Plus':
|
||||
return new JGoogleDataPlus($options, $auth);
|
||||
case 'picasa':
|
||||
case 'Picasa':
|
||||
return new JGoogleDataPicasa($options, $auth);
|
||||
case 'adsense':
|
||||
case 'Adsense':
|
||||
return new JGoogleDataAdsense($options, $auth);
|
||||
case 'calendar':
|
||||
case 'Calendar':
|
||||
return new JGoogleDataCalendar($options, $auth);
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to create JGoogleEmbed objects
|
||||
*
|
||||
* @param string $name Name of property to retrieve
|
||||
* @param JRegistry $options Google options object.
|
||||
*
|
||||
* @return JGoogleEmbed Google embed API object.
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function embed($name, $options = null)
|
||||
{
|
||||
if ($this->options && !$options)
|
||||
{
|
||||
$options = $this->options;
|
||||
}
|
||||
switch ($name)
|
||||
{
|
||||
case 'maps':
|
||||
case 'Maps':
|
||||
return new JGoogleEmbedMaps($options);
|
||||
case 'analytics':
|
||||
case 'Analytics':
|
||||
return new JGoogleEmbedAnalytics($options);
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an option from the JGoogle instance.
|
||||
*
|
||||
* @param string $key The name of the option to get.
|
||||
*
|
||||
* @return mixed The option value.
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function getOption($key)
|
||||
{
|
||||
return $this->options->get($key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set an option for the JGoogle instance.
|
||||
*
|
||||
* @param string $key The name of the option to set.
|
||||
* @param mixed $value The option value to set.
|
||||
*
|
||||
* @return JGoogle This object for method chaining.
|
||||
*
|
||||
* @since 12.3
|
||||
*/
|
||||
public function setOption($key, $value)
|
||||
{
|
||||
$this->options->set($key, $value);
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
1
libraries/joomla/google/index.html
Normal file
1
libraries/joomla/google/index.html
Normal file
@ -0,0 +1 @@
|
||||
<!DOCTYPE html><title></title>
|
Reference in New Issue
Block a user