diff --git a/README.md b/README.md new file mode 100644 index 0000000..feffa06 --- /dev/null +++ b/README.md @@ -0,0 +1,39 @@ +# Eden PHP Library +##Designed for rapid prototyping, with less code. + +Eden is purely a library packed with core concepts and web services. You can use Eden on top of any CMS or framework you choose. At Openovate Labs, we use Eden for all of our internal products which in turn keeps Eden updated, evolving and constantly expanding. Eden takes advantage of PHP 5.3 with the tools available to get products made faster. Eden works with major players including: + +* Google +* Facebook +* Twitter +* Tumblr +* Four Square +* Get Satisfaction +* Eventbrite +* Zappos +* Web Charge +* Paypal +* Authorize.net +* Amazon +* Jabber + +#Contibuting to Eden + +##Setting up your machine with the Eden repository and your fork + +1. Fork the main Eden repository (https://github.com/Openovate/eden) +2. Fire up your local terminal and clone the *MAIN EDEN REPOSITORY* (git clone git://github.com/Openovate/eden.git) +3. Add your *FORKED EDEN REPOSITORY* as a remote (git remote add fork git@github.com:*github_username*/eden.git) + +##Making pull requests + +1. Before anything, make sure to update the *MAIN EDEN REPOSITORY*. (git checkout master; git pull origin master) +2. Once updated with the latest code, create a new branch with a branch name describing what your changes are (git checkout -b bugfix/fix-twitter-auth) + Possible types: + - bugfix + - feature + - improvement +3. Make your code changes. Always make sure to sign-off (-s) on all commits made (git commit -s -m "Commit message") +4. Once you've committed all the code to this branch, push the branch to your *FORKED EDEN REPOSITORY* (git push fork bugfix/fix-twitter-auth) +5. Go back to your *FORKED EDEN REPOSITORY* on GitHub and submit a pull request. +6. An Eden developer will review your code and merge it in when it has been classified as suitable. diff --git a/library/eden.php b/library/eden.php new file mode 100644 index 0000000..7d2d744 --- /dev/null +++ b/library/eden.php @@ -0,0 +1,284 @@ + +/* + * This file is part of the Eden package. + * (c) 2009-2011 Christian Blanquera + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +require_once dirname(__FILE__).'/eden/event.php'; + +/** + * The starting point of every framework call. + * + * @author Christian Blanquera cblanquera@openovate.com + */ +function eden() { + $class = Eden::i(); + if(func_num_args() == 0) { + return $class; + } + + $args = func_get_args(); + return $class->__invoke($args); +} + +/** + * Defines the starting point of every framework call. + * Starts laying out how classes and methods are handled. + * + * @package Eden + * @category framework + * @author Christian Blanquera cblanquera@openovate.com + */ +class Eden extends Eden_Event { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_root = NULL; + protected static $_active = NULL; + + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getSingleton(__CLASS__); + } + + public function __construct() { + if(!self::$_active) { + self::$_active = $this; + } + + $this->_root = dirname(__FILE__); + } + + public function __call($name, $args) { + //first try to call the parent call + try { + return parent::__call($name, $args); + //this means something in the route went wrong + } catch(Eden_Route_Exception $e) { + //now try to call parent with the eden prefix + return parent::__call('Eden_'.$name, $args); + } + } + + /* Public Methods + -------------------------------*/ + /** + * Sets the root path + * + * @param string + * @return this + */ + public function setRoot($root) { + Eden_Error::i()->argument(1, 'string'); + + if(!class_exists('Eden_Path')) { + Eden_Loader::i()->load('Eden_Path'); + } + + $this->_root = (string) Eden_Path::i($root); + + return $this; + } + + /** + * Returns the root path + * + * @return string + */ + public function getRoot() { + return $this->_root; + } + + /** + * Get Active Application + * + * @return Eden + */ + public function getActiveApp() { + return self::$_active; + } + + /** + * Sets up Autoloading + * + * @param string|array path + * @return this + */ + public function setLoader() { + if(!class_exists('Eden_Loader')) { + //require autoload + require_once dirname(__FILE__).'/eden/loader.php'; + } + + //set autoload class as the autoload handler + spl_autoload_register(array(Eden_Loader::i(), 'handler')); + + //we need Eden_Path to fix the path formatting + if(!class_exists('Eden_Path')) { + Eden_Loader::i()->addRoot(dirname(__FILE__))->load('Eden_Path'); + } + + //get paths + $paths = func_get_args(); + + //if no paths + if(empty($paths)) { + //do nothing more + return $this; + } + + //no dupes + $paths = array_unique($paths); + + //for each path + foreach($paths as $i => $path) { + if(!is_string($path) && !is_null($path)) { + continue; + } + + if($path) { + //format the path + $path = (string) Eden_Path::i($path); + } else { + $path = $this->_root; + } + + //if path is not a real path + if(!is_dir($path)) { + //append the root + $path = $this->_root.$path; + } + + //if the path is still a real path + if(is_dir($path)) { + //add the root + Eden_Loader::i()->addRoot($path); + } + } + + return $this; + } + + /** + * Sets class routes + * + * @param string|array routes + * @return Eden_Framework + */ + public function routeClasses($routes) { + Eden_Error::i()->argument(1, 'string', 'array', 'bool'); + $route = Eden_Route::i()->getClass(); + + if($routes === true) { + $route->route('Cache', 'Eden_Cache') + ->route('Registry', 'Eden_Registry') + ->route('Model', 'Eden_Model') + ->route('Collection', 'Eden_Collection') + ->route('Cookie', 'Eden_Cookie') + ->route('Session', 'Eden_Session') + ->route('Template', 'Eden_Template') + ->route('Curl', 'Eden_Curl') + ->route('Event', 'Eden_Event') + ->route('Path', 'Eden_Path') + ->route('File', 'Eden_File') + ->route('Folder', 'Eden_Folder') + ->route('Image', 'Eden_Image') + ->route('Mysql', 'Eden_Mysql') + ->route('Type', 'Eden_Type'); + + return $this; + } + + if(is_string($routes)) { + $routes = include($routes); + } + + foreach($routes as $alias => $class) { + $route->route($alias, $class); + } + + return $this; + } + + /** + * Sets method routes + * + * @param string|array routes + * @return Eden_Framework + */ + public function routeMethods($routes) { + Eden_Error::i()->argument(1, 'string', 'array', 'bool'); + $route = Eden_Route::i()->getMethod(); + + if(is_bool($routes)) { + $route->route(NULL, 'output', 'Eden_Debug'); + return $this; + } + + if(is_string($routes)) { + $routes = include($routes); + } + + //walk the routes + foreach($routes as $method => $routePath) { + //if the path is a string + if(is_string($routePath)) { + //turn it into an array + $routePath = array($routePath); + } + + //if the path is an array and it's not empty + if(is_array($routePath) && !empty($routePath)) { + //if the size is 1 + if(count($routePath) == 1) { + //they mean the methods have the same name + $routePath[] = $method; + } + + //route the method + $route->route($method, $routePath[0], $routePath[1]); + } + } + + return $this; + } + + /** + * Starts a session + * + * @return this + */ + public function startSession() { + //get the session class + Eden_Session::i()->start(); + + return $this; + } + + /** + * Sets the PHP timezone + * + * @return this + */ + public function setTimezone($zone) { + Eden_Error::i()->argument(1, 'string'); + + date_default_timezone_set($zone); + + return $this; + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/LICENSE.txt b/library/eden/LICENSE.txt new file mode 100644 index 0000000..da712da --- /dev/null +++ b/library/eden/LICENSE.txt @@ -0,0 +1,15 @@ +Eden PHP Library +Copyright (C) 2012-2013 Christian Blanquera, Openovate Labs + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see http://www.gnu.org/licenses/. \ No newline at end of file diff --git a/library/eden/amazon/base.php b/library/eden/amazon/base.php new file mode 100644 index 0000000..63f6aba --- /dev/null +++ b/library/eden/amazon/base.php @@ -0,0 +1,183 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Amazon S3 + * + * @package Eden + * @category amazon + * @author Clark Galgo cgalgo@openovate.com + */ +class Eden_Amazon_Base extends Eden_Class { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_host = 'ecs.amazonaws.'; + protected $_uri = '/onca/xml'; + protected $_params = array(); + protected $_method = 'GET'; + protected $_publicKey = NULL; + protected $_privateKey = NULL; + protected $_canonicalizedQuery = NULL; + protected $_stringToSign = NULL; + protected $_signature = NULL; + protected $_requestUrl = NULL; + + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + public function __construct($privateKey, $publicKey) { + //argument testing + Eden_Amazon_Error::i() + ->argument(1, 'string') + ->argument(2, 'string'); + + $this->_privateKey = $privateKey; + $this->_publicKey = $publicKey; + } + + /* Public Methods + -------------------------------*/ + /** + * Returns the meta of the last call + * + * @return array + */ + public function getMeta() { + + return $this->_meta; + } + + /* Set timestamp + * + * @param string|null + * @return this + */ + public function setTimestamp($time = NULL) { + //argument 1 must be a string, integer or null + Eden_Amazon_Error::i()->argument(1, 'string', 'int', 'null'); + //if they dont set time + if($time == NULL) { + //set the time for crrent time + $time = time(); + } + //if it is string + if(is_string($time)) { + //comvert it to integer + $time = strtotime($time); + } + //well format time + $this->_params['Timestamp'] = gmdate("Y-m-d\TH:i:s\Z", $time); + + return $this; + } + + /* Set api version + * + * @param string + * @return this + */ + public function setVersion($version) { + //argument 1 must be a string + Eden_Amazon_Error::i()->argument(1, 'string'); + $this->_params['Version'] = $version; + + return $this; + } + + /* Protected Methods + -------------------------------*/ + protected function _sendRequest() { + //set curl + return $this->Eden_Curl() + ->setUrl($this->_requestUrl) + ->verifyHost(false) + ->verifyPeer(false) + ->setTimeout(60) + ->getResponse(); + } + + protected function _setSignature($date = NULL) { + //if date is not set + if(is_null($date) || empty($date)) { + $this->_signature = base64_encode(hash_hmac("sha256", $this->_stringToSign, $this->_privateKey, True)); + $this->_signature = str_replace("%7E", "~", rawurlencode($this->_signature)); + //else date is set + } else { + //encode signature using HmacSHA256 for SES + $this->_signature = base64_encode(hash_hmac('sha256', $date, $this->_privateKey, true)); + + } + return $this; + } + + protected function _postRequest($query, $headers = array()) { + //set url + $url = 'https://'.$this->_host.'/'; + //set curl + $curl = Eden_Curl::i() + ->verifyHost(false) + ->verifyPeer(false) + ->setUrl($url) + ->setPost(true) + ->setHeaders($headers) + ->setPostFields($query); + + $response = $curl->getResponse(); + //get curl infomation + $this->_meta['url'] = $url; + $this->_meta['query'] = $query; + $this->_meta['curl'] = $curl->getMeta(); + $this->_meta['response'] = $response; + + return $response; + + } + + protected function _getResponse() { + //each params + foreach ($this->_params as $param => $value) { + //this is my custom url encode + if(is_array($value)) { + foreach($value as $k => $v) { + $canonicalizedQuery[] = str_replace("%7E", "~", rawurlencode($param.'.'.$k)).'='.str_replace("%7E", "~", rawurlencode($v)); + } + + } else { + $canonicalizedQuery[] = str_replace("%7E", "~", rawurlencode($param)).'='.str_replace("%7E", "~", rawurlencode($value)); + } + } + + //sort parameter query + sort($canonicalizedQuery, SORT_STRING); + $date = gmdate('D, d M Y H:i:s e'); + //implode it to make a string of query + $this->_canonicalizedQuery = implode("&", $canonicalizedQuery); + //set signature + $this->_setSignature($date); + $query = $this->_canonicalizedQuery; + //auth is the authentication string. we'll use that on the header of our curl request + $auth = 'AWS3-HTTPS AWSAccessKeyId='.$this->_publicKey; + $auth .= ',Algorithm=HmacSHA256,Signature='.$this->_signature; + + //assigning header variables including the authentication string + $headers = array('X-Amzn-Authorization: '.$auth, 'Date: '.$date, 'Host: '.$this->_host); + + //send post request + return $this->_postRequest($query, $headers); + } +} diff --git a/library/eden/amazon/ecs.php b/library/eden/amazon/ecs.php new file mode 100644 index 0000000..473e02c --- /dev/null +++ b/library/eden/amazon/ecs.php @@ -0,0 +1,190 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Amazon S3 + * + * @package Eden + * @category amazon + * @author Christian Blanquera cblanquera@openovate.com + */ +class Eden_Amazon_Ecs extends Eden_Class { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_publicKey = NULL; + protected $_privateKey = NULL; + protected $_host = 'ecs.amazonaws.'; + protected $_uri = '/onca/xml'; + protected $_params = array(); + protected $_method = 'GET'; + protected $_canonicalizedQuery = NULL; + protected $_stringToSign = NULL; + protected $_signature = NULL; + protected $_requestUrl = NULL; + + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + public function __construct($privateKey, $publicKey) { + Eden_Amazon_Error::i() + ->argument(1, 'string') + ->argument(2, 'string'); + + $this->_privateKey = $privateKey; + $this->_publicKey = $publicKey; + } + + /* Public Methods + -------------------------------*/ + public function setAssociateTag($tag) { + Eden_Amazon_Error::i()->argument(1, 'string'); + $this->_params['AssociateTag'] = $tag; + + return $this; + } + + public function setCountry($country = 'com') { + Eden_Amazon_Error::i()->argument(1, 'string'); + $this->_host = $this->_host.$country; + + return $this; + } + + public function setIdType($type) { + Eden_Amazon_Error::i()->argument(1, 'string'); + $this->_params['IdType'] = $type; + + return $this; + } + + public function setItemId($id) { + Eden_Amazon_Error::i()->argument(1, 'string', 'int'); + $this->_params['ItemId'] = $id; + + return $this; + } + + public function setKeyword($keyword) { + Eden_Amazon_Error::i()->argument(1, 'string', 'int'); + $this->_params['Keywords'] = $keyword; + + return $this; + } + + public function setMethod($method) { + Eden_Amazon_Error::i()->argument(1, 'string'); + $this->_method = $method; + + return $this; + } + + public function setOperation($operation) { + Eden_Amazon_Error::i()->argument(1, 'string'); + $this->_params['Operation'] = $operation; + + return $this; + } + + public function setPage($page = 1) { + Eden_Amazon_Error::i()->argument(1, 'int'); + $this->_params['ItemPage'] = $page; + + return $this; + } + + public function getResponse() { + $this->_params['AWSAccessKeyId'] = $this->_publicKey; + + ksort($this->_params); + $canonicalizedQuery = array(); + foreach ($this->_params as $param => $value) { + $param = str_replace("%7E", "~", rawurlencode($param)); + $value = str_replace("%7E", "~", rawurlencode($value)); + $canonicalizedQuery[] = $param."=".$value; + } + + $this->_canonicalizedQuery = implode("&", $canonicalizedQuery); + $this->_stringToSign = $this->_method."\n".$this->_host."\n".$this->_uri."\n".$this->_canonicalizedQuery; + $this->_setSignature(); + $this->_requestUrl = 'http://'.$this->_host.$this->_uri.'?'.$this->_canonicalizedQuery.'&Signature='.$this->_signature; + return $this->_sendRequest(); + } + + public function setResponseGroup($group) { + Eden_Amazon_Error::i()->argument(1, 'string'); + $this->_params['ResponseGroup'] = $group; + + return $this; + } + + public function setSearchIndex($index = 'All') { + Eden_Amazon_Error::i()->argument(1, 'string'); + $this->_params['SearchIndex'] = $index; + + return $this; + } + + public function setService($service) { + Eden_Amazon_Error::i()->argument(1, 'string'); + $this->_params['Service'] = $service; + + return $this; + } + + public function setTimestamp($time = NULL) { + Eden_Amazon_Error::i()->argument(1, 'string', 'int', 'null'); + if($time == NULL) { + $time = time(); + } + + if(is_string($time)) { + $time = strtotime($time); + } + + $this->_params['Timestamp'] = gmdate("Y-m-d\TH:i:s\Z", $time); + return $this; + } + + public function setVersion($version) { + Eden_Amazon_Error::i()->argument(1, 'string'); + $this->_params['Version'] = $version; + + return $this; + } + + /* Protected Methods + -------------------------------*/ + protected function _sendRequest() { + return Eden_Curl::i() + ->setUrl($this->_requestUrl) + ->verifyHost(false) + ->verifyPeer(false) + ->setTimeout(60) + ->getResponse(); + } + + protected function _setSignature() { + $this->_signature = base64_encode(hash_hmac("sha256", $this->_stringToSign, $this->_privateKey, True)); + $this->_signature = str_replace("%7E", "~", rawurlencode($this->_signature)); + + return $this; + } + + /* Private Methods + -------------------------------*/ +} diff --git a/library/eden/amazon/error.php b/library/eden/amazon/error.php new file mode 100644 index 0000000..6a8847d --- /dev/null +++ b/library/eden/amazon/error.php @@ -0,0 +1,39 @@ + +/* + * This file is part of the Eden package. + * (c) 2010-2012 Christian Blanquera + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Amazon Errors + * + * @package Eden + * @category amazon + * @author Christian Blanquera cblanquera@openovate.com + */ +class Eden_Amazon_Error extends Eden_Error { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i($message = NULL, $code = 0) { + $class = __CLASS__; + return new $class($message, $code); + } + + /* Public Methods + -------------------------------*/ + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/amazon/s3.php b/library/eden/amazon/s3.php new file mode 100644 index 0000000..f09246e --- /dev/null +++ b/library/eden/amazon/s3.php @@ -0,0 +1,898 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Amazon S3 + * + * @package Eden + * @category amazon + * @author Christian Blanquera cblanquera@openovate.com + */ +class Eden_Amazon_S3 extends Eden_Class { + /* Constants + -------------------------------*/ + const ACL_PRIVATE = 'private'; + const ACL_PUBLIC_READ = 'public-read'; + const ACL_PUBLIC_READ_WRITE = 'public-read-write'; + const ACL_AUTHENTICATED_READ = 'authenticated-read'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_ssl = false; + protected $_host = 's3.amazonaws.com'; + protected $_user = NULL; + protected $_pass = NULL; + + protected $_meta = array(); + protected $_response = NULL; + + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + public function __construct($user, $pass, $host = 's3.amazonaws.com', $ssl = false) { + $this->_host = $host; + $this->_user = $user; + $this->_pass = $pass; + $this->_ssl = $ssl; + } + + /* Public Methods + -------------------------------*/ + /** + * Put a bucket + * + * @param string $bucket Bucket name + * @param constant $acl ACL flag + * @param string $location Set as "EU" to create buckets hosted in Europe + * @return boolean + */ + public function addBucket($bucket, $acl = self::ACL_PRIVATE, $location = false) { + //argument test + Eden_Amazon_Error::i() + ->argument(1, 'string') //Argument 1 must be string + ->argument(2, 'string', 'null') //Argument 2 must be string or null + ->argument(3, 'bool'); //Argument 3 must be bool + + $data = NULL; + $headers = array(); + $amazon = array('x-amz-acl' => $acl); + + if ($location !== false) { + $dom = new DOMDocument; + $config = $dom->createElement('CreateBucketConfiguration'); + $constraint = $dom->createElement('LocationConstraint', strtoupper($location)); + + $config->appendChild($constraint); + $dom->appendChild($config); + $data = $dom->saveXML(); + + $headers['Content-Type'] = 'application/xml'; + } + + $this->_setResponse('PUT', $bucket, '/', array(), $data, $headers, $amazon); + + if(!empty($this->_meta['error']) || empty($this->_response)) { + return false; + } + + return true; + } + + /** + * Put an object + * + * @param mixed $input Input data + * @param string $bucket Bucket name + * @param string $path Object URI + * @param constant $acl ACL constant + * @param array $metaHeaders Array of x-amz-meta-* headers + * @param array $requestHeaders Array of request headers or content type as a string + * @return boolean + */ + public function addFile($bucket, $path, $data, $acl = self::ACL_PRIVATE, $file = false) { + //argument test + Eden_Amazon_Error::i() + ->argument(1, 'string') //Argument 1 must be string + ->argument(2, 'string') //Argument 2 must be string + ->argument(4, 'string') //Argument 4 must be string + ->argument(5, 'bool'); //Argument 5 must be boolean + + $headers = $amazon = array(); + + $headers['Content-Type'] = Eden_File::i()->getMimeType($path); + $amazon['x-amz-acl'] = $acl; + + if(strpos($path, '/') !== 0) { + $path = '/'.$path; + } + + //if not file + if(!$file) { + //put it into a file + //we do this because file data in memory is bad + $tmp = tmpfile(); + fwrite($tmp, $data); + $file = $tmp; + $size = strlen($data); + //release file data from memory + $data = NULL; + //if is a file + } else { + $file = fopen($data, 'r'); + $size = filesize($data); + } + + $data = array($file, $size); + + $this->_setResponse('PUT', $bucket, $path, array(), $data, $headers, $amazon); + + //dont forget to close + fclose($file); + + if(!empty($this->_meta['error'])) { + return false; + } + + return $size; + } + + /** + * Delete an empty bucket + * + * @param string $bucket Bucket name + * @return boolean + */ + public function deleteBucket($bucket) { + //Argument 1 must be string + Eden_Amazon_Error::i()->argument(1, 'string'); + $this->_setResponse('DELETE', $bucket); + + if(!empty($this->_meta['error']) || empty($this->_response)) { + return false; + } + + return true; + } + + /** + * Delete an object + * + * @param string $bucket Bucket name + * @param string $uri Object URI + * @return boolean + */ + public function deleteFile($bucket, $path) { + //argument test + Eden_Amazon_Error::i() + ->argument(1, 'string') //Argument 1 must be string + ->argument(2, 'string'); //Argument 2 must be string + + $this->_setResponse('DELETE', $bucket, $path); + + if(!empty($this->_meta['error']) || empty($this->_response)) { + return false; + } + + return true; + } + + /** + * Delete an object + * + * @param string $bucket Bucket name + * @param string $uri Object URI + * @return boolean + */ + public function deleteFolder($bucket, $path) { + //argument test + Eden_Amazon_Error::i() + ->argument(1, 'string') //Argument 1 must be string + ->argument(2, 'string'); //Argument 2 must be string + + $list = $this->getBucket($bucket); + + if(strpos($path, '/') === 0) { + $path = substr($path, 1); + } + + if(substr($path, -1) == '/') { + $path = substr($path, 0, -1); + } + + + $files = array(); + foreach($list as $object) { + //if the oject does not start with the path + if(strpos($object['name'], $path) !== 0) { + //skip it + continue; + } + + $this->deleteFile($bucket, '/'.$object['name']); + } + + return true; + } + + /** + * Get contents for a bucket + * + * If maxKeys is NULL this method will loop through truncated result sets + * + * @param string $name Bucket name + * @param string $prefix Prefix + * @param string $marker Marker (last file listed) + * @param string $maxKeys Max keys (maximum number of keys to return) + * @param string $delimiter Delimiter + * @return array | false + */ + public function getBucket($name, $prefix = NULL, $marker = NULL, $maxKeys = NULL, $delimiter = NULL) { + //argument test + Eden_Amazon_Error::i() + ->argument(1, 'string') //Argument 1 must be string + ->argument(2, 'string', 'null') //Argument 2 must be string or null + ->argument(3, 'string', 'null') //Argument 3 must be string or null + ->argument(4, 'string', 'null') //Argument 4 must be string or null + ->argument(5, 'string', 'null'); //Argument 5 must be string or null + + $bucket = array(); + + do { + $query = array(); + if($prefix) { + $query['prefix'] = $prefix; + } + + if($marker) { + $query['marker'] = $marker; + } + + if($maxKeys) { + $query['max-keys'] = $maxKeys; + } + + if($delimiter) { + $query['delimiter'] = $delimiter; + } + + $this->_setResponse('GET', $name, '/', $query); + + if(!empty($this->_meta['error']) || empty($this->_response)) { + break; + } + + + $nextMarker = NULL; + foreach ($this->_response->Contents as $content) { + $bucket[(string)$content->Key] = array( + 'name' => (string)$content->Key, + 'time' => strtotime((string)$content->LastModified), + 'size' => (string)$content->Size, + 'hash' => substr((string)$content->ETag, 1, -1) + ); + + $nextMarker = (string)$content->Key; + } + + foreach ($this->_response->CommonPrefixes as $prefix) { + $bucket['prefixes'][] = (string)$prefixes->Prefix; + } + + if(isset($this->_response->IsTruncated) && $this->_response->IsTruncated == 'false') { + break; + } + + if (isset($this->_response->NextMarker)) { + $nextMarker = (string)$this->_response->NextMarker; + } + } while(!$maxKeys && $nextMarker); + + return $bucket; + } + + /** + * Get a list of buckets + * + * @param boolean $detailed Returns detailed bucket list when true + * @return array | false + */ + public function getBuckets() { + $this->_setResponse('GET'); + + if(!empty($this->_meta['error']) || empty($this->_response)) { + return false; + } + + $buckets = array(); + foreach ($this->_response->Buckets->Bucket as $bucket) { + $buckets[] = (string)$bucket->Name; + } + + return $buckets; + } + + /** + * Get an object + * + * @param string $bucket Bucket name + * @param string $uri Object URI + * @param mixed $saveTo Filename or resource to write to + * @return mixed + */ + public function getFile($bucket, $path) { + //argument test + Eden_Amazon_Error::i() + ->argument(1, 'string') //Argument 1 must be string + ->argument(2, 'string'); //Argument 2 must be string + + $this->_setResponse('GET', $bucket, $path); + + if(!empty($this->_meta['error']) || empty($this->_response)) { + return false; + } + + return $this->_response; + } + + /** + * Get object information + * + * @param string $bucket Bucket name + * @param string $uri Object URI + * @param boolean $returnInfo Return response information + * @return mixed | false + */ + public function getFileInfo($bucket, $path) { + //argument test + Eden_Amazon_Error::i() + ->argument(1, 'string') //Argument 1 must be string + ->argument(2, 'string'); //Argument 2 must be string + + if(strpos($path, '/') !== 0) { + $path = '/'.$path; + } + + $this->_setResponse('HEAD', $bucket, $path); + + if(!empty($this->_meta['error'])) { + return false; + } + + return $this->_meta['headers']; + } + + /** + * Get files for a bucket given a path + * + * If maxKeys is NULL this method will loop through truncated result sets + * + * @param string $bucket Bucket name + * @param string $prefix Prefix + * @param string $marker Marker (last file listed) + * @param string $maxKeys Max keys (maximum number of keys to return) + * @param string $delimiter Delimiter + * @param boolean $prefixes Set to true to return CommonPrefixes + * @return array | false + */ + public function getFiles($bucket, $path = NULL, $prefix = NULL, $marker = NULL, $maxKeys = NULL, $delimiter = NULL) { + //argument test + Eden_Amazon_Error::i() + ->argument(1, 'string') //Argument 1 must be string + ->argument(2, 'string', 'null') //Argument 2 must be string or null + ->argument(3, 'string', 'null') //Argument 3 must be string or null + ->argument(4, 'string', 'null') //Argument 4 must be string or null + ->argument(5, 'string', 'null') //Argument 5 must be string or null + ->argument(6, 'string', 'null'); //Argument 6 must be string or null + + $bucket = $this->getBucket($bucket, $prefix, $marker, $maxKeys, $delimiter); + + if(strpos($path, '/') === 0) { + $path = substr($path, 1); + } + + if(substr($path, -1) == '/') { + $path = substr($path, 0, -1); + } + + $files = array(); + foreach($bucket as $object) { + $name = $object['name']; + if($path) { + //if the oject does not start with the path + if(strpos($name, $path.'/') !== 0) { + //skip it + continue; + } + + //remove the path + $name = substr($name, strlen($path.'/')); + } + + //if the oject has a / or + //if this is an s3fox folder + if(strpos($name, '/') !== false || strpos($name, '_$folder$') !== false) { + //skip it + continue; + } + + $files[$name] = true; + } + + return array_keys($files); + } + + /** + * Get folders given a path + * + * If maxKeys is NULL this method will loop through truncated result sets + * + * @param string $bucket Bucket name + * @param string path + * @param string $prefix Prefix + * @param string $marker Marker (last file listed) + * @param string $maxKeys Max keys (maximum number of keys to return) + * @param string $delimiter Delimiter + * @param boolean $prefixes Set to true to return CommonPrefixes + * @return array | false + */ + public function getFolders($bucket, $path = NULL, $prefix = NULL, $marker = NULL, $maxKeys = NULL, $delimiter = NULL) { + //argument test + Eden_Amazon_Error::i() + ->argument(1, 'string') //Argument 1 must be string + ->argument(2, 'string', 'null') //Argument 2 must be string or null + ->argument(3, 'string', 'null') //Argument 3 must be string or null + ->argument(4, 'string', 'null') //Argument 4 must be string or null + ->argument(5, 'string', 'null') //Argument 5 must be string or null + ->argument(6, 'string', 'null'); //Argument 6 must be string or null + + $bucket = $this->getBucket($bucket, $prefix, $marker, $maxKeys, $delimiter); + + if(strpos($path, '/') === 0) { + $path = substr($path, 1); + } + + if(substr($path, -1) == '/') { + $path = substr($path, 0, -1); + } + + $folders = array(); + foreach($bucket as $object) { + $name = $object['name']; + if($path) { + //if the oject does not start with the path + if(strpos($name, $path.'/') !== 0) { + //skip it + continue; + } + + //remove the path + $name = substr($name, strlen($path.'/')); + } + + //we just care about the sub string before the / + $paths = explode('/', $name); + //if this is an s3fox folder + if(strpos($paths[0], '_$folder$') !== false) { + //remove the suffix + $paths[0] = str_replace('_$folder$', '', $paths[0]); + } + + $folders[$paths[0]] = true; + } + + return array_keys($folders); + } + + /** + * Gets the size of a folder + * + * @param string $bucket Bucket name + * @param string $uri Object URI + * @return boolean + */ + public function getFolderSize($bucket, $path) { + //argument test + Eden_Amazon_Error::i() + ->argument(1, 'string') //Argument 1 must be string + ->argument(2, 'string'); //Argument 2 must be string + + $bucket = $this->getBucket($bucket); + + if(strpos($path, '/') === 0) { + $path = substr($path, 1); + } + + if(substr($path, -1) == '/') { + $path = substr($path, 0, -1); + } + + $size = 0; + foreach($bucket as $object) { + //if the oject does not start with the path + if(strpos($object['name'], $path.'/') !== 0) { + //skip it + continue; + } + + $size += $object['size']; + } + + return $size; + } + + public function getMeta($key = NULL) { + if(isset($this->_meta[$key])) { + return $this->_meta[$key]; + } + + return $this->_meta; + } + + /** + * Get object or bucket Access Control Policy + * + * @param string $bucket Bucket name + * @param string $uri Object URI + * @return mixed | false + */ + public function getPermissions($bucket, $path = '/') { + //argument test + Eden_Amazon_Error::i() + ->argument(1, 'string') //Argument 1 must be string + ->argument(2, 'string'); //Argument 2 must be string + + $query['acl'] = NULL; + $this->_setResponse('GET', $bucket, $path); + + if(!empty($this->_meta['error']) || empty($this->_response)) { + return false; + } + + $permission = array(); + if (isset($this->_response->Owner, $this->_response->Owner->ID, $this->_response->Owner->DisplayName)) { + $permission['owner'] = array( + 'id' => $this->_response->Owner->ID, + 'name' => $this->_response->Owner->DisplayName); + } + + if (isset($this->_response->AccessControlList)) { + $acp['users'] = array(); + foreach ($this->_response->AccessControlList->Grant as $grant) { + foreach ($grant->Grantee as $grantee) { + if (isset($grantee->ID, $grantee->DisplayName)) { // CanonicalUser + + $permission['users'][] = array( + 'type' => 'CanonicalUser', + 'id' => $grantee->ID, + 'name' => $grantee->DisplayName, + 'permission' => $grant->Permission); + + } else if (isset($grantee->EmailAddress)) { // AmazonCustomerByEmail + + $permission['users'][] = array( + 'type' => 'AmazonCustomerByEmail', + 'email' => $grantee->EmailAddress, + 'permission' => $grant->Permission); + + } else if (isset($grantee->URI)) { // Group + + $permission['users'][] = array( + 'type' => 'Group', + 'uri' => $grantee->URI, + 'permission' => $grant->Permission); + + } + } + } + } + + return $permission; + } + + /** + * Set object or bucket Access Control Policy + * + * @param string $bucket Bucket name + * @param string $uri Object URI + * @param array $acp Access Control Policy Data (same as the data returned from getAccessControlPolicy) + * @return boolean + */ + public function setPermissions($bucket, $path = '/', array $acp = array()) { + //argument test + Eden_Amazon_Error::i() + ->argument(1, 'string') //Argument 1 must be string + ->argument(2, 'string'); //Argument 2 must be string + + $dom = new DOMDocument; + $dom->formatOutput = true; + $policy = $dom->createElement('AccessControlPolicy'); + $list = $dom->createElement('AccessControlList'); + + // It seems the owner has to be passed along too + $owner = $dom->createElement('Owner'); + $owner->appendChild($dom->createElement('ID', $acp['owner']['id'])); + $owner->appendChild($dom->createElement('DisplayName', $acp['owner']['name'])); + $policy->appendChild($owner); + + foreach ($acp['acl'] as $permission) { + $grant = $dom->createElement('Grant'); + $grantee = $dom->createElement('Grantee'); + + $grantee->setAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance'); + + if (isset($permission['id'])) { // CanonicalUser (DisplayName is omitted) + $grantee->setAttribute('xsi:type', 'CanonicalUser'); + $grantee->appendChild($dom->createElement('ID', $permission['id'])); + } elseif (isset($permission['email'])) { // AmazonCustomerByEmail + $grantee->setAttribute('xsi:type', 'AmazonCustomerByEmail'); + $grantee->appendChild($dom->createElement('EmailAddress', $permission['email'])); + } elseif ($permission['type'] == 'Group') { // Group + $grantee->setAttribute('xsi:type', 'Group'); + $grantee->appendChild($dom->createElement('URI', $permission['uri'])); + } + + $grant->appendChild($grantee); + $grant->appendChild($dom->createElement('Permission', $permission['permission'])); + $list->appendChild($grant); + } + + $policy->appendChild($list); + $dom->appendChild($policy); + + $data = $dom->saveXML(); + $query = array('acl' => NULL); + $header = array('Content-Type' => 'application/xml'); + + $this->_setResponse('PUT', $bucket, $path, $query, $data, $headers); + + if(!empty($this->_meta['error']) || empty($this->_response)) { + return false; + } + + return true; + } + + /* Protected Methods + -------------------------------*/ + protected function _getHost($bucket = NULL) { + if(!$bucket) { + return $this->_host; + } + + return strtolower($bucket).'.'.$this->_host; + } + + protected function _getPath($bucket = NULL, $path = '/', array $query = array()) { + if ($bucket) { + return '/'.strtolower($bucket).$path; + } + + $keys = array_keys($query); + foreach($keys as $key) { + if(in_array($key, array('acl', 'location', 'torrent', 'logging'))) { + $query = http_build_query($query); + + $link = '?'; + if(strpos($path, '?') !== false) { + $link = '&'; + } + + return $path.$link.$query; + } + } + + return $path; + } + + protected function _getSignature($string) { + if(extension_loaded('hash')) { + $hash = base64_encode(hash_hmac('sha1', $string, $this->_pass, true)); + } else { + $pad1 = str_pad($this->_pass, 64, chr(0x00)) ^ str_repeat(chr(0x36), 64); + $pad2 = str_pad($this->_pass, 64, chr(0x00)) ^ str_repeat(chr(0x5c), 64); + $pack1 = pack('H*', sha1($pad1 . $string)); + $pack2 = pack('H*', sha1($pad2 . $pack1)); + $hash = base64_encode($pack2); + } + + return 'AWS '.$this->_user.':'.$hash; + } + + protected function _getUrl($host, $path, $query = NULL) { + if(is_array($query)) { + $query = http_build_query($query); + } + + $link = '?'; + if(strpos($path, '?') !== false) { + $link = '&'; + } + + $protocol = 'http://'; + if($this->_ssl && extension_loaded('openssl')) { + $protocol = 'https://'; + } + + return $protocol.$host.$path.$link.$query; + } + + protected function _responseHeaderCallback(&$curl, &$data) { + $strlen = strlen($data); + if ($strlen <= 2) { + return $strlen; + } + + if (substr($data, 0, 4) == 'HTTP') { + $this->_meta['code'] = substr($data, 9, 3); + return $strlen; + } + + list($header, $value) = explode(': ', trim($data), 2); + + if ($header == 'Last-Modified') { + $this->_meta['headers']['time'] = strtotime($value); + } else if ($header == 'Content-Length') { + $this->_meta['headers']['size'] = $value; + } else if ($header == 'Content-Type') { + $this->_meta['headers']['type'] = $value; + } else if ($header == 'ETag') { + $this->_meta['headers']['hash'] = $value{0} == '"' ? substr($value, 1, -1) : $value; + } else if (preg_match('/^x-amz-meta-.*$/', $header)) { + $this->_meta['headers'][$header] = $value; + } + + return $strlen; + } + + protected function _responseWriteCallback(&$curl, &$data) { + $this->_response .= $data; + return strlen($data); + } + + protected function _setResponse($action, $bucket = NULL, $path = '/', array $query = array(), + $data = NULL, array $headers = array(), array $amazon = array()) { + + //reset meta and response + $this->_meta = array(); + $this->_response = NULL; + + //get host - bucket1.s3.amazonaws.com + $host = $this->_getHost($bucket); + //get url - http://bucket1.s3.amazonaws.com/some/path + $url = $this->_getUrl($host, $path, $query); + //get path - /bucket1/some/path + $path = $this->_getPath($bucket, $path); + + //get headers + ksort($amazon); + $curlHeaders = $amazonHeaders = array(); + + $headers['Host'] = $host; + $headers['Date'] = gmdate('D, d M Y H:i:s T'); + + foreach ($amazon as $header => $value) { + $curlHeaders[] = $header.': '.$value; + $amazonHeaders[] = strtolower($header).':'.$value; + } + + foreach ($headers as $header => $value) { + $curlHeaders[] = $header.': '.$value; + } + + $amazonHeaders = "\n".implode("\n", $amazonHeaders); + + if(!trim($amazonHeaders)) { + $amazonHeaders = NULL; + } + + if(!isset($headers['Content-MD5'])) { + $headers['Content-MD5'] = NULL; + } + + if(!isset($headers['Content-Type'])) { + $headers['Content-Type'] = NULL; + } + + //get signature + $signature = array( + $action, + $headers['Content-MD5'], + $headers['Content-Type'], + $headers['Date'].$amazonHeaders, + $path); + + $signature = implode("\n", $signature); + if($headers['Host'] == 'cloudfront.amazonaws.com') { + $signature = $headers['Date']; + } + + $curlHeaders[] = 'Authorization: ' . $this->_getSignature($signature); + + //setup curl + $curl = Eden_Curl::i() + ->setUserAgent('S3/php') + ->setUrl($url) + ->setHeaders($curlHeaders) + ->setHeader(false) + ->setWriteFunction(array(&$this, '_responseWriteCallback')) + ->setHeaderFunction(array(&$this, '_responseHeaderCallback')) + ->when($this->_ssl) + ->verifyHost(true) + ->verifyPeer(true) + ->endWhen(); + + // Request types + switch ($action) { + case 'GET': + break; + case 'PUT': + case 'POST': // POST only used for CloudFront + $curl->setPut(true) + ->setInFile($data[0]) + ->setInFileSize($data[1]); + break; + case 'HEAD': + $curl->setCustomRequest('HEAD')->setNobody(true); + break; + case 'DELETE': + $curl->setCustomRequest('DELETE'); + break; + } + + $response = $curl->getResponse(); + $meta = $curl->getMeta(); + + // Execute, grab errors + if ($response) { + $this->_meta['code'] = $meta['info']; + $this->_meta['error'] = array(); + } else { + $this->_meta['error'] = array( + 'code' => $meta['error_code'], + 'message' => $meta['error_message'], + 'path' => $path); + } + + // Parse body into XML + if(empty($this->_meta['error']) + && isset($this->_meta['headers']['type']) + && $this->_meta['headers']['type'] == 'application/xml' + && strlen($this->_response) > 0) { + + $this->_response = simplexml_load_string($this->_response); + + if(!in_array($this->_meta['code'], array(200, 204)) + && isset($this->_response->Code, $this->_response->Message)) { + + $this->_meta['error'] = array( + 'code' => $this->_response->Code, + 'message' => $this->_response->Message, + 'path' => $path); + + if(isset($this->_response->Resource)) { + $this->_meta['error']['path'] = $this->_response->Resource; + } + + $this->_response = NULL; + } + } + + return $this; + } + + /* Private Methods + -------------------------------*/ +} diff --git a/library/eden/apc.php b/library/eden/apc.php new file mode 100755 index 0000000..af540bf --- /dev/null +++ b/library/eden/apc.php @@ -0,0 +1,146 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +require_once dirname(__FILE__).'/class.php'; + +/** + * This class objectifies APC and easily makes APC functionality + * available. APC does not offer having multiple instances so no + * model class was defined in Eve. Alternative PHP Cache (APC) + * Allows you to cache data in memory for the duration of the + * active server or an expire time has been reached. We cache + * when computing the same data is expensive on memory or time. + * Once the actual data is stored in memory, it can be used in + * the future by accessing the cached copy rather than + * recomputing the original data. + * + * @package Eden + * @category cache + * @author Christian Blanquera cblanquera@openovate.com + */ +class Eden_Apc extends Eden_Class { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + public static function i() { + return self::_getSingleton(__CLASS__); + } + + /* Magic + -------------------------------*/ + public function __construct() { + //if apc_cache_info is not a function + if(!function_exists('apc_cache_info')) { + //throw exception + Eden_Apc_Error::i(Eden_Apc_Error::NOT_INSTALLED)->trigger(); + } + } + + /* Magic + -------------------------------*/ + /* Public Methods + -------------------------------*/ + /** + * Flushes the cache + * + * @return this + */ + public function clear() { + apc_clear_cache(); + + return $this; + } + + /** + * Gets a data cache + * + * @param string|array the key to the data + * @param int MemCache flag + * @return variable + */ + public function get($key) { + //Argument 1 must be a string or array + Eden_Memcache_Error::i()->argument(1, 'string', 'array'); + + return apc_fetch($key); + } + + /** + * deletes data of a cache + * + * @param string the key to the data + * @return this + */ + public function remove($key) { + //Argument 1 must be a string or array + Eden_Memcache_Error::i()->argument(1, 'string', 'array'); + + apc_delete($key); + + return $this; + } + + /** + * Sets a data cache + * + * @param string the key to the data + * @param variable the data to be cached + * @param int expire + * @return bool + */ + public function set($key, $data, $expire = NULL) { + //argument test + Eden_Apc_Error::i() + ->argument(1, 'string') //Argument 1 must be a string or array + ->argument(3, 'int', 'null'); //Argument 2 must be an integer or null + + apc_store($key, $data, $expire); + + return $this; + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} + +/** + * APC Errors + */ +class Eden_Apc_Error extends Eden_Error { + /* Constants + -------------------------------*/ + const NOT_INSTALLED = 'APC is not installed.'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i($message = NULL, $code = 0) { + $class = __CLASS__; + return new $class($message, $code); + } + + /* Public Methods + -------------------------------*/ + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/asiapay.php b/library/eden/asiapay.php new file mode 100644 index 0000000..e84ec02 --- /dev/null +++ b/library/eden/asiapay.php @@ -0,0 +1,80 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +require_once dirname(__FILE__).'/template.php'; +require_once dirname(__FILE__).'/asiapay/error.php'; +require_once dirname(__FILE__).'/asiapay/base.php'; +require_once dirname(__FILE__).'/asiapay/client.php'; +require_once dirname(__FILE__).'/asiapay/directclient.php'; + +/** + * Asiapay API factory. This is a factory class with + * methods that will load up different asiapay classes. + * Asiapay classes are organized as described on their + * developer site: client and directclient. + * + * @package Eden + * @category asiapay + * @author Christian Symon M. Buenavista sbuenavista@openovate.com + */ +class Eden_Asiapay extends Eden_Class { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function i() { + return self::_getSingleton(__CLASS__); + } + /* Magic + -------------------------------*/ + /* Public Methods + -------------------------------*/ + /** + * Returns asiapay client post + * + * @param *string + * @param *boolean + * @return Eden_Asiapay_Client + */ + public function clientPost($merchantId, $test = true) { + + //argument test + Eden_Asiapay_Error::i() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'bool'); //Argument 2 must be a boolean + + return Eden_Asiapay_Client::i($merchantId, $test); + } + + /** + * Returns asiapay direct client + * + * @param *string + * @param *boolean + * @return Eden_Asiapay_Directclient + */ + public function directClient($merchantId, $test = true) { + //argument test + Eden_Asiapay_Error::i() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'bool'); //Argument 2 must be a boolean + + return Eden_Asiapay_Directclient::i($merchantId, $test); + } + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/asiapay/base.php b/library/eden/asiapay/base.php new file mode 100644 index 0000000..d64fcd8 --- /dev/null +++ b/library/eden/asiapay/base.php @@ -0,0 +1,90 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Asia pay base + * + * @package Eden + * @category asiapay + * @author Christian Symon M. Buenavista sbuenavista@openovate.com + */ +class Eden_Asiapay_Base extends Eden_Class { + /* Constants + -------------------------------*/ + const MERCHANT_ID = 'merchantId'; + const ORDER_REF = 'orderRef'; + const CLIENTPOST_TEST_URL = 'https://test.pesopay.com/b2cDemo/eng/payment/payForm.jsp'; + const CLIENTPOST_LIVE_URL = 'https://www.pesopay.com/b2c2/eng/payment/payForm.jsp'; + const DIRECTCLIENT_TEST_URL = 'https://test.pesopay.com/b2cDemo/eng/dPayment/payComp.jsp'; + const DIRECTCLIENT_LIVE_URL = 'https://www.pesopay.com/b2c2/eng/dPayment/payComp.jsp'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + /* Magic + -------------------------------*/ + /* Public Methods + -------------------------------*/ + /* Protected Methods + -------------------------------*/ + protected function _reset() { + //foreach this as key => value + foreach ($this as $key => $value) { + //if the value of key is not array + if(!is_array($this->$key)) { + //if key name starts at underscore, probably it is protected variable + if(preg_match('/^_/', $key)) { + //if the protected variable is not equal to token + //we dont want to unset the access token + if($key != '_token') { + //reset all protected variables that currently use + $this->$key = NULL; + } + } + } + } + + return $this; + } + + protected function _removeNull($array) { + foreach($array as $key => $val) { + if(is_array($val)) { + $array[$key] = $this->_accessKey($val); + } + + if($val == false || $val == NULL || empty($val)) { + unset($array[$key]); + } + + } + + return $array; + } + + protected function _generateHash($amount, $orderRef) { + //merge parameters to generate hash + $hash = $this->_merchantId . '|' . + $orderRef. '|' . + $this->_currencyCode . '|' . + $amount . '|' . + $this->_payType . '|' . + $this->_secureHashSecret; + + return sha1($hash); + } + + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/asiapay/client.php b/library/eden/asiapay/client.php new file mode 100644 index 0000000..1d9f7cf --- /dev/null +++ b/library/eden/asiapay/client.php @@ -0,0 +1,284 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Asia pay client post + * + * @package Eden + * @category asiapay + * @author Christian Symon M. Buenavista sbuenavista@openovate.com + */ +class Eden_Asiapay_Client extends Eden_Asiapay_Base { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_secureHashSecret = NULL; + protected $_mpsMode = NULL; + protected $_remark = NULL; + protected $_redirect = NULL; + protected $_print = NULL; + protected $_failRetry = NULL; + protected $_currencyCode = '608'; + protected $_payType = 'N'; + protected $_language = 'E'; + protected $_payMethod = 'CC'; + + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + public function __construct($merchantId, $test = true) { + //argument test + Eden_Asiapay_Error::i() + ->argument(1, 'string') //argument 1 must be a string + ->argument(2, 'bool'); //argument 2 must be a boolean + + $this->_merchantId = $merchantId; + $this->_test = $test; + } + + /* Public Methods + -------------------------------*/ + /** + * Set secure hash. You may retrieve the Secure Hash Secret of + * the merchant account by accessing to the Merchant Administration Interface, + * “Profile”  “Payment Information”. The Secure Hash Secret must be kept + * safely for the function to be effective. The Secure Hash Secret will + * be changed every 2 years to enhance the level of security. + * + * @param string + * @return this + */ + public function setHash($hash) { + //argument 1 must be a string + Eden_Asiapay_Error::i()->argument(1, 'string'); + $this->_secureHashSecret = $hash; + + return $this; + } + + /** + * Set Multi-Currency Processing Service (MPS) Mode + * For merchant who applied MPS function + * Accepted values are: + * NIL or not provide – Disable MPS (merchant not using MPS) + * SCP – Enable MPS with ‘Simple Currency Conversion’ + * DCC – Enable MPS with ‘Dynamic Currency Conversion’ + * MCP – Enable MPS with ‘Multi Currency Pricing’ + * + * @param string + * @return this + */ + public function setMpsmode($mpsMode) { + //argument 1 must be a string + Eden_Asiapay_Error::i()->argument(1, 'string'); + $this->_mpsMode = $mpsMode; + + return $this; + } + + /** + * A remark field for you to store additional data that will + * not show on the transaction web page + * + * @param string + * @return this + */ + public function setRemark($remark) { + //argument 1 must be a string + Eden_Asiapay_Error::i()->argument(1, 'string'); + $this->_remark = $remark; + + return $this; + } + + /** + * Number of seconds auto-redirection to merchant’s site + * takes place at PesoPay’s Payment Success / Fail page + * + * @param string|integer + * @return this + */ + public function setRedirect($redirect) { + //argument 1 must be a string or integer + Eden_Asiapay_Error::i()->argument(1, 'int', 'string'); + $this->_remark = $redirect; + + return $this; + } + + /** + * Disable the print function at payment result page + * + * @return this + */ + public function disablePrint() { + $this->_print = 'no'; + + return $this; + } + + /** + * Disable the retry function when the transaction is rejected + * + * @return this + */ + public function disableFailRetry() { + $this->_failRetry = 'no'; + + return $this; + } + /** + * Set the currency of the payment: + * + * @param string + * @return this + */ + public function setCurrencyCode($currencyCode) { + //argument 1 must be a string + Eden_Asiapay_Error::i()->argument(1, 'string'); + $this->_currencyCode = $currencyCode; + + return $this; + } + + /** + * Set payment type + * + * @param string + * @return this + */ + public function setPaymentType($payType) { + //argument 1 must be a string + Eden_Asiapay_Error::i()->argument(1, 'string'); + $this->_payType = $payType; + + return $this; + } + + /** + * Set language of the payment page + * + * @param string + * @return this + */ + public function setLanguage($language) { + //argument 1 must be a string + Eden_Asiapay_Error::i()->argument(1, 'string'); + $this->_language = $language; + + return $this; + } + + /** + * The payment method + * Accepted values are: + * ALL –All the available payment method + * CC – Credit Card Payment + * VISA – Visa Payment + * Master – MasterCard Payment + * JCB – JCB Payment + * AMEX – AMEX Payment + * Diners – Diners Club Payment + * PAYPAL – PayPal By PesoPay Payment + * BancNet – BancNet Debit Payment + * GCash – GCash Payment + * SMARTMONEY – Smartmoney Payment + * + * @param string + * @return this + */ + public function setPaymentMethod($payMethod) { + //argument 1 must be a string + Eden_Asiapay_Error::i()->argument(1, 'string'); + $this->_payMethod = $payMethod; + + return $this; + } + + /** + * Create asia pay form + * + * @param integer|float The total amount your want to charge the customer for the provided currency + * @param url A Web page address you want us to redirect upon the transaction being rejected by us. + * @param url A Web page address you want us to redirect upon the transaction being rejected by us. + * @param url A Web page address you want us to redirect upon the transaction being cancelled by your customer + * @return string + */ + public function createForm($amount, $successUrl, $failUrl, $cancelUrl) { + //argument test + Eden_Asiapay_Error::i() + ->argument(1, 'int', 'float') //argument 1 must be a integer or float + ->argument(2, 'url') //argument 2 must be a url + ->argument(3, 'url') //argument 3 must be a url + ->argument(4, 'url'); //argument 4 must be a url + + //creata a random order reference number + $orderRef = rand(10000, 99999); + + //populate fields + $query = array( + 'amount' => $amount, + 'successUrl' => $successUrl, + 'failUrl' => $failUrl, + 'cancelUrl' => $cancelUrl, + 'orderRef' => $orderRef, + 'merchantId' => $this->_merchantId, + 'currCode' => $this->_currencyCode, //if not specify, default is '608' - PH + 'payType' => $this->_payType, //if not specify, default is 'N' - Normal Payment (Sales) + 'lang' => $this->_language, //if not specify, default is 'E' - English + 'payMethod' => $this->_payMethod, //if not specify, default is 'CC' - Credit Card Payment + 'mpsMode' => $this->_mpsMode, //optional + 'remark' => $this->_remark, //optional + 'redirect' => $this->_redirect, //optional + 'print' => $this->_print, //optional + 'failRetry' => $this->_failRetry); //optional + + //prevent sending fields with no value + $query = $this->_removeNull($query); + + //if test is true + if($this->_test) { + //use the test url + $url = self::CLIENTPOST_TEST_URL; + //else test is false + } else { + //use the live url + $url = self::CLIENTPOST_LIVE_URL; + //make a secure hash to prevent hacking + $hash = $this->_generateHash($amount, $orderRef); + //use secure hash when using live transaction + $query['secureHash'] = $hash; + } + + //make a form template + $parameters = Eden_Template::i() + ->set('query', $query) + ->set('url', $url) + ->parsePHP(dirname(__FILE__).'/template/asiapay.php'); + + //reset variables + $this->_reset(); + + return $parameters; + } + + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/asiapay/directclient.php b/library/eden/asiapay/directclient.php new file mode 100644 index 0000000..bfcae50 --- /dev/null +++ b/library/eden/asiapay/directclient.php @@ -0,0 +1,292 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Asia pay direct client + * + * @package Eden + * @category asiapay + * @author Christian Symon M. Buenavista sbuenavista@openovate.com + */ +class Eden_Asiapay_Directclient extends Eden_Asiapay_Base { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_secureHashSecret = NULL; + protected $_mpsMode = NULL; + protected $_remark = NULL; + protected $_redirect = NULL; + protected $_print = NULL; + protected $_failRetry = NULL; + protected $_currencyCode = '608'; + protected $_payType = 'N'; + protected $_language = 'E'; + protected $_payMethod = 'VISA'; + + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + public function __construct($merchantId, $test = true) { + //argument test + Eden_Asiapay_Error::i() + ->argument(1, 'string') //argument 1 must be a string + ->argument(2, 'bool'); //argument 2 must be a boolean + + $this->_merchantId = $merchantId; + $this->_test = $test; + } + + /* Public Methods + -------------------------------*/ + /** + * Set secure hash. You may retrieve the Secure Hash Secret of + * the merchant account by accessing to the Merchant Administration Interface, + * “Profile† “Payment Informationâ€. The Secure Hash Secret must be kept + * safely for the function to be effective. The Secure Hash Secret will + * be changed every 2 years to enhance the level of security. + * + * @param string + * @return this + */ + public function setHash($hash) { + //argument 1 must be a string + Eden_Asiapay_Error::i()->argument(1, 'string'); + $this->_secureHashSecret = $hash; + + return $this; + } + + /** + * Set Multi-Currency Processing Service (MPS) Mode + * For merchant who applied MPS function + * Accepted values are: + * NIL or not provide – Disable MPS (merchant not using MPS) + * SCP – Enable MPS with ‘Simple Currency Conversion’ + * DCC – Enable MPS with ‘Dynamic Currency Conversion’ + * MCP – Enable MPS with ‘Multi Currency Pricing’ + * + * @param string + * @return this + */ + public function setMpsmode($mpsMode) { + //argument 1 must be a string + Eden_Asiapay_Error::i()->argument(1, 'string'); + $this->_mpsMode = $mpsMode; + + return $this; + } + + /** + * A remark field for you to store additional data that will + * not show on the transaction web page + * + * @param string + * @return this + */ + public function setRemark($remark) { + //argument 1 must be a string + Eden_Asiapay_Error::i()->argument(1, 'string'); + $this->_remark = $remark; + + return $this; + } + + /** + * Number of seconds auto-redirection to merchant’s site + * takes place at PesoPay’s Payment Success / Fail page + * + * @param string|integer + * @return this + */ + public function setRedirect($redirect) { + //argument 1 must be a string or integer + Eden_Asiapay_Error::i()->argument(1, 'int', 'string'); + $this->_remark = $redirect; + + return $this; + } + + /** + * Disable the print function at payment result page + * + * @return this + */ + public function disablePrint() { + $this->_print = 'no'; + + return $this; + } + + /** + * Disable the retry function when the transaction is rejected + * + * @return this + */ + public function disableFailRetry() { + $this->_failRetry = 'no'; + + return $this; + } + /** + * Set the currency of the payment: + * + * @param string + * @return this + */ + public function setCurrencyCode($currencyCode) { + //argument 1 must be a string + Eden_Asiapay_Error::i()->argument(1, 'string'); + $this->_currencyCode = $currencyCode; + + return $this; + } + + /** + * Set payment type + * + * @param string + * @return this + */ + public function setPaymentType($payType) { + //argument 1 must be a string + Eden_Asiapay_Error::i()->argument(1, 'string'); + $this->_payType = $payType; + + return $this; + } + + /** + * Set language of the payment page + * + * @param string + * @return this + */ + public function setLanguage($language) { + //argument 1 must be a string + Eden_Asiapay_Error::i()->argument(1, 'string'); + $this->_language = $language; + + return $this; + } + + /** + * The payment method + * Accepted values are: + * VISA – Visa Payment + * Master – MasterCard Payment + * JCB – JCB Payment + * AMEX – AMEX Payment + * + * @param string + * @return this + */ + public function setPaymentMethod($payMethod) { + //argument 1 must be a string + Eden_Asiapay_Error::i()->argument(1, 'string'); + $this->_payMethod = $payMethod; + + return $this; + } + + /** + * Create asia pay form + * + * @param integer|float The total amount your want to charge the customer for the provided currency + * @param url A Web page address you want us to redirect upon the transaction being rejected by us. + * @param url A Web page address you want us to redirect upon the transaction being rejected by us. + * @param url A Web page address you want us to redirect upon the transaction being cancelled by your customer + * @param credit card number + * @param string Credit Card Verification Code + * @param string Credit card holder name + * @param string Credit card expiry month + * @param string Credit card expiry year + * @return string + */ + public function createForm($amount, $successUrl, $failUrl, $cancelUrl, $cardNumber, $securityCode, $cardHolder, $month, $year) { + //argument test + Eden_Asiapay_Error::i() + ->argument(1, 'int', 'float') //argument 1 must be a integer or float + ->argument(2, 'url') //argument 2 must be a url + ->argument(3, 'url') //argument 3 must be a url + ->argument(4, 'url') //argument 4 must be a url + ->argument(5, 'cc') //argument 5 must be a credit card number + ->argument(6, 'string') //argument 6 must be a string + ->argument(7, 'string') //argument 7 must be a string + ->argument(8, 'string') //argument 8 must be a string + ->argument(9, 'string'); //argument 9 must be a string + + //creata a random order reference number + $orderRef = rand(10000, 99999); + + //populate fields + $query = array( + 'amount' => $amount, + 'successUrl' => $successUrl, + 'failUrl' => $failUrl, + 'cancelUrl' => $cancelUrl, + 'cardNo' => $cardNumber, + 'securityCode' => $securityCode, + 'cardHolder' => $cardHolder, + 'epMonth' => $month, + 'epYear' => $year, + 'orderRef' => $orderRef, + 'merchantId' => $this->_merchantId, + 'currCode' => $this->_currencyCode, //if not specify, default is '608' - PH + 'payType' => $this->_payType, //if not specify, default is 'N' - Normal Payment (Sales) + 'lang' => $this->_language, //if not specify, default is 'E' - English + 'pMethod' => $this->_payMethod, //if not specify, default is 'VISA' + 'mpsMode' => $this->_mpsMode, //optional + 'remark' => $this->_remark, //optional + 'redirect' => $this->_redirect, //optional + 'print' => $this->_print, //optional + 'failRetry' => $this->_failRetry); //optional + + //prevent sending fields with no value + $query = $this->_removeNull($query); + + //if test is true + if($this->_test) { + //use the test url + $url = self::DIRECTCLIENT_TEST_URL; + //else test is false + } else { + //use the live url + $url = self::DIRECTCLIENT_LIVE_URL; + //make a secure hash to prevent hacking + $hash = $this->_generateHash($amount, $orderRef); + //use secure hash when using live transaction + $query['secureHash'] = $hash; + } + + //make a form template + $parameters = Eden_Template::i() + ->set('query', $query) + ->set('url', $url) + ->parsePHP(dirname(__FILE__).'/template/asiapay.php'); + + //reset variables + $this->_reset(); + + return $parameters; + } + + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/asiapay/error.php b/library/eden/asiapay/error.php new file mode 100644 index 0000000..62bf987 --- /dev/null +++ b/library/eden/asiapay/error.php @@ -0,0 +1,40 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Google Errors + * + * @package Eden + * @category google + * @author Christian Blanquera cblanquera@openovate.com + */ +class Eden_Asiapay_Error extends Eden_Error { + /* Constants + -------------------------------*/ + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i($message = NULL, $code = 0) { + $class = __CLASS__; + return new $class($message, $code); + } + + /* Public Methods + -------------------------------*/ + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/asiapay/template/asiapay.php b/library/eden/asiapay/template/asiapay.php new file mode 100644 index 0000000..c17d1bc --- /dev/null +++ b/library/eden/asiapay/template/asiapay.php @@ -0,0 +1,6 @@ +
+ $value): ?> + + + +
diff --git a/library/eden/authorizenet.php b/library/eden/authorizenet.php new file mode 100644 index 0000000..6000f4f --- /dev/null +++ b/library/eden/authorizenet.php @@ -0,0 +1,140 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +require_once dirname(__FILE__).'/curl.php'; +require_once dirname(__FILE__).'/authorizenet/error.php'; +require_once dirname(__FILE__).'/authorizenet/base.php'; +require_once dirname(__FILE__).'/authorizenet/customer.php'; +require_once dirname(__FILE__).'/authorizenet/direct.php'; +require_once dirname(__FILE__).'/authorizenet/payment.php'; +require_once dirname(__FILE__).'/authorizenet/recurring.php'; +require_once dirname(__FILE__).'/authorizenet/server.php'; + +/** + * Authorize.net API factory. This is a factory class with + * methods that will load up different Authorize.net classes. + * Authorize.net classes are organized as described on their + * developer site: customer integration, direct post, advance + * integration, authomated recurring and server integration method + * + * @package Eden + * @category Authorize.net + * @author Christian Symon M. Buenavista sbuenavista@openovate.com + */ +class Eden_Authorizenet extends Eden_Class { + /* Constants + -------------------------------*/ + const PEM = '/authorizenet/cert.pem'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function i() { + return self::_getSingleton(__CLASS__); + } + + /* Magic + -------------------------------*/ + /* Public Methods + -------------------------------*/ + /** + * Returns authorize.net customer integration method + * + * @param *string API login key + * @param *string API transaction key + * @param *string API signature + * @param *boolean Live mode + * @return Eden_Authorizenet_Customer + */ + public function customer($apiLogin, $transactionKey, $live = false, $certificate = NULL) { + if(!is_string($certificate)) { + $certificate = dirname(__FILE__).self::PEM; + } + + return Eden_Authorizenet_Customer::i($apiLogin, $transactionKey, $certificate, $live); + } + + /** + * Returns authorize.net direct post method + * + * @param *string API login key + * @param *string API transaction key + * @param *string API signature + * @param *boolean Live mode + * @return Eden_Authorizenet_Direct + */ + public function direct($apiLogin, $transactionKey, $live = false, $certificate = NULL) { + if(!is_string($certificate)) { + $certificate = dirname(__FILE__).self::PEM; + } + + return Eden_Authorizenet_Direct::i($apiLogin, $transactionKey, $certificate, $live); + } + + /** + * Returns authorize.net advance integration method + * + * @param *string API login key + * @param *string API transaction key + * @param *string API signature + * @param *boolean Live mode + * @return Eden_Authorizenet_Payment + */ + public function payment($apiLogin, $transactionKey, $live = false, $certificate = NULL) { + if(!is_string($certificate)) { + $certificate = dirname(__FILE__).self::PEM; + } + + return Eden_Authorizenet_Payment::i($apiLogin, $transactionKey, $certificate, $live = false); + } + + /** + * Returns authorize.net authomated recurring method + * + * @param *string API login key + * @param *string API transaction key + * @param *string API signature + * @param *boolean Live mode + * @return Eden_Authorizenet_Recurring + */ + public function recurring($apiLogin, $transactionKey, $live = false, $certificate = NULL) { + if(!is_string($certificate)) { + $certificate = dirname(__FILE__).self::PEM; + } + + return Eden_Authorizenet_Recurring::i($apiLogin, $transactionKey, $certificate, $live = false); + } + + /** + * Returns authorize.net server integration method + * + * @param *string API login key + * @param *string API transaction key + * @param *string API signature + * @param *boolean Live mode + * @return Eden_Authorizenet_Server + */ + public function server($apiLogin, $transactionKey, $live = false, $certificate = NULL) { + if(!is_string($certificate)) { + $certificate = dirname(__FILE__).self::PEM; + } + + return Eden_Authorizenet_Server::i($apiLogin, $transactionKey, $certificate, $live = false); + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/authorizenet/base.php b/library/eden/authorizenet/base.php new file mode 100644 index 0000000..fbf051a --- /dev/null +++ b/library/eden/authorizenet/base.php @@ -0,0 +1,148 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Authorize Base - Sends requests to the Authorize.Net gateways. + * + * @package Eden + * @category authorize.net + * @author Christian Symon M. Buenavista sbuenavista@openovate.com + */ +class Eden_Authorizenet_Base extends Eden_Class { + /* Constants + -------------------------------*/ + const LIVE_URL = 'https://secure.authorize.net/gateway/transact.dll'; + const TEST_URL = 'https://test.authorize.net/gateway/transact.dll'; + const LIVE_XML_URL = 'https://api.authorize.net/xml/v1/request.api'; + const TEST_XML_URL = 'https://apitest.authorize.net/xml/v1/request.api'; + const VERSION = '3.1'; + const XML = 'xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd"'; + const MERCHANT = 'merchantAuthentication'; + const NAME = 'name'; + const KEY = 'transactionKey'; + const XMLNS = 'xmlns'; + const SCHEMA = 'AnetApi/xml/v1/schema/AnetApiSchema.xsd'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_xmlUrl = self::TEST_XML_URL; + protected $_url = self::TEST_URL; + protected $_isLive = false; + protected $_apiLogin = NULL; + protected $_transactionKey = NULL; + protected $_certificate = NULL; + + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public function __construct($apiLogin, $transactionKey, $certificate, $live = false){ + //Argument test + Eden_Authorizenet_Error::i() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'string') //Argument 2 must be a string + ->argument(3, 'string') //Argument 3 must be a string + ->argument(4, 'bool'); //Argument 4 must ba a boolean + + $this->_isLive = $live; + $this->_time = time(); + $this->_sequence = '123'.$this->_time; + $this->_apiLogin = $apiLogin; + $this->_transactionKey = $transactionKey; + $this->_certificate = $certificate; + } + + /* Public Methods + -------------------------------*/ + /* Protected Methods + -------------------------------*/ + protected function _constructXml($requestType) { + $this->_xml = new SimpleXMLElement('<'.$requestType.'/>'); + $this->_xml->addAttribute(self::XMLNS, self::SCHEMA); + + $merchant = $this->_xml->addChild(self::MERCHANT); + $merchant->addChild(self::NAME,$this->_apiLogin); + $merchant->addChild(self::KEY, $this->_transactionKey); + + return $this; + } + + protected function _getFingerprint($amount){ + //Argument 1 must be an integer or float + Eden_Authorizenet_Error::i()->argument(1, 'float','int'); + + $signature = sprintf('%s^%s^%s^%s^', $this->_apiLogin, $this->_sequence, $this->_time, $amount); + + return hash_hmac('md5', $signature, $this->_transactionKey); + } + + protected function _process($xml) { + //Argument 1 must be a string + Eden_Authorizenet_Error::i()->argument(1, 'string'); + + //If it is in live mode + if($this->_isLive) { + $this->_xmlUrl = self::LIVE_XML_URL; + } + //Execute curl + $curl = Eden_Curl::i() + ->setUrl($this->_xmlUrl) + ->setPostFields($xml) + ->setHeader(false) + ->setTimeout(45) + ->verifyHost(true) + ->setHttpHeader(array('Content-Type: text/xml')) + ->verifyPeer(false) + ->setPost(true); + + //Close curl + $response = $curl->getResponse(); + //Replace all occurrences of the search + $responses = str_replace(self::XML, '', $response); + //Call SimpleXMLElement class + $xml = new SimpleXMLElement($responses); + + return array( + 'resultCode' => (string) $xml->messages->resultCode, + 'code' => (string) $xml->messages->message->code, + 'text' => (string) $xml->messages->message->text, + 'validation' => (string) $xml->validationDirectResponse, + 'directResponse' => (string) $xml->directResponse, + 'profileId' => (int) $xml->customerProfileId, + 'addressId' => (int) $xml->customerAddressId, + 'ids' => (int) $xml->ids, + 'paymentProfileId' => (int) $xml->customerPaymentProfileId); + } + + protected function _sendRequest($post){ + //Argument 1 must be a string + Eden_Authorizenet_Error::i()->argument(1, 'string'); + + //if it is in live mode + if($this->_isLive) { + $this->_url = self::LIVE_URL; + } + //Execute curl + $curl = Eden_Curl::i() + ->setUrl($this->_url) + ->setPostFields($post) + ->setHeader(false) + ->setTimeout(45) + ->verifyHost(true) + ->setCaInfo($this->_certificate) + ->setPost(true); + + return $curl->getResponse(); + } + + /* Private Methods + -------------------------------*/ +} diff --git a/library/eden/authorizenet/block/confirm.php b/library/eden/authorizenet/block/confirm.php new file mode 100644 index 0000000..443c797 --- /dev/null +++ b/library/eden/authorizenet/block/confirm.php @@ -0,0 +1,164 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Confirm Block + * + * @package Eden + * @category authorize.net + * @author Christian Blanquera cblanquera@openovate.com + */ +class Eden_Authorizenet_Block_Confirm extends Eden_Block { + /* Constants + -------------------------------*/ + const VERSION = '3.1'; + const SUBMIT = 'Submit Payment'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_login = NULL; + protected $_fingerprint = NULL; + protected $_description = NULL; + protected $_time = NULL; + protected $_sequence = NULL; + protected $_url = NULL; + protected $_action = NULL; + protected $_test = false; + protected $_amount = 0; + protected $_version = self::VERSION; + protected $_submit = self::SUBMIT; + + + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + public function __construct($login, $fingerprint, $amount, $description, $url) { + //Argument Test + Eden_Authorizenet_Error::i() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'string') //Argument 2 must be a string + ->argument(3, 'float', 'int') //Argument 3 must be an integer or float + ->argument(4, 'string') //Argument 4 must be a string + ->argument(5, 'string'); //Argument 5 must be a string + + $this->_login = $login; + $this->_fingerprint = $fingerprint; + $this->_amount = $amount; + $this->_description = $description; + $this->_url = $url; + + $this->_time = time(); + $this->_sequence = '123'.$this->_time; + } + + /* Public Methods + -------------------------------*/ + /** + * Set the URL the form will submit to + * + * @param string + * @return this + */ + public function setAction($action) { + //Argument 1 must be as string + Eden_Authorizenet_Error::i()->argument(1, 'string'); + $this->_action = $action; + return $this; + } + + /** + * Set the value of the submit button + * + * @param string + * @return this + */ + public function setButton($text) { + //Argument 1 must be as string + Eden_Authorizenet_Error::i()->argument(1, 'string'); + $this->_submit = $text; + return $this; + } + + /** + * Set the transaction sequence. + * Should be a unique set of characters + * + * @param string + * @return this + */ + public function setSequence($sequence) { + //Argument 1 must be as string + Eden_Authorizenet_Error::i()->argument(1, 'string'); + $this->_sequence = $sequence; + return $this; + } + + /** + * Returns a template file + * + * @return string + */ + public function getTemplate() { + return realpath(dirname(__FILE__).'/template/confirm.php'); + } + + /** + * Set the transaction time + * + * @param int + * @return this + */ + public function setTime($time) { + //Argument 1 must be an integer + Eden_Authorizenet_Error::i()->argument(1, 'int'); + $this->_time = $time; + return $this; + } + + /** + * Returns the template variables in key value format + * + * @param array data + * @return array + */ + public function getVariables() { + return array( + 'login' => $this->_login, + 'fingerprint' => $this->_fingerprint, + 'amount' => $this->_amount, + 'description' => $this->_description, + 'time' => $this->_time, + 'sequence' => $this->_sequence, + 'action' => $this->_url, + 'version' => $this->_version, + 'test' => $this->_test?'true':false, + 'submit' => $this->_submit,); + } + + /** + * Set the authorize.net API version + * + * @param string + * @return this + */ + public function setVersion($version) { + //Argument 1 must be as string + Eden_Authorizenet_Error::i()->argument(1, 'string'); + $this->_version = $version; + return $this; + } + +} \ No newline at end of file diff --git a/library/eden/authorizenet/block/post.php b/library/eden/authorizenet/block/post.php new file mode 100644 index 0000000..9fa9fe0 --- /dev/null +++ b/library/eden/authorizenet/block/post.php @@ -0,0 +1,430 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Confirm Block + * + * @package Eden + * @category authorize.net + * @author Christian Symon M. Buenavista sbuenavista@openovate.com + */ +class Eden_Authorizenet_Block_Post extends Eden_Block { + /* Constants + -------------------------------*/ + const CARD_NUMBER = 'Credit Card Number'; + const EXPIRATION = 'Expiration Date'; + const CVV = 'CVV'; + const FIRST_NAME = 'First Name'; + const LAST_NAME = 'Last Name'; + const ADDRESS = 'Address'; + const CITY = 'City'; + const STATE = 'State'; + const ZIP = 'Zip Code'; + const COUNTRY = 'Country'; + const SUBMIT = 'Submit'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_url = NULL; + protected $_fields = array(); + protected $_cardNumber = NULL; + protected $_expiration = NULL; + protected $_cvv = NULL; + protected $_firstName = NULL; + protected $_lastName = NULL; + protected $_address = NULL; + protected $_city = NULL; + protected $_state = NULL; + protected $_zip = NULL; + protected $_country = NULL; + protected $_cardNumberLabel = self::CARD_NUMBER, + protected $_expirationLabel = self::EXPIRATION, + protected $_cvvLabel = self::CVV, + protected $_firstNameLabel = self::FIRST_NAME, + protected $_lastNameLabel = self::LAST_NAME, + protected $_addressLabel = self::ADDRESS, + protected $_cityLabel = self::CITY, + protected $_stateLabel = self::STATE, + protected $_zipLabel = self::ZIP, + protected $_countryLabel = self::COUNTRY, + protected $_submitButton = self::SUBMIT, + + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + public function __construct($url, array $fields) { + //Argument 1 must be a string + Eden_Authorizenet_Error::i()->argument(1, 'string'); + + $this->_url = $url; + $this->_fields = $fields; + } + + /* Public Methods + -------------------------------*/ + /** + * Set customer address + * + * @param *string + * @return this + */ + public function setAddress($address) { + //Argument 1 must be a string + Eden_Authorizenet_Error::i()->argument(1, 'string'); + + $this->_address = $address; + return $this; + } + + /** + * Set address label + * + * @param *string + * @return this + */ + public function setAddressLabel($addressLabel) { + //Argument 1 must be a string + Eden_Authorizenet_Error::i()->argument(1, 'string'); + + $this->_addressLabel = $addressLabel; + return $this; + } + + /** + * Set customer card number + * + * @param *string + * @return this + */ + public function setCardNumber($cardNumber) { + //Argument 1 must be a string + Eden_Authorizenet_Error::i()->argument(1, 'string'); + + $this->_cardNumber = $cardNumber; + return $this; + } + /** + * Set card number label + * + * @param *string + * @return this + */ + public function setCardNumberLabel($cardNumberLabel) { + //Argument 1 must be a string + Eden_Authorizenet_Error::i()->argument(1, 'string'); + + $this->_cardNumberLabel = $cardNumberLabel; + return $this; + } + + /** + * Set customer city + * + * @param *string + * @return this + */ + public function setCity($city) { + //Argument 1 must be a string + Eden_Authorizenet_Error::i()->argument(1, 'string'); + + $this->_city = $city; + return $this; + } + + /** + * Set city label + * + * @param *string + * @return this + */ + public function setCityLabel($cityLabel) { + //Argument 1 must be a string + Eden_Authorizenet_Error::i()->argument(1, 'string'); + + $this->_cityLabel = $cityLabel; + return $this; + } + + /** + * Set customer country + * + * @param *string + * @return this + */ + public function setCountry($country) { + //Argument 1 must be a string + Eden_Authorizenet_Error::i()->argument(1, 'string'); + + $this->_country = $country; + return $this; + } + + /** + * Set country label + * + * @param *string + * @return this + */ + public function setCountryLabel($countryLabel) { + //Argument 1 must be a string + Eden_Authorizenet_Error::i()->argument(1, 'string'); + + $this->__countryLabel = $countryLabel; + return $this; + } + + /** + * Set customer cvv + * + * @param *string + * @return this + */ + public function setCvv($cvv) { + //Argument 1 must be a string + Eden_Authorizenet_Error::i()->argument(1, 'string'); + + $this->_cvvr = $cvv; + return $this; + } + + /** + * Set cvv label + * + * @param *string + * @return this + */ + public function setCvvLabel($cvvLabel) { + //Argument 1 must be a string + Eden_Authorizenet_Error::i()->argument(1, 'string'); + + $this->_cvvLabel = $cvvLabel; + return $this; + } + + /** + * Set customer exipiration date + * + * @param *string + * @return this + */ + public function setExpiration($date) { + //Argument 1 must be a string + Eden_Authorizenet_Error::i()->argument(1, 'string'); + + $this->_date = $date; + return $this; + } + + /** + * Set expiration date label + * + * @param *string + * @return this + */ + public function setExpirationLabel($expirationLabel) { + //Argument 1 must be a string + Eden_Authorizenet_Error::i()->argument(1, 'string'); + + $this->_expirationLabel = $expirationLabel; + return $this; + } + + /** + * Set customer first name + * + * @param *string + * @return this + */ + public function setFirstName($firstName) { + //Argument 1 must be a string + Eden_Authorizenet_Error::i()->argument(1, 'string'); + + $this->_firstName = $firstName; + return $this; + } + + /** + * Set first name label + * + * @param *string + * @return this + */ + public function setFirstNameLabel($firstNameLabel) { + //Argument 1 must be a string + Eden_Authorizenet_Error::i()->argument(1, 'string'); + + $this->_firstNameLabel = $firstNameLabel; + return $this; + } + + /** + * Set customer last name + * + * @param *string + * @return this + */ + public function setLastName($lastName) { + //Argument 1 must be a string + Eden_Authorizenet_Error::i()->argument(1, 'string'); + + $this->_lastName = $lastName; + return $this; + } + + /** + * Set last name label + * + * @param *string + * @return this + */ + public function setLastNameLabel($lastNameLabel) { + //Argument 1 must be a string + Eden_Authorizenet_Error::i()->argument(1, 'string'); + + $this->_lastNameLabel = $lastNameLabel; + return $this; + } + + /** + * Set customer state + * + * @param *string + * @return this + */ + public function setState($state) { + //Argument 1 must be a string + Eden_Authorizenet_Error::i()->argument(1, 'string'); + + $this->_state = $state; + return $this; + } + + /** + * Set state label + * + * @param *string + * @return this + */ + public function setStateLabel($stateLabel) { + //Argument 1 must be a string + Eden_Authorizenet_Error::i()->argument(1, 'string'); + + $this->_stateLabel = $stateLabel; + return $this; + } + + /** + * Set submit button value + * + * @param *string + * @return this + */ + public function setSubmitButton($submitButton) { + //Argument 1 must be a string + Eden_Authorizenet_Error::i()->argument(1, 'string'); + + $this->_submitButton = $submitButton; + return $this; + } + + /** + * Returns a template file + * + * @return string + */ + public function getTemplate() { + return realpath(dirname(__FILE__).'/template/post.php'); + } + + /** + * Returns the template variables in key value format + * + * @param array data + * @return array + */ + public function getVariables() { + $fields = array( + 'x_relay_response' => 'FALSE', + 'x_version' => Eden_Authorizenet_Base::VERSION, + 'x_delim_char' => ',', + 'x_delim_data' => 'TRUE'); + + foreach($this->_fields as $key => $value) { + if (!trim($value)) { + continue; + } + $fields[$key] = $value; + } + + return array( + 'url' => $this->_url, + 'fields' => $fields, + 'cardNumberLabel' => $this->_cardNumberLabel, + 'expirationLabel' => $this->_expirationLabel, + 'cvvLabel' => $this->_cvvLabel, + 'firstNameLabel' => $this->_firstNameLabel, + 'lastNameLabel' => $this->_lastNameLabel, + 'addressLabel' => $this->_addressLabel, + 'cityLabel' => $this->_cityLabel, + 'stateLabel' => $this->_stateLabel, + 'zipLabel' => $this->_zipLabel, + 'countryLabel' => $this->_countryLabel, + 'submitButton' => $this->_submitButton, + 'cardNumber' => $this->_cardNumber, + 'expiration' => $this->_expiration, + 'cvv' => $this->_cvv, + 'firstName' => $this->_firstName, + 'lastName' => $this->_lastName, + 'address' => $this->_address, + 'city' => $this->_city, + 'state' => $this->_state, + 'zip' => $this->_zip, + 'country' => $this->_country); + } + + /** + * Set customer zip + * + * @param *string + * @return this + */ + public function setZip($zip) { + //Argument 1 must be a string + Eden_Authorizenet_Error::i()->argument(1, 'string'); + + $this->_zip = $zip; + return $this; + } + + /** + * Set zip label + * + * @param *string + * @return this + */ + public function setZipLabel($zipLabel) { + //Argument 1 must be a string + Eden_Authorizenet_Error::i()->argument(1, 'string'); + + $this->_zipLabel = $zipLabel; + return $this; + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/authorizenet/block/template/confirm.php b/library/eden/authorizenet/block/template/confirm.php new file mode 100644 index 0000000..7ba9e5b --- /dev/null +++ b/library/eden/authorizenet/block/template/confirm.php @@ -0,0 +1,13 @@ +
+ + + + + + + + + + + +
\ No newline at end of file diff --git a/library/eden/authorizenet/block/template/post.php b/library/eden/authorizenet/block/template/post.php new file mode 100644 index 0000000..4ff1bd2 --- /dev/null +++ b/library/eden/authorizenet/block/template/post.php @@ -0,0 +1,56 @@ +
+
+
+ + +
+
+ + +
+
+ + +
+
+
+
+ + +
+
+ + +
+
+
+
+ + +
+
+ + +
+
+
+
+ + +
+
+ + +
+
+ + +
+
+ + $value): ?> + + + + +
\ No newline at end of file diff --git a/library/eden/authorizenet/cert.pem b/library/eden/authorizenet/cert.pem new file mode 100644 index 0000000..b59fbb0 --- /dev/null +++ b/library/eden/authorizenet/cert.pem @@ -0,0 +1,253 @@ +-----BEGIN CERTIFICATE----- +MIIEYTCCA0mgAwIBAgIESyDOMjANBgkqhkiG9w0BAQUFADCBsTELMAkGA1UEBhMC +VVMxFjAUBgNVBAoTDUVudHJ1c3QsIEluYy4xOTA3BgNVBAsTMHd3dy5lbnRydXN0 +Lm5ldC9ycGEgaXMgaW5jb3Jwb3JhdGVkIGJ5IHJlZmVyZW5jZTEfMB0GA1UECxMW +KGMpIDIwMDkgRW50cnVzdCwgSW5jLjEuMCwGA1UEAxMlRW50cnVzdCBDZXJ0aWZp +Y2F0aW9uIEF1dGhvcml0eSAtIEwxQzAeFw0xMDAzMzExNzA0MDBaFw0xMjAzMzAx +NzMzNTdaMIGVMQswCQYDVQQGEwJVUzETMBEGA1UECBMKQ2FsaWZvcm5pYTEWMBQG +A1UEBxMNTW91bnRhaW4gVmlldzEgMB4GA1UEChMXQ3liZXJzb3VyY2UgQ29ycG9y +YXRpb24xHTAbBgNVBAsTFFBsYXRpbnVtU1NMIFdpbGRjYXJkMRgwFgYDVQQDFA8q +LmF1dGhvcml6ZS5uZXQwgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBAOSIsv0X +OFMm2cV74o2jSF7zkNGeLHkPsI10xsFXTG1xqjzq4eImAReA3eIp1oHvLmji4kea +rmTbxo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AooCagJIYiaHR0cDovL2NybC5lbnRydXN0Lm5ldC9sZXZlbDFl +LmNybDBBBgNVHSAEOjA4MDYGCmCGSAGG+mwKAQIwKDAmBggrBgEFBQcCARYa +aHR0cDovL3d3dy5lbnRydXN0Lm5ldC9ycGEwHwYDVR0RBBgwFoIUc2VjdXJl +LmF1dGhvcml6ZS5uZXQwHwYDVR0jBBgwFoAUW0GKssRDwb2/yFRBVZ3glq3/ +uaEwHQYDVR0OBBYEFGZazQ8qcWqAiT+oFpV/D7WTbcGlMAkGA1UdEwQCMAAw +DQYJKoZIhvcNAQEFBQADggEBAEG1lvV2JQXDXRmEXkDp5qpF6uj1eNfffViE +QR6XCLPWIuaEcgnieTfFzRPEYbxzUY9jCqM62U37hUTDdMKjZas7fwaZ8RjE +wQASNPrIsHFsXEb0Nbz58g3cY00teCH3qQ9N9uW3TC+OXiSz9aSBxYkHD/63 +2D1rzaZLVHXUoReMMbjwf69zLDN7qsy6VDksHMVjqQugZF0ZCLFPPH5jfdAx +sOtocx7eyUovzO387ve8UMTdw6Anr9Ai7iVaYf4MpMqcuaHVet3QeE97Koy1 +mT3q9FmUGbXM+nCqSs/TQ4jSqOo4zqDnkK/cOgbzjsuJJZ/rCPSxaKvz3b/n +wMWH7kM= +-----END CERTIFICATE----- \ No newline at end of file diff --git a/library/eden/authorizenet/customer.php b/library/eden/authorizenet/customer.php new file mode 100644 index 0000000..146cae8 --- /dev/null +++ b/library/eden/authorizenet/customer.php @@ -0,0 +1,1106 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Authorize.net - Customer Information Manager + * + * @package Eden + * @category authorize.net + * @author Christian Symon M. Buenavista sbuenavista@openovate.com + */ +class Eden_Authorizenet_Customer extends Eden_Authorizenet_Base { + /* Constants + -------------------------------*/ + const CREATE_PROFILE = 'createCustomerProfileRequest'; + const CREATE_PAYMENT_PROFILE = 'createCustomerPaymentProfileRequest'; + const CREATE_SHIPPING_PROFILE = 'createCustomerShippingAddressRequest'; + const CREATE_TRANSACTION = 'createCustomerProfileTransactionRequest'; + const REMOVE_PROFILE = 'deleteCustomerProfileRequest'; + const REMOVE_PAYMENT_PROFILE = 'deleteCustomerPaymentProfileRequest'; + const REMOVE_SHIPPING_PROFILE = 'deleteCustomerShippingAddressRequest'; + const GET_PROFILE = 'getCustomerProfileRequest'; + const GET_PAYMENT_PROFILE = 'getCustomerPaymentProfileRequest'; + const GET_SHIPPING_PROFILE = 'getCustomerShippingAddressRequest'; + const UPDATE_PROFILE = 'updateCustomerProfileRequest'; + const UPDATE_PAYMENT_PROFILE = 'updateCustomerPaymentProfileRequest'; + const UPDATE_SHIPPING_PROFILE = 'updateCustomerShippingAddressRequest'; + const VALIDATE = 'validateCustomerPaymentProfileRequest'; + + const INDIVIDUAL = 'individual'; + const BUSINESS = 'business'; + const CHECK = 'check'; + const CREDIT = 'credit'; + const TEST = 'testMode'; + const LIVE = 'liveMode'; + const AUTH_CAPTURE = 'profileTransAuthCapture'; + const CAPTURE_ONLY = 'profileTransCaptureOnly'; + const AUTH_ONLY = 'profileTransAuthOnly'; + const PROFILE = 'profile'; + const MERCHANT_ID = 'merchantCustomerId'; + const DESCRIPTION = 'description'; + const EMAIL = 'email'; + const PAYMENT_PROFILE = 'paymentProfiles'; + const CUSTOMER_TYPE = 'customerType'; + const PAYMENT = 'payment'; + const CREDIT_CARD = 'creditCard'; + const CARD_NUMBER = 'cardNumber'; + const EXPIRATION = 'expirationDate'; + const BANK_ACCOUNT = 'bankAccount'; + const ACCOUNT_TYPE = 'accountType'; + const ACCOUNT_NAME = 'nameOnAccount'; + const E_CHECK = 'echeckType'; + const BANK_NAME = 'bankName'; + const ROUTING_NAME = 'routingNumber'; + const ACCOUNT_NUMBER = 'accountNumber'; + const PROFILE_ID = 'customerProfileId'; + const PAYMENT_ID = 'customerPaymentProfileId'; + const SHIPPING_ID = 'customerShippingAddressId'; + const PHONE_NUMBER = 'phoneNumber'; + const FAX_NUMBER = 'faxNumber'; + const FIRST_NAME = 'firstName'; + const LAST_NAME = 'lastName'; + const COMPANY = 'company'; + const ADDRESS = 'address'; + const CITY = 'city'; + const COUNTRY = 'country'; + const ZIP = 'zip'; + const STATE = 'state'; + const SHIPPING_LIST = 'shipToList'; + const BILLING = 'billTo'; + const VALIDATION = 'validationMode'; + const TRASACTION = 'transaction'; + const SHIPPING = 'shipping'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_useProfile = false; + protected $_shipping = false; + protected $_type = self::CREDIT; + protected $_customerType = self::INDIVIDUAL; + protected $_profileType = self::AUTH_CAPTURE; + protected $_validationMode = self::TEST; + + protected $_description = NULL; + protected $_email = NULL; + protected $_billToFirstName = NULL; + protected $_billToLastName = NULL; + protected $_billToCompany = NULL; + protected $_billToAddress = NULL; + protected $_billToCity = NULL; + protected $_billToState = NULL; + protected $_billToZip = NULL; + protected $_billToCountry = NULL; + protected $_billToPhoneNumber = NULL; + protected $_billToFaxNumber = NULL; + protected $_cardNumber = NULL; + protected $_expirationDate = NULL; + protected $_accountType = NULL; + protected $_nameOnAccount = NULL; + protected $_echeckType = NULL; + protected $_bankName = NULL; + protected $_routingNumber = NULL; + protected $_accountNumber = NULL; + protected $_shipToFirstName = NULL; + protected $_shipToLastName = NULL; + protected $_shipToCompany = NULL; + protected $_shipToAddress = NULL; + protected $_shipToCity = NULL; + protected $_shipToState = NULL; + protected $_shipToZip = NULL; + protected $_shipToCountry = NULL; + protected $_shipToPhoneNumber = NULL; + protected $_shipToFaxNumber = NULL; + protected $_amount = NULL; + protected $_cardCode = NULL; + protected $_shipAmount = NULL; + protected $_shipName = NULL; + protected $_shipDescription = NULL; + + protected $_customerId = NULL; + protected $_customerProfileId = NULL; + protected $_customerPaymentProfileId = NULL; + protected $_customerShippingAddressId = NULL; + + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + /* Public Methods + -------------------------------*/ + + /** + * Create a new customer payment profile for + * an existing customer profile. + * + * @return array + */ + public function createPaymentProfile() { + + $this->_constructXml(self::CREATE_PAYMENT_PROFILE); + + $this->_xml->addChild(self::PROFILE_ID, $this->_customerProfileId); + + $paymentProfile = $this->_xml->addChild(self::PAYMENT_PROFILE); + $paymentProfiles->addChild(self::CUSTOMER_TYPE, $this->_customerType); + //Populate billing parameters + $billTo = $paymentProfile->addChild(self::BILLING); + $billTo->addChild(self::FIRST_NAME, $this->_billToFirstName); + $billTo->addChild(self::LAST_NAME, $this->_billToLastName); + $billTo->addChild(self::COMPANY, $this->_billToCompany); + $billTo->addChild(self::ADDRESS, $this->_billToAddress); + $billTo->addChild(self::CITY, $this->_billToCity); + $billTo->addChild(self::STATE, $this->_billToState); + $billTo->addChild(self::ZIP, $this->_billToZip); + $billTo->addChild(self::COUNTRY, $this->_billToCountry); + $billTo->addChild(self::PHONE_NUMBER, $this->_billToPhoneNumber); + $billTo->addChild(self::FAX_NUMBER, $this->_billToFaxNumber); + $payment = $paymentProfiles->addChild(self::PAYMENT); + + //If it is in credit transaction + if ($this->_type === self::CREDIT) { + //Populate credit parameters + $creditCard = $payment->addChild(self::CREDIT_CARD); + $creditCard->addChild(self::CARD_NUMBER, $this->_cardNumber); + $creditCard->addChild(self::EXPIRATION, $this->_expirationDate); + + //If it is in check transaction + } else if ($this->_type === self::CHECK) { + //Populate bank parameters + $bankAccount = $payment->addChild(self::BANK_ACCOUNT); + $bankAccount->addChild(self::ACCOUNT_TYPE, $this->_accountType); + $bankAccount->addChild(self::ACCOUNT_NAME, $this->_nameOnAccount); + $bankAccount->addChild(self::E_CHECK, $this->_echeckType); + $bankAccount->addChild(self::BANK_NAME, $this->_bankName); + $bankAccount->addChild(self::ROUTING_NUMBER, $this->_routingNumber); + $bankAccount->addChild(self::ACCOUNT_NUMBER, $this->_accountNumber); + } + $this->_xml->addChild(self::VALIDATION, $this->_validationMode); + + return $this->_process($this->_xml->asXML()); + } + + /** + * Create a new customer profile along with any + * customer payment profiles and customer shipping + * addresses for the customer profile. + * + * @return array + */ + public function createProfile() { + + $this->_constructXml(self::CREATE_PROFILE); + + $profile = $this->_xml->addChild(self::PROFILE); + $profile->addChild(self::MERCHANT_ID, $this->_customerId); + $profile->addChild(self::DESCRIPTION, $this->_description); + $profile->addChild(self::EMAIL, $this->_email); + + $paymentProfiles = $profile->addChild(self::PAYMENT_PROFILE); + $paymentProfiles->addChild(self::CUSTOMER_TYPE, $this->_customerType); + $payment = $paymentProfiles->addChild(self::PAYMENT); + + //If it is in credit transaction + if ($this->_type === self::CREDIT) { + //Populate credit parameters + $creditCard = $payment->addChild(self::CREDIT_CARD); + $creditCard->addChild(self::CARD_NUMBER, $this->_cardNumber); + $creditCard->addChild(self::EXPIRATION, $this->_expirationDate); + + //If it is in check transaction + } else if ($this->_type === self::CHECK) { + //Populate bank parameters + $bankAccount = $payment->addChild(self::BANK_ACCOUNT); + $bankAccount->addChild(self::ACCOUNT_TYPE, $this->_accountType); + $bankAccount->addChild(self::ACCOUNT_NAME, $this->_nameOnAccount); + $bankAccount->addChild(self::E_CHECK, $this->_echeckType); + $bankAccount->addChild(self::BANK_NAME, $this->_bankName); + $bankAccount->addChild(self::ROUTING_NAME, $this->_routingNumber); + $bankAccount->addChild(self::ACCOUNT_NUMBER, $this->_accountNumber); + } + + //Populate shipping paramaters + $shipToList = $profile->addChild(self::SHIPPING_LIST); + $shipToList->addChild(self::FIRST_NAME, $this->_shipToFirstName); + $shipToList->addChild(self::LAST_NAME, $this->_shipToLastName ); + $shipToList->addChild(self::COMPANY, $this->_shipToCompany ); + $shipToList->addChild(self::ADDRESS, $this->_shipToAddress ); + $shipToList->addChild(self::CITY, $this->_shipToCity ); + $shipToList->addChild(self::ZIP, $this->_shipToZip ); + $shipToList->addChild(self::COUNTRY, $this->_shipToCountry ); + $shipToList->addChild(self::PHONE_NUMBER, $this->_shipToPhoneNumber ); + $shipToList->addChild(self::FAX_NUMBER, $this->_shipToFaxNumber ); + + return $this->_process($this->_xml->asXML()); + + } + + /** + * Create a new payment transaction from + * an existing customer profile. + * + * @return array + */ + public function createProfileTransaction() { + + $this->_constructXml(self::CREATE_TRANSACTION); + + $transaction = $this->_xml->addChild(self::TRASACTION); + $this->_profileType = $transaction->addChild( $this->_profileType); + $this->_profileType->addChild(self::AMOUNT, $this->_amount); + + //If shipping is set + if (isset($this->_shipping)) { + //Populate shipping parameters + $shipping = $this->_profileType->addChild(self::SHIPPING); + $shipping->addChild(self::AMOUNT, $this->_shipAmount); + $shipping->addChild(self::NAME, $this->_shipName); + $shipping->addChild(self::DESCRIPTION, $this->_shipDescription); + } + $this->_profileType->addChild(self::PROFILE_ID, $this->_customerProfileId); + $this->_profileType->addChild(self::PAYMENT_ID, $this->_customerPaymentProfileId); + $this->_profileType->addChild(self::SHIPPING_ID, $this->_customerShippingAddressId); + + return $this->_process($this->_xml->asXML()); + } + + /** + * Create a new customer shipping address + * for an existing customer profile. + * + * @return array + */ + public function createShippingAddress() { + + $this->_constructXml(self::SHIPPING_PROFILE); + + $this->_xml->addChild(self::PROFILE_ID, $this->_customerProfileId); + //Populate address parameters + $address = $this->_xml->addChild(self::ADDRESS); + $address->addChild(self::FIRST_NAME, $this->_shipToFirstName); + $address->addChild(self::LAST_NAME, $this->_shipToLastName); + $address->addChild(self::COMPANY, $this->_shipToCompany); + $address->addChild(self::ADDRESS, $this->_shipToAddress); + $address->addChild(self::CITY, $this->_shipToCity); + $address->addChild(self::STATE, $this->_shipToState); + $address->addChild(self::ZIP, $this->_shipToZip); + $address->addChild(self::COUNTRY, $this->_shipToCountry); + $address->addChild(self::PHONE_NUMBER, $this->_shipToPhoneNumber); + $address->addChild(self::FAX_NUMBER, $this->_shipToFaxNumber); + + return $this->_process($this->_xml->asXML()); + } + + /** + * Retrieve an existing customer profile along with all the + * associated customer payment profiles and customer shipping addresses. + * + * @return array + */ + public function getPaymentProfile() { + + $this->_constructXml(self::GET_PAYMENT_PROFILE); + + $this->_xml->addChild(self::PROFILE_ID, $this->_customerProfileId); + $this->_xml->addChild(self::PAYMENT_ID, $this->_customerPaymentProfileId); + + return $this->_process($this->_xml->asXML()); + } + + /** + * Retrieve all customer profile IDs you have previously + * created. + * + * @return array + */ + public function getProfile() { + + $this->_constructXml(self::GET_PROFILE); + + $this->_xml->addChild(self::PROFILE_ID, $this->_customerProfileId); + + return $this->_process($this->_xml->asXML()); + } + + /** + * Retrieve a customer shipping address for an + * existing customer profile. + * + * @return array + */ + public function getShippingAddress() { + + $this->_constructXml(self::GET_SHIPPING_PROFILE); + + $this->_xml->addChild(self::PROFILE_ID, $this->_customerProfileId); + $this->_xml->addChild(self::PAYMENT_ID, $this->_customerPaymentProfileId); + + return $this->_process($this->_xml->asXML()); + } + + /** + * Delete a customer payment profile from an + * existing customer profile. + * + * @return array + */ + public function removePaymentProfile() { + + $this->_constructXml(self::REMOVE_PAYMENT_PROFILE); + + $this->_xml->addChild(self::PROFILE_ID, $this->_customerProfileId); + $this->_xml->addChild(self::PAYMENT_ID, $this->_customerPaymentProfileId); + + return $this->_process($this->_xml->asXML()); + } + + /** + * Delete a customer profile + * + * @return array + */ + public function removeProfile() { + + $this->_constructXml(self::REMOVE_PROFILE); + + $this->_xml->addChild(self::PROFILE_ID, $this->_customerProfileId); + + return $this->_process($this->_xml->asXML()); + } + + /** + * Delete a customer shipping address from + * an existing customer profile. + * + * @return array + */ + public function removeShippingAddress() { + + $this->_constructXml(self::REMOVE_SHIPPING_PROFILE); + + $this->_xml->addChild(self::PROFILE_ID, $this->_customerProfileId); + $this->_xml->addChild(self::PAYMENT_ID, $this->_customerPaymentProfileId); + + return $this->_process($this->_xml->asXML()); + } + + /** + * Set account number + * + * @param *string + * @return this + */ + public function setAccountNumber($accountNumber) { + //Argument 1 must be a string + Eden_Authorizenet_Error::i()->argument(1, 'string'); + + $this->_accountNumber = $accountNumber; + return $this; + } + + /** + * Set account type + * + * @param *string + * @return this + */ + public function setAccountType($accountType) { + //Argument 1 must be a string + Eden_Authorizenet_Error::i()->argument(1, 'string'); + + $this->_accountType = $accountType; + return $this; + } + + /** + * Set amount + * + * @param *integer|float + * @return this + */ + public function setAmount($amount) { + //Argument 1 must be an integer or float + Eden_Authorizenet_Error::i()->argument(1, 'int', 'float'); + + $this->_amount = $amount; + return $this; + } + + /** + * Set profile transaction to authorize only + * + * @return this + */ + public function setAuthorizeOnly() { + $this->_profileType = self::AUTH_ONLY; + return $this; + } + + /** + * Set bank name + * + * @param *string + * @return this + */ + public function setBankName($bankName) { + //Argument 1 must be a string + Eden_Authorizenet_Error::i()->argument(1, 'string'); + + $this->_bankName = $bankName; + return $this; + } + + /** + * Set billing address + * + * @param *string + * @return this + */ + public function setBillingAddress($address) { + //Argument 1 must be a string + Eden_Authorizenet_Error::i()->argument(1, 'string'); + + $this->_billToAddress = $address; + return $this; + } + + /** + * Set billing city + * + * @param *string + * @return this + */ + public function setBillingCity($city) { + //Argument 1 must be a string + Eden_Authorizenet_Error::i()->argument(1, 'string'); + + $this->_billToCity = $city; + return $this; + } + + /** + * Set billing country + * + * @param *string + * @return this + */ + public function setBillingCountry($country) { + //Argument 1 must be a string + Eden_Authorizenet_Error::i()->argument(1, 'string'); + + $this->_billToCountry = $country; + return $this; + } + + /** + * Set billing email + * + * @param *string + * @return this + */ + public function setBillingEmail($email) { + //Argument 1 must be a string + Eden_Authorizenet_Error::i()->argument(1, 'string'); + + $this->_email = $email; + return $this; + } + + /** + * Set billing fax Number + * + * @param *string + * @return this + */ + public function setBillingFaxNumber($faxNumber) { + //Argument 1 must be a string + Eden_Authorizenet_Error::i()->argument(1, 'string'); + + $this->_billToFaxNumber = $faxNumber; + return $this; + } + + /** + * Set billing first name + * + * @param *string + * @return this + */ + public function setBillingFirstName($firstName) { + //Argument 1 must be a string + Eden_Authorizenet_Error::i()->argument(1, 'string'); + + $this->__billToFirstName = $firstName; + return $this; + } + + /** + * Set billing last name + * + * @param *string + * @return this + */ + public function setBillingLastName($lastName) { + //Argument 1 must be a string + Eden_Authorizenet_Error::i()->argument(1, 'string'); + + $this->_billToLastName = $lastName; + return $this; + } + + /** + * Set billing phone Number + * + * @param *string + * @return this + */ + public function setBillingPhoneNumber($phoneNumber) { + //Argument 1 must be a string + Eden_Authorizenet_Error::i()->argument(1, 'string'); + + $this->_billToPhoneNumber = $phoneNumber; + return $this; + } + + /** + * Set billing state + * + * @param *string + * @return this + */ + public function setBillingState($state) { + //Argument 1 must be a string + Eden_Authorizenet_Error::i()->argument(1, 'string'); + + $this->_billToState = $state; + return $this; + } + + /** + * Set billing zip + * + * @param *string + * @return this + */ + public function setBillingZip($zip) { + //Argument 1 must be a string + Eden_Authorizenet_Error::i()->argument(1, 'string'); + + $this->_billToZip = $zip; + return $this; + } + + /** + * Set profile transaction to capture only + * + * @return this + */ + public function setCaptureOnly() { + $this->_profileType = self::CAPTURE_ONLY; + return $this; + } + + /** + * Set card Number + * + * @param *string + * @return this + */ + public function setCardNumber($cardNumber) { + //Argument 1 must be a string + Eden_Authorizenet_Error::i()->argument(1, 'string'); + + $this->_cardNumber = $cardNumber; + return $this; + } + + /** + * Set echeck type + * + * @param *string + * @return this + */ + public function setECheckType($eCheck) { + //Argument 1 must be a string + Eden_Authorizenet_Error::i()->argument(1, 'string'); + + $this->_echeckType = $eCheck; + return $this; + } + + /** + * Set description + * + * @param *string + * @return this + */ + public function setDescription($description) { + //Argument 1 must be a string + Eden_Authorizenet_Error::i()->argument(1, 'string'); + + $this->_description = $description; + return $this; + } + + /** + * Set expiration Date + * + * @param *string + * @return this + */ + public function setExpiration($expirationDate) { + //Argument 1 must be a string + Eden_Authorizenet_Error::i()->argument(1, 'string'); + + $this->_expirationDate = $expirationDate; + return $this; + } + + /** + * Set name on account + * + * @param *string + * @return this + */ + public function setName($name) { + //Argument 1 must be a string + Eden_Authorizenet_Error::i()->argument(1, 'string'); + + $this->_nameOnAccount = $name; + return $this; + } + + /** + * Set payment profile id + * + * @param *string + * @return this + */ + public function setPaymentId($id) { + //Argument 1 must be a string + Eden_Authorizenet_Error::i()->argument(1, 'string'); + + $this->_customerPaymentProfileId = $id; + return $this; + } + + /** + * Set use profile + * + * @return this + */ + public function setProfile() { + $this->_useProfile = true; + return $this; + } + + /** + * Set profile id + * + * @param *string + * @return this + */ + public function setProfileId($id) { + //Argument 1 must be a string + Eden_Authorizenet_Error::i()->argument(1, 'string'); + + $this->_customerProfileId = $id; + return $this; + } + + /** + * Enable recurring billing + * + * @return this + */ + public function setRecurringBilling() { + $this->_recurringBilling = TRUE; + return $this; + } + + /** + * Set routing number + * + * @param *string + * @return this + */ + public function setRoutingNumber($routingNumber) { + //Argument 1 must be a string + Eden_Authorizenet_Error::i()->argument(1, 'string'); + + $this->_routingNumber = $routingNumber; + return $this; + } + + /** + * Set shipping in profile transaction + * + * @return this + */ + public function setShipping() { + $this->_shipping = true; + return $this; + } + + /** + * Set shipping address + * + * @param *string + * @return this + */ + public function setShippingAddress($address) { + //Argument 1 must be a string + Eden_Authorizenet_Error::i()->argument(1, 'string'); + + $this->_shipToAddress = $address; + return $this; + } + + /** + * Set shipping amount + * + * @param *integer|float + * @return this + */ + public function setShippingAmount($amount) { + //Argument 1 must be an integer or float + Eden_Authorizenet_Error::i()->argument(1, 'int', 'float'); + + $this->_shipAmount = $amount; + return $this; + } + + /** + * Set shipping city + * + * @param *string + * @return this + */ + public function setShippingCity($city) { + //Argument 1 must be a string + Eden_Authorizenet_Error::i()->argument(1, 'string'); + + $this->_shipToCity = $city; + return $this; + } + + /** + * Set shipping company + * + * @param *string + * @return this + */ + public function setShippingCompany($company) { + //Argument 1 must be a string + Eden_Authorizenet_Error::i()->argument(1, 'string'); + + $this->_shipToCompany = $company; + return $this; + } + + /** + * Set shipping country + * + * @param *string + * @return this + */ + public function setShippingCountry($country) { + //Argument 1 must be a string + Eden_Authorizenet_Error::i()->argument(1, 'string'); + + $this->_shipToCountry = $country; + return $this; + } + + /** + * Set shipping description + * + * @param *string + * @return this + */ + public function setShippingDescription($desc) { + //Argument 1 must be a string + Eden_Authorizenet_Error::i()->argument(1, 'string'); + + $this->_shipdescription = $desc; + return $this; + } + + /** + * Set shipping fax number + * + * @param *string + * @return this + */ + public function setShippingFaxNumber($faxNumber) { + //Argument 1 must be a string + Eden_Authorizenet_Error::i()->argument(1, 'string'); + + $this->_shipToFaxNumber = $faxNumber; + return $this; + } + + /** + * Set shipping first name + * + * @param *string + * @return this + */ + public function setShippingFirstName($firstName) { + //Argument 1 must be a string + Eden_Authorizenet_Error::i()->argument(1, 'string'); + + $this->_shipToFirstName = $firstName; + return $this; + } + + /** + * Set shipping address id + * + * @param *string + * @return this + */ + public function setShippingId($id) { + //Argument 1 must be a string + Eden_Authorizenet_Error::i()->argument(1, 'string'); + + $this->_customerShippingAddressId = $id; + return $this; + } + + /** + * Set shipping last name + * + * @param *string + * @return this + */ + public function setShippingLastName($lastName) { + //Argument 1 must be a string + Eden_Authorizenet_Error::i()->argument(1, 'string'); + + $this->_shipToLastName = $lastName; + return $this; + } + + /** + * Set shipping name + * + * @param *string + * @return this + */ + public function setShippingName($name) { + //Argument 1 must be a string + Eden_Authorizenet_Error::i()->argument(1, 'string'); + + $this->_shipName = $name; + return $this; + } + + /** + * Set shipping phone number + * + * @param *string + * @return this + */ + public function setShippingPhoneNumber($phoneNumber) { + //Argument 1 must be a string + Eden_Authorizenet_Error::i()->argument(1, 'string'); + + $this->_shipToPhoneNumber = $phoneNumber; + return $this; + } + + /** + * Set shipping state + * + * @param *string + * @return this + */ + public function setShippingState($state) { + //Argument 1 must be a string + Eden_Authorizenet_Error::i()->argument(1, 'string'); + + $this->_shipToState = $state; + return $this; + } + + /** + * Set shipping zip + * + * @param *string + * @return this + */ + public function setShippingZip($zip) { + //Argument 1 must be a string + Eden_Authorizenet_Error::i()->argument(1, 'string'); + + $this->_shipToZip = $zip; + return $this; + } + + /** + * Enable Tax Exemption + * + * @return this + */ + public function setTaxExemption() { + $this->_taxExempt = TRUE; + return $this; + } + + /** + * Set customer type to business + * + * @return this + */ + public function setToBusiness() { + $this->_customerType = self::BUSINESS; + return $this; + } + + /** + * Set transaction type to check + * + * @return this + */ + public function setToCheck() { + $this->_type = self::CHECK; + return $this; + } + + /** + * Update a customer payment profile for an + * existing customer profile. + * + * @return array + */ + public function updatePaymentProfile() { + + $this->_constructXml(self::UPDATE_PAYMENT_PROFILE); + + $this->_xml->addChild(self::PROFILE_ID, $this->_customerProfileId); + $profile = $this->_xml->addChild(self::PROFILE); + $profile->addChild(self::MERCHANT_ID, $this->_customerId); + $profile->addChild(self::DESCRIPTION, $this->_description); + $profile->addChild(self::EMAIL, $this->_email); + + $paymentProfiles = $profile->addChild(self::PAYMENT_PROFILE); + $paymentProfiles->addChild(self::CUSTOMER_TYPE, $this->_customerType); + + $billTo = $paymentProfile->addChild(self::BILLING); + //Populate billing parameters + $billTo->addChild(self::FIRST_NAME, $this->_billToFirstName); + $billTo->addChild(self::LAST_NAME, $this->_billToLastName); + $billTo->addChild(self::COMPANY, $this->_billToCompany); + $billTo->addChild(self::ADDRESS, $this->_billToAddress); + $billTo->addChild(self::CITY, $this->_billToCity); + $billTo->addChild(self::STATE, $this->_billToState); + $billTo->addChild(self::ZIP, $this->_billToZip); + $billTo->addChild(self::COUNTRY, $this->_billToCountry); + $billTo->addChild(self::PHONE_NUMBER, $this->_billToPhoneNumber); + $billTo->addChild(self::FAX_NUMBER, $this->_billToFaxNumber); + + $payment = $paymentProfiles->addChild(self::PAYMENT); + + //If it is in credit transaction + if ($this->_type === self::CREDIT) { + //Populate credit parameters + $creditCard = $payment->addChild(self::CREDIT_CARD); + $creditCard->addChild(self::CARD_NUMBER, $this->_cardNumber); + $creditCard->addChild(self::EXPIRATION, $this->_expirationDate); + + //If it is in check transaction + } else if ($this->_type === self::CHECK) { + //Populate bank parameters + $bankAccount = $payment->addChild(self::BANK_ACCOUNT); + $bankAccount->addChild(self::ACCOUNT_TYPE, $this->_accountType); + $bankAccount->addChild(self::ACCOUNT_NAME, $this->_nameOnAccount); + $bankAccount->addChild(self::E_CHECK, $this->_echeckType); + $bankAccount->addChild(self::BANK_NAME, $this->_bankName); + $bankAccount->addChild(self::ROUTING_NUMBER, $this->_routingNumber); + $bankAccount->addChild(self::ACCOUNT_NUMBER, $this->_accountNumber); + } + $paymentProfiles->addChild(self::PAYMENT_ID, $this->_customerPaymentProfileId); + + return $this->_process($this->_xml->asXML()); + } + + /** + * Update an existing customer profile. + * + * @return array + */ + public function updateProfile() { + + $this->_constructXml(self::UPDATE_PROFILE); + + $profile = $this->_xml->addChild(self::PROFILE); + $profile->addChild(self::MERCHANT_ID, $this->_merchantCustomerId); + $profile->addChild(self::DESCRIPTION, $this->_description); + $profile->addChild(self::EMAIL, $this->_email); + $profile->addChild(self::PROFILE_ID, $this->_customerProfileId); + + return $this->_process($this->_xml->asXML()); + } + + /** + * Update a shipping address for an + * existing customer profile. + * + * @return array + */ + public function updateShippingAddress() { + + $this->_constructXml(self::UPDATE_SHIPPING_PROFILE); + + $this->_xml->addChild(self::PROFILE_ID, $this->_customerProfileId); + $address = $this->_xml->addChild(self::ADDRESS); + //Populate address parameters + $address->addChild(self::FIRST_NAME, $this->_shipToFirstName); + $address->addChild(self::LAST_NAME, $this->_shipToLastName); + $address->addChild(self::COMPANY, $this->_shipToCompany); + $address->addChild(self::ADDRESS, $this->_shipToAddress); + $address->addChild(self::CITY, $this->_shipToCity); + $address->addChild(self::STATE, $this->_shipToState); + $address->addChild(self::ZIP, $this->_shipToZip); + $address->addChild(self::COUNTRY, $this->_shipToCountry); + $address->addChild(self::PHONE_NUMBER, $this->_shipToPhoneNumber); + $address->addChild(self::FAX_NUMBER, $this->_shipToFaxNumber); + + return $this->_process($this->_xml->asXML()); + } + + /** + * Verify an existing customer payment + * profile by generating a test transaction. + * + * @return array + */ + public function validatePaymentProfile() { + + $this->_constructXml(self::VALIDATE); + + $this->_xml->addChild(self::PROFILE_ID, $this->_customerProfileId); + $this->_xml->addChild(self::PAYMENT_ID, $this->_customerPaymentProfileId); + $this->_xml->addChild(self::SHIPPING_ID, $this->_customerAddressId); + $this->_xml->addChild(self::VALIDATION, $this->_validationMode); + + return $this->_process($this->_xml->asXML()); + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} diff --git a/library/eden/authorizenet/direct.php b/library/eden/authorizenet/direct.php new file mode 100644 index 0000000..7e51aad --- /dev/null +++ b/library/eden/authorizenet/direct.php @@ -0,0 +1,106 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Authorize.net - Direct Post Method + * + * @package Eden + * @category authorize.net + * @author Christian Symon M. Buenavista sbuenavista@openovate.com + */ +class Eden_Authorizenet_Direct extends Eden_Authorizenet_Base{ + /* Constants + -------------------------------*/ + const LIVE_URL = 'https://secure.authorize.net/gateway/transact.dll'; + const TEST_URL = 'https://test.authorize.net/gateway/transact.dll'; + + const AMOUNT = 'x_amount'; + const SEQUENCE = 'x_fp_sequence'; + const HASH = 'x_fp_hash'; + const TIMESTAMP = 'x_fp_timestamp'; + const RESPONSE = 'x_relay_response'; + const RELAY_URL = 'x_relay_url'; + const LOGIN = 'x_login'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_amount = 0; + protected $_returnUrl = NULL; + protected $_postUrl = self::TEST_URL; + + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + /* Public Methods + -------------------------------*/ + /** + * Set transaction amount + * + * @param *integer|float Transaction amount + * @return this + */ + public function setAmount($amount) { + //Argument 1 must be an integer or float + Eden_Authorizenet_Error::i()->argument(1, 'int', 'float'); + + $this->_amount = $amount; + return $this; + } + + /** + * Demonstrates the Direct Post Method + * + * return this + */ + public function getResponse(){ + //if it is in live mode + if($this->_isLive) { + $this->_postUrl = self::LIVE_URL; + } + + //Call get fingerprint method + $fingerPrint = $this->_getFingerprint($this->_amount); + + //Call block + return Eden_Authorizenet_Block_Post::i($this->_postUrl, array( + self::AMOUNT => $this->_amount, + self::SEQUENCE => $this->_sequence, + self::HASH => $fingerPrint, + self::TIMESTAMP => $this->_time, + self::RESPONSE => 'FALSE', + self::RELAY_URL => $this->_returnUrl, + self::LOGIN => $this->_apiLogin)); + } + + /** + * Set return URL + * + * @param *string + * @return this + */ + public function setReturnUrl($url) { + //Argument 1 must be a string + Eden_Authorizenet_Error::i()->argument(1, 'string'); + + $this->_returnUrl = $url; + return $this; + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/authorizenet/error.php b/library/eden/authorizenet/error.php new file mode 100644 index 0000000..bfa6658 --- /dev/null +++ b/library/eden/authorizenet/error.php @@ -0,0 +1,41 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Authorize.net Errors + * + * @package Eden + * @category authorize.net + * @author Christian Blanquera cblanquera@gmail.com + */ +class Eden_Authorizenet_Error extends Eden_Error { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function i($message = NULL, $code = 0) { + $class = __CLASS__; + return new $class($message, $code); + } + + /* Magic + -------------------------------*/ + /* Public Methods + -------------------------------*/ + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/authorizenet/payment.php b/library/eden/authorizenet/payment.php new file mode 100644 index 0000000..4e8edee --- /dev/null +++ b/library/eden/authorizenet/payment.php @@ -0,0 +1,391 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Authorize.net Server Integration Method + * + * @package Eden + * @category authorize.net + * @author Christian Symon M. Buenavista sbuenavista@openovate.com + */ +class Eden_Authorizenet_Payment extends Eden_Authorizenet_Base { + /* Constants + -------------------------------*/ + const AUTH_CAPTURE = 'AUTH_CAPTURE'; + const PRIOR_AUTH_CAPTURE = 'PRIOR_AUTH_CAPTURE'; + const AUTH_ONLY = 'AUTH_ONLY'; + const VOID = 'VOID'; + const CAPTURE_ONLY = 'CAPTURE_ONLY'; + const CREDIT = 'CREDIT'; + const VERSION_NOW = '3.1'; + const CC = 'CC'; + + const TRANSACTION_ID = 'x_trans_id'; + const LOGIN = 'x_login'; + const TRANS_KEY = 'x_tran_key'; + const VERSION = 'x_version'; + const DATA = 'x_delim_data'; + const CHAR = 'x_delim_char'; + const RELAY = 'x_relay_response'; + const TYPE = 'x_type'; + const METHOD = 'x_method'; + const CARD_NUM = 'x_card_num'; + const EXP_DATE = 'x_exp_date'; + const AMOUNT = 'x_amount'; + const DESCRIPTION = 'x_description'; + const FIRST_NAME = 'x_first_name'; + const LAST_NAME = 'x_last_name'; + const ADDRESS = 'x_address'; + const STATE = 'x_state'; + const ZIP = 'x_zip'; + const EMAIL = 'x_emai'; + const EMAIL_CUSTOMER = 'x_email_customer'; + const MERCHANT_EMAIL = 'x_merchant_email'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_type = self::AUTH_CAPTURE; + protected $_emailCustomer = true; + protected $_amount = NULL; + protected $_cardNumber = NULL; + protected $_expiration = NULL; + protected $_description = NULL; + protected $_address = NULL; + protected $_firstName = NULL; + protected $_lastName = NULL; + protected $_state = NULL; + protected $_zip = NULL; + protected $_transactionId = NULL; + protected $_code = NULL; + protected $_email = NULL; + protected $_merchantEmail = NULL; + + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + /* Public Methods + -------------------------------*/ + + /** + * Do Transactions + * + * @return array + */ + public function getResponse() { + //populate Fields + $default = array( + self::LOGIN => $this->_apiLogin, //API login id + self::TRANS_KEY => $this->_transactionKey, //Transaction key + self::VERSION => self::VERSION_NOW, //API version + self::DATA => true, + self::CHAR => '|', + self::RELAY => false, //Relay response + self::TYPE => $this->_type, //The method type + self::METHOD => self::CC, + self::EMAIL => $this->_email, //Cardholder email + self::EMAIL_CUSTOMER => $this->_emailCustomer, + self::MERCHANT_EMAIL => $this->_merchantEmail); //Merchant email + + //if it is set to prior auth capture transaction + switch($this->_type) { + case self::PRIOR_AUTH_CAPTURE: + $type = array( + self::TRANSACTION_ID => $this->_transactionId, //Transaction id + self::AMOUNT => $this->_amount); //Item Amount + break; + + case self::VOID: + $type = array(self::TRANSACTION_ID => $this->_transactionId); + break; + + case self::CREDIT: + $type = array( + self::TRANSACTION_ID => $this->_transactionId, //Transaction id + self::AMOUNT => $this->_amount, //Item Amount + self::CARD_NUM => $this->_cardNumber); //Cardholder card number + break; + + default: + $type = array( + self::CARD_NUM => $this->_cardNumber, //Cardholder card number + self::EXP_DATE => $this->_expiration, //Card expiration date + self::AMOUNT => $this->_amount, //Item Amount + self::DESCRIPTION => $this->_description, //Item description + self::FIRST_NAME => $this->_firstName, //Cardholder first name + self::LAST_NAME => $this->_lastName, //Cardholder last name + self::ADDRESS => $this->_address, //Cardholder Address + self::STATE => $this->_state, //Cardholder state + self::ZIP => $this->_zip); //Cardholder zip + break; + } + + //Merge the array + $query = array_merge($default, $type); + //Generate URL-encoded query string + $query = http_build_query($query); + //call curl method + $response = $this->_sendRequest($query); + //explode the response + return explode('|', $response); + } + + /** + * Set cardholder address + * + * @param *string address + * @return this + */ + public function setAddress($address) { + //Argument 1 must be a string + Eden_Authorizenet_Error::i()->argument(1, 'string'); + + $this->_address = $address; + return $this; + } + + /** + * Set transaction amount + * + * @param *integer|float Transaction amount + * @return this + */ + public function setAmount($amount) { + //Argument 1 must be an integer or float + Eden_Authorizenet_Error::i()->argument(1, 'int', 'float'); + + $this->_amount = $amount; + return $this; + } + + /** + * Set authentication code + * + * @param *string Authentication code + * @return this + */ + public function setAuthentication($code) { + //Argument 1 must be a string + Eden_Authorizenet_Error::i()->argument(1, 'string'); + + $this->_code = $code; + return $this; + } + + /** + * Set cardholder card number + * + * @param *string Card number + * @return this + */ + public function setCardNumber($cardNumber) { + //Argument 1 must be a string + Eden_Authorizenet_Error::i()->argument(1, 'string'); + + $this->_cardNumber = $cardNumber; + return $this; + } + + /** + * Set item Description + * + * @param *string item description + * @return this + */ + public function setDescription($description) { + //Argument 1 must be a string + Eden_Authorizenet_Error::i()->argument(1, 'string'); + + $this->_description = $description; + return $this; + } + + /** + * Set customer email address + * + * @param *string customer email address + * @return this + */ + public function setEmail($email) { + //Argument 1 must be a string + Eden_Authorizenet_Error::i()->argument(1, 'string'); + + $this->_email = $email; + return $this; + } + + /** + * Set cardholder card expiration date + * + * @param *string Card expirartion date + * @return this + */ + public function setExpiration($expiration) { + //Argument 1 must be a string + Eden_Authorizenet_Error::i()->argument(1, 'string'); + + $this->_expiration = $expiration; + return $this; + } + + /** + * Set cardholder first name + * + * @param *string First name + * @return this + */ + public function setFirstName($firstName) { + //Argument 1 must be a string + Eden_Authorizenet_Error::i()->argument(1, 'string'); + + $this->_firstName = $firstName; + return $this; + } + + /** + * Set cardholder last name + * + * @param *string Last name + * @return this + */ + public function setLastName($lastName) { + //Argument 1 must be a string + Eden_Authorizenet_Error::i()->argument(1, 'string'); + + $this->_lastName = $lastName; + return $this; + } + + /** + * Set merchant email address + * + * @param *string merchant email address + * @return this + */ + public function setMerchantEmail($email) { + //Argument 1 must be a string + Eden_Authorizenet_Error::i()->argument(1, 'string'); + + $this->_merchantEmail = $email; + return $this; + } + + /** + * Do not email receipt to customer + * + * @return this + */ + public function setReceiptOff() { + $this->_emailCustomer = false; + return $this; + } + + /** + * Set cardholder state + * + * @param *string state + * @return this + */ + public function setState($state) { + //Argument 1 must be a string + Eden_Authorizenet_Error::i()->argument(1, 'string'); + + $this->_state = $state; + return $this; + } + + /** + * Set authorize only transaction + * + * @return this + */ + public function setToAuthorizeOnly() { + $this->_type = self::AUTH_ONLY; + return $this; + } + + /** + * Set capture only transaction + * + * @return this + */ + public function setToCaptureOnly() { + $this->_type = self::CAPTURE_ONLY; + return $this; + } + + /** + * Set credit transaction + * + * @return this + */ + public function setToCredit() { + $this->_type = self::CREDIT; + return $this; + } + + /** + * Set prior and capture only transaction + * + * @return this + */ + public function setToPrior() { + $this->_type = self::PRIOR_AUTH_CAPTURE; + return $this; + } + + /** + * Set void transaction + * + * @return this + */ + public function setToVoid() { + $this->_type = self::VOID; + return $this; + } + + /** + * Set transaction id + * + * @param *string Valid transaction id + * @return this + */ + public function setTrasactionId($id) { + //Argument 1 must be a string + Eden_Authorizenet_Error::i()->argument(1, 'string'); + + $this->_transactionId = $id; + return $this; + } + + /** + * Set cardholder zip + * + * @param *string zip code + * @return this + */ + public function setZip($zip) { + //Argument 1 must be a string + Eden_Authorizenet_Error::i()->argument(1, 'string'); + + $this->_zip = $zip; + return $this; + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/authorizenet/recurring.php b/library/eden/authorizenet/recurring.php new file mode 100644 index 0000000..30e7774 --- /dev/null +++ b/library/eden/authorizenet/recurring.php @@ -0,0 +1,788 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Authorize.net - Automated Recurring Billing + * + * @package Eden + * @category authorize.net + * @author Christian Symon M. Buenavista sbuenavista@openovate.com + */ +class Eden_Authorizenet_Recurring extends Eden_Authorizenet_Base { + /* Constants + -------------------------------*/ + const CREATE = 'ARBCreateSubscriptionRequest'; + const UPDATE = 'ARBUpdateSubscriptionRequest'; + const REMOVE = 'ARBCancelSubscriptionRequest'; + + const SUBSCRIPTION = 'subscription'; + const NAME = 'name'; + const PAYMENT_SCHEDULE = 'paymentSchedule'; + const INTERVAL = 'interval'; + const LENGTH = 'length'; + const UNIT = 'unit'; + const DATE = 'startDate'; + const TOTAL = 'totalOccurrences'; + const TRIAL = 'trialOccurrences'; + const AMOUNT = 'amount'; + const TRIAL_AMOUNT = 'trialAmount'; + const PAYMENT = 'payment'; + const BANK = 'bankAccount'; + const ACCOUNT = 'accountType'; + const ROUTING_NUMBER = 'routingNumber'; + const ACCOUNT_NUMBER = 'accountNumber'; + const ACCOUNT_NAME = 'nameOnAccount'; + const BANK_NAME = 'bankName'; + const CREDIT_CARD = 'creditCard'; + const CARD_NUMBER = 'cardNumber'; + const EXPIRATION = 'expirationDate'; + const ORDER = 'order'; + const INVOICE = 'invoiceNumber'; + const DESCRIPTION = 'description'; + const CUSTOMER = 'customer'; + const ID = 'id'; + const EMAIL = 'email'; + const PHONE_NUMBER = 'phoneNumber'; + const FAX_NUMBER = 'faxNumber'; + const FIRST_NAME = 'firstName'; + const LAST_NAME = 'lastName'; + const COMPANY = 'company'; + const ADDRESS = 'address'; + const CITY = 'city'; + const STATE = 'state'; + const ZIP = 'zip'; + const SHIPPING = 'shipTo'; + const BILLING = 'billTo'; + const SUBSCRIPTION_ID = 'subscriptionId'; + const DAYS = 'days'; + const MONTHS = 'months'; + const YEARS = 'years'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_echeck = false; + protected $_subscrName = NULL; + protected $_intervalLength = NULL; + protected $_intervalUnit = NULL; + protected $_startDate = NULL; + protected $_totalOccurrences = NULL; + protected $_trialOccurrences = NULL; + protected $_amount = NULL; + protected $_trialAmount = NULL; + protected $_cardNumber = NULL; + protected $_expirationDate = NULL; + protected $_orderInvoiceNumber = NULL; + protected $_orderDescription = NULL; + protected $_customerId = NULL; + protected $_customerEmail = NULL; + protected $_customerPhoneNumber = NULL; + protected $_customerFaxNumber = NULL; + protected $_firstName = NULL; + protected $_lastName = NULL; + protected $_company = NULL; + protected $_address = NULL; + protected $_city = NULL; + protected $_state = NULL; + protected $_zip = NULL; + protected $_accountType = NULL; + protected $_nameOnAccount = NULL; + protected $_bankName = NULL; + protected $_routingNumber = NULL; + protected $_accountNumber = NULL; + protected $_shipFirstName = NULL; + protected $_shipLastName = NULL; + protected $_shipCompany = NULL; + protected $_shipAddress = NULL; + protected $_shipCity = NULL; + protected $_shipState = NULL; + protected $_shipZip = NULL; + + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + /* Public Methods + -------------------------------*/ + + /** + * Create Authomated Recurring + * subscription account + * + * @return array + */ + public function create() { + $this->_constructXml(self::CREATE); + + $subscription = $this->_xml->addChild(self::SUBSCRIPTION); + $subscription->addChild(self::NAME, $this->_subscrName); + $paymentSchedule = $subscription->addChild(self::PAYMENT_SCHEDULE); + + $interval = $paymentSchedule->addChild(self::INTERVAL); + //Populate interval parameters + $interval->addChild(self::LENGTH, $this->_intervalLength); + $interval->addChild(self::UNIT, $this->_intervalUnit); + + $paymentSchedule->addChild(self::DATE, $this->_startDate); + $paymentSchedule->addChild(self::TOTAL, $this->_totalOccurrences); + $paymentSchedule->addChild(self::TRIAL, $this->_trialOccurrences); + + $subscription->addChild(self::AMOUNT, $this->_amount); + $subscription->addChild(self::TRIAL_AMOUNT, $this->_trialAmount); + $payment = $subscription->addChild(self::PAYMENT); + + //if it is E check + if ($this->_echeck) { + //Populate bank parameters + $bankAccount = $payment->addChild(self::BANK); + $bankAccount->addChild(self::ACCOUNT, $this->_accountType); + $bankAccount->addChild(self::ROUTING_NUMBER, $this->_routingNumber); + $bankAccount->addChild(self::ACCOUNT_NUMBER, $this->_accountNumber); + $bankAccount->addChild(self::ACCOUNT_NAME, $this->_nameOnAccount); + $bankAccount->addChild(self::BANK_NAME, $this->_bankName); + //else it is credit + } else { + //Populate credit parameters + $creditCard = $payment->addChild(self::CREDIT_CARD); + $creditCard->addChild(self::CARD_NUMBER, $this->_cardNumber); + $creditCard->addChild(self::EXPIRATION, $this->_expirationDate); + } + + //Populate order parameters + $order = $subscription->addChild(); + $order->addChild(self::ORDER, $this->_orderInvoiceNumber); + $order->addChild(self::DESCRIPTION, $this->_orderDescription); + //Populate customer parameters + $customer = $subscription->addChild(self::CUSTOMER); + $customer->addChild(self::ID, $this->_customerId); + $customer->addChild(self::EMAIL, $this->_customerEmail); + $customer->addChild(self::PHONE_NUMBER, $this->_customerPhoneNumber); + $customer->addChild(self::FAX_NUMBER, $this->_customerFaxNumber); + //Populate billing parameters + $billTo = $subscription->addChild(self::BILLING); + $billTo->addChild(self::FIRST_NAME, $this->_firstName); + $billTo->addChild(self::LAST_NAME, $this->_lastName); + $billTo->addChild(self::COMPANY, $this->_company); + $billTo->addChild(self::ADDRESS, $this->_address); + $billTo->addChild(self::CITY, $this->_city); + $billTo->addChild(self::STATE, $this->_state); + $billTo->addChild(self::ZIP, $this->_zip); + //Populate shipping parameters + $shipTo = $subscription->addChild(self::SHIPPING); + $shipTo->addChild(self::FIRST_NAME, $this->_shipFirstName); + $shipTo->addChild(self::LAST_NAME, $this->_shipLastName); + $shipTo->addChild(self::COMPANY, $this->_shipCompany); + $shipTo->addChild(self::ADDRESS, $this->_address); + $shipTo->addChild(self::CITY, $this->_shipCity); + $shipTo->addChild(self::STATE, $this->_shipState); + $shipTo->addChild(self::ZIP, $this->_shipZip); + + return $this->_process($this->_xml->asXML()); + } + + /** + * Remove Authomated Recurring + * subscription account + * + * @return array + */ + public function remove() { + $this->_constructXml(self::REMOVE); + $this->_xml->addChild(self::SUBSCRIPTION_ID, $this->_subscrId); + + return $this->_process($this->_xml->asXML()); + } + + /** + * Set account number + * + * @param *string + * @return this + */ + public function setAccountNumber($accountNumber) { + //Argument 1 must be a string + Eden_Authorizenet_Error::i()->argument(1, 'string'); + + $this->_accountNumber = $accountNumber; + return $this; + } + + /** + * Set account type + * + * @param *string + * @return this + */ + public function setAccountType($accountType) { + //Argument 1 must be a string + Eden_Authorizenet_Error::i()->argument(1, 'string'); + + $this->_accountType = $accountType; + return $this; + } + + /** + * Set amount + * + * @params *integer|float + * @return this + */ + public function setAmount($amount) { + //Argument 1 must be an integer or float + Eden_Authorizenet_Error::i()->argument(1, 'int', 'float'); + + $this->_amount = $amount; + return $this; + + } + + /** + * Set bank name + * + * @param *string + * @return this + */ + public function setBank($bankName) { + //Argument 1 must be a string + Eden_Authorizenet_Error::i()->argument(1, 'string'); + + $this->_bankName = $bankName; + return $this; + } + + /** + * Set Billing address + * + * @param *string + * @return this + */ + public function setBillingAddress($address) { + //Argument 1 must be a string + Eden_Authorizenet_Error::i()->argument(1, 'string'); + + $this->_address = $address; + return $this; + } + + /** + * Set Billing city + * + * @param *string + * @return this + */ + public function setBillingCity($city) { + //Argument 1 must be a string + Eden_Authorizenet_Error::i()->argument(1, 'string'); + + $this->_city = $city; + return $this; + } + + /** + * Set Billing company + * + * @param *string + * @return this + */ + public function setBillingCompany($company) { + //Argument 1 must be a string + Eden_Authorizenet_Error::i()->argument(1, 'string'); + + $this->_company = $company; + return $this; + } + + /** + * Set Billing first name + * + * @param *string + * @return this + */ + public function setBillingFirstName($name) { + //Argument 1 must be a string + Eden_Authorizenet_Error::i()->argument(1, 'string'); + + $this->_firstName = $name; + return $this; + } + + /** + * Set Billing last name + * + * @param *string + * @return this + */ + public function seBillingtLastName($name) { + //Argument 1 must be a string + Eden_Authorizenet_Error::i()->argument(1, 'string'); + + $this->_lastName = $name; + return $this; + } + + /** + * Set Billing city + * + * @param *state + * @return this + */ + public function setBillingState($state) { + //Argument 1 must be a string + Eden_Authorizenet_Error::i()->argument(1, 'string'); + + $this->_state = $state; + return $this; + } + + /** + * Set Billing city + * + * @param *zip + * @return this + */ + public function setBillingZip($zip) { + //Argument 1 must be a string + Eden_Authorizenet_Error::i()->argument(1, 'string'); + + $this->_zip = $zip; + return $this; + } + + /** + * Set card Number + * + * @param *string + * @return this + */ + public function setCardNumber($cardNumber) { + //Argument 1 must be a string + Eden_Authorizenet_Error::i()->argument(1, 'string'); + + $this->_cardNumber = $cardNumber; + return $this; + } + + /** + * Set customer email + * + * @param *string + * @return this + */ + public function setCustomerEmail($email) { + //Argument 1 must be a string + Eden_Authorizenet_Error::i()->argument(1, 'string'); + + $this->_customerEmail = $email; + return $this; + } + + /** + * Set customer fax number + * + * @param *string + * @return this + */ + public function setCustomerFax($fax) { + //Argument 1 must be a string + Eden_Authorizenet_Error::i()->argument(1, 'string'); + + $this->_customerFaxNumber = $fax; + return $this; + } + + /** + * Set customer id + * + * @param *string + * @return this + */ + public function setCustomerId($id) { + //Argument 1 must be a string + Eden_Authorizenet_Error::i()->argument(1, 'string'); + + $this->_customerId = $id; + return $this; + } + + /** + * Set customer phone number + * + * @param *string + * @return this + */ + public function setCustomerPhone($phone) { + //Argument 1 must be a string + Eden_Authorizenet_Error::i()->argument(1, 'string'); + + $this->_customerPhoneNumber = $phone; + return $this; + } + + /** + * Set start date + * + * @params *string + * @return this + */ + public function setDate($date) { + //Argument 1 must be a string + Eden_Authorizenet_Error::i()->argument(1, 'string'); + + $this->_startDate = date("Y-m-d",strtotime($date)); + return $this; + } + + /** + * Set echeck + * + * @return this + */ + public function setECheck() { + $this->_echeck = true; + return $this; + } + + /** + * Set expiration Date + * + * @param *string + * @return this + */ + public function setExpiration($expirationDate) { + //Argument 1 must be a string + Eden_Authorizenet_Error::i()->argument(1, 'string'); + + $this->_expirationDate = $expirationDate; + return $this; + } + + /** + * The measurement of time, in association with the Interval + * Unit, that is used to define the frequency of the + * billing occurrences. If the Interval Unit is "months," + * can be any number between one (1) and 12. + * If the Interval Unit is "days," can be any + * number between seven (7) and 365. + * + * @params *integer + * @return this + */ + public function setIntervalLength($length) { + //Argument 1 must be a integer + Eden_Authorizenet_Error::i()->argument(1, 'int'); + + $this->_intervalLength = $length; + return $this; + } + + /** + * Set name on account + * + * @param *string + * @return this + */ + public function setNameOnAccount($nameOnAccount) { + //Argument 1 must be a string + Eden_Authorizenet_Error::i()->argument(1, 'string'); + + $this->_nameOnAccount = $nameOnAccount; + return $this; + } + + /** + * Set order invoice number + * + * @param *string + * @return this + */ + public function setOrderDescription($description) { + //Argument 1 must be a string + Eden_Authorizenet_Error::i()->argument(1, 'string'); + + $this->_orderDescription = $description; + return $this; + } + + /** + * Set order invoice number + * + * @param *integer + * @return this + */ + public function setOrderInvoiceNumber($order) { + //Argument 1 must be an integer + Eden_Authorizenet_Error::i()->argument(1, 'int'); + + $this->_orderInvoiceNumber = $order; + return $this; + } + + /** + * Set routing number + * + * @param *string + * @return this + */ + public function setRoutingNumber($routingNumber) { + //Argument 1 must be a string + Eden_Authorizenet_Error::i()->argument(1, 'string'); + + $this->_routingNumber = $routingNumber; + return $this; + } + + /** + * Set shipping address + * + * @param *string + * @return this + */ + public function setShippingAddress($address) { + //Argument 1 must be a string + Eden_Authorizenet_Error::i()->argument(1, 'string'); + + $this->_shipAddress = $address; + return $this; + } + + /** + * Set shipping city + * + * @param *string + * @return this + */ + public function setShippingCity($city) { + //Argument 1 must be a string + Eden_Authorizenet_Error::i()->argument(1, 'string'); + + $this->_shipCity = $city; + return $this; + } + + /** + * Set shipping company + * + * @param *string + * @return this + */ + public function setShippingCompany($company) { + //Argument 1 must be a string + Eden_Authorizenet_Error::i()->argument(1, 'string'); + + $this->_shipCompany = $company; + return $this; + } + + /** + * Set shipping first name + * + * @param *string + * @return this + */ + public function setShippingFirstName($firstName) { + //Argument 1 must be a string + Eden_Authorizenet_Error::i()->argument(1, 'string'); + + $this->_shipFirstName = $firstName; + return $this; + } + + /** + * Set shipping last name + * + * @param *string + * @return this + */ + public function setShippingLastName($lastName) { + //Argument 1 must be a string + Eden_Authorizenet_Error::i()->argument(1, 'string'); + + $this->_shipLastName = $lastName; + return $this; + } + + /** + * Set shipping state + * + * @param *string + * @return this + */ + public function setShippingState($state) { + //Argument 1 must be a string + Eden_Authorizenet_Error::i()->argument(1, 'string'); + + $this->_shipState = $state; + return $this; + } + + /** + * Set shipping zip + * + * @param *string + * @return this + */ + public function setShippingZip($zip) { + //Argument 1 must be a string + Eden_Authorizenet_Error::i()->argument(1, 'string'); + + $this->_shipZip = $zip; + return $this; + } + + /** + * Set subscription id + * + * @param *string + * @return this + */ + public function setSubscriptionId($id) { + //Argument 1 must be a string + Eden_Authorizenet_Error::i()->argument(1, 'string'); + + $this->_subscrId = $id; + return $this; + } + + /** + * Set subscription name + * + * @params *string + * @return this + */ + public function setSubscriptionName($name) { + //Argument 1 must be a string + Eden_Authorizenet_Error::i()->argument(1, 'string'); + + $this->_subscrName = $name; + return $this; + } + + /** + * Set interval unit to days + * + * @return this + */ + public function setToDays() { + $this->_intervalUnit = self::DAYS; + return $this; + } + + /** + * Set interval unit to months + * + * @return this + */ + public function setToMonths() { + $this->_intervalUnit = self::MONTHS; + return $this; + } + + /** + * Number of billing occurrences or payments for the + * subscription. To submit a subscription with no end + * date (an ongoing subscription), this field must be + * submitted with a value of “9999.†If a trial period + * is specified, this number should include the Trial + * Occurrences. + * + * @params *integer + * @return this + */ + public function setTotalOccurrences($total) { + //Argument 1 must be an integer + Eden_Authorizenet_Error::i()->argument(1, 'int'); + + $this->_totalOccurrences = $total; + return $this; + } + + /** + * Set interval unit to years + * + * @return this + */ + public function setToYears() { + $this->_intervalUnit = self::YEARS; + return $this; + } + + /** + * Number of billing occurrences or payments in the trial + * period. If a trial period is specified, this number must + * be included in the Total Occurrences. + * + * @params *integer + * @return this + */ + public function setTrialOccurrences($trial) { + //Argument 1 must be an integer + Eden_Authorizenet_Error::i()->argument(1, 'int'); + + $this->_trialOccurrences = $trial; + return $this; + } + + /** + * Set trial amount + * + * @params *integer|float + * @return this + */ + public function setTrialAmount($amount) { + //Argument 1 must be an integer or float + Eden_Authorizenet_Error::i()->argument(1, 'int', 'float'); + + $this->_trialAmount = $amount; + return $this; + + } + + /** + * Update Authomated Recurring + * subscription account + * + * @return array + */ + public function update() { + $this->_constructXml(self::UPDATE); + + $this->_xml->addChild(self::SUBSCRIPTION_ID, $this->_subscrId); + $subscription = $this->_xml->addChild(self::SUBSCRIPTION); + $subscription->addChild(self::NAME, $this->_subscrName); + $subscription->addChild(self::AMOUNT, $this->_amount); + $subscription->addChild(self::TRIAL_NAME, $this->_trialAmount); + + $payment = $subscription->addChild(self::PAYMENT); + //Populate credit parameters + $creditCard = $payment->addChild(self::CREDIT_CARD); + $creditCard->addChild(self::CARD_NUMBER,$this->_cardNumber); + $creditCard->addChild(self::EXPIRATION, $this->_expirationDate); + //Populate billing parameters + $billTo = $subscription->addChild(self::BILLING); + $billTo->addChild(self::FIRST_NAME, $this->_firstName); + $billTo->addChild(self::LAST_NAME, $this->_lastName); + $billTo->addChild(self::COMPANY, $this->_company); + $billTo->addChild(self::ADDRESS, $this->_address); + $billTo->addChild(self::CITY, $this->_city); + $billTo->addChild(self::STATE, $this->_state); + $billTo->addChild(self::ZIP, $this->_zip); + + return $this->_process($this->_xml->asXML()); + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} diff --git a/library/eden/authorizenet/server.php b/library/eden/authorizenet/server.php new file mode 100644 index 0000000..31a9fe4 --- /dev/null +++ b/library/eden/authorizenet/server.php @@ -0,0 +1,94 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Authorize.net Server Integration Method + * + * @package Eden + * @category authorize.net + * @author Christian Symon M. Buenavista sbuenavista@openovate.com + */ +class Eden_Authorizenet_Server extends Eden_Authorizenet_Base{ + /* Constants + -------------------------------*/ + const LIVE_URL = 'https://secure.authorize.net/gateway/transact.dll'; + const TEST_URL = 'https://test.authorize.net/gateway/transact.dll'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_testMode = self::TEST_URL; + protected $_amount = NULL; + protected $_description = NULL; + + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + /* Public Methods + -------------------------------*/ + /** + * Set the amount of the item + * + * @param *integer|float Amount of the item + * @return this + */ + public function setAmount($amount) { + //Argument 1 must be an integer or float + Eden_Paypal_Error::i()->argument(1, 'int', 'float'); + + $this->_amount = $amount; + return $this; + } + + /** + * Set item description + * + * @param *string Short description of the item + * @return this + */ + public function setDescription($description) { + //Argument 1 must be a string + Eden_Paypal_Error::i()->argument(1, 'string'); + + $this->_description = $description; + return $this; + } + + /** + * Provides a secure hosted payment form. + * + * @return this + */ + public function getResponse() { + //if it is in live mode + if($this->_isLive) { + $this->_testMode = self::LIVE_URL; + } + //Call get fingerprint method + $fingerprint = $this->_getFingerprint($this->_amount); + //Call block + return Eden_Authorizenet_Block_Confirm::i( + $this->_apiLogin, + $fingerprint, + $this->_amount, + $this->_description, + $this->_testMode); + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/block.php b/library/eden/block.php new file mode 100644 index 0000000..e5a9707 --- /dev/null +++ b/library/eden/block.php @@ -0,0 +1,97 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Base class for any class that defines an output block. + * A block is a default and customizable piece of output. + * + * @package Eden + * @category core + * @author Christian Blanquera cblanquera@openovate.com + */ +abstract class Eden_Block extends Eden_Class { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected static $_blockRoot = NULL; + + /* Private Properties + -------------------------------*/ + private static $_global = array(); + + /* Get + -------------------------------*/ + /* Magic + -------------------------------*/ + public function __toString() { + try { + return (string) $this->render(); + } catch(Exception $e) { + Eden_Error_Event::i()->exceptionHandler($e); + } + + return ''; + } + + /* Public Methods + -------------------------------*/ + /** + * returns location of template file + * + * @return string + */ + abstract public function getTemplate(); + + /** + * returns variables used for templating + * + * @return array + */ + abstract public function getVariables(); + + /** + * Transform block to string + * + * @param array + * @return string + */ + public function render() { + return Eden_Template::i()->set($this->getVariables())->parsePhp($this->getTemplate()); + } + + /** + * For one file Eden, you can set the default + * location of Eden's template to another location. + * + * @param string + * @return this + */ + public function setBlockRoot($root) { + Eden_Error::i()->argument(1, 'folder'); + self::$_blockRoot = $root; + return $this; + } + + /* Protected Methods + -------------------------------*/ + protected function _getGlobal($value) { + if(in_array($value, self::$_global)) { + return false; + } + + self::$_global[] = $value; + return $value; + } + + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/cache.php b/library/eden/cache.php new file mode 100755 index 0000000..6d513d1 --- /dev/null +++ b/library/eden/cache.php @@ -0,0 +1,236 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +require_once dirname(__FILE__).'/file.php'; + +/** + * This class allows the use of setting up multiple file cache + * locations. A file cache is a collection of files with data + * that was previously computed. We cache when computing the + * same data is expensive on memory or time. Once the data is + * stored in the file cache, it can be used in the future by + * accessing the cached copy rather than recomputing the + * original data. + * + * @package Eden + * @category cache + * @author Christian Blanquera cblanquera@openovate.com + */ +class Eden_Cache extends Eden_Class { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_key = NULL; + protected $_path = NULL; + protected $_cache = array(); + + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + public function __construct($root, $key = 'key.php') { + Eden_Cache_Error::i() + ->argument(1, 'string') + ->argument(2, 'string'); + + $this->setKey($key)->setRoot($root)->build(); + } + + /* Public Methods + -------------------------------*/ + /** + * Builds the cache into memory + * + * @return Eden_CacheModel + */ + public function build() { + try { + $this->_cache = Eden_File::i($this->_path.'/'.$this->_key)->getData(); + } catch(Eden_Path_Error $e) { + $this->_cache = array(); + } + return $this; + } + + /** + * Gets a data cache + * + * @param *string the key to the data + * @return mixed + */ + public function get($key, $default = NULL) { + //argument 1 must be a string + Eden_Cache_Error::i()->argument(1, 'string'); + + //if the key exists + if($this->keyExists($key)) { + //return it + return Eden_File::i($this->_cache[$key])->getData(); + } + + //return the defauit + return $default; + } + + /** + * Gets the unix time of when a cache has been created + * + * @param *string the key to the data + * @return int + */ + public function getCreated($key) { + //argument 1 must be a string + Eden_Cache_Error::i()->argument(1, 'string'); + + //if the key exists + if($this->keyExists($key)) { + //return it + return Eden_File::i($this->_cache[$key])->getTime(); + } + + return 0; + } + + /** + * returns a list of keys + * + * @return array + */ + public function getKeys() { + //return the defauit + return array_keys($this->_cache); + } + + /** + * Checks if a key is cached + * + * @param *string the key to the data + * @return bool + */ + public function keyExists($key) { + //argument 1 must be a string + Eden_Cache_Error::i()->argument(1, 'string'); + + return isset($this->_cache[$key]) && file_exists($this->_cache[$key]); + } + + /** + * Sets a data cache + * + * @param *string the key to the data + * @return this + */ + public function remove($key) { + //argument test + Eden_Cache_Error::i()->argument(1, 'string'); //argument 1 must be a string + + if(isset($this->_cache[$key])) { + unset($this->_cache[$key]); + } + + //now we want to store the key and data file correlation + Eden_File::i($this->_path.'/'.$this->_key)->setData($this->_cache); + + return $this; + } + + /** + * Sets a data cache + * + * @param *string the key to the data + * @param *string the path of the cache + * @param *mixed the data to be cached + * @return Eden_CacheModel + */ + public function set($key, $path, $data) { + //argument test + Eden_Cache_Error::i() + ->argument(1, 'string') //argument 1 must be a string + ->argument(2, 'string'); //argument 2 must be a string + + //get the proper path format + $path = $this->_path.Eden_Path::i($path); + //set the data to the file + Eden_File::i($path)->setData($data); + //store this data in memory by keyword + $this->_cache[$key] = $path; + //now we want to store the key and data file correlation + Eden_File::i($this->_path.'/'.$this->_key)->setData($this->_cache); + + return $this; + } + + /** + * Sets a cache key file + * + * @param *string the name of the key file + * @return Eden_CacheModel + */ + public function setKey($key) { + //argument 1 must be a string + Eden_Cache_Error::i()->argument(1, 'string'); + + $this->_key = $key; + return $this; + } + + /** + * Sets a cache path root + * + * @param string the root path + * @return Eden_CacheModel + */ + public function setRoot($root) { + //argument 1 must be a string + Eden_Cache_Error::i()->argument(1, 'string'); + + $this->_path = (string) Eden_Path::i($root)->absolute(); + + return $this; + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} + +/** + * Cache Errors + */ +class Eden_Cache_Error extends Eden_Error { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i($message = NULL, $code = 0) { + $class = __CLASS__; + return new $class($message, $code); + } + + /* Public Methods + -------------------------------*/ + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/class.php b/library/eden/class.php new file mode 100755 index 0000000..76ca644 --- /dev/null +++ b/library/eden/class.php @@ -0,0 +1,308 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +require_once dirname(__FILE__).'/error.php'; +require_once dirname(__FILE__).'/route.php'; + +require_once dirname(__FILE__).'/debug.php'; +require_once dirname(__FILE__).'/when.php'; +require_once dirname(__FILE__).'/loop.php'; + +/** + * The base class for all classes wishing to integrate with Eden. + * Extending this class will allow your methods to seemlessly be + * overloaded and overrided as well as provide some basic class + * loading patterns. + * + * @package Eden + * @category core + * @author Christian Blanquera cblanquera@openovate.com + */ +class Eden_Class { + /* Constants + -------------------------------*/ + const DEBUG = 'DEBUG %s:'; + const INSTANCE = 0; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + private static $_instances = array(); + + /* Magic + -------------------------------*/ + public static function i() { + if(static::INSTANCE === 1) { + return self::_getSingleton(); + } + + return self::_getMultiple(); + } + + public function __call($name, $args) { + //if the method name starts with a capital letter + //most likely they want a class + if(preg_match("/^[A-Z]/", $name)) { + //lets first consider that they may just + //want to load a class so lets try + try { + //return the class + return Eden_Route::i()->getClass($name, $args); + //only if there's a route exception do we want to catch it + //this is because a class can throw an exception in their construct + //so if that happens then we do know that the class has actually + //been called and an exception is suppose to happen + } catch(Eden_Route_Error $e) {} + } + + try { + //let the router handle this + return Eden_Route::i()->getMethod()->call($this, $name, $args); + } catch(Eden_Route_Error $e) { + Eden_Error::i($e->getMessage())->trigger(); + } + } + + public function __invoke() { + //if arguments are 0 + if(func_num_args() == 0) { + //return this + return $this; + } + + //get the arguments + $args = func_get_args(); + + //if the first argument is an array + if(is_array($args[0])) { + //make the args that + $args = $args[0]; + } + + //take our the class name + $class = array_shift($args); + //if this class does not start with Eden + if(strpos('Eden_', $class) !== 0) { + //add it + $class = 'Eden_'.$class; + } + + //try to + try { + //instantiate it + return Eden_Route::i()->getClass($class, $args); + } catch(Eden_Route_Error $e) { + //throw the error at this point + //to get rid of false positives + Eden_Error::i($e->getMessage())->trigger(); + } + } + + public function __toString() { + return get_class($this); + } + + /* Public Methods + -------------------------------*/ + /** + * Calls a method in this class and allows + * argumetns to be passed as an array + * + * @param string + * @param array + * @return mixed + */ + public function callThis($method, array $args = array()) { + //argument 1 must be a string + Eden_Error::i()->argument(1,'string'); + + return Eden_Route::i()->getMethod($this, $method, $args); + } + + /** + * Force outputs any class property + * + * @param string|null + * @param string|null + * @return this + */ + public function debug($variable = NULL, $next = NULL) { + //we are using tool in all cases + $class = get_class($this); + + //if variable is null + if(is_null($variable)) { + //output the class + Eden_Debug::i() + ->output(sprintf(self::DEBUG, $class)) + ->output($this); + + return $this; + } + + //if variable is true + if($variable === true) { + //return whatever the next response is + //or return the next specified variable + return Eden_Debug::i()->next($this, $next); + } + + //if variable is not a string + if(!is_string($variable)) { + //soft output error + Eden_Debug::i()->output(Eden_Error::DEBUG_NOT_STRING); + return $this; + } + + //if variable is set + if(isset($this->$variable)) { + //output it + Eden_Debug::i() + ->output(sprintf(self::DEBUG, $class.'->'.$variable)) + ->output($this->$variable); + + return $this; + } + + //could be private + $private = '_'.$variable; + //if private variable is set + if(isset($this->$private)) { + //output it + Eden_Debug::i() + ->output(sprintf(self::DEBUG, $class.'->'.$private)) + ->output($this->$private); + + return $this; + } + + //soft output error + Eden_Debug::i()->output(sprintf(Eden_Error::DEBUG_NOT_PROPERTY, $variable, $class)); + + return $this; + } + + /** + * Loops through returned result sets + * + * @param *callable + * @return this + */ + public function each($callback) { + Eden_Error::i()->argument(1, 'callable'); + return Eden_Loop::i()->iterate($this, $callback); + } + + /** + * Creates a class route for this class. + * + * @param *string the class route name + * @return Eden_Class + */ + public function routeThis($route) { + //argument 1 must be a string + Eden_Error::i()->argument(1, 'string'); + + if(func_num_args() == 1) { + //when someone calls a class call this instead + Eden_Route::i()->getClass()->route($route, $this); + return $this; + } + + //argument 2 must be a string + Eden_Error::i()->argument(2, 'string', 'object'); + + $args = func_get_args(); + + $source = array_shift($args); + $class = array_shift($args); + $destination = NULL; + + if(count($args)) { + $destination = array_shift($args); + } + + //when someone calls a method here call something ele instead + Eden_Route::i()->getMethod()->route($this, $source, $class, $destination); + return $this; + } + + /** + * Invokes When if conditional is false + * + * @param bool + * @return this|Eden_Noop + */ + public function when($isTrue, $lines = 0) { + if($isTrue) { + return $this; + } + + return Eden_When::i($this, $lines); + } + + /* Protected Methods + -------------------------------*/ + protected static function _getMultiple($class = NULL) { + if(is_null($class) && function_exists('get_called_class')) { + $class = get_called_class(); + } + + $class = Eden_Route::i()->getClass()->getRoute($class); + return self::_getInstance($class); + } + + protected static function _getSingleton($class = NULL) { + if(is_null($class) && function_exists('get_called_class')) { + $class = get_called_class(); + } + + $class = Eden_Route::i()->getClass()->getRoute($class); + + if(!isset(self::$_instances[$class])) { + self::$_instances[$class] = self::_getInstance($class); + } + + return self::$_instances[$class]; + } + + /* Private Methods + -------------------------------*/ + private static function _getInstance($class) { + $trace = debug_backtrace(); + $args = array(); + + if(isset($trace[1]['args']) && count($trace[1]['args']) > 1) { + $args = $trace[1]['args']; + //shift out the class name + array_shift($args); + } else if(isset($trace[2]['args']) && count($trace[2]['args']) > 0) { + $args = $trace[2]['args']; + } + + if(count($args) === 0 || !method_exists($class, '__construct')) { + return new $class; + } + + $reflect = new ReflectionClass($class); + + try { + return $reflect->newInstanceArgs($args); + } catch(Reflection_Exception $e) { + Eden_Error::i() + ->setMessage(Eden_Error::REFLECTION_ERROR) + ->addVariable($class) + ->addVariable('new') + ->trigger(); + } + } +} \ No newline at end of file diff --git a/library/eden/collection.php b/library/eden/collection.php new file mode 100644 index 0000000..e1038b7 --- /dev/null +++ b/library/eden/collection.php @@ -0,0 +1,410 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * A collection is a list of common models used for mass manipulations. + * + * @package Eden + * @category model + * @author Christian Blanquera cblanquera@openovate.com + */ +class Eden_Collection extends Eden_Class implements ArrayAccess, Iterator, Serializable, Countable { + /* Constants + -------------------------------*/ + const FIRST = 'first'; + const LAST = 'last'; + const MODEL = 'Eden_Model'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_list = array(); + protected $_model = self::MODEL; + + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + public function __call($name, $args) { + //if the method starts with get + if(strpos($name, 'get') === 0) { + //getUserName('-') - get all rows column values + $value = isset($args[0]) ? $args[0] : NULL; + + //make a new model + $list = Eden_Model::i(); + //for each row + foreach($this->_list as $i => $row) { + //just add the column they want + //let the model worry about the rest + $list[] = $row->$name(isset($args[0]) ? $args[0] : NULL); + } + + return $list; + + //if the method starts with set + } else if (strpos($name, 'set') === 0) { + //setUserName('Chris', '-') - set all user names to Chris + $value = isset($args[0]) ? $args[0] : NULL; + $separator = isset($args[1]) ? $args[1] : NULL; + + //for each row + foreach($this->_list as $i => $row) { + //just call the method + //let the model worry about the rest + $row->$name($value, $separator); + } + + return $this; + } + + $found = false; + + //for an array of models the method might exist + //we should loop and check for a valid method + + foreach($this->_list as $i => $row) { + //if no method exists + if(!method_exists($row, $name)) { + continue; + } + + $found = true; + + //just call the method + //let the model worry about the rest + $row->callThis($name, $args); + } + + //if found, it means something happened + if($found) { + //so it was successful + return $this; + } + + //nothing more, just see what the parent has to say + try { + return parent::__call($name, $args); + } catch(Eden_Error $e) { + Eden_Collection_Error::i($e->getMessage())->trigger(); + } + } + + public function __construct(array $data = array()) { + $this->set($data); + } + + public function __set($name, $value) { + //set all rows with this column and value + foreach($this->_list as $i => $row) { + $row[$name] = $value; + } + + return $this; + } + + public function __toString() { + return json_encode($this->get()); + } + + /* Public Methods + -------------------------------*/ + /** + * Adds a row to the collection + * + * @param array|Eden_Model + * @return this + */ + public function add($row = array()) { + //Argument 1 must be an array or Eden_Model + Eden_Collection_Error::i()->argument(1, 'array', $this->_model); + + //if it's an array + if(is_array($row)) { + //make it a model + $model = $this->_model; + $row = $this->$model($row); + } + + //add it now + $this->_list[] = $row; + + return $this; + } + + /** + * returns size using the Countable interface + * + * @return string + */ + public function count() { + return count($this->_list); + } + + public function cut($index = self::LAST) { + //Argument 1 must be a string or integer + Eden_Collection_Error::i()->argument(1, 'string', 'int'); + + //if index is first + if($index == self::FIRST) { + //we really mean 0 + $index = 0; + //if index is last + } else if($index == self::LAST) { + //we realy mean the last index number + $index = count($this->_list) -1; + } + + //if this row is found + if(isset($this->_list[$index])) { + //unset it + unset($this->_list[$index]); + } + + //reindex the list + $this->_list = array_values($this->_list); + + return $this; + } + + /** + * Loops through returned result sets + * + * @param *callable + * @return this + */ + public function each($callback) { + Eden_Error::i()->argument(1, 'callable'); + + foreach($this->_list as $key => $value) { + call_user_func($callback, $key, $value); + } + + return $this; + } + + /** + * Returns the current item + * For Iterator interface + * + * @return void + */ + public function current() { + return current($this->_list); + } + + /** + * Returns the row array + * + * @param bool + * @return array + */ + public function get($modified = true) { + //Argument 1 must be a boolean + Eden_Collection_Error::i()->argument(1, 'bool'); + + $array = array(); + //for each row + foreach($this->_list as $i => $row) { + //get the array of that (recursive) + $array[$i] = $row->get($modified); + } + + return $array; + } + + /** + * Returns th current position + * For Iterator interface + * + * @return void + */ + public function key() { + return key($this->_list); + } + + /** + * Increases the position + * For Iterator interface + * + * @return void + */ + public function next() { + next($this->_list); + } + + /** + * isset using the ArrayAccess interface + * + * @param number + * @return bool + */ + public function offsetExists($offset) { + return isset($this->_list[$offset]); + } + + /** + * returns data using the ArrayAccess interface + * + * @param number + * @return bool + */ + public function offsetGet($offset) { + return isset($this->_list[$offset]) ? $this->_list[$offset] : NULL; + } + + /** + * Sets data using the ArrayAccess interface + * + * @param number + * @param mixed + * @return void + */ + public function offsetSet($offset, $value) { + //Argument 2 must be an array or Eden_Model + Eden_Collection_Error::i()->argument(2, 'array', $this->_model); + + if(is_array($value)) { + //make it a model + $model = $this->_model; + $value = $this->$model($value); + } + + if (is_null($offset)) { + $this->_list[] = $value; + } else { + $this->_list[$offset] = $value; + } + } + + /** + * unsets using the ArrayAccess interface + * + * @param number + * @return bool + */ + public function offsetUnset($offset) { + $this->_list = Eden_Model::i($this->_list) + ->cut($offset) + ->get(); + } + + /** + * Rewinds the position + * For Iterator interface + * + * @return void + */ + public function rewind() { + reset($this->_list); + } + + /** + * returns serialized data using the Serializable interface + * + * @return string + */ + public function serialize() { + return $this->__toString(); + } + + /** + * Sets data + * + * @return this + */ + public function set(array $data = array()) { + foreach($data as $row) { + $this->add($row); + } + + return $this; + } + + /** + * Sets default model + * + * @param string + * @return this + */ + public function setModel($model) { + $error = Eden_Collection_Error::i()->argument(1, 'string'); + + if(!is_subclass_of($model, 'Eden_Model')) { + $error->setMessage(Eden_Collection_Error::NOT_SUB_MODEL) + ->addVariable($model) + ->trigger(); + } + + $this->_model = $model; + + return $this; + } + + /** + * sets data using the Serializable interface + * + * @param string + * @return void + */ + public function unserialize($data) { + $this->_list = json_decode($data, true); + return $this; + } + + /** + * Validates whether if the index is set + * For Iterator interface + * + * @return void + */ + public function valid() { + return isset($this->_list[key($this->_list)]); + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} + +/** + * Model Errors + */ +class Eden_Collection_Error extends Eden_Error { + /* Constants + -------------------------------*/ + const NOT_COLLECTION = 'The data passed into __construct is not a collection.'; + const NOT_SUB_MODEL = 'Class %s is not a child of Eden_Model'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i($message = NULL, $code = 0) { + $class = __CLASS__; + return new $class($message, $code); + } + + /* Public Methods + -------------------------------*/ + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/cookie.php b/library/eden/cookie.php new file mode 100755 index 0000000..7cd132e --- /dev/null +++ b/library/eden/cookie.php @@ -0,0 +1,281 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +require_once dirname(__FILE__).'/class.php'; + +/** + * General available methods for common cookie procedures. + * + * @package Eden + * @category utility + * @author Christian Blanquera cblanquera@openovate.com + */ +class Eden_Cookie extends Eden_Class implements ArrayAccess, Iterator { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getSingleton(__CLASS__); + } + + /* Public Methods + -------------------------------*/ + /** + * Removes all cookies. + * + * @return Eden_Cookie + */ + public function clear() { + foreach($_COOKIE as $key => $value) { + $this->remove($key); + } + + return $this; + } + + /** + * Returns the current item + * For Iterator interface + * + * @return void + */ + public function current() { + return current($_COOKIE); + } + + /** + * Returns data + * + * @param string|null + * @return mixed + */ + public function get($key = NULL) { + Eden_Cookie_Error::i()->argument(1, 'string', 'null'); + + if(is_null($key)) { + return $_COOKIE; + } + + if(isset($_COOKIE[$key])) { + return $_COOKIE[$key]; + } + + return NULL; + } + + /** + * Returns th current position + * For Iterator interface + * + * @return void + */ + public function key() { + return key($_COOKIE); + } + + /** + * Increases the position + * For Iterator interface + * + * @return void + */ + public function next() { + next($_COOKIE); + } + + /** + * isset using the ArrayAccess interface + * + * @param number + * @return bool + */ + public function offsetExists($offset) { + return isset($_COOKIE[$offset]); + } + + /** + * returns data using the ArrayAccess interface + * + * @param number + * @return bool + */ + public function offsetGet($offset) { + return isset($_COOKIE[$offset]) ? $_COOKIE[$offset] : NULL; + } + + /** + * Sets data using the ArrayAccess interface + * + * @param number + * @param mixed + * @return void + */ + public function offsetSet($offset, $value) { + $this->set($offset, $value, strtotime('+10 years')); + } + + /** + * unsets using the ArrayAccess interface + * + * @param number + * @return bool + */ + public function offsetUnset($offset) { + $this->remove($offset); + } + + /** + * Removes a cookie. + * + * @param *string cookie name + * @return Eden_Cookie + */ + public function remove($name) { + Eden_Cookie_Error::i()->argument(1, 'string'); + + $this->set($name, NULL, time() - 3600); + + if(isset($_COOKIE[$name])) { + unset($_COOKIE[$name]); + } + + return $this; + } + + /** + * Rewinds the position + * For Iterator interface + * + * @return void + */ + public function rewind() { + reset($_COOKIE); + } + + /** + * Sets a cookie. + * + * @param *string cookie name + * @param variable the data + * @param int expiration + * @param string path to make the cookie available + * @param string|null the domain + * @return this + */ + public function set($key, $data = NULL, $expires = 0, $path = NULL, $domain = NULL, $secure = false, $httponly = false) { + //argment test + Eden_Cookie_Error::i() + ->argument(1, 'string') //argument 1 must be a string + ->argument(2, 'string', 'numeric', 'null') //argument 2 must be a string,numeric or null + ->argument(3, 'int') //argument 3 must be a integer + ->argument(4, 'string', 'null') //argument 4 must be a string or null + ->argument(5, 'string', 'null') //argument 5 must be a string or null + ->argument(6, 'bool') //argument 6 must be a boolean + ->argument(7, 'bool'); //argument 7 must be a boolean + + $_COOKIE[$key] = $data; + setcookie($key, $data, $expires, $path, $domain, $secure, $httponly); + + return $this; + } + + /** + * Sets a set of cookies. + * + * @param *array the data in key value format + * @param int expiration + * @param string path to make the cookie available + * @param string|null the domain + * @return this + */ + public function setData(array $data, $expires = 0, $path = NULL, $domain = NULL, $secure = false, $httponly = false) { + foreach($data as $key => $value) { + $this->set($key, $value, $expires, $path, $domain, $secure, $httponly); + } + + return $this; + } + + /** + * Sets a secure cookie. + * + * @param *string cookie name + * @param variable the data + * @param int expiration + * @param string path to make the cookie available + * @param string|null the domain + * @return this + */ + public function setSecure($key, $data = NULL, $expires = 0, $path = NULL, $domain = NULL) { + return $this->set($key, $data, $expires, $path, $domain, true, false); + } + + /** + * Sets a set of secure cookies. + * + * @param *array the data in key value format + * @param int expiration + * @param string path to make the cookie available + * @param string|null the domain + * @return this + */ + public function setSecureData(array $data, $expires = 0, $path = NULL, $domain = NULL) { + $this->set($data, $expires, $path, $domain, true, false); + return $this; + } + + /** + * Validates whether if the index is set + * For Iterator interface + * + * @return void + */ + public function valid() { + return isset($_COOKIE[$this->key()]); + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} + +/** + * Cookie Errors + */ +class Eden_Cookie_Error extends Eden_Error { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i($message = NULL, $code = 0) { + $class = __CLASS__; + return new $class($message, $code); + } + + /* Public Methods + -------------------------------*/ + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/country.php b/library/eden/country.php new file mode 100644 index 0000000..619afbc --- /dev/null +++ b/library/eden/country.php @@ -0,0 +1,188 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +require_once dirname(__FILE__).'/class.php'; +require_once dirname(__FILE__).'/country/error.php'; +require_once dirname(__FILE__).'/country/us.php'; +require_once dirname(__FILE__).'/country/ca.php'; +require_once dirname(__FILE__).'/country/uk.php'; +require_once dirname(__FILE__).'/country/au.php'; + +/** + * Country Factory + * + * @package Eden + * @category utility + * @author Christian Blanquera cblanquera@openovate.com + */ +class Eden_Country extends Eden_Class { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getSingleton(__CLASS__); + } + + /* Public Methods + -------------------------------*/ + public function au() { + return Eden_Country_Au::i(); + } + + public function ca() { + return Eden_Country_Ca::i(); + } + + public function getList() { + return self::$_countries; + } + + public function uk() { + return Eden_Country_Uk::i(); + } + + public function us() { + return Eden_Country_Us::i(); + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ + /* Large Data + -------------------------------*/ + protected static $_countries = array( + 'GB' => 'United Kingdom', 'US' => 'United States', + 'AF' => 'Afghanistan', 'AL' => 'Albania', + 'DZ' => 'Algeria', 'AS' => 'American Samoa', + 'AD' => 'Andorra', 'AO' => 'Angola', + 'AI' => 'Anguilla', 'AQ' => 'Antarctica', + 'AG' => 'Antigua And Barbuda', 'AR' => 'Argentina', + 'AM' => 'Armenia', 'AW' => 'Aruba', + 'AU' => 'Australia', 'AT' => 'Austria', + 'AZ' => 'Azerbaijan', 'BS' => 'Bahamas', + 'BH' => 'Bahrain', 'BD' => 'Bangladesh', + 'BB' => 'Barbados', 'BY' => 'Belarus', + 'BE' => 'Belgium', 'BZ' => 'Belize', + 'BJ' => 'Benin', 'BM' => 'Bermuda', + 'BT' => 'Bhutan', 'BO' => 'Bolivia', + 'BA' => 'Bosnia And Herzegowina', 'BW' => 'Botswana', + 'BV' => 'Bouvet Island', 'BR' => 'Brazil', + 'IO' => 'British Indian Ocean Territory', 'BN' => 'Brunei Darussalam', + 'BG' => 'Bulgaria', 'BF' => 'Burkina Faso', + 'BI' => 'Burundi', 'KH' => 'Cambodia', + 'CM' => 'Cameroon', 'CA' => 'Canada', + 'CV' => 'Cape Verde', 'KY' => 'Cayman Islands', + 'CF' => 'Central African Republic', 'TD' => 'Chad', + 'CL' => 'Chile', 'CN' => 'China', + 'CX' => 'Christmas Island', 'CC' => 'Cocos (Keeling) Islands', + 'CO' => 'Colombia', 'KM' => 'Comoros', + 'CG' => 'Congo', 'CD' => 'Congo, The Democratic Republic Of The', + 'CK' => 'Cook Islands', 'CR' => 'Costa Rica', + 'CI' => 'Cote D\'Ivoire', 'HR' => 'Croatia (Local Name: Hrvatska)', + 'CU' => 'Cuba', 'CY' => 'Cyprus', + 'CZ' => 'Czech Republic', 'DK' => 'Denmark', + 'DJ' => 'Djibouti', 'DM' => 'Dominica', + 'DO' => 'Dominican Republic', 'TP' => 'East Timor', + 'EC' => 'Ecuador', 'EG' => 'Egypt', + 'SV' => 'El Salvador', 'GQ' => 'Equatorial Guinea', + 'ER' => 'Eritrea', 'EE' => 'Estonia', + 'ET' => 'Ethiopia', 'FK' => 'Falkland Islands (Malvinas)', + 'FO' => 'Faroe Islands', 'FJ' => 'Fiji', + 'FI' => 'Finland', 'FR' => 'France', + 'FX' => 'France, Metropolitan', 'GF' => 'French Guiana', + 'PF' => 'French Polynesia', 'TF' => 'French Southern Territories', + 'GA' => 'Gabon', 'GM' => 'Gambia', + 'GE' => 'Georgia', 'DE' => 'Germany', + 'GH' => 'Ghana', 'GI' => 'Gibraltar', + 'GR' => 'Greece', 'GL' => 'Greenland', + 'GD' => 'Grenada', 'GP' => 'Guadeloupe', + 'GU' => 'Guam', 'GT' => 'Guatemala', + 'GN' => 'Guinea', 'GW' => 'Guinea-Bissau', + 'GY' => 'Guyana', 'HT' => 'Haiti', + 'HM' => 'Heard And Mc Donald Islands', 'VA' => 'Holy See (Vatican City State)', + 'HN' => 'Honduras', 'HK' => 'Hong Kong', + 'HU' => 'Hungary', 'IS' => 'Iceland', + 'IN' => 'India', 'ID' => 'Indonesia', + 'IR' => 'Iran (Islamic Republic Of)', 'IQ' => 'Iraq', + 'IE' => 'Ireland', 'IL' => 'Israel', + 'IT' => 'Italy', 'JM' => 'Jamaica', + 'JP' => 'Japan', 'JO' => 'Jordan', + 'KZ' => 'Kazakhstan', 'KE' => 'Kenya', + 'KI' => 'Kiribati', 'KP' => 'Korea, Democratic People\'s Republic Of', + 'KR' => 'Korea, Republic Of', 'KW' => 'Kuwait', + 'KG' => 'Kyrgyzstan', 'LA' => 'Lao People\'s Democratic Republic', + 'LV' => 'Latvia', 'LB' => 'Lebanon', + 'LS' => 'Lesotho', 'LR' => 'Liberia', + 'LY' => 'Libyan Arab Jamahiriya', 'LI' => 'Liechtenstein', + 'LT' => 'Lithuania', 'LU' => 'Luxembourg', + 'MO' => 'Macau', 'MK' => 'Macedonia, Former Yugoslav Republic Of', + 'MG' => 'Madagascar', 'MW' => 'Malawi', + 'MY' => 'Malaysia', 'MV' => 'Maldives', + 'ML' => 'Mali', 'MT' => 'Malta', + 'MH' => 'Marshall Islands', 'MQ' => 'Martinique', + 'MR' => 'Mauritania', 'MU' => 'Mauritius', + 'YT' => 'Mayotte', 'MX' => 'Mexico', + 'FM' => 'Micronesia, Federated States Of', 'MD' => 'Moldova, Republic Of', + 'MC' => 'Monaco', 'MN' => 'Mongolia', + 'MS' => 'Montserrat', 'MA' => 'Morocco', + 'MZ' => 'Mozambique', 'MM' => 'Myanmar', + 'NA' => 'Namibia', 'NR' => 'Nauru', + 'NP' => 'Nepal', 'NL' => 'Netherlands', + 'AN' => 'Netherlands Antilles', 'NC' => 'New Caledonia', + 'NZ' => 'New Zealand', 'NI' => 'Nicaragua', + 'NE' => 'Niger', 'NG' => 'Nigeria', + 'NU' => 'Niue', 'NF' => 'Norfolk Island', + 'MP' => 'Northern Mariana Islands', 'NO' => 'Norway', + 'OM' => 'Oman', 'PK' => 'Pakistan', + 'PW' => 'Palau', 'PA' => 'Panama', + 'PG' => 'Papua New Guinea', 'PY' => 'Paraguay', + 'PE' => 'Peru', 'PH' => 'Philippines', + 'PN' => 'Pitcairn', 'PL' => 'Poland', + 'PT' => 'Portugal', 'PR' => 'Puerto Rico', + 'QA' => 'Qatar', 'RE' => 'Reunion', + 'RO' => 'Romania', 'RU' => 'Russian Federation', + 'RW' => 'Rwanda', 'KN' => 'Saint Kitts And Nevis', + 'LC' => 'Saint Lucia', 'VC' => 'Saint Vincent And The Grenadines', + 'WS' => 'Samoa', 'SM' => 'San Marino', + 'ST' => 'Sao Tome And Principe', 'SA' => 'Saudi Arabia', + 'SN' => 'Senegal', 'SC' => 'Seychelles', + 'SL' => 'Sierra Leone', 'SG' => 'Singapore', + 'SK' => 'Slovakia (Slovak Republic)', 'SI' => 'Slovenia', + 'SB' => 'Solomon Islands', 'SO' => 'Somalia', + 'ZA' => 'South Africa', 'GS' => 'South Georgia, South Sandwich Islands', + 'ES' => 'Spain', 'LK' => 'Sri Lanka', + 'SH' => 'St. Helena', 'PM' => 'St. Pierre And Miquelon', + 'SD' => 'Sudan', 'SR' => 'Suriname', + 'SJ' => 'Svalbard And Jan Mayen Islands', 'SZ' => 'Swaziland', + 'SE' => 'Sweden', 'CH' => 'Switzerland', + 'SY' => 'Syrian Arab Republic', 'TW' => 'Taiwan', + 'TJ' => 'Tajikistan', 'TZ' => 'Tanzania, United Republic Of', + 'TH' => 'Thailand', 'TG' => 'Togo', + 'TK' => 'Tokelau', 'TO' => 'Tonga', + 'TT' => 'Trinidad And Tobago', 'TN' => 'Tunisia', + 'TR' => 'Turkey', 'TM' => 'Turkmenistan', + 'TC' => 'Turks And Caicos Islands', 'TV' => 'Tuvalu', + 'UG' => 'Uganda', 'UA' => 'Ukraine', + 'AE' => 'United Arab Emirates', 'UM' => 'United States Minor Outlying Islands', + 'UY' => 'Uruguay', 'UZ' => 'Uzbekistan', + 'VU' => 'Vanuatu', 'VE' => 'Venezuela', + 'VN' => 'Viet Nam', 'VG' => 'Virgin Islands (British)', + 'VI' => 'Virgin Islands (U.S.)', 'WF' => 'Wallis And Futuna Islands', + 'EH' => 'Western Sahara', 'YE' => 'Yemen', + 'YU' => 'Yugoslavia', 'ZM' => 'Zambia', + 'ZW' => 'Zimbabwe'); +} \ No newline at end of file diff --git a/library/eden/country/au.php b/library/eden/country/au.php new file mode 100644 index 0000000..3a5f55c --- /dev/null +++ b/library/eden/country/au.php @@ -0,0 +1,53 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Australia + * + * @package Eden + * @category utility + * @author Christian Blanquera cblanquera@openovate.com + */ +class Eden_Country_Australia extends Eden_Class { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected static $_territories = array( + 'Australian Capital Territory', 'New South Wales', + 'Northern Territory', 'Queensland', + 'South Australia', 'Tasmania', + 'Victoria', 'Western Australia'); + + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getSingleton(__CLASS__); + } + + /* Public Methods + -------------------------------*/ + /** + * Returns a list of Austrailian territories + * + * @return array + */ + public function getTerritories() { + return self::$_territories; + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/country/ca.php b/library/eden/country/ca.php new file mode 100644 index 0000000..ea3266f --- /dev/null +++ b/library/eden/country/ca.php @@ -0,0 +1,56 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Canada + * + * @package Eden + * @category utility + * @author Christian Blanquera cblanquera@openovate.com + */ +class Eden_Country_Ca extends Eden_Class { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected static $_territories = array( + 'BC' => 'British Columbia', 'ON' => 'Ontario', + 'NL' => 'Newfoundland and Labrador', 'NS' => 'Nova Scotia', + 'PE' => 'Prince Edward Island', 'NB' => 'New Brunswick', + 'QC' => 'Quebec', 'MB' => 'Manitoba', + 'SK' => 'Saskatchewan', 'AB' => 'Alberta', + 'NT' => 'Northwest Territories', 'NU' => 'Nunavut', + 'YT' => 'Yukon Territory'); + + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getSingleton(__CLASS__); + } + + /* Public Methods + -------------------------------*/ + /** + * Returns a list of Canadian territories + * + * @return array + */ + public function getTerritories() { + return self::$_territories; + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/country/error.php b/library/eden/country/error.php new file mode 100644 index 0000000..461e695 --- /dev/null +++ b/library/eden/country/error.php @@ -0,0 +1,39 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Country exception + * + * @package Eden + * @category utility + * @author Christian Blanquera cblanquera@openovate.com + */ +class Eden_Country_Error extends Eden_Error { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i($message = NULL, $code = 0) { + $class = __CLASS__; + return new $class($message, $code); + } + + /* Public Methods + -------------------------------*/ + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/country/uk.php b/library/eden/country/uk.php new file mode 100644 index 0000000..471b418 --- /dev/null +++ b/library/eden/country/uk.php @@ -0,0 +1,103 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * United Kingdom + * + * @package Eden + * @category utility + * @author Christian Blanquera cblanquera@openovate.com + */ +class Eden_Country_Uk extends Eden_Class { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getSingleton(__CLASS__); + } + + /* Public Methods + -------------------------------*/ + /** + * Returns a list of counties + * + * @return array + */ + public function getCounties() { + return self::$_counties; + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ + /* Large Data + -------------------------------*/ + protected static $_counties = array( + 'Aberdeenshire', 'Alderney', + 'Angus/Forfarshire', 'Argyllshire', + 'Avon', 'Ayrshire', + 'Banffshire', 'Bedfordshire', + 'Berkshire', 'Berwickshire', + 'Buckinghamshire', 'Buteshire', + 'Caithness', 'Cambridgeshire', + 'Cheshire', 'Clackmannanshire', + 'Clwyd', 'Cornwall', + 'County Antrim', 'County Armagh', + 'County Down', 'County Fermanagh', + 'County Londonderry', 'County Tyrone', + 'Cumbria', 'Derbyshire', + 'Devon', 'Dorset', + 'Dumbartonshire', 'Dumfriesshire', + 'Durham', 'Dyfed', + 'East Lothian', 'East Sussex', + 'East Yorkshire', 'Essex', + 'Fair Isle', 'Fife', + 'Gloucestershire', 'Greater London', + 'Greater Manchester', 'Guernsey', + 'Gwent', 'Gwynedd', + 'Hampshire', 'Herefordshire', + 'Herm', 'Hertfordshire', + 'Huntingdonshire', 'Inner Hebrides', + 'Inverness-shire', 'Isle of Man', + 'Isle of Wight', 'Isles of Scilly', + 'Jersey', 'Kent', + 'Kincardineshire', 'Kinross-shire', + 'Kirkcudbrightshire', 'Lanarkshire', + 'Lancashire', 'Leicestershire', + 'Lincolnshire', 'Merseyside', + 'Mid Glamorgan', 'Middlesex', + 'Midlothian/Edinburghshire', 'Morayshire', + 'Nairnshire', 'Norfolk', + 'North Yorkshire', 'Northamptonshire', + 'Northumberland', 'Nottinghamshire', + 'Orkney', 'Outer Hebrides', + 'Oxfordshire', 'Peeblesshire', + 'Perthshire', 'Powys', + 'Renfrewshire', 'Ross-shire', + 'Roxburghshire', 'Rutland', + 'Sark', 'Selkirkshire', + 'Shetland', 'Shropshire', + 'Somerset', 'South Glamorgan', + 'South Yorkshire', 'Staffordshire', + 'Stirlingshire', 'Suffolk', + 'Surrey', 'Sutherland', + 'Tyne and Wear', 'Warwickshire', + 'West Glamorgan', 'West Lothian/Linlithgowshire', + 'West Midlands', 'West Sussex', + 'West Yorkshire', 'Wigtownshire', + 'Wiltshire', 'Worcestershire'); +} \ No newline at end of file diff --git a/library/eden/country/us.php b/library/eden/country/us.php new file mode 100644 index 0000000..00691d2 --- /dev/null +++ b/library/eden/country/us.php @@ -0,0 +1,140 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * United States + * + * @package Eden + * @category utility + * @author Christian Blanquera cblanquera@openovate.com + */ +class Eden_Country_Us extends Eden_Class { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getSingleton(__CLASS__); + } + + /* Public Methods + -------------------------------*/ + /** + * Returns a state abbreviation based on zip code + * + * @param int + * @return string + */ + public function getStateFromPostal($postal) { + Eden_Country_Error::i()->argument(1, 'int'); + + if(strlen((string) $postal) < 5) { + return false; + } + + for($i=0; $i < count(self::$_codes); $i++) { + if($postal < substr(self::$_codes[$i],2,5) + || $postal > substr(self::$_codes[$i],7,5)) { + continue; + } + + return substr(self::$_codes[$i], 0, 2); + } + + return false; + + } + + /** + * Returns a list of US states + * + * @return array + */ + public function getStates() { + return self::$_states; + } + + /** + * Returns a list of US territories + * + * @return array + */ + public function getTerritories() { + return self::$_territories; + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ + /* Large Data + -------------------------------*/ + protected static $_codes = array( + 'AK9950099929', 'AL3500036999', 'AR7160072999', 'AR7550275505', + 'AZ8500086599', 'CA9000096199', 'CO8000081699', 'CT0600006999', + 'DC2000020099', 'DC2020020599', 'DE1970019999', 'FL3200033999', + 'FL3410034999', 'GA3000031999', 'HI9670096798', 'HI9680096899', + 'IA5000052999', 'ID8320083899', 'IL6000062999', 'IN4600047999', + 'KS6600067999', 'KY4000042799', 'KY4527545275', 'LA7000071499', + 'LA7174971749', 'MA0100002799', 'MD2033120331', 'MD2060021999', + 'ME0380103801', 'ME0380403804', 'ME0390004999', 'MI4800049999', + 'MN5500056799', 'MO6300065899', 'MS3860039799', 'MT5900059999', + 'NC2700028999', 'ND5800058899', 'NE6800069399', 'NH0300003803', + 'NH0380903899', 'NJ0700008999', 'NM8700088499', 'NV8900089899', + 'NY0040000599', 'NY0639006390', 'NY0900014999', 'OH4300045999', + 'OK7300073199', 'KY7340074999', 'OR9700097999', 'PA1500019699', + 'RI0280002999', 'RI0637906379', 'SC2900029999', 'SD5700057799', + 'TN3700038599', 'TN7239572395', 'TX7330073399', 'TX7394973949', + 'TX7500079999', 'TX8850188599', 'UT8400084799', 'VA2010520199', + 'VA2030120301', 'VA2037020370', 'VA2200024699', 'VT0500005999', + 'WA9800099499', 'WI4993649936', 'WI5300054999', 'WV2470026899', + 'WY8200083199'); + + protected static $_states = array( + 'AL' => 'Alabama', 'AK' => 'Alaska', + 'AZ' => 'Arizona', 'AR' => 'Arkansas', + 'CA' => 'California', 'CO' => 'Colorado', + 'CT' => 'Connecticut', 'DE' => 'Delaware', + 'DC' => 'District Of Columbia', 'FL' => 'Florida', + 'GA' => 'Georgia', 'HI' => 'Hawaii', + 'ID' => 'Idaho', 'IL' => 'Illinois', + 'IN' => 'Indiana', 'IA' => 'Iowa', + 'KS' => 'Kansas', 'KY' => 'Kentucky', + 'LA' => 'Louisiana', 'ME' => 'Maine', + 'MD' => 'Maryland', 'MA' => 'Massachusetts', + 'MI' => 'Michigan', 'MN' => 'Minnesota', + 'MS' => 'Mississippi', 'MO' => 'Missouri', + 'MT' => 'Montana', 'NE' => 'Nebraska', + 'NV' => 'Nevada', 'NH' => 'New Hampshire', + 'NJ' => 'New Jersey', 'NM' => 'New Mexico', + 'NY' => 'New York', 'NC' => 'North Carolina', + 'ND' => 'North Dakota', 'OH' => 'Ohio', + 'OK' => 'Oklahoma', 'OR' => 'Oregon', + 'PA' => 'Pennsylvania', 'RI' => 'Rhode Island', + 'SC' => 'South Carolina', 'SD' => 'South Dakota', + 'TN' => 'Tennessee', 'TX' => 'Texas', + 'UT' => 'Utah', 'VT' => 'Vermont', + 'VA' => 'Virginia', 'WA' => 'Washington', + 'WV' => 'West Virginia', 'WI' => 'Wisconsin', + 'WY' => 'Wyoming'); + + protected static $_territories = array( + 'AS' => 'American Samoa', 'FM' => 'Federated States of Micronesia', + 'GU' => 'Guam', 'MH' => 'Marshall Islands', + 'MP' => 'Northern Mariana Islands', 'PW' => 'Palau', + 'PR' => 'Puerto Rico', 'VI' => 'Virgin Islands', + 'AE' => 'Armed Forces', 'AA' => 'Armed Forces Americas', + 'AP' => 'Armed Forces Pacific'); +} \ No newline at end of file diff --git a/library/eden/curl.php b/library/eden/curl.php new file mode 100644 index 0000000..6bc4817 --- /dev/null +++ b/library/eden/curl.php @@ -0,0 +1,588 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +require_once dirname(__FILE__).'/class.php'; + +/** + * cURL allows you to connect and communicate to many + * different types of servers with many different types + * of protocols. We rely on cURL heavily as the main + * transport for all API interactions. + * + * @package Eden + * @category curl + * @author Christian Blanquera cblanquera@openovate.com + */ +class Eden_Curl extends Eden_Class implements ArrayAccess { + /* Constants + -------------------------------*/ + const PUT = 'PUT'; + const DELETE = 'DELETE'; + const GET = 'GET'; + const POST = 'POST'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_options = array(); + protected $_meta = array(); + protected $_query = array(); + protected $_headers = array(); + + protected static $_setBoolKeys = array( + 'AutoReferer' => CURLOPT_AUTOREFERER, + 'BinaryTransfer' => CURLOPT_BINARYTRANSFER, + 'CookieSession' => CURLOPT_COOKIESESSION, + 'CrlF' => CURLOPT_CRLF, + 'DnsUseGlobalCache' => CURLOPT_DNS_USE_GLOBAL_CACHE, + 'FailOnError' => CURLOPT_FAILONERROR, + 'FileTime' => CURLOPT_FILETIME, + 'FollowLocation' => CURLOPT_FOLLOWLOCATION, + 'ForbidReuse' => CURLOPT_FORBID_REUSE, + 'FreshConnect' => CURLOPT_FRESH_CONNECT, + 'FtpUseEprt' => CURLOPT_FTP_USE_EPRT, + 'FtpUseEpsv' => CURLOPT_FTP_USE_EPSV, + 'FtpAppend' => CURLOPT_FTPAPPEND, + 'FtpListOnly' => CURLOPT_FTPLISTONLY, + 'Header' => CURLOPT_HEADER, + 'HeaderOut' => CURLINFO_HEADER_OUT, + 'HttpGet' => CURLOPT_HTTPGET, + 'HttpProxyTunnel' => CURLOPT_HTTPPROXYTUNNEL, + 'Netrc' => CURLOPT_NETRC, + 'Nobody' => CURLOPT_NOBODY, + 'NoProgress' => CURLOPT_NOPROGRESS, + 'NoSignal' => CURLOPT_NOSIGNAL, + 'Post' => CURLOPT_POST, + 'Put' => CURLOPT_PUT, + 'ReturnTransfer' => CURLOPT_RETURNTRANSFER, + 'SslVerifyPeer' => CURLOPT_SSL_VERIFYPEER, + 'TransferText' => CURLOPT_TRANSFERTEXT, + 'UnrestrictedAuth' => CURLOPT_UNRESTRICTED_AUTH, + 'Upload' => CURLOPT_UPLOAD, + 'Verbose' => CURLOPT_VERBOSE); + + protected static $_setIntegerKeys = array( + 'BufferSize' => CURLOPT_BUFFERSIZE, + 'ClosePolicy' => CURLOPT_CLOSEPOLICY, + 'ConnectTimeout' => CURLOPT_CONNECTTIMEOUT, + 'ConnectTimeoutMs' => CURLOPT_CONNECTTIMEOUT_MS, + 'DnsCacheTimeout' => CURLOPT_DNS_CACHE_TIMEOUT, + 'FtpSslAuth' => CURLOPT_FTPSSLAUTH, + 'HttpVersion' => CURLOPT_HTTP_VERSION, + 'HttpAuth' => CURLOPT_HTTPAUTH, + 'InFileSize' => CURLOPT_INFILESIZE, + 'LowSpeedLimit' => CURLOPT_LOW_SPEED_LIMIT, + 'LowSpeedTime' => CURLOPT_LOW_SPEED_TIME, + 'MaxConnects' => CURLOPT_MAXCONNECTS, + 'MaxRedirs' => CURLOPT_MAXREDIRS, + 'Port' => CURLOPT_PORT, + 'ProxyAuth' => CURLOPT_PROXYAUTH, + 'ProxyPort' => CURLOPT_PROXYPORT, + 'ProxyType' => CURLOPT_PROXYTYPE, + 'ResumeFrom' => CURLOPT_RESUME_FROM, + 'SslVerifyHost' => CURLOPT_SSL_VERIFYHOST, + 'SslVersion' => CURLOPT_SSLVERSION, + 'TimeCondition' => CURLOPT_TIMECONDITION, + 'Timeout' => CURLOPT_TIMEOUT, + 'TimeoutMs' => CURLOPT_TIMEOUT_MS, + 'TimeValue' => CURLOPT_TIMEVALUE); + + protected static $_setStringKeys = array( + 'CaInfo' => CURLOPT_CAINFO, + 'CaPath' => CURLOPT_CAPATH, + 'Cookie' => CURLOPT_COOKIE, + 'CookieFile' => CURLOPT_COOKIEFILE, + 'CookieJar' => CURLOPT_COOKIEJAR, + 'CustomRequest' => CURLOPT_CUSTOMREQUEST, + 'EgdSocket' => CURLOPT_EGDSOCKET, + 'Encoding' => CURLOPT_ENCODING, + 'FtpPort' => CURLOPT_FTPPORT, + 'Interface' => CURLOPT_INTERFACE, + 'Krb4Level' => CURLOPT_KRB4LEVEL, + 'PostFields' => CURLOPT_POSTFIELDS, + 'Proxy' => CURLOPT_PROXY, + 'ProxyUserPwd' => CURLOPT_PROXYUSERPWD, + 'RandomFile' => CURLOPT_RANDOM_FILE, + 'Range' => CURLOPT_RANGE, + 'Referer' => CURLOPT_REFERER, + 'SslCipherList' => CURLOPT_SSL_CIPHER_LIST, + 'SslCert' => CURLOPT_SSLCERT, + 'SslCertPassword' => CURLOPT_SSLCERTPASSWD, + 'SslCertType' => CURLOPT_SSLCERTTYPE, + 'SslEngine' => CURLOPT_SSLENGINE, + 'SslEngineDefault' => CURLOPT_SSLENGINE_DEFAULT, + 'Sslkey' => CURLOPT_SSLKEY, + 'SslKeyPasswd' => CURLOPT_SSLKEYPASSWD, + 'SslKeyType' => CURLOPT_SSLKEYTYPE, + 'Url' => CURLOPT_URL, + 'UserAgent' => CURLOPT_USERAGENT, + 'UserPwd' => CURLOPT_USERPWD); + + protected static $_setArrayKeys = array( + 'Http200Aliases' => CURLOPT_HTTP200ALIASES, + 'HttpHeader' => CURLOPT_HTTPHEADER, + 'PostQuote' => CURLOPT_POSTQUOTE, + 'Quote' => CURLOPT_QUOTE); + + protected static $_setFileKeys = array( + 'File' => CURLOPT_FILE, + 'InFile' => CURLOPT_INFILE, + 'StdErr' => CURLOPT_STDERR, + 'WriteHeader' => CURLOPT_WRITEHEADER); + + protected static $_setCallbackKeys = array( + 'HeaderFunction' => CURLOPT_HEADERFUNCTION, + 'ReadFunction' => CURLOPT_READFUNCTION, + 'WriteFunction' => CURLOPT_WRITEFUNCTION); + + + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + public function __call($name, $args) { + if(strpos($name, 'set') === 0) { + $method = substr($name, 3); + + if(isset(self::$_setBoolKeys[$method])) { + Eden_Curl_Error::i()->vargument($name, $args, 1, 'bool'); + $key = self::$_setBoolKeys[$method]; + $this->_options[$key] = $args[0]; + + return $this; + } + + if(isset(self::$_setIntegerKeys[$method])) { + Eden_Curl_Error::i()->vargument($name, $args, 1, 'int'); + $key = self::$_setIntegerKeys[$method]; + $this->_options[$key] = $args[0]; + + return $this; + } + + if(isset(self::$_setStringKeys[$method])) { + Eden_Curl_Error::i()->vargument($name, $args, 1, 'string'); + $key = self::$_setStringKeys[$method]; + $this->_options[$key] = $args[0]; + + return $this; + } + + if(isset(self::$_setArrayKeys[$method])) { + Eden_Curl_Error::i()->vargument($name, $args, 1, 'array'); + $key = self::$_setArrayKeys[$method]; + $this->_options[$key] = $args[0]; + + return $this; + } + + if(isset(self::$_setFileKeys[$method])) { + $key = self::$_setFileKeys[$method]; + $this->_options[$key] = $args[0]; + + return $this; + } + + if(isset(self::$_setCallbackKeys[$method])) { + Eden_Curl_Error::i()->vargument($name, $args, 1, 'array', 'string'); + $key = self::$_setCallbackKeys[$method]; + $this->_options[$key] = $args[0]; + + return $this; + } + } + + parent::__call($name, $args); + } + + /* Public Methods + -------------------------------*/ + /** + * Send the curl off and returns the results + * parsed as DOMDocument + * + * @return DOMDOcument + */ + public function getDomDocumentResponse() { + $this->_meta['response'] = $this->getResponse(); + $xml = new DOMDocument(); + $xml->loadXML($this->_meta['response']); + return $xml; + } + + /** + * Send the curl off and returns the results + * parsed as JSON + * + * @return array + */ + public function getJsonResponse($assoc = true) { + $this->_meta['response'] = $this->getResponse(); + Eden_Curl_Error::i()->argument(1, 'bool'); + return json_decode($this->_meta['response'], $assoc); + } + + /** + * Returns the meta of the last call + * + * @return array + */ + public function getMeta($key = NULL) { + Eden_Curl_Error::i()->argument(1, 'string', 'null'); + + if(isset($this->_meta[$key])) { + return $this->_meta[$key]; + } + + return $this->_meta; + } + + /** + * Send the curl off and returns the results + * parsed as url query + * + * @return array + */ + public function getQueryResponse() { + $this->_meta['response'] = $this->getResponse(); + parse_str($this->_meta['response'], $response); + return $response; + } + + /** + * Send the curl off and returns the results + * + * @return string + */ + public function getResponse() { + $curl = curl_init(); + + $this->_addParameters()->_addHeaders(); + $this->_options[CURLOPT_RETURNTRANSFER] = true; + curl_setopt_array($curl, $this->_options); + + $response = curl_exec($curl); + + $this->_meta = array( + 'info' => curl_getinfo($curl, CURLINFO_HTTP_CODE), + 'error_message' => curl_errno($curl), + 'error_code' => curl_error($curl)); + + curl_close($curl); + unset($curl); + + return $response; + } + + /** + * Send the curl off and returns the results + * parsed as SimpleXml + * + * @return SimpleXmlElement + */ + public function getSimpleXmlResponse() { + $this->_meta['response'] = $this->getResponse(); + return simplexml_load_string($this->_meta['response']); + } + + /** + * isset using the ArrayAccess interface + * + * @param number + * @return bool + */ + public function offsetExists($offset) { + return isset($this->_option[$offset]); + } + + /** + * returns data using the ArrayAccess interface + * + * @param number + * @return bool + */ + public function offsetGet($offset) { + return isset($this->_option[$offset]) ? $this->_option[$offset] : NULL; + } + + /** + * Sets data using the ArrayAccess interface + * + * @param number + * @param mixed + * @return void + */ + public function offsetSet($offset, $value) { + if (!is_null($offset)) { + if(in_array($offset, $this->_setBoolKeys)) { + $method = array_search($offset, $this->_setBoolKeys); + $this->_call('set'.$method, array($value)); + } + + if(in_array($offset, $this->_setIntegerKeys)) { + $method = array_search($offset, $this->_setIntegerKeys); + $this->_call('set'.$method, array($value)); + } + + if(in_array($offset, $this->_setStringKeys)) { + $method = array_search($offset, $this->_setStringKeys); + $this->_call('set'.$method, array($value)); + } + + if(in_array($offset, $this->_setArrayKeys)) { + $method = array_search($offset, $this->_setArrayKeys); + $this->_call('set'.$method, array($value)); + } + + if(in_array($offset, $this->_setFileKeys)) { + $method = array_search($offset, $this->_setFileKeys); + $this->_call('set'.$method, array($value)); + } + + if(in_array($offset, $this->_setCallbackKeys)) { + $method = array_search($offset, $this->_setCallbackKeys); + $this->_call('set'.$method, array($value)); + } + } + } + + /** + * unsets using the ArrayAccess interface + * + * @param number + * @return bool + */ + public function offsetUnset($offset) { + unset($this->_option[$offset]); + } + + /** + * Send the curl off + * + * @return this + */ + public function send() { + $curl = curl_init(); + + $this->_addParameters()->_addHeaders(); + curl_setopt_array($curl, $this->_options); + curl_exec($curl); + + $this->_meta = array( + 'info' => curl_getinfo($curl, CURLINFO_HTTP_CODE), + 'error_message' => curl_errno($curl), + 'error_code' => curl_error($curl)); + + curl_close($curl); + unset($curl); + + return $this; + } + + /** + * Curl has problems handling custom request types + * from misconfigured end points or vice versa. + * When default cURL fails, try a custom GET instead + * + * @return this + */ + public function setCustomGet() { + $this->setCustomRequest(self::GET); + return $this; + } + + /** + * Curl has problems handling custom request types + * from misconfigured end points or vice versa. + * When default cURL fails, try a custom POST instead + * + * @return this + */ + public function setCustomPost() { + $this->setCustomRequest(self::POST); + return $this; + } + + /** + * Curl has problems handling custom request types + * from misconfigured end points or vice versa. + * When default cURL fails, try a custom PUT instead + * + * @return this + */ + public function setCustomPut() { + $this->setCustomRequest(self::PUT); + return $this; + } + + /** + * Curl has problems handling custom request types + * from misconfigured end points or vice versa. + * When default cURL fails, try a custom DELETE instead + * + * @return this + */ + public function setCustomDelete() { + $this->setCustomRequest(self::DELETE); + return $this; + } + + /** + * CURLOPT_POSTFIELDS accepts array and string + * arguments, this is a special case that __call + * does not handle + * + * @param string|array + * @return this + */ + public function setPostFields($fields) { + //argument 1 must be a string or array + Eden_Curl_Error::i()->argument(1, 'array', 'string'); + $this->_options[CURLOPT_POSTFIELDS] = $fields; + + return $this; + } + + /** + * Sets request headers + * + * @param array|string + * @return this + */ + public function setHeaders($key, $value = NULL) { + Eden_Curl_Error::i() + ->argument(1, 'array', 'string') + ->argument(2, 'scalar','null'); + + if(is_array($key)) { + $this->_headers = $key; + return $this; + } + + $this->_headers[] = $key.': '.$value; + return $this; + } + + /** + * Sets url parameter + * + * @param array|string + * @return this + */ + public function setUrlParameter($key, $value = NULL) { + Eden_Curl_Error::i() + ->argument(1, 'array', 'string') + ->argument(2, 'scalar'); + + if(is_array($key)) { + $this->_param = $key; + return $this; + } + + $this->_param[$key] = $value; + } + + /** + * Sets CURLOPT_SSL_VERIFYHOST + * + * @param bool + * @return this + */ + public function verifyHost($on = true) { + Eden_Curl_Error::i()->argument(1, 'bool'); + $this->_options[CURLOPT_SSL_VERIFYHOST] = $on ? 1 : 2; + return $this; + } + + /** + * Sets CURLOPT_SSL_VERIFYPEER + * + * @param bool + * @return this + */ + public function verifyPeer($on = true) { + Eden_Curl_Error::i()->argument(1, 'bool'); + $this->_options[CURLOPT_SSL_VERIFYPEER] = $on; + return $this; + } + + /* Protected Methods + -------------------------------*/ + protected function _addHeaders() { + if(empty($this->_headers)) { + return $this; + } + + $this->_options[CURLOPT_HTTPHEADER] = $this->_headers; + return $this; + } + + protected function _addParameters() { + if(empty($this->_params)) { + return $this; + } + + $params = http_build_query($this->_params); + if($this->_options[CURLOPT_POST]) { + $this->_options[CURLOPT_POSTFIELDS] = $params; + return $this; + } + + //if there is a question mark in the url + if(strpos($this->_options[CURLOPT_URL], '?') === false) { + //add the question mark + $params = '?'.$params; + //else if the question mark is not at the end + } else if(substr($this->_options[CURLOPT_URL], -1, 1) != '?') { + //append the parameters to the end + //with the other parameters + $params = '&'.$params; + } + + //append the parameters + $this->_options[CURLOPT_URL] .= $params; + + return $this; + } + + /* Private Methods + -------------------------------*/ +} + +/** + * cUrl Errors + */ +class Eden_Curl_Error extends Eden_Error { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i($message = NULL, $code = 0) { + $class = __CLASS__; + return new $class($message, $code); + } + + /* Public Methods + -------------------------------*/ + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/debug.php b/library/eden/debug.php new file mode 100644 index 0000000..5c96cfa --- /dev/null +++ b/library/eden/debug.php @@ -0,0 +1,125 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +require_once dirname(__FILE__).'/class.php'; + +/** + * Used to inspect classes and result sets + * + * @package Eden + * @category core + * @author Christian Blanquera cblanquera@openovate.com + */ +class Eden_Debug extends Eden_Class { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_scope = NULL; + protected $_name = NULL; + + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getSingleton(__CLASS__); + } + + public function __call($name, $args) { + //if the scope is null + if(is_null($this->_scope)) { + //just call the parent + return parent::__call($name, $args); + } + + //get the results from the method call + $results = $this->_getResults($name, $args); + + //set temp variables + $name = $this->_name; + $scope = $this->_scope; + + //reset globals + $this->_name = NULL; + $this->_scope = NULL; + + //if there's a property name + if($name) { + //output that + $scope->debug($name); + //and return the results + return $results; + } + + //at this point we should output the results + $class = get_class($scope); + + $this->output(sprintf(self::DEBUG, $class.'->'.$name)) + ->output($results); + + //and return the results + return $results; + } + + /* Public Methods + -------------------------------*/ + /** + * Hijacks the class and reports the results of the next + * method call + * + * @param object + * @param string + * @return this + */ + public function next($scope, $name = NULL) { + Eden_Error::i() + ->argument(1, 'object') + ->argument(2, 'string', 'null'); + + $this->_scope = $scope; + $this->_name = $name; + + return $this; + } + + /** + * Outputs anything + * + * @param *variable any data + * @return Eden_Tool + */ + public function output($variable) { + if($variable === true) { + $variable = '*TRUE*'; + } else if($variable === false) { + $variable = '*FALSE*'; + } else if(is_null($variable)) { + $variable = '*NULL*'; + } + + echo '
'.print_r($variable, true).'
'; + return $this; + } + + /* Protected Methods + -------------------------------*/ + protected function _getResults($name, $args) { + if(method_exists($this->_scope, $name)) { + return call_user_func_array(array($this->_scope, $name), $args); + } + + return $this->_scope->__call($name, $args); + } + + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/error.php b/library/eden/error.php new file mode 100755 index 0000000..6cccfe4 --- /dev/null +++ b/library/eden/error.php @@ -0,0 +1,554 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * The base class for any class handling exceptions. Exceptions + * allow an application to custom handle errors that would + * normally let the system handle. This exception allows you to + * specify error levels and error types. Also using this exception + * outputs a trace (can be turned off) that shows where the problem + * started to where the program stopped. + * + * @package Eden + * @category error + * @author Christian Blanquera cblanquera@openovate.com + */ +class Eden_Error extends Exception { + /* Constants + -------------------------------*/ + const REFLECTION_ERROR = 'Error creating Reflection Class: %s, Method: %s.'; + const INVALID_ARGUMENT = 'Argument %d in %s() was expecting %s, however %s was given.'; + + //error type + const ARGUMENT = 'ARGUMENT'; //used when argument is invalidated + const LOGIC = 'LOGIC'; //used when logic is invalidated + const GENERAL = 'GENERAL'; //used when anything in general is invalidated + const CRITICAL = 'CRITICAL'; //used when anything caused application to crash + + //error level + const WARNING = 'WARNING'; + const ERROR = 'ERROR'; + const DEBUG = 'DEBUG'; //used for temporary developer output + const INFORMATION = 'INFORMATION'; //used for permanent developer notes + + const DEBUG_NOT_STRING = 'Debug was expecting a string'; + const DEBUG_NOT_PROPERTY = 'Debug: %s is not a property of %s'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_reporter = NULL; + protected $_type = NULL; + protected $_level = NULL; + protected $_offset = 1; + protected $_variables = array(); + protected $_trace = array(); + + protected static $_argumentTest = true; + + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i($message = NULL, $code = 0) { + $class = __CLASS__; + return new $class($message, $code); + } + + public function __construct($message = NULL, $code = 0) { + $this->_type = self::LOGIC; + $this->_level = self::ERROR; + + parent::__construct($message, $code); + } + + /* Public Methods + -------------------------------*/ + /** + * Adds parameters used in the message + * + * @return this + */ + public function addVariable($variable) { + $this->_variables[] = $variable; + return $this; + } + + /** + * Tests arguments for valid data types + * + * @param *int + * @param *mixed + * @param *string[,string..] + * @return this + */ + public function argument($index, $types) { + //if no test + if(!self::$_argumentTest) { + return $this; + } + + $trace = debug_backtrace(); + $trace = $trace[1]; + $types = func_get_args(); + $index = array_shift($types) - 1; + + if($index < 0) { + $index = 0; + } + + //if it's not set then it's good because the default value + //set in the method will be it. + if($index >= count($trace['args'])) { + return $this; + } + + $argument = $trace['args'][$index]; + + foreach($types as $i => $type) { + if($this->_isValid($type, $argument)) { + return $this; + } + } + + //lets formulate the method + $method = $trace['function']; + if(isset($trace['class'])) { + $method = $trace['class'].'->'.$method; + } + + $type = $this->_getType($argument); + + $this->setMessage(self::INVALID_ARGUMENT) + ->addVariable($index + 1) + ->addVariable($method) + ->addVariable(implode(' or ', $types)) + ->addVariable($type) + ->setTypeLogic() + ->setTraceOffset(1) + ->trigger(); + } + + /** + * Returns the exception level + * + * @return string + */ + public function getLevel() { + return $this->_level; + } + + /** + * Returns raw trace + * + * @return array + */ + public function getRawTrace() { + return $this->_trace; + } + + /** + * REturns the class or method that caught this + * + * @return string + */ + public function getReporter() { + return $this->_reporter; + } + + /** + * Returns the trace offset; where we should start the trace + * + * @return this + */ + public function getTraceOffset() { + return $this->_offset; + } + + /** + * Returns the exception type + * + * @return string + */ + public function getType() { + return $this->_type; + } + + /** + * Returns variables + * + * @return array + */ + public function getVariables() { + return $this->_variables; + } + + /** + * In a perfect production environment, + * we can assume that arguments passed in + * all methods are valid. To increase + * performance call this method. + * + * @return this + */ + public function noArgTest() { + self::$_argumentTest = false; + return $this; + } + + /** + * Sets exception level + * + * @param string + * @return this + */ + public function setLevel($level) { + $this->_level = $level; + return $this; + } + + /** + * Sets exception level to DEBUG + * + * @return this + */ + public function setLevelDebug() { + return $this->setLevel(self::DEBUG); + } + + /** + * Sets exception level to ERROR + * + * @return this + */ + public function setLevelError() { + return $this->setLevel(self::WARNING); + } + + /** + * Sets exception level to INFORMATION + * + * @return this + */ + public function setLevelInformation() { + return $this->setLevel(self::INFORMATION); + } + + /** + * Sets exception level to WARNING + * + * @return this + */ + public function setLevelWarning() { + return $this->setLevel(self::WARNING); + } + + /** + * Sets message + * + * @param string + * @return this + */ + public function setMessage($message) { + $this->message = $message; + return $this; + } + + /** + * Sets what index the trace should start at + * + * @return this + */ + public function setTraceOffset($offset) { + $this->_offset = $offset; + return $this; + } + + /** + * Sets exception type + * + * @param string + * @return this + */ + public function setType($type) { + $this->_type = $type; + return $this; + } + + /** + * Sets exception type to ARGUMENT + * + * @return this + */ + public function setTypeArgument() { + return $this->setType(self::ARGUMENT); + } + + /** + * Sets exception type to CRITICAL + * + * @return this + */ + public function setTypeCritical() { + return $this->setType(self::CRITICAL); + } + + /** + * Sets exception type to GENERAL + * + * @return this + */ + public function setTypeGeneral() { + return $this->setType(self::GENERAL); + } + + /** + * Sets exception type to LOGIC + * + * @return this + */ + public function setTypeLogic() { + return $this->setType(self::CRITICAL); + } + + /** + * Combines parameters with message and throws it + * + * @return void + */ + public function trigger() { + $this->_trace = debug_backtrace(); + + $this->_reporter = get_class($this); + if(isset($this->_trace[$this->_offset]['class'])) { + $this->_reporter = $this->_trace[$this->_offset]['class']; + } + + if(isset($this->_trace[$this->_offset]['file'])) { + $this->file = $this->_trace[$this->_offset]['file']; + } + + if(isset($this->_trace[$this->_offset]['line'])) { + $this->line = $this->_trace[$this->_offset]['line']; + } + + if(!empty($this->_variables)) { + $this->message = vsprintf($this->message, $this->_variables); + $this->_variables = array(); + } + + throw $this; + } + + /** + * Tests virtual arguments for valid data types + * + * @param *int + * @param *mixed + * @param *string[,string..] + * @return this + */ + public function vargument($method, $args, $index, $types) { + //if no test + if(!self::$_argumentTest) { + return $this; + } + + $trace = debug_backtrace(); + $trace = $trace[1]; + $types = func_get_args(); + $method = array_shift($types); + $args = array_shift($types); + $index = array_shift($types) - 1; + + if($index < 0) { + $index = 0; + } + + //if it's not set then it's good because the default value + //set in the method will be it. + if($index >= count($args)) { + return $this; + } + + $argument = $args[$index]; + + foreach($types as $i => $type) { + if($this->_isValid($type, $argument)) { + return $this; + } + } + + $method = $trace['class'].'->'.$method; + + $type = $this->_getType($argument); + + $this->setMessage(self::INVALID_ARGUMENT) + ->addVariable($index + 1) + ->addVariable($method) + ->addVariable(implode(' or ', $types)) + ->addVariable($type) + ->setTypeLogic() + ->setTraceOffset(1) + ->trigger(); + } + + /* Protected Methods + -------------------------------*/ + protected function _isCreditCard($value) { + return preg_match('/^(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]'. + '{14}|6(?:011|5[0-9][0-9])[0-9]{12}|3[47][0-9]{13}|3(?:0[0-'. + '5]|[68][0-9])[0-9]{11}|(?:2131|1800|35\d{3})\d{11})$/', $value); + } + + protected function _isEmail($value) { + return preg_match('/^(?:(?:(?:[^@,"\[\]\x5c\x00-\x20\x7f-\xff\.]|\x5c(?=[@,"\[\]'. + '\x5c\x00-\x20\x7f-\xff]))(?:[^@,"\[\]\x5c\x00-\x20\x7f-\xff\.]|(?<=\x5c)[@,"\[\]'. + '\x5c\x00-\x20\x7f-\xff]|\x5c(?=[@,"\[\]\x5c\x00-\x20\x7f-\xff])|\.(?=[^\.])){1,62'. + '}(?:[^@,"\[\]\x5c\x00-\x20\x7f-\xff\.]|(?<=\x5c)[@,"\[\]\x5c\x00-\x20\x7f-\xff])|'. + '[^@,"\[\]\x5c\x00-\x20\x7f-\xff\.]{1,2})|"(?:[^"]|(?<=\x5c)"){1,62}")@(?:(?!.{64})'. + '(?:[a-zA-Z0-9][a-zA-Z0-9-]{1,61}[a-zA-Z0-9]\.?|[a-zA-Z0-9]\.?)+\.(?:xn--[a-zA-Z0-9]'. + '+|[a-zA-Z]{2,6})|\[(?:[0-1]?\d?\d|2[0-4]\d|25[0-5])(?:\.(?:[0-1]?\d?\d|2[0-4]\d|25'. + '[0-5])){3}\])$/', $value); + } + + protected function _isHex($value) { + return preg_match("/^[0-9a-fA-F]{6}$/", $value); + } + + protected function _isHtml($value) { + return preg_match("/<\/?\w+((\s+(\w|\w[\w-]*\w)(\s*=\s*". + "(?:\".*?\"|'.*?'|[^'\">\s]+))?)+\s*|\s*)\/?>/i", $value); + } + + protected function _isUrl($value) { + return preg_match('/^(http|https|ftp):\/\/([A-Z0-9][A-Z0'. + '-9_-]*(?:.[A-Z0-9][A-Z0-9_-]*)+):?(d+)?\/?/i', $value); + } + + public function _alphaNum($value) { + return preg_match('/^[a-zA-Z0-9]+$/', $value); + } + + public function _alphaNumScore($value) { + return preg_match('/^[a-zA-Z0-9_]+$/', $value); + } + + public function _alphaNumHyphen($value) { + return preg_match('/^[a-zA-Z0-9-]+$/', $value); + } + + public function _alphaNumLine($value) { + return preg_match('/^[a-zA-Z0-9-_]+$/', $value); + } + + protected function _isValid($type, $data) { + $type = $this->_getTypeName($type); + + switch($type) { + case 'number': + return is_numeric($data); + case 'int': + return is_numeric($data) && strpos((string) $data, '.') === false; + case 'float': + return is_numeric($data) && strpos((string) $data, '.') !== false; + case 'file': + return is_string($data) && file_exists($data); + case 'folder': + return is_string($data) && is_dir($data); + case 'email': + return is_string($data) && $this->_isEmail($data); + case 'url': + return is_string($data) && $this->_isUrl($data); + case 'html': + return is_string($data) && $this->_isHtml($data); + case 'cc': + return (is_string($data) || is_int($data)) && $this->_isCreditCard($data); + case 'hex': + return is_string($data) && $this->_isHex($data); + case 'alphanum': + return is_string($data) && $this->_alphaNum($data); + case 'alphanumscore': + return is_string($data) && $this->_alphaNumScore($data); + case 'alphanumhyphen': + return is_string($data) && $this->_alphaNumHyphen($data); + case 'alphanumline': + return is_string($data) && $this->_alphaNumLine($data); + default: break; + } + + $method = 'is_'.$type; + if(function_exists($method)) { + return $method($data); + } + + if(class_exists($type)) { + return $data instanceof $type; + } + + return true; + } + + /* Private Methods + -------------------------------*/ + private function _getType($data) { + if(is_string($data)) { + return "'".$data."'"; + } + + if(is_numeric($data)) { + return $data; + } + + if(is_array($data)) { + return 'Array'; + } + + if(is_bool($data)) { + return $data ? 'true' : 'false'; + } + + if(is_object($data)) { + return get_class($data); + } + + if(is_null($data)) { + return 'null'; + } + + return 'unknown'; + } + + private function _getTypeName($data) { + if(is_string($data)) { + return $data; + } + + if(is_numeric($data)) { + return 'numeric'; + } + + if(is_array($data)) { + return 'array'; + } + + if(is_bool($data)) { + return 'bool'; + } + + if(is_object($data)) { + return get_class($data); + } + + if(is_null($data)) { + return 'null'; + } + } +} \ No newline at end of file diff --git a/library/eden/error/event.php b/library/eden/error/event.php new file mode 100755 index 0000000..7898a6d --- /dev/null +++ b/library/eden/error/event.php @@ -0,0 +1,185 @@ + +/* + * This file is part of the Eden package. + * (c) 2010-2012 Christian Blanquera + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * + * @package Eden + * @category error + * @author Christian Blanquera cblanquera@openovate.com + */ +class Eden_Error_Event extends Eden_Event { + /* Constants + -------------------------------*/ + //error type + const PHP = 'PHP'; //used when argument is invalidated + const UNKNOWN = 'UNKNOWN'; + + //error level + const WARNING = 'WARNING'; + const ERROR = 'ERROR'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getSingleton(__CLASS__); + } + + /* Public Methods + -------------------------------*/ + /** + * Called when a PHP error has occured. Must + * use setErrorHandler() first. + * + * @param number error number + * @param string message + * @param string file + * @param string line + * @return true + */ + public function errorHandler($errno, $errstr, $errfile, $errline) { + //depending on the error number + //we can determine the error level + switch ($errno) { + case E_NOTICE: + case E_USER_NOTICE: + case E_WARNING: + case E_USER_WARNING: + $level = self::WARNING; + break; + case E_ERROR: + case E_USER_ERROR: + default: + $level = self::ERROR; + break; + } + + //errors are only triggered through PHP + $type = self::PHP; + + //get the trace + $trace = debug_backtrace(); + + //by default we do not know the class + $class = self::UNKNOWN; + + //if there is a trace + if(count($trace) > 1) { + //formulate the class + $class = $trace[1]['function'].'()'; + if(isset($trace[1]['class'])) { + $class = $trace[1]['class'].'->'.$class; + } + } + + $this->trigger( + 'error', $type, $level, + $class, $errfile, $errline, + $errstr, $trace, 1); + + //Don't execute PHP internal error handler + return true; + } + + /** + * Called when a PHP exception has occured. Must + * use setExceptionHandler() first. + * + * @param Exception + * @return void + */ + public function exceptionHandler(Exception $e) { + //by default set LOGIC ERROR + $type = Eden_Error::LOGIC; + $level = Eden_Error::ERROR; + $offset = 1; + $reporter = get_class($e); + + $trace = $e->getTrace(); + $message = $e->getMessage(); + + //if the exception is an eden exception + if($e instanceof Eden_Error) { + //set type and level from that + $trace = $e->getRawTrace(); + + $type = $e->getType(); + $level = $e->getLevel(); + $offset = $e->getTraceOffset(); + $reporter = $e->getReporter(); + } + + $this->trigger( + 'exception', $type, $level, + $reporter, $e->getFile(), $e->getLine(), + $message, $trace, $offset); + } + + /** + * Returns default handler back to PHP + * + * @return this + */ + public function releaseErrorHandler() { + restore_error_handler(); + return $this; + } + + /** + * Returns default handler back to PHP + * + * @return this + */ + public function releaseExceptionHandler() { + restore_exception_handler(); + return $this; + } + + /** + * Registers this class' error handler to PHP + * + * @return this + */ + public function setErrorHandler() { + set_error_handler(array($this, 'errorHandler')); + return $this; + } + + /** + * Registers this class' exception handler to PHP + * + * @return this + */ + public function setExceptionHandler() { + set_exception_handler(array($this, 'exceptionHandler')); + return $this; + } + + /** + * Sets reporting + * + * @param int + * @return this + */ + public function setReporting($type) { + error_reporting($type); + return $this; + } + + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/event.php b/library/eden/event.php new file mode 100755 index 0000000..15f6ca3 --- /dev/null +++ b/library/eden/event.php @@ -0,0 +1,241 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +require_once dirname(__FILE__).'/class.php'; + +/** + * Allows the ability to listen to events made known by another + * piece of functionality. Events are items that transpire based + * on an action. With events you can add extra functionality + * right after the event has triggered. + * + * @package Eden + * @category event + * @author Christian Blanquera cblanquera@openovate.com + */ +class Eden_Event extends Eden_Class { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_observers = array(); + + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getSingleton(__CLASS__); + } + + /* Public Methods + -------------------------------*/ + /** + * Attaches an instance to be notified + * when an event has been triggered + * + * @param *string + * @param *string|object|callable + * @param string|null|bool + * @param bool + * @return this + */ + public function listen($event, $instance, $method = NULL, $important = false) { + $error = Eden_Event_Error::i() + ->argument(1, 'string') //argument 1 must be string + ->argument(2, 'object', 'string', 'callable') //argument 2 must be object, string or callable + ->argument(3, 'null', 'string', 'bool') //argument 3 must be string or null + ->argument(4, 'bool'); //argument 4 must be boolean + + //if method is bool + if(is_bool($method)) { + //this was meant to be important + $important = $method; + $method = NULL; + } + + $id = $this->_getId($instance, $method); + $callable = $this->_getCallable($instance, $method); + + //set up the observer + $observer = array($event, $id, $callable); + + //if this is important + if($important) { + //put the observer on the top of the list + array_unshift($this->_observers, $observer); + return $this; + } + + //add the observer + $this->_observers[] = $observer; + return $this; + } + + /** + * Notify all observers of that a specific + * event has happened + * + * @param string + * @param [mixed] + * @return this + */ + public function trigger($event = NULL) { + //argument 1 must be string + Eden_Event_Error::i()->argument(1, 'string', 'null'); + + if(is_null($event)) { + $trace = debug_backtrace(); + $event = $trace[1]['function']; + } + + //get the arguments + $args = func_get_args(); + //shift out the event + $event = array_shift($args); + + //as a courtesy lets shift in the object + array_unshift($args, $this, $event); + + //for each observer + foreach($this->_observers as $observer) { + //if this is the same event, call the method, if the method returns false + if($event == $observer[0] && call_user_func_array($observer[2], $args) === false) { + //break out of the loop + break; + } + } + + return $this; + } + + /** + * Stops listening to an event + * + * @param string|null + * @param object|null + * @param string|null + * @return this + */ + public function unlisten($event, $instance = NULL, $method = NULL) { + Eden_Event_Error::i() + ->argument(1, 'string', 'null') //argument 1 must be string or null + ->argument(2, 'object', 'string', 'null') //argument 2 must be instance or null + ->argument(3, 'string', 'null'); //argument 3 must be string or null + + //if there is no event and no instance + if(is_null($event) && is_null($instance)) { + //it means that they want to remove everything + $this->_observers = array(); + return $this; + } + + $id = $this->_getId($instance, $method); + + //if we could not determine the id + if($id === false) { + //do nothing + return false; + } + + //for each observer + foreach($this->_observers as $i => $observer) { + //if there is an event and is not being listened to + if(!is_null($event) && $event != $observer[0]) { + //skip it + continue; + } + + if($id == $observer[1] && is_array($observer[2]) && $method != $observer[2][1]) { + continue; + } + + if($id != $observer[1]) { + continue; + } + + //unset it + unset($this->_observers[$i]); + } + + return $this; + } + + /* Protected Methods + -------------------------------*/ + protected function _getCallable($instance, $method = NULL) { + if(class_exists('Closure') && $instance instanceof Closure) { + return $instance; + } + + if(is_object($instance)) { + return array($instance, $method); + } + + if(is_string($instance) && is_string($method)) { + return $instance.'::'.$method; + } + + if(is_string($instance)) { + return $instance; + } + + return NULL; + } + + protected function _getId($instance, $method = NULL) { + if(is_object($instance)) { + return spl_object_hash($instance); + } + + if(is_string($instance) && is_string($method)) { + return $instance.'::'.$method; + } + + if(is_string($instance)) { + return $instance; + } + + return false; + } + + /* Private Methods + -------------------------------*/ +} + +/** + * Event Errors + */ +class Eden_Event_Error extends Eden_Error { + /* Constants + -------------------------------*/ + const NO_METHOD = 'Instance %s was passed but, no callable method was passed in listen().'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i($message = NULL, $code = 0) { + $class = __CLASS__; + return new $class($message, $code); + } + + /* Public Methods + -------------------------------*/ + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/eventbrite.php b/library/eden/eventbrite.php new file mode 100644 index 0000000..9e631ee --- /dev/null +++ b/library/eden/eventbrite.php @@ -0,0 +1,218 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +require_once dirname(__FILE__).'/oauth2.php'; +require_once dirname(__FILE__).'/eventbrite/error.php'; +require_once dirname(__FILE__).'/eventbrite/base.php'; +require_once dirname(__FILE__).'/eventbrite/oauth.php'; +require_once dirname(__FILE__).'/eventbrite/discount.php'; +require_once dirname(__FILE__).'/eventbrite/event.php'; +require_once dirname(__FILE__).'/eventbrite/organizer.php'; +require_once dirname(__FILE__).'/eventbrite/payment.php'; +require_once dirname(__FILE__).'/eventbrite/ticket.php'; +require_once dirname(__FILE__).'/eventbrite/user.php'; +require_once dirname(__FILE__).'/eventbrite/venue.php'; +require_once dirname(__FILE__).'/eventbrite/event/search.php'; +require_once dirname(__FILE__).'/eventbrite/event/set.php'; + +/** + * Eventbrite API factory. This is a factory class with + * methods that will load up different Eventbrite classes. + * Eventbrite classes are organized as described on their + * developer site: discount, event, organizer, payment, + * ticket, user, venue. We also added a search class and + * set class with advanced options for searching and + * creating events. + * + * @package Eden + * @category tool + * @author Christian Blanquera cblanquera@openovate.com + */ +class Eden_Eventbrite extends Eden_Class { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getSingleton(__CLASS__); + } + + /* Public Methods + -------------------------------*/ + /** + * Returns Eventbrite Oauth + * + * @param string client ID + * @param string app secret + * @return Eden_Eventbrite_Discount + */ + public function auth($clientId, $appSecret, $redirect) { + Eden_Eventbrite_Error::i() + ->argument(1, 'string', 'int') + ->argument(2, 'string') + ->argument(3, 'string'); + + return Eden_Eventbrite_Oauth::i((string) $clientId, $appSecret, $redirect); + } + + /** + * Returns Eventbrite Discount + * + * @param string + * @param string|null + * @return Eden_Eventbrite_Discount + */ + public function discount($user, $api = NULL) { + //argument test + Eden_Eventbrite_Error::i() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'string', 'null'); //Argument 2 must be a string or null + + return Eden_Eventbrite_Discount::i($user, $api); + } + + /** + * Returns Eventbrite Event + * + * @param string + * @param string|null + * @return Eden_Eventbrite_Event + */ + public function event($user, $api = NULL) { + //argument test + Eden_Eventbrite_Error::i() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'string', 'null'); //Argument 2 must be a string or null + + return Eden_Eventbrite_Event::i($user, $api); + } + + /** + * Returns Eventbrite Organizer + * + * @param string + * @param string|null + * @return Eden_Eventbrite_Organizer + */ + public function organizer($user, $api = NULL) { + //argument test + Eden_Eventbrite_Error::i() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'string', 'null'); //Argument 2 must be a string or null + + return Eden_Eventbrite_Organizer::i($user, $api); + } + + /** + * Returns Eventbrite Payment + * + * @param string + * @param string|null + * @return Eden_Eventbrite_Payment + */ + public function payment($user, $api = NULL) { + //argument test + Eden_Eventbrite_Error::i() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'string', 'null'); //Argument 2 must be a string or null + + return Eden_Eventbrite_Payment::i($user, $api); + } + + /** + * Returns Eventbrite Search + * + * @param string + * @param string|null + * @return Eden_Eventbrite_Venue + */ + public function search($user, $api = NULL) { + //argument test + Eden_Eventbrite_Error::i() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'string', 'null'); //Argument 2 must be a string or null + + return Eden_Eventbrite_Event_Search::i($user, $api); + } + + /** + * Returns Eventbrite Set + * + * @param string + * @param string|null + * @return Eden_Eventbrite_Venue + */ + public function set($user, $api = NULL) { + //argument test + Eden_Eventbrite_Error::i() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'string', 'null'); //Argument 2 must be a string or null + + return Eden_Eventbrite_Event_Set::i($user, $api); + } + + /** + * Returns Eventbrite Ticket + * + * @param string + * @param string|null + * @return Eden_Eventbrite_Ticket + */ + public function ticket($user, $api = NULL) { + //argument test + Eden_Eventbrite_Error::i() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'string', 'null'); //Argument 2 must be a string or null + + return Eden_Eventbrite_Ticket::i($user, $api); + } + + /** + * Returns Eventbrite User + * + * @param string + * @param string|null + * @return Eden_Eventbrite_User + */ + public function user($user, $api = NULL) { + //argument test + Eden_Eventbrite_Error::i() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'string', 'null'); //Argument 2 must be a string or null + + return Eden_Eventbrite_User::i($user, $api); + } + + /** + * Returns Eventbrite Venue + * + * @param string + * @param string|null + * @return Eden_Eventbrite_Venue + */ + public function venue($user, $api = NULL) { + //argument test + Eden_Eventbrite_Error::i() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'string', 'null'); //Argument 2 must be a string or null + + return Eden_Eventbrite_Venue::i($user, $api); + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/eventbrite/base.php b/library/eden/eventbrite/base.php new file mode 100644 index 0000000..57f88d3 --- /dev/null +++ b/library/eden/eventbrite/base.php @@ -0,0 +1,122 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Eventbrite Base + * + * @package Eden + * @category eventbrite + * @author Christian Blanquera cblanquera@openovate.com + */ +class Eden_Eventbrite_Base extends Eden_Class { + /* Constants + -------------------------------*/ + const ACCESS_HEADER = 'Authorization: Bearer %s'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_user = NULL; + protected $_api = NULL; + protected $_meta = array(); + + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public function __construct($user, $api = NULL) { + //argument test + Eden_Eventbrite_Error::i() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'string', 'null'); //Argument 2 must be a string or null + + $this->_api = $api; + $this->_user = $user; + } + + /* Public Methods + -------------------------------*/ + /** + * Returns the meta of the last call + * + * @return array + */ + public function getMeta($key = NULL) { + Eden_Eventbrite_Error::i()->argument(1, 'string', 'null'); + + if(isset($this->_meta[$key])) { + return $this->_meta[$key]; + } + + return $this->_meta; + } + + /* Protected Methods + -------------------------------*/ + protected function _getJsonResponse($url, array $query = array()) { + $response = $this->_getResponse($url, $query); + return json_decode($response, true); + } + + protected function _getResponse($url, array $query = array()) { + $headers = array(); + $headers[] = 'Content-Type: application/json'; + + //if api key is null + if(is_null($this->_api)) { + //we must have an oauth token + $headers[] = sprintf(self::ACCESS_HEADER, $this->_user); + } else { + $query['app_key'] = $this->_api; + $query['user_key'] = $this->_user; + } + + $query = http_build_query($query); + + //determine the conector + $connector = NULL; + + //if there is no question mark + if(strpos($url, '?') === false) { + $connector = '?'; + //if the redirect doesn't end with a question mark + } else if(substr($url, -1) != '?') { + $connector = '&'; + } + + //now add the authorization to the url + $url .= $connector.$query; + + //set curl + $curl = Eden_Curl::i() + ->verifyHost(false) + ->verifyPeer(false) + ->setUrl($url) + ->setHeaders($headers); + + //get the response + $response = $curl->getResponse(); + + $this->_meta = $curl->getMeta(); + $this->_meta['url'] = $url; + $this->_meta['headers'] = $headers; + $this->_meta['query'] = $query; + + return $response; + } + + protected function _getXmlResponse($url, array $query = array()) { + $response = $this->_getResponse($url, $query); + return simplexml_load_string($response); + } + + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/eventbrite/discount.php b/library/eden/eventbrite/discount.php new file mode 100644 index 0000000..2fd3238 --- /dev/null +++ b/library/eden/eventbrite/discount.php @@ -0,0 +1,194 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Eventbrite new or update discount + * + * @package Eden + * @category eventbrite + * @author Christian Blanquera cblanquera@openovate.com + */ +class Eden_Eventbrite_Discount extends Eden_Eventbrite_Base { + /* Constants + -------------------------------*/ + const URL_NEW = 'https://www.eventbrite.com/json/discount_new'; + const URL_UPDATE = 'https://www.eventbrite.com/json/discount_update'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_query = array(); + + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + /* Public Methods + -------------------------------*/ + /** + * Creates the discount + * + * @param int the event id + * @return array + */ + public function create($event) { + //Argument 1 must be int + Eden_Eventbrite_Error::i()->argument(1, 'int'); + + $query = $this->_query; + $query['event_id'] = $event; + return $this->_getJsonResponse(self::URL_NEW, $query); + } + + /** + * Sets the discount amount + * + * @param float|int + * @return this + */ + public function setAmountOff($amount) { + //Argument 1 must be int + Eden_Eventbrite_Error::i()->argument(1, 'float', 'int'); + + $this->_query['amount_off'] = $amount; + + return $this; + } + + /** + * Sets the discount code + * + * @param string + * @return this + */ + public function setCode($code) { + //Argument 1 must be int + Eden_Eventbrite_Error::i()->argument(1, 'string'); + + $this->_query['code'] = $code; + + return $this; + } + + /** + * Set the end time + * + * @param string|int + * @return this + */ + public function setEnd($end) { + //Argument 1 must be a string + Eden_Eventbrite_Error::i()->argument(1, 'string', 'int'); + + if(is_string($end)) { + $end = strtotime($end); + } + + $end = date('Y-m-d H:i:s', $end); + + $this->_query['end_date'] = $end; + + return $this; + } + + /** + * Sets the discount percent + * + * @param float|int + * @return this + */ + public function setPercentOff($percent) { + //Argument 1 must be int + Eden_Eventbrite_Error::i()->argument(1, 'int', 'float'); + + $this->_query['percent_off'] = $percent; + + return $this; + } + + /** + * Set quantity + * + * @param int + * @return this + */ + public function setQuantity($quantity) { + //Argument 1 must be int + Eden_Eventbrite_Error::i()->argument(1, 'int'); + + $this->_query['quantity_available'] = $quantity; + + return $this; + } + + /** + * Set the start time + * + * @param int|string + * @return this + */ + public function setStart($start) { + //Argument 1 must be a string + Eden_Eventbrite_Error::i()->argument(1, 'string', 'int'); + + if(is_string($start)) { + $start = strtotime($start); + } + + $start = date('Y-m-d H:i:s', $start); + + $this->_query['start_date'] = $start; + + return $this; + } + + /** + * Set ticket ID or a list of ticket IDs + * + * @param string|array + * @return this + */ + public function setTickets($tickets) { + //Argument 1 must be int + Eden_Eventbrite_Error::i()->argument(1, 'string', 'array'); + + if(is_array($tickets)) { + $tickets = implode(',', $tickets); + } + + $this->_query['tickets'] = $tickets; + + return $this; + } + + /** + * Creates the discount + * + * @param int the discount id + * @return array + */ + public function update($id) { + //Argument 1 must be int + Eden_Eventbrite_Error::i()->argument(1, 'int'); + + $query = $this->_query; + $query['id'] = $id; + return $this->_getJsonResponse(self::URL_UPDATE, $query); + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/eventbrite/error.php b/library/eden/eventbrite/error.php new file mode 100644 index 0000000..ac4ffb4 --- /dev/null +++ b/library/eden/eventbrite/error.php @@ -0,0 +1,60 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Eventbrite Errors + * + * @package Eden + * @category eventbrite + * @author Christian Blanquera cblanquera@openovate.com + */ +class Eden_Eventbrite_Error extends Eden_Error { + /* Constants + -------------------------------*/ + const TITLE_NOT_SET = 'You tried to set an event without setting a title. Call setTitle() before send()'; + const START_NOT_SET = 'You tried to set an event without setting a start date. Call setStart() before send()'; + const END_NOT_SET = 'You tried to set an event without setting an end date. Call setEnd() before send()'; + const ZONE_NOT_SET = 'You tried to set an event without setting a timezone. Call setTimezone() before send()'; + + const PRIVACY_NOT_SET = 'You tried to set an event without setting the privacy. Call setPublic() or setPrivate() before send()'; + const URL_NOT_SET = 'You tried to set an event without setting a personal url. Call setUrl() before send()'; + const ORGANIZER_NOT_SET = 'You tried to set an event without setting an orgaizer. Call setOrganizer() before send()'; + const VENUE_NOT_SET = 'You tried to set an event without setting a venue. Call setVenue() before send()'; + const CAPACITY_NOT_SET = 'You tried to set an event without setting the capacity. Call setCapacity() before send()'; + const CURRENCY_NOT_SET = 'You tried to set an event without setting a currency. Call setCurrency() before send()'; + const INVALID_PASSWORD = 'Password must be 4 characters or greater!'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i($message = NULL, $code = 0) { + $class = __CLASS__; + return new $class($message, $code); + } + + /* Public Methods + -------------------------------*/ + /* Protected Methods + -------------------------------*/ + protected function _isValid($type, $data) { + if($type == 'gmt') { + return preg_match('/^GMT(\-|\+)[0-9]{2,4}$/', $data); + } + + return parent::_isValid($type, $data); + } + + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/eventbrite/event.php b/library/eden/eventbrite/event.php new file mode 100644 index 0000000..262eebb --- /dev/null +++ b/library/eden/eventbrite/event.php @@ -0,0 +1,143 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Eventbrite event + * + * @package Eden + * @category eventbrite + * @author Christian Blanquera cblanquera@openovate.com + */ +class Eden_Eventbrite_Event extends Eden_Eventbrite_Base { + /* Constants + -------------------------------*/ + const URL_COPY = 'https://www.eventbrite.com/json/event_copy'; + const URL_GET = 'https://www.eventbrite.com/json/event_get'; + const URL_LIST_ATTENDEES = 'https://www.eventbrite.com/json/event_list_attendees'; + const URL_LIST_DISCOUNTS = 'https://www.eventbrite.com/json/event_list_discounts'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected static $_validDisplays = array('profile','answers','address'); + + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + /* Public Methods + -------------------------------*/ + /** + * Copies the event to a new one + * + * @param number + * @param string + * @return array + */ + public function copy($id, $name) { + //argument test + Eden_Eventbrite_Error::i() + ->argument(1, 'numeric') //Argument 1 must be numeric + ->argument(2, 'string'); //Argument 2 must be a string + + $query = array('id' => $id, 'name' => $name); + + return $this->_getJsonResponse(self::URL_COPY, $query); + } + + /** + * Returns event attendees + * + * @param number + * @param number + * @param number + * @param string|null + * @param bool + * @return array + */ + public function getAttendees($id, $count = 50, $page = 1, $display = NULL, $barcodes = false) { + //argument test + $error = Eden_Eventbrite_Error::i() + ->argument(1, 'numeric') //Argument 1 must be numeric + ->argument(2, 'numeric') //Argument 2 must be numeric + ->argument(3, 'numeric') //Argument 3 must be numeric + ->argument(4, 'string', 'null') //Argument 4 must be a string + ->argument(5, 'bool'); //Argument 4 must be a boolean + + $query = array('id' => $id, 'count' => $count, 'page' => $page); + + if(!is_null($display) && in_array($display, $this->_validDisplays)) { + $query['do_not_display'] = $display; + } + + if($barcodes) { + $query['show_full_barcodes'] = $barcodes; + } + + return $this->_getJsonResponse(self::URL_LIST_ATTENDEES, $query); + } + + /** + * Returns the event details + * + * @param number + * @return array + */ + public function getDetail($id) { + //Argument 1 must be numeric + Eden_Eventbrite_Error::i()->argument(1, 'numeric'); + + $query = array('id' => $id); + + return $this->_getJsonResponse(self::URL_GET, $query); + } + + /** + * Returns any event discounts + * + * @param number + * @return array + */ + public function getDiscounts($id) { + //Argument 1 must be numeric + Eden_Eventbrite_Error::i()->argument(1, 'numeric'); + + $query = array('id' => $id); + + return $this->_getJsonResponse(self::URL_LIST_DISCOUNTS, $query); + } + + /** + * Returns the search class + * + * @return Eden_Eventbrite_Event_Set + */ + public function search() { + return Eden_Eventbrite_Event_Search::i($this->_user, $this->_api); + } + + /** + * Returns the set class + * + * @return Eden_Eventbrite_Event_Set + */ + public function set() { + return Eden_Eventbrite_Event_Set::i($this->_user, $this->_api); + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/eventbrite/event/search.php b/library/eden/eventbrite/event/search.php new file mode 100644 index 0000000..243e905 --- /dev/null +++ b/library/eden/eventbrite/event/search.php @@ -0,0 +1,432 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Eventbrite search + * + * @package Eden + * @category eventbrite + * @author Christian Blanquera cblanquera@openovate.com + */ +class Eden_Eventbrite_Event_Search extends Eden_Eventbrite_Base { + /* Constants + -------------------------------*/ + const URL = 'https://www.eventbrite.com/json/event_search'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_query = array(); + + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + /* Public Methods + -------------------------------*/ + /** + * Only return the number of results found + * + * @param string + * @return this + */ + public function countOnly() { + $query['count_only'] = 'true'; + + return $this; + } + + /** + * Retrieves response + * + * @return array + */ + public function send() { + return $this->_getJsonResponse(self::URL, $this->_query); + } + + /** + * Filters by address + * + * @param string + * @return this + */ + public function setAddress($address) { + //Argument 1 must be a string + Eden_Eventbrite_Error::i()->argument(1, 'string'); + + $query['address'] = $address; + + return $this; + } + + /** + * Filters by categories + * + * @param string|array + * @return this + */ + public function setCategory($category) { + //Argument 1 must be a string or array + Eden_Eventbrite_Error::i()->argument(1, 'string', 'array'); + + if(is_array($tickets)) { + $tickets = implode(',', $tickets); + } + + $query['category'] = $category; + + return $this; + } + + /** + * Filters by country + * + * @param string + * @return this + */ + public function setCountry($country) { + //Argument 1 must be a string + Eden_Eventbrite_Error::i()->argument(1, 'string'); + + $query['country'] = $country; + + return $this; + } + + /** + * Filters by city + * + * @param string + * @return this + */ + public function setCity($city) { + //Argument 1 must be a string + Eden_Eventbrite_Error::i()->argument(1, 'string'); + + $query['city'] = $city; + + return $this; + } + + /** + * Filters by event date. Limit the list of results to a + * date range, specified by a label or by exact dates. + * Currently supported labels include: All, Future, + * Past, Today, Yesterday, Last Week, This Week, + * Next week, This Month, Next Month and months by + * name like October. Exact date ranges take the + * form 2008-04-25 2008-04-27. + * + * @param string + * @return this + */ + public function setDate($date) { + //Argument 1 must be a string + Eden_Eventbrite_Error::i()->argument(1, 'string'); + + $query['date'] = $date; + + return $this; + } + + /** + * Filters by when the event was created. Limit the + * list of results to a date range, specified by a + * label or by exact dates. Currently supported + * labels include: All, Future, Past, Today, + * Yesterday, Last Week, This Week, Next week, + * This Month, Next Month and months by name like + * October. Exact date ranges take the form + * 2008-04-25 2008-04-27. + * + * @param string + * @return this + */ + public function setDateCreated($date) { + //Argument 1 must be a string + Eden_Eventbrite_Error::i()->argument(1, 'string'); + + $query['date_created'] = $date; + + return $this; + } + + /** + * Filters by when the event was modified. Limit the + * list of results to a date range, specified by a + * label or by exact dates. Currently supported + * labels include: All, Future, Past, Today, + * Yesterday, Last Week, This Week, Next week, + * This Month, Next Month and months by name like + * October. Exact date ranges take the form + * 2008-04-25 2008-04-27. + * + * @param string + * @return this + */ + public function setDateModified($date) { + //Argument 1 must be a string + Eden_Eventbrite_Error::i()->argument(1, 'string'); + + $query['date_modified'] = $date; + + return $this; + } + + /** + * Filters by keywords + * + * @param string + * @return this + */ + public function setKeywords($keywords) { + //Argument 1 must be a string + Eden_Eventbrite_Error::i()->argument(1, 'string'); + + $query['keywords'] = $keywords; + + return $this; + } + + /** + * Filters by latitude + * + * @param float + * @return this + */ + public function setLatitude($latitude) { + //Argument 1 must be a float + Eden_Eventbrite_Error::i()->argument(1, 'float'); + + $query['latitude'] = $latitude; + + return $this; + } + + /** + * Filters by longitude + * + * @param float + * @return this + */ + public function setLongitude($longitude) { + //Argument 1 must be a float + Eden_Eventbrite_Error::i()->argument(1, 'float'); + + $query['longitude'] = $longitude; + + return $this; + } + + /** + * Set number of results + * + * @param int + * @return this + */ + public function setMax($max) { + //Argument 1 must be a int + Eden_Eventbrite_Error::i()->argument(1, 'int'); + + if($max > 100) { + $max = 100; + } + + $query['max'] = $max; + + return $this; + } + + /** + * Filters by organizer + * + * @param string + * @return this + */ + public function setOrganizer($organizer) { + //Argument 1 must be a string + Eden_Eventbrite_Error::i()->argument(1, 'string'); + + $query['organizer'] = $organizer; + + return $this; + } + + /** + * Filters by postal/zip code + * + * @param string|int + * @return this + */ + public function setPostal($postal) { + //Argument 1 must be a string or integer + Eden_Eventbrite_Error::i()->argument(1, 'string', 'int'); + + $query['postal_code'] = $postal; + + return $this; + } + + /** + * Filters by region + * + * @param string + * @return this + */ + public function setRegion($region) { + //Argument 1 must be a string + Eden_Eventbrite_Error::i()->argument(1, 'string'); + + $query['region'] = $region; + + return $this; + } + + /** + * Filters within a specified area + * + * @param int + * @return this + */ + public function setWithin($within) { + //Argument 1 must be a int + Eden_Eventbrite_Error::i()->argument(1, 'int'); + + $query['within'] = $within; + + return $this; + } + + /** + * Filters within an area unit + * + * @param string + * @return this + */ + public function setWithinUnit($unit) { + //Argument 1 must be a string + Eden_Eventbrite_Error::i()->argument(1, 'string'); + + $query['within_unit'] = $unit; + + return $this; + } + + /** + * Sort by city + * + * @return this + */ + public function sortByCity() { + //Argument 1 must be a string + Eden_Eventbrite_Error::i()->argument(1, 'string'); + + $query['sort_by'] = 'city'; + + return $this; + } + + /** + * Sort by event date + * + * @return this + */ + public function sortByDate() { + //Argument 1 must be a string + Eden_Eventbrite_Error::i()->argument(1, 'string'); + + $query['sort_by'] = 'date'; + + return $this; + } + + /** + * Sort by event id + * + * @return this + */ + public function sortById() { + //Argument 1 must be a string + Eden_Eventbrite_Error::i()->argument(1, 'string'); + + $query['sort_by'] = 'id'; + + return $this; + } + + /** + * Sort by event name + * + * @return this + */ + public function sortByName() { + //Argument 1 must be a string + Eden_Eventbrite_Error::i()->argument(1, 'string'); + + $query['sort_by'] = 'name'; + + return $this; + } + + /** + * Set pagination + * + * @param int + * @return this + */ + public function setPage($page) { + //Argument 1 must be a int + Eden_Eventbrite_Error::i()->argument(1, 'int'); + + $query['page'] = $page; + + return $this; + } + + /** + * Filter by event ids greater than specified + * + * @param int + * @return this + */ + public function setSince($since) { + //Argument 1 must be a int + Eden_Eventbrite_Error::i()->argument(1, 'int'); + + $query['since_id'] = $since; + + return $this; + } + + /** + * Sets a tranking link + * + * @param string + * @return this + */ + public function setTracking($tracking) { + //Argument 1 must be a string + Eden_Eventbrite_Error::i()->argument(1, 'string'); + + $query['tracking_link'] = $tracking; + + return $this; + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/eventbrite/event/set.php b/library/eden/eventbrite/event/set.php new file mode 100644 index 0000000..787e0c8 --- /dev/null +++ b/library/eden/eventbrite/event/set.php @@ -0,0 +1,489 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Eventbrite new or update event + * + * @package Eden + * @category eventbrite + * @author Christian Blanquera cblanquera@openovate.com + */ +class Eden_Eventbrite_Event_Set extends Eden_Eventbrite_Base { + /* Constants + -------------------------------*/ + const URL_NEW = 'https://www.eventbrite.com/json/event_new'; + const URL_UPDATE = 'https://www.eventbrite.com/json/event_update'; + + const DRAFT = 'draft'; + const LIVE = 'live'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_query = array(); + + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + /* Public Methods + -------------------------------*/ + /** + * Set event to private + * + * @return this + */ + public function isPrivate() { + $this->_query['privacy'] = 0; + + return $this; + } + + /** + * Set the event to public + * + * @return this + */ + public function isPublic() { + $this->_query['privacy'] = 1; + + return $this; + } + + /** + * Sends event off to be created or updated + * + * @return this + */ + public function send() { + if(!isset($this->_query['title'])) { + Eden_Eventbrite_Error::i()->setMessage(Eden_Eventbrite_Error::TITLE_NOT_SET)->trigger(); + } + + if(!isset($this->_query['start_date'])) { + Eden_Eventbrite_Error::i()->setMessage(Eden_Eventbrite_Error::START_NOT_SET)->trigger(); + } + + + if(!isset($this->_query['end_date'])) { + Eden_Eventbrite_Error::i()->setMessage(Eden_Eventbrite_Error::END_NOT_SET)->trigger(); + } + + if(!isset($this->_query['timezone'])) { + Eden_Eventbrite_Error::i()->setMessage(Eden_Eventbrite_Error::ZONE_NOT_SET)->trigger(); + } + + $url = self::URL_NEW; + + if(isset($this->_query['event_id'])) { + $url = self::URL_UPDATE; + + if(!isset($this->_query['privacy'])) { + Eden_Eventbrite_Error::i()->setMessage(Eden_Eventbrite_Error::PRIVACY_NOT_SET)->trigger(); + } + + if(!isset($this->_query['personalized_url'])) { + Eden_Eventbrite_Error::i()->setMessage(Eden_Eventbrite_Error::URL_NOT_SET)->trigger(); + } + + if(!isset($this->_query['organizer_id'])) { + Eden_Eventbrite_Error::i()->setMessage(Eden_Eventbrite_Error::ORGANIZER_NOT_SET)->trigger(); + } + + if(!isset($this->_query['venue_id'])) { + Eden_Eventbrite_Error::i()->setMessage(Eden_Eventbrite_Error::VENUE_NOT_SET)->trigger(); + } + + if(!isset($this->_query['capacity'])) { + Eden_Eventbrite_Error::i()->setMessage(Eden_Eventbrite_Error::CAPACITY_NOT_SET)->trigger(); + } + + if(!isset($this->_query['currency'])) { + Eden_Eventbrite_Error::i()->setMessage(Eden_Eventbrite_Error::CURRENCY_NOT_SET)->trigger(); + } + } + + return $this->_getJsonResponse($url, $this->_query); + } + + /** + * Set the background color + * + * @param string + * @return this + */ + public function setBackground($color) { + //Argument 1 must be a string + Eden_Eventbrite_Error::i()->argument(1, 'hex'); + + $this->_query['background_color'] = $color; + + return $this; + } + + /** + * Sets the border color + * + * @param string + * @return this + */ + public function setBorderColor($color) { + //Argument 1 must be a string + Eden_Eventbrite_Error::i()->argument(1, 'hex'); + + $this->_query['box_border_color'] = $color; + + return $this; + } + + /** + * Set the box background color + * + * @param string + * @return this + */ + public function setBoxBackground($color) { + //Argument 1 must be a string + Eden_Eventbrite_Error::i()->argument(1, 'hex'); + + $this->_query['box_background_color'] = $color; + + return $this; + } + + /** + * Sets the box color + * + * @param string + * @return this + */ + public function setBoxColor($color) { + //Argument 1 must be a string + Eden_Eventbrite_Error::i()->argument(1, 'hex'); + + $this->_query['box_text_color'] = $color; + + return $this; + } + + /** + * Set the event capacity + * + * @param int + * @return this + */ + public function setCapacity($capacity) { + //Argument 1 must be a int + Eden_Eventbrite_Error::i()->argument(1, 'int'); + + $this->_query['capacity'] = $capacity; + + return $this; + } + + /** + * Sets currency + * + * @param string + * @return this + */ + public function setCurrency($currency) { + //Argument 1 must be a string + Eden_Eventbrite_Error::i()->argument(1, 'string'); + + $this->_query['currency'] = $currency; + + return $this; + } + + /** + * Set the description + * + * @param string + * @return this + */ + public function setDescription($description) { + //Argument 1 must be a string + Eden_Eventbrite_Error::i()->argument(1, 'string'); + + $this->_query['description'] = $description; + + return $this; + } + + /** + * Sets status to draft + * + * @return this + */ + public function setDraft() { + $this->_query['status'] = self::DRAFT; + + return $this; + } + + /** + * Set the end time + * + * @param string|int + * @return this + */ + public function setEnd($end) { + //Argument 1 must be a string + Eden_Eventbrite_Error::i()->argument(1, 'string', 'int'); + + if(is_string($end)) { + $end = strtotime($end); + } + + $end = date('Y-m-d H:i:s', $end); + + $this->_query['end_date'] = $end; + + return $this; + } + + /** + * Set the footer HTML + * + * @param string + * @return this + */ + public function setFooter($html) { + //Argument 1 must be a string + Eden_Eventbrite_Error::i()->argument(1, 'string'); + + $this->_query['custom_footer'] = $html; + + return $this; + } + + /** + * Set the header HTML + * + * @param string + * @return this + */ + public function setHeader($html) { + //Argument 1 must be a string + Eden_Eventbrite_Error::i()->argument(1, 'string'); + + $this->_query['custom_header'] = $html; + + return $this; + } + + /** + * Sets the header background color + * + * @param string + * @return this + */ + public function setHeaderBackground($color) { + //Argument 1 must be a string + Eden_Eventbrite_Error::i()->argument(1, 'hex'); + + $this->_query['box_header_background_color'] = $color; + + return $this; + } + + /** + * Sets color to Hexdecimal + * + * @param string + * @return this + */ + public function setHeaderColor($color) { + //Argument 1 must be a string + Eden_Eventbrite_Error::i()->argument(1, 'hex'); + + $this->_query['box_header_text_color'] = $color; + + return $this; + } + + /** + * Set the event ID. Set this if you want to + * perform an update instead of an insert + * + * @param int + * @return this + */ + public function setId($id) { + //Argument 1 must be int + Eden_Eventbrite_Error::i()->argument(1, 'int'); + + $this->_query['event_id'] = $id; + + return $this; + } + + /** + * Set the link color + * + * @param string + * @return this + */ + public function setLinkColor($color) { + //Argument 1 must be a string + Eden_Eventbrite_Error::i()->argument(1, 'hex'); + + $this->_query['link_color'] = $color; + + return $this; + } + + /** + * Sets status to live + * + * @return this + */ + public function setLive() { + $this->_query['status'] = self::LIVE; + + return $this; + } + + /** + * Set the organizer ID + * + * @param int + * @return this + */ + public function setOrganizer($organizer) { + //Argument 1 must be a numeric + Eden_Eventbrite_Error::i()->argument(1, 'int'); + + $this->_query['organizer_id'] = $organizer; + + return $this; + } + + /** + * Set the start time + * + * @param int|string + * @return this + */ + public function setStart($start) { + //Argument 1 must be a string + Eden_Eventbrite_Error::i()->argument(1, 'string', 'int'); + + if(is_string($start)) { + $start = strtotime($start); + } + + $start = date('Y-m-d H:i:s', $start); + + $this->_query['start_date'] = $start; + + return $this; + } + + /** + * Set the text color + * + * @param string + * @return this + */ + public function setTextColor($color) { + //Argument 1 must be a string + Eden_Eventbrite_Error::i()->argument(1, 'hex'); + + $this->_query['text_color'] = $color; + + return $this; + } + + /** + * Set the timezone in GMT format ie. GMT+01 + * + * @param string + * @return this + */ + public function setTimezone($zone) { + //Argument 1 must be a string + Eden_Eventbrite_Error::i()->argument(1, 'gmt'); + + $this->_query['timezone'] = $zone; + + return $this; + } + + /** + * Set the title + * + * @param string + * @return this + */ + public function setTitle($title) { + //Argument 1 must be a string + Eden_Eventbrite_Error::i()->argument(1, 'string'); + + $this->_query['title'] = $title; + + return $this; + } + + /** + * Set the title color + * + * @param string + * @return this + */ + public function setTitleColor($color) { + //Argument 1 must be a string + Eden_Eventbrite_Error::i()->argument(1, 'hex'); + + $this->_query['title_text_color'] = $color; + + return $this; + } + + /** + * Set event URL + * + * @param string + * @return this + */ + public function setUrl($url) { + //Argument 1 must be a string + Eden_Eventbrite_Error::i()->argument(1, 'url'); + + $this->_query['personalized_url'] = $url; + + return $this; + } + + /** + * + * + * @param int + * @return this + */ + public function setVenue($venue) { + //Argument 1 must be a numeric + Eden_Eventbrite_Error::i()->argument(1, 'numeric'); + + $this->_query['venue_id'] = $venue; + + return $this; + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/eventbrite/oauth.php b/library/eden/eventbrite/oauth.php new file mode 100644 index 0000000..99c31d5 --- /dev/null +++ b/library/eden/eventbrite/oauth.php @@ -0,0 +1,53 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Eventbrite oauth + * + * @package Eden + * @category eventbrite + * @author Christian Blanquera cblanquera@openovate.com + */ +class Eden_Eventbrite_Oauth extends Eden_Oauth2_Client { + /* Constants + -------------------------------*/ + const REQUEST_URL = 'https://www.eventbrite.com/oauth/authorize'; + const ACCESS_URL = 'https://www.eventbrite.com/oauth/token'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + public function __construct($clientId, $appSecret, $redirect) { + //argument test + Eden_Eventbrite_Error::i() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'string') //Argument 2 must be a string + ->argument(3, 'string'); //Argument 3 must be a string + + parent::__construct($clientId, $appSecret, $redirect, self::REQUEST_URL, self::ACCESS_URL); + } + + /* Public Methods + -------------------------------*/ + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/eventbrite/organizer.php b/library/eden/eventbrite/organizer.php new file mode 100644 index 0000000..0fa0317 --- /dev/null +++ b/library/eden/eventbrite/organizer.php @@ -0,0 +1,100 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Eventbrite Organizer + * + * @package Eden + * @category eventbrite + * @author Christian Blanquera cblanquera@openovate.com + */ +class Eden_Eventbrite_Organizer extends Eden_Eventbrite_Base { + /* Constants + -------------------------------*/ + const URL_NEW = 'https://www.eventbrite.com/json/organizer_new'; + const URL_UPDATE = 'https://www.eventbrite.com/json/organizer_update'; + const URL_EVENTS = 'https://www.eventbrite.com/json/organizer_list_events'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + /* Public Methods + -------------------------------*/ + /** + * Creates an organizer + * + * @param string + * @param string|null + * @return array + */ + public function create($name, $description = NULL) { + //Argument Test + Eden_Eventbrite_Error::i() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'string', 'null'); //Argument 2 must be a string + + $query = array( + 'name' => $name, + 'description' => $description); + + return $this->_getJsonResponse(self::URL_NEW, $query); + } + + /** + * Returns all active organizer events + * + * @param int + * @return array + */ + public function getEvents($id) { + //Argument 1 must be an int + Eden_Eventbrite_Error::i()->argument(1, 'int'); + + $query = array('id' => $id); + + return $this->_getJsonResponse(self::URL_EVENTS, $query); + } + + /** + * Updates an organizer + * + * @param int + * @param string + * @param string|null + * @return array + */ + public function update($id, $name, $description = NULL) { + //Argument Test + Eden_Eventbrite_Error::i() + ->argument(1, 'int') //Argument 1 must be an integer + ->argument(2, 'string') //Argument 2 must be a string + ->argument(3, 'string', 'null'); //Argument 3 must be a string + + $query = array( + 'id' => $id, + 'name' => $name, + 'description' => $description); + + return $this->_getJsonResponse(self::URL_UPDATE, $query); + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/eventbrite/payment.php b/library/eden/eventbrite/payment.php new file mode 100644 index 0000000..eff88f5 --- /dev/null +++ b/library/eden/eventbrite/payment.php @@ -0,0 +1,211 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Eventbrite payment + * + * @package Eden + * @category eventbrite + * @author Christian Blanquera cblanquera@openovate.com + */ +class Eden_Eventbrite_Payment extends Eden_Eventbrite_Base { + /* Constants + -------------------------------*/ + const URL = 'https://www.eventbrite.com/json/payment_update'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_query = array(); + + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + /* Public Methods + -------------------------------*/ + /** + * Accept cash + * + * @return this + */ + public function acceptCash() { + $this->_query['accept_check'] = 1; + + return $this; + } + + /** + * Accept check + * + * @return this + */ + public function acceptCheck() { + $this->_query['accept_check'] = 1; + + return $this; + } + + /** + * Accept Google Checkout + * + * @return this + */ + public function acceptGoogle() { + $this->_query['accept_google'] = 1; + + return $this; + } + + /** + * Accept invoice + * + * @return this + */ + public function acceptInovice() { + $this->_query['accept_invoice'] = 1; + + return $this; + } + + /** + * Accept PayPal + * + * @return this + */ + public function acceptPaypal() { + $this->_query['accept_paypal'] = 1; + + return $this; + } + + /** + * Set cash instructions + * + * @param string + * @return this + */ + public function setCashInstructions($instructions) { + //Argument 1 must be a string + Eden_Eventbrite_Error::i()->argument(1, 'string'); + + $this->_query['insrtructions_cash'] = $instructions; + + return $this; + } + + /** + * Set check instructions + * + * @param string + * @return this + */ + public function setCheckInstructions($instructions) { + //Argument 1 must be a string + Eden_Eventbrite_Error::i()->argument(1, 'string'); + + $this->_query['insrtructions_check'] = $instructions; + + return $this; + } + + /** + * Set event ID + * + * @param int + * @return this + */ + public function setEvent($id) { + //Argument 1 must be int + Eden_Eventbrite_Error::i()->argument(1, 'int'); + + $this->_query['event_id'] = $id; + + return $this; + } + + /** + * Set your google merchant ID + * + * @param string + * @return this + */ + public function setGoogleMerchantId($id) { + //Argument 1 must be a string + Eden_Eventbrite_Error::i()->argument(1, 'string'); + + $this->_query['google_merchant_id'] = $id; + + return $this; + } + + /** + * Set google merchant key + * + * @param string + * @return this + */ + public function setGoogleMerchantKey($key) { + //Argument 1 must be a string + Eden_Eventbrite_Error::i()->argument(1, 'string'); + + $this->_query['google_merchant_key'] = $key; + + return $this; + } + + /** + * Set invoice instructions + * + * @param string + * @return this + */ + public function setInvoiceInstructions($instructions) { + //Argument 1 must be a string + Eden_Eventbrite_Error::i()->argument(1, 'string'); + + $this->_query['insrtructions_invoice'] = $instructions; + + return $this; + } + + /** + * Accept PayPal Email + * + * @param string + * @return this + */ + public function setPaypalEmail($email) { + //Argument 1 must be a string + Eden_Eventbrite_Error::i()->argument(1, 'string'); + + $this->_query['paypal_email'] = $email; + + return $this; + } + + /** + * Send update + * + * @return array + */ + public function update() { + return $this->_getJsonResponse($url, $this->_query); + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/eventbrite/ticket.php b/library/eden/eventbrite/ticket.php new file mode 100644 index 0000000..adeeb29 --- /dev/null +++ b/library/eden/eventbrite/ticket.php @@ -0,0 +1,307 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Eventbrite ticketing + * + * @package Eden + * @category eventbrite + * @author Christian Blanquera cblanquera@openovate.com + */ +class Eden_Eventbrite_Ticket extends Eden_Eventbrite_Base { + /* Constants + -------------------------------*/ + const URL_NEW = 'https://www.eventbrite.com/json/ticket_new'; + const URL_UPDATE = 'https://www.eventbrite.com/json/ticket_update'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_query = array(); + + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + /* Public Methods + -------------------------------*/ + /** + * Creates the ticket + * + * @return array + */ + public function create() { + if(!isset($this->_query['event_id'])) { + Eden_Eventbrite_Error::i()->setMessage(Eden_Eventbrite_Error::EVENT_NOT_SET)->trigger(); + } + + if(!isset($this->_query['name'])) { + Eden_Eventbrite_Error::i()->setMessage(Eden_Eventbrite_Error::NAME_NOT_SET)->trigger(); + } + + if(!isset($this->_query['price'])) { + Eden_Eventbrite_Error::i()->setMessage(Eden_Eventbrite_Error::PRICE_NOT_SET)->trigger(); + } + + if(!isset($this->_query['quantity'])) { + Eden_Eventbrite_Error::i()->setMessage(Eden_Eventbrite_Error::QUANTITY_NOT_SET)->trigger(); + } + + $query = $this->_query; + if(isset($query['hide'])) { + unset($query['hide']); + } + + return $this->_getJsonResponse(self::URL_NEW, $query); + } + + /** + * Set the description + * + * @param string + * @return this + */ + public function setDescription($description) { + //Argument 1 must be a string + Eden_Eventbrite_Error::i()->argument(1, 'string'); + $this->_query['description'] = $description; + + return $this; + } + + /** + * Accept donations + * + * @return this + */ + public function setDonation() { + $this->_query['is_donation'] = 1; + + return $this; + } + + /** + * Set the end time + * + * @param string|int + * @return this + */ + public function setEnd($end) { + //Argument 1 must be a string + Eden_Eventbrite_Error::i()->argument(1, 'string', 'int'); + + if(is_string($end)) { + $end = strtotime($end); + } + + $end = date('Y-m-d H:i:s', $end); + + $this->_query['end_sales'] = $end; + + return $this; + } + + /** + * Set event ID + * + * @param int + * @return this + */ + public function setEvent($id) { + //Argument 1 must be numeric + Eden_Eventbrite_Error::i()->argument(1, 'numeric'); + $this->_query['event_id'] = $id; + + return $this; + } + + /** + * Include Eventbrite's fee on top of the ticket fee + * + * @return this + */ + public function setFee() { + $this->_query['include_fee'] = 1; + + return $this; + } + + /** + * If true, will hide the ticket type + * + * @param bool + * @return this + */ + public function setHide($hide) { + //Argument 1 must be a boolean + Eden_Eventbrite_Error::i()->argument(1, 'bool'); + + //if the string hide is show + if($hide) { + //hide is equal to yes + $this->_query['hide'] = 'y'; + } else if($hide === false) { + //hide is equal to no + $this->_query['hide'] = 'n'; + } + + return $this; + } + + /** + * Set Ticket ID + * + * @param int + * @return this + */ + public function setId($ticketId) { + //Argument 1 must be numeric + Eden_Eventbrite_Error::i()->argument(1, 'numeric'); + $this->_query['id'] = $ticketId; + + return $this; + } + + /** + * Set the maximum number of tickets per order + * + * @param int + * @return this + */ + public function setMax($max) { + //Argument 1 must be an integer + Eden_Eventbrite_Error::i()->argument(1, 'int'); + if($max < 1) { + $max = 1; + } + + $this->_query['max'] = $max; + + return $this; + } + + /** + * Set the minimum number of tickets per order + * + * @param int + * @return this + */ + public function setMin($quantity) { + //Argument 1 must be an integer + Eden_Eventbrite_Error::i()->argument(1, 'int'); + if($min < 0) { + $min = 0; + } + $this->_query['min'] = $min; + + return $this; + } + + /** + * Set ticket name + * + * @param string + * @return this + */ + public function setName($name) { + //Argument 1 must be numeric + Eden_Eventbrite_Error::i()->argument(1, 'string'); + $this->_query['name'] = $name; + + return $this; + } + + /** + * Set price + * + * @param float + * @return this + */ + public function setPrice($price) { + //Argument 1 must be float + Eden_Eventbrite_Error::i()->argument(1, 'float', 'int'); + $this->_query['price'] = $price; + + return $this; + } + + /** + * Set quantity + * + * @param int + * @return this + */ + public function setQuantity($quantity) { + //Argument 1 must be an integer + Eden_Eventbrite_Error::i()->argument(1, 'int'); + $this->_query['quantity'] = $quantity; + + return $this; + } + + /** + * Set the start time + * + * @param int|string + * @return this + */ + public function setStart($start) { + //Argument 1 must be a string + Eden_Eventbrite_Error::i()->argument(1, 'string', 'int'); + + if(is_string($start)) { + $start = strtotime($start); + } + + $start = date('Y-m-d H:i:s', $start); + + $this->_query['start_sales'] = $start; + + return $this; + } + + /** + * Updates the ticket + * + * @return array + */ + public function update() { + if(!isset($this->_query['event_id'])) { + Eden_Eventbrite_Error::i()->setMessage(Eden_Eventbrite_Error::EVENT_NOT_SET)->trigger(); + } + + if(!isset($this->_query['name'])) { + Eden_Eventbrite_Error::i()->setMessage(Eden_Eventbrite_Error::NAME_NOT_SET)->trigger(); + } + + + if(!isset($this->_query['price'])) { + Eden_Eventbrite_Error::i()->setMessage(Eden_Eventbrite_Error::PRICE_NOT_SET)->trigger(); + } + + if(!isset($this->_query['quantity'])) { + Eden_Eventbrite_Error::i()->setMessage(Eden_Eventbrite_Error::QUANTITY_NOT_SET)->trigger(); + } + + return $this->_getJsonResponse(self::URL_UPDATE, $this->_query); + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} + + + diff --git a/library/eden/eventbrite/user.php b/library/eden/eventbrite/user.php new file mode 100644 index 0000000..8340fba --- /dev/null +++ b/library/eden/eventbrite/user.php @@ -0,0 +1,248 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Eventbrite user + * + * @package Eden + * @category eventbrite + * @author Christian Blanquera cblanquera@openovate.com + */ +class Eden_Eventbrite_User extends Eden_Eventbrite_Base { + /* Constants + -------------------------------*/ + const URL_GET = 'https://www.eventbrite.com/json/user_get'; + const URL_LIST_EVENTS = 'https://www.eventbrite.com/json/user_list_events'; + const URL_LIST_ORGANIZERS = 'https://www.eventbrite.com/json/user_list_organizers'; + const URL_LIST_TICKETS = 'https://www.eventbrite.com/json/user_list_tickets'; + const URL_LIST_VENUES = 'https://www.eventbrite.com/json/user_list_venues'; + const URL_NEW = 'https://www.eventbrite.com/json/user_new'; + const URL_UPDATE = 'https://www.eventbrite.com/json/user_update'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_query = array(); + + protected static $_validDisplays = array('description', 'venue', 'logo', 'style', 'organizer', 'tickets'); + + protected static $_validStatus = array('live', 'started', 'ended'); + + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + /* Public Methods + -------------------------------*/ + + /** + * Create a new user + * + * @param string + * @param string + * @return array + */ + public function add($user, $pass) { + //argument test + $error = Eden_Eventbrite_Error::i() + ->argument(1, 'string') //Argument 1 must be a atring + ->argument(2, 'string'); //Argument 2 must be a string + //if the string lenght of pass is less than 4 + if(strlen($pass) < 4){ + //show an error + $error->setMessage(Eden_Eventbrite_Error::INVALID_PASSWORD)->trigger(); + } + + $query = array('password' => $pass, 'user' => $user); + + return $this->_getJsonResponse(self::URL_NEW, $query); + + } + + /** + * Returns detail about the user + * + * @param int|string|null + * @return array + */ + public function getDetail($id = NULL) { + //Argument 1 must be a integer, string or null + Eden_Eventbrite_Error::i()->argument(1, 'int', 'string', 'null'); + + $query = array(); + //if it is not empty + if(is_int($id)) { + //lets put it in query + $query['user_id'] = $id; + //is it a string? + } else if(is_string($id)) { + //add it to query + $query['email'] = $id; + } + + return $this->_getJsonResponse(self::URL_GET, $query); + + } + + /** + * Returns a user's event list + * + * @param string|null + * @param string|array|null + * @param string|null + * @param string|null + * @return array + */ + public function getEvents($user = NULL, $hide = NULL, $status = NULL, $order = NULL) { + //argument test + Eden_Eventbrite_Error::i() + ->argument(1, 'string', 'null') //Argument 1 must be a string or null + ->argument(2, 'string', 'array', 'null') //Argument 2 must be a string or null + ->argument(3, 'string', 'null') //Argument 3 must be a string or null + ->argument(4, 'string', 'null'); //Argument 4 must be a string or null + + $query = array(); + //if user is not empty + if(!is_null($user)){ + //add it to our query + $query['user'] = $user; + } + + //if there is a hide + if(!is_null($hide)) { + //if hide is a string + if(is_string($hide)){ + //lets may it an array + $hide = explode(',', $hide); + } + //at this poit hide will be an array + $displays = array(); + //for each hide + foreach($hide as $display){ + //if this display is a valid display + if(in_array($display, $this->_validDisplays)){ + //lets asdd this to our valid status list + $displays[] = $display; + } + } + //if we have at least one valid status + if(!empty($displays)){ + //lets make hide into a string + $hide = implode(',', $displays); + //and add to query + $query['do_not_display'] = $hide; + } + } + + //if there is a status + if(!is_null($status)) { + //if status is a string + if(is_string($status)) { + //lets make it an array + $status = explode(',', $status); + } + //at this point status will be an array + $statuses = array(); + //for each status + foreach($status as $event) { + //if this status is a valid status + if(in_array($status, $this->_validStatus)) { + //lets add this to our valid status list + $statuses[] = $event; + } + } + //if we have at least one valid status + if(!empty($statuses)) { + //lets make statuses into a string + $status = implode(',', $events); + //and add to query + $query['event_statuses'] = $status; + } + } + //if order is equal to desc + if($order == 'desc') { + //add it to our query + $query['asc_or_desc'] = 'desc'; + } + + return $this->_getJsonResponse(self::URL_LIST_EVENTS, $query); + } + + /** + * Returns a user's oraganizations + * + * @return array + */ + public function getOrganizers() { + return $this->_getJsonResponse(self::URL_LIST_ORGANIZERS); + } + + /** + * Returns a user's ticket history + * + * @return array + */ + public function getTickets(){ + return $this->_getJsonResponse(self::URL_LIST_TICKETS); + } + + /** + * Returns a user's venue list they have used before + * + * @return array + */ + public function getVenues() { + return $this->_getJsonResponse(self::URL_LIST_VENUES); + } + + /** + * Updates the current user + * + * @param string|null + * @param string|null + * @return array + */ + public function update($email = NULL, $pass = NULL) { + //argument test + Eden_Eventbrite_Error::i() + ->argument(1, 'string', 'null') //Argument 1 must be a string or null + ->argument(2, 'string', 'null'); //Argument 2 must be a string or null + + $query = array(); + //if email is not empty + if(!is_null($email)){ + //add it to our query + $query['new_email'] = $email; + } + //if pass is not empty and the string lenght is greater than equal to 4 + if(!is_null($pass) && strlen($pass) >= 4) { + //add it to our query + $query['new_password'] = $pass; + } + + return $this->getJsonResponse(self::URL_UPDATE, $query); + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} + + + + + + + \ No newline at end of file diff --git a/library/eden/eventbrite/venue.php b/library/eden/eventbrite/venue.php new file mode 100644 index 0000000..936d0d3 --- /dev/null +++ b/library/eden/eventbrite/venue.php @@ -0,0 +1,171 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Eventbrite venue + * + * @package Eden + * @category eventbrite + * @author Christian Blanquera cblanquera@openovate.com + */ +class Eden_Eventbrite_Venue extends Eden_Eventbrite_Base { + /* Constants + -------------------------------*/ + const URL_NEW = 'https://www.eventbrite.com/json/venue_new'; + const URL_UPDATE = 'https://www.eventbrite.com/json/venue_update'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_query = array(); + + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + /* Magic + -------------------------------*/ + /* Public Methods + -------------------------------*/ + /** + * Creates the venue + * + * @param string + * @param string + * @param string + * @param string + * @return array + */ + public function create($organizer, $venue, $country, $region) { + //argument test + Eden_Eventbrite_Error::i() + ->argument(1, 'string', 'int') //Argument must be a string + ->argument(2, 'string') //Argument msut be a string + ->argument(3, 'string') //Argument must be a string + ->argument(4, 'string'); //Argument must be a string + + + $query = array( + 'organizer_id' => $organizer, + 'venue' => $venue, + 'country' => $country, + 'region' => $region); + + $query = array_merge($query, $this->_query); + + return $this->_getJsonResponse(self::URL_NEW, $query); + } + + /** + * Set Address + * + * @param string + * @param string|null + * @return this + */ + public function setAddress($address, $address2 = NULL) { + Eden_Eventbrite_Error::i() + ->argument(1, 'string') + ->argument(2, 'string', 'null'); + + $this->_query['address'] = $address; + + if(!is_null($address2)) { + $this->_query['address2'] = $address2; + } + + return $this; + } + + /** + * Set city + * + * @param string + * @return this + */ + public function setCity($city) { + Eden_Eventbrite_Error::i()->argument(1, 'string'); + $this->_query['city'] = $city; + return $this; + } + + /** + * Set Country + * + * @param string + * @return this + */ + public function setCountry($country) { + Eden_Eventbrite_Error::i()->argument(1, 'string'); + $this->_query['country_code'] = $country; + return $this; + } + + /** + * Set postal + * + * @param string + * @return this + */ + public function setPostal($code) { + Eden_Eventbrite_Error::i()->argument(1, 'string'); + $this->_query['postal_code'] = $code; + return $this; + } + + /** + * Set Region + * + * @param string + * @return this + */ + public function setRegion($region) { + Eden_Eventbrite_Error::i()->argument(1, 'string'); + $this->_query['region'] = $region; + return $this; + } + + /** + * Updates the venue + * + * @param int + * @param string + * @return array + */ + public function update($id, $venue) { + //argument test + Eden_Eventbrite_Error::i() + ->argument(1, 'int') //Argument must be a integer + ->argument(2, 'string'); //Argument must be a string + + $query = array('id' => $id, 'venue' => $venue); + $query = array_merge($query, $this->_query); + + return $this->getJsonResponse(self::URL_UPDATE, $query); + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} + + + + + + + + + + diff --git a/library/eden/facebook.php b/library/eden/facebook.php new file mode 100644 index 0000000..29feae0 --- /dev/null +++ b/library/eden/facebook.php @@ -0,0 +1,148 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +require_once dirname(__FILE__).'/oauth2.php'; +require_once dirname(__FILE__).'/facebook/error.php'; +require_once dirname(__FILE__).'/facebook/auth.php'; +require_once dirname(__FILE__).'/facebook/graph.php'; +require_once dirname(__FILE__).'/facebook/post.php'; +require_once dirname(__FILE__).'/facebook/event.php'; +require_once dirname(__FILE__).'/facebook/link.php'; +require_once dirname(__FILE__).'/facebook/select.php'; +require_once dirname(__FILE__).'/facebook/search.php'; +require_once dirname(__FILE__).'/facebook/fql.php'; + +/** + * Facebook API factory. This is a factory class with + * methods that will load up different Facebook classes. + * Facebook classes are organized as described on their + * developer site: auth, graph, FQL. We also added a post + * class for more advanced options when posting to Facebook. + * + * @package Eden + * @category facebook + * @author Christian Blanquera cblanquera@openovate.com + */ +class Eden_Facebook extends Eden_Class { + /* Constants + -------------------------------*/ + const RSS = 'https://www.facebook.com/feeds/page.php?id=%s&format=rss20'; + const RSS_AGENT = 'Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.13) Gecko/20101206 Ubuntu/10.10 (maverick) Firefox/3.6.13'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getSingleton(__CLASS__); + } + + /* Public Methods + -------------------------------*/ + /** + * Returns Facebook Auth + * + * @param string + * @param string + * @param string + * @return Eden_Facebook_Auth + */ + public function auth($key, $secret, $redirect) { + Eden_Facebook_Error::i() + ->argument(1, 'string') + ->argument(2, 'string') + ->argument(3, 'string'); + + return Eden_Facebook_Auth::i($key, $secret, $redirect); + } + + /** + * Add an event + * + * @param string + * @param string + * @param string|int + * @param string|int + * @return Eden_Facebook_Event + */ + public function event($token, $name, $start, $end) { + return Eden_Facebook_Event::i($token, $name, $start, $end); + } + + /** + * Returns Facebook FQL + * + * @param string + * @return Eden_Facebook_Fql + */ + public function fql($token) { + Eden_Facebook_Error::i()->argument(1, 'string'); + return Eden_Facebook_Fql::i($token); + } + + /** + * Returns Facebook Graph + * + * @param string + * @return Eden_Facebook_Graph + */ + public function graph($token) { + Eden_Facebook_Error::i()->argument(1, 'string'); + return Eden_Facebook_Graph::i($token); + } + + /** + * Add a link + * + * @param string + * @param string + * @return Eden_Facebook_Post + */ + public function link($token, $url) { + return Eden_Facebook_Link::i($token, $url); + } + + /** + * Returns Facebook Post + * + * @param string + * @param string + * @return Eden_Facebook_Post + */ + public function post($token, $message) { + return Eden_Facebook_Post::i($token, $message); + } + + /** + * Returns an RSS feed to a public id + * + * @param int + * @return SimpleXml + */ + public function rss($id) { + Eden_Facebook_Error::i()->argument(1, 'int'); + return Eden_Curl::i() + ->setUrl(sprintf(self::RSS, $id)) + ->setUserAgent(self::RSS_AGENT) + ->setConnectTimeout(10) + ->setFollowLocation(true) + ->setTimeout(60) + ->verifyPeer(false) + ->getSimpleXmlResponse(); + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/facebook/auth.php b/library/eden/facebook/auth.php new file mode 100644 index 0000000..c64263f --- /dev/null +++ b/library/eden/facebook/auth.php @@ -0,0 +1,56 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package.st. + */ + +/** + * Facebook Authentication + * + * @package Eden + * @category facebook + * @author Christian Blanquera cblanquera@openovate.com + */ +class Eden_Facebook_Auth extends Eden_Oauth2_Client { + /* Constants + -------------------------------*/ + const REQUEST_URL = 'https://www.facebook.com/dialog/oauth'; + const ACCESS_URL = 'https://graph.facebook.com/oauth/access_token'; + const USER_AGENT = 'facebook-php-3.1'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_key = NULL; + protected $_secret = NULL; + protected $_redirect = NULL; + + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + public function __construct($key, $secret, $redirect) { + //argument test + Eden_Facebook_Error::i() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'string') //Argument 2 must be a string + ->argument(3, 'string'); //Argument 4 must be a string + + parent::__construct($key, $secret, $redirect, self::REQUEST_URL, self::ACCESS_URL); + } + + /* Public Methods + -------------------------------*/ + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/facebook/columns.php b/library/eden/facebook/columns.php new file mode 100644 index 0000000..1edd052 --- /dev/null +++ b/library/eden/facebook/columns.php @@ -0,0 +1,288 @@ + +return array( + 'album' => array( + 'aid', 'object_id', 'owner', + 'cover_pid', 'cover_object_id', 'name', + 'created', 'modified', 'description', + 'location', 'size', 'link', + 'visible', 'modified_major', 'edit_link', + 'type', 'can_upload', 'photo_count', + 'video_count'), + 'application' => array( + 'app_id', 'api_key', + 'canvas_name', 'display_name', + 'icon_url', 'logo_url', + 'company_name', 'developers', + 'description', 'daily_active_users', + 'weekly_active_users', 'monthly_active_users', + 'category', 'subcategory', + 'is_facebook_app', 'restriction_info', + 'app_domains', 'auth_dialog_data_help_url', + 'auth_dialog_description', 'auth_dialog_headline', + 'auth_dialog_perms_explanation', 'auth_referral_user_perms', + 'auth_referral_friend_perms', 'auth_referral_default_activity_privacy', + 'auth_referral_enabled', 'auth_referral_extended_perms', + 'auth_referral_response_type', 'canvas_fluid_height', + 'canvas_fluid_width', 'canvas_url', + 'contact_email', 'created_time', + 'creator_uid', 'deauth_callback_url', + 'iphone_app_store_id', 'hosting_url', + 'mobile_web_url', 'page_tab_default_name', + 'page_tab_url', 'privacy_policy_url', + 'secure_canvas_url', 'secure_page_tab_url', + 'server_ip_whitelist', 'social_discovery', + 'terms_of_service_url', 'update_ip_whitelist', + 'user_support_email', 'user_support_url', + 'website_url'), + 'apprequest' => array( + 'request_id', 'app_id', 'recipient_uid', + 'sender_uid', 'message', 'data', + 'created_time'), + 'checkin' => array( + 'checkin_id', 'author_uid', 'page_id', + 'app_id', 'post_id', 'coords', + 'timestamp', 'tagged_uids', 'message'), + 'comment' => array( + 'xid', 'object_id', 'post_id', + 'fromid', 'time', 'text', + 'id', 'username ', 'reply_xid', + 'post_fbid', 'app_id', 'likes', + 'comments', 'user_likes', 'is_private'), + 'comments_info' => array( + 'app_id', 'xid', + 'count', 'updated_time'), + 'connection' => array( + 'source_id', 'target_id', + 'target_type', 'is_following'), + 'cookies' => array( + 'uid', 'name', 'value', + 'expires', 'path'), + 'developer' => array('developer_id', 'application_id', 'role'), + 'domain' => array('domain_id', 'domain_name'), + 'domain_admin' => array('owner_id', 'domain_id'), + 'event' => array( + 'eid', 'name', 'tagline', + 'nid', 'pic_small', 'pic_big', + 'pic_square', 'pic', 'host', + 'description', 'event_type', 'event_subtype', + 'start_time', 'end_time', 'creator', + 'update_time', 'location', 'venue', + 'privacy', 'hide_guest_list', 'can_invite_friends'), + 'event_member' => array( + 'uid', 'eid', + 'rsvp_status', 'start_time'), + 'family' => array( + 'profile_id', 'uid', + 'name', 'birthday', + 'relationship'), + 'friend' => array('uid1', 'uid2'), + 'friend_request' => array( + 'uid_to', 'uid_from', + 'time', 'message', + 'unread'), + 'friendlist' => array('owner', 'flid', 'name'), + 'friendlist_member' => array('flid', 'uid'), + 'group' => array( + 'gid', 'name', 'nid', + 'pic_small', 'pic_big', 'pic', + 'description', 'group_type', 'group_subtype', + 'recent_news', 'creator', 'update_time', + 'office', 'website', 'venue', + 'privacy', 'icon', 'icon34', + 'icon68', 'email', 'version'), + 'group_member' => array( + 'uid', 'gid', 'administrator', + 'positions', 'unread', 'bookmark_order'), + 'insights' => array('object_id', 'metric', 'end_time', 'period', 'value'), + 'like' => array('object_id', 'post_id', 'user_id', 'object_type'), + 'link' => array( + 'link_id', 'owner', 'owner_comment', + 'created_time', 'title', 'summary', + 'url', 'picture', 'image_urls'), + 'link_stat' => array( + 'url', 'normalized_url', 'share_count', + 'like_count', 'comment_count', 'total_count', + 'click_count', 'comments_fbid', 'commentsbox_count'), + 'mailbox_folder' => array( + 'folder_id', 'viewer_id', 'name', + 'unread_count', 'total_count'), + 'message' => array( + 'message_id', 'thread_id', 'author_id', + 'body', 'created_time', 'attachment', + 'viewer_id'), + 'note' => array( + 'uid', 'note_id', 'created_time', + 'updated_time', 'content', 'content_html', + 'title'), + 'notification' => array( + 'notification_id', 'sender_id', 'recipient_id', + 'created_time', 'updated_time', 'title_html', + 'title_text', 'body_html', 'body_text', + 'href', 'app_id', 'is_unread', + 'is_hidden', 'object_id', 'object_type', + 'icon_url'), + 'object_url' => array( + 'url', 'id', + 'type', 'site'), + 'page' => array( + 'page_id', 'name', 'username', + 'description', 'categories', 'is_community_page', + 'pic_small', 'pic_big', 'pic_square', + 'pic', 'pic_large', 'page_url', + 'fan_count', 'type', 'website', + 'has_added_app', 'general_info', 'can_post', + 'checkins', 'founded', 'company_overview', + 'mission', 'products', 'location', + 'parking', 'hours', 'pharma_safety_info', + 'public_transit', 'attire', 'payment_options', + 'culinary_team', 'general_manager', 'price_range', + 'restaurant_services', 'restaurant_specialties', 'phone', + 'release_date', 'genre', 'starring', + 'screenplay_by', 'directed_by', 'produced_by', + 'studio', 'awards', 'plot_outline', + 'season', 'network', 'schedule', + 'written_by', 'band_members', 'hometown', + 'current_location', 'record_label', 'booking_agent', + 'press_contact', 'artists_we_like', 'influences', + 'band_interests', 'bio', 'affiliation', + 'birthday', 'personal_info', 'personal_interests', + 'built', 'features', 'mpg'), + 'page_admin' => array('uid', 'page_id', 'type'), + 'page_blocked_user' => array('page_id', 'uid'), + 'page_fan' => array( + 'uid', 'page_id', + 'type', 'profile_section', + 'created_time'), + 'permissions' => array('uid', 'PERMISSION_NAME'), + 'permissions_info' => array('permission_name', 'header', 'summary'), + 'photo' => array( + 'pid', 'aid', 'owner', + 'src_small', 'src_small_width', 'src_small_height', + 'src_big', 'src_big_width', 'src_big_height', + 'src', 'src_width', 'src_height', + 'link', 'caption', 'created', + 'modified', 'position', 'object_id', + 'album_object_id', 'images'), + 'photo_tag' => array( + 'pid', 'subject', 'object_id', + 'text', 'xcoord', 'ycoord', + 'created'), + 'place' => array( + 'page_id', 'name', 'description', + 'geometry', 'latitude', 'longitude', + 'checkin_count', 'display_subtext'), + 'privacy' => array( + 'id', 'object_id', 'value ', + 'description', 'allow', 'deny', + 'owner_id', 'networks', 'friends'), + 'privacy_setting' => array( + 'name', 'value ', 'description', + 'allow', 'deny', 'networks', + 'friends'), + 'profile' => array( + 'id', 'can_post', 'name', + 'url', 'pic', 'pic_square', + 'pic_small', 'pic_big', 'pic_crop', + 'type', 'username'), + 'question' => array( + 'id', 'owner', 'question', + 'created_time', 'updated_time'), + 'question_option' => array( + 'id', 'question_id', 'name', + 'votes', 'object_id', 'owner', + 'created_time'), + 'question_option_votes' => array('option_id', 'voter_id'), + 'review' => array( + 'reviewee_id', 'reviewer_id', 'review_id', + 'message', 'created_time', 'rating'), + 'standard_friend_info' => array('uid1', 'uid2'), + 'standard_user_info' => array( + 'uid', 'name', 'username', + 'third_party_id', 'first_name', 'last_name', + 'locale', 'affiliations', 'profile_url', + 'timezone', 'birthday', 'sex', + 'proxied_email', 'current_location', 'allowed_restrictions'), + 'status' => array( + 'uid', 'status_id', + 'time', 'source', + 'message'), + 'stream' => array( + 'post_id', 'viewer_id ', 'app_id', + 'source_id ', 'updated_time', 'created_time', + 'filter_key', 'attribution ', 'actor_id', + 'target_id', 'message', 'app_data', + 'action_links', 'attachment', 'impressions', + 'comments', 'likes', 'privacy', + 'permalink', 'xid', 'tagged_ids', + 'message_tags', 'description', 'description_tags'), + 'stream_filter' => array( + 'uid', 'filter_key ', 'name', + 'rank ', 'icon_url', 'is_visible', + 'type', 'value'), + 'stream_tag' => array('post_id', 'actor_id', 'target_id'), + 'thread' => array( + 'thread_id', 'folder_id', 'subject', + 'recipients', 'updated_time', 'parent_message_id', + 'parent_thread_id', 'message_count', 'snippet', + 'snippet_author', 'object_id', 'unread', + 'viewer_id'), + 'translation' => array( + 'locale', 'native_hash', 'native_string', + 'description', 'translation', 'approval_status', + 'pre_hash_string', 'best_string'), + 'unified_message' => array( + 'message_id', 'thread_id', 'subject', + 'body', 'unread', 'action_id', + 'timestamp', 'tags', 'sender', + 'recipients', 'object_sender', 'html_body', + 'attachments', 'attachment_map', 'shares', + 'share_map'), + 'unified_thread' => array( + 'action_id', 'archived', 'can_reply', + 'folder', 'former_participants', 'has_attachments', + 'is_subscribed', 'last_visible_add_action_id', 'name', + 'num_messages', 'num_unread', 'object_participants', + 'participants', 'senders', 'single_recipient', + 'snippet', 'snippet_sender', 'snippet_message_has_attachment', + 'subject', 'tags', 'thread_id', + 'thread_participants', 'timestamp', 'unread'), + 'unified_thread_action' => array( + 'action_id', 'actor', 'thread_id', + 'timestamp', 'type', 'users'), + 'unified_thread_count' => array( + 'folder', 'unread_count', 'unseen_count', + 'last_action_id', 'last_seen_time', 'total_threads'), + 'url_like' => array('user_id', 'url'), + 'user' => array( + 'uid', 'username', 'first_name', + 'middle_name', 'last_name', 'name', + 'pic_small', 'pic_big', 'pic_square', + 'pic', 'affiliations', 'profile_update_time', + 'timezone', 'religion', 'birthday', + 'birthday_date', 'sex', 'hometown_location', + 'meeting_sex', 'meeting_for', 'relationship_status', + 'significant_other_id', 'political', 'current_location', + 'activities', 'interests', 'is_app_user', + 'music', 'tv', 'movies', + 'books', 'quotes', 'about_me', + 'hs_info', 'education_history', 'work_history', + 'notes_count', 'wall_count', 'status', + 'has_added_app', 'online_presence', 'locale', + 'proxied_email', 'profile_url', 'email_hashes', + 'pic_small_with_logo', 'pic_big_with_logo', 'pic_square_with_logo', + 'pic_with_logo', 'allowed_restrictions', 'verified', + 'profile_blurb', 'family', 'website', + 'is_blocked', 'contact_email', 'email', + 'third_party_id', 'name_format', 'video_upload_limits', + 'games', 'is_minor', 'work', + 'education', 'sports', 'favorite_athletes', + 'favorite_teams', 'inspirational_people', 'languages', + 'likes_count', 'friend_count', 'mutual_friend_count', + 'can_post'), + 'video' => array( + 'vid', 'owner', 'album_id', + 'title', 'description', 'link', + 'thumbnail_link', 'embed_html', 'updated_time', + 'created_time', 'length', 'src', + 'src_hq'), + 'video_tag' => array('vid', 'subject', 'updated_time', 'created_time')); \ No newline at end of file diff --git a/library/eden/facebook/error.php b/library/eden/facebook/error.php new file mode 100644 index 0000000..200da6f --- /dev/null +++ b/library/eden/facebook/error.php @@ -0,0 +1,40 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Facebook Errors + * + * @package Eden + * @category facebook + * @author Christian Blanquera cblanquera@openovate.com + */ +class Eden_Facebook_Error extends Eden_Error { + /* Constants + -------------------------------*/ + const AUTHENTICATION_FAILED = 'Application authentication failed. Facebook returned %s: %s'; + const GRAPH_FAILED = 'Call to graph.facebook.com failed. Facebook returned %s: %s'; + const REQUIRES_AUTH = 'Call to %s requires authentication. Please set token first or set argument 4 in setObject() to false.'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + /* Magic + -------------------------------*/ + /* Public Methods + -------------------------------*/ + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/facebook/event.php b/library/eden/facebook/event.php new file mode 100644 index 0000000..1c780cd --- /dev/null +++ b/library/eden/facebook/event.php @@ -0,0 +1,240 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Create Facebook Event + * + * @package Eden + * @category facebook + * @author Christian Blanquera cblanquera@openovate.com + */ +class Eden_Facebook_Event extends Eden_Class { + /* Constants + -------------------------------*/ + const OPEN = 'OPEN'; + const CLOSED = 'CLOSED'; + const SECRET = 'SECRET'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_id = 'me'; + protected $_post = array(); + protected $_venue = array(); + + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + public function __construct($token, $name, $start, $end) { + //Argument 1 must be a string + Eden_Facebook_Error::i() + ->argument(1, 'string') + ->argument(2, 'string') + ->argument(3, 'string', 'int') + ->argument(4, 'string', 'int'); + + if(is_string($start)) { + $start = strtotime($start); + } + + if(is_string($end)) { + $end = strtotime($end); + } + + $this->_token = $token; + $this->_post = array( + 'name' => $name, + 'start_time' => $start, + 'end_time' => $end); + } + + /* Public Methods + -------------------------------*/ + /** + * sends the post to facebook + * + * @return int + */ + public function create() { + //post variable must be array + $post = $this->_post; + + if(!empty($this->_venue)) { + $post['venue'] = json_encode($this->_venue); + } + + //get the facebook graph url + $url = Eden_Facebook_Graph::GRAPH_URL.$this->_id.'/events'; + $query = array('access_token' => $this->_token); + $url .= '?'.http_build_query($query); + + //send it into curl + $response = Eden_Curl::i() + ->setUrl($url) //sets the url + ->setConnectTimeout(10) //sets connection timeout to 10 sec. + ->setFollowLocation(true) //sets the follow location to true + ->setTimeout(60) //set page timeout to 60 sec + ->verifyPeer(false) //verifying Peer must be boolean + ->setUserAgent(Eden_Facebook_Auth::USER_AGENT) //set facebook USER_AGENT + ->setHeaders('Expect') //set headers to EXPECT + ->setPost(true) //set post to true + ->setPostFields(http_build_query($post)) //set post fields + ->getJsonResponse(); //get the json response + + return $response['id']; //return the id + } + + /** + * Sets the venue city + * + * @param string + * @return this + */ + public function setCity($city){ + //Argument 1 must be a string + Eden_Facebook_Error::i()->argument(1, 'string'); + + $this->_venue['city'] = $city; + return $this; + } + + /** + * Sets the venue coordinates + * + * @param float + * @param float + * @return this + */ + public function setCoordinates($latitude, $longitude){ + Eden_Facebook_Error::i()->argument(1, 'float')->argument(2, 'float'); + + $this->_venue['latitude'] = $latitude; + $this->_venue['longitude'] = $longitude; + return $this; + } + + /** + * Sets the venue country + * + * @param string + * @return this + */ + public function setCountry($country){ + //Argument 1 must be a string + Eden_Facebook_Error::i()->argument(1, 'string'); + + $this->_venue['country'] = $country; + return $this; + } + + /** + * Sets description + * + * @param string + * @return this + */ + public function setDescription($description){ + //Argument 1 must be a string + Eden_Facebook_Error::i()->argument(1, 'string'); + + $this->_post['description'] = $description; + return $this; + } + + public function setId($id) { + //Argument 1 must be a string + Eden_Facebook_Error::i()->argument(1, 'numeric'); + + $this->_id = $id; + return $this; + } + + /** + * Sets the title of a post + * + * @param string + * @return this + */ + public function setLocation($location){ + //Argument 1 must be a string + Eden_Facebook_Error::i()->argument(1, 'string'); + + $this->_post['location'] = $location; + return $this; + } + + /** + * Sets privacy to closed + * + * @return this + */ + public function setPrivacyClosed() { + $this->_post['privacy'] = self::CLOSED; + return $this; + } + + /** + * Sets privacy to open + * + * @return this + */ + public function setPrivacyOpen() { + $this->_post['privacy'] = self::OPEN; + return $this; + } + + /** + * Sets privacy to secret + * + * @return this + */ + public function setPrivacySecret() { + $this->_post['privacy'] = self::SECRET; + return $this; + } + + /** + * Sets the venue state + * + * @param string + * @return this + */ + public function setState($state){ + //Argument 1 must be a string + Eden_Facebook_Error::i()->argument(1, 'string'); + + $this->_venue['state'] = $state; + return $this; + } + + /** + * Sets the venue street + * + * @param string + * @return this + */ + public function setStreet($street){ + //Argument 1 must be a string + Eden_Facebook_Error::i()->argument(1, 'string'); + + $this->_venue['street'] = $street; + return $this; + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/facebook/fql.php b/library/eden/facebook/fql.php new file mode 100644 index 0000000..167a235 --- /dev/null +++ b/library/eden/facebook/fql.php @@ -0,0 +1,341 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Abstractly defines a layout of available methods to + * connect to and query a database. This class also lays out + * query building methods that auto renders a valid query + * the specific database will understand without actually + * needing to know the query language. + * + * @package Eden + * @category sql + * @author Christian Blanquera cblanquera@openovate.com + */ +class Eden_Facebook_Fql extends Eden_Class { + /* Constants + -------------------------------*/ + const SELECT = 'Eden_Facebook_Select'; + const FQL_URL = 'https://graph.facebook.com/fql'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_queries = array(); + + protected $_token = NULL; + + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + public function __construct($token) { + $this->_token = $token; + } + + /* Public Methods + -------------------------------*/ + /** + * Returns a collection given the query parameters + * + * @param string table + * @param array filter + * @param array sort + * @param int start + * @param int range + * @return array + */ + public function getCollection($table, $filters = NULL, array $sort = array(), $start = 0, $range = 0, $index = NULL) { + //argument test + Eden_Facebook_Error::i() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'string', 'array', 'null') //Argument 3 must be a string number or null + ->argument(4, 'numeric') //Argument 5 must be a number + ->argument(5, 'numeric') //Argument 6 must be a number + ->argument(6, 'numeric', 'null'); //Argument 7 must be a number or null + + $results = $this->getRows($table, $filters, $sort, $start, $range, $index); + + $collection = Eden_Collection::i(); + + if(is_null($results)) { + return $collection; + } + + if(!is_null($index)) { + return $this->model($results); + } + + return $collection->set($results); + } + + /** + * Returns a model given the column name and the value + * + * @param string table + * @param string name + * @param string value + * @return array|NULL + */ + public function getModel($table, $name, $value) { + //argument test + Eden_Facebook_Error::i() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'string') //Argument 2 must be a string + ->argument(3, 'string', 'numeric'); //Argument 3 must be a string or number + + $result = $this->getRow($table, $name, $value); + + $model = Eden_Model::i(); + + if(is_null($result)) { + return $model; + } + + return $model->set($result); + } + + /** + * Returns a 1 row result given the column name and the value + * + * @param string table + * @param string name + * @param string value + * @return array + */ + public function getRow($table, $name, $value) { + //argument test + Eden_Facebook_Error::i() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'string') //Argument 2 must be a string + ->argument(3, 'string', 'numeric'); //Argument 3 must be a string or number + + $query = $this->select() + ->from($table) + ->where($name.' = '.$value) + ->limit(0, 1); + + $results = $this->query($query); + + return isset($results[0]) ? $results[0] : NULL; + } + + /** + * Returns a list of results given the query parameters + * + * @param string table + * @param array filter + * @param array sort + * @param int start + * @param int range + * @return array + */ + public function getRows($table, $filters = NULL, array $sort = array(), $start = 0, $range = 0, $index = NULL) { + //argument test + Eden_Facebook_Error::i() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'string', 'array', 'null') //Argument 3 must be a string number or null + ->argument(4, 'numeric') //Argument 5 must be a number + ->argument(5, 'numeric') //Argument 6 must be a number + ->argument(6, 'numeric', 'null'); //Argument 7 must be a number or null + + $query = $this->select()->from($table); + + if(is_array($filters)) { + foreach($filters as $i => $filter) { + if(!is_array($filter)) { + continue; + } + + //array('post_id=%s AND post_title IN %s', 123, array('asd')); + $format = array_shift($filter); + $filters[$i] = vsprintf($format, $filter); + } + } + + if(!is_null($filters)) { + $query->where($filters); + } + + if(!empty($sort)) { + foreach($sort as $key => $value) { + if(is_string($key) && trim($key)) { + $query->sortBy($key, $value); + } + } + } + + if($range) { + $query->limit($start, $range); + } + + $results = $this->query($query); + + if(!is_null($index)) { + if(empty($results)) { + $results = NULL; + } else { + if($index == self::FIRST) { + $index = 0; + } + + if($index == self::LAST) { + $index = count($results)-1; + } + + if(isset($results[$index])) { + $results = $results[$index]; + } else { + $results = NULL; + } + } + } + + return $results; + } + + /** + * Returns the number of results given the query parameters + * + * @param string table + * @param array filter + * @return int | false + */ + public function getRowsCount($table, $filters = NULL) { + //argument test + Eden_Facebook_Error::i() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'string', 'array', 'null'); //Argument 3 must be a string number or null + + $query = $this->select('COUNT(*) as count')->from($table); + + if(is_array($filters)) { + foreach($filters as $i => $filter) { + if(!is_array($filter)) { + continue; + } + + $format = array_shift($filter); + $filters[$i] = vsprintf($format, $filter); + } + } + + if(!is_null($filters)) { + $query->where($filters); + } + + $results = $this->query($query); + + if(isset($results[0]['count'])) { + return $results[0]['count']; + } + + return false; + } + + /** + * Returns the history of queries made still in memory + * + * @return array the queries + */ + public function getQueries($index = NULL) { + if(is_null($index)) { + return $this->_queries; + } + + if($index == self::FIRST) { + $index = 0; + } + + if($index == self::LAST) { + $index = count($this->_queries) - 1; + } + + if(isset($this->_queries[$index])) { + return $this->_queries[$index]; + } + + return NULL; + } + + /** + * Queries the database + * + * @param string query + * @return array|object + */ + public function query($query) { + //Argument 1 must be a string or null + Eden_Facebook_Error::i()->argument(1, 'string', 'array', self::SELECT); + + if(!is_array($query)) { + $query = array('q' => (string) $query); + } else { + foreach($query as $key => $select) { + $query[$key] = (string) $select; + } + + $query = array('q' => json_encode($query)); + } + + $query['access_token'] = $this->_token; + $url = self::FQL_URL.'?'.http_build_query($query); + + $results = Eden_Curl::i() + ->setUrl($url) + ->setConnectTimeout(10) + ->setFollowLocation(true) + ->setTimeout(60) + ->verifyPeer(false) + ->setUserAgent(Eden_Facebook_Auth::USER_AGENT) + ->setHeaders('Expect') + ->getJsonResponse(); + + $this->_queries[] = array( + 'query' => $query['q'], + 'results' => $results); + + if(isset($results['error']['message'])) { + Eden_Facebook_Error::i($query['q'].$results['error']['message'])->trigger(); + } + + return $results['data']; + } + + /** + * Returns search + * + * @return Eden_Facebook_Search + */ + public function search() { + return Eden_Facebook_Search::i($this); + } + + /** + * Returns the select query builder + * + * @return Eden_Facebook_Select + */ + public function select($select = '*') { + //Argument 1 must be a string or array + Eden_Facebook_Error::i()->argument(1, 'string', 'array'); + + return Eden_Facebook_Select::i($select); + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/facebook/graph.php b/library/eden/facebook/graph.php new file mode 100644 index 0000000..bbc1635 --- /dev/null +++ b/library/eden/facebook/graph.php @@ -0,0 +1,603 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package.st. + */ + +/** + * Facebook Authentication + * + * @package Eden + * @category facebook + * @author Christian Blanquera cblanquera@openovate.com + */ +class Eden_Facebook_Graph extends Eden_Class { + /* Constants + -------------------------------*/ + const GRAPH_URL = 'https://graph.facebook.com/'; + const LOGOUT_URL = 'https://www.facebook.com/logout.php?next=%s&access_token=%s'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_token = NULL; + + protected $_list = array( + 'Friends', 'Home', + 'Feed', 'Likes', + 'Movies', 'Music', + 'Books', 'Photos', + 'Albums', 'Videos', + 'VideoUploads', 'Events', + 'Groups', 'Checkins'); + + protected $_search = array( + 'Posts', 'Users', + 'Pages', 'Likes', + 'Places', 'Events', + 'Groups', 'Checkins'); + + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + public function __call($name, $args) { + //if the method starts with get + if(strpos($name, 'get') === 0 && in_array(substr($name, 3), $this->_list)) { + $key = preg_replace("/([A-Z])/", "/$1", $name); + //get rid of get + $key = strtolower(substr($key, 4)); + + $id = 'me'; + if(!empty($args)) { + $id = array_shift($args); + } + + array_unshift($args, $id, $key); + + return call_user_func_array(array($this, '_getList'), $args); + } else if(strpos($name, 'search') === 0 && in_array(substr($name, 6), $this->_search)) { + + //get rid of get + $key = strtolower(substr($name, 6)); + + array_unshift($args, $key); + + return call_user_func_array(array($this, '_search'), $args); + } + } + + public function __construct($token) { + $this->_token = $token; + } + /* Public Methods + -------------------------------*/ + + /** + * Add an album + * + * @param string|int the object ID to place the album + * @param string + * @param string the album description + * @return int the album ID + */ + public function addAlbum($id, $name, $message) { + //Argument test + Eden_Facebook_Error::i() + ->argument(1, 'string', 'int') //Argument 1 must be a string or integer + ->argument(2, 'string') //Argument 2 must be a string + ->argument(3, 'string'); //Argument 3 must be a string + + //form the URL + $url = self::GRAPH_URL.$id.'/albums'; + $post = array('name'=>$name,'message'=>$message); + $query = array('access_token' => $this->_token); + $url .= '?'.http_build_query($query); + $results = json_decode($this->_call($url, $post), true); + + return $results['id']; + } + + /** + * Adds a comment to a post + * + * @param int the post ID commenting on + * @param string + * @return int the comment ID + */ + public function addComment($id, $message) { + //Argument test + Eden_Facebook_Error::i() + ->argument(1, 'int') //Argument 1 must be an integer + ->argument(2, 'string'); //Argument 2 must be a string + + //form the URL + $url = self::GRAPH_URL.$id.'/comments'; + $post = array('message' => $message); + $query = array('access_token' => $this->_token); + $url .= '?'.http_build_query($query); + $results = json_decode($this->_call($url, $post), true); + + return $results['id']; + } + + /** + * Attend an event + * + * @param int the event ID + * @return this + */ + public function attendEvent($id) { + Eden_Facebook_Error::i()->argument(1, 'int'); + + $url = self::GRAPH_URL.$id.'/attending'; + $query = array('access_token' => $this->_token); + $url .= '?'.http_build_query($query); + + json_decode($this->_call($url), true); + + return $this; + } + + /** + * Check into a place + * + * @param string|int the checkin ID + * @param string + * @param float + * @param float + * @param int the place ID + * @param string|array + * @return int + */ + public function checkin($id, $message, $latitude, $longitude, $place, $tags) { + //Argument test + Eden_Facebook_Error::i() + ->argument(1, 'string', 'int') //Argument 1 must be a string or integer + ->argument(2, 'string') //Argument 2 must be a string + ->argument(3, 'float') //Argument 3 must be a string + ->argument(4, 'float') //Argument 4 must be a string + ->argument(5, 'int') //Argument 5 must be a string + ->argument(6, 'string', 'array'); //Argument 6 must be a string + + $url = self::GRAPH_URL.$id.'/checkins'; + $post = array('message' => $message); + $query = array('access_token' => $this->_token); + $url .= '?'.http_build_query($query); + + //if message + if($message) { + //add it + $post['message'] = $message; + } + + //if coords + if($latitude && $longitute) { + //add it + $post['coordinates'] = json_encode(array( + 'latitude' => $latitude, + 'longitude' => $longitude)); + } + + //if place + if($place) { + //add it + $post['place'] = $place; + } + + //if tags + if($tags) { + //add it + $post['tags'] = $tags; + } + + $results = json_decode($this->_call($url, $post), true); + return $results['id']; + } + + /** + * Add a note + * + * @param int|string object ID where to put the note + * @param string + * @param string + * @return int + */ + public function createNote($id = 'me', $subject, $message) { + //Argument test + Eden_Facebook_Error::i() + ->argument(1, 'string', 'int') //Argument 1 must be a string or integer + ->argument(2, 'string') //Argument 2 must be a string + ->argument(3, 'string'); //Argument 3 must be a string + + //form the URL + $url = self::GRAPH_URL.$id.'/notes'; + $post = array('subject' => $subject, 'message' => $message); + $query = array('access_token' => $this->_token); + $url .= '?'.http_build_query($query); + $results = json_decode($this->_call($url, $post), true); + + return $results['id']; + } + + /** + * Decline an event + * + * @param int event ID + * @return this + */ + public function declineEvent($id) { + Eden_Facebook_Error::i()->argument(1, 'int'); + $url = self::GRAPH_URL.$id.'/declined'; + $query = array('access_token' => $this->_token); + $url .= '?'.http_build_query($query); + + json_decode($this->_call($url), true); + + return $this; + } + + /** + * Add an event + * + * @param string name of event + * @param string|int string date or time format + * @param string|int string date or time format + * @return Eden_Facebook_Event + */ + public function event($name, $start, $end) { + return Eden_Facebook_Event::i($this->_token, $name, $start, $end); + } + /** + * Returns specific fields of an object + * + * @param string|int + * @param string|array + * @return array + */ + public function getFields($id = 'me', $fields) { + //Argument test + Eden_Facebook_Error::i() + ->argument(1, 'string', 'int') //Argument 1 must be a string or int + ->argument(2, 'string', 'array'); //Argument 2 must be a string or array + + //if fields is an array + if(is_array($fields)) { + //make it into a string + $fields = implode(',', $fields); + } + + //call it + return $this->getObject($id, NULL, array('fields' => $fields)); + } + + /** + * Returns the logout URL + * + * @param string + * @return string + */ + public function getLogoutUrl($redirect) { + Eden_Facebook_Error::i()->argument(1, 'url'); + return sprintf(self::LOGOUT_URL, urlencode($redirect), $this->_token); + } + + /** + * Returns the detail of any object + * + * @param string|int + * @param string|null + * @param array + * @param bool + * @return array + */ + public function getObject($id = 'me', $connection = NULL, array $query = array(), $auth = true) { + //Argument test + Eden_Facebook_Error::i() + ->argument(1, 'string', 'int') //Argument 1 must be a string or int + ->argument(2, 'string', 'null') //Argument 2 must be a string or null + ->argument(3, 'array') //Argument 3 must be an array + ->argument(4, 'bool'); //Argument 4 must be a boolean + + //if we have a connection + if($connection) { + //prepend a slash + $connection = '/'.$connection; + } + + //for the url + $url = self::GRAPH_URL.$id.$connection; + + //if this requires authentication + if($auth) { + //add the token + $query['access_token'] = $this->_token; + } + + //if we have a query + if(!empty($query)) { + //append it to the url + $url .= '?'.http_build_query($query); + } + + //call it + $object = $this->_call($url); + $object = json_decode($object, true); + + //if there is an error + if (isset($object['error'])) { + //throw it + Eden_Facebook_Error::i() + ->setMessage(Eden_Facebook_Error::GRAPH_FAILED) + ->addVariable($url) + ->addVariable($object['error']['type']) + ->addVariable($object['error']['message']) + ->trigger(); + } + + return $object; + } + + /** + * Returns user permissions + * + * @param string|int + * @return array + */ + public function getPermissions($id = 'me') { + Eden_Facebook_Error::i()->argument(1, 'string', 'int'); + $permissions = $this->getObject($id, 'permissions'); + return $permissions['data']; + } + + /** + * Returns the user's image + * + * @param string|int + * @param bool + * @return string + */ + public function getPictureUrl($id = 'me', $token = true) { + //Argument test + Eden_Facebook_Error::i() + ->argument(1, 'string', 'int') //Argument 1 must be a string or int + ->argument(2, 'bool'); //Argument 2 must be a boolean + + //for the URL + $url = self::GRAPH_URL.$id.'/picture'; + + //if this needs a token + if($token) { + //add it + $url .= '?access_token='.$this->_token; + } + + return $url; + } + + /** + * Returns the user info + * + * @return array + */ + public function getUser() { + return $this->getObject('me'); + } + + /** + * Like an object + * + * @param int|string object ID + * @return array + */ + public function like($id) { + Eden_Facebook_Error::i()->argument(1, 'string', 'int'); + $url = self::GRAPH_URL.$id.'/likes'; + $query = array('access_token' => $this->_token); + $url .= '?'.http_build_query($query); + + $this->_call($url); + return $this; + } + + /** + * Add a link + * + * @param string + * @return Eden_Facebook_Link + */ + public function link($url) { + return Eden_Facebook_Link::i($this->_token, $url); + } + + /** + * Maybe an event + * + * @param int event ID + * @return this + */ + public function maybeEvent($id) { + Eden_Facebook_Error::i()->argument(1, 'int'); + + $url = self::GRAPH_URL.$id.'/maybe'; + $query = array('access_token' => $this->_token); + $url .= '?'.http_build_query($query); + + json_decode($this->_call($url), true); + + return $this; + } + + /** + * Returns Facebook Post + * + * @param string + * @return Eden_Facebook_Post + */ + public function post($message) { + return Eden_Facebook_Post::i($this->_token, $message); + } + + /** + * Uploads a file of your album + * + * @param int|string + * @param string + * @param string|null + * @return int photo ID + */ + public function uploadPhoto($albumId, $file, $message = NULL) { + //Argument test + Eden_Facebook_Error::i() + ->argument(1, 'string', 'int') //Argument 1 must be a string or integer + ->argument(2, 'file') //Argument 2 must be a file + ->argument(3, 'string', 'null'); //Argument 3 must be a string or null + + //form the URL + $url = self::GRAPH_URL.$albumId.'/photos'; + $post = array('source' => '@'.$file); + $query = array('access_token' => $this->_token); + + //if there is a message + if($message) { + $post['message'] = $message; + } + + $url .= '?'.http_build_query($query); + + //send it off + $results = Eden_Curl::i() + ->setUrl($url) + ->setConnectTimeout(10) + ->setFollowLocation(true) + ->setTimeout(60) + ->verifyPeer(false) + ->setUserAgent(Eden_Facebook_Auth::USER_AGENT) + ->setHeaders('Expect') + ->when(!empty($post), 2) + ->setPost(true) + ->setPostFields($post) + ->getJsonResponse(); + + return $results['id']; + } + + /** + * Subscribes to Facebook real-time updates + * + * @param $app_id string Facebook app_id (We need to get this from a different place somehow, doesn't seem right making it a variable) + * @param $object string type of Facebook object (user, permissions, page) + * @param $fields string comma-deliminated list of fields to subscribe to (e.g. "name,picture,friends,feed") + * @param $callback_url - callback-url for the real-time updates + */ + public function subscribe($app_id, $object, $fields, $callback_url) + { + Eden_Facebook_Error::i() + ->argument(1, 'string') + ->argument(2, 'string') + ->argument(3, 'string'); + + $url = self::GRAPH_URL . "{$app_id}/subscriptions"; + $query = array('access_token' => $this->_token); + $url .= '?'.http_build_query($query); + + $verify_token = sha1($app_id.$object.$callback_url); + $post = array( + 'object' => $object, + 'fields' => $fields, + 'callback_url' => $callback_url, + 'verify_token' => $verify_token + ); + + //send it off + $results = Eden_Curl::i() + ->setUrl($url) + ->setConnectTimeout(10) + ->setFollowLocation(true) + ->setTimeout(60) + ->verifyPeer(false) + ->setUserAgent(Eden_Facebook_Auth::USER_AGENT) + ->setHeaders('Expect') + ->setPost(true) + ->setPostFields($post) + ->getJsonResponse(); + + return $verify_token; + } + + /* Protected Methods + -------------------------------*/ + protected function _call($url, array $post = array()) { + return Eden_Curl::i() + ->setUrl($url) + ->setConnectTimeout(10) + ->setFollowLocation(true) + ->setTimeout(60) + ->verifyPeer(false) + ->setUserAgent(Eden_Facebook_Auth::USER_AGENT) + ->setHeaders('Expect') + ->when(!empty($post), 2) + ->setPost(true) + ->setPostFields(http_build_query($post)) + ->getResponse(); + + } + + protected function _getList($id, $connection, $start = 0, $range = 0, $since = 0, $until = 0, $dateFormat = NULL) { + $query = array(); + if($start > 0) { + $query['offset'] = $start; + } + + if($range > 0) { + $query['limit'] = $range; + } + + if(is_string($since)) { + $since = strtotime($since); + } + + if(is_string($until)) { + $until = strtotime($until); + } + + if($since !== 0) { + $query['since'] = $since; + } + + if($until !== 0) { + $query['until'] = $until; + } + + $list = $this->getObject($id, $connection, $query); + + return $list['data']; + } + + protected function _search($connection, $query, $fields = NULL) { + $query = array('type' => $connection, 'q' => $query); + + if(is_array($fields)) { + $fields = implode(',', $fields); + } + + if($fields) { + $query['fields'] = $fields; + } + + $results = $this->getObject('search', NULL, $query); + + return $results['data']; + } + + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/facebook/link.php b/library/eden/facebook/link.php new file mode 100644 index 0000000..d1385bc --- /dev/null +++ b/library/eden/facebook/link.php @@ -0,0 +1,148 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Create Facebook link + * + * @package Eden + * @category facebook + * @author Christian Blanquera cblanquera@openovate.com + */ +class Eden_Facebook_Link extends Eden_Class { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_id = 'me'; + protected $_post = array(); + + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + public function __construct($token, $url) { + //Argument 1 must be a string + Eden_Facebook_Error::i() + ->argument(1, 'string') + ->argument(2, 'url'); + + $this->_token = $token; + $this->_post = array('url' => $url); + } + + /* Public Methods + -------------------------------*/ + /** + * sends the post to facebook + * + * @return int + */ + public function create() { + //get the facebook graph url + $url = Eden_Facebook_Graph::GRAPH_URL.$this->_id.'/links'; + $query = array('access_token' => $this->_token); + $url .= '?'.http_build_query($query); + + //send it into curl + $response = Eden_Curl::i() + ->setUrl($url) //sets the url + ->setConnectTimeout(10) //sets connection timeout to 10 sec. + ->setFollowLocation(true) //sets the follow location to true + ->setTimeout(60) //set page timeout to 60 sec + ->verifyPeer(false) //verifying Peer must be boolean + ->setUserAgent(Eden_Facebook_Auth::USER_AGENT) //set facebook USER_AGENT + ->setHeaders('Expect') //set headers to EXPECT + ->setPost(true) //set post to true + ->setPostFields(http_build_query($this->_post)) //set post fields + ->getJsonResponse(); //get the json response + + return $response['id']; //return the id + } + + /** + * Sets a picture caption + * + * @param string + * @return this + */ + public function setCaption($caption){ + //Argument 1 must be a string + Eden_Facebook_Error::i()->argument(1, 'string'); + + $this->_post['caption'] = $caption; + return $this; + } + + /** + * Sets description + * + * @param string + * @return this + */ + public function setDescription($description){ + //Argument 1 must be a string + Eden_Facebook_Error::i()->argument(1, 'string'); + + $this->_post['description'] = $description; + return $this; + } + + /** + * Set the profile id + * + * @param int|string + * @return this + */ + public function setId($id) { + //Argument 1 must be a string + Eden_Facebook_Error::i()->argument(1, 'int', 'string'); + + $this->_id = $id; + return $this; + } + + /** + * Sets the link title + * + * @param string + * @return this + */ + public function setName($name){ + //Argument 1 must be a string + Eden_Facebook_Error::i()->argument(1, 'string'); + + $this->_post['name'] = $name; + return $this; + } + + /** + * Sets a picture + * + * @param string + * @return this + */ + public function setPicture($picture){ + //Argument 1 must be a string + Eden_Facebook_Error::i()->argument(1, 'url'); + + $this->_post['picture'] = $picture; + return $this; + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/facebook/post.php b/library/eden/facebook/post.php new file mode 100644 index 0000000..bc24908 --- /dev/null +++ b/library/eden/facebook/post.php @@ -0,0 +1,168 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Create Facebook post + * + * @package Eden + * @category facebook + * @author Christian Blanquera cblanquera@openovate.com + */ +class Eden_Facebook_Post extends Eden_Class { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_id = 'me'; + protected $_post = array(); + + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + public function __construct($token, $message) { + Eden_Facebook_Error::i() + ->argument(1, 'string') + ->argument(2, 'string'); + + $this->_token = $token; + $this->_message = $message; + } + + /* Public Methods + -------------------------------*/ + /** + * sends the post to facebook + * + * @return this + */ + public function create() { + //get the facebook graph url + $url = Eden_Facebook_Graph::GRAPH_URL.$this->_id.'/feed'; + $query = array('access_token' => $this->_token); + $url .= '?'.http_build_query($query); + + //send it into curl + $response = Eden_Curl::i() + ->setUrl($url) //sets the url + ->setConnectTimeout(10) //sets connection timeout to 10 sec. + ->setFollowLocation(true) //sets the follow location to true + ->setTimeout(60) //set page timeout to 60 sec + ->verifyPeer(false) //verifying Peer must be boolean + ->setUserAgent(Eden_Facebook_Auth::USER_AGENT) //set facebook USER_AGENT + ->setHeaders('Expect') //set headers to EXPECT + ->setPost(true) //set post to true + ->setPostFields(http_build_query($this->_post)) //set post fields + ->getJsonResponse(); //get the json response + + return $response['id']; //return the id + } + + /** + * Sets media description + * + * @param string + * @return this + */ + public function setDescription($description){ + //Argument 1 must be a string + Eden_Facebook_Error::i()->argument(1, 'string'); + + $this->_post['description'] = $description; + return $this; + } + + /** + * Sets anicon for this post + * + * @param string + * @return this + */ + public function setIcon($url){ + //Argument 1 must be a string + Eden_Facebook_Error::i()->argument(1, 'url'); + + $this->_post['icon'] = $url; + return $this; + } + + public function setId($id) { + Eden_Facebook_Error::i()->argument(1, 'numeric'); + + $this->_id = $id; + return $this; + } + + /** + * sets the link to your post + * + * @param string + * @return this + */ + public function setLink($url) { + //Argument 1 must be a string + Eden_Facebook_Error::i()->argument(1, 'url'); + + $this->_post['link'] = $url; + return $this; + } + + /** + * sets the picture to your post + * + * @param string + * @return this + */ + public function setPicture($url) { + //Argument 1 must be a string + Eden_Facebook_Error::i()->argument(1, 'url'); + + $this->_post['picture'] = $url; + return $this; + } + + /** + * Sets the title of a post + * + * @param string + * @return this + */ + public function setTitle($title){ + //Argument 1 must be a string + Eden_Facebook_Error::i()->argument(1, 'string'); + + $this->_post['title'] = $title; + return $this; + } + + /** + * sets the video to your post + * + * @param string + * @return this + */ + public function setVideo($url) { + //Argument 1 must be a string + Eden_Facebook_Error::i()->argument(1, 'url'); + + $this->_post['video'] = $url; + return $this; + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/facebook/search.php b/library/eden/facebook/search.php new file mode 100644 index 0000000..67ff821 --- /dev/null +++ b/library/eden/facebook/search.php @@ -0,0 +1,366 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Facebook Search + * + * @package Eden + * @category sql + * @author Christian Blanquera cblanquera@openovate.com + */ +class Eden_Facebook_Search extends Eden_Class { + /* Constants + -------------------------------*/ + const ASC = 'ASC'; + const DESC = 'DESC'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_database = NULL; + protected $_table = NULL; + protected $_columns = array(); + protected $_filter = array(); + protected $_sort = array(); + protected $_start = 0; + protected $_range = 0; + + protected $_group = array(); + + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + public function __call($name, $args) { + if(strpos($name, 'filterBy') === 0) { + //filterByUserName('Chris', '-') + $separator = '_'; + if(isset($args[1]) && is_scalar($args[1])) { + $separator = (string) $args[1]; + } + + $key = Eden_Type_String::i($name) + ->substr(8) + ->preg_replace("/([A-Z])/", $separator."$1") + ->substr(strlen($separator)) + ->strtolower() + ->get(); + + if(!isset($args[0])) { + $args[0] = NULL; + } + + $key = $key.'=%s'; + + $this->addFilter($key, $args[0]); + + return $this; + } + + if(strpos($name, 'sortBy') === 0) { + //filterByUserName('Chris', '-') + $separator = '_'; + if(isset($args[1]) && is_scalar($args[1])) { + $separator = (string) $args[1]; + } + + $key = Eden_Type_String::i($name) + ->substr(6) + ->preg_replace("/([A-Z])/", $separator."$1") + ->substr(strlen($separator)) + ->strtolower() + ->get(); + + if(!isset($args[0])) { + $args[0] = self::ASC; + } + + $this->addSort($key, $args[0]); + + return $this; + } + + try { + return parent::__call($name, $args); + } catch(Eden_Error $e) { + Eden_Facebook_Error::i($e->getMessage())->trigger(); + } + } + + public function __construct(Eden_Facebook_Fql $database) { + $this->_database = $database; + } + + /* Public Methods + -------------------------------*/ + /** + * Adds filter + * + * @param string + * @param string[,string..] + * @return this + */ + public function addFilter() { + Eden_Facebook_Error::i()->argument(1, 'string'); + + $this->_filter[] = func_get_args(); + + return $this; + } + + /** + * Adds sort + * + * @param string + * @param string + * @return this + */ + public function addSort($column, $order = self::ASC) { + Eden_Facebook_Error::i() + ->argument(1, 'string') + ->argument(2, 'string'); + + if($order != self::DESC) { + $order = self::ASC; + } + + $this->_sort[$column] = $order; + + return $this; + } + + /** + * Returns the results in a collection + * + * @return Eden_Facebook_Collection + */ + public function getCollection($key = 'last') { + $rows = $this->getRows($key); + + if(count($this->_group) == 1) { + return Eden_Collection::i($rows); + } + + foreach($rows as $key => $collection) { + $rows[$key] = Eden_Collection::i($collection['fql_result_set']); + } + + return $rows; + } + + /** + * Returns the array rows + * + * @return array + */ + public function getRows($key = 'last') { + $this->group($key); + + if(empty($this->_group)) { + return array(); + } + + $group = array(); + foreach($this->_group as $key => $query) { + $this->_table = $query['table']; + $this->_columns = $query['columns']; + $this->_filter = $query['filter']; + $this->_sort = $query['sort']; + $this->_start = $query['start']; + $this->_range = $query['range']; + + $query = $this->_getQuery(); + + if(!empty($this->_columns)) { + $query->select(implode(', ', $this->_columns)); + } + + foreach($this->_sort as $name => $value) { + $query->sortBy($name, $value); + } + + if($this->_range) { + $query->limit($this->_start, $this->_range); + } + + $group[$key] = $query; + } + + $query = $group; + + if(count($query) == 1) { + $query = $group[$key]; + } + + $results = $this->_database->query($query); + return $results; + } + + /** + * Returns the total results + * + * @return int + */ + public function getTotal() { + $query = $this->_getQuery()->select('COUNT(*) as total'); + + $rows = $this->_database->query($query); + + if(!isset($rows[0]['total'])) { + return 0; + } + + return $rows[0]['total']; + } + + /** + * Stores this search and resets class. + * Useful for multiple queries. + * + * @param scalar + * @return this + */ + public function group($key) { + Eden_Facebook_Error::i()->argument(1, 'scalar'); + if(is_null($this->_table)) { + return $this; + } + + $this->_group[$key] = array( + 'table' => $this->_table, + 'columns' => $this->_columns, + 'filter' => $this->_filter, + 'sort' => $this->_sort, + 'start' => $this->_start, + 'range' => $this->_range); + + $this->_table = NULL; + $this->_columns = array(); + $this->_filter = array(); + $this->_sort = array(); + $this->_start = 0; + $this->_range = 0; + + return $this; + } + + /** + * Sets Columns + * + * @param string[,string..]|array + * @return this + */ + public function setColumns($columns) { + if(!is_array($columns)) { + $columns = func_get_args(); + } + + $this->_columns = $columns; + + return $this; + } + + /** + * Sets the pagination page + * + * @param int + * @return this + */ + public function setPage($page) { + Eden_Facebook_Error::i()->argument(1, 'int'); + + if($page < 1) { + $page = 1; + } + + $this->_start = ($page - 1) * $this->_range; + + return $this; + } + + /** + * Sets the pagination range + * + * @param int + * @return this + */ + public function setRange($range) { + Eden_Facebook_Error::i()->argument(1, 'int'); + + if($range < 0) { + $range = 25; + } + + $this->_range = $range; + + return $this; + } + + /** + * Sets the pagination start + * + * @param int + * @return this + */ + public function setStart($start) { + Eden_Facebook_Error::i()->argument(1, 'int'); + + if($start < 0) { + $start = 0; + } + + $this->_start = $start; + + return $this; + } + + /** + * Sets Table + * + * @param string + * @return this + */ + public function setTable($table) { + Eden_Facebook_Error::i()->argument(1, 'string'); + $this->_table = $table; + return $this; + } + + /* Protected Methods + -------------------------------*/ + protected function _getQuery() { + $query = $this->_database->select()->from($this->_table); + + foreach($this->_filter as $i => $filter) { + //array('post_id=%s AND post_title IN %s', 123, array('asd')); + $where = array_shift($filter); + if(!empty($filter)) { + foreach($filter as $i => $value) { + if(!is_string($value)) { + continue; + } + $filter[$i] = "'".$value."'"; + } + $where = vsprintf($where, $filter); + } + + $query->where($where); + } + + return $query; + } + + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/facebook/select.php b/library/eden/facebook/select.php new file mode 100644 index 0000000..d5b5fd0 --- /dev/null +++ b/library/eden/facebook/select.php @@ -0,0 +1,459 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Generates select query string syntax + * + * @package Eden + * @category sql + * @author Christian Blanquera cblanquera@openovate.com + */ +class Eden_Facebook_Select extends Eden_Class { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_select = NULL; + protected $_from = NULL; + protected $_where = array(); + protected $_sortBy = array(); + protected $_page = NULL; + protected $_length = NULL; + + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + public function __toString() { + return $this->getQuery(); + } + + /* Public Methods + -------------------------------*/ + + /** + * From clause + * + * @param string from + * @return this + * @notes loads from phrase into registry + */ + public function from($from) { + //Argument 1 must be a string + Eden_Facebook_Error::i()->argument(1, 'string'); + + $this->_from = $from; + return $this; + } + + /** + * Limit clause + * + * @param string|int page + * @param string|int length + * @return this + * @notes loads page and length into registry + */ + public function limit($page, $length) { + //argument test + Eden_Facebook_Error::i() + ->argument(1, 'numeric') //Argument 1 must be a number + ->argument(2, 'numeric'); //Argument 2 must be a number + + $this->_page = $page; + $this->_length = $length; + + return $this; + } + + /** + * Returns the string version of the query + * + * @param bool + * @return string + * @notes returns the query based on the registry + */ + public function getQuery() { + $where = empty($this->_where) ? '' : 'WHERE '.implode(' AND ', $this->_where); + $sort = empty($this->_sortBy) ? '' : 'ORDER BY '.implode(', ', $this->_sortBy); + $limit = is_null($this->_page) ? '' : 'LIMIT ' . $this->_page .',' .$this->_length; + + if(empty($this->_select) || $this->_select == '*') { + $this->_select = implode(', ', self::$_columns[$this->_from]); + } + + $query = sprintf( + 'SELECT %s FROM %s %s %s %s;', + $this->_select, $this->_from, + $where, $sort, $limit); + + return str_replace(' ', ' ', $query); + } + + /** + * Select clause + * + * @param string select + * @return this + * @notes loads select phrase into registry + */ + public function select($select = '*') { + //Argument 1 must be a string or array + Eden_Facebook_Error::i()->argument(1, 'string', 'array'); + + //if select is an array + if(is_array($select)) { + //transform into a string + $select = implode(', ', $select); + } + + $this->_select = $select; + + return $this; + } + + /** + * Order by clause + * + * @param string field + * @param string order + * @return this + * @notes loads field and order into registry + */ + public function sortBy($field, $order = 'ASC') { + //argument test + Eden_Facebook_Error::i() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'string'); //Argument 2 must be a string + + $this->_sortBy[] = $field . ' ' . $order; + + return $this; + } + + /** + * Where clause + * + * @param array|string where + * @return this + * @notes loads a where phrase into registry + */ + public function where($where) { + //Argument 1 must be a string or array + Eden_Facebook_Error::i()->argument(1, 'string', 'array'); + + if(is_string($where)) { + $where = array($where); + } + + $this->_where = array_merge($this->_where, $where); + + return $this; + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ + /* Large Data + -------------------------------*/ + protected static $_columns = array( + 'album' => array( + 'aid', 'object_id', 'owner', + 'cover_pid', 'cover_object_id', 'name', + 'created', 'modified', 'description', + 'location', 'size', 'link', + 'visible', 'modified_major', 'edit_link', + 'type', 'can_upload', 'photo_count', + 'video_count'), + 'application' => array( + 'app_id', 'api_key', + 'canvas_name', 'display_name', + 'icon_url', 'logo_url', + 'company_name', 'developers', + 'description', 'daily_active_users', + 'weekly_active_users', 'monthly_active_users', + 'category', 'subcategory', + 'is_facebook_app', 'restriction_info', + 'app_domains', 'auth_dialog_data_help_url', + 'auth_dialog_description', 'auth_dialog_headline', + 'auth_dialog_perms_explanation', 'auth_referral_user_perms', + 'auth_referral_friend_perms', 'auth_referral_default_activity_privacy', + 'auth_referral_enabled', 'auth_referral_extended_perms', + 'auth_referral_response_type', 'canvas_fluid_height', + 'canvas_fluid_width', 'canvas_url', + 'contact_email', 'created_time', + 'creator_uid', 'deauth_callback_url', + 'iphone_app_store_id', 'hosting_url', + 'mobile_web_url', 'page_tab_default_name', + 'page_tab_url', 'privacy_policy_url', + 'secure_canvas_url', 'secure_page_tab_url', + 'server_ip_whitelist', 'social_discovery', + 'terms_of_service_url', 'update_ip_whitelist', + 'user_support_email', 'user_support_url', + 'website_url'), + 'apprequest' => array( + 'request_id', 'app_id', 'recipient_uid', + 'sender_uid', 'message', 'data', + 'created_time'), + 'checkin' => array( + 'checkin_id', 'author_uid', 'page_id', + 'app_id', 'post_id', 'coords', + 'timestamp', 'tagged_uids', 'message'), + 'comment' => array( + 'xid', 'object_id', 'post_id', + 'fromid', 'time', 'text', + 'id', 'username ', 'reply_xid', + 'post_fbid', 'app_id', 'likes', + 'comments', 'user_likes', 'is_private'), + 'comments_info' => array( + 'app_id', 'xid', + 'count', 'updated_time'), + 'connection' => array( + 'source_id', 'target_id', + 'target_type', 'is_following'), + 'cookies' => array( + 'uid', 'name', 'value', + 'expires', 'path'), + 'developer' => array('developer_id', 'application_id', 'role'), + 'domain' => array('domain_id', 'domain_name'), + 'domain_admin' => array('owner_id', 'domain_id'), + 'event' => array( + 'eid', 'name', 'tagline', + 'nid', 'pic_small', 'pic_big', + 'pic_square', 'pic', 'host', + 'description', 'event_type', 'event_subtype', + 'start_time', 'end_time', 'creator', + 'update_time', 'location', 'venue', + 'privacy', 'hide_guest_list', 'can_invite_friends'), + 'event_member' => array( + 'uid', 'eid', + 'rsvp_status', 'start_time'), + 'family' => array( + 'profile_id', 'uid', + 'name', 'birthday', + 'relationship'), + 'friend' => array('uid1', 'uid2'), + 'friend_request' => array( + 'uid_to', 'uid_from', + 'time', 'message', + 'unread'), + 'friendlist' => array('owner', 'flid', 'name'), + 'friendlist_member' => array('flid', 'uid'), + 'group' => array( + 'gid', 'name', 'nid', + 'pic_small', 'pic_big', 'pic', + 'description', 'group_type', 'group_subtype', + 'recent_news', 'creator', 'update_time', + 'office', 'website', 'venue', + 'privacy', 'icon', 'icon34', + 'icon68', 'email', 'version'), + 'group_member' => array( + 'uid', 'gid', 'administrator', + 'positions', 'unread', 'bookmark_order'), + 'insights' => array('object_id', 'metric', 'end_time', 'period', 'value'), + 'like' => array('object_id', 'post_id', 'user_id', 'object_type'), + 'link' => array( + 'link_id', 'owner', 'owner_comment', + 'created_time', 'title', 'summary', + 'url', 'picture', 'image_urls'), + 'link_stat' => array( + 'url', 'normalized_url', 'share_count', + 'like_count', 'comment_count', 'total_count', + 'click_count', 'comments_fbid', 'commentsbox_count'), + 'mailbox_folder' => array( + 'folder_id', 'viewer_id', 'name', + 'unread_count', 'total_count'), + 'message' => array( + 'message_id', 'thread_id', 'author_id', + 'body', 'created_time', 'attachment', + 'viewer_id'), + 'note' => array( + 'uid', 'note_id', 'created_time', + 'updated_time', 'content', 'content_html', + 'title'), + 'notification' => array( + 'notification_id', 'sender_id', 'recipient_id', + 'created_time', 'updated_time', 'title_html', + 'title_text', 'body_html', 'body_text', + 'href', 'app_id', 'is_unread', + 'is_hidden', 'object_id', 'object_type', + 'icon_url'), + 'object_url' => array( + 'url', 'id', + 'type', 'site'), + 'page' => array( + 'page_id', 'name', 'username', + 'description', 'categories', 'is_community_page', + 'pic_small', 'pic_big', 'pic_square', + 'pic', 'pic_large', 'page_url', + 'fan_count', 'type', 'website', + 'has_added_app', 'general_info', 'can_post', + 'checkins', 'founded', 'company_overview', + 'mission', 'products', 'location', + 'parking', 'hours', 'pharma_safety_info', + 'public_transit', 'attire', 'payment_options', + 'culinary_team', 'general_manager', 'price_range', + 'restaurant_services', 'restaurant_specialties', 'phone', + 'release_date', 'genre', 'starring', + 'screenplay_by', 'directed_by', 'produced_by', + 'studio', 'awards', 'plot_outline', + 'season', 'network', 'schedule', + 'written_by', 'band_members', 'hometown', + 'current_location', 'record_label', 'booking_agent', + 'press_contact', 'artists_we_like', 'influences', + 'band_interests', 'bio', 'affiliation', + 'birthday', 'personal_info', 'personal_interests', + 'built', 'features', 'mpg'), + 'page_admin' => array('uid', 'page_id', 'type'), + 'page_blocked_user' => array('page_id', 'uid'), + 'page_fan' => array( + 'uid', 'page_id', + 'type', 'profile_section', + 'created_time'), + 'permissions' => array('uid', 'PERMISSION_NAME'), + 'permissions_info' => array('permission_name', 'header', 'summary'), + 'photo' => array( + 'pid', 'aid', 'owner', + 'src_small', 'src_small_width', 'src_small_height', + 'src_big', 'src_big_width', 'src_big_height', + 'src', 'src_width', 'src_height', + 'link', 'caption', 'created', + 'modified', 'position', 'object_id', + 'album_object_id', 'images'), + 'photo_tag' => array( + 'pid', 'subject', 'object_id', + 'text', 'xcoord', 'ycoord', + 'created'), + 'place' => array( + 'page_id', 'name', 'description', + 'geometry', 'latitude', 'longitude', + 'checkin_count', 'display_subtext'), + 'privacy' => array( + 'id', 'object_id', 'value ', + 'description', 'allow', 'deny', + 'owner_id', 'networks', 'friends'), + 'privacy_setting' => array( + 'name', 'value ', 'description', + 'allow', 'deny', 'networks', + 'friends'), + 'profile' => array( + 'id', 'can_post', 'name', + 'url', 'pic', 'pic_square', + 'pic_small', 'pic_big', 'pic_crop', + 'type', 'username'), + 'question' => array( + 'id', 'owner', 'question', + 'created_time', 'updated_time'), + 'question_option' => array( + 'id', 'question_id', 'name', + 'votes', 'object_id', 'owner', + 'created_time'), + 'question_option_votes' => array('option_id', 'voter_id'), + 'review' => array( + 'reviewee_id', 'reviewer_id', 'review_id', + 'message', 'created_time', 'rating'), + 'standard_friend_info' => array('uid1', 'uid2'), + 'standard_user_info' => array( + 'uid', 'name', 'username', + 'third_party_id', 'first_name', 'last_name', + 'locale', 'affiliations', 'profile_url', + 'timezone', 'birthday', 'sex', + 'proxied_email', 'current_location', 'allowed_restrictions'), + 'status' => array( + 'uid', 'status_id', + 'time', 'source', + 'message'), + 'stream' => array( + 'post_id', 'viewer_id ', 'app_id', + 'source_id ', 'updated_time', 'created_time', + 'filter_key', 'attribution ', 'actor_id', + 'target_id', 'message', 'app_data', + 'action_links', 'attachment', 'impressions', + 'comments', 'likes', 'privacy', + 'permalink', 'xid', 'tagged_ids', + 'message_tags', 'description', 'description_tags'), + 'stream_filter' => array( + 'uid', 'filter_key ', 'name', + 'rank ', 'icon_url', 'is_visible', + 'type', 'value'), + 'stream_tag' => array('post_id', 'actor_id', 'target_id'), + 'thread' => array( + 'thread_id', 'folder_id', 'subject', + 'recipients', 'updated_time', 'parent_message_id', + 'parent_thread_id', 'message_count', 'snippet', + 'snippet_author', 'object_id', 'unread', + 'viewer_id'), + 'translation' => array( + 'locale', 'native_hash', 'native_string', + 'description', 'translation', 'approval_status', + 'pre_hash_string', 'best_string'), + 'unified_message' => array( + 'message_id', 'thread_id', 'subject', + 'body', 'unread', 'action_id', + 'timestamp', 'tags', 'sender', + 'recipients', 'object_sender', 'html_body', + 'attachments', 'attachment_map', 'shares', + 'share_map'), + 'unified_thread' => array( + 'action_id', 'archived', 'can_reply', + 'folder', 'former_participants', 'has_attachments', + 'is_subscribed', 'last_visible_add_action_id', 'name', + 'num_messages', 'num_unread', 'object_participants', + 'participants', 'senders', 'single_recipient', + 'snippet', 'snippet_sender', 'snippet_message_has_attachment', + 'subject', 'tags', 'thread_id', + 'thread_participants', 'timestamp', 'unread'), + 'unified_thread_action' => array( + 'action_id', 'actor', 'thread_id', + 'timestamp', 'type', 'users'), + 'unified_thread_count' => array( + 'folder', 'unread_count', 'unseen_count', + 'last_action_id', 'last_seen_time', 'total_threads'), + 'url_like' => array('user_id', 'url'), + 'user' => array( + 'uid', 'username', 'first_name', + 'middle_name', 'last_name', 'name', + 'pic_small', 'pic_big', 'pic_square', + 'pic', 'affiliations', 'profile_update_time', + 'timezone', 'religion', 'birthday', + 'birthday_date', 'sex', 'hometown_location', + 'meeting_sex', 'meeting_for', 'relationship_status', + 'significant_other_id', 'political', 'current_location', + 'activities', 'interests', 'is_app_user', + 'music', 'tv', 'movies', + 'books', 'quotes', 'about_me', + 'hs_info', 'education_history', 'work_history', + 'notes_count', 'wall_count', 'status', + 'has_added_app', 'online_presence', 'locale', + 'proxied_email', 'profile_url', 'email_hashes', + 'pic_small_with_logo', 'pic_big_with_logo', 'pic_square_with_logo', + 'pic_with_logo', 'allowed_restrictions', 'verified', + 'profile_blurb', 'family', 'website', + 'is_blocked', 'contact_email', 'email', + 'third_party_id', 'name_format', 'video_upload_limits', + 'games', 'is_minor', 'work', + 'education', 'sports', 'favorite_athletes', + 'favorite_teams', 'inspirational_people', 'languages', + 'likes_count', 'friend_count', 'mutual_friend_count', + 'can_post'), + 'video' => array( + 'vid', 'owner', 'album_id', + 'title', 'description', 'link', + 'thumbnail_link', 'embed_html', 'updated_time', + 'created_time', 'length', 'src', + 'src_hq'), + 'video_tag' => array('vid', 'subject', 'updated_time', 'created_time')); +} \ No newline at end of file diff --git a/library/eden/file.php b/library/eden/file.php new file mode 100644 index 0000000..ff7c985 --- /dev/null +++ b/library/eden/file.php @@ -0,0 +1,370 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +require_once dirname(__FILE__).'/path.php'; + +/** + * General available methods for common file + * manipulations and information per file + * + * @package Eden + * @category path + * @author Christian Blanquera cblanquera@openovate.com + */ +class Eden_File extends Eden_Path { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_path = NULL; + + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + /* Public Methods + -------------------------------*/ + /** + * Checks to see if this + * path is a real file + * + * @return bool + */ + public function isFile() { + return file_exists($this->_data); + } + + /** + * Returns the base file name with out the extension + * + * @return string + */ + public function getBase() { + $pathInfo = pathinfo($this->_data); + return $pathInfo['filename']; + } + + /** + * Returns the contents of a file given the path + * + * @param var default value if no file is found + * @return string + */ + public function getContent() { + $this->absolute(); + + //if the pat is not a real file + if(!is_file($this->_data)) { + //throw an exception + Eden_File_Error::i() + ->setMessage(Eden_File_Error::PATH_IS_NOT_FILE) + ->addVariable($this->_data) + ->trigger(); + } + + return file_get_contents($this->_data); + } + + /** + * Returns the executes the specified file and returns the final value + * + * @return * + */ + public function getData() { + $this->absolute(); + + return include($this->_data); + } + + /** + * Returns the base file name extension + * + * @return string + */ + public function getExtension() { + $pathInfo = pathinfo($this->_data); + + if(!isset($pathInfo['extension'])) { + return NULL; + } + + return $pathInfo['extension']; + } + + /** + * Returns the file path + * + * @return string + */ + public function getFolder() { + return dirname($this->_data); + } + + /** + * Returns the mime type of a file + * + * @return string + */ + public function getMime() { + $this->absolute(); + + //mime_content_type seems to be deprecated in some versions of PHP + //if it does exist then lets use it + if(function_exists('mime_content_type')) { + return mime_content_type($this->_data); + } + + //if not then use the replacement funciton fileinfo + //see: http://www.php.net/manual/en/function.finfo-file.php + if(function_exists('finfo_open')) { + $resource = finfo_open(FILEINFO_MIME_TYPE); + $mime = finfo_file($resource, $this->_data); + finfo_close($finfo); + + return $mime; + } + + //ok we have to do this manually + //get this file extension + $extension = strtolower($this->getExtension()); + + //get the list of mimetypes stored locally + $types = self::$_mimeTypes; + //if this extension exissts in the types + if(isset($types[$extension])) { + //return the mimetype + return $types[$extension]; + } + + //return text/plain by default + return $types['class']; + } + + /** + * Returns the file name + * + * @return string + */ + public function getName() { + return basename($this->_data); + } + + /** + * Returns the size of a file in bytes + * + * @return string + */ + public function getSize() { + $this->absolute(); + + return filesize($this->_data); + } + + /** + * Returns the last time file was modified in UNIX time + * + * @return int + */ + public function getTime() { + $this->absolute(); + + return filemtime($this->_data); + } + + /** + * Creates a file and puts specified content into that file + * + * @param string content + * @return bool + */ + public function setContent($content) { + //argument 1 must be string + Eden_File_Error::i()->argument(1, 'string'); + + try { + $this->absolute(); + } catch(Eden_Path_Error $e) { + $this->touch(); + } + + file_put_contents($this->_data, $content); + + return $this; + } + + /** + * Creates a php file and puts specified variable into that file + * + * @param string variable + * @return bool + */ + public function setData($variable) { + return $this->setContent("\nreturn ".var_export($variable, true).";"); + } + + /** + * Removes a file + * + * @return bool + */ + public function remove() { + $this->absolute(); + + //if it's a file + if(is_file($this->_data)) { + //remove it + unlink($this->_data); + + return $this; + } + + return $this; + } + + /** + * Touches a file (effectively creates the file if + * it doesn't exist and updates the date if it does) + * + * @return bool + */ + public function touch() { + touch($this->_data); + + return $this; + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ + /* Large Data + -------------------------------*/ + protected static $_mimeTypes = array( + 'ai' => 'application/postscript', 'aif' => 'audio/x-aiff', + 'aifc' => 'audio/x-aiff', 'aiff' => 'audio/x-aiff', + 'asc' => 'text/plain', 'atom' => 'application/atom+xml', + 'au' => 'audio/basic', 'avi' => 'video/x-msvideo', + 'bcpio' => 'application/x-bcpio', 'bin' => 'application/octet-stream', + 'bmp' => 'image/bmp', 'cdf' => 'application/x-netcdf', + 'cgm' => 'image/cgm', 'class' => 'application/octet-stream', + 'cpio' => 'application/x-cpio', 'cpt' => 'application/mac-compactpro', + 'csh' => 'application/x-csh', 'css' => 'text/css', + 'dcr' => 'application/x-director', 'dif' => 'video/x-dv', + 'dir' => 'application/x-director', 'djv' => 'image/vnd.djvu', + 'djvu' => 'image/vnd.djvu', 'dll' => 'application/octet-stream', + 'dmg' => 'application/octet-stream', 'dms' => 'application/octet-stream', + 'doc' => 'application/msword', 'dtd' => 'application/xml-dtd', + 'dv' => 'video/x-dv', 'dvi' => 'application/x-dvi', + 'dxr' => 'application/x-director', 'eps' => 'application/postscript', + 'etx' => 'text/x-setext', 'exe' => 'application/octet-stream', + 'ez' => 'application/andrew-inset', 'gif' => 'image/gif', + 'gram' => 'application/srgs', 'grxml' => 'application/srgs+xml', + 'gtar' => 'application/x-gtar', 'hdf' => 'application/x-hdf', + 'hqx' => 'application/mac-binhex40', 'htm' => 'text/html', + 'html' => 'text/html', 'ice' => 'x-conference/x-cooltalk', + 'ico' => 'image/x-icon', 'ics' => 'text/calendar', + 'ief' => 'image/ief', 'ifb' => 'text/calendar', + 'iges' => 'model/iges', 'igs' => 'model/iges', + 'jnlp' => 'application/x-java-jnlp-file', 'jp2' => 'image/jp2', + 'jpe' => 'image/jpeg', 'jpeg' => 'image/jpeg', + 'jpg' => 'image/jpeg', 'js' => 'application/x-javascript', + 'kar' => 'audio/midi', 'latex' => 'application/x-latex', + 'lha' => 'application/octet-stream', 'lzh' => 'application/octet-stream', + 'm3u' => 'audio/x-mpegurl', 'm4a' => 'audio/mp4a-latm', + 'm4b' => 'audio/mp4a-latm', 'm4p' => 'audio/mp4a-latm', + 'm4u' => 'video/vnd.mpegurl', 'm4v' => 'video/x-m4v', + 'mac' => 'image/x-macpaint', 'man' => 'application/x-troff-man', + 'mathml' => 'application/mathml+xml', 'me' => 'application/x-troff-me', + 'mesh' => 'model/mesh', 'mid' => 'audio/midi', + 'midi' => 'audio/midi', 'mif' => 'application/vnd.mif', + 'mov' => 'video/quicktime', 'movie' => 'video/x-sgi-movie', + 'mp2' => 'audio/mpeg', 'mp3' => 'audio/mpeg', + 'mp4' => 'video/mp4', 'mpe' => 'video/mpeg', + 'mpeg' => 'video/mpeg', 'mpg' => 'video/mpeg', + 'mpga' => 'audio/mpeg', 'ms' => 'application/x-troff-ms', + 'msh' => 'model/mesh', 'mxu' => 'video/vnd.mpegurl', + 'nc' => 'application/x-netcdf', 'oda' => 'application/oda', + 'ogg' => 'application/ogg', 'pbm' => 'image/x-portable-bitmap', + 'pct' => 'image/pict', 'pdb' => 'chemical/x-pdb', + 'pdf' => 'application/pdf', 'pgm' => 'image/x-portable-graymap', + 'pgn' => 'application/x-chess-pgn', 'pic' => 'image/pict', + 'pict' => 'image/pict', 'png' => 'image/png', + 'pnm' => 'image/x-portable-anymap', 'pnt' => 'image/x-macpaint', + 'pntg' => 'image/x-macpaint', 'ppm' => 'image/x-portable-pixmap', + 'ppt' => 'application/vnd.ms-powerpoint', 'ps' => 'application/postscript', + 'qt' => 'video/quicktime', 'qti' => 'image/x-quicktime', + 'qtif' => 'image/x-quicktime', 'ra' => 'audio/x-pn-realaudio', + 'ram' => 'audio/x-pn-realaudio', 'ras' => 'image/x-cmu-raster', + 'rdf' => 'application/rdf+xml', 'rgb' => 'image/x-rgb', + 'rm' => 'application/vnd.rn-realmedia', 'roff' => 'application/x-troff', + 'rtf' => 'text/rtf', 'rtx' => 'text/richtext', + 'sgm' => 'text/sgml', 'sgml' => 'text/sgml', + 'sh' => 'application/x-sh', 'shar' => 'application/x-shar', + 'silo' => 'model/mesh', 'sit' => 'application/x-stuffit', + 'skd' => 'application/x-koan', 'skm' => 'application/x-koan', + 'skp' => 'application/x-koan', 'skt' => 'application/x-koan', + 'smi' => 'application/smil', 'smil' => 'application/smil', + 'snd' => 'audio/basic', 'so' => 'application/octet-stream', + 'spl' => 'application/x-futuresplash', 'src' => 'application/x-wais-source', + 'sv4cpio' => 'application/x-sv4cpio', 'sv4crc' => 'application/x-sv4crc', + 'svg' => 'image/svg+xml', 'swf' => 'application/x-shockwave-flash', + 't' => 'application/x-troff', 'tar' => 'application/x-tar', + 'tcl' => 'application/x-tcl', 'tex' => 'application/x-tex', + 'texi' => 'application/x-texinfo', 'texinfo' => 'application/x-texinfo', + 'tif' => 'image/tiff', 'tiff' => 'image/tiff', + 'tr' => 'application/x-troff', 'tsv' => 'text/tab-separated-values', + 'txt' => 'text/plain', 'ustar' => 'application/x-ustar', + 'vcd' => 'application/x-cdlink', 'vrml' => 'model/vrml', + 'vxml' => 'application/voicexml+xml', 'wav' => 'audio/x-wav', + 'wbmp' => 'image/vnd.wap.wbmp', 'wbmxl' => 'application/vnd.wap.wbxml', + 'wml' => 'text/vnd.wap.wml', 'wmlc' => 'application/vnd.wap.wmlc', + 'wmls' => 'text/vnd.wap.wmlscript', 'wmlsc' => 'application/vnd.wap.wmlscriptc', + 'wrl' => 'model/vrml', 'xbm' => 'image/x-xbitmap', + 'xht' => 'application/xhtml+xml', 'xhtml' => 'application/xhtml+xml', + 'xls' => 'application/vnd.ms-excel', 'xml' => 'application/xml', + 'xpm' => 'image/x-xpixmap', 'xsl' => 'application/xml', + 'xslt' => 'application/xslt+xml', 'xul' => 'application/vnd.mozilla.xul+xml', + 'xwd' => 'image/x-xwindowdump', 'xyz' => 'chemical/x-xyz', + 'zip' => 'application/zip'); +} + +/** + * File Errors + */ +class Eden_File_Error extends Eden_Path_Error { + /* Constants + -------------------------------*/ + const PATH_IS_NOT_FILE = 'Path %s is not a file in the system.'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i($message = NULL, $code = 0) { + $class = __CLASS__; + return new $class($message, $code); + } + + /* Public Methods + -------------------------------*/ + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/folder.php b/library/eden/folder.php new file mode 100644 index 0000000..b700383 --- /dev/null +++ b/library/eden/folder.php @@ -0,0 +1,288 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +require_once dirname(__FILE__).'/path.php'; + +/** + * This is an abstract definition of common + * folder manipulation listing and information + * per folder. + * + * @package Eden + * @category path + * @author Christian Blanquera cblanquera@openovate.com + */ +class Eden_Folder extends Eden_Path { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + /* Public Methods + -------------------------------*/ + /** + * Creates a folder given the path + * + * @param int chmod + * @return this + */ + public function create($chmod = 0755) { + //if chmod is not and integer or not between 0 and 777 + if(!is_int($chmod) || $chmod < 0 || $chmod > 777) { + //throw an error + Eden_Folder_Error::i(Eden_Folder_Exception::CHMOD_IS_INVALID)->trigger(); + } + + //if it's not a directory + if(!is_dir($this->_data)) { + //then make it + mkdir($this->_data, $chmod, true); + } + + return $this; + } + + /** + * Returns a list of files given the path and optionally the pattern + * + * @param string regular expression + * @return array + */ + public function getFiles($regex = NULL, $recursive = false) { + //argument test + $error = Eden_Folder_Error::i() + ->argument(1, 'string', 'null') //argument 1 must be a string + ->argument(2, 'bool'); //argument 2 must be a boolean + + $this->absolute(); + + $files = array(); + + if ($handle = opendir($this->_data)) { + //for each file + while (false !== ($file = readdir($handle))) { + // If this is infact a file + if(filetype($this->_data . '/' . $file) == 'file' + && (!$regex || preg_match($regex, $file))) { + //add it + $files[] = Eden_File::i($this->_data . '/' . $file); + // recursive and this is infact a directory + } else if($recursive && $file != '.' && $file != '..' + && filetype($this->_data .'/'. $file) == 'dir') { + $subfiles = self::i($this->_data.'/'.$file); + $files = array_merge($files, $subfiles->getFiles($regex, $recursive)); + } + } + + closedir($handle); + } + + return $files; + } + + /** + * Returns a list of folders given the path and optionally the regular expression + * + * @param string regular expression + * @return array + */ + public function getFolders($regex = NULL, $recursive = false) { + //argument test + Eden_Folder_Error::i() + ->argument(1, 'string', 'null') //argument 1 must be a string + ->argument(2, 'bool'); //argument 2 must be a boolean + + $this->absolute(); + + $folders = array(); + + if($handle = opendir($this->_data)) { + //walk the directory + while (false !== ($folder = readdir($handle))) { + // If this is infact a directory + //and if it matches the regex + if($folder != '.' && $folder != '..' + && filetype($this->_data .'/'. $folder) == 'dir' + && (!$regex || preg_match($regex, $folder))) { + + //add it + $folders[] = Eden_Folder::i($this->_data . '/' . $folder); + if($recursive) { + $subfolders = Eden_Folder::i($this->_data.'/'.$folder); + $folders = array_merge($folders, $subfolders->getFolders($regex, $recursive)); + } + + } + } + closedir($handle); + } + + return $folders; + } + + /** + * Returns the name of the directory.. just the name + * + * @return string the name + */ + public function getName() { + $pathArray = $this->getArray(); + return array_pop($pathArray); + } + + /** + * Checks to see if this + * path is a real file + * + * @return bool + */ + public function isFile() { + return file_exists($this->_data); + } + + /** + * Checks to see if this + * path is a real file + * + * @return bool + */ + public function isFolder($path = NULL) { + Eden_Folder_Error::i()->argument(1, 'string', 'null'); //argument 1 must be a string + + //if path is string + if(is_string($path)) { + //return path appended + return is_dir($this->_data.'/'.$path); + } + + return is_dir($this->_data); + } + + /** + * Removes a folder given the path + * + * @return this + */ + public function remove() { + //get absolute path + $path = $this->absolute(); + + //if it's a directory + if(is_dir($path)) { + //remove it + rmdir($path); + } + + return $this; + } + + /** + * Removes files given the path and optionally a regular expression + * + * @param string regular expression + * @return bool + */ + public function removeFiles($regex = NULL) { + Eden_Folder_Error::i()->argument(1, 'string', 'null'); //argument 1 must be a string + + //get the files + $files = $this->getFiles($regex); + + if(empty($files)) { + return $this; + } + + //walk the array + foreach($files as $file) { + //remove everything + $file->remove(); + } + + return $this; + } + + /** + * Removes a folder given the path and optionally the regular expression + * + * @param string regular expression + * @return bool + */ + public function removeFolders($regex = NULL) { + Eden_Folder_Error::i()->argument(1, 'string', 'null'); //argument 1 must be a string + + $this->absolute(); + + $folders = $this->getFolders($regex); + + if(empty($folders)) { + return $this; + } + + //walk directory + foreach($folders as $folder) { + //remove directory + $folder->remove(); + } + + return $this; + } + + /** + * Removes files and folder given a path + * + * @return this + */ + public function truncate() { + $this->removeFolders(); + $this->removeFiles(); + + return $this; + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} + +/** + * Folder Errors + */ +class Eden_Folder_Error extends Eden_Error { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i($message = NULL, $code = 0) { + $class = __CLASS__; + return new $class($message, $code); + } + + /* Public Methods + -------------------------------*/ + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/foursquare.php b/library/eden/foursquare.php new file mode 100644 index 0000000..686d01f --- /dev/null +++ b/library/eden/foursquare.php @@ -0,0 +1,262 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ +require_once dirname(__FILE__).'/oauth2.php'; +require_once dirname(__FILE__).'/foursquare/error.php'; +require_once dirname(__FILE__).'/foursquare/base.php'; +require_once dirname(__FILE__).'/foursquare/oauth.php'; +require_once dirname(__FILE__).'/foursquare/campaign.php'; +require_once dirname(__FILE__).'/foursquare/checkins.php'; +require_once dirname(__FILE__).'/foursquare/events.php'; +require_once dirname(__FILE__).'/foursquare/list.php'; +require_once dirname(__FILE__).'/foursquare/pages.php'; +require_once dirname(__FILE__).'/foursquare/pageupdates.php'; +require_once dirname(__FILE__).'/foursquare/photos.php'; +require_once dirname(__FILE__).'/foursquare/settings.php'; +require_once dirname(__FILE__).'/foursquare/specials.php'; +require_once dirname(__FILE__).'/foursquare/tips.php'; +require_once dirname(__FILE__).'/foursquare/updates.php'; +require_once dirname(__FILE__).'/foursquare/users.php'; +require_once dirname(__FILE__).'/foursquare/venue.php'; +require_once dirname(__FILE__).'/foursquare/venuegroups.php'; + +/** + * foursquare API factory. This is a factory class with + * methods that will load up different google classes. + * Foursquare classes are organized as described on their + * developer site: campaign, checkins, events, list, pages + * pageupdates, photos, settings, tips, updates, users, venue + * and venuegroups. + * + * @package Eden + * @category google + * @author Christian Symon M. Buenavista sbuenavista@openovate.com + */ +class Eden_Foursquare extends Eden_Class { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function i() { + return self::_getSingleton(__CLASS__); + } + /* Magic + -------------------------------*/ + /* Public Methods + -------------------------------*/ + /** + * Returns foursquare oauth + * + * @param *string + * @param *string + * @param *string + * @return Eden_Foursquare_Oauth + */ + public function auth($clientId, $clientSecret,$redirect) { + //argument test + Eden_Foursquare_Error::i() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'string') //Argument 2 must be a string + ->argument(3, 'string'); //Argument 3 must be a string + + return Eden_Foursquare_Oauth::i($clientId, $clientSecret, $redirect); + } + + /** + * Returns foursquare campaign + * + * @param *string + * @return Eden_Foursquare_Campaign + */ + public function campaign($token) { + //Argument 1 must be a string + Eden_Foursquare_Error::i()->argument(1, 'string'); + + return Eden_Foursquare_Campaign::i($token); + } + + /** + * Returns foursquare campaign + * + * @param *string + * @return Eden_Foursquare_Checkins + */ + public function checkins($token) { + //Argument 1 must be a string + Eden_Foursquare_Error::i()->argument(1, 'string'); + + return Eden_Foursquare_Checkins::i($token); + } + + /** + * Returns foursquare events + * + * @param *string + * @return Eden_Foursquare_Events + */ + public function events($token) { + //Argument 1 must be a string + Eden_Foursquare_Error::i()->argument(1, 'string'); + + return Eden_Foursquare_Events::i($token); + } + + /** + * Returns foursquare lists + * + * @param *string + * @return Eden_Foursquare_List + */ + public function lists($token) { + //Argument 1 must be a string + Eden_Foursquare_Error::i()->argument(1, 'string'); + + return Eden_Foursquare_List::i($token); + } + + /** + * Returns foursquare pages + * + * @param *string + * @return Eden_Foursquare_Pages + */ + public function pages($token) { + //Argument 1 must be a string + Eden_Foursquare_Error::i()->argument(1, 'string'); + + return Eden_Foursquare_Pages::i($token); + } + + /** + * Returns foursquare pageUpdates + * + * @param *string + * @return Eden_Foursquare_Pageupdates + */ + public function pageUpdates($token) { + //Argument 1 must be a string + Eden_Foursquare_Error::i()->argument(1, 'string'); + + return Eden_Foursquare_Pageupdates::i($token); + } + + /** + * Returns foursquare photos + * + * @param *string + * @return Eden_Foursquare_Photos + */ + public function photos($token) { + //Argument 1 must be a string + Eden_Foursquare_Error::i()->argument(1, 'string'); + + return Eden_Foursquare_Photos::i($token); + } + + /** + * Returns foursquare settings + * + * @param *string + * @return Eden_Foursquare_Settings + */ + public function settings($token) { + //Argument 1 must be a string + Eden_Foursquare_Error::i()->argument(1, 'string'); + + return Eden_Foursquare_Settings::i($token); + } + + /** + * Returns foursquare specials + * + * @param *string + * @return Eden_Foursquare_Specials + */ + public function specials($token) { + //Argument 1 must be a string + Eden_Foursquare_Error::i()->argument(1, 'string'); + + return Eden_Foursquare_Specials::i($token); + } + + /** + * Returns foursquare tips + * + * @param *string + * @return Eden_Foursquare_Tips + */ + public function tips($token) { + //Argument 1 must be a string + Eden_Foursquare_Error::i()->argument(1, 'string'); + + return Eden_Foursquare_Tips::i($token); + } + + /** + * Returns foursquare updates + * + * @param *string + * @return Eden_Foursquare_Updates + */ + public function updates($token) { + //Argument 1 must be a string + Eden_Foursquare_Error::i()->argument(1, 'string'); + + return Eden_Foursquare_Updates::i($token); + } + + /** + * Returns foursquare users + * + * @param *string + * @return Eden_Foursquare_Users + */ + public function users($token) { + //Argument 1 must be a string + Eden_Foursquare_Error::i()->argument(1, 'string'); + + return Eden_Foursquare_Users::i($token); + } + + /** + * Returns foursquare venue + * + * @param *string + * @return Eden_Foursquare_Venue + */ + public function venue($token) { + //Argument 1 must be a string + Eden_Foursquare_Error::i()->argument(1, 'string'); + + return Eden_Foursquare_Venue::i($token); + } + + /** + * Returns foursquare venueGroups + * + * @param *string + * @return Eden_Foursquare_Venuegroups + */ + public function venueGroups($token) { + //Argument 1 must be a string + Eden_Foursquare_Error::i()->argument(1, 'string'); + + return Eden_Foursquare_Venuegroups::i($token); + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/foursquare/base.php b/library/eden/foursquare/base.php new file mode 100644 index 0000000..6039f0d --- /dev/null +++ b/library/eden/foursquare/base.php @@ -0,0 +1,161 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Four Square base + * + * @package Eden + * @category foursquare + * @author Christian Symon M. Buenavista sbuenavista@openovate.com + */ +class Eden_Foursquare_Base extends Eden_Class { + /* Constants + -------------------------------*/ + const ACCESS_TOKEN = 'oauth_token'; + const KEY = 'key'; + const MAX_RESULTS = 'maxResults'; + const FORM_HEADER = 'application/x-www-form-urlencoded'; + const CONTENT_TYPE = 'Content-Type: application/json'; + const SELF = 'self'; + const VERIFY = 'v'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_token = NULL; + protected $_maxResult = NULL; + protected $_headers = array(self::FORM_HEADER, self::CONTENT_TYPE); + + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + /* Magic + -------------------------------*/ + /* Public Methods + -------------------------------*/ + /** + * Returns the meta of the last call + * + * @return array + */ + public function getMeta($key = NULL) { + Eden_Google_Error::i()->argument(1, 'string', 'null'); + + if(isset($this->_meta[$key])) { + return $this->_meta[$key]; + } + + return $this->_meta; + } + + /** + * Set Maximum results of query + * + * @param int + * @return array + */ + public function setMaxResult($maxResult) { + Eden_Google_Error::i()->argument(1, 'int'); + $this->_maxResult = $maxResult; + + return $this; + } + + /* Protected Methods + -------------------------------*/ + protected function _reset() { + //foreach this as key => value + foreach ($this as $key => $value) { + //if the value of key is not array + if(!is_array($this->$key)) { + //if key name starts at underscore, probably it is protected variable + if(preg_match('/^_/', $key)) { + //if the protected variable is not equal to token + //we dont want to unset the access token + if($key != '_token') { + //reset all protected variables that currently use + $this->$key = NULL; + } + } + } + } + + return $this; + } + + protected function _accessKey($array) { + foreach($array as $key => $val) { + if(is_array($val)) { + $array[$key] = $this->_accessKey($val); + } + + if($val == false || $val == NULL || empty($val)) { + unset($array[$key]); + } + + } + + return $array; + } + + protected function _getResponse($url, array $query = array()) { + //add access token to query + $query[self::ACCESS_TOKEN] = $this->_token; + //add current date for verification + $query[self::VERIFY] = date('Ymd', time()); + //prevent sending fields with no value + $query = $this->_accessKey($query); + //build url query + $url .= '?'.http_build_query($query); + //reset variables + $this->_reset(); + + //set curl + return $this->Eden_Curl() + ->setUrl($url) + ->verifyHost(false) + ->verifyPeer(false) + ->setTimeout(60) + ->getJsonResponse(); + } + + protected function _post($url, array $query = array()) { + //add access token to query + $url = $url.'?'.self::ACCESS_TOKEN.'='.$this->_token; + //prevent sending fields with no value + $query = $this->_accessKey($query); + //add current date for verification + $query[self::VERIFY] = date('Ymd', time()); + //build a to string query + $query = http_build_query($query); + //reset variables + $this->_reset(); + + //set curl + $curl = Eden_Curl::i() + ->verifyHost(false) + ->verifyPeer(false) + ->setUrl($url) + ->setPostFields($query); + + //get the response + $response = $curl->getJsonResponse(); + + $this->_meta = $curl->getMeta(); + $this->_meta['url'] = $url; + $this->_meta['query'] = $query; + + return $response; + } + + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/foursquare/campaign.php b/library/eden/foursquare/campaign.php new file mode 100644 index 0000000..fe08ed2 --- /dev/null +++ b/library/eden/foursquare/campaign.php @@ -0,0 +1,261 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Four square campaign + * + * @package Eden + * @category four square + * @author Christian Symon M. Buenavista sbuenavista@openovate.com + */ +class Eden_Foursquare_Campaign extends Eden_Foursquare_Base { + /* Constants + -------------------------------*/ + const URL_CAMPAIGN_ADD = 'https://api.foursquare.com/v2/campaigns/add'; + const URL_CAMPAIGN_GET_LIST = 'https://api.foursquare.com/v2/campaigns/list'; + const URL_CAMPAIGN_TIME_SERIES = 'https://api.foursquare.com/v2/campaigns/%s/timeseries'; + const URL_CAMPAIGN_DELETE = 'https://api.foursquare.com/v2/campaigns/%s/delete'; + const URL_CAMPAIGN_END = 'https://api.foursquare.com/v2/campaigns/%s/end'; + const URL_CAMPAIGN_START = 'https://api.foursquare.com/v2/campaigns/%s/start'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_startAt = NULL; + protected $_endAt = NULL; + protected $_campaignId = NULL; + protected $_specialId = NULL; + protected $_groupId = NULL; + protected $_status = NULL; + + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + public function __construct($token) { + //argument test + Eden_Foursquare_Error::i()->argument(1, 'string'); + $this->_token = $token; + } + + /* Public Methods + -------------------------------*/ + /** + * DateTime when the campaign is to be started (seconds since epoch). + * If this parameter is not specified, the campaign will be in a pending + * state until the campaign is actually started via the start action. + * If this parameter is specified and is in the past, the campaign + * will be started as of the current time. + * + * @param string YYYY-MM-DD + * @return this + */ + public function setStartTime($startTime) { + //argument 1 must be a string + Eden_Foursquare_Error::i()->argument(1, 'string'); + $this->_startAt = strtotime($startTime); + + return $this; + } + + /** + * DateTime when the campaign is to be automatically deactivated. + * + * @param string YYYY-MM-DD + * @return this + */ + public function setEndTime($endTime) { + //argument 1 must be a string + Eden_Foursquare_Error::i()->argument(1, 'string'); + $this->_endAt = strtotime($endTime); + + return $this; + } + + /** + * ID of an existing campaign to copy. + * + * @param string + * @return this + */ + public function setCampaignId($campaignId) { + //argument 1 must be a string + Eden_Foursquare_Error::i()->argument(1, 'string'); + $this->_campaignId = $campaignId; + + return $this; + } + + /** + * If specified, limits response to campaigns involving the given special + * + * @param string + * @return this + */ + public function setSpecialId($specialId) { + //argument 1 must be a string + Eden_Foursquare_Error::i()->argument(1, 'string'); + $this->_specialId = $specialId; + + return $this; + } + + /** + * If specified, limits response to campaigns involving the given group + * + * @param string + * @return this + */ + public function setGroupId($groupId) { + //argument 1 must be a string + Eden_Foursquare_Error::i()->argument(1, 'string'); + $this->_groupId = $groupId; + + return $this; + } + + /** + * Accepted fields are pending, scheduled, active, + * expired, depleted, stopped, notStarted, ended, all + * + * @param string + * @return this + */ + public function setStatus($status) { + //argument 1 must be a string + Eden_Foursquare_Error::i()->argument(1, 'string'); + + //if the input value is not allowed + if(!in_array($status, array('pending', 'scheduled', 'active', 'expired', 'depleted', 'stopped', 'notStarted', 'ended', 'all'))) { + //throw error + Eden_Foursquare_Error::i() + ->setMessage(Eden_Foursquare_Error::INVALID_CAMPAIGN_STATUS) + ->addVariable($status) + ->trigger(); + } + + $this->_status = $status; + + return $this; + } + + /** + * Create a campaign. The special must be started in order + * for it to be visible to users. + * + * @param string|null required (unless campaignId has been provided). Special ID + * @param string|null required (unless venueId has been provided) + * @param string|null required (unless groupId has been provided) + * @return array + */ + public function creatCampaign($specialId = NULL, $groupId = NULL, $venueId = NULL) { + //argument test + Eden_Foursquare_Error::i() + ->argument(1, 'string', 'null') //argument 1 must be a string or null + ->argument(2, 'string', 'null') //argument 2 must be a string or null + ->argument(3, 'string', 'null'); //argument 3 must be a string or null + + //populate fields + $query = array( + 'specialId' => $specialId, + 'groupId' => $groupId, + 'venueId' => $venueId, + 'endAt' => $this->_endAt, //optional + 'startAt' => $this->_startAt, //optional + 'campaignId' => $this->_campaignId); //optional + + return $this->_post(self::URL_CAMPAIGN_ADD, $query); + } + + /** + * List all campaigns matching the given criteria. + * + * @return array + */ + public function getList() { + + //populate fields + $query = array( + 'specialId' => $this->_specialId, //optional + 'groupId' => $this->_groupId, //optional + 'status' => $this->_status); //optional + + return $this->_getResponse(self::URL_CAMPAIGN_GET_LIST, $query); + } + + /** + * Get daily campaign stats over a given time range. + * + * @param string The campaign id to retrieve stats for. + * @return array + */ + public function getTimeSeries($campaignId) { + //argument 1 must be a string + Eden_Foursquare_Error::i()->argument(1, 'string'); + + //populate fields + $query = array( + 'endAt' => $this->_endAt, //optional + 'startAt' => $this->_startAt); //optional + + return $this->_post(sprintf(self::URL_CAMPAIGN_TIME_SERIES, $campaignId), $query); + } + + /** + * Delete a campaign that has never been activated. + * + * @param string The ID of the campaign to delete. + * @return array + */ + public function deleteCampaign($campaignId) { + //argument 1 must be a string + Eden_Foursquare_Error::i()->argument(1, 'string'); + + return $this->_post(sprintf(self::URL_CAMPAIGN_DELETE, $campaignId)); + } + + /** + * End a campaign. + * + * @param string The ID of the campaign to end. + * @return array + */ + public function endCampaign($campaignId) { + //argument 1 must be a string + Eden_Foursquare_Error::i()->argument(1, 'string'); + + return $this->_post(sprintf(self::URL_CAMPAIGN_END, $campaignId)); + } + + /** + * Start a campaign. + * + * @param string The ID of the campaign to start. + * @return array + */ + public function startCampaign($campaignId) { + //argument 1 must be a string + Eden_Foursquare_Error::i()->argument(1, 'string'); + + //populate fields + $query = array('startAt' => $this->_startAt); //optional + + return $this->_post(sprintf(self::URL_CAMPAIGN_START, $campaignId), $query); + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/foursquare/checkins.php b/library/eden/foursquare/checkins.php new file mode 100644 index 0000000..a990ce3 --- /dev/null +++ b/library/eden/foursquare/checkins.php @@ -0,0 +1,257 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Four square checkins + * + * @package Eden + * @category four square + * @author Christian Symon M. Buenavista sbuenavista@openovate.com + */ +class Eden_Foursquare_Checkins extends Eden_Foursquare_Base { + /* Constants + -------------------------------*/ + const URL_CHECKINS_CREATE = 'https://api.foursquare.com/v2/checkins/add'; + const URL_CHECKINS_RECENT = 'https://api.foursquare.com/v2/checkins/recent'; + const URL_CHECKINS_ADD_COMMENT = 'https://api.foursquare.com/v2/checkins/%s/addcomment'; + const URL_CHECKINS_ADD_POST = 'https://api.foursquare.com/v2/checkins/%s/addpost'; + const URL_CHECKINS_DELETE_COMMENT = 'https://api.foursquare.com/v2/checkins/%s/deletecomment'; + const URL_CHECKINS_REPLY = 'https://api.foursquare.com/v2/checkins/%s/reply'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_eventId = NULL; + protected $_location = NULL; + protected $_limit = NULL; + protected $_contentId = NULL; + protected $_url = NULL; + protected $_shout = NULL; + + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + public function __construct($token) { + //argument test + Eden_Foursquare_Error::i()->argument(1, 'string'); + $this->_token = $token; + } + + /* Public Methods + -------------------------------*/ + /** + * The event the user is checking in to. + * + * @param string + * @return this + */ + public function setEventId($eventId) { + //argument 1 must be a string + Eden_Foursquare_Error::i()->argument(1, 'string'); + $this->_eventId = $eventId; + + return $this; + } + + /** + * Set shout + * + * @param string + * @return this + */ + public function setShout($shout) { + //argument 1 must be a string + Eden_Foursquare_Error::i()->argument(1, 'string'); + + $this->_shout = $shout; + + return $this; + } + + /** + * Number of results to return, up to 50. + * + * @param integer + * @return this + */ + public function setLimit($limit) { + //argument 1 must be a string + Eden_Foursquare_Error::i()->argument(1, 'int'); + $this->_limit = $limit; + + return $this; + } + + /** + * The url of the homepage of the venue. + * + * @param string + * @return this + */ + public function setUrl($url) { + //argument 1 must be a string + Eden_Foursquare_Error::i()->argument(1, 'string'); + $this->_url = $url; + + return $this; + } + + /** + * Set Content id. + * + * @param string + * @return this + */ + public function setContentId($contentId) { + //argument 1 must be a string + Eden_Foursquare_Error::i()->argument(1, 'string'); + $this->_contentId = $contentId; + + return $this; + } + + /** + * Check in to a place. + * + * @param string The venue where the user is checking in + * @param string Who to broadcast this check-in to + * @return array + */ + public function checkin($venueId, $broadcast) { + //argument test + Eden_Foursquare_Error::i() + ->argument(1, 'string') //argument 1 must be a string + ->argument(2, 'string'); //argument 2 must be a string + + //if the input value is not allowed + if(!in_array($broadcast, array('private', 'public', 'facebook', 'twitter', 'followers'))) { + //throw error + Eden_Foursquare_Error::i() + ->setMessage(Eden_Foursquare_Error::INVALID_BROADCAST) + ->addVariable($broadcast) + ->trigger(); + } + + $query = array( + 'venueId' => $venueId, + 'broadcast' => $broadcast, + 'eventId' => $this->_eventId, //optional + 'shout' => $this->_shout); //optional + + return $this->_post(self::URL_CHECKINS_CREATE, $query); + } + + /** + * Returns a list of recent checkins from friends. + * + * @return array + */ + public function getRecentCheckins() { + + $query = array( + 'll' => $this->_location, //optional + 'limit' => $this->_limit); //optional + + return $this->_getResponse(self::URL_CHECKINS_CHECKINS, $query); + } + + /** + * Comment on a checkin-in + * + * @param string The ID of the checkin to add a comment to. + * @param string The text of the comment, up to 200 characters. + * @return array + */ + public function addComment($checkinId, $text) { + //argument test + Eden_Foursquare_Error::i() + ->argument(1, 'string') //argument 1 must be a string + ->argument(2, 'string'); //argument 2 must be a string + + //populate fiels + $query = array('text' => $text); + + return $this->_post(sprintf(self::URL_CHECKINS_ADD_COMMENT, $checkinId), $query); + } + + /** + * Post user generated content from an external app to a check-in. + * This post will be accessible to anyone who can view the details of the check-in. + * + * @param string The ID of the checkin to add a comment to. + * @param string The text of the comment, up to 200 characters. + * @return array + */ + public function addPost($checkinId, $text) { + //argument test + Eden_Foursquare_Error::i() + ->argument(1, 'string') //argument 1 must be a string + ->argument(2, 'string'); //argument 2 must be a string + + //populate fiels + $query = array( + 'text' => $text, + 'url' => $this->_url, //optional + 'contentId' => $this->_contentId); //optional + + return $this->_post(sprintf(self::URL_CHECKINS_ADD_POST, $checkinId), $query); + } + + /** + * Remove a comment from a checkin, if the acting user is the author or the owner of the checkin. + * + * @param string The ID of the checkin to remove a comment from. + * @param string The id of the comment to remove. + * @return array + */ + public function deleteComment($checkinId, $commentId) { + //argument test + Eden_Foursquare_Error::i() + ->argument(1, 'string') //argument 1 must be a string + ->argument(2, 'string'); //argument 2 must be a string + + //populate fiels + $query = array('commentId' => $commentId); + + return $this->_post(sprintf(self::URL_CHECKINS_DELETE_COMMENT, $checkinId), $query); + } + + /** + * Reply to a user about their check-in. This reply will only be visible to the owner of the check-in. + * + * @param string The ID of the checkin to remove a comment from. + * @param string The id of the comment to remove. + * @return array + */ + public function replyToCheckin($checkinId, $text) { + //argument test + Eden_Foursquare_Error::i() + ->argument(1, 'string') //argument 1 must be a string + ->argument(2, 'string'); //argument 2 must be a string + + //populate fiels + $query = array( + 'text' => $text, + 'url' => $this->_url, //optional + 'contentId' => $this->_contentId); //optional + + return $this->_post(sprintf(self::URL_CHECKINS_REPLY, $checkinId), $query); + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/foursquare/error.php b/library/eden/foursquare/error.php new file mode 100644 index 0000000..157110a --- /dev/null +++ b/library/eden/foursquare/error.php @@ -0,0 +1,55 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Four Square Errors + * + * @package Eden + * @category foursquare + * @author Christian Blanquera cblanquera@openovate.com + */ +class Eden_Foursquare_Error extends Eden_Error { + /* Constants + -------------------------------*/ + const INVALID_PROBLEM = 'Argument 2 was expecting mislocated, closed, duplicate, inappropriate, doesnt_exist, event_over. %s was given'; + const INVALID_GROUPS = 'Argument 2 was expecting checkin, venue. %s was given'; + const INVALID_FIELDS = 'Argument 1 was expecting totalCheckins, newCheckins, uniqueVisitors, sharing, genders, ages, hours. %s was given'; + const INVALID_BROADCAST = 'Argument 2 was expecting private, public, facebook, twitter, followers. %s was given'; + const INVALID_BROADCAST_TIPS = 'Argument 1 was expecting facebook, twitter, followers. %s was given'; + const INVALID_GROUP = 'Argument 1 was expecting created, edited, followed, friends, other. %s was given'; + const INVALID_BROADCAST_LIST = 'Argument 1 was expecting facebook, twitter. %s was given'; + const INVALID_STATUS = 'Argument 1 was expecting pending, active, expired, all. %s was given'; + const INVALID_PROBLEM_SPECIAL = 'Argument 1 was expecting not_redeemable, not_valuable. %s was given'; + + const INVALID_FIELDS_PAGES = 'Argument 1 was expecting totalCheckins, newCheckins, uniqueVisitors, sharing, genders, ages, hours. %s was given'; + const INVALID_CAMPAIGN_STATUS = 'Argument 1 was expecting pending, scheduled, active, expired, depleted, stopped, notStarted, ended, all %s was given'; + const INVALID_SETTING = 'Argument 1 was expecting sendToTwitter, sendMayorshipsToTwitter, sendBadgesToTwitter, sendToFacebook, sendMayorshipsToFacebook, sendBadgesToFacebook, receivePings, receiveCommentPings. %s was given'; + + const INVALID_PAGEUPDATES_BROADCAST = 'Argument 1 was expecting facebook, twitter, private. %s was given'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i($message = NULL, $code = 0) { + $class = __CLASS__; + return new $class($message, $code); + } + + /* Public Methods + -------------------------------*/ + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/foursquare/events.php b/library/eden/foursquare/events.php new file mode 100644 index 0000000..bdeaaba --- /dev/null +++ b/library/eden/foursquare/events.php @@ -0,0 +1,56 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Four square events + * + * @package Eden + * @category four square + * @author Christian Symon M. Buenavista sbuenavista@openovate.com + */ +class Eden_Foursquare_Events extends Eden_Foursquare_Base { + /* Constants + -------------------------------*/ + const URL_EVENTS_LIST = 'https://api.foursquare.com/v2/events/categories'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + public function __construct($token) { + //argument test + Eden_Foursquare_Error::i()->argument(1, 'string'); + $this->_token = $token; + } + + /* Public Methods + -------------------------------*/ + /** + * Returns a hierarchical list of categories applied to events. + * + * @return array + */ + public function getList() { + + return $this->_getResponse(self::URL_EVENTS_LIST); + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/foursquare/list.php b/library/eden/foursquare/list.php new file mode 100644 index 0000000..3015bd4 --- /dev/null +++ b/library/eden/foursquare/list.php @@ -0,0 +1,495 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Four square list + * + * @package Eden + * @category four square + * @author Christian Symon M. Buenavista sbuenavista@openovate.com + */ +class Eden_Foursquare_List extends Eden_Foursquare_Base { + /* Constants + -------------------------------*/ + const URL_LIST_ADD = 'https://api.foursquare.com/v2/lists/add'; + const URL_LIST_UPDATE = 'https://api.foursquare.com/v2/lists/%s/update'; + const URL_LIST_SUGGEST_PHOTO = 'https://api.foursquare.com/v2/lists/%s/suggestphoto'; + const URL_LIST_SUGGEST_TIPS = 'https://api.foursquare.com/v2/lists/%s/suggesttip'; + const URL_LIST_SUGGEST_VENUES = 'https://api.foursquare.com/v2/lists/%s/suggestvenues'; + const URL_LIST_ADD_ITEM = 'https://api.foursquare.com/v2/lists/%s/additem'; + const URL_LIST_DELETE_ITEM = 'https://api.foursquare.com/v2/lists/%s/deleteitem'; + const URL_LIST_UPDATE_ITEM = 'https://api.foursquare.com/v2/lists/%s/updateitem'; + const URL_LIST_MOVE_ITEM = 'https://api.foursquare.com/v2/lists/%s/moveitem'; + const URL_LIST_FOLLOWERS = 'https://api.foursquare.com/v2/lists/%s/followers'; + const URL_LIST_FOLLOW = 'https://api.foursquare.com/v2/lists/%s/follow'; + const URL_LIST_UNFOLLOW = 'https://api.foursquare.com/v2/lists/%s/unfollow'; + const URL_LIST_SHARE = 'https://api.foursquare.com/v2/lists/%s/share'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_description = NULL; + protected $_collaborative = NULL; + protected $_photoId = NULL; + protected $_venueId = NULL; + protected $_text = NULL; + protected $_url = NULL; + protected $_tipId = NULL; + protected $_listId = NULL; + protected $_itemId = NULL; + protected $_beforeId = NULL; + protected $_afterId = NULL; + protected $_broadcast = NULL; + protected $_message = NULL; + protected $_name = NULL; + + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + public function __construct($token) { + //argument test + Eden_Foursquare_Error::i()->argument(1, 'string'); + $this->_token = $token; + } + + /* Public Methods + -------------------------------*/ + /** + * Where to broadcast this list. Send twitter if you want to send to twitter, + * facebook if you want to send to facebook, or twitter,facebook if + * you want to send to both. + * + * @param string + * @return this + */ + public function broadcast($broadcast) { + //argument 1 must be a string + Eden_Foursquare_Error::i()->argument(1, 'string'); + + //if the input value is not allowed + if(!in_array($broadcast, array('facebook', 'twitter'))) { + //throw error + Eden_Foursquare_Error::i() + ->setMessage(Eden_Foursquare_Error::INVALID_BROADCAST_LIST) + ->addVariable($broadcast) + ->trigger(); + } + + $this->_broadcast = $broadcast; + + return $this; + } + + /** + * A personal note to include with the share. + * + * @param string + * @return this + */ + public function setMessage($message) { + //argument 1 must be a string + Eden_Foursquare_Error::i()->argument(1, 'string'); + $this->_message = $message; + + return $this; + } + + /** + * The url of the homepage of the venue. + * + * @param string + * @return this + */ + public function setUrl($url) { + //argument 1 must be a string + Eden_Foursquare_Error::i()->argument(1, 'string'); + $this->_url = $url; + + return $this; + } + + /** + * Move itemId before beforeId. + * + * @param string + * @return this + */ + public function setBeforeId($beforeId) { + //argument 1 must be a string + Eden_Foursquare_Error::i()->argument(1, 'string'); + $this->_beforeId = $beforeId; + + return $this; + } + + /** + * Move itemId after afterId. + * + * @param string + * @return this + */ + public function setAfterId($afterId) { + //argument 1 must be a string + Eden_Foursquare_Error::i()->argument(1, 'string'); + $this->_afterId = $afterId; + + return $this; + } + + /** + * If the target is a user-created list, this will create + * a public tip on the venue. If the target is /userid/todos, + * the text will be a private note that is only visible to the author. + * + * @param string + * @return this + */ + public function setText($text) { + //argument 1 must be a string + Eden_Foursquare_Error::i()->argument(1, 'string'); + $this->_text = $text; + + return $this; + } + + /** + * Used in conjuction with listId, the id of an item on that list that we wish to copy to this list. + * + * @param string + * @return this + */ + public function setItemId($itemId) { + //argument 1 must be a string + Eden_Foursquare_Error::i()->argument(1, 'string'); + $this->_itemId = $itemId; + + return $this; + } + + /** + * Used in conjuction with itemId, the id for a user created or + * followed list as well as one of USER_ID/tips, USER_ID/todos, or USER_ID/dones. + * + * @param string + * @return this + */ + public function setListId($listId) { + //argument 1 must be a string + Eden_Foursquare_Error::i()->argument(1, 'string'); + $this->_listId = $listId; + + return $this; + } + + /** + * Used to add a tip to a list. Cannot be used in conjunction with the text and url fields. + * + * @param string + * @return this + */ + public function setTipId($tipId) { + //argument 1 must be a string + Eden_Foursquare_Error::i()->argument(1, 'string'); + $this->_tipId = $tipId; + + return $this; + } + + /** + * A venue to add to the list. + * + * @param string + * @return this + */ + public function setVenueId($venueId) { + //argument 1 must be a string + Eden_Foursquare_Error::i()->argument(1, 'string'); + $this->_venueId = $venueId; + + return $this; + } + + /** + * The description of the list. + * + * @param string + * @return this + */ + public function setDescription($description) { + //argument 1 must be a string + Eden_Foursquare_Error::i()->argument(1, 'string'); + $this->_description = $description; + + return $this; + } + + /** + * If present and a non-empty value, updates the List name. + * + * @param string + * @return this + */ + public function setListName($name) { + //argument 1 must be a string + Eden_Foursquare_Error::i()->argument(1, 'string'); + $this->_name = $name; + + return $this; + } + + + /** + * Set to can be edited by friends. + * + * @return this + */ + public function setCollaborative() { + $this->_collaborative = true; + + return $this; + } + + /** + * The id of a photo that should be set as the list photo. + * + * @param string + * @return this + */ + public function setPhotoId($photoId) { + //argument 1 must be a string + Eden_Foursquare_Error::i()->argument(1, 'string'); + $this->_photoId = $photoId; + + return $this; + } + + /** + * Allows users to create a new list. + * + * @param string The name of the list. + * @return array + */ + public function addlist($name) { + //argument test + Eden_Foursquare_Error::i()->argument(1, 'string'); + + $query = array( + 'name' => $name, + 'description' => $this->_description, //optional + 'collaborative' => $this->_collaborative, //optional + 'photoId' => $this->_photoId); //optional + + return $this->_post(self::URL_LIST_ADD, $query); + } + + /** + * Returns a count and items of users following this list. + * + * @param string Id for a user-created list + * @return array + */ + public function getFollowers($listId) { + //argument test + Eden_Foursquare_Error::i()->argument(1, 'string'); + + return $this->_getResponse(sprintf(self::URL_LIST_FOLLOWERS, $listId)); + } + + /** + * Suggests photos that may be appropriate for this item. + * + * @param string Id for a user-created list + * @param string Id of item on this list. + * @return array + */ + public function suggestPhoto($listId, $itemId) { + //argument test + Eden_Foursquare_Error::i()->argument(1, 'string'); + + //populate fields + $query = array('itemId' => $itemId); + + return $this->_getResponse(sprintf(self::URL_LIST_SUGGEST_PHOTO, $listId), $query); + } + + /** + * Suggests tips that may be appropriate for this item. + * + * @param string Id for a user-created list + * @param string Id of item on this list. + * @return array + */ + public function suggestTips($listId, $itemId) { + //argument test + Eden_Foursquare_Error::i()->argument(1, 'string'); + + //populate fields + $query = array('itemId' => $itemId); + + return $this->_getResponse(sprintf(self::URL_LIST_SUGGEST_TIPS, $listId), $query); + } + + /** + * Suggests venues may be appropriate for this item. + * + * @param string Id for a user-created list + * @return array + */ + public function suggestVenues($listId) { + //argument test + Eden_Foursquare_Error::i()->argument(1, 'string'); + + return $this->_getResponse(sprintf(self::URL_LIST_SUGGEST_VENUES, $listId)); + } + + /** + * Allows you to add an item to a list. All fields are optional, but exactly + * one of the following must be specified: venueId, tipId, listId and itemId + * + * @param string Id for a user-created list + * @return array + */ + public function addItem($listId) { + //argument test + Eden_Foursquare_Error::i()->argument(1, 'string'); + + //populate fields + $query = array( + 'venueId' => $this->_venueId, //optional + 'text' => $this->_text, //optional + 'url' => $this->_url, //optional + 'tipId' => $this->_tipId, //optional + 'listId' => $this->_listId, //optional + 'itemId' => $this->_itemId); //optional + + return $this->_post(sprintf(self::URL_LIST_ADD_ITEM, $listId), $query); + } + + /** + * Allows you to update items on user-created lists. + * + * @param string Id for a user-created list + * @param string The id of an item on this list. + * @return array + */ + public function updateItem($listId, $itemId) { + //argument test + Eden_Foursquare_Error::i() + ->argument(1, 'string') //argument 1 must be a string + ->argument(2, 'string'); //argument 2 must be a string + + //populate fields + $query = array( + 'itemId' => $itemId, + 'text' => $this->_text, //optional + 'url' => $this->_url, //optional + 'tipId' => $this->_tipId, //optional + 'photoId' => $this->_photoId); //optional + + return $this->_post(sprintf(self::URL_LIST_UPDATE_ITEM, $listId), $query); + } + + /** + * Allows you to delete an item from a list. + * + * @param string Id for a user-created list or followed list or one of + * USER_ID/tips, USER_ID/todos, or USER_ID/dones. + * @param string Id of the item to delete. + * @return array + */ + public function deleteItem($listId, $itemId) { + //argument test + Eden_Foursquare_Error::i() + ->argument(1, 'string') //argument 1 must be a string + ->argument(2, 'string'); //argument 2 must be a string + + //populate fields + $query = array('itemId' => $itemId); + + return $this->_post(sprintf(self::URL_LIST_DELETE_ITEM, $listId), $query); + } + + /** + * Allows you to move an item on a list. One of beforeId or afterId must be specified. + * + * @param string Id for a user-created list + * @param string Id of the item to delete. + * @return array + */ + public function moveItem($listId, $itemId) { + //argument test + Eden_Foursquare_Error::i() + ->argument(1, 'string') //argument 1 must be a string + ->argument(2, 'string'); //argument 2 must be a string + + //populate fields + $query = array( + 'itemId' => $itemId, + 'beforeId' => $this->_beforeId, + 'afterId' => $this->_afterId); + + return $this->_post(sprintf(self::URL_LIST_MOVE_ITEM, $listId), $query); + } + + /** + * Allows you to follow a list. + * + * @param string Id for a user-created list + * @return array + */ + public function followList($listId) { + //argument test + Eden_Foursquare_Error::i()->argument(1, 'string'); + + return $this->_post(sprintf(self::URL_LIST_FOLLOW, $listId)); + } + + /** + * Allows you to unfollow a list. + * + * @param string Id for a user-created list + * @return array + */ + public function unfollowList($listId) { + //argument test + Eden_Foursquare_Error::i()->argument(1, 'string'); + + return $this->_post(sprintf(self::URL_LIST_UNFOLLOW, $listId)); + } + + /** + * Share a user-created list to twitter or facebook. + * + * @param string Id for a user-created list + * @return array + */ + public function shareList($listId) { + //argument test + Eden_Foursquare_Error::i()->argument(1, 'string'); + + //populate fields + $query = array( + 'itemId' => $itemId, + 'broadcast' => $this->_broadcast, //optional + 'message' => $this->_message); //optional + + return $this->_post(sprintf(self::URL_LIST_SHARE, $listId), $query); + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/foursquare/oauth.php b/library/eden/foursquare/oauth.php new file mode 100644 index 0000000..834ef93 --- /dev/null +++ b/library/eden/foursquare/oauth.php @@ -0,0 +1,51 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Google oauth + * + * @package Eden + * @category google + * @author Christian Blanquera cblanquera@openovate.com + */ +class Eden_Foursquare_Oauth extends Eden_Oauth2_Client { + /* Constants + -------------------------------*/ + const REQUEST_URL = 'https://foursquare.com/oauth2/authorize'; + const ACCESS_URL = 'https://foursquare.com/oauth2/access_token'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + public function __construct($clientId, $clientSecret, $redirect) { + //argument test + Eden_Foursquare_Error::i() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'string') //Argument 2 must be a string + ->argument(3, 'string'); //Argument 4 must be a string + + parent::__construct($clientId, $clientSecret, $redirect, self::REQUEST_URL, self::ACCESS_URL); + } + + /* Public Methods + -------------------------------*/ + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/foursquare/pages.php b/library/eden/foursquare/pages.php new file mode 100644 index 0000000..1425125 --- /dev/null +++ b/library/eden/foursquare/pages.php @@ -0,0 +1,246 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Four square pages + * + * @package Eden + * @category four square + * @author Christian Symon M. Buenavista sbuenavista@openovate.com + */ +class Eden_Foursquare_Pages extends Eden_Foursquare_Base { + /* Constants + -------------------------------*/ + const URL_PAGES_SEARCH = 'https://api.foursquare.com/v2/pages/search'; + const URL_PAGES_TIMESERIES = 'https://api.foursquare.com/v2/pages/%s/timeseries'; + const URL_PAGES_VENUES = 'https://api.foursquare.com/v2/pages/%s/venues'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_twitter = NULL; + protected $_fbId = NULL; + protected $_endAt = NULL; + protected $_fields = NULL; + protected $_location = NULL; + protected $_raduis = NULL; + protected $_offset = NULL; + protected $_limit = NULL; + + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + public function __construct($token) { + //argument test + Eden_Foursquare_Error::i()->argument(1, 'string'); + $this->_token = $token; + } + + /* Public Methods + -------------------------------*/ + /** + * Set twitter account + * + * @param string + * @return this + */ + public function setTwitter($twitter) { + //argument test + Eden_Foursquare_Error::i()->argument(1, 'string'); + $this->_twitter = $twitter; + + return $this; + } + + /** + * Set twitter account + * + * @param string + * @return this + */ + public function setFacebookId($fbId) { + //argument test + Eden_Foursquare_Error::i()->argument(1, 'string'); + $this->_fbId = $fbId; + + return $this; + } + + /** + * Specifies which fields to return. May be one or more of + * totalCheckins, newCheckins, uniqueVisitors, sharing, + * genders, ages, hours, + * + * @param string + * @return this + */ + public function setFields($fields) { + //argument test + Eden_Foursquare_Error::i()->argument(1, 'string'); + + //if the input value is not allowed + if(!in_array($fields, array('totalCheckins', 'newCheckins', 'uniqueVisitors', 'sharing', 'genders', 'ages', 'hours'))) { + //throw error + Eden_Foursquare_Error::i() + ->setMessage(Eden_Foursquare_Error::INVALID_FIELDS_PAGES) + ->addVariable($fields) + ->trigger(); + } + + $this->_fields = $fields; + + return $this; + } + + /** + * The end of the time range to retrieve stats for (seconds since epoch). + * If omitted, the current time is assumed. + * + * @param string YYYY-MM-DD + * @return this + */ + public function setEndTime($endTime) { + //argument 1 must be a string + Eden_Foursquare_Error::i()->argument(1, 'string'); + $this->_endAt = strtotime($endTime); + + return $this; + } + + /** + * Set location by setting longtitide + * and latitude + * + * @param int|float + * @param int|float + * @return this + */ + public function setLocation($longtitude, $latitude) { + //argument test + Eden_Foursquare_Error::i() + ->argument(1, 'int', 'float') //argument 1 must be an integer or float + ->argument(2, 'int', 'float'); //argument 2 must be an integer or float + + $this->_location = $longtitude.', '.$latitude; + + return $this; + } + + /** + * Radius in meters, up to approximately 2000 meters. + * + * @param integer + * @return this + */ + public function setRadius($radius) { + //argument 1 must be a string + Eden_Foursquare_Error::i()->argument(1, 'int'); + $this->_radius = $radius; + + return $this; + } + + /** + * The number of venues to return. Defaults to 20, max of 100. + * + * @param integer + * @return this + */ + public function setLimit($limit) { + //argument 1 must be a string + Eden_Foursquare_Error::i()->argument(1, 'int'); + $this->_limit = $limit; + + return $this; + } + + /** + * The offset of which venues to return. Defaults to 0. + * + * @param integer + * @return this + */ + public function setOffset($offset) { + //argument 1 must be a string + Eden_Foursquare_Error::i()->argument(1, 'int'); + $this->_offset = $offset; + + return $this; + } + + /** + * Returns a list of pages matching the search term. + * + * @param string A search term to be applied against page names. + * @return array + */ + public function search($name) { + //argument test + Eden_Foursquare_Error::i()->argument(1, 'string'); + + $query = array( + 'name' => $name, + 'twitter' => $this->_twitter, //optional + 'fbid' => $this->_fbId); //optionalc + + return $this->_getResponse(self::URL_PAGES_SEARCH, $query); + } + + /** + * Get daily venue stats for venues managed by a page over a time range. + * + * @param string The page whose venues to get timeseries data for + * @param string The start of the time range to retrieve stats for + * @return array + */ + public function getTimeSeries($pageId, $startAt) { + //argument test + Eden_Foursquare_Error::i() + ->argument(1, 'string') //argument 1 must be a string + ->argument(2, 'string'); //argument 2 must be a string + + $query = array( + 'startAt' => strtotime($startAt), + 'endAt' => $this->_endAt, //optional + 'fields' => $this->_fields); //optional + + return $this->_getResponse(sprintf(self::URL_PAGES_TIMESERIES, $pageId), $query); + } + + /** + * Allows you to get the page's venues. + * + * @param string The page id for which venues are being requested. + * @return array + */ + public function getVenue($pageId) { + //argument 1 must be a string + Eden_Foursquare_Error::i()->argument(1, 'string'); + + $query = array( + 'll' => $this->_location, //optional + 'radius' => $this->_radius, //optional + 'offset' => $this->_offset, //optional + 'limit' => $this->_limit); //optional + + return $this->_getResponse(sprintf(self::URL_PAGES_VENUES, $pageId), $query); + } + + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/foursquare/pageupdates.php b/library/eden/foursquare/pageupdates.php new file mode 100644 index 0000000..76d1b10 --- /dev/null +++ b/library/eden/foursquare/pageupdates.php @@ -0,0 +1,226 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Four square page updates + * + * @package Eden + * @category four square + * @author Christian Symon M. Buenavista sbuenavista@openovate.com + */ +class Eden_Foursquare_Pageupdates extends Eden_Foursquare_Base { + /* Constants + -------------------------------*/ + const URL_PAGEUPDATES_ADD = 'https://api.foursquare.com/v2/pageupdates/add'; + const URL_PAGEUPDATES_LIST = 'https://api.foursquare.com/v2/pageupdates/list'; + const URL_PAGEUPDATES_DELETE = 'https://api.foursquare.com/v2/pageupdates/%s/delete'; + const URL_PAGEUPDATES_LIKE = 'https://api.foursquare.com/v2/pageupdates/%s/like'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_pageId = NULL; + protected $_groupId = NULL; + protected $_venueId = NULL; + protected $_shout = NULL; + protected $_campaignId = NULL; + protected $_photoId = NULL; + protected $_broadcast = NULL; + + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + public function __construct($token) { + //argument test + Eden_Foursquare_Error::i()->argument(1, 'string'); + $this->_token = $token; + } + + /* Public Methods + -------------------------------*/ + /** + * The page to associate the with broadcast. + * + * @param string + * @return this + */ + public function setPageId($pageId) { + //argument test + Eden_Foursquare_Error::i()->argument(1, 'string'); + $this->_pageId = $pageId; + + return $this; + } + + /** + * The venue group from which to broadcast an update. + * + * @param string + * @return this + */ + public function setGroupId($groupId) { + //argument test + Eden_Foursquare_Error::i()->argument(1, 'string'); + $this->_groupId = $groupId; + + return $this; + } + + /** + * Venue ID indicated which venues to broadcast from. + * + * @param string + * @return this + */ + public function setVenueId($venueId) { + //argument test + Eden_Foursquare_Error::i()->argument(1, 'string'); + $this->_venueId = $venueId; + + return $this; + } + + /** + * Text associated with the broadcast. 160 characters max. + * + * @param string + * @return this + */ + public function setShout($shout) { + //argument test + Eden_Foursquare_Error::i()->argument(1, 'string'); + $this->_shout = $shout; + + return $this; + } + + /** + * An optional special to attach to the broadcast. + * + * @param string + * @return this + */ + public function setCampaignId($campaignId) { + //argument test + Eden_Foursquare_Error::i()->argument(1, 'string'); + $this->_campaignId = $campaignId; + + return $this; + } + + /** + * An optional special to attach to the broadcast. + * + * @param string + * @return this + */ + public function setPhotoId($photoId) { + //argument test + Eden_Foursquare_Error::i()->argument(1, 'string'); + $this->_photoId = $photoId; + + return $this; + } + + /** + * Additional places to send the broadcast to. + * Accepts list of values: + * facebook - share on facebook + * twitter - share on twitter + * private - just create the update without broadcasting to anyone + * + * @param string + * @return this + */ + public function setBroadcast($broadcast) { + //argument test + Eden_Foursquare_Error::i()->argument(1, 'string'); + + //if the input value is not allowed + if(!in_array($broadcast, array('facebook', 'twitter', 'private'))) { + //throw error + Eden_Foursquare_Error::i() + ->setMessage(Eden_Foursquare_Error::INVALID_PAGEUPDATES_BROADCAST) + ->addVariable($broadcast) + ->trigger(); + } + + $this->_broadcast = $broadcast; + + return $this; + } + + /** + * Allows you to add the page's venues. + * + * @return array + */ + public function addPage() { + + $query = array( + 'pageId' => $this->_pageId, //optional + 'groupId' => $this->_groupId, //optional + 'venueId' => $this->_venueId, //optional + 'shout' => $this->_shout, //optional + 'campaignId' => $this->_campaignId, //optional + 'photoId' => $this->_photoId, //optional + 'broadcast' => $this->_broadcast); //optional + + return $this->_post(self::URL_PAGEUPDATES_ADD, $query); + } + + /** + * Returns a list of page updates created by the current user. + * + * @return array + */ + public function getList() { + + return $this->_getResponse(self::URL_PAGEUPDATES_LIST); + } + + /** + * Delete a page update created by the current user. + * + * @param string The ID of the update to delete. + * @return array + */ + public function delete($pageId) { + //argument test + Eden_Foursquare_Error::i()->argument(1, 'string'); + + return $this->_getResponse(sprintf(self::URL_PAGEUPDATES_DELETE, $pageId)); + } + + /** + * Causes the current user to 'like' a page update. + * If there is a campaign associated with the update, + * the like will propagate to the special as well. + * + * @param string The ID of the update to like. + * @return array + */ + public function like($pageId) { + //argument test + Eden_Foursquare_Error::i()->argument(1, 'string'); + + return $this->_getResponse(sprintf(self::URL_PAGEUPDATES_LIKE, $pageId)); + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/foursquare/photos.php b/library/eden/foursquare/photos.php new file mode 100644 index 0000000..33a9374 --- /dev/null +++ b/library/eden/foursquare/photos.php @@ -0,0 +1,59 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Four square photos + * + * @package Eden + * @category four square + * @author Christian Symon M. Buenavista sbuenavista@openovate.com + */ +class Eden_Foursquare_Photos extends Eden_Foursquare_Base { + /* Constants + -------------------------------*/ + const URL_PHOTOS_GET = 'https://api.foursquare.com/v2/photos/%s'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + public function __construct($token) { + //argument test + Eden_Foursquare_Error::i()->argument(1, 'string'); + $this->_token = $token; + } + + /* Public Methods + -------------------------------*/ + /** + * Get details of a photo. + * + * @param string The ID of the photo to retrieve additional information for. + * @return array + */ + public function getDetail($photoId) { + //argument 1 must be a string + Eden_Foursquare_Error::i()->argument(1, 'string'); + + return $this->_getResponse(sprintf(self::URL_PHOTOS_GET, $photoId)); + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/foursquare/settings.php b/library/eden/foursquare/settings.php new file mode 100644 index 0000000..3fb2888 --- /dev/null +++ b/library/eden/foursquare/settings.php @@ -0,0 +1,89 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Four square setting + * + * @package Eden + * @category four square + * @author Christian Symon M. Buenavista sbuenavista@openovate.com + */ +class Eden_Foursquare_Settings extends Eden_Foursquare_Base { + /* Constants + -------------------------------*/ + const URL_SETTINGS_LIST = 'https://api.foursquare.com/v2/settings/all'; + const URL_SETTINGS_CHANGE = 'https://api.foursquare.com/v2/settings/%s/set'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + public function __construct($token) { + //argument test + Eden_Foursquare_Error::i()->argument(1, 'string'); + $this->_token = $token; + } + + /* Public Methods + -------------------------------*/ + /** + * Returns the settings of the acting user. + * + * @return this + */ + public function getSettings() { + + return $this->_getResponse(self::URL_SETTINGS_LIST); + } + + /** + * Change a setting for the given user. + * + * @param string Name of setting to change, sendToTwitter, + * sendMayorshipsToTwitter, sendBadgesToTwitter, sendToFacebook, + * sendMayorshipsToFacebook, sendBadgesToFacebook, receivePings, receiveCommentPings. + * @param integer 1 for true, and 0 for false. + * @return array + */ + public function changeSettings($settingId, $value) { + //argument test + Eden_Foursquare_Error::i() + ->argument(1, 'string') //argument 1 must be a string + ->argument(2, 'int'); //argument 2 must be a integer + + //if the input value is not allowed + if(!in_array($settingId, array('sendToTwitter', 'sendMayorshipsToTwitter', 'sendBadgesToTwitter', 'sendToFacebook', + 'sendMayorshipsToFacebook', 'sendBadgesToFacebook', 'receivePings', 'receiveCommentPings'))) { + //throw error + Eden_Foursquare_Error::i() + ->setMessage(Eden_Foursquare_Error::INVALID_SETTING) + ->addVariable($settingId) + ->trigger(); + } + + $query = array( + 'SETTING_ID' => $settingId, + 'value' => $value); + + return $this->_post(sprintf(self::URL_SETTINGS_CHANGE, $settingId), $query); + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/foursquare/specials.php b/library/eden/foursquare/specials.php new file mode 100644 index 0000000..0e4711c --- /dev/null +++ b/library/eden/foursquare/specials.php @@ -0,0 +1,435 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Four square special + * + * @package Eden + * @category four square + * @author Christian Symon M. Buenavista sbuenavista@openovate.com + */ +class Eden_Foursquare_Specials extends Eden_Foursquare_Base { + /* Constants + -------------------------------*/ + const URL_SPECIAL_ADD = 'https://api.foursquare.com/v2/specials/add'; + const URL_SPECIAL_GET = 'https://api.foursquare.com/v2/specials/list'; + const URL_SPECIAL_SEARCH = 'https://api.foursquare.com/v2/specials/search'; + const URL_SPECIAL_GET_DETAIL = 'https://api.foursquare.com/v2/specials/%s/configuration'; + const URL_SPECIAL_FLAG = 'https://api.foursquare.com/v2/specials/%s/flag'; + const URL_SPECIAL_RETIRE = 'https://api.foursquare.com/v2/specials/%s/retire'; + + /* Public Properties + -------------------------------*/ + protected $_venueId = NULL; + protected $_status = NULL; + protected $_name = NULL; + protected $_finePrint = NULL; + protected $_count1 = NULL; + protected $_count2 = NULL; + protected $_count3 = NULL; + protected $_offerId = NULL; + protected $_cost = NULL; + protected $_type = NULL; + protected $_text = NULL; + + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + public function __construct($token) { + //argument test + Eden_Foursquare_Error::i()->argument(1, 'string'); + $this->_token = $token; + } + + /* Public Methods + -------------------------------*/ + /** + * Set venue Id + * + * @param string + * @return this + */ + public function setVenueId($venueId) { + //argument 1 must be a string + Eden_Foursquare_Error::i()->argument(1, 'string'); + $this->_venueId = $venueId; + + return $this; + } + + /** + * Set specials to return: pending, active, expired, all + * + * @param string + * @return this + */ + public function setStatus($status) { + //argument 1 must be a string + Eden_Foursquare_Error::i()->argument(1, 'string'); + + //if the input value is not allowed + if(!in_array($status, array('pending', 'active', 'expired', 'all'))) { + //throw error + Eden_Foursquare_Error::i() + ->setMessage(Eden_Foursquare_Error::INVALID_STATUS) + ->addVariable($status) + ->trigger(); + } + + $this->_status = $status; + + return $this; + } + + /** + * A name for the special. + * + * @param string + * @return this + */ + public function setName($name) { + //argument 1 must be a string + Eden_Foursquare_Error::i()->argument(1, 'string'); + $this->_name = $name; + + return $this; + } + + /** + * Additional text about why the user has flagged this special + * + * @param string + * @return this + */ + public function setText($text) { + //argument 1 must be a string + Eden_Foursquare_Error::i()->argument(1, 'string'); + $this->_text = $text; + + return $this; + } + + /** + * Maximum length of 200 characters. Fine print, + * shown in small type on the special detail page. + * + * @param string + * @return this + */ + public function setFinePrint($finePrint) { + //argument 1 must be a string + Eden_Foursquare_Error::i()->argument(1, 'string'); + $this->_finePrint = $finePrint; + + return $this; + } + + /** + * Count for frequency, count, regular, swarm, friends, and flash specials + * + * @param integer + * @return this + */ + public function count1($count1) { + //argument 1 must be a integer + Eden_Foursquare_Error::i()->argument(1, 'int'); + $this->_count1 = $count1; + + return $this; + } + + /** + * Secondary count for regular, flash specials + * + * @param integer + * @return this + */ + public function count2($count2) { + //argument 1 must be a integer + Eden_Foursquare_Error::i()->argument(1, 'int'); + $this->_count2 = $count2; + + return $this; + } + + /** + * Tertiary count for flash specials + * + * @param integer + * @return this + */ + public function count3($count3) { + //argument 1 must be a integer + Eden_Foursquare_Error::i()->argument(1, 'int'); + $this->_count3 = $count3; + + return $this; + } + + /** + * Maximum length of 16 characters. + * Internal id in your 3rd party system. + * + * @param integer + * @return this + */ + public function setOfferId($offerId) { + //argument 1 must be a integer + Eden_Foursquare_Error::i()->argument(1, 'int'); + $this->_offerId = $offerId; + + return $this; + } + + /** + * The amount of money the user must spend to use this + * special in dollars and cents. For example, 5.50 meaning 5 dollars and 50 cents. + * + * @param integer|float + * @return this + */ + public function setCost($cost) { + //argument 1 must be a integer or float + Eden_Foursquare_Error::i()->argument(1, 'int', 'float'); + $this->_cost = $cost; + + return $this; + } + + /** + * The type of special to mayor + * unlocked only for the mayor + * + * @param string + * @return this + */ + public function setTypeToMayor() { + $this->_type = 'mayor'; + + return $this; + } + + /** + * The type of special to frequency + * unlocked every count1 check-ins + * + * @param string + * @return this + */ + public function setTypeToFrequency() { + $this->_type = 'frequency'; + + return $this; + } + + /** + * The type of special to count + * unlocked on the count1th check-in (all-time) + * + * @param string + * @return this + */ + public function setTypeToCount() { + $this->_type = 'count'; + + return $this; + } + + /** + * The type of special to regular + * unlocked if you have checked in at least count1 times in the last count2 days + * + * @param string + * @return this + */ + public function setTypeToRegular() { + $this->_type = 'regular'; + + return $this; + } + + /** + * The type of special to swarm + * unlocked if there are count1 people here right now (but only for the first count1 people) + * + * @param string + * @return this + */ + public function setTypeToSwarm() { + $this->_type = 'swarm'; + + return $this; + } + + /** + * The type of special to swarm + * unlocked if at least count1 friends check in together. + * + * @param string + * @return this + */ + public function setTypeToFriends() { + $this->_type = 'friends'; + + return $this; + } + + /** + * The type of special to flash + * first-come first-serve; unlocked for the first count1 + * people to check in between count2 and count3 (given in + * minutes since midnight, local time) each day. In all cases, + * the user must be at the venue (checked in within the last 3 hours, + * and not having checked in anywhere else since then) to unlock a special. + * + * @param string + * @return this + */ + public function setTypeToFlash() { + $this->_type = 'flash'; + + return $this; + } + + /** + * Allows you to create a new special. + * + * @param string Maximum length of 200 characters. + * @param string Maximum length of 200 characters. Special text that is shown when the user has unlocked the special. + * @return array + */ + public function createSpecial($text, $unlockedText) { + //argument test + Eden_Foursquare_Error::i() + ->argument(1, 'string') //argument 1 must be a string + ->argument(2, 'string'); //argument 2 must be a string + + $query = array( + 'text' => $text, + 'unlockedText' => $unlockedText, + 'name' => $this->_name, //optional + 'finePrint' => $this->_finePrint, //optional + 'count1' => $this->_count1, //optional + 'count2' => $this->_count2, //optional + 'count3' => $this->_count3, //optional + 'type' => $this->_type, //optional + 'offerId' => $this->_offerId, //optional + 'cost' => $this->_cost); //optional + + return $this->_post(self::URL_SPECIAL_ADD, $query); + } + + /** + * List available specials. + * + * @return array + */ + public function getSpecial() { + + $query = array( + 'venueId' => $this->_venueId, //optional + 'status' => $this->_status); //optional + + return $this->_getResponse(self::URL_SPECIAL_GET, $query); + } + + /** + * Returns a list of specials near the current location. + * + * @param string|integer|float Longtitude + * @param string|integer|float Latitude + * @return array + */ + public function search($longtitude, $latitude) { + //argument test + Eden_Foursquare_Error::i() + ->argument(1, 'string', 'int', 'float') //argument 1 must be a string, integer or float + ->argument(2, 'string', 'int', 'float'); //argument 2 must be a string, integer or float + + $query = array( + 'll' => $longtitude.',',$latitude, + 'radius' => $this->_radius, //optional + 'limit' => $this->_limit); //optional + + return $this->_getResponse(self::URL_SPECIAL_SEARCH, $query); + } + + /** + * Get special configuration details. + * + * @param string The ID of the special to retrieve configuration details for. + * @return array + */ + public function getSpecialDetail($specialId) { + //argument 1 must be a string + Eden_Foursquare_Error::i()->argument(1, 'string'); + + return $this->_getResponse(sprintf(self::URL_SPECIAL_GET_DETAIL, $specialId)); + } + + /** + * Allows users to indicate a Special is improper in some way. + * + * @param string The ID of the special being flagged + * @param string The id of the venue running the special. + * @param string One of not_redeemable, not_valuable, other + * @return array + */ + public function flag($specialId, $venueId, $problem) { + //argument test + Eden_Foursquare_Error::i() + ->argument(1, 'string') //argument 1 must be a string + ->argument(2, 'string') //argument 2 must be a string + ->argument(3, 'string'); //argument 3 must be a string + + //if the input value is not allowed + if(!in_array($problem, array('not_redeemable', 'not_valuable', 'other'))) { + //throw error + Eden_Foursquare_Error::i() + ->setMessage(Eden_Foursquare_Error::INVALID_PROBLEM_SPECIAL) + ->addVariable($problem) + ->trigger(); + } + + //populate fields + $query = array( + 'venueId' => $venueId, + 'problem' => $problem, + 'text' => $this->_text); //optional + + return $this->_post(sprintf(self::URL_SPECIAL_FLAG, $specialId), $query); + } + + /** + * Retire a special. Retired specials will not show up in the list + * of specials and cannot be assigned to a group. Also ends any + * active campaigns associated with the special. + * + * @param string The ID of the special to retire + * @return array + */ + public function retire($specialId) { + //argument 1 must be a string + Eden_Foursquare_Error::i()->argument(1, 'string'); + + return $this->_post(sprintf(self::URL_SPECIAL_RETIRE, $specialId)); + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/foursquare/tips.php b/library/eden/foursquare/tips.php new file mode 100644 index 0000000..29d9ae0 --- /dev/null +++ b/library/eden/foursquare/tips.php @@ -0,0 +1,305 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Four square tips + * + * @package Eden + * @category four square + * @author Christian Symon M. Buenavista sbuenavista@openovate.com + */ +class Eden_Foursquare_Tips extends Eden_Foursquare_Base { + /* Constants + -------------------------------*/ + const URL_TIPS_ADD = 'https://api.foursquare.com/v2/tips/add'; + const URL_TIPS_SEARCH = 'https://api.foursquare.com/v2/tips/search'; + const URL_TIPS_GET = 'https://api.foursquare.com/v2/tips/%s/done'; + const URL_TIPS_LIST = 'https://api.foursquare.com/v2/tips/%s/listed'; + const URL_TIPS_MARK_DONE = 'https://api.foursquare.com/v2/tips/%s/markdone'; + const URL_TIPS_MARK_TODO = 'https://api.foursquare.com/v2/tips/%s/marktodo'; + const URL_TIPS_UNMARK = 'https://api.foursquare.com/v2/tips/%s/unmark'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_broadcast = NULL; + protected $_url = NULL; + protected $_location = NULL; + protected $_limit = NULL; + protected $_filter = NULL; + protected $_query = NULL; + protected $_group = NULL; + + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + public function __construct($token) { + //argument test + Eden_Foursquare_Error::i()->argument(1, 'string'); + $this->_token = $token; + } + + /* Public Methods + -------------------------------*/ + /** + * The url of the homepage of the venue. + * + * @param string + * @return this + */ + public function setUrl($url) { + //argument 1 must be a string + Eden_Foursquare_Error::i()->argument(1, 'string'); + $this->_url = $url; + + return $this; + } + + /** + * Set location by setting longtitide + * and latitude + * + * @param int|float + * @param int|float + * @return this + */ + public function setLocation($longtitude, $latitude) { + //argument test + Eden_Foursquare_Error::i() + ->argument(1, 'int', 'float') //argument 1 must be an integer or float + ->argument(2, 'int', 'float'); //argument 2 must be an integer or float + + $this->_location = $longtitude.', '.$latitude; + + return $this; + } + + /** + * Number of results to return, up to 50. + * + * @param integer + * @return this + */ + public function setLimit($limit) { + //argument 1 must be a integer + Eden_Foursquare_Error::i()->argument(1, 'int'); + $this->_limit = $limit; + + return $this; + } + + /** + * If set to friends, only show nearby tips from friends. + * + * @param string + * @return this + */ + public function setFilter($filter) { + //argument 1 must be a string + Eden_Foursquare_Error::i()->argument(1, 'string'); + $this->_filter = $filter; + + return $this; + } + + /** + * Only find tips matching the given term, cannot be used in + * conjunction with friends filter. + * + * @param string + * @return this + */ + public function setQuery($query) { + //argument 1 must be a string + Eden_Foursquare_Error::i()->argument(1, 'string'); + $this->_query = $query; + + return $this; + } + + /** + * Whether to broadcast this tip. Send twitter if you want to + * send to twitter, facebook if you want to send to facebook, + * or twitter,facebook if you want to send to both. + * + * @param string + * @return this + */ + public function broadcast($broadcast) { + //argument 1 must be a string + Eden_Foursquare_Error::i()->argument(1, 'string'); + + //if the input value is not allowed + if(!in_array($broadcast, array('facebook', 'twitter', 'followers'))) { + //throw error + Eden_Foursquare_Error::i() + ->setMessage(Eden_Foursquare_Error::INVALID_BROADCAST_TIPS) + ->addVariable($broadcast) + ->trigger(); + } + + $this->_broadcast = $broadcast; + + return $this; + } + + /** + * Can be created, edited, followed, friends, other. If no + * acting user is present, only other is supported. + * + * @param string + * @return this + */ + public function setGroup($group) { + //argument 1 must be a string + Eden_Foursquare_Error::i()->argument(1, 'string'); + + //if the input value is not allowed + if(!in_array($group, array('created', 'edited', 'followed', 'friends', 'other'))) { + //throw error + Eden_Foursquare_Error::i() + ->setMessage(Eden_Foursquare_Error::INVALID_GROUP) + ->addVariable($broadcast) + ->trigger(); + } + + $this->_group = $group; + + return $this; + } + + /** + * Check in to a place. + * + * @param string The venue where the user is checking in + * @param string The text of the tip, up to 200 characters. + * @return array + */ + public function checkin($venueId, $text) { + //argument test + Eden_Foursquare_Error::i() + ->argument(1, 'string') //argument 1 must be a string + ->argument(2, 'string'); //argument 2 must be a string + + $query = array( + 'venueId' => $venueId, + 'text' => $text, + 'broadcast' => $this->_broadcast, //optional + 'url' => $this->_eventId); //optional + + return $this->_post(self::URL_TIPS_ADD, $query); + } + + /** + * Returns a list of tips near the area specified. + * + * @param string The venue where the user is checking in + * @return array + */ + public function search($near) { + //argument 1 must be a string + Eden_Foursquare_Error::i()->argument(1, 'string'); + + //populate fields + $query = array( + 'near' => $near, + 'll' => $this->_location, //optional + 'limit' => $this->_limit, //optional + 'offset' => $this->_offset, //optional + 'filter' => $this->_filters, //optional + 'query' => $this->_query); //optional + + + return $this->_post(self::URL_TIPS_SEARCH, $query); + } + + /** + * Returns an array of users have done this tip. + * + * @param string Identity of a tip to get users who have marked the tip as done. + * @return array + */ + public function getTips($tipId) { + //argument 1 must be a string + Eden_Foursquare_Error::i()->argument(1, 'string'); + + //populate fields + $query = array( + 'limit' => $this->_limit, //optional + 'offset' => $this->_offset); //optional + + return $this->_post(sprintf(self::URL_TIPS_GET, $tipId), $query); + } + + /** + * Returns lists that this tip appears on + * + * @param string Identity of a tip to get lists for. + * @return array + */ + public function getTipsList($tipId) { + //argument 1 must be a string + Eden_Foursquare_Error::i()->argument(1, 'string'); + + //populate fields + $query = array('group' => $this->_group); + + return $this->_post(sprintf(self::URL_TIPS_LIST, $tipId), $query); + } + + /** + * Allows the acting user to mark a tip done. + * + * @param string The tip you want to mark done. + * @return array + */ + public function markDone($tipId) { + //argument 1 must be a string + Eden_Foursquare_Error::i()->argument(1, 'string'); + + return $this->_post(sprintf(self::URL_TIPS_MARK_DONE, $tipId)); + } + + /** + * Allows you to mark a tip to-do. + * + * @param string The tip you want to mark done. + * @return array + */ + public function markToDo($tipId) { + //argument 1 must be a string + Eden_Foursquare_Error::i()->argument(1, 'string'); + + return $this->_post(sprintf(self::URL_TIPS_MARK_TODO, $tipId)); + } + + /** + * Allows you to remove a tip from your to-do list or done list. + * + * @param string The tip you want to mark done. + * @return array + */ + public function unmark($tipId) { + //argument 1 must be a string + Eden_Foursquare_Error::i()->argument(1, 'string'); + + return $this->_post(sprintf(self::URL_TIPS_UNMARK, $tipId)); + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/foursquare/updates.php b/library/eden/foursquare/updates.php new file mode 100644 index 0000000..ef9c918 --- /dev/null +++ b/library/eden/foursquare/updates.php @@ -0,0 +1,97 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Four square updates detail + * + * @package Eden + * @category four square + * @author Christian Symon M. Buenavista sbuenavista@openovate.com + */ +class Eden_Foursquare_Updates extends Eden_Foursquare_Base { + /* Constants + -------------------------------*/ + const URL_UPDATES_NOTIFICATION = 'https://api.foursquare.com/v2/updates/notifications'; + const URL_UPDATES_MARK_AS_READ = 'https://api.foursquare.com/v2/updates/marknotificationsread'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_limit = NULL; + + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + public function __construct($token) { + //argument test + Eden_Foursquare_Error::i()->argument(1, 'string'); + $this->_token = $token; + } + + /* Public Methods + -------------------------------*/ + /** + * Maximum number of results to return, up to 99. + * Notifications are grouped over time, so there will + * usually be fewer than 99 results available at any given + * time. offset 0 Used to page through results. Only the 99 most + * recent notifications are visible, so offset must be no more + * than 99 - limit. + * + * @param integer + * @return this + */ + public function setLimit($limit) { + //argument 1 must be a string + Eden_Foursquare_Error::i()->argument(1, 'int'); + $this->_limit = $limit; + + return $this; + } + + /** + * Retrieve a user's notification tray notifications + * + * @return array + */ + public function getNotification() { + + $query = array('limit' => $this->_limit); //optional + + return $this->_getResponse(self::URL_UPDATES_NOTIFICATION, $query); + } + + /** + * Mark notification tray notifications as read up, to a certain timestamp. + * + * @param string|integer The timestamp of the most recent notification that the user viewed. + * @return array + */ + public function markAsRead($highWatermark) { + //argument 1 must be a string or integer + Eden_Foursquare_Error::i()->argument(1, 'string', 'int'); + + $highWatermark = strtotime($highWatermark); + + $query = array('highWatermark' => $highWatermark); //optional + + return $this->_post(self::URL_UPDATES_MARK_AS_READ, $query); + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/foursquare/users.php b/library/eden/foursquare/users.php new file mode 100644 index 0000000..8fa59d6 --- /dev/null +++ b/library/eden/foursquare/users.php @@ -0,0 +1,530 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Four square users + * + * @package Eden + * @category four square + * @author Christian Symon M. Buenavista sbuenavista@openovate.com + */ +class Eden_Foursquare_Users extends Eden_Foursquare_Base { + /* Constants + -------------------------------*/ + const URL_USERS = 'https://api.foursquare.com/v2/users/self'; + const URL_USERS_LEADERBOARD = 'https://api.foursquare.com/v2/users/leaderboard'; + const URL_USERS_PENDING = 'https://api.foursquare.com/v2/users/requests'; + const URL_USERS_SEARCH = 'https://api.foursquare.com/v2/users/search'; + const URL_USERS_BADGES = 'https://api.foursquare.com/v2/users/self/badges'; + const URL_USERS_CHECKINS = 'https://api.foursquare.com/v2/users/self/checkins'; + const URL_USERS_FRIENDS = 'https://api.foursquare.com/v2/users/self/friends'; + const URL_USERS_LIST = 'https://api.foursquare.com/v2/users/self/lists'; + const URL_USERS_MAYORSHIPS = 'https://api.foursquare.com/v2/users/self/mayorships'; + const URL_USERS_PHOTOS = 'https://api.foursquare.com/v2/users/self/photos'; + const URL_USERS_TIPS = 'https://api.foursquare.com/v2/users/self/tips'; + const URL_USERS_TODOS = 'https://api.foursquare.com/v2/users/self/todos'; + const URL_USERS_VENUE = 'https://api.foursquare.com/v2/users/self/venuehistory'; + + const URL_USERS_UPDATE_PHOTO = 'https://api.foursquare.com/v2/users/self/update'; + const URL_USERS_UNFRIEND = 'https://api.foursquare.com/v2/users/self/unfriend'; + const URL_USERS_SETPINGS = 'https://api.foursquare.com/v2/users/self/setpings'; + const URL_USERS_SEND_REQUEST = 'https://api.foursquare.com/v2/users/self/request'; + const URL_USERS_DENY_REQUEST = 'https://api.foursquare.com/v2/users/self/deny'; + const URL_USERS_APPROVE_REQUEST = 'https://api.foursquare.com/v2/users/self/approve'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_sort = 'popular'; + protected $_token = NULL; + protected $_phone = NULL; + protected $_email = NULL; + protected $_twitter = NULL; + protected $_twitterSource = NULL; + protected $_fbid = NULL; + protected $_name = NULL; + protected $_limit = NULL; + protected $_offset = NULL; + protected $_afterTimestamp = NULL; + protected $_beforeTimestamp = NULL; + protected $_group = NULL; + protected $_location = NULL; + protected $_catagoryId = NULL; + protected $_userId = NULL; + protected $_photo = NULL; + + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + public function __construct($token) { + //argument test + Eden_Foursquare_Error::i()->argument(1, 'string'); + $this->_token = $token; + + } + + /* Public Methods + -------------------------------*/ + /** + * Set phone + * + * @param string + * @return this + */ + public function setPhone($phone) { + //argument test + Eden_Foursquare_Error::i()->argument(1, 'string'); + $this->_phone = $phone; + + return $this; + } + + /** + * Set email + * + * @param string + * @return this + */ + public function setEmail($email) { + //argument test + Eden_Foursquare_Error::i()->argument(1, 'string'); + $this->_email = $email; + + return $this; + } + + /** + * Set twitter account + * + * @param string + * @return this + */ + public function setTwitter($twitter) { + //argument test + Eden_Foursquare_Error::i()->argument(1, 'string'); + $this->_twitter = $twitter; + + return $this; + } + + /** + * Set twitter account id + * + * @param string + * @return this + */ + public function setTwitterSource($twitterSource) { + //argument test + Eden_Foursquare_Error::i()->argument(1, 'string'); + $this->_twitterSource = $twitterSource; + + return $this; + } + + /** + * Set facebook account + * + * @param string + * @return this + */ + public function setFacebookId($facebookId) { + //argument test + Eden_Foursquare_Error::i()->argument(1, 'string'); + $this->_facebookId = $facebookId; + + return $this; + } + + /** + * Set name + * + * @param string + * @return this + */ + public function setName($name) { + //argument test + Eden_Foursquare_Error::i()->argument(1, 'string'); + $this->_name = $name; + + return $this; + } + + /** + * Set limits + * + * @param integer + * @return this + */ + public function setLimit($limit) { + //argument test + Eden_Foursquare_Error::i()->argument(1, 'int'); + $this->_limit = $limit; + + return $this; + } + + /** + * Set to get a results after + * timestamp + * + * @return this + */ + public function setAfterTimeStamp() { + $this->_afterTimeStamp = time(); + + return $this; + } + + /** + * Set to get a results before + * timestamp + * + * @return this + */ + public function setBeforeTimeStamp() { + $this->_beforeTimeStamp = time(); + + return $this; + } + + /** + * Set offset for the results + * timestamp + * + * @param integer + * @return this + */ + public function setOffset($offset) { + //argument test + Eden_Foursquare_Error::i()->argument(1, 'int'); + $this->_offset = $offset; + + return $this; + } + + /** + * Set groups + * + * @param string + * @return this + */ + public function setGroup($group) { + //argument test + Eden_Foursquare_Error::i()->argument(1, 'string'); + $this->_group = $group; + + return $this; + } + + /** + * Sort results by recent tips + * + * @return this + */ + public function sortByRecent() { + $this->_sort = 'recent'; + + return $this; + } + + /** + * Sort results by near by tips + * + * @return this + */ + public function sortByNearBy() { + $this->_sort = 'nearby'; + + return $this; + } + + /** + * Set location by setting longtitide + * and latitude + * + * @param int|float + * @param int|float + * @return this + */ + public function setLocation($longtitude, $latitude) { + //argument test + Eden_Foursquare_Error::i() + ->argument(1, 'int', 'float') //argument 1 must be an integer or float + ->argument(2, 'int', 'float'); //argument 2 must be an integer or float + + $this->_location = $longtitude.', '.$latitude; + + return $this; + } + + /** + * Returns users informations + * + * @return array + */ + public function getList() { + + return $this->_getResponse(self::URL_USERS); + } + + /** + * Returns users leader board + * + * @param string + * @return array + */ + public function getLeaderBoard() { + + return $this->_getResponse(self::URL_USERS_LEADERBOARD); + } + + /** + * Returns users all pending request + * + * @return array + */ + public function getPendingRequest() { + + return $this->_getResponse(self::URL_USERS_PENDING); + } + + /** + * Returns users search + * + * @return array + */ + public function search() { + //populate fields + $query = array( + 'phone' => $this->_phone, //optional + 'email' => $this->_email, //optional + 'twitter' => $this->_twitter, //optional + 'twitterSource' => $this->_twitterSource, //optional + 'fbid' => $this->_fbid, //optional + 'name' => $this->_name); //optional + + return $this->_getResponse(self::URL_USERS_SEARCH, $query); + } + + /** + * Returns users badges + * + * @return array + */ + public function getBadget() { + + return $this->_getResponse(self::URL_USERS_BADGES); + } + + /** + * Returns users checkins + * + * @return array + */ + public function getCheckins() { + + //populate fields + $query = array( + 'limit' => $this->_limit, //optional + 'offset' => $this->_offset, //optional + 'afterTimestamp' => $this->_afterTimestamp, //optional + 'beforeTimestamp' => $this->_beforeTimestamp); //optional + + return $this->_getResponse(self::URL_USERS_CHECKINS, $query); + } + + /** + * Returns users friends + * + * @param string + * @return array + */ + public function getFriends() { + + //populate fields + $query = array( + 'limit' => $this->_limit, //optional + 'offset' => $this->_offset); //optional + + return $this->_getResponse(self::URL_USERS_FRIENDS, $query); + } + + /** + * Returns users list + * + * @return array + */ + public function getUsersList() { + + //populate fields + $query = array( + 'group' => $this->_group, //optional + 'll' => $this->_location); //optional + + return $this->_getResponse(self::URL_USERS_LIST, $query); + } + + /** + * Returns users mayor ships + * + * @return array + */ + public function getMayorships() { + + return $this->_getResponse(self::URL_USERS_MAYORSHIPS); + } + + /** + * Returns users photos + * + * @return array + */ + public function getPhotos() { + //populate fields + $query = array( + 'limit' => $this->_limit, //optional + 'offset' => $this->_offset); //optional + + return $this->_getResponse(self::URL_USERS_PHOTOS, $query); + } + + /** + * Returns users catagory history + * + * @return array + */ + public function getVenuehistory() { + + //populate fields + $query = array( + 'categoryId' => $this->_categoryId, + 'afterTimestamp' => $this->_afterTimestamp, + 'beforeTimestamp' => $this->_beforeTimestamp); + + return $this->_getResponse(self::URL_USERS_VENUE, $query); + } + + /** + * Updates the user's profile photo. + * + * @param string Photo under 100KB in multipart MIME encoding with content type image/jpeg, image/gif, or image/png. + * @return array + */ + public function updatePhoto($photo) { + //argument 1 must be a string + Eden_Foursquare_Error::i()->argument(1, 'string'); + + //populate fields + $query = array('photo' => $photo); + + return $this->_post(self::URL_USERS_UPDATE_PHOTO, $query); + + } + + /** + * Cancels any relationship between the + * acting user and the specified user. + * + * @param string Identity of the user to unfriend. + * @return array + */ + public function unFriend($userId) { + //argument 1 must be a string + Eden_Foursquare_Error::i()->argument(1, 'string'); + + //populate fields + $query = array('USER_ID' => $userId); + + return $this->_post(self::URL_USERS_UNFRIEND, $query); + + } + + /** + * Changes whether the acting user will receive pings + * when the specified user checks in. + * + * @param string The user ID of a friend. + * @param boolean + * @return array + */ + public function setPings($userId, $value) { + //argument test + Eden_Foursquare_Error::i() + ->argument(1, 'string') //argument 1 must be a string + ->argument(2, 'bool'); //argument 2 must be a boolean + + //populate fields + $query = array( + 'USER_ID' => $this->_userId, + 'value' => $this->_value); + + return $this->_post(self::URL_USERS_SETPINGS, $query); + } + + /** + * Sends a friend request to another user. + * + * @param string The user ID to which a request will be sent. + * @return array + */ + public function sendRequest($userId) { + //argument 1 must be a string + Eden_Foursquare_Error::i()->argument(1, 'string'); + + //populate fields + $query = array('USER_ID' => $userId); + + return $this->_post(self::URL_USERS_SEND_REQUEST, $query); + + } + + /** + * Denies a pending friend request from another user. + * + * @param string The user ID of a pending friend. + * @return array + */ + public function denyRequest($userId) { + //argument 1 must be a string + Eden_Foursquare_Error::i()->argument(1, 'string'); + //populate fields + $query = array('USER_ID' => $userId); + + return $this->_post(self::URL_USERS_DENY_REQUEST, $query); + + } + + /** + * Approves a pending friend request from another user. + * + * @param string The user ID of a pending friend. + * @return array + */ + public function approveRequest($userId) { + //argument 1 must be a string + Eden_Foursquare_Error::i()->argument(1, 'string'); + + //populate fields + $query = array('USER_ID' => $userId); + + return $this->_post(self::URL_USERS_APPROVE_REQUEST, $query); + + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/foursquare/venue.php b/library/eden/foursquare/venue.php new file mode 100644 index 0000000..a387ffd --- /dev/null +++ b/library/eden/foursquare/venue.php @@ -0,0 +1,687 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Four square Venue + * + * @package Eden + * @category four square + * @author Christian Symon M. Buenavista sbuenavista@openovate.com + */ +class Eden_Foursquare_Venue extends Eden_Foursquare_Base { + /* Constants + -------------------------------*/ + const URL_VENUE = 'https://api.foursquare.com/v2/venues/%s'; + const URL_VENUE_ADD = 'https://api.foursquare.com/v2/venues/add'; + const URL_VENUE_CATEGORY = 'https://api.foursquare.com/v2/venues/categories'; + const URL_VENUE_MANAGE = 'https://api.foursquare.com/v2/venues/managed'; + const URL_VENUE_TIME = 'https://api.foursquare.com/v2/venues/timeseries'; + const URL_VENUE_SEARCH = 'https://api.foursquare.com/v2/venues/search'; + const URL_VENUE_TRENDING = 'https://api.foursquare.com/v2/venues/trending'; + const URL_VENUE_EVENTS = 'https://api.foursquare.com/v2/venues/%s/events'; + const URL_VENUE_LIST = 'https://api.foursquare.com/v2/venues/%s/listed'; + const URL_VENUE_MENU = 'https://api.foursquare.com/v2/venues/%s/menu'; + const URL_VENUE_PHOTOS = 'https://api.foursquare.com/v2/venues/%s/photos'; + const URL_VENUE_SIMILAR = 'https://api.foursquare.com/v2/venues/%s/similar'; + const URL_VENUE_STATS = 'https://api.foursquare.com/v2/venues/%s/stats'; + const URL_VENUE_TIPS = 'https://api.foursquare.com/v2/venues/%s/tips'; + + const URL_VENUE_EDIT = 'https://api.foursquare.com/v2/venues/%s/edit'; + const URL_VENUE_FLAG = 'https://api.foursquare.com/v2/venues/%s/flag'; + const URL_VENUE_MARK = 'https://api.foursquare.com/v2/venues/%s/marktodo'; + const URL_VENUE_PROPOSE_EDIT = 'https://api.foursquare.com/v2/venues/%s/proposeedit'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_id = NULL; + protected $_crossStreet = NULL; + protected $_city = NULL; + protected $_state = NULL; + protected $_zip = NULL; + protected $_phone = NULL; + protected $_twitter = NULL; + protected $_primaryCategoryId = NULL; + protected $_description = NULL; + protected $_url = NULL; + protected $_limit = NULL; + protected $_radius = NULL; + protected $_startTime = NULL; + protected $_endTime = NULL; + protected $_name = NULL; + protected $_address = NULL; + protected $_location = NULL; + protected $_text = NULL; + protected $_categoryId = NULL; + + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + public function __construct($token) { + //argument test + Eden_Foursquare_Error::i()->argument(1, 'string'); + $this->_token = $token; + } + + /* Public Methods + -------------------------------*/ + /** + * Set name of the venue + * + * @param string + * @return this + */ + public function setVenueName($venueName) { + //argument 1 must be a string + Eden_Foursquare_Error::i()->argument(1, 'string'); + $this->_name = $venueName; + + return $this; + } + + /** + * Set text of the tip + * + * @param string + * @return this + */ + public function setText($text) { + //argument 1 must be a string + Eden_Foursquare_Error::i()->argument(1, 'string'); + $this->_text = $text; + + return $this; + } + + /** + * Set address of the venue + * + * @param string + * @return this + */ + public function setVenueAddress($venueAddress) { + //argument 1 must be a string + Eden_Foursquare_Error::i()->argument(1, 'string'); + $this->_address = $venueAddress; + + return $this; + } + + + /** + * Set location by setting longtitide + * and latitude + * + * @param int|float + * @param int|float + * @return this + */ + public function setLocation($longtitude, $latitude) { + //argument test + Eden_Foursquare_Error::i() + ->argument(1, 'int', 'float') //argument 1 must be an integer or float + ->argument(2, 'int', 'float'); //argument 2 must be an integer or float + + $this->_location = $longtitude.', '.$latitude; + + return $this; + } + + /** + * Set twitter account + * + * @param string + * @return this + */ + public function setTwitter($twitter) { + //argument test + Eden_Foursquare_Error::i()->argument(1, 'string'); + $this->_twitter = $twitter; + + return $this; + } + + /** + * Set category id + * + * @param string + * @return this + */ + public function setCategoryId($categoryId) { + //argument test + Eden_Foursquare_Error::i()->argument(1, 'string'); + $this->_categoryId = $categoryId; + + return $this; + } + + /** + * The nearest intersecting street or streets. + * + * @param string + * @return this + */ + public function setCrossStreet($crossStreet) { + //argument 1 must be a string + Eden_Foursquare_Error::i()->argument(1, 'string'); + $this->_crossStreet = $crossStreet; + + return $this; + } + + /** + * The city name where this venue is. + * + * @param string + * @return this + */ + public function setCity($city) { + //argument 1 must be a string + Eden_Foursquare_Error::i()->argument(1, 'string'); + $this->_city = $city; + + return $this; + } + + /** + * The nearest state or province to the venue. + * + * @param string + * @return this + */ + public function setState($state) { + //argument 1 must be a string + Eden_Foursquare_Error::i()->argument(1, 'string'); + $this->_state = $state; + + return $this; + } + + /** + * The zip or postal code for the venue. + * + * @param string + * @return this + */ + public function setZip($zip) { + //argument 1 must be a string + Eden_Foursquare_Error::i()->argument(1, 'string'); + $this->_zip = $zip; + + return $this; + } + + /** + * The phone number of the venue. + * + * @param string + * @return this + */ + public function setPhone($phone) { + //argument 1 must be a string + Eden_Foursquare_Error::i()->argument(1, 'string'); + $this->_phone = $phone; + + return $this; + } + + /** + * The ID of the category to which you want to assign this venue. + * + * @param string + * @return this + */ + public function setPrimaryCategoryId($primaryCategoryId) { + //argument 1 must be a string + Eden_Foursquare_Error::i()->argument(1, 'string'); + $this->_primaryCategoryId = $primaryCategoryId; + + return $this; + } + + /** + * A freeform description of the venue, up to 300 characters. + * + * @param string + * @return this + */ + public function setDescription($description) { + //argument 1 must be a string + Eden_Foursquare_Error::i()->argument(1, 'string'); + $this->_description = $description; + + return $this; + } + + /** + * The url of the homepage of the venue. + * + * @param string + * @return this + */ + public function setUrl($url) { + //argument 1 must be a string + Eden_Foursquare_Error::i()->argument(1, 'string'); + $this->_url = $url; + + return $this; + } + + /** + * Number of results to return, up to 50. + * + * @param integer + * @return this + */ + public function setLimit($limit) { + //argument 1 must be a string + Eden_Foursquare_Error::i()->argument(1, 'int'); + $this->_limit = $limit; + + return $this; + } + + /** + * Radius in meters, up to approximately 2000 meters. + * + * @param integer + * @return this + */ + public function setRadius($radius) { + //argument 1 must be a string + Eden_Foursquare_Error::i()->argument(1, 'int'); + $this->_radius = $radius; + + return $this; + } + + /** + * The start of the time range to retrieve stats for + * (seconds since epoch). If omitted, all-time stats will be returned. + * + * @param integer|integer + * @return this + */ + public function setStartTime($startTime) { + //argument 1 must be a string or integer + Eden_Foursquare_Error::i()->argument(1, 'string', 'int'); + $this->_startTime = $startTime; + + return $this; + } + + /** + * The end of the time range to retrieve stats for + * (seconds since epoch). If omitted, the current time is assumed. + * + * @param integer|integer + * @return this + */ + public function setEndTime($endTime) { + //argument 1 must be a string or integer + Eden_Foursquare_Error::i()->argument(1, 'string', 'int'); + $this->_endTime = $endTime; + + return $this; + } + + /** + * Allows users to add a new venue. + * + * @param string + * @param string|integer|float + * @param string|integer|float + * @return array + */ + public function addVenue($venueName, $latitude, $longtitude) { + //argument test + Eden_Foursquare_Error::i() + ->argument(1, 'string') //argument 1 must be a string + ->argument(2, 'string', 'int', 'float') //argument 2 must be a string or integer or float + ->argument(3, 'string', 'int', 'float'); //argument 3 must be a string or integer or float + + //populate fields + $query = array( + 'name' => $venueName, + 'll' => $latitude.','.$longtitude, + 'crossStreet' => $this->_crossStreet, //optional + 'city' => $this->_city, //optional + 'state' => $this->_state, //optional + 'zip' => $this->_zip, //optional + 'phone' => $this->_phone, //optional + 'twitter' => $this->_twitter, //optional + 'primaryCategoryId' => $this->_primaryCategoryId, //optional + 'description' => $this->_description, //optional + 'url' => $this->_url); //optional + + return $this->_post(self::URL_VENUE_ADD, $query); + } + + /** + * Returns a hierarchical list of categories applied to venues. + * + * @return array + */ + public function getVenueCategories() { + + return $this->_getResponse(self::URL_VENUE_CATEGORY); + } + + /** + * Returns a list of venues the current user manages. + * + * @return array + */ + public function getManagedVenues() { + + return $this->_getResponse(self::URL_VENUE_MANAGE); + } + + /** + * Returns a list of venues near the current location, + * optionally matching the search term. + * + * @param string A string naming a place in the world + * @param string|integer|float + * @param string|integer|float + * @return array + */ + public function search($near, $latitude, $longtitude) { + //argument test + Eden_Foursquare_Error::i() + ->argument(1, 'string') //argument 1 must be a string + ->argument(2, 'string', 'int', 'float') //argument 2 must be a string or integer or float + ->argument(3, 'string', 'int', 'float'); //argument 3 must be a string or integer or float + + //populate fields + $query = array( + 'near' => $name, + 'll' => $latitude.','.$longtitude); + + return $this->_post(self::URL_VENUE_ADD, $query); + } + + /** + * Get daily venue stats for a list of venues over a time range. + * + * @param string|integer The start of the time range to retrieve stats. Example: YYYY-MM-DD + * @param string + * @return array + */ + public function getDailyVenueStats($startTime, $venueId) { + //argument test + Eden_Foursquare_Error::i() + ->argument(1, 'string', 'int') //argument 1 must be a string or integer + ->argument(2, 'string'); //argument 2 must be a string + + $startTime = strtotime($startTime); + + $query = array( + 'startAt' => $startTime, + 'venueId' => $venueId); + + return $this->_getResponse(self::URL_VENUE_TIME, $query); + } + + /** + * Returns a list of venues near the current location with the most people currently checked in. + * + * @param string|integer|float + * @param string|integer|float + * @return array + */ + public function getTrending($latitude, $longtitude) { + //argument test + Eden_Foursquare_Error::i() + ->argument(1, 'string', 'int', 'float') //argument 1 must be a string or integer or float + ->argument(2, 'string', 'int', 'float'); //argument 2 must be a string or integer or float + + //populate fields + $query = array( + 'll' => $latitude.','.$longtitude, + 'limit' => $this->_limit, //optional + 'radius' => $this->_radius); //optional + + return $this->_getResponse(self::URL_VENUE_TRENDING, $query); + } + + /** + * Allows you to access information about the current events at a place. + * + * @param string The venue id for which events are being requested. + * @return array + */ + public function getVenueEventInfo($venueId) { + //argument 1 must be a string + Eden_Foursquare_Error::i()->argument(1, 'string'); + + return $this->_getResponse(sprintf(self::URL_VENUE_EVENT, $venueId)); + } + + /** + * The lists that this venue appears on + * + * @param string Identity of a venue to get lists for. + * @return array + */ + public function getVenueList($venueId) { + //argument 1 must be a string + Eden_Foursquare_Error::i()->argument(1, 'string'); + + //populate fields + $query = array('limit' => $this->_limit); //optional + + return $this->_getResponse(sprintf(self::URL_VENUE_LIST, $venueId), $query); + } + + /** + * Returns menu information for a venue + * + * @param string The venue id for which menu is being requested. + * @return array + */ + public function getVenueMenu($venueId) { + //argument 1 must be a string + Eden_Foursquare_Error::i()->argument(1, 'string'); + + return $this->_getResponse(sprintf(self::URL_VENUE_MENU, $venueId)); + } + + /** + * Returns menu information for a venue + * + * @param string The venue you want photos for. + * @param string checkin or venue + * @return array + */ + public function getVenuePhoto($venueId, $group) { + //argument test + Eden_Foursquare_Error::i() + ->argument(1, 'string') //argument 1 must be a string + ->argument(2, 'string'); //argument 2 must be a string + + //if the input value is not allowed + if(!in_array($group, array('checkin', 'venue'))) { + //throw error + Eden_Foursquare_Error::i() + ->setMessage(Eden_Foursquare_Error::INVALID_GROUPS) + ->addVariable($group) + ->trigger(); + } + + //populate fields + $query = array( + 'group' => $groups, + 'limit' => $this->_limit); //optional + + return $this->_getResponse(sprintf(self::URL_VENUE_PHOTO, $venueId), $query); + } + + /** + * Returns a list of venues similar to the specified venue. + * + * @param string The venue you want similar venues for. + * @return array + */ + public function getSimilarVenues($venueId) { + //argument 1 must be a string + Eden_Foursquare_Error::i()->argument(1, 'string'); + + return $this->_getResponse(sprintf(self::URL_VENUE_SIMILAR, $venueId)); + } + + /** + * Returns venue stats over a given time range. + * + * @param string The venue you want similar venues for. + * @return array + */ + public function getVenueStats($venueId) { + //argument 1 must be a string + Eden_Foursquare_Error::i()->argument(1, 'string'); + + //populate fields + $query = array( + 'startAt' => $this->_startTime, //optional + 'endAt' => $this->_endTime); //optional + + return $this->_getResponse(sprintf(self::URL_VENUE_STATS, $venueId), $query); + } + + /** + * Returns tips for a venue. + * + * @param string The venue you want tips for. + * @return array + */ + public function getVenueTips($venueId) { + //argument 1 must be a string + Eden_Foursquare_Error::i()->argument(1, 'string'); + + //populate fields + $query = array('limit' => $this->_limit); //optional + + return $this->_getResponse(sprintf(self::URL_VENUE_STATS, $venueId), $query); + } + + /** + * Make changes to a venue + * + * @param string The venue id to edit + * @return array + */ + public function editVenue($venueId) { + //argument 1 must be a string + Eden_Foursquare_Error::i()->argument(1, 'string'); + + //populate fields + $query = array( + 'VENUE_ID' => $venueId, + 'name' => $this->_name, //optional + 'address' => $this->_address, //optional + 'crossStreet' => $this->_crossStreet, //optional + 'city' => $this->_city, //optional + 'state' => $this->_state, //optional + 'zip' => $this->_zip, //optional + 'phone' => $this->_phone, //optional + 'll ' => $this->_location, //optional + 'categoryId' => $this->_categoryId, //optional + 'twitter' => $this->_twitter, //optional + 'description' => $this->_description, //optional + 'url' => $this->_url); //optional + + return $this->_post(sprintf(self::URL_VENUE_EDIT, $venueId), $query); + } + + /** + * Allows users to indicate a venue is incorrect in some way. + * + * @param string The venue id for which an edit is being proposed + * @param string One of mislocated, closed, duplicate, inappropriate, doesnt_exist, event_over + * @return array + */ + public function flagVenue($venueId, $problem) { + //argument test + Eden_Foursquare_Error::i() + ->argument(1, 'string') //argument 1 must be a string + ->argument(2, 'string'); //argument 2 must be a string + + //if the input value is not allowed + if(!in_array($problem, array('mislocated', 'closed', 'duplicate', 'inappropriate', 'doesnt_exist', 'event_over'))) { + //throw error + Eden_Foursquare_Error::i() + ->setMessage(Eden_Foursquare_Error::INVALID_PROBLEM) + ->addVariable($problem) + ->trigger(); + } + + //populate fields + $query = array( + 'VENUE_ID' => $venueId, + 'problem' => $problem); + + return $this->_post(sprintf(self::URL_VENUE_FLAG, $venueId), $query); + } + + /** + * Allows you to mark a venue to-do, with optional text. + * + * @param string The venue id for which an edit is being proposed + * @param string One of mislocated, closed, duplicate, inappropriate, doesnt_exist, event_over + * @return array + */ + public function markVenue($venueId) { + //argument 1 must be a string + Eden_Foursquare_Error::i()->argument(1, 'string'); + + //populate fields + $query = array( + 'VENUE_ID' => $venueId, + 'text' => $this->_text); + + return $this->_post(sprintf(self::URL_VENUE_MARK, $venueId), $query); + } + + /** + * Make changes to a venue + * + * @param string The venue id to edit + * @return array + */ + public function proposeEdit($venueId) { + //argument 1 must be a string + Eden_Foursquare_Error::i()->argument(1, 'string'); + + //populate fields + $query = array( + 'VENUE_ID' => $venueId, + 'name' => $this->_name, //optional + 'address' => $this->_address, //optional + 'crossStreet' => $this->_crossStreet, //optional + 'city' => $this->_city, //optional + 'state' => $this->_state, //optional + 'zip' => $this->_zip, //optional + 'phone' => $this->_phone, //optional + 'll ' => $this->_location, //optional + 'primaryCategoryId' => $this->_primaryCategoryId); //optional + + return $this->_post(sprintf(self::URL_VENUE_PROPOSE_EDIT, $venueId), $query); + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/foursquare/venuegroups.php b/library/eden/foursquare/venuegroups.php new file mode 100644 index 0000000..d570da7 --- /dev/null +++ b/library/eden/foursquare/venuegroups.php @@ -0,0 +1,408 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Four square Venue groups + * + * @package Eden + * @category four square + * @author Christian Symon M. Buenavista sbuenavista@openovate.com + */ +class Eden_Foursquare_Venuegroups extends Eden_Foursquare_Base { + /* Constants + -------------------------------*/ + const URL_VENUE_GROUPS_ADD = 'https://api.foursquare.com/v2/venuegroups/add'; + const URL_VENUE_GROUPS_DELETE = 'https://api.foursquare.com/v2/venuegroups/%s/delete'; + const URL_VENUE_GROUPS_LIST = 'https://api.foursquare.com/v2/venuegroups/list'; + const URL_VENUE_GROUPS_TIMESERIES = 'https://api.foursquare.com/v2/venuegroups/%s/timeseries'; + const URL_VENUE_GROUPS_ADDVENUE = 'https://api.foursquare.com/v2/venuegroups/%s/addvenue'; + const URL_VENUE_GROUPS_CAMPAIGNS = 'https://api.foursquare.com/v2/venuegroups/%s/campaigns'; + const URL_VENUE_GROUPS_EDIT_VENUE = 'https://api.foursquare.com/v2/venuegroups/%s/edit'; + const URL_VENUE_GROUPS_REMOVE = 'https://api.foursquare.com/v2/venuegroups/%s/removevenue'; + const URL_VENUE_GROUPS_UPDATE = 'https://api.foursquare.com/v2/venuegroups/%s/update'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_venueId = NULL; + protected $_city = NULL; + protected $_state = NULL; + protected $_zip = NULL; + protected $_phone = NULL; + protected $_twitter = NULL; + protected $_description = NULL; + protected $_url = NULL; + protected $_categoryId = NULL; + + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + public function __construct($token) { + //argument test + Eden_Foursquare_Error::i()->argument(1, 'string'); + $this->_token = $token; + } + + /* Public Methods + -------------------------------*/ + /** + * Set venue Id + * + * @param string + * @return this + */ + public function setVenueId($venueId) { + //argument 1 must be a string + Eden_Foursquare_Error::i()->argument(1, 'string'); + $this->_venueId = $venueId; + + return $this; + } + + /** + * Set name of the venue + * + * @param string + * @return this + */ + public function setVenueName($venueName) { + //argument 1 must be a string + Eden_Foursquare_Error::i()->argument(1, 'string'); + $this->_name = $venueName; + + return $this; + } + + /** + * Set twitter account + * + * @param string + * @return this + */ + public function setTwitter($twitter) { + //argument test + Eden_Foursquare_Error::i()->argument(1, 'string'); + $this->_twitter = $twitter; + + return $this; + } + + /** + * The city name where this venue is. + * + * @param string + * @return this + */ + public function setCity($city) { + //argument 1 must be a string + Eden_Foursquare_Error::i()->argument(1, 'string'); + $this->_city = $city; + + return $this; + } + + /** + * The nearest state or province to the venue. + * + * @param string + * @return this + */ + public function setState($state) { + //argument 1 must be a string + Eden_Foursquare_Error::i()->argument(1, 'string'); + $this->_state = $state; + + return $this; + } + + /** + * The zip or postal code for the venue. + * + * @param string + * @return this + */ + public function setZip($zip) { + //argument 1 must be a string + Eden_Foursquare_Error::i()->argument(1, 'string'); + $this->_zip = $zip; + + return $this; + } + + /** + * The phone number of the venue. + * + * @param string + * @return this + */ + public function setPhone($phone) { + //argument 1 must be a string + Eden_Foursquare_Error::i()->argument(1, 'string'); + $this->_phone = $phone; + + return $this; + } + + /** + * A freeform description of the venue, up to 300 characters. + * + * @param string + * @return this + */ + public function setDescription($description) { + //argument 1 must be a string + Eden_Foursquare_Error::i()->argument(1, 'string'); + $this->_description = $description; + + return $this; + } + + /** + * The url of the homepage of the venue. + * + * @param string + * @return this + */ + public function setUrl($url) { + //argument 1 must be a string + Eden_Foursquare_Error::i()->argument(1, 'string'); + $this->_url = $url; + + return $this; + } + + /** + * Set category id + * + * @param string + * @return this + */ + public function setCategoryId($categoryId) { + //argument test + Eden_Foursquare_Error::i()->argument(1, 'string'); + $this->_categoryId = $categoryId; + + return $this; + } + + /** + * The end of the time range to retrieve stats for + * + * @param string + * @return this + */ + public function setEndTime($endTime) { + //argument 1 must be a string + Eden_Foursquare_Error::i()->argument(1, 'string'); + $this->_endTime = strtotime($endTime); + + return $this; + } + + /** + * Specifies which fields to return. May be one or more of totalCheckins, + * newCheckins, uniqueVisitors, sharing, genders, ages, hours. + * + * @param string + * @return this + */ + public function setFields($fields) { + //argument 1 must be a string + Eden_Foursquare_Error::i()->argument(1, 'string'); + + //if the input value is not allowed + if(!in_array($fields, array('totalCheckins', 'newCheckins', 'uniqueVisitors', 'sharing', 'genders', 'ages', 'hours'))) { + //throw error + Eden_Foursquare_Error::i() + ->setMessage(Eden_Foursquare_Error::INVALID_FIELDS) + ->addVariable($fields) + ->trigger(); + } + + $this->_fields = $fields; + + return $this; + } + + /** + * Create a venue group + * + * @param string The name to give the group. + * @return array + */ + public function addVenueGroups($name) { + //argument 1 must be a string + Eden_Foursquare_Error::i()->argument(1, 'string'); + + //populate fields + $query = array( + 'name' => $name, + 'venueId' => $this->_venueId); //optional + + return $this->_post(self::URL_VENUE_GROUPS_ADD, $query); + } + + /** + * Delete a venue group + * + * @param string The ID of the venue group to delete. + * @return array + */ + public function deleteVenueGroups($groupId) { + //argument 1 must be a string + Eden_Foursquare_Error::i()->argument(1, 'string'); + + return $this->_post(sprintf(self::URL_VENUE_GROUPS_DELETE, $groupId), $query); + } + + /** + * Return all venue groups owned by the user. + * + * @return array + */ + public function getList() { + + return $this->_getResponse(self::URL_VENUE_GROUPS_LIST); + } + + /** + * Get daily venue stats for the venues in a group over a time range. + * + * @param string The venue group to retrieve series data for. + * @param string The start of the time range to retrieve stats for. YYYY-MM-DD + * @return array + */ + public function getTimeSeries($groupId, $startTime) { + //argument test + Eden_Foursquare_Error::i() + ->argument(1, 'string') //argument 1 must be a string + ->argument(2, 'string'); //argument 2 must be a string + + $startTime = strtotime($startTime); + + //populate fields + $query = array( + 'startAt' => $startTime, + 'GROUP_ID' => $groupId, + 'endAt' => $this->_endTime, //optional + 'fields' => $this->_fields); //optional + + return $this->_getResponse(sprintf(self::URL_VENUE_GROUPS_TIMESERIES, $groupId), $query); + } + + /** + * Add a venue to a venue group. + * + * @param string The ID of the venue group to modify + * @param string Venue IDs to add to the group + * @return array + */ + public function addVenueToGroup($groupId, $venueId) { + //argument test + Eden_Foursquare_Error::i() + ->argument(1, 'string') //argument 1 must be a string + ->argument(2, 'string'); //argument 2 must be a string + + //populate fields + $query = array( + 'GROUP_ID' => $groupId, + 'venueId' => $venueId); + + return $this->_post(sprintf(self::URL_VENUE_GROUPS_ADDVENUE, $groupId), $query); + } + + /** + * Make changes to all venues in a venue group + * + * @param string The ID of the venue group to access + * @return array + */ + public function getCampaigns($groupId) { + //argument 1 must be a string + Eden_Foursquare_Error::i()->argument(1, 'string'); + + return $this->_getResponse(sprintf(self::URL_VENUE_GROUPS_CAMPAIGNS, $groupId)); + } + + /** + * Make changes to a venue + * + * @param string The venue id to edit + * @return array + */ + public function editVenue($venueGroupId) { + //argument 1 must be a string + Eden_Foursquare_Error::i()->argument(1, 'string'); + + //populate fields + $query = array( + 'VENUEGROUP_ID' => $venueGroupId, + 'name' => $this->_name, //optional + 'city' => $this->_city, //optional + 'state' => $this->_state, //optional + 'zip' => $this->_zip, //optional + 'phone' => $this->_phone, //optional + 'categoryId' => $this->_categoryId, //optional + 'twitter' => $this->_twitter, //optional + 'description' => $this->_description, //optional + 'url' => $this->_url); //optional + + return $this->_post(sprintf(self::URL_VENUE_GROUPS_EDIT_VENUE, $venueGroupId), $query); + } + + /** + * Remove a venue from a venue group. + * + * @param string The ID of the venue group to modify + * @return array + */ + public function removeVenue($groupId, $venueId) { + //argument test + Eden_Foursquare_Error::i() + ->argument(1, 'string') //argument 1 must be a string + ->argument(2, 'string'); //argument 2 must be a string + + $query = array('venueId' => $venueId); + + return $this->_post(sprintf(self::URL_VENUE_GROUPS_REMOVE, $groupId), $query); + } + + /** + * Updates a venue group + * + * @param string The ID of the venue group to modify + * @param string Venue ID that will become the new set of venue IDs for the group. + * @param string The new name to give to the group. + * @return array + */ + public function updateVenueGroup($groupId, $venueId, $name) { + //argument test + Eden_Foursquare_Error::i() + ->argument(1, 'string') //argument 1 must be a string + ->argument(2, 'string') //argument 2 must be a string + ->argument(3, 'string'); //argument 3 must be a string + + $query = array( + 'venueId' => $venueId, + 'name' => $name); + + return $this->_post(sprintf(self::URL_VENUE_GROUPS_UPDATE, $groupId), $query); + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/getsatisfaction.php b/library/eden/getsatisfaction.php new file mode 100644 index 0000000..161bacc --- /dev/null +++ b/library/eden/getsatisfaction.php @@ -0,0 +1,285 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +require_once dirname(__FILE__).'/oauth.php'; +require_once dirname(__FILE__).'/getsatisfaction/error.php'; +require_once dirname(__FILE__).'/getsatisfaction/base.php'; +require_once dirname(__FILE__).'/getsatisfaction/company.php'; +require_once dirname(__FILE__).'/getsatisfaction/detail.php'; +require_once dirname(__FILE__).'/getsatisfaction/oauth.php'; +require_once dirname(__FILE__).'/getsatisfaction/people.php'; +require_once dirname(__FILE__).'/getsatisfaction/product.php'; +require_once dirname(__FILE__).'/getsatisfaction/reply.php'; +require_once dirname(__FILE__).'/getsatisfaction/replies.php'; +require_once dirname(__FILE__).'/getsatisfaction/tag.php'; +require_once dirname(__FILE__).'/getsatisfaction/topic.php'; + +/** + * Get Satisfaction API factory. This is a factory class with + * methods that will load up different Get Satisfaction classes. + * Get Satisfaction classes are organized as described on their + * developer site: company, detail, oauth, people, post, product, + * replies, tag, topics. + * + * @package Eden + * @category getsatisfaction + * @author Christian Blanquera cblanquera@openovate.com + */ +class Eden_Getsatisfaction extends Eden_Class { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getSingleton(__CLASS__); + } + + /* Public Methods + -------------------------------*/ + /** + * Returns Getsatisfaction Company + * + * @param string + * @param string + * @param string + * @param string + * @return Eden_Getsatisfaction_Company + */ + public function company($consumerKey, $consumerSecret, $accessToken, $accessSecret) { + Eden_Getsatisfaction_Error::i() + ->argument(1, 'string') + ->argument(2, 'string') + ->argument(3, 'string') + ->argument(4, 'string'); + + return Eden_Getsatisfaction_Company::i( + $consumerKey, + $consumerSecret, + $accessToken, + $accessSecret); + } + + /** + * Returns Getsatisfaction Detail + * + * @param string + * @param string + * @param string + * @param string + * @return Eden_Getsatisfaction_Detail + */ + public function detail($consumerKey, $consumerSecret, $accessToken, $accessSecret) { + Eden_Getsatisfaction_Error::i() + ->argument(1, 'string') + ->argument(2, 'string') + ->argument(3, 'string') + ->argument(4, 'string'); + + return Eden_Getsatisfaction_Detail::i( + $consumerKey, + $consumerSecret, + $accessToken, + $accessSecret); + } + + /** + * Returns Getsatisfaction OAuth + * + * @param string + * @param string + * @param string + * @param string + * @return Eden_Getsatisfaction_Oauth + */ + public function auth($consumerKey, $consumerSecret, $accessToken, $accessSecret) { + Eden_Getsatisfaction_Error::i() + ->argument(1, 'string') + ->argument(2, 'string') + ->argument(3, 'string') + ->argument(4, 'string'); + + return Eden_Getsatisfaction_Oauth::i( + $consumerKey, + $consumerSecret, + $accessToken, + $accessSecret); + } + + /** + * Returns Getsatisfaction People + * + * @param string + * @param string + * @param string + * @param string + * @return Eden_Getsatisfaction_People + */ + public function people($consumerKey, $consumerSecret, $accessToken, $accessSecret) { + Eden_Getsatisfaction_Error::i() + ->argument(1, 'string') + ->argument(2, 'string') + ->argument(3, 'string') + ->argument(4, 'string'); + + return Eden_Getsatisfaction_People::i( + $consumerKey, + $consumerSecret, + $accessToken, + $accessSecret); + } + + /** + * Returns Getsatisfaction post + * + * @param string + * @param string + * @param string + * @param string + * @return Eden_Getsatisfaction_Post + */ + public function post($consumerKey, $consumerSecret, $accessToken, $accessSecret) { + Eden_Getsatisfaction_Error::i() + ->argument(1, 'string') + ->argument(2, 'string') + ->argument(3, 'string') + ->argument(4, 'string'); + + return Eden_Getsatisfaction_Post::i( + $consumerKey, + $consumerSecret, + $accessToken, + $accessSecret); + } + + /** + * Returns Getsatisfaction Product + * + * @param string + * @param string + * @param string + * @param string + * @return Eden_Getsatisfaction_Product + */ + public function product($consumerKey, $consumerSecret, $accessToken, $accessSecret) { + Eden_Getsatisfaction_Error::i() + ->argument(1, 'string') + ->argument(2, 'string') + ->argument(3, 'string') + ->argument(4, 'string'); + + return Eden_Getsatisfaction_Product::i( + $consumerKey, + $consumerSecret, + $accessToken, + $accessSecret); + } + + /** + * Returns Getsatisfaction Replies + * + * @param string + * @param string + * @param string + * @param string + * @return Eden_Getsatisfaction_Replies + */ + public function replies($consumerKey, $consumerSecret, $accessToken, $accessSecret) { + Eden_Getsatisfaction_Error::i() + ->argument(1, 'string') + ->argument(2, 'string') + ->argument(3, 'string') + ->argument(4, 'string'); + + return Eden_Getsatisfaction_Replies::i( + $consumerKey, + $consumerSecret, + $accessToken, + $accessSecret); + } + + /** + * Returns Getsatisfaction reply + * + * @param string + * @param string + * @param string + * @param string + * @return Eden_Getsatisfaction_Reply + */ + public function reply($consumerKey, $consumerSecret, $accessToken, $accessSecret) { + Eden_Getsatisfaction_Error::i() + ->argument(1, 'string') + ->argument(2, 'string') + ->argument(3, 'string') + ->argument(4, 'string'); + + return Eden_Getsatisfaction_Reply::i( + $consumerKey, + $consumerSecret, + $accessToken, + $accessSecret); + } + + /** + * Returns Getsatisfaction Tags + * + * @param string + * @param string + * @param string + * @param string + * @return Eden_Getsatisfaction_Tag + */ + public function tag($consumerKey, $consumerSecret, $accessToken, $accessSecret) { + Eden_Getsatisfaction_Error::i() + ->argument(1, 'string') + ->argument(2, 'string') + ->argument(3, 'string') + ->argument(4, 'string'); + + return Eden_Getsatisfaction_Tag::i( + $consumerKey, + $consumerSecret, + $accessToken, + $accessSecret); + } + + /** + * Returns Getsatisfaction Topics + * + * @param string + * @param string + * @param string + * @param string + * @return Eden_Getsatisfaction_Topic + */ + public function topic($consumerKey, $consumerSecret, $accessToken, $accessSecret) { + Eden_Getsatisfaction_Error::i() + ->argument(1, 'string') + ->argument(2, 'string') + ->argument(3, 'string') + ->argument(4, 'string'); + + return Eden_Getsatisfaction_Topic::i( + $consumerKey, + $consumerSecret, + $accessToken, + $accessSecret); + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} diff --git a/library/eden/getsatisfaction/base.php b/library/eden/getsatisfaction/base.php new file mode 100644 index 0000000..5c8f02f --- /dev/null +++ b/library/eden/getsatisfaction/base.php @@ -0,0 +1,102 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Get Satisfaction base + * + * @package Eden + * @category getsatisfaction + * @author Christian Blanquera cblanquera@openovate.com + */ +class Eden_Getsatisfaction_Base extends Eden_Class { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_consumerKey = NULL; + protected $_consumerSecret = NULL; + protected $_accessToken = NULL; + protected $_accessSecret = NULL; + + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + /* Magic + -------------------------------*/ + public function __construct($consumerKey, $consumerSecret, $accessToken, $accessSecret) { + //argument test + Eden_Getsatisfaction_Error::i() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'string') //Argument 2 must be a string + ->argument(3, 'string') //Argument 3 must be a string + ->argument(4, 'string'); //Argument 4 must be a string + + $this->_consumerKey = $consumerKey; + $this->_consumerSecret = $consumerSecret; + $this->_accessToken = $accessToken; + $this->_accessSecret = $accessSecret; + } + + /* Public Methods + -------------------------------*/ + /** + * Returns the meta of the last call + * + * @return array + */ + public function getMeta($key = NULL) { + Eden_Google_Error::i()->argument(1, 'string', 'null'); + + if(isset($this->_meta[$key])) { + return $this->_meta[$key]; + } + + return $this->_meta; + } + + /* Protected Methods + -------------------------------*/ + protected function _getResponse($url, array $query = array()) { + $rest = Eden_Oauth::i() + ->consumer($url, $this->_consumerKey, $this->_consumerSecret) + ->setToken($this->_accessToken, $this->_accessSecret) + ->setSignatureToHmacSha1(); + + $response = $rest->getJsonResponse($query); + + $this->_meta = $rest->getMeta(); + + return $response; + } + + protected function _post($url, $query = array(), $jsonEncode = false) { + $rest = Eden_Oauth::i() + ->consumer($url, $this->_consumerKey, $this->_consumerSecret) + ->setToken($this->_accessToken, $this->_accessSecret) + ->setMethodToPost() + ->useAuthorization() + ->setSignatureToHmacSha1(); + + if($jsonEncode) { + $rest->jsonEncodeQuery(); + } + + $response = $rest->getJsonResponse($query); + + $this->_meta = $rest->getMeta(); + + return $response; + } + + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/getsatisfaction/company.php b/library/eden/getsatisfaction/company.php new file mode 100644 index 0000000..0b99d5d --- /dev/null +++ b/library/eden/getsatisfaction/company.php @@ -0,0 +1,204 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Various ways to get a list of companies in Get Satisfaction + * + * @package Eden + * @category getsatisfaction + * @author Christian Blanquera cblanquera@openovate.com + */ +class Eden_Getsatisfaction_Company extends Eden_Getsatisfaction_Base { + /* Constants + -------------------------------*/ + const URL_LIST = 'http://api.getsatisfaction.com/companies.json'; + const URL_PEOPLE = 'http://api.getsatisfaction.com/people/%s/companies.json'; + const URL_PRODUCT = 'http://api.getsatisfaction.com/products/%s/companies.json'; + const URL_ACTIVITY = 'http://api.getsatisfaction.com/companies/%s/last_activity_at.json'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_query = array(); + protected $_url = self::URL_LIST; + + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + /* Public Methods + -------------------------------*/ + /** + * Set keyword filter + * + * @param string + * @return this + */ + public function filterByKeyword($keyword) { + Eden_Getsatisfaction_Error::i()->argument(1, 'string'); + + $this->_query['query'] = $keyword; + + return $this; + } + + /** + * Returns a list of companies + * + * @return array + */ + public function getResponse() { + return $this->_getResponse($this->_url, $this->_query); + } + + /** + * Sets activity URL + * + * @param int|string + * @return this + */ + public function searchByActivity($company) { + Eden_Getsatisfaction_Error::i()->argument(1, 'string', 'int'); + + $this->_url = sprintf(self::URL_ACTIVITY, $company); + return $this; + } + + /** + * Set product URL + * + * @param int|string + * @return this + */ + public function searchByProduct($product) { + Eden_Getsatisfaction_Error::i()->argument(1, 'string', 'int'); + + $this->_url = sprintf(self::URL_PRODUCT, $product); + return $this; + } + + /** + * Sets user URL + * + * @param int|string + * @return this + */ + public function searchByUser($user) { + Eden_Getsatisfaction_Error::i()->argument(1, 'string', 'int'); + + $this->_url = sprintf(self::URL_PEOPLE, $user); + return $this; + } + + /** + * Show private companies + * + * @return this + */ + public function showPrivate() { + $this->_query['show'] = 'private'; + return $this; + } + + /** + * Show public companies + * + * @return this + */ + public function showPublic() { + $this->_query['show'] = 'public'; + return $this; + } + + /** + * Show visible companies + * + * @return this + */ + public function showVisible() { + $this->_query['show'] = 'not_hidden'; + return $this; + } + + /** + * Set page + * + * @param int + * @return this + */ + public function setPage($page = 0) { + Eden_Getsatisfaction_Error::i()->argument(1, 'int'); + + if($page < 0) { + $page = 0; + } + + $this->_query['page'] = $page; + + return $this; + } + + /** + * Set range + * + * @param int + * @return this + */ + public function setRange($limit = 10) { + Eden_Getsatisfaction_Error::i()->argument(1, 'int'); + + if($limit < 0) { + $limit = 10; + } + + $this->_query['limit'] = $limit; + + return $this; + } + + /** + * Sort by active + * + * @return this + */ + public function sortByActive() { + $this->_query['sort'] = 'recently_active'; + return $this; + } + + /** + * Sort by letters + * + * @return this + */ + public function sortByAlphabet() { + $this->_query['sort'] = 'alpha'; + return $this; + } + + /** + * Sort by created + * + * @return this + */ + public function sortByCreated() { + $this->_query['sort'] = 'recently_created'; + return $this; + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/getsatisfaction/detail.php b/library/eden/getsatisfaction/detail.php new file mode 100644 index 0000000..75b3775 --- /dev/null +++ b/library/eden/getsatisfaction/detail.php @@ -0,0 +1,52 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Get Satisfaction Detail Methods + * + * @package Eden + * @category getsatisfaction + * @author Christian Blanquera cblanquera@openovate.com + */ +class Eden_GetSatisfaction_Detail extends Eden_GetSatisfaction_Base { + /* Constants + -------------------------------*/ + const URL = 'http://api.getsatisfaction.com/topics/%s.json'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + /* Public Methods + -------------------------------*/ + /** + * Returns topic details + * + * @param string|int + * @return array + */ + public function getTopic($topic) { + Eden_Getsatisfaction_Error::i()->argument(1, 'string', 'int'); + + return $this->_getResponse(sprintf(self::URL, $topic)); + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/getsatisfaction/error.php b/library/eden/getsatisfaction/error.php new file mode 100644 index 0000000..a7c83e8 --- /dev/null +++ b/library/eden/getsatisfaction/error.php @@ -0,0 +1,39 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Get Satisfaction Errors + * + * @package Eden + * @category getsatisfaction + * @author Christian Blanquera cblanquera@openovate.com + */ +class Eden_Getsatisfaction_Error extends Eden_Error { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i($message = NULL, $code = 0) { + $class = __CLASS__; + return new $class($message, $code); + } + + /* Public Methods + -------------------------------*/ + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/getsatisfaction/oauth.php b/library/eden/getsatisfaction/oauth.php new file mode 100644 index 0000000..10a60d0 --- /dev/null +++ b/library/eden/getsatisfaction/oauth.php @@ -0,0 +1,123 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Get Satisfaction OAuth + * + * @package Eden + * @category getsatisfaction + * @author Christian Blanquera cblanquera@openovate.com + */ +class Eden_Getsatisfaction_Oauth extends Eden_Class { + /* Constants + -------------------------------*/ + const REQUEST_URL = 'http://getsatisfaction.com/api/request_token'; + const AUTHORIZE_URL = 'http://getsatisfaction.com/api/authorize'; + const ACCESS_URL = 'http://getsatisfaction.com/api/access_token'; + const SECRET_KEY = 'getsatisfaction_token_secret'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_key = NULL; + protected $_secret = NULL; + + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + public function __construct($consumerKey, $consumerSecret) { + //argument test + Eden_Getsatisfaction_Error::i() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'string'); //Argument 2 must be a string + + $this->_key = $consumerKey; + $this->_secret = $consumerSecret; + } + + /* Public Methods + -------------------------------*/ + /** + * Returns the access token + * + * @param string + * @param string + * @return string + */ + public function getAccess($token, $secret) { + //argument test + Eden_Getsatisfaction_Error::i() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'string'); //Argument 2 must be a string + + return Eden_Oauth::i() + ->consumer(self::ACCESS_URL, $this->_key, $this->_secret) + ->useAuthorization() + ->setMethodToPost() + ->setToken($token, $secret) + ->setSignatureToHmacSha1() + ->getQueryResponse(); + } + + /** + * Returns the URL used for login. + * + * @param string + * @return string + */ + public function getLoginUrl($redirect) { + //Argument 1 must be a string + Eden_Getsatisfaction_Error::i()->argument(1, 'string'); + + //get the token + $token = Eden_Oauth::i() + ->consumer(self::REQUEST_URL, $this->_key, $this->_secret) + ->useAuthorization() + ->setMethodToPost() + ->setSignatureToHmacSha1() + ->getQueryResponse(); + + //to avoid any unesissary usage of persistent data, + //we are going to attach the secret to the login URL + $secret = self::SECRET_KEY.'='.$token['oauth_token_secret']; + + //determine the conector + $connector = NULL; + + //if there is no question mark + if(strpos($redirect, '?') === false) { + $connector = '?'; + //if the redirect doesn't end with a question mark + } else if(substr($redirect, -1) != '?') { + $connector = '&'; + } + + //now add the secret to the redirect + $redirect .= $connector.$secret; + + //build the query + $query = array( + 'oauth_token' => $token['oauth_token'], + 'oauth_callback' => $redirect); + + $query = http_build_query($query); + return self::AUTHORIZE_URL.'?'.$query; + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/getsatisfaction/people.php b/library/eden/getsatisfaction/people.php new file mode 100644 index 0000000..a016cf1 --- /dev/null +++ b/library/eden/getsatisfaction/people.php @@ -0,0 +1,144 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Various ways to get a list of people in Get Satisfaction + * + * @package Eden + * @category getsatisfaction + * @author Christian Blanquera cblanquera@openovate.com + */ +class Eden_GetSatisfaction_People extends Eden_GetSatisfaction_Base { + /* Constants + -------------------------------*/ + const URL_LIST = 'http://api.getsatisfaction.com/people.json'; + const URL_EMPLOYEE = 'http://api.getsatisfaction.com/companies/%s/employees.json'; + const URL_COMPANY = 'http://api.getsatisfaction.com/companies/%s/people.json'; + const URL_TOPIC = 'http://api.getsatisfaction.com/topics/%s/people'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_query = array(); + protected $_url = self::URL_LIST; + + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + /* Public Methods + -------------------------------*/ + /** + * Filter by keyword + * + * @param string + * @return this + */ + public function filterByKeyword($keyword) { + Eden_Getsatisfaction_Error::i()->argument(1, 'string'); + + $this->_query['query'] = $keyword; + + return $this; + } + + /** + * Returns a list of companies + * + * @return array + */ + public function getResponse() { + return $this->_getResponse($this->_url, $this->_query); + } + + /** + * Sets company URL + * + * @param string|int + * @return this + */ + public function searchByCompany($company) { + Eden_Getsatisfaction_Error::i()->argument(1, 'string', 'int'); + + $this->_url = sprintf(self::URL_COMPANY, $company); + return $this; + } + + /** + * Sets Employee URL + * + * @param string|int + * @return this + */ + public function searchByEmployee($company) { + Eden_Getsatisfaction_Error::i()->argument(1, 'string', 'int'); + + $this->_url = sprintf(self::URL_EMPLOYEE, $company); + return $this; + } + + /** + * Sets topic URL + * + * @param string|int + * @return this + */ + public function searchByTopic($topic) { + Eden_Getsatisfaction_Error::i()->argument(1, 'string', 'int'); + + $this->_url = sprintf(self::URL_TOPIC, $topic); + return $this; + } + + /** + * Set page + * + * @param int + * @return this + */ + public function setPage($page = 0) { + Eden_Getsatisfaction_Error::i()->argument(1, 'int'); + + if($page < 0) { + $page = 0; + } + + $this->_query['page'] = $page; + + return $this; + } + + /** + * Set range + * + * @param int + * @return this + */ + public function setRange($limit = 10) { + Eden_Getsatisfaction_Error::i()->argument(1, 'int'); + + if($limit < 0) { + $limit = 10; + } + + $this->_query['limit'] = $limit; + + return $this; + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/getsatisfaction/post.php b/library/eden/getsatisfaction/post.php new file mode 100644 index 0000000..e999276 --- /dev/null +++ b/library/eden/getsatisfaction/post.php @@ -0,0 +1,257 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Get Satisfaction Post Methods + * + * @package Eden + * @category getsatisfaction + * @author Christian Blanquera cblanquera@openovate.com + */ +class Eden_Getsatisfaction_Post extends Eden_Getsatisfaction_Base { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_query = array(); + + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + /* Public Methods + -------------------------------*/ + /** + * Creates the post + * + * @param string|int + * @return array + */ + public function create($company) { + Eden_Getsatisfaction_Error::i()->argument(1, 'string', 'int'); + + $url = sprintf(Eden_Getsatisfaction_Topic::URL_COMPANY, $company); + + return $this->_post($url, array('topic' => $this->_query), true); + } + + /** + * Overwrite keywords + * + * @return this + */ + public function overwriteKeywords() { + $this->_query['overwrite_keywords'] = 'true'; + return $this; + } + + /** + * Set topic detail + * + * @param string + * @return this + */ + public function setDetail($detail) { + Eden_Getsatisfaction_Error::i()->argument(1, 'string'); + $this->_query['additional_detail'] = $detail; + return $this; + } + + /** + * Set topic mood + * + * @param string + * @return this + */ + public function setFeeling($feeling) { + Eden_Getsatisfaction_Error::i()->argument(1, 'string'); + + $this->_query['emotitag']['feeling'] = $feeling; + return $this; + } + + /** + * Add happy face + * + * @return this + */ + public function setHappyFace() { + $this->_query['emotitag']['face'] = 'happy'; + return $this; + } + + /** + * Set topic style to idea format + * + * @return this + */ + public function setIdea() { + $this->_query['style'] = 'idea'; + return $this; + } + + /** + * Add lame face + * + * @return this + */ + public function setIndifferentFace() { + $this->_query['emotitag']['face'] = 'indifferent'; + return $this; + } + + /** + * Set topic intensity + * + * @param int 0-5 + * @return this + */ + public function setIntensity($intensity) { + Eden_Getsatisfaction_Error::i()->argument(1, 'int'); + + if($intensity < 0) { + $intensity = 0; + } else if($intensity > 5) { + $intensity = 5; + } + + $this->_query['emotitag']['intensity'] = $intensity; + return $this; + } + + /** + * Set topic style to praise format + * + * @return this + */ + public function setPraise() { + $this->_query['style'] = 'praise'; + return $this; + } + + /** + * Set topic style to problem format + * + * @return this + */ + public function setProblem() { + $this->_query['style'] = 'problem'; + return $this; + } + + /** + * Set products this topic is related to + * + * @param string|array + * @return this + */ + public function setProducts($products) { + Eden_Getsatisfaction_Error::i()->argument(1, 'string', 'array'); + + if(is_array($products)) { + $tags = implode(',', $products); + } + + $this->_query['products'] = $products; + return $this; + } + + /** + * Set topic style to question format + * + * @return this + */ + public function setQuestion() { + $this->_query['style'] = 'question'; + return $this; + } + + /** + * Add sad face + * + * @return this + */ + public function setSadFace() { + $this->_query['emotitag']['face'] = 'sad'; + return $this; + } + + /** + * Add silly face + * + * @return this + */ + public function setSillyFace() { + $this->_query['emotitag']['face'] = 'silly'; + return $this; + } + + /** + * Add tags + * + * @param string|array + * @return this + */ + public function setTags($tags) { + Eden_Getsatisfaction_Error::i()->argument(1, 'string', 'array'); + + if(is_array($tags)) { + $tags = implode(',', $tags); + } + + $this->_query['keywords'] = $tags; + } + + /** + * Set title + * + * @param string + * @return this + */ + public function setTitle($title) { + Eden_Getsatisfaction_Error::i()->argument(1, 'string'); + $this->_query['subject'] = $title; + return $this; + } + + /** + * Set topic style to update format + * + * @return this + */ + public function setUpdate() { + $this->_query['style'] = 'update'; + return $this; + } + + /** + * Updates the post + * + * @param string|int + * @return array + */ + public function update($topic) { + Eden_Getsatisfaction_Error::i()->argument(1, 'string', 'numeric'); + + $url = sprintf(Eden_GetSatisfaction_Detail::URL, $topic); + + return $this->_post($url, array('topic' => $this->_query), true); + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/getsatisfaction/product.php b/library/eden/getsatisfaction/product.php new file mode 100644 index 0000000..834a581 --- /dev/null +++ b/library/eden/getsatisfaction/product.php @@ -0,0 +1,174 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Get Satisfaction Product Methods + * + * @package Eden + * @category getsatisfaction + * @author Christian Blanquera cblanquera@openovate.com + */ +class Eden_GetSatisfaction_Product extends Eden_GetSatisfaction_Base { + /* Constants + -------------------------------*/ + const URL_LIST = 'http://api.getsatisfaction.com/products.json'; + const URL_COMPANY = 'http://api.getsatisfaction.com/companies/%s/products.json'; + const URL_PEOPLE = 'http://api.getsatisfaction.com/people/%s/products.json'; + const URL_TOPIC = 'http://api.getsatisfaction.com/topics/%s/products.json'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_query = array(); + protected $_url = self::URL_LIST; + + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + /* Public Methods + -------------------------------*/ + /** + * Returns a list of companies + * + * @return array + */ + public function getResponse() { + return $this->_getResponse($this->_url, $this->_query); + } + + /** + * Filter by keyword + * + * @param string + * @return this + */ + public function filterByKeyword($keyword) { + Eden_Getsatisfaction_Error::i()->argument(1, 'string'); + + $this->_query['query'] = $keyword; + + return $this; + } + + /** + * Sets company URL + * + * @param string|int + * @return this + */ + public function searchByCompany($company) { + Eden_Getsatisfaction_Error::i()->argument(1, 'string', 'int'); + + $this->_url = sprintf(self::URL_COMPANY, $company); + return $this; + } + + /** + * Sets topic URL + * + * @param string|int + * @return this + */ + public function searchByTopic($topic) { + Eden_Getsatisfaction_Error::i()->argument(1, 'string', 'int'); + + $this->_url = sprintf(self::URL_TOPIC, $topic); + return $this; + } + + /** + * Sets user URL + * + * @param int|string + * @return this + */ + public function searchByUser($user) { + Eden_Getsatisfaction_Error::i()->argument(1, 'string', 'int'); + + $this->_url = sprintf(self::URL_PEOPLE, $user); + return $this; + } + + /** + * Set page + * + * @param int + * @return this + */ + public function setPage($page = 0) { + Eden_Getsatisfaction_Error::i()->argument(1, 'int'); + + if($page < 0) { + $page = 0; + } + + $this->_query['page'] = $page; + + return $this; + } + + /** + * Set range + * + * @param int + * @return this + */ + public function setRange($limit = 10) { + Eden_Getsatisfaction_Error::i()->argument(1, 'int'); + + if($limit < 0) { + $limit = 10; + } + + $this->_query['limit'] = $limit; + + return $this; + } + + /** + * Sort by letters + * + * @return this + */ + public function sortByAlphabet() { + $this->_query['sort'] = 'alpha'; + return $this; + } + + /** + * Sort by lame + * + * @return this + */ + public function sortByLeastPopular() { + $this->_query['sort'] = 'least_popular'; + return $this; + } + + /** + * Sort by popular + * + * @return this + */ + public function sortByMostPopular() { + $this->_query['sort'] = 'most_popular'; + return $this; + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/getsatisfaction/replies.php b/library/eden/getsatisfaction/replies.php new file mode 100644 index 0000000..8343412 --- /dev/null +++ b/library/eden/getsatisfaction/replies.php @@ -0,0 +1,161 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Get Satisfaction Reply Methods + * + * @package Eden + * @category getsatisfaction + * @author Christian Blanquera cblanquera@openovate.com + */ +class Eden_Getsatisfaction_Replies extends Eden_Getsatisfaction_Base { + /* Constants + -------------------------------*/ + const URL_LIST = 'http://api.getsatisfaction.com/replies.json'; + const URL_TOPIC = 'http://api.getsatisfaction.com/topics/%s/replies.json'; + const URL_PEOPLE = 'http://api.getsatisfaction.com/people/%s/replies.json'; + const URL_REPLY = 'http://api.getsatisfaction.com/topics/%s/replies'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_query = array(); + protected $_url = self::URL_LIST; + + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + /* Public Methods + -------------------------------*/ + + /** + * Filter by best + * + * @return this + */ + public function filterByBest() { + $this->_query['filter'] = 'best'; + + return $this; + } + + /** + * Filter by company promoted + * + * @return this + */ + public function filterByCompanyPromoted() { + $this->_query['filter'] = 'company_promoted'; + + return $this; + } + + /** + * Filter by flat promoted + * + * @return this + */ + public function filterByFlatPromoted() { + $this->_query['filter'] = 'flat_promoted'; + + return $this; + } + + /** + * Filter by star promoted + * + * @return this + */ + public function filterByStarPromoted() { + $this->_query['filter'] = 'star_promoted'; + + return $this; + } + + /** + * Returns a list of companies + * + * @return array + */ + public function getResponse() { + return $this->_getResponse($this->_url, $this->_query); + } + + /** + * Sets topic URL + * + * @param string|int + * @return this + */ + public function searchByTopic($topic) { + Eden_Getsatisfaction_Error::i()->argument(1, 'string', 'int'); + + $this->_url = sprintf(self::URL_TOPIC, $topic); + return $this; + } + /** + * Sets user URL + * + * @param int|string + * @return this + */ + public function searchByUser($user) { + Eden_Getsatisfaction_Error::i()->argument(1, 'string', 'int'); + + $this->_url = sprintf(self::URL_PEOPLE, $user); + return $this; + } + + /** + * Set page + * + * @param int + * @return this + */ + public function setPage($page = 0) { + Eden_Getsatisfaction_Error::i()->argument(1, 'int'); + + if($page < 0) { + $page = 0; + } + + $this->_query['page'] = $page; + + return $this; + } + + /** + * Set range + * + * @param int + * @return this + */ + public function setRange($limit = 10) { + Eden_Getsatisfaction_Error::i()->argument(1, 'int'); + + if($limit < 0) { + $limit = 10; + } + + $this->_query['limit'] = $limit; + + return $this; + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/getsatisfaction/reply.php b/library/eden/getsatisfaction/reply.php new file mode 100644 index 0000000..06c9d4a --- /dev/null +++ b/library/eden/getsatisfaction/reply.php @@ -0,0 +1,130 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Get Satisfaction Post Methods + * + * @package Eden + * @category getsatisfaction + * @author Christian Blanquera cblanquera@openovate.com + */ +class Eden_Getsatisfaction_Reply extends Eden_Getsatisfaction_Base { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_query = array(); + + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + /* Public Methods + -------------------------------*/ + /** + * Creates the post + * + * @param string|int + * @param string + * @return array + */ + public function create($topic, $content) { + Eden_Getsatisfaction_Error::i() + ->argument(1, 'string', 'int') + ->argument(2, 'string'); + + $url = sprintf(Eden_Getsatisfaction_Replies::URL_REPLY, $topic); + $query = array('content' => $content); + + return $this->_post($url, array('reply' => $this->_query), true); + } + + /** + * Set topic mood + * + * @param string + * @return this + */ + public function setFeeling($feeling) { + Eden_Getsatisfaction_Error::i()->argument(1, 'string'); + + $this->_query['emotitag']['feeling'] = $feeling; + return $this; + } + + /** + * Add happy face + * + * @return this + */ + public function setHappyFace() { + $this->_query['emotitag']['face'] = 'happy'; + return $this; + } + + /** + * Add lame face + * + * @return this + */ + public function setIndifferentFace() { + $this->_query['emotitag']['face'] = 'indifferent'; + return $this; + } + + /** + * Set topic intensity + * + * @param int 0-5 + * @return this + */ + public function setIntensity($intensity) { + Eden_Getsatisfaction_Error::i()->argument(1, 'int'); + + if($intensity < 0) { + $intensity = 0; + } else if($intensity > 5) { + $intensity = 5; + } + + $this->_query['emotitag']['intensity'] = $intensity; + return $this; + } + + /** + * Add sad face + * + * @return this + */ + public function setSadFace() { + $this->_query['emotitag']['face'] = 'sad'; + return $this; + } + + /** + * Add silly face + * + * @return this + */ + public function setSillyFace() { + $this->_query['emotitag']['face'] = 'silly'; + return $this; + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/getsatisfaction/tag.php b/library/eden/getsatisfaction/tag.php new file mode 100644 index 0000000..73c38d4 --- /dev/null +++ b/library/eden/getsatisfaction/tag.php @@ -0,0 +1,116 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Get Satisfaction Tag Methods + * + * @package Eden + * @category getsatisfaction + * @author Christian Blanquera cblanquera@openovate.com + */ +class Eden_GetSatisfaction_Tag extends Eden_GetSatisfaction_Base { + /* Constants + -------------------------------*/ + const URL_LIST = 'http://api.getsatisfaction.com/tags.json'; + const URL_TOPIC = 'http://api.getsatisfaction.com/topics/%s/tags.json'; + const URL_COMPANY = 'http://api.getsatisfaction.com/companies/%s/tags.json'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_query = array(); + protected $_url = self::URL_LIST; + + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + /* Public Methods + -------------------------------*/ + /** + * Returns a list of companies + * + * @return array + */ + public function getResponse() { + return $this->_getResponse($this->_url, $this->_query); + } + + /** + * Sets company URL + * + * @param string|int + * @return this + */ + public function searchByCompany($company) { + Eden_Getsatisfaction_Error::i()->argument(1, 'string', 'int'); + + $this->_url = sprintf(self::URL_COMPANY, $company); + return $this; + } + + /** + * Sets topic URL + * + * @param string|int + * @return this + */ + public function searchByTopic($topic) { + Eden_Getsatisfaction_Error::i()->argument(1, 'string', 'int'); + + $this->_url = sprintf(self::URL_TOPIC, $topic); + return $this; + } + + /** + * Set page + * + * @param int + * @return this + */ + public function setPage($page = 0) { + Eden_Getsatisfaction_Error::i()->argument(1, 'int'); + + if($page < 0) { + $page = 0; + } + + $this->_query['page'] = $page; + + return $this; + } + + /** + * Set range + * + * @param int + * @return this + */ + public function setRange($limit = 10) { + Eden_Getsatisfaction_Error::i()->argument(1, 'int'); + + if($limit < 0) { + $limit = 10; + } + + $this->_query['limit'] = $limit; + + return $this; + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/getsatisfaction/topic.php b/library/eden/getsatisfaction/topic.php new file mode 100644 index 0000000..75cb13c --- /dev/null +++ b/library/eden/getsatisfaction/topic.php @@ -0,0 +1,450 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Get Satisfaction Topic Methods + * + * @package Eden + * @category getsatisfaction + * @author Christian Blanquera cblanquera@openovate.com + */ +class Eden_GetSatisfaction_Topic extends Eden_GetSatisfaction_Base { + /* Constants + -------------------------------*/ + const URL_LIST = 'http://api.getsatisfaction.com/topics.json'; + const URL_COMPANY = 'http://api.getsatisfaction.com/companies/%s/topics.json'; + const URL_COMPANY_PRODUCT = 'http://api.getsatisfaction.com/companies/%s/products/%s/topics.json'; + const URL_COMPANY_TAG = 'http://api.getsatisfaction.com/companies/%s/tags/%s/topics.json'; + const URL_PEOPLE = 'http://api.getsatisfaction.com/people/%s/topics.json'; + const URL_PEOPLE_FOLLOWED = 'http://api.getsatisfaction.com/people/%s/followed/topics.json'; + const URL_PRODUCT = 'http://api.getsatisfaction.com/products/%s/topics.json'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_query = array(); + protected $_url = self::URL_LIST; + + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + /* Public Methods + -------------------------------*/ + + /** + * Filter by company + * + * @param string|int + * @return this + */ + public function filterByCompany($company) { + Eden_Getsatisfaction_Error::i()->argument(1, 'string', 'int'); + + $this->_query['company'] = $company; + + return $this; + } + + /** + * Filter by defined + * + * @param string|int + * @return this + */ + public function filterByDefined($defined) { + Eden_Getsatisfaction_Error::i()->argument(1, 'string', 'int'); + + $this->_query['user_defined_code'] = $defined; + + return $this; + } + + /** + * Filter by product + * + * @param string|int|array + * @return this + */ + public function filterByProduct($product) { + Eden_Getsatisfaction_Error::i()->argument(1, 'string', 'int', 'array'); + + if(is_array($product)) { + $product = implode(',', $product); + } + + $this->_query['product'] = $product; + + return $this; + } + + /** + * Filter by since + * + * @param string|int + * @return this + */ + public function filterBySince($since) { + Eden_Getsatisfaction_Error::i()->argument(1, 'string', 'int'); + + if(is_string($since)) { + $since = strtotime($since); + } + + $this->_query['active_since'] = $since; + + return $this; + } + + /** + * Filter by active status + * + * @return this + */ + public function filterByStatusActive() { + if(!isset($this->_filter['status']) || !in_array('active', $this->_filter['status'])) { + $this->_filter['status'][] = 'active'; + } + + return $this; + } + + /** + * Filter by complete status + * + * @return this + */ + public function filterByStatusComplete() { + if(!isset($this->_filter['status']) || !in_array('complete', $this->_filter['status'])) { + $this->_filter['status'][] = 'complete'; + } + + return $this; + } + + /** + * Filter by no status + * + * @return this + */ + public function filterByStatusNone() { + if(!isset($this->_filter['status']) || !in_array('none', $this->_filter['status'])) { + $this->_filter['status'][] = 'none'; + } + + return $this; + } + + /** + * Filter by pending status + * + * @return this + */ + public function filterByStatusPending() { + if(!isset($this->_filter['status']) || !in_array('pending', $this->_filter['status'])) { + $this->_filter['status'][] = 'pending'; + } + + return $this; + } + + /** + * Filter by rejected status + * + * @return this + */ + public function filterByStatusRejected() { + if(!isset($this->_filter['status']) || !in_array('rejected', $this->_filter['status'])) { + $this->_filter['status'][] = 'rejected'; + } + + return $this; + } + + /** + * Filter by tag + * + * @param string + * @return this + */ + public function filterByTag($tag) { + Eden_Getsatisfaction_Error::i()->argument(1, 'string'); + + $this->_query['tag'] = $tag; + + return $this; + } + + /** + * Filter by user + * + * @param string|int + * @return this + */ + public function filterByUser($user) { + Eden_Getsatisfaction_Error::i()->argument(1, 'string', 'int'); + + $this->_query['user'] = $user; + + return $this; + } + + /** + * Returns a list of companies + * + * @return array + */ + public function getResponse() { + if(isset($this->_query['status']) && is_array($this->_query['status'])) { + $this->_query['status'] = implode(',', $this->_query['status']); + } + + return $this->_getResponse($this->_url, $this->_query); + } + + /** + * Sets company URL + * + * @param string|int + * @return this + */ + public function setCompany($company) { + Eden_Getsatisfaction_Error::i()->argument(1, 'string', 'int'); + + $this->_url = sprintf(self::URL_COMPANY, $company); + return $this; + } + + /** + * Sets company URL + * + * @param string|int + * @param string|int + * @return this + */ + public function setCompanyProduct($company, $product) { + Eden_Getsatisfaction_Error::i() + ->argument(1, 'string', 'int') + ->argument(2, 'string', 'int'); + + $this->_url = sprintf(self::URL_COMPANY_PRODUCT, $company, $product); + return $this; + } + + /** + * Sets company URL + * + * @param string|int + * @param string|int + * @return this + */ + public function setCompanyTag($company, $tag) { + Eden_Getsatisfaction_Error::i() + ->argument(1, 'string', 'int') + ->argument(2, 'string', 'int'); + + $this->_url = sprintf(self::URL_COMPANY_TAG, $company, $tag); + return $this; + } + + /** + * Sets company URL + * + * @param string|int + * @return this + */ + public function setFollowed($user) { + Eden_Getsatisfaction_Error::i()->argument(1, 'string', 'int'); + + $this->_url = sprintf(self::URL_PEOPLE_FOLLOWED, $user); + return $this; + } + + /** + * Set page + * + * @param int + * @return this + */ + public function setPage($page = 0) { + Eden_Getsatisfaction_Error::i()->argument(1, 'int'); + + if($page < 0) { + $page = 0; + } + + $this->_query['page'] = $page; + + return $this; + } + + /** + * Sets company URL + * + * @param string|int + * @return this + */ + public function setProduct($product) { + Eden_Getsatisfaction_Error::i()->argument(1, 'string', 'int'); + + $this->_url = sprintf(self::URL_PRODUCT, $product); + return $this; + } + + /** + * Set range + * + * @param int + * @return this + */ + public function setRange($limit = 10) { + Eden_Getsatisfaction_Error::i()->argument(1, 'int'); + + if($limit < 0) { + $limit = 10; + } + + $this->_query['limit'] = $limit; + + return $this; + } + + /** + * Sets company URL + * + * @param string|int + * @return this + */ + public function setUser($user) { + Eden_Getsatisfaction_Error::i()->argument(1, 'string', 'int'); + + $this->_url = sprintf(self::URL_PEOPLE, $user); + return $this; + } + /** + * Sort by updates + * + * @return this + */ + public function showUpdates() { + $this->_query['style'] = 'update'; + return $this; + } + + /** + * Sort by ideas + * + * @return this + */ + public function showIdeas() { + $this->_query['style'] = 'idea'; + return $this; + } + + /** + * Sort by praise + * + * @return this + */ + public function showPraise() { + $this->_query['style'] = 'praise'; + return $this; + } + + /** + * Sort by problems + * + * @return this + */ + public function showProblems() { + $this->_query['style'] = 'question'; + return $this; + } + + /** + * Sort by questions + * + * @return this + */ + public function showQuestions() { + $this->_query['style'] = 'question'; + return $this; + } + + /** + * Sort by active + * + * @return this + */ + public function sortByActive() { + $this->_query['sort'] = 'recently_active'; + return $this; + } + + /** + * Sort by created + * + * @return this + */ + public function sortByCreated() { + $this->_query['sort'] = 'recently_created'; + return $this; + } + + /** + * Sort by priority + * + * @return this + */ + public function sortByPriority() { + $this->_query['sort'] = 'priority'; + return $this; + } + + /** + * Sort by replies + * + * @return this + */ + public function sortByReplies() { + $this->_query['sort'] = 'most_replies'; + return $this; + } + + /** + * Sort by unanswered + * + * @return this + */ + public function sortByUnanswered() { + $this->_query['sort'] = 'answered'; + return $this; + } + + /** + * Sort by votes + * + * @return this + */ + public function sortByVotes() { + $this->_query['sort'] = 'most_me_toos'; + return $this; + } + + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/google.php b/library/eden/google.php new file mode 100644 index 0000000..d262798 --- /dev/null +++ b/library/eden/google.php @@ -0,0 +1,236 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ +require_once dirname(__FILE__).'/oauth2.php'; +require_once dirname(__FILE__).'/template.php'; +require_once dirname(__FILE__).'/google/error.php'; +require_once dirname(__FILE__).'/google/base.php'; +require_once dirname(__FILE__).'/google/oauth.php'; +require_once dirname(__FILE__).'/google/calendar/acl.php'; +require_once dirname(__FILE__).'/google/calendar/calendars.php'; +require_once dirname(__FILE__).'/google/calendar/event.php'; +require_once dirname(__FILE__).'/google/calendar/freebusy.php'; +require_once dirname(__FILE__).'/google/calendar/list.php'; +require_once dirname(__FILE__).'/google/calendar/settings.php'; +require_once dirname(__FILE__).'/google/calendar.php'; +require_once dirname(__FILE__).'/google/checkout/form.php'; +require_once dirname(__FILE__).'/google/drive/changes.php'; +require_once dirname(__FILE__).'/google/drive/children.php'; +require_once dirname(__FILE__).'/google/drive/files.php'; +require_once dirname(__FILE__).'/google/drive/parent.php'; +require_once dirname(__FILE__).'/google/drive/permissions.php'; +require_once dirname(__FILE__).'/google/drive/revisions.php'; +require_once dirname(__FILE__).'/google/drive.php'; +require_once dirname(__FILE__).'/google/contacts/batch.php'; +require_once dirname(__FILE__).'/google/contacts/data.php'; +require_once dirname(__FILE__).'/google/contacts/groups.php'; +require_once dirname(__FILE__).'/google/contacts/photo.php'; +require_once dirname(__FILE__).'/google/contacts.php'; +require_once dirname(__FILE__).'/google/analytics/management.php'; +require_once dirname(__FILE__).'/google/analytics/reporting.php'; +require_once dirname(__FILE__).'/google/analytics/multichannel.php'; +require_once dirname(__FILE__).'/google/analytics.php'; +require_once dirname(__FILE__).'/google/plus/activity.php'; +require_once dirname(__FILE__).'/google/plus/comment.php'; +require_once dirname(__FILE__).'/google/plus/people.php'; +require_once dirname(__FILE__).'/google/plus.php'; +require_once dirname(__FILE__).'/google/maps/direction.php'; +require_once dirname(__FILE__).'/google/maps/distance.php'; +require_once dirname(__FILE__).'/google/maps/elevation.php'; +require_once dirname(__FILE__).'/google/maps/geocoding.php'; +require_once dirname(__FILE__).'/google/maps/image.php'; +require_once dirname(__FILE__).'/google/maps.php'; +require_once dirname(__FILE__).'/google/shortener.php'; +require_once dirname(__FILE__).'/google/youtube/activity.php'; +require_once dirname(__FILE__).'/google/youtube/channel.php'; +require_once dirname(__FILE__).'/google/youtube/comment.php'; +require_once dirname(__FILE__).'/google/youtube/contacts.php'; +require_once dirname(__FILE__).'/google/youtube/favorites.php'; +require_once dirname(__FILE__).'/google/youtube/history.php'; +require_once dirname(__FILE__).'/google/youtube/message.php'; +require_once dirname(__FILE__).'/google/youtube/playlist.php'; +require_once dirname(__FILE__).'/google/youtube/profile.php'; +require_once dirname(__FILE__).'/google/youtube/ratings.php'; +require_once dirname(__FILE__).'/google/youtube/search.php'; +require_once dirname(__FILE__).'/google/youtube/subscription.php'; +require_once dirname(__FILE__).'/google/youtube/upload.php'; +require_once dirname(__FILE__).'/google/youtube/video.php'; +require_once dirname(__FILE__).'/google/youtube.php'; + +/** + * Google API factory. This is a factory class with + * methods that will load up different google classes. + * Google classes are organized as described on their + * developer site: analytics, calendar ,contacts ,drive, plus and youtube. + * + * @package Eden + * @category google + * @author Christian Symon M. Buenavista sbuenavista@openovate.com + */ +class Eden_Google extends Eden_Class { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function i() { + return self::_getSingleton(__CLASS__); + } + /* Magic + -------------------------------*/ + /* Public Methods + -------------------------------*/ + /** + * Returns google analytics methods + * + * @param *string + * @param *string + * @param *url + * @param *string + * @return Eden_Google_Oauth + */ + public function auth($clientId, $clientSecret, $redirect, $apiKey = NULL ) { + //argument test + Eden_Google_Error::i() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'string') //Argument 2 must be a string + ->argument(3, 'url') //Argument 3 must be a url + ->argument(4, 'string', 'null'); //Argument 4 must be a string + + return Eden_Google_Oauth::i($clientId, $clientSecret, $redirect, $apiKey); + } + + /** + * Returns google analytics methods + * + * @param *string + * @return Eden_Google_Analytics + */ + public function analytics($token) { + //Argument 1 must be a string + Eden_Google_Error::i()->argument(1, 'string'); + + return Eden_Google_Analytics::i($token); + } + + /** + * Returns google calendar methods + * + * @param *string + * @return Eden_Google_Calendar + */ + public function calendar($token) { + //Argument 1 must be a string + Eden_Google_Error::i()->argument(1, 'string'); + + return Eden_Google_Calendar::i($token); + } + + /** + * Returns google checkout methods + * + * @param *string + * @return Eden_Google_Checkout_Form + */ + public function checkout($merchantId) { + //Argument 1 must be a string + Eden_Google_Error::i()->argument(1, 'string'); + + return Eden_Google_Checkout_Form::i($merchantId); + } + + /** + * Returns google contacts methods + * + * @param *string + * @return Eden_Google_Contacts + */ + public function contacts($token) { + //Argument 1 must be a string + Eden_Google_Error::i()->argument(1, 'string'); + + return Eden_Google_Contacts::i($token); + } + + /** + * Returns google drive methods + * + * @param *string + * @return Eden_Google_Drive + */ + public function drive($token) { + //Argument 1 must be a string + Eden_Google_Error::i()->argument(1, 'string'); + + return Eden_Google_Drive::i($token); + } + + /** + * Returns google maps methods + * + * @param *string + * @return Eden_Google_Maps + */ + public function maps($token) { + //Argument 1 must be a string + Eden_Google_Error::i()->argument(1, 'string'); + + return Eden_Google_Maps::i($token); + } + + /** + * Returns google plus methods + * + * @param *string + * @return Eden_Google_Plus + */ + public function plus($token) { + //Argument 1 must be a string + Eden_Google_Error::i()->argument(1, 'string'); + + return Eden_Google_Plus::i($token); + } + + /** + * Returns google shortener methods + * + * @param *string API key + * @return Eden_Google_Plus + */ + public function shortener($key) { + //Argument 1 must be a string + Eden_Google_Error::i()->argument(1, 'string'); + + return Eden_Google_Shortener::i($key); + } + + /** + * Returns google youtube methods + * + * @param *string + * @param *string + * @return Eden_Google_Youtube + */ + public function youtube($token, $developerId) { + //Argument Testing + Eden_Google_Error::i() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'string'); //Argument 2 must be a string + + return Eden_Google_Youtube::i($token, $developerId); + } + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/google/analytics.php b/library/eden/google/analytics.php new file mode 100644 index 0000000..f141c94 --- /dev/null +++ b/library/eden/google/analytics.php @@ -0,0 +1,71 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Google Analytics + * + * @package Eden + * @category google + * @author Christian Symon M. Buenavista sbuenavista@openovate.com + */ +class Eden_Google_Analytics extends Eden_Google_Base { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + public function __construct($token) { + //argument test + Eden_Google_Error::i()->argument(1, 'string'); + $this->_token = $token; + } + + /* Public Methods + -------------------------------*/ + /** + * Returns Google analytics management + * + * @return Eden_Google_Analytics_Management + */ + public function management() { + return Eden_Google_Analytics_Management::i($this->_token); + } + + /** + * Returns Google analytics reporting + * + * @return Eden_Google_Analytics_Reporting + */ + public function reporting() { + return Eden_Google_Analytics_Reporting::i($this->_token); + } + + /** + * Returns Google analytics multichannel + * + * @return Eden_Google_Analytics_Multichannel + */ + public function multiChannel() { + return Eden_Google_Analytics_Multichannel::i($this->_token); + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/google/analytics/management.php b/library/eden/google/analytics/management.php new file mode 100644 index 0000000..21147a2 --- /dev/null +++ b/library/eden/google/analytics/management.php @@ -0,0 +1,171 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Google + * + * @package Eden + * @category google + * @author Christian Symon M. Buenavista sbuenavista@openovate.com + */ +class Eden_Google_Analytics_Management extends Eden_Google_Base { + /* Constants + -------------------------------*/ + const URL_ANALYTICS_ACCOUNTS = 'https://www.googleapis.com/analytics/v3/management/accounts'; + const URL_ANALYTICS_WEBPROPERTIES = 'https://www.googleapis.com/analytics/v3/management/accounts/%s/webproperties'; + const URL_ANALYTICS_PROFILE = 'https://www.googleapis.com/analytics/v3/management/accounts/%s/webproperties/%s/profiles'; + const URL_ANALYTICS_GOALS = 'https://www.googleapis.com/analytics/v3/management/accounts/%s/webproperties/%s/profiles/%s/goals'; + const URL_ANALYTICS_SEGMENTS = 'https://www.googleapis.com/analytics/v3/management/segments'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_startIndex = NULL; + protected $_maxResults = NULL; + + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + public function __construct($token) { + //argument test + Eden_Google_Error::i()->argument(1, 'string'); + $this->_token = $token; + } + + /* Public Methods + -------------------------------*/ + /** + * Set start index + * + * @param integer + * @return this + */ + public function setStartIndex($startIndex) { + //argument 1 must be a integer + Eden_Google_Error::i()->argument(1, 'integer'); + $this->_startIndex = $startIndex; + + return $this; + } + + /** + * Set start index + * + * @param integer + * @return this + */ + public function setMaxResults($maxResults) { + //argument 1 must be a integer + Eden_Google_Error::i()->argument(1, 'integer'); + $this->_maxResults = $maxResults; + + return $this; + } + + /** + * Returns all accounts to which the user has access. + * + * @return array + */ + public function getAccounts() { + //populate parameters + $query = array( + self::START_INDEX => $this->_startIndex, //optional + self::MAX_RESULTS => $this->_maxResults); //optional + + return $this->_getResponse(self::URL_ANALYTICS_ACCOUNTS, $query); + } + + /** + * Returns web properties to which the user has access + * + * @param string + * @return array + */ + public function getWebProperties($accountId = self::ALL) { + //argument test + Eden_Google_Error::i()->argument(1, 'string'); + + //populate parameters + $query = array( + self::START_INDEX => $this->_startIndex, //optional + self::MAX_RESULTS => $this->_maxResults); //optional + + return $this->_getResponse(sprintf(self::URL_ANALYTICS_WEBPROPERTIES, $accountId), $query); + } + + /** + * Returns lists of profiles to which the user has access + * + * @param string + * @param string + * @return array + */ + public function getProfiles($accountId = self::ALL, $webPropertyId = self::ALL) { + //argument test + Eden_Google_Error::i() + ->argument(1, 'string') //argument 1 must be a string + ->argument(2, 'string'); //argument 2 must be a string + + //populate parameters + $query = array( + self::START_INDEX => $this->_startIndex, //optional + self::MAX_RESULTS => $this->_maxResults); //optional + + return $this->_getResponse(sprintf(self::URL_ANALYTICS_PROFILE, $accountId, $webPropertyId), $query); + } + + /** + * Returns lists of goals to which the user has access + * + * @param string + * @param string + * @param string + * @return array + */ + public function getGoals($accountId = self::ALL, $webPropertyId = self::ALL, $profileId = self::ALL) { + //argument test + Eden_Google_Error::i() + ->argument(1, 'string') //argument 1 must be a string + ->argument(2, 'string') //argument 2 must be a string + ->argument(3, 'string'); //argument 3 must be a string + + //populate parameters + $query = array( + self::START_INDEX => $this->_startIndex, //optional + self::MAX_RESULTS => $this->_maxResults); //optional + + return $this->_getResponse(sprintf(self::URL_ANALYTICS_GOALS, $accountId, $webPropertyId, $profileId), $query); + } + + /** + * Returns lists of advanced segments to which the user has access + * + * @return array + */ + public function getSegments() { + //populate parameters + $query = array( + self::START_INDEX => $this->_startIndex, ///optional + self::MAX_RESULTS => $this->_maxResults); //optional + + return $this->_getResponse(self::URL_ANALYTICS_SEGMENTS, $query); + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/google/analytics/multichannel.php b/library/eden/google/analytics/multichannel.php new file mode 100644 index 0000000..054c04f --- /dev/null +++ b/library/eden/google/analytics/multichannel.php @@ -0,0 +1,152 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Google analytics multi channel funnel + * + * @package Eden + * @category google + * @author Christian Symon M. Buenavista sbuenavista@openovate.com + */ +class Eden_Google_Analytics_Multichannel extends Eden_Google_Base { + /* Constants + -------------------------------*/ + const URL_ANALYTICS_MULTI_CHANNEL = 'https://www.googleapis.com/analytics/v3/data/mcf'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_startIndex = NULL; + protected $_maxResults = NULL; + protected $_dimensions = NULL; + protected $_sort = NULL; + protected $_filters = NULL; + + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + public function __construct($token) { + //argument test + Eden_Google_Error::i()->argument(1, 'string'); + $this->_token = $token; + } + + /* Public Methods + -------------------------------*/ + /** + * Set start index + * + * @param integer + * @return this + */ + public function setStartIndex($startIndex) { + //argument 1 must be a integer + Eden_Google_Error::i()->argument(1, 'integer'); + $this->_startIndex = $startIndex; + + return $this; + } + + /** + * Set start index + * + * @param integer + * @return this + */ + public function setMaxResults($maxResults) { + //argument 1 must be a integer + Eden_Google_Error::i()->argument(1, 'integer'); + $this->_maxResults = $maxResults; + + return $this; + } + + /** + * Set dimensions + * + * @param integer + * @return this + */ + public function setDimesion($dimensions) { + //argument 1 must be a integer + Eden_Google_Error::i()->argument(1, 'integer'); + $this->_dimensions = $dimensions; + + return $this; + } + + /** + * Set sort + * + * @param integer + * @return this + */ + public function setSort($sort) { + //argument 1 must be a integer + Eden_Google_Error::i()->argument(1, 'integer'); + $this->_sort = $sort; + + return $this; + } + + /** + * Dimension or metric filters that restrict the data returned for your request. + * + * @param integer + * @return this + */ + public function setFilters($filters) { + //argument 1 must be a integer + Eden_Google_Error::i()->argument(1, 'integer'); + $this->_filters = $filters; + + return $this; + } + + /** + * Returns all accounts to which the user has access. + * + * @param string Unique table ID of the form + * @param string First date of the date range for which you are requesting the data. YYYY-MM-DD. + * @param string Last date of the date range for which you are requesting the data. YYYY-MM-DD. + * @param string List of comma-separated metrics, such as ga:visits,ga:bounces. + * @return array + */ + public function getInfo($id, $startDate, $endDate, $metrics) { + //argument test + Eden_Google_Error::i() + ->argument(1, 'string') //argument 1 must be a string + ->argument(2, 'string') //argument 2 must be a string + ->argument(3, 'string'); //argument 3 must be a string + + //populate parameters + $query = array( + 'ids' => $id, + 'start-date' => $startDate, + 'end-date' => $endDate, + 'metrics' => $metrics, + 'dimensions' => $this->_dimensions, //optional + 'sort' => $this->_sort, //optional + 'filters' => $this->_filters, //optional + 'start-index' => $this->_startIndex, //optional + 'max-results' => $this->_maxResults); //optional + + return $this->_getResponse(self::URL_ANALYTICS_MULTI_CHANNEL, $query); + } + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/google/analytics/reporting.php b/library/eden/google/analytics/reporting.php new file mode 100644 index 0000000..ed72547 --- /dev/null +++ b/library/eden/google/analytics/reporting.php @@ -0,0 +1,563 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Google Analytics Reporting + * + * @package Eden + * @category google + * @author Christian Symon M. Buenavista sbuenavista@openovate.com + * @author Christian Blanquera cblanquera@openovate.com + */ +class Eden_Google_Analytics_Reporting extends Eden_Google_Base { + /* Constants + -------------------------------*/ + const URL_ANALYTICS_CORE_REPORTING = 'https://www.googleapis.com/analytics/v3/data/ga'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_startIndex = NULL; + protected $_maxResults = NULL; + protected $_dimensions = array(); + protected $_sort = array(); + protected $_filters = NULL; + protected $_segment = array(); + protected $_fields = NULL; + protected $_prettyPrint = NULL; + protected $_userIp = NULL; + protected $_quotaUser = NULL; + + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + public function __construct($token) { + //argument test + Eden_Google_Error::i()->argument(1, 'string'); + $this->_token = $token; + } + + public function __call($name, $args) { + if(strpos($name, 'addDimension') === 0) { + //addSegmentCity('Manila') + $key = Eden_Type_String::i($name) + ->substr(12) + ->strtolower() + ->get(); + + if(!isset(self::$_options[$key], $args[0])) { + return $this; + } + + $this->_dimensions[] = self::$_options[$key]; + return $this; + } + + if(strpos($name, 'addSegment') === 0) { + //addSegmentCity('Manila') + $key = Eden_Type_String::i($name) + ->substr(10) + ->strtolower() + ->get(); + + if(!isset(self::$_options[$key], $args[0])) { + return $this; + } + + $this->_segment[] = self::$_options[$key]; + return $this; + } + + + + if(strpos($name, 'sortBy') === 0) { + //sortByCity('Manila') + $key = Eden_Type_String::i($name) + ->substr(6) + ->strtolower() + ->get(); + + if(!isset(self::$_options[$key], $args[0])) { + return $this; + } + + $this->_sort[] = self::$_options[$key]; + return $this; + } + + try { + return parent::__call($name, $args); + } catch(Eden_Error $e) { + Eden_Sql_Error::i($e->getMessage())->trigger(); + } + } + + /* Public Methods + -------------------------------*/ + /** + * Set start index + * + * @param integer + * @return this + */ + public function setStartIndex($startIndex) { + //argument 1 must be a integer + Eden_Google_Error::i()->argument(1, 'integer'); + $this->_startIndex = $startIndex; + + return $this; + } + + /** + * Set Max results + * + * @param integer + * @return this + */ + public function setMaxResults($maxResults) { + //argument 1 must be a integer + Eden_Google_Error::i()->argument(1, 'integer'); + $this->_maxResults = $maxResults; + + return $this; + } + + /** + * Set dimensions + * + * @param string|array The dimensions parameter breaks down metrics by common criteria; + * for example, by ga:browser or ga:city. + * @return this + */ + public function setDimensions($dimensions) { + //argument 1 must be a string or array + Eden_Google_Error::i()->argument(1, 'string', 'array'); + + if(is_string($dimensions)) { + $dimensions = func_get_args(); + } + + foreach($dimensions as $i => $dimension) { + if(isset(self::$_options[strtolower($dimension)])) { + $dimensions[$i] = self::$_options[strtolower($dimension)]; + } + } + + $this->_dimensions = $dimensions; + + return $this; + } + + /** + * Sorting order is specified by the left to right order of the metrics + * and dimensions listed. Sorting direction defaults to ascending and can be changed to descending + * by using a minus sign (-) prefix on the requested field. + * + * @param string|array Example: ga:country,ga:browser. + * @return this + */ + public function setSort($sort) { + //argument 1 must be a string or array + Eden_Google_Error::i()->argument(1, 'string', 'array'); + + if(is_string($sort)) { + $sort = func_get_args(); + } + + foreach($sort as $i => $key) { + if(isset(self::$_options[strtolower($key)])) { + $sort[$i] = self::$_options[strtolower($key)]; + } + } + + $this->_sort = $sort; + + return $this; + } + + /** + * Dimension or metric filters that restrict the data returned for your request. + * + * @param string Example: ga:browser >= FireFox + * @return this + */ + public function setFilters($filters) { + //argument 1 must be a string + Eden_Google_Error::i()->argument(1, 'string'); + + if(strpos($filters, ' ') === false) { + $this->_filters = $filters; + return $this; + } + + $gaWord = true; + $filters = explode(' ', $filters); + + foreach($filters as $i => $word) { + if($gaWord) { + if(strpos($word, 'ga:') !== 0) { + $filters[$i] = 'ga:'.$word; + if(isset(self::$_options[$word])) { + $filters[$i] = self::$_options[$word]; + } + } + + $gaWord = false; + } + + if(strtolower($word) == 'and') { + $filters[$i] = ';'; + $gaWord = false; + } else if(strtolower($word) == 'or') { + $filters[$i] = ','; + $gaWord = false; + } + } + + $this->_filters = urlencode(implode('', $filters)); + + return $this; + } + + /** + * Segments the data returned for your request. + * + * @param string|array Example: dynamic::ga:medium%3D%3Dreferral. + * @return this + */ + public function setSegments($segments) { + //argument 1 must be a string or array + Eden_Google_Error::i()->argument(1, 'string', 'array'); + + if(is_string($segments)) { + $segments = func_get_args(); + } + + foreach($segments as $i => $segment) { + if(isset(self::$_options[strtolower($segment)])) { + $segments[$i] = self::$_options[strtolower($segments)]; + } + } + + $this->_segment = $segments; + + return $this; + } + + /** + * Selector specifying a subset of fields to include in the response. + * + * @param string Example: rows,columnHeaders(name,dataType). + * @return this + */ + public function setFields($fields) { + //argument 1 must be a string + Eden_Google_Error::i()->argument(1, 'string'); + $this->_fields = $fields; + + return $this; + } + + /** + * Returns response with indentations and line breaks. + * + * @param integer + * @return this + */ + public function setPrettyPrint($prettyPrint) { + //argument 1 must be a integer + Eden_Google_Error::i()->argument(1, 'integer'); + $this->_prettyPrint = $prettyPrint; + + return $this; + } + + /** + * Specifies IP address of the end user for whom the API call is being made. + * + * @param string + * @return this + */ + public function setUserIp($userIp) { + //argument 1 must be a string + Eden_Google_Error::i()->userIp(1, 'string'); + $this->_userIp = $prettyPrint; + + return $this; + } + + /** + * Alternative to userIp in cases when the user's IP address is unknown. + * + * @param string + * @return this + */ + public function setQuotaUser($quotaUser) { + //argument 1 must be a string + Eden_Google_Error::i()->argument(1, 'string'); + $this->_quotaUser = $quotaUser; + + return $this; + } + + /** + * Returns all accounts to which the user has access. + * + * @param string Unique table ID of the form + * @param string First date of the date range for which you are requesting the data. YYYY-MM-DD. + * @param string Last date of the date range for which you are requesting the data. YYYY-MM-DD. + * @param string List of comma-separated metrics, such as ga:visits,ga:bounces. + * @return array + */ + public function getInfo($id, $startDate, $endDate, $metrics) { + //argument test + Eden_Google_Error::i() + ->argument(1, 'string', 'int') //argument 1 must be a string or int + ->argument(2, 'string', 'int') //argument 2 must be a string or int + ->argument(3, 'string', 'int') //argument 3 must be a string or int + ->argument(4, 'string', 'array'); //argument 4 must be a string or array + + $id = (string) $id; + if(strpos($id, 'ga:') !== 0) { + $id = 'ga:'.$id; + } + + if(is_string($startDate)) { + $startDate = strtotime($startDate); + } + + $startDate = date('Y-m-d', $startDate); + + if(is_string($endDate)) { + $endDate = strtotime($endDate); + } + + $endDate = date('Y-m-d', $endDate); + + if(!is_array($metrics)) { + $metrics = explode(',', $metrics); + } + + foreach($metrics as $i => $metric) { + $metric = trim($metric); + if(isset(self::$_options[strtolower($metric)])) { + $metrics[$i] = self::$_options[strtolower($metric)]; + } + } + + //populate parameters + $query = array( + 'ids' => $id, + 'start-date' => $startDate, + 'end-date' => $endDate, + 'metrics' => implode(',', $metrics), + 'dimensions' => implode(',', $this->_dimensions), //optional + 'sort' => implode(',', $this->_sort), //optional + 'filters' => $this->_filters, //optional + 'segment' => implode(',', $this->_segment), //optional + 'start-index' => $this->_startIndex, //optional + 'max-results' => $this->_maxResults, //optional + 'fields' => $this->_fields, //optional + 'prettyPrint' => $this->_prettyPrint, //optional + 'userIp' => $this->_userIp, //optional + 'quotaUser' => $this->_quotaUser); //optional + + return $this->_getResponse(self::URL_ANALYTICS_CORE_REPORTING, $query); + } + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ + /* Large Data + -------------------------------*/ + protected static $_options = array( + 'visitortype' => 'ga:visitorType', + 'visitcount' => 'ga:visitCount', + 'dayssincelastvisit' => 'ga:daysSinceLastVisit', + 'userdefinedvalue' => 'ga:userDefinedValue', + 'visitors' => 'ga:visitors', + 'newvisits' => 'ga:newVisits', + 'percentnewvisits' => 'ga:percentNewVisits', + 'visitlength' => 'ga:visitLength', + 'visits' => 'ga:visits', + 'bounces' => 'ga:bounces', + 'entrancebouncerate' => 'ga:entranceBounceRate', + 'visitbouncerate' => 'ga:visitBounceRate', + 'timeonsite' => 'ga:timeOnSite', + 'avgtimeonsite' => 'ga:avgTimeOnSite', + 'referralpath' => 'ga:referralPath', + 'campaign' => 'ga:campaign', + 'source' => 'ga:source', + 'medium' => 'ga:medium', + 'keyword' => 'ga:keyword', + 'adcontent' => 'ga:adContent', + 'organicsearches' => 'ga:organicSearches', + 'adgroup' => 'ga:adGroup', + 'adslot' => 'ga:adSlot', + 'adslotposition' => 'ga:adSlotPosition', + 'addistributionetwork' => 'ga:adDistributionNetwork', + 'admatchtype' => 'ga:adMatchType', + 'admatchedquery' => 'ga:adMatchedQuery', + 'adplacementdomain' => 'ga:adPlacementDomain', + 'adplacementurl' => 'ga:adPlacementUrl', + 'adformat' => 'ga:adFormat', + 'adtargetingtype' => 'ga:adTargetingType', + 'adtargetingoption' => 'ga:adTargetingOption', + 'addisplayurl' => 'ga:adDisplayUrl', + 'addestinationurl' => 'ga:adDestinationUrl', + 'adwordscustomerid' => 'ga:adwordsCustomerId', + 'adwordscampaignid' => 'ga:adwordsCampaignId', + 'adwordsadGroupid' => 'ga:adwordsAdGroupId', + 'adwordscreativeid' => 'ga:adwordsCreativeId', + 'qdwordscriteriaid' => 'ga:adwordsCriteriaId', + 'impressions' => 'ga:impressions', + 'adclicks' => 'ga:adClicks', + 'adcost' => 'ga:adCost', + 'cpm' => 'ga:CPM', + 'cpc' => 'ga:CPC', + 'ctr' => 'ga:CTR', + 'costpertransaction' => 'ga:costPerTransaction', + 'costpergoalconversion' => 'ga:costPerGoalConversion', + 'costperconversion' => 'ga:costPerConversion', + 'rpc' => 'ga:RPC', + 'roi' => 'ga:ROI', + 'margin' => 'ga:margin', + 'goalstarts' => 'ga:goal(n)Starts', + 'goalstartsall' => 'ga:goalStartsAll', + 'goalcompletions' => 'ga:goal(n)Completions', + 'goalcompletionsall' => 'ga:goalCompletionsAll', + 'goalvalue' => 'ga:goal(n)Value', + 'goalvalueall' => 'ga:goalValueAll', + 'goalvaluepervisit' => 'ga:goalValuePerVisit', + 'goalconversionrate' => 'ga:goal(n)ConversionRate', + 'goalconversionrateall' => 'ga:goalConversionRateAll', + 'goalabandons' => 'ga:goal(n)Abandons', + 'goalabandonsall' => 'ga:goalAbandonsAll', + 'goalabandonrate' => 'ga:goal(n)AbandonRate', + 'goalabandonrateall' => 'ga:goalAbandonRateAll', + 'browser' => 'ga:browser', + 'browserversion' => 'ga:browserVersion', + 'operatingsystem' => 'ga:operatingSystem', + 'operatingsystemversion' => 'ga:operatingSystemVersion', + 'flashversion' => 'ga:flashVersion', + 'javaenabled' => 'ga:javaEnabled', + 'ismobile' => 'ga:isMobile', + 'language' => 'ga:language', + 'screencolors' => 'ga:screenColors', + 'screenresolution' => 'ga:screenResolution', + 'continent' => 'ga:continent', + 'subcontinent' => 'ga:subContinent', + 'country' => 'ga:country', + 'region' => 'ga:region', + 'city' => 'ga:city', + 'latitude' => 'ga:latitude', + 'longitude' => 'ga:longitude', + 'networkdomain' => 'ga:networkDomain', + 'networklocation' => 'ga:networkLocation', + 'hostname' => 'ga:hostname', + 'pagepath' => 'ga:pagePath', + 'pagetitle' => 'ga:pageTitle', + 'landingpagepath' => 'ga:landingPagePath', + 'secondpagepath' => 'ga:secondPagePath', + 'exitpagepath' => 'ga:exitPagePath', + 'previouspagepath' => 'ga:previousPagePath', + 'nextpagepath' => 'ga:nextPagePath', + 'pagedepth' => 'ga:pageDepth', + 'entrances' => 'ga:entrances', + 'entrancerate' => 'ga:entranceRate', + 'pageviews' => 'ga:pageviews', + 'pageviewspervisit' => 'ga:pageviewsPerVisit', + 'uniquepageviews' => 'ga:uniquePageviews', + 'timeonpage' => 'ga:timeOnPage', + 'avgtimeonpage' => 'ga:avgTimeOnPage', + 'exits' => 'ga:exits', + 'exiteate' => 'ga:exitRate', + 'searchused' => 'ga:searchUsed', + 'searchkeyword' => 'ga:searchKeyword', + 'searchkeywordrefinement' => 'ga:searchKeywordRefinement', + 'searchcategory' => 'ga:searchCategory', + 'searchstartpage' => 'ga:searchStartPage', + 'searchdestinationpage' => 'ga:searchDestinationPage', + 'searchresultviews' => 'ga:searchResultViews', + 'searchuniques' => 'ga:searchUniques', + 'avgSearchresultviews' => 'ga:avgSearchResultViews', + 'searchvisits' => 'ga:searchVisits', + 'percentvisitswithsearch' => 'ga:percentVisitsWithSearch', + 'searchdepth' => 'ga:searchDepth', + 'avgsearchdepth' => 'ga:avgSearchDepth', + 'searchrefinements' => 'ga:searchRefinements', + 'searchduration' => 'ga:searchDuration', + 'avgsearchduration' => 'ga:avgSearchDuration', + 'searchexits' => 'ga:searchExits', + 'searchexitrate' => 'ga:searchExitRate', + 'searchgoalconversionrate' => 'ga:searchGoal(n)ConversionRate', + 'searchgoalconversionrateall' => 'ga:searchGoalConversionRateAll', + 'goalvalueallpersearch' => 'ga:goalValueAllPerSearch', + 'pageloadtime' => 'ga:pageLoadTime', + 'pageloadsample' => 'ga:pageLoadSample', + 'avgpageloadtime' => 'ga:avgPageLoadTime', + 'domainlookuptime' => 'ga:domainLookupTime', + 'avgdomainlookuptime' => 'ga:avgDomainLookupTime', + 'pagedownloadtime' => 'ga:pageDownloadTime', + 'avgpagedownloadtime' => 'ga:avgPageDownloadTime', + 'redirectiontime' => 'ga:redirectionTime', + 'avgredirectiontime' => 'ga:avgRedirectionTime', + 'serverconnectiontime' => 'ga:serverConnectionTime', + 'avgserverconnectiontime' => 'ga:avgServerConnectionTime', + 'serverresponsetime' => 'ga:serverResponseTime', + 'avgserverresponsetime' => 'ga:avgServerResponseTime', + 'speedmetricssample' => 'ga:speedMetricsSample', + 'eventcategory' => 'ga:eventCategory', + 'eventaction' => 'ga:eventAction', + 'eventlabel' => 'ga:eventLabel', + 'totalevents' => 'ga:totalEvents', + 'uniqueevents' => 'ga:uniqueEvents', + 'eventvalue' => 'ga:eventValue', + 'avgeventvalue' => 'ga:avgEventValue', + 'visitswithevent' => 'ga:visitsWithEvent', + 'eventspervisitwithevent' => 'ga:eventsPerVisitWithEvent', + 'transactionid' => 'ga:transactionId', + 'affiliation' => 'ga:affiliation', + 'visitstotransaction' => 'ga:visitsToTransaction', + 'daystotransaction' => 'ga:daysToTransaction', + 'productsku' => 'ga:productSku', + 'productname' => 'ga:productName', + 'productcategory' => 'ga:productCategory', + 'transactions' => 'ga:transactions', + 'transactionspervisit' => 'ga:transactionsPerVisit', + 'transactionrevenue' => 'ga:transactionRevenue', + 'revenuepertransaction' => 'ga:revenuePerTransaction', + 'transactionrevenuepervisit' => 'ga:transactionRevenuePerVisit', + 'transactionshipping' => 'ga:transactionShipping', + 'transactiontax' => 'ga:transactionTax', + 'totalvalue' => 'ga:totalValue', + 'itemquantity' => 'ga:itemQuantity', + 'uniquepurchases' => 'ga:uniquePurchases', + 'revenueperitem' => 'ga:revenuePerItem', + 'itemrevenue' => 'ga:itemRevenue', + 'itemsperpurchase' => 'ga:itemsPerPurchase', + 'customvarname' => 'ga:customVarName(n)', + 'customvarvalue' => 'ga:customVarValue(n)', + 'date' => 'ga:date', + 'year' => 'ga:year', + 'month' => 'ga:month', + 'week' => 'ga:week', + 'day' => 'ga:day', + 'hour' => 'ga:hour', + 'nthmonth' => 'ga:nthMonth', + 'nthweek' => 'ga:nthWeek', + 'nthday' => 'ga:nthDay', + 'dayofweek' => 'ga:dayOfWeek'); +} \ No newline at end of file diff --git a/library/eden/google/base.php b/library/eden/google/base.php new file mode 100644 index 0000000..e4893d9 --- /dev/null +++ b/library/eden/google/base.php @@ -0,0 +1,618 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Google base + * + * @package Eden + * @category google + * @author Christian Symon M. Buenavista sbuenavista@openovate.com + */ +class Eden_Google_Base extends Eden_Class { + /* Constants + -------------------------------*/ + const ACCESS_TOKEN = 'access_token'; + const KEY = 'key'; + const MAX_RESULTS = 'maxResults'; + const FORM_HEADER = 'application/x-www-form-urlencoded'; + const CONTENT_TYPE = 'Content-Type: application/json'; + const KIND = 'kind'; + const ID = 'id'; + const OCR = 'ocr'; + const SELF_LINK = 'selfLink'; + const CHILD_LINK = 'childLink'; + const CONVERT = 'convert'; + const PINNED = 'pinned'; + const TITLE = 'title'; + const IS_ROOT = 'isRoot'; + const ETAG = 'etag'; + const NAME = 'name'; + const ROLE = 'role'; + const TYPE = 'type'; + const RESPONSE = 'alt'; + const JSON_FORMAT = 'json'; + const VERSION = 'v'; + const QUERY = 'q'; + const QUERY_STRING = 'query'; + + const NEW_REVISION = 'newRevision'; + const OCR_LANGUAGE = 'ocrLanguage'; + const TEXT_LANGUAGE = 'timedTextLanguage'; + const TEXT_TRACKNAME = 'timedTextTrackName'; + const DESCRIPTION = 'description'; + const LAST_VIEW = 'lastViewedByMeDate'; + const MIME_TYPE = 'mimeType'; + const MODIFIED_DATE = 'modifiedDate'; + const AUTH_KEY = 'authKey'; + const WITH_LINK = 'withLink'; + const PHOTO_LINK = 'photoLink'; + const VALUE = 'value'; + const FILESIZE = 'fileSize'; + const SCOPE = 'scope'; + const CALENDAR_ID = 'calendarId'; + const SUMMARY = 'summary'; + const LOCATION = 'location'; + const TIMEZONE = 'timezone'; + const START = 'start'; + const END = 'end'; + const DESTINATION = 'destination'; + const STATUS = 'status'; + const ATTENDEES = 'attendees'; + const COLOR_ID = 'colorId'; + const CREATOR = 'creator'; + const ORGANIZER = 'organizer'; + const REMINDERS = 'reminders'; + const UID = 'iCalUID'; + const TEXT = 'text'; + const TIMEMIN = 'timeMin'; + const TIMEMAX = 'timeMax'; + const ITEMS = 'items'; + const ACCESS_ROLE = 'accessRole'; + const HIDDEN = 'hidden'; + const SELECTED = 'selected'; + const LAST_MODIFY = 'lastModifyingUserName'; + const PUBLISHED = 'published'; + + const SOURCE_LANGUAGE = 'sourceLanguage'; + const TARGET_LANGUAGE = 'targetLanguage'; + const GROUP_EXPANSION = 'groupExpansionMax'; + const CALENDAR_EXPANSION = 'calendarExpansionMax'; + const ORIGINAL_FILENAME = 'originalFilename'; + const OUTSIDE_DOMAIN = 'publishedOutsideDomain'; + const DEFAULT_REMINDERS = 'defaultRemiders'; + const SUMMARY_OVERRIDE = 'summaryOverride'; + const PUBLISHED_LINK = 'publishedLink'; + const PUBLISHED_AUTO = 'publishAuto'; + const DOWNLOAD_URL = 'downloadUrl'; + const EXPORT_LINK = 'exportLinks'; + const MD5_CHECKSUM = 'md5Checksum'; + const KEYWORD = 'keyword'; + const CATEGORY = 'category'; + const POST_URL = 'postUrl'; + const UPLOAD_TOKEN = 'uploadToken'; + const REDIRECT_URL = 'redirectUrl'; + const USER = 'user'; + const CHANNEL = 'channel'; + const START_INDEX = 'start-index'; + const ORDER_BY = 'orderby'; + const LIKE = 'like'; + const DISLIKE = 'dislike'; + const RATINGS = 'ratings'; + const USER_NAME = 'userName'; + const VIDEO_ID = 'videoId'; + const POSITION = 'position'; + const COMMENT = 'comment'; + const COMMENT_ID = 'commentId'; + const TIME = 'time'; + const COLLECTION = 'collection'; + const USER_ID = 'userId'; + const PAGE_TOKEN = 'pageToken'; + const ORDER = 'orderBy'; + const SORT = 'sortOrder'; + const ACITIVITY_ID = 'activityId'; + const INFO = 'info'; + const GIVEN_NAME = 'givenName'; + const FAMILY_NAME = 'familyName'; + const STREET = 'street'; + const PHONE_NUMBER = 'phoneNumber'; + const CITY = 'city'; + const POST_CODE = 'postCode'; + const COUNTRY = 'country'; + const NOTES = 'notes'; + const EMAIL = 'email'; + const PRIMARY = 'primary'; + const DEFAULT_VALUE = 'default'; + const VERSION_THREE = '3.0'; + const VERSION_TWO = '2'; + const ME = 'me'; + const PUBLIC_DATA = 'public'; + const ALL = '~all'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_token = NULL; + protected $_maxResult = NULL; + protected $_headers = array(self::FORM_HEADER, self::CONTENT_TYPE); + protected $_meta = array(); + protected $_developerId = NULL; + protected $_etag = NULL; + protected $_apiKey = NULL; + + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + /* Magic + -------------------------------*/ + /* Public Methods + -------------------------------*/ + /** + * Returns the meta of the last call + * + * @return array + */ + public function getMeta() { + + return $this->_meta; + } + + /** + * Check if the response is xml + * + * @param string|array|object|null + * @return bollean + */ + public function isXml($xml) { + //argument 1 must be a string, array, object or null + Eden_Google_Error::i()->argument(1, 'string', 'array', 'object', 'null'); + + if(is_array($xml) || is_null($xml)) { + return false; + } + libxml_use_internal_errors( true ); + $doc = new DOMDocument('1.0', 'utf-8'); + $doc->loadXML($xml); + $errors = libxml_get_errors(); + //front()->output($errors); exit; + return empty($errors); + } + + /** + * Check if the response is json format + * + * @param string + * @return boolean + */ + public function isJson($string) { + //argument 1 must be a string + Eden_Google_Error::i()->argument(1, 'string'); + + json_decode($string); + return (json_last_error() == JSON_ERROR_NONE); + } + + /** + * Set xml headers + * + * @param string + * @param boolean + * @return array + */ + public function setXmlHeaders($developerId, $etag = false) { + //argument testing + Eden_Google_Error::i() + ->argument(1, 'string', 'null') //argument 1 must be a string or null + ->argument(2, 'bool'); //argument 2 must be a boolean + + //if developer id is not needed in header + if(is_null($developerId)) { + //form xml header with no header + $headers = array( + 'application/x-www-form-urlencoded', + 'Content-Type: application/atom+xml'); + } + //if developer id is needed + if(!is_null($developerId) && !$etag){ + //form xml header with developer id + $headers = array( + 'application/x-www-form-urlencoded', + 'Content-Type: application/atom+xml', + 'X-GData-Key: key='.$developerId, + 'GData-Version: 2'); + } + + //if etag is needed in the headers + if(is_null($developerId) && $etag){ + //form xml header + $headers = array( + 'application/x-www-form-urlencoded', + 'Content-Type: application/atom+xml', + 'If-Match: *'); + } + + return $headers; + } + + /** + * Well format xml + * + * @param string|object + * @return xml + */ + public function formatToXml($query) { + //argument 1 must be a string or object + Eden_Google_Error::i()->argument(1, 'string', 'object'); + + $xml = new DOMDocument(); + $xml->preserveWhiteSpace = false; + $xml->formatOutput = true; + $xml->loadXML($query); + + return $xml->saveXML(); + } + /* Protected Methods + -------------------------------*/ + protected function _accessKey($array) { + + foreach($array as $key => $val) { + // if value is array + if(is_array($val)) { + $array[$key] = $this->_accessKey($val); + } + //if value in null + if($val == NULL || empty($val)) { + //remove it from query + unset($array[$key]); + } + } + return $array; + } + + protected function _reset() { + //foreach this as key => value + foreach ($this as $key => $value) { + //if the value of key is not array + if(!is_array($this->$key)) { + //if key name starts at underscore, probably it is protected variable + if(preg_match('/^_/', $key)) { + //if the protected variable is not equal to token + //we dont want to unset the access token + if($key != '_token') { + //reset all protected variables that currently use + $this->$key = NULL; + } + } + } + } + + return $this; + } + + protected function _customPost($url, array $query = array()) { + //add access token to query + $query[self::ACCESS_TOKEN] = $this->_token; + //if query is an array + if(is_array($query)) { + //prevent sending fields with no value + $query = $this->_accessKey($query); + //covent query to string + $query = http_build_query($query); + } + //combine url and query + $url = $url.'?'.$query; + //set curl + $curl = Eden_Curl::i() + ->verifyHost(false) + ->verifyPeer(false) + ->setUrl($url) + ->setPost(true) + ->setPostFields($query) + ->setHeaders($this->_headers); + + //get the response + $response = $curl->getJsonResponse(); + + $this->_meta = $curl->getMeta(); + $this->_meta['url'] = $url; + $this->_meta['headers'] = $this->_headers; + $this->_meta['query'] = $query; + + //reset protected variables + $this->_reset(); + + return $response; + } + + protected function _delete($url, array $query = array(), $etag = false) { + //if etag or developer id is needed in header + if($etag || !is_null($this->_developerId)) { + //set different headers for xml + $this->_headers = $this->setXmlHeaders($this->_developerId, $etag); + //add access token and version to the url + $url = $url.'?'.self::ACCESS_TOKEN.'='.$this->_token.'&v=3'; + //else it just needed regular headers + } else { + //add access token to the url + $url = $url.'?'.self::ACCESS_TOKEN.'='.$this->_token; + } + //set curl + $curl = Eden_Curl::i() + ->verifyHost(false) + ->verifyPeer(false) + ->setUrl($url) + ->setHeaders($this->_headers) + ->setCustomRequest('DELETE'); + + //get the response + $response = $curl->getResponse(); + + $this->_meta = $curl->getMeta(); + $this->_meta['url'] = $url; + $this->_meta['headers'] = $this->_headers; + + //reset protected variables + $this->_reset(); + + //check if response is in json format + if($this->isJson($response)) { + //else it is in json format, covert it to array + $response = json_decode($response, true); + } + //check if response is in xml format + if($this->isXml($response)) { + //if it is xml, convert it to array + $response = simplexml_load_string($response); + } + + return $response; + } + + protected function _getResponse($url, array $query = array()) { + //if needed, add access token to query + $query[self::ACCESS_TOKEN] = $this->_token; + //if needed, add developer id to the query + if(!is_null($this->_developerId)) { + $query[self::KEY] = $this->_developerId; + } + //if needed, add api key to the query + if(!is_null($this->_apiKey)) { + $query[self::KEY] = $this->_apiKey; + } + //prevent sending fields with no value + $query = $this->_accessKey($query); + //build url query + $url = $url.'?'.http_build_query($query); + //set curl + $curl = Eden_Curl::i() + ->setUrl($url) + ->verifyHost(false) + ->verifyPeer(false) + ->setTimeout(60); + //get response from curl + $response = $curl->getResponse(); + //get curl infomation + $this->_meta['url'] = $url; + $this->_meta['query'] = $query; + $this->_meta['curl'] = $curl->getMeta(); + $this->_meta['response'] = $response; + + //reset protected variables + $this->_reset(); + + //check if response is in xml format + if($this->isXml($response)) { + //if it is xml, convert it to array + return $response = simplexml_load_string($response); + } + + //check if response is in json format + if($this->isJson($response)) { + //else it is in json format, convert it to array + return $response = json_decode($response, true); + } + + //check if response is in base64 format + if(base64_decode($response, true)) { + //if not base64 format, return normal response + return $response; + //else it is in base64 format + } else { + //return an image + return ''; + } + + } + + protected function _patch($url, array $query = array()) { + //add access token to query + $url = $url.'?'.self::ACCESS_TOKEN.'='.$this->_token; + //prevent sending fields with no value + $query = $this->_accessKey($query); + //json encode query + $query = json_encode($query); + //set curl + $curl = Eden_Curl::i() + ->verifyHost(false) + ->verifyPeer(false) + ->setUrl($url) + ->setPost(true) + ->setPostFields($query) + ->setHeaders($this->_headers) + ->setCustomRequest('PATCH'); + + //get the response + $response = $curl->getJsonResponse(); + + $this->_meta = $curl->getMeta(); + $this->_meta['url'] = $url; + $this->_meta['headers'] = $this->_headers; + $this->_meta['query'] = $query; + + //reset protected variables + $this->_reset(); + + return $response; + } + + protected function _post($url, $query, $etag = false) { + //if query is in array + if(is_array($query)) { + //prevent sending fields with no value + $query = $this->_accessKey($query); + //json encode query + $query = json_encode($query); + //add access token to query + $url = $url.'?'.self::ACCESS_TOKEN.'='.$this->_token; + } + //if query is in xml format + if($this->isXml($query)) { + //set different headers for xml + $this->_headers = $this->setXmlHeaders($this->_developerId, $etag); + //well format the xml + $query = $this->formatToXml($query); + //add access token to query and convert response ti json format + $url = $url.'?'.self::ACCESS_TOKEN.'='.$this->_token.'&alt=json'; + } + //set curl + $curl = Eden_Curl::i() + ->verifyHost(false) + ->verifyPeer(false) + ->setUrl($url) + ->setPost(true) + ->setPostFields($query) + ->setHeaders($this->_headers); + //get response form curl + $response = $curl->getResponse(); + + $this->_meta = $curl->getMeta(); + $this->_meta['url'] = $url; + $this->_meta['headers'] = $this->_headers; + $this->_meta['query'] = $query; + + //reset protected variables + $this->_reset(); + + //check if response is in json format + if($this->isJson($response)) { + //else it is in json format, covert it to array + return $response = json_decode($response, true); + } + //check if response is in xml format + if($this->isXml($response)) { + //if it is xml, convert it to array + return $response = simplexml_load_string($response); + } + //if it is a normal response + return $response; + } + + protected function _put($url, $query, $etag = false) { + //if query is an array + if(is_array($query)) { + //prevent sending fields with no value + $query = $this->_accessKey($query); + //covent query to json format + $query = json_encode($query); + //add access token to the url + $url = $url.'?'.self::ACCESS_TOKEN.'='.$this->_token; + } + //if query is an xml + if($this->isXml($query)) { + //set different headers for xml + $this->_headers = $this->setXmlHeaders($this->_developerId, $etag); + //well format the xml + $query = $this->formatToXml($query); + //add access token to the url + $url = $url.'?'.self::ACCESS_TOKEN.'='.$this->_token; + } + //Open a file resource using the php://memory stream + $fh = fopen('php://memory', 'rw'); + // Write the data to the file + fwrite($fh, $query); + // Move back to the beginning of the file + rewind($fh); + + //start curl + $curl = Eden_Curl::i() + ->verifyHost(false) + ->verifyPeer(false) + ->setHeaders($this->_headers) + ->setPut(true) + ->setUrl($url) + ->setInFile($fh) + ->setInFileSize(strlen($query)); + + //get the response + $response = $curl->getResponse(); + + $this->_meta = $curl->getMeta(); + $this->_meta['url'] = $url; + $this->_meta['headers'] = $this->_headers; + $this->_meta['query'] = $query; + + //reset protected variables + $this->_reset(); + + //check if response is in json format + if($this->isJson($response)) { + //else it is in json format, covert it to array + return $response = json_decode($response, true); + } + //check if response is in xml format + if($this->isXml($response)) { + //if it is xml, convert it to array + return $response = simplexml_load_string($response); + } + + return $response; + } + + protected function _upload($url, $query, $etag = false) { + //well format the xml + $query = $this->formatToXml($query); + //set different headers for xml + $this->_headers = $this->setXmlHeaders($this->_developerId, $etag); + $this->_headers[] = 'Content-Length:'.strlen($query); + $this->_headers[] = 'Host: gdata.youtube.com'; + //add access token to query + $url = $url.'?'.self::ACCESS_TOKEN.'='.$this->_token; + + //set curl + $curl = Eden_Curl::i() + ->verifyHost(false) + ->verifyPeer(false) + ->setUrl($url) + ->setPost(true) + ->setPostFields($query) + ->setHeaders($this->_headers); + //get response form curl + $response = $curl->getResponse(); + + $this->_meta = $curl->getMeta(); + $this->_meta['url'] = $url; + $this->_meta['headers'] = $this->_headers; + $this->_meta['query'] = $query; + + //reset protected variables + $this->_reset(); + + //check if response is in xml format + if($this->isXml($response)) { + //if it is xml, convert it to array + return $response = simplexml_load_string($response); + } + //if it is a normal response + return $response; + } + + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/google/calendar.php b/library/eden/google/calendar.php new file mode 100644 index 0000000..9f9a730 --- /dev/null +++ b/library/eden/google/calendar.php @@ -0,0 +1,110 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Google Calendar API Factory + * + * @package Eden + * @category google + * @author Christian Symon M. Buenavista sbuenavista@openovate.com + */ +class Eden_Google_Calendar extends Eden_Google_Base { + /* Constants + -------------------------------*/ + const URL_CALENDAR_COLOR = 'https://www.googleapis.com/calendar/v3/colors'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + public function __construct($token) { + //argument test + Eden_Google_Error::i()->argument(1, 'string'); + $this->_token = $token; + } + + /* Public Methods + -------------------------------*/ + /** + * Returns Google acl + * + * @return Eden_Google_Calendar_acl + */ + public function acl() { + return Eden_Google_Calendar_Acl::i($this->_token); + } + + /** + * Returns Google Calendars + * + * @return Eden_Google_Calendar_Calendars + */ + public function calendars() { + return Eden_Google_Calendar_Calendars::i($this->_token); + } + + /** + * Returns the color definitions for + * calendars and events. + * + * @return array + */ + public function getColors() { + return $this->_getResponse(self::URL_CALENDAR_COLOR); + } + + /** + * Returns Google Event + * + * @return Eden_Google_Calendar_Event + */ + public function event() { + return Eden_Google_Calendar_Event::i($this->_token); + } + + /** + * Returns Google freebusy + * + * @return Eden_Google_Calendar_freebusy + */ + public function freebusy() { + return Eden_Google_Calendar_Freebusy::i($this->_token); + } + + /** + * Returns Google List + * + * @return Eden_Google_Calendar_List + */ + public function lists() { + return Eden_Google_Calendar_List::i($this->_token); + } + + /** + * Returns Google setting + * + * @return Eden_Google_Calendar_Settings + */ + public function settings() { + return Eden_Google_Calendar_Settings::i($this->_token); + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/google/calendar/acl.php b/library/eden/google/calendar/acl.php new file mode 100644 index 0000000..78e8b26 --- /dev/null +++ b/library/eden/google/calendar/acl.php @@ -0,0 +1,286 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Google Calendar Acl Class + * + * @package Eden + * @category google + * @author Christian Symon M. Buenavista sbuenavista@openovate.com + */ +class Eden_Google_Calendar_Acl extends Eden_Google_Base { + /* Constants + -------------------------------*/ + const URL_CALENDAR_ACL_GET = 'https://www.googleapis.com/calendar/v3/calendars/%s/acl'; + const URL_CALENDAR_ACL_SPECIFIC = 'https://www.googleapis.com/calendar/v3/calendars/%s/acl/%s'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_role = NULL; + protected $_type = NULL; + protected $_etag = NULL; + protected $_id = NULL; + protected $_kind = NULL; + + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + public function __construct($token) { + //argument test + Eden_Google_Error::i()->argument(1, 'string'); + $this->_token = $token; + } + + /* Public Methods + -------------------------------*/ + /** + * Creates a secondary calendar. + * + * @param string The role assigned to the scope + * @param string The type of the scope + * @param string Calendar identifier + * @return array + */ + public function create($role, $type, $calendarId = self::PRIMARY) { + //argument test + Eden_Google_Error::i() + ->argument(1, 'string') //argument 1 must be a string + ->argument(2, 'string') //argument 2 must be a string + ->argument(3, 'string'); //argument 3 must be a string + + //populate fields + $query = array( + self::ROLE => $role, + self::ETAG => $this->_etag, //optional + self::ID => $this->_id, //optional + self::KIND => $this->_kind, //optional + self::SCOPE => array(self::TYPE => $type)); + + return $this->_post(sprintf(self::URL_CALENDAR_ACL_GET, $calendarId), $query); + } + + /** + * Deletes an access control rule + * + * @param string ACL rule identifier + * @param string Calendar identifier + * @return null + */ + public function delete($ruleId, $calendarId = self::PRIMARY) { + //argument test + Eden_Google_Error::i() + ->argument(1, 'string') //argument 1 must be a string + ->argument(2, 'string'); //argument 1 must be a string + + return $this->_delete(sprintf(self::URL_CALENDAR_ACL_SPECIFIC, $calendarId, $ruleId)); + } + + /** + * Returns the rules in the access + * control list for the calendar. + * + * @param string Calendar identifier + * @return array + */ + public function getList($calendarId = self::PRIMARY) { + //argument test + Eden_Google_Error::i()->argument(1, 'string'); + + return $this->_getResponse(sprintf(self::URL_CALENDAR_ACL_GET, $calendarId)); + } + + /** + * Returns an access control rule. + * + * @param string ACL rule identifier + * @param string Calendar identifier + * @return array + */ + public function getSpecific($ruleId, $calendarId = self::PRIMARY) { + //argument test + Eden_Google_Error::i() + ->argument(1, 'string') //argument 1 must be a string + ->argument(2, 'string'); //argument 1 must be a string + + return $this->_getResponse(sprintf(self::URL_CALENDAR_ACL_SPECIFIC, $calendarId, $ruleId)); + } + + /** + * Set etag + * + * @param string ETag of the resource. + * @return this + */ + public function setEtag($etag) { + //argument 1 must be a string + Eden_Google_Error::i()->argument(1, 'string'); + $this->_etag = $etag; + + return $this; + } + + /** + * Set id + * + * @param string|integer Identifier of the ACL rule. + * @return this + */ + public function setId($id) { + //argument 1 must be a string or integer + Eden_Google_Error::i()->argument(1, 'string', 'int'); + $this->_id = $id; + + return $this; + } + + /** + * Set calendar kind + * + * @param string Type of the resource ("calendar#aclRule"). + * @return this + */ + public function setKind($kind) { + //argument 1 must be a string + Eden_Google_Error::i()->argument(1, 'string'); + $this->_kind = $kind; + + return $this; + } + + /** + * Provides read access to free/busy information. + * + * @return this + */ + public function setRoleToFreeBusyReader() { + $this->_role = 'freeBusyReader'; + + return $this; + } + + /** + * Provides no access role. + * + * @return this + */ + public function setRoleToNone() { + $this->_role = 'none'; + + return $this; + } + + /** + * Provides read access to the calendar. + * 1Private events will appear to users + * with reader access, but event details + * will be hidden. + * + * @return this + */ + public function setRoleToReader() { + $this->_role = 'reader'; + + return $this; + } + + /** + * Provides read and write access to + * the calendar. Private events will + * appear to users with writer access, + * and event details will be visible. + * + * @return this + */ + public function setRoleToWriter() { + $this->_role = 'writer'; + + return $this; + } + + /** + * Provides ownership of the calendar. + * This role has all of the permissions + * of the writer role with the additional + * ability to see and manipulate ACLs. + * + * @return this + */ + public function setRoleToOwner() { + $this->_role = 'owner'; + + return $this; + } + + /** + * Set rule id + * + * @param string + * @return this + */ + public function setRuleId($ruleId) { + //argument 1 must be a string + Eden_Google_Error::i()->argument(1, 'string'); + $this->_ruleId= $ruleId; + + return $this; + } + + /** + * The type of the scope. Possible values are: + * "default" - The public scope. This is the default value. + * "user" - Limits the scope to a single user. + * "group" - Limits the scope to a group. + * "domain" - Limits the scope to a domain. + * + * @return this + */ + public function setType($type) { + //argument 1 must be a string + Eden_Google_Error::i()->argument(1, 'string'); + $this->_type = $type; + + return $this; + } + + /** + * Updates an access control rule + * + * @param string ACL rule identifier + * @param string Calendar identifier + * @return array + */ + public function update($ruleId, $calendarId = self::PRIMARY) { + //argument test + Eden_Google_Error::i() + ->argument(1, 'string') //argument 1 must be a string + ->argument(2, 'string'); //argument 1 must be a string + + //populate fields + $query = array( + self::ETAG => $this->_etag, + self::ID => $this->_id, + self::KIND => $this->_kind, + self::ROLE => $this->_role, + self::SCOPE => $scope = array(self::TYPE => $this->_type)); + + return $this->_put(sprintf(self::URL_CALENDAR_ACL_SPECIFIC, $calendarId, $ruleId), $query); + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/google/calendar/calendars.php b/library/eden/google/calendar/calendars.php new file mode 100644 index 0000000..7252361 --- /dev/null +++ b/library/eden/google/calendar/calendars.php @@ -0,0 +1,260 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Google Calendar Calendars Class + * + * @package Eden + * @category google + * @author Christian Symon M. Buenavista sbuenavista@openovate.com + */ +class Eden_Google_Calendar_Calendars extends Eden_Google_Base { + /* Constants + -------------------------------*/ + const URL_CALENDAR_GET = 'https://www.googleapis.com/calendar/v3/calendars/%s'; + const URL_CALENDAR_CREATE = 'https://www.googleapis.com/calendar/v3/calendars'; + const URL_CALENDAR_CLEAR = 'https://www.googleapis.com/calendar/v3/calendars/%s/clear'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_timeZone = NULL; + protected $_etag = NULL; + protected $_id = NULL; + protected $_kind = NULL; + protected $_location = NULL; + protected $_summary = NULL; + protected $_description = NULL; + + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + public function __construct($token) { + //argument test + Eden_Google_Error::i()->argument(1, 'string'); + $this->_token = $token; + } + + /* Public Methods + -------------------------------*/ + /** + * Clears a primary calendar. This operation + * deletes all data associated with the primary + * calendar of an account and cannot be undone + * + * @param string Calendar identifier + * @return null + */ + public function clear($calendarId = self::PRIMARY) { + //argument 1 must be a string + Eden_Google_Error::i()->argument(1, 'string'); + + return $this->_post(sprintf(self::URL_CALENDAR_CLEAR, calendarId)); + } + + /** + * Creates a secondary calendar. + * + * @param string* Title of the calendar. + * @return array + */ + public function create($summary) { + //argument 1 must be a string + Eden_Google_Error::i()->argument(1, 'string'); + + //populate fields + $query = array( + self::SUMMARY => $summary, + self::ETAG => $this->_etag, //optional + self::ID => $this->_id, //optional + self::KIND => $this->_kind, //optional + self::DESCRIPTION => $this->_description, //optional + self::LOCATION => $this->_location, //optional + self::TIMEZONE => $this->_timeZone); //optional + + return $this->_post(self::URL_CALENDAR_CREATE, $query); + } + + /** + * Deletes a secondary calendar. + * + * @param string Calendar identifier + * @return null + */ + public function delete($calendarid = self::PRIMARY) { + //argument 1 must be a string + Eden_Google_Error::i()->argument(1, 'string'); + + return $this->_delete(sprintf(self::URL_CALENDAR_GET, $calendarId)); + } + + /** + * Return specific calendar + * + * @param string Calendar identifier + * @return array + */ + public function getCalendars($calendarId = self::PRIMARY) { + //argument 1 must be a string + Eden_Google_Error::i()->argument(1, 'string'); + + return $this->_getResponse(sprintf(self::URL_CALENDAR_GET, $calendarId)); + } + + /** + * Updates metadata for a calendar. + * This method supports patch semantics. + * + * @param string Calendar identifier + * @return array + */ + public function patch($calendarId = self::PRIMARY) { + //argument 1 must be a string + Eden_Google_Error::i()->argument(1, 'string'); + + //populate fields + $query = array( + self::ETAG => $this->_etag, //optional + self::ID => $this->_id, //optional + self::KIND => $this->_kind, //optional + self::SUMARRY => $this->_summary); //optional + + return $this->_patch(sprintf(self::URL_CALENDAR_GET, $calendarId), $query); + } + + /** + * Set default reminders + * + * @param string + * @return this + */ + public function setDescription($description) { + //argument 1 must be a string + Eden_Google_Error::i()->argument(1, 'string'); + $this->_description = $description; + + return $this; + } + + /** + * ETag of the resource. + * + * @param string + * @return this + */ + public function setEtag($etag) { + //argument 1 must be a string + Eden_Google_Error::i()->argument(1, 'string'); + $this->_etag = $etag; + + return $this; + } + + /** + * Identifier of the calendar. + * + * @param string|integer + * @return this + */ + public function setId($id) { + //argument 1 must be a string or integer + Eden_Google_Error::i()->argument(1, 'string', 'int'); + $this->_id = $id; + + return $this; + } + + /** + * Set calendar kind + * + * @param string Type of the resource ("calendar#calendar"). + * @return this + */ + public function setKind($kind) { + //argument 1 must be a string + Eden_Google_Error::i()->argument(1, 'string'); + $this->_kind = $kind; + + return $this; + } + + /** + * Set geographic location of the + 8 calendar as free-form text. + * + * @param string + * @return this + */ + public function setLocation($location) { + //argument 1 must be a string + Eden_Google_Error::i()->argument(1, 'string'); + $this->_location = $location; + + return $this; + } + + /** + * Set summary + * + * @param string + * @return this + */ + public function setSummary($summary) { + //argument 1 must be a string + Eden_Google_Error::i()->argument(1, 'string'); + $this->_summary = $summary; + + return $this; + } + + /** + * Set time zone + * + * @param string The time zone of the calendar. + * @return this + */ + public function setTimeZone($timeZone) { + //argument 1 must be a string + Eden_Google_Error::i()->argument(1, 'string'); + $this->_timeZone = $timeZone; + + return $this; + } + + /** + * Update Calendar + * + * @param string Calendar identifier + * @return array + */ + public function update($calendarId = self::PRIMARY) { + //argument 1 must be a string + Eden_Google_Error::i()->argument(1, 'string'); + + //populate fields + $query = array( + self::ETAG => $this->_etag, //optional + self::ID => $this->_id, //optional + self::KIND => $this->_kind, //optional + self::SUMARRY => $this->_summary); //optional + + return $this->_put(sprintf(self::URL_CALENDAR_GET, $calendarId), $query); + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/google/calendar/event.php b/library/eden/google/calendar/event.php new file mode 100644 index 0000000..e278a64 --- /dev/null +++ b/library/eden/google/calendar/event.php @@ -0,0 +1,456 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Google Calendar Event Class + * + * @package Eden + * @category google + * @author Christian Symon M. Buenavista sbuenavista@openovate.com + */ +class Eden_Google_Calendar_Event extends Eden_Google_Base { + /* Constants + -------------------------------*/ + const URL_CALENDAR_EVENT = 'https://www.googleapis.com/calendar/v3/calendars/%s/events'; + const URL_CALENDAR = 'https://www.googleapis.com/calendar/v3/calendars/%s/events/%s'; + const URL_CALENDAR_IMPORT = 'https://www.googleapis.com/calendar/v3/calendars/%s/events/import'; + const URL_CALENDAR_MOVE = 'https://www.googleapis.com/calendar/v3/calendars/%s/events/%s/move'; + const URL_QUICK_CREATE_EVENT = 'https://www.googleapis.com/calendar/v3/calendars/%s/events/quickAdd'; + const URL_CALENDAR_INSTANCES = 'https://www.googleapis.com/calendar/v3/calendars/%s/events/%s/instances'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_location = NULL; + protected $_description = NULL; + protected $_colorId = NULL; + protected $_creator = NULL; + protected $_kind = NULL; + protected $_organizer = NULL; + protected $_reminders = NULL; + protected $_status = NULL; + + protected $_start = array(); + protected $_end = array(); + protected $_attendees = array(); + + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + public function __construct($token) { + //argument test + Eden_Google_Error::i()->argument(1, 'string'); + $this->_token = $token; + } + + /* Public Methods + -------------------------------*/ + + /** + * sets the attendees for event + * + * @param string|array + * @return this + */ + public function addAttendee($attendee) { + //argument 1 must be a string or array + Eden_Google_Error::i()->argument(1, 'string', 'array'); + + if(!is_array($attendee)) { + $attendee = array($attendee); + } + + foreach($attendee as $user) { + $this->_attendees[] = array('email' => $user); + } + + return $this; + } + + /** + * Create event + * + * @param string* Title of the calendar + * @param string* Calendar identifier. + * @return array + */ + public function create($summary, $calendarId = self::PRIMARY) { + //argument testing + Eden_Google_Error::i() + ->argument(1, 'string') //argument 1 must be a string + ->argument(2, 'string'); //argument 2 must be a string + + //populate fields + $query = array( + self::SUMMARY => $summary, + self::LOCATION => $this->_location, //optional + self::START => $this->_start, //optional + self::END => $this->_end, //optional + self::ATTENDEES => $this->_attendees); //optional + + return $this->_post(sprintf(self::URL_CALENDAR_EVENT, $calendarId), $query); + } + + /** + * Delete Calendar specific events + * + * @param string Event identifier + * @param string Calendar identifier + * @return array + */ + public function delete($eventId, $calendarId = self::PRIMARY) { + //argument testing + Eden_Google_Error::i() + ->argument(1, 'string') //argument 1 must be a string + ->argument(2, 'string'); //argument 2 must be a string + + return $this->_delete(sprintf(self::URL_CALENDAR, $calendarId, $eventId), $url); + } + + /** + * Return all event fo calendar + * + * @param string Calendar identifier + * @return array + */ + public function getEvent($calendarId = self::PRIMARY) { + //argument 1 must be a string or integer + Eden_Google_Error::i()->argument(1, 'int', 'string'); + + return $this->_getResponse(sprintf(self::URL_CALENDAR_EVENT, $calendarId)); + } + + /** + * Return instances of specific event + * + * @param string Event identifier + * @param string Calendar identifier + * @return array + */ + public function getInstances($eventId, $calendarId = self::PRIMARY) { + //argument testing + Eden_Google_Error::i() + ->argument(1, 'string') //argument 1 must be a string + ->argument(2, 'string'); //argument 2 must be a string + + return $this->_getResponse(sprintf(self::URL_CALENDAR_INSTANCES, $calendarId, $eventId)); + } + + /** + * Return specific event + * + * @param string Event identifier + * @param string Calendar identifier + * @return array + */ + public function getSpecificEvent($eventId, $calendarId = self::PRIMARY) { + //argument testing + Eden_Google_Error::i() + ->argument(1, 'string') //argument 1 must be a string + ->argument(2, 'string'); //argument 2 must be a string + + return $this->_getResponse(sprintf(self::URL_CALENDAR, $calendarId, $eventId)); + } + + /** + * Import an event of a calendar + * + * @param string|integer The (exclusive) start time of the event + * @param string|integer The (exclusive) end time of the event + * @param string Event ID in the iCalendar format. + * @param string Calendar identifier + * @return array + */ + public function importEvent($start, $end, $importId, $calendarId = self::PRIMARY) { + //argument testing + Eden_Google_Error::i() + ->argument(1, 'string', 'int') //argument 1 must be a string or integer + ->argument(2, 'string', 'int') //argument 2 must be a string or integer + ->argument(3, 'string') //argument 3 must be a string + ->argument(4, 'string'); //argument 4 must be a string + + if(is_string($start) ) { + $start = strtotime($start); + } + + if(is_string($end) ) { + $end = strtotime($end); + } + + $end['dateTime'] = date('c', $end); + $start['dateTime'] = date('c', $start); + + //populate fields + $query = array( + self::START => $start, + self::END => $end, + self::UID => $importId); + + return $this->_post(sprintf(self::URL_CALENDAR_IMPORT, $calendarId), $query); + } + + /** + * Moves an event to another calendar + * + * @param string Calendar identifier of the target calendar where the event is to be moved to. + * @param string Event identifier + * @param string Calendar identifier + * @return array + */ + public function moveEvent($destination, $eventId, $calendarId = self::PRIMARY) { + //argument testing + Eden_Google_Error::i() + ->argument(1, 'string') //argument 1 must be a string + ->argument(2, 'string') //argument 2 must be a string + ->argument(3, 'string'); //argument 3 must be a string + + //populate fields + $query = array(self::DESTINATION => $destination); + + return $this->_customPost(sprintf(self::URL_CALENDAR_MOVE, $calendarId, $eventId), $query); + } + + /** + * Updates an entry on the user's calendar list. + * This method supports patch semantics. + * + * @param string Event identifier + * @param string Calendar identifier + * @return array + */ + public function patch($eventId, $calendarId = self::PRIMARY) { + //argument testing + Eden_Google_Error::i() + ->argument(1, 'string') //argument 1 must be a string + ->argument(2, 'string'); //argument 2 must be a string + + //populate fields + $query = array( + self::END => $this->_end, //optional + self::START => $this->_start, //optional + self::DESCRIPTION => $this->_description, //optional + self::COLOR_ID => $this->_colorId, //optional + self::CREATOR => $this->_creator, //optional + self::KIND => $this->_kind, //optional + self::LOCATION => $this->_location, //optional + self::ORGANIZER => $this->_organizer, //optional + self::REMINDERS => $this->_reminders, //optional + self::STATUS => $this->_status); //optional + + return $this->_patch(sprintf(self::URL_CALENDAR, $calendarId, $eventId), $query); + } + + /** + * Creates an event based on a simple text string + * + * @param string The text describing the event to be created. + * @param string Calendar identifier + * @return array + */ + public function quickCreate($text, $calendarId = self::PRIMARY) { + //argument testing + Eden_Google_Error::i() + ->argument(1, 'string') //argument 1 must be a string + ->argument(2, 'string'); //argument 2 must be a string + + //populate fields + $query = array(self::TEXT => $text); + + return $this->_customPost(sprintf(self::URL_QUICK_CREATE_EVENT, $calendarId), $query); + } + + /** + * Set event color id + * + * @param integer + * @return this + */ + public function setColorId($colorId) { + //argument 1 must be a integer + Eden_Google_Error::i()->argument(1, 'int'); + $this->_colorId = $colorId; + + return $this; + } + + /** + * Set the color of the event. + * + * @param string ID referring to an entry in the "event" section of the colors definition + * @return this + */ + public function setCreator($creator) { + //argument 1 must be a string + Eden_Google_Error::i()->argument(1, 'string'); + $this->_creator = $creator; + + return $this; + } + + /** + * Set event description + * + * @param string + * @return this + */ + public function setDescription($description) { + //argument 1 must be a string + Eden_Google_Error::i()->argument(1, 'string'); + $this->_description = $description; + + return $this; + } + + /** + * sets the end for event + * + * @param string|int + * @return this + */ + public function setEnd($end) { + //argument 1 must be a string or integer + Eden_Google_Error::i()->argument(1, 'string', 'int'); + + if(is_string($end)) { + $end = strtotime($end); + } + + $this->_end['dateTime'] = date('c', $end); + + return $this; + } + + /** + * Set event kind + * + * @param string + * @return this + */ + public function setKind($kind) { + //argument 1 must be a string + Eden_Google_Error::i()->argument(1, 'string'); + $this->_kind = $kind; + + return $this; + } + + /** + * Set the location for event + * + * @param string + * @return this + */ + public function setLocation($location) { + //argument 1 must be a string + Eden_Google_Error::i()->argument(1, 'string'); + $this->_location = $location; + + return $this; + } + + /** + * Set event organizer + * + * @param string + * @return this + */ + public function setOrganizer($organizer) { + //argument 1 must be a string + Eden_Google_Error::i()->argument(1, 'string'); + $this->_organizer = $organizer; + + return $this; + } + + /** + * Set event reminders + * + * @param string + * @return this + */ + public function setReminders($reminders) { + //argument 1 must be a string + Eden_Google_Error::i()->argument(1, 'string'); + $this->_reminders = $reminders; + + return $this; + } + /** + * Set start for event + * + * @param string|int + * @return this + */ + public function setStart($start) { + //argument 1 must be a string or integer + Eden_Google_Error::i()->argument(1, 'string', 'int'); + + if(is_string($start)) { + $start = strtotime($start); + } + + $this->_start['dateTime'] = date('c', $start); + + return $this; + } + + /** + * Set event status + * + * @param string + * @return this + */ + public function setStatus($status) { + //argument 1 must be a string + Eden_Google_Error::i()->argument(1, 'string'); + $this->_status = $status; + + return $this; + } + + /** + * Update Calendar specific events + * + * @param string Event identifier + * @param string Calendar identifier + * @return array + */ + public function update($eventId, $calendarId = self::PRIMARY) { + //argument testing + Eden_Google_Error::i() + ->argument(1, 'string') //argument 1 must be a string + ->argument(2, 'string'); //argument 2 must be a string + + //populate fields + $query = array( + self::END => $this->_end, //optional + self::START => $this->_start, //optional + self::DESCRIPTION => $this->_description, //optional + self::COLOR_ID => $this->_colorId, //optional + self::CREATOR => $this->_creator, //optional + self::KIND => $this->_kind, //optional + self::LOCATION => $this->_location, //optional + self::ORGANIZER => $this->_organizer, //optional + self::REMINDERS => $this->_reminders, //optional + self::STATUS => $this->_status); //optional + + return $this->_put(sprintf(self::URL_CALENDAR, $calendarId, $eventId), $query); + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/google/calendar/freebusy.php b/library/eden/google/calendar/freebusy.php new file mode 100644 index 0000000..f36056f --- /dev/null +++ b/library/eden/google/calendar/freebusy.php @@ -0,0 +1,127 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Google Calendar Freebusy Class + * + * @package Eden + * @category google + * @author Christian Symon M. Buenavista sbuenavista@openovate.com + */ +class Eden_Google_Calendar_Freebusy extends Eden_Google_Base { + /* Constants + -------------------------------*/ + const URL_CALENDAR_FREEBUSY = 'https://www.googleapis.com/calendar/v3/freeBusy'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_timeZone = NULL; + protected $_groupExpansionMax = NULL; + protected $_calendarExpansionMax = NULL; + protected $_items = NULL; + + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + public function __construct($token) { + //argument test + Eden_Google_Error::i()->argument(1, 'string'); + $this->_token = $token; + } + + /* Public Methods + -------------------------------*/ + /** + * Returns free/busy information + * for a set of calendars + * + * @param string|integer The start of the interval + * @param string|integer The end of the interval + * @return array + */ + public function query($startTime, $endTime) { + //argument test + Eden_Google_Error::i() + ->argument(1, 'string', 'int') //argument 1 must be a string or integer + ->argument(2, 'string', 'int'); //argument 2 must be a string or integer + + if(is_string($startTime)) { + $startTime = strtotime($startTime); + } + + if(is_string($endTime)) { + $endTime = strtotime($endTime); + } + + //populate fields + $query = array( + self::TIMEMIN => $startTime, + self::TIMEMAX => $endTime, + self::TIMEZONE => $this->_timeZone, + self::GROUP_EXPANSION => $this->_groupExpansionMax, + self::CALENDAR_EXPANSION => $this->_calendarExpansionMax, + self::ITEMS => $id = array(self::ID => $this->_items)); + + return $this->_post(self::URL_CALENDAR_FREEBUSY, $query); + } + + /** + * Set calendar expansion max + * + * @param intger + * @return this + */ + public function setCalendarExpansionMax($calendarExpansionMax) { + //argument 1 must be a integer + Eden_Google_Error::i()->argument(1, 'int'); + $this->_calendarExpansionMax = $calendarExpansionMax; + + return $this; + } + + /** + * Set group expansion max + * + * @param intger + * @return this + */ + public function setGroupExpansionMax($groupExpansionMax) { + //argument 1 must be a integer + Eden_Google_Error::i()->argument(1, 'int'); + $this->_groupExpansionMax = $groupExpansionMax; + + return $this; + } + + /** + * Set items + * + * @param string|intger + * @return this + */ + public function setItem($item) { + //argument 1 must be a string or integer + Eden_Google_Error::i()->argument(1, 'string', 'int'); + $this->_items = $item; + + return $this; + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/google/calendar/list.php b/library/eden/google/calendar/list.php new file mode 100644 index 0000000..7a0d6e8 --- /dev/null +++ b/library/eden/google/calendar/list.php @@ -0,0 +1,375 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Google Calendar List Class + * + * @package Eden + * @category google + * @author Christian Symon M. Buenavista sbuenavista@openovate.com + */ +class Eden_Google_Calendar_List extends Eden_Google_Base { + /* Constants + -------------------------------*/ + const URL_CALENDAR_LIST = 'https://www.googleapis.com/calendar/v3/users/me/calendarList'; + const URL_CALENDAR_GET = 'https://www.googleapis.com/calendar/v3/users/me/calendarList/%s'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_timeZone = NULL; + protected $_calendarId = NULL; + protected $_maxResults = NULL; + protected $_accessRole = NULL; + protected $_colorId = NULL; + protected $_etag = NULL; + protected $_id = NULL; + protected $_kind = NULL; + protected $_location = NULL; + protected $_summary = NULL; + protected $_defaultReminders = NULL; + protected $_description = NULL; + protected $_summaryOverride = NULL; + + protected $_selected = false; + protected $_hidden = false; + + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + public function __construct($token) { + //argument test + Eden_Google_Error::i()->argument(1, 'string'); + $this->_token = $token; + } + + /* Public Methods + -------------------------------*/ + /** + * Adds an entry to the user's calendar list. + * + * @param string Identifier of the calendar + * @return array + */ + public function create($id) { + //argument test + Eden_Google_Error::i()->argument(1, 'string'); + + //populate fields + $query = array( + self::ID => $id, + self::ACCESS_ROLE => $this->_accessRole, //optional + self::COLOR_ID => $this->_colorId, //optional + self::DEFAULT_REMINDERS => $this->_defaultReminders, //optional + self::DESCRIPTION => $this->_description, //optional + self::HIDDEN => $this->_hidden, //optional + self::LOCATION => $this->_location, //optional + self::SELECTED => $this->_selected, //optional + self::SUMMARY => $this->_summary, //optional + self::SUMMARY_OVERRIDE => $this->_summaryOverride, //optional + self::TIMEZONE => $this->_timeZone); //optional + + return $this->_post(self::URL_CALENDAR_LIST, $query); + } + + /** + * Return all event of calendar + * + * @param string Calendar identifier + * @return array + */ + public function delete($calendarId) { + //argument test + Eden_Google_Error::i()->argument(1, 'string'); + + return $this->_delete(sprintf(self::URL_CALENDAR_GET, $calendarId)); + } + + /** + * Return all event fo calendar + * + * @param string Calendar identifier + * @return array + */ + public function getCalendar($calendarId) { + //argument test + Eden_Google_Error::i()->argument(1, 'string'); + + return $this->_getResponse(sprintf(self::URL_CALENDAR_GET, $calendarId)); + } + + /** + * Return all event fo calendar + * + * @return array + */ + public function getList() { + //populate fields + $query = array(self::MAX_RESULTS => $this->_maxResults); + + return $this->_getResponse(self::URL_CALENDAR_LIST, $query); + } + + /** + * Updates an entry on the user's calendar list. This method supports patch semantics. + * + * @param string Calendar identifier + * @return array + */ + public function patch($calendarId) { + //argument test + Eden_Google_Error::i()->argument(1, 'string'); + + //populate fields + $query = array( + self::COLOR_ID => $this->_colorId, //optional + self::DEFAULT_REMINDERS => $this->_defaultReminders, //optional + self::HIDDEN => $this->_hidden, //optional + self::SELECTED => $this->_selected, //optional + self::SUMMARY_OVERRIDE => $this->_summaryOverride); //optional + + return $this->_patch(sprintf(self::URL_CALENDAR_GET, $calendarId), $query); + } + + /** + * Set Access Role + * + * @param string + * @return this + */ + public function setAccessRole($accessRole) { + //argument 1 must be a string + Eden_Google_Error::i()->argument(1, 'string'); + $this->_accessRole = $accessRole; + + return $this; + } + + /** + * Set calendar id + * + * @param string + * @return this + */ + public function setCalendarId($calendarId) { + //argument 1 must be a string + Eden_Google_Error::i()->argument(1, 'string'); + $this->_calendarId = $calendarId; + + return $this; + } + + /** + * Set color id + * + * @param integer ID referring to an entry in the "calendar" section of the colors definition + * @return this + */ + public function setColorId($colorId) { + //argument 1 must be a integer + Eden_Google_Error::i()->argument(1, 'int'); + $this->_colorId = $colorId; + + return $this; + } + + /** + * Set default reminders + * + * @param string + * @return this + */ + public function setDefaultReminders($defaultReminders) { + //argument 1 must be a string + Eden_Google_Error::i()->argument(1, 'string'); + $this->_defaultReminders = $defaultReminders; + + return $this; + } + + /** + * Set default reminders + * + * @param string + * @return this + */ + public function setDescription($description) { + //argument 1 must be a string + Eden_Google_Error::i()->argument(1, 'string'); + $this->_description = $description; + + return $this; + } + + /** + * Set etag + * + * @param string + * @return this + */ + public function setEtag($etag) { + //argument 1 must be a string + Eden_Google_Error::i()->argument(1, 'string'); + $this->_etag = $etag; + + return $this; + } + + /** + * Set calendar hidden + * + * @return this + */ + public function setHidden() { + $this->_hidden = true; + + return $this; + } + + /** + * Set id + * + * @param string|integer + * @return this + */ + public function setId($id) { + //argument 1 must be a string or integer + Eden_Google_Error::i()->argument(1, 'string', 'int'); + $this->_id = $id; + + return $this; + } + + /** + * Set calendar kind + * + * @param string + * @return this + */ + public function setKind($kind) { + //argument 1 must be a string + Eden_Google_Error::i()->argument(1, 'string'); + $this->_kind = $kind; + + return $this; + } + + /** + * Set location + * + * @param string + * @return this + */ + public function setLocation($location) { + //argument 1 must be a string + Eden_Google_Error::i()->argument(1, 'string'); + $this->_location = $location; + + return $this; + } + + /** + * Set query max results + * + * @param integer + * @return this + */ + public function setMaxResults($maxResults) { + //argument 1 must be a integer + Eden_Google_Error::i()->argument(1, 'int'); + $this->_maxResults = $maxResults; + + return $this; + } + + /** + * Set selected + * + * @return this + */ + public function setSelected() { + $this->_selected = true; + + return $this; + } + + /** + * Set summary + * + * @param string + * @return this + */ + public function setSummary($summary) { + //argument 1 must be a string + Eden_Google_Error::i()->argument(1, 'string'); + $this->_summary = $summary; + + return $this; + } + + /** + * Set summary override + * + * @param string + * @return this + */ + public function setSummaryOverride($summaryOverride) { + //argument 1 must be a string + Eden_Google_Error::i()->argument(1, 'string'); + $this->_summaryOverride = $summaryOverride; + + return $this; + } + + /** + * Set time zone + * + * @param string The time zone of the calendar. + * @return this + */ + public function setTimeZone($timeZone) { + //argument 1 must be a string + Eden_Google_Error::i()->argument(1, 'string'); + $this->_timeZone = $timeZone; + + return $this; + } + + /** + * Update Calendar + * + * @param string Calendar identifier + * @return array + */ + public function update($calendarId) { + //argument 1 must be a string + Eden_Google_Error::i()->argument(1, 'string'); + + //populate fields + $query = array( + self::COLOR_ID => $this->_colorId, //optional + self::DEFAULT_REMINDERS => $this->_defaultReminders, //optional + self::HIDDEN => $this->_hidden, //optional + self::SELECTED => $this->_selected, //optional + self::SUMMARY_OVERRIDE => $this->_summaryOverride); //optional + + return $this->_put(sprintf(self::URL_CALENDAR_GET, $calendarId), $query); + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/google/calendar/settings.php b/library/eden/google/calendar/settings.php new file mode 100644 index 0000000..630abfe --- /dev/null +++ b/library/eden/google/calendar/settings.php @@ -0,0 +1,68 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Google Calendar Settings Class + * + * @package Eden + * @category google + * @author Christian Symon M. Buenavista sbuenavista@openovate.com + */ +class Eden_Google_Calendar_Settings extends Eden_Google_Base { + /* Constants + -------------------------------*/ + const URL_CALENDAR_SETTINGS = 'https://www.googleapis.com/calendar/v3/users/me/settings'; + const URL_CALENDAR_SETTINGS_GET = 'https://www.googleapis.com/calendar/v3/users/me/settings/%s'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + public function __construct($token) { + //argument test + Eden_Google_Error::i()->argument(1, 'string'); + $this->_token = $token; + } + + /* Public Methods + -------------------------------*/ + /** + * Returns all user settings for the authenticated user. + * + * @return array + */ + public function getList() { + + return $this->_getResponse(self::URL_CALENDAR_SETTINGS); + } + + /** + * Returns a single user setting + * + * @param string Name of the user setting. + * @return array + */ + public function getSpecific($setting) { + + return $this->_getResponse(sprintf(self::URL_CALENDAR_SETTINGS_GET, $setting)); + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/google/checkout/form.php b/library/eden/google/checkout/form.php new file mode 100644 index 0000000..f522a3d --- /dev/null +++ b/library/eden/google/checkout/form.php @@ -0,0 +1,91 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Google + * + * @package Eden + * @category google + * @author Christian Symon M. Buenavista sbuenavista@openovate.com + */ +class Eden_Google_Checkout_Form extends Eden_Google_Base { + /* Constants + -------------------------------*/ + const URL_TEST_CHECKOUT = 'https://sandbox.google.com/checkout/api/checkout/v2/checkoutForm/Merchant/%s'; + const URL_LIVE_CHECKOUT = 'https://checkout.google.com/api/checkout/v2/checkoutForm/Merchant/%s'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_merchantId = NULL; + + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + public function __construct($merchantId) { + //argument test + Eden_Google_Error::i()->argument(1, 'string'); + + $this->_merchantId = $merchantId; + + } + /* Public Methods + -------------------------------*/ + /** + * Returns a checkout form + * + * @param string + * @param string|integer + * @param string + * @param string|integer + * @param string + * @param boolean Set to false for live url + * @return array + */ + public function checkoutForm($itemName, $price, $description, $quantity, $currency = 'USD', $test = true) { + //argument test + Eden_Google_Error::i() + ->argument(1, 'string') //argument 1 must be a string + ->argument(2, 'string', 'int') //argument 2 must be a string or integer + ->argument(3, 'string') //argument 3 must be a string + ->argument(4, 'string', 'int') //argument 4 must be a string or integer + ->argument(5, 'string') //argument 5 must be a string + ->argument(6, 'bool'); //argument 6 must be a booelean + + if($test = true) { + //set url to sandbox + $url = sprintf(self::URL_TEST_CHECKOUT, $this->_merchantId); + } else { + //set url to live account + $url = sprintf(self::URL_LIVE_CHECKOUT, $this->_merchantId); + } + //make a xml template + $form = Eden_Template::i() + ->set('url', $url) + ->set('itemName', $itemName) + ->set('itemDescription', $description) + ->set('itemPrice', $price) + ->set('itemCurrency', $currency) + ->set('itemQuantity', $quantity) + ->set('merchantId', $this->_merchantId) + ->parsePHP(dirname(__FILE__).'/template/form.php'); + + return $form; + } + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/google/checkout/template/form.php b/library/eden/google/checkout/template/form.php new file mode 100644 index 0000000..5daf81a --- /dev/null +++ b/library/eden/google/checkout/template/form.php @@ -0,0 +1,11 @@ +
+ + + + + + + +
\ No newline at end of file diff --git a/library/eden/google/contacts.php b/library/eden/google/contacts.php new file mode 100644 index 0000000..921effc --- /dev/null +++ b/library/eden/google/contacts.php @@ -0,0 +1,83 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Google Contacts + * + * @package Eden + * @category google + * @author Christian Symon M. Buenavista sbuenavista@openovate.com + */ +class Eden_Google_Contacts extends Eden_Google_Base { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + public function __construct($token) { + //argument test + Eden_Google_Error::i()->argument(1, 'string'); + $this->_token = $token; + } + + /* Public Methods + -------------------------------*/ + /** + * Returns Google contacts batch + * + * @return Eden_Google_Contacts_Batch + */ + public function batch() { + + return Eden_Google_Contacts_Batch::i($this->_token); + } + + /** + * Returns Google contacts data + * + * @return Eden_Google_Contacts_Batch + */ + public function data() { + + return Eden_Google_Contacts_Data::i($this->_token); + } + + /** + * Returns Google contacts groups + * + * @return Eden_Google_Contacts_Groups + */ + public function groups() { + + return Eden_Google_Contacts_Groups::i($this->_token); + } + + /** + * Returns Google contacts photo + * + * @return Eden_Google_Contacts_Photo + */ + public function photo() { + + return Eden_Google_Contacts_Photo::i($this->_token); + } + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/google/contacts/batch.php b/library/eden/google/contacts/batch.php new file mode 100644 index 0000000..ebd910b --- /dev/null +++ b/library/eden/google/contacts/batch.php @@ -0,0 +1,187 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Google contacts batch + * + * @package Eden + * @category google + * @author Christian Symon M. Buenavista sbuenavista@openovate.com + */ +class Eden_Google_Contacts_Batch extends Eden_Google_Base { + /* Constants + -------------------------------*/ + const URL_CONTACTS_GROUPS_LIST = 'https://www.google.com/m8/feeds/groups/%s/full'; + const URL_CONTACTS_GROUPS_GET = 'https://www.google.com/m8/feeds/groups/%s/full/%s'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_userEmail = 'default'; + protected $_version = '3.0'; + protected $_title = NULL; + protected $_description = NULL; + protected $_info = NULL; + protected $_groupId = NULL; + + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + public function __construct($token) { + //argument test + Eden_Google_Error::i()->argument(1, 'string'); + $this->_token = $token; + } + + /* Public Methods + -------------------------------*/ + /** + * Set user email + * + * @param string + * @return this + */ + public function setUserEmail($userEmail) { + //argument 1 must be a string + Eden_Google_Error::i()->argument(1, 'string'); + $this->_userEmail = $userEmail; + + return $this; + } + + /** + * Set user email + * + * @param string + * @return this + */ + public function setGroupId($groupId) { + //argument 1 must be a string + Eden_Google_Error::i()->argument(1, 'string'); + $this->_groupId = $groupId; + + return $this; + } + + /** + * Set group title + * + * @param string + * @return this + */ + public function setTitle($title) { + //argument 1 must be a string + Eden_Google_Error::i()->argument(1, 'string'); + $this->_title = $title; + + return $this; + } + + /** + * Set group description + * + * @param string + * @return this + */ + public function setDescription($description) { + //argument 1 must be a string + Eden_Google_Error::i()->argument(1, 'string'); + $this->_description = $description; + + return $this; + } + + /** + * Set group description + * + * @param string + * @return this + */ + public function setInfo($info) { + //argument 1 must be a string + Eden_Google_Error::i()->argument(1, 'string'); + $this->_info = $info; + + return $this; + } + + /** + * Retrieve all group list + * + * @param string + * @return array + */ + public function getList($userEmail = self::DEFAULT_VALUE) { + //argument 1 must be a string + Eden_Google_Error::i()->argument(1, 'string'); + + //populate fields + $query = array(self::VERSION => self::VERSION_THREE); + + return $this->_getResponse(sprintf(self::URL_CONTACTS_GROUPS_LIST, $userEmail), $query); + } + + /** + * Retrieve all group list + * + * @param string + * @param string + * @param string + * @param string + * @return array + */ + public function create($title, $description, $info, $userEmail = self::DEFAULT_VALUE) { + //argument test + Eden_Google_Error::i() + ->argument(1, 'string') //argument 1 must be a string + ->argument(2, 'string') //argument 2 must be a string + ->argument(3, 'string') //argument 3 must be a string + ->argument(4, 'string'); //argument 4 must be a string + + //populate fields + $parameters = array( + self::TITLE => $title, + self::DESCRIPTION => $description, + self::INFO => $info); + + //make a xml template + $query = Eden_Template::i() + ->set($parameters) + ->parsePHP(dirname(__FILE__).'/template/addgroups.php'); + + return $this->_post(sprintf(self::URL_CONTACTS_GROUPS_LIST, $userEmail), $query); + } + + /** + * Delete a group + * + * @param string + * @param string + * @return array + */ + public function delete($groupId, $userEmail = self::DEFAULT_VALUE) { + //argument test + Eden_Google_Error::i() + ->argument(1, 'string') //argument 1 must be a string + ->argument(2, 'string'); //argument 2 must be a string + + return $this->_delete(sprintf(self::URL_CONTACTS_GROUPS_GET, $userEmail, $groupId), true); + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/google/contacts/data.php b/library/eden/google/contacts/data.php new file mode 100644 index 0000000..b48285e --- /dev/null +++ b/library/eden/google/contacts/data.php @@ -0,0 +1,147 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Google contacts data + * + * @package Eden + * @category google + * @author Christian Symon M. Buenavista sbuenavista@openovate.com + */ +class Eden_Google_Contacts_Data extends Eden_Google_Base { + /* Constants + -------------------------------*/ + const URL_CONTACTS_LIST = 'https://www.google.com/m8/feeds/contacts/%s/full'; + const URL_CONTACTS_GET = 'https://www.google.com/m8/feeds/contacts/%s/full/%s'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + public function __construct($token) { + //argument test + Eden_Google_Error::i()->argument(1, 'string'); + $this->_token = $token; + } + + /* Public Methods + -------------------------------*/ + /** + * Retrieve all of a user's contacts + * + * @param string + * @return array + */ + public function getList($userEmail = self::DEFAULT_VALUE) { + //argument 1 must be a string + Eden_Google_Error::i()->argument(1, 'string'); + + //populate fields + $query = array( + self::VERSION => self::VERSION_THREE, + self::RESPONSE => self::JSON_FORMAT); + + return $this->_getResponse(sprintf(self::URL_CONTACTS_LIST, $userEmail), $query); + } + + /** + * Retrieve a single contact + * + * @param string + * @param string + * @return array + */ + public function getSpecific($contactId, $userEmail = self::DEFAULT_VALUE) { + //argument test + Eden_Google_Error::i() + ->argument(1, 'string') //argument 1 must be a string + ->argument(2, 'string'); //argument 2 must be a string + + //populate fields + $query = array( + self::VERSION => self::VERSION_THREE, + self::RESPONSE => self::JSON_FORMAT); + + return $this->_getResponse(sprintf(self::URL_CONTACTS_GET, $userEmail, $contactId), $query); + } + + /** + * Creates a contacts. + * + * @param string + * @param string + * @param string + * @param string + * @param string + * @param string + * @param string + * @param string + * @param string + * @param string + * @return array + */ + public function create($givenName, $familyName, $phoneNumber, $city, $street, $postCode, $country, $notes, $email, $userEmail = self::DEFAULT_VALUE) { + //argument test + Eden_Google_Error::i() + ->argument(1, 'string') //argument 1 must be a string + ->argument(2, 'string') //argument 2 must be a string + ->argument(3, 'string') //argument 3 must be a string + ->argument(4, 'string') //argument 4 must be a string + ->argument(5, 'string') //argument 5 must be a string + ->argument(6, 'string') //argument 6 must be a string + ->argument(7, 'string') //argument 7 must be a string + ->argument(8, 'string') //argument 8 must be a string + ->argument(9, 'string') //argument 9 must be a string + ->argument(10, 'string'); //argument 10 must be a string + + //make a xml template + $query = Eden_Template::i() + ->set(self::GIVEN_NAME, $givenName) + ->set(self::FAMILY_NAME, $familyName) + ->set(self::PHONE_NUMBER, $phoneNumber) + ->set(self::CITY, $city) + ->set(self::STREET, $street) + ->set(self::POST_CODE, $postCode) + ->set(self::COUNTRY, $country) + ->set(self::NOTES, $notes) + ->set(self::EMAIL, $email) + ->parsePHP(dirname(__FILE__).'/template/addcontacts.php'); + + return $this->_post(sprintf(self::URL_CONTACTS_LIST, $userEmail), $query); + } + + /** + * Delete a contact + * + * @return array + * @param string + * @param string + */ + public function delete($contactId, $userEmail = self::DEFAULT_VALUE) { + //argument test + Eden_Google_Error::i() + ->argument(1, 'string') //argument 1 must be a string + ->argument(2, 'string'); //argument 2 must be a string + + return $this->_delete(sprintf(self::URL_CONTACTS_GET, $userEmail, $contactId), true); + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/google/contacts/groups.php b/library/eden/google/contacts/groups.php new file mode 100644 index 0000000..dce5dd8 --- /dev/null +++ b/library/eden/google/contacts/groups.php @@ -0,0 +1,129 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Google contacts groups + * + * @package Eden + * @category google + * @author Christian Symon M. Buenavista sbuenavista@openovate.com + */ +class Eden_Google_Contacts_Groups extends Eden_Google_Base { + /* Constants + -------------------------------*/ + const URL_CONTACTS_GROUPS_LIST = 'https://www.google.com/m8/feeds/groups/%s/full'; + const URL_CONTACTS_GROUPS_GET = 'https://www.google.com/m8/feeds/groups/%s/full/%s'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + public function __construct($token) { + //argument test + Eden_Google_Error::i()->argument(1, 'string'); + $this->_token = $token; + } + + /* Public Methods + -------------------------------*/ + /** + * Retrieve all group list + * + * @param string + * @return array + */ + public function getList($userEmail = self::DEFAULT_VALUE) { + //argument 1 must be a string + Eden_Google_Error::i()->argument(1, 'string'); + + //populate fields + $query = array( + self::VERSION => self::VERSION_THREE, + self::RESPONSE => self::JSON_FORMAT); + + return $this->_getResponse(sprintf(self::URL_CONTACTS_CONTACTS_LIST, $userEmail), $query); + } + + /** + * Retrieve single group list + * + * @param string + * @param string + * @return array + */ + public function getSpecific($groudId, $userEmail = self::DEFAULT_VALUE) { + //argument test + Eden_Google_Error::i() + ->argument(1, 'string') //argument 1 must be a string + ->argument(2, 'string'); //argument 2 must be a string + + //populate fields + $query = array( + self::VERSION => self::VERSION_THREE, + self::RESPONSE => self::JSON_FORMAT); + + return $this->_getResponse(sprintf(self::URL_CONTACTS_GROUPS_GET, $userEmail, $groupId), $query); + } + + /** + * Retrieve all group list + * + * @param string + * @param string + * @param string + * @param string + * @return array + */ + public function create($title, $description, $info, $userEmail = self::DEFAULT_VALUE) { + //argument test + Eden_Google_Error::i() + ->argument(1, 'string') //argument 1 must be a string + ->argument(2, 'string') //argument 2 must be a string + ->argument(3, 'string') //argument 3 must be a string + ->argument(4, 'string'); //argument 4 must be a string + + //make a xml template + $query = Eden_Template::i() + ->set(self::TITLE, $title) + ->set(self::DESCRIPTION, $description) + ->set(self::INFO, $info) + ->parsePHP(dirname(__FILE__).'/template/addgroups.php'); + + return $this->_post(sprintf(self::URL_CONTACTS_GROUPS_LIST, $userEmail), $query); + } + + /** + * Delete a group + * + * @param string + * @param string + * @return array + */ + public function delete($groupId, $userEmail = self::DEFAULT_VALUE) { + //argument test + Eden_Google_Error::i() + ->argument(1, 'string') //argument 1 must be a string + ->argument(2, 'string'); //argument 2 must be a string + + return $this->_delete(sprintf(self::URL_CONTACTS_GROUPS_GET, $userEmail, $groupId), true); + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/google/contacts/photo.php b/library/eden/google/contacts/photo.php new file mode 100644 index 0000000..dc12242 --- /dev/null +++ b/library/eden/google/contacts/photo.php @@ -0,0 +1,82 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Google Contacts Photos + * + * @package Eden + * @category google + * @author Christian Symon M. Buenavista sbuenavista@openovate.com + */ +class Eden_Google_Contacts_Photo extends Eden_Google_Base { + /* Constants + -------------------------------*/ + const URL_CONTACTS_GET_IMAGE = 'https://www.google.com/m8/feeds/photos/media/%s/%s'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + public function __construct($token) { + //argument test + Eden_Google_Error::i()->argument(1, 'string'); + $this->_token = $token; + } + + /* Public Methods + -------------------------------*/ + /** + * Retrieve a single contact photo + * + * @param string + * @param string + * @return array + */ + public function getImage($contactId, $userEmail = self::DAFAULT) { + //argument test + Eden_Google_Error::i() + ->argument(1, 'string') //argument 1 must be a string + ->argument(2, 'string'); //argument 2 must be a string + + //populate fields + $query = array( + self::VERSION => self::VERSION_THREE, + self::RESPONSE => self::JSON_FORMAT); + + return $this->_getResponse(sprintf(self::URL_CONTACTS_GET_IMAGE, $userEmail, $contactId), $query); + } + + /** + * Delete a photo + * + * @param string + * @param string + * @return array + */ + public function delete($contactId, $userEmail = self::DAFAULT) { + //argument test + Eden_Google_Error::i() + ->argument(1, 'string') //argument 1 must be a string + ->argument(2, 'string'); //argument 2 must be a string + + return $this->_delete(sprintf(self::URL_CONTACTS_GET_IMAGE, $userEmail, contactId), true); + } + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/google/contacts/template/addcontacts.php b/library/eden/google/contacts/template/addcontacts.php new file mode 100644 index 0000000..bdb1882 --- /dev/null +++ b/library/eden/google/contacts/template/addcontacts.php @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/library/eden/google/contacts/template/addgroups.php b/library/eden/google/contacts/template/addgroups.php new file mode 100644 index 0000000..6ef45d0 --- /dev/null +++ b/library/eden/google/contacts/template/addgroups.php @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/library/eden/google/drive.php b/library/eden/google/drive.php new file mode 100644 index 0000000..04ed0b0 --- /dev/null +++ b/library/eden/google/drive.php @@ -0,0 +1,120 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Google Drive API factory + * + * @package Eden + * @category google + * @author Christian Symon M. Buenavista sbuenavista@openovate.com + */ +class Eden_Google_Drive extends Eden_Google_Base { + /* Constants + -------------------------------*/ + const URL_DRIVE_ABOUT = 'https://www.googleapis.com/drive/v2/about'; + const URL_DRIVE_APPS = 'hhttps://www.googleapis.com/drive/v2/apps'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + public function __construct($token) { + //argument test + Eden_Google_Error::i()->argument(1, 'string'); + $this->_token = $token; + } + + /* Public Methods + -------------------------------*/ + /** + * Returns Google Drive Changes + * + * @return Eden_Google_Drive_Changes + */ + public function changes() { + return Eden_Google_Drive_Changes::i($this->_token); + } + + /** + * Returns Google Drive Children + * + * @return Eden_Google_Drive_Children + */ + public function children() { + return Eden_Google_Drive_Children::i($this->_token); + } + + /** + * Returns Google Drive Files + * + * @return Eden_Google_Drive_Files + */ + public function files() { + return Eden_Google_Drive_Files::i($this->_token); + } + + /** + * Gets the information about the + * current user along with Drive API settings + * + * @return array + */ + public function getAbout() { + return $this->_getResponse(self::URL_DRIVE_ABOUT); + } + + /** + * Lists a user's apps. + * + * @return array + */ + public function getApps() { + return $this->_getResponse(self::URL_DRIVE_APPS); + } + + /** + * Returns Google Drive parent + * + * @return Eden_Google_Drive_Parent + */ + public function parents() { + return Eden_Google_Drive_Parent::i($this->_token); + } + + /** + * Returns Google Drive Permissions + * + * @return Eden_Google_Drive_Permissions + */ + public function permissions() { + return Eden_Google_Drive_Permissions::i($this->_token); + } + + /** + * Returns Google Drive Revisions + * + * @return Eden_Google_Drive_Revisions + */ + public function revisions() { + return Eden_Google_Drive_Revisions::i($this->_token); + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/google/drive/changes.php b/library/eden/google/drive/changes.php new file mode 100644 index 0000000..3019851 --- /dev/null +++ b/library/eden/google/drive/changes.php @@ -0,0 +1,69 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Google Drive Changes Class + * + * @package Eden + * @category google + * @author Christian Symon M. Buenavista sbuenavista@openovate.com + */ +class Eden_Google_Drive_Changes extends Eden_Google_Base { + /* Constants + -------------------------------*/ + const URL_DRIVE_CHANGES_LIST = 'https://www.googleapis.com/drive/v2/changes'; + const URL_DRIVE_CHANGES_GET = 'https://www.googleapis.com/drive/v2/changes/%s'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + public function __construct($token) { + //argument test + Eden_Google_Error::i()->argument(1, 'string'); + $this->_token = $token; + } + + /* Public Methods + -------------------------------*/ + /** + * Lists the changes for a user. + * + * @return array + */ + public function getList() { + + return $this->_getResponse(self::URL_DRIVE_CHANGES_LIST); + } + + /** + * Gets a specific changes. + * + * @param string The ID of the change + * @return array + */ + public function getSpecific($changeId) { + //argument test + Eden_Google_Error::i()->argument(1, 'string'); + + return $this->_getResponse(sprintf(self::URL_DRIVE_CHANGES_GET, $changeId)); + } + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/google/drive/children.php b/library/eden/google/drive/children.php new file mode 100644 index 0000000..6addbd7 --- /dev/null +++ b/library/eden/google/drive/children.php @@ -0,0 +1,110 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Google Drive Children Class + * + * @package Eden + * @category google + * @author Christian Symon M. Buenavista sbuenavista@openovate.com + */ +class Eden_Google_Drive_Children extends Eden_Google_Base { + /* Constants + -------------------------------*/ + const URL_CHILDREN_LIST = 'https://www.googleapis.com/drive/v2/files/%s/children'; + const URL_CHILDREN_SPECIFIC = 'https://www.googleapis.com/drive/v2/files/%s/children/%s'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + public function __construct($token) { + //argument test + Eden_Google_Error::i()->argument(1, 'string'); + $this->_token = $token; + } + + /* Public Methods + -------------------------------*/ + /** + * Removes a child from a folder + * + * @param string + * @param string + * @return array + */ + public function delete($folderId, $childId) { + //argument test + Eden_Google_Error::i() + ->argument(1, 'string') //argunemt 1 must be a string + ->argument(2, 'string'); //argunemt 2 must be a string + + return $this->_delete(sprintf(self::URL_CHILDREN_SPECIFIC, $fileId, $childId)); + } + + /** + * Returns list of folder's children + * + * @param string + * @return array + */ + public function getList($folderId) { + //argument test + Eden_Google_Error::i()->argument(1, 'string'); + + return $this->_getResponse(sprintf(self::URL_CHANGES_LIST, $folderId)); + } + + /** + * Gets a specific child reference + * + * @param string + * @param string + * @return array + */ + public function getSpecific($folderId, $childId) { + //argument test + Eden_Google_Error::i() + ->argument(1, 'string') //argunemt 1 must be a string + ->argument(2, 'string'); //argunemt 2 must be a string + + return $this->_getResponse(sprintf(self::URL_CHILDREN_SPECIFIC, $fileId, $childId)); + } + + /** + * Inserts a file into a folder + * + * @param string + * @param string + * @return array + */ + public function insert($folderId, $childId) { + //argument test + Eden_Google_Error::i() + ->argument(1, 'string') //argunemt 1 must be a string + ->argument(2, 'string'); //argunemt 2 must be a string + + //populate fields + $query = array(self::ID => $childId); + + return $this->_post(sprintf(self::URL_CHANGES_LIST, $folderId), $query); + } + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/google/drive/files.php b/library/eden/google/drive/files.php new file mode 100644 index 0000000..da6cf51 --- /dev/null +++ b/library/eden/google/drive/files.php @@ -0,0 +1,437 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Google Drive Files Class + * + * @package Eden + * @category google + * @author Christian Symon M. Buenavista sbuenavista@openovate.com + */ +class Eden_Google_Drive_Files extends Eden_Google_Base { + /* Constants + -------------------------------*/ + const URL_DRIVE_LIST = 'https://www.googleapis.com/drive/v2/files'; + const URL_DRIVE_GET = 'https://www.googleapis.com/drive/v2/files/%s'; + const URL_DRIVE_TRASH = 'https://www.googleapis.com/drive/v2/files/%s/trash'; + const URL_DRIVE_UNTRASH = 'https://www.googleapis.com/drive/v2/files/%s/untrash'; + const URL_DRIVE_TOUCH = 'https://www.googleapis.com/drive/v2/files/%s/touch'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_convert = false; + protected $_ocr = false; + protected $_pinned = false; + protected $_newRevision = false; + protected $_ocrLanguage = NULL; + protected $_sourceLanguage = NULL; + protected $_targetLanguage = NULL; + protected $_timedTextLanguage = NULL; + protected $_timedTextTrackName = NULL; + protected $_description = NULL; + protected $_lastViewedByMeDate = NULL; + protected $_mimeType = NULL; + protected $_modifiedDate = NULL; + protected $_title = NULL; + + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + public function __construct($token) { + //argument test + Eden_Google_Error::i()->argument(1, 'string'); + $this->_token = $token; + } + + /* Public Methods + -------------------------------*/ + /** + * Creates a copy of the specified file + * + * @param string + * @return array + */ + public function copyFile($fileId) { + //argument test + Eden_Google_Error::i()->argument(1, 'string'); + + return $this->_post(sprintf(self::URL_DRIVE_COPY, $fileId)); + } + + /** + * This method supports media upload. + * Uploaded files must conform to these constraints: + * + * @return array + */ + public function create() { + //populate parameters + $parameters = array( + self::CONVERT => $this->_convert, //optional + self::OCR => $this->_ocr, //optional + self::OCR_LANGUAGE => $this->_ocrLanguage, //optional + self::PINNED => $this->_pinned, //optional + self::SOURCE_LANGUAGE => $this->_sourceLanguage, //optional + self::TARGET_LANGUAGE => $this->_targetLanguage, //optional + self::TEXT_LANGUAGE => $this->_timedTextLanguage, //optional + self::TEXT_TRACKNAME => $this->_timedTextTrackName); //optional + + //populate fields + $requestBody = array ( + self::DESCRIPTION => $this->_description, //optional + self::LAST_VIEW => $this->_lastViewedByMeDate, //optional + self::MIME_TYPE => $this->_mimeType, //optional + self::MODIFIED_DATE => $this->_modifiedDate, //optional + self::TITLE => $this->_title); //optional + + return $this->_post(self::URL_DRIVE_LIST, $query = array_merge($parameters, $requestBody)); + } + + /** + * Updates file metadata and/or content. + * + * @param string + * @return array + */ + public function delete($fileId) { + //argument test + Eden_Google_Error::i()->argument(1, 'string'); + + return $this->_delete(sprintf(self::URL_DRIVE_GET, $fileId)); + } + + /** + * Returns the color definitions for + * calendars and events. + * + * @return array + */ + public function getList() { + + return $this->_getResponse(self::URL_DRIVE_LIST); + } + + /** + * Gets a file's metadata by ID. + * + * @param string + * @return array + */ + public function getSpecific($fileId) { + //argument test + Eden_Google_Error::i()->argument(1, 'string'); + + return $this->_getResponse(sprintf(self::URL_DRIVE_GET, $fileId)); + } + + /** + * Updates file metadata and/or content. + * This method supports patch semantics. + * + * @return array + */ + public function patch($fileId) { + //argument test + Eden_Google_Error::i()->argument(1, 'string'); + + //populate parameters + $parameters = array( + self::CONVERT => $this->_convert, //optional + self::NEW_REVISION => $this->_newRevision, //optional + self::OCR => $this->_ocr, //optional + self::OCR_LANGUAGE => $this->_ocrLanguage, //optional + self::PINNED => $this->_pinned, //optional + self::SOURCE_LANGUAGE => $this->_sourceLanguage, //optional + self::TARGET_LANGUAGE => $this->_targetLanguage, //optional + self::TEXT_LANGUAGE => $this->_timedTextLanguage, //optional + self::TEXT_TRACKNAME => $this->_timedTextTrackName); //optional + + //populate fields + $requestBody = array ( + self::DESCRIPTION => $this->_description, //optional + self::LAST_VIEW => $this->_lastViewedByMeDate, //optional + self::MIME_TYPE => $this->_mimeType, //optional + self::MODIFIED_DATE => $this->_modifiedDate, //optional + self::TITLE => $this->_title); //optional + + return $this->_patch(sprintf(self::URL_DRIVE_GET, $fileId), $query = array_merge($parameters, $requestBody)); + } + + /** + * A short description of the file. + * + * @param string + * @return this + */ + public function setDescription($description) { + //argument 1 must be a string + Eden_Google_Error::i()->argument(1, 'string'); + $this->_description = $description; + + return $this; + } + + /** + * Last time this file was viewed by the user + * (formatted RFC 3339 timestamp). + * + * @param string|int + * @return this + */ + public function setLastViewedDate($lastViewedDate) { + //argument 1 must be a string or integer + Eden_Google_Error::i()->argument(1, 'string', 'int'); + + if(is_string($lastViewedByMeDate)) { + $lastViewedByMeDate = strtotime($lastViewedByMeDate); + } + + $this->_lastViewedByMeDate['dateTime'] = date('c', $lastViewedByMeDate); + + return $this; + } + + /** + * Last time this file was modified by anyone (formatted RFC 3339 timestamp). + * This is only mutable on update when the setModifiedDate parameter is set. + * + * @param string|int + * @return this + */ + public function setModifiedDate($modifiedDate) { + //argument 1 must be a string or integer + Eden_Google_Error::i()->argument(1, 'string', 'int'); + + if(is_string($modifiedDate)) { + $modifiedDate = strtotime($modifiedDate); + } + + $this->_modifiedDate['dateTime'] = date('c', $modifiedDate); + + return $this; + } + + /** + * If ocr is true, hints at the language + * to use. Valid values are ISO 639-1 codes. + * + * @param string + * @return this + */ + public function setOcrLanguage($ocrLanguage) { + //argument 1 must be a string + Eden_Google_Error::i()->argument(1, 'string'); + $this->_ocrLanguage = $ocrLanguage; + + return $this; + } + + /** + * The language of the original file to be translated. + * + * @param string + * @return this + */ + public function setSourceLanguage($sourceLanguage) { + //argument 1 must be a string + Eden_Google_Error::i()->argument(1, 'string'); + $this->_sourceLanguage = $sourceLanguage; + + return $this; + } + + /** + * Target language to translate the + * file to. If no sourceLanguage is provided, + * the API will attempt to detect the language. + * + * @param string + * @return this + */ + public function setTargetLanguage($targetLanguage) { + //argument 1 must be a string + Eden_Google_Error::i()->argument(1, 'string'); + $this->_targetLanguage = $targetLanguage; + + return $this; + } + + /** + * The language of the timed text. + * + * @param string + * @return this + */ + public function setTimedTextLanguage($timedTextLanguage) { + //argument 1 must be a string + Eden_Google_Error::i()->argument(1, 'string'); + $this->_timedTextLanguage = $timedTextLanguageE; + + return $this; + } + + /** + * The timed text track name. + * + * @param string + * @return this + */ + public function setTimedTextTrackName($timedTextTrackName) { + //argument 1 must be a string + Eden_Google_Error::i()->argument(1, 'string'); + $this->_timedTextTrackName = $timedTextTrackName; + + return $this; + } + + /** + * The title of the this file. Used + * to identify file or folder name. + * + * @param string + * @return this + */ + public function setTitle($title) { + //argument 1 must be a string + Eden_Google_Error::i()->argument(1, 'string'); + $this->_title = $title; + + return $this; + } + + /** + * Whether to convert this file + * to the corresponding Google Docs format. + * + * @return this + */ + public function convert() { + $this->_convert = true; + + return $this; + } + + /** + * Whether a blob upload should create a new revision. + * If false, the blob data in the current head revision will be replaced. + * + * @return this + */ + public function setToNewRevision() { + $this->_newRevision = true; + + return $this; + } + + /** + * Whether to attempt OCR on .jpg, .png, or .gif uploads. + * + * @return this + */ + public function setToOcr() { + $this->_ocr = true; + + return $this; + } + + /** + * Whether to pin the head revision of the uploaded file. + * + * @return this + */ + public function setToPinned() { + $this->_pinned = true; + + return $this; + } + + /** + * Moves a file to the trash. + * + * @param string + * @return array + */ + public function trash($fileId) { + //argument 1 must be a string + Eden_Google_Error::i()->argument(1, 'string'); + + return $this->_post(sprintf(self::URL_DRIVE_TRASH, $fileId)); + } + + /** + * Set the file's updated time to the current server time + * + * @param string + * @return array + */ + public function touchFile($fileId) { + //argument 1 must be a string + Eden_Google_Error::i()->argument(1, 'string'); + + return $this->_post(sprintf(self::URL_DRIVE_TOUCH, $fileId)); + } + + /** + * Restores a file from the trash + * + * @param string + * @return array + */ + public function untrash() { + //argument 1 must be a string + Eden_Google_Error::i()->argument(1, 'string'); + + return $this->_post(sprintf(self::URL_DRIVE_UNTRASH, $fileId)); + } + + /** + * Updates file metadata and/or content. + * + * @param string + * @return array + */ + public function update($fileId) { + //argument 1 must be a string + Eden_Google_Error::i()->argument(1, 'string'); + + //populate parameters + $parameters = array( + self::CONVERT => $this->_convert, //optional + self::NEW_REVISION => $this->_newRevision, //optional + self::OCR => $this->_ocr, //optional + self::OCR_LANGUAGE => $this->_ocrLanguage, //optional + self::PINNED => $this->_pinned, //optional + self::SOURCE_LANGUAGE => $this->_sourceLanguage, //optional + self::TARGET_LANGUAGE => $this->_targetLanguage, //optional + self::TEXT_LANGUAGE => $this->_timedTextLanguage, //optional + self::TEXT_TRACKNAME => $this->_timedTextTrackName); //optional + + //populate fields + $requestBody = array ( + self::DESCRIPTION => $this->_description, //optional + self::LAST_VIEW => $this->_lastViewedByMeDate, //optional + self::MIME_TYPE => $this->_mimeType, //optional + self::MODIFIED_DATE => $this->_modifiedDate, //optional + self::TITLE => $this->_title); //optional + + return $this->_post(sprintf(self::URL_DRIVE_GET, $fileId), $query = array_merge($parameters, $requestBody)); + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/google/drive/parent.php b/library/eden/google/drive/parent.php new file mode 100644 index 0000000..fdbf506 --- /dev/null +++ b/library/eden/google/drive/parent.php @@ -0,0 +1,124 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Google Drive Parent Class + * + * @package Eden + * @category google + * @author Christian Symon M. Buenavista sbuenavista@openovate.com + */ +class Eden_Google_Drive_Parent extends Eden_Google_Base { + /* Constants + -------------------------------*/ + const URL_PARENT_LIST = 'https://www.googleapis.com/drive/v2/files/%s/parents'; + const URL_PARENT_GET = 'https://www.googleapis.com/drive/v2/files/%s/parents/%s'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + public function __construct($token) { + //argument test + Eden_Google_Error::i()->argument(1, 'string'); + $this->_token = $token; + } + + /* Public Methods + -------------------------------*/ + /** + * Removes a parent from a file. + * + * @param string + * @param string + * @return array + */ + public function delete($fileId, $parentId) { + //argument test + Eden_Google_Error::i() + ->argument(1, 'string') //argument 1 must be a string + ->argument(2, 'string'); //argument 2 must be a string + + return $this->_delete(sprintf(self::URL_PARENT_GET, $fileId, $parentId)); + } + + /** + * A link to the child. + * + * @param string + * @return this + */ + public function setChildLink($childLink) { + //argument 1 must be a string + Eden_Google_Error::i()->argument(1, 'string'); + $this->_childLink = $childLink; + + return $this; + } + + /** + * Lists a file's parents. + * + * @param string + * @return array + */ + public function getList($fileId) { + //argument 1 must be a string + Eden_Google_Error::i()->argument(1, 'string'); + + return $this->_getResponse(sprintf(self::URL_PARENT_LIST, $fileId)); + } + + /** + * Gets a specific parent reference. + * + * @param string + * @param string + * @return array + */ + public function getSpecific($fileId, $parentId) { + //argument test + Eden_Google_Error::i() + ->argument(1, 'string') //argument 1 must be a string + ->argument(2, 'string'); //argument 2 must be a string + + return $this->_getResponse(sprintf(self::URL_PARENT_GET, $fileId, $parentId)); + } + + /** + * Adds a parent folder for a file. + * + * @param string + * @param string + * @return array + */ + public function insert($fileId, $parentId) { + //argument test + Eden_Google_Error::i() + ->argument(1, 'string') //argument 1 must be a string + ->argument(2, 'string'); //argument 2 must be a string + + //populate fields + $query = array(self::ID => $parentId); + + return $this->_post(sprintf(self::URL_PARENT_LIST, $fileId), $query); + } + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/google/drive/permissions.php b/library/eden/google/drive/permissions.php new file mode 100644 index 0000000..101059b --- /dev/null +++ b/library/eden/google/drive/permissions.php @@ -0,0 +1,283 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Google Drive Permissions Class + * + * @package Eden + * @category google + * @author Christian Symon M. Buenavista sbuenavista@openovate.com + */ +class Eden_Google_Drive_Permissions extends Eden_Google_Base { + /* Constants + -------------------------------*/ + const URL_PERMISSIONS_LIST = 'https://www.googleapis.com/drive/v2/files/%s/permissions'; + const URL_PERMISSIONS_GET = 'https://www.googleapis.com/drive/v2/files/%s/permissions/%s'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_withLink = false; + protected $_id = NULL; + protected $_name = NULL; + protected $_role = NULL; + protected $_type = NULL; + protected $_value = NULL; + + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + public function __construct($token) { + //argument test + Eden_Google_Error::i()->argument(1, 'string'); + $this->_token = $token; + } + + /* Public Methods + -------------------------------*/ + /** + * Deletes a permission from a file + * + * @param string + * @param string + * @return array + */ + public function delete($fileId, $permissionId) { + //argument test + Eden_Google_Error::i() + ->argument(1, 'string') //argument 1 must be a string + ->argument(2, 'string'); //argument 1 must be a string + + return $this->_delete(sprintf(self::URL_PERMISSIONS_GET, $fileId, $permissionId)); + } + + /** + * Lists a file's permissions + * + * @param string + * @return array + */ + public function getList($fileId) { + //argument test + Eden_Google_Error::i()->argument(1, 'string'); + + return $this->_getResponse(sprintf(self::URL_PERMISSIONS_LIST, $fileId)); + } + + /** + * Gets a permission by ID + * + * @param string + * @param string + * @return array + */ + public function getSpecific($fileId, $permissionId) { + //argument test + Eden_Google_Error::i() + ->argument(1, 'string') //argument 1 must be a string + ->argument(2, 'string'); //argument 2 must be a string + + return $this->_getResponse(sprintf(self::URL_PERMISSIONS_GET, $fileId, $permissionId)); + } + + /** + * Inserts a permission for a file + * + * @param string + * @param string The primary role for this user + * @param string The account type + * @param string The email address or domain name for the entity + * @return array + */ + public function insert($fileId, $role, $type, $value = 'me') { + //argument test + Eden_Google_Error::i() + ->argument(1, 'string') //argument 1 must be a string + ->argument(2, 'string') //argument 2 must be a string + ->argument(3, 'string') //argument 3 must be a string + ->argument(4, 'string'); //argument 4 must be a string + + //if the input value is not allowed + if(!in_array($role, array('owner', 'reader', 'writer'))) { + //throw error + Eden_Google_Error::i() + ->setMessage(Eden_Google_Error::INVALID_ROLE) + ->addVariable($role) + ->trigger(); + } + + //if the input value is not allowed + if(!in_array($type, array('user', 'group', 'domain', 'anyone'))) { + //throw error + Eden_Google_Error::i() + ->setMessage(Eden_Google_Error::INVALID_TYPE) + ->addVariable($type) + ->trigger(); + } + + //populate fields + $query = array( + self::VALUE => $value, + self::ROLE => $role, + self::TYPE => $type, + self::NAME => $this->_name, //optional + self::WITH_LINK => $this->_withLink); //optional + + return $this->_post(sprintf(self::URL_PERMISSIONS_LIST, $fileId), $query); + } + + /** + * Updates a permission. This method supports patch semantics. + * + * @param string + * @param string + * @return array + */ + public function patch($fileId, $permissionId) { + //argument test + Eden_Google_Error::i() + ->argument(1, 'string') //argument 1 must be a string + ->argument(2, 'string'); //argument 2 must be a string + + //populate fields + $query = array( + self::NAME => $this->_name, //optional + self::ROLE => $this->_role, //optional + self::TYPE => $this->_type, //optional + self::WITH_LINK => $this->_withLink, //optional + self::VALUE => $this->_value); //optional + + return $this->_patch(sprintf(self::URL_PERMISSIONS_GET, $fileId, $permissionId), $query); + } + + /** + * The ID of the child. + * + * @param string + * @return this + */ + public function setId($id) { + //argument 1 must be a string + Eden_Google_Error::i()->argument(1, 'string'); + $this->_id = $id; + + return $this; + } + + /** + * The name for this permission. + * + * @param string + * @return this + */ + public function setName($name) { + //argument 1 must be a string + Eden_Google_Error::i()->argument(1, 'string'); + $this->_name = $name; + + return $this; + } + + /** + * The primary role for this user + * Allowed values are: + * - owner + * - reader + * - writer + * + * @param string + * @return this + */ + public function setRole($role) { + //argument 1 must be a string + Eden_Google_Error::i()->argument(1, 'string'); + $this->_role = $role; + + return $this; + } + + /** + * Allowed values are: + * - user + * - group + * - domain + * - anyone + * + * @param string + * @return this + */ + public function setType($type) { + //argument 1 must be a string + Eden_Google_Error::i()->argument(1, 'string'); + $this->_type = $type; + + return $this; + } + + /** + * The email address or domain name for the + * entity. This is not populated in responses. + * + * @param string + * @return this + */ + public function setValue($value) { + //argument 1 must be a string + Eden_Google_Error::i()->argument(1, 'string'); + $this->_value = $value; + + return $this; + } + + /** + * WWhether the link is required for this permission. + * + * @return this + */ + public function setWithLink() { + $this->_withLink = true; + + return $this; + } + + /** + * Updates a permission. + * + * @param string + * @param string + * @return array + */ + public function update($fileId, $permissionId) { + //argument test + Eden_Google_Error::i() + ->argument(1, 'string') //argument 1 must be a string + ->argument(2, 'string'); //argument 2 must be a string + + //populate fields + $query = array( + self::NAME => $this->_name, //optional + self::ROLE => $this->_role, //optional + self::TYPE => $this->_type, //optional + self::WITH_LINK => $this->_withLink, //optional + self::VALUE => $this->_value); //optional + + return $this->_put(sprintf(self::URL_PERMISSIONS_GET, $fileId, $permissionId), $query); + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/google/drive/revisions.php b/library/eden/google/drive/revisions.php new file mode 100644 index 0000000..aac27c1 --- /dev/null +++ b/library/eden/google/drive/revisions.php @@ -0,0 +1,204 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Google Drive Revisions Class + * + * @package Eden + * @category google + * @author Christian Symon M. Buenavista sbuenavista@openovate.com + */ +class Eden_Google_Drive_Revisions extends Eden_Google_Base { + /* Constants + -------------------------------*/ + const URL_REVISIONS_LIST = 'https://www.googleapis.com/drive/v2/files/%s/revisions'; + const URL_REVISIONS_GET = 'https://www.googleapis.com/drive/v2/files/%s/revisions/%s'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_pinned = false; + protected $_publishAuto = false; + protected $_publishedOutsideDomain = false; + protected $_published = NULL; + + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + public function __construct($token) { + //argument test + Eden_Google_Error::i()->argument(1, 'string'); + $this->_token = $token; + } + + /* Public Methods + -------------------------------*/ + /** + * Removes a revision + * + * @param string + * @param string + * @return array + */ + public function delete($fileId, $revisionId) { + //argument test + Eden_Google_Error::i() + ->argument(1, 'string') //argument 1 must be a string + ->argument(2, 'string'); //argument 2 must be a string + + return $this->_delete(sprintf(self::URL_REVISIONS_GET, $fileId, $revisionId)); + } + + /** + * Lists a file's revisions + * + * @param string + * @return array + */ + public function getList($fileId) { + //argument test + Eden_Google_Error::i()->argument(1, 'string'); + + return $this->_getResponse(sprintf(self::URL_REVISIONS_LIST, $fileId)); + } + + /** + * Gets a specific revision + * + * @param string + * @param string + * @return array + */ + public function getSpecific($fileId, $revisionId) { + //argument test + Eden_Google_Error::i() + ->argument(1, 'string') //argument 1 must be a string + ->argument(2, 'string'); //argument 2 must be a string + + return $this->_getResponse(sprintf(self::URL_REVISIONS_GET, $fileId, $revisionId)); + } + + /** + * Updates a revision. This method supports patch semantics + * + * @param string + * @param string + * @return array + */ + public function patch($fileId, $revisionId) { + //argument test + Eden_Google_Error::i() + ->argument(1, 'string') //argument 1 must be a string + ->argument(2, 'string'); //argument 2 must be a string + + //populate fields + $query = array( + self::PINNED => $this->_pinned, //optional + self::PUBLISHED => $this->_published, //optional + self::PUBLISHED_LINK => $this->_publishedLink, //optional + self::PUBLISHED_AUTO => $this->_publishAuto, //optional + self::OUTSIDE_DOMAIN => $this->_publishedOutsideDomain); //optional + + return $this->_patch(sprintf(self::URL_PERMISSIONS_GET, $fileId, $revisionId), $query); + } + + /** + * Whether this revision is pinned to prevent automatic purging. + * This will only be populated on files with content stored in Drive. + * + * @return this + */ + public function setPinned() { + $this->_pinned = true; + + return $this; + } + + /** + * Whether subsequent revisions will be automatically republished. + * + * @return this + */ + public function setPublishAuto() { + $this->_publishAuto = true; + + return $this; + } + + /** + * Whether this revision is published. This is only populated for Google Docs. + * + * @return this + */ + public function setPublished() { + $this->_published = true; + + return $this; + } + + /** + * A link to the published revision. + * + * @param string + * @return this + */ + public function setPublishedLink($publishedLink) { + //argument 1 must be a string + Eden_Google_Error::i()->argument(1, 'string'); + $this->_publishedLink = $publishedLink; + + return $this; + } + + /** + * Whether this revision is published outside the domain. + * + * @return this + */ + public function setPublishedOutsideDomain() { + $this->_publishedOutsideDomain = true; + + return $this; + } + + /** + * Updates a revision. + * + * @param string + * @param string + * @return array + */ + public function update($fileId, $revisionId) { + //argument test + Eden_Google_Error::i() + ->argument(1, 'string') //argument 1 must be a string + ->argument(2, 'string'); //argument 2 must be a string + + //populate fields + $query = array( + self::PINNED => $this->_pinned, //optional + self::PUBLISHED => $this->_published, //optional + self::PUBLISHED_LINK => $this->_publishedLink, //optional + self::PUBLISHED_AUTO => $this->_publishAuto, //optional + self::OUTSIDE_DOMAIN => $this->_publishedOutsideDomain); //optional + + return $this->_put(sprintf(self::URL_PERMISSIONS_GET, $fileId, $revisionId), $query); + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/google/error.php b/library/eden/google/error.php new file mode 100644 index 0000000..da18231 --- /dev/null +++ b/library/eden/google/error.php @@ -0,0 +1,46 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Google Errors + * + * @package Eden + * @category google + * @author Christian Blanquera cblanquera@openovate.com + */ +class Eden_Google_Error extends Eden_Error { + /* Constants + -------------------------------*/ + const INVALID_ROLE = 'Argument 2 was expecting owner, reader, writer. %s was given'; + const INVALID_TYPE = 'Argument 3 was expecting user, group, domain, anyone. %s was given'; + const INVALID_COLLECTION = 'Argument 2 was expecting plusoners, resharers. %s was given'; + const INVALID_FEEDS_TWO = 'Argument 2 was expecting most_viewed, most_subscribed. %s was given'; + const INVALID_FEEDS_ONE = 'Argument 1 was expecting most_viewed, most_subscribed. %s was given'; + const INVALID_STATUS = 'Argument 2 was expecting accepted, rejected. %s was given'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i($message = NULL, $code = 0) { + $class = __CLASS__; + return new $class($message, $code); + } + + /* Public Methods + -------------------------------*/ + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/google/maps.php b/library/eden/google/maps.php new file mode 100644 index 0000000..df9450d --- /dev/null +++ b/library/eden/google/maps.php @@ -0,0 +1,94 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Google Maps + * + * @package Eden + * @category google + * @author Christian Symon M. Buenavista sbuenavista@openovate.com + */ +class Eden_Google_Maps extends Eden_Google_Base { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + public function __construct($token) { + //argument test + Eden_Google_Error::i()->argument(1, 'string'); + $this->_token = $token; + } + + /* Public Methods + -------------------------------*/ + /** + * Returns Google maps direction + * + * @return Eden_Google_Maps_Direction + */ + public function direction() { + + return Eden_Google_Maps_Direction::i($this->_token); + } + + /** + * Returns Google maps distance + * + * @return Eden_Google_Maps_Distance + */ + public function distance() { + + return Eden_Google_Maps_Distance::i($this->_token); + } + + /** + * Returns Google maps elevation + * + * @return Eden_Google_Maps_Elevation + */ + public function elevation() { + + return Eden_Google_Maps_Elevation::i($this->_token); + } + + /** + * Returns Google maps geocoding + * + * @return Eden_Google_Maps_Geocoding + */ + public function geocoding() { + + return Eden_Google_Maps_Geocoding::i($this->_token); + } + + /** + * Returns Google maps image + * + * @return Eden_Google_Maps_Image + */ + public function image() { + + return Eden_Google_Maps_Image::i($this->_token); + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/google/maps/direction.php b/library/eden/google/maps/direction.php new file mode 100644 index 0000000..a004d65 --- /dev/null +++ b/library/eden/google/maps/direction.php @@ -0,0 +1,254 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Google Map Direction Class + * + * @package Eden + * @category google + * @author Christian Symon M. Buenavista sbuenavista@openovate.com + */ +class Eden_Google_Maps_Direction extends Eden_Google_Base { + /* Constants + -------------------------------*/ + const URL_MAP_DIRECTION = 'http://maps.googleapis.com/maps/api/directions/json'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_apiKey = NULL; + protected $_samples = NULL; + protected $_mode = NULL; + protected $_language = NULL; + protected $_avoid = NULL; + protected $_units = NULL; + protected $_waypoints = NULL; + protected $_alternatives = NULL; + protected $_departureTime = NULL; + protected $_arrivalTime = NULL; + protected $_region = NULL; + + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + /* Public Methods + -------------------------------*/ + /** + * Set Distance to avoid highways + * + * @return this + */ + public function avoidHighways() { + $this->_avoid = 'highways'; + return $this; + } + + /** + * Set Distance to avoid tolls + * + * @return this + */ + public function avoidTolls() { + $this->_avoid = 'tolls'; + return $this; + } + + /** + * Specifies the mode of transport to use when + * calculating directions is bicycling. + * + * @return this + */ + public function bicycling() { + $this->_mode = 'bicycling'; + return $this; + } + + /** + * Specifies the mode of transport to use when + * calculating directions is driving. + * + * @return this + */ + public function driving() { + $this->_mode = 'driving'; + return $this; + } + + /** + * Requests directions via public transit + * routes. Both arrivalTime and departureTime are + * only valid when mode is set to "transit". + * + * @return this + */ + public function transit() { + $this->_mode = 'transit'; + return $this; + } + + /** + * Specifies the mode of transport to use when + * calculating directions is walking. + * + * @return this + */ + public function walking() { + $this->_mode = 'walking'; + return $this; + } + + /** + * The language in which to return results. + * + * @param string|integer + * @return this + */ + public function setLanguage($language) { + //argument 1 must be a string or integer + Eden_Google_Error::i()->argument(1, 'string', 'int'); + + $this->_language = $language; + + return $this; + } + + /** + * Waypoints alter a route by routing it through the specified location(s) + * + * @param string|integer + * @return this + */ + public function setWaypoints($waypoint) { + //argument 1 must be a string or integer + Eden_Google_Error::i()->argument(1, 'string', 'int'); + + $this->_waypoint = $waypoint; + + return $this; + } + + /** + * The region code + * + * @param string|integer + * @return this + */ + public function setRegion($region) { + //argument 1 must be a string or integer + Eden_Google_Error::i()->argument(1, 'string', 'int'); + + $this->_region = $region; + + return $this; + } + + /** + * Returns distances in miles and feet. + * + * @return this + */ + public function setUnitToImperial() { + $this->_units = 'imperial'; + return $this; + } + + /** + * Specifies that the Directions service may + * provide more than one route alternative in the response. + * + * @return this + */ + public function setAlternatives() { + $this->_alternatives = 'true'; + return $this; + } + + /** + * Specifies the desired time of departure for transit directions as seconds + * -timespamp + * + * @param string|int + * @return this + */ + public function setDepartureTime($departureTime) { + //argument 1 must be a string or integer + Eden_Google_Error::i()->argument(1, 'string', 'int'); + + if(is_string($departureTime)) { + $departureTime = strtotime($departureTime); + } + + $this->_departureTime = $departureTime; + + return $this; + } + + /** + * specifies the desired time of arrival for transit directions as seconds + * -timespamp + * + * @param string|int + * @return this + */ + public function setArrivalTime($arrivalTime) { + //argument 1 must be a string or integer + Eden_Google_Error::i()->argument(1, 'string', 'int'); + + if(is_string($arrivalTime)) { + $arrivalTime = strtotime($arrivalTime); + } + + $this->_arrivalTime = $arrivalTime; + + return $this; + } + + /** + * Returns calculated directions between locations + * + * @param string|integer|float The address or textual latitude/longitude value from which you wish to calculate directions + * @param string|integer|float The address or textual latitude/longitude value from which you wish to calculate directions + * @param booelean Indicates whether or not the directions request comes from a device with a location sensor + * @return array + */ + public function getResponse($origin, $destination, $sensor = 'false') { + //argument test + Eden_Google_Error::i() + ->argument(1, 'string', 'int', 'float') //argument 1 must be a string, integer or float + ->argument(2, 'string', 'int', 'float') //argument 2 must be a string, integer or float + ->argument(3, 'string'); //argument 3 must be a string + + //populate paramenter + $query = array( + 'origin' => $origin, + 'sensor' => $sensor, + 'destination' => $destination, + 'alternatives' => $this->_alternatives, //optional + 'region' => $this->_region, //optional + 'departureTime' => $this->_departureTime, //optional + 'arrivalTime' => $this->_arrivalTime, //optional + 'language' => $this->_language, //optional + 'avoid' => $this->_avoid, //optional + 'units' => $this->_units); //optional + + + return $this->_getResponse(self::URL_MAP_DIRECTION, $query); + } + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/google/maps/distance.php b/library/eden/google/maps/distance.php new file mode 100644 index 0000000..23d8374 --- /dev/null +++ b/library/eden/google/maps/distance.php @@ -0,0 +1,152 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Google Map distance Class + * + * @package Eden + * @category google + * @author Christian Symon M. Buenavista sbuenavista@openovate.com + */ +class Eden_Google_Maps_Distance extends Eden_Google_Base { + /* Constants + -------------------------------*/ + const URL_MAP_DISTANCE = 'http://maps.googleapis.com/maps/api/distancematrix/json'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_apiKey = NULL; + protected $_mode = NULL; + protected $_language = NULL; + protected $_avoid = NULL; + protected $_units = NULL; + + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + /* Public Methods + -------------------------------*/ + /** + * Set Distance to avoid highways + * + * @return this + */ + public function avoidHighways() { + $this->_avoid = 'highways'; + return $this; + } + + /** + * Set Distance to avoid tolls + * + * @return this + */ + public function avoidTolls() { + $this->_avoid = 'tolls'; + return $this; + } + + /** + * Specifies the mode of transport to use when + * calculating directions is bicycling. + * + * @return this + */ + public function bicycling() { + $this->_mode = 'bicycling'; + return $this; + } + + /** + * Specifies the mode of transport to use when + * calculating directions is driving. + * + * @return this + */ + public function driving() { + $this->_mode = 'driving'; + return $this; + } + + /** + * Specifies the mode of transport to use when + * calculating directions is walking. + * + * @return this + */ + public function walking() { + $this->_mode = 'walking'; + return $this; + } + + /** + * The language in which to return results. + * + * @param string|integer + * @return this + */ + public function setLanguage($language) { + //argument 1 must be a string or integer + Eden_Google_Error::i()->argument(1, 'string', 'int'); + + $this->_language = $language; + + return $this; + } + + /** + * Returns distances in miles and feet. + * + * @return this + */ + public function setUnitToImperial() { + $this->_units = 'imperial'; + + return $this; + } + + /** + * Returns travel distance and time for a matrix of origins and destinations + * + * @param string|integer|float + * @param string|integer|float + * @param string + * @return array + */ + public function getResponse($origin, $destination, $sensor = 'false') { + //argument test + Eden_Google_Error::i() + ->argument(1, 'string', 'int', 'float') //argument 1 must be a string, integer or float + ->argument(2, 'string', 'int', 'float') //argument 2 must be a string, integer or float + ->argument(3, 'string'); //argument 3 must be a string + + //populate paramenter + $query = array( + 'origins' => $origin, + 'sensor' => $sensor, + 'destinations' => $destination, + 'language' => $this->_language, //optional + 'avoid' => $this->_avoid, //optional + 'mode' => $this->_mode, //optional + 'units' => $this->_units); //optional + + return $this->_getResponse(self::URL_MAP_DISTANCE, $query); + } + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/google/maps/elevation.php b/library/eden/google/maps/elevation.php new file mode 100644 index 0000000..2cf722a --- /dev/null +++ b/library/eden/google/maps/elevation.php @@ -0,0 +1,99 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Google Map Static Class + * + * @package Eden + * @category google + * @author Christian Symon M. Buenavista sbuenavista@openovate.com + */ +class Eden_Google_Maps_Elevation extends Eden_Google_Base { + /* Constants + -------------------------------*/ + const URL_MAP_ELEVATION = 'http://maps.googleapis.com/maps/api/elevation/json'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_apiKey = NULL; + protected $_path = NULL; + protected $_samples = NULL; + + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + /* Public Methods + -------------------------------*/ + /** + * Defines a path on the earth for which to return elevation data. + * + * @param string|int|float + * @param string|int|float + * @return this + */ + public function setPath($latitude, $longtitude) { + //argument testing + Eden_Google_Error::i() + ->argument(1, 'string', 'int', 'float') //argument 1 must be a string, integer or float + ->argument(2, 'string', 'int', 'float'); //argument 2 must be a string, integer or float + + $this->_path = $latitude.', '.$longtitude; + + return $this; + } + + /** + * Specifies the number of sample points along a + * path for which to return elevation data. + * + * @param string|integer + * @return this + */ + public function setSamples($samples) { + //argument 1 must be a string or integer + Eden_Google_Error::i()->argument(1, 'string', 'int'); + + $this->_samples = $samples; + + return $this; + } + + /** + * Returns elevation information + * + * @param string latitude,longitude pair in string(e.g. "40.714728,-73.998672") + * @return array + */ + public function getResponse($location, $sensor = 'false') { + //argument test + Eden_Google_Error::i() + ->argument(1, 'string') //argument 1 must be a string + ->argument(2, 'string'); //argument 2 must be a string + + //populate paramenter + $query = array( + 'locations' => $ocation, + 'sensor' => $sensor, + 'path' => $this->_path, //optional + 'samples' => $this->_samples); //optional + + return $this->_getResponse(self::URL_MAP_ELEVATION, $query); + } + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/google/maps/geocoding.php b/library/eden/google/maps/geocoding.php new file mode 100644 index 0000000..7be2a16 --- /dev/null +++ b/library/eden/google/maps/geocoding.php @@ -0,0 +1,132 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Google Map geocoding Class + * + * @package Eden + * @category google + * @author Christian Symon M. Buenavista sbuenavista@openovate.com + */ +class Eden_Google_Maps_Geocoding extends Eden_Google_Base { + /* Constants + -------------------------------*/ + const URL_MAP_GEOCODING = 'http://maps.googleapis.com/maps/api/geocode/json'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_apiKey = NULL; + protected $_latlng = NULL; + protected $_bounds = NULL; + protected $_language = NULL; + protected $_region = NULL; + + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + /* Public Methods + -------------------------------*/ + /** + * The textual latitude/longitude value for which you wish to obtain the closest. + * + * @param string|int|float + * @param string|int|float + * @return this + */ + public function setLocation($latitude, $longtitude) { + //argument testing + Eden_Google_Error::i() + ->argument(1, 'string', 'int', 'float') //argument 1 must be a string, integer or float + ->argument(2, 'string', 'int', 'float'); //argument 2 must be a string, integer or float + + $this->_latlng = $latitude.','.$longtitude; + + return $this; + } + + /** + * The bounding box of the viewport within which to bias geocode results more prominently. + * + * @param string + * @return this + */ + public function setBounds($bounds) { + //argument 1 must be a string + Eden_Google_Error::i()->argument(1, 'string'); + + $this->_bounds = $bounds; + + return $this; + } + + /** + * The language in which to return results. + * + * @param string + * @return this + */ + public function setLanguage($language) { + //argument 1 must be a string + Eden_Google_Error::i()->argument(1, 'string'); + + $this->_language = $language; + + return $this; + } + + /** + * The region code + * + * @param string + * @return this + */ + public function setRegion($region) { + //argument 1 must be a string + Eden_Google_Error::i()->argument(1, 'string'); + + $this->_region = $region; + + return $this; + } + + /** + * Returns geocode information + * + * @param string + * @param string + * @return array + */ + public function getResponse($address, $sensor = 'false') { + //argument test + Eden_Google_Error::i() + ->argument(1, 'string') //argument 1 must be a string + ->argument(2, 'string'); //argument 2 must be a string + + //populate paramenter + $query = array( + 'address' => $address, + 'sensor' => $sensor, + 'bounds' => $this->_bounds, //optional + 'language' => $this->_language, //optional + 'region' => $this->_region); //optional + + return $this->_getResponse(self::URL_MAP_GEOCODING, $query); + } + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/google/maps/image.php b/library/eden/google/maps/image.php new file mode 100644 index 0000000..8b6e033 --- /dev/null +++ b/library/eden/google/maps/image.php @@ -0,0 +1,350 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Google Map Static Class + * + * @package Eden + * @category google + * @author Christian Symon M. Buenavista sbuenavista@openovate.com + */ +class Eden_Google_Maps_Image extends Eden_Google_Base { + /* Constants + -------------------------------*/ + const URL_MAP_IMAGE_STATIC = 'http://maps.googleapis.com/maps/api/staticmap'; + const URL_MAP_IMAGE_STREET = 'http://maps.googleapis.com/maps/api/streetview'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_apiKey = NULL; + protected $_scale = NULL; + protected $_format = NULL; + protected $_maptype = NULL; + protected $_language = NULL; + protected $_region = NULL; + protected $_markers = NULL; + protected $_path = NULL; + protected $_visible = NULL; + protected $_style = NULL; + protected $_heading = NULL; + protected $_fov = NULL; + protected $_pitch = NULL; + + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + public function __construct($apiKey) { + //argument test + Eden_Google_Error::i()->argument(1, 'string'); + $this->_apiKey = $apiKey; + } + + /* Public Methods + -------------------------------*/ + /** + * Affects the number of pixels that are returned. + * + * @param integer + * @return this + */ + public function setScale($scale) { + //argument 1 must be a integer + Eden_Google_Error::i()->argument(1, 'int'); + + $this->_scale = $scale; + + return $this; + } + + /** + * Defines the format of the resulting image. + * By default, the Static Maps API creates PNG images. + * + * @param string + * @return this + */ + public function setFormat($format) { + //argument 1 must be a string + Eden_Google_Error::i()->argument(1, 'string'); + + $this->_format = $format; + + return $this; + } + + /** + * Defines the language to use for display of labels on map tiles + * + * @param string + * @return this + */ + public function setLanguage($language) { + //argument 1 must be a string + Eden_Google_Error::i()->argument(1, 'string'); + + $this->_language = $language; + + return $this; + } + + /** + * Defines the appropriate borders to display, + * based on geo-political sensitivities. + * + * @param string + * @return this + */ + public function setRegion($region) { + //argument 1 must be a string + Eden_Google_Error::i()->argument(1, 'string'); + + $this->_region = $region; + + return $this; + } + + /** + * Define one or more markers to attach to the image at + * specified locations. + * + * @param string + * @return this + */ + public function setMarkers($markers) { + //argument 1 must be a string + Eden_Google_Error::i()->argument(1, 'string'); + + $this->_markers = $markers; + + return $this; + } + + /** + * Defines a single path of two or more connected points + * to overlay on the image at specified locations. + * + * @param string + * @return this + */ + public function setPath($path) { + //argument 1 must be a string + Eden_Google_Error::i()->argument(1, 'string'); + + $this->_path = $path; + + return $this; + } + + /** + * Specifies one or more locations that should remain + * visible on the map, though no markers or other + * indicators will be displayed. + * + * @param string + * @return this + */ + public function setVisible($visible) { + //argument 1 must be a string + Eden_Google_Error::i()->argument(1, 'string'); + + $this->_visible = $visible; + + return $this; + } + + /** + * Defines a custom style to alter the presentation of a + * specific feature (road, park, etc.) of the map. + * + * @param string + * @return this + */ + public function setStyle($style) { + //argument 1 must be a string + Eden_Google_Error::i()->argument(1, 'string'); + + $this->_style = $style; + + return $this; + } + + /** + * Indicates the compass heading of the camera. + * Accepted values are from 0 to 360 (both values + * indicating North, with 90 indicating East, and 180 South). + * + * @param integer + * @return this + */ + public function setHeading($heading) { + //argument 1 must be a integer + Eden_Google_Error::i()->argument(1, 'int'); + + $this->_heading = $heading; + + return $this; + } + + /** + * Determines the horizontal field of view of the image. + * The field of view is expressed in degrees, with a + * maximum allowed value of 120. + * + * @param integer + * @return this + */ + public function setFov($fov) { + //argument 1 must be a integer + Eden_Google_Error::i()->argument(1, 'int'); + + $this->_fov = $fov; + + return $this; + } + + /** + * specifies the up or down angle of the camera relative + * to the Street View vehicle. + * + * @param integer + * @return this + */ + public function setPitch($pitch) { + //argument 1 must be a integer + Eden_Google_Error::i()->argument(1, 'int'); + + $this->_pitch = $pitch; + + return $this; + } + + /** + * Specifies a standard roadmap image, as is normally + * shown on the Google Maps website. If no maptype + * value is specified, the Static Maps API serves + * roadmap tiles by default. + * + * @return this + */ + public function useRoadMap() { + $this->_maptype = 'roadmap'; + + return $this; + } + + /** + * Specifies a satellite image + * + * @return this + */ + public function useSatelliteMap() { + $this->_maptype = 'satellite'; + + return $this; + } + + /** + * Specifies a physical relief map image, + * showing terrain and vegetation. + * + * @return this + */ + public function useTerrainMap() { + $this->_maptype = 'terrain'; + + return $this; + } + + /** + * Specifies a hybrid of the satellite and + * roadmap image, showing a transparent layer + * of major streets and place names on the satellite image. + * + * @return this + */ + public function useHybridMap() { + $this->_maptype = 'hybrid'; + + return $this; + } + + /** + * Return url of the image map + * + * @param string Defines the center of the map, latitude,longitude pai or address pair + * @param string Defines the zoom level of the map, which determines the magnification level of the map + * @param string This parameter takes a string of the form {horizontal_value}x{vertical_value} + * @param string + * @return url + */ + public function getStaticMap($center, $zoom, $size, $sensor = 'false') { + //argument test + Eden_Google_Error::i() + ->argument(1, 'string') //argument 1 must be a string + ->argument(2, 'string') //argument 2 must be a string + ->argument(3, 'string') //argument 3 must be a string + ->argument(4, 'string'); //argument 4 must be a string + + //populate fields + $query = array( + 'center' => $center, + 'zoom' => $zoom, + 'size' => $size, + 'sensor' => $sensor, + 'scale' => $this->_scale, //optional + 'format' => $this->_format, //optional + 'maptype' => $this->_maptype, //optional + 'language' => $this->_language, //optional + 'region' => $this->_region, //optional + 'markers' => $this->_markers, //optional + 'path' => $this->_path, //optional + 'visible' => $this->_visible, //optional + 'style' => $this->_style); //optional + + return $this->_getResponse(self::URL_MAP_IMAGE_STATIC, $query); + } + + /** + * Return url of the street map + * + * @param string Latitude,longitude pai or address pair + * @param string Size is specified as {width}x{height} + * @param string + * @return url + */ + public function getStreetMap($location, $size, $sensor = 'false') { + //argument test + Eden_Google_Error::i() + ->argument(1, 'string') //argument 1 must be a string + ->argument(2, 'string') //argument 2 must be a string + ->argument(3, 'string'); //argument 3 must be a string + + //populate paramenter + $query = array( + 'size' => $size, + 'location' => $location, + 'sensor' => $sensor, + 'heading' => $this->_heading, //optional + 'fov' => $this->_fov, //optional + 'pitch' => $this->_pitch); //optional + + return $this->_getResponse(self::URL_MAP_IMAGE_STREET, $query); + } + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/google/oauth.php b/library/eden/google/oauth.php new file mode 100644 index 0000000..1214499 --- /dev/null +++ b/library/eden/google/oauth.php @@ -0,0 +1,146 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Google oauth + * + * @package Eden + * @category google + * @author Christian Blanquera cblanquera@openovate.com + * @author Christian Symon M. Buenavista sbuenavista@openovate.com + */ +class Eden_Google_Oauth extends Eden_Oauth2_Client { + /* Constants + -------------------------------*/ + const REQUEST_URL = 'https://accounts.google.com/o/oauth2/auth'; + const ACCESS_URL = 'https://accounts.google.com/o/oauth2/token'; + + const SCOPE_ANALYTICS = 'https://www.googleapis.com/auth/analytics.readonly'; + const SCOPE_BASE = 'https://www.google.com/base/feeds/'; + const SCOPE_BUZZ = 'https://www.googleapis.com/auth/buzz'; + const SCOPE_BOOK = 'https://www.google.com/books/feeds/'; + const SCOPE_BLOGGER = 'https://www.blogger.com/feeds/'; + const SCOPE_CALENDAR = 'https://www.google.com/calendar/feeds/'; + const SCOPE_CONTACTS = 'https://www.google.com/m8/feeds/'; + const SCOPE_CHROME = 'https://www.googleapis.com/auth/chromewebstore.readonly'; + const SCOPE_DOCUMENTS = 'https://docs.google.com/feeds/'; + const SCOPE_DRIVE = 'https://www.googleapis.com/auth/drive'; + const SCOPE_FINANCE = 'https://finance.google.com/finance/feeds/'; + const SCOPE_GMAIL = 'https://mail.google.com/mail/feed/atom'; + const SCOPE_HEALTH = 'https://www.google.com/health/feeds/'; + const SCOPE_H9 = 'https://www.google.com/h9/feeds/'; + const SCOPE_MAPS = 'https://maps.google.com/maps/feeds/'; + const SCOPE_MODERATOR = 'https://www.googleapis.com/auth/moderator'; + const SCOPE_OPENSOCIAL = 'https://www-opensocial.googleusercontent.com/api/people/'; + const SCOPE_ORKUT = 'https://www.googleapis.com/auth/orkut'; + const SCOPE_PLUS = 'https://www.googleapis.com/auth/plus.me'; + const SCOPE_PICASA = 'https://picasaweb.google.com/data/'; + const SCOPE_SIDEWIKI = 'https://www.google.com/sidewiki/feeds/'; + const SCOPE_SITES = 'https://sites.google.com/feeds/'; + const SCOPE_SREADSHEETS = 'https://spreadsheets.google.com/feeds/'; + const SCOPE_TASKS = 'https://www.googleapis.com/auth/tasks'; + const SCOPE_SHORTENER = 'https://www.googleapis.com/auth/urlshortener'; + const SCOPE_WAVE = 'http://wave.googleusercontent.com/api/rpc'; + const SCOPE_WEBMASTER = 'https://www.google.com/webmasters/tools/feeds/'; + const SCOPE_YOUTUBE = 'https://gdata.youtube.com'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_apiKey = NULL; + protected $_scopes = array( + 'analytics' => self::SCOPE_ANALYTICS, + 'base' => self::SCOPE_BASE, + 'buzz' => self::SCOPE_BUZZ, + 'book' => self::SCOPE_BOOK, + 'blogger' => self::SCOPE_BLOGGER, + 'calendar' => self::SCOPE_CALENDAR, + 'contacts' => self::SCOPE_CONTACTS, + 'chrome' => self::SCOPE_CHROME, + 'documents' => self::SCOPE_DOCUMENTS, + 'drive' => self::SCOPE_DRIVE, + 'finance' => self::SCOPE_FINANCE, + 'gmail' => self::SCOPE_GMAIL, + 'health' => self::SCOPE_HEALTH, + 'h9' => self::SCOPE_H9, + 'maps' => self::SCOPE_MAPS, + 'moderator' => self::SCOPE_MODERATOR, + 'opensocial' => self::SCOPE_OPENSOCIAL, + 'orkut' => self::SCOPE_ORKUT, + 'plus' => self::SCOPE_PLUS, + 'picasa' => self::SCOPE_PICASA, + 'sidewiki' => self::SCOPE_SIDEWIKI, + 'sites' => self::SCOPE_SITES, + 'spreadsheets' => self::SCOPE_SREADSHEETS, + 'tasks' => self::SCOPE_TASKS, + 'shortener' => self::SCOPE_SHORTENER, + 'wave' => self::SCOPE_WAVE, + 'webmaster' => self::SCOPE_WEBMASTER, + 'youtube' => self::SCOPE_YOUTUBE); + + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + public function __construct($clientId, $clientSecret, $redirect, $apiKey = NULL) { + //argument test + Eden_Google_Error::i() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'string') //Argument 2 must be a string + ->argument(3, 'string') //Argument 3 must be a string + ->argument(4, 'string', 'null'); //Argument 4 must be a string or null + + $this->_apiKey = $apiKey; + + parent::__construct($clientId, $clientSecret, $redirect, self::REQUEST_URL, self::ACCESS_URL); + } + + /* Public Methods + -------------------------------*/ + /** + * Returns website login url + * + * @param string|null + * @param string|null + * @return url + */ + public function getLoginUrl($scope = NULL, $display = NULL) { + //argument test + Eden_Google_Error::i() + ->argument(1, 'string', 'array', 'null') //argument 1 must be a string, array or null + ->argument(2, 'string', 'array', 'null'); //argument 2 must be a string, array or null + + //if scope is a key in the scopes array + if(is_string($scope) && isset($this->_scopes[$scope])) { + $scope = $this->_scopes[$scope]; + //if it's an array + } else if(is_array($scope)) { + //loop through it + foreach($scope as $i => $key) { + //if this is a scope key + if(is_string($key) && isset($this->_scopes[$key])) { + //change it + $scope[$i] = $this->_scopes[$key]; + } + } + } + + return parent::getLoginUrl($scope, $display); + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/google/plus.php b/library/eden/google/plus.php new file mode 100644 index 0000000..f654562 --- /dev/null +++ b/library/eden/google/plus.php @@ -0,0 +1,74 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Google Plus + * + * @package Eden + * @category google + * @author Clark Galgo cgalgo@openovate.com + */ +class Eden_Google_Plus extends Eden_Google_Base { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + public function __construct($token) { + //argument test + Eden_Google_Error::i()->argument(1, 'string'); + $this->_token = $token; + } + + /* Public Methods + -------------------------------*/ + /** + * Factory method for Eden_Google_Plus_Activity Class + * + * @return Eden_Google_Plus_Activity + */ + public function activity() { + + return Eden_Google_Plus_Activity::i($this->_token); + } + + /** + * Factory method for Eden_Google_Plus_Activity Class + * + * @return Eden_Google_Plus_Activity + */ + public function comment() { + + return Eden_Google_Plus_Comment::i($this->_token); + } + + /** + * Factory method for Eden_Google_Plus_People Class + * + * @return Eden_Google_Plus_People + */ + public function people() { + + return Eden_Google_Plus_People::i($this->_token); + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/google/plus/activity.php b/library/eden/google/plus/activity.php new file mode 100644 index 0000000..f833273 --- /dev/null +++ b/library/eden/google/plus/activity.php @@ -0,0 +1,154 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Google Plus activity + * + * @package Eden + * @category google + * @author Clark Galgo cgalgo@openovate.com + */ +class Eden_Google_Plus_Activity extends Eden_Google_Base { + /* Constants + -------------------------------*/ + const URL_ACTIVITY_LIST = 'https://www.googleapis.com/plus/v1/people/%s/activities/%s'; + const URL_ACTIVITY_GET = 'https://www.googleapis.com/plus/v1/activities/%s'; + const URL_ACTIVITY_SEARCH = 'https://www.googleapis.com/plus/v1/activities'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_pageToken = NULL; + protected $_maxResults = NULL; + protected $_orderBy = NULL; + + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + public function __construct($token) { + //argument test + Eden_Google_Error::i()->argument(1, 'string'); + $this->_token = $token; + } + + /* Public Methods + -------------------------------*/ + /** + * Set page token + * + * @param string + * @return array + */ + public function setPageToken($pageToken) { + //argument 1 must be a string + Eden_Google_Error::i()->argument(1, 'string'); + $this->_pageToken = $pageToken; + + return $this; + } + + /** + * The maximum number of people to include in the response, + * used for paging. + * + * @param integer + * @return this + */ + public function setMaxResults($maxResults) { + //argument 1 must be a integer + Eden_Google_Error::i()->argument(1, 'int'); + $this->_maxResults = $maxResults; + + return $this; + } + + /** + * Sort activities by relevance to the user, most relevant first. + * + * @return this + */ + public function orderByBest() { + $this->_orderBy = 'best'; + + return $this; + } + + /** + * Sort activities by published date, most recent first. + * + * @return this + */ + public function orderByRecent() { + $this->_orderBy = 'recent'; + + return $this; + } + + /** + * Get activity list of user + * + * @param string + * @return array + */ + public function getList($userId = self::ME) { + //argument 1 must be a string + Eden_Google_Error::i()->argument(1, 'string'); + + //populate fields + $query = array( + self::MAX_RESULTS => $this->_maxResults, //optional + SELF::PAGE_TOKEN => $this->_pageToken); //optional + + return $this->_getResponse(sprintf(self::URL_ACTIVITY_LIST, $userId, self::PUBLIC_DATA), $query); + } + + /** + * Get an activity + * + * @param string + * @return array + */ + public function getSpecific($activityId) { + //argument 1 must be a string + Eden_Google_Error::i()->argument(1, 'string'); + + return $this->_getResponse(sprintf(self::URL_ACTIVITY_GET, $activityId)); + } + + /** + * Search public activities + * + * @param string|integer + * @return array + */ + public function search($queryString) { + //argument 1 must be a string + Eden_Google_Error::i()->argument(1, 'string', 'int'); + + //populate fields + $query = array( + self::QUERY_STRING => $queryString, + self::PAGE_TOKEN => $this->_pageToken, //optional + self::MAX_RESULTS => $this->_maxResults, //optional + self::ORDER => $this->_orderBy); //optional + + return $this->_getResponse(self::URL_ACTIVITY_SEARCH, $query); + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/google/plus/comment.php b/library/eden/google/plus/comment.php new file mode 100644 index 0000000..c79a5dc --- /dev/null +++ b/library/eden/google/plus/comment.php @@ -0,0 +1,127 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Google Plus comment + * + * @package Eden + * @category google + * @author Clark Galgo cgalgo@openovate.com + */ +class Eden_Google_Plus_Comment extends Eden_Google_Base { + /* Constants + -------------------------------*/ + const URL_COMMENTS_LIST = 'https://www.googleapis.com/plus/v1/activities/%s/comments'; + const URL_COMMENTS_GET = 'https://www.googleapis.com/plus/v1/comments/%s'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_pageToken = NULL; + protected $_maxResults = NULL; + protected $_sortOrder = NULL; + + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + public function __construct($token) { + //argument test + Eden_Google_Error::i()->argument(1, 'string'); + $this->_token = $token; + } + + /* Public Methods + -------------------------------*/ + /** + * 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. + * + * @param string + * @return this + */ + public function setPageToken($pageToken) { + //argument 1 must be a string + Eden_Google_Error::i()->argument(1, 'string'); + $this->_pageToken = $pageToken; + + return $this; + } + + /** + * The maximum number of people to include in the response, + * used for paging. + * + * @param integer + * @return this + */ + public function setMaxResults($maxResults) { + //argument 1 must be a integer + Eden_Google_Error::i()->argument(1, 'int'); + $this->_maxResults = $maxResults; + + return $this; + } + + /** + * Sort newest comments first. + * + * @param string + * @return array + */ + public function descendingOrder() { + $this->_sortOrder = 'descending'; + + return $this; + } + + /** + * List all of the comments for an activity. + * + * @param string + * @return array + */ + public function getList($activityId) { + //argument 1 must be a string + Eden_Google_Error::i()->argument(1, 'string'); + + //populate fields + $query = array( + self::MAX_RESULTS => $this->_maxResults, //optional + self::PAGE_TOKEN => $this->_pageToken, //optional + self::SORT => $this->_sortOrder); //optional + + return $this->_getResponse(sprintf(self::URL_COMMENTS_LIST, $activityId), $query); + } + + /** + * Get a comment + * + * @param string + * @return array + */ + public function getSpecific($commentId) { + //argument 1 must be a string + Eden_Google_Error::i()->argument(1, 'string'); + + return $this->_getResponse(sprintf(self::URL_COMMENTS_GET, $commentId)); + } + + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/google/plus/people.php b/library/eden/google/plus/people.php new file mode 100644 index 0000000..c977bd5 --- /dev/null +++ b/library/eden/google/plus/people.php @@ -0,0 +1,147 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Google Plus people + * + * @package Eden + * @category google + * @author Clark Galgo cgalgo@openovate.com + */ +class Eden_Google_Plus_People extends Eden_Google_Base { + /* Constants + -------------------------------*/ + const URL_GET_USER = 'https://www.googleapis.com/plus/v1/people/%s'; + const URL_PEOPLE_SEARCH = 'https://www.googleapis.com/plus/v1/people'; + const URL_PEOPLE_ACTIVITY = 'https://www.googleapis.com/plus/v1/activities/%s/people/%s'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_maxResults = NULL; + protected $_pageToken = NULL; + + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + public function __construct($token) { + //argument test + Eden_Google_Error::i()->argument(1, 'string'); + $this->_token = $token; + } + + /* Public Methods + -------------------------------*/ + /** + * 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. + * + * @param string + * @return this + */ + public function setPageToken($pageToken) { + //argument 1 must be a string + Eden_Google_Error::i()->argument(1, 'string'); + $this->_pageToken = $pageToken; + + return $this; + } + + /** + * The maximum number of people to include in the response, + * used for paging. + * + * @param integer + * @return this + */ + public function setMaxResults($maxResults) { + //argument 1 must be a integer + Eden_Google_Error::i()->argument(1, 'int'); + $this->_maxResults = $maxResults; + + return $this; + } + + /** + * Returns user info + * + * @param string + * @return array + */ + public function getUserInfo($userId = self::ME) { + //argument 1 must be a string + Eden_Google_Error::i()->argument(1, 'string'); + + return $this->_getResponse(sprintf(self::URL_GET_USER,$userId)); + } + + /** + * Returns people that matches the queryString + * + * @param string|integer Full text search of public text in all profiles. + * @return array + */ + public function search($queryString) { + //argument 1 must be a string or integer + Eden_Google_Error::i()->argument(1, 'string', 'int'); + + //populate fields + $query = array( + self::QUERY_STRING => $queryString, + self::PAGE_TOKEN => $this->_pageToken, //optional + self::MAX_RESULTS => $this->_maxResults); //optional + + return $this->_getResponse(self::URL_PEOPLE_SEARCH, $query); + } + + /** + * List all of the people in the specified + * collection for a particular activity + * + * @param string + * @param string + * @return array + */ + public function getActivityList($activityId, $collection) { + //argument test + Eden_Google_Error::i() + ->argument(1, 'string') //argument 1 must be a string + ->argument(2, 'string'); //argument 1 must be a string + + //if the input value is not allowed + if(!in_array($collection, array('plusoners', 'resharers'))) { + //throw error + Eden_Google_Error::i() + ->setMessage(Eden_Google_Error::INVALID_COLLECTION) + ->addVariable($collection) + ->trigger(); + } + + //populate fields + $query = array( + self::ACTIVITY_ID => $activityId, + self::COLLECTION => $collection, + self::MAX_RESULTS => $this->_maXResults, //optional + self::PAGE_TOKEN => $this->_pageToken); //optional + + return $this->_getResponse(sprintf(self::URL_PEOPLE_ACTIVITY, $activityId, $collection), $query); + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/google/shopping.php b/library/eden/google/shopping.php new file mode 100644 index 0000000..9214b1d --- /dev/null +++ b/library/eden/google/shopping.php @@ -0,0 +1,260 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Google calendar + * + * @package Eden + * @category google + * @author Christian Blanquera cblanquera@openovate.com + */ +class Eden_Google_Shopping extends Eden_Google_Base { + /* Constants + -------------------------------*/ + const RANGES = ':ranges'; + const REQUEST_URL = 'https://www.googleapis.com/shopping/search/v1/public/products'; + + const NAME = 'name'; + const VALUE = 'value'; + + const QUERY = 'q'; + const COUNTRY = 'country'; + const CURRENCY = 'currency'; + const RESTRICT_BY = 'restrictBy'; + const RANK_BY = 'rankBy'; + const CROWD_BY = 'crowdBy'; + const SPELLING_CHECK = 'spelling.enabled'; + const FACETS_ENABLED = 'facets.enabled'; + const FACETS_INCLUDE = 'facets.include'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_country = NULL; + protected $_currency = NULL; + protected $_restrictBy = array(); + protected $_rankBy = array(); + protected $_crowding = array(); + protected $_keyword = array(); + protected $_spellChecker = false; + protected $_facet = false; + + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + public function __construct($token) { + //argument test + Eden_Google_Error::i()->argument(1, 'string'); + $this->_token = $token; + } + + /* Public Methods + -------------------------------*/ + /** + * Add facet + * + * @param string + * @param array + * @return this + */ + public function addFacet($name, $value, $range = false) { + Eden_Google_Error::i() + ->argument(1, 'string') + ->argument(2, 'string', 'int') + ->argument(3, 'bool'); + + if(!$this->_facet) { //set facet if not yet set + $this->_facet = true; + } + + if($range) { + $value = $value.self::RANGES; + } + + $this->_facetItem[] = array( + self::NAME => $name, + self::VALUE => $value); + + return $this; + + } + + /** + * add keyword to be searched + * + * @param string + * @return this + */ + public function addKeyword($keyword) { + Eden_Google_Error::i()->argument(1, 'string'); + $this->_keyword[] = $keyword; + + return $this; + } + + /** + * Add restriction for the search + * + * @param string + * @param array + * @return this + */ + public function addRestriction($name, $value) { + Eden_Google_Error::i() + ->argument(1, 'string') + ->argument(2, 'array'); + + $this->_restrictBy[] = array( + self::NAME => $name, + self::VALUE => implode('|', $value)); + + return $this; + } + + /** + * get response + * + * @return json + */ + public function getResponse() { + if(!empty($this->_restrictBy)) { + foreach($this->_restrictBy as $key => $restrict) { + $restrictBy[] = $restrict[self::NAME].':'.$restrict[self::VALUE]; + } + } + + if(!empty($this->_rankBy)) { + $order = $this->_rankBy[self::NAME].':'.$this->_rankBy[self::VALUE]; + } + + if(!empty($this->_crowding)) { + $crowding = $this->_crowding[self::NAME].':'.$this->_crowding[self::VALUE]; + } + + if(!empty($this->_facetItem)) { + foreach($this->_facetItem as $key => $facet) { + $facets[] = $facet[self::NAME].':'.$facet[self::VALUE]; + } + } + + $params = array( + self::QUERY => implode('|', $this->_keyword), + self::COUNTRY => $this->_country, + self::CURRENCY => $this->_currency, + self::RESTRICT_BY => (!isset($restrictBy)) ? NULL : implode(', ', $restrictBy), + self::RANK_BY => (!isset($order)) ? NULL : $order, + self::CROWD_BY => (!isset($crowding)) ? NULL : $crowding, + self::SPELLING_CHECK => ($this->_spellChecker) ? 'true' : 'false', + self::FACETS_ENABLED => ($this->_facet) ? 'true' : 'false', + self::FACETS_INCLUDE => (!isset($facets)) ? NULL : implode(', ', $facets)); + + return $this->_getResponse(self::REQUEST_URL, $params); + } + + /** + * Sets the country + * + * @param string + * @return this + */ + public function setCountry($country = 'US'){ + Eden_Google_Error::i()->argument(1, 'string'); + $this->_country = $country; + + return $this; + } + + /** + * Set crowding of the search result + * + * @param string + * @param int + * @return this + */ + public function setCrowding($name, $occurrence) { + Eden_Google_Error::i() + ->argument(1, 'string') + ->argument(2, 'int'); + + $this->_crowding = array( + self::NAME => $name, + self::VALUE => $occurrence); + + return $this; + } + + /** + * Sets currency + * + * @param string + * @return this + */ + public function setCurrency($currency = 'USD'){ + Eden_Google_Error::i()->argument(1, 'string'); + $this->_currency = $currency; + + return $this; + } + + /** + * Set facet + * + * @param bool + * @return this + */ + public function setFacet($value = true) { + Eden_Google_Error::i()->argument(1, 'bool'); + $this->_facet = $value; + + return $this; + } + + /** + * Set Order of the search result + * + * @param string + * @param array + * @return this + */ + public function setOrder($name, $value = 'assending') { + Eden_Google_Error::i() + ->argument(1, 'string') + ->argument(2, 'string'); + + $this->_rankBy = array( + self::NAME => $name, + self::VALUE => $value); + + return $this; + } + + /** + * Set spell checker + * + * @param bool + * @return this + */ + public function setSpellChecker($value = true) { + Eden_Google_Error::i()->argument(1, 'bool'); + $this->_spellChecker = $value; + + return $this; + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/google/shortener.php b/library/eden/google/shortener.php new file mode 100644 index 0000000..f10f606 --- /dev/null +++ b/library/eden/google/shortener.php @@ -0,0 +1,214 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Google calendar + * + * @package Eden + * @category google + * @author Christian Blanquera cblanquera@openovate.com + */ +class Eden_Google_Shortener extends Eden_Class { + /* Constants + -------------------------------*/ + const URL = 'https://www.googleapis.com/urlshortener/v1/url'; + const SERVICE_URL = 'http://goo.gl/'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_key = NULL; + protected $_meta = array(); + + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + public function __construct($key) { + //Argument 1 must be a string + Eden_Google_Error::i()->argument(1, 'string'); + + $this->_key = $key; + } + + /* Public Methods + -------------------------------*/ + /** + * Returns full analytics of this short url + * + * @param string short url + * @return array + */ + public function getAnalytics($url) { + + if(strpos($url, self::SERVICE_URL) !== 0) { + $url = self::SERVICE_URL.$url; + } + + $query = array('shortUrl' => $url, 'projection'=>'FULL'); + + $response = $this->_getResponse(self::URL, $query); + + return json_decode($response, true); + } + + /** + * Returns the short id for a long url + * + * @param string long url + * @return string | false + */ + public function getId($url) { + $url = $this->getShortUrl($url); + + if(!$url) { + return false; + } + + return substr($url, strlen(self::SERVICE_URL)); + } + + /** + * Returns the long version of this short url + * + * @param string short url + * @return string | false + */ + public function getLongUrl($url) { + $response = $this->getAnalytics($url); + + if(!is_array($response) || !isset($response['longUrl'])) { + return false; + } + + return $response['longUrl']; + } + + /** + * Returns the meta of the last call + * + * @return array + */ + public function getMeta($key = NULL) { + Eden_Google_Error::i()->argument(1, 'string', 'null'); + + if(isset($this->_meta[$key])) { + return $this->_meta[$key]; + } + + return $this->_meta; + } + + /** + * Returns the short url version for a long url + * + * @param string long url + * @return string | false + */ + public function getShortUrl($url) { + $query = array('longUrl' => $url); + $response = $this->_post(self::URL, $query); + $response = json_decode($response, true); + + if(!is_array($response) || !isset($response['id'])) { + return false; + } + + return $response['id']; + } + + /* Protected Methods + -------------------------------*/ + protected function _getResponse($url, array $query = array()) { + $headers = array(); + $headers[] = 'Content-Type: application/json'; + + $query['key'] = $this->_key; + $query = http_build_query($query); + + //determine the conector + $connector = NULL; + + //if there is no question mark + if(strpos($url, '?') === false) { + $connector = '?'; + //if the redirect doesn't end with a question mark + } else if(substr($url, -1) != '?') { + $connector = '&'; + } + + //now add the authorization to the url + $url .= $connector.$query; + + //set curl + $curl = Eden_Curl::i() + ->verifyHost(false) + ->verifyPeer(false) + ->setUrl($url) + ->setHeaders($headers); + + //get the response + $response = $curl->getResponse(); + + $this->_meta = $curl->getMeta(); + $this->_meta['url'] = $url; + $this->_meta['headers'] = $headers; + $this->_meta['query'] = $query; + + return $response; + } + + protected function _post($url, $query = array()) { + $headers = array(); + $headers[] = 'Content-Type: application/json'; + + $query = json_encode($query); + + //determine the conector + $connector = NULL; + + //if there is no question mark + if(strpos($url, '?') === false) { + $connector = '?'; + //if the redirect doesn't end with a question mark + } else if(substr($url, -1) != '?') { + $connector = '&'; + } + + //now add the authorization to the url + $url .= $connector.'key='.$this->_key; + + //set curl + $curl = Eden_Curl::i() + ->verifyHost(false) + ->verifyPeer(false) + ->setUrl($url) + ->setPost(true) + ->setPostFields($query) + ->setHeaders($headers); + + //get the response + $response = $curl->getResponse(); + + $this->_meta = $curl->getMeta(); + $this->_meta['url'] = $url; + $this->_meta['headers'] = $headers; + $this->_meta['query'] = $query; + + return $response; + } + + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/google/youtube.php b/library/eden/google/youtube.php new file mode 100644 index 0000000..327f2f4 --- /dev/null +++ b/library/eden/google/youtube.php @@ -0,0 +1,173 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Google youtube + * + * @package Eden + * @category google + * @author Christian Symon M. Buenavista sbuenavista@openovate.com + */ +class Eden_Google_Youtube extends Eden_Google_Base { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + public function __construct($token, $developerId) { + //argument test + Eden_Google_Error::i() + ->argument(1, 'string') + ->argument(2, 'string'); + + $this->_token = $token; + $this->_developerId = $developerId; + } + + /* Public Methods + -------------------------------*/ + /** + * Factory method for youtube activity + * + * @return Eden_Google_Youtube_Activity + */ + public function activity() { + return Eden_Google_Youtube_Activity::i($this->_token, $this->_developerId); + } + + /** + * Factory method for youtube channel + * + * @return Eden_Google_Youtube_Channel + */ + public function channel() { + return Eden_Google_Youtube_Channel::i($this->_token); + } + + /** + * Factory method for youtube comment + * + * @return Eden_Google_Youtube_Activity + */ + public function comment() { + return Eden_Google_Youtube_Comment::i($this->_token, $this->_developerId); + } + + /** + * Factory method for youtube contacts + * + * @return Eden_Google_Youtube_Contacts + */ + public function contacts() { + return Eden_Google_Youtube_Contacts::i($this->_token, $this->_developerId); + } + + /** + * Factory method for youtube favorites + * + * @return Eden_Google_Youtube_Favorites + */ + public function favorites() { + return Eden_Google_Youtube_Favorites::i($this->_token, $this->_developerId); + } + + /** + * Factory method for youtube history + * + * @return Eden_Google_Youtube_History + */ + public function history() { + return Eden_Google_Youtube_History::i($this->_token, $this->_developerId); + } + + /** + * Factory method for youtube message + * + * @return Eden_Google_Youtube_Message + */ + public function message() { + return Eden_Google_Youtube_Message::i($this->_token, $this->_developerId); + } + + /** + * Factory method for youtube playlist + * + * @return Eden_Google_Youtube_Playlist + */ + public function playlist() { + return Eden_Google_Youtube_Playlist::i($this->_token, $this->_developerId); + } + + /** + * Factory method for youtube profile + * + * @return Eden_Google_Youtube_Profile + */ + public function profile() { + return Eden_Google_Youtube_Profile::i($this->_token, $this->_developerId); + } + + /** + * Factory method for youtube ratings + * + * @return Eden_Google_Youtube_Ratings + */ + public function ratings() { + return Eden_Google_Youtube_Ratings::i($this->_token, $this->_developerId); + } + + /** + * Factory method for youtube search + * + * @return Eden_Google_Youtube_Search + */ + public function search() { + return Eden_Google_Youtube_Search::i($this->_token); + } + + /** + * Factory method for youtube subscription + * + * @return Eden_Google_Youtube_Subscription + */ + public function subscription() { + return Eden_Google_Youtube_Subscription::i($this->_token, $this->_developerId); + } + + /** + * Factory method for youtube upload + * + * @return Eden_Google_Youtube_Upload + */ + public function upload() { + return Eden_Google_Youtube_Upload::i($this->_token, $this->_developerId); + } + + /** + * Factory method for youtube video + * + * @return Eden_Google_Youtube_Video + */ + public function video() { + return Eden_Google_Youtube_Video::i($this->_token); + } + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/google/youtube/activity.php b/library/eden/google/youtube/activity.php new file mode 100644 index 0000000..bed5671 --- /dev/null +++ b/library/eden/google/youtube/activity.php @@ -0,0 +1,86 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Google youtube activity + * + * @package Eden + * @category google + * @author Christian Symon M. Buenavista sbuenavista@openovate.com + */ +class Eden_Google_Youtube_Activity extends Eden_Google_Base { + /* Constants + -------------------------------*/ + const URL_YOUTUBE_EVENT = 'https://gdata.youtube.com/feeds/api/users/%s/events'; + const URL_YOUTUBE_SUBTIVITY = 'https://gdata.youtube.com/feeds/api/users/%s/subtivity'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + public function __construct($token, $developerId) { + //argument test + Eden_Google_Error::i() + ->argument(1, 'string') + ->argument(2, 'string'); + + $this->_token = $token; + $this->_developerId = $developerId; + } + + /* Public Methods + -------------------------------*/ + /** + * Retrieve all user's event + * + * @param string + * @return array + */ + public function getEvent($userId = self::DEFAULT_VALUE) { + //argument 1 must be a string + Eden_Google_Error::i()->argument(1, 'string'); + + //populate fields + $query = array( + self::RESPONSE => self::JSON_FORMAT, + self::VERSION => self::VERSION); + + return $this->_getResponse(sprintf(self::URL_YOUTUBE_EVENT, $userId), $query); + } + + /** + * Retrieve all user's subtivity + * + * @param string + * @return array + */ + public function getSubtivity($userId = self::DEFAULT_VALUE) { + //argument 1 must be a string + Eden_Google_Error::i()->argument(1, 'string'); + //populate fields + $query = array( + self::RESPONSE => self::JSON_FORMAT, + self::VERSION => self::VERSION); + + return $this->_getResponse(sprintf(self::URL_YOUTUBE_SUBTIVITY, $userId), $query); + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/google/youtube/channel.php b/library/eden/google/youtube/channel.php new file mode 100644 index 0000000..7d8a578 --- /dev/null +++ b/library/eden/google/youtube/channel.php @@ -0,0 +1,199 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Google youtube channel + * + * @package Eden + * @category google + * @author Christian Symon M. Buenavista sbuenavista@openovate.com + */ +class Eden_Google_Youtube_Channel extends Eden_Google_Base { + /* Constants + -------------------------------*/ + const URL_YOUTUBE_CHANNEL = 'https://gdata.youtube.com/feeds/api/channels'; + const URL_YOUTUBE_CHANNEL_FEEDS = 'https://gdata.youtube.com/feeds/api/channelstandardfeeds/%s'; + const URL_YOUTUBE_REGION = 'https://gdata.youtube.com/feeds/api/channelstandardfeeds/%s/%s'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_startIndex = NULL; + protected $_maxResults = NULL; + protected $_time = NULL; + + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + public function __construct($token) { + //argument test + Eden_Google_Error::i()->argument(1, 'string'); + $this->_token = $token; + } + + /* Public Methods + -------------------------------*/ + /** + * Set start index + * + * @param integer + * @return this + */ + public function setStartIndex($startIndex) { + //argument 1 must be a integer + Eden_Google_Error::i()->argument(1, 'integer'); + $this->_startIndex = $startIndex; + + return $this; + } + + /** + * Set start index + * + * @param integer + * @return this + */ + public function setMaxResults($maxResults) { + //argument 1 must be a integer + Eden_Google_Error::i()->argument(1, 'integer'); + $this->_maxResults = $maxResults; + + return $this; + } + + /** + * Returns all feeds this day + * + * @return this + */ + public function setToday() { + $this->_time = 'today'; + + return $this; + } + + /** + * Returns all feeds this week + * + * @return this + */ + public function setThisWeek() { + $this->_time = 'this_week'; + + return $this; + } + + /** + * Returns all feeds this month + * + * @return this + */ + public function setThisMonth() { + $this->_time = 'this_month'; + + return $this; + } + + /** + * Returns all feeds + * + * @return this + */ + public function setToAllTime() { + $this->_time = 'all_time'; + + return $this; + } + + /** + * Returns a collection of videos that match the API request parameters. + * + * @param string + * @return array + */ + public function search($queryString) { + //argument 1 must be a string + Eden_Google_Error::i()->argument(1, 'string'); + + //populate parameters + $query = array( + self::QUERY => $queryString, + self::START_INDEX => $this->_startIndex, //optional + self::MAX_RESULTS => $this->_maxResults, //optional + self::VERSION => self::VERSION_TWO); + + return $this->_getResponse(self::URL_YOUTUBE_CHANNEL, $query); + } + + /** + * Returns a collection of videos that match the API request parameters. + * + * @param string + * @return array + */ + public function getChannelFeeds($feeds) { + //argument 1 must be a string + Eden_Google_Error::i()->argument(1, 'string'); + + //if the input value is not allowed + if(!in_array($feeds, array('most_viewed', 'most_subscribed'))) { + //throw error + Eden_Google_Error::i() + ->setMessage(Eden_Google_Error::INVALID_FEEDS_ONE) + ->addVariable($feeds) + ->trigger(); + } + + //populate parameters + $query = array( + self::VERSION => self::VERSION_TWO, + self::TIME => $this->_time); + + return $this->_getResponse(sprintf(self::URL_YOUTUBE_CHANNEL_FEEDS, $feeds), $query); + } + + /** + * Returns a collection of videos that match the API request parameters. + * + * @param string + * @param string + * @return array + */ + public function getChannelByRegion($regionId, $feeds) { + //argument test + Eden_Google_Error::i() + ->argument(1, 'string') //argument 1 must be a string + ->argument(2, 'string'); //argument 2 must be a string + + //if the input value is not allowed + if(!in_array($feeds, array('most_viewed', 'most_subscribed'))) { + //throw error + Eden_Google_Error::i() + ->setMessage(Eden_Google_Error::INVALID_FEEDS_TWO) + ->addVariable($feeds) + ->trigger(); + } + + //populate parameters + $query = array(self::VERSION => self::VERSION_TWO); + + return $this->_getResponse(sprintf(self::URL_YOUTUBE_REGION, $regionId, $feeds), $query); + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/google/youtube/comment.php b/library/eden/google/youtube/comment.php new file mode 100644 index 0000000..c76edef --- /dev/null +++ b/library/eden/google/youtube/comment.php @@ -0,0 +1,142 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Google youtube comments + * + * @package Eden + * @category google + * @author Christian Symon M. Buenavista sbuenavista@openovate.com + */ +class Eden_Google_Youtube_Comment extends Eden_Google_Base { + /* Constants + -------------------------------*/ + const URL_YOUTUBE_GET_COMMENTS = 'https://gdata.youtube.com/feeds/api/videos/%s/comments'; + const URL_YOUTUBE_COMMENTS = 'https://gdata.youtube.com/feeds/api/videos/%s/comments/%s'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + public function __construct($token, $developerId) { + //argument test + Eden_Google_Error::i() + ->argument(1, 'string') + ->argument(2, 'string'); + + $this->_token = $token; + $this->_developerId = $developerId; + } + + /* Public Methods + -------------------------------*/ + /** + * Returns a collection of videos that match the API request parameters. + * + * @param string + * @return array + */ + public function getList($videoId) { + //argument 1 must be a string + Eden_Google_Error::i()->argument(1, 'string'); + + return $this->_getResponse(sprintf(self::URL_YOUTUBE_GET_COMMENTS, $videoId)); + } + + /** + * Returns a specific comment + * + * @param string + * @param string + * @return array + */ + public function getSpecific($videoId, $commentId) { + //argument test + Eden_Google_Error::i() + ->argument(1, 'string') //argument 1 must be a string + ->argument(2, 'string'); //argument 2 must be a string + + return $this->_getResponse(sprintf(self::URL_YOUTUBE_COMMENTS, $videoId, $commentId)); + } + + /** + * Add comment to a video + * + * @param string + * @param string + * @return array + */ + public function addComment($videoId, $comment) { + //argument test + Eden_Google_Error::i() + ->argument(1, 'string') //argument 1 must be a string + ->argument(2, 'string'); //argument 2 must be a string + + //make a xml template file + $query = Eden_Template::i() + ->set(self::COMMENT, $comment) + ->parsePHP(dirname(__FILE__).'/template/addcomment.php'); + + return $this->_post(sprintf(self::URL_YOUTUBE_GET_COMMENTS, $videoId), $query); + } + + /** + * Reply to a comment in a video + * + * @param string + * @param string + * @param string + * @return array + */ + public function replyToComment($videoId,$commentId, $comment) { + //argument test + Eden_Google_Error::i() + ->argument(1, 'string') //argument 1 must be a string + ->argument(2, 'string') //argument 2 must be a string + ->argument(3, 'string'); //argument 3 must be a string + + //make a xml template file + $query = Eden_Template::i() + ->set(self::COMMENT, $comment) + ->set(self::COMMENT_ID, $commentId) + ->set(self::VIDEO_ID, $videoId) + ->parsePHP(dirname(__FILE__).'/template/replytocomment.php'); + + return $this->_post(sprintf(self::URL_YOUTUBE_GET_COMMENTS, $videoId), $query); + } + + /** + * Delete a comment + * + * @param string + * @param string + * @return array + */ + public function delete($videoId, $commentId) { + //argument test + Eden_Google_Error::i() + ->argument(1, 'string') //argument 1 must be a string + ->argument(2, 'string'); //argument 2 must be a string + + return $this->_delete(sprintf(self::URL_YOUTUBE_COMMENTS, $videoId, $commentId)); + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/google/youtube/contacts.php b/library/eden/google/youtube/contacts.php new file mode 100644 index 0000000..5daeec5 --- /dev/null +++ b/library/eden/google/youtube/contacts.php @@ -0,0 +1,154 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Google youtube constacts + * + * @package Eden + * @category google + * @author Christian Symon M. Buenavista sbuenavista@openovate.com + */ +class Eden_Google_Youtube_Contacts extends Eden_Google_Base { + /* Constants + -------------------------------*/ + const URL_YOUTUBE_CONTACTS = 'https://gdata.youtube.com/feeds/api/users/%s/contacts'; + const URL_YOUTUBE_CONTACTS_GET = 'https://gdata.youtube.com/feeds/api/users/%s/contacts/%s'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + public function __construct($token, $developerId) { + //argument test + Eden_Google_Error::i() + ->argument(1, 'string') + ->argument(2, 'string'); + + $this->_token = $token; + $this->_developerId = $developerId; + } + + /* Public Methods + -------------------------------*/ + /** + * Retrieve all user's contacts + * + * @param string + * @return array + */ + public function getList($userId = self::DEFAULT_VALUE) { + //argument 1 must be a string + Eden_Google_Error::i()->argument(1, 'string'); + + //populate fields + $query = array(self::RESPONSE => self::JSON_FORMAT); + + return $this->_getResponse(sprintf(self::URL_YOUTUBE_CONTACTS, $userId), $query); + } + + /** + * Retrieve specific user's contacts + * + * @param string + * @param string + * @return array + */ + public function getSpecific($userName, $userId = self::DEFAULT_VALUE) { + //argument test + Eden_Google_Error::i() + ->argument(1, 'string') //argument 1 must be a string + ->argument(2, 'string'); //argument 2 must be a string + //populate fields + $query = array(self::RESPONSE => self::JSON_FORMAT); + + return $this->_getResponse(sprintf(self::URL_YOUTUBE_CONTACTS_GET, $userId, $userName), $query); + } + + /** + * Delete a contact + * + * @param string + * @param string + * @return array + */ + public function delete($userName, $userId = self::DEFAULT_VALUE) { + //argument test + Eden_Google_Error::i() + ->argument(1, 'string') //argument 1 must be a string + ->argument(2, 'string'); //argument 2 must be a string + + return $this->_delete(sprintf(self::URL_YOUTUBE_CONTACTS_GET, $userId, $userName)); + } + + /** + * Add contacts + * + * @param string + * @param string + * @return array + */ + public function addContacts($userName, $userId = self::DEFAULT_VALUE) { + //argument test + Eden_Google_Error::i() + ->argument(1, 'string') //argument 1 must be a string + ->argument(2, 'string'); //argument 2 must be a string + + //make a xml template file + $query = Eden_Template::i() + ->set(self::USER_NAME, $userName) + ->parsePHP(dirname(__FILE__).'/template/activate.php'); + + return $this->_post(sprintf(self::URL_YOUTUBE_CONTACTS, $userId), $query); + } + + /** + * Update contacts + * + * @param string + * @param string + * @param string + * @return array + */ + public function updateContacts($userName, $status, $userId = self::DEFAULT_VALUE) { + //argument test + Eden_Google_Error::i() + ->argument(1, 'string') //argument 1 must be a string + ->argument(2, 'string') //argument 2 must be a string + ->argument(3, 'string'); //argument 3 must be a string + + //if the input value is not allowed + if(!in_array($status, array('accepted', 'rejected'))) { + //throw error + Eden_Google_Error::i() + ->setMessage(Eden_Google_Error::INVALID_STATUS) + ->addVariable($status) + ->trigger(); + } + + //make a xml template file + $query = Eden_Template::i() + ->set(self::STATUS, $status) + ->parsePHP(dirname(__FILE__).'/template/updatecontacts.php'); + + return $this->_put(sprintf(self::URL_YOUTUBE_CONTACTS_GET, $userId, $userName), $query); + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/google/youtube/favorites.php b/library/eden/google/youtube/favorites.php new file mode 100644 index 0000000..997ea35 --- /dev/null +++ b/library/eden/google/youtube/favorites.php @@ -0,0 +1,122 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Google youtube favorites + * + * @package Eden + * @category google + * @author Christian Symon M. Buenavista sbuenavista@openovate.com + */ +class Eden_Google_Youtube_Favorites extends Eden_Google_Base { + /* Constants + -------------------------------*/ + const URL_YOUTUBE_FAVORITES = 'https://gdata.youtube.com/feeds/api/users/%s/favorites'; + const URL_YOUTUBE_FAVORITES_GET = 'https://gdata.youtube.com/feeds/api/users/%s/favorites/%s'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + public function __construct($token, $developerId) { + //argument test + Eden_Google_Error::i() + ->argument(1, 'string') + ->argument(2, 'string'); + + $this->_token = $token; + $this->_developerId = $developerId; + } + + /* Public Methods + -------------------------------*/ + /** + * Retrieving all user's favorite videos. + * + * @param string + * @return array + */ + public function getList($userId = self::DEFAULT_VALUE) { + //argument 1 must be a string + Eden_Google_Error::i()->argument(1, 'string'); + + //populate fields + $query = array(self::RESPONSE => self::JSON_FORMAT); + + return $this->_getResponse(sprintf(self::URL_YOUTUBE_FAVORITES, $userId), $query); + } + + /** + * Retrieving specific user's favorite videos. + * + * @param string + * @param string + * @return array + */ + public function getSpecific($favoriteVideoId, $userId = self::DEFAULT_VALUE) { + //argument test + Eden_Google_Error::i() + ->argument(1, 'string') //argument 1 must be a string + ->argument(2, 'string'); //argument 2 must be a string + + //populate fields + $query = array(self::RESPONSE => self::JSON_FORMAT); + + return $this->_getResponse(sprintf(self::URL_YOUTUBE_FAVORITES_GET, $userId, $favoriteVideoId), $query); + } + + /** + * Retrieving a user's favorite videos. + * + * @param string + * @param string + * @return array + */ + public function addFavorites($videoId, $userId = self::DEFAULT_VALUE) { + //argument test + Eden_Google_Error::i() + ->argument(1, 'string') //argument 1 must be a string + ->argument(2, 'string'); //argument 2 must be a string + + //make a xml template file + $query = Eden_Template::i() + ->set(self::VIDEO_ID, $videoId) + ->parsePHP(dirname(__FILE__).'/template/addfavorites.php'); + + return $this->_post(sprintf(self::URL_YOUTUBE_FAVORITES, $userId), $query); + } + + /** + * Retrieving a user's favorite videos. + * + * @param string + * @param string + * @return array + */ + public function removeFavorites($favoriteVideoId, $userId = self::DEFAULT_VALUE) { + //argument test + Eden_Google_Error::i() + ->argument(1, 'string') //argument 1 must be a string + ->argument(2, 'string'); //argument 2 must be a string + + return $this->_delete(sprintf(self::URL_YOUTUBE_FAVORITES_GET, $userId, $favoriteVideoId)); + } + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/google/youtube/history.php b/library/eden/google/youtube/history.php new file mode 100644 index 0000000..aef28d9 --- /dev/null +++ b/library/eden/google/youtube/history.php @@ -0,0 +1,91 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Google youtube history + * + * @package Eden + * @category google + * @author Christian Symon M. Buenavista sbuenavista@openovate.com + */ +class Eden_Google_Youtube_History extends Eden_Google_Base { + /* Constants + -------------------------------*/ + const URL_YOUTUBE_HISTORY = 'https://gdata.youtube.com/feeds/api/users/default/watch_history'; + const URL_YOUTUBE_HISTORY_GET = 'https://gdata.youtube.com/feeds/api/users/default/watch_history/%s'; + const URL_YOUTUBE_HISTORY_CLEAR = 'https://gdata.youtube.com/feeds/api/users/default/watch_history/actions/clear'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + public function __construct($token, $developerId) { + //argument test + Eden_Google_Error::i() + ->argument(1, 'string') + ->argument(2, 'string'); + + $this->_token = $token; + $this->_developerId = $developerId; + } + + /* Public Methods + -------------------------------*/ + /** + * Retrieve a user's watch history feed. + * + * @return array + */ + public function getList() { + //populate fields + $query = array( + self::VERSION => self::VERSION_TWO, + self::RESPONSE => self::JSON_FORMAT); + + return $this->_getResponse(sprintf(self::URL_YOUTUBE_HISTORY), $query); + } + + /** + * Delete a specific history + * + * @param string + * @return array + */ + public function deleteSpecific($historyId) { + //argument 1 must be a string + Eden_Google_Error::i()->argument(1, 'string'); + + return $this->_delete(sprintf(self::URL_YOUTUBE_HISTORY_GET, $historyId)); + } + + /** + * Clear history + * + * @return array + */ + public function clearHistory() { + //call block to format xml files + $query = $this->Eden_Google_Youtube_Block_Clear(); + + return $this->_post(sprintf(self::URL_YOUTUBE_HISTORY_CLEAR), $query); + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/google/youtube/message.php b/library/eden/google/youtube/message.php new file mode 100644 index 0000000..177dfc9 --- /dev/null +++ b/library/eden/google/youtube/message.php @@ -0,0 +1,107 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Google youtube message + * + * @package Eden + * @category google + * @author Christian Symon M. Buenavista sbuenavista@openovate.com + */ +class Eden_Google_Youtube_Message extends Eden_Google_Base { + /* Constants + -------------------------------*/ + const URL_YOUTUBE_MESSAGE = 'https://gdata.youtube.com/feeds/api/users/%s/inbox'; + const URL_YOUTUBE_MESSAGE_GET = 'https://gdata.youtube.com/feeds/api/users/%s/inbox/%s'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + public function __construct($token, $developerId) { + //argument test + Eden_Google_Error::i() + ->argument(1, 'string') + ->argument(2, 'string'); + + $this->_token = $token; + $this->_developerId = $developerId; + } + + /* Public Methods + -------------------------------*/ + /** + * Retrieve all user's contacts + * + * @param string + * @return array + */ + public function getList($userId = self::DEFAULT_VALUE) { + //argument 1 must be a string + Eden_Google_Error::i()->argument(1, 'string'); + + //populate fields + $query = array(self::RESPONSE => self::JSON_FORMAT); + + return $this->_getResponse(sprintf(self::URL_YOUTUBE_MESSAGE, $userId), $query); + } + + /** + * Send a video message + * + * @param string + * @param string + * @param string + * @return array + */ + public function sendMessage($videoId, $summary, $userName) { + //argument test + Eden_Google_Error::i() + ->argument(1, 'string') //argument 1 must be a string + ->argument(2, 'string') //argument 2 must be a string + ->argument(3, 'string'); //argument 3 must be a string + + //make a xml template + $query = Eden_Template::i() + ->set(self::VIDEO_ID, $videoId) + ->set(self::SUMMARY, $summary) + ->parsePHP(dirname(__FILE__).'/template/sendmessage.php'); + + return $this->_post(sprintf(self::URL_YOUTUBE_MESSAGE, $userName), $query); + } + + /** + * Delete a message + * + * @param string + * @param string + * @return array + */ + public function delete($messageId, $userId = self::DEFAULT_VALUE) { + //argument test + Eden_Google_Error::i() + ->argument(1, 'string') //argument 1 must be a string + ->argument(2, 'string'); //argument 2 must be a string + + return $this->_delete(sprintf(self::URL_YOUTUBE_MESSAGE_GET, $userId, $messageId)); + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/google/youtube/playlist.php b/library/eden/google/youtube/playlist.php new file mode 100644 index 0000000..cae5d30 --- /dev/null +++ b/library/eden/google/youtube/playlist.php @@ -0,0 +1,199 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Google youtube playlist + * + * @package Eden + * @category google + * @author Christian Symon M. Buenavista sbuenavista@openovate.com + */ +class Eden_Google_Youtube_Playlist extends Eden_Google_Base { + /* Constants + -------------------------------*/ + const URL_YOUTUBE_PLAYLIST = 'https://gdata.youtube.com/feeds/api/users/%s/playlists'; + const URL_YOUTUBE_PLAYLIST_UPDATE = 'https://gdata.youtube.com/feeds/api/users/%s/playlists/%s'; + const URL_YOUTUBE_PLAYLIST_DELETE = 'https://gdata.youtube.com/feeds/api/users/%s/playlists/%s'; + const URL_YOUTUBE_PLAYLIST_GET = 'https://gdata.youtube.com/feeds/api/playlists/%s'; + const URL_YOUTUBE_PLAYLIST_VIDEO = 'https://gdata.youtube.com/feeds/api/playlists/%s/%s'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + public function __construct($token, $developerId) { + //argument test + Eden_Google_Error::i() + ->argument(1, 'string') + ->argument(2, 'string'); + + $this->_developerId = $developerId; + $this->_token = $token; + } + + /* Public Methods + -------------------------------*/ + /** + * Returns user playlist + * + * @param string + * @return array + */ + public function getList($userId = self::DEFAULT_VALUE) { + //argument 1 must be a string + Eden_Google_Error::i()->argument(1, 'string'); + + //populate fields + $query = array(self::RESPONSE => self::JSON_FORMAT); + + return $this->_getResponse(sprintf(self::URL_YOUTUBE_PLAYLIST, $userId), $query); + } + + /** + * Create a playlist + * + * @param string + * @param string + * @param string + * @return array + */ + public function create($title, $summary, $userId = self::DEFAULT_VALUE) { + //argument test + Eden_Google_Error::i() + ->argument(1, 'string') //argument 1 must be a string + ->argument(2, 'string') //argument 2 must be a string + ->argument(3, 'string'); //argument 3 must be a string + + //make a xml template + $query = Eden_Template::i() + ->set(self::TITLE, $title) + ->set(self::SUMMARY, $summary) + ->parsePHP(dirname(__FILE__).'/template/createplaylist.php'); + + return $this->_post(sprintf(self::URL_YOUTUBE_PLAYLIST, $userId), $query); + } + + /** + * Create a playlist + * + * @param string + * @param string + * @param string + * @param string + * @return array + */ + public function update($title, $summary, $playlistId, $userId = self::DEFAULT_VALUE) { + //argument test + Eden_Google_Error::i() + ->argument(1, 'string') //argument 1 must be a string + ->argument(2, 'string') //argument 2 must be a string + ->argument(3, 'string') //argument 3 must be a string + ->argument(4, 'string'); //argument 4 must be a string + + //make a xml template + $query = Eden_Template::i() + ->set(self::TITLE, $title) + ->set(self::SUMMARY, $summary) + ->parsePHP(dirname(__FILE__).'/template/createplaylist.php'); + + return $this->_put(sprintf(self::URL_YOUTUBE_PLAYLIST_UPDATE, $userId, $playlistId), $query); + } + + /** + * Add video to a playlist + * + * @param string + * @param string + * @param string + * @return array + */ + public function addVideo($videoId, $position, $playlistId) { + //argument test + Eden_Google_Error::i() + ->argument(1, 'string') //argument 1 must be a string + ->argument(2, 'string') //argument 2 must be a string + ->argument(3, 'string'); //argument 3 must be a string + + //make a xml template + $query = Eden_Template::i() + ->set(self::VIDEO_ID, $videoId) + ->set(self::POSITION, $position) + ->parsePHP(dirname(__FILE__).'/template/addvideo.php'); + + return $this->_post(sprintf(self::URL_YOUTUBE_PLAYLIST_GET, $playlistId), $query); + } + + /** + * Add video to a playlist + * + * @param string + * @param string + * @param string + * @return array + */ + public function updateVideo($position, $playlistId, $entryId) { + //argument test + Eden_Google_Error::i() + ->argument(1, 'string') //argument 1 must be a string + ->argument(2, 'string') //argument 2 must be a string + ->argument(3, 'string'); //argument 3 must be a string + + //make a xml template + $query = Eden_Template::i() + ->set(self::POSITION, $position) + ->parsePHP(dirname(__FILE__).'/template/addvideo.php'); + + return $this->_put(sprintf(self::URL_YOUTUBE_PLAYLIST_VIDEO, $playlistId, $entryId), $query); + } + + /** + * Remove a video in the playlist + * + * @param string + * @param string + * @return array + */ + public function removeVideo($playlistId, $entryId) { + //argument test + Eden_Google_Error::i() + ->argument(1, 'string') //argument 1 must be a string + ->argument(2, 'string'); //argument 2 must be a string + + return $this->_delete(sprintf(self::URL_YOUTUBE_PLAYLIST_VIDEO, $playlistId, $entryId)); + } + + /** + * Delete a playlist + * + * @param string + * @param string + * @return array + */ + public function delete($playlistId, $userId = self::DEFAULT_VALUE) { + //argument test + Eden_Google_Error::i() + ->argument(1, 'string') //argument 1 must be a string + ->argument(2, 'string'); //argument 2 must be a string + + return $this->_delete(sprintf(self::URL_YOUTUBE_PLAYLIST_DELETE, $this->_userId, $this->_playlistId)); + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/google/youtube/profile.php b/library/eden/google/youtube/profile.php new file mode 100644 index 0000000..6b378aa --- /dev/null +++ b/library/eden/google/youtube/profile.php @@ -0,0 +1,124 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Google youtube profile + * + * @package Eden + * @category google + * @author Christian Symon M. Buenavista sbuenavista@openovate.com + */ +class Eden_Google_Youtube_Profile extends Eden_Google_Base { + /* Constants + -------------------------------*/ + const URL_YOUTUBE_PROFILE = 'https://gdata.youtube.com/feeds/api/users/%s'; + const URL_YOUTUBE_UPLOADS = 'https://gdata.youtube.com/feeds/api/users/%s/uploads'; + const URL_YOUTUBE_GET = 'https://gdata.youtube.com/feeds/api/users/%s/uploads/%s'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + public function __construct($token, $developerId) { + //argument test + Eden_Google_Error::i() + ->argument(1, 'string') + ->argument(2, 'string'); + + $this->_token = $token; + $this->_developerId = $developerId; + } + + /* Public Methods + -------------------------------*/ + /** + * Returns a collection of videos that match the API request parameters. + * + * @param string + * @return array + */ + public function getList($userId = self::DEFAULT_VALUE) { + //argument 1 must be a string + Eden_Google_Error::i()->argument(1, 'string'); + + //populate fields + $query = array(self::RESPONSE => self::JSON_FORMAT); + + return $this->_getResponse(sprintf(self::URL_YOUTUBE_PROFILE, $userId), $query); + } + + /** + * Returns all videos uploaded by user, + * + * @param string + * @return array + */ + public function getUserVideoUploads($userId = self::DEFAULT_VALUE) { + //argument 1 must be a string + Eden_Google_Error::i()->argument(1, 'string'); + + //populate fields + $query = array(self::RESPONSE => self::JSON_FORMAT); + + return $this->_getResponse(sprintf(self::URL_YOUTUBE_UPLOADS, $userId), $query); + } + + /** + * Returns specific videos uploaded by user, + * + * @param string + * @param string + * @return array + */ + public function getSpecificUserVideo($videoId, $userId = self::DEFAULT_VALUE) { + //argument test + Eden_Google_Error::i() + ->argument(1, 'string') //argument 1 must be a string + ->argument(2, 'string'); //argument 2 must be a string + + //populate fields + $query = array(self::RESPONSE => self::JSON_FORMAT); + + return $this->_getResponse(sprintf(self::URL_YOUTUBE_GET, $userId, $videoId), $query); + } + + /** + * Activate user account for youtube + * + * @param string + * @param string + * @return array + */ + public function activateAccount($userName, $userId = self::DEFAULT_VALUE) { + //argument test + Eden_Google_Error::i() + ->argument(1, 'string') //argument 1 must be a string + ->argument(2, 'string'); //argument 2 must be a string + + //make a xml template + $query = Eden_Template::i() + ->set(self::USER_NAME, $userName) + ->parsePHP(dirname(__FILE__).'/template/activate.php'); + + return $this->_put(sprintf(self::URL_YOUTUBE_PROFILE, $userId), $query); + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/google/youtube/ratings.php b/library/eden/google/youtube/ratings.php new file mode 100644 index 0000000..39436c8 --- /dev/null +++ b/library/eden/google/youtube/ratings.php @@ -0,0 +1,107 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Google Youtube ratings + * + * @package Eden + * @category google + * @author Christian Symon M. Buenavista sbuenavista@openovate.com + */ +class Eden_Google_Youtube_Ratings extends Eden_Google_Base { + /* Constants + -------------------------------*/ + const URL_YOUTUBE_RATINGS = 'https://gdata.youtube.com/feeds/api/videos/%s/ratings'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + public function __construct($token, $developerId) { + //argument test + Eden_Google_Error::i() + ->argument(1, 'string') + ->argument(2, 'string'); + + $this->_token = $token; + $this->_developerId = $developerId; + } + + /* Public Methods + -------------------------------*/ + /** + * Add a numeric (1-5) video rating + * + * @param string + * @param integer Video ratings (1-5) + * @return array + */ + public function addRating($videoId, $rating) { + //argument test + Eden_Google_Error::i() + ->argument(1, 'string') //argument 1 must be a string + ->argument(2, 'string', 'int'); //argument 2 must be a string or integer + + //make a xml template + $query = Eden_Template::i() + ->set(self::RATINGS, $rating) + ->parsePHP(dirname(__FILE__).'/template/addratings.php'); + + return $this->_post(sprintf(self::URL_YOUTUBE_RATINGS, $videoId), $query); + } + + /** + * Like a video + * + * @param string + * @return array + */ + public function like($videoId) { + //argument 1 must be a string + Eden_Google_Error::i()->argument(1, 'string'); + + //make a xml template + $query = Eden_Template::i() + ->set(self::VALUE, self::LIKE) + ->parsePHP(dirname(__FILE__).'/template/like.php'); + + return $this->_post(sprintf(self::URL_YOUTUBE_RATINGS, $videoId), $query); + } + + /** + * Dislike a video + * + * @param string + * @return array + */ + public function dislike($videoId) { + //argument 1 must be a string + Eden_Google_Error::i()->argument(1, 'string'); + + //make a xml template + $query = Eden_Template::i() + ->set(self::VALUE, self::DISLIKE) + ->parsePHP(dirname(__FILE__).'/template/like.php'); + + return $this->_post(sprintf(self::URL_YOUTUBE_RATINGS, $videoId), $query); + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/google/youtube/search.php b/library/eden/google/youtube/search.php new file mode 100644 index 0000000..bb01322 --- /dev/null +++ b/library/eden/google/youtube/search.php @@ -0,0 +1,143 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Google youtube search + * + * @package Eden + * @category google + * @author Christian Symon M. Buenavista sbuenavista@openovate.com + */ +class Eden_Google_Youtube_Search extends Eden_Google_Base { + /* Constants + -------------------------------*/ + const URL_YOUTUBE_SEARCH = 'https://gdata.youtube.com/feeds/api/videos'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_startIndex = NULL; + protected $_maxResults = NULL; + protected $_orderBy = NULL; + + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + public function __construct($token) { + //argument test + Eden_Google_Error::i()->argument(1, 'string'); + $this->_token = $token; + } + + /* Public Methods + -------------------------------*/ + /** + * Set start index + * + * @param integer + * @return this + */ + public function setStart($start) { + //argument 1 must be a integer + Eden_Google_Error::i()->argument(1, 'integer'); + $this->_startIndex = $start; + + return $this; + } + + /** + * Set start index + * + * @param integer + * @return this + */ + public function setRange($range) { + //argument 1 must be a integer + Eden_Google_Error::i()->argument(1, 'integer'); + $this->_maxResults = $range; + + return $this; + } + + /** + * Order results by relevance + * + * @return this + */ + public function orderByRelevance() { + $this->_orderBy = 'relevance'; + + return $this; + } + + /** + * Order results by published + * + * @return this + */ + public function orderByPublished() { + $this->_orderBy = 'published'; + + return $this; + } + + /** + * Order results by viewCount + * + * @return this + */ + public function orderByViewCount() { + $this->_orderBy = 'viewCount'; + + return $this; + } + + /** + * Order results by rating + * + * @return this + */ + public function orderByRating() { + $this->_orderBy = 'rating'; + + return $this; + } + + /** + * Returns a collection of videos that match the API request parameters. + * + * @param string + * @return array + */ + public function getResponse($queryString) { + //argument 1 must be a string + Eden_Google_Error::i()->argument(1, 'string'); + + //populate parameters + $query = array( + self::QUERY => $queryString, + self::VERSION => self::VERSION_TWO, + self::START_INDEX => $this->_startIndex, //optional + self::MAX_RESULTS => $this->_maxResults, //optional + self::ORDER_BY => $this->_orderBy); //optional + + return $this->_getResponse(self::URL_YOUTUBE_SEARCH, $query); + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/google/youtube/subscription.php b/library/eden/google/youtube/subscription.php new file mode 100644 index 0000000..024713d --- /dev/null +++ b/library/eden/google/youtube/subscription.php @@ -0,0 +1,142 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Google youtube subscription + * + * @package Eden + * @category google + * @author Christian Symon M. Buenavista sbuenavista@openovate.com + */ +class Eden_Google_Youtube_Subscription extends Eden_Google_Base { + /* Constants + -------------------------------*/ + const URL_YOUTUBE_SUBSCRIPTION = 'https://gdata.youtube.com/feeds/api/users/%s/subscriptions'; + const URL_YOUTUBE_NEW_SUBSCRIPTION = 'https://gdata.youtube.com/feeds/api/users/%s/newsubscriptionvideos'; + const URL_YOUTUBE_UNSUBSCRIPTION = 'https://gdata.youtube.com/feeds/api/users/%s/subscriptions/%s'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + public function __construct($token, $developerId) { + //argument test + Eden_Google_Error::i() + ->argument(1, 'string') + ->argument(2, 'string'); + + $this->_token = $token; + $this->_developerId = $developerId; + } + + /* Public Methods + -------------------------------*/ + /** + * Returns all user subscription + * + * @param string + * @return array + */ + public function getList($userId = self::DEFAULT_VALUE) { + //argument 1 must be a string + Eden_Google_Error::i()->argument(1, 'string'); + + //populate fields + $query = array(self::RESPONSE => self::JSON_FORMAT); + + return $this->_getResponse(sprintf(self::URL_YOUTUBE_SUBSCRIPTION, $userId), $query); + } + + /** + * Returns new user subscription + * + * @param string + * @return array + */ + public function getNewSubscription($userId = self::DEFAULT_VALUE) { + //argument 1 must be a string + Eden_Google_Error::i()->argument(1, 'string'); + + //populate fields + $query = array(self::RESPONSE => self::JSON_FORMAT); + + return $this->_getResponse(sprintf(self::URL_YOUTUBE_NEW_SUBSCRIPTION, $userId), $query); + } + + /** + * Subscribe to a channel + * + * @param string + * @param string + * @return array + */ + public function subscribeToChannel($channel, $userId = self::DEFAULT_VALUE) { + //argument test + Eden_Google_Error::i() + ->argument(1, 'string') //argument 1 must be a string + ->argument(2, 'string'); //argument 2 must be a string + + //make a xml template + $query = Eden_Template::i() + ->set(self::CHANNEL, $channel) + ->parsePHP(dirname(__FILE__).'/template/subscribe.php'); + + return $this->_post(sprintf(self::URL_YOUTUBE_SUBSCRIPTION, $userId), $query); + } + + /** + * Subscribe to a users activity + * + * @param string + * @param string + * @return array + */ + public function subscribeToUser($user, $userId = self::DEFAULT_VALUE) { + //argument test + Eden_Google_Error::i() + ->argument(1, 'string') //argument 1 must be a string + ->argument(2, 'string'); //argument 2 must be a string + + //make a xml template + $query = Eden_Template::i() + ->set(self::USER, $user) + ->parsePHP(dirname(__FILE__).'/template/subscribe.php'); + + return $this->_post(sprintf(self::URL_YOUTUBE_SUBSCRIPTION, $userId), $query); + } + + /** + * Subscribe to a users activity + * + * @param string + * @param string + * @return array + */ + public function unsubscribe($subscriptionId, $userId = self::DEFAULT_VALUE) { + //argument test + Eden_Google_Error::i() + ->argument(1, 'string') //argument 1 must be a string + ->argument(2, 'string'); //argument 2 must be a string + + return $this->_delete(sprintf(self::URL_YOUTUBE_UNSUBSCRIPTION, $userId, $subscriptionId)); + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/google/youtube/template/activate.php b/library/eden/google/youtube/template/activate.php new file mode 100644 index 0000000..6e94a19 --- /dev/null +++ b/library/eden/google/youtube/template/activate.php @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/library/eden/google/youtube/template/addcomment.php b/library/eden/google/youtube/template/addcomment.php new file mode 100644 index 0000000..a4cd300 --- /dev/null +++ b/library/eden/google/youtube/template/addcomment.php @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/library/eden/google/youtube/template/addfavorites.php b/library/eden/google/youtube/template/addfavorites.php new file mode 100644 index 0000000..11dbc54 --- /dev/null +++ b/library/eden/google/youtube/template/addfavorites.php @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/library/eden/google/youtube/template/addratings.php b/library/eden/google/youtube/template/addratings.php new file mode 100644 index 0000000..57c99eb --- /dev/null +++ b/library/eden/google/youtube/template/addratings.php @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/library/eden/google/youtube/template/addvideo.php b/library/eden/google/youtube/template/addvideo.php new file mode 100644 index 0000000..2906f8d --- /dev/null +++ b/library/eden/google/youtube/template/addvideo.php @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/library/eden/google/youtube/template/clear.php b/library/eden/google/youtube/template/clear.php new file mode 100644 index 0000000..4cc7c26 --- /dev/null +++ b/library/eden/google/youtube/template/clear.php @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/library/eden/google/youtube/template/createplaylist.php b/library/eden/google/youtube/template/createplaylist.php new file mode 100644 index 0000000..27d017f --- /dev/null +++ b/library/eden/google/youtube/template/createplaylist.php @@ -0,0 +1,6 @@ + + + <?php echo $title; ?> + + \ No newline at end of file diff --git a/library/eden/google/youtube/template/form.php b/library/eden/google/youtube/template/form.php new file mode 100644 index 0000000..bf434fd --- /dev/null +++ b/library/eden/google/youtube/template/form.php @@ -0,0 +1,5 @@ +
+ + + +
\ No newline at end of file diff --git a/library/eden/google/youtube/template/like.php b/library/eden/google/youtube/template/like.php new file mode 100644 index 0000000..9c763de --- /dev/null +++ b/library/eden/google/youtube/template/like.php @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/library/eden/google/youtube/template/replytocomment.php b/library/eden/google/youtube/template/replytocomment.php new file mode 100644 index 0000000..6aa8ed1 --- /dev/null +++ b/library/eden/google/youtube/template/replytocomment.php @@ -0,0 +1,8 @@ + + + + + \ No newline at end of file diff --git a/library/eden/google/youtube/template/sendmessage.php b/library/eden/google/youtube/template/sendmessage.php new file mode 100644 index 0000000..2095f41 --- /dev/null +++ b/library/eden/google/youtube/template/sendmessage.php @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/library/eden/google/youtube/template/subscribe.php b/library/eden/google/youtube/template/subscribe.php new file mode 100644 index 0000000..73755eb --- /dev/null +++ b/library/eden/google/youtube/template/subscribe.php @@ -0,0 +1,14 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/library/eden/google/youtube/template/updatecontacts.php b/library/eden/google/youtube/template/updatecontacts.php new file mode 100644 index 0000000..5b20493 --- /dev/null +++ b/library/eden/google/youtube/template/updatecontacts.php @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/library/eden/google/youtube/template/upload.php b/library/eden/google/youtube/template/upload.php new file mode 100644 index 0000000..c646f0f --- /dev/null +++ b/library/eden/google/youtube/template/upload.php @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/library/eden/google/youtube/upload.php b/library/eden/google/youtube/upload.php new file mode 100644 index 0000000..5fbaad0 --- /dev/null +++ b/library/eden/google/youtube/upload.php @@ -0,0 +1,100 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Google Youtube Upload + * + * @package Eden + * @category google + * @author Christian Symon M. Buenavista sbuenavista@openovate.com + */ +class Eden_Google_Youtube_Upload extends Eden_Google_Base { + /* Constants + -------------------------------*/ + const URL_YOUTUBE_UPLOAD = 'http://uploads.gdata.youtube.com/action/GetUploadToken'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + public function __construct($token, $developerId) { + //argument test + Eden_Google_Error::i() + ->argument(1, 'string') + ->argument(2, 'string'); + + $this->_token = $token; + $this->_developerId = $developerId; + } + + /* Public Methods + -------------------------------*/ + /** + * Get upload token + * + * @param string + * @param string + * @param string + * @param string + * @return array + */ + public function getUploadToken($title, $description, $category, $keyword, $userId = self::DEFAULT_VALUE) { + //argument test + Eden_Google_Error::i() + ->argument(1, 'string') //argument 1 must be a string + ->argument(2, 'string') //argument 2 must be a string + ->argument(3, 'string') //argument 3 must be a string + ->argument(4, 'string'); //argument 4 must be a string + + //make a xml template + $query = Eden_Template::i() + ->set(self::TITLE, $title) + ->set(self::DESCRIPTION, $description) + ->set(self::CATEGORY, $category) + ->set(self::KEYWORD, $keyword) + ->parsePHP(dirname(__FILE__).'/template/upload.php'); + + return $this->_upload(sprintf(self::URL_YOUTUBE_UPLOAD, $userId), $query); + } + + /** + * Upload video to youtube + * + * @return form + */ + public function upload($uploadToken, $postUrl, $redirectUrl) { + //argument test + Eden_Google_Error::i() + ->argument(1, 'object', 'string') //argument 1 must be a object or string + ->argument(2, 'object', 'string') //argument 2 must be a object or string + ->argument(3, 'string'); //argument 3 must be a string + + //make a xml template + $query = Eden_Template::i() + ->set(self::UPLOAD_TOKEN, $uploadToken) + ->set(self::REDIRECT_URL, $redirectUrl) + ->set(self::POST_URL, $postUrl) + ->parsePHP(dirname(__FILE__).'/template/form.php'); + + return $query; + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/google/youtube/video.php b/library/eden/google/youtube/video.php new file mode 100644 index 0000000..0c6f987 --- /dev/null +++ b/library/eden/google/youtube/video.php @@ -0,0 +1,211 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Google youtube video + * + * @package Eden + * @category google + * @author Christian Symon M. Buenavista sbuenavista@openovate.com + */ +class Eden_Google_Youtube_Video extends Eden_Google_Base { + /* Constants + -------------------------------*/ + const URL_YOUTUBE_FEEDS = 'https://gdata.youtube.com/feeds/api/standardfeeds/%s'; + const URL_YOUTUBE_CATEGORY = 'https://gdata.youtube.com/feeds/api/videos'; + const URL_YOUTUBE_REGION = 'http://gdata.youtube.com/feeds/api/standardfeeds/%s/%s'; + const URL_YOUTUBE_FAVORITES = 'http://gdata.youtube.com/feeds/api/users/%s/favorites'; + const URL_YOUTUBE_GET = 'https://gdata.youtube.com/feeds/api/videos/%s'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_feeds = 'most_popular'; + + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + public function __construct($token) { + //argument test + Eden_Google_Error::i()->argument(1, 'string'); + $this->_token = $token; + } + + /* Public Methods + -------------------------------*/ + /** + * Returns the most highly rated YouTube videos. + * + * @return this + */ + public function filterByTopRated() { + $this->_feeds = 'top_rated'; + + return $this; + } + + /** + * Returns videos most frequently flagged as favorite videos. + * + * @return this + */ + public function filterByTopFavorites() { + $this->_feeds = 'top_favorites'; + + return $this; + } + + /** + * Returns YouTube videos most frequently shared on Facebook and Twitter. + * + * @return this + */ + public function filterByMostShared() { + $this->_feeds = 'most_shared'; + return $this; + } + + /** + * Returns the most popular YouTube videos, + * + * @return this + */ + public function filterByMostPopular() { + $this->_feeds = 'most_popular'; + return $this; + } + + /** + * Returns videos most recently submitted to YouTube. + * + * @return this + */ + public function filterByMostRecent() { + $this->_feeds = 'most_recent'; + return $this; + } + + /** + * Returns YouTube videos that have received the most comments. + * + * @return this + */ + public function filterByMostDiscussed() { + $this->_feeds = 'most_discussed'; + return $this; + } + + /** + * Returns YouTube videos that receive the most video responses. + * + * @return this + */ + public function filterByMostResponded() { + $this->_feeds = 'most_responded'; + return $this; + } + + /** + * Returns videos recently featured on the YouTube home page or featured videos tab. + * + * @return this + */ + public function filterByRecentFeatured() { + $this->_feeds = 'recently_featured'; + return $this; + } + + /** + * Returns lists trending videos as seen on YouTube Trends, + * + * @return this + */ + public function filterByOnTheWeb() { + $this->_feeds = 'on_the_web'; + return $this; + } + + /** + * Returns a specific videos + * + * @param string + * @return array + */ + public function getSpecific($videoId) { + //argument test + Eden_Google_Error::i()->argument(1, 'string'); + + return $this->_getResponse(sprintf(self::URL_YOUTUBE_GET, $videoId)); + } + + /** + * Returns a collection of videos of users favorites. + * + * @return array + */ + public function getFavorites() { + //populate parameters + $query = array(self::VERSION => self::VERSION_TWO); + return $this->_getResponse(sprintf(self::URL_YOUTUBE_FAVORITES, $this->_feeds), $query); + } + + /** + * Returns a collection of videos that match the API request parameters. + * + * @return array + */ + public function getList() { + return $this->_getResponse(sprintf(self::URL_YOUTUBE_FEEDS, $this->_feeds)); + } + + /** + * Returns a collection of videos from category. + * + * @param string + * @return array + */ + public function getListByCategory($category) { + //argument test + Eden_Google_Error::i()->argument(1, 'string'); + + //populate parameters + $query = array( + self::CATEGORY => $category, + self::VERSION => self::VERSION_TWO); + + return $this->_getResponse(sprintf(self::URL_YOUTUBE_CATEGORY, $this->_feeds), $query); + } + + /** + * Returns a collection of videos that match the API request parameters. + * + * @param string + * @return array + */ + public function getListByRegion($regionId) { + //argument test + Eden_Google_Error::i()->argument(1, 'string'); + + //populate parameters + $query = array(self::VERSION => self::VERSION_TWO); + + return $this->_getResponse(sprintf(self::URL_YOUTUBE_REGION, $regionId, $this->_feeds), $query); + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/image.php b/library/eden/image.php new file mode 100644 index 0000000..c0ad676 --- /dev/null +++ b/library/eden/image.php @@ -0,0 +1,742 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +require_once dirname(__FILE__).'/class.php'; + +/** + * Abstract definition for common image manipulations per image. + * PHP is not limited to creating just HTML output. It can also be + * used to create and manipulate image files in a variety of + * different image formats, including GIF, PNG, JPEG, WBMP, and + * XPM. Even more convenient, PHP can output image streams directly + * to a browser. You will need to compile PHP with the GD library + * of image functions for this to work. GD and PHP may also require + * other libraries, depending on which image formats you want to + * work with. + * + * @package Eden + * @category utility + * @author Christian Blanquera cblanquera@openovate.com + */ +class Eden_Image extends Eden_Class { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_resource = NULL; + protected $_width = 0; + protected $_height = 0; + + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + public function __construct($data, $type = NULL, $path = true, $quality = 75) { + Eden_Image_Error::i() + ->argument(1, 'string') + ->argument(2, 'string', 'null') + ->argument(3, 'bool') + ->argument(4, 'int'); + + $this->_type = $type; + + //some render functions allow you + //to set the quality of the render + $this->_quality = $quality; + + //create the resource + $this->_resource = $this->_getResource($data, $path); + + //set the initial with and height + list($this->_width, $this->_height) = $this->getDimensions(); + } + + public function __destruct() { + if($this->_resource) { + imagedestroy($this->_resource); + } + } + + public function __toString() { + #imagepng() - Output a PNG image to either the browser or a file + #imagegif() - Output image to browser or file + #imagewbmp() - Output image to browser or file + #imagejpeg() - Output image to browser or file + ob_start(); + switch($this->_type) { + case 'gif': + imagegif($this->_resource); + break; + case 'png': + $quality = (100 - $this->_quality) / 10; + + if($quality > 9) { + $quality = 9; + } + + imagepng($this->_resource, NULL, $quality); + break; + case 'bmp': + case 'wbmp': + imagewbmp($this->_resource, NULL, $this->_quality); + break; + case 'jpg': + case 'jpeg': + case 'pjpeg': + default: + imagejpeg($this->_resource, NULL, $this->_quality); + break; + + } + + return ob_get_clean(); + + } + + /* Public Methods + -------------------------------*/ + /** + * Applies the selective blur filter. Blurs the image + * + * @return Eden_Image_Model + */ + public function blur() { + //apply filter + imagefilter($this->_resource, IMG_FILTER_SELECTIVE_BLUR); + + return $this; + } + + /** + * Applies the brightness filter. Changes the brightness of the image. + * + * @param *number level + * @return Eden_Image_Model + */ + public function brightness($level) { + //Argument 1 must be a number + Eden_Image_Error::i()->argument(1, 'numeric'); + + //apply filter + imagefilter($this->_resource, IMG_FILTER_BRIGHTNESS, $level); + + return $this; + } + + /** + * Applies the colorize filter. Like greyscale except you can specify the color. + * + * @param *number red + * @param *number blue + * @param *number green + * @param number alpha + * @return Eden_Image_Model + */ + public function colorize($red, $blue, $green, $alpha = 0) { + //argument test + Eden_Image_Error::i() + ->argument(1, 'numeric') //Argument 1 must be a number + ->argument(2, 'numeric') //Argument 2 must be a number + ->argument(3, 'numeric') //Argument 3 must be a number + ->argument(4, 'numeric'); //Argument 4 must be a number + + //apply filter + imagefilter($this->_resource, IMG_FILTER_COLORIZE, $red, $blue, $green, $alpha); + + return $this; + } + + /** + * Applies the contrast filter. Changes the contrast of the image. + * + * @param *number level + * @return Eden_Image_Model + */ + public function contrast($level) { + //Argument 1 must be a number + Eden_Image_Error::i()->argument(1, 'numeric'); + + //apply filter + imagefilter($this->_resource, IMG_FILTER_CONTRAST, $level); + + return $this; + } + + /** + * Crops the image + * + * @param int|null the width; if null will use the original width + * @param int|null the height; if null will use the original height + * @return Eden_Image_Model + */ + public function crop($width = NULL, $height = NULL) { + //argument test + Eden_Image_Error::i() + ->argument(1, 'numeric', 'null') //Argument 1 must be a number or null + ->argument(2, 'numeric', 'null'); //Argument 2 must be a number or null + + //get the source width and height + $orgWidth = imagesx($this->_resource); + $orgHeight = imagesy($this->_resource); + + //set the width if none is defined + if(is_null($width)) { + $width = $orgWidth; + } + + //set the height if none is defined + if(is_null($height)) { + $height = $orgHeight; + } + + //if the width and height are the same as the originals + if($width == $orgWidth && $height == $orgHeight) { + //there's no need to process + return $this; + } + + //if we are here then we do need to crop + //create the new resource with the width and height + $crop = imagecreatetruecolor($width, $height); + + //set some defaults + $xPosition = 0; + $yPosition = 0; + + //if the width is greater than the original width + //or if the height is greater than the original height + if($width > $orgWidth || $height > $orgHeight) { + //save the destination width and height + //because they will change here + $newWidth = $width; + $newHeight = $height; + + //if the desired height is larger than the desired width + if($height > $width) { + //and adjust the height instead + $height = $this->_getHeightAspectRatio($orgWidth, $orgHeight, $width); + //if the aspect height is bigger than the desired height + if($newHeight > $height) { + //set it back to the desired height + $height = $newHeight; + //and adjust the width instead + $width = $this->_getWidthAspectRatio($orgWidth, $orgHeight, $height); + //now because of the way GD renders we need to find the ratio of desired + //height if it was brought down to the original height + $rWidth = $this->_getWidthAspectRatio($newWidth, $newHeight, $orgHeight); + //set the x Position of the source to the center of the + //original width image width minus half the rWidth width + $xPosition = ($orgWidth / 2) - ($rWidth / 2); + } else { + //now because of the way GD renders we need to find the ratio of desired + //height if it was brought down to the original height + $rHeight = $this->_getHeightAspectRatio($newWidth, $newHeight, $orgWidth); + //set the y Position of the source to the center of the + //new sized image height minus half the desired height + $yPosition = ($orgHeight / 2) - ($rHeight / 2) ; + } + //if the desired height is smaller than the desired width + } else { + //get the width aspect ratio + $width = $this->_getWidthAspectRatio($orgWidth, $orgHeight, $height); + //if the aspect height is bigger than the desired height + if($newWidth > $width) { + //set it back to the desired height + $width = $newWidth; + //and adjust the width instead + $height = $this->_getHeightAspectRatio($orgWidth, $orgHeight, $width); + //now because of the way GD renders we need to find the ratio of desired + //height if it was brought down to the original height + $rHeight = $this->_getHeightAspectRatio($newWidth, $newHeight, $orgWidth); + //set the y Position of the source to the center of the + //new sized image height minus half the desired height + $yPosition = ($orgHeight / 2) - ($rHeight / 2) ; + } else { + //now because of the way GD renders we need to find the ratio of desired + //height if it was brought down to the original height + $rWidth = $this->_getWidthAspectRatio($newWidth, $newHeight, $orgHeight); + //set the x Position of the source to the center of the + //original width image width minus half the rWidth width + $xPosition = ($orgWidth / 2) - ($rWidth / 2); + } + } + } else { + //if the width is less than the original width + if($width < $orgWidth) { + //set the x Position of the source to the center of the + //original image width minus half the desired width + $xPosition = ($orgWidth / 2) - ($width / 2); + //set the destination width to be the original width + $width = $orgWidth; + } + + //if the height is less than the original height + if($height < $orgHeight) { + //set the y Position of the source to the center of the + //original image height minus half the desired height + $yPosition = ($orgHeight / 2) - ($height / 2); + //set the destination height to be the original height + $height = $orgHeight; + } + } + + //render the image + imagecopyresampled($crop, $this->_resource, 0, 0, $xPosition, $yPosition, $width, $height, $orgWidth, $orgHeight); + + //destroy the original resource + imagedestroy($this->_resource); + + //assign the new resource + $this->_resource = $crop; + + return $this; + } + + /** + * Applies the edgedetect filter. Uses edge detection to highlight the edges in the image. + * + * @return Eden_Image_Model + */ + public function edgedetect() { + //apply filter + imagefilter($this->_resource, IMG_FILTER_EDGEDETECT); + + return $this; + } + + /** + * Applies the emboss filter. Embosses the image. + * + * @return Eden_Image_Model + */ + public function emboss() { + //apply filter + imagefilter($this->_resource, IMG_FILTER_EMBOSS); + + return $this; + } + + /** + * Applies the gaussian blur filter. Blurs the image using the Gaussian method. + * + * @return Eden_Image_Model + */ + public function gaussianBlur() { + //apply filter + imagefilter($this->_resource, IMG_FILTER_GAUSSIAN_BLUR); + + return $this; + } + + /** + * Returns the size of the image + * + * @return array + */ + public function getDimensions() { + return array(imagesx($this->_resource), imagesy($this->_resource)); + } + + /** + * Returns the resource for custom editing + * + * @return [RESOURCE] + */ + public function getResource() { + return $this->_resource; + } + + /** + * Applies the greyscale filter. Converts the image into grayscale. + * + * @return Eden_Image_Model + */ + public function greyscale() { + //apply filter + imagefilter($this->_resource, IMG_FILTER_GRAYSCALE); + + return $this; + } + + /** + * Inverts the image. + * + * @param bool if true invert vertical; if false invert horizontal + * @return Eden_Image_Model + */ + public function invert($vertical = false) { + //Argument 1 must be a boolean + Eden_Image_Error::i()->argument(1, 'bool'); + + //get the source width and height + $orgWidth = imagesx($this->_resource); + $orgHeight = imagesy($this->_resource); + + $invert = imagecreatetruecolor($orgWidth, $orgHeight); + + if($vertical) { + imagecopyresampled($invert, $this->_resource, 0, 0, 0, ($orgHeight-1), $orgWidth, $orgHeight, $orgWidth, 0-$orgHeight); + } else { + imagecopyresampled($invert, $this->_resource, 0, 0, ($orgWidth-1), 0, $orgWidth, $orgHeight, 0-$orgWidth, $orgHeight); + } + + //destroy the original resource + imagedestroy($this->_resource); + + //assign the new resource + $this->_resource = $invert; + + return $this; + } + + /** + * Applies the mean removal filter. Uses mean removal to achieve a "sketchy" effect. + * + * @return Eden_Image_Model + */ + public function meanRemoval() { + //apply filter + imagefilter($this->_resource, IMG_FILTER_MEAN_REMOVAL); + + return $this; + } + + /** + * Applies the greyscale filter. Reverses all colors of the image. + * + * @return Eden_Image_Model + */ + public function negative() { + //apply filter + imagefilter($this->_resource, IMG_FILTER_NEGATE); + + return $this; + } + + /** + * Resizes the image. This is a version of + * scale but keeping it's original aspect ratio + * + * @param int|null the width; if null will use the original width + * @param int|null the height; if null will use the original height + * @return Eden_Image_Model + */ + public function resize($width = NULL, $height = NULL) { + //argument test + Eden_Image_Error::i() + ->argument(1, 'numeric', 'null') //Argument 1 must be a number or null + ->argument(2, 'numeric', 'null'); //Argument 2 must be a number or null + + //get the source width and height + $orgWidth = imagesx($this->_resource); + $orgHeight = imagesy($this->_resource); + + //set the width if none is defined + if(is_null($width)) { + $width = $orgWidth; + } + + //set the height if none is defined + if(is_null($height)) { + $height = $orgHeight; + } + + //if the width and height are the same as the originals + if($width == $orgWidth && $height == $orgHeight) { + //there's no need to process + return $this; + } + + $newWidth = $width; + $newHeight = $height; + + //if the desired height is larger than the desired width + if($height < $width) { + //get the width aspect ratio + $width = $this->_getWidthAspectRatio($orgWidth, $orgHeight, $height); + //if the aspect width is bigger than the desired width + if($newWidth < $width) { + //set it back to the desired width + $width = $newWidth; + //and adjust the height instead + $height = $this->_getHeightAspectRatio($orgWidth, $orgHeight, $width); + } + //if the desired height is smaller than the desired width + } else { + //get the width aspect ratio + $height = $this->_getHeightAspectRatio($orgWidth, $orgHeight, $width); + //if the aspect height is bigger than the desired height + if($newHeight < $height) { + //set it back to the desired height + $height = $newHeight; + //and adjust the width instead + $width = $this->_getWidthAspectRatio($orgWidth, $orgHeight, $height); + } + } + + return $this->scale($width, $height); + } + + /** + * Rotates the image. + * + * @param *int the degree to rotate by + * @param int background color code + * @return Eden_Image_Model + */ + public function rotate($degree, $background = 0) { + //argument test + Eden_Image_Error::i() + ->argument(1, 'numeric') //Argument 1 must be a number + ->argument(2, 'numeric'); //Argument 2 must be a number + + //rotate the image + $rotate = imagerotate($this->_resource, $degree, $background); + + //destroy the original resource + imagedestroy($this->_resource); + + //assign the new resource + $this->_resource = $rotate; + + return $this; + } + + /** + * Scales the image. If width or height is set + * to NULL a width or height will be auto determined based on the + * aspect ratio + * + * @param int|null the width; if null will use the original width + * @param int|null the height; if null will use the original height + * @return Eden_Image_Model + */ + public function scale($width = NULL, $height = NULL) { + //argument test + Eden_Image_Error::i() + ->argument(1, 'numeric', 'null') //Argument 1 must be a number or null + ->argument(2, 'numeric', 'null'); //Argument 2 must be a number or null + + //get the source width and height + $orgWidth = imagesx($this->_resource); + $orgHeight = imagesy($this->_resource); + + //set the width if none is defined + if(is_null($width)) { + $width = $orgWidth; + } + + //set the height if none is defined + if(is_null($height)) { + $height = $orgHeight; + } + + //if the width and height are the same as the originals + if($width == $orgWidth && $height == $orgHeight) { + //there's no need to process + return $this; + } + + //if we are here then we do need to crop + //create the new resource with the width and height + $scale = imagecreatetruecolor($width, $height); + + //render the image + imagecopyresampled($scale, $this->_resource, 0, 0, 0, 0, $width, $height, $orgWidth, $orgHeight); + + //destroy the original resource + imagedestroy($this->_resource); + + //assign the new resource + $this->_resource = $scale; + + return $this; + } + + public function setTransparency() { + imagealphablending( $this->_resource, false ); + imagesavealpha( $this->_resource, true ); + + return $this; + } + + /** + * Applies the smooth filter. Makes the image smoother. + * + * @param *number level + * @return Eden_Image_Model + */ + public function smooth($level) { + //Argument 1 must be a number + Eden_Image_Error::i()->argument(1, 'numeric'); + + //apply filter + imagefilter($this->_resource, IMG_FILTER_SMOOTH, $level); + + return $this; + } + + /** + * Saves the image data to a file + * + * @param *string the path to save to + * @param string|null the render type + * @return this + */ + public function save($path, $type = NULL) { + #imagepng() - Output a PNG image to either the browser or a file + #imagegif() - Output image to browser or file + #imagewbmp() - Output image to browser or file + #imagejpeg() - Output image to browser or file + //$path = Eden_Path::i()->getAbsolute($path); + + if(!$type) { + $type = $this->_type; + } + + switch($type) { + case 'gif': + imagegif($this->_resource, $path); + break; + case 'png': + $quality = (100 - $this->_quality) / 10; + + if($quality > 9) { + $quality = 9; + } + + imagepng($this->_resource, $path, $quality); + break; + case 'bmp': + case 'wbmp': + imagewbmp($this->_resource, $path, $this->_quality); + break; + case 'jpg': + case 'jpeg': + case 'pjpeg': + default: + imagejpeg($this->_resource, $path, $this->_quality); + break; + + } + + return $this; + } + + /* Protected Methods + -------------------------------*/ + protected function _getHeightAspectRatio($sourceWidth, $sourceHeight, $destinationWidth) { + $ratio = $destinationWidth / $sourceWidth; + return $sourceHeight * $ratio; + } + + protected function _getResource($data, $path) { + //if the GD Library is not installed + if(!function_exists('gd_info')) { + //throw error + Eden_Image_Error::i(Eden_Image_Error::GD_NOT_INSTALLED)->trigger(); + } + + # imagecreatefromgd — Create a new image from GD file or URL + # imagecreatefromgif — Create a new image from file or URL + # imagecreatefromjpeg — Create a new image from file or URL + # imagecreatefrompng — Create a new image from file or URL + # imagecreatefromstring — Create a new image from the image stream in the string + # imagecreatefromwbmp — Create a new image from file or URL + # imagecreatefromxbm — Create a new image from file or URL + # imagecreatefromxpm — Create a new image from file or URL + + $resource = false; + + if(!$path) { + return imagecreatefromstring($data); + } + + //depending on the extension lets load + //the file using the right GD loader + switch($this->_type) { + case 'gd': + $resource = imagecreatefromgd($data); + break; + case 'gif': + $resource = imagecreatefromgif($data); + break; + case 'jpg': + case 'jpeg': + case 'pjpeg': + $resource = imagecreatefromjpeg($data); + break; + case 'png': + $resource = imagecreatefrompng($data); + break; + case 'bmp': + case 'wbmp': + $resource = imagecreatefromwbmp($data); + break; + case 'xbm': + $resource = imagecreatefromxbm($data); + break; + case 'xpm': + $resource = imagecreatefromxpm($data); + break; + } + + //if there is no resource still + if(!$resource) { + //throw error + Eden_Image_Error::i() + ->setMessage(Eden_Image_Error::NOT_VALID_IMAGE_FILE) + ->addVariable($path); + } + + return $resource; + } + + protected function _getWidthAspectRatio($sourceWidth, $sourceHeight, $destinationHeight) { + $ratio = $destinationHeight / $sourceHeight; + return $sourceWidth * $ratio; + } + + /* Private Methods + -------------------------------*/ +} + +/** + * Image exception + */ +class Eden_Image_Error extends Eden_Error { + /* Constants + -------------------------------*/ + const GD_NOT_INSTALLED = 'PHP GD Library is not installed.'; + const NOT_VALID_IMAGE_FILE = '%s is not a valid image file.'; + const NOT_STRING_MODEL = 'Argument %d is expecting a string or Eden_Image_Model.'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + /* Magic + -------------------------------*/ + /* Public Methods + -------------------------------*/ + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/jabber.php b/library/eden/jabber.php new file mode 100644 index 0000000..ce62f7c --- /dev/null +++ b/library/eden/jabber.php @@ -0,0 +1,1119 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +require_once dirname(__FILE__).'/class.php'; + +/** + * XMPP/Jabber abstract for IM clients. + * + * @package Eden + * @category jabber + * @author Christian Blanquera cblanquera@openovate.com + */ +class Eden_Jabber extends Eden_Event { + /* Constants + --------------------------------*/ + //connection types + const AOL_HOST = 'xmpp.oscar.aol.com'; + const AOL_PORT = 5222; + + const GOOGLE_HOST = 'gmail.com'; + const GOOGLE_PORT = 5222; + + const JABBER_HOST = 'jabber.org'; + const JABBER_PORT = 5222; + + const MSN_HOST = 'messenger.live.com'; + const MSN_PORT = 5222; + + const YAHOO_HOST = 'chat.live.yahoo.com'; + const YAHOO_PORT = 5222; + + //presence types + const PRESENCE_ONLINE = 'online'; + const PRESENCE_OFFLINE = 'offline'; + const PRESENCE_AWAY = 'away'; + const PRESENCE_DND = 'dnd'; + const PRESENCE_XA = 'xa'; + + const PRESENCE_TYPE_PROBE = 'probe'; + const PRESENCE_TYPE_UNAVAILABLE = 'unavailable'; + const PRESENCE_TYPE_ERROR = 'error'; + const PRESENCE_TYPE_SUBSCRIBE = 'subscribe'; + const PRESENCE_TYPE_SUBSCRIBED = 'subscribed'; + const PRESENCE_TYPE_UNSUBSCRIBE = 'unsubscribe'; + const PRESENCE_TYPE_UNSUBSCRIBED = 'unsubscribed'; + + const MESSAGE_TYPE_CHAT = 'chat'; + const MESSAGE_TYPE_ERROR = 'error'; + const MESSAGE_TYPE_GROUPCHAT = 'groupchat'; + const MESSAGE_TYPE_HEADLINE = 'headline'; + const MESSAGE_TYPE_NORMAL = 'normal'; + + const AUTH_NOOP = 0; + const AUTH_STARTED = 1; + const AUTH_CHALLENGE = 2; + const AUTH_FAILIURE = 3; + const AUTH_PROCEED = 4; + const AUTH_SUCCESS = 5; + + const AUTH_TYPE_STREAM = 'stream:stream'; + const AUTH_TYPE_FEATURES = 'stream:features'; + const AUTH_TYPE_CHALLENGE = 'challenge'; + const AUTH_TYPE_FAILURE = 'failure'; + const AUTH_TYPE_PROCEED = 'proceed'; + const AUTH_TYPE_SUCCESS = 'success'; + + const QUERY_TYPE_BIND = 'bind_1'; + const QUERY_TYPE_SESSION = 'sess_1'; + const QUERY_TYPE_REGISTER = 'reg_1'; + const QUERY_TYPE_REGISTERED = 'reg_2'; + const QUERY_TYPE_UNREGISTER = 'unreg_1'; + const QUERY_TYPE_ROSTER = 'roster_1'; + const QUERY_TYPE_PUSH = 'push'; + + /* Public Properties + --------------------------------*/ + /* Protected Properties + --------------------------------*/ + protected $_host = NULL; + protected $_port = NULL; + protected $_user = NULL; + protected $_pass = NULL; + + protected $_ssl = false; + protected $_tls = false; + + protected $_negotiation = self::AUTH_NOOP; + + protected $_connection = NULL; + protected $_jabberId = NULL; + protected $_streamId = NULL; + protected $_presence = NULL; + protected $_session = false; + + protected $_resource = NULL; + + protected static $_presences = array( + self::PRESENCE_ONLINE, + self::PRESENCE_OFFLINE, + self::PRESENCE_DND, + self::PRESENCE_AWAY, + self::PRESENCE_XA); + + protected static $_presenceTypes = array( + self::PRESENCE_TYPE_PROBE, + self::PRESENCE_TYPE_UNAVAILABLE, + self::PRESENCE_TYPE_ERROR, + self::PRESENCE_TYPE_SUBSCRIBE, + self::PRESENCE_TYPE_SUBSCRIBED, + self::PRESENCE_TYPE_UNSUBSCRIBE, + self::PRESENCE_TYPE_UNSUBSCRIBED); + + protected static $_messageTypes = array( + self::MESSAGE_TYPE_CHAT, + self::MESSAGE_TYPE_ERROR, + self::MESSAGE_TYPE_GROUPCHAT, + self::MESSAGE_TYPE_HEADLINE, + self::MESSAGE_TYPE_NORMAL); + + protected static $_authentications = array( + self::AUTH_TYPE_STREAM, + self::AUTH_TYPE_FEATURES, + self::AUTH_TYPE_CHALLENGE, + self::AUTH_TYPE_FAILURE, + self::AUTH_TYPE_PROCEED, + self::AUTH_TYPE_SUCCESS); + + protected static $_queries = array( + self::QUERY_TYPE_BIND, + self::QUERY_TYPE_SESSION, + self::QUERY_TYPE_REGISTER, + self::QUERY_TYPE_REGISTERED, + self::QUERY_TYPE_UNREGISTER, + self::QUERY_TYPE_ROSTER, + self::QUERY_TYPE_PUSH); + + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + /* Magic + -------------------------------*/ + public function __construct($host, $port, $user, $pass, $ssl = false, $tls = true) { + Eden_Jabber_Error::i() + ->argument(1, 'string') + ->argument(2, 'int') + ->argument(3, 'string') + ->argument(4, 'string') + ->argument(5, 'bool') + ->argument(6, 'bool'); + + $this->_host = $host; + $this->_port = $port; + $this->_user = $user; + $this->_pass = $pass; + $this->_domain = $host; + + $this->_ssl = $ssl && $this->_canUseSSL(); + $this->_tls = $tls && $this->_canUseTLS(); + + + if(strpos($user, '@') !== false) { + list($this->_user, $this->_domain) = explode('@', $user); + } + + // Change port if we use SSL + if ($this->_port == 5222 && $this->_ssl) { + $this->_port = 5223; + } + } + + /* Public Methods + --------------------------------*/ + /** + * Connects to the remote server + * + * @param number timeout + * @return this + */ + public function connect($timeout = 10) { + Eden_Jabber_Error::i()->argument(1, 'int'); + + //if already connected + if($this->_connection) { + //do nothing more + return $this; + } + + $host = $this->_host; + + //if dns_get_record function exists + if (function_exists('dns_get_record')) { + //get the dns record + $record = @dns_get_record("_xmpp-client._tcp.$host", DNS_SRV); + + //if the record is not empty + if(!empty($record) && !empty($record[0]['target'])) { + //set the target to be the host + $host = $record[0]['target']; + } + } + + //fix for ssl + if($this->_ssl) { + $host = 'ssl://' . $host; + } + + //try to open a connection + try { + $this->_connection = fsockopen($host, $this->_port, $errorno, $errorstr, $timeout); + } catch(_Exception $e) { + //throw an exception + Eden_Jabber_Error::i()->setMessage(Eden_Jabber_Error::CONNECTION_FAILED) + ->addVariable($host) + ->addVariable($this->_port) + ->trigger(); + } + + socket_set_blocking($this->_connection, 0); + socket_set_timeout($this->_connection, 60); + + //send off what a typical jabber server opens with + $this->send("\n"); + $this->send("\n"); + + $this->trigger('connected'); + + //start waiting + $this->_response($this->wait()); + + return $this; + } + + /** + * Disconnects from the server + * + * @return this + */ + public function disconnect() { + //if its not connected + if (!$this->_connection) { + return $this; + } + + // disconnect gracefully + if (isset($this->_presence)) { + $this->setPresence(self::PRESENCE_OFFLINE, self::PRESENCE_OFFLINE, NULL, 'unavailable'); + } + + //close the stream + $this->send(''); + + //close the connection + fclose($this->_connection); + + $this->_connection = NULL; + + $this->trigger('disconnected'); + + return $this; + } + + /** + * Returns Meta Data + * + * @return array + */ + public function getMeta() { + return array( + 'host' => $this->_host, + 'port' => $this->_port, + 'user' => $this->_user, + 'ssl' => $this->_ssl, + 'tls' => $this->_tls, + 'negotiation' => $this->_negotiation, + 'connection' => $this->_connection, + 'jabberId' => $this->_jabberId, + 'streamId' => $this->_streamId, + 'presence' => $this->_presence, + 'session' => $this->_session); + } + + /** + * Check to see who is online + * + * @return this + */ + public function probe($to) { + return $this->setPresence($to, NULL, self::PRESENCE_TYPE_PROBE); + } + + /** + * Sends xml data to host + * + * @param string xml + * @return this + */ + public function send($xml) { + //if not connected + if (!$this->_connection) { + //throw exception + Eden_Jabber_Error::i(Eden_Jabber_Error::NOT_CONNECTED)->trigger(); + } + + //clean the XML + $xml = trim($xml); + + $this->trigger('sent', $xml); + + //send the XML off + fwrite($this->_connection, $xml); + + return $this; + } + + /** + * Set the presence to away + * + * @param string|array to + * @param string message + * @return this + */ + public function setAway($to = NULL, $message = NULL) { + return $this->setPresence($to, $message, NULL, self::PRESENCE_AWAY); + } + + /** + * Set the presence to DND + * + * @param string|array to + * @param string message + * @return this + */ + public function setDND($to = NULL, $message = NULL) { + return $this->setPresence($to, $message, NULL, self::PRESENCE_DND); + } + + /** + * Set the presence to offline + * + * @param string|array to + * @param string message + * @return this + */ + public function setOffline($to = NULL, $message = NULL) { + return $this->setPresence($to, $message, NULL, self::PRESENCE_OFFLINE); + } + + /** + * Set the presence to online + * + * @param string|array to + * @param string message + * @return this + */ + public function setOnline($to = NULL, $message = NULL) { + return $this->setPresence($to, $message, NULL, self::PRESENCE_ONLINE); + } + + /** + * Set the presence of a user + * + * @param string|array to + * @param string message + * @param string type + * @param string presence title + * @return this + */ + public function setPresence($to = NULL, $message = NULL, $type = NULL, $show = NULL) { + Eden_Jabber_Error::i() + ->argument(1, 'array', 'string', 'null') + ->argument(2, 'string', 'null') + ->argument(3, 'string', 'null') + ->argument(4, 'string', 'null'); + + //if no JID + if (!isset($this->_jabberId)) { + //throw exception + Eden_Jabber_Error::i(Eden_Jabber_Error::NO_JID)->trigger(); + } + + //fix show + $show = strtolower($show); + $show = in_array($show, self::$_presences) ? ''. $show .'' : NULL; + + //fix type + $type = in_array($type, self::$_presenceTypes) ? ' type="'.$type.'"' : NULL; + + //fix from + $from = 'from="'.$this->_jabberId.'"'; + + //fix message + $message = $message ? '' . htmlspecialchars($message) .'' : NULL; + + $template = ''; + if($show || $message) { + $template = ''.$show.$message.''; + } + + if(is_null($to)) { + $this->send(sprintf($template, '')); + return $this; + } + + //if to is a string + if (is_string($to)) { + //make it into an array + $to = array($to); + } + + //walk to + foreach ($to as $user) { + //fix to + $to = $user ? ' to="'.$user.'"' : ''; + //send prensense to user + $this->send(sprintf($template, $to)); + } + + return $this; + } + + /** + * Defines a resource name. + * This is usuall your app name. + * + * @param string + * @return this + */ + public function setResource($name) { + Eden_Jabber_Error::i()->argument(1, 'string'); + $this->_resource = $name; + return $this; + } + + /** + * Requests for roster + * + * @param string message + * @return this + */ + public function getRoster() { + $this->send(' '); + return $this; + } + + /** + * Set the presence to XA ? + * + * @param string|array to + * @param string message + * @return this + */ + public function setXA($to = NULL, $message = NULL) { + return $this->setPresence($to, $message, NULL, self::PRESENCE_XA); + } + + /** + * Generic start up + * + * @return this + */ + public function start() { + $this->connect(); + while($this->_connection) { + set_time_limit(60); + $response = $this->_response($this->wait()); + if($response === false) { + break; + } + } + return $this->disconnect(); + } + + /** + * Set the presence of a user + * + * @param string|array to + * @param string message + * @param string type + * @param string presence title + * @return this + */ + public function subscribeTo($to = NULL, $message = NULL) { + $this->send(sprintf('', $to)); + + return $this->setPresence($to, $message, self::PRESENCE_TYPE_SUBSCRIBE); + } + + /** + * Sends a message to a user + * + * @param string to whom to send to + * @param string text + * @param string subject + * @param string message type + * @return this + */ + public function to($to, $text, $subject = NULL, $thread = NULL) { + Eden_Jabber_Error::i() + ->argument(1, 'string') + ->argument(2, 'string') + ->argument(3, 'string', 'null') + ->argument(4, 'string', 'null'); + + //if no JID + if (!isset($this->_jabberId)) { + //throw exception + Eden_Jabber_Error::i(Eden_Jabber_Error::NO_JID)->trigger(); + } + + + $from = $this->_jabberId; + + if(!$thread) { + $template = ''. + '%s%s'; + + return $this->send(sprintf( + $template, + htmlspecialchars($from), + htmlspecialchars($to), + self::MESSAGE_TYPE_NORMAL, + uniqid('msg'), + htmlspecialchars($subject), + htmlspecialchars($text))); + } + + + $template = ''. + '%s%s%s'. + ''. + ''; + + return $this->send(sprintf( + $template, + htmlspecialchars($from), + htmlspecialchars($to), + self::MESSAGE_TYPE_CHAT, + uniqid('msg'), + htmlspecialchars($subject), + htmlspecialchars($text), + $thread)); + } + + /** + * Listens for imcoming data + * + * @return string XML + */ + public function wait($timeout = 10) { + //if not connected + if (!$this->_connection) { + //throw exception + Eden_Jabber_Error::i(Eden_Jabber_Error::NOT_CONNECTED)->trigger(); + } + + $start = time(); + $data = ''; + + do { + //get the incoming data + $read = trim(fread($this->_connection, 4096)); + //append it to the buffer + $data .= $read; + //keep going till timeout or connection was terminated or data is complete (denoted by > ) + } while (time() <= $start + $timeout + && !feof($this->_connection) + && ($data == '' + || $read != '' + || (substr(rtrim($data), -1) != '>'))); + + //if there is data + if ($data != '') { + $this->trigger('received', $data); + //parse the xml and return + return $this->_parseXml($data); + } else { + //return nothing + return NULL; + } + } + + /* Protected Methods + --------------------------------*/ + protected function _authenticate($command, $xml) { + //response switch + switch ($command) { + case self::AUTH_TYPE_STREAM: + // Connection initialized (or after authentication). Not much to do here... + if (isset($xml['stream:stream'][0]['#']['stream:features'])) { + // we already got all info we need + $features = $xml['stream:stream'][0]['#']; + } else { + $features = $this->wait(); + } + + $second_time = isset($this->_streamId); + $this->_streamId = $xml['stream:stream'][0]['@']['id']; + + if ($second_time) { + // If we are here for the second time after TLS, we need to continue logging in + //if there are no features + if (!sizeof($features)) { + //throw exception + Eden_Jabber_Error::i(Eden_Jabber_Error::NO_FEATURES)->trigger(); + } + + return $this->_response($features); + } + + //we are on the first step + $this->_negotiation = self::AUTH_STARTED; + + // go on with authentication? + if (isset($features['stream:features'][0]['#']['mechanisms']) || $this->_negotiation == self::AUTH_PROCEED) { + return $this->_response($features); + } + + break; + + case self::AUTH_TYPE_FEATURES: + // Resource binding after successful authentication + if ($this->_negotiation == self::AUTH_SUCCESS) { + // session required? + $this->_session = isset($xml['stream:features'][0]['#']['session']); + + $this->send("". + "" . htmlspecialchars($this->_resource) . ''); + + return $this->_response($this->wait()); + } + + // Let's use TLS if SSL is not enabled and we can actually use it + if (!$this->_ssl && $this->_tls && $this->_canUseSSL() && + isset($xml['stream:features'][0]['#']['starttls'])) { + $this->send("\n"); + return $this->_response($this->wait()); + } + + // Does the server support SASL authentication? + + // I hope so, because we do (and no other method). + if (isset($xml['stream:features'][0]['#']['mechanisms'][0]['@']['xmlns']) && + $xml['stream:features'][0]['#']['mechanisms'][0]['@']['xmlns'] == 'urn:ietf:params:xml:ns:xmpp-sasl') { + // Now decide on method + $methods = array(); + + foreach ($xml['stream:features'][0]['#']['mechanisms'][0]['#']['mechanism'] as $value) { + $methods[] = $value['#']; + } + + // we prefer DIGEST-MD5 + // we don't want to use plain authentication (neither does the server usually) if no encryption is in place + + // http://www.xmpp.org/extensions/attic/jep-0078-1.7.html + // The plaintext mechanism SHOULD NOT be used unless the underlying stream is encrypted (using SSL or TLS) + // and the client has verified that the server certificate is signed by a trusted certificate authority. + + if (in_array('DIGEST-MD5', $methods)) { + $this->send(""); + } else if (in_array('PLAIN', $methods) && ($this->_ssl || $this->_negotiation == self::AUTH_PROCEED)) { + $this->send("" + . base64_encode(chr(0) . $this->_user . '@' . $this->_domain . chr(0) . $this->_pass) . + ''); + } else if (in_array('ANONYMOUS', $methods)) { + $this->send(""); + } else { + // not good... + //disconnect + $this->disconnect(); + //throw an exception + Eden_Jabber_Error::i(Eden_Jabber_Error::NO_AUTH_METHOD)->trigger(); + } + + return $this->_response($this->wait()); + } + + // ok, this is it. bye. + //disconnect + $this->disconnect(); + //throw an exception + Eden_Jabber_Error::i(Eden_Jabber_Error::NO_SASL)->trigger(); + break; + + case self::AUTH_TYPE_CHALLENGE: + // continue with authentication...a challenge literally -_- + $this->_negotiation = self::AUTH_CHALLENGE; + $decoded = base64_decode($xml['challenge'][0]['#']); + $decoded = $this->_parseData($decoded); + + if (!isset($decoded['digest-uri'])) { + $decoded['digest-uri'] = 'xmpp/'. $this->_host; + } + + // better generate a cnonce, maybe it's needed + $decoded['cnonce'] = base64_encode(md5(uniqid(mt_rand(), true))); + + // second challenge? + if (isset($decoded['rspauth'])) { + $this->send(""); + } else { + // Make sure we only use 'auth' for qop (relevant for $this->_encryptPass()) + // If the is choking up on the changed parameter we may need to adjust _encryptPass() directly + if (isset($decoded['qop']) && $decoded['qop'] != 'auth' && strpos($decoded['qop'], 'auth') !== false) { + $decoded['qop'] = 'auth'; + } + + $response = array( + 'username' => $this->_user, + 'response' => $this->_encryptPass(array_merge($decoded, array('nc' => '00000001'))), + 'charset' => 'utf-8', + 'nc' => '00000001', + 'qop' => 'auth'); // only auth being supported + + foreach (array('nonce', 'digest-uri', 'realm', 'cnonce') as $key) { + if (isset($decoded[$key])) { + $response[$key] = $decoded[$key]; + } + } + + $this->send("" . + base64_encode($this->_implodeData($response)) . ''); + } + + return $this->_response($this->wait()); + + case self::AUTH_TYPE_FAILURE: + $this->_negotiation = self::AUTH_FAILIURE; + $this->trigger('failiure'); + //disconnect + $this->disconnect(); + //throw an exception + Eden_Jabber_Error::i(Eden_Jabber_Error::SERVER_FAILED)->trigger(); + + case self::AUTH_TYPE_PROCEED: + // continue switching to TLS + $meta = stream_get_meta_data($this->_connection); + socket_set_blocking($this->_connection, 1); + + if (!stream_socket_enable_crypto($this->_connection, true, STREAM_CRYPTO_METHOD_TLS_CLIENT)) { + //'Error: TLS mode change failed.' + Eden_Jabber_Error::i(Eden_Jabber_Error::SERVER_FAILED)->trigger(); + } + + socket_set_blocking($this->_connection, $meta['blocked']); + $this->_negotiation = self::AUTH_PROCEED; + + // new stream + $this->send("\n"); + $this->send("\n"); + + return $this->_response($this->wait()); + + case self::AUTH_TYPE_SUCCESS: + // Yay, authentication successful. + $this->send("\n"); + + $this->_negotiation = self::AUTH_SUCCESS; + + // we have to wait for another response + return $this->_response($this->wait()); + } + + return $this; + } + + protected function _canUseSSL() { + return @extension_loaded('openssl'); + } + + protected function _canUseTLS() { + return @extension_loaded('openssl') + && function_exists('stream_socket_enable_crypto') + && function_exists('stream_get_meta_data') + && function_exists('socket_set_blocking') + && function_exists('stream_get_wrappers'); + } + + protected function _encryptPass($data) { + // let's me think about again... + foreach (array('realm', 'cnonce', 'digest-uri') as $key) { + if (!isset($data[$key])) { + $data[$key] = ''; + } + } + + $pack = md5($this->_user . ':' . $data['realm'] . ':' . $this->_pass); + + if (isset($data['authzid'])) { + $a1 = pack('H32', $pack) . sprintf(':%s:%s:%s', $data['nonce'], $data['cnonce'], $data['authzid']); + } else { + $a1 = pack('H32', $pack) . sprintf(':%s:%s', $data['nonce'], $data['cnonce']); + } + + // should be: qop = auth + $a2 = 'AUTHENTICATE:'. $data['digest-uri']; + + return md5(sprintf('%s:%s:%s:%s:%s:%s', md5($a1), $data['nonce'], $data['nc'], $data['cnonce'], $data['qop'], md5($a2))); + } + + protected function _getDepth($vals, &$i) { + $children = array(); + + if (isset($vals[$i]['value'])) { + array_push($children, $vals[$i]['value']); + } + + while (++$i < sizeof($vals)) { + switch ($vals[$i]['type']) { + case 'open': + $tagname = (isset($vals[$i]['tag'])) ? $vals[$i]['tag'] : ''; + $size = (isset($children[$tagname])) ? sizeof($children[$tagname]) : 0; + + if (isset($vals[$i]['attributes'])) { + $children[$tagname][$size]['@'] = $vals[$i]['attributes']; + } + + $children[$tagname][$size]['#'] = $this->_getDepth($vals, $i); + + break; + + case 'cdata': + array_push($children, $vals[$i]['value']); + break; + + case 'complete': + $tagname = $vals[$i]['tag']; + $size = (isset($children[$tagname])) ? sizeof($children[$tagname]) : 0; + $children[$tagname][$size]['#'] = (isset($vals[$i]['value'])) ? $vals[$i]['value'] : array(); + + if (isset($vals[$i]['attributes'])) { + $children[$tagname][$size]['@'] = $vals[$i]['attributes']; + } + + break; + + case 'close': + return $children; + break; + } + } + + return $children; + } + + protected function _implodeData($data) { + $return = array(); + foreach ($data as $key => $value) { + $return[] = $key . '="' . $value . '"'; + } + return implode(',', $return); + } + + protected function _query($command, $xml) { + // multiple possibilities here + switch ($command) { + case self::QUERY_TYPE_BIND: + $this->_jabberId = $xml['iq'][0]['#']['bind'][0]['#']['jid'][0]['#']; + $this->trigger('loggedin'); + // and (maybe) yet another request to be able to send messages *finally* + if ($this->_session) { + $this->send(" + "); + + return $this->_response($this->wait()); + } + + return $this; + + case self::QUERY_TYPE_SESSION: + $this->trigger('session'); + return $this; + + case self::QUERY_TYPE_REGISTER: + $this->send("" . + htmlspecialchars($this->_user)."".htmlspecialchars($this->_pass) . + ""); + + return $this->_response($this->wait()); + + case self::QUERY_TYPE_REGISTERED: + // registration end + if (isset($xml['iq'][0]['#']['error'])) { + //'Warning: Registration failed.' + return $this; + } + + $this->trigger('registered'); + + return $this; + + case self::QUERY_TYPE_UNREGISTER: + $this->trigger('unregistered'); + return $this; + + case self::QUERY_TYPE_ROSTER: + if (!isset($xml['iq'][0]['#']['query'][0]['#']['item'])) { + //'Warning: No Roster Returned.' + $this->trigger('roster', array()); + return $this; + } + + $roster = array(); + foreach($xml['iq'][0]['#']['query'][0]['#']['item'] as $item) { + $jid = $item['@']['jid']; + $subscription = $item['@']['subscription']; + $roster[$jid] = $subscription; + } + + $this->trigger('roster', $roster); + break; + + case 'push': + if (!isset($xml['iq'][0]['#']['query'][0]['#']['item'][0]['@']['ask'])) { + //'Request for push denied.' + return $this; + } + + $attributes = $xml['iq'][0]['#']['query'][0]['#']['item'][0]['@']; + + if($attributes['ask'] == 'subscribe' + && strpos($this->_user.'@'.$this->_domain, $attributes['jid']) === false) { + $this->setPresence( + self::PRESENCE_CHAT, + self::ONLINE, + $attributes['jid'], + 'subscribed'); + + $this->setPresence( + self::PRESENCE_CHAT, + self::ONLINE, + $attributes['jid']); + } + + $this->trigger('subscribe', $attributes['ask'], $attributes['jid']); + break; + //'Notice: Received unexpected IQ.' + default: break; + } + + return $this; + } + + protected function _parseData($data) { + $data = explode(',', $data); + $pairs = array(); + $key = false; + + foreach ($data as $pair) { + $dd = strpos($pair, '='); + + if ($dd) { + $key = trim(substr($pair, 0, $dd)); + $pairs[$key] = trim(trim(substr($pair, $dd + 1)), '"'); + } else if (strpos(strrev(trim($pair)), '"') === 0 && $key) { + // We are actually having something left from "a, b" values, add it to the last one we handled. + $pairs[$key] .= ',' . trim(trim($pair), '"'); + continue; + } + } + + return $pairs; + } + + protected function _parseXml($data, $skip_white = 1, $encoding = 'UTF-8') { + $data = trim($data); + + //if the data does not start with an XML header + if (substr($data, 0, 5) != ''. $data . ''; + } + + $vals = $index = $array = array(); + + //parse xml to an array + $parser = xml_parser_create($encoding); + xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0); + xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, $skip_white); + xml_parse_into_struct($parser, $data, $vals, $index); + xml_parser_free($parser); + + $i = 0; + //get the tag name + $tagname = $vals[$i]['tag']; + + $array[$tagname][0]['@'] = (isset($vals[$i]['attributes'])) ? $vals[$i]['attributes'] : array(); + $array[$tagname][0]['#'] = $this->_getDepth($vals, $i); + + //if the data does not start with an XML header + if (substr($data, 0, 5) != ' ..., 'presence' => ...) + if (sizeof($xml) > 1) { + foreach ($xml as $key => $value) { + $this->_response(array($key => $value)); + } + + return $this; + // or even multiple elements of the same type? + // array('message' => array(0 => ..., 1 => ...)) + } else if (sizeof(reset($xml)) > 1) { + foreach (reset($xml) as $value) { + $this->_response(array(key($xml) => array(0 => $value))); + } + return $this; + } + + $command = key($xml); + + if(in_array($command, self::$_authentications)) { + return $this->_authenticate($command, $xml); + } + + if($command == 'iq') { + // we are not interested in IQs we did not expect + if (!isset($xml['iq'][0]['@']['id'])) { + return $this; + } + + $command = $xml['iq'][0]['@']['id']; + + return $this->_query($command, $xml); + } + + if($command == 'message') { + // we are only interested in content... + if (!isset($xml['message'][0]['#']['body'])) { + return $this; + } + + $from = $xml['message'][0]['@']['from']; + $to = $xml['message'][0]['@']['to']; + $body = $xml['message'][0]['#']['body'][0]['#']; + //sometimes the message received is that they are just fishing for who + //will respond we should notify them of our presence + //we will let whomever deal with this + $fishing = $to != $this->_jabberId; + + $subject = NULL; + if (isset($xml['message'][0]['#']['subject'])) { + $subject = $xml['message'][0]['#']['subject'][0]['#']; + } + + $thread = NULL; + if (isset($xml['message'][0]['#']['thread'])) { + $thread = $xml['message'][0]['#']['thread'][0]['#']; + } + + $this->trigger('message', $from, $body, $subject, $thread, $fishing); + + return $this; + } + } + + /* Private Methods + -------------------------------*/ +} + +/** + * XMPP/Jabber exception + */ +class Eden_Jabber_Error extends Eden_Error { + /* Constants + -------------------------------*/ + const CONNECTION_FAILED = 'Connection to %s on port %s failed'; + const NO_FEATURES = 'Error: No feature information from server available'; + const NOT_CONNECTED = 'Not connected'; + const NO_JID = 'No jid given.'; + const NO_AUTH_METHOD = 'No authentication method supported'; + const NO_SASL = 'Server does not offer SASL authentication'; + const SERVER_FAILED = 'Server sent a failiure message'; + const TLS_CHANGE_FAILED = 'TLS mode change failed'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i($message = NULL, $code = 0) { + $class = __CLASS__; + return new $class($message, $code); + } + + /* Public Methods + -------------------------------*/ + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/language.php b/library/eden/language.php new file mode 100644 index 0000000..3058f2f --- /dev/null +++ b/library/eden/language.php @@ -0,0 +1,245 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +require_once dirname(__FILE__).'/class.php'; + +/** + * Translator utility + * + * @package Eden + * @category utility + * @author Christian Blanquera cblanquera@openovate.com + */ +class Eden_Language extends Eden_Class implements ArrayAccess, Iterator { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_language = array(); + protected $_file = NULL; + + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + public function __construct($language = array()) { + Eden_Language_Error::i()->argument(1, 'file', 'array'); + + if(is_string($language)) { + $this->_file = $language; + $language = include($language); + } + + $this->_language = $language; + } + + /* Public Methods + -------------------------------*/ + /** + * Returns the current item + * For Iterator interface + * + * @return void + */ + public function current() { + return current($this->_language); + } + + /** + * Returns the translated key. + * if the key is not set it will set + * the key to the value of the key + * + * @param string + * @return string + */ + public function get($key) { + Eden_Language_Error::i()->argument(1, 'string'); + + if(!isset($this->_language[$key])) { + $this->_language[$key] = $key; + } + + return $this->_language[$key]; + } + + /** + * Return the language set + * + * @return array + */ + public function getLanguage() { + return $this->_language; + } + + /** + * Returns th current position + * For Iterator interface + * + * @return void + */ + public function key() { + return key($this->_language); + } + + /** + * Increases the position + * For Iterator interface + * + * @return void + */ + public function next() { + next($this->_language); + } + + /** + * isset using the ArrayAccess interface + * + * @param number + * @return bool + */ + public function offsetExists($offset) { + return isset($this->_language[$offset]); + } + + /** + * returns data using the ArrayAccess interface + * + * @param number + * @return bool + */ + public function offsetGet($offset) { + return $this->get($offset); + } + + /** + * Sets data using the ArrayAccess interface + * + * @param number + * @param mixed + * @return void + */ + public function offsetSet($offset, $value) { + $this->translate($offset, $value); + } + + /** + * unsets using the ArrayAccess interface + * + * @param number + * @return bool + */ + public function offsetUnset($offset) { + unset($this->_language[$offset]); + } + + /** + * Rewinds the position + * For Iterator interface + * + * @return void + */ + public function rewind() { + reset($this->_language); + } + + /** + * Saves the language to a file + * + * @param string|null + * @return this + */ + public function save($file = NULL) { + Eden_Language_Error::i()->argument(1, 'file', 'null'); + + if(is_null($file)) { + $file = $this->_file; + } + + if(is_null($file)) { + Eden_Language_Error::i() + ->setMessage(Eden_Language_Error::INVALID_ARGUMENT) + ->addVariable(1) + ->addVariable(__CLASS__.'->'.__FUNCTION__) + ->addVariable('file or null') + ->addVariable($file) + ->setTypeLogic() + ->trigger(); + } + + Eden_File::i($file)->setData($this->_language); + + return $this; + } + + /** + * Sets the translated value to the specified key + * + * @param string + * @param string + * @return this + */ + public function translate($key, $value) { + Eden_Language_Error::i() + ->argument(1, 'string') + ->argument(2, 'string'); + + $this->_language[$key] = $value; + + return $this; + } + + /** + * Validates whether if the index is set + * For Iterator interface + * + * @return void + */ + public function valid() { + return isset($this->_language[key($this->_language)]); + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} + +/** + * Language Errors + */ +class Eden_Language_Error extends Eden_Error { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i($message = NULL, $code = 0) { + $class = __CLASS__; + return new $class($message, $code); + } + + /* Public Methods + -------------------------------*/ + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/loader.php b/library/eden/loader.php new file mode 100755 index 0000000..f274998 --- /dev/null +++ b/library/eden/loader.php @@ -0,0 +1,121 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +require_once dirname(__FILE__).'/class.php'; + +/** + * Handler for class autoloading. Many developers writing + * object-oriented applications create one PHP source file per-class + * definition. One of the biggest annoyances is having to write a + * long list of needed includes at the beginning of each script + * (one for each class). When a class is not found an Autoload + * class is used to define how it is found. I have adopted Zend's + * autoloading logic where a class name with underscores is the actual + * location of that class if the underscores were replaced with foward + * slashes. For example: Eden_Cache_Model is located at eve/cache/model. + * + * @package Eden + * @category core + * @author Christian Blanquera cblanquera@openovate.com + */ +class Eden_Loader extends Eden_Class { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_root = array(); + + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getSingleton(__CLASS__); + } + + public function __construct($eden = true) { + if($eden) { + $this->addRoot(realpath(dirname(__FILE__).'/..')); + } + } + + public function __call($name, $args) { + //if the method name starts with a capital letter + //most likely they want a class + //since we are in the loader class + //we might as well try to load it + if(preg_match("/^[A-Z]/", $name)) { + $this->load($name); + } + + return parent::__call($name, $args); + } + + /* Public Methods + -------------------------------*/ + /** + * Allows extra paths to search in before looking in the root first + * + * @param *string the path + * @return Eden_Autoload + */ + public function addRoot($path) { + //add the absolute path + array_unshift($this->_root, $path); + + return $this; + } + + /** + * Logically includes a class if not included already. + * + * @param *string the class name + * @return bool + */ + public function handler($class) { + if(!is_string($class)) { + return false; + } + + $path = str_replace(array('_', '\\'), '/', $class); + $path = '/'.strtolower($path); + $path = str_replace('//', '/', $path); + + foreach($this->_root as $root) { + $file = $root.$path.'.php'; + + if(file_exists($file) && require_once($file)) { + //then we are done + return true; + } + } + + return false; + } + + /** + * Logically includes a class if not included already. + * + * @param *string the class name + * @return this + */ + public function load($class) { + if(!class_exists($class)) { + $this->handler($class); + } + return $this; + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/loop.php b/library/eden/loop.php new file mode 100644 index 0000000..5981554 --- /dev/null +++ b/library/eden/loop.php @@ -0,0 +1,91 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +require_once dirname(__FILE__).'/class.php'; + +/** + * Loops through returned result sets + * + * @package Eden + * @category core + * @author Christian Blanquera cblanquera@openovate.com + */ +class Eden_Loop extends Eden_Class { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_scope = NULL; + protected $_callback = NULL; + + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getSingleton(__CLASS__); + } + + public function __call($name, $args) { + //if the scope is null + if(is_null($this->_scope)) { + //just call the parent + return parent::__call($name, $args); + } + + //get the results from the method call + $results = $this->_getResults($name, $args); + + //lets make sure this is loopable + $loopable = is_scalar($results) ? array($results) : $results; + + //at this point we should loop through the results + foreach($loopable as $key => $value) { + call_user_func($this->_callback, $key, $value); + } + + //and return the results + return $results; + } + + /* Public Methods + -------------------------------*/ + /** + * Hijacks the class and loop through the results + * + * @param object + * @param callable + * @return this + */ + public function iterate($scope, $callback) { + Eden_Error::i() + ->argument(1, 'object') + ->argument(2, 'callable'); + + $this->_scope = $scope; + $this->_callback = $callback; + + return $this; + } + + /* Protected Methods + -------------------------------*/ + protected function _getResults($name, $args) { + if(method_exists($this->_scope, $name)) { + return call_user_func_array(array($this->_scope, $name), $args); + } + + return $this->_scope->__call($name, $args); + } + + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/mail.php b/library/eden/mail.php new file mode 100644 index 0000000..126cd33 --- /dev/null +++ b/library/eden/mail.php @@ -0,0 +1,102 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +require_once dirname(__FILE__).'/class.php'; +require_once dirname(__FILE__).'/mail/error.php'; +require_once dirname(__FILE__).'/mail/smtp.php'; +require_once dirname(__FILE__).'/mail/pop3.php'; +require_once dirname(__FILE__).'/mail/imap.php'; + +/** + * Mail API factory. This is a factory class with + * methods that will load up SMTP, IMAP, POP3 + * + * @package Eden + * @category mail + * @author Christian Blanquera cblanquera@openovate.com + */ +class Eden_Mail extends Eden_Class { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getSingleton(__CLASS__); + } + + /* Public Methods + -------------------------------*/ + /** + * Returns Mail IMAP + * + * @param string + * @param string + * @return Eden_Mail_Imap + */ + public function imap($host, $user, $pass, $port = NULL, $ssl = false, $tls = false) { + Eden_Mail_Error::i() + ->argument(1, 'string') + ->argument(2, 'string') + ->argument(3, 'string') + ->argument(4, 'int', 'null') + ->argument(5, 'bool') + ->argument(6, 'bool'); + + return Eden_Mail_Imap::i($host, $user, $pass, $port, $ssl, $tls); + } + + /** + * Returns Mail POP3 + * + * @param string + * @param string + * @return Eden_Mail_Pop3 + */ + public function pop3($host, $user, $pass, $port = NULL, $ssl = false, $tls = false) { + Eden_Mail_Error::i() + ->argument(1, 'string') + ->argument(2, 'string') + ->argument(3, 'string') + ->argument(4, 'int', 'null') + ->argument(5, 'bool') + ->argument(6, 'bool'); + + return Eden_Mail_Pop3::i($host, $user, $pass, $port, $ssl, $tls); + } + + /** + * Returns Mail SMTP + * + * @param string + * @param string + * @return Eden_Mail_Smtp + */ + public function smtp($host, $user, $pass, $port = NULL, $ssl = false, $tls = false) { + Eden_Mail_Error::i() + ->argument(1, 'string') + ->argument(2, 'string') + ->argument(3, 'string') + ->argument(4, 'int', 'null') + ->argument(5, 'bool') + ->argument(6, 'bool'); + + return Eden_Mail_Smtp::i($host, $user, $pass, $port, $ssl, $tls); + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/mail/error.php b/library/eden/mail/error.php new file mode 100644 index 0000000..cec9aaf --- /dev/null +++ b/library/eden/mail/error.php @@ -0,0 +1,45 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Mail exception + * + * @package Eden + * @category mail + * @author Christian Blanquera cblanquera@openovate.com + */ +class Eden_Mail_Error extends Eden_Error { + /* Constants + -------------------------------*/ + const SERVER_ERROR = 'Problem connecting to %s . Check server, port or ssl settings for your email server.'; + const LOGIN_ERROR = 'Your email provider has rejected your login information. Verify your email and/or password is correct.'; + const TLS_ERROR = 'Problem connecting to %s with TLS on.'; + const SMTP_ADD_EMAIL = 'Adding %s to email failed.'; + const SMTP_DATA = 'Server did not allow data to be added.'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i($message = NULL, $code = 0) { + $class = __CLASS__; + return new $class($message, $code); + } + + /* Public Methods + -------------------------------*/ + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/mail/imap.php b/library/eden/mail/imap.php new file mode 100644 index 0000000..a6298e1 --- /dev/null +++ b/library/eden/mail/imap.php @@ -0,0 +1,1099 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * General available methods for common IMAP functionality + * + * @package Eden + * @category mail + * @author Christian Blanquera cblanquera@openovate.com + */ +class Eden_Mail_Imap extends Eden_Class { + /* Constants + -------------------------------*/ + const TIMEOUT = 30; + const NO_SUBJECT = '(no subject)'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_host = NULL; + protected $_port = NULL; + protected $_ssl = false; + protected $_tls = false; + + protected $_username = NULL; + protected $_password = NULL; + + protected $_tag = 0; + protected $_total = 0; + protected $_buffer = NULL; + protected $_socket = NULL; + protected $_mailbox = NULL; + protected $_mailboxes = array(); + + /* Private Properties + -------------------------------*/ + private $_debugging = false; + + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + public function __construct($host, $user, $pass, $port = NULL, $ssl = false, $tls = false) { + Eden_Mail_Error::i() + ->argument(1, 'string') + ->argument(2, 'string') + ->argument(3, 'string') + ->argument(4, 'int', 'null') + ->argument(5, 'bool') + ->argument(6, 'bool'); + + if (is_null($port)) { + $port = $ssl ? 993 : 143; + } + + $this->_host = $host; + $this->_username = $user; + $this->_password = $pass; + $this->_port = $port; + $this->_ssl = $ssl; + $this->_tls = $tls; + } + + /* Public Methods + -------------------------------*/ + /** + * Connects to the server + * + * @return this + */ + public function connect($timeout = self::TIMEOUT, $test = false) { + Eden_Mail_Error::i()->argument(1, 'int')->argument(2, 'bool'); + + if($this->_socket) { + return $this; + } + + $host = $this->_host; + + if ($this->_ssl) { + $host = 'ssl://' . $host; + } + + $errno = 0; + $errstr = ''; + + $this->_socket = @fsockopen($host, $this->_port, $errno, $errstr, $timeout); + + if (!$this->_socket) { + //throw exception + Eden_Mail_Error::i() + ->setMessage(Eden_Mail_Error::SERVER_ERROR) + ->addVariable($host.':'.$this->_port) + ->trigger(); + } + + if (strpos($this->_getLine(), '* OK') === false) { + $this->disconnect(); + //throw exception + Eden_Mail_Error::i() + ->setMessage(Eden_Mail_Error::SERVER_ERROR) + ->addVariable($host.':'.$this->_port) + ->trigger(); + } + + if ($this->_tls) { + $this->_send('STARTTLS'); + if (!stream_socket_enable_crypto($this->_socket, true, STREAM_CRYPTO_METHOD_TLS_CLIENT)) { + $this->disconnect(); + //throw exception + Eden_Mail_Error::i() + ->setMessage(Eden_Mail_Error::TLS_ERROR) + ->addVariable($host.':'.$this->_port) + ->trigger(); + } + } + + if($test) { + fclose($this->_socket); + + $this->_socket = NULL; + return $this; + } + + //login + $result = $this->_call('LOGIN', $this->_escape($this->_username, $this->_password)); + + if(strpos(implode(' ', $result), 'OK') === false) { + $this->disconnect(); + //throw exception + Eden_Mail_Error::i(Eden_Mail_Error::LOGIN_ERROR)->trigger(); + } + + return $this; + } + + /** + * Disconnects from the server + * + * @return this + */ + public function disconnect() { + if ($this->_socket) { + $this->_send('LOGOUT'); + + fclose($this->_socket); + + $this->_socket = NULL; + } + + return $this; + } + + /** + * Returns the active mailbox + * + * @return string + */ + public function getActiveMailbox() { + return $this->_mailbox; + } + + /** + * Returns a list of emails given the range + * + * @param number start + * @param number range + * @param bool add threads + * @return array + */ + public function getEmails($start = 0, $range = 10) { + Eden_Mail_Error::i() + ->argument(1, 'int', 'array') + ->argument(2, 'int'); + + //if not connected + if(!$this->_socket) { + //then connect + $this->connect(); + } + + //if the total in this mailbox is 0 + //it means they probably didn't select a mailbox + //or the mailbox selected is empty + if($this->_total == 0) { + //we might as well return an empty array + return array(); + } + + //if start is an array + if (is_array($start)) { + //it is a set of numbers + $set = implode(',', $start); + //just ignore the range parameter + //start is a number + } else { + //range must be grater than 0 + $range = $range > 0 ? $range : 1; + //start must be a positive number + $start = $start >= 0 ? $start : 0; + + //calculate max (ex. 300 - 4 = 296) + $max = $this->_total - $start; + + //if max is less than 1 + if($max < 1) { + //set max to total (ex. 300) + $max = $this->_total; + } + + //calculate min (ex. 296 - 15 + 1 = 282) + $min = $max - $range + 1; + + //if min less than 1 + if($min < 1) { + //set it to 1 + $min = 1; + } + + //now add min and max to set (ex. 282:296 or 1 - 300) + $set = $min . ':' . $max; + + //if min equal max + if($min == $max) { + //we should only get one number + $set = $min; + } + } + + $items = array('UID', 'FLAGS', 'BODY[HEADER]'); + + //now lets call this + $emails = $this->_getEmailResponse('FETCH', array($set, $this->_getList($items))); + + //this will be in ascending order + //we actually want to reverse this + $emails = array_reverse($emails); + + return $emails; + } + + /** + * Returns the total number of emails in a mailbox + * + * @return number + */ + public function getEmailTotal() { + return $this->_total; + } + + /** + * Returns a list of mailboxes + * + * @return array + */ + public function getMailboxes() { + if(!$this->_socket) { + $this->connect(); + } + + $response = $this->_call('LIST', $this->_escape('', '*')); + + $mailboxes = array(); + foreach($response as $line) { + if (strpos($line, 'Noselect') !== false || strpos($line, 'LIST') == false) { + continue; + } + + $line = explode('"', $line); + + if(strpos(trim($line[0]), '*') !== 0 ) { + continue; + } + + $mailboxes[] = $line[count($line)-2]; + } + + return $mailboxes; + } + + /** + * Returns a list of emails given a uid or set of uids + * + * @param number|array uid/s + * @return array + */ + public function getUniqueEmails($uid, $body = false) { + Eden_Mail_Error::i() + ->argument(1, 'int', 'string', 'array') + ->argument(2, 'bool'); + //if not connected + if(!$this->_socket) { + //then connect + $this->connect(); + } + + //if the total in this mailbox is 0 + //it means they probably didn't select a mailbox + //or the mailbox selected is empty + if($this->_total == 0) { + //we might as well return an empty array + return array(); + } + + //if uid is an array + if (is_array($uid)) { + $uid = implode(',', $uid); + } + + //lets call it + $items = array('UID', 'FLAGS', 'BODY[HEADER]'); + + if($body) { + $items = array('UID', 'FLAGS', 'BODY[]'); + } + + $first = is_numeric($uid) ? true : false; + return $this->_getEmailResponse('UID FETCH', array($uid, $this->_getList($items)), $first); + } + + /** + * Moves an email to another mailbox + * + * @param number uid + * @param string mailbox + * @return this + */ + public function move($uid, $mailbox) { + Eden_Mail_Error::i()->argument(1, 'int', 'string')->argument(2, 'string'); + if(!$this->_socket) { + $this->connect(); + } + + if(!is_array($uid)) { + $uid = array($uid); + } + + $this->_call('UID COPY '.implode(',', $uid).' '.$mailbox); + + return $this->remove($uid); + } + + /** + * Remove an email from a mailbox + * + * @param number uid + * @return this + */ + public function remove($uid) { + Eden_Mail_Error::i()->argument(1, 'int', 'string'); + + if(!$this->_socket) { + $this->connect(); + } + + if(!is_array($uid)) { + $uid = array($uid); + } + + $this->_call('UID STORE '.implode(',', $uid).' FLAGS.SILENT \Deleted'); + + return $this; + } + + /** + * Searches a mailbox for specific emails + * + * @param array filter + * @param string sort + * @param string order ASC|DESC + * @param number start + * @param number range + * @param bool or search? + * @return array + */ + public function search(array $filter, $start = 0, $range = 10, $or = false, $body = false) { + Eden_Mail_Error::i() + ->argument(2, 'int') + ->argument(3, 'int') + ->argument(4, 'bool') + ->argument(5, 'bool'); + + if(!$this->_socket) { + $this->connect(); + } + + //build a search criteria + $search = $not = array(); + foreach($filter as $where) { + if(is_string($where)) { + $search[] = $where; + continue; + } + + if($where[0] == 'NOT') { + $not = $where[1]; + continue; + } + + $item = $where[0].' "'.$where[1].'"'; + if(isset($where[2])) { + $item .= ' "'.$where[2].'"'; + } + + $search[] = $item; + } + + //if this is an or search + if($or && count($search) > 1) { + //item1 + //OR (item1) (item2) + //OR (item1) (OR (item2) (item3)) + //OR (item1) (OR (item2) (OR (item3) (item4))) + $query = NULL; + while($item = array_pop($search)) { + if(is_null($query)) { + $query = $item; + } else if(strpos($query, 'OR') !== 0) { + $query = 'OR ('.$query.') ('.$item.')'; + } else { + $query = 'OR ('.$item.') ('.$query.')'; + } + } + $search = $query; + //this is an and search + } else { + $search = implode(' ', $search); + } + + //do the search + $response = $this->_call('UID SEARCH '.$search); + + //get the result + $result = array_pop($response); + //if we got some results + if(strpos($result, 'OK') !== false) { + //parse out the uids + $uids = explode(' ', $response[0]); + array_shift($uids); + array_shift($uids); + + foreach($uids as $i => $uid) { + if(in_array($uid, $not)) { + unset($uids[$i]); + } + } + + if(empty($uids)) { + return array(); + } + + $uids = array_reverse($uids); + + //pagination + $count = 0; + foreach($uids as $i => $id) { + if($i < $start) { + unset($uids[$i]); + continue; + } + + $count ++; + + if($range != 0 && $count > $range) { + unset($uids[$i]); + continue; + } + } + + //return the email details for this + return $this->getUniqueEmails($uids, $body); + } + + //it's not okay just return an empty set + return array(); + } + + /** + * Returns the total amount of emails + * + * @param array filter + * @return number + */ + public function searchTotal(array $filter, $or = false) { + Eden_Mail_Error::i()->argument(2, 'bool'); + + if(!$this->_socket) { + $this->connect(); + } + + //build a search criteria + $search = array(); + foreach($filter as $where) { + $item = $where[0].' "'.$where[1].'"'; + if(isset($where[2])) { + $item .= ' "'.$where[2].'"'; + } + + $search[] = $item; + } + + //if this is an or search + if($or) { + $search = 'OR ('.implode(') (', $search).')'; + //this is an and search + } else { + $search = implode(' ', $search); + } + + $response = $this->_call('UID SEARCH '.$search); + + //get the result + $result = array_pop($response); + + //if we got some results + if(strpos($result, 'OK') !== false) { + //parse out the uids + $uids = explode(' ', $response[0]); + array_shift($uids); + array_shift($uids); + + return count($uids); + } + + //it's not okay just return 0 + return 0; + } + + /** + * IMAP requires setting an active mailbox + * before getting a list of mails + * + * @param string name of mailbox + * @return false|this + */ + public function setActiveMailbox($mailbox) { + Eden_Mail_Error::i()->argument(1, 'string'); + + if(!$this->_socket) { + $this->connect(); + } + + $response = $this->_call('SELECT', $this->_escape($mailbox)); + $result = array_pop($response); + + foreach($response as $line) { + if(strpos($line, 'EXISTS') !== false) { + list($star, $this->_total, $type) = explode(' ', $line, 3); + break; + } + } + + if(strpos($result, 'OK') !== false) { + $this->_mailbox = $mailbox; + + return $this; + } + + return false; + } + + /* Protected Methods + -------------------------------*/ + protected function _call($command, $parameters = array()) { + if(!$this->_send($command, $parameters)) { + return false; + } + + return $this->_receive($this->_tag); + } + + protected function _getLine() { + $line = fgets($this->_socket); + + if($line === false) { + $this->disconnect(); + } + + $this->_debug('Receiving: '.$line); + + return $line; + } + + protected function _receive($sentTag) { + $this->_buffer = array(); + + $start = time(); + + while (time() < ($start + self::TIMEOUT)) { + list($receivedTag, $line) = explode(' ', $this->_getLine(), 2); + $this->_buffer[] = trim($receivedTag . ' ' . $line); + if($receivedTag == 'TAG'.$sentTag) { + return $this->_buffer; + } + + } + + return NULL; + } + + protected function _send($command, $parameters = array()) { + $this->_tag ++; + + $line = 'TAG' . $this->_tag . ' ' . $command; + + if(!is_array($parameters)) { + $parameters = array($parameters); + } + + foreach ($parameters as $parameter) { + if (is_array($parameter)) { + if (fputs($this->_socket, $line . ' ' . $parameter[0] . "\r\n") === false) { + return false; + } + + if (strpos($this->_getLine(), '+ ') === false) { + return false; + } + + $line = $parameter[1]; + } else { + $line .= ' ' . $parameter; + } + } + + $this->_debug('Sending: '.$line); + + return fputs($this->_socket, $line . "\r\n"); + } + + + /* Private Methods + -------------------------------*/ + private function _debug($string) { + if($this->_debugging) { + $string = htmlspecialchars($string); + + + echo '
'.$string.'
'."\n"; + } + return $this; + } + + private function _escape($string) { + if (func_num_args() < 2) { + if (strpos($string, "\n") !== false) { + return array('{' . strlen($string) . '}', $string); + } else { + return '"' . str_replace(array('\\', '"'), array('\\\\', '\\"'), $string) . '"'; + } + } + $result = array(); + foreach (func_get_args() as $string) { + $result[] = $this->_escape($string); + } + return $result; + } + + private function _getEmailFormat($email, $uniqueId = NULL, array $flags = array()) { + //if email is an array + if(is_array($email)) { + //make it into a string + $email = implode("\n", $email); + } + + //split the head and the body + $parts = preg_split("/\n\s*\n/", $email, 2); + + $head = $parts[0]; + $body = NULL; + if(isset($parts[1]) && trim($parts[1]) != ')') { + $body = $parts[1]; + } + + $lines = explode("\n", $head); + $head = array(); + foreach($lines as $line) { + if(trim($line) && preg_match("/^\s+/", $line)) { + $head[count($head)-1] .= ' '.trim($line); + continue; + } + + $head[] = trim($line); + } + + $head = implode("\n", $head); + + $recipientsTo = $recipientsCc = $recipientsBcc = $sender = array(); + + //get the headers + $headers1 = imap_rfc822_parse_headers($head); + $headers2 = $this->_getHeaders($head); + + //set the from + $sender['name'] = NULL; + if(isset($headers1->from[0]->personal)) { + $sender['name'] = $headers1->from[0]->personal; + //if the name is iso or utf encoded + if(preg_match("/^\=\?[a-zA-Z]+\-[0-9]+.*\?/", strtolower($sender['name']))) { + //decode the subject + $sender['name'] = str_replace('_', ' ', mb_decode_mimeheader($sender['name'])); + } + } + + $sender['email'] = $headers1->from[0]->mailbox . '@' . $headers1->from[0]->host; + + //set the to + if(isset($headers1->to)) { + foreach($headers1->to as $to) { + if(!isset($to->mailbox, $to->host)) { + continue; + } + + $recipient = array('name'=>NULL); + if(isset($to->personal)) { + $recipient['name'] = $to->personal; + //if the name is iso or utf encoded + if(preg_match("/^\=\?[a-zA-Z]+\-[0-9]+.*\?/", strtolower($recipient['name']))) { + //decode the subject + $recipient['name'] = str_replace('_', ' ', mb_decode_mimeheader($recipient['name'])); + } + } + + $recipient['email'] = $to->mailbox . '@' . $to->host; + + $recipientsTo[] = $recipient; + } + } + + //set the cc + if(isset($headers1->cc)) { + foreach($headers1->cc as $cc) { + $recipient = array('name'=>NULL); + if(isset($cc->personal)) { + $recipient['name'] = $cc->personal; + + //if the name is iso or utf encoded + if(preg_match("/^\=\?[a-zA-Z]+\-[0-9]+.*\?/", strtolower($recipient['name']))) { + //decode the subject + $recipient['name'] = str_replace('_', ' ', mb_decode_mimeheader($recipient['name'])); + } + } + + $recipient['email'] = $cc->mailbox . '@' . $cc->host; + + $recipientsCc[] = $recipient; + } + } + + //set the bcc + if(isset($headers1->bcc)) { + foreach($headers1->bcc as $bcc) { + $recipient = array('name'=>NULL); + if(isset($bcc->personal)) { + $recipient['name'] = $bcc->personal; + //if the name is iso or utf encoded + if(preg_match("/^\=\?[a-zA-Z]+\-[0-9]+.*\?/", strtolower($recipient['name']))) { + //decode the subject + $recipient['name'] = str_replace('_', ' ', mb_decode_mimeheader($recipient['name'])); + } + } + + $recipient['email'] = $bcc->mailbox . '@' . $bcc->host; + + $recipientsBcc[] = $recipient; + } + } + + //if subject is not set + if(!isset( $headers1->subject ) || strlen(trim($headers1->subject)) === 0) { + //set subject + $headers1->subject = self::NO_SUBJECT; + } + + //trim the subject + $headers1->subject = str_replace(array('<', '>'), '', trim($headers1->subject)); + + //if the subject is iso or utf encoded + if(preg_match("/^\=\?[a-zA-Z]+\-[0-9]+.*\?/", strtolower($headers1->subject))) { + //decode the subject + $headers1->subject = str_replace('_', ' ', mb_decode_mimeheader($headers1->subject)); + } + + //set thread details + $topic = isset($headers2['thread-topic']) ? $headers2['thread-topic'] : $headers1->subject; + $parent = isset($headers2['in-reply-to']) ? str_replace('"', '', $headers2['in-reply-to']) : NULL; + + //set date + $date = isset($headers1->date) ? strtotime($headers1->date) : NULL; + + //set message id + if(isset($headers2['message-id'])) { + $messageId = str_replace('"', '', $headers2['message-id']); + } else { + $messageId = ''; + } + + $attachment = isset($headers2['content-type']) && strpos($headers2['content-type'], 'multipart/mixed') === 0; + + $format = array( + 'id' => $messageId, + 'parent' => $parent, + 'topic' => $topic, + 'mailbox' => $this->_mailbox, + 'uid' => $uniqueId, + 'date' => $date, + 'subject' => str_replace('’', '\'', $headers1->subject), + 'from' => $sender, + 'flags' => $flags, + 'to' => $recipientsTo, + 'cc' => $recipientsCc, + 'bcc' => $recipientsBcc, + 'attachment' => $attachment); + + if(trim($body) && $body != ')') { + //get the body parts + $parts = $this->_getParts($email); + + //if there are no parts + if(empty($parts)) { + //just make the body as a single part + $parts = array('text/plain' => $body); + } + + //set body to the body parts + $body = $parts; + + //look for attachments + $attachment = array(); + //if there is an attachment in the body + if(isset($body['attachment'])) { + //take it out + $attachment = $body['attachment']; + unset($body['attachment']); + } + + $format['body'] = $body; + $format['attachment'] = $attachment; + } + + return $format; + } + + private function _getEmailResponse($command, $parameters = array(), $first = false) { + //send out the command + if(!$this->_send($command, $parameters)) { + return false; + } + + $messageId = $uniqueId = $count = 0; + $emails = $email = array(); + $start = time(); + + //while there is no hang + while (time() < ($start + self::TIMEOUT)) { + //get a response line + $line = str_replace("\n", '', $this->_getLine()); + + //if the line starts with a fetch + //it means it's the end of getting an email + if(strpos($line, 'FETCH') !== false && strpos($line, 'TAG'.$this->_tag) === false) { + //if there is email data + if(!empty($email)) { + //create the email format and add it to emails + $emails[$uniqueId] = $this->_getEmailFormat($email, $uniqueId, $flags); + + //if all we want is the first one + if($first) { + //just return this + return $emails[$uniqueId]; + } + + //make email data empty again + $email = array(); + } + + //if just okay + if(strpos($line, 'OK') !== false) { + //then skip the rest + continue; + } + + //if it's not just ok + //it will contain the message id and the unique id and flags + $flags = array(); + if(strpos($line, '\Answered' ) !== false) { + $flags[] = 'answered'; + } + + if(strpos($line, '\Flagged' ) !== false) { + $flags[] = 'flagged'; + } + + if(strpos($line, '\Deleted' ) !== false) { + $flags[] = 'deleted'; + } + + if(strpos($line, '\Seen' ) !== false) { + $flags[] = 'seen'; + } + + if(strpos($line, '\Draft' ) !== false) { + $flags[] = 'draft'; + } + + $findUid = explode(' ', $line); + foreach($findUid as $i => $uid) { + if(is_numeric($uid)) { + $uniqueId = $uid; + } + if(strpos(strtolower($uid), 'uid') !== false) { + $uniqueId = $findUid[$i+1]; + break; + } + } + + //skip the rest + continue; + } + + //if there is a tag it means we are at the end + if(strpos($line, 'TAG'.$this->_tag) !== false) { + + //if email details are not empty and the last line is just a ) + if(!empty($email) && strpos(trim($email[count($email) -1]), ')') === 0) { + //take it out because that is not part of the details + array_pop($email); + } + + //if there is email data + if(!empty($email)) { + //create the email format and add it to emails + $emails[$uniqueId] = $this->_getEmailFormat($email, $uniqueId, $flags); + + //if all we want is the first one + if($first) { + //just return this + return $emails[$uniqueId]; + } + } + + //break out of this loop + break; + } + + //so at this point we are getting raw data + //capture this data in email details + $email[] = $line; + } + + return $emails; + } + + private function _getHeaders($rawData) { + if(is_string($rawData)) { + $rawData = explode("\n", $rawData); + } + + $key = NULL; + $headers = array(); + foreach($rawData as $line) { + $line = trim($line); + if(preg_match("/^([a-zA-Z0-9-]+):/i", $line, $matches)) { + $key = strtolower($matches[1]); + if(isset($headers[$key])) { + if(!is_array($headers[$key])) { + $headers[$key] = array($headers[$key]); + } + + $headers[$key][] = trim(str_replace($matches[0], '', $line)); + continue; + } + + $headers[$key] = trim(str_replace($matches[0], '', $line)); + continue; + } + + if(!is_null($key) && isset($headers[$key])) { + if(is_array($headers[$key])) { + $headers[$key][count($headers[$key])-1] .= ' '.$line; + continue; + } + + $headers[$key] .= ' '.$line; + } + } + + return $headers; + } + + private function _getList($array) { + $list = array(); + foreach ($array as $key => $value) { + $list[] = !is_array($value) ? $value : $this->_getList($v); + } + return '(' . implode(' ', $list) . ')'; + } + + private function _getParts($content, array $parts = array()) { + //separate the head and the body + list($head, $body) = preg_split("/\n\s*\n/", $content, 2); + //front()->output($head); + //get the headers + $head = $this->_getHeaders($head); + //if content type is not set + if(!isset($head['content-type'])) { + return $parts; + } + + //split the content type + if(is_array($head['content-type'])) { + $type = array($head['content-type'][1]); + if(strpos($type[0], ';') !== false) { + $type = explode(';', $type[0], 2); + } + } else { + $type = explode(';', $head['content-type'], 2); + } + + //see if there are any extra stuff + $extra = array(); + if(count($type) == 2) { + $extra = explode('; ', str_replace(array('"', "'"), '', trim($type[1]))); + } + + //the content type is the first part of this + $type = trim($type[0]); + + + //foreach extra + foreach($extra as $i => $attr) { + //transform the extra array to a key value pair + $attr = explode('=', $attr, 2); + if(count($attr) > 1) { + list($key, $value) = $attr; + $extra[$key] = $value; + } + unset($extra[$i]); + } + + //if a boundary is set + if(isset($extra['boundary'])) { + //split the body into sections + $sections = explode('--'.str_replace(array('"', "'"), '', $extra['boundary']), $body); + //we only want what's in the middle of these sections + array_pop($sections); + array_shift($sections); + + //foreach section + foreach($sections as $section) { + //get the parts of that + $parts = $this->_getParts($section, $parts); + } + //if name is set, it's an attachment + } else { + + //if encoding is set + if(isset($head['content-transfer-encoding'])) { + //the goal here is to make everytihg utf-8 standard + switch(strtolower($head['content-transfer-encoding'])) { + case 'binary': + $body = imap_binary($body); + case 'base64': + $body = base64_decode($body); + break; + case 'quoted-printable': + $body = quoted_printable_decode($body); + break; + case '7bit': + $body = mb_convert_encoding ($body, 'UTF-8', 'ISO-2022-JP'); + break; + default: + $body = str_replace(array("\n", ' '), '', $body); + break; + } + } + + if(isset($extra['name'])) { + //add to parts + $parts['attachment'][$extra['name']][$type] = $body; + //it's just a regular body + } else { + //add to parts + $parts[$type] = $body; + } + } + return $parts; + } + +} \ No newline at end of file diff --git a/library/eden/mail/pop3.php b/library/eden/mail/pop3.php new file mode 100644 index 0000000..a9263c9 --- /dev/null +++ b/library/eden/mail/pop3.php @@ -0,0 +1,304 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * General available methods for common POP3 functionality + * + * @package Eden + * @category mail + * @author Christian Blanquera cblanquera@openovate.com + */ +class Eden_Mail_Pop3 extends Eden_Class { + /* Constants + -------------------------------*/ + const TIMEOUT = 30; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_host = NULL; + protected $_port = NULL; + protected $_ssl = false; + protected $_tls = false; + + protected $_username = NULL; + protected $_password = NULL; + protected $_timestamp = NULL; + + protected $_socket = NULL; + + /* Private Properties + -------------------------------*/ + private $_debugging = false; + + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + public function __construct($host, $user, $pass, $port = NULL, $ssl = false, $tls = false) { + Eden_Mail_Error::i() + ->argument(1, 'string') + ->argument(2, 'string') + ->argument(3, 'string') + ->argument(4, 'int', 'null') + ->argument(5, 'bool') + ->argument(6, 'bool'); + + if (is_null($port)) { + $port = $ssl ? 995 : 110; + } + + $this->_host = $host; + $this->_username = $user; + $this->_password = $pass; + $this->_port = $port; + $this->_ssl = $ssl; + $this->_tls = $tls; + + $this->_connect(); + } + + /* Public Methods + -------------------------------*/ + /** + * Connects to the server + * + * @return this + */ + public function connect($test = false) { + Eden_Mail_Error::i()->argument(1, 'bool'); + + if($this->_loggedin) { + return $this; + } + + $host = $this->_host; + + if ($this->_ssl) { + $host = 'ssl://' . $host; + } + + $errno = 0; + $errstr = ''; + + $this->_socket = fsockopen($host, $this->_port, $errno, $errstr, self::TIMEOUT); + + if (!$this->_socket) { + //throw exception + Eden_Mail_Error::get()->setMessage(Eden_Mail_Error::SERVER_ERROR) + ->addVariable($host.':'.$this->_port) + ->trigger(); + } + + $welcome = $this->_receive(); + + strtok($welcome, '<'); + $this->_timestamp = strtok('>'); + if (!strpos($this->_timestamp, '@')) { + $this->_timestamp = null; + } else { + $this->_timestamp = '<' . $this->_timestamp . '>'; + } + + if ($this->_tls) { + $this->_call('STLS'); + if (!stream_socket_enable_crypto($this->_socket, true, STREAM_CRYPTO_METHOD_TLS_CLIENT)) { + $this->disconnect(); + //throw exception + Eden_Mail_Error::get()->setMessage(Eden_Mail_Exception::TLS_ERROR) + ->addVariable($host.':'.$this->_port) + ->trigger(); + } + } + + //login + if ($this->_timestamp) { + try { + $this->_call('APOP '.$this->_username .' ' . md5($this->_timestamp . $this->_password)); + return; + } catch (Exception $e) { + // ignore + } + } + + $this->_call('USER '.$this->_username); + $this->_call('PASS '.$this->_password); + + return $this; + } + + /** + * Disconnects from the server + * + * @return this + */ + public function disconnect() { + if (!$this->_socket) { + return; + } + + try { + $this->request('QUIT'); + } catch (Exception $e) { + // ignore error - we're closing the socket anyway + } + + fclose($this->_socket); + $this->_socket = NULL; + } + + /** + * Returns a list of emails given the range + * + * @param number start + * @param number range + * @return array + */ + public function getEmails($start = 0, $range = 10) { + Eden_Mail_Error::i() + ->argument(1, 'int') + ->argument(2, 'int'); + + $total = $this->getEmailTotal(); + $total = $total['messages']; + + if($total == 0) { + return array(); + } + + if (!is_array($start)) { + $range = $range > 0 ? $range : 1; + $start = $start >= 0 ? $start : 0; + $max = $total - $start; + + if($max < 1) { + $max = $total; + } + + $min = $max - $range + 1; + + if($min < 1) { + $min = 1; + } + + $set = $min . ':' . $max; + + if($min == $max) { + $set = $min; + } + } + + + $emails = array(); + for($i = $min; $i <= $max; $i++) { + $emails[] = $this->_call('RETR '.$i, true); + } + + return $emails; + } + + /** + * Returns the total number of emails in a mailbox + * + * @return number + */ + public function getEmailTotal() { + list($messages, $octets) = explode(' ', $this->_call('STAT')); + + return array('messages' => $messages, 'octets' => $octets); + } + + /** + * Remove an email from a mailbox + * + * @param number uid + * @param string mailbox + * @return this + */ + public function remove($msgno) { + Eden_Mail_Error::i()->argument(1, 'int', 'string'); + + $this->_call("DELE $msgno"); + + if(!$this->_loggedin || !$this->_socket) { + return false; + } + + if(!is_array($msgno)) { + $msgno = array($msgno); + } + + foreach($msgno as $number) { + $this->_call('DELE '.$number); + + } + + return $this; + } + + /* Protected Methods + -------------------------------*/ + protected function _call($command, $multiline = false) { + if(!$this->_send($command)) { + return false; + } + + return $this->_receive($multiline); + } + + protected function _receive($multiline = false) { + $result = @fgets($this->_socket); + $status = $result = trim($result); + $message = ''; + + if (strpos($result, ' ')) { + list($status, $message) = explode(' ', $result, 2); + } + + if ($status != '+OK') { + return false; + } + + if ($multiline) { + $message = ''; + $line = fgets($this->_socket); + while ($line && rtrim($line, "\r\n") != '.') { + if ($line[0] == '.') { + $line = substr($line, 1); + } + $this->_debug('Receiving: '.$line); + $message .= $line; + $line = fgets($this->_socket); + }; + } + + return $message; + } + + protected function _send($command) { + + $this->_debug('Sending: '.$command); + + return fputs($this->_socket, $command . "\r\n"); + } + /* Private Methods + -------------------------------*/ + private function _debug($string) { + if($this->_debugging) { + $string = htmlspecialchars($string); + + + echo '
'.$string.'
'."\n"; + } + return $this; + } +} \ No newline at end of file diff --git a/library/eden/mail/smtp.php b/library/eden/mail/smtp.php new file mode 100644 index 0000000..06b6a75 --- /dev/null +++ b/library/eden/mail/smtp.php @@ -0,0 +1,795 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * General available methods for common SMTP functionality + * + * @package Eden + * @cateogry mail + * @author Christian Blanquera cblanquera@openovate.com + */ +class Eden_Mail_Smtp extends Eden_Class { + /* Constants + -------------------------------*/ + const TIMEOUT = 30; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_host = NULL; + protected $_port = NULL; + protected $_ssl = false; + protected $_tls = false; + + protected $_username = NULL; + protected $_password = NULL; + + protected $_socket = NULL; + protected $_boundary = array(); + + protected $_subject = NULL; + protected $_body = array(); + + protected $_to = array(); + protected $_cc = array(); + protected $_bcc = array(); + protected $_attachments = array(); + + /* Private Properties + -------------------------------*/ + private $_debugging = false; + + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + public function __construct($host, $user, $pass, $port = NULL, $ssl = false, $tls = false) { + Eden_Mail_Error::i() + ->argument(1, 'string') + ->argument(2, 'string') + ->argument(3, 'string') + ->argument(4, 'int', 'null') + ->argument(5, 'bool') + ->argument(6, 'bool'); + + if (is_null($port)) { + $port = $ssl ? 465 : 25; + } + + $this->_host = $host; + $this->_username = $user; + $this->_password = $pass; + $this->_port = $port; + $this->_ssl = $ssl; + $this->_tls = $tls; + + $this->_boundary[] = md5(time().'1'); + $this->_boundary[] = md5(time().'2'); + } + + /* Public Methods + -------------------------------*/ + + /** + * Adds an attachment to the email + * + * @param string filename + * @param string data + * @param string mime + * @return this + */ + public function addAttachment($filename, $data, $mime = NULL) { + Eden_Mail_Error::i() + ->argument(1, 'string') + ->argument(2, 'string') + ->argument(3, 'string', 'null'); + + $this->_attachments[] = array($filename, $data, $mime); + return $this; + } + + /** + * Adds an email to the bcc list + * + * @param string email + * @param string name + * @return this + */ + public function addBCC($email, $name = NULL) { + Eden_Mail_Error::i() + ->argument(1, 'string') + ->argument(2, 'string', 'null'); + + $this->_bcc[$email] = $name; + return $this; + } + + /** + * Adds an email to the cc list + * + * @param string email + * @param string name + * @return this + */ + public function addCC($email, $name = NULL) { + Eden_Mail_Error::i() + ->argument(1, 'string') + ->argument(2, 'string', 'null'); + + $this->_cc[$email] = $name; + return $this; + } + + /** + * Adds an email to the to list + * + * @param string email + * @param string name + * @return this + */ + public function addTo($email, $name = NULL) { + Eden_Mail_Error::i() + ->argument(1, 'string') + ->argument(2, 'string', 'null'); + + $this->_to[$email] = $name; + return $this; + } + + /** + * Connects to the server + * + * @return this + */ + public function connect($timeout = self::TIMEOUT, $test = false) { + Eden_Mail_Error::i() + ->argument(1, 'int') + ->argument(2, 'bool'); + + $host = $this->_host; + + if ($this->_ssl) { + $host = 'ssl://' . $host; + } else { + $host = 'tcp://' . $host; + } + + $errno = 0; + $errstr = ''; + $this->_socket = @stream_socket_client($host.':'.$this->_port, $errno, $errstr, $timeout); + + if (!$this->_socket || strlen($errstr) > 0 || $errno > 0) { + //throw exception + Eden_Mail_Error::get() + ->setMessage(Eden_Mail_Error::SERVER_ERROR) + ->addVariable($host.':'.$this->_port) + ->trigger(); + } + + $this->_receive(); + + if(!$this->_call('EHLO '.$_SERVER['HTTP_HOST'], 250) && !$this->_call('HELO '.$_SERVER['HTTP_HOST'], 250)) { + $this->disconnect(); + //throw exception + Eden_Mail_Error::get() + ->setMessage(Eden_Mail_Error::SERVER_ERROR) + ->addVariable($host.':'.$this->_port) + ->trigger(); + } +; + if ($this->_tls && !$this->_call('STARTTLS', 220, 250)) { + if(!stream_socket_enable_crypto($this->_socket, true, STREAM_CRYPTO_METHOD_TLS_CLIENT)) { + $this->disconnect(); + //throw exception + Eden_Mail_Error::get() + ->setMessage(Eden_Mail_Error::TLS_ERROR) + ->addVariable($host.':'.$this->_port) + ->trigger(); + } + + if(!$this->_call('EHLO '.$_SERVER['HTTP_HOST'], 250) && !$this->_call('HELO '.$_SERVER['HTTP_HOST'], 250)) { + $this->disconnect(); + //throw exception + Eden_Mail_Error::get() + ->setMessage(Eden_Mail_Error::SERVER_ERROR) + ->addVariable($host.':'.$this->_port) + ->trigger(); + } + } + + if($test) { + $this->disconnect(); + return $this; + } + + //login + if(!$this->_call('AUTH LOGIN', 250, 334)) { + $this->disconnect(); + //throw exception + Eden_Mail_Error::i(Eden_Mail_Error::LOGIN_ERROR)->trigger(); + } + + if(!$this->_call(base64_encode($this->_username), 334)) { + $this->disconnect(); + //throw exception + Eden_Mail_Error::i()->setMessage(Eden_Mail_Error::LOGIN_ERROR); + } + + if(!$this->_call(base64_encode($this->_password), 235, 334)) { + $this->disconnect(); + //throw exception + Eden_Mail_Error::i()->setMessage(Eden_Mail_Error::LOGIN_ERROR); + } + + return $this; + } + + /** + * Disconnects from the server + * + * @return this + */ + public function disconnect() { + if ($this->_socket) { + $this->_send('QUIT'); + + fclose($this->_socket); + + $this->_socket = NULL; + } + + return $this; + } + + /** + * Reply to an existing email + * + * @param string message id + * @param string topic + * @return array headers + */ + public function reply($messageId, $topic = NULL, array $headers = array()) { + Eden_Mail_Error::i() + ->argument(1, 'string') + ->argument(2, 'string', 'null'); + + $headers['In-Reply-To'] = $messageId; + + if($topic) { + $headers['Thread-Topic'] = $topic; + } + + return $this->send($headers); + } + + /** + * Resets the class + * + * @return this + */ + public function reset() { + $this->_subject = NULL; + $this->_body = array(); + $this->_to = array(); + $this->_cc = array(); + $this->_bcc = array(); + $this->_attachments = array(); + + $this->disconnect(); + + return $this; + } + + /** + * Sends an email + * + * @param array custom headers + * @return array headers + */ + public function send(array $headers = array()) { + //if no socket + if(!$this->_socket) { + //then connect + $this->connect(); + } + + $headers = $this->_getHeaders($headers); + $body = $this->_getBody(); + + //add from + if(!$this->_call('MAIL FROM:<' . $this->_username . '>', 250, 251)) { + $this->disconnect(); + //throw exception + Eden_Mail_Error::i() + ->setMessage(Eden_Mail_Error::SMTP_ADD_EMAIL) + ->addVariable($this->_username) + ->trigger(); + } + + //add to + foreach($this->_to as $email => $name) { + if(!$this->_call('RCPT TO:<' . $email . '>', 250, 251)) { + $this->disconnect(); + //throw exception + Eden_Mail_Error::i() + ->setMessage(Eden_Mail_Error::SMTP_ADD_EMAIL) + ->addVariable($email) + ->trigger(); + } + } + + //add cc + foreach($this->_cc as $email => $name) { + if(!$this->_call('RCPT TO:<' . $email . '>', 250, 251)) { + $this->disconnect(); + //throw exception + Eden_Mail_Error::i() + ->setMessage(Eden_Mail_Error::SMTP_ADD_EMAIL) + ->addVariable($email) + ->trigger(); + } + } + + //add bcc + foreach($this->_bcc as $email => $name) { + if(!$this->_call('RCPT TO:<' . $email . '>', 250, 251)) { + $this->disconnect(); + //throw exception + Eden_Mail_Error::i() + ->setMessage(Eden_Mail_Error::SMTP_ADD_EMAIL) + ->addVariable($email) + ->trigger(); + } + } + + //start compose + if(!$this->_call('DATA', 354)) { + $this->disconnect(); + //throw exception + Eden_Mail_Error::i(Eden_Mail_Error::SMTP_DATA)->trigger(); + } + + //send header data + foreach($headers as $name => $value) { + $this->_send($name.': '.$value); + } + + //send body data + foreach($body as $line) { + if (strpos($line, '.') === 0) { + // Escape lines prefixed with a '.' + $line = '.' . $line; + } + + $this->_send($line); + } + + //tell server this is the end + if(!$this->_call("\r\n.\r\n", 250)) { + $this->disconnect(); + //throw exception + Eden_Mail_Error::i(Eden_Mail_Error::SMTP_DATA)->trigger(); + } + + //reset (some reason without this, this class spazzes out) + $this->_send('RSET'); + + return $headers; + } + /** + * Sets body + * + * @param string body + * @param bool is this an html body? + * @return this + */ + public function setBody($body, $html = false) { + Eden_Mail_Error::i() + ->argument(1, 'string') + ->argument(2, 'bool'); + + if($html) { + $this->_body['text/html'] = $body; + $body = strip_tags($body); + } + + $this->_body['text/plain'] = $body; + + return $this; + } + + /** + * Sets subject + * + * @param string subject + * @return this + */ + public function setSubject($subject) { + Eden_Mail_Error::i()->argument(1, 'string'); + $this->_subject = $subject; + return $this; + } + + /* Protected Methods + -------------------------------*/ + protected function _addAttachmentBody(array $body) { + foreach($this->_attachments as $attachment) { + list($name, $data, $mime) = $attachment; + $mime = $mime ? $mime : Eden_File::get()->getMimeType($name); + $data = base64_encode($data); + $count = ceil(strlen($data) / 998); + + $body[] = '--'.$this->_boundary[1]; + $body[] = 'Content-type: '.$mime.'; name="'.$name.'"'; + $body[] = 'Content-disposition: attachment; filename="'.$name.'"'; + $body[] = 'Content-transfer-encoding: base64'; + $body[] = NULL; + + for ($i = 0; $i < $count; $i++) { + $body[] = substr($data, ($i * 998), 998); + } + + $body[] = NULL; + $body[] = NULL; + } + + $body[] = '--'.$this->_boundary[1].'--'; + + return $body; + } + + protected function _call($command, $code = NULL) { + if(!$this->_send($command)) { + return false; + } + + $receive = $this->_receive(); + + $args = func_get_args(); + if(count($args) > 1) { + for($i = 1; $i < count($args); $i++) { + if(strpos($receive, (string)$args[$i]) === 0) { + return true; + } + } + + return false; + } + + return $receive; + } + + protected function _getAlternativeAttachmentBody() { + $alternative = $this->_getAlternativeBody(); + + $body = array(); + $body[] = 'Content-Type: multipart/mixed; boundary="'.$this->_boundary[1].'"'; + $body[] = NULL; + $body[] = '--'.$this->_boundary[1]; + + foreach($alternative as $line) { + $body[] = $line; + } + + return $this->_addAttachmentBody($body); + } + + protected function _getAlternativeBody() { + $plain = $this->_getPlainBody(); + $html = $this->_getHtmlBody(); + + $body = array(); + $body[] = 'Content-Type: multipart/alternative; boundary="'.$this->_boundary[0].'"'; + $body[] = NULL; + $body[] = '--'.$this->_boundary[0]; + + foreach($plain as $line) { + $body[] = $line; + } + + $body[] = '--'.$this->_boundary[0]; + + foreach($html as $line) { + $body[] = $line; + } + + $body[] = '--'.$this->_boundary[0].'--'; + $body[] = NULL; + $body[] = NULL; + + return $body; + } + + protected function _getBody() { + $type = 'Plain'; + if(count($this->_body) > 1) { + $type = 'Alternative'; + } else if(isset($this->_body['text/html'])) { + $type = 'Html'; + } + + $method = '_get%sBody'; + if(!empty($this->_attachments)) { + $method = '_get%sAttachmentBody'; + } + + $method = sprintf($method, $type); + + return $this->$method(); + } + + protected function _getHeaders(array $customHeaders = array()) { + $timestamp = $this->_getTimestamp(); + + $subject = trim($this->_subject); + $subject = str_replace(array("\n", "\r"), '', $subject); + + $to = $cc = $bcc = array(); + foreach($this->_to as $email => $name) { + $to[] = trim($name.' <'.$email.'>'); + } + + foreach($this->_cc as $email => $name) { + $cc[] = trim($name.' <'.$email.'>'); + } + + foreach($this->_bcc as $email => $name) { + $bcc[] = trim($name.' <'.$email.'>'); + } + + list($account, $suffix) = explode('@', $this->_username); + + $headers = array( + 'Date' => $timestamp, + 'Subject' => $subject, + 'From' => '<'.$this->_username.'>', + 'To' => implode(', ', $to)); + + if(!empty($cc)) { + $headers['Cc'] = implode(', ', $cc); + } + + if(!empty($bcc)) { + $headers['Bcc'] = implode(', ', $bcc); + } + + $headers['Message-ID'] = '<'.md5(uniqid(time())).'.eden@'.$suffix.'>'; + + $headers['Thread-Topic'] = $this->_subject; + + $headers['Reply-To'] = '<'.$this->_username.'>'; + + foreach($customHeaders as $key => $value) { + $headers[$key] = $value; + } + + return $headers; + } + + protected function _getHtmlAttachmentBody() { + $html = $this->_getHtmlBody(); + + $body = array(); + $body[] = 'Content-Type: multipart/mixed; boundary="'.$this->_boundary[1].'"'; + $body[] = NULL; + $body[] = '--'.$this->_boundary[1]; + + foreach($html as $line) { + $body[] = $line; + } + + return $this->_addAttachmentBody($body); + } + + protected function _getHtmlBody() { + $charset = $this->_isUtf8($this->_body['text/html']) ? 'utf-8' : 'US-ASCII'; + $html = str_replace("\r", '', trim($this->_body['text/html'])); + + $encoded = explode("\n", $this->_quotedPrintableEncode($html)); + $body = array(); + $body[] = 'Content-Type: text/html; charset='.$charset; + $body[] = 'Content-Transfer-Encoding: quoted-printable'."\n"; + + foreach($encoded as $line) { + $body[] = $line; + } + + $body[] = NULL; + $body[] = NULL; + + return $body; + } + + protected function _getPlainAttachmentBody() { + $plain = $this->_getPlainBody(); + + $body = array(); + $body[] = 'Content-Type: multipart/mixed; boundary="'.$this->_boundary[1].'"'; + $body[] = NULL; + $body[] = '--'.$this->_boundary[1]; + + foreach($plain as $line) { + $body[] = $line; + } + + return $this->_addAttachmentBody($body); + } + + protected function _getPlainBody() { + $charset = $this->_isUtf8($this->_body['text/plain']) ? 'utf-8' : 'US-ASCII'; + $plane = str_replace("\r", '', trim($this->_body['text/plain'])); + $count = ceil(strlen($plane) / 998); + + $body = array(); + $body[] = 'Content-Type: text/plain; charset='.$charset; + $body[] = 'Content-Transfer-Encoding: 7bit'; + $body[] = NULL; + + for ($i = 0; $i < $count; $i++) { + $body[] = substr($plane, ($i * 998), 998); + } + + $body[] = NULL; + $body[] = NULL; + + return $body; + } + + protected function _receive() { + $data = ''; + $now = time(); + + while($str = fgets($this->_socket, 1024)) { + + $data .= $str; + + if(substr($str,3,1) == ' ' || time() > ($now + self::TIMEOUT)) { + break; + } + } + + $this->_debug('Receiving: '. $data); + return $data; + } + + protected function _send($command) { + $this->_debug('Sending: '.$command); + + return fwrite($this->_socket, $command . "\r\n"); + } + + /* Private Methods + -------------------------------*/ + private function _debug($string) { + if($this->_debugging) { + $string = htmlspecialchars($string); + + + echo '
'.$string.'
'."\n"; + } + return $this; + } + + private function _getTimestamp() { + $zone = date('Z'); + $sign = ($zone < 0) ? '-' : '+'; + $zone = abs($zone); + $zone = (int)($zone / 3600) * 100 + ($zone % 3600) / 60; + return sprintf("%s %s%04d", date('D, j M Y H:i:s'), $sign, $zone); + } + + private function _isUtf8($string) { + $regex = array( + '[\xC2-\xDF][\x80-\xBF]', + '\xE0[\xA0-\xBF][\x80-\xBF]', + '[\xE1-\xEC\xEE\xEF][\x80-\xBF]{2}', + '\xED[\x80-\x9F][\x80-\xBF]', + '\xF0[\x90-\xBF][\x80-\xBF]{2}', + '[\xF1-\xF3][\x80-\xBF]{3}', + '\xF4[\x80-\x8F][\x80-\xBF]{2}'); + + $count = ceil(strlen($string) / 5000); + for ($i = 0; $i < $count; $i++) { + if(preg_match('%(?:'. implode('|', $regex).')+%xs', substr($string, ($i * 5000), 5000))) { + return false; + } + } + + return true; + } + + private function _quotedPrintableEncode($input, $line_max = 75) { + $hex = array('0','1','2','3','4','5','6','7', + '8','9','A','B','C','D','E','F'); + $lines = preg_split("/(?:\r\n|\r|\n)/", $input); + $linebreak = "=0D=0A=\r\n"; + /* the linebreak also counts as characters in the mime_qp_long_line + * rule of spam-assassin */ + $line_max = $line_max - strlen($linebreak); + $escape = "="; + $output = ""; + $cur_conv_line = ""; + $length = 0; + $whitespace_pos = 0; + $addtl_chars = 0; + + // iterate lines + for ($j=0; $j 126) ) { + $h2 = floor($dec/16); $h1 = floor($dec%16); + $c = $escape . $hex["$h2"] . $hex["$h1"]; + $length += 2; + $addtl_chars += 2; + } + + // length for wordwrap exceeded, get a newline into the text + if ($length >= $line_max) { + $cur_conv_line .= $c; + + // read only up to the whitespace for the current line + $whitesp_diff = $i - $whitespace_pos + $addtl_chars; + + /* the text after the whitespace will have to be read + * again ( + any additional characters that came into + * existence as a result of the encoding process after the whitespace) + * + * Also, do not start at 0, if there was *no* whitespace in + * the whole line */ + if (($i + $addtl_chars) > $whitesp_diff) { + $output .= substr($cur_conv_line, 0, (strlen($cur_conv_line) - + $whitesp_diff)) . $linebreak; + $i = $i - $whitesp_diff + $addtl_chars; + } else { + $output .= $cur_conv_line . $linebreak; + } + + $cur_conv_line = ""; + $length = 0; + $whitespace_pos = 0; + } else { + // length for wordwrap not reached, continue reading + $cur_conv_line .= $c; + } + } // end of for + + $length = 0; + $whitespace_pos = 0; + $output .= $cur_conv_line; + $cur_conv_line = ""; + + if ($j<=count($lines)-1) { + $output .= $linebreak; + } + } // end for + + return trim($output); + } // end quoted_printable_encode +} \ No newline at end of file diff --git a/library/eden/memcache.php b/library/eden/memcache.php new file mode 100755 index 0000000..deac01d --- /dev/null +++ b/library/eden/memcache.php @@ -0,0 +1,195 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +require_once dirname(__FILE__).'/class.php'; + +/** + * Definition of available memcache methods. Memcache module + * provides handy procedural and object oriented interface to + * memcached, highly effective caching daemon, which was + * especially designed to decrease database load in dynamic + * web applications. We cache when computing the same data is + * expensive on memory or time. Once the actual data is stored + * in memory, it can be used in the future by accessing the + * cached copy rather than recomputing the original data. + * + * @package Eden + * @category cache + * @author Christian Blanquera cblanquera@openovate.com + */ +class Eden_Memcache extends Eden_Class { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_memcache = NULL; + + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + public function __construct($host = 'localhost', $port = 11211, $timeout = 1) { + //argument test + $error = Eden_Memcache_Error::i() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'int') //Argument 2 must be an integer + ->argument(3, 'int'); //Argument 3 must be an integer + + //if memcache is not a class + if(!class_exists('Memcached')) { + //throw exception + $error->setMessage(Eden_Memcache_Error::NOT_INSTALLED)->trigger(); + } + + try { + $this->_memcache = new Memcached; + } catch(Exception $e) { + //throw exception + $error->setMessage(Eden_Memcache_Error::NOT_INSTALLED)->trigger(); + } + + $this->_memcache->connect($host, $port, $timeout); + + return $this; + } + + public function __destruct() { + if(!is_null($this->_memcache)) { + $this->_memcache->close(); + $this->_memcache = NULL; + } + } + + /* Public Methods + -------------------------------*/ + /** + * Add a memcached server to connection pool + * + * @param string the key to the data + * @param string the path of the cache + * @param variable the data to be cached + * @return bool + */ + public function addServer($host = 'localhost', $port = 11211, $persistent = true, $weight = NULL, $timeout = 1) { + //argument test + Eden_Memcache_Error::i() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'int') //Argument 2 must be an integer + ->argument(3, 'bool') //Argument 3 must be a boolean + ->argument(4, 'int', 'null') //Argument 4 must be a integer or null + ->argument(5, 'int'); //Argument 5 must be an integer + + $this->_memcache->addServer($host, $port, $persistent, $weight, $timeout); + + return $this; + } + + /** + * Flushes the cache + * + * return this + */ + public function clear() { + $this->_memcache->flush(); + + return $this; + } + + /** + * Gets a data cache + * + * @param string|array the key to the data + * @param int MemCache flag + * @return variable + */ + public function get($key, $flag = NULL) { + //argument test + Eden_Memcache_Error::i() + ->argument(1, 'string', 'array') //Argument 1 must be a string or array + ->argument(2, 'int', 'null'); //Argument 2 must be an integer or null + + return $this->_memcache->get($key, $flag); + } + + /** + * deletes data of a cache + * + * @param string the key to the data + * @return this + */ + public function remove($key) { + //Argument 1 must be a string or array + Eden_Memcache_Error::i()->argument(1, 'string', 'array'); + + $this->_memcache->delete($key); + + return $this; + } + + /** + * Sets a data cache + * + * @param string the key to the data + * @param variable the data to be cached + * @param int MemCache flag + * @param int expire + * @return bool + */ + public function set($key, $data, $flag = NULL, $expire = NULL) { + //argument test + Eden_Memcache_Error::i() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(3, 'int', 'null') //Argument 3 must be an integer or null + ->argument(4, 'int', 'null'); //Argument 4 must be an integer or null + + $this->_memcache->set($key, $data, $flag, $expire); + + return $this; + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} + +/** + * Memcache Errors + */ +class Eden_Memcache_Error extends Eden_Error { + /* Constants + -------------------------------*/ + const NOT_INSTALLED = 'Memcache is not installed.'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i($message = NULL, $code = 0) { + $class = __CLASS__; + return new $class($message, $code); + } + + /* Public Methods + -------------------------------*/ + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/model.php b/library/eden/model.php new file mode 100755 index 0000000..55e7c9e --- /dev/null +++ b/library/eden/model.php @@ -0,0 +1,71 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +require_once dirname(__FILE__).'/type.php'; + +/** + * Base model that allows setting and getting of key values + * + * @package Eden + * @category model + * @author Christian Blanquera cblanquera@openovate.com + */ +class Eden_Model extends Eden_Type_Array { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + /* Public Methods + -------------------------------*/ + /* Protected Methods + -------------------------------*/ + protected function _getMethodType(&$name) { + return false; + } + + /* Private Methods + -------------------------------*/ +} + +/** + * Model Errors + */ +class Eden_Model_Error extends Eden_Error { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i($message = NULL, $code = 0) { + $class = __CLASS__; + return new $class($message, $code); + } + + /* Public Methods + -------------------------------*/ + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/mysql.php b/library/eden/mysql.php new file mode 100755 index 0000000..ee9835b --- /dev/null +++ b/library/eden/mysql.php @@ -0,0 +1,302 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +require_once dirname(__FILE__).'/sql/database.php'; +require_once dirname(__FILE__).'/mysql/error.php'; +require_once dirname(__FILE__).'/mysql/alter.php'; +require_once dirname(__FILE__).'/mysql/create.php'; +require_once dirname(__FILE__).'/mysql/subselect.php'; +require_once dirname(__FILE__).'/mysql/utility.php'; + +/** + * Abstractly defines a layout of available methods to + * connect to and query a MySQL database. This class also + * lays out query building methods that auto renders a + * valid query the specific database will understand without + * actually needing to know the query language. Extending + * all SQL classes, comes coupled with loosely defined + * searching, collections and models. + * + * @package Eden + * @category sql + * @author Christian Blanquera cblanquera@openovate.com + */ +class Eden_Mysql extends Eden_Sql_Database { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_host = 'localhost'; + protected $_name = NULL; + protected $_user = NULL; + protected $_pass = NULL; + + protected $_model = self::MODEL; + protected $_collection = self::COLLECTION; + + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + public function __construct($host, $name, $user, $pass = NULL, $port = NULL) { + //argument test + Eden_Mysql_Error::i() + ->argument(1, 'string', 'null') //Argument 1 must be a string or null + ->argument(2, 'string') //Argument 2 must be a string + ->argument(3, 'string') //Argument 3 must be a string + ->argument(4, 'string', 'null') //Argument 4 must be a number or null + ->argument(5, 'numeric', 'null'); //Argument 4 must be a number or null + + $this->_host = $host; + $this->_name = $name; + $this->_user = $user; + $this->_pass = $pass; + $this->_port = $port; + } + + /* Public Methods + -------------------------------*/ + + /** + * Returns the alter query builder + * + * @return Eden_Sql_Alter + */ + public function alter($name = NULL) { + //Argument 1 must be a string or null + Eden_Mysql_Error::i()->argument(1, 'string', 'null'); + + return Eden_Mysql_Alter::i($name); + } + + /** + * Returns the create query builder + * + * @return Eden_Sql_Create + */ + public function create($name = NULL) { + //Argument 1 must be a string or null + Eden_Mysql_Error::i()->argument(1, 'string', 'null'); + + return Eden_Mysql_Create::i($name); + } + + /** + * Connects to the database + * + * @param array the connection options + * @return this + */ + public function connect(array $options = array()) { + $host = $port = NULL; + + if(!is_null($this->_host)) { + $host = 'host='.$this->_host.';'; + if(!is_null($this->_port)) { + $port = 'port='.$this->_port.';'; + } + } + + $connection = 'mysql:'.$host.$port.'dbname='.$this->_name; + + $this->_connection = new PDO($connection, $this->_user, $this->_pass, $options); + + $this->trigger(); + + return $this; + } + + /** + * Returns the Subselect query builder + * + * @return Eden_Sql_Subselect + */ + public function subselect($parentQuery, $select = '*') { + //Argument 2 must be a string + Eden_Mysql_Error::i()->argument(2, 'string'); + + return Eden_Mysql_Subselect::i($parentQuery, $select); + } + + /** + * Returns the alter query builder + * + * @return Eden_Sql_Utility + */ + public function utility() { + return Eden_Mysql_Utility::i(); + } + + /** + * Returns the columns and attributes given the table name + * + * @param the name of the table + * @return attay|false + */ + public function getColumns($table, $filters = NULL) { + //Argument 1 must be a string + Eden_Mysql_Error::i()->argument(1, 'string'); + + $query = $this->utility(); + + if(is_array($filters)) { + foreach($filters as $i => $filter) { + //array('post_id=%s AND post_title IN %s', 123, array('asd')); + $format = array_shift($filter); + $filter = $this->bind($filter); + $filters[$i] = vsprintf($format, $filter); + } + } + + $query->showColumns($table, $filters); + return $this->query($query, $this->getBinds()); + } + + /** + * Peturns the primary key name given the table + * + * @param string table + * @return string + */ + public function getPrimaryKey($table) { + //Argument 1 must be a string + Eden_Mysql_Error::i()->argument(1, 'string'); + + $query = $this->utility(); + $results = $this->getColumns($table, "`Key` = 'PRI'"); + return isset($results[0]['Field']) ? $results[0]['Field'] : NULL; + } + + /** + * Returns the whole enitre schema and rows + * of the current databse + * + * @return string + */ + public function getSchema() { + $backup = array(); + $tables = $this->getTables(); + foreach($tables as $table) { + $backup[] = $this->getBackup(); + } + + return implode("\n\n", $backup); + } + + /** + * Returns a listing of tables in the DB + * + * @param the like pattern + * @return attay|false + */ + public function getTables($like = NULL) { + //Argument 1 must be a string or null + Eden_Mysql_Error::i()->argument(1, 'string', 'null'); + + $query = $this->utility(); + $like = $like ? $this->bind($like) : NULL; + $results = $this->query($query->showTables($like), $q->getBinds()); + $newResults = array(); + foreach($results as $result) { + foreach($result as $key => $value) { + $newResults[] = $value; + break; + } + } + + return $newResults; + } + + /** + * Returns the whole enitre schema and rows + * of the current table + * + * @return string + */ + public function getTableSchema($table) { + //Argument 1 must be a string + Eden_Mysql_Error::i()->argument(1, 'string'); + + $backup = array(); + //get the schema + $schema = $this->getColumns($table); + if(count($schema)) { + //lets rebuild this schema + $query = $this->create()->setName($table); + foreach($schema as $field) { + //first try to parse what we can from each field + $fieldTypeArray = explode(' ', $field['Type']); + $typeArray = explode('(', $fieldTypeArray[0]); + + $type = $typeArray[0]; + $length = str_replace(')', '', $typeArray[1]); + $attribute = isset($fieldTypeArray[1]) ? $fieldTypeArray[1] : NULL; + + $null = strtolower($field['Null']) == 'no' ? false : true; + + $increment = strtolower($field['Extra']) == 'auto_increment' ? true : false; + + //lets now add a field to our schema class + $q->addField($field['Field'], array( + 'type' => $type, + 'length' => $length, + 'attribute' => $attribute, + 'null' => $null, + 'default' => $field['Default'], + 'auto_increment' => $increment)); + + //set keys where found + switch($field['Key']) + { + case 'PRI': + $query->addPrimaryKey($field['Field']); + break; + case 'UNI': + $query->addUniqueKey($field['Field'], array($field['Field'])); + break; + case 'MUL': + $query->addKey($field['Field'], array($field['Field'])); + break; + } + } + + //store the query but dont run it + $backup[] = $query; + } + + //get the rows + $rows = $this->query($this->select->from($table)->getQuery()); + if(count($rows)) { + //lets build an insert query + $query = $this->insert($table); + foreach($rows as $index => $row) { + foreach($row as $key => $value) { + $query->set($key, $this->getBinds($value), $index); + } + } + + //store the query but dont run it + $backup[] = $query->getQuery(true); + } + + return implode("\n\n", $backup); + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} + diff --git a/library/eden/mysql/alter.php b/library/eden/mysql/alter.php new file mode 100755 index 0000000..6bce65c --- /dev/null +++ b/library/eden/mysql/alter.php @@ -0,0 +1,319 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Generates alter query string syntax + * + * @package Eden + * @category sql + * @author Christian Blanquera cblanquera@openovate.com + */ +class Eden_Mysql_Alter extends Eden_Sql_Query { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_name = NULL; + protected $_changeFields = array(); + protected $_addFields = array(); + protected $_removeFields = array(); + protected $_addKeys = array(); + protected $_removeKeys = array(); + protected $_addUniqueKeys = array(); + protected $_removeUniqueKeys = array(); + protected $_addPrimaryKeys = array(); + protected $_removePrimaryKeys = array(); + + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + public function __construct($name = NULL) { + if(is_string($name)) { + $this->setName($name); + } + } + + /* Public Methods + -------------------------------*/ + /** + * Adds a field in the table + * + * @param string name + * @param array attributes + * @return this + */ + public function addField($name, array $attributes) { + //Argument 1 must be a string + Eden_Mysql_Error::i()->argument(1, 'string'); + + $this->_addFields[$name] = $attributes; + return $this; + } + + /** + * Adds an index key + * + * @param string name + * @return this + */ + public function addKey($name) { + //Argument 1 must be a string + Eden_Mysql_Error::i()->argument(1, 'string'); + + $this->_addKeys[] = '`'.$name.'`'; + return $this; + } + + /** + * Adds a primary key + * + * @param string name + * @return this + */ + public function addPrimaryKey($name) { + //Argument 1 must be a string + Eden_Mysql_Error::i()->argument(1, 'string'); + + $this->_addPrimaryKeys[] = '`'.$name.'`'; + return $this; + } + + /** + * Adds a unique key + * + * @param string name + * @return this + */ + public function addUniqueKey($name) { + //Argument 1 must be a string + Eden_Mysql_Error::i()->argument(1, 'string'); + + $this->_addUniqueKeys[] = '`'.$name.'`'; + return $this; + } + + /** + * Changes attributes of the table given + * the field name + * + * @param string name + * @param array attributes + * @return this + */ + public function changeField($name, array $attributes) { + //Argument 1 must be a string + Eden_Mysql_Error::i()->argument(1, 'string'); + + $this->_changeFields[$name] = $attributes; + return $this; + } + + /** + * Returns the string version of the query + * + * @param bool + * @return string + * @notes returns the query based on the registry + */ + public function getQuery($unbind = false) { + $fields = array(); + $table = '`'.$this->_name.'`'; + + foreach($this->_removeFields as $name) { + $fields[] = 'DROP `'.$name.'`'; + } + + foreach($this->_addFields as $name => $attr) { + $field = array('ADD `'.$name.'`'); + if(isset($attr['type'])) { + $field[] = isset($attr['length']) ? $attr['type'] . '('.$attr['length'].')' : $attr['type']; + } + + if(isset($attr['attribute'])) { + $field[] = $attr['attribute']; + } + + if(isset($attr['null'])) { + if($attr['null'] == false) { + $field[] = 'NOT NULL'; + } else { + $field[] = 'DEFAULT NULL'; + } + } + + if(isset($attr['default'])&& $attr['default'] !== false) { + if(!isset($attr['null']) || $attr['null'] == false) { + if(is_string($attr['default'])) { + $field[] = 'DEFAULT \''.$attr['default'] . '\''; + } else if(is_numeric($attr['default'])) { + $field[] = 'DEFAULT '.$attr['default']; + } + } + } + + if(isset($attr['auto_increment']) && $attr['auto_increment'] == true) { + $field[] = 'auto_increment'; + } + + $fields[] = implode(' ', $field); + } + + foreach($this->_changeFields as $name => $attr) { + $field = array('CHANGE `'.$name.'` `'.$name.'`'); + + if(isset($attr['name'])) { + $field = array('CHANGE `'.$name.'` `'.$attr['name'].'`'); + } + + if(isset($attr['type'])) { + $field[] = isset($attr['length']) ? $attr['type'] . '('.$attr['length'].')' : $attr['type']; + } + + if(isset($attr['attribute'])) { + $field[] = $attr['attribute']; + } + + if(isset($attr['null'])) { + if($attr['null'] == false) { + $field[] = 'NOT NULL'; + } else { + $field[] = 'DEFAULT NULL'; + } + } + + if(isset($attr['default'])&& $attr['default'] !== false) { + if(!isset($attr['null']) || $attr['null'] == false) { + if(is_string($attr['default'])) { + $field[] = 'DEFAULT \''.$attr['default'] . '\''; + } else if(is_numeric($attr['default'])) { + $field[] = 'DEFAULT '.$attr['default']; + } + } + } + + if(isset($attr['auto_increment']) && $attr['auto_increment'] == true) { + $field[] = 'auto_increment'; + } + + $fields[] = implode(' ', $field); + } + + foreach($this->_removeKeys as $key) { + $fields[] = 'DROP INDEX `'.$key.'`'; + } + + if(!empty($this->_addKeys)) { + $fields[] = 'ADD INDEX ('.implode(', ', $this->_addKeys).')'; + } + + foreach($this->_removeUniqueKeys as $key) { + $fields[] = 'DROP INDEX `'.$key.'`'; + } + + if(!empty($this->_addUniqueKeys)) { + $fields[] = 'ADD UNIQUE ('.implode(', ', $this->_addUniqueKeys).')'; + } + + foreach($this->_removePrimaryKeys as $key) { + $fields[] = 'DROP PRIMARY KEY `'.$key.'`'; + } + + if(!empty($this->_addPrimaryKeys)) { + $fields[] = 'ADD PRIMARY KEY ('.implode(', ', $this->_addPrimaryKeys).')'; + } + + $fields = implode(", \n", $fields); + + return sprintf( + 'ALTER TABLE %s %s;', + $table, $fields); + } + + /** + * Removes a field + * + * @param string name + * @return this + */ + public function removeField($name) { + //Argument 1 must be a string + Eden_Mysql_Error::i()->argument(1, 'string'); + + $this->_removeFields[] = $name; + return $this; + } + + /** + * Removes an index key + * + * @param string name + * @return this + */ + public function removeKey($name) { + //Argument 1 must be a string + Eden_Mysql_Error::i()->argument(1, 'string'); + + $this->_removeKeys[] = $name; + return $this; + } + + /** + * Removes a primary key + * + * @param string name + * @return this + */ + public function removePrimaryKey($name) { + //Argument 1 must be a string + Eden_Mysql_Error::i()->argument(1, 'string'); + + $this->_removePrimaryKeys[] = $name; + return $this; + } + + /** + * Removes a unique key + * + * @param string name + * @return this + */ + public function removeUniqueKey($name) { + //Argument 1 must be a string + Eden_Mysql_Error::i()->argument(1, 'string'); + + $this->_removeUniqueKeys[] = $name; + return $this; + } + + /** + * Sets the name of the table you wish to create + * + * @param string name + * @return this + */ + public function setName($name) { + //Argument 1 must be a string + Eden_Mysql_Error::i()->argument(1, 'string'); + + $this->_name = $name; + return $this; + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/mysql/create.php b/library/eden/mysql/create.php new file mode 100755 index 0000000..cf4a0f2 --- /dev/null +++ b/library/eden/mysql/create.php @@ -0,0 +1,252 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Generates create table query string syntax + * + * @package Eden + * @category sql + * @author Christian Blanquera cblanquera@openovate.com + */ +class Eden_Mysql_Create extends Eden_Sql_Query { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_name = NULL; + protected $_comments = NULL; + protected $_fields = array(); + protected $_keys = array(); + protected $_uniqueKeys = array(); + protected $_primaryKeys = array(); + + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + public function __construct($name = NULL) { + if(is_string($name)) { + $this->setName($name); + } + } + + /* Public Methods + -------------------------------*/ + /** + * Adds a field in the table + * + * @param string name + * @param array attributes + * @return this + */ + public function addField($name, array $attributes) { + //Argument 1 must be a string + Eden_Mysql_Error::i()->argument(1, 'string'); + + $this->_fields[$name] = $attributes; + return $this; + } + + /** + * Adds an index key + * + * @param string name + * @param array fields + * @return this + */ + public function addKey($name, array $fields) { + //Argument 1 must be a string + Eden_Mysql_Error::i()->argument(1, 'string'); + + $this->_keys[$name] = $fields; + return $this; + } + + /** + * Adds a primary key + * + * @param string name + * @return this + */ + public function addPrimaryKey($name) { + //Argument 1 must be a string + Eden_Mysql_Error::i()->argument(1, 'string'); + + $this->_primaryKeys[] = $name; + return $this; + } + + /** + * Adds a unique key + * + * @param string name + * @param array fields + * @return this + */ + public function addUniqueKey($name, array $fields) { + //Argument 1 must be a string + Eden_Mysql_Error::i()->argument(1, 'string'); + + $this->_uniqueKeys[$name] = $fields; + return $this; + } + + /** + * Returns the string version of the query + * + * @param bool + * @return string + * @notes returns the query based on the registry + */ + public function getQuery($unbind = false) { + $table = '`'.$this->_name.'`'; + + $fields = array(); + foreach($this->_fields as $name => $attr) { + $field = array('`'.$name.'`'); + if(isset($attr['type'])) { + $field[] = isset($attr['length']) ? $attr['type'] . '('.$attr['length'].')' : $attr['type']; + } + + if(isset($attr['attribute'])) { + $field[] = $attr['attribute']; + } + + if(isset($attr['null'])) { + if($attr['null'] == false) { + $field[] = 'NOT NULL'; + } else { + $field[] = 'DEFAULT NULL'; + } + } + + if(isset($attr['default'])&& $attr['default'] !== false) { + if(!isset($attr['null']) || $attr['null'] == false) { + if(is_string($attr['default'])) { + $field[] = 'DEFAULT \''.$attr['default'] . '\''; + } else if(is_numeric($attr['default'])) { + $field[] = 'DEFAULT '.$attr['default']; + } + } + } + + if(isset($attr['auto_increment']) && $attr['auto_increment'] == true) { + $field[] = 'auto_increment'; + } + + $fields[] = implode(' ', $field); + } + + $fields = !empty($fields) ? implode(', ', $fields) : ''; + + $primary = !empty($this->_primaryKeys) ? ', PRIMARY KEY (`'.implode('`, `', $this->_primaryKeys).'`)' : ''; + + $uniques = array(); + foreach($this->_uniqueKeys as $key => $value) { + $uniques[] = 'UNIQUE KEY `'. $key .'` (`'.implode('`, `', $value).'`)'; + } + + $uniques = !empty($uniques) ? ', ' . implode(", \n", $uniques) : ''; + + $keys = array(); + foreach($this->_keys as $key => $value) { + $keys[] = 'KEY `'. $key .'` (`'.implode('`, `', $value).'`)'; + } + + $keys = !empty($keys) ? ', ' . implode(", \n", $keys) : ''; + + return sprintf( + 'CREATE TABLE %s (%s%s%s%s)', + $table, $fields, $primary, + $unique, $keys); + } + + /** + * Sets comments + * + * @param string comments + * @return this + */ + public function setComments($comments) { + //Argument 1 must be a string + Eden_Mysql_Error::i()->argument(1, 'string'); + + $this->_comments = $comments; + return $this; + } + + /** + * Sets a list of fields to the table + * + * @param array fields + * @return this + */ + public function setFields(array $fields) { + $this->_fields = $fields; + return $this; + } + + /** + * Sets a list of keys to the table + * + * @param array keys + * @return this + */ + public function setKeys(array $keys) { + $this->_keys = $keys; + return $this; + } + + /** + * Sets the name of the table you wish to create + * + * @param string name + * @return this + */ + public function setName($name) { + //Argument 1 must be a string + Eden_Mysql_Error::i()->argument(1, 'string'); + + $this->_name = $name; + return $this; + } + + /** + * Sets a list of primary keys to the table + * + * @param array primaryKeys + * @return this + */ + public function setPrimaryKeys(array $primaryKeys) { + $this->_primaryKeys = $primaryKeys; + return $this; + } + + /** + * Sets a list of unique keys to the table + * + * @param array uniqueKeys + * @return this + */ + public function setUniqueKeys(array $uniqueKeys) { + $this->_uniqueKeys = $uniqueKeys; + return $this; + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/mysql/error.php b/library/eden/mysql/error.php new file mode 100755 index 0000000..ed6ce0f --- /dev/null +++ b/library/eden/mysql/error.php @@ -0,0 +1,39 @@ + +/* + * This file is part of the Eden package. + * (c) 2010-2012 Christian Blanquera + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * MySql Errors + * + * @package Eden + * @category sql + * @author Christian Blanquera cblanquera@openovate.com + */ +class Eden_Mysql_Error extends Eden_Error { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i($message = NULL, $code = 0) { + $class = __CLASS__; + return new $class($message, $code); + } + + /* Public Methods + -------------------------------*/ + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/mysql/subselect.php b/library/eden/mysql/subselect.php new file mode 100755 index 0000000..cf7f1cf --- /dev/null +++ b/library/eden/mysql/subselect.php @@ -0,0 +1,71 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Generates subselect query string syntax + * + * @package Eden + * @category sql + * @author Christian Blanquera cblanquera@openovate.com + */ +class Eden_Mysql_Subselect extends Eden_Class { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_parentQuery; + + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + public function __construct(Eden_Sql_Select $parentQuery, $select = '*') { + //Argument 2 must be a string + Eden_Mysql_Error::i()->argument(2, 'string'); + + $this->setParentQuery($parentQuery); + $this->_select = is_array($select) ? implode(', ', $select) : $select; + } + + /* Public Methods + -------------------------------*/ + /** + * Returns the string version of the query + * + * @param bool + * @return string + * @notes returns the query based on the registry + */ + public function getQuery() { + + return '('.substr(parent::getQuery(), 0, -1).')'; + } + + /** + * Sets the parent Query + * + * @param object usually the parent query object + * @return this + */ + public function setParentQuery(Eden_Sql_Select $parentQuery) { + $this->_parentQuery = $parentQuery; + return $this; + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/mysql/utility.php b/library/eden/mysql/utility.php new file mode 100755 index 0000000..520d51e --- /dev/null +++ b/library/eden/mysql/utility.php @@ -0,0 +1,124 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Generates utility query strings + * + * @package Eden + * @category sql + * @author Christian Blanquera cblanquera@openovate.com + */ +class Eden_Mysql_Utility extends Eden_Sql_Query +{ + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_query = NULL; + + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + /* Public Methods + -------------------------------*/ + /** + * Query for dropping a table + * + * @param string the name of the table + * @return this + */ + public function dropTable($table) { + //Argument 1 must be a string + Eden_Mysql_Error::i()->argument(1, 'string'); + + $this->_query = 'DROP TABLE `' . $table .'`'; + return $this; + } + + /** + * Returns the string version of the query + * + * @return string + */ + public function getQuery() { + return $this->_query.';'; + } + + /** + * Query for renaming a table + * + * @param string the name of the table + * @param string the new name of the table + * @return this + */ + public function renameTable($table, $name) { + //Argument 1 must be a string, 2 must be string + Eden_Mysql_Error::i()->argument(1, 'string')->argument(2, 'string'); + + $this->_query = 'RENAME TABLE `' . $table . '` TO `' . $name . '`'; + return $this; + } + + /** + * Query for showing all columns of a table + * + * @param string the name of the table + * @return this + */ + public function showColumns($table, $where = NULL) { + //Argument 1 must be a string, 2 must be string null + Eden_Mysql_Error::i()->argument(1, 'string')->argument(2, 'string', 'null'); + + $where = $where ? ' WHERE '.$where : NULL; + $this->_query = 'SHOW FULL COLUMNS FROM `' . $table .'`' . $where; + return $this; + } + + /** + * Query for showing all tables + * + * @param string like + * @return this + */ + public function showTables($like = NULL) { + Eden_Mysql_Error::i()->argument(1, 'string', 'null'); + + $like = $like ? ' LIKE '.$like : NULL; + $this->_query = 'SHOW TABLES'.$like; + return $this; + } + + /** + * Query for truncating a table + * + * @param string the name of the table + * @return this + */ + public function truncate($table) { + //Argument 1 must be a string + Eden_Mysql_Error::i()->argument(1, 'string'); + + $this->_query = 'TRUNCATE `' . $table .'`'; + return $this; + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/oauth.php b/library/eden/oauth.php new file mode 100644 index 0000000..ce9408d --- /dev/null +++ b/library/eden/oauth.php @@ -0,0 +1,608 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +require_once dirname(__FILE__).'/curl.php'; +require_once dirname(__FILE__).'/oauth/error.php'; +require_once dirname(__FILE__).'/oauth/base.php'; +require_once dirname(__FILE__).'/oauth/consumer.php'; +require_once dirname(__FILE__).'/oauth/server.php'; + +/** + * Oauth Factory; A summary of 2-legged and 3-legged OAuth + * which can generally connect to any properly implemented + * OAuth server. + * + * @package Eden + * @category core + * @author Christian Blanquera cblanquera@openovate.com + */ +class Eden_Oauth extends Eden_Class { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getSingleton(__CLASS__); + } + + /* Public Methods + -------------------------------*/ + /** + * Returns the oauth consumer class + * + * @return Eden_Oauth_Consumer + */ + public function consumer($url, $key, $secret) { + return Eden_Oauth_Consumer::i($url, $key, $secret); + } + + /** + * Returns an access token given the requiremets + * GET, HMAC-SHA1 + * + * @param string url + * @param string cnsumer key + * @param string consumer secret + * @param string token + * @param string token secret + * @param array extra query + * @param string|null realm + * @param string|null verifier + * @return string access token + */ + public function getHmacGetAccessToken($url, $key, $secret, $token, + $tokenSecret, array $query = array(), $realm = NULL, $verifier = NULL) { + //argument test + Eden_Oauth_Error::i() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'string') //Argument 2 must be a string + ->argument(3, 'string') //Argument 3 must be a string + ->argument(4, 'string') //Argument 4 must be a string + ->argument(5, 'string') //Argument 5 must be a string + ->argument(7, 'string', 'null') //Argument 7 must be a string or null + ->argument(8, 'string', 'null'); //Argument 8 must be a string or null + + return $this->consumer($url, $key, $secret) + ->setMethodToGet() //set method to get + ->setSignatureToHmacSha1() //set method to HMAC-SHA1 + ->when($realm) //when there is a realm + ->setRealm($realm) //set the realm + ->endWhen() //return back the consumer + ->when($verifier) //when there is a verifier + ->setVerifier($verifier) //set the verifier + ->endWhen() //return back the consumer + ->setRequestToken($token, $tokenSecret) //set the request token + ->getToken($query); //get the token + } + + /** + * Returns an access token given the requiremets + * GET, HMAC-SHA1, use Authorization Header + * + * @param string url + * @param string cnsumer key + * @param string consumer secret + * @param string token + * @param string token secret + * @param array extra query + * @param string|null realm + * @param string|null verifier + * @return string access token + */ + public function getHmacGetAuthorizationAccessToken($url, $key, $secret, $token, + $tokenSecret, array $query = array(), $realm = NULL, $verifier = NULL) { + //argument test + Eden_Oauth_Error::i() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'string') //Argument 2 must be a string + ->argument(3, 'string') //Argument 3 must be a string + ->argument(4, 'string') //Argument 4 must be a string + ->argument(5, 'string') //Argument 5 must be a string + ->argument(7, 'string', 'null') //Argument 7 must be a string or null + ->argument(8, 'string', 'null'); //Argument 8 must be a string or null + + return $this->consumer($url, $key, $secret) + ->useAuthorization() //use authorization header + ->setMethodToGet() //set method to get + ->setSignatureToHmacSha1() //set method to HMAC-SHA1 + ->when($realm) //when there is a realm + ->setRealm($realm) //set the realm + ->endWhen() //return back the consumer + ->when($verifier) //when there is a verifier + ->setVerifier($verifier) //set the verifier + ->endWhen() //return back the consumer + ->setRequestToken($token, $tokenSecret) //set the request token + ->getToken($query); //get the token + } + + /** + * Returns a request token given the requiremets + * GET, HMAC-SHA1, use Authorization Header + * + * @param string url + * @param string cnsumer key + * @param string consumer secret + * @param array extra query + * @param string|null realm + * @return string request token + */ + public function getHmacGetAuthorizationRequestToken($url, $key, $secret, array $query = array(), $realm = NULL) { + //argument test + Eden_Oauth_Error::i() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'string') //Argument 2 must be a string + ->argument(3, 'string') //Argument 3 must be a string + ->argument(5, 'string', 'null'); //Argument 5 must be a string or null + + return $this->consumer($url, $key, $secret) + ->useAuthorization() //use authorization header + ->setMethodToGet() //set method to get + ->setSignatureToHmacSha1() //set method to HMAC-SHA1 + ->when($realm) //when there is a realm + ->setRealm($realm) //set the realm + ->endWhen() //return back the consumer + ->getToken($query); //get the token + } + + /** + * Returns a request token given the requiremets + * GET, HMAC-SHA1 + * + * @param string url + * @param string cnsumer key + * @param string consumer secret + * @param array extra query + * @param string|null realm + * @return string request token + */ + public function getHmacGetRequestToken($url, $key, $secret, array $query = array(), $realm = NULL) { + //argument test + Eden_Oauth_Error::i() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'string') //Argument 2 must be a string + ->argument(3, 'string') //Argument 3 must be a string + ->argument(5, 'string', 'null'); //Argument 5 must be a string or null + + return $this->consumer($url, $key, $secret) + ->setMethodToGet() //set method to get + ->setSignatureToHmacSha1() //set method to HMAC-SHA1 + ->when($realm) //when there is a realm + ->setRealm($realm) //set the realm + ->endWhen() //return back the consumer + ->getToken($query); //get the token + } + + /** + * Returns an access token given the requiremets + * POST, HMAC-SHA1 + * + * @param string url + * @param string cnsumer key + * @param string consumer secret + * @param string token + * @param string token secret + * @param array extra query + * @param string|null realm + * @param string|null verifier + * @return string access token + */ + public function getHmacPostAccessToken($url, $key, $secret, $token, + $tokenSecret, array $query = array(), $realm = NULL, $verifier = NULL) { + //argument test + Eden_Oauth_Error::i() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'string') //Argument 2 must be a string + ->argument(3, 'string') //Argument 3 must be a string + ->argument(4, 'string') //Argument 4 must be a string + ->argument(5, 'string') //Argument 5 must be a string + ->argument(7, 'string', 'null') //Argument 7 must be a string or null + ->argument(8, 'string', 'null'); //Argument 8 must be a string or null + + return $this->consumer($url, $key, $secret) + ->setMethodToPost() //set method to post + ->setSignatureToHmacSha1() //set method to HMAC-SHA1 + ->when($realm) //when there is a realm + ->setRealm($realm) //set the realm + ->endWhen() //return back the consumer + ->when($verifier) //when there is a verifier + ->setVerifier($verifier) //set the verifier + ->endWhen() //return back the consumer + ->setRequestToken($token, $tokenSecret) //set the request token + ->getToken($query); //get the token + } + + /** + * Returns an access token given the requiremets + * POST, HMAC-SHA1, use Authorization Header + * + * @param string url + * @param string cnsumer key + * @param string consumer secret + * @param string token + * @param string token secret + * @param array extra query + * @param string|null realm + * @param string|null verifier + * @return string access token + */ + public function getHmacPostAuthorizationAccessToken($url, $key, $secret, $token, + $tokenSecret, array $query = array(), $realm = NULL, $verifier = NULL) { + //argument test + Eden_Oauth_Error::i() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'string') //Argument 2 must be a string + ->argument(3, 'string') //Argument 3 must be a string + ->argument(4, 'string') //Argument 4 must be a string + ->argument(5, 'string') //Argument 5 must be a string + ->argument(7, 'string', 'null') //Argument 7 must be a string or null + ->argument(8, 'string', 'null'); //Argument 8 must be a string or null + + return $this->consumer($url, $key, $secret) + ->useAuthorization() //use authorization header + ->setMethodToPost() //set method to post + ->setSignatureToHmacSha1() //set method to HMAC-SHA1 + ->when($realm) //when there is a realm + ->setRealm($realm) //set the realm + ->endWhen() //return back the consumer + ->when($verifier) //when there is a verifier + ->setVerifier($verifier) //set the verifier + ->endWhen() //return back the consumer + ->setRequestToken($token, $tokenSecret) //set the request token + ->getToken($query); //get the token + } + + /** + * Returns a request token given the requiremets + * POST, HMAC-SHA1, use Authorization Header + * + * @param string url + * @param string cnsumer key + * @param string consumer secret + * @param array extra query + * @param string|null realm + * @return string request token + */ + public function getHmacPostAuthorizationRequestToken($url, $key, $secret, array $query = array(), $realm = NULL) { + //argument test + Eden_Oauth_Error::i() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'string') //Argument 2 must be a string + ->argument(3, 'string') //Argument 3 must be a string + ->argument(5, 'string', 'null'); //Argument 5 must be a string or null + + return $this->consumer($url, $key, $secret) + ->useAuthorization() //use authorization header + ->setMethodToPost() //set method to post + ->setSignatureToHmacSha1() //set method to HMAC-SHA1 + ->when($realm) //when there is a realm + ->setRealm($realm) //set the realm + ->endWhen() //return back the consumer + ->getToken($query); //get the token + } + + /** + * Returns a request token given the requiremets + * POST, HMAC-SHA1 + * + * @param string url + * @param string cnsumer key + * @param string consumer secret + * @param array extra query + * @param string|null realm + * @return string request token + */ + public function getHmacPostRequestToken($url, $key, $secret, array $query = array(), $realm = NULL) { + //argument test + Eden_Oauth_Error::i() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'string') //Argument 2 must be a string + ->argument(3, 'string') //Argument 3 must be a string + ->argument(5, 'string', 'null'); //Argument 5 must be a string or null + + return $this->consumer($url, $key, $secret) + ->setMethodToPost() //set method to post + ->setSignatureToHmacSha1() //set method to HMAC-SHA1 + ->when($realm) //when there is a realm + ->setRealm($realm) //set the realm + ->endWhen() //return back the consumer + ->getToken($query); //get the token + } + + /** + * Returns an access token given the requiremets + * GET, PLAINTEXT + * + * @param string url + * @param string cnsumer key + * @param string consumer secret + * @param string token + * @param string token secret + * @param array extra query + * @param string|null realm + * @param string|null verifier + * @return string access token + */ + public function getPlainGetAccessToken($url, $key, $secret, $token, + $tokenSecret, array $query = array(), $realm = NULL, $verifier = NULL) { + //argument test + Eden_Oauth_Error::i() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'string') //Argument 2 must be a string + ->argument(3, 'string') //Argument 3 must be a string + ->argument(4, 'string') //Argument 4 must be a string + ->argument(5, 'string') //Argument 5 must be a string + ->argument(7, 'string', 'null') //Argument 7 must be a string or null + ->argument(8, 'string', 'null'); //Argument 8 must be a string or null + + return $this->consumer($url, $key, $secret) + ->setMethodToGet() //set method to get + ->setSignatureToPlainText() //set method to PLAIN TEXT + ->when($realm) //when there is a realm + ->setRealm($realm) //set the realm + ->endWhen() //return back the consumer + ->when($verifier) //when there is a verifier + ->setVerifier($verifier) //set the verifier + ->endWhen() //return back the consumer + ->setRequestToken($token, $tokenSecret) //set the request token + ->getToken($query); //get the token + } + + /** + * Returns an access token given the requiremets + * GET, PLAINTEXT, use Authorization Header + * + * @param string url + * @param string cnsumer key + * @param string consumer secret + * @param string token + * @param string token secret + * @param array extra query + * @param string|null realm + * @param string|null verifier + * @return string access token + */ + public function getPlainGetAuthorizationAccessToken($url, $key, $secret, $token, + $tokenSecret, array $query = array(), $realm = NULL, $verifier = NULL) { + //argument test + Eden_Oauth_Error::i() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'string') //Argument 2 must be a string + ->argument(3, 'string') //Argument 3 must be a string + ->argument(4, 'string') //Argument 4 must be a string + ->argument(5, 'string') //Argument 5 must be a string + ->argument(7, 'string', 'null') //Argument 7 must be a string or null + ->argument(8, 'string', 'null'); //Argument 8 must be a string or null + + return $this->consumer($url, $key, $secret) + ->useAuthorization() //use authorization header + ->setMethodToGet() //set method to get + ->setSignatureToPlainText() //set method to PLAIN TEXT + ->when($realm) //when there is a realm + ->setRealm($realm) //set the realm + ->endWhen() //return back the consumer + ->when($verifier) //when there is a verifier + ->setVerifier($verifier) //set the verifier + ->endWhen() //return back the consumer + ->setRequestToken($token, $tokenSecret) //set the request token + ->getToken($query); //get the token + } + + /** + * Returns a request token given the requiremets + * GET, PLAINTEXT, use Authorization Header + * + * @param string url + * @param string cnsumer key + * @param string consumer secret + * @param array extra query + * @param string|null realm + * @return string request token + */ + public function getPlainGetAuthorizationRequestToken($url, $key, $secret, array $query = array(), $realm = NULL) { + //argument test + Eden_Oauth_Error::i() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'string') //Argument 2 must be a string + ->argument(3, 'string') //Argument 3 must be a string + ->argument(5, 'string', 'null'); //Argument 5 must be a string or null + + return $this->consumer($url, $key, $secret) + ->useAuthorization() //use authorization header + ->setMethodToGet() //set method to get + ->setSignatureToPlainText() //set method to PLAIN TEXT + ->when($realm) //when there is a realm + ->setRealm($realm) //set the realm + ->endWhen() //return back the consumer + ->getToken($query); //get the token + } + + /** + * Returns a request token given the requiremets + * GET, PLAINTEXT + * + * @param string url + * @param string cnsumer key + * @param string consumer secret + * @param array extra query + * @param string|null realm + * @return string request token + */ + public function getPlainGetRequestToken($url, $key, $secret, array $query = array(), $realm = NULL) { + //argument test + Eden_Oauth_Error::i() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'string') //Argument 2 must be a string + ->argument(3, 'string') //Argument 3 must be a string + ->argument(5, 'string', 'null'); //Argument 5 must be a string or null + + return $this->consumer($url, $key, $secret) + ->setMethodToGet() //set method to get + ->setSignatureToPlainText() //set method to PLAIN TEXT + ->when($realm) //when there is a realm + ->setRealm($realm) //set the realm + ->endWhen() //return back the consumer + ->getToken($query); //get the token + } + + /** + * Returns an access token given the requiremets + * POST, PLAINTEXT + * + * @param string url + * @param string cnsumer key + * @param string consumer secret + * @param string token + * @param string token secret + * @param array extra query + * @param string|null realm + * @param string|null verifier + * @return string access token + */ + public function getPlainPostAccessToken($url, $key, $secret, $token, + $tokenSecret, array $query = array(), $realm = NULL, $verifier = NULL) { + //argument test + Eden_Oauth_Error::i() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'string') //Argument 2 must be a string + ->argument(3, 'string') //Argument 3 must be a string + ->argument(4, 'string') //Argument 4 must be a string + ->argument(5, 'string') //Argument 5 must be a string + ->argument(7, 'string', 'null') //Argument 7 must be a string or null + ->argument(8, 'string', 'null'); //Argument 8 must be a string or null + + return $this->consumer($url, $key, $secret) + ->setMethodToPost() //set method to post + ->setSignatureToPlainText() //set method to PLAIN TEXT + ->when($realm) //when there is a realm + ->setRealm($realm) //set the realm + ->endWhen() //return back the consumer + ->when($verifier) //when there is a verifier + ->setVerifier($verifier) //set the verifier + ->endWhen() //return back the consumer + ->setRequestToken($token, $tokenSecret) //set the request token + ->getToken($query); //get the token + } + + /** + * Returns an access token given the requiremets + * POST, PLAINTEXT, use Authorization Header + * + * @param string url + * @param string cnsumer key + * @param string consumer secret + * @param string token + * @param string token secret + * @param array extra query + * @param string|null realm + * @param string|null verifier + * @return string access token + */ + public function getPlainPostAuthorizationAccessToken($url, $key, $secret, $token, + $tokenSecret, array $query = array(), $realm = NULL, $verifier = NULL) { + //argument test + Eden_Oauth_Error::i() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'string') //Argument 2 must be a string + ->argument(3, 'string') //Argument 3 must be a string + ->argument(4, 'string') //Argument 4 must be a string + ->argument(5, 'string') //Argument 5 must be a string + ->argument(7, 'string', 'null') //Argument 7 must be a string or null + ->argument(8, 'string', 'null'); //Argument 8 must be a string or null + + return $this->consumer($url, $key, $secret) + ->useAuthorization() //use authorization header + ->setMethodToPost() //set method to post + ->setSignatureToPlainText() //set method to PLAIN TEXT + ->when($realm) //when there is a realm + ->setRealm($realm) //set the realm + ->endWhen() //return back the consumer + ->when($verifier) //when there is a verifier + ->setVerifier($verifier) //set the verifier + ->endWhen() //return back the consumer + ->setRequestToken($token, $tokenSecret) //set the request token + ->getToken($query); //get the token + } + + /** + * Returns a request token given the requiremets + * POST, PLAINTEXT, use Authorization Header + * + * @param string url + * @param string cnsumer key + * @param string consumer secret + * @param array extra query + * @param string|null realm + * @return string request token + */ + public function getPlainPostAuthorizationRequestToken($url, $key, $secret, array $query = array(), $realm = NULL) { + //argument test + Eden_Oauth_Error::i() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'string') //Argument 2 must be a string + ->argument(3, 'string') //Argument 3 must be a string + ->argument(5, 'string', 'null'); //Argument 5 must be a string or null + + return $this->consumer($url, $key, $secret) + ->useAuthorization() //use authorization header + ->setMethodToPost() //set method to post + ->setSignatureToPlainText() //set method to PLAIN TEXT + ->when($realm) //when there is a realm + ->setRealm($realm) //set the realm + ->endWhen() //return back the consumer + ->getToken($query); //get the token + } + + /** + * Returns a request token given the requiremets + * POST, PLAINTEXT + * + * @param string url + * @param string cnsumer key + * @param string consumer secret + * @param array extra query + * @param string|null realm + * @return string request token + */ + public function getPlainPostRequestToken($url, $key, $secret, array $query = array(), $realm = NULL) { + //argument test + Eden_Oauth_Error::i() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'string') //Argument 2 must be a string + ->argument(3, 'string') //Argument 3 must be a string + ->argument(5, 'string', 'null'); //Argument 5 must be a string or null + + return $this->consumer($url, $key, $secret) + ->setMethodToPost() //set method to post + ->setSignatureToPlainText() //set method to PLAIN TEXT + ->when($realm) //when there is a realm + ->setRealm($realm) //set the realm + ->endWhen() //return back the consumer + ->getToken($query); //get the token + } + + /** + * Returns the oauth server class + * + * @return Eden_Oauth_Server + */ + public function server() { + return Eden_Oauth_Server::i(); + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/oauth/base.php b/library/eden/oauth/base.php new file mode 100644 index 0000000..bfebcbe --- /dev/null +++ b/library/eden/oauth/base.php @@ -0,0 +1,138 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Trigger when something is false + * + * @package Eden + * @category core + * @author Christian Blanquera cblanquera@openovate.com + */ +class Eden_Oauth_Base extends Eden_Class { + /* Constants + -------------------------------*/ + const HMAC_SHA1 = 'HMAC-SHA1'; + const RSA_SHA1 = 'RSA-SHA1'; + const PLAIN_TEXT = 'PLAINTEXT'; + + const POST = 'POST'; + const GET = 'GET'; + + const OAUTH_VERSION = '1.0'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + /* Magic + -------------------------------*/ + /* Public Methods + -------------------------------*/ + /* Protected Methods + -------------------------------*/ + protected function _buildQuery($params, $separator = '&', $noQuotes = true, $subList = false) { + if(empty($params)) { + return ''; + } + + //encode both keys and values + $keys = $this->_encode(array_keys($params)); + $values = $this->_encode(array_values($params)); + + $params = array_combine($keys, $values); + + // Parameters are sorted by name, using lexicographical byte value ordering. + // http://oauth.net/core/1.0/#rfc.section.9.1.1 + uksort($params, 'strcmp'); + + // Turn params array into an array of "key=value" strings + foreach ($params as $key => $value) { + if (is_array($value)) { + // If two or more parameters share the same name, + // they are sorted by their value. OAuth Spec: 9.1.1 (1) + natsort($value); + $params[$key] = $this->_buildQuery($value, $separator, $noQuotes, true); + continue; + } + + if(!$noQuotes) { + $value = '"'.$value.'"'; + } + + $params[$key] = $value; + } + + if($subList) { + return $params; + } + + foreach($params as $key => $value) { + $params[$key] = $key.'='.$value; + } + + return implode($separator, $params); + } + + protected function _encode($string) { + if (is_array($string)) { + foreach($string as $i => $value) { + $string[$i] = $this->_encode($value); + } + + return $string; + } + + if (is_scalar($string)) { + return str_replace('%7E', '~', rawurlencode($string)); + } + + return NULL; + } + + protected function _decode($raw_input) { + return rawurldecode($raw_input); + } + + protected function _parseString($string) { + $array = array(); + + if(strlen($string) < 1) { + return $array; + } + + // Separate single string into an array of "key=value" strings + $keyvalue = explode('&', $query_string); + + // Separate each "key=value" string into an array[key] = value + foreach ($keyvalue as $pair) { + list($k, $v) = explode('=', $pair, 2); + + // Handle the case where multiple values map to the same key + // by pulling those values into an array themselves + if (isset($query_array[$k])) { + // If the existing value is a scalar, turn it into an array + if (is_scalar($query_array[$k])) { + $query_array[$k] = array($query_array[$k]); + } + array_push($query_array[$k], $v); + } else { + $query_array[$k] = $v; + } + } + + return $array; + } + + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/oauth/consumer.php b/library/eden/oauth/consumer.php new file mode 100644 index 0000000..4e4c0bd --- /dev/null +++ b/library/eden/oauth/consumer.php @@ -0,0 +1,499 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Oauth consumer methods + * + * @package Eden + * @category oauth + * @author Christian Blanquera cblanquera@openovate.com + */ +class Eden_Oauth_Consumer extends Eden_Oauth_Base { + /* Constants + -------------------------------*/ + const AUTH_HEADER = 'Authorization: OAuth %s'; + const POST_HEADER = 'Content-Type: application/x-www-form-urlencoded'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_consumerKey = NULL; + protected $_consumerSecret = NULL; + protected $_requestToken = NULL; + protected $_requestSecret = NULL; + protected $_useAuthorization = false; + + protected $_url = NULL; + protected $_method = NULL; + protected $_realm = NULL; + protected $_time = NULL; + protected $_nonce = NULL; + protected $_verifier = NULL; + protected $_callback = NULL; + protected $_signature = NULL; + protected $_meta = array(); + protected $_headers = array(); + + protected $_json = false; + + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + public function __construct($url, $key, $secret) { + //argument test + Eden_Oauth_Error::i() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'string') //Argument 2 must be a string + ->argument(3, 'string'); //Argument 3 must be a string + + $this->_consumerKey = $key; + $this->_consumerSecret = $secret; + + $this->_url = $url; + $this->_time = time(); + $this->_nonce = md5(uniqid(rand(), true)); + + $this->_signature = self::PLAIN_TEXT; + $this->_method = self::GET; + } + + /* Public Methods + -------------------------------*/ + /** + * Returns the authorization header string + * + * @param string + * @return string + */ + public function getAuthorization($signature, $string = true) { + //argument test + Eden_Oauth_Error::i() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'bool'); //Argument 2 must be a boolean + + //this is all possible configurations + $params = array( + 'realm' => $this->_realm, + 'oauth_consumer_key' => $this->_consumerKey, + 'oauth_token' => $this->_requestToken, + 'oauth_signature_method' => self::HMAC_SHA1, + 'oauth_signature' => $signature, + 'oauth_timestamp' => $this->_time, + 'oauth_nonce' => $this->_nonce, + 'oauth_version' => self::OAUTH_VERSION, + 'oauth_verifier' => $this->_verifier, + 'oauth_callback' => $this->_callback); + + //if no realm + if(is_null($this->_realm)) { + //remove it + unset($params['realm']); + } + + //if no token + if(is_null($this->_requestToken)) { + //remove it + unset($params['oauth_token']); + } + + //if no verifier + if(is_null($this->_verifier)) { + //remove it + unset($params['oauth_verifier']); + } + + + //if no callback + if(is_null($this->_callback)) { + //remove it + unset($params['oauth_callback']); + } + + if(!$string) { + return $params; + } + + return sprintf(self::AUTH_HEADER, $this->_buildQuery($params, ',', false)); + } + + /** + * Returns the results + * parsed as DOMDocument + * + * @return DOMDOcument + */ + public function getDomDocumentResponse(array $query = array()) { + $xml = new DOMDocument(); + $xml->loadXML($this->getResponse($query)); + return $xml; + } + + /** + * Returns the signature + * + * @return string + */ + public function getHmacPlainTextSignature() { + return $this->_consumerSecret . '&' . $this->_tokenSecret; + } + + /** + * Returns the signature + * + * @param array + * @return string + */ + public function getHmacSha1Signature(array $query = array()) { + //this is like the authorization params minus the realm and signature + $params = array( + 'oauth_consumer_key' => $this->_consumerKey, + 'oauth_token' => $this->_requestToken, + 'oauth_signature_method' => self::HMAC_SHA1, + 'oauth_timestamp' => $this->_time, + 'oauth_nonce' => $this->_nonce, + 'oauth_version' => self::OAUTH_VERSION, + 'oauth_verifier' => $this->_verifier, + 'oauth_callback' => $this->_callback); + + //if no token + if(is_null($this->_requestToken)) { + //unset that parameter + unset($params['oauth_token']); + } + + //if no token + if(is_null($this->_verifier)) { + //unset that parameter + unset($params['oauth_verifier']); + } + + //if no callback + if(is_null($this->_callback)) { + //remove it + unset($params['oauth_callback']); + } + + $query = array_merge($params, $query); //merge the params and the query + $query = $this->_buildQuery($query); //make query into a string + + //create the base string + $string = array($this->_method, $this->_encode($this->_url), $this->_encode($query)); + $string = implode('&', $string); + + //create the encryption key + $key = $this->_encode($this->_consumerSecret) . '&' . $this->_encode($this->_requestSecret); + + //authentication method + return base64_encode(hash_hmac('sha1', $string, $key, true)); + } + + /** + * Returns the json response from the server + * + * @param array + * @return array + */ + public function getJsonResponse(array $query = array(), $assoc = true) { + return json_decode($this->getResponse($query), $assoc); + } + + /** + * Returns the meta of the last call + * + * @return array + */ + public function getMeta($key = NULL) { + Eden_Oauth_Error::i()->argument(1, 'string', 'null'); + + if(isset($this->_meta[$key])) { + return $this->_meta[$key]; + } + + return $this->_meta; + } + + /** + * Returns the query response from the server + * + * @param array + * @return array + */ + public function getQueryResponse(array $query = array()) { + parse_str($this->getResponse($query), $response); + return $response; + } + + /** + * Returns the token from the server + * + * @param array + * @return array + */ + public function getResponse(array $query = array()) { + $headers = $this->_headers; + $json = NULL; + + if($this->_json) { + $json = json_encode($query); + $query = array(); + } + + //get the authorization parameters as an array + $signature = $this->getSignature($query); + $authorization = $this->getAuthorization($signature, false); + + //if we should use the authrization + if($this->_useAuthorization) { + //add the string to headers + $headers[] = sprintf(self::AUTH_HEADER, $this->_buildQuery($authorization, ',', false)); + } else { + //merge authorization and query + $query = array_merge($authorization, $query); + } + + $query = $this->_buildQuery($query); + $url = $this->_url; + + //set curl + $curl = Eden_Curl::i()->verifyHost(false)->verifyPeer(false); + + //if post + if($this->_method == self::POST) { + $headers[] = self::POST_HEADER; + + if(!is_null($json)) { + $query = $json; + } + + //get the response + $response = $curl->setUrl($url) + ->setPost(true) + ->setPostFields($query) + ->setHeaders($headers) + ->getResponse(); + } else { + if(trim($query)) { + //determine the conector + $connector = NULL; + + //if there is no question mark + if(strpos($url, '?') === false) { + $connector = '?'; + //if the redirect doesn't end with a question mark + } else if(substr($url, -1) != '?') { + $connector = '&'; + } + + //now add the secret to the redirect + $url .= $connector.$query; + } + + //get the response + $response = $curl->setUrl($url)->setHeaders($headers)->getResponse(); + } + + $this->_meta = $curl->getMeta(); + $this->_meta['url'] = $url; + $this->_meta['authorization'] = $authorization; + $this->_meta['headers'] = $headers; + $this->_meta['query'] = $query; + $this->_meta['response'] = $response; + + return $response; + } + + /** + * Returns the signature based on what signature method was set + * + * @param array + * @return string + */ + public function getSignature(array $query = array()) { + switch($this->_signature) { + case self::HMAC_SHA1: + return $this->getHmacSha1Signature($query); + case self::RSA_SHA1: + case self::PLAIN_TEXT: + default: + return $this->getHmacPlainTextSignature(); + } + } + + /** + * Returns the results + * parsed as SimpleXml + * + * @return SimpleXmlElement + */ + public function getSimpleXmlResponse(array $query = array()) { + return simplexml_load_string($this->getResponse($query)); + } + + /** + * When sent, sends the parameters as post fields + * + * @return this + */ + public function jsonEncodeQuery() { + $this->_json = true; + return $this; + } + + /** + * Sets the callback for authorization + * This should be set if wanting an access token + * + * @param string + * @return this + */ + public function setCallback($url) { + Eden_Oauth_Error::i()->argument(1, 'string'); + + $this->_callback = $url; + + return $this; + } + + /** + * Sets request headers + * + * @param array|string + * @return this + */ + public function setHeaders($key, $value = NULL) { + Eden_Oauth_Error::i() + ->argument(1, 'array', 'string') + ->argument(2, 'scalar','null'); + + if(is_array($key)) { + $this->_headers = $key; + return $this; + } + + $this->_headers[] = $key.': '.$value; + return $this; + } + + /** + * When sent, appends the parameters to the URL + * + * @return this + */ + public function setMethodToGet() { + $this->_method = self::GET; + return $this; + } + + /** + * When sent, sends the parameters as post fields + * + * @return this + */ + public function setMethodToPost() { + $this->_method = self::POST; + return $this; + } + + /** + * Some Oauth servers requires a realm to be set + * + * @param string + * @return this + */ + public function setRealm($realm) { + Eden_Oauth_Error::i()->argument(1, 'string'); + $this->_realm = $realm; + return $this; + } + + /** + * Sets the signature encryption type to HMAC-SHA1 + * + * @return this + */ + public function setSignatureToHmacSha1() { + $this->_signature = self::HMAC_SHA1; + return $this; + } + + /** + * Sets the signature encryption to RSA-SHA1 + * + * @return this + */ + public function setSignatureToRsaSha1() { + $this->_signature = self::RSA_SHA1; + return $this; + } + + /** + * Sets the signature encryption to PLAINTEXT + * + * @return this + */ + public function setSignatureToPlainText() { + $this->_signature = self::PLAIN_TEXT; + return $this; + } + + /** + * Sets the request token and secret. + * This should be set if wanting an access token + * + * @param string + * @param string + * @return this + */ + public function setToken($token, $secret) { + Eden_Oauth_Error::i() + ->argument(1, 'string') + ->argument(2, 'string'); + + $this->_requestToken = $token; + $this->_requestSecret = $secret; + + return $this; + } + + /** + * Some Oauth servers requires a verifier to be set + * when retrieving an access token + * + * @param string + * @return this + */ + public function setVerifier($verifier) { + Eden_Oauth_Error::i()->argument(1, 'scalar'); + $this->_verifier = $verifier; + return $this; + } + + /** + * When sent, appends the authroization to the headers + * + * @param bool + * @return this + */ + public function useAuthorization($use = true) { + Eden_Oauth_Error::i()->argument(1, 'bool'); + $this->_useAuthorization = $use; + return $this; + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/oauth/error.php b/library/eden/oauth/error.php new file mode 100644 index 0000000..f7a2392 --- /dev/null +++ b/library/eden/oauth/error.php @@ -0,0 +1,39 @@ + +/* + * This file is part of the Eden package. + * (c) 2010-2012 Christian Blanquera + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Oauth Errors + * + * @package Eden + * @category oauth + * @author Christian Blanquera cblanquera@openovate.com + */ +class Eden_Oauth_Error extends Eden_Error { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i($message = NULL, $code = 0) { + $class = __CLASS__; + return new $class($message, $code); + } + + /* Public Methods + -------------------------------*/ + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/oauth/server.php b/library/eden/oauth/server.php new file mode 100644 index 0000000..cd159e4 --- /dev/null +++ b/library/eden/oauth/server.php @@ -0,0 +1,38 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Oauth server methods + * + * @package Eden + * @category oauth + * @author Christian Blanquera cblanquera@openovate.com + */ +class Eden_Oauth_Server extends Eden_Oauth_Base { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + /* Public Methods + -------------------------------*/ + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/oauth2.php b/library/eden/oauth2.php new file mode 100644 index 0000000..37f062b --- /dev/null +++ b/library/eden/oauth2.php @@ -0,0 +1,87 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +require_once dirname(__FILE__).'/curl.php'; +require_once dirname(__FILE__).'/oauth2/error.php'; +require_once dirname(__FILE__).'/oauth2/abstract.php'; +require_once dirname(__FILE__).'/oauth2/client.php'; +require_once dirname(__FILE__).'/oauth2/desktop.php'; + +/** + * Oauth2 Factory class; + * + * @package Eden + * @category core oauth2 + * @author Christian Symon M. Buenavista sbuenavista@openovate.com + */ +class Eden_Oauth2 extends Eden_Class { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getSingleton(__CLASS__); + } + + /* Public Methods + -------------------------------*/ + /** + * Returns oauth 2 client side class + * + * @param string The application client ID, can get through registration + * @param string The application secret, can get through registration + * @param url Your callback url or where do you want to redirect the user after authentication + * @param url The request url, can get through registration + * @param url The access url, can get through registration + * @return Eden_Oauth2_Client + */ + public function client($client, $secret, $redirect, $requestUrl, $accessUrl) { + //argument test + Eden_Oauth2_Error::i() + ->argument(1, 'string') //argument 1 must be a string + ->argument(2, 'string') //argument 2 must be a url + ->argument(3, 'url') //argument 3 must be a url + ->argument(4, 'url') //argument 4 must be a url + ->argument(5, 'url'); //argument 5 must be a url + + return Eden_Oauth2_Client::i($client, $secret, $redirect, $requestUrl, $accessUrl); + } + + /** + * Returns oauth 2 desktop class + * + * @param string The application client ID, can get through registration + * @param string The application secret, can get through registration + * @param url Your callback url or where do you want to redirect the user after authentication + * @param url The request url, can get through registration + * @param url The access url, can get through registration + * @return Eden_Oauth2_Client + */ + public function desktop($client, $secret, $redirect, $requestUrl, $accessUrl) { + //argument test + Eden_Oauth2_Error::i() + ->argument(1, 'string') //argument 1 must be a string + ->argument(2, 'string') //argument 2 must be a url + ->argument(3, 'url') //argument 3 must be a url + ->argument(4, 'url') //argument 4 must be a url + ->argument(5, 'url'); //argument 5 must be a url + + return Eden_Oauth2_Desktop::i($client, $secret, $redirect, $requestUrl, $accessUrl); + } + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/oauth2/abstract.php b/library/eden/oauth2/abstract.php new file mode 100644 index 0000000..f9622bc --- /dev/null +++ b/library/eden/oauth2/abstract.php @@ -0,0 +1,228 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Oauth2 abstract class + * + * @package Eden + * @category oauth2 + * @author Christian Symon M. Buenavista sbuenavista@openovate.com + */ +abstract class Eden_Oauth2_Abstract extends Eden_Class { + /* Constants + -------------------------------*/ + const CODE = 'code'; + const TOKEN = 'token'; + const ONLINE = 'online'; + const OFFLINE = 'offline'; + const AUTO = 'auto'; + const FORCE = 'force'; + const TYPE = 'Content-Type'; + const REQUEST = 'application/x-www-form-urlencoded'; + + const RESPONSE_TYPE = 'response_type'; + const CLIENT_ID = 'client_id'; + const REDIRECT_URL = 'redirect_uri'; + const ACCESS_TYPE = 'access_type'; + const APROVAL = 'approval_prompt'; + const CLIENT_SECRET = 'client_secret'; + const GRANT_TYPE = 'grant_type'; + const AUTHORIZATION = 'authorization_code'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_client = NULL; + protected $_secret = NULL; + protected $_redirect = NULL; + protected $_state = NULL; + protected $_scope = NULL; + protected $_display = NULL; + protected $_requestUrl = NULL; + protected $_accessUrl = NULL; + + protected $_responseType = self::CODE; + protected $_approvalPrompt = self::AUTO; + + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public function __construct($client, $secret, $redirect, $requestUrl, $accessUrl) { + //argument test + Eden_Oauth2_Error::i() + ->argument(1, 'string') //argument 1 must be a string + ->argument(2, 'string') //argument 2 must be a string + ->argument(3, 'url') //argument 3 must be a url + ->argument(4, 'url') //argument 4 must be a url + ->argument(5, 'url'); //argument 5 must be a url + + $this->_client = $client; + $this->_secret = $secret; + $this->_redirect = $redirect; + $this->_requestUrl = $requestUrl; + $this->_accessUrl = $accessUrl; + } + + /* Public Methods + -------------------------------*/ + /** + * Set auth to auto approve + * + * @return this + */ + public function autoApprove() { + $this->_approvalPrompt = self::AUTO; + + return $this; + } + + /** + * Set auth for force approve + * + * @return this + */ + public function forceApprove() { + $this->_approvalPrompt = self::FORCE; + + return $this; + } + + /** + * Set state + * + * @param string + * @return this + */ + public function setState($state) { + //argument 1 must be a string + Eden_Oauth2_Error::i()->argument(1, 'string'); + $this->_state = $state; + + return $this; + } + + /** + * Set scope + * + * @param string|array + * @return this + */ + public function setScope($scope) { + //argument 1 must be a string or array + Eden_Oauth2_Error::i()->argument(1, 'string', 'array'); + $this->_scope = $scope; + + return $this; + } + + /** + * Set display + * + * @param string|array + * @return this + */ + public function setDisplay($display) { + //argument 1 must be a string or array + Eden_Oauth2_Error::i()->argument(1, 'string', 'array'); + $this->_display = $display; + + return $this; + } + + /** + * Check if the response is json format + * + * @param string + * @return boolean + */ + public function isJson($string) { + //argument 1 must be a string + Eden_Oauth2_Error::i()->argument(1, 'string'); + + json_decode($string); + return (json_last_error() == JSON_ERROR_NONE); + } + + /** + * abstract function for getting login url + * + * @param string|null + * + */ + abstract public function getLoginUrl($scope = NULL, $display = NULL); + + /** + * Returns website login url + * + * @param string* + * @return array + */ + abstract public function getAccess($code); + + /* Protected Methods + -------------------------------*/ + protected function _getLoginUrl($query) { + //if there is a scope + if(!is_null($this->_scope)) { + //if scope is in array + if(is_array($this->_scope)) { + $this->_scope = implode(' ', $this->_scope); + } + //add scope to the query + $query['scope'] = $this->_scope; + } + //if there is state + if(!is_null($this->_state)) { + //add state to the query + $query['state'] = $this->_state; + } + //if there is display + if(!is_null($this->_display)) { + //add state to the query + $query['display'] = $this->_display; + } + //generate a login url + return $this->_requestUrl.'?'.http_build_query($query); + } + + + protected function _getAccess($query, $code = NULL) { + //if there is a code + if(!is_null($code)) { + //put codein the query + $query[self::CODE] = $code; + } + //set curl + $result = Eden_Curl::i() + ->setUrl($this->_accessUrl) + ->verifyHost() + ->verifyPeer() + ->setHeaders(self::TYPE, self::REQUEST) + ->setPostFields(http_build_query($query)) + ->getResponse(); + + //check if results is in JSON format + if($this->isJson($result)) { + //if it is in json, lets json decode it + $response = json_decode($result, true); + //else its not in json format + } else { + //parse it to make it an array + parse_str($result, $response); + } + + return $response; + } + + + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/oauth2/client.php b/library/eden/oauth2/client.php new file mode 100644 index 0000000..31c4175 --- /dev/null +++ b/library/eden/oauth2/client.php @@ -0,0 +1,120 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Oauth2 client class + * + * @package Eden + * @category oauth2 + * @author Christian Symon M. Buenavista sbuenavista@openovate.com + */ +class Eden_Oauth2_Client extends Eden_Oauth2_Abstract { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_responseType = self::CODE; + protected $_accessType = self::ONLINE; + protected $_approvalPrompt = self::AUTO; + protected $_grantType = self::AUTHORIZATION; + + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getSingleton(__CLASS__); + } + + /* Public Methods + -------------------------------*/ + /** + * Set auth for offline access + * + * @return this + */ + public function forOffline() { + $this->_accessType = self::OFFLINE; + + return $this; + } + + /** + * Set auth for online access + * + * @return this + */ + public function forOnline() { + $this->_accessType = self::ONLINE; + + return $this; + } + + /** + * Returns website login url + * + * @param string|null + * @param string|null + * @return url + */ + public function getLoginUrl($scope = NULL, $display = NULL) { + //argument test + Eden_Oauth2_Error::i() + ->argument(1, 'string', 'array', 'null') //argument 1 must be a string, array or null + ->argument(2, 'string', 'array', 'null'); //argument 2 must be a string, array or null + + //if scope in not null + if(!is_null($scope)) { + //lets set the scope + $this->setScope($scope); + } + //if display in not null + if(!is_null($display)) { + //lets set the display + $this->setDisplay($display); + } + + //populate fields + $query = array( + self::RESPONSE_TYPE => $this->_responseType, + self::CLIENT_ID => $this->_client, + self::REDIRECT_URL => $this->_redirect, + self::ACCESS_TYPE => $this->_accessType, + self::APROVAL => $this->_approvalPrompt); + + return $this->_getLoginUrl($query); + } + + /** + * Returns website login url + * + * @param string* + * @return array + */ + public function getAccess($code) { + //argument 1 must be a string + Eden_Oauth2_Error::i()->argument(1, 'string'); + + //populate fields + $query = array( + self::CLIENT_ID => $this->_client, + self::CLIENT_SECRET => $this->_secret, + self::REDIRECT_URL => $this->_redirect, + self::GRANT_TYPE => $this->_grantType); + + return $this->_getAccess($query, $code); + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} diff --git a/library/eden/oauth2/desktop.php b/library/eden/oauth2/desktop.php new file mode 100644 index 0000000..21a9e67 --- /dev/null +++ b/library/eden/oauth2/desktop.php @@ -0,0 +1,95 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Oauth2 desktop class + * + * @package Eden + * @category desktop + * @author Christian Symon M. Buenavista sbuenavista@openovate.com + */ +class Eden_Oauth2_Desktop extends Eden_Oauth2_Abstract { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_responseType = self::CODE; + protected $_grantType = 'authorization_code'; + + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + /* Public Methods + -------------------------------*/ + /** + * Returns website login url + * + * @param string|null + * @param string|null + * @return url + */ + public function getLoginUrl($scope = NULL, $display = NULL) { + //argument test + Eden_Oauth2_Error::i() + ->argument(1, 'string', 'array', 'null') //argument 1 must be a string, array or null + ->argument(2, 'string', 'array', 'null'); //argument 2 must be a string, array or null + + //if scope in not null + if(!is_null($scope)) { + //lets set the scope + $this->setScope($scope); + } + //if display in not null + if(!is_null($display)) { + //lets set the display + $this->setDisplay($display); + } + + //populate fields + $query = array( + self::RESPONSE_TYPE => $this->_responseType, + self::CLIENT_ID => $this->_client, + self::REDIRECT_URL => $this->_redirect); + + return $this->_getLoginUrl($query); + + } + + /** + * Returns website login url + * + * @param string* + * @return array + */ + public function getAccess($code) { + //argument 1 must be a string + Eden_Oauth2_Error::i()->argument(1, 'string'); + + //populate fields + $query = array( + self::CLIENT_ID => $this->_client, + self::CLIENT_SECRET => $this->_secret, + self::REDIRECT_URL => $this->_redirect, + self::GRANT_TYPE => $this->_grantType); + + return $this->_getAccess($query, $code); + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} diff --git a/library/eden/oauth2/error.php b/library/eden/oauth2/error.php new file mode 100644 index 0000000..1a3bf19 --- /dev/null +++ b/library/eden/oauth2/error.php @@ -0,0 +1,39 @@ + +/* + * This file is part of the Eden package. + * (c) 2010-2012 Christian Blanquera + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Oauth2 Error class + * + * @package Eden + * @category error + * @author Christian Blanquera cblanquera@openovate.com + */ +class Eden_Oauth2_Error extends Eden_Error { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i($message = NULL, $code = 0) { + $class = __CLASS__; + return new $class($message, $code); + } + + /* Public Methods + -------------------------------*/ + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/oauth2/server.php b/library/eden/oauth2/server.php new file mode 100644 index 0000000..6069838 --- /dev/null +++ b/library/eden/oauth2/server.php @@ -0,0 +1,38 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Oauth2 server methods + * + * @package Eden + * @category oauth2 + * @author Christian Blanquera cblanquera@openovate.com + */ +class Eden_Oauth2_Server extends Eden_Oauth_Base { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + /* Public Methods + -------------------------------*/ + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/path.php b/library/eden/path.php new file mode 100644 index 0000000..78c36fb --- /dev/null +++ b/library/eden/path.php @@ -0,0 +1,309 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +require_once dirname(__FILE__).'/type.php'; + +/** + * General available methods for common pathing issues + * + * @package Eden + * @category core + * @author Christian Blanquera cblanquera@openovate.com + */ +class Eden_Path extends Eden_Type_String implements ArrayAccess { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + public function __construct($path) { + //argument 1 must be a string + Eden_Path_Error::i()->argument(1, 'string'); + parent::__construct($this->_format($path)); + } + + public function __toString() { + return $this->_data; + } + + /* Public Methods + -------------------------------*/ + /** + * Attempts to get the full absolute path + * as described on the server. The path + * given must exist. + * + * @param string|null root path + * @return this + */ + public function absolute($root = NULL) { + //argument 1 must be a string or null + Eden_Path_Error::i()->argument(1, 'string', 'null'); + + //if path is a directory or file + if(is_dir($this->_data) || is_file($this->_data)) { + return $this; + } + + //if root is null + if(is_null($root)) { + //assume the root is doc root + $root = $_SERVER['DOCUMENT_ROOT']; + } + + //get the absolute path + $absolute = $this->_format($root).$this->_data; + + //if absolute is a directory or file + if(is_dir($absolute) || is_file($absolute)) { + $this->_data = $absolute; + return $this; + } + + //if we are here then it means that no path was found so we should throw an exception + Eden_Path_Error::i() + ->setMessage(Eden_Path_Error::FULL_PATH_NOT_FOUND) + ->addVariable($this->_data) + ->addVariable($absolute) + ->trigger(); + } + + /** + * Adds a path to the existing one + * + * @param string[,string..] + * @return this + */ + public function append($path) { + //argument 1 must be a string + $error = Eden_Path_Error::i()->argument(1, 'string'); + + //each argument will be a path + $paths = func_get_args(); + + //for each path + foreach($paths as $i => $path) { + //check for type errors + $error->argument($i + 1, $path, 'string'); + //add to path + $this->_data .= $this->_format($path); + } + + return $this; + } + + /** + * Returns the path array + * + * @return array + */ + public function getArray() { + return explode('/', $this->_data); + } + + /** + * isset using the ArrayAccess interface + * + * @param number + * @return bool + */ + public function offsetExists($offset) { + return in_array($offset, $this->getArray()); + } + + /** + * returns data using the ArrayAccess interface + * + * @param number + * @return bool + */ + public function offsetGet($offset) { + $pathArray = $this->getArray(); + + if($offset == 'first') { + $offset = 0; + } + + if($offset == 'last') { + $offset = count($pathArray) - 1; + } + + if(is_numeric($offset)) { + + return isset($pathArray[$offset]) ? $pathArray[$offset] : NULL; + } + + return NULL; + } + + /** + * Sets data using the ArrayAccess interface + * + * @param number + * @param mixed + * @return void + */ + public function offsetSet($offset, $value) { + if (is_null($offset)) { + $this->append($value); + } else if($offset == 'prepend') { + $this->prepend($value); + } else if($offset == 'replace') { + $this->replace($value); + } else { + $pathArray = $this->getArray(); + if($offset > 0 && $offset < count($pathArray)) { + $pathArray[$offset] = $value; + $this->_data = implode('/', $pathArray); + } + } + } + + /** + * unsets using the ArrayAccess interface + * + * @param number + * @return bool + */ + public function offsetUnset($offset) {} + + /** + * Adds a path before the existing one + * + * @param string[,string..] + * @return string + */ + public function prepend($path) { + //argument 1 must be a string + $error = Eden_Path_Error::i()->argument(1, 'string'); + + //each argument will be a path + $paths = func_get_args(); + + //for each path + foreach($paths as $i => $path) { + //check for type errors + $error->argument($i + 1, $path, 'string'); + //add to path + $this->_data = $this->_format($path).$this->_data; + } + + return $this; + } + + /** + * Remove the last path + * + * @return this + */ + public function pop(){ + //get the path array + $pathArray = $this->getArray(); + + //remove the last + $path = array_pop($pathArray); + + //set path + $this->_data = implode('/', $pathArray); + + return $path; + } + + /** + * Replaces the last path with this one + * + * @param string + * @return string + */ + public function replace($path) { + //argument 1 must be a string + Eden_Path_Error::i()->argument(1, 'string'); + + //get the path array + $pathArray = $this->getArray(); + + //pop out the last + array_pop($pathArray); + + //push in the new + $pathArray[] = $path; + + //assign back to path + $this->_data = implode('/', $pathArray); + + return $this; + } + + /* Protected Methods + -------------------------------*/ + protected function _format($path) { + //replace back slash with forward + $path = str_replace('\\', '/', $path); + + //replace double forward slash with 1 forward slash + $path = str_replace('//', '/', $path); + + //if there is a last forward slash + if(substr($path, -1, 1) == '/') { + //remove it + $path = substr($path, 0, -1); + } + + //if the path does not start with a foward slash + //and the path does not have a colon + //(this is a test for windows) + if(substr($path, 0, 1) != '/' && !preg_match("/^[A-Za-z]+\:/", $path)) { + //it's safe to add a slash + $path = '/'.$path; + } + + return $path; + } + + /* Private Methods + -------------------------------*/ +} + +/** + * Timezone Errors + */ +class Eden_Path_Error extends Eden_Error { + /* Constants + -------------------------------*/ + const FULL_PATH_NOT_FOUND = 'The path %s or %s was not found.'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i($message = NULL, $code = 0) { + $class = __CLASS__; + return new $class($message, $code); + } + + /* Public Methods + -------------------------------*/ + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/paypal.php b/library/eden/paypal.php new file mode 100644 index 0000000..1fc747c --- /dev/null +++ b/library/eden/paypal.php @@ -0,0 +1,213 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +require_once dirname(__FILE__).'/curl.php'; +require_once dirname(__FILE__).'/paypal/error.php'; +require_once dirname(__FILE__).'/paypal/base.php'; +require_once dirname(__FILE__).'/paypal/authorization.php'; +require_once dirname(__FILE__).'/paypal/base.php'; +require_once dirname(__FILE__).'/paypal/billing.php'; +require_once dirname(__FILE__).'/paypal/button.php'; +require_once dirname(__FILE__).'/paypal/checkout.php'; +require_once dirname(__FILE__).'/paypal/direct.php'; +require_once dirname(__FILE__).'/paypal/recurring.php'; +require_once dirname(__FILE__).'/paypal/transaction.php'; + +/** + * Paypal API factory. This is a factory class with + * methods that will load up different Paypal API methods. + * Paypal classes are organized as described on their + * developer site: Express Checkout, Transaction, + * Authorization, Direct Payment, Recurring Payment, + * Button Manager and Billing Agreement + * + * @package Eden + * @category Paypal + * @author Christian Blanquera cblanquera@openovate.com + */ +class Eden_Paypal extends Eden_Class { + /* Constants + -------------------------------*/ + const PEM = '/paypal/cacert.pem'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getSingleton(__CLASS__); + } + + /* Public Methods + -------------------------------*/ + /** + * Returns paypal authorization + * + * @param string API username + * @param string API password + * @param string API signature + * @param string API certificate file + * @return Eden_Paypal_Authorization + */ + public function authorization($user, $password, $signature, $certificate = NULL) { + Eden_Paypal_Error::i() + ->argument(1, 'string') + ->argument(2, 'string') + ->argument(3, 'string') + ->argument(4, 'string', 'null'); + + if(!is_string($certificate)) { + $certificate = dirname(__FILE__).self::PEM; + } + + return Eden_Paypal_Authorization::i($user, $password, $signature, $certificate); + } + + /** + * Returns paypal billing + * + * @param string API username + * @param string API password + * @param string API signature + * @param string API certificate file + * @return Eden_Paypal_Billing + */ + public function billing($user, $password, $signature, $certificate = NULL) { + if(!is_string($certificate)) { + $certificate = dirname(__FILE__).self::PEM; + } + + return Eden_Paypal_Billing::i($user, $password, $signature, $certificate); + } + + /** + * Returns paypal button + * + * @param string API username + * @param string API password + * @param string API signature + * @param string API certificate file + * @return Eden_Paypal_Button + */ + public function button($user, $password, $signature, $certificate = NULL) { + Eden_Paypal_Error::i() + ->argument(1, 'string') + ->argument(2, 'string') + ->argument(3, 'string') + ->argument(4, 'string', 'null'); + + if(!is_string($certificate)) { + $certificate = dirname(__FILE__).self::PEM; + } + + return Eden_Paypal_Button::i($user, $password, $signature, $certificate); + } + + /** + * Returns paypal express checkout + * + * @param string + * @param string API username + * @param string API password + * @param string API signature + * @param string|null API certificate file + * @return Eden_Paypal_Checkout + */ + public function checkout($user, $password, $signature, $certificate = NULL, $live = false) { + Eden_Paypal_Error::i() + ->argument(1, 'string') + ->argument(2, 'string') + ->argument(3, 'string') + ->argument(4, 'string', 'null'); + + if(!is_string($certificate)) { + $certificate = dirname(__FILE__).self::PEM; + } + + return Eden_Paypal_Checkout::i($user, $password, $signature, $certificate, $live); + } + + /** + * Returns paypal directPayment + * + * @param string API username + * @param string API password + * @param string API signature + * @param string API certificate file + * @return Eden_Paypal_Direct + */ + public function direct($user, $password, $signature, $certificate = NULL) { + Eden_Paypal_Error::i() + ->argument(1, 'string') + ->argument(2, 'string') + ->argument(3, 'string') + ->argument(4, 'string', 'null'); + + if(!is_string($certificate)) { + $certificate = dirname(__FILE__).self::PEM; + } + + return Eden_Paypal_Direct::i($user, $password, $signature, $certificate); + } + + /** + * Returns paypal recurringPayment + * + * @param string API username + * @param string API password + * @param string API signature + * @param string API certificate file + * @return Eden_Paypal_Recurring + */ + public function recurring($user, $password, $signature, $certificate = NULL) { + Eden_Paypal_Error::i() + ->argument(1, 'string') + ->argument(2, 'string') + ->argument(3, 'string') + ->argument(4, 'string', 'null'); + + if(!is_string($certificate)) { + $certificate = dirname(__FILE__).self::PEM; + } + + return Eden_Paypal_Recurring::i($user, $password, $signature, $certificate); + } + + /** + * Returns paypal transaction + * + * @param string API username + * @param string API password + * @param string API signature + * @param string API certificate file + * @return Eden_Paypal_Transaction + */ + public function transaction($user, $password, $signature, $certificate = NULL) { + Eden_Paypal_Error::i() + ->argument(1, 'string') + ->argument(2, 'string') + ->argument(3, 'string') + ->argument(4, 'string', 'null'); + + if(!is_string($certificate)) { + $certificate = dirname(__FILE__).self::PEM; + } + + return Eden_Paypal_Transaction::i($user, $password, $signature, $certificate); + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/paypal/authorization.php b/library/eden/paypal/authorization.php new file mode 100644 index 0000000..6537209 --- /dev/null +++ b/library/eden/paypal/authorization.php @@ -0,0 +1,234 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Paypal Website Payments Pro - Authorization and Capture + * + * @package Eden + * @category Paypal + * @author Christian Symon M. Buenavista sbuenavista@openovate.com + */ +class Eden_Paypal_Authorization extends Eden_Paypal_Base { + /* Constants + -------------------------------*/ + const DO_AUTHORIZATION = 'DoAuthorization'; + const DO_CAPTURE = 'DoCapture'; + const DO_REAUTHORIZATION = 'DoReauthorization'; + const DO_VOID = 'DoVoid'; + + const TRANSACTION_ID = 'TRANSACTIONID'; + const AUTHORIZATION_ID = 'AUTHORIZATIONID'; + + const ENTITY = 'TRANSACTIONENTITY'; + const ORDER = 'Order'; + const ACK = 'ACK'; + const SUCCESS = 'Success'; + const AMOUNT = 'AMT'; + const CURRENCY = 'CURRENCYCODE'; + const COMPLETE_TYPE = 'COMPLETETYPE'; + const COMPLETE = 'COMPLETE'; + const NO_COMPLETE = 'NoComplete'; + const NOTE = 'NOTE'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_amout = NULL; + protected $_currency = NULL; + protected $_completeType = NULL; + protected $_note = NULL; + protected $_transactionId = NULL; + + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + /* Public Methods + -------------------------------*/ + /** + * Authorize a payment. + * + * @return string + */ + public function doAuthorization() { + //populate fields + $query = array( + self::TRANSACTION_ID => $this->_transactionId, + self::AMOUNT => $this->_amount, //amount of the payment + self::ENTITY => self::ORDER, //Type of transaction to authorize + self::CURRENCY => $this->_currency); //currency code, default is USD + //call request method + $response = $this->_request(self::DO_AUTHORIZATION, $query); + //if parameters are success + if(isset($response[self::ACK]) && $response[self::ACK] == self::SUCCESS) { + // Get the transaction Id + return $response[self::TRANSACTION_ID]; + } + + return $response; + } + + /** + * Captures an authorized payment. + * + * @return string + */ + public function doCapture() { + //populate fields + $query = array( + self::AUTHORIZATION_ID => $this->_transactionId, //Transaction Id + self::AMOUNT => $this->_amount, //amount of the payment + self::CURRENCY => $this->_currency, //currency code, default is USD + self::COMPLETE_TYPE => $this->_completeType, //Valid values are Complete or NotComplete + self::NOTE => $this->_note); //An informational note about the settlement + + //call request method + $response = $this->_request(self::DO_CAPTURE, $query); + //if parameters are success + if(isset($response[self::ACK]) && $response[self::ACK] == self::SUCCESS) { + // Get the authorization Id + return $response[self::AUTHORIZATION_ID]; + } + + return $response; + } + + /** + * Re-authorize a payment. + * + * @return string + */ + public function doReAuthorization() { + //populate fields + $query = array( + self::AUTHORIZATION_ID => $this->_transactionId, + self::AMOUNT => $this->_amount, //amount of the payment + self::CURRENCY => $this->_currency); //currency code, default is USD + //call request method + $response = $this->_request(self::DO_REAUTHORIZATION, $query); + //if parameters are success + if(isset($response[self::ACK]) && $response[self::ACK] == self::SUCCESS) { + // Get the authorization ID + return $response[self::AUTHORIZATION_ID]; + } + + return $response; + } + + /** + * Void an order or an authorization. + * + * @return string + */ + public function doVoid() { + //populate fields + $query = array( + self::AUTHORIZATION_ID => $this->_transactionId, + self::NOTE => $this->_note); //An informational note about the settlement + //call request method + $response = $this->_request(self::DO_VOID, $query); + //if parameters are success + if(isset($response[self::ACK]) && $response[self::ACK] == self::SUCCESS) { + // Get the authorization ID + return $response[self::AUTHORIZATION_ID]; + } + + return $response; + } + + /** + * Set item amount + * + * @param integer|float Item amount + * @return this + */ + public function setAmount($amount) { + //Argument 1 must be an integer or float + Eden_Paypal_Error::i()->argument(1, 'int', 'float'); + + $this->_amount = $amount; + return $this; + } + + /** + * Set complete type to complete + * Complete - This the last capture you intend to make + * + * @return this + */ + public function setComplete() { + $this->_completeType = self::COMPLETE; + return $this; + } + + /** + * Set currency code + * + * @param string Currency code + * @return this + */ + public function setCurrency($currency) { + //Argument 1 must be a string + Eden_Paypal_Error::i()->argument(1, 'string'); + + $this->_currency = $currency; + return $this; + } + + /** + * Set complete type to no complete + * NoComplete - You intend to make additional captures. + * + * @return this + */ + public function setNoComplete() { + $this->_completeType = self::NO_COMPLETE; + return $this; + } + + /** + * An informational note about this settlement that + * is displayed to the buyer in email and in their + * transaction history. + * + * @param string + * @return this + */ + public function setNote($note) { + //Argument 1 must be a string + Eden_Paypal_Error::i()->argument(1, 'string'); + + $this->_note = $note; + return $this; + } + + /** + * Set Transaction Id + * + * @param string + * @return this + */ + public function setTransactionId($transactionId) { + //Argument 1 must be a string + Eden_Paypal_Error::i()->argument(1, 'string'); + + $this->_transactionId = $transactionId; + return $this; + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/paypal/base.php b/library/eden/paypal/base.php new file mode 100644 index 0000000..e35470c --- /dev/null +++ b/library/eden/paypal/base.php @@ -0,0 +1,118 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Paypal Base + * + * @package Eden + * @category paypal + * @author Christian Symon M. Buenavista sbuenavista@openovate.com + */ +class Eden_Paypal_Base extends Eden_Class { + /* Constants + -------------------------------*/ + const VERSION = '84.0'; + const TEST_URL = 'https://api-3t.sandbox.paypal.com/nvp'; + const LIVE_URL = 'https://api-3t.paypal.com/nvp'; + const SANDBOX_URL = 'https://test.authorize.net/gateway/transact.dll'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_meta = array(); + protected $_url = NULL; + protected $_user = NULL; + protected $_password = NULL; + protected $_signature = NULL; + protected $_certificate = NULL; + + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + /* Magic + -------------------------------*/ + public function __construct($user, $password, $signature, $certificate, $live = false) { + $this->_user = $user; + $this->_password = $password; + $this->_signature = $signature; + $this->_certificate = $certificate; + + $this->_url = self::TEST_URL; + $this->_baseUrl = self::TEST_URL; + if($live) { + $this->_url = self::LIVE_URL; + $this->_baseUrl = self::LIVE_URL; + } + } + + /* Public Methods + -------------------------------*/ + /** + * Populates after a request has been sent + * + * @return array + */ + public function getMeta() { + return $this->_meta; + } + + /* Protected Methods + -------------------------------*/ + protected function _accessKey($array) { + foreach($array as $key => $val) { + if(is_array($val)) { + $array[$key] = $this->_accessKey($val); + } + + if($val == false || $val == NULL || empty($val) || !$val) { + unset($array[$key]); + } + + } + + return $array; + } + + protected function _request($method, array $query = array(), $post = true) { + //Argument 1 must be a string + Eden_Paypal_Error::i()->argument(1, 'string'); + + //Our request parameters + $default = array( + 'USER' => $this->_user, + 'PWD' => $this->_password, + 'SIGNATURE' => $this->_signature, + 'VERSION' => self::VERSION, + 'METHOD' => $method); + + //generate URL-encoded query string to build our NVP string + $query = http_build_query($query + $default); + + $curl = Eden_Curl::i() + ->setUrl($this->_baseUrl) + ->setVerbose(true) + ->setCaInfo($this->_certificate) + ->setPost(true) + ->setPostFields($query); + + $response = $curl->getQueryResponse(); + + $this->_meta['url'] = $this->_baseUrl; + $this->_meta['query'] = $query; + $this->_meta['curl'] = $curl->getMeta(); + $this->_meta['response'] = $response; + + return $response; + } + + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/paypal/billing.php b/library/eden/paypal/billing.php new file mode 100644 index 0000000..0db865d --- /dev/null +++ b/library/eden/paypal/billing.php @@ -0,0 +1,175 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Paypal Website Payments Pro - Billing Agreement + * + * @package Eden + * @category Paypal + * @author Christian Symon M. Buenavista sbuenavista@openovate.com + */ +class Eden_Paypal_Billing extends Eden_Paypal_Base { + /* Constants + -------------------------------*/ + const SET_AGREEMENT = 'SetCustomerBillingAgreement'; + const GET_AGREEMENT = 'GetBillingAgreementCustomerDetails'; + const TOKEN = 'TOKEN'; + const RETURN_URL = 'RETURNURL'; + const CANCEL_URL = 'CANCELURL'; + + const ANY = 'Any'; + const INSTANT_ONLY = 'InstantOnly'; + const ACK = 'ACK'; + const SUCCESS = 'Success'; + + const BILLING_TYPE = 'L_BILLINGTYPEn'; + const BILLING_DESC = 'L_BILLINGAGREEMENTDESCRIPTIONn'; + const PAYMENT_TYPE = 'L_PAYMENTTYPEn'; + const AGREEMENT_CUSTOM = 'L_BILLINGAGREEMENTCUSTOMn'; + const AMOUNT = 'AMT'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_token = NULL; + protected $_amout = NULL; + protected $_currency = NULL; + protected $_completeType = NULL; + protected $_billingType = NULL; + protected $_billingDesc = NULL; + protected $_paymentType = NULL; + protected $_agreementCustom = NULL; + + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + /* Public Methods + -------------------------------*/ + /** + * initiates the creation of a billing agreement. + * + * @param string Returing URL + * @param string Cancel URL + * @return string + */ + public function getResponse($return, $cancel) { + //Argument Test + Eden_Paypal_Error::i() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'string'); //Argument 2 must be a string + + //populate fields + $query = array( + self::RETURN_URL => $return, + self::CANCEL_URL => $cancel, + self::BILLING_TYPE => $this->_billingType, + self::BILLING_DESC => $this->_billingDesc, //Description associated with the billing agreement. + self::PAYMENT_TYPE => $this->_paymentType, //Valid vaules are Any or InstantOnly + self::AGREEMENT_CUSTOM => $this->_agreementCustom); //Custom annotation field for your own use. + + //call request method + $response = $this->_request(self::SET_AGREEMENT, $query); + + //if parameters are success + if(isset($response[self::ACK]) && $response[self::ACK] == self::SUCCESS) { + //fetch token + $this->_token = $response[self::TOKEN]; + //if token is exist and not empty + if($this->_token) { + return $this->_getAgreement(); + } + } + + return $response; + } + + /** + * Custom annotation field for your own use. + * + * @param string + * @return this + * @note For recurring payments, this field is ignored. + */ + public function setAgreementCustom($agreementCustom) { + //Argument 1 must be a string + Eden_Paypal_Error::i()->argument(1, 'string'); + + $this->_agreementCustom = $agreementCustom; + return $this; + } + + /** + * Description of goods or services associated + * with the billing agreement. + * + * @param string + * @return this + */ + public function setBillingDesc($billingDesc) { + //Argument 1 must be a string + Eden_Paypal_Error::i()->argument(1, 'string'); + + $this->_billingDesc = $billingDesc; + return $this; + } + + /** + * Set billing type + * + * @param string + * @return this + */ + public function setBillingType($billingType) { + //Argument 1 must be a string + Eden_Paypal_Error::i()->argument(1, 'string'); + + $this->_billingType = $billingType; + return $this; + } + + /** + * Set payment type to Any + * + * @return this + * @note For recurring payments, this field is ignored. + */ + public function setToAny() { + $this->_paymentType = self::ANY; + return $this; + } + + /** + * Set payment type to Instant Only + * + * @return this + * @note For recurring payments, this field is ignored. + */ + public function setToInstantOnly() { + $this->_paymentType = self::INSTANT_ONLY; + return $this; + } + + /* Protected Methods + -------------------------------*/ + protected function _getAgreement() { + //populate fields + $query = array(self::TOKEN => $this->_token); + //call request method + return $this->_request(self::GET_AGREEMENT, $query); + } + + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/paypal/button.php b/library/eden/paypal/button.php new file mode 100644 index 0000000..b63bb59 --- /dev/null +++ b/library/eden/paypal/button.php @@ -0,0 +1,529 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Website Payments Standard - Button Manager + * + * @package Eden + * @category Paypal + * @author Christian Symon M. Buenavista sbuenavista@openovate.com + */ +class Eden_Paypal_Button extends Eden_Paypal_Base { + /* Constants + -------------------------------*/ + const SEARCH = 'BMButtonSearch'; + const SET_BUTTON = 'BMCreateButton'; + const GET_BUTTON = 'BMGetButtonDetails'; + const GET_INVENTORY = 'BMGetInventory'; + const REMOVE_BUTTON = 'BMManageButtonStatus'; + const UPDATE_BUTTON = 'BMUpdateButton'; + + const BUTTON_ID = 'HOSTEDBUTTONID'; + const REMOVE = 'DELETE'; + + const OPTION_NAME = 'OPTIONnNAME'; + const OPTION_SELECT = 'L_OPTIONnSELECTx'; + const OPTION_PRICE = 'L_OPTION0PRICEx'; + const OPTION_TYPE = 'OPTIONnTYPE'; + const BILLING_PERIOD = 'L_OPTIONnBILLINGPERIOD x'; + const BILLING_FREQUENCY = 'L_OPTIONnBILLINGPFREQUENCY x'; + const BILING_TOTAL = 'L_OPTIONnTOTALBILLINGCYCLES x'; + const OPTION_AMOUNT = 'L_OPTIONnAMOUNTx'; + const SHIPPING_AMOUNT = 'L_OPTIONnSHIPPINGAMOUNTx'; + const TAX_AMOUNT = 'L_OPTIONnTAXAMOUNTx'; + const START = 'STARTDATE'; + const END = 'ENDDATE'; + + const BUY_NOW = 'BUYNOW'; + const CART = 'CART'; + const GIFT_CERTIFICATE = 'GIFTCERTIFICATE'; + const SUBSCRIBE = 'SUBSCRIBE'; + const DONATE = 'DONATE'; + const UNSUBSCRIBE = 'UNSUBSCRIBE'; + const VIEW_CART = 'VIEWCART'; + const PAYMENT_PLAN = 'PAYMENTPLAN'; + const AUTOBILLING = 'AUTOBILLING'; + const PAYMENT = 'PAYMENT'; + + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_buttonId = NULL; + protected $_start = NULL; + protected $_end = NULL; + protected $_buttonType = NULL; + protected $_optionName = NULL; + protected $_optionSelect = NULL; + protected $_optionPrice = NULL; + protected $_optionType = NULL; + protected $_billingPeriod = NULL; + protected $_billingFrequency = NULL; + protected $_billingTotal = NULL; + protected $_optionAmount = NULL; + protected $_shippingAmount = NULL; + protected $_taxAmount = NULL; + + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + /* Public Methods + -------------------------------*/ + /** + * Initiates the creation of a billing agreement. + * + * @return string + */ + public function getButton() { + //populate fields + $query = array( + self::BUTTON_TYPE => $this->_buttonType, //The kind of button you want to create. + self::OPTION_NAME => $this->_name, //The menu name + self::OPTION_SELECT => $this->_select, //The menu item’s name + self::OPTION_PRICE => $this->_price, //The price associated with the first menu item + self::OPTION_TYPE => $this->_type, //The installment option type for an OPTIONnNAME + self::BILLING_PERIOD => $this->_billingPeriod, //The installment cycle unit + self::BILLING_FREQUENCY => $this->_billingFrequency,//The installment cycle frequency in units + self::BILLING_TOTAL => $this->_billingTotal, //The total number of billing cycles, + self::OPTION_AMOUNT => $this->_optionAmount, //The base amount to bill for the cycle. + self::SHIPPING_AMOUNt => $this->_shippingAmount, //The shipping amount to bill for the cycle + self::TAX_AMOUNT => $this->_taxAmount); //The tax amount to bill for the cycle + + //call request method + $response = $this->_request(self::SET_BUTTON, $query); + //if parameters are success + if(isset($response[self::BUTTON_ID])) { + // Get the button ID + $this->_buttonId = $response[self::BUTTON_ID]; + //call get button detail method + return $this->_request(self::GET_BUTTON, $query); + } + + return $response; + } + + /** + * Determine the inventory levels and other + * inventory-related information for a button + * and menu items associated with the button. + * Typically, you call BMGetInventory to obtain + * field values before calling BMSetInventory + * to change the inventory levels. + * + * @return string + */ + public function getInventory() { + //populate fields + $query = array(self::BUTTON_ID => $this->_buttonId); + //call request method + $resposne = $this->_request(self::GET_INVENTORY, $query); + + return $response; + } + + /** + * Change the status of a hosted button. + * Currently, you can only delete a button. + * + * @return string + */ + public function remove() { + //populate fields + $query = array( + self::BUTTON_ID => $this->_buttonId, //The Hosted Button Id + self::STATUS => self::REMOVE); //Delete the button + //call request method + $resposne = $this->_request(self::REMOVE_BUTTON, $query); + + return $response; + } + + /** + * Obtain a list of your hosted Website + * Payments Standard buttons. + * + * @return string + */ + public function search() { + //populate fields + $query = array( + self::START => $this->_start, //Starting date for the search. + self::END => $this->_end); //Ending date for the search. + //call request method + return $this->_request(self::SEARCH, $query); + } + + /** + * The base amount to bill for the cycle. + * + * @param string + * @return this + */ + public function setAmount($amount) { + //Argument 1 must be a string + Eden_Paypal_Error::i()->argument(1, 'string'); + + $this->_amount = $amount; + return $this; + } + + /** + * The installment cycle frequency in units, + * e.g. if the billing frequency is 2 and the + * billing period is Month, the billing cycle + * is every 2 months. The default billing + * frequency is 1. + * + * @param string + * @return this + */ + public function setBillingFrequency($billingFrequency) { + //Argument 1 must be a string + Eden_Paypal_Error::i()->argument(1, 'int'); + + $this->_billingFrequency = $billingFrequency; + return $this; + } + + /** + * Valid values are + * NoBillingPeriodType - None (default) + * Day + * Week + * SemiMonth + * Month + * Year + * + * @param string + * @return this + */ + public function setBillingPeriod($billingPeriod) { + //Argument 1 must be a string + Eden_Paypal_Error::i()->argument(1, 'string'); + + $this->_billingPeriod = $billingPeriod; + return $this; + } + + /** + * The total number of billing cycles, regardless of + * the duration of a cycle; 1 is the default + * + * @param string + * @return this + */ + public function setBillingTotal($billingTotal) { + //Argument 1 must be a string + Eden_Paypal_Error::i()->argument(1, 'int'); + + $this->_billingTotal = $billingTotal; + return $this; + } + + /** + * Set hosted button id + * + * @param string The hosted button id + * @return this + */ + public function setButtonId($setbuttonId) { + //Argument 1 must be a string + Eden_Paypal_Error::i()->argument(1, 'string'); + + $this->_setbuttonId = setbuttonId; + return $this; + } + + /** + * Ending date for the search. + * The value must be in UTC/GMT format + * + * @param string + * @return this + */ + public function setEndDate($end) { + //Argument 1 must be a string + Eden_Paypal_Error::i()->argument(1, 'string'); + + $date = strtotime($end); + $this->_end = gmdate('Y-m-d\TH:i:s\Z', $date); + return $this; + } + + /** + * It is one or more variables, in which n is a + * digit between 0 and 4, inclusive, for hosted + * buttons; otherwise, it is a digit between 0 + * and 9, inclusive + * + * @param string + * @return this + */ + public function setName($name) { + //Argument 1 must be a string + Eden_Paypal_Error::i()->argument(1, 'string'); + + $this->_name = $name; + return $this; + } + + /** + * It is a list of variables for each OPTIONnNAME, + * in which x is a digit between 0 and 9, inclusive + * + * @param string + * @return this + * @note If you specify a price, you cannot set + * a button variable to amount. + */ + public function setOptionPrice($optionPrice) { + //Argument 1 must be a string + Eden_Paypal_Error::i()->argument(1, 'string'); + + $this->_optionPrice = $optionPrice; + return $this; + } + + /** + * It is a list of variables for each OPTIONnNAME, + * in which x is a digit between 0 and 9, inclusive + * + * @param string + * @return this + */ + public function setOptionSelect($optionSelect) { + //Argument 1 must be a string + Eden_Paypal_Error::i()->argument(1, 'string'); + + $this->_optionSelect = $optionSelect; + return $this; + } + + /** + * The shipping amount to bill for the cycle, + * in addition to the base amount. + * + * @param string + * @return this + */ + public function setShippingAmount($shippingAmount) { + //Argument 1 must be a string + Eden_Paypal_Error::i()->argument(1, 'string'); + + $this->_shippingAmount = $shippingAmount; + return $this; + } + + /** + * Starting date for the search. + * The value must be in UTC/GMT format + * + * @param string + * @return this + */ + public function setStartDate($start) { + //Argument 1 must be a string + Eden_Paypal_Error::i()->argument(1, 'string'); + + $date = strtotime($start); + $this->_start = gmdate('Y-m-d\TH:i:s\Z', $date); + return $this; + } + + /** + * The tax amount to bill for the cycle, + * in addition to the base amount. + * + * @param string + * @return this + */ + public function setTaxAmount($taxAmount) { + //Argument 1 must be a string + Eden_Paypal_Error::i()->argument(1, 'string'); + + $this->_taxAmount = $taxAmount; + return $this; + } + + /** + * Set button type to Autobilling + * + * @return this + */ + public function setToAutobilling() { + $this->_buttonType = self::AUTOBILLING; + return $this; + } + + /** + * Set button type to buy now + * + * @return this + */ + public function setToBuyNow() { + $this->_buttonType = self::BUY_NOW; + return $this; + } + + /** + * Set button type to CART + * + * @return this + */ + public function setToCart() { + $this->_buttonType = self::CART; + return $this; + } + + /** + * Set button type to Donate + * + * @return this + */ + public function setToDonate() { + $this->_buttonType = self::DONATE; + return $this; + } + + /** + * Set button type to Gift Certificate + * + * @return this + */ + public function setToGiftCertificate() { + $this->_buttonType = self::GIFT_CERTIFICATE; + return $this; + } + + /** + * Set button type to Payment + * + * @return this + */ + public function setToPayment() { + $this->_buttonType = self::PAYMENT; + return $this; + } + + /** + * Set button type to Payment Plan + * + * @return this + */ + public function setToPaymentPlan() { + $this->_buttonType = self::PAYMENT_PLAN; + return $this; + } + + /** + * Set button type to Subscribe + * + * @return this + */ + public function setToSubscribe() { + $this->_buttonType = self::SUBSCRIBE; + return $this; + } + + /** + * Set button type to UnSubscribe + * + * @return this + */ + public function setToUnSubscribe() { + $this->_buttonType = self::UNSUBSCRIBE; + return $this; + } + + /** + * Set button type to View Cart + * + * @return this + */ + public function setToViewCart() { + $this->_buttonType = self::VIEW_CART; + return $this; + } + + /** + * Valid values are + * FULL - Payment in full + * VARIABLE - Variable installments + * EMI - Equal installments + * + * @param string + * @return this + */ + public function setType() { + + $this->_type = $tType; + return $this; + } + + /** + * Valid values are + * FULL - Payment in full + * VARIABLE - Variable installments + * EMI - Equal installments + * + * @param string + * @return this + */ + public function setTypeFull() { + + $this->_optionType = 'FULL'; + return $this; + } + + /** + * Updates the an agreeement + * + * @return string + */ + public function update() { + //populate fields + $query = array( + self::BUTTON_ID => $this->_buttonId, //The Hosted Button Id + self::BUTTON_TYPE => $this->_buttonType, //The kind of button you want to create. + self::OPTION_NAME => $this->_optionName, //The menu name + self::OPTION_SELECT => $this->_optionSelect, //The menu item’s name + self::OPTION_PRICE => $this->_optionPrice, //The price associated with the first menu item + self::OPTION_TYPE => $this->_optionType, //he installment option type for an OPTIONnNAME + self::BILLING_PERIOD => $this->_billingPeriod, //The installment cycle unit + self::BILLING_FREQUENCY => $this->_billingFrequency,//The installment cycle frequency in units + self::BILLING_TOTAL => $this->_billingTotal, //The total number of billing cycles, + self::OPTION_AMOUNT => $this->_amount, //The base amount to bill for the cycle. + self::SHIPPING_AMOUNt => $this->_shippingAmount, //The shipping amount to bill for the cycle + self::TAX_AMOUNT => $this->_taxAmount); //The tax amount to bill for the cycle + + //call request method + $response = $this->_request(self::UPDATE, $query); + //if parameters are success + if(isset($response[self::BUTTON_ID])) { + // Get the button ID + $this->_buttonId = $response[self::BUTTON_ID]; + //call get button detail method + return $this->_getButton; + } + + return $response; + + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/paypal/cacert.pem b/library/eden/paypal/cacert.pem new file mode 100644 index 0000000..cb4d18b --- /dev/null +++ b/library/eden/paypal/cacert.pem @@ -0,0 +1,3379 @@ + + +
##
+## ca-bundle.crt -- Bundle of CA Root Certificates
+##
+## Certificate data from Mozilla as of: Thu Nov  3 19:04:19 2011
+##
+## This is a bundle of X.509 certificates of public Certificate Authorities
+## (CA). These were automatically extracted from Mozilla's root certificates
+## file (certdata.txt).  This file can be found in the mozilla source tree:
+## http://mxr.mozilla.org/mozilla/source/security/nss/lib/ckfw/builtins/certdata.txt?raw=1
+##
+## It contains the certificates in PEM format and therefore
+## can be directly used with curl / libcurl / php_curl, or with
+## an Apache+mod_ssl webserver for SSL client authentication.
+## Just configure this file as the SSLCACertificateFile.
+##
+
+# ***** BEGIN LICENSE BLOCK *****
+# Version: MPL 1.1/GPL 2.0/LGPL 2.1
+#
+# The contents of this file are subject to the Mozilla Public License Version
+# 1.1 (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+# http://www.mozilla.org/MPL/
+#
+# Software distributed under the License is distributed on an "AS IS" basis,
+# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+# for the specific language governing rights and limitations under the
+# License.
+#
+# The Original Code is the Netscape security libraries.
+#
+# The Initial Developer of the Original Code is
+# Netscape Communications Corporation.
+# Portions created by the Initial Developer are Copyright (C) 1994-2000
+# the Initial Developer. All Rights Reserved.
+#
+# Contributor(s):
+#
+# Alternatively, the contents of this file may be used under the terms of
+# either the GNU General Public License Version 2 or later (the "GPL"), or
+# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+# in which case the provisions of the GPL or the LGPL are applicable instead
+# of those above. If you wish to allow use of your version of this file only
+# under the terms of either the GPL or the LGPL, and not to allow others to
+# use your version of this file under the terms of the MPL, indicate your
+# decision by deleting the provisions above and replace them with the notice
+# and other provisions required by the GPL or the LGPL. If you do not delete
+# the provisions above, a recipient may use your version of this file under
+# the terms of any one of the MPL, the GPL or the LGPL.
+#
+# ***** END LICENSE BLOCK *****
+# @(#) $RCSfile: certdata.txt,v $ $Revision: 1.80 $ $Date: 2011/11/03 15:11:58 $
+
+GTE CyberTrust Global Root
+==========================
+-----BEGIN CERTIFICATE-----
+MIICWjCCAcMCAgGlMA0GCSqGSIb3DQEBBAUAMHUxCzAJBgNVBAYTAlVTMRgwFgYDVQQKEw9HVEUg
+Q29ycG9yYXRpb24xJzAlBgNVBAsTHkdURSBDeWJlclRydXN0IFNvbHV0aW9ucywgSW5jLjEjMCEG
+A1UEAxMaR1RFIEN5YmVyVHJ1c3QgR2xvYmFsIFJvb3QwHhcNOTgwODEzMDAyOTAwWhcNMTgwODEz
+MjM1OTAwWjB1MQswCQYDVQQGEwJVUzEYMBYGA1UEChMPR1RFIENvcnBvcmF0aW9uMScwJQYDVQQL
+Ex5HVEUgQ3liZXJUcnVzdCBTb2x1dGlvbnMsIEluYy4xIzAhBgNVBAMTGkdURSBDeWJlclRydXN0
+IEdsb2JhbCBSb290MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCVD6C28FCc6HrHiM3dFw4u
+sJTQGz0O9pTAipTHBsiQl8i4ZBp6fmw8U+E3KHNgf7KXUwefU/ltWJTSr41tiGeA5u2ylc9yMcql
+HHK6XALnZELn+aks1joNrI1CqiQBOeacPwGFVw1Yh0X404Wqk2kmhXBIgD8SFcd5tB8FLztimQID
+AQABMA0GCSqGSIb3DQEBBAUAA4GBAG3rGwnpXtlR22ciYaQqPEh346B8pt5zohQDhT37qw4wxYMW
+M4ETCJ57NE7fQMh017l93PR2VX2bY1QY6fDq81yx2Yt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BAMCAQYwHwYDVR0jBBgwFoAUSOZo+SvS
+spXXR9gjIBBPM5iQn9QwHQYDVR0OBBYEFEjmaPkr0rKV10fYIyAQTzOYkJ/UMAwGA1UdEwQFMAMB
+Af8wGgYJKoZIhvZ9B0EABA0wCxsFVjMuMGMDAgbAMA0GCSqGSIb3DQEBBQUAA4GBAFjOKer89961
+zgK5F7WF0bnj4JXMJTENAKaSbn+2kmOeUJXRmm/kEd5jhW6Y7qj/WsjTVbJmcVfewCHrPSqnI0kB
+BIZCe/zuf6IWUrVnZ9NA2zsmWLIodz2uFHdh1voqZiegDfqnc1zqcPGUIWVEX/r87yloqaKHee95
+70+sB3c4
+-----END CERTIFICATE-----
+
+Digital Signature Trust Co. Global CA 1
+=======================================
+-----BEGIN CERTIFICATE-----
+MIIDKTCCApKgAwIBAgIENnAVljANBgkqhkiG9w0BAQUFADBGMQswCQYDVQQGEwJVUzEkMCIGA1UE
+ChMbRGlnaXRhbCBTaWduYXR1cmUgVHJ1c3QgQ28uMREwDwYDVQQLEwhEU1RDQSBFMTAeFw05ODEy
+MTAxODEwMjNaFw0xODEyMTAxODQwMjNaMEYxCzAJBgNVBAYTAlVTMSQwIgYDVQQKExtEaWdpdGFs
+IFNpZ25hdHVyZSBUcnVzdCBDby4xETAPBgNVBAsTCERTVENBIEUxMIGdMA0GCSqGSIb3DQEBAQUA
+A4GLADCBhwKBgQCgbIGpzzQeJN3+hijM3oMv+V7UQtLodGBmE5gGHKlREmlvMVW5SXIACH7TpWJE
+NySZj9mDSI+ZbZUTu0M7LklOiDfBu1h//uG9+LthzfNHwJmm8fOR6Hh8AMthyUQncWlVSn5JTe2i
+o74CTADKAqjuAQIxZA9SLRN0dja1erQtcQIBA6OCASQwggEgMBEGCWCGSAGG+EIBAQQEAwIABzBo
+BgNVHR8EYTBfMF2gW6BZpFcwVTELMAkGA1UEBhMCVVMxJDAiBgNVBAoTG0RpZ2l0YWwgU2lnbmF0
+dXJlIFRydXN0IENvLjERMA8GA1UECxMIRFNUQ0EgRTExDTALBgNVBAMTBENSTDEwKwYDVR0QBCQw
+IoAPMTk5ODEyMTAxODEwMjNagQ8yMDE4MTIxMDE4MTAyM1owCwYDVR0PBAQDAgEGMB8GA1UdIwQY
+MBaAFGp5fpFpRhgTCgJ3pVlbYJglDqL4MB0GA1UdDgQWBBRqeX6RaUYYEwoCd6VZW2CYJQ6i+DAM
+BgNVHRMEBTADAQH/MBkGCSqGSIb2fQdBAAQMMAobBFY0LjADAgSQMA0GCSqGSIb3DQEBBQUAA4GB
+ACIS2Hod3IEGtgllsofIH160L+nEHvI8wbsEkBFKg05+k7lNQseSJqBcNJo4cvj9axY+IO6CizEq
+kzaFI4iKPANo08kJD038bKTaKHKTDomAsH3+gG9lbRgzl4vCa4nuYD3Im+9/KzJic5PLPON74nZ4
+RbyhkwS7hp86W0N6w4pl
+-----END CERTIFICATE-----
+
+Digital Signature Trust Co. Global CA 3
+=======================================
+-----BEGIN CERTIFICATE-----
+MIIDKTCCApKgAwIBAgIENm7TzjANBgkqhkiG9w0BAQUFADBGMQswCQYDVQQGEwJVUzEkMCIGA1UE
+ChMbRGlnaXRhbCBTaWduYXR1cmUgVHJ1c3QgQ28uMREwDwYDVQQLEwhEU1RDQSBFMjAeFw05ODEy
+MDkxOTE3MjZaFw0xODEyMDkxOTQ3MjZaMEYxCzAJBgNVBAYTAlVTMSQwIgYDVQQKExtEaWdpdGFs
+IFNpZ25hdHVyZSBUcnVzdCBDby4xETAPBgNVBAsTCERTVENBIEUyMIGdMA0GCSqGSIb3DQEBAQUA
+A4GLADCBhwKBgQC/k48Xku8zExjrEH9OFr//Bo8qhbxe+SSmJIi2A7fBw18DW9Fvrn5C6mYjuGOD
+VvsoLeE4i7TuqAHhzhy2iCoiRoX7n6dwqUcUP87eZfCocfdPJmyMvMa1795JJ/9IKn3oTQPMx7JS
+xhcxEzu1TdvIxPbDDyQq2gyd55FbgM2UnQIBA6OCASQwggEgMBEGCWCGSAGG+EIBAQQEAwIABzBo
+BgNVHR8EYTBfMF2gW6BZpFcwVTELMAkGA1UEBhMCVVMxJDAiBgNVBAoTG0RpZ2l0YWwgU2lnbmF0
+dXJlIFRydXN0IENvLjERMA8GA1UECxMIRFNUQ0EgRTIxDTALBgNVBAMTBENSTDEwKwYDVR0QBCQw
+IoAPMTk5ODEyMDkxOTE3MjZagQ8yMDE4MTIwOTE5MTcyNlowCwYDVR0PBAQDAgEGMB8GA1UdIwQY
+MBaAFB6CTShlgDzJQW6sNS5ay97u+DlbMB0GA1UdDgQWBBQegk0oZYA8yUFurDUuWsve7vg5WzAM
+BgNVHRMEBTADAQH/MBkGCSqGSIb2fQdBAAQMMAobBFY0LjADAgSQMA0GCSqGSIb3DQEBBQUAA4GB
+AEeNg61i8tuwnkUiBbmi1gMOOHLnnvx75pO2mqWilMg0HZHRxdf0CiUPPXiBng+xZ8SQTGPdXqfi
+up/1902lMXucKS1M/mQ+7LZT/uqb7YLbdHVLB3luHtgZg3Pe9T7Qtd7nS2h9Qy4qIOF+oHhEngj1
+mPnHfxsb1gYgAlihw6ID
+-----END CERTIFICATE-----
+
+Verisign Class 3 Public Primary Certification Authority
+=======================================================
+-----BEGIN CERTIFICATE-----
+MIICPDCCAaUCEHC65B0Q2Sk0tjjKewPMur8wDQYJKoZIhvcNAQECBQAwXzELMAkGA1UEBhMCVVMx
+FzAVBgNVBAoTDlZlcmlTaWduLCBJbmMuMTcwNQYDVQQLEy5DbGFzcyAzIFB1YmxpYyBQcmltYXJ5
+IENlcnRpZmljYXRpb24gQXV0aG9yaXR5MB4XDTk2MDEyOTAwMDAwMFoXDTI4MDgwMTIzNTk1OVow
+XzELMAkGA1UEBhMCVVMxFzAVBgNVBAoTDlZlcmlTaWduLCBJbmMuMTcwNQYDVQQLEy5DbGFzcyAz
+IFB1YmxpYyBQcmltYXJ5IENlcnRpZmljYXRpb24gQXV0aG9yaXR5MIGfMA0GCSqGSIb3DQEBAQUA
+A4GNADCBiQKBgQDJXFme8huKARS0EN8EQNvjV69qRUCPhAwL0TPZ2RHP7gJYHyX3KqhEBarsAx94
+f56TuZoAqiN91qyFomNFx3InzPRMxnVx0jnvT0Lwdd8KkMaOIG+YD/isI19wKTakyYbnsZogy1Ol
+hec9vn2a/iRFM9x2Fe0PonFkTGUugWhFpwIDAQABMA0GCSqGSIb3DQEBAgUAA4GBALtMEivPLCYA
+TxQT3ab7/AoRhIzzKBxnki98tsX63/Dolbwdj2wsqFHMc9ikwFPwTtYmwHYBV4GSXiHx0bH/59Ah
+WM1pF+NEHJwZRDmJXNycAA9WjQKZ7aKQRUzkuxCkPfAyAw7xzvjoyVGM5mKf5p/AfbdynMk2Omuf
+Tqj/ZA1k
+-----END CERTIFICATE-----
+
+Verisign Class 3 Public Primary Certification Authority - G2
+============================================================
+-----BEGIN CERTIFICATE-----
+MIIDAjCCAmsCEH3Z/gfPqB63EHln+6eJNMYwDQYJKoZIhvcNAQEFBQAwgcExCzAJBgNVBAYTAlVT
+MRcwFQYDVQQKEw5WZXJpU2lnbiwgSW5jLjE8MDoGA1UECxMzQ2xhc3MgMyBQdWJsaWMgUHJpbWFy
+eSBDZXJ0aWZpY2F0aW9uIEF1dGhvcml0eSAtIEcyMTowOAYDVQQLEzEoYykgMTk5OCBWZXJpU2ln
+biwgSW5jLiAtIEZvciBhdXRob3JpemVkIHVzZSBvbmx5MR8wHQYDVQQLExZWZXJpU2lnbiBUcnVz
+dCBOZXR3b3JrMB4XDTk4MDUxODAwMDAwMFoXDTI4MDgwMTIzNTk1OVowgcExCzAJBgNVBAYTAlVT
+MRcwFQYDVQQKEw5WZXJpU2lnbiwgSW5jLjE8MDoGA1UECxMzQ2xhc3MgMyBQdWJsaWMgUHJpbWFy
+eSBDZXJ0aWZpY2F0aW9uIEF1dGhvcml0eSAtIEcyMTowOAYDVQQLEzEoYykgMTk5OCBWZXJpU2ln
+biwgSW5jLiAtIEZvciBhdXRob3JpemVkIHVzZSBvbmx5MR8wHQYDVQQLExZWZXJpU2lnbiBUcnVz
+dCBOZXR3b3JrMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDMXtERXVxp0KvTuWpMmR9ZmDCO
+FoUgRm1HP9SFIIThbbP4pO0M8RcPO/mn+SXXwc+EY/J8Y8+iR/LGWzOOZEAEaMGAuWQcRXfH2G71
+lSk8UOg013gfqLptQ5GVj0VXXn7F+8qkBOvqlzdUMG+7AUcyM83cV5tkaWH4mx0ciU9cZwIDAQAB
+MA0GCSqGSIb3DQEBBQUAA4GBAFFNzb5cy5gZnBWyATl4Lk0PZ3BwmcYQWpSkU01UbSuvDV1Ai2TT
+1+7eVmGSX6bEHRBhNtMsJzzoKQm5EWR0zLVznxxIqbxhAe7iF6YM40AIOw7n60RzKprxaZLvcRTD
+Oaxxp5EJb+RxBrO6WVcmeQD2+A2iMzAo1KpYoJ2daZH9
+-----END CERTIFICATE-----
+
+Verisign Class 4 Public Primary Certification Authority - G2
+============================================================
+-----BEGIN CERTIFICATE-----
+MIIDAjCCAmsCEDKIjprS9esTR/h/xCA3JfgwDQYJKoZIhvcNAQEFBQAwgcExCzAJBgNVBAYTAlVT
+MRcwFQYDVQQKEw5WZXJpU2lnbiwgSW5jLjE8MDoGA1UECxMzQ2xhc3MgNCBQdWJsaWMgUHJpbWFy
+eSBDZXJ0aWZpY2F0aW9uIEF1dGhvcml0eSAtIEcyMTowOAYDVQQLEzEoYykgMTk5OCBWZXJpU2ln
+biwgSW5jLiAtIEZvciBhdXRob3JpemVkIHVzZSBvbmx5MR8wHQYDVQQLExZWZXJpU2lnbiBUcnVz
+dCBOZXR3b3JrMB4XDTk4MDUxODAwMDAwMFoXDTI4MDgwMTIzNTk1OVowgcExCzAJBgNVBAYTAlVT
+MRcwFQYDVQQKEw5WZXJpU2lnbiwgSW5jLjE8MDoGA1UECxMzQ2xhc3MgNCBQdWJsaWMgUHJpbWFy
+eSBDZXJ0aWZpY2F0aW9uIEF1dGhvcml0eSAtIEcyMTowOAYDVQQLEzEoYykgMTk5OCBWZXJpU2ln
+biwgS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ATE-----
+
+Verisign Class 3 Public Primary Certification Authority - G3
+============================================================
+-----BEGIN CERTIFICATE-----
+MIIEGjCCAwICEQCbfgZJoz5iudXukEhxKe9XMA0GCSqGSIb3DQEBBQUAMIHKMQswCQYDVQQGEwJV
+UzEXMBUGA1UEChMOVmVyaVNpZ24sIEluYy4xHzAdBgNVBAsTFlZlcmlTaWduIFRydXN0IE5ldHdv
+cmsxOjA4BgNVBAsTMShjKSAxOTk5IFZlcmlTaWduLCBJbmMuIC0gRm9yIGF1dGhvcml6ZWQgdXNl
+IG9ubHkxRTBDBgNVBAMTPFZlcmlTaWduIENsYXNzIDMgUHVibGljIFByaW1hcnkgQ2VydGlmaWNh
+dGlvbiBBdXRob3JpdHkgLSBHMzAeFw05OTEwMDEwMDAwMDBaFw0zNjA3MTYyMzU5NTlaMIHKMQsw
+CQYDVQQGEwJVUzEXMBUGA1UEChMOVmVyaVNpZ24sIEluYy4xHzAdBgNVBAsTFlZlcmlTaWduIFRy
+dXN0IE5ldHdvcmsxOjA4BgNVBAsTMShjKSAxOTk5IFZlcmlTaWduLCBJbmMuIC0gRm9yIGF1dGhv
+cml6ZWQgdXNlIG9ubHkxRTBDBgNVBAMTPFZlcmlTaWduIENsYXNzIDMgUHVibGljIFByaW1hcnkg
+Q2VydGlmaWNhdGlvbiBBdXRob3JpdHkgLSBHMzCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoC
+ggEBAMu6nFL8eB8aHm8bN3O9+MlrlBIwT/A2R/XQkQr1F8ilYcEWQE37imGQ5XYgwREGfassbqb1
+EUGO+i2tKmFZpGcmTNDovFJbcCAEWNF6yaRpvIMXZK0Fi7zQWM6NjPXr8EJJC52XJ2cybuGukxUc
+cLwgTS8Y3pKI6GyFVxEa6X7jJhFUokWWVYPKMIno3Nij7SqAP395ZVc+FSBmCC+Vk7+qRy+oRpfw
+EuL+wgorUeZ25rdGt+INpsyow0xZVYnm6FNcHOqd8GIWC6fJXwzw3sJ2zq/3avL6QaaiMxTJ5Xpj
+055iN9WFZZ4O5lMkdBteHRJTW8cs54NJOxWuimi5V5cCAwEAATANBgkqhkiG9w0BAQUFAAOCAQEA
+ERSWwauSCPc/L8my/uRan2Te2yFPhpk0djZX3dAVL8WtfxUfN2JzPtTnX84XA9s1+ivbrmAJXx5f
+j267Cz3qWhMeDGBvtcC1IyIuBwvLqXTLR7sdwdela8wv0kL9Sd2nic9TutoAWii/gt/4uhMdUIaC
+/Y4wjylGsB49Ndo4YhYYSq3mtlFs3q9i6wHQHiT+eo8SGhJouPtmmRQURVyu565pF4ErWjfJXir0
+xuKhXFSbplQAz/DxwceYMBo7Nhbbo27q/a2ywtrvAkcTisDxszGtTxzhT5yvDwyd93gN2PQ1VoDa
+t20Xj50egWTh/sVFuq1ruQp6Tk9LhO5L8X3dEQ==
+-----END CERTIFICATE-----
+
+Verisign Class 4 Public Primary Certification Authority - G3
+============================================================
+-----BEGIN CERTIFICATE-----
+MIIEGjCCAwICEQDsoKeLbnVqAc/EfMwvlF7XMA0GCSqGSIb3DQEBBQUAMIHKMQswCQYDVQQGEwJV
+UzEXMBUGA1UEChMOVmVyaVNpZ24sIEluYy4xHzAdBgNVBAsTFlZlcmlTaWduIFRydXN0IE5ldHdv
+cmsxOjA4BgNVBAsTMShjKSAxOTk5IFZlcmlTaWduLCBJbmMuIC0gRm9yIGF1dGhvcml6ZWQgdXNl
+IG9ubHkxRTBDBgNVBAMTPFZlcmlTaWduIENsYXNzIDQgUHVibGljIFByaW1hcnkgQ2VydGlmaWNh
+dGlvbiBBdXRob3JpdHkgLSBHMzAeFw05OTEwMDEwMDAwMDBaFw0zNjA3MTYyMzU5NTlaMIHKMQsw
+CQYDVQQGEwJVUzEXMBUGA1UEChMOVmVyaVNpZ24sIEluYy4xHzAdBgNVBAsTFlZlcmlTaWduIFRy
+dXN0IE5ldHdvcmsxOjA4BgNVBAsTMShjKSAxOTk5IFZlcmlTaWduLCBJbmMuIC0gRm9yIGF1dGhv
+cml6ZWQgdXNlIG9ubHkxRTBDBgNVBAMTPFZlcmlTaWduIENsYXNzIDQgUHVibGljIFByaW1hcnkg
+Q2VydGlmaWNhdGlvbiBBdXRob3JpdHkgLSBHMzCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoC
+ggEBAK3LpRFpxlmr8Y+1GQ9Wzsy1HyDkniYlS+BzZYlZ3tCD5PUPtbut8XzoIfzk6AzufEUiGXaS
+tBO3IFsJ+mGuqPKljYXCKtbeZjbSmwL0qJJgfJxptI8kHtCGUvYynEFYHiK9zUVilQhu0GbdU6LM
+8BDcVHOLBKFGMzNcF0C5nk3T875Vg+ixiY5afJqWIpA7iCXy0lOIAgwLePLmNxdLMEYH5IBtptiW
+Lugs+BGzOA1mppvqySNb247i8xOOGlktqgLw7KSHZtzBP/XYufTsgsbSPZUd5cBPhMnZo0QoBmrX
+Razwa2rvTl/4EYIeOGM0ZlDUPpNz+jDDZq3/ky2X7wMCAwEAATANBgkqhkiG9w0BAQUFAAOCAQEA
+j/ola09b5KROJ1WrIhVZPMq1CtRK26vdoV9TxaBXOcLORyu+OshWv8LZJxA6sQU8wHcxuzrTBXtt
+mhwwjIDLk5Mqg6sFUYICABFna/OIYUdfA5PVWw3g8dShMjWFsjrbsIKr0csKvE+MW8VLADsfKoKm
+fjaF3H48ZwC15DtS4KjrXRX5xm3wrR0OhbepmnMUWluPQSjA1egtTaRezarZ7c7c2NU8Qh0XwRJd
+RTjDOPP8hS6DRkiy1yBfkjaP53kPmF6Z6PDQpLv1U70qzlmwr25/bLvSHgCwIe34QWKCudiyxLtG
+UPMxxY8BqHTr9Xgn2uf3ZkPznoM+IKrDNWCRzg==
+-----END CERTIFICATE-----
+
+Entrust.net Secure Server CA
+============================
+-----BEGIN CERTIFICATE-----
+MIIE2DCCBEGgAwIBAgIEN0rSQzANBgkqhkiG9w0BAQUFADCBwzELMAkGA1UEBhMCVVMxFDASBgNV
+BAoTC0VudHJ1c3QubmV0MTswOQYDVQQLEzJ3d3cuZW50cnVzdC5uZXQv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0wCwYDVQQDEwRDUkwxMCmgJ6AlhiNodHRwOi8vd3d3LmVu
+dHJ1c3QubmV0L0NSTC9uZXQxLmNybDArBgNVHRAEJDAigA8xOTk5MDUyNTE2MDk0MFqBDzIwMTkw
+NTI1MTYwOTQwWjALBgNVHQ8EBAMCAQYwHwYDVR0jBBgwFoAU8BdiE1U9s/8KAGv7UISX8+1i0Bow
+HQYDVR0OBBYEFPAXYhNVPbP/CgBr+1CEl/PtYtAaMAwGA1UdEwQFMAMBAf8wGQYJKoZIhvZ9B0EA
+BAwwChsEVjQuMAMCBJAwDQYJKoZIhvcNAQEFBQADgYEAkNwwAvpkdMKnCqV8IY00F6j7Rw7/JXyN
+Ewr75Ji174z4xRAN95K+8cPV1ZVqBLssziY2ZcgxxufuP+NXdYR6Ee9GTxj005i7qIcyunL2POI9
+n9cd2cNgQ4xYDiKWL2KjLB+6rQXvqzJ4h6BUcxm1XAX5Uj5tLUUL9wqT6u0G+bI=
+-----END CERTIFICATE-----
+
+Entrust.net Premium 2048 Secure Server CA
+=========================================
+-----BEGIN CERTIFICATE-----
+MIIEXDCCA0SgAwIBAgIEOGO5ZjANBgkqhkiG9w0BAQUFADCBtDEUMBIGA1UEChMLRW50cnVzdC5u
+ZXQxQDA+BgNVBAsUN3d3dy5lbnRydXN0Lm5ldC9DUFNfMjA0OCBpbmNvcnAuIGJ5IHJlZi4gKGxp
+bWl0cyBsaWFiLikxJTAjBgNVBAsTHChjKSAxOTk5IEVudHJ1c3QubmV0IExpbWl0ZWQxMzAxBgNV
+BAMTKkVudHJ1c3QubmV0IENlcnRpZmljYXRpb24gQXV0aG9yaXR5ICgyMDQ4KTAeFw05OTEyMjQx
+NzUwNTFaFw0xOTEyMjQxODIwNTFaMIG0MRQwEgYDVQQKEwtFbnRydXN0Lm5ldDFAMD4GA1UECxQ3
+d3d3LmVudHJ1c3QubmV0L0NQU18yMDQ4IGluY29ycC4gYnkgcmVmLiAobGltaXRzIGxpYWIuKTEl
+MCMGA1UECxM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SNzkE1akxehi/oCr0Epn3o0WC4zxe9Z2etciefC7IpJ5OCBRLbf1wbWsa
+Y71k5h+3zvDyny67G7fyUIhzksLi4xaNmjICq44Y3ekQEe5+NauQrz4wlHrQMz2nZQ/1/I6eYs9H
+RCwBXbsdtTLSR9I4LtD+gdwyah617jzV/OeBHRnDJELqYzmp
+-----END CERTIFICATE-----
+
+Equifax Secure Global eBusiness CA
+==================================
+-----BEGIN CERTIFICATE-----
+MIICkDCCAfmgAwIBAgIBATANBgkqhkiG9w0BAQQFADBaMQswCQYDVQQGEwJVUzEcMBoGA1UEChMT
+RXF1aWZheCBTZWN1cmUgSW5jLjEtMCsGA1UEAxMkRXF1aWZheCBTZWN1cmUgR2xvYmFsIGVCdXNp
+bmVzcyBDQS0xMB4XDTk5MDYyMTA0MDAwMFoXDTIwMDYyMTA0MDAwMFowWjELMAkGA1UEBhMCVVMx
+HDAaBgNVBAoTE0VxdWlmYXggU2VjdXJlIEluYy4xLTArBgNVBAMTJEVxdWlmYXggU2VjdXJlIEds
+b2JhbCBlQnVzaW5lc3MgQ0EtMTCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEAuucXkAJlsTRV
+PEnCUdXfp9E3j9HngXNBUmCbnaEXJnitx7HoJpQytd4zjTov2/KaelpzmKNc6fuKcxtc58O/gGzN
+qfTWK8D3+ZmqY6KxRwIP1ORROhI8bIpaVIRw28HFkM9yRcuoWcDNM50/o5brhTMhHD4ePmBudpxn
+hcXIw2ECAwEAAaNmMGQwEQYJYIZIAYb4QgEBBAQDAgAHMA8GA1UdEwEB/wQFMAMBAf8wHwYDVR0j
+BBgwFoAUvqigdHJQa0S3ySPY+6j/s1draGwwHQYDVR0OBBYEFL6ooHRyUGtEt8kj2Puo/7NXa2hs
+MA0GCSqGSIb3DQEBBAUAA4GBADDiAVGqx+pf2rnQZQ8w1j7aDRRJbpGTJxQx78T3LUX47Me/okEN
+I7SS+RkAZ70Br83gcfxaz2TE4JaY0KNA4gGK7ycH8WUBikQtBmV1UsCGECAhX2xrD2yuCRyv8qIY
+NMR1pHMc8Y3c7635s3a0kr/clRAevsvIO1qEYBlWlKlV
+-----END CERTIFICATE-----
+
+Equifax Secure eBusiness CA 1
+=============================
+-----BEGIN CERTIFICATE-----
+MIICgjCCAeugAwIBAgIBBDANBgkqhkiG9w0BAQQFADBTMQswCQYDVQQGEwJVUzEcMBoGA1UEChMT
+RXF1aWZheCBTZWN1cmUgSW5jLjEmMCQGA1UEAxMdRXF1aWZheCBTZWN1cmUgZUJ1c2luZXNzIENB
+LTEwHhcNOTkwNjIxMDQwMDAwWhcNMjAwNjIxMDQwMDAwWjBTMQswCQYDVQQGEwJVUzEcMBoGA1UE
+ChMTRXF1aWZheCBTZWN1cmUgSW5jLjEmMCQGA1UEAxMdRXF1aWZheCBTZWN1cmUgZUJ1c2luZXNz
+IENBLTEwgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBAM4vGbwXt3fek6lfWg0XTzQaDJj0ItlZ
+1MRoRvC0NcWFAyDGr0WlIVFFQesWWDYyb+JQYmT5/VGcqiTZ9J2DKocKIdMSODRsjQBuWqDZQu4a
+IZX5UkxVWsUPOE9G+m34LjXWHXzr4vCwdYDIqROsvojvOm6rXyo4YgKwEnv+j6YDAgMBAAGjZjBk
+MBEGCWCGSAGG+EIBAQQEAwIABzAPBgNVHRMBAf8EBTADAQH/MB8GA1UdIwQYMBaAFEp4MlIR21kW
+Nl7fwRQ2QGpHfEyhMB0GA1UdDgQWBBRKeDJSEdtZFjZe38EUNkBqR3xMoTANBgkqhkiG9w0BAQQF
+AAOBgQB1W6ibAxHm6VZMzfmpTMANmvPMZWnmJXbMWbfWVMMdzZmsGd20hdXgPfxiIKeES1hl8eL5
+lSE/9dR+WB5Hh1Q+WKG1tfgq73HnvMP2sUlG4tega+VWeponmHxGYhTnyfxuAxJ5gDgdSIKN/Bf+
+KpYrtWKmpj29f5JZzVoqgrI3eQ==
+-----END CERTIFICATE-----
+
+Equifax Secure eB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WmkZzBlMQswCQYDVQQGEwJT
+RTEUMBIGA1UEChMLQWRkVHJ1c3QgQUIxHTAbBgNVBAsTFEFkZFRydXN0IFRUUCBOZXR3b3JrMSEw
+HwYDVQQDExhBZGRUcnVzdCBDbGFzcyAxIENBIFJvb3SCAQEwDQYJKoZIhvcNAQEFBQADggEBACxt
+ZBsfzQ3duQH6lmM0MkhHma6X7f1yFqZzR1r0693p9db7RcwpiURdv0Y5PejuvE1Uhh4dbOMXJ0Ph
+iVYrqW9yTkkz43J8KiOavD7/KCrto/8cI7pDVwlnTUtiBi34/2ydYB7YHEt9tTEv2dB8Xfjea4MY
+eDdXL+gzB2ffHsdrKpV2ro9Xo/D0UrSpUwjP4E/TelOL/bscVjby/rK25Xa71SJlpz/+0WatC7xr
+mYbvP33zGDLKe8bjq2RGlfgmadlVg3sslgf/WSxEo8bl6ancoWOAWiFeIc9TVPC6b4nbqKqVz4vj
+ccweGyBECMB6tkD9xOQ14R0WHNC8K47Wcdk=
+-----END CERTIFICATE-----
+
+AddTrust External Root
+======================
+-----BEGIN CERTIFICATE-----
+MIIENjCCAx6gAwIBAgIBATANBgkqhkiG9w0BAQUFADBvMQswCQYDVQQGEwJTRTEUMBIGA1UEChML
+QWRkVHJ1c3QgQUIxJjAkBgNVBAsTHUFkZFRydXN0IEV4dGVybmFsIFRUUCBOZXR3b3JrMSIwIAYD
+VQQDExlBZGRUcnVzdCBFeHRlcm5hbCBDQSBSb290MB4XDTAwMDUzMDEwNDgzOFoXDTIwMDUzMDEw
+NDgzOFowbzELMAkGA1UEBhMCU0UxFDASBgNVBAoTC0FkZFRydXN0IEFCMSYwJAYDVQQLEx1BZGRU
+cnVzdCBFeHRlcm5hbCBUVFAgTmV0d29yazEiMCAGA1UEAxMZQWRkVHJ1c3QgRXh0ZXJuYWwgQ0Eg
+Um9vdDCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBALf3GjPm8gAELTngTlvtH7xsD821
++iO2zt6bETOXpClMfZOfvUq8k+0DGuOPz+VtUFrWlymUWoCwSXrbLpX9uMq/NzgtHj6RQa1wVsfw
+Tz/oMp50ysiQVOnGXw94nZpAPA6sYapeFI+eh6FqUNzXmk6vBbOmcZSccbNQYArHE504B4YCqOmo
+aSYYkKtMsE8jqzpPhNjfzp/haW+710LXa0Tkx63ubUFfclpxCDezeWWkWaCUN/cALw3CknLa0Dhy
+2xSoRcRdKn23tNbE7qzNE0S3ySvdQwAl+mG5aWpYIxG3pzOPVnVZ9c0p10a3CitlttNCbxWyuHv7
+7+ldU9U0WicCAwEAAaOB3DCB2TAdBgNVHQ4EFgQUrb2YejS0Jvf6xCZU7wO94CTLVBowCwYDVR0P
+BAQDAgEGMA8GA1UdEwEB/wQFMAMBAf8wgZkGA1UdIwSBkTCBjoAUrb2YejS0Jvf6xCZU7wO94CTL
+VBqhc6RxMG8xCzAJBgNVBAYTAlNFMRQwEgYDVQQKEwtBZGRUcnVzdCBBQjEmMCQGA1UECxMdQWRk
+VHJ1c3QgRXh0ZXJuYWwgVFRQIE5ldHdvcmsxIjAgBgNVBAMTGUFkZFRydXN0IEV4dGVybmFsIENB
+IFJvb3SCAQEwDQYJKoZIhvcNAQEFBQADggEBALCb4IUlwtYj4g+WBpKdQZic2YR5gdkeWxQHIzZl
+j7DYd7usQWxHYINRsPkyPef89iYTx4AWpb9a/IfPeHmJIZriTAcKhjW88t5RxNKWt9x+Tu5w/Rw5
+6wwCURQtjr0W4MHfRnXnJK3s9EK0hZNwEGe6nQY1ShjTK3rMUUKhemPR5ruhxSvCNr4TDea9Y355
+e6cJDUCrat2PisP29owaQgVR1EX1n6diIWgVIEM8med8vSTYqZEXc4g/VhsxOBi0cQ+azcgOno4u
+G+GMmIPLHzHxREzGBHNJdmAPx/i9F4BrLunMTA5amnkPIAou1Z5jJh5VkpTYghdae9C8x49OhgQ=
+-----END CERTIFICATE-----
+
+AddTrust Public Services Root
+=============================
+-----BEGIN CERTIFICATE-----
+MIIEFTCCAv2gAwIBAgIBATANBgk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r4
+JNojVhaTdt02KLmuG7jD8WS6IBh4lSknVwW8fCr0uVFV2ocC3g8WFzH4qnkuCRO7r7IgGRLlk/lL
++YPoRNWyQSW/iHVv/xD8SlTQX/D67zZzfRs2RcYhbbQVuE7PnFylPVoAjgbjPGsye/Kf8Lb93/Ao
+GEjwxrzQvzSAlsJKsW2Ox5BF3i9nrEUEo3rcVZLJR2bYGozH7ZxOmuASu7VqTITh4SINhwBk/ox9
+Yjllpu9CtoAlEmEBqCQTcAARJl/6NVDFSMwGR+gn2HCNX2TmoUQmXiLsks3/QppEIW1cxeMiHV9H
+EufOX1362KqxMy3ZdvJOOjMMK7MtkAY=
+-----END CERTIFICATE-----
+
+AddTrust Qualified Certificates Root
+====================================
+-----BEGIN CERTIFICATE-----
+MIIEHjCCAwagAwIBAgIBATANBgkqhkiG9w0BAQUFADBnMQswCQYDVQQGEwJTRTEUMBIGA1UEChML
+QWRkVHJ1c3QgQUIxHTAbBgNVBAsTFEFkZFRydXN0IFRUUCBOZXR3b3JrMSMwIQYDVQQDExpBZGRU
+cnVzdCBRdWFsaWZpZWQgQ0EgUm9vdDAeFw0wMDA1MzAxMDQ0NTBaFw0yMDA1MzAxMDQ0NTBaMGcx
+CzAJBgNVBAYTAlNFMRQwEgYDVQQKEwtBZGRUcnVzdCBBQjEdMBsGA1UECxMUQWRkVHJ1c3QgVFRQ
+IE5ldHdvcmsxIzAhBgNVBAMTGkFkZFRydXN0IFF1YWxpZmllZCBDQSBSb290MIIBIjANBgkqhkiG
+9w0BAQEFAAOCAQ8AMIIBCgKCAQEA5B6a/twJWoekn0e+EV+vhDTbYjx5eLfpMLXsDBwqxBb/4Oxx
+64r1EW7tTw2R0hIYLUkVAcKkIhPHEWT/IhKauY5cLwjPcWqzZwFZ8V1G87B4pfYOQnrjfxvM0PC3
+KP0q6p6zsLkEqv32x7SxuCqg+1jxGaBvcCV+PmlKfw8i2O+tCBGaKZnhqkRFmhJePp1tUvznoD1o
+L/BLcHwTOK28FSXx1s6rosAx1i+f4P8UWfyEk9mHfExUE+uf0S0R+Bg6Ot4l2ffTQO2kBhLEO+GR
+wVY18BTcZTYJbqukB8c10cIDMzZbdSZtQvESa0NvS3GU+jQd7RNuyoB/mC9suWXY6QIDAQABo4HU
+MIHRMB0GA1UdDgQWBBQ5lYtii1zJ1IC6WA+XPxUIQ8yYpzALBgNVHQ8EBAMCAQYwDwYDVR0TAQH/
+BAUwAwEB/zCBkQYDVR0jBIGJMIGGgBQ5lYtii1zJ1IC6WA+XPxUIQ8yYp6FrpGkwZzELMAkGA1UE
+BhMCU0UxFDASBgNVBAoTC0FkZFRydXN0IEFCMR0wGwYDVQQLExRBZGRUcnVzdCBUVFAgTmV0d29y
+azEjMCEGA1UEAxMaQWRkVHJ1c3QgUXVhbGlmaWVkIENBIFJvb3SCAQEwDQYJKoZIhvcNAQEFBQAD
+ggEBABmrder4i2VhlRO6aQTvhsoToMeqT2QbPxj2qC0sVY8FtzDqQmodwCVRLae/DLPt7wh/bDxG
+GuoYQ992zPlmhpwsaPXpF/gxsxjE1kh9I0xowX67ARRvxdlu3rsEQmr49lx95dr6h+sNNVJn0J6X
+dgWTP5XHAeZpVTh/EGGZyeNfpso+gmNIquIISD6q8rKFYqa0p9m9N5xotS1WfbC3P6CxB9bpT9ze
+RXEwMn8bLgn5v1Kh7sKAPgZcLlVAwRv1cEWw3F369nJad9Jjzc9YiQBCYz95OdBEsIJuQRno3eDB
+iFrRHnGTHyQwdOUeqN48Jzd/g66ed8/wMLH/S5noxqE=
+-----END CERTIFICATE-----
+
+Entrust Root Certification Authority
+====================================
+-----BEGIN CERTIFICATE-----
+MIIEkTCCA3mgAwIBAgIERWtQVDANBgkqhkiG9w0BAQUFADCBsDELMAkGA1UEBhMCVVMxFjAUBgNV
+BAoTDUVudHJ1c3QsIEluYy4xOTA3BgNVBAsTMHd3dy5lbnRydXN0Lm5ldC9DUFMgaXMgaW5jb3Jw
+b3JhdGVkIGJ5IHJlZmVyZW5jZTEfMB0GA1UECx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UcyiYWTjgAA1i00J9IZ+uPTqM1fp3DRgrFg5fNuH8KrUwJM/gYwx7WBr+
+mbpCErGR9Hxo4sjoryzqyX6uuyo9DRXcNJW2GHSoag/HtPQTxORb7QrSpJdMKu0vbBKJPfEncKpq
+A1Ihn0CoZ1Dy81of398j9tx4TuaYT1U6U+Pv8vSfx3zYWK8pIpe44L2RLrB27FcRz+8pRPPphXpg
+Y+RdM4kX2TGq2tbzGDVyz4crL2MjhF2EjD9XoIj8mZEoJmmZ1I+XRL6O1UixpCgp8RW04eWe3fiP
+pm8m1wk8OhwRDqZsN/etRIcsKMfYdIKz0G9KV7s1KSegi+ghp4dkNl3M2Basx7InQJJVOCiNUW7d
+FGdTbHFcJoRNdVq2fmBWqU2t+5sel/MN2dKXVHfaPRK34B7vCAas+YWH6aLcr34YEoP9VhdBLtUp
+gn2Z9DH2canPLAEnpQW5qrJITirvn5NSUZU8UnOOVkwXQMAJKOSLakhT2+zNVVXxxvjpoixMptEm
+X36vWkzaH6byHCx+rgIW0lbQL1dTR+iS
+-----END CERTIFICATE-----
+
+America Online Root Certification Authority 1
+=============================================
+-----BEGIN CERTIFICATE-----
+MIIDpDCCAoygAwIBAgIBATANBgkqhkiG9w0BAQUFADBjMQswCQYDVQQGEwJVUzEcMBoGA1UEChMT
+QW1lcmljYSBPbmxpbmUgSW5jLjE2MDQGA1UEAxMtQW1lcmljYSBPbmxpbmUgUm9vdCBDZXJ0aWZp
+Y2F0aW9uIEF1dGhvcml0eSAxMB4XDTAyMDUyODA2MDAwMFoXDTM3MTExOTIwNDMwMFowYzELMAkG
+A1UEBhMCVVMxHDAaBgNVBAoTE0FtZXJpY2EgT25saW5lIEluYy4xNjA0BgNVBAMTLUFtZXJpY2Eg
+T25saW5lIFJvb3QgQ2VydGlmaWNhdGlvbiBBdXRob3JpdHkgMTCCASIwDQYJKoZIhvcNAQEBBQAD
+ggEPADCCAQoCggEBAKgv6KRpBgNHw+kqmP8ZonCaxlCyfqXfaE0bfA+2l2h9LaaLl+lkhsmj76CG
+v2BlnEtUiMJIxUo5vxTjWVXlGbR0yLQFOVwWpeKVBeASrlmLojNoWBym1BW32J/X3HGrfpq/m44z
+DyL9Hy7nBzbvYjnF3cu6JRQj3gzGPTzOggjmZj7aUTsWOqMFf6Dch9Wc/HKpoH145LcxVR5lu9Rh
+sCFg7RAycsWSJR74kEoYeEfffjA3PlAb2xzTa5qGUwew76wGePiEmf4hjUyAtgyC9mZweRrTT6PP
+8c9GsEsPPt2IYriMqQkoO3rHl+Ee5fSfwMCuJKDIodkP1nsmgmkyPacCAwEAAaNjMGEwDwYDVR0T
+AQH/BAUwAwEB/zAdBgNVHQ4EFgQUAK3Zo/Z59m50qX8zPYEX10zPM94wHwYDVR0jBBgwFoAUAK3Z
+o/Z59m50qX8zPYEX10zPM94wDgYDVR0PAQH/BAQDAgGGMA0GCSqGSIb3DQEBBQUAA4IBAQB8itEf
+GDeC4Liwo+1WlchiYZwFos3CYiZhzRAW18y0ZTTQEYqtqKkFZu90821fnZmv9ov761KyBZiibyrF
+VL0lvV+uyIbqRizBs73B6UlwGBaXCBOMIOAbLjpHyx7kADCVW/RFo8AasAFOq73AI25jP4BKxQft
+3OJvx8Fi8eNy1gTIdGcL+oiroQHIb/AUr9KZzVGTfu0uOMe9zkZQPXLjeSWdm4grECDdpbgyn43g
+Kd8hdIaC2y+CMMbHNYaz+ZZfRtsMRf3zUMNvxsNIrUam4SdHCh0Om7bCd39j8uB9Gr784N/Xx6ds
+sPmuujz9dLQR6FgNgLzTqIA6me11zEZ7
+-----END CERTIFICATE-----
+
+America Online Root Certification Authority 2
+=============================================
+-----BEGIN CERTIFICATE-----
+MIIFpDCCA4ygAwIBAgIBATANBgkqhkiG9w0BAQUFADBjMQswCQYDVQQGEwJVUzEcMBoGA1UEChMT
+QW1lcmljYSBPbmxpbmUgSW5jLjE2MDQGA1UEAxMtQW1lcmljYSBPbmxpbmUgUm9vdCBDZXJ0aWZp
+Y2F0aW9uIEF1dGhvcml0eSA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wJVUzENMAsGA1UEChMEVklTQTEvMC0GA1UECxMm
+VmlzYSBJbnRlcm5hdGlvbmFsIFNlcnZpY2UgQXNzb2NpYXRpb24xHDAaBgNVBAMTE1Zpc2EgZUNv
+bW1lcmNlIFJvb3QwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCvV95WHm6h2mCxlCfL
+F9sHP4CFT8icttD0b0/Pmdjh28JIXDqsOTPHH2qLJj0rNfVIsZHBAk4ElpF7sDPwsRROEW+1QK8b
+RaVK7362rPKgH1g/EkZgPI2h4H3PVz4zHvtH8aoVlwdVZqW1LS7YgFmypw23RuwhY/81q6UCzyr0
+TP579ZRdhE2o8mCP2w4lPJ9zcc+U30rq299yOIzzlr3xF7zSujtFWsan9sYXiwGd/BmoKoMWuDpI
+/k4+oKsGGelT84ATB+0tvz8KPFUgOSwsAGl0lUq8ILKpeeUYiZGo3BxN77t+Nwtd/jmliFKMAGzs
+GHxBvfaLdXe6YJ2E5/4tAgMBAAGjQjBAMA8GA1UdEwEB/wQFMAMBAf8wDgYDVR0PAQH/BAQDAgEG
+MB0GA1UdDgQWBBQVOIMPPyw/cDMezUb+B4wg4NfDtzANBgkqhkiG9w0BAQUFAAOCAQEAX/FBfXxc
+CLkr4NWSR/pnXKUTwwMhmytMiUbPWU3J/qVAtmPN3XEolWcRzCSs00Rsca4BIGsDoo8Ytyk6feUW
+YFN4PMCvFYP3j1IzJL1kk5fui/fbGKhtcbP3LBfQdCVp9/5rPJS+TUtBjE7ic9DjkCJzQ83z7+pz
+zkWKsKZJ/0x9nXGIxHYdkFsd7v3M9+79YKWxehZx0RbQfBI8bGmX265fOZpwLwU8GUYEmSA20GBu
+YQa7FkKMcPcw++DbZqMAAb3mLNqRX6BGi01qnD093QVG/na/oAo85ADmJ7f/hC3euiInlhBx6yLt
+398znM/jra6O1I7mT1GvFpLgXPYHDw==
+-----END CERTIFICATE-----
+
+TC TrustCenter, Germany, Class 2 CA
+===================================
+-----BEGIN CERTIFIC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XNu4ywLQMG4GA1UdIwRnMGWAFPLAE+CCQz777i9nMpY1XNu4
+ywLQoUmkRzBFMQswCQYDVQQGEwJCTTEZMBcGA1UEChMQUXVvVmFkaXMgTGltaXRlZDEbMBkGA1UE
+AxMSUXVvVmFkaXMgUm9vdCBDQSAzggIFxjANBgkqhkiG9w0BAQUFAAOCAgEAT62gLEz6wPJv92ZV
+qyM07ucp2sNbtrCD2dDQ4iH782CnO11gUyeim/YIIirnv6By5ZwkajGxkHon24QRiSemd1o417+s
+hvzuXYO8BsbRd2sPbSQvS3pspweWyuOEn62Iix2rFo1bZhfZFvSLgNLd+LJ2w/w4E6oM3kJpK27z
+POuAJ9v1pkQNn1pVWQvVDVJIxa6f8i+AxeoyUDUSly7B4f/xI4hROJ/yZlZ25w9Rl6VSDE1JUZU2
+Pb+iSwwQHYaZTKrzchGT5Or2m9qoXadNt54CrnMAyNojA+j56hl0YgCUyyIgvpSnWbWCar6ZeXqp
+8kokUvd0/bpO5qgdAm6xDYBEwa7TIzdfu4V8K5Iu6H6li92Z4b8nby1dqnuH/grdS/yO9SbkbnBC
+bjPsMZ57k8HkyWkaPcBrTiJt7qtYTcbQQcEr6k8Sh17rRdhs9ZgC06DYVYoGmRmioHfRMJ6szHXu
+g/WwYjnPbFfiTNKRCw51KBuav/0aQ/HKd/s7j2G4aSgWQgRecCocIdiP4b0jWy10QJLZYxkNc91p
+vGJHvOB0K7Lrfb5BG7XARsWhIstfTsEokt4YutUqKLsRixeTmJlglFwjz1onl14LBQaTNx47aTbr
+qZ5hHY8y2o4M1nQ+ewkk2gF3R8Q7zTSMmfXK4SVhM7JZG+Ju1zdXtg2pEto=
+-----END CERTIFICATE-----
+
+Security Communication Root CA
+==============================
+-----BEGIN CERTIFICATE-----
+MIIDWjCCAkKgAwIBAgIBADANBgkqhkiG9w0BAQUFADBQMQswCQYDVQQGEwJKUDEYMBYGA1UEChMP
+U0VDT00gVHJ1c3QubmV0MScwJQYDVQQLEx5TZWN1cml0eSBDb21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8wHQYDVR0OBBYEFKFyXyYbKJhDlV0HN9WF
+lp1L0sNFMEQGA1UdHwQ9MDswOaA3oDWGM2h0dHA6Ly9jcmwudXNlcnRydXN0LmNvbS9VVE4tVVNF
+UkZpcnN0LUhhcmR3YXJlLmNybDAxBgNVHSUEKjAoBggrBgEFBQcDAQYIKwYBBQUHAwUGCCsGAQUF
+BwMGBggrBgEFBQcDBzANBgkqhkiG9w0BAQUFAAOCAQEARxkP3nTGmZev/K0oXnWO6y1n7k57K9cM
+//bey1WiCuFMVGWTYGufEpytXoMs61quwOQt9ABjHbjAbPLPSbtNk28GpgoiskliCE7/yMgUsogW
+XecB5BKV5UU0s4tpvc+0hY91UZ59Ojg6FEgSxvunOxqNDYJAB+gECJChicsZUN/KHAG8HQQZexB2
+lzvukJDKxA4fFm517zP4029bHpbj4HR3dHuKom4t3XbWOTCC8KucUvIqx69JXn7HaOWCgchqJ/kn
+iCrVWFCVH/A7HFe7fRQ5YiuayZSSKqMiDP+JJn1fIytH1xUdqWqeUQ0qUZ6B+dQ7XnASfxAynB67
+nfhmqA==
+-----END CERTIFICATE-----
+
+Camerfirma Chambers of Commerce Root
+====================================
+-----BEGIN CERTIFICATE-----
+MIIEvTCCA6WgAwIBAgIBADANBgkqhkiG9w0BAQUFADB/MQswCQYDVQQGEwJFVTEnMCUGA1UEChMe
+QUMgQ2FtZXJmaXJtYSBTQSBDSUYgQTgyNzQzMjg3MSMwIQYDVQQLExpodHRwOi8vd3d3LmNoYW1i
+ZXJzaWduLm9yZzEiMCAGA1UEAxMZQ2hhbWJlcnMgb2YgQ29tbWVyY2UgUm9vdDAeFw0wMzA5MzAx
+NjEzNDNaFw0zNzA5MzAxNjEzNDRaMH8xCzAJBgNVBAYTAkVVMScwJQYDVQQKEx5BQyBDYW1lcmZp
+cm1hIFNBIENJRiBBODI3NDMyODcxIzAhBgNVBAsTGmh0dHA6Ly93d3cuY2hhbWJlcnNpZ24ub3Jn
+MSIwIAYDVQQDExlDaGFtYmVycy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GOQmIMOM
+8CgHrTwXZoi1/baI
+-----END CERTIFICATE-----
+
+NetLock Business (Class B) Root
+===============================
+-----BEGIN CERTIFICATE-----
+MIIFSzCCBLSgAwIBAgIBaTANBgkqhkiG9w0BAQQFADCBmTELMAkGA1UEBhMCSFUxETAPBgNVBAcT
+CEJ1ZGFwZXN0MScwJQYDVQQKEx5OZXRMb2NrIEhhbG96YXRiaXp0b25zYWdpIEtmdC4xGjAYBgNV
+BAsTEVRhbnVzaXR2YW55a2lhZG9rMTIwMAYDVQQDEylOZXRMb2NrIFV6bGV0aSAoQ2xhc3MgQikg
+VGFudXNpdHZhbnlraWFkbzAeFw05OTAyMjUxNDEwMjJaFw0xOTAyMjAxNDEwMjJaMIGZMQswCQYD
+VQQGEwJIVTERMA8GA1UEBxMIQnVkYXBlc3QxJzAlBgNVBAoTHk5ldExvY2sgSGFsb3phdGJpenRv
+bnNhZ2kgS2Z0LjEaMBgGA1UECxMRVGFudXNpdHZhbnlraWFkb2sxMjAwBgNVBAMTKU5ldExvY2sg
+VXpsZXRpIChDbGFzcyBCKSBUYW51c2l0dmFueWtpYWRvMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCB
+iQKBgQCx6gTsIKAjwo84YM/HRrPVG/77uZmeBNwcf4xKgZjupNTKihe5In+DCnVMm8Bp2GQ5o+2S
+o/1bXHQawEfKOml2mrriRBf8TKPV/riXiK+IA4kfpPIEPsgHC+b5sy96YhQJRhTKZPWLgLViqNhr
+1nGTLbO/CVRY7QbrqHvcQ7GhaQIDAQABo4ICnzCCApswEgYDVR0TAQH/BAgwBgEB/wIBBDAOBgNV
+HQ8BAf8EBAMCAAYwEQYJYIZIAYb4QgEBBAQDAgAHMIICYAYJYIZIAYb4QgENBIICURaCAk1GSUdZ
+RUxFTSEgRXplbiB0YW51c2l0dmFueSBhIE5ldExvY2sgS2Z0LiBBbHRhbGFub3MgU3pvbGdhbHRh
+dGFzaSBGZWx0ZXRlbGVpYmVuIGxlaXJ0IGVsamFyYXNvayBhbGFwamFuIGtlc3p1bHQuIEEgaGl0
+ZWxlc2l0ZXMgZm9seWFtYXRhdCBhIE5ldExvY2sgS2Z0LiB0ZXJtZWtmZWxlbG9zc2VnLWJpenRv
+c2l0YXNhIHZlZGkuIEEgZGlnaXRhbGlzIGFsYWlyYXMgZWxmb2dhZGFzYW5hayBmZWx0ZXRlbGUg
+YXogZWxvaXJ0IGVsbGVub3J6ZXNpIGVsamFyYXMgbWVndGV0ZWxlLiBBeiBlbGphcmFzIGxlaXJh
+c2EgbWVndGFsYWxoYXRvIGEgTmV0TG9jayBLZnQuIEludGVybmV0IGhvbmxhcGphbiBhIGh0dHBz
+Oi8vd3d3Lm5ldGxvY2submV0L2RvY3MgY2ltZW4gdmFneSBrZXJoZXRvIGF6IGVsbGVub3J6ZXNA
+bmV0bG9jay5uZXQgZS1tYWlsIGNpbWVuLiBJTVBPUlRBTlQhIFRoZSBpc3N1YW5jZSBhbmQgdGhl
+IHVzZSBvZiB0aGlzIGNlcnRpZmljYXRlIGlzIHN1YmplY3QgdG8gdGhlIE5ldExvY2sgQ1BTIGF2
+YWlsYWJsZSBhdCBodHRwczovL3d3dy5uZXRsb2NrLm5ldC9kb2NzIG9yIGJ5IGUtbWFpbCBhdCBj
+cHNAbmV0bG9jay5uZXQuMA0GCSqGSIb3DQEBBAUAA4GBAATbrowXr/gOkDFOzT4JwG06sPgzTEdM
+43WIEJessDgVkcYplswhwG08pXTP2IKlOcNl40JwuyKQ433bNXbhoLXan3BukxowOR0w2y7jfLKR
+stE3Kfq51hdcR0/jHTjrn9V7lagonhVK0dHQKwCXoOKSNitjrFgBazMpUIaD8QFI
+-----END CERTIFICATE-----
+
+NetLock Express (Class C) Root
+==============================
+-----BEGIN CERTIFICATE-----
+MIIFTzCCBLigAwIBAgIBaDANBgkqhkiG9w0BAQQFADCBmzELMAkGA1UEBhMCSFUxETAPBgNVBAcT
+CEJ1ZGFwZXN0MScwJQYDVQQKEx5OZXRMb2NrIEhhbG96YXRia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R5IEdyb3VwLCBJbmMu
+MTEwLwYDVQQLEyhHbyBEYWRkeSBDbGFzcyAyIENlcnRpZmljYXRpb24gQXV0aG9yaXR5ggEAMAwG
+A1UdEwQFMAMBAf8wDQYJKoZIhvcNAQEFBQADggEBADJL87LKPpH8EsahB4yOd6AzBhRckB4Y9wim
+PQoZ+YeAEW5p5JYXMP80kWNyOO7MHAGjHZQopDH2esRU1/blMVgDoszOYtuURXO1v0XJJLXVggKt
+I3lpjbi2Tc7PTMozI+gciKqdi0FuFskg5YmezTvacPd+mSYgFFQlq25zheabIZ0KbIIOqPjCDPoQ
+HmyW74cNxA9hi63ugyuV+I6ShHI56yDqg+2DzZduCLzrTia2cyvk0/ZM/iZx4mERdEr/VxqHD3VI
+Ls9RaRegAhJhldXRQLIQTO7ErBBDpqWeCtWVYpoNz4iCxTIM5CufReYNnyicsbkqWletNw+vHX/b
+vZ8=
+-----END CERTIFICATE-----
+
+Starfield Class 2 CA
+====================
+-----BEGIN CERTIFICATE-----
+MIIEDzCCAvegAwIBAgIBADANBgkqhkiG9w0BAQUFADBoMQswCQYDVQQGEwJVUzElMCMGA1UEChMc
+U3RhcmZpZWxkIFRlY2hub2xvZ2llcywgSW5jLjEyMDAGA1UECxMpU3RhcmZpZWxkIENsYXNzIDIg
+Q2VydGlmaWNhdGlvbiBBdXRob3JpdHkwHhcNMDQwNjI5MTczOTE2WhcNMzQwNjI5MTczOTE2WjBo
+MQswCQYDVQQGEwJVUzElMCMGA1UEChMcU3RhcmZpZWxkIFRlY2hub2xvZ2llcywgSW5jLjEyMDAG
+A1UECxMpU3RhcmZpZWxkIENsYXNzIDIgQ2VydGlmaWNhdGlvbiBBdXRob3JpdHkwggEgMA0GCSqG
+SIb3DQEBAQUAA4IBDQAwggEIAoIBAQC3Msj+6XGmBIWtDBFk385N78gDGIc/oav7PKaf8MOh2tTY
+bitTkPskpD6E8J7oX+zlJ0T1KKY/e97gKvDIr1MvnsoFAZMej2YcOadN+lq2cwQlZut3f+dZxkqZ
+JRRU6ybH838Z1TBwj6+wRir/resp7defqgSHo9T5iaU0X9tDkYI22WY8sbi5gv2cOj4QyDvvBmVm
+epsZGD3/cVE8MC5fvj13c7JdBmzDI1aaK4UmkhynArPkPw2vCHmCuDY96pzTNbO8acr1zJ3o/WSN
+F4Azbl5KXZnJHoe0nRrA1W4TNSNe35tfPe/W93bC6j67eA0cQmdrBNj41tpvi/JEoAGrAgEDo4HF
+MIHCMB0GA1UdDgQWBBS/X7fRzt0fhvRbVazc1xDCDqmI5zCBkgYDVR0jBIGKMIGHgBS/X7fRzt0f
+hvRbVazc1xDCDqmI56FspGowaDELMAkGA1UEBhMCVVMxJTAjBgNVBAoTHFN0YXJmaWVsZCBUZWNo
+bm9sb2dpZXMsIEluYy4xMjAwBgNVBAsTKVN0YXJmaWVsZCBDbGFzcyAyIENlcnRpZmljYXRpb24g
+QXV0aG9yaXR5ggEAMAwGA1UdEwQFMAMBAf8wDQYJKoZIhvcNAQEFBQADggEBAAWdP4id0ckaVaGs
+afPzWdqbAYcaT1epoXkJKtv3L7IezMdeatiDh6GX70k1PncGQVhiv45YuApnP+yz3SFmH8lU+nLM
+PUxA2IGvd56Deruix/U0F47ZEUD0/CwqTRV/p2JdLiXTAAsgGh1o+Re49L2L7ShZ3U0WixeDyLJl
+xy16paq8U4Zt3VekyvggQQto8PT7dL5WXXp59fkdheMtlb71cZBDzI0fmgAKhynpVSJYACPq4xJD
+KVtHCN2MQWplBqjlIapBtJUhlbl90TSrE9atvNziPTnNvT51cKEYWQPJIrSPnNVeKtelttQKbfi3
+QBFGmh95DmK/D5fs4C8fF5Q=
+-----END CERTIFICATE-----
+
+StartCom Certification Authority
+================================
+-----BEGIN CERTIFICATE-----
+MIIHyTCCBbGgAwIBAgIBATANBgkqhkiG9w0BAQUFADB9MQswCQYDVQQGEwJJTDEWMBQGA1UEChMN
+U3RhcnRDb20gTHRkLjErMCkGA1UECxMiU2VjdXJlIERpZ2l0YWwgQ2VydGlmaWNhdGUgU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BYMql1GNXRor5H
+4idq9Joz+EkIYIvUX7Q6hL+hqkpMfT7PT19sdl6gSzeRntwi5m3OFBqOasv+zbMUZBfHWymeMr/y
+7vrTC0LUq7dBMtoM1O/4gdW7jVg/tRvoSSiicNoxBN33shbyTApOB6jtSj1etX+jkMOvJwIDAQAB
+o2MwYTAOBgNVHQ8BAf8EBAMCAYYwDwYDVR0TAQH/BAUwAwEB/zAdBgNVHQ4EFgQUA95QNVbRTLtm
+8KPiGxvDl7I90VUwHwYDVR0jBBgwFoAUA95QNVbRTLtm8KPiGxvDl7I90VUwDQYJKoZIhvcNAQEF
+BQADggEBAMucN6pIExIK+t1EnE9SsPTfrgT1eXkIoyQY/EsrhMAtudXH/vTBH1jLuG2cenTnmCmr
+EbXjcKChzUyImZOMkXDiqw8cvpOp/2PV5Adg06O/nVsJ8dWO41P0jmP6P6fbtGbfYmbW0W5BjfIt
+tep3Sp+dWOIrWcBAI+0tKIJFPnlUkiaY4IBIqDfv8NZ5YBberOgOzW6sRBc4L0na4UU+Krk2U886
+UAb3LujEV0lsYSEY1QSteDwsOoBrp+uvFRTp2InBuThs4pFsiv9kuXclVzDAGySj4dzp30d8tbQk
+CAUw7C29C79Fv1C5qfPrmAESrciIxpg0X40KPMbp1ZWVbd4=
+-----END CERTIFICATE-----
+
+DigiCert High Assurance EV Root CA
+==================================
+-----BEGIN CERTIFICATE-----
+MIIDxTCCAq2gAwIBAgIQAqxcJmoLQJuPC3nyrkYldzANBgkqhkiG9w0BAQUFADBsMQswCQYDVQQG
+EwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3d3cuZGlnaWNlcnQuY29tMSsw
+KQYDVQQDEyJEaWdpQ2VydCBIaWdoIEFzc3VyYW5jZSBFViBSb290IENBMB4XDTA2MTExMDAwMDAw
+MFoXDTMxMTExMDAwMDAwMFowbDELMAkGA1UEBhMCVVMxFTATBgNVBAoTDERpZ2lDZXJ0IEluYzEZ
+MBcGA1UECxMQd3d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vbrGn2zpfDPy
+MjwmR/onJALJfh1biEITajV8fTXpLmaRcpPVMibEdPVTo7NdmvYJywIDAQABo4HIMIHFMA8GA1Ud
+EwEB/wQFMAMBAf8wDgYDVR0PAQH/BAQDAgHGMB8GA1UdEQQYMBaBFHBraS1vcHNAdHJ1c3Rkc3Qu
+Y29tMGIGA1UdIARbMFkwVwYKYIZIAWUDAgEBATBJMEcGCCsGAQUFBwIBFjtodHRwOi8vd3d3LnRy
+dXN0ZHN0LmNvbS9jZXJ0aWZpY2F0ZXMvcG9saWN5L0FDRVMtaW5kZXguaHRtbDAdBgNVHQ4EFgQU
+CXIGThhDD+XWzMNqizF7eI+og7gwDQYJKoZIhvcNAQEFBQADggEBAKPYjtay284F5zLNAdMEA+V2
+5FYrnJmQ6AgwbN99Pe7lv7UkQIRJ4dEorsTCOlMwiPH1d25Ryvr/ma8kXxug/fKshMrfqfBfBC6t
+Fr8hlxCBPeP/h40y3JTlR4peahPJlJU90u7INJXQgNStMgiAVDzgvVJT11J8smk/f3rPanTK+gQq
+nExaBqXpIK1FZg9p8d2/6eMyi/rgwYZNcjwu2JN4Cir42NInPRmJX1p7ijvMDNpRrscL9yuwNwXs
+vFcj4jjSm2jzVhKIT0J8uDHEtdvkyCE06UgRNe76x5JXxZ805Mf29w4LTJxoeHtxMcfrHuBnQfO3
+oKfN5XozNmr6mis=
+-----END CERTIFICATE-----
+
+TURKTRUST Certificate Services Provider Root 1
+==============================================
+-----BEGIN CERTIFICATE-----
+MIID+zCCAuOgAwIBAgIBATANBgkqhkiG9w0BAQUFADCBtzE/MD0GA1UEAww2VMOcUktUUlVTVCBF
+bGVrdHJvbmlrIFNlcnRpZmlrYSBIaXptZXQgU2HEn2xhecSxY8Sxc8SxMQswCQYDVQQGDAJUUjEP
+MA0GA1UEBwwGQU5LQVJBMVYwVAYDVQQKDE0oYykgMjAwNSBUw5xSS1RSVVNUIEJpbGdpIMSwbGV0
+acWfaW0gdmUgQmlsacWfaW0gR8O8dmVubGnE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zgY
+nNN9aV3wxqUeJBujR/xpB2jn5Jq07Q+hh4cCzofSSE7hvP/L8XKSRGQDJereW26fyfJOrN3H
+-----END CERTIFICATE-----
+
+TURKTRUST Certificate Services Provider Root 2
+==============================================
+-----BEGIN CERTIFICATE-----
+MIIEPDCCAySgAwIBAgIBATANBgkqhkiG9w0BAQUFADCBvjE/MD0GA1UEAww2VMOcUktUUlVTVCBF
+bGVrdHJvbmlrIFNlcnRpZmlrYSBIaXptZXQgU2HEn2xhecSxY8Sxc8SxMQswCQYDVQQGEwJUUjEP
+MA0GA1UEBwwGQW5rYXJhMV0wWwYDVQQKDFRUw5xSS1RSVVNUIEJpbGdpIMSwbGV0acWfaW0gdmUg
+QmlsacWfaW0gR8O8dmVubGnEn2kgSGl6bWV0bGVyaSBBLsWeLiAoYykgS2FzxLFtIDIwMDUwHhcN
+MDUxMTA3MTAwNzU3WhcNMTUwOTE2MTAwNzU3WjCBvjE/MD0GA1UEAww2VMOcUktUUlVTVCBFbGVr
+dHJvbmlrIFNlcnRpZmlrYSBIaXptZXQgU2HEn2xhecSxY8Sxc8SxMQswCQYDVQQGEwJUUjEPMA0G
+A1UEBwwGQW5rYXJhMV0wWwYDVQQKDFRUw5xSS1RSVVNUIEJpbGdpIMSwbGV0acWfaW0gdmUgQmls
+acWfaW0gR8O8dmVubGnEn2kgSGl6bWV0bGVyaSBBLsWeLiAoYykgS2FzxLFtIDIwMDUwggEiMA0G
+CSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCpNn7DkUNMwxmYCMjHWHtPFoylzkkBH3MOrHUTpvqe
+LCDe2JAOCtFp0if7qnefJ1Il4std2NiDUBd9irWCPwSOtNXwSadktx4uXyCcUHVPr+G1QRT0mJKI
+x+XlZEdhR3n9wFHxwZnn3M5q+6+1ATDcRhzviuyV79z/rxAc653YsKpqhRgNF8k+v/Gb0AmJQv2g
+QrSdiVFVKc8bcLyEVK3BEx+Y9C52YItdP5qtygy/p1Zbj3e41Z55SZI/4PGXJH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/7SXgz2W79WEE790eslpBIlqhn10s6FvJbakMDHiqYMZWjwFa
+DGi8aRl5xB9+lwW/xekkUV7U1UtT7dkjWjYDZaPBA61BMPNGG4WQr2W11bHkFlt4dR2Xem1ZqSqP
+e97Dh4kQmUlzeMg9vVE1dCrV8X5pGyq7O70luJpaPXJhkGaH7gzWTdQRdAtq/gsD/KNVV4n+Ssuu
+WxcFyPKNIzFTONItaj+CuY0IavdeQXRuwxF+B6wpYJE/OMpXEA29MC/HpeZBoNquBYeaoKRlbEwJ
+DIm6uNO5wJOKMPqN5ZprFQFOZ6raYlY+hAhm0sQ2fac+EPyI4NSA5QC9qvNOBqN6avlicuMJT+ub
+DgEj8Z+7fNzcbBGXJbLytGMU0gYqZ4yD9c7qB9iaah7s5Aq7KkzrCWA5zspi2C5u
+-----END CERTIFICATE-----
+
+GeoTrust Primary Certification Authority
+========================================
+-----BEGIN CERTIFICATE-----
+MIIDfDCCAmSgAwIBAgIQGKy1av1pthU6Y2yv2vrEoTANBgkqhkiG9w0BAQUFADBYMQswCQYDVQQG
+EwJVUzEWMBQGA1UEChMNR2VvVHJ1c3QgSW5jLjExMC8GA1UEAxMoR2VvVHJ1c3QgUHJpbWFyeSBD
+ZXJ0aWZpY2F0aW9uIEF1dGhvcml0eTAeFw0wNjExMjcwMDAwMDBaFw0zNjA3MTYyMzU5NTlaMFgx
+CzAJBgNVBAYTAlVTMRYwFAYDVQQKEw1HZW9UcnVzdCBJbmMuMTEwLwYDVQQDEyhHZW9UcnVzdCBQ
+cmltYXJ5IENlcnRpZmljYXRpb24gQXV0aG9yaXR5MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIB
+CgKCAQEAvrgVe//UfH1nrYNke8hCUy3f9oQIIGHWAVlqnEQRr+92/ZV+zmEwu3qDXwK9AWbK7hWN
+b6EwnL2hhZ6UOvNWiAAxz9juapYC2e0DjPt1befquFUWBRaa9OBesYjAZIVcFU2Ix7e64HXprQU9
+nceJSOC7KMgD4TCTZF5Sw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2C2F+fpErgUfCJzDupxBdN49cOSvkBPB7jVaMaA==
+-----END CERTIFICATE-----
+
+VeriSign Class 3 Public Primary Certification Authority - G5
+============================================================
+-----BEGIN CERTIFICATE-----
+MIIE0zCCA7ugAwIBAgIQGNrRniZ96LtKIVjNzGs7SjANBgkqhkiG9w0BAQUFADCByjELMAkGA1UE
+BhMCVVMxFzAVBgNVBAoTDlZlcmlTaWduLCBJbmMuMR8wHQYDVQQLExZWZXJpU2lnbiBUcnVzdCBO
+ZXR3b3JrMTowOAYDVQQLEzEoYykgMjAwNiBWZXJpU2lnbiwgSW5jLiAtIEZvciBhdXRob3JpemVk
+IHVzZSBvbmx5MUUwQwYDVQQDEzxWZXJpU2lnbiBDbGFzcyAzIFB1YmxpYyBQcmltYXJ5IENlcnRp
+ZmljYXRpb24gQXV0aG9yaXR5IC0gRzUwHhcNMDYxMTA4MDAwMDAwWhcNMzYwNzE2MjM1OTU5WjCB
+yjELMAkGA1UEBhMCVVMxFzAVBgNVBAoTDlZlcmlTaWduLCBJbmMuMR8wHQYDVQQLExZWZXJpU2ln
+biBUcnVzdCBOZXR3b3JrMTowOAYDVQQLEzEoYykgMjAwNiBWZXJpU2lnbiwgSW5jLiAtIEZvciBh
+dXRob3JpemVkIHVzZSBvbmx5MUUwQwYDVQQDEzxWZXJpU2lnbiBDbGFzcyAzIFB1YmxpYyBQcmlt
+YXJ5IENlcnRpZmljYXRpb24gQXV0aG9yaXR5IC0gRzUwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAw
+ggEKAoIBAQCvJAgIKXo1nmAMqudLO07cfLw8RRy7K+D+KQL5VwijZIUVJ/XxrcgxiV0i6CqqpkKz
+j/i5Vbext0uz/o9+B1fs70PbZmIVYc9gDaTY3vjgw2IIPVQT60nKWVSFJuUrjxuf6/WhkcIzSdhD
+Y2pSS9KP6HBRTdGJaXvHcPaz3BJ023tdS1bTlr8Vd6Gw9KIl8q8ckmcY5fQGBO+QueQA5N06tRn/
+Arr0PO7gi+s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68+aCiV0BN7OrJKQVDpI1WkpEXk5X+nXOH0jOZvQ8QCaSmGwb7iRGDBezUqXbpZGRzzfTb+cn
+CDpOGR86p1hcF895P4vkp9MmI50mD1hp/Ed+stCNi5O/KU9DaXR2Z0vPB4zmAve14bRDtUstFJ/5
+3CYNv6ZHdAbYiNE6KTCEztI5gGIbqMdXSbxqVVFnFUq+NQfk1XWYN3kwFNspnWzFacxHVaIw98xc
+f8LDmBxrThaA63p4ZUWiABqvDA1VZDRIuJK58bRQKfJPIx/abKwfROHdI3hRW8cW
+-----END CERTIFICATE-----
+
+COMODO Certification Authority
+==============================
+-----BEGIN CERTIFICATE-----
+MIIEHTCCAwWgAwIBAgIQToEtioJl4AsC7j41AkblPTANBgkqhkiG9w0BAQUFADCBgTELMAkGA1UE
+BhMCR0IxGzAZBgNVBAgTEkdyZWF0ZXIgTWFuY2hlc3RlcjEQMA4GA1UEBxMHU2FsZm9yZDEaMBgG
+A1UEChMRQ09NT0RPIENBIExpbWl0ZWQxJzAlBgNVBAMTHkNPTU9ETyBDZXJ0aWZpY2F0aW9uIEF1
+dGhvcml0eTAeFw0wNjEyMDEwMDAwMDBaFw0yOTEyMzEyMzU5NTlaMIGBMQswCQYDVQQGEwJHQjEb
+MBkGA1UECBMSR3JlYXRlciBNYW5jaGVzdGVyMRAwDgYDVQQHEwdTYWxmb3JkMRowGAYDVQQKExFD
+T01PRE8gQ0EgTGltaXRlZDEnMCUGA1UEAxMeQ09NT0RPIENlcnRpZmljYXRpb24gQXV0aG9yaXR5
+MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA0ECLi3LjkRv3UcEbVASY06m/weaKXTuH
++7uIzg3jLz8GlvCiKVCZrts7oVewdFFxze1CkU1B/qnI2GqGd0S7WWaXUF601CxwRM/aN5VCaTww
+xHGzUvAhTaHYujl8HJ6jJJ3ygxaYqhZ8Q5sVW7euNJH+1GImGEaaP+vB+fGQV+useg2L23IwambV
+4EajcNxo2f8ESIl33rXp+2dtQem8Ob0y2WIC8bGoPW43nOIv4tOiJovGuFVDiOEjPqXSJDlqR6sA
+1KGzqSX+DT+nHbrTUcELpNqsOO9VUCQFZUaTNE8tja3G1CEZ0o7KBWFxB3NH5YoZEr0ETc5OnKVI
+rLsm9wIDAQABo4GOMIGLMB0GA1UdDgQWBBQLWOWLxkwVN6RAqTCpIb5HNlpW/zAOBgNVHQ8BAf8E
+BAMCAQYwDwYDVR0TAQH/BAUwAwEB/zBJBgNVHR8EQjBAMD6gPKA6hjhodHRwOi8vY3JsLmNvbW9k
+b2NhLmNvbS9DT01PRE9DZXJ0aWZpY2F0aW9uQXV0aG9yaXR5LmNybDANBgkqhkiG9w0BAQUFAAOC
+AQEAPpiem/Yb6dc5t3iuHXIYSdOH5EOC6z/JqvWote9VfCFSZfnVDeFs9D6Mk3ORLgLETgdxb8CP
+OGEIqB6BCsAvIC9Bi5HcSEW88cbeunZrM8gALTFGTO3nnc+IlP8zwFboJIYmuNg4ON8qa90SzMc/
+RxdMosIGlgnW2/4/PEZB31jiVg88O8EckzXZOFKs7sjsLjBOlDW0JB9LeGna8gI4zJVSk/BwJVmc
+IGfE7vmLV2H0knZ9P4SNVbfo5azV8fUZVqZa+5Acr5Pr5RzUZ5ddBA6+C4OmF4O5MBKgxTMVBbkN
++8cFduPYSo38NBejxiEovjBFMR7HeL5YYTisO+IBZQ==
+-----END CERTIFICATE-----
+
+Network Solutions Certificate Authority
+=======================================
+-----BEGIN CERTIFICATE-----
+MIID5jCCAs6gAwIBAgIQV8szb8JcFuZHFhfjkDFo4DANBgkqhkiG9w0BAQUFADBiMQswCQYDVQQG
+EwJVUzEhMB8GA1UEChMYTmV0d29yayBTb2x1dGlvbnMgTC5MLkMuMTAwLgYDVQQDEydOZXR3b3Jr
+IFNvbHV0aW9ucyBDZXJ0aWZpY2F0ZSBBdXRob3JpdHkwHhcNMDYxMjAxMDAwMDAwWhcNMjkxMjMx
+MjM1OTU5WjBiMQswCQYDVQQGEwJVUzEhMB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ydi8NmdspZS11My5vWo1ViHe2MPr+8ukYEywVaCge1ey
+-----END CERTIFICATE-----
+
+WellsSecure Public Root Certificate Authority
+=============================================
+-----BEGIN CERTIFICATE-----
+MIIEvTCCA6WgAwIBAgIBATANBgkqhkiG9w0BAQUFADCBhTELMAkGA1UEBhMCVVMxIDAeBgNVBAoM
+F1dlbGxzIEZhcmdvIFdlbGxzU2VjdXJlMRwwGgYDVQQLDBNXZWxscyBGYXJnbyBCYW5rIE5BMTYw
+NAYDVQQDDC1XZWxsc1NlY3VyZSBQdWJsaWMgUm9vdCBDZXJ0aWZpY2F0ZSBBdXRob3JpdHkwHhcN
+MDcxMjEzMTcwNzU0WhcNMjIxMjE0MDAwNzU0WjCBhTELMAkGA1UEBhMCVVMxIDAeBgNVBAoMF1dl
+bGxzIEZhcmdvIFdlbGxzU2VjdXJlMRwwGgYDVQQLDBNXZWxscyBGYXJnbyBCYW5rIE5BMTYwNAYD
+VQQDDC1XZWxsc1NlY3VyZSBQdWJsaWMgUm9vdCBDZXJ0aWZpY2F0ZSBBdXRob3JpdHkwggEiMA0G
+CSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDub7S9eeKPCCGeOARBJe+rWxxTkqxtnt3CxC5FlAM1
+iGd0V+PfjLindo8796jE2yljDpFoNoqXjopxaAkH5OjUDk/41itMpBb570OYj7OeUt9tkTmPOL13
+i0Nj67eT/DBMHAGTthP796EfvyXhdDcsHqRePGj4S78NuR4uNuip5Kf4D8uCdXw1LSLWwr8L87T8
+bJVhHlfXBIEyg1J55oNjz7fLY4sR4r1e6/aN7ZVyKLSsEmLpSjPmgzKuBXWVvYSV2ypcm44uDLiB
+K0HmOFafSZtsdvqKXfcBeYF8wYNABf5x/Qw/zE5gCQ5lRxAvAcAFP4/4s0HvWkJ+We/SlwxlAgMB
+AAGjggE0MIIBMDAPBgNVHRMBAf8EBTADAQH/MDkGA1UdHwQyMDAwLqAsoCqGKGh0dHA6Ly9jcmwu
+cGtpLndlbGxzZmFyZ28uY29tL3dzcHJjYS5jcmwwDgYDVR0PAQH/BAQDAgHGMB0GA1UdDgQWBBQm
+lRkQ2eihl5H/3BnZtQQ+0nMKajCBsgYDVR0jBIGqMIGngBQmlRkQ2eihl5H/3BnZtQQ+0nMKaqGB
+i6SBiDCBhTELMAkGA1UEBhMCVVMxIDAeBgNVBAoMF1dlbGxzIEZhcmdvIFdlbGxzU2VjdXJlMRww
+GgYDVQQLDBNXZWxscyBGYXJnbyBCYW5rIE5BMTYwNAYDVQQDDC1XZWxsc1NlY3VyZSBQdWJsaWMg
+Um9vdCBDZXJ0aWZpY2F0ZSBBdXRob3JpdHmCAQEwDQYJKoZIhvcNAQEFBQADggEBALkVsUSRzCPI
+K0134/iaeycNzXK7mQDKfGYZUMbVmO2rvwNa5U3lHshPcZeG1eMd/ZDJPHV3V3p9+N701NX3leZ0
+bh08rnyd2wIDBSxxSyU+B+NemvVmFymIGjifz6pBA4SXa5M4esowRBskRDPQ5NHcKDj0E0M1NSlj
+qHyita04pO2t/caaH/+Xc/77szWnk4bGdpEA5qxRFsQnMlzbc9qlk1eOPm01JghZ1edE13YgY+es
+E2fDbbFwRnzVlhE9iW9dqKHrjQrawx0zbKPqZxmamX9LPYNRKh3KL4YMon4QLSvUFpULB6ouFJJJ
+tylv2G0xffX8oRAHh84vWdw+WNs=
+-----END CERTIFICATE-----
+
+COMODO ECC Certification Authority
+==================================
+-----BEGIN CERTIFICATE-----
+MIICiTCCAg+gAwIBAgIQH0evqmIAcFBUTAGem2OZKjAKBggqhkjOPQQDAzCBhTELMAkGA1UEBhMC
+R0IxGzAZBgNVBAgTEkdyZWF0ZXIgTWFuY2hlc3RlcjEQMA4GA1UEBxMHU2FsZm9yZDEaMBgGA1UE
+ChMRQ09NT0RPIENBIExpbWl0ZWQxKzApBgNVBAMTIkNPTU9ETyBFQ0MgQ2VydGlmaWNhdGlvbiBB
+dXRob3JpdHkwHhcNMDgwMzA2MDAwMDAwWhcNMzgwMTE4MjM1OTU5WjC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SDbEJrbvXZ5B3eZKK2aXtqxT0QsNY6llsf9g/BYxnnW
+mHyojf6GPgcWkuF75x3sM3Z+Qi5KhfmRiWiEA4Glm5q+4zfFVKtWOxgtQaQM+ELbmaDgcm+7XeEW
+T1MKZPlO9L9OVL14bIjqv5wTJMJwaaJ/D8g8rQjJsJhAoyrniIPtd490
+-----END CERTIFICATE-----
+
+OISTE WISeKey Global Root GA CA
+===============================
+-----BEGIN CERTIFICATE-----
+MIID8TCCAtmgAwIBAgIQQT1yx/RrH4FDffHSKFTfmjANBgkqhkiG9w0BAQUFADCBijELMAkGA1UE
+BhMCQ0gxEDAOBgNVBAoTB1dJU2VLZXkxGzAZBgNVBAsTEkNvcHlyaWdodCAoYykgMjAwNTEiMCAG
+A1UECxMZT0lTVEUgRm91bmRhdGlvbiBFbmRvcnNlZDEoMCYGA1UEAxMfT0lTVEUgV0lTZUtleSBH
+bG9iYWwgUm9vdCBHQSBDQTAeFw0wNTEyMTExNjAzNDRaFw0zNzEyMTExNjA5NTFaMIGKMQswCQYD
+VQQGEwJDSDEQMA4GA1UEChMHV0lTZUtleTEbMBkGA1UECxMSQ29weXJpZ2h0IChjKSAyMDA1MSIw
+IAYDVQQLExlPSVNURSBGb3VuZGF0aW9uIEVuZG9yc2VkMSgwJgYDVQQDEx9PSVNURSBXSVNlS2V5
+IEdsb2JhbCBSb290IEdBIENBMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAy0+zAJs9
+Nt350UlqaxBJH+zYK7LG+DKBKUOVTJoZIyEVRd7jyBxRVVuuk+g3/ytr6dTqvirdqFEr12bDYVxg
+Asj1znJ7O7jyTmUIms2kahnBAbtzptf2w93NvKSLtZlhuAGio9RN1AU9ka34tAhxZK9w8RxrfvbD
+d50kc3vkDIzh2TbhmYsFmQvtRTEJysIA2/dyoJaqlYfQjse2YXMNdmaM3Bu0Y6Kff5MTMPGhJ9vZ
+/yxViJGg4E8HsChWjBgbl0SOid3gF27nKu+POQoxhIL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UdEwEB
+/wQFMAMBAf8wDgYDVR0PAQH/BAQDAgEGMB0GA1UdDgQWBBTUovyfs8PYA9NXXAek0CSnwPIA1DCB
+7QYDVR0fBIHlMIHiMIHfoIHcoIHZhjVodHRwOi8vd3d3LnRydXN0Y2VudGVyLmRlL2NybC92Mi90
+Y19jbGFzc18zX2NhX0lJLmNybIaBn2xkYXA6Ly93d3cudHJ1c3RjZW50ZXIuZGUvQ049VEMlMjBU
+cnVzdENlbnRlciUyMENsYXNzJTIwMyUyMENBJTIwSUksTz1UQyUyMFRydXN0Q2VudGVyJTIwR21i
+SCxPVT1yb290Y2VydHMsREM9dHJ1c3RjZW50ZXIsREM9ZGU/Y2VydGlmaWNhdGVSZXZvY2F0aW9u
+TGlzdD9iYXNlPzANBgkqhkiG9w0BAQUFAAOCAQEANmDkcPcGIEPZIxpC8vijsrlNirTzwppVMXzE
+O2eatN9NDoqTSheLG43KieHPOh6sHfGcMrSOWXaiQYUlN6AT0PV8TtXqluJucsG7Kv5sbviRmEb8
+yRtXW+rIGjs/sFGYPAfaLFkB2otE6OF0/ado3VS6g0bsyEa1+K+XwDsJHI/OcpY9M1ZwvJbL2NV9
+IJqDnxrcOfHFcqMRA/07QlIp2+gB95tejNaNhk4Z+rwcvsUhpYeeeC422wlxo3I0+GzjBgnyXlal
+092Y+tTmBvTwtiBjS+opvaqCZh77gaqnN60TGOaSw4HBM7uIHqHn4rS9MWwOUT1v+5ZWgOI2F9Hc
+5A==
+-----END CERTIFICATE-----
+
+TC TrustCenter Universal CA I
+=============================
+-----BEGIN CERTIFICATE-----
+MIID3TCCAsWgAwIBAgIOHaIAAQAC7LdggHiNtgYwDQYJKoZIhvcNAQEFBQAweTELMAkGA1UEBhMC
+REUxHDAaBgNVBAoTE1RDIFRydXN0Q2VudGVyIEdtYkgxJDAiBgNVBAsTG1RDIFRydXN0Q2VudGVy
+IFVuaXZlcnNhbCBDQTEmMCQGA1UEAxMdVEMgVHJ1c3RDZW50ZXIgVW5pdmVyc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Rlc/ZpjGSUOnmFKbAWKwyCPwacx/0QK54PLLae4xW/2TYcuiUaUj0a
+7CIMHOCkoj3w6DnPgcB77V0fb8XQC9eY
+-----END CERTIFICATE-----
+
+Deutsche Telekom Root CA 2
+==========================
+-----BEGIN CERTIFICATE-----
+MIIDnzCCAoegAwIBAgIBJjANBgkqhkiG9w0BAQUFADBxMQswCQYDVQQGEwJERTEcMBoGA1UEChMT
+RGV1dHNjaGUgVGVsZWtvbSBBRzEfMB0GA1UECxMWVC1UZWxlU2VjIFRydXN0IENlbnRlcjEjMCEG
+A1UEAxMaRGV1dHNjaGUgVGVsZWtvbSBSb290IENBIDIwHhcNOTkwNzA5MTIxMTAwWhcNMTkwNzA5
+MjM1OTAwWjBxMQswCQYDVQQGEwJERTEcMBoGA1UEChMTRGV1dHNjaGUgVGVsZWtvbSBBRzEfMB0G
+A1UECxMWVC1UZWxlU2VjIFRydXN0IENlbnRlcjEjMCEGA1UEAxMaRGV1dHNjaGUgVGVsZWtvbSBS
+b290IENBIDIwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCrC6M14IspFLEUha88EOQ5
+bzVdSq7d6mGNlUn0b2SjGmBmpKlAIoTZ1KXleJMOaAGtuU1cOs7TuKhCQN/Po7qCWWqSG6wcmtoI
+KyUn+WkjR/Hg6yx6m/UTAtB+NHzCnjwAWav12gz1MjwrrFDa1sPeg5TKqAyZMg4ISFZbavva4VhY
+AUlfckE8FQYBjl2tqriTtM2e66foai1SNNs671x1Udrb8zH57nGYMsRUFUQM+ZtV7a3fGAigo4aK
+Se5TBY8ZTNXeWHmb0mocQqvF1afPaA+W5OFhmHZhyJF81j4A4pFQh+GdCuatl9Idxjp9y7zaAzTV
+jlsB9WoHtxa2bkp/AgMBAAGjQjBAMB0GA1UdDgQWBBQxw3kbuvVT1xfgiXotF2wKsyudMzAPBgNV
+HRMECDAGAQH/AgEFMA4GA1UdDwEB/wQEAwIBBjANBgkqhkiG9w0BAQUFAAOCAQEAl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23CO21O1fWLE3TdVJDm71aofW
+0ozSJ8bi/zafmGWgE07GKmSb1ZASzxQG9Dvj1Ci+6A74q05IlG2OlTEQXO2iLb3VOm2yHLtgwEZL
+AfVJrn5GitB0jaEMAs7u/OePuGtm839EAL9mJRQr3RAwHQeWP032a7iPt3sMpTjr3kfb1V05/Iin
+89cqdPHoWqI7n1C6poxFNcJQZZXcY4Lv3b93TZxiyWNzFtApD0mpSPCzqrdsxacwOUBdrsTiXSZT
+8M4cIwhhqJQZugRiQOwfOHB3EgZxpzAYXSUnpQIDAQABo4GlMIGiMA4GA1UdDwEB/wQEAwIBBjAP
+BgNVHRMBAf8EBTADAQH/MB0GA1UdDgQWBBS2CHsNesysIEyGVjJez6tuhS1wVzA/BgNVHR8EODA2
+MDSgMqAwhi5odHRwOi8vd3d3Mi5wdWJsaWMtdHJ1c3QuY29tL2NybC9jdC9jdHJvb3QuY3JsMB8G
+A1UdIwQYMBaAFLYIew16zKwgTIZWMl7Pq26FLXBXMA0GCSqGSIb3DQEBBQUAA4IBAQBW7wojoFRO
+lZfJ+InaRcHUowAl9B8Tq7ejhVhpwjCt2BWKLePJzYFa+HMjWqd8BfP9IjsO0QbE2zZMcwSO5bAi
+5MXzLqXZI+O4Tkogp24CJJ8iYGd7ix1yCcUxXOl5n4BHPa2hCwcUPUf/A2kaDAtE52Mlp3+yybh2
+hO0j9n0Hq0V+09+zv+mKts2oomcrUtW3ZfA5TGOgkXmTUg9U3YO7n9GPp1Nzw8v/MOx8BLjYRB+T
+X3EJIrduPuocA06dGiBh+4E37F78CkWr1+cXVdCg6mCbpvbjjFspwgZgFJ0tl0ypkxWdYcQBX0jW
+WL1WMRJOEcgh4LMRkWXbtKaIOM5V
+-----END CERTIFICATE-----
+
+ePKI Root Certification Authority
+=================================
+-----BEGIN CERTIFICATE-----
+MIIFsDCCA5igAwIBAgIQFci9ZUdcr7iXAF7kBtK8nTANBgkqhkiG9w0BAQUFADBeMQswCQYDVQQG
+EwJUVzEjMCEGA1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FwFU5Lnc/Qkqi
+MAwGA1UdEwQFMAMBAf8wOQYEZyoHAAQxMC8wLQIBADAJBgUrDgMCGgUAMAcGBWcqAwAABBRFsMLH
+ClZ87lt4DJX5GFPBphzYEDANBgkqhkiG9w0BAQUFAAOCAgEACbODU1kBPpVJufGBuvl2ICO1J2B0
+1GqZNF5sAFPZn/KmsSQHRGoqxqWOeBLoR9lYGxMqXnmbnwoqZ6YlPwZpVnPDimZI+ymBV3QGypzq
+KOg4ZyYr8dW1P2WT+DZdjo2NQCCHGervJ8A9tDkPJXtoUHRVnAxZfVo9QZQlUgjgRywVMRnVvwdV
+xrsStZf0X4OFunHB2WyBEXYKCrC/gpf36j36+uwtqSiUO1bd0lEursC9CBWMd1I0ltabrNMdjmEP
+NXubrjlpC2JgQCA2j6/7Nu4tCEoduL+bXPjqpRugc6bY+G7gMwRfaKonh+3ZwZCc7b3jajWvY9+r
+GNm65ulK6lCKD2GTHuItGeIwlDWSXQ62B68ZgI9HkFFLLk3dheLSClIKF5r8GrBQAuUBo2M3IUxE
+xJtRmREOc5wGj1QupyheRDmHVi03vYVElOEMSyycw5KFNGHLD7ibSkNS/jQ6fbjpKdx2qcgw+BRx
+gMYeNkh0IkFch4LoGHGLQYlE535YW6i4jRPpp2zDR+2zGp1iro2C6pSe3VkQw63d4k3jMdXH7Ojy
+sP6SHhYKGvzZ8/gntsm+HbRsZJB/9OTEW9c3rkIO3aQab3yIVMUWbuF6aC74Or8NpDyJO3inTmOD
+BCEIZ43ygknQW/2xzQ+DhNQ+IIX3Sj0rnP0qCglN6oH4EZw=
+-----END CERTIFICATE-----
+
+T\xc3\x9c\x42\xC4\xB0TAK UEKAE K\xC3\xB6k Sertifika Hizmet Sa\xC4\x9Flay\xc4\xb1\x63\xc4\xb1s\xc4\xb1 - S\xC3\xBCr\xC3\xBCm 3
+=============================================================================================================================
+-----BEGIN CERTIFICATE-----
+MIIFFzCCA/+gAwIBAgIBETANBgkqhkiG9w0BAQUFADCCASsxCzAJBg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\xc4\xb1
+==========================================================================
+-----BEGIN CERTIFICATE-----
+MIIF5zCCA8+gAwIBAgIITK9zQhyOdAIwDQYJKoZIhvcNAQEFBQAwgYAxODA2BgNVBAMML0VCRyBF
+bGVrdHJvbmlrIFNlcnRpZmlrYSBIaXptZXQgU2HEn2xhecSxY8Sxc8SxMTcwNQYDVQQKDC5FQkcg
+QmlsacWfaW0gVGVrbm9sb2ppbGVyaSB2ZSBIaXptZXRsZXJpIEEuxZ4uMQswCQYDVQQGEwJUUjAe
+Fw0wNjA4MTcwMDIxMDlaFw0xNjA4MTQwMDMxMDlaMIGAMTgwNgYDVQQDDC9FQkcgRWxla3Ryb25p
+ayBTZXJ0aWZpa2EgSGl6bWV0IFNhxJ9sYXnEsWPEsXPEsTE3MDUGA1UECgwuRUJHIEJpbGnFn2lt
+IFRla25vbG9qaWxlcmkgdmUgSGl6bWV0bGVyaSBBLsWeLjELMAkGA1UEBhMCVFIwggIiMA0GCSqG
+SIb3DQEBAQUAA4ICDwAwggIKAoICAQDuoIRh0DpqZhAy2DE4f6en5f2h4fuXd7hxlugTlkaDT7by
+X3JWbhNgpQGR4lvFzVcfd2NR/y8927k/qqk153nQ9dAktiHq6yOU/im/+4mRDGSaBUorzAzu8T2b
+gmmkTPiab+ci2hC6X5L8GCcKqKpE+i4stPtGmggDg3KriORqcsnlZR9uKg+ds+g75AxuetpX/dfr
+eYteIAbTdgtsApWjluTLdlHRKJ2hGvxEok3MenaoDT2/F08iiFD9rrbskFBKW5+VQarKD7JK/oCZ
+TqNGFav4c0JqwmZ2sQomFd2TkuzbqV9UIlKRcF0T6kjsbgNs2d1s/OsNA/+mgxKb8amTD8UmTDGy
+Y5lhcucqZJnSuOl14nypqZoaqsNW2xCaPINStnuWt6yHd6i58mcLlEOzrz5z+kI2sSXFCjEmN1Zn
+uqMLfdb3ic1nobc6HmZP9qBVFCVMLDMNpkGMvQQxahByCp0OLna9XvNRiYuoP1Vzv9s6xiQFlpJI
+qkuNKgPlV5EQ9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uL8BV8F3RTIM
+O/G0HAiw/VGgod2aHRM2mm23xzy54cXZF/qD1T0VoDy7HgviyJA/qIYM/PmLXoXLT1tLYhFHxUV8
+BS9BsZ4QaRuZluBVeftOhpm4lNqGOGqTo+fLbuXf6iFViZx9fX+Y9QCJ7uOEwFyWtcVG6kbghVW2
+G8kS1sHNzYDzAgE8yGnLRUhj2JTQ7IUOO04RZfSCjKY9ri4ilAnIXOo8gV0WKgOXFlUJ24pBgp5m
+mxE=
+-----END CERTIFICATE-----
+
+ApplicationCA - Japanese Government
+===================================
+-----BEGIN CERTIFICATE-----
+MIIDoDCCAoigAwIBAgIBMTANBgkqhkiG9w0BAQUFADBDMQswCQYDVQQGEwJKUDEcMBoGA1UEChMT
+SmFwYW5lc2UgR292ZXJubWVudDEWMBQGA1UECxMNQXBwbGljYXRpb25DQTAeFw0wNzEyMTIxNTAw
+MDBaFw0xNzEyMTIxNTAwMDBaMEMxCzAJBgNVBAYTAkpQMRwwGgYDVQQKExNKYXBhbmVzZSBHb3Zl
+cm5tZW50MRYwFAYDVQQLEw1BcHBsaWNhdGlvbkNBMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIB
+CgKCAQEAp23gdE6Hj6UG3mii24aZS2QNcfAKBZuOquHMLtJqO8F6tJdhjYq+xpqcBrSGUeQ3DnR4
+fl+Kf5Sk10cI/VBaVuRorChzoHvpfxiSQE8tnfWuREhzNgaeZCw7NCPbXCbkcXmP1G55IrmTwcrN
+wVbtiGrXoDkhBFcsovW8R0FPXjQilbUfKW1eSvNNcr5BViCH/OlQR9cwFO5cjFW6WY2H/CPek9AE
+jP3vbb3QesmlOmpyM8ZKDQUXKi17safY1vC+9D/qDihtQWEjdnjDuGWk81quzMKq2edY3rZ+nYVu
+nyoKb58DKTCXKB28t89UKU5RMfkntigm/qJj5kEW8DOYRwIDAQABo4GeMIGbMB0GA1UdDgQWBBRU
+WssmP3HMlEYNllPqa0jQk/5CdTAOBgNVHQ8BAf8EBAMCAQYwWQYDVR0RBFIwUKROMEwxCzAJBgNV
+BAYTAkpQMRgwFgYDVQQKDA/ml6XmnKzlm73mlL/lupwxIzAhBgNVBAsMGuOCouODl+ODquOCseOD
+vOOCt+ODp+ODs0NBMA8GA1UdEwEB/wQFMAMBAf8wDQYJKoZIhvcNAQEFBQADggEBADlqRHZ3ODrs
+o2dGD/mLBqj7apAxzn7s2tGJfHrrLgy9mTLnsCTWw//1sogJhyzjVOGjprIIC8CFqMjSnHH2HZ9g
+/DgzE+Ge3Atf2hZQKXsvcJEPmbo0NI2VdMV+eKlmXb3KIXdCEKxmJj3ekav9FfBv7WxfEPjzFvYD
+io+nEhEMy/0/ecGc/WLuo89UDNErXxc+4z6/wCs+CZv+iKZ+tJIX/COUgb1up8WMwusRRdv4QcmW
+dupwX3kSa+SjB1oF7ydJzyGfikwJcGapJsErEU4z0g781mzSDjJkaP+tBXhfAx2o45CsJOAPQKdL
+rosot4LKGAfmt1t06SAZf7IbiVQ=
+-----END CERTIFICATE-----
+
+GeoTrust Primary Certification Authority - G3
+=============================================
+-----BEGIN CERTIFICATE-----
+MIID/jCCAuagAwIBAgIQFaxulBmyeUtB9iepwxgPHzANBgkqhkiG9w0BAQsFADCBmDELMAkGA1UE
+BhMCVVMxFjAUBgNVBAoTDUdlb1RydXN0IEluYy4xOTA3BgNVBAsTMChjKSAyMDA4IEdlb1RydXN0
+IEluYy4gLSBGb3IgYXV0aG9yaXplZCB1c2Ugb25seTE2MDQGA1UEAxMtR2VvVHJ1c3QgUHJpbWFy
+eSBDZXJ0aWZpY2F0aW9uIEF1dGhvcml0eSAtIEczMB4XDTA4MDQwMjAwMDAwMFoXDTM3MTIwMTIz
+NTk1OVowgZgxCzAJBgNVBAYTAlVTMRYwFAYDVQQKEw1HZW9UcnVzdCBJbmMuMTkwNwYDVQQLEzAo
+YykgMjAwOCBHZW9UcnVzdCBJbmMuIC0gRm9yIGF1dGhvcml6ZWQgdXNlIG9ubHkxNjA0BgNVBAMT
+LUdlb1RydXN0IFByaW1hcnkgQ2VydGlmaWNhdGlvbiBBdXRob3JpdHkgLSBHMzCCASIwDQYJKoZI
+hvcNAQEBBQADggEPADCCAQoCggEBANziXmJYHTNXOTIz+uvLh4yn1ErdBojqZI4xmKU4kB6Yzy5j
+K/BGvESyiaHAKAxJcCGVn2TAppMSAmUmhsalifD614SgcK9PGpc/BkTVyetyEH3kMSj7HGHmKAdE
+c5IiaacDiGydY8hS2pgn5whMcD60yRLBxWeDXTPzAxHsatBT4tG6NmCUgLthY2xbF37fQJQeqw3C
+IShwiP/WJmxsYAQlTlV+fe+/lEjetx3dcI0FX4ilm/LC7urRQEFtYjgdVgbFA0dRIBn8exALDmKu
+dlW/X3e+PkkBUz2YJQN2JFodtNuJ6nnltrM7P7pMKEF/BqxqjsHQ9gUdfeZChuOl1UcCAwEAAaNC
+MEAwDwYDVR0TAQH/BAUwAwEB/zAOBgNVHQ8BAf8EBAMCAQYwHQYDVR0OBBYEFMR5yo6hTgMdHNxr
+2zFblD4/MH8tMA0GCSqGSIb3DQEBCwUAA4IBAQAtxRPPVoB7eni9n64smefv2t+UXglpp+duaIy9
+cr5HqQ6XErhK8WTTOd8lNNTBzU6B8A8ExCSzNJbGpqow32hhc9f5joWJ7w5elShKKiePEI4ufIbE
+Ap7aDHdlDkQNkv39sxY2+hENHYwOB4lqKVb3cvTdFZx3NWZXqxNT2I7BQMXXExZacse3aQHEerGD
+AWh9jUGhlBjBJVz88P6DAod8DQ3PLghcSkANPuyBYeYk28rgDi0Hsj5W3I31QYUHSJsMC8tJP33s
+t/3LjWeJGqvtux6jAAgIFyqCXDFdRootD4abdNlF+9RAsXqqaC2Gspki4cErx5z481+oghLrGREt
+-----END CERTIFICATE-----
+
+thawte Primary Root CA - G2
+===========================
+-----BEGIN CERTIFICATE-----
+MIICiDCCAg2gAwIBAgIQNfwmXNmET8k9Jj1Xm67XVjAKBggqhkjOPQQDAzCBhDELMAkGA1UEBhMC
+VVMxFTATBgNVBAoTDHRoYXd0ZSwg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QzUbF83d597YV4Djbxy8ooAw/dyZ02SUS2jHaGh7cKUGRIjxpp7sC
+8rZcJwOJ9Abqm+RyguOhCcHpABnTPtRwa7pxpqpYrvS76Wy274fMm7v/OeZWYdMKp8RcTGB7BXcm
+er/YB1IsYvdwY9k5vG8cwnncdimvzsUsZAReiDZuMdRAGmI0Nj81Aa6sY6A=
+-----END CERTIFICATE-----
+
+GeoTrust Primary Certification Authority - G2
+=============================================
+-----BEGIN CERTIFICATE-----
+MIICrjCCAjWgAwIBAgIQPLL0SAoA4v7rJDteYD7DazAKBggqhkjOPQQDAzCBmDELMAkGA1UEBhMC
+VVMxFjAUBgNVBAoTDUdlb1RydXN0IEluYy4xOTA3BgNVBAsTMChjKSAyMDA3IEdlb1RydXN0IElu
+Yy4gLSBGb3IgYXV0aG9yaXplZCB1c2Ugb25seTE2MDQGA1UEAxMtR2VvVHJ1c3QgUHJpbWFyeSBD
+ZXJ0aWZpY2F0aW9uIEF1dGhvcml0eSAtIEcyMB4XDTA3MTEwNTAwMDAwMFoXDTM4MDExODIzNTk1
+OVowgZgxCzAJBgNVBAYTAlVTMRYwFAYDVQQKEw1HZW9UcnVzdCBJbmMuMTkwNwYDVQQLEzAoYykg
+MjAwNyBHZW9UcnVzdCBJbmMuIC0gRm9yIGF1dGhvcml6ZWQgdXNlIG9ubHkxNjA0BgNVBAMTLUdl
+b1RydXN0IFByaW1hcnkgQ2VydGlmaWNhdGlvbiBBdXRob3JpdHkgLSBHMjB2MBAGByqGSM49AgEG
+BSuBBAAiA2IABBWx6P0DFUPlrOuHNxFi79KDNlJ9RVcLSo17VDs6bl8VAsBQps8lL33KSLjHUGMc
+KiEIfJo22Av+0SbFWDEwKCXzXV2juLaltJLtbCyf691DiaI8S0iRHVDsJt/WYC69IaNCMEAwDwYD
+VR0TAQH/BAUwAwEB/zAOBgNVHQ8BAf8EBAMCAQYwHQYDVR0OBBYEFBVfNVdRVfslsq0DafwBo/q+
+EVXVMAoGCCqGSM49BAMDA2cAMGQCMGSWWaboCd6LuvpaiIjwH5HTRqjySkwCY/tsXzjbLkGTqQ7m
+ndwxHLKgpxgceeHHNgIwOlavmnRs9vuD4DPTCF+hnMJbn0bWtsuRBmOiBuczrD6ogRLQy7rQkgu2
+npaqBA+K
+-----END CERTIFICATE-----
+
+VeriSign Universal Root Certification Authority
+===============================================
+-----BEGIN CERTIFICATE-----
+MIIEuTCCA6GgAwIBAgIQQBrEZCGzEyEDDrvkEhrFHTANBgkqhkiG9w0BAQsFADCBvTELMAkGA1UE
+BhMCVVMxFzAVBgNVBAoTDlZlcmlTaWduLCBJbmMuMR8wHQYDVQQLExZWZXJpU2lnbiBUcnVzdCBO
+ZXR3b3JrMTowOAYDVQQLEzEoYykgMjAwOCBWZXJpU2lnbiwgSW5jLiAtIEZvciBhdXRob3JpemVk
+IHVzZSBvbmx5MTgwNgYDVQQDEy9WZXJpU2lnbiBVbml2ZXJzYWwgUm9vdCBDZXJ0aWZpY2F0aW9u
+IEF1dGhvcml0eTAeFw0wODA0MDIwMDAwMDBaFw0zNzEyMDEyMzU5NTlaMIG9MQswCQYDVQQGEwJV
+UzEXMBUGA1UEChMOVmVyaVNpZ24sIEluYy4xHzAdBgNVBAsTFlZlcmlTaWduIFRydXN0IE5ldHdv
+cmsxOjA4BgNVBAsTMShjKSAyMDA4IFZlcmlTaWduLCBJbmMuIC0gRm9yIGF1dGhvcml6ZWQgdXNl
+IG9ubHkxODA2BgNVBAMTL1ZlcmlTaWduIFVuaXZlcnNhbCBSb290IENlcnRpZmljYXRpb24gQXV0
+aG9yaXR5MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAx2E3XrEBNNti1xWb/1hajCMj
+1mCOkdeQmIN65lgZOIzF9uVkhbSicfvtvbnazU0AtMgtc6XHaXGVHzk8skQHnOgO+k1KxCHfKWGP
+MiJhgsWHH26MfF8WIFFE0XBPV+rjHOPMee5Y2A7Cs0WTwCznmhcrewA3ekEzeOEz4vMQGn+HLL72
+9fdC4uW/h2KJXwBL38Xd5HVEMkE6HnFuacsLdUYI0crSK5XQz/u5QGtkjFdN/BMReYTtXlT2NJ8I
+AfMQJQYXStrxHXpma5hgZqTZ79IugvHw7wnqRMkVauIDbjPTrJ9VAMf2CGqUuV/c4DPxhGD5WycR
+tPwW8rtWaoAljQIDAQABo4GyMIGvMA8GA1UdEwEB/wQFMAMBAf8wDgYDVR0PAQH/BAQDAgEGMG0G
+CCsGAQUFBwEMBGEwX6FdoFswWTBXMFUWCWltYWdlL2dpZjAhMB8wBwYFKw4DAhoEFI/l0xqGrI2O
+a8PPgGrUSBgsexkuMCUWI2h0dHA6Ly9sb2dvLnZlcmlzaWduLmNvbS92c2xvZ28uZ2lmMB0GA1Ud
+DgQWBBS2d/ppSEefUxLVwuoHMnYH0ZcHGTANBgkqhkiG9w0BAQsFAAOCAQEASvj4sAPmLGd75JR3
+Y8xuTPl9Dg3cyLk1uXBPY/ok+myDjEedO2Pzmvl2MpWRsXe8rJq+seQxIcaBlVZaDrHC1LGmWazx
+Y8u4TB1ZkErvkBYoH1quEPuBUDgMbMzxPcP1Y+Oz4yHJJDnp/RVmRvQbEdBNc6N9Rvk97ahfYtTx
+P/jgdFcrGJ2BtMQo2pSXpXDrrB2+BxHw1dvd5Yzw1TKwg+ZX4o+/vqGqvz0dtdQ46tewXDpPaj+P
+wGZsY6rp2aQW9IHRlRQOfc2VNNnSj3BzgXucfr2YYdhFh5iQxeuGMMY1v/D/w1WIg0vvBZIGcfK4
+mJO37M2CYfE45k+XmCpajQ==
+-----END CERTIFICATE-----
+
+VeriSign Class 3 Public Primary Certification Authority - G4
+============================================================
+-----BEGIN CERTIFICATE-----
+MIIDhDCCAwqgAwIBAgIQL4D+I4wOIg9IZxIokYesszAKBggqhkjOPQQDAzCByjELMAkGA1UEBhMC
+VVMxFzAVBgNVBAoTDlZlcmlTaWduLCBJbmMuMR8wHQYDVQQLExZWZXJpU2lnbiBUcnVzdCBOZXR3
+b3JrMTowOAYDVQQLEzEo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9iGKt0uEA==
+-----END CERTIFICATE-----
+
+NetLock Arany (Class Gold) Főtanúsítvány
+============================================
+-----BEGIN CERTIFICATE-----
+MIIEFTCCAv2gAwIBAgIGSUEs5AAQMA0GCSqGSIb3DQEBCwUAMIGnMQswCQYDVQQGEwJIVTERMA8G
+A1UEBwwIQnVkYXBlc3QxFTATBgNVBAoMDE5ldExvY2sgS2Z0LjE3MDUGA1UECwwuVGFuw7pzw610
+dsOhbnlraWFkw7NrIChDZXJ0aWZpY2F0aW9uIFNlcnZpY2VzKTE1MDMGA1UEAwwsTmV0TG9jayBB
+cmFueSAoQ2xhc3MgR29sZCkgRsWRdGFuw7pzw610dsOhbnkwHhcNMDgxMjExMTUwODIxWhcNMjgx
+MjA2MTUwODIxWjCBpzELMAkGA1UEBhMCSFUxETAPBgNVBAcMCEJ1ZGFwZXN0MRUwEwYDVQQKDAxO
+ZXRMb2NrIEtmdC4xNzA1BgNVBAsMLlRhbsO6c8OtdHbDoW55a2lhZMOzayAoQ2VydGlmaWNhdGlv
+biBTZXJ2aWNlcykxNTAzBgNVBAMMLE5ldExvY2sgQXJhbnkgKENsYXNzIEdvbGQpIEbFkXRhbsO6
+c8OtdHbDoW55MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAxCRec75LbRTDofTjl5Bu
+0jBFHjzuZ9lk4BqKf8owyoPjIMHj9DrTlF8afFttvzBPhCf2nx9JvMaZCpDyD/V/Q4Q3Y1GLeqVw
+/HpYzY6b7cNGbIRwXdrzAZAj/E4wqX7hJ2Pn7WQ8oLjJM2P+FpD/sLj916jAwJRDC7bVWaaeVtAk
+H3B5r9s5VA1lddkVQZQBr17s9o3x/61k/iCa11zr/qYfCGSji3ZVrR47KGAuhyXoqq8fxmRGILdw
+fzzeSNuWU7c5d+Qa4scWhHaXWy+7GRWF+GmF9ZmnqfI0p6m2pgP8b4Y9VHx2BJtr+UBdADTHLpl1
+neWIA6pN+APSQnbAGwIDAKiLo0UwQzASBgNVHRMBAf8ECDAGAQH/AgEEMA4GA1UdDwEB/wQEAwIB
+BjAdBgNVHQ4EFgQUzPpnk/C2uNClwB7zU/2MU9+D15YwDQYJKoZIhvcNAQELBQADggEBAKt/7hwW
+qZw8UQCgwBEIBaeZ5m8BiFRhbvG5GK1Krf6BQCOUL/t1fC8oS2IkgYIL9WHxHG64YTjrgfpioTta
+YtOUZcTh5m2C+C8lcLIhJsFyUR+MLMOEkMNaj7rP9KdlpeuY0fsFskZ1FSNqb4VjMIDw1Z4fKRzC
+bLBQWV2QWzuoDTDPv31/zvGdg73JRm4gpvlhUbohL3u+pRVjodSVh/GeufOJ8z2FuLjbvrW5Kfna
+NwUASZQDhETnv0Mxz3WLJdH0pmT1kvarBes96aULNmLazAZfNou2XjG4Kvte9nHfRCaexOYNkbQu
+dZWAUWpLMKawYqGT8ZvYzsRjdT9ZR7E=
+-----END CERTIFICATE-----
+
+Staat der Nederlanden Root CA - G2
+==================================
+-----BEGIN CERTIFICATE-----
+MIIFyjCCA7KgAwIBAgIEAJiWjDANBgkqhkiG9w0BAQsFADBaMQswCQYDVQQGEwJOTDEeMBwGA1UE
+CgwVU3RhYXQgZGVyIE5lZGVybGFuZGVuMSswKQYDVQQDDCJTdGFhdCBkZXIgTmVkZXJsYW5kZW4g
+Um9vdCBDQSAtIEcyMB4XDTA4MDMyNjExMTgxN1oXDTIwMDMyNTExMDMxMFowWjELMAkGA1UEBhMC
+TkwxHjAcBgNVBAoMFVN0YWF0IGRlciBOZWRlcmxhbmRlbjErMCkGA1UEAwwiU3RhYXQgZGVyIE5l
+ZGVybGFuZGVuIFJvb3QgQ0EgLSBHMjCCAiIwDQYJKoZIhvcNAQEBBQADggIPADCCAgoCggIBAMVZ
+5291qj5LnLW4rJ4L5PnZyqtdj7U5EILXr1HgO+EASGrP2uEGQxGZqhQlEq0i6ABtQ8SpuOUfiUtn
+vWFI7/3S4GCI5bkYYCjDdyutsDeqN95kWSpGV+RLufg3fNU254DBtvPUZ5uW6M7Xxg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9tqg
+aHtPkl7qpHMyEVNEskTLnewPeUKzEKbHDZ3Ltvo/Onzqv4hTGzz3gvoFNTPhNahXwOf9jU8/kzJP
+eGYDdwdY6ZXIfj7QeQCM8htRM5u8lOk6e25SLTKeI6RF+7YuE7CLGLHdztUdp0J/Vb77W7tH1Pwk
+zQSulgUV1qzOMPPKC8W64iLgpq0i5ALudBF/TP94HTXa5gI06xgSYXcGCRZj6hitoocf8seACQl1
+ThCojz2GuHURwCRiipZ7SkXp7FnFvmuD5uHorLUwHv4FB4D54SMNUI8FmP8sX+g7tq3PgbUhh8oI
+KiMnMCArz+2UW6yyetLHKKGKC5tNSixthT8Jcjxn4tncB7rrZXtaAWPWkFtPF2Y9fwsZo5NjEFIq
+nxQWWOLcpfShFosOkYuByptZ+thrkQdlVV9SH686+5DdaaVbnG0OLLb6zqylfDJKZ0DcMDQj3dcE
+I2bw/FWAp/tmGYI1Z2JwOV5vx+qQQEQIHriy1tvuWacNGHk0vFQYXlPKNFHtRQrmjseCNj6nOGOp
+MCwXEGCSn1WHElkQwg9naRHMTh5+Spqtr0CodaxWkHS4oJyleW/c6RrIaQXpuvoDs3zk4E7Czp3o
+tkYNbn5XOmeUwssfnHdKZ05phkOTOPu220+DkdRgfks+KzgHVZhepA==
+-----END CERTIFICATE-----
+
+Verisign Class 3 Public Primary Certification Authority
+=======================================================
+-----BEGIN CERTIFICATE-----
+MIICPDCCAaUCEDyRMcsf9tAbDpq40ES/Er4wDQYJKoZIhvcNAQEFBQAwXzELMAkGA1UEBhMCVVMx
+FzAVBgNVBAoTDlZlcmlTaWduLCBJbmMuMTcwNQYDVQQLEy5DbGFzcyAzIFB1YmxpYyBQcmltYXJ5
+IENlcnRpZmljYXRpb24gQXV0aG9yaXR5MB4XDTk2MDEyOTAwMDAwMFoXDTI4MDgwMjIzNTk1OVow
+XzELMAkGA1UEBhMCVVMxFzAVBgNVBAoTDlZlcmlTaWduLCBJbmMuMTcwNQYDVQQLEy5DbGFzcyAz
+IFB1Ym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viZpWNwrZuuyjNA
+fW2WbqEORO7hE52UQlKavXWFdCyoDh2Tthi3jCyoz/tccbna7P7ofo/kLx2yqHWH2Leh5TvPmUpG
+0IMZfcChEhyVbUr02MelTTMuhTlAdX4UfIASmFDHQWe4oIBhVKZsTh/gnQ4H6cm6M+f+wFUoLAKA
+pxn1ntxVUwOXewdI/5n7N4okxFnMUBBjjqqpGrCEGob5X7uxUG6k0QrM1XF+H6cbfPVTbiJfyyvm
+1HxdrtbCxkzlBQHZ7Vf8wSN5/PrIJIOV87VqUQHQd9bpEqH5GoP7ghu5sJf0dgYzQ0mg/wu1+rUC
+AwEAAaOBgDB+MA8GA1UdEwEB/wQFMAMBAf8wDgYDVR0PAQH/BAQDAgEGMB0GA1UdDgQWBBTLD8bf
+QkPMPcu1SCOhGnqmKrs0aDAfBgNVHSMEGDAWgBTLD8bfQkPMPcu1SCOhGnqmKrs0aDAbBgNVHREE
+FDASgRBpbmZvQGUtc3ppZ25vLmh1MA0GCSqGSIb3DQEBCwUAA4IBAQDJ0Q5eLtXMs3w+y/w9/w0o
+lZMEyL/azXm4Q5DwpL7v8u8hmLzU1F0G9u5C7DBsoKqpyvGvivo/C3NqPuouQH4frlRheesuCDfX
+I/OMn74dseGkddug4lQUsbocKaQY9hK6ohQU4zE1yED/t+AFdlfBHFny+L/k7SViXITwfn4fs775
+tyERzAMBVnCnEJIeGzSBHq2cGsMEPO0CYdYeBvNfOofyK/FFh+U9rNHHV4S9a67c2Pm2G2JwCz02
+yULyMtd6YebS2z3PyKnJm9zbWETXbzivf3jTo60adbocwTZ8jx5tHMN1Rq41Bab2XD0h7lbwyYIi
+LXpUq3DDfSJlgnCW
+-----END CERTIFICATE-----
+
+E-Guven Kok Elektronik Sertifika Hizmet Saglayicisi
+===================================================
+-----BEGIN CERTIFICATE-----
+MIIDtjCCAp6gAwIBAgIQRJmNPMADJ72cdpW56tustTANBgkqhkiG9w0BAQUFADB1MQswCQYDVQQG
+EwJUUjEoMCYGA1UEChMfRW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95ZURUm7
+lgAJQayzE4aGKAczymvmdLm6AC2upArT9fHxD4q/c2dKg8dEe3jgr25sbwMpjjM5RcOO5LlXbKr8
+EpbsU8Yt5CRsuZRj+9xTaGdWPoO4zzUhw8lo/s7awlOqzJCK6fBdRoyV3XpYKBovHd7NADdBj+1E
+bddTKJd+82cEHhXXipa0095MJ6RMG3NzdvQXmcIfeg7jLQitChws/zyrVQ4PkX4268NXSb7hLi18
+YIvDQVETI53O9zJrlAGomecsMx86OyXShkDOOyyGeMlhLxS67ttVb9+E7gUJTb0o2HLO02JQZR7r
+kpeDMdmztcpHWD9f
+-----END CERTIFICATE-----
+
+TC TrustCenter Universal CA III
+===============================
+-----BEGIN CERTIFICATE-----
+MIID4TCCAsmgAwIBAgIOYyUAAQACFI0zFQLkbPQwDQYJKoZIhvcNAQEFBQAwezELMAkGA1UEBhMC
+REUxHDAaBgNVBAoTE1RDIFRydXN0Q2VudGVyIEdtYkgxJDAiBgNVBAsTG1RDIFRydXN0Q2VudGVy
+IFVuaXZlcnNhbCBDQTEoMCYGA1UEAxMfVEMgVHJ1c3RDZW50ZXIgVW5pdmVyc2FsIENBIElJSTAe
+Fw0wOTA5MDkwODE1MjdaFw0yOTEyMzEyMzU5NTlaMHsxCzAJBgNVBAYTAkRFMRwwGgYDVQQKExNU
+QyBUcnVzdENlbnRlciBHbWJIMSQwIgYDVQQLExtUQyBUcnVzdENlbnRlciBVbml2ZXJzYWwgQ0Ex
+KDAmBgNVBAMTH1RDIFRydXN0Q2VudGVyIFVuaXZlcnNhbCBDQSBJSUkwggEiMA0GCSqGSIb3DQEB
+AQUAA4IBDwAwggEKAoIBAQDC2pxisLlxErALyBpXsq6DFJmzNEubkKLF5+cvAqBNLaT6hdqbJYUt
+QCggbergvbFIgyIpRJ9Og+41URNzdNW88jBmlFPAQDYvDIRlzg9uwliT6CwLOunBjvvya8o84pxO
+juT5fdMnnxvVZ3iHLX8LR7PH6MlIfK8vzArZQe+f/prhsq75U7Xl6UafYOPfjdN/+5Z+s7Vy+Eut
+CHnNaYlAJ/Uqwa1D7KRTyGG299J5KmcYdkhtWyUB0SbFt1dpIxVbYYqt8Bst2a9c8SaQaanVDED1
+M4BDj5yjdipFtK+/fz6HP3bFzSreIMUWWMv5G/UPyw0RUmS40nZid4PxWJ//AgMBAAGjYzBhMB8G
+A1UdIwQYMBaAFFbn4VslQ4Dg9ozhcbyO5YAvxEjiMA8GA1UdEwEB/wQFMAMBAf8wDgYDVR0PAQH/
+BAQDAgEGMB0GA1UdDgQWBBRW5+FbJUOA4PaM4XG8juWAL8RI4jANBgkqhkiG9w0BAQUFAAOCAQEA
+g8ev6n9NCjw5sWi+e22JLumzCecYV42FmhfzdkJQEw/HkG8zrcVJYCtsSVgZ1OK+t7+rSbyUyKu+
+KGwWaODIl0YgoGhnYIg5IFHYaAERzqf2EQf27OysGh+yZm5WZ2B6dF7AbZc2rrUNXWZzwCUyRdhK
+BgePxLcHsU0GDeGl6/R1yrqc0L2z0zIkTO5+4nYES0lT2PLpVDP85XEfPRRclkvxOvIAu2y0+pZV
+CIgJwcyRGSmwIC3/yzikQOEXvnlhgP8HA4ZMTnsGnxGGjYnuJ8Tb4rwZjgvDwxPHLQNjO9Po5KIq
+woIIlBZU8O8fJ5AluA0OKBtHd0e9HKgl8ZS0Zg==
+-----END CERTIFICATE-----
+
+Autoridad de Certificacion Firmaprofesional CIF A62634068
+=========================================================
+-----BEGIN CERTIFICATE-----
+MIIGFDCCA/ygAwIBAgIIU+w77vuySF8wDQYJKoZIhvcNAQEFBQAwUTELMAkGA1UEBhMCRVMxQjBA
+BgNVBAMMOUF1dG9yaWRhZCBkZSBDZXJ0aWZpY2FjaW9uIEZpcm1hcHJvZmVzaW9uYWwgQ0lGIEE2
+MjYzNDA2ODAeFw0wOTA1MjAwODM4MTVaFw0zMDEyMzEwODM4MTVaMFExCzAJBgNVBAYTAkVTMUIw
+QAYDVQQDDDlBdXRvcmlkYWQgZGUgQ2VydGlmaWNhY2lvbiBGaXJtY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Q6o8iV7tJHP5LGx5r1VdGwFMA0GCSqGSIb3DQEBCwUAA4ICAQB4pgwWSp9MiDrAyw6l
+Fn2fuUhfGI8NYjb2zRlrrKvV9pF9rnHzP7MOeIWblaQnIUdCSnxIOvVFfLMMjlF4rJUT3sb9fbga
+kEyrkgPH7UIBzg/YsfqikuFgba56awmqxinuaElnMIAkejEWOVt+8Rwu3WwJrfIxwYJOubv5vr8q
+hT/AQKM6WfxZSzwoJNu0FXWuDYi6LnPAvViH5ULy617uHjAimcs30cQhbIHsvm0m5hzkQiCeR7Cs
+g1lwLDXWrzY0tM07+DKo7+N4ifuNRSzanLh+QBxh5z6ikixL8s36mLYp//Pye6kfLqCTVyvehQP5
+aTfLnnhqBbTFMXiJ7HqnheG5ezzevh55hM6fcA5ZwjUukCox2eRFekGkLhObNA5me0mrZJfQRsN5
+nXJQY6aYWwa9SG3YOYNw6DXwBdGqvOPbyALqfP2C2sJbUjWumDqtujWTI6cfSN01RpiyEGjkpTHC
+ClguGYEQyVB1/OpaFs4R1+7vUIgtYf8/QnMFlEPVjjxOAToZpR9GTnfQXeWBIiGH/pR9hNiTrdZo
+Q0iy2+tzJOeRf1SktoA+naM8THLCV8Sg1Mw4J87VBp6iSNnpn86CcDaTmjvfliHjWbcM2pE38P1Z
+WrOZyGlsQyYBNWNgVYkDOnXYukrZVP/u3oDYLdE41V4tC5h9Pmzb/CaIxw==
+-----END CERTIFICATE-----
+
+Chambers of Commerce Root - 2008
+================================
+-----BEGIN CERTIFICATE-----
+MIIHTzCCBTegAwIBAgIJAKPaQn6ksa7aMA0GCSqGSIb3DQEBBQUAMIGuMQswCQYDVQQGEwJFVTFD
+MEEGA1UEBxM6TWFkcmlkIChzZWUgY3VycmVudCBhZGRyZXNzIGF0IHd3dy5jYW1lcmZpcm1hLmNv
+bS9hZGRyZXNzKTESMBAGA1UEBRMJQTgyNzQzMjg3MRswGQYDVQQKExJBQyBDYW1lcmZpcm1hIFMu
+QS4xKTAnBgNVBAMTIENoY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AtwQlRPLJsFfClI9eDdOTlLsn+mCdCxqvG
+nrDQWzilm1DefhiYtUU79nm06PcaewaD+9CL2rvHvRirCG88gGtAPxkZumWK5r7VXNM21+9AUiRg
+OGcEMeyP84LG3rlV8zsxkVrctQgVrXYlCg17LofiDKYGvCYQbTed7N14jHyAxfDZd0jQ
+-----END CERTIFICATE-----
+
+Global Chambersign Root - 2008
+==============================
+-----BEGIN CERTIFICATE-----
+MIIHSTCCBTGgAwIBAgIJAMnN0+nVfSPOMA0GCSqGSIb3DQEBBQUAMIGsMQswCQYDVQQGEwJFVTFD
+MEEGA1UEBxM6TWFkcmlkIChzZWUgY3VycmVudCBhZGRyZXNzIGF0IHd3dy5jYW1lcmZpcm1hLmNv
+bS9hZGRyZXNzKTESMBAGA1UEBRMJQTgyNzQzMjg3MRswGQYDVQQKExJBQyBDYW1lcmZpcm1hIFMu
+QS4xJzAlBgNVBAMTHkdsb2JhbCBDaGFtYmVyc2lnbiBSb290IC0gMjAwODAeFw0wODA4MDExMjMx
+NDBaFw0zODA3MzExMjMxNDBaMIGsMQswCQYDVQQGEwJFVTFDMEEGA1UEBxM6TWFkcmlkIChzZWUg
+Y3VycmVudCBhZGRyZXNzIGF0IHd3dy5jYW1lcmZpcm1hLmNvbS9hZGRyZXNzKTESMBAGA1UEBRMJ
+QTgyNzQzMjg3MRswGQYDVQQKExJBQyBDYW1lcmZpcm1hIFMuQS4xJzAlBgNVBAMTHkdsb2JhbCBD
+aGFtYmVyc2lnbiBSb290IC0gMjAwODCCAiIwDQYJKoZIhvcNAQEBBQADggIPADCCAgoCggIBAMDf
+VtPkOpt2RbQT2//BthmLN0EYlVJH6xedKYiONWwGMi5HYvNJBL99RDaxccy9Wglz1dmFRP+RVyXf
+XjaOcNFccUMd2drvXNL7G706tcuto8xEpw2uIRU/uXpbknXYpBI4iRmKt4DS4jJvVpyR1ogQC7N0
+ZJJ0YPP2zxhPYLIj0Mc7zmFLmY/CDNBAspjcDahOo7kKrmCgrUVSY7pm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kn2EaqbylZUohwEurdPfWbU1Rv4WCiqAm57OtZfMY18dwY6fFn5a+6
+ReAJ3spED8IXDneRRXozX1+WLGiLwUePmJs9wOzL9dWCkoQ10b42OFZyMVtHLaoXpGNR6woBrX/s
+dZ7LoR/xfxKxueRkf2fWIyr0uDldmOghp+G9PUIadJpwr2hsUF1Jz//7Dl3mLEfXgTpZALVza2Mg
+9jFFCDkO9HB+QHBaP9BrQql0PSgvAm11cpUJjUhjxsYjV5KTXjXBjfkK9yydYhz2rXzdpjEetrHH
+foUm+qRqtdpjMNHvkzeyZi99Bffnt0uYlDXA2TopwZ2yUDMdSqlapskD7+3056huirRXhOukP9Du
+qqqHW2Pok+JrqNS4cnhrG+055F3Lm6qH1U9OAP7Zap88MQ8oAgF9mOinsKJknnn4SPIVqczmyETr
+P3iZ8ntxPjzxmKfFGBI/5rsoM0LpRQp8bfKGeS/Fghl9CYl8slR2iK7ewfPM4W7bMdaTrpmg7yVq
+c5iJWzouE4gev8CSlDQb4ye3ix5vQv/n6TebUB0tovkC7stYWDpxvGjjqsGvHCgfotwjZT+B6q6Z
+09gwzxMNTxXJhLynSC34MCN32EZLeW32jO06f2ARePTpm67VVMB0gNELQp/B
+-----END CERTIFICATE-----
+
+Go Daddy Root Certificate Authority - G2
+========================================
+-----BEGIN CERTIFICATE-----
+MIIDxTCCAq2gAwIBAgIBADANBgkqhkiG9w0BAQsFADCBgzELMAkGA1UEBhMCVVMxEDAOBgNVBAgT
+B0FyaXpvbmExEzARBgNVBAcTClNjb3R0c2RhbGUxGjAYBgNVBAoTEUdvRGFkZHkuY29tLCBJbmMu
+MTEwLwYDVQQDEyhHbyBEYWRkeSBSb290IENlcnRpZmljYXRlIEF1dGhvcml0eSAtIEcyMB4XDTA5
+MDkwMTAwMDAwMFoXDTM3MTIzMTIzNTk1OVowgYMxCzAJBgNVBAYTAlVTMRAwDgYDVQQIEwdBcml6
+b25hMRMwEQYDVQQHEwpTY290dHNkYWxlMRowGAYDVQQKExFHb0RhZGR5LmNvbSwgSW5jLjExMC8G
+A1UEAxMoR28gRGFkZHkgUm9vdCBDZXJ0aWZpY2F0ZSBBdXRob3JpdHkgLSBHMjCCASIwDQYJKoZI
+hvcNAQEBBQADggEPADCCAQoCggEBAL9xYgjx+lk09xvJGKP3gElY6SKDE6bFIEMBO4Tx5oVJnyfq
+9oQbTqC023CYxzIBsQU+B07u9PpPL1kwIuerGVZr4oAH/PMWdYA5UXvl+TW2dE6pjYIT5LY/qQOD
++qK+ihVqf94Lw7YZFAXK6sOoBJQ7RnwyDfMAZiLIjWltNowRGLfTshxgtDj6AozO091GB94KPutd
+fMh8+7ArU6SSYmlRJQVhGkSBjCypQ5Yj36w6gZoOKcUcqeldHraenjAKOc7xiID7S13MMuyFYkMl
+NAJWJwGRtDtwKj9useiciAF9n9T521NtYJ2/LOdYq7hfRvzOxBsDPAnrSTFcaUaz4EcCAwEAAaNC
+MEAwDwYDVR0TAQH/BAUwAwEB/zAOBgNVHQ8BAf8EBAMCAQYwHQYDVR0OBBYEFDqahQcQZyi27/a9
+BUFuIMGU2g/eMA0GCSqGSIb3DQEBCwUAA4IBAQCZ21151fmXWWcDYfF+OwYxdS2hII5PZYe096ac
+vNjpL9DbWu7PdIxztDhC2gV7+AJ1uP2lsdeu9tfeE8tTEH6KRtGX+rcuKxGrkLAngPnon1rpN5+r
+5N9ss4UXnT3ZJE95kTXWXwTrgIOrmgIttRD02JDHBHNA7XIloKmf7J6raBKZV8aPEjoJpL1E/QYV
+N8Gb5DKj7Tjo2GTzLH4U/ALqn83/B2gX2yKQOC16jdFU8WnjXzPKej17CuPKf1855eJ1usV2GDPO
+LPAvTK33sefOT6jEm0pUBsV/fdUID+Ic/n4XuKxe9tQWskMJDE32p2u0mYRlynqI4uJEvlz36hz1
+-----END CERTIFICATE-----
+
+Starfield Root Certificate Authority - G2
+=========================================
+-----BEGIN CERTIFICATE-----
+MIID3TCCAsWgAwIBAgIBADANBgkqhkiG9w0BAQsFADCBjzELMAkGA1UEB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E03lRTs2Q9GcHGcg8RnoNAX3FWOdt5oUw
+F5okxBDgBPfg8n/Uqgr/Qh037ZTlZFkSIHc40zI+OIF1lnP6aI+xy84fxez6nH7PfrHxBy22/L/K
+pL/QlwVKvOoYKAKQvVR4CSFx09F9HdkWsKlhPdAKACL8x3vLCWRFCztAgfd9fDL1mMpYjn0q7pBZ
+c2T5NnReJaH1ZgUufzkVqSr7UIuOhWn0
+-----END CERTIFICATE-----
+
+Starfield Services Root Certificate Authority - G2
+==================================================
+-----BEGIN CERTIFICATE-----
+MIID7zCCAtegAwIBAgIBADANBgkqhkiG9w0BAQsFADCBmDELMAkGA1UEBhMCVVMxEDAOBgNVBAgT
+B0FyaXpvbmExEzARBgNVBAcTClNjb3R0c2RhbGUxJTAjBgNVBAoTHFN0YXJmaWVsZCBUZWNobm9s
+b2dpZXMsIEluYy4xOzA5BgNVBAMTMlN0YXJmaWVsZCBTZXJ2aWNlcyBSb290IENlcnRpZmljYXRl
+IEF1dGhvcml0eSAtIEcyMB4XDTA5MDkwMTAwMDAwMFoXDTM3MTIzMTIzNTk1OVowgZgxCzAJBgNV
+BAYTAlVTMRAwDgYDVQQIEwdBcml6b25hMRMwEQYDVQQHEwpTY290dHNkYWxlMSUwIwYDVQQKExxT
+dGFyZmllbGQgVGVjaG5vbG9naWVzLCBJbmMuMTswOQYDVQQDEzJTdGFyZmllbGQgU2VydmljZXMg
+Um9vdCBDZXJ0aWZpY2F0ZSBBdXRob3JpdHkgLSBHMjCCASIwDQYJKoZIhvcNAQEBBQADggEPADCC
+AQoCggEBANUMOsQq+U7i9b4Zl1+OiFOxHz/Lz58gE20pOsgPfTz3a3Y4Y9k2YKibXlwAgLIvWX/2
+h/klQ4bnaRtSmpDhcePYLQ1Ob/bISdm28xpWriu2dBTrz/sm4xq6HZYuajtYlIlHVv8loJNwU4Pa
+hHQUw2eeBGg6345AWh1KTs9DkTvnVtYAcMtS7nt9rjrnvDH5RfbCYM8TWQIrgMw0R9+53pBlbQLP
+L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ZMOH8oMDX/nyNTt7buFHAAQCva
+R6s0fl6nVjBhK4tDrP22iCj1a7Y+YEq6QpA0Z43q619FVDsXrIvkxmUP7tCMXWY5zjKn2BCXwH40
+nJ+U8/aGH88bc62UeYdocMMzpXDn2NU4lG9jeeu/Cg4I58UvD0KgKxRA/yHgBcUn4YQRE7rWhh1B
+CxMjidPJC+iKunqjo3M3NYB9Ergzd0A4wPpeMNLytqOx1qKVl4GbUu1pTP+A5FPbVFsDbVRfsbjv
+JL1vnxHDx2TCDyhihWZeGnuyt++uNckZM6i4J9szVb9o4XVIRFb7zdNIu0eJOqxp9YDG5ERQL1TE
+qkPFMTFYvZbF6nVsmnWxTfj3l/+WFvKXTej28xH5On2KOG4Ey+HTRRWqpdEdnV1j6CTmNhTih60b
+WfVEm/vXd3wfAXBioSAaosUaKPQhA+4u2cGA6rnZgtZbdsLLO7XSAPCjDuGtbkD326C00EauFddE
+wk01+dIL8hf2rGbVJLJP0RyZwG71fet0BLj5TXcJ17TPBzAJ8bgAVtkXFhYKK4bfjwEZGuW7gmP/
+vgt2Fl43N+bYdJeimUV5
+-----END CERTIFICATE-----
+
+Root CA Generalitat Valenciana
+==============================
+-----BEGIN CERTIFICATE-----
+MIIGizCCBXOgAwIBAgIEO0XlaDANBgkqhkiG9w0BAQUFADBoMQswCQYDVQQGEwJFUzEfMB0GA1UE
+ChMWR2VuZXJhbGl0YXQgVmFsZW5jaWFuYTEPMA0GA1UECxMGUEtJR1ZBMScwJQYDVQQDEx5Sb290
+IENBIEdlbmVyYWxpdGF0IFZhbGVuY2lhbmEwHhcNMDEwNzA2MTYyMjQ3WhcNMjEwNzAxMTUyMjQ3
+WjBoMQswCQYDVQQGEwJFUzEfMB0GA1UEChMWR2VuZXJhbGl0YXQgVmFsZW5jaWFuYTEPMA0GA1UE
+CxMGUEtJR1ZBMScwJQYDVQQDEx5Sb290IENBIEdlbmVyYWxpdGF0IFZhbGVuY2lhbmEwggEiMA0G
+CSqGSIb3DQEBAQUAA4I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A5GPBnc6hQLdmNVDeD/GMBWsm2vLV7eJUYs66MmEDNuxUCAKGkq6
+ahq97BvIxYSazQ==
+-----END CERTIFICATE-----
+
+TWCA Root Certification Authority
+=================================
+-----BEGIN CERTIFICATE-----
+MIIDezCCAmOgAwIBAgIBATANBgkqhkiG9w0BAQUFADBfMQswCQYDVQQGEwJUVzESMBAGA1UECgwJ
+VEFJV0FOLUNBMRAwDgYDVQQLDAdSb290IENBMSowKAYDVQQDDCFUV0NBIFJvb3QgQ2VydGlmaWNh
+dGlvbiBBdXRob3JpdHkwHhcNMDgwODI4MDcyNDMzWhcNMzAxMjMxMTU1OTU5WjBfMQswCQYDVQQG
+EwJUVzESMBAGA1UECgwJVEFJV0FOLUNBMRAwDgYDVQQLDAdSb290IENBMSowKAYDVQQDDCFUV0NB
+IFJvb3QgQ2VydGlmaWNhdGlvbiBBdXRob3JpdHkwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEK
+AoIBAQCwfnK4pAOU5qfeCTiRShFAh6d8WWQUe7UREN3+v9XAu1bihSX0NXIP+FPQQeFEAcK0HMMx
+QhZHhTMidrIKbw/lJVBPhYa+v5guEGcevhEFhgWQxFnQfHgQsIBct+HHK3XLfJ+utdGdIzdjp9xC
+oi2SBBtQwXu4PhvJVgSLL1KbralW6cH/ralYhzC2gfeXRfwZVzsrb+RH9JlF/h3x+JejiB03HFyP
+4HYlmlD4oFT/RJB2I9IyxsOrBr/8+7/zrX2SYgJbKdM1o5OaQ2RgXbL6Mv87BK9NQGr5x+PvI/1r
+y+UPizgN7gr8/g+YnzAx3WxSZfmLgb4i4RxYA7qRG4kHAgMBAAGjQjBAMA4GA1UdDwEB/wQEAwIB
+BjAPBgNVHRMBAf8EBTADAQH/MB0GA1UdDgQWBBRqOFsmjd6LWvJPelSDGRjjCDWmujANBgkqhkiG
+9w0BAQUFAAOCAQEAPNV3PdrfibqHDAhUaiBQkr6wQT25JmSDCi/oQMCXKCeCMErJk/9q56YAf4lC
+mtYR5VPOL8zy2gXE/uJQxDqGfczafhAJO5I1KlOy/usrBdlsXebQ79NqZp4VKIV66IIArB6nCWlW
+QtNoURi+VJq/REG6Sb4gumlc7rh3zc5sH62Dlhh9DrUUOYTxKOkto557HnpyWoOzeW/vtPzQCqVY
+T0bf+215WfKEIlKuD8z7fDvnaspHYcN6+NOSBB+4IIThNlQWx0DeO4pz3N/GCUzf7Nr/1FNCocny
+Yh0igzyXxfkZYiesZSLX0zzG5Y6yU8xJzrww/nsOM5D77dIUkR8Hrw==
+-----END CERTIFICATE-----
+
\ No newline at end of file diff --git a/library/eden/paypal/checkout.php b/library/eden/paypal/checkout.php new file mode 100644 index 0000000..e924d49 --- /dev/null +++ b/library/eden/paypal/checkout.php @@ -0,0 +1,455 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Paypal Express Checkout + * + * @package Eden + * @category Paypal + * @author Christian Symon M. Buenavista sbuenavista@openovate.com + */ +class Eden_Paypal_Checkout extends Eden_Paypal_Base { + /* Constants + -------------------------------*/ + const TEST_URL_CHECKOUT = 'https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=%s'; + const LIVE_URL = 'https://www.paypal.com/webscr?cmd=_express-checkout&token=%s'; + + const SET_METHOD = 'SetExpressCheckout'; + const GET_METHOD = 'GetExpressCheckoutDetails'; + const DO_METHOD = 'DoExpressCheckoutPayment'; + const DO_ADDRESS_VERIFY = 'AddressVerify'; + const CALL_BACK = 'Callback'; + const GET_BALANCE = 'GetBalance'; + const MASS_PAYMENT = 'MassPay'; + const GET_DETAIL = 'GetPalDetails'; + + const SUCCESS = 'Success'; + const ACK = 'ACK'; + const TOKEN = 'TOKEN'; + const SALE = 'Sale'; + const ERROR = 'L_LONGMESSAGE0'; + + const RETURN_URL = 'RETURNURL'; + const CANCEL_URL = 'CANCELURL'; + + const TOTAL_AMOUNT = 'PAYMENTREQUEST_0_AMT'; + const SHIPPING_AMOUNT = 'PAYMENTREQUEST_0_SHIPPINGAMT'; + const CURRENCY = 'PAYMENTREQUEST_0_CURRENCYCODE'; + const ITEM_AMOUNT = 'PAYMENTREQUEST_0_ITEMAMT'; + const ITEM_NAME = 'L_PAYMENTREQUEST_0_NAME0'; + const ITEM_DESCRIPTION = 'L_PAYMENTREQUEST_0_DESC0'; + const ITEM_AMOUNT2 = 'L_PAYMENTREQUEST_0_AMT0'; + const QUANTITY = 'L_PAYMENTREQUEST_0_QTY0'; + const EMAIL = 'EMAIL'; + const STREET = 'STREET'; + const ZIP = 'ZIP'; + const RETURN_CURRENCIES = 'RETURNALLCURRENCIES'; + const EMAIL_SUBJECT = 'EMAILSUBJECT'; + const SOLUTION_TYPE = 'SOLUTIONTYPE'; + + const PAYMENT_ACTION = 'PAYMENTACTION'; + const PAYER_ID = 'PAYERID'; + const TRANSACTION_ID = 'PAYMENTINFO_0_TRANSACTIONID'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_callBack = false; + protected $_currencies = 0; + + protected $_amount = NULL; + protected $_shippingAmount = NULL; + protected $_currency = NULL; + protected $_itemAmount = NULL; + protected $_itemName = NULL; + protected $_itemDescription = NULL; + protected $_quantity = NULL; + protected $_email = NULL; + protected $_street = NULL; + protected $_zip = NULL; + protected $_emailSubject = NULL; + protected $_solutionType = 'Sole'; + + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + /* Magic + -------------------------------*/ + public function __construct($user, $password, $signature, $certificate, $live = false) { + parent::__construct($user, $password, $signature, $certificate, $live); + + $this->_url = self::TEST_URL_CHECKOUT; + if($live) { + $this->_url = self::LIVE_URL; + } + } + + /* Public Methods + -------------------------------*/ + + /** + * Confirms whether a postal address and postal + * code match those of the specified PayPal + * account holder. + * + * @return string + */ + public function checkAddress() { + $query = array( + self::EMAIL => $this->_email, + self::STREET => $this->_street, + self::ZIP => $this->_zip); + + //call request method address verify + $response = $this->_request(self::DO_ADDRESS_VERIFY, $query); + // If checking successful + if(isset($response[self::ACK]) && $response[self::ACK] == self::SUCCESS) { + + return $response; + } + + return $response; + } + + /** + * Makes a payment to one or more PayPal account holders. + * + * @return string + */ + public function doMassPayment() { + + $query = array( + self::EMAIL_SUBJECT => $this->_emailSubject, //The subject line of the email that PayPal sends + self::CURRENCY => $this->_currency); //currency code + //call request method call back + return $this->_request(self::MASS_PAYMENT, $query); + + } + + /** + * Obtains the available balance for a PayPal account. + * + * @return string + */ + public function getBalance() { + // Indicates whether to return all currencies. + $query = array(self::RETURN_CURRENCIES => $this->_currencies); + //call request method call back + return $this->_request(self::GET_BALANCE, $query); + + } + + /** + * Obtains your Pal ID, which is the PayPal-assigned merchant + * account number, and other information about your account. + * You need the account number when working with dynamic + * versions of PayPal buttons and logos. + * + * @return string + */ + public function getDetail() { + //call request method call back + return $this->_request(self::GET_DETAIL); + + } + + /** + * Sends checkout information to paypal + * + * @param string The Return URL + * @param string The Cancel URL + * @param array + * @return string + */ + public function getResponse($return, $cancel) { + //Argument Test + Eden_Paypal_Error::i() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'string'); //Argument 2 must be a string + + $query = array( + 'PAYMENTREQUEST_0_PAYMENTACTION' => 'Authorization', + self::SOLUTION_TYPE => $this->_solutionType, + self::TOTAL_AMOUNT => $this->_amount, //amount of item + self::RETURN_URL => $return, + self::CANCEL_URL => $cancel, + self::SHIPPING_AMOUNT => $this->_shippingAmount, //amount of shipping + self::CURRENCY => $this->_currency, //currency code + self::ITEM_AMOUNT => $this->_itemAmount, //item amount is shippingAmount minus amount + self::ITEM_NAME => $this->_itemName, //name of item + self::ITEM_DESCRIPTION => $this->_itemDescription, //description of item + self::ITEM_AMOUNT2 => $this->_itemAmount, //item amount is shipping minus amount + self::QUANTITY => $this->_quantity,); //quantity of item + + //call request method set express checkout + $response = $this->_request(self::SET_METHOD, $query, false); + //if parameters are success + if(isset($response[self::ACK]) && $response[self::ACK] == self::SUCCESS) { + //fetch token + //if callback is true + if($this->_callBack) { + $this->_token = $response[self::TOKEN]; + return $this->_getCallback(); + } + } + + return $response; + } + + public function getTransactionId($payerId) { + $this->_payer = $payerId; + if(!$this->_token) { + return NULL; + } + + return $this->_getTransactionId(); + } + /** + * Set the amount of the item + * + * @param integer or float Amount of the item + * @return this + */ + public function setAmount($amount) { + //Argument 1 must be an integer or float + Eden_Paypal_Error::i()->argument(1, 'integer', 'float'); + + $this->_amount = $amount; + return $this; + } + + /** + * Set callback to true + * + * @return this + */ + public function setCallBack() { + $this->_callBack = 'true'; + return $this; + } + + /** + * Set Solution type, value are + * Sole – Buyer does not need to create a + * PayPal account to check out. This + * is referred to as PayPal Account Optional. + * Mark – Buyer must have a PayPal account to + * check out. + * + * @param string + * @return this + */ + public function setSolutionType($solutioType = 'Sole') { + //Argument 1 must be an string + Eden_Paypal_Error::i()->argument(1, 'string'); + + $this->_solutionType = $solutioType; + return $this; + } + + /** + * Indicates whether to return all currencies. + * + * @return this + */ + public function setCurrencies() { + $this->_currencies = 1; + return $this; + } + + /** + * Set currrency + * + * @param string Currency code + * @return this + */ + public function setCurrency($currency) { + //Argument 1 must be a string + Eden_Paypal_Error::i()->argument(1, 'string'); + + $this->_currency = $currency; + return $this; + } + + /** + * Set consumer email + * + * @param string consumer email + * @return this + */ + public function setEmail($email) { + //Argument 1 must be a string + Eden_Paypal_Error::i()->argument(1, 'string'); + + $this->_email = $email; + return $this; + } + + /** + * Indicates whether to return all currencies. + * + * @param boolean + * @return this + */ + public function setEmailSubject($emailSubject) { + //Argument 1 must be a string + Eden_Paypal_Error::i()->argument(1, 'string'); + + $this->_emailSubject = $emailSubject; + return $this; + } + + /** + * Set total amount of the item + * + * @param integer or float Total amount of the item + * @return this + */ + public function setItemAmount($itemAmount) { + //Argument 1 must be an integer or float + Eden_Paypal_Error::i()->argument(1, 'integer', 'float'); + + $this->_itemAmount = $itemAmount; + return $this; + } + + /** + * Set item descrption + * + * @param string Item Description + * @return this + */ + public function setItemDescription($itemDescription) { + //Argument 1 must be a string + Eden_Paypal_Error::i()->argument(1, 'string'); + + $this->_itemDescription = $itemDescription; + return $this; + } + + /** + * Set item name + * + * @param string Item name + * @return this + */ + public function setItemName($itemName) { + //Argument 1 must be a string + Eden_Paypal_Error::i()->argument(1, 'string'); + + $this->_itemName = $itemName; + return $this; + } + + /** + * Set quantity of item + * + * @param integer Item quantity + * @return this + */ + public function setQuantity($quantity) { + //Argument 1 must be a integer + Eden_Paypal_Error::i()->argument(1, 'int'); + + $this->_quantity = $quantity; + return $this; + } + + /** + * Set shipping amount of the item + * + * @param integer or float Shipping amount of the item + * @return this + */ + public function setShippingAmount($shippingAmount) { + //Argument 1 must be an integer or float + Eden_Paypal_Error::i()->argument(1, 'integer', 'float'); + + $this->_shippingAmount = $shippingAmount; + return $this; + } + + /** + * Set consumer street + * + * @param string consumer street + * @return this + */ + public function setStreet($street) { + //Argument 1 must be a string + Eden_Paypal_Error::i()->argument(1, 'string'); + + $this->_street = $street; + return $this; + } + + public function setToken($token, $redirect = false) { + $this->_token = $token; + if($redirect == true){ + header('Location: '. sprintf($this->_url, urlencode($this->_token)) ); + return; + } + + return $this; + } + + /** + * Set consumer zip code + * + * @param string consumer zip code + * @return this + */ + public function setZip($zip) { + //Argument 1 must be a string + Eden_Paypal_Error::i()->argument(1, 'string'); + + $this->_zip = $zip; + return $this; + } + + /* Protected Methods + -------------------------------*/ + protected function _getCallback() { + //currency code + $query = array(self::CURRENCY => $this->_currency, + self::TOKEN => $this->_token); + //call request method call back + return $this->_request(self::CALL_BACK, $query); + + } + + protected function _getTransactionId() { + // Get checkout details, including buyer information, call get express checkout method + $checkoutDetails = $this->_request(self::GET_METHOD, array(self::TOKEN => $this->_token)); + + // Complete the checkout transaction + $query = array( + self::TOKEN => $this->_token, + self::PAYMENT_ACTION => self::SALE, + self::PAYER_ID => $this->_payer, + self::TOTAL_AMOUNT => $this->_amount, // Same amount as in the original request + self::CURRENCY => $this->_currency); // Same currency as the original request + + //call request method do express checckout + $response = $this->_request(self::DO_METHOD, $query); + + // If payment successful\ + // Fetch the transaction ID + return $response; + } + + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/paypal/direct.php b/library/eden/paypal/direct.php new file mode 100644 index 0000000..8d925a9 --- /dev/null +++ b/library/eden/paypal/direct.php @@ -0,0 +1,356 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Paypal Website Payments Pro - Direct Payment + * + * @package Eden + * @category Paypal + * @author Christian Symon M. Buenavista sbuenavista@openovate.com + */ +class Eden_Paypal_Direct extends Eden_Paypal_Base { + /* Constants + -------------------------------*/ + const DIRECT_PAYMENT = 'DoDirectPayment'; + const NON_REFERENCED_CREDIT = 'DoNonReferencedCredit'; + + const TRANSACTION_ID = 'TRANSACTIONID'; + const SALE = 'sale'; + const ACK = 'ACK'; + const SUCCESS = 'Success'; + const REMOTE_ADDRESS = 'REMOTE_ADDR'; + const IP_ADDRESS = 'IPADDRESS'; + const PAYMENT_ACTION = 'PAYMENTACTION'; + + const CARD_TYPE = 'CREDITCARDTYPE'; + const CARD_NUMBER = 'ACCT'; + const EXPIRATION_DATE = 'EXPDATE' ; + const CVV = 'CVV2'; + const FIRST_NAME = 'FIRSTNAME'; + const LAST_NAME = 'LASTNAME'; + const EMAIL = 'EMAIL'; + const COUNTRY_CODE = 'COUNTRYCODE'; + const STATE = 'STATE'; + const CITY = 'CITY'; + const STREET = 'STREET'; + const ZIP = 'ZIP'; + const AMOUNT = 'AMT'; + const CURRENCY = 'CURRENCYCODE'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_nonReferencedCredit = false; + + protected $_profileId = NULL; + protected $_cardType = NULL; + protected $_cardNumber = NULL; + protected $_expirationDate = NULL; + protected $_cvv2 = NULL; + protected $_firstName = NULL; + protected $_lastName = NULL; + protected $_email = NULL; + protected $_countryCode = NULL; + protected $_state = NULL; + protected $_city = NULL; + protected $_street = NULL; + protected $_zip = NULL; + protected $_amout = NULL; + protected $_currency = NULL; + + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + /* Public Methods + -------------------------------*/ + /** + * Process a credit card direct payment + * + * @return string + * @note Contact PayPal to use DoNonReferencedCredit + * API operation, in most cases, you should use the + * RefundTransaction API operation instead. + */ + public function getResponse() { + //populate fields + $query = array( + self::IP_ADDRESS => $_SERVER[self::REMOTE_ADDRESS], //IP address of the consumer + self::PAYMENT_ACTION => self::SALE, //payment action(sale or authorize) + self::CARD_TYPE => $this->_cardType, //creidit card type + self::CARD_NUMBER => $this->_cardNumber, //credit card account number + self::EXPIRATION_DATE => $this->_expirationDate, //credit card expiration date + self::CVV => $this->_cvv2, //3 - digits card verification number + self::FIRST_NAME => $this->_firstName, //cardholder firstname + self::LAST_NAME => $this->_lastName, //cardholder lastname + self::EMAIL => $this->_email, //cardholder email + self::COUNTRY_CODE => $this->_countryCode, //cardholder country code + self::STATE => $this->_state, //cardholder state + self::CITY => $this->_city, //cardholder city + self::STREET => $this->_street, //cardholder street + self::ZIP => $this->_zip, //cardholder ZIP + self::AMOUNT => $this->_amount, //amount of the payment + self::CURRENCY => $this->_currency); //currency code, default is USD + + //if Set Non Referenced Credit is true + if($this->_setNonReferencedCredit){ + //call non referenced credit method + return $this->_setNonReferencedCredit($query); + } + //call direct payment method + return $this->_setDirectPayment($query); + } + + /** + * Set item amount + * + * @param integer or float Item amount + * @return this + */ + public function setAmount($amount) { + //Argument 1 must be a string + Eden_Paypal_Error::i()->argument(1, 'int', 'float'); + + $this->_amount = $amount; + return $this; + } + + /** + * Set credit card number + * + * @param string Credit card number + * @return this + */ + public function setCardNumber($cardNumber) { + //Argument 1 must be a string + Eden_Paypal_Error::i()->argument(1, 'string'); + + $this->_cardNumber = $cardNumber; + return $this; + } + + /** + * Set credit card type + * + * @param string Credit card type + * @return this + */ + public function setCardType($cardType) { + //Argument 1 must be a string + Eden_Paypal_Error::i()->argument(1, 'string'); + + $this->_cardType = $cardType; + return $this; + } + + /** + * Set cardholder city + * + * @param string City + * @return this + */ + public function setCity($city) { + //Argument 1 must be a string + Eden_Paypal_Error::i()->argument(1, 'string'); + + $this->_city = $city; + return $this; + } + + /** + * Set cardholder country code + * + * @param string Country Code + * @return this + */ + public function setCountryCode($countryCode) { + //Argument 1 must be a string + Eden_Paypal_Error::i()->argument(1, 'string'); + + $this->_countryCode = $countryCode; + return $this; + } + + /** + * Set currency code + * + * @param string Currency code + * @return this + */ + public function setCurrency($currency) { + //Argument 1 must be a string + Eden_Paypal_Error::i()->argument(1, 'string'); + + $this->_currency = $currency; + return $this; + } + + /** + * Set Card Verification Value + * + * @param string 3 - digit cvv number + * @return this + */ + public function setCvv2($cvv2) { + //Argument 1 must be a string + Eden_Paypal_Error::i()->argument(1, 'string'); + + $this->_cvv2 = $cvv2; + return $this; + } + + /** + * Set cardholder email address + * + * @param string Email address + * @return this + */ + public function setEmail($email) { + //Argument 1 must be a string + Eden_Paypal_Error::i()->argument(1, 'string'); + + $this->_email = $email; + return $this; + } + + /** + * Set credit card expiration date + * + * @param string Credit card expiration date + * @return this + */ + public function setExpirationDate($expirationDate) { + //Argument 1 must be a string + Eden_Paypal_Error::i()->argument(1, 'string'); + + $this->_expirationDate = $expirationDate; + return $this; + } + + /** + * Set cardholder first name + * + * @param string First name + * @return this + */ + public function setFirstName($firstName) { + //Argument 1 must be a string + Eden_Paypal_Error::i()->argument(1, 'string'); + + $this->_firstName = $firstName; + return $this; + } + + /** + * Set cardholder last name + * + * @param string Last name + * @return this + */ + public function setLastName($lastName) { + //Argument 1 must be a string + Eden_Paypal_Error::i()->argument(1, 'string'); + + $this->_lastName = $lastName; + return $this; + } + + /** + * Issue a credit to a card not referenced + * by the original transaction. + * + * @return this + */ + public function setNonReferencedCredit() { + $this->_setNonReferencedCredit = 'true'; + return $this; + } + + /** + * Set cardholder state + * + * @param string State + * @return this + */ + public function setState($state) { + //Argument 1 must be a string + Eden_Paypal_Error::i()->argument(1, 'string'); + + $this->_state = $state; + return $this; + } + + /** + * Set cardholder street + * + * @param string Street + * @return this + */ + public function setStreet($street) { + //Argument 1 must be a string + Eden_Paypal_Error::i()->argument(1, 'string'); + + $this->_street = $street; + return $this; + } + + /** + * Set cardholder zip code + * + * @param string Zip code + * @return this + */ + public function setZip($zip) { + //Argument 1 must be a string + Eden_Paypal_Error::i()->argument(1, 'string'); + + $this->_zip = $zip; + return $this; + } + + /* Protected Methods + -------------------------------*/ + protected function _setDirectPayment($query) { + //Argument 1 must be an array + Eden_Paypal_Error::i()->argument(1, 'array'); + + //do direct payment + $response = $this->_request(self::DIRECT_PAYMENT, $query); + //if parameters are success + if(isset($response[self::ACK]) && $response[self::ACK] == self::SUCCESS) { + // Get the transaction ID + return $response[self::TRANSACTION_ID]; + } + + return $response; + } + + protected function _setNonReferencedCredit($query) { + //Argument 1 must be an array + Eden_Paypal_Error::i()->argument(1, 'array'); + + //call request method + $response = $this->_request(self::NON_REFERENCED_CREDIT, $query); + //if parameters are success + if(isset($response[self::ACK]) && $response[self::ACK] == self::SUCCESS) { + // Get the transaction ID + return $response[self::TRANSACTION_ID]; + } + + return $response; + } + + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/paypal/error.php b/library/eden/paypal/error.php new file mode 100644 index 0000000..f49af3a --- /dev/null +++ b/library/eden/paypal/error.php @@ -0,0 +1,39 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Eventbrite Errors + * + * @package Eden + * @category Paypal + * @author Christian Blanquera cblanquera@openovate.com + */ +class Eden_Paypal_Error extends Eden_Error { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i($message = NULL, $code = 0) { + $class = __CLASS__; + return new $class($message, $code); + } + + /* Public Methods + -------------------------------*/ + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/paypal/recurring.php b/library/eden/paypal/recurring.php new file mode 100644 index 0000000..b86c9f2 --- /dev/null +++ b/library/eden/paypal/recurring.php @@ -0,0 +1,551 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Paypal Website Payments Pro - Recurring Payment + * + * @package Eden + * @category Paypal + * @author Christian Symon M. Buenavista sbuenavista@openovate.com + */ +class Eden_Paypal_Recurring extends Eden_Paypal_Base { + /* Constants + -------------------------------*/ + const RECURRING_PAYMENT = 'CreateRecurringPaymentsProfile'; + const GET_DETAIL = 'GetRecurringPaymentsProfileDetails'; + const MANAGE_STATUS = 'ManageRecurringPaymentsProfileStatus'; + const BILL_AMOUNT = 'BillOutstandingAmount'; + const PROFILE_ID = 'PROFILEID'; + + const SALE = 'sale'; + const ACK = 'ACK'; + const SUCCESS = 'Success'; + const ERROR = 'L_LONGMESSAGE0'; + const REMOTE_ADDRESS = 'REMOTE_ADDR'; + const IP_ADDRESS = 'IPADDRESS'; + const PAYMENT_ACTION = 'PAYMENTACTION'; + + const DAY = 'Day'; + const WEEK = 'Week'; + const SEMI_MONTH = 'SemiMonth'; + const MONTH = 'Month'; + const YEAR = 'Year'; + const CANCEL = 'Cancel'; + const SUSPEND = 'Suspend'; + const REACTIVATE = 'Reactivate'; + + const CARD_TYPE = 'CREDITCARDTYPE'; + const CARD_NUMBER = 'ACCT'; + const EXPIRATION_DATE = 'EXPDATE' ; + const CVV = 'CVV2'; + const FIRST_NAME = 'FIRSTNAME'; + const LAST_NAME = 'LASTNAME'; + const EMAIL = 'EMAIL'; + const COUNTRY_CODE = 'COUNTRYCODE'; + const STATE = 'STATE'; + const CITY = 'CITY'; + const STREET = 'STREET'; + const ZIP = 'ZIP'; + const AMOUNT = 'AMT'; + const CURRENCY = 'CURRENCYCODE'; + const DESCRIPTION = 'DESC'; + const START_DATE = 'PROFILESTARTDATE'; + const BILLING_PERIOD = 'BILLINGPERIOD'; + const BILLING_FREQUENCY = 'BILLINGFREQUENCY'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_profileId = NULL; + protected $_cardType = NULL; + protected $_cardNumber = NULL; + protected $_expirationDate = NULL; + protected $_cvv2 = NULL; + protected $_firstName = NULL; + protected $_lastName = NULL; + protected $_email = NULL; + protected $_countryCode = NULL; + protected $_state = NULL; + protected $_city = NULL; + protected $_street = NULL; + protected $_zip = NULL; + protected $_amout = NULL; + protected $_currency = NULL; + protected $_action = NULL; + protected $_note = NULL; + + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + /* Public Methods + -------------------------------*/ + /** + * The action to be performed to the + * recurring payments profile set + * to Cancel + * + * @return this + */ + public function cancel() { + $this->_action = self::CANCEL; + return $this; + } + + /** + * Bills the buyer for the outstanding balance + * associated with a recurring payments profile.. + * + * @return string + */ + public function getBilling() { + //populate fields + $query = array( + self::PROFILE_ID => $this->_profileId, //profile id of consumer + self::AMOUNT => $this->_amount, //outstading amount balance + self::NOTE => $this->_note); //the reason for the change in status + //call request method + $response = $this->_request(self::BILL_AMOUNT, $query); + //if parameters are success + if(isset($response[self::ACK]) && $response[self::ACK] == self::SUCCESS) { + + return $response; + } + + return $response; + } + + /** + * Create a recurring payments profile using direct payment + * associated with a debit or credit card. + * + * @return string + */ + public function getResponse() { + //populate fields + $query = array( + self::IP_ADDRESS => $_SERVER[self::REMOTE_ADDRESS], //IP address of the consumer + self::PAYMENT_ACTION => self::SALE, //payment action(sale or authorize) + self::CARD_TYPE => $this->_cardType, //creidit card type + self::CARD_NUMBER => $this->_cardNumber, //credit card account number + self::EXPIRATION_DATE => $this->_expirationDate, //credit card expiration date + self::CVV => $this->_cvv2, //3 - digits card verification number + self::FIRST_NAME => $this->_firstName, //cardholder firstname + self::LAST_NAME => $this->_lastName, //cardholder lastname + self::EMAIL => $this->_email, //cardholder email + self::COUNTRY_CODE => $this->_countryCode, //cardholder country code + self::STATE => $this->_state, //cardholder state + self::CITY => $this->_city, //cardholder city + self::STREET => $this->_street, //cardholder street + self::ZIP => $this->_zip, //cardholder ZIP + self::AMOUNT => $this->_amount, //amount of the recurring payment + self::CURRENCY => $this->_currency, //currency code, default is USD + self::DESCRIPTION => $this->_description, //description of recurring payment + self::START_DATE => date('Y-m-d H:i:s'), //start date of the recurring billing agreement + self::BILLING_PERIOD => $this->_billingPeriod, //the unit to be used to calculate the billing cycle + self::BILLING_FREQUENCY => $this->_billingFrequency); //billing periods that make up the billing cycle. + //call request method + $response = $this->_request(self::RECURRING_PAYMENT, $query); + //if parameters are success + if(isset($response[self::ACK]) && $response[self::ACK] == self::SUCCESS) { + // Get the profile Id + $this->_profileId = $response[self::PROFILE_ID]; + + return $this->_getDetails(); + } + return $response; + } + + /** + * Cancels, suspends, or reactivates a recurring + * payments profile. + * + * @return string + */ + public function getStatus() { + //populate fields + $query = array( + self::PROFILE_ID => $this->_profileId, //profile id of consumer + self::ACTION => $this->_action, //valid value are Cancel, Suspend and Reactivate + self::NOTE => $this->_note); //the reason for the change in status + //call request method + $response = $this->_request(self::MANAGE_STATUS, $query); + //if parameters are success + if(isset($response[self::ACK]) && $response[self::ACK] == self::SUCCESS) { + + return $response; + } + + return $response; + } + + /** + * The action to be performed to the + * recurring payments profile set + * to Reactivate + * + * @return this + */ + public function reactivate() { + $this->_action = self::REACTIVATE; + return $this; + } + + /** + * Set item amount + * + * @param integer or float Item amount + * @return this + */ + public function setAmount($amount) { + //Argument 1 must be a string + Eden_Paypal_Error::i()->argument(1, 'int', 'float'); + + $this->_amount = $amount; + return $this; + } + + /** + * Set the billing frequency + * + * @param integer Billing frequency + * @return this + */ + public function setBillingFrequency($billingFrequency) { + //Argument 1 must be an integer + Eden_Paypal_Error::i()->argument(1, 'int'); + + $this->_billingFrequency = $billingFrequency; + return $this; + } + /** + * Set credit card number + * + * @param string Credit card number + * @return this + */ + public function setCardNumber($cardNumber) { + //Argument 1 must be a string + Eden_Paypal_Error::i()->argument(1, 'string'); + + $this->_cardNumber = $cardNumber; + return $this; + } + + /** + * Set credit card type + * + * @param string Credit card type + * @return this + */ + public function setCardType($cardType) { + //Argument 1 must be a string + Eden_Paypal_Error::i()->argument(1, 'string'); + + $this->_cardType = $cardType; + return $this; + } + + /** + * Set cardholder city + * + * @param string City + * @return this + */ + public function setCity($city) { + //Argument 1 must be a string + Eden_Paypal_Error::i()->argument(1, 'string'); + + $this->_city = $city; + return $this; + } + + /** + * Set cardholder country code + * + * @param string Country Code + * @return this + */ + public function setCountryCode($countryCode) { + //Argument 1 must be a string + Eden_Paypal_Error::i()->argument(1, 'string'); + + $this->_countryCode = $countryCode; + return $this; + } + + /** + * Set currency code + * + * @param string Currency code + * @return this + */ + public function setCurrency($currency) { + //Argument 1 must be a string + Eden_Paypal_Error::i()->argument(1, 'string'); + + $this->_currency = $currency; + return $this; + } + + /** + * Set Card Verification Value + * + * @param string 3 - digit cvv number + * @return this + */ + public function setCvv2($cvv2) { + //Argument 1 must be a string + Eden_Paypal_Error::i()->argument(1, 'string'); + + $this->_cvv2 = $cvv2; + return $this; + } + + /** + * Set unit to be used to calculate the billing cycle + * to Day + * + * @return this + */ + public function setDay() { + $this->_billingPeriod = self::DAY; + return $this; + } + + /** + * Set item description + * + * @param string Item description + * @return this + */ + public function setDescription($description) { + //Argument 1 must be a string + Eden_Paypal_Error::i()->argument(1, 'string'); + + $this->_description = $description; + return $this; + } + + /** + * Set cardholder email address + * + * @param string Email address + * @return this + */ + public function setEmail($email) { + //Argument 1 must be a string + Eden_Paypal_Error::i()->argument(1, 'string'); + + $this->_email = $email; + return $this; + } + + /** + * Set credit card expiration date + * + * @param string Credit card expiration date + * @return this + */ + public function setExpirationDate($expirationDate) { + //Argument 1 must be a string + Eden_Paypal_Error::i()->argument(1, 'string'); + + $this->_expirationDate = $expirationDate; + return $this; + } + + /** + * Set cardholder first name + * + * @param string First name + * @return this + */ + public function setFirstName($firstName) { + //Argument 1 must be a string + Eden_Paypal_Error::i()->argument(1, 'string'); + + $this->_firstName = $firstName; + return $this; + } + + /** + * Set cardholder last name + * + * @param string Last name + * @return this + */ + public function setLastName($lastName) { + //Argument 1 must be a string + Eden_Paypal_Error::i()->argument(1, 'string'); + + $this->_lastName = $lastName; + return $this; + } + + /** + * Set unit to be used to calculate the billing cycle + * to Month + * + * @return this + */ + public function setMonth() { + $this->_billingPeriod = self::MONTH; + return $this; + } + + /** + * Set reason for the change in status + * + * @param string The reason for the change in status + * @return this + */ + public function setNote($note) { + //Argument 1 must be a string + Eden_Paypal_Error::i()->argument(1, 'string'); + + $this->_note = $note; + return $this; + } + + /** + * Set Profile Id + * + * @param string a valid profile id + * @return this + */ + public function setProfileId($profileId) { + //Argument 1 must be a string + Eden_Paypal_Error::i()->argument(1, 'string'); + + $this->_profileId = $profileId; + return $this; + } + + /** + * Set unit to be used to calculate the billing cycle + * to SemiMonth + * + * @return this + */ + public function setSemiMonth() { + $this->_billingPeriod = self::SEMI_MONTH; + return $this; + } + + /** + * Set cardholder state + * + * @param string State + * @return this + */ + public function setState($state) { + //Argument 1 must be a string + Eden_Paypal_Error::i()->argument(1, 'string'); + + $this->_state = $state; + return $this; + } + + /** + * Set to manage profile status + * + * @param boolean + * @return this + */ + public function setStatus($status) { + $this->_status = $status; + return $this; + } + + /** + * Set cardholder street + * + * @param string Street + * @return this + */ + public function setStreet($street) { + //Argument 1 must be a string + Eden_Paypal_Error::i()->argument(1, 'string'); + + $this->_street = $street; + return $this; + } + + /** + * Set unit to be used to calculate the billing cycle + * to Week + * + * @return this + */ + public function setWeek() { + $this->_billingPeriod = self::WEEK; + return $this; + } + + /** + * Set unit to be used to calculate the billing cycle + * to Year + * + * @return this + */ + public function setYear() { + $this->_billingPeriod = self::YEAR; + return $this; + } + + /** + * Set cardholder zip code + * + * @param string Zip code + * @return this + */ + public function setZip($zip) { + //Argument 1 must be a string + Eden_Paypal_Error::i()->argument(1, 'string'); + + $this->_zip = $zip; + return $this; + } + + /** + * The action to be performed to the + * recurring payments profile set + * to Suspend + * + * @return this + */ + public function suspend() { + $this->_action = self::SUSPEND; + return $this; + } + + /* Protected Methods + -------------------------------*/ + protected function _getDetails() { + //populate fields + $query = array(self::PROFILE_ID => $this->_profileId); //profile id of consumer + //call request method + $response = $this->_request(self::GET_DETAIL, $query); + //if parameters are success + if(isset($response[self::ACK]) && $response[self::ACK] == self::SUCCESS) { + return $response; + } + + return $response; + + } + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/paypal/transaction.php b/library/eden/paypal/transaction.php new file mode 100644 index 0000000..bfb2b5e --- /dev/null +++ b/library/eden/paypal/transaction.php @@ -0,0 +1,361 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Paypal Website Payments Pro - Common transaction + * + * @package Eden + * @category Paypal + * @author Christian Symon M. Buenavista sbuenavista@openovate.com + */ +class Eden_Paypal_Transaction extends Eden_Paypal_Base { + /* Constants + -------------------------------*/ + const GET_DETAIL = 'GetTransactionDetails'; + const MANAGE_STATUS = 'ManagePendingTransactionStatus'; + const REFUND_TRANSACTION = 'RefundTransaction'; + const SEARCH = 'TransactionSearch'; + + const ACTION = 'ACTION'; + const REFUND_TYPE = 'REFUNDTYPE'; + const STORE_ID = 'STOREID'; + const START = 'STARTDATE'; + const END = 'ENDDATE'; + const EMAIL = 'EMAIL'; + const RECEIVER = 'RECEIVER'; + const RECEIPT_ID = 'RECEIPTID'; + const TRANSACTION_ID = 'TRANSACTIONID'; + const CARD_NUMBER = 'ACCT'; + const AMOUNT = 'AMT'; + const CURRENCY = 'CURRENCYCODE'; + const STATUS = 'STATUS'; + const NOTE = 'NOTE'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_action = NULL; + protected $_refundType = NULL; + protected $_amount = NULL; + protected $_currency = NULL; + protected $_note = NULL; + protected $_storeId = NULL; + protected $_start = NULL; + protected $_end = NULL; + protected $_email = NULL; + protected $_receiver = NULL; + protected $_receiptId = NULL; + protected $_transactionId = NULL; + protected $_cardNumber = NULL; + protected $_status = NULL; + + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + /* Public Methods + -------------------------------*/ + /** + * Obtains information about a specific transaction. + * + * @return string + */ + public function getDetail() { + //populate fields + $query = array(self::TRANSACTION_ID => $this->_transactionId); + //call request method + $response = $this->_request(self::GET_DETAIL, $query); + + return $response; + } + + /** + * Accepts or denys a pending transaction held + * by Fraud Management Filters. + * + * @return string + */ + public function manageStatus() { + //populate fields + $query = array( + self::TRANSACTION_ID => $this->_transactionId, //The transaction ID of the payment transaction. + self::ACTION => $this->_action); //Valid values are Accept or Deny + //call request method + $response = $this->_request(self::MANAGE_STATUS, $query); + + return $response; + } + + /** + * Issues a refund to the PayPal account holder + * associated with a transaction. + * + * @return string + */ + public function refundTransaction() { + //populate fields + $query = array( + self::TRANSACTION_ID => $this->_transactionId, //The transaction ID of the payment transaction. + self::REFUND_TYPE => $this->_refundType, //Valid values are Full,Partial,ExternalDispute or Other + self::AMOUNT => $this->_amount, //Refund amount. + self::CURRENCY => $this->_currency, //Currency code + self::NOTE => $this->_note, //Custom memo about refund + self::STORE_ID => $this->_storeId); //ID of merchant store + //call request method + $response = $this->_request(self::REFUND_TRANSACTION, $query); + + return $response; + } + + /** + * Searches transaction history for transactions + * that meet the specified criteria. + * + * @return string + * @note The maximum number of transactions that + * can be returned from a TransactionSearch API call is 100. + */ + public function search() { + //populate fields + $query = array( + self::START => $this->_start, //The earliest transaction date at which to start the search + self::END => $this->_end, //The latest transaction date to be included in the search. + self::EMAIL => $this->_email, //Search by the buyer’s email address. + self::RECEIVER => $this->_receiver, //Search by the receiver’s email address. + self::RECEIPT_ID => $this->_receiptId, //Search by the PayPal Account Optional receipt ID. + self::TRANSACTION_ID => $this->_transactionId, //The transaction ID of the payment transaction. + self::CARD_NUMBER => $this->_cardNumber, //Search by credit card number + self::AMOUNT => $this->_amount, //Search by transaction amount + self::CURRENCY => $this->_currency, //Search by currency code. + self::STATUS => $this->_status); //Search by transaction status. + + //call request method + $response = $this->_request(self::SEARCH, $query); + + return $response; + } + + /** + * Valid values are Accept or Deny + * + * @param string + * @return this + */ + public function setAction($action) { + //Argument 1 must be a string + Eden_Paypal_Error::i()->argument(1, 'string'); + + $this->_action = $action; + return $this; + } + + /** + * Set item amount + * + * @param string Item amount + * @return this + */ + public function setAmount($amount) { + //Argument 1 must be a string + Eden_Paypal_Error::i()->argument(1, 'string'); + + $this->_amount = $amount; + return $this; + } + + /** + * Search by credit card number + * + * @param string Credit card number + * @return this + */ + public function setCardNumber($cardNumber) { + //Argument 1 must be a string + Eden_Paypal_Error::i()->argument(1, 'string'); + + $this->_cardNumber = $cardNumber; + return $this; + } + + /** + * Set currency code + * + * @param string Currency code + * @return this + */ + public function setCurrency($currency) { + //Argument 1 must be a string + Eden_Paypal_Error::i()->argument(1, 'string'); + + $this->_currency = $currency; + return $this; + } + + /** + * Search by the buyer’s email address. + * + * @param string + * @return this + */ + public function setEmail($email) { + //Argument 1 must be a string + Eden_Paypal_Error::i()->argument(1, 'string'); + + $this->_email = $email; + return $this; + } + + /** + * The latest transaction date to be + * included in the search. + * + * @param string + * @return this + */ + public function setEndDate($end) { + $date = strtotime($end); + $this->_end = gmdate('Y-m-d\TH:i:s\Z', $date); + return $this; + } + + /** + * Custom memo about the refund. + * + * @param string + * @return this + */ + public function setNote($note) { + //Argument 1 must be a string + Eden_Paypal_Error::i()->argument(1, 'string'); + + $this->_note = $note; + return $this; + } + + /** + * Search by the PayPal Account Optional + * receipt ID. + * + * @param string + * @return this + */ + public function setReceiptId($receiptId) { + //Argument 1 must be a string + Eden_Paypal_Error::i()->argument(1, 'string'); + + $this->_receiptId = $receiptId; + return $this; + } + + /** + * Search by the receiver’s email address. + * If the merchant account has only one email + * address, this is the primary email. It can + * also be a non-primary email address. + * + * @param string + * @return this + */ + public function setReceiver($receiver) { + //Argument 1 must be a string + Eden_Paypal_Error::i()->argument(1, 'string'); + + $this->_receiver = $receiver; + return $this; + } + + /** + * Valid values are + * Full - Full refund (default). + * Partial – Partial refund. + * ExternalDispute – External dispute. + * Other – Other type of refund. + * + * @param string + * @return this + */ + public function setRefundType($refundType) { + //Argument 1 must be a string + Eden_Paypal_Error::i()->argument(1, 'string'); + + $this->_refundType = $refundType; + return $this; + } + + /** + * The earliest transaction date at + * which to start the search. + * + * @param string + * @return this + */ + public function setStartDate($start) { + //Argument 1 must be a string + Eden_Paypal_Error::i()->argument(1, 'string'); + + $date = strtotime($start); + $this->_start = gmdate('Y-m-d\TH:i:s\Z', $date); + return $this; + } + + /** + * Search by transaction status. + * + * @param string Currency code + * @return this + */ + public function setStatus($status) { + //Argument 1 must be a string + Eden_Paypal_Error::i()->argument(1, 'string'); + + $this->_status = $status; + return $this; + } + + /** + * ID of the merchant store. This field is + * required for point-of-sale transactions. + * + * @param string + * @return this + */ + public function setStoreId($storeId) { + //Argument 1 must be a string + Eden_Paypal_Error::i()->argument(1, 'string'); + + $this->_storeId = $storeId; + return $this; + } + + /** + * Search by the transaction ID. The + * returned results are from the merchant’s + * transaction records. + * + * @param string + * @return this + */ + public function setTransactionId($transactionId) { + //Argument 1 must be a string + Eden_Paypal_Error::i()->argument(1, 'string'); + + $this->_transactionId = $transactionId; + return $this; + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/postgre.php b/library/eden/postgre.php new file mode 100644 index 0000000..4f336bf --- /dev/null +++ b/library/eden/postgre.php @@ -0,0 +1,358 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +require_once dirname(__FILE__).'/sql/database.php'; +require_once dirname(__FILE__).'/postgre/error.php'; +require_once dirname(__FILE__).'/postgre/delete.php'; +require_once dirname(__FILE__).'/postgre/select.php'; +require_once dirname(__FILE__).'/postgre/update.php'; +require_once dirname(__FILE__).'/postgre/insert.php'; +require_once dirname(__FILE__).'/postgre/alter.php'; +require_once dirname(__FILE__).'/postgre/create.php'; +require_once dirname(__FILE__).'/postgre/utility.php'; + +/** + * Abstractly defines a layout of available methods to + * connect to and query a PostGres database. This class also + * lays out query building methods that auto renders a + * valid query the specific database will understand without + * actually needing to know the query language. Extending + * all SQL classes, comes coupled with loosely defined + * searching, collections and models. + * + * @package Eden + * @category sql + * @author Christian Blanquera cblanquera@openovate.com + */ +class Eden_Postgre extends Eden_Sql_Database { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_host = 'localhost'; + protected $_port = NULL; + protected $_name = NULL; + protected $_user = NULL; + protected $_pass = NULL; + + protected $_model = self::MODEL; + protected $_collection = self::COLLECTION; + + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + public function __construct($host, $name, $user, $pass = NULL, $port = NULL) { + //argument test + Eden_Postgre_Error::i() + ->argument(1, 'string', 'null') //Argument 1 must be a string or null + ->argument(2, 'string') //Argument 2 must be a string + ->argument(3, 'string') //Argument 3 must be a string + ->argument(4, 'string', 'null') //Argument 4 must be a number or null + ->argument(5, 'numeric', 'null'); //Argument 4 must be a number or null + + $this->_host = $host; + $this->_name = $name; + $this->_user = $user; + $this->_pass = $pass; + $this->_port = $port; + } + + /* Public Methods + -------------------------------*/ + /** + * Returns the alter query builder + * + * @return Eden_Sql_Alter + */ + public function alter($name = NULL) { + //Argument 1 must be a string or null + Eden_Postgre_Error::i()->argument(1, 'string', 'null'); + + return Eden_Postgre_Alter::i($name); + } + + /** + * Connects to the database + * + * @param array the connection options + * @return this + */ + public function connect(array $options = array()) { + $host = $port = NULL; + + if(!is_null($this->_host)) { + $host = 'host='.$this->_host.';'; + if(!is_null($this->_port)) { + $port = 'port='.$this->_port.';'; + } + } + + $connection = 'pgsql:'.$host.$port.'dbname='.$this->_name; + + $this->_connection = new PDO($connection, $this->_user, $this->_pass, $options); + + $this->trigger(); + + return $this; + } + + /** + * Returns the create query builder + * + * @return Eden_Sql_Create + */ + public function create($name = NULL) { + //Argument 1 must be a string or null + Eden_Postgre_Error::i()->argument(1, 'string', 'null'); + + return Eden_Postgre_Create::i($name); + } + + /** + * Returns the delete query builder + * + * @return Eden_Sql_Delete + */ + public function delete($table = NULL) { + //Argument 1 must be a string or null + Eden_Postgre_Error::i()->argument(1, 'string', 'null'); + + return Eden_Postgre_Delete::i($table); + } + + /** + * Query for showing all columns of a table + * + * @param string the name of the table + * @return this + */ + public function getColumns($table, $schema = NULL) { + //Argument 1 must be a string + Eden_Postgre_Error::i()->argument(1, 'string')->argument(2, 'string', 'null'); + + $select = array( + 'columns.table_schema', + 'columns.column_name', + 'columns.ordinal_position', + 'columns.column_default', + 'columns.is_nullable', + 'columns.data_type', + 'columns.character_maximum_length', + 'columns.character_octet_length', + 'pg_class2.relname AS index_type'); + + $where = array( + "pg_attribute.attrelid = pg_class1.oid AND pg_class1.relname='".$table."'", + 'columns.column_name = pg_attribute.attname AND columns.table_name=pg_class1.relname', + 'pg_class1.oid = pg_index.indrelid AND pg_attribute.attnum = ANY(pg_index.indkey)', + 'pg_class2.oid = pg_index.indexrelid'); + + if($schema) { + $where[1] .= ' AND columns.table_schema="'.$schema.'"'; + } + + $query = Eden_Postgre_Select::i() + ->select($select) + ->from('pg_attribute') + ->innerJoin('pg_class AS pg_class1', $where[0], false) + ->innerJoin('information_schema.COLUMNS AS columns', $where[1], false) + ->leftJoin('pg_index', $where[2], false) + ->leftJoin('pg_class AS pg_class2', $where[3], false) + ->getQuery(); + + $results = $this->query($query); + + $columns = array(); + foreach($results as $column) { + $key = NULL; + if(strpos($column['index_type'], '_pkey') !== false) { + $key = 'PRI'; + } else if(strpos($column['index_type'], '_key') !== false) { + $key = 'UNI'; + } + + $columns[] = array( + 'Field' => $column['column_name'], + 'Type' => $column['data_type'], + 'Default' => $column['column_default'], + 'Null' => $column['is_nullable'], + 'Key' => $key); + } + + return $columns; + } + + /** + * Query for showing all columns of a table + * + * @param string the name of the table + * @return this + */ + public function getIndexes($table, $schema = NULL) { + //Argument 1 must be a string + Eden_Postgre_Error::i()->argument(1, 'string')->argument(2, 'string', 'null'); + + $select = array('columns.column_name', + 'pg_class2.relname AS index_type'); + + $where = array( + "pg_attribute.attrelid = pg_class1.oid AND pg_class1.relname='".$table."'", + 'columns.column_name = pg_attribute.attname AND columns.table_name=pg_class1.relname', + 'pg_class1.oid = pg_index.indrelid AND pg_attribute.attnum = ANY(pg_index.indkey)', + 'pg_class2.oid = pg_index.indexrelid'); + + if($schema) { + $where[1] .= ' AND columns.table_schema="'.$schema.'"'; + } + + $query = Eden_Postgre_Select::i() + ->select($select) + ->from('pg_attribute') + ->innerJoin('pg_class AS pg_class1', $where[0], false) + ->innerJoin('information_schema.COLUMNS AS columns', $where[1], false) + ->innerJoin('pg_index', $where[2], false) + ->innerJoin('pg_class AS pg_class2', $where[3], false) + ->getQuery(); + + return $this->query($query); + } + + /** + * Query for showing all columns of a table + * + * @param string the name of the table + * @return this + */ + public function getPrimary($table, $schema = NULL) { + //Argument 1 must be a string + Eden_Postgre_Error::i()->argument(1, 'string')->argument(2, 'string', 'null'); + + $select = array('columns.column_name'); + + $where = array( + "pg_attribute.attrelid = pg_class1.oid AND pg_class1.relname='".$table."'", + 'columns.column_name = pg_attribute.attname AND columns.table_name=pg_class1.relname', + 'pg_class1.oid = pg_index.indrelid AND pg_attribute.attnum = ANY(pg_index.indkey)', + 'pg_class2.oid = pg_index.indexrelid'); + + if($schema) { + $where[1] .= ' AND columns.table_schema="'.$schema.'"'; + } + + $query = Eden_Postgre_Select::i() + ->select($select) + ->from('pg_attribute') + ->innerJoin('pg_class AS pg_class1', $where[0], false) + ->innerJoin('information_schema.COLUMNS AS columns', $where[1], false) + ->innerJoin('pg_index', $where[2], false) + ->innerJoin('pg_class AS pg_class2', $where[3], false) + ->where('pg_class2.relname LIKE \'%_pkey\'') + ->getQuery(); + + return $this->query($query); + } + + /** + * Returns a listing of tables in the DB + * + * @return attay|false + */ + public function getTables() { + $query = Eden_Postgre_Select::i() + ->select('tablename') + ->from('pg_tables') + ->where("tablename NOT LIKE 'pg\\_%'") + ->where("tablename NOT LIKE 'sql\\_%'") + ->getQuery(); + + return $this->query($query); + } + + /** + * Returns the insert query builder + * + * @return Eden_Sql_Insert + */ + public function insert($table = NULL) { + //Argument 1 must be a string or null + Eden_Postgre_Error::i()->argument(1, 'string', 'null'); + + return Eden_Postgre_Insert::i($table); + } + + /** + * Returns the select query builder + * + * @return Eden_Sql_Select + */ + public function select($select = '*') { + //Argument 1 must be a string or array + Eden_Postgre_Error::i()->argument(1, 'string', 'array'); + + return Eden_Postgre_Select::i($select); + } + + /** + * Set schema search paths + * + * @string + */ + public function setSchema($schema) { + $schema = array($schema); + if(func_num_args() > 0) { + $schema = func_get_args(); + } + + $error = Eden_Postgre_Error::i(); + foreach($schema as $i => $name) { + $error->argument($i + 1, 'string'); + } + + $schema = implode(',', $schema); + + $query = $this->utility()->setSchema($schema); + $this->query($query); + + return $this; + } + + /** + * Returns the update query builder + * + * @return Eden_Sql_Update + */ + public function update($table = NULL) { + //Argument 1 must be a string or null + Eden_Postgre_Error::i()->argument(1, 'string', 'null'); + + return Eden_Postgre_Update::i($table); + } + + /** + * Returns the alter query builder + * + * @return Eden_Sql_Utility + */ + public function utility() { + return Eden_Postgre_Utility::i(); + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} + diff --git a/library/eden/postgre/alter.php b/library/eden/postgre/alter.php new file mode 100644 index 0000000..a7b6544 --- /dev/null +++ b/library/eden/postgre/alter.php @@ -0,0 +1,247 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Generates alter query string syntax + * + * @package Eden + * @category sql + * @author Christian Blanquera cblanquera@openovate.com + */ +class Eden_Postgre_Alter extends Eden_Sql_Query { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_name = NULL; + protected $_changeFields = array(); + protected $_addFields = array(); + protected $_removeFields = array(); + protected $_addPrimaryKeys = array(); + protected $_removePrimaryKeys = array(); + + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + public function __construct($name = NULL) { + if(is_string($name)) { + $this->setName($name); + } + } + + /* Public Methods + -------------------------------*/ + /** + * Adds a field in the table + * + * @param string name + * @param array attributes + * @return this + */ + public function addField($name, array $attributes) { + //Argument 1 must be a string + Eden_Mysql_Error::i()->argument(1, 'string'); + + $this->_addFields[$name] = $attributes; + return $this; + } + + /** + * Adds a primary key + * + * @param string name + * @return this + */ + public function addPrimaryKey($name) { + //Argument 1 must be a string + Eden_Mysql_Error::i()->argument(1, 'string'); + + $this->_addPrimaryKeys[] = '"'.$name.'"'; + return $this; + } + + /** + * Changes attributes of the table given + * the field name + * + * @param string name + * @param array attributes + * @return this + */ + public function changeField($name, array $attributes) { + //Argument 1 must be a string + Eden_Mysql_Error::i()->argument(1, 'string'); + + $this->_changeFields[$name] = $attributes; + return $this; + } + + /** + * Returns the string version of the query + * + * @param bool + * @return string + * @notes returns the query based on the registry + */ + public function getQuery($unbind = false) { + $fields = array(); + $table = '"'.$this->_name.'""'; + + foreach($this->_removeFields as $name) { + $fields[] = 'DROP COLUMN "'.$name.'"'; + } + + foreach($this->_addFields as $name => $attr) { + $field = array('ADD "'.$name.'"'); + if(isset($attr['type'])) { + $field[] = isset($attr['length']) ? $attr['type'] . '('.$attr['length'].')' : $attr['type']; + if(isset($attr['list']) && $attr['list']) { + $field[count($field)-1].='[]'; + } + } + + if(isset($attr['attribute'])) { + $field[] = $attr['attribute']; + } + + if(isset($attr['unique']) && $attr['unique']) { + $field[] = 'UNIQUE'; + } + + if(isset($attr['null'])) { + if($attr['null'] == false) { + $field[] = 'NOT NULL'; + } else { + $field[] = 'DEFAULT NULL'; + } + } + + if(isset($attr['default'])&& $attr['default'] !== false) { + if(!isset($attr['null']) || $attr['null'] == false) { + if(is_string($attr['default'])) { + $field[] = 'DEFAULT \''.$attr['default'] . '\''; + } else if(is_numeric($attr['default'])) { + $field[] = 'DEFAULT '.$attr['default']; + } + } + } + + $fields[] = implode(' ', $field); + } + + foreach($this->_changeFields as $name => $attr) { + $field = array('ALTER COLUMN "'.$name.'"'); + + if(isset($attr['name'])) { + $field = array('CHANGE "'.$name.'" "'.$attr['name'].'"'); + } + + if(isset($attr['type'])) { + $field[] = isset($attr['length']) ? $attr['type'] . '('.$attr['length'].')' : $attr['type']; + if(isset($attr['list']) && $attr['list']) { + $field[count($field)-1].='[]'; + } + } + + if(isset($attr['attribute'])) { + $field[] = $attr['attribute']; + } + + if(isset($attr['unique']) && $attr['unique']) { + $field[] = 'UNIQUE'; + } + + if(isset($attr['null'])) { + if($attr['null'] == false) { + $field[] = 'NOT NULL'; + } else { + $field[] = 'DEFAULT NULL'; + } + } + + if(isset($attr['default'])&& $attr['default'] !== false) { + if(!isset($attr['null']) || $attr['null'] == false) { + if(is_string($attr['default'])) { + $field[] = 'DEFAULT \''.$attr['default'] . '\''; + } else if(is_numeric($attr['default'])) { + $field[] = 'DEFAULT '.$attr['default']; + } + } + } + + $fields[] = implode(' ', $field); + } + + foreach($this->_removePrimaryKeys as $key) { + $fields[] = 'DROP PRIMARY KEY "'.$key.'"'; + } + + if(!empty($this->_addPrimaryKeys)) { + $fields[] = 'ADD PRIMARY KEY ('.implode(', ', $this->_addPrimaryKeys).')'; + } + + $fields = implode(", \n", $fields); + + return sprintf('ALTER TABLE %s %s;', $table, $fields); + } + + /** + * Removes a field + * + * @param string name + * @return this + */ + public function removeField($name) { + //Argument 1 must be a string + Eden_Mysql_Error::i()->argument(1, 'string'); + + $this->_removeFields[] = $name; + return $this; + } + + /** + * Removes a primary key + * + * @param string name + * @return this + */ + public function removePrimaryKey($name) { + //Argument 1 must be a string + Eden_Mysql_Error::i()->argument(1, 'string'); + + $this->_removePrimaryKeys[] = $name; + return $this; + } + + /** + * Sets the name of the table you wish to create + * + * @param string name + * @return this + */ + public function setName($name) { + //Argument 1 must be a string + Eden_Mysql_Error::i()->argument(1, 'string'); + + $this->_name = $name; + return $this; + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/postgre/create.php b/library/eden/postgre/create.php new file mode 100644 index 0000000..17e2765 --- /dev/null +++ b/library/eden/postgre/create.php @@ -0,0 +1,177 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Generates create table query string syntax + * + * @package Eden + * @category sql + * @author Christian Blanquera cblanquera@openovate.com + */ +class Eden_Postgre_Create extends Eden_Sql_Query { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_name = NULL; + protected $_fields = array(); + protected $_primaryKeys = array(); + protected $_oids = false; + + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + public function __construct($name = NULL) { + if(is_string($name)) { + $this->setName($name); + } + } + + /* Public Methods + -------------------------------*/ + /** + * Adds a field in the table + * + * @param string name + * @param array attributes + * @return this + */ + public function addField($name, array $attributes) { + //Argument 1 must be a string + Eden_Mysql_Error::i()->argument(1, 'string'); + + $this->_fields[$name] = $attributes; + return $this; + } + + /** + * Adds a primary key + * + * @param string name + * @return this + */ + public function addPrimaryKey($name) { + //Argument 1 must be a string + Eden_Mysql_Error::i()->argument(1, 'string'); + + $this->_primaryKeys[] = $name; + return $this; + } + + /** + * Returns the string version of the query + * + * @param bool + * @return string + * @notes returns the query based on the registry + */ + public function getQuery($unbind = false) { + $table = '"'.$this->_name.'"'; + + $fields = array(); + foreach($this->_fields as $name => $attr) { + $field = array('"'.$name.'"'); + if(isset($attr['type'])) { + $field[] = isset($attr['length']) ? $attr['type'] . '('.$attr['length'].')' : $attr['type']; + if(isset($attr['list']) && $attr['list']) { + $field[count($field)-1].='[]'; + } + } + + if(isset($attr['attribute'])) { + $field[] = $attr['attribute']; + } + + if(isset($attr['unique']) && $attr['unique']) { + $field[] = 'UNIQUE'; + } + + if(isset($attr['null'])) { + if($attr['null'] == false) { + $field[] = 'NOT NULL'; + } else { + $field[] = 'DEFAULT NULL'; + } + } + + if(isset($attr['default'])&& $attr['default'] !== false) { + if(!isset($attr['null']) || $attr['null'] == false) { + if(is_string($attr['default'])) { + $field[] = 'DEFAULT \''.$attr['default'] . '\''; + } else if(is_numeric($attr['default'])) { + $field[] = 'DEFAULT '.$attr['default']; + } + } + } + + $fields[] = implode(' ', $field); + } + + $oids = $this->_oids ? 'WITH OIDS':NULL; + $fields = !empty($fields) ? implode(', ', $fields) : ''; + $primary = !empty($this->_primaryKeys) ? ', PRIMARY KEY ("'.implode('", ""', $this->_primaryKeys).'")' : ''; + return sprintf('CREATE TABLE %s (%s%s) %s', $table, $fields, $primary, $oids); + } + + /** + * Sets a list of fields to the table + * + * @param array fields + * @return this + */ + public function setFields(array $fields) { + $this->_fields = $fields; + return $this; + } + + /** + * Sets the name of the table you wish to create + * + * @param string name + * @return this + */ + public function setName($name) { + //Argument 1 must be a string + Eden_Mysql_Error::i()->argument(1, 'string'); + + $this->_name = $name; + return $this; + } + + /** + * Sets a list of primary keys to the table + * + * @param array primaryKeys + * @return this + */ + public function setPrimaryKeys(array $primaryKeys) { + $this->_primaryKeys = $primaryKeys; + return $this; + } + + public function withOids($oids) { + //Argument 1 must be a boolean + Eden_Mysql_Error::i()->argument(1, 'bool'); + + $this->_oids = $oids; + return $this; + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/postgre/delete.php b/library/eden/postgre/delete.php new file mode 100644 index 0000000..88ec2b6 --- /dev/null +++ b/library/eden/postgre/delete.php @@ -0,0 +1,57 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Generates delete query string syntax + * + * @package Eden + * @category sql + * @author Christian Blanquera cblanquera@openovate.com + */ +class Eden_Postgre_Delete extends Eden_Sql_Delete { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_table = NULL; + protected $_where = array(); + + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + public function __construct($table = NULL) { + if(is_string($table)) { + $this->setTable($table); + } + } + + /* Public Methods + -------------------------------*/ + /** + * Returns the string version of the query + * + * @return string + * @notes returns the query based on the registry + */ + public function getQuery() { + return 'DELETE FROM "'. $this->_table . '" WHERE '. implode(' AND ', $this->_where).';'; + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/postgre/error.php b/library/eden/postgre/error.php new file mode 100644 index 0000000..3d9f016 --- /dev/null +++ b/library/eden/postgre/error.php @@ -0,0 +1,39 @@ + +/* + * This file is part of the Eden package. + * (c) 2010-2012 Christian Blanquera + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Postgre Errors + * + * @package Eden + * @category sql + * @author Christian Blanquera cblanquera@openovate.com + */ +class Eden_Postgre_Error extends Eden_Sql_Error { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i($message = NULL, $code = 0) { + $class = __CLASS__; + return new $class($message, $code); + } + + /* Public Methods + -------------------------------*/ + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/postgre/insert.php b/library/eden/postgre/insert.php new file mode 100644 index 0000000..13f5463 --- /dev/null +++ b/library/eden/postgre/insert.php @@ -0,0 +1,83 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Generates insert query string syntax + * + * @package Eden + * @category sql + * @author Christian Blanquera cblanquera@openovate.com + */ +class Eden_Postgre_Insert extends Eden_Sql_Insert { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + /* Public Methods + -------------------------------*/ + /** + * Returns the string version of the query + * + * @param bool + * @return string + * @notes returns the query based on the registry + */ + public function getQuery() { + $multiValList = array(); + foreach($this->_setVal as $val) { + $multiValList[] = '('.implode(', ', $val).')'; + } + + return 'INSERT INTO "'. $this->_table . '" ("'.implode('", "', $this->_setKey).'") VALUES '.implode(", \n", $multiValList).';'; + } + + /** + * Set clause that assigns a given field name to a given value. + * You can also use this to add multiple rows in one call + * + * @param string + * @param string + * @return this + * @notes loads a set into registry + */ + public function set($key, $value, $index = 0) { + //argument test + Eden_Sql_Error::i() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'scalar', 'null'); //Argument 2 must be scalar or null + + if(!in_array($key, $this->_setKey)) { + $this->_setKey[] = $key; + } + + if(is_null($value)) { + $value = 'NULL'; + } else if(is_bool($value)) { + $value = $value ? 'TRUE' : 'FALSE'; + } + + $this->_setVal[$index][] = $value; + return $this; + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} diff --git a/library/eden/postgre/select.php b/library/eden/postgre/select.php new file mode 100644 index 0000000..cc9409f --- /dev/null +++ b/library/eden/postgre/select.php @@ -0,0 +1,60 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Generates select query string syntax + * + * @package Eden + * @category sql + * @author Christian Blanquera cblanquera@openovate.com + */ +class Eden_Postgre_Select extends Eden_Sql_Select { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + /* Public Methods + -------------------------------*/ + /** + * Returns the string version of the query + * + * @param bool + * @return string + * @notes returns the query based on the registry + */ + public function getQuery() { + $joins = empty($this->_joins) ? '' : implode(' ', $this->_joins); + $where = empty($this->_where) ? '' : 'WHERE '.implode(' AND ', $this->_where); + $sort = empty($this->_sortBy) ? '' : 'ORDER BY '.implode(', ', $this->_sortBy); + $limit = is_null($this->_page) ? '' : 'LIMIT ' . $this->_page .' OFFSET ' .$this->_length; + $group = empty($this->_group) ? '' : 'GROUP BY ' . implode(', ', $this->_group); + + $query = sprintf( + 'SELECT %s FROM %s %s %s %s %s %s;', + $this->_select, $this->_from, $joins, + $where, $group, $sort, $limit); + + return str_replace(' ', ' ', $query); + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/postgre/update.php b/library/eden/postgre/update.php new file mode 100644 index 0000000..88bb990 --- /dev/null +++ b/library/eden/postgre/update.php @@ -0,0 +1,82 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Generates update query string syntax + * + * @package Eden + * @category sql + * @author Christian Blanquera cblanquera@openovate.com + */ +class Eden_Postgre_Update extends Eden_Postgre_Delete { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_set = array(); + + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + /* Public Methods + -------------------------------*/ + /** + * Returns the string version of the query + * + * @param bool + * @return string + * @notes returns the query based on the registry + */ + public function getQuery() { + + $set = array(); + foreach($this->_set as $key => $value) { + $set[] = '"'.$key.'" = '.$value; + } + + return 'UPDATE '. $this->_table . ' SET ' . implode(', ', $set) . ' WHERE '. implode(' AND ', $this->_where).';'; + } + + /** + * Set clause that assigns a given field name to a given value. + * + * @param string + * @param string + * @return this + * @notes loads a set into registry + */ + public function set($key, $value) { + //argument test + Eden_Sql_Error::i() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'scalar', 'null'); //Argument 2 must be scalar or null + + if(is_null($value)) { + $value = 'NULL'; + } else if(is_bool($value)) { + $value = $value ? 'TRUE' : 'FALSE'; + } + + $this->_set[$key] = $value; + + return $this; + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/postgre/utility.php b/library/eden/postgre/utility.php new file mode 100644 index 0000000..3d0d868 --- /dev/null +++ b/library/eden/postgre/utility.php @@ -0,0 +1,100 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Generates utility query strings + * + * @package Eden + * @category sql + * @author Christian Blanquera cblanquera@openovate.com + */ +class Eden_Postgre_Utility extends Eden_Sql_Query +{ + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_query = NULL; + + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + /* Public Methods + -------------------------------*/ + /** + * Query for dropping a table + * + * @param string the name of the table + * @return this + */ + public function dropTable($table) { + //Argument 1 must be a string + Eden_Postgre_Error::i()->argument(1, 'string'); + + $this->_query = 'DROP TABLE "' . $table .'"'; + return $this; + } + + /** + * Returns the string version of the query + * + * @return string + */ + public function getQuery() { + return $this->_query.';'; + } + + /** + * Query for renaming a table + * + * @param string the name of the table + * @param string the new name of the table + * @return this + */ + public function renameTable($table, $name) { + //Argument 1 must be a string, 2 must be string + Eden_Postgre_Error::i()->argument(1, 'string')->argument(2, 'string'); + + $this->_query = 'RENAME TABLE "' . $table . '" TO "' . $name . '"'; + return $this; + } + + public function setSchema($schema) { + $this->_query = 'SET search_path TO '.$schema; + return $this; + } + + /** + * Query for truncating a table + * + * @param string the name of the table + * @return this + */ + public function truncate($table) { + //Argument 1 must be a string + Eden_Postgre_Error::i()->argument(1, 'string'); + + $this->_query = 'TRUNCATE "' . $table .'"'; + return $this; + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/registry.php b/library/eden/registry.php new file mode 100755 index 0000000..9efabc5 --- /dev/null +++ b/library/eden/registry.php @@ -0,0 +1,238 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +require_once dirname(__FILE__).'/type.php'; + +/** + * This class allows the reference of a global registry. This + * is a better registry in memory design. What makes this + * registry truly unique is that it uses a pathing design + * similar to a file/folder structure to organize data which also + * in turn allows you to get a data set based on similar + * pathing. + * + * @package Eden + * @category registry + * @author Christian Blanquera cblanquera@openovate.com + */ +class Eden_Registry extends Eden_Type_Array { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + public function __construct($data = array()) { + //if there is more arguments or data is not an array + if(func_num_args() > 1 || !is_array($data)) { + //just get the args + $data = func_get_args(); + } + + foreach($data as $key => $value) { + if(!is_array($value)) { + continue; + } + + $class = get_class($this); + + $data[$key] = $this->$class($value); + } + + parent::__construct($data); + } + + public function __toString() { + return json_encode($this->getArray()); + } + + /* Public Methods + -------------------------------*/ + /** + * Gets a value given the path in the registry. + * + * @return mixed + */ + public function get($modified = true) { + $args = func_get_args(); + + if(count($args) == 0) { + return $this; + } + + $key = array_shift($args); + + if($key === false) { + if(count($args) == 0) { + return $this->getArray(); + } + + $modified = $key; + $key = array_shift($args); + array_unshift($args, $modified); + } + + if(!isset($this->_data[$key])) { + return NULL; + } + + if(count($args) == 0) { + return $this->_data[$key]; + } + + if($this->_data[$key] instanceof Eden_Registry) { + return call_user_func_array(array($this->_data[$key], __FUNCTION__), $args); + } + + return NULL; + } + + /** + * Returns the raw array recursively + * + * @return array + */ + public function getArray($modified = true) { + $array = array(); + foreach($this->_data as $key => $data) { + if($data instanceof Eden_Registry) { + $array[$key] = $data->getArray($modified); + continue; + } + + $array[$key] = $data; + } + + return $array; + } + + /** + * Checks to see if a key is set + * + * @return bool + */ + public function isKey() { + $args = func_get_args(); + + if(count($args) == 0) { + return $this; + } + + $key = array_shift($args); + + if(!isset($this->_data[$key])) { + return false; + } + + if(count($args) == 0) { + return true; + } + + if($this->_data[$key] instanceof Eden_Registry) { + return call_user_func_array(array($this->_data[$key], __FUNCTION__), $args); + } + + return false; + } + + /** + * returns data using the ArrayAccess interface + * + * @param number + * @return bool + */ + public function offsetGet($offset) { + if(!isset($this->_data[$offset])) { + return NULL; + } + + if($this->_data[$offset] instanceof Eden_Registry) { + return $this->_data[$offset]->getArray(); + } + + return $this->_data[$offset]; + } + + /** + * Removes a key and everything associated with it + * + * @return Eden_Registry + */ + public function remove() { + $args = func_get_args(); + + if(count($args) == 0) { + return $this; + } + + $key = array_shift($args); + + if(!isset($this->_data[$key])) { + return $this; + } + + if(count($args) == 0) { + unset($this->_data[$key]); + return $this; + } + + if($this->_data[$key] instanceof Eden_Registry) { + return call_user_func_array(array($this->_data[$key], __FUNCTION__), $args); + } + + return $this; + } + + /** + * Creates the name space given the space + * and sets the value to that name space + * + * @return Eden_Registry + */ + public function set($value) { + $args = func_get_args(); + + if(count($args) < 2) { + return $this; + } + + $key = array_shift($args); + + if(count($args) == 1) { + if(is_array($args[0])) { + $args[0] = self::i($args[0]); + } + + $this->_data[$key] = $args[0]; + + return $this; + } + + if(!isset($this->_data[$key]) || !($this->_data[$key] instanceof Eden_Registry)) { + $this->_data[$key] = self::i(); + } + + call_user_func_array(array($this->_data[$key], __FUNCTION__), $args); + + return $this; + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/route.php b/library/eden/route.php new file mode 100755 index 0000000..d53bbeb --- /dev/null +++ b/library/eden/route.php @@ -0,0 +1,86 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +require_once dirname(__FILE__).'/class.php'; +require_once dirname(__FILE__).'/route/error.php'; +require_once dirname(__FILE__).'/route/class.php'; +require_once dirname(__FILE__).'/route/method.php'; +require_once dirname(__FILE__).'/route/function.php'; + +/** + * Definition for overloading methods and overriding classes. + * This class also provides methods to list out various routes + * and has the ability to call methods, static methods and + * functions passing arguments as an array. + * + * @package Eden + * @category core + * @author Christian Blanquera cblanquera@openovate.com + */ +class Eden_Route extends Eden_Class { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected static $_instance = NULL; + + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function i() { + $class = __CLASS__; + if(is_null(self::$_instance)) { + self::$_instance = new $class(); + } + + return self::$_instance; + } + + /* Magic + -------------------------------*/ + /* Public Methods + -------------------------------*/ + public function getClass($class = NULL, array $args = array()) { + $route = Eden_Route_Class::i(); + + if(is_null($class)) { + return $route; + } + + return $route->callArray($class, $args); + } + + public function getFunction($function = NULL, array $args = array()) { + $route = Eden_Route_Function::i(); + + if(is_null($function)) { + return $route; + } + + return $route->callArray($function, $args); + } + + public function getMethod($class = NULL, $method = NULL, array $args = array()) { + $route = Eden_Route_Method::i(); + + if(is_null($class) || is_null($method)) { + return $route; + } + + return $route->call($class, $method, $args); + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/route/class.php b/library/eden/route/class.php new file mode 100644 index 0000000..76a81a6 --- /dev/null +++ b/library/eden/route/class.php @@ -0,0 +1,172 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Definition for overriding classes. + * This class also provides methods to list out various routes + * + * @package Eden + * @category core + * @author Christian Blanquera cblanquera@openovate.com + */ +class Eden_Route_Class extends Eden_Class { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected static $_instance = NULL; + protected $_route = array(); //class registry + + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function i() { + $class = __CLASS__; + if(is_null(self::$_instance)) { + self::$_instance = new $class(); + } + + return self::$_instance; + } + + /* Magic + -------------------------------*/ + /* Public Methods + -------------------------------*/ + /** + * Calls a class considering all routes. + * + * @param *string class + * @param [variable..] arguments + * @return object + */ + public function call($class) { + //argument 1 must be a string + Eden_Route_Error::i()->argument(1, 'string'); + + $args = func_get_args(); + $class = array_shift($args); + + return $this->callArray($class, $args); + } + + /** + * Calls a class considering all routes. + * + * @param *string class + * @param array arguments + * @return object + */ + public function callArray($class, array $args = array()) { + //argument 1 must be a string + Eden_Route_Error::i()->argument(1, 'string'); + + $route = $this->getRoute($class); + + if(is_object($route)) { + return $route; + } + + $reflect = new ReflectionClass($route); + + if(method_exists($route, 'i')) { + $declared = $reflect + ->getMethod('i') + ->getDeclaringClass() + ->getName(); + + return Eden_Route_Method::i()->callStatic($class, 'i', $args); + } + + return $reflect->newInstanceArgs($args); + } + + /** + * Returns the class that will be routed to given the route. + * + * @param *string the class route name + * @param string|null returns this variable if no route is found + * @return string|variable + */ + public function getRoute($route) { + //argument 1 must be a string + Eden_Route_Error::i()->argument(1, 'string'); + + if($this->isRoute($route)) { + return $this->_route[strtolower($route)]; + } + + return $route; + } + + /** + * Returns all class routes + * + * @return array + */ + public function getRoutes() { + return $this->_route; + } + + /** + * Checks to see if a name is a route + * + * @param string + * @return bool + */ + public function isRoute($route) { + return isset($this->_route[strtolower($route)]); + } + + /** + * Unsets the route + * + * @param *string the class route name + * @return string|variable + */ + public function release($route) { + if($this->isRoute($route)) { + unset($this->_route[strtolower($route)]); + } + + return $this; + } + + /** + * Routes a class + * + * @param *string the class route name + * @param *string the name of the class to route to + * @return Eden_Route + */ + public function route($route, $class) { + Eden_Route_Error::i() + ->argument(1, 'string', 'object') //argument 1 must be a string or object + ->argument(2, 'string', 'object'); //argument 2 must be a string or object + + if(is_object($route)) { + $route = get_class($route); + } + + if(is_string($class)) { + $class = $this->getRoute($class); + } + + $this->_route[strtolower($route)] = $class; + return $this; + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/route/error.php b/library/eden/route/error.php new file mode 100644 index 0000000..33341c2 --- /dev/null +++ b/library/eden/route/error.php @@ -0,0 +1,32 @@ + +/** + * Route Errors + */ +class Eden_Route_Error extends Eden_Error { + /* Constants + -------------------------------*/ + const CLASS_NOT_EXISTS = 'Invalid class call: %s->%s(). Class does not exist.'; + const METHOD_NOT_EXISTS = 'Invalid class call: %s->%s(). Method does not exist.'; + const STATIC_ERROR = 'Invalid class call: %s::%s().'; + const FUNCTION_ERROR = 'Invalid function run: %s().'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i($message = NULL, $code = 0) { + $class = __CLASS__; + return new $class($message, $code); + } + + /* Public Methods + -------------------------------*/ + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/route/function.php b/library/eden/route/function.php new file mode 100644 index 0000000..92d54a9 --- /dev/null +++ b/library/eden/route/function.php @@ -0,0 +1,152 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Definition for overriding classes. + * This class also provides methods to list out various routes + * + * @package Eden + * @category core + * @author Christian Blanquera cblanquera@openovate.com + */ +class Eden_Route_Function extends Eden_Class { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected static $_instance = NULL; + protected $_route = array(); //class registry + + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function i() { + $class = __CLASS__; + if(is_null(self::$_instance)) { + self::$_instance = new $class(); + } + + return self::$_instance; + } + + /* Magic + -------------------------------*/ + /* Public Methods + -------------------------------*/ + /** + * Calls a function considering all routes. + * + * @param *string class + * @param [variable..] arguments + * @return object + */ + public function call($function) { + //argument 1 must be a string + Eden_Route_Error::i()->argument(1, 'string'); + + $args = func_get_args(); + $function = array_shift($args); + + return $this->callArray($function, $args); + } + + /** + * Calls a function considering all routes. + * + * @param *string class + * @param array arguments + * @return object + */ + public function callArray($function, array $args = array()) { + //argument 1 must be a string + Eden_Route_Error::i()->argument(1, 'string'); + + $function = $this->getRoute($function); + + //try to run the function using PHP call_user_func_array + return call_user_func_array($function, $args); + } + + /** + * Returns the class that will be routed to given the route. + * + * @param *string the class route name + * @param string|null returns this variable if no route is found + * @return string|variable + */ + public function getRoute($route) { + //argument 1 must be a string + Eden_Route_Error::i()->argument(1, 'string'); + + if($this->isRoute($route)) { + return $this->_route[strtolower($route)]; + } + + return $route; + } + + /** + * Returns all class routes + * + * @return array + */ + public function getRoutes() { + return $this->_route; + } + + /** + * Checks to see if a name is a route + * + * @param string + * @return bool + */ + public function isRoute($route) { + return isset($this->_route[strtolower($route)]); + } + + /** + * Unsets the route + * + * @param *string the class route name + * @return string|variable + */ + public function release($route) { + if($this->isRoute($route)) { + unset($this->_route[strtolower($route)]); + } + + return $this; + } + + /** + * Routes a class + * + * @param *string the class route name + * @param *string the name of the class to route to + * @return Eden_Route + */ + public function route($route, $function) { + Eden_Route_Error::i() + ->argument(1, 'string') //argument 1 must be a string + ->argument(2, 'string'); //argument 2 must be a string + + $function = $this->getRoute($function); + + $this->_route[strtolower($route)] = $function; + return $this; + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/route/method.php b/library/eden/route/method.php new file mode 100644 index 0000000..f3004d7 --- /dev/null +++ b/library/eden/route/method.php @@ -0,0 +1,266 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Definition for overloading methods. + * This class also provides methods to list out various routes + * and has the ability to call methods, static methods and + * functions passing arguments as an array. + * + * @package Eden + * @category core + * @author Christian Blanquera cblanquera@openovate.com + */ +class Eden_Route_Method extends Eden_Class { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected static $_instance = NULL; + protected $_route = array(); //method registry + + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function i() { + $class = __CLASS__; + if(is_null(self::$_instance)) { + self::$_instance = new $class(); + } + + return self::$_instance; + } + + /* Magic + -------------------------------*/ + /* Public Methods + -------------------------------*/ + /** + * Calls a method considering all routes + * + * @param *string|object the class name + * @param *string the method name + * @param array the arguments you want to pass into the method + * @return mixed + */ + public function call($class, $method, array $args = array()) { + //argument test + Eden_Route_Error::i() + ->argument(1, 'string', 'object') //argument 1 must be string or object + ->argument(2, 'string'); //argument 2 must be string + + $instance = NULL; + if(is_object($class)) { + $instance = $class; + $class = get_class($class); + } + + $classRoute = Eden_Route_Class::i(); + $isClassRoute = $classRoute->isRoute($class); + $isMethodRoute = $this->isRoute($class, $method); + + //method might be a route + //lets make sure we are dealing with the right method + //this also checks class as well + list($class, $method) = $this->getRoute($class, $method); + + //class does not exist + if(!is_object($class) && !class_exists($class)) { + //throw exception + Eden_Route_Error::i() + ->setMessage(Eden_Route_Error::CLASS_NOT_EXISTS) + ->addVariable($class) + ->addVariable($method) + ->trigger(); + } + + //method does not exist + if(!$isClassRoute && !$isMethodRoute && !method_exists($class, $method)) { + //throw exception + Eden_Route_Error::i() + ->setMessage(Eden_Route_Error::METHOD_NOT_EXISTS) + ->addVariable($class) + ->addVariable($method) + ->trigger(); + } + + //if there is a route or no instance + if($isClassRoute || !$instance) { + $instance = $classRoute->call($class); + } + + return call_user_func_array(array(&$instance, $method), $args); + } + + /** + * Calls a static method considering all routes + * + * @param *string|object the class name + * @param *string the method name + * @param array the arguments you want to pass into the method + * @return mixed + */ + public function callStatic($class, $method, array $args = array()) { + //argument test + Eden_Route_Error::i() + ->argument(1, 'string', 'object') //argument 1 must be string or object + ->argument(2, 'string'); //argument 2 must be string + + if(is_object($class)) { + $class = get_class($class); + } + + $isClassRoute = Eden_Route_Class::i()->isRoute($class); + $isMethodRoute = $this->isRoute($class, $method); + + //method might be a route + //lets make sure we are dealing with the right method + //this also checks class as well + list($class, $method) = $this->getRoute($class, $method); + + //class does not exist + if(!is_object($class) && !class_exists($class)) { + //throw exception + Eden_Route_Error::i() + ->setMessage(Eden_Route_Error::CLASS_NOT_EXISTS) + ->addVariable($class) + ->addVariable($method) + ->trigger(); + } + + //method does not exist + if(!$isClassRoute && !$isMethodRoute && !method_exists($class, $method)) { + //throw exception + Eden_Route_Error::i() + ->setMessage(Eden_Route_Error::METHOD_NOT_EXISTS) + ->addVariable($class) + ->addVariable($method) + ->trigger(); + } + + if(is_object($class)) { + $class = get_class($class); + } + + return call_user_func_array($class.'::'.$method, $args); // As of 5.2.3 + } + + /** + * Returns the class and method that will be routed to given the route. + * + * @param *string the class route name + * @param *string the class route method + * @param string|null returns this variable if no route is found + * @return array|variable + */ + public function getRoute($class, $method) { + Eden_Route_Error::i() + ->argument(1, 'string') //argument 1 must be a string + ->argument(2, 'string'); //argument 2 must be a string + + if($this->isRoute(NULL, $method)) { + return $this->_route[NULL][strtolower($method)]; + } + + $class = Eden_Route_Class::i()->getRoute($class); + + if($this->isRoute($class, $method)) { + return $this->_route[strtolower($class)][strtolower($method)]; + } + + return array($class, $method); + } + + /** + * Returns all method routes + * + * @return array + */ + public function getRoutes() { + return $this->_route; + } + + /** + * Checks to see if a name is a route + * + * @param string + * @param string + * @return bool + */ + public function isRoute($class, $method) { + if(is_string($class)) { + $class = strtolower($class); + } + + return isset($this->_route[$class][strtolower($method)]); + } + + /** + * Unsets the route + * + * @param *string the class route name + * @return string|variable + */ + public function release($class, $method) { + if($this->isRoute($class, $method)) { + unset($this->_route[strtolower($class)][strtolower($method)]); + } + + return $this; + } + + /** + * Routes a method. + * + * @param *string the class route name + * @param *string the method route name + * @param *string the name of the class to route to + * @param *string the name of the method to route to + * @return Eden_Route + */ + public function route($source, $alias, $class, $method = NULL) { + //argument test + Eden_Route_Error::i() + ->argument(1, 'string', 'object', 'null') //argument 1 must be a string, object or null + ->argument(2, 'string') //argument 2 must be a string + ->argument(3, 'string', 'object') //argument 3 must be a string or object + ->argument(4, 'string'); //argument 4 must be a string + + if(is_object($source)) { + $source = get_class($source); + } + + //if the method is not a string + if(!is_string($method)) { + $method = $alias; + } + + $route = Eden_Route_Class::i(); + if(!is_null($source)) { + $source = $route->getRoute($source); + $source = strtolower($source); + } + + if(is_string($class)) { + $class = $route->getRoute($class); + } + + $this->_route[$source][strtolower($alias)] = array($class, $method); + + return $this; + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/session.php b/library/eden/session.php new file mode 100755 index 0000000..9d2afb4 --- /dev/null +++ b/library/eden/session.php @@ -0,0 +1,342 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +require_once dirname(__FILE__).'/class.php'; + +/** + * General available methods for common + * server session procedures. + * + * @package Eden + * @category utility + * @author Christian Blanquera cblanquera@openovate.com + */ +class Eden_Session extends Eden_Class implements ArrayAccess, Iterator { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected static $_session = false; + + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getSingleton(__CLASS__); + } + + public function __toString() { + if(!self::$_session) { + return '[]'; + } + + return json_encode($_SESSION); + } + + /* Public Methods + -------------------------------*/ + /** + * Removes all session data + * + * @return bool + */ + public function clear() { + if(!self::$_session) { + Eden_Session_Error::i(Eden_Session_Error::ERROR_NOT_STARTED)->trigger(); + } + + $_SESSION = array(); + + return $this; + } + + /** + * Returns the current item + * For Iterator interface + * + * @return void + */ + public function current() { + if(!self::$_session) { + Eden_Session_Error::i(Eden_Session_Error::ERROR_NOT_STARTED)->trigger(); + } + + return current($_SESSION); + } + + /** + * Returns data + * + * @param string|null + * @return mixed + */ + public function get($key = NULL) { + $error = Eden_Session_Error::i()->argument(1, 'string', 'null'); + + if(!self::$_session) { + $error->setMessage(Eden_Session_Error::ERROR_ERROR_NOT_STARTED)->trigger(); + } + + if(is_null($key)) { + return $_SESSION; + } + + if(isset($_SESSION[$key])) { + return $_SESSION[$key]; + } + + return NULL; + } + + /** + * Returns session id + * + * @return int + */ + public function getId() { + if(!self::$_session) { + Eden_Session_Error::i(Eden_Session_Error::ERROR_NOT_STARTED)->trigger(); + } + + return session_id(); + } + + /** + * Returns th current position + * For Iterator interface + * + * @return void + */ + public function key() { + if(!self::$_session) { + Eden_Session_Error::i(Eden_Session_Error::ERROR_NOT_STARTED)->trigger(); + } + + return key($_SESSION); + } + + /** + * Increases the position + * For Iterator interface + * + * @return void + */ + public function next() { + if(!self::$_session) { + Eden_Session_Error::i(Eden_Session_Error::ERROR_NOT_STARTED)->trigger(); + } + + next($_SESSION); + } + + /** + * isset using the ArrayAccess interface + * + * @param number + * @return bool + */ + public function offsetExists($offset) { + if(!self::$_session) { + Eden_Session_Error::i(Eden_Session_Error::ERROR_NOT_STARTED)->trigger(); + } + + return isset($_SESSION[$offset]); + } + + /** + * returns data using the ArrayAccess interface + * + * @param number + * @return bool + */ + public function offsetGet($offset) { + if(!self::$_session) { + Eden_Session_Error::i(Eden_Session_Error::ERROR_NOT_STARTED)->trigger(); + } + + return isset($_SESSION[$offset]) ? $_SESSION[$offset] : NULL; + } + + /** + * Sets data using the ArrayAccess interface + * + * @param number + * @param mixed + * @return void + */ + public function offsetSet($offset, $value) { + if(!self::$_session) { + Eden_Session_Error::i(Eden_Session_Error::ERROR_NOT_STARTED)->trigger(); + } + + if (is_null($offset)) { + $_SESSION[] = $value; + } else { + $_SESSION[$offset] = $value; + } + } + + /** + * unsets using the ArrayAccess interface + * + * @param number + * @return bool + */ + public function offsetUnset($offset) { + if(!self::$_session) { + Eden_Session_Error::i(Eden_Session_Error::ERROR_NOT_STARTED)->trigger(); + } + + unset($_SESSION[$offset]); + } + + /** + * Removes a session. + * + * @param *string session name + * @return this + */ + public function remove($name) { + Eden_Session_Error::i()->argument(1, 'string'); + + if(isset($_SESSION[$name])) { + unset($_SESSION[$name]); + } + + return $this; + } + + /** + * Rewinds the position + * For Iterator interface + * + * @return void + */ + public function rewind() { + if(!self::$_session) { + Eden_Session_Error::i(Eden_Session_Error::ERROR_NOT_STARTED)->trigger(); + } + + reset($_SESSION); + } + + /** + * Sets data + * + * @param array|string + * @param mixed + * @return this + */ + public function set($data, $value = NULL) { + $error = Eden_Session_Error::i()->argument(1, 'array', 'string'); + + if(!self::$_session) { + $error->setMessage(Eden_Session_Error::ERROR_ERROR_NOT_STARTED)->trigger(); + } + + if(is_array($data)) { + $_SESSION = $data; + return $this; + } + + $_SESSION[$data] = $value; + + return $this; + } + + /** + * Sets the session ID + * + * @param *int + * @return int + */ + public function setId($sid) { + $error = Eden_Session_Error::i()->argument(1, 'numeric'); + + if(!self::$_session) { + $error->setMessage(Eden_Session_Error::ERROR_ERROR_NOT_STARTED)->trigger(); + } + + return session_id((int) $sid); + } + /** + * Starts a session + * + * @return bool + */ + public function start() { + if(!session_id()) { + self::$_session = session_start(); + } + + return $this; + } + + /** + * Starts a session + * + * @return Eden_SessionServer + */ + public function stop() { + self::$_session = false; + session_write_close(); + return $this; + } + + /** + * Validates whether if the index is set + * For Iterator interface + * + * @return void + */ + public function valid() { + if(!self::$_session) { + Eden_Session_Error::i(Eden_Session_Error::ERROR_NOT_STARTED)->trigger(); + } + + return isset($_SESSION[$this->key()]); + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} + +/** + * Session Errors + */ +class Eden_Session_Error extends Eden_Error { + /* Constants + -------------------------------*/ + const ERROR_NOT_STARTED = 'Session is not started. Try using Eden_Session->start() first.'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i($message = NULL, $code = 0) { + $class = __CLASS__; + return new $class($message, $code); + } + + /* Public Methods + -------------------------------*/ + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/sql/collection.php b/library/eden/sql/collection.php new file mode 100644 index 0000000..e905810 --- /dev/null +++ b/library/eden/sql/collection.php @@ -0,0 +1,137 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Sql Collection handler + * + * @package Eden + * @category sql + * @author Christian Blanquera cblanquera@openovate.com + */ +class Eden_Sql_Collection extends Eden_Collection { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_model = Eden_Sql_Database::MODEL; + protected $_database = NULL; + protected $_table = NULL; + + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + /* Public Methods + -------------------------------*/ + /** + * Adds a row to the collection + * + * @param array|Eden_Model + * @return this + */ + public function add($row = array()) { + //Argument 1 must be an array or Eden_Model + Eden_Sql_Error::i()->argument(1, 'array', $this->_model); + + //if it's an array + if(is_array($row)) { + //make it a model + $model = $this->_model; + $row = $this->$model($row); + } + + if(!is_null($this->_database)) { + $row->setDatabase($this->_database); + } + + if(!is_null($this->_table)) { + $row->setTable($this->_table); + } + + //add it now + $this->_list[] = $row; + + return $this; + } + + /** + * Sets the default database + * + * @param Eden_Sql + */ + public function setDatabase(Eden_Sql_Database $database) { + $this->_database = $database; + + //for each row + foreach($this->_list as $row) { + if(!is_object($row) || !method_exists($row, __FUNCTION__)) { + continue; + } + + //let the row handle this + $row->setDatabase($database); + } + + return $this; + } + + /** + * Sets default model + * + * @param string + * @return this + */ + public function setModel($model) { + $error = Eden_Sql_Error::i()->argument(1, 'string'); + + if(!is_subclass_of($model, 'Eden_Model')) { + $error->setMessage(Eden_Sql_Error::NOT_SUB_MODEL) + ->addVariable($model) + ->trigger(); + } + + $this->_model = $model; + return $this; + } + + /** + * Sets the default database + * + * @param string + */ + public function setTable($table) { + //Argument 1 must be a string + Eden_Sql_Error::i()->argument(1, 'string'); + + $this->_table = $table; + + //for each row + foreach($this->_list as $row) { + if(!is_object($row) || !method_exists($row, __FUNCTION__)) { + continue; + } + + //let the row handle this + $row->setTable($table); + } + + return $this; + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/sql/database.php b/library/eden/sql/database.php new file mode 100755 index 0000000..08cc7af --- /dev/null +++ b/library/eden/sql/database.php @@ -0,0 +1,766 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +require_once dirname(__FILE__).'/../event.php'; +require_once dirname(__FILE__).'/../collection.php'; +require_once dirname(__FILE__).'/../model.php'; +require_once dirname(__FILE__).'/error.php'; +require_once dirname(__FILE__).'/query.php'; +require_once dirname(__FILE__).'/delete.php'; +require_once dirname(__FILE__).'/select.php'; +require_once dirname(__FILE__).'/update.php'; +require_once dirname(__FILE__).'/insert.php'; +require_once dirname(__FILE__).'/collection.php'; +require_once dirname(__FILE__).'/model.php'; +require_once dirname(__FILE__).'/search.php'; + +/** + * Abstractly defines a layout of available methods to + * connect to and query a database. This class also lays out + * query building methods that auto renders a valid query + * the specific database will understand without actually + * needing to know the query language. + * + * @package Eden + * @category sql + * @author Christian Blanquera cblanquera@openovate.com + */ +abstract class Eden_Sql_Database extends Eden_Event { + /* Constants + -------------------------------*/ + const QUERY = 'Eden_Sql_Query'; + + const FIRST = 'first'; + const LAST = 'last'; + + const MODEL = 'Eden_Sql_Model'; + const COLLECTION = 'Eden_Sql_Collection'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_queries = array(); + + protected $_connection = NULL; + protected $_binds = array(); + + protected $_model = self::MODEL; + protected $_collection = self::COLLECTION; + + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + /* Magic + -------------------------------*/ + /* Public Methods + -------------------------------*/ + /** + * Connects to the database + * + * @param array the connection options + * @return this + */ + abstract public function connect(array $options = array()); + + /** + * Binds a value and returns the bound key + * + * @param string + * @return string + */ + public function bind($value) { + //Argument 1 must be an array, string or number + Eden_Sql_Error::i()->argument(1, 'array', 'string', 'numeric', 'null'); + + if(is_array($value)) { + foreach($value as $i => $item) { + $value[$i] = $this->bind($item); + } + + return '('.implode(",",$value).')'; + } else if(is_numeric($value)) { + return $value; + } + + $name = ':bind'.count($this->_binds).'bind'; + $this->_binds[$name] = $value; + return $name; + } + + /** + * Returns collection + * + * @return Eden_Sql_Collection + */ + public function collection(array $data = array()) { + $collection = $this->_collection; + return $this->$collection() + ->setDatabase($this) + ->setModel($this->_model) + ->set($data); + } + + /** + * Returns the delete query builder + * + * @return Eden_Sql_Delete + */ + public function delete($table = NULL) { + //Argument 1 must be a string or null + Eden_Sql_Error::i()->argument(1, 'string', 'null'); + + return Eden_Sql_Delete::i($table); + } + + /** + * Removes rows that match a filter + * + * @param string table + * @param array filter + * @return var + */ + public function deleteRows($table, $filters = NULL) { + //Argument 1 must be a string + Eden_Sql_Error::i()->argument(1, 'string'); + + $query = $this->delete($table); + + if(is_array($filters)) { + foreach($filters as $i => $filter) { + //array('post_id=%s AND post_title IN %s', 123, array('asd')); + $format = array_shift($filter); + + foreach($filter as $j => $value) { + $filter[$j] = $this->bind($value); + } + + $filters[$i] = vsprintf($format, $filter); + } + } + + $query->where($filters); + + //run the query + $this->query($query, $this->getBinds()); + + $this->trigger($table, $filters); + + return $this; + } + + /** + * Returns all the bound values of this query + * + * @param void + * @return array + */ + public function getBinds() { + return $this->_binds; + } + + /** + * Returns a collection given the query parameters + * + * @param string table + * @param array joins + * @param array filter + * @param array sort + * @param int start + * @param int range + * @return array + */ + public function getCollection($table, array $joins = array(), $filters = NULL, + array $sort = array(), $start = 0, $range = 0, $index = NULL) { + //argument test + Eden_Sql_Error::i() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(3, 'string', 'array', 'null') //Argument 3 must be a string number or null + ->argument(5, 'numeric') //Argument 5 must be a number + ->argument(6, 'numeric') //Argument 6 must be a number + ->argument(7, 'numeric', 'null'); //Argument 7 must be a number or null + + $results = $this->getRows($table, $joins, $filters, $sort, $start, $range, $index); + + $collection = $this->collection() + ->setTable($table) + ->setModel($this->_model); + + if(is_null($results)) { + return $collection; + } + + if(!is_null($index)) { + return $this->model($results)->setTable($table); + } + + return $collection->set($results); + } + + /** + * Returns the connection object + * if no connection has been made + * it will attempt to make it + * + * @param array connection options + * @return PDO connection resource + */ + public function getConnection() { + if(!$this->_connection) { + $this->connect(); + } + + return $this->_connection; + } + + /** + * Returns the last inserted id + * + * @return int the id + */ + public function getLastInsertedId() { + return $this->getConnection()->lastInsertId(); + } + + /** + * Returns a model given the column name and the value + * + * @param string table + * @param string name + * @param string value + * @return array|NULL + */ + public function getModel($table, $name, $value) { + //argument test + Eden_Sql_Error::i() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'string') //Argument 2 must be a string + ->argument(3, 'string', 'numeric'); //Argument 3 must be a string or number + + $result = $this->getRow($table, $name, $value); + + $model = $this->model()->setTable($table); + + if(is_null($result)) { + return $model; + } + + return $model->set($result); + } + + /** + * Returns the history of queries made still in memory + * + * @return array the queries + */ + public function getQueries($index = NULL) { + if(is_null($index)) { + return $this->_queries; + } + + if($index == self::FIRST) { + $index = 0; + } + + if($index == self::LAST) { + $index = count($this->_queries) - 1; + } + + if(isset($this->_queries[$index])) { + return $this->_queries[$index]; + } + + return NULL; + } + + /** + * Returns a 1 row result given the column name and the value + * + * @param string table + * @param string name + * @param string value + * @return array + */ + public function getRow($table, $name, $value) { + //argument test + Eden_Sql_Error::i() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'string') //Argument 2 must be a string + ->argument(3, 'string', 'numeric'); //Argument 3 must be a string or number + + $query = $this->select() + ->from($table) + ->where($name.' = '.$this->bind($value)) + ->limit(0, 1); + + $results = $this->query($query, $this->getBinds()); + + $this->trigger($table, $name, $value, $results); + + return isset($results[0]) ? $results[0] : NULL; + } + + /** + * Returns a list of results given the query parameters + * + * @param string table + * @param array joins + * @param array filter + * @param array sort + * @param int start + * @param int range + * @return array + */ + public function getRows($table, array $joins = array(), $filters = NULL, + array $sort = array(), $start = 0, $range = 0, $index = NULL) { + //argument test + Eden_Sql_Error::i() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(3, 'string', 'array', 'null') //Argument 3 must be a string number or null + ->argument(5, 'numeric') //Argument 5 must be a number + ->argument(6, 'numeric') //Argument 6 must be a number + ->argument(7, 'numeric', 'null'); //Argument 7 must be a number or null + + $query = $this->select()->from($table); + + foreach($joins as $join) { + if(!is_array($join) || count($join) < 3) { + continue; + } + + if(count($join) == 3) { + $join[] = true; + } + + $query->join($join[0], $join[1], $join[2], $join[3]); + } + + if(is_array($filters)) { + foreach($filters as $i => $filter) { + //array('post_id=%s AND post_title IN %s', 123, array('asd')); + $format = array_shift($filter); + + foreach($filter as $j => $value) { + $filter[$j] = $this->bind($value); + } + + $filters[$i] = vsprintf($format, $filter); + } + } + + if(!is_null($filters)) { + $query->where($filters); + } + + if(!empty($sort)) { + foreach($sort as $key => $value) { + if(is_string($key) && trim($key)) { + $query->sortBy($key, $value); + } + } + } + + if($range) { + $query->limit($start, $range); + } + + $results = $this->query($query, $this->getBinds()); + + if(!is_null($index)) { + if(empty($results)) { + $results = NULL; + } else { + if($index == self::FIRST) { + $index = 0; + } + + if($index == self::LAST) { + $index = count($results)-1; + } + + if(isset($results[$index])) { + $results = $results[$index]; + } else { + $results = NULL; + } + } + } + + $this->trigger($table, $joins, $filters, $sort, $start, $range, $index, $results); + + return $results; + } + + /** + * Returns the number of results given the query parameters + * + * @param string table + * @param array filter + * @return int | false + */ + public function getRowsCount($table, array $joins = array(), $filters = NULL) { + //argument test + Eden_Sql_Error::i() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(3, 'string', 'array', 'null'); //Argument 3 must be a string number or null + + $query = $this->select('COUNT(*) as count')->from($table); + + foreach($joins as $join) { + if(!is_array($join) || count($join) < 3) { + continue; + } + + if(count($join) == 3) { + $join[] = true; + } + + $query->join($join[0], $join[1], $join[2], $join[3]); + } + + if(is_array($filters)) { + foreach($filters as $i => $filter) { + //array('post_id=%s AND post_title IN %s', 123, array('asd')); + $format = array_shift($filter); + $filter = $this->bind($filter); + $filters[$i] = vsprintf($format, $filter); + } + } + + $query->where($filters); + + $results = $this->query($query, $this->getBinds()); + + if(isset($results[0]['count'])) { + $this->trigger($table, $joins, $filters, $results[0]['count']); + return $results[0]['count']; + } + + $this->trigger($table, $joins, $filters, false); + + return false; + } + + /** + * Returns the insert query builder + * + * @return Eden_Sql_Insert + */ + public function insert($table = NULL) { + //Argument 1 must be a string or null + Eden_Sql_Error::i()->argument(1, 'string', 'null'); + + return Eden_Sql_Insert::i($table); + } + + /** + * Inserts data into a table and returns the ID + * + * @param string table + * @param array setting + * @return int + */ + public function insertRow($table, array $setting, $bind = true) { + //Argument 1 must be a string + Eden_Sql_Error::i()->argument(1, 'string')->argument(3, 'array', 'bool'); + + $query = $this->insert($table); + + foreach($setting as $key => $value) { + if(is_null($value) || is_bool($value)) { + $query->set($key, $value); + continue; + } + + if((is_bool($bind) && $bind) || (is_array($bind) && in_array($key, $bind))) { + $value = $this->bind($value); + } + + $query->set($key, $value); + } + + //run the query + $this->query($query, $this->getBinds()); + + $this->trigger($table, $setting); + + return $this; + } + + /** + * Inserts multiple rows into a table + * + * @param string table + * @param array settings + * @return void + */ + public function insertRows($table, array $settings, $bind = true) { + //Argument 1 must be a string + Eden_Sql_Error::i()->argument(1, 'string')->argument(3, 'array', 'bool'); + + $query = $this->insert($table); + + foreach($settings as $index => $setting) { + foreach($setting as $key => $value) { + if(is_null($value) || is_bool($value)) { + $query->set($key, $value); + continue; + } + + if((is_bool($bind) && $bind) || (is_array($bind) && in_array($key, $bind))) { + $value = $this->bind($value); + } + + $query->set($key, $value, $index); + } + } + + //run the query + $this->query($query, $this->getBinds()); + + $this->trigger($table, $settings); + + return $this; + } + + /** + * Returns model + * + * @return Eden_Sql_Model + */ + public function model(array $data = array()) { + $model = $this->_model; + return $this->$model($data)->setDatabase($this); + } + + /** + * Queries the database + * + * @param string query + * @param array binded value + * @return array|object + */ + public function query($query, array $binds = array()) { + //Argument 1 must be a string or null + Eden_Sql_Error::i()->argument(1, 'string', self::QUERY); + + $connection = $this->getConnection(); + $query = (string) $query; + $stmt = $connection->prepare($query); + + foreach($binds as $key => $value) { + $stmt->bindValue($key, $value); + } + + if(!$stmt->execute()) { + $error = $stmt->errorInfo(); + + foreach($binds as $key => $value) { + $query = str_replace($key, "'$value'", $query); + } + + Eden_Sql_Error::i() + ->setMessage(Eden_Sql_Error::QUERY_ERROR) + ->addVariable($query) + ->addVariable($error[2]) + ->trigger(); + } + + $results = $stmt->fetchAll( PDO::FETCH_ASSOC ); + + $this->_queries[] = array( + 'query' => $query, + 'binds' => $binds, + 'results' => $results); + + $this->_binds = array(); + + $this->trigger($query, $binds, $results); + + return $results; + } + + /** + * Returns search + * + * @return Eden_Sql_Search + */ + public function search($table = NULL) { + //Argument 1 must be a string or null + Eden_Sql_Error::i()->argument(1, 'string', 'null'); + + $search = Eden_Sql_Search::i($this) + ->setCollection($this->_collection) + ->setModel($this->_model); + + if($table) { + $search->setTable($table); + } + + return $search; + } + + /** + * Returns the select query builder + * + * @return Eden_Sql_Select + */ + public function select($select = '*') { + //Argument 1 must be a string or array + Eden_Sql_Error::i()->argument(1, 'string', 'array'); + + return Eden_Sql_Select::i($select); + } + + /** + * Sets all the bound values of this query + * + * @param array + * @return this + */ + public function setBinds(array $binds) { + $this->_binds = $binds; + return $this; + } + + /** + * Sets default collection + * + * @param string + * @return this + */ + public function setCollection($collection) { + $error = Eden_Sql_Error::i()->argument(1, 'string'); + + if(!is_subclass_of($collection, self::COLLECTION)) { + $error->setMessage(Eden_Sql_Error::NOT_SUB_COLLECTION) + ->addVariable($collection) + ->trigger(); + } + + $this->_collection = $collection; + return $this; + } + + /** + * Sets the default model + * + * @param string + * @return this + */ + public function setModel($model) { + $error = Eden_Sql_Error::i()->argument(1, 'string'); + + if(!is_subclass_of($model, self::MODEL)) { + $error->setMessage(Eden_Sql_Error::NOT_SUB_MODEL) + ->addVariable($model) + ->trigger(); + } + + $this->_model = $model; + return $this; + } + + /** + * Sets only 1 row given the column name and the value + * + * @param string table + * @param string name + * @param string value + * @param array setting + * @return var + */ + public function setRow($table, $name, $value, array $setting) { + //argument test + Eden_Sql_Error::i() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'string') //Argument 2 must be a string + ->argument(3, 'string', 'numeric'); //Argument 3 must be a string or number + + //first check to see if the row exists + $row = $this->getRow($table, $name, $value); + + if(!$row) { + //we need to insert + $setting[$name] = $value; + return $this->insertRow($table, $setting); + } else { + //we need to update this row + return $this->updateRows($table, $setting, array(array($name.'=%s', $value))); + } + } + + /** + * Returns the update query builder + * + * @return Eden_Sql_Update + */ + public function update($table = NULL) { + //Argument 1 must be a string or null + Eden_Sql_Error::i()->argument(1, 'string', 'null'); + + return Eden_Sql_Update::i($table); + } + + /** + * Updates rows that match a filter given the update settings + * + * @param string table + * @param array setting + * @param array filter + * @return var + */ + public function updateRows($table, array $setting, $filters = NULL, $bind = true) { + //Argument 1 must be a string + Eden_Sql_Error::i()->argument(1, 'string')->argument(4, 'array', 'bool'); + + $query = $this->update($table); + + foreach($setting as $key => $value) { + if(is_null($value) || is_bool($value)) { + $query->set($key, $value); + continue; + } + + if((is_bool($bind) && $bind) || (is_array($bind) && in_array($key, $bind))) { + $value = $this->bind($value); + } + + $query->set($key, $value); + } + + if(is_array($filters)) { + foreach($filters as $i => $filter) { + //array('post_id=%s AND post_title IN %s', 123, array('asd')); + $format = array_shift($filter); + + foreach($filter as $j => $value) { + $filter[$j] = $this->bind($value); + } + + $filters[$i] = vsprintf($format, $filter); + } + } + + $query->where($filters); + + //run the query + $this->query($query, $this->getBinds()); + + $this->trigger($table, $setting, $filters); + + return $this; + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/sql/delete.php b/library/eden/sql/delete.php new file mode 100755 index 0000000..49ad21e --- /dev/null +++ b/library/eden/sql/delete.php @@ -0,0 +1,91 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Generates delete query string syntax + * + * @package Eden + * @category sql + * @author Christian Blanquera cblanquera@openovate.com + */ +class Eden_Sql_Delete extends Eden_Sql_Query { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_table = NULL; + protected $_where = array(); + + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + public function __construct($table = NULL) { + if(is_string($table)) { + $this->setTable($table); + } + } + + /* Public Methods + -------------------------------*/ + /** + * Returns the string version of the query + * + * @return string + * @notes returns the query based on the registry + */ + public function getQuery() { + return 'DELETE FROM '. $this->_table . ' WHERE '. implode(' AND ', $this->_where).';'; + } + + /** + * Set the table name in which you want to delete from + * + * @param string name + * @return this + */ + public function setTable($table) { + //Argument 1 must be a string + Eden_Sql_Error::i()->argument(1, 'string'); + + $this->_table = $table; + return $this; + } + + /** + * Where clause + * + * @param array|string where + * @return this + * @notes loads a where phrase into registry + */ + public function where($where) { + //Argument 1 must be a string or array + Eden_Sql_Error::i()->argument(1, 'string', 'array'); + + if(is_string($where)) { + $where = array($where); + } + + $this->_where = array_merge($this->_where, $where); + + return $this; + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/sql/error.php b/library/eden/sql/error.php new file mode 100755 index 0000000..0789807 --- /dev/null +++ b/library/eden/sql/error.php @@ -0,0 +1,46 @@ + +/* + * This file is part of the Eden package. + * (c) 2010-2012 Christian Blanquera + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Sql Errors + * + * @package Eden + * @category sql + * @author Christian Blanquera cblanquera@openovate.com + */ +class Eden_Sql_Error extends Eden_Error { + /* Constants + -------------------------------*/ + const QUERY_ERROR = '%s Query: %s'; + const TABLE_NOT_SET = 'No default table set or was passed.'; + const DATABASE_NOT_SET = 'No default database set or was passed.'; + + const NOT_SUB_MODEL = 'Class %s is not a child of Eden_Model'; + const NOT_SUB_COLLECTION = 'Class %s is not a child of Eden_Collection'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i($message = NULL, $code = 0) { + $class = __CLASS__; + return new $class($message, $code); + } + + /* Public Methods + -------------------------------*/ + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/sql/insert.php b/library/eden/sql/insert.php new file mode 100755 index 0000000..74fb91b --- /dev/null +++ b/library/eden/sql/insert.php @@ -0,0 +1,106 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Generates insert query string syntax + * + * @package Eden + * @category sql + * @author Christian Blanquera cblanquera@openovate.com + */ +class Eden_Sql_Insert extends Eden_Sql_Query { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_setKey = array(); + protected $_setVal = array(); + + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + public function __construct($table = NULL) { + if(is_string($table)) { + $this->setTable($table); + } + } + + /* Public Methods + -------------------------------*/ + /** + * Returns the string version of the query + * + * @param bool + * @return string + * @notes returns the query based on the registry + */ + public function getQuery() { + $multiValList = array(); + foreach($this->_setVal as $val) { + $multiValList[] = '('.implode(', ', $val).')'; + } + + return 'INSERT INTO '. $this->_table . ' ('.implode(', ', $this->_setKey).") VALUES ".implode(", \n", $multiValList).';'; + } + + /** + * Set clause that assigns a given field name to a given value. + * You can also use this to add multiple rows in one call + * + * @param string + * @param string + * @return this + * @notes loads a set into registry + */ + public function set($key, $value, $index = 0) { + //argument test + Eden_Sql_Error::i() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'scalar', 'null'); //Argument 2 must be scalar or null + + if(!in_array($key, $this->_setKey)) { + $this->_setKey[] = $key; + } + + if(is_null($value)) { + $value = 'NULL'; + } else if(is_bool($value)) { + $value = $value ? 1 : 0; + } + + $this->_setVal[$index][] = $value; + return $this; + } + + /** + * Set the table name in which you want to delete from + * + * @param string name + * @return this + */ + public function setTable($table) { + //Argument 1 must be a string + Eden_Sql_Error::i()->argument(1, 'string'); + + $this->_table = $table; + return $this; + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} diff --git a/library/eden/sql/model.php b/library/eden/sql/model.php new file mode 100644 index 0000000..f3dbba1 --- /dev/null +++ b/library/eden/sql/model.php @@ -0,0 +1,423 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Sql Model + * + * @package Eden + * @category sql + * @author Christian Blanquera cblanquera@openovate.com + */ +class Eden_Sql_Model extends Eden_Model { + /* Constants + -------------------------------*/ + const COLUMNS = 'columns'; + const PRIMARY = 'primary'; + const DATETIME = 'Y-m-d h:i:s'; + const DATE = 'Y-m-d'; + const TIME = 'h:i:s'; + const TIMESTAMP = 'U'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_table = NULL; + protected $_database = NULL; + + protected static $_meta = array(); + + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + /* Public Methods + -------------------------------*/ + /** + * Useful method for formating a time column. + * + * @param string + * @param string + * @return this + */ + public function formatTime($column, $format = self::DATETIME) { + //Argument Test + Eden_Sql_Error::i() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'string'); //Argument 1 must be a string + + //if the column isn't set + if(!isset($this->_data[$column])) { + //do nothing more + return $this; + } + + //if this is column is a string + if(is_string($this->_data[$column])) { + //make into time + $this->_data[$column] = strtotime($this->_data[$column]); + } + + //if this column is not an integer + if(!is_int($this->_data[$column])) { + //do nothing more + return $this; + } + + //set it + $this->_data[$column] = date($format, $this->_data[$column]); + + return $this; + } + + /** + * Inserts model to database + * + * @param string + * @param Eden_Sql_Database + * @return this + */ + public function insert($table = NULL, Eden_Sql_Database $database = NULL) { + //Argument 1 must be a string + $error = Eden_Sql_Error::i()->argument(1, 'string', 'null'); + + //if no table + if(is_null($table)) { + //if no default table either + if(!$this->_table) { + //throw error + $error->setMessage(Eden_Sql_Error::TABLE_NOT_SET)->trigger(); + } + + $table = $this->_table; + } + + //if no database + if(is_null($database)) { + //and no default database + if(!$this->_database) { + $error->setMessage(Eden_Sql_Error::DATABASE_NOT_SET)->trigger(); + } + + $database = $this->_database; + } + + //get the meta data, the valid column values and whether is primary is set + $meta = $this->_getMeta($table, $database); + $data = $this->_getValidColumns(array_keys($meta[self::COLUMNS])); + + //update original data + $this->_original = $this->_data; + + //we insert it + $database->insertRow($table, $data); + + //only if we have 1 primary key + if(count($meta[self::PRIMARY]) == 1) { + //set the primary key + $this->_data[$meta[self::PRIMARY][0]] = $database->getLastInsertedId(); + } + + return $this; + } + + /** + * Removes model from database + * + * @param string + * @param Eden_Sql_Database + * @param string|array|null + * @return this + */ + public function remove($table = NULL, Eden_Sql_Database $database = NULL, $primary = NULL) { + //Argument 1 must be a string + $error = Eden_Sql_Error::i()->argument(1, 'string', 'null'); + + //if no table + if(is_null($table)) { + //if no default table either + if(!$this->_table) { + //throw error + $error->setMessage(Eden_Sql_Error::TABLE_NOT_SET)->trigger(); + } + + $table = $this->_table; + } + + //if no database + if(is_null($database)) { + //and no default database + if(!$this->_database) { + $error->setMessage(Eden_Sql_Error::DATABASE_NOT_SET)->trigger(); + } + + $database = $this->_database; + } + + //get the meta data and valid columns + $meta = $this->_getMeta($table, $database); + $data = $this->_getValidColumns(array_keys($meta[self::COLUMNS])); + + if(is_null($primary)) { + $primary = $meta[self::PRIMARY]; + } + + if(is_string($primary)) { + $primary = array($primary); + } + + $filter = array(); + //for each primary key + foreach($primary as $column) { + //if the primary is not set + if(!isset($data[$column])) { + //we can't do a remove + //do nothing more + return $this; + } + + //add the condition to the filter + $filter[] = array($column.'=%s', $data[$column]); + } + + //we delete it + $database->deleteRows($table, $filter); + + return $this; + } + + /** + * Inserts or updates model to database + * + * @param string + * @param Eden_Sql_Database + * @param string|array|null + * @return this + */ + public function save($table = NULL, Eden_Sql_Database $database = NULL, $primary = NULL) { + //Argument 1 must be a string + $error = Eden_Sql_Error::i()->argument(1, 'string', 'null'); + + //if no table + if(is_null($table)) { + //if no default table either + if(!$this->_table) { + //throw error + $error->setMessage(Eden_Sql_Error::TABLE_NOT_SET)->trigger(); + } + + $table = $this->_table; + } + + //if no database + if(is_null($database)) { + //and no default database + if(!$this->_database) { + $error->setMessage(Eden_Sql_Error::DATABASE_NOT_SET)->trigger(); + } + + $database = $this->_database; + } + + //get the meta data, the valid column values and whether is primary is set + $meta = $this->_getMeta($table, $database); + + if(is_null($primary)) { + $primary = $meta[self::PRIMARY]; + } + + if(is_string($primary)) { + $primary = array($primary); + } + + $primarySet = $this->_isPrimarySet($primary); + + //update original data + $this->_original = $this->_data; + + //if no primary meta or primary values are not set + if(empty($primary) || !$primarySet) { + return $this->insert($table, $database); + } + + return $this->update($table, $database, $primary); + } + + /** + * Sets the default database + * + * @param Eden_Sql + */ + public function setDatabase(Eden_Sql_Database $database) { + $this->_database = $database; + return $this; + } + + /** + * Sets the default database + * + * @param string + */ + public function setTable($table) { + //Argument 1 must be a string + Eden_Sql_Error::i()->argument(1, 'string'); + + $this->_table = $table; + return $this; + } + + /** + * Updates model to database + * + * @param string + * @param Eden_Sql_Database + * @param string|array|null + * @return this + */ + public function update($table = NULL, Eden_Sql_Database $database = NULL, $primary = NULL) { + //Argument 1 must be a string + $error = Eden_Sql_Error::i()->argument(1, 'string', 'null'); + + //if no table + if(is_null($table)) { + //if no default table either + if(!$this->_table) { + //throw error + $error->setMessage(Eden_Sql_Error::TABLE_NOT_SET)->trigger(); + } + + $table = $this->_table; + } + + //if no database + if(is_null($database)) { + //and no default database + if(!$this->_database) { + $error->setMessage(Eden_Sql_Error::DATABASE_NOT_SET)->trigger(); + } + + $database = $this->_database; + } + + //get the meta data, the valid column values and whether is primary is set + $meta = $this->_getMeta($table, $database); + $data = $this->_getValidColumns(array_keys($meta[self::COLUMNS])); + + //update original data + $this->_original = $this->_data; + + //from here it means that this table has primary + //columns and all primary values are set + + if(is_null($primary)) { + $primary = $meta[self::PRIMARY]; + } + + if(is_string($primary)) { + $primary = array($primary); + } + + $filter = array(); + //for each primary key + foreach($primary as $column) { + //add the condition to the filter + $filter[] = array($column.'=%s', $data[$column]); + } + + //we update it + $database->updateRows($table, $data, $filter); + + return $this; + } + + /* Protected Methods + -------------------------------*/ + protected function _isLoaded($table = NULL, $database = NULL) { + //if no table + if(is_null($table)) { + //if no default table either + if(!$this->_table) { + return false; + } + + $table = $this->_table; + } + + //if no database + if(is_null($database)) { + //and no default database + if(!$this->_database) { + return false; + } + + $database = $this->_database; + } + + $meta = $this->_getMeta($table, $database); + + return $this->_isPrimarySet($meta[self::PRIMARY]); + } + + protected function _isPrimarySet(array $primary) { + foreach($primary as $column) { + if(is_null($this[$column])) { + return false; + } + } + + return true; + } + + protected function _getMeta($table, $database) { + $uid = spl_object_hash($database); + if(isset(self::$_meta[$uid][$table])) { + return self::$_meta[$uid][$table]; + } + + $columns = $database->getColumns($table); + + $meta = array(); + foreach($columns as $i => $column) { + $meta[self::COLUMNS][$column['Field']] = array( + 'type' => $column['Type'], + 'key' => $column['Key'], + 'default' => $column['Default'], + 'empty' => $column['Null'] == 'YES'); + + if($column['Key'] == 'PRI') { + $meta[self::PRIMARY][] = $column['Field']; + } + } + + self::$_meta[$uid][$table] = $meta; + + return $meta; + } + + protected function _getValidColumns($columns) { + $valid = array(); + foreach($columns as $column) { + if(!isset($this->_data[$column])) { + continue; + } + + $valid[$column] = $this->_data[$column]; + } + + return $valid; + } + + /* Private Methods + -------------------------------*/ +} + diff --git a/library/eden/sql/query.php b/library/eden/sql/query.php new file mode 100755 index 0000000..d5bc653 --- /dev/null +++ b/library/eden/sql/query.php @@ -0,0 +1,49 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Generates select query string syntax + * + * @package Eden + * @category sql + * @author Christian Blanquera cblanquera@openovate.com + */ +abstract class Eden_Sql_Query extends Eden_Class { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + /* Magic + -------------------------------*/ + public function __toString() { + return $this->getQuery(); + } + + /* Public Methods + -------------------------------*/ + /** + * Returns the string version of the query + * + * @param bool + * @return string + * @notes returns the query based on the registry + */ + abstract public function getQuery(); + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/sql/search.php b/library/eden/sql/search.php new file mode 100644 index 0000000..e6b982c --- /dev/null +++ b/library/eden/sql/search.php @@ -0,0 +1,749 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Sql Search + * + * @package Eden + * @category sql + * @author Christian Blanquera cblanquera@openovate.com + */ +class Eden_Sql_Search extends Eden_Class { + /* Constants + -------------------------------*/ + const LEFT = 'LEFT'; + const RIGHT = 'RIGHT'; + const INNER = 'INNER'; + const OUTER = 'OUTER'; + const ASC = 'ASC'; + const DESC = 'DESC'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_database = NULL; + protected $_table = NULL; + protected $_columns = array(); + protected $_join = array(); + protected $_filter = array(); + protected $_sort = array(); + protected $_group = array(); + protected $_start = 0; + protected $_range = 0; + + protected $_model = Eden_Sql_Database::MODEL; + protected $_collection = Eden_Sql_Database::COLLECTION; + + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + public function __call($name, $args) { + if(strpos($name, 'filterBy') === 0) { + //filterByUserName('Chris', '-') + $separator = '_'; + if(isset($args[1]) && is_scalar($args[1])) { + $separator = (string) $args[1]; + } + + $key = Eden_Type_String::i($name) + ->substr(8) + ->preg_replace("/([A-Z0-9])/", $separator."$1") + ->substr(strlen($separator)) + ->strtolower() + ->get(); + + if(!isset($args[0])) { + $args[0] = NULL; + } + + $key = $key.'=%s'; + + $this->addFilter($key, $args[0]); + + return $this; + } + + if(strpos($name, 'sortBy') === 0) { + //filterByUserName('Chris', '-') + $separator = '_'; + if(isset($args[1]) && is_scalar($args[1])) { + $separator = (string) $args[1]; + } + + $key = Eden_Type_String::i($name) + ->substr(6) + ->preg_replace("/([A-Z0-9])/", $separator."$1") + ->substr(strlen($separator)) + ->strtolower() + ->get(); + + if(!isset($args[0])) { + $args[0] = self::ASC; + } + + $this->addSort($key, $args[0]); + + return $this; + } + + try { + return parent::__call($name, $args); + } catch(Eden_Error $e) { + Eden_Sql_Error::i($e->getMessage())->trigger(); + } + } + + public function __construct(Eden_Sql_Database $database) { + $this->_database = $database; + } + + /* Public Methods + -------------------------------*/ + + /** + * Adds filter + * + * @param string + * @param string[,string..] + * @return this + */ + public function addFilter() { + Eden_Sql_Error::i()->argument(1, 'string'); + + $this->_filter[] = func_get_args(); + + return $this; + } + + /** + * Adds Inner Join On + * + * @param string + * @param string[,string..] + * @return this + */ + public function addInnerJoinOn($table, $where) { + Eden_Sql_Error::i() + ->argument(1, 'string') + ->argument(2, 'string'); + + $where = func_get_args(); + $table = array_shift($where); + + $this->_join[] = array(self::INNER, $table, $where, false); + + return $this; + } + + /** + * Adds Inner Join Using + * + * @param string + * @param string[,string..] + * @return this + */ + public function addInnerJoinUsing($table, $where) { + Eden_Sql_Error::i() + ->argument(1, 'string') + ->argument(2, 'string'); + + $where = func_get_args(); + $table = array_shift($where); + + $this->_join[] = array(self::INNER, $table, $where, true); + + return $this; + } + + /** + * Adds Left Join On + * + * @param string + * @param string[,string..] + * @return this + */ + public function addLeftJoinOn($table, $where) { + Eden_Sql_Error::i() + ->argument(1, 'string') + ->argument(2, 'string'); + + $where = func_get_args(); + $table = array_shift($where); + + $this->_join[] = array(self::LEFT, $table, $where, false); + + return $this; + } + + /** + * Adds Left Join Using + * + * @param string + * @param string[,string..] + * @return this + */ + public function addLeftJoinUsing($table, $where) { + Eden_Sql_Error::i() + ->argument(1, 'string') + ->argument(2, 'string'); + + $where = func_get_args(); + $table = array_shift($where); + + $this->_join[] = array(self::LEFT, $table, $where, true); + + return $this; + } + + /** + * Adds Outer Join On + * + * @param string + * @param string[,string..] + * @return this + */ + public function addOuterJoinOn($table, $where) { + Eden_Sql_Error::i() + ->argument(1, 'string') + ->argument(2, 'string'); + + $where = func_get_args(); + $table = array_shift($where); + + $this->_join[] = array(self::OUTER, $table, $where, false); + + return $this; + } + + /** + * Adds Outer Join USing + * + * @param string + * @param string[,string..] + * @return this + */ + public function addOuterJoinUsing($table, $where) { + Eden_Sql_Error::i() + ->argument(1, 'string') + ->argument(2, 'string'); + + $where = func_get_args(); + $table = array_shift($where); + + $this->_join[] = array(self::OUTER, $table, $where, true); + + return $this; + } + + /** + * Adds Right Join On + * + * @param string + * @param string[,string..] + * @return this + */ + public function addRightJoinOn($table, $where) { + Eden_Sql_Error::i() + ->argument(1, 'string') + ->argument(2, 'string'); + + $where = func_get_args(); + $table = array_shift($where); + + $this->_join[] = array(self::RIGHT, $table, $where, false); + + return $this; + } + + /** + * Adds Right Join Using + * + * @param string + * @param string[,string..] + * @return this + */ + public function addRightJoinUsing($table, $where) { + Eden_Sql_Error::i() + ->argument(1, 'string') + ->argument(2, 'string'); + + $where = func_get_args(); + $table = array_shift($where); + + $this->_join[] = array(self::RIGHT, $table, $where, true); + + return $this; + } + + /** + * Adds sort + * + * @param string + * @param string + * @return this + */ + public function addSort($column, $order = self::ASC) { + Eden_Sql_Error::i() + ->argument(1, 'string') + ->argument(2, 'string'); + + if($order != self::DESC) { + $order = self::ASC; + } + + $this->_sort[$column] = $order; + + return $this; + } + + /** + * Returns the results in a collection + * + * @return Eden_Sql_Collection + */ + public function getCollection() { + $collection = $this->_collection; + return $this->$collection() + ->setDatabase($this->_database) + ->setTable($this->_table) + ->setModel($this->_model) + ->set($this->getRows()); + } + + /** + * Returns the one result in a model + * + * @param int + * @return Eden_Sql_Model + */ + public function getModel($index = 0) { + Eden_Sql_Error::i()->argument(1, 'int'); + return $this->getCollection()->offsetGet($index); + } + + /** + * Returns the one result + * + * @param int|string + * @param string|null + * @return array|null + */ + public function getRow($index = 0, $column = NULL) { + Eden_Sql_Error::i() + ->argument(1, 'int', 'string') + ->argument(2, 'string', 'null'); + + if(is_string($index)) { + $column = $index; + $index = 0; + } + + $rows = $this->getRows(); + + if(!is_null($column) && isset($rows[$index][$column])) { + return $rows[$index][$column]; + } else if(is_null($column) && isset($rows[$index])) { + return $rows[$index]; + } + + return NULL; + } + + /** + * Returns the array rows + * + * @return array + */ + public function getRows() { + $query = $this->_getQuery(); + + if(!empty($this->_columns)) { + $query->select(implode(', ', $this->_columns)); + } + + foreach($this->_sort as $key => $value) { + $query->sortBy($key, $value); + } + + if($this->_range) { + $query->limit($this->_start, $this->_range); + } + + if(!empty($this->_group)) { + $query->groupBy($this->_group); + } + + return $this->_database->query($query, $this->_database->getBinds()); + } + + /** + * Returns the total results + * + * @return int + */ + public function getTotal() { + $query = $this->_getQuery()->select('COUNT(*) as total'); + + $rows = $this->_database->query($query, $this->_database->getBinds()); + + if(!isset($rows[0]['total'])) { + return 0; + } + + return $rows[0]['total']; + } + + /** + * Adds Inner Join On + * + * @param string + * @param string[,string..] + * @return this + */ + public function innerJoinOn($table, $where) { + Eden_Sql_Error::i() + ->argument(1, 'string') + ->argument(2, 'string'); + + $where = func_get_args(); + $table = array_shift($where); + + $this->_join[] = array(self::INNER, $table, $where, false); + + return $this; + } + + /** + * Adds Inner Join Using + * + * @param string + * @param string[,string..] + * @return this + */ + public function innerJoinUsing($table, $where) { + Eden_Sql_Error::i() + ->argument(1, 'string') + ->argument(2, 'string'); + + $where = func_get_args(); + $table = array_shift($where); + + $this->_join[] = array(self::INNER, $table, $where, true); + + return $this; + } + + /** + * Adds Left Join On + * + * @param string + * @param string[,string..] + * @return this + */ + public function leftJoinOn($table, $where) { + Eden_Sql_Error::i() + ->argument(1, 'string') + ->argument(2, 'string'); + + $where = func_get_args(); + $table = array_shift($where); + + $this->_join[] = array(self::LEFT, $table, $where, false); + + return $this; + } + + /** + * Adds Left Join Using + * + * @param string + * @param string[,string..] + * @return this + */ + public function leftJoinUsing($table, $where) { + Eden_Sql_Error::i() + ->argument(1, 'string') + ->argument(2, 'string'); + + $where = func_get_args(); + $table = array_shift($where); + + $this->_join[] = array(self::LEFT, $table, $where, true); + + return $this; + } + + /** + * Adds Outer Join On + * + * @param string + * @param string[,string..] + * @return this + */ + public function outerJoinOn($table, $where) { + Eden_Sql_Error::i() + ->argument(1, 'string') + ->argument(2, 'string'); + + $where = func_get_args(); + $table = array_shift($where); + + $this->_join[] = array(self::OUTER, $table, $where, false); + + return $this; + } + + /** + * Adds Outer Join USing + * + * @param string + * @param string[,string..] + * @return this + */ + public function outerJoinUsing($table, $where) { + Eden_Sql_Error::i() + ->argument(1, 'string') + ->argument(2, 'string'); + + $where = func_get_args(); + $table = array_shift($where); + + $this->_join[] = array(self::OUTER, $table, $where, true); + + return $this; + } + + /** + * Adds Right Join On + * + * @param string + * @param string[,string..] + * @return this + */ + public function rightJoinOn($table, $where) { + Eden_Sql_Error::i() + ->argument(1, 'string') + ->argument(2, 'string'); + + $where = func_get_args(); + $table = array_shift($where); + + $this->_join[] = array(self::RIGHT, $table, $where, false); + + return $this; + } + + /** + * Adds Right Join Using + * + * @param string + * @param string[,string..] + * @return this + */ + public function rightJoinUsing($table, $where) { + Eden_Sql_Error::i() + ->argument(1, 'string') + ->argument(2, 'string'); + + $where = func_get_args(); + $table = array_shift($where); + + $this->_join[] = array(self::RIGHT, $table, $where, true); + + return $this; + } + + /** + * Sets Columns + * + * @param string[,string..]|array + * @return this + */ + public function setColumns($columns) { + if(!is_array($columns)) { + $columns = func_get_args(); + } + + $this->_columns = $columns; + + return $this; + } + + /** + * Sets default collection + * + * @param string + * @return this + */ + public function setCollection($collection) { + $error = Eden_Sql_Error::i()->argument(1, 'string'); + + if(!is_subclass_of($collection, 'Eden_Collection')) { + $error->setMessage(Eden_Sql_Error::NOT_SUB_COLLECTION) + ->addVariable($collection) + ->trigger(); + } + + $this->_collection = $collection; + return $this; + } + + /** + * Group by clause + * + * @param string group + * @return this + * @notes adds broup by functionality + */ + public function setGroup($group) { + //Argument 1 must be a string or array + Eden_Sql_Error::i()->argument(1, 'string', 'array'); + + if(is_string($group)) { + $group = array($group); + } + + $this->_group = $group; + return $this; + } + + /** + * Sets default model + * + * @param string + * @return this + */ + public function setModel($model) { + $error = Eden_Sql_Error::i()->argument(1, 'string'); + + if(!is_subclass_of($model, 'Eden_Model')) { + $error->setMessage(Eden_Sql_Error::NOT_SUB_MODEL) + ->addVariable($model) + ->trigger(); + } + + $this->_model = $model; + return $this; + } + + /** + * Sets the pagination page + * + * @param int + * @return this + */ + public function setPage($page) { + Eden_Sql_Error::i()->argument(1, 'int'); + + if($page < 1) { + $page = 1; + } + + $this->_start = ($page - 1) * $this->_range; + + return $this; + } + + /** + * Sets the pagination range + * + * @param int + * @return this + */ + public function setRange($range) { + Eden_Sql_Error::i()->argument(1, 'int'); + + if($range < 0) { + $range = 25; + } + + $this->_range = $range; + + return $this; + } + + /** + * Sets the pagination start + * + * @param int + * @return this + */ + public function setStart($start) { + Eden_Sql_Error::i()->argument(1, 'int'); + + if($start < 0) { + $start = 0; + } + + $this->_start = $start; + + return $this; + } + + /** + * Sets Table + * + * @param string + * @return this + */ + public function setTable($table) { + Eden_Sql_Error::i()->argument(1, 'string'); + $this->_table = $table; + return $this; + } + + /* Protected Methods + -------------------------------*/ + protected function _getQuery() { + $query = $this->_database->select()->from($this->_table); + + foreach($this->_join as $join) { + if(!is_array($join[2])) { + $join[2] = array($join[2]); + } + + $where = array_shift($join[2]); + if(!empty($join[2])) { + foreach($join[2] as $i => $value) { + $join[2][$i] = $this->_database->bind($value); + } + + $where = vsprintf($where, $join[2]); + } + + $query->join($join[0], $join[1], $where, $join[3]); + } + + + foreach($this->_filter as $i => $filter) { + //array('post_id=%s AND post_title IN %s', 123, array('asd')); + $where = array_shift($filter); + if(!empty($filter)) { + foreach($filter as $i => $value) { + $filter[$i] = $this->_database->bind($value); + } + + $where = vsprintf($where, $filter); + } + + $query->where($where); + } + + return $query; + } + + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/sql/select.php b/library/eden/sql/select.php new file mode 100755 index 0000000..d0efb4d --- /dev/null +++ b/library/eden/sql/select.php @@ -0,0 +1,289 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Generates select query string syntax + * + * @package Eden + * @category sql + * @author Christian Blanquera cblanquera@openovate.com + */ +class Eden_Sql_Select extends Eden_Sql_Query { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_select = NULL; + protected $_from = NULL; + protected $_joins = NULL; + protected $_where = array(); + protected $_sortBy = array(); + protected $_group = array(); + protected $_page = NULL; + protected $_length = NULL; + + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + public function __construct($select = '*') { + $this->select($select); + } + + /* Public Methods + -------------------------------*/ + /** + * From clause + * + * @param string from + * @return this + * @notes loads from phrase into registry + */ + public function from($from) { + //Argument 1 must be a string + Eden_Sql_Error::i()->argument(1, 'string'); + + $this->_from = $from; + return $this; + } + + /** + * Returns the string version of the query + * + * @param bool + * @return string + * @notes returns the query based on the registry + */ + public function getQuery() { + $joins = empty($this->_joins) ? '' : implode(' ', $this->_joins); + $where = empty($this->_where) ? '' : 'WHERE '.implode(' AND ', $this->_where); + $sort = empty($this->_sortBy) ? '' : 'ORDER BY '.implode(', ', $this->_sortBy); + $limit = is_null($this->_page) ? '' : 'LIMIT ' . $this->_page .',' .$this->_length; + $group = empty($this->_group) ? '' : 'GROUP BY ' . implode(', ', $this->_group); + + $query = sprintf( + 'SELECT %s FROM %s %s %s %s %s %s;', + $this->_select, $this->_from, $joins, + $where, $group, $sort, $limit); + + return str_replace(' ', ' ', $query); + } + + /** + * Group by clause + * + * @param string group + * @return this + * @notes adds broup by functionality + */ + public function groupBy($group) { + //Argument 1 must be a string or array + Eden_Sql_Error::i()->argument(1, 'string', 'array'); + + if(is_string($group)) { + $group = array($group); + } + + $this->_group = $group; + return $this; + } + + /** + * Inner join clause + * + * @param string table + * @param string where + * @param bool on + * @return this + * @notes loads inner join phrase into registry + */ + public function innerJoin($table, $where, $using = true) { + //argument test + Eden_Sql_Error::i() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'string') //Argument 2 must be a string + ->argument(3, 'bool'); //Argument 3 must be a boolean + + return $this->join('INNER', $table, $where, $using); + } + + /** + * Allows you to add joins of different types + * to the query + * + * @param string type + * @param string table + * @param string where + * @param bool on + * @return this + * @notes loads join phrase into registry + */ + public function join($type, $table, $where, $using = true) { + //argument test + Eden_Sql_Error::i() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'string') //Argument 2 must be a string + ->argument(3, 'string') //Argument 3 must be a string + ->argument(4, 'bool'); //Argument 4 must be a boolean + + $linkage = $using ? 'USING ('.$where.')' : ' ON ('.$where.')'; + $this->_joins[] = $type.' JOIN ' . $table . ' ' . $linkage; + + return $this; + } + + /** + * Left join clause + * + * @param string table + * @param string where + * @param bool on + * @return this + * @notes loads left join phrase into registry + */ + public function leftJoin($table, $where, $using = true) { + //argument test + Eden_Sql_Error::i() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'string') //Argument 2 must be a string + ->argument(3, 'bool'); //Argument 3 must be a boolean + + return $this->join('LEFT', $table, $where, $using); + } + + /** + * Limit clause + * + * @param string|int page + * @param string|int length + * @return this + * @notes loads page and length into registry + */ + public function limit($page, $length) { + //argument test + Eden_Sql_Error::i() + ->argument(1, 'numeric') //Argument 1 must be a number + ->argument(2, 'numeric'); //Argument 2 must be a number + + $this->_page = $page; + $this->_length = $length; + + return $this; + } + + /** + * Outer join clause + * + * @param string table + * @param string where + * @param bool on + * @return this + * @notes loads outer join phrase into registry + */ + public function outerJoin($table, $where, $using = true) { + //argument test + Eden_Sql_Error::i() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'string') //Argument 2 must be a string + ->argument(3, 'bool'); //Argument 3 must be a boolean + + return $this->join('OUTER', $table, $where, $using); + } + + /** + * Right join clause + * + * @param string table + * @param string where + * @param bool on + * @return this + * @notes loads right join phrase into registry + */ + public function rightJoin($table, $where, $using = true) { + //argument test + Eden_Sql_Error::i() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'string') //Argument 2 must be a string + ->argument(3, 'bool'); //Argument 3 must be a boolean + + return $this->join('RIGHT', $table, $where, $using); + } + + /** + * Select clause + * + * @param string select + * @return this + * @notes loads select phrase into registry + */ + public function select($select = '*') { + //Argument 1 must be a string or array + Eden_Sql_Error::i()->argument(1, 'string', 'array'); + + //if select is an array + if(is_array($select)) { + //transform into a string + $select = implode(', ', $select); + } + + $this->_select = $select; + + return $this; + } + + /** + * Order by clause + * + * @param string field + * @param string order + * @return this + * @notes loads field and order into registry + */ + public function sortBy($field, $order = 'ASC') { + //argument test + Eden_Sql_Error::i() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'string'); //Argument 2 must be a string + + $this->_sortBy[] = $field . ' ' . $order; + + return $this; + } + + /** + * Where clause + * + * @param array|string where + * @return this + * @notes loads a where phrase into registry + */ + public function where($where) { + //Argument 1 must be a string or array + Eden_Sql_Error::i()->argument(1, 'string', 'array'); + + if(is_string($where)) { + $where = array($where); + } + + $this->_where = array_merge($this->_where, $where); + + return $this; + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/sql/update.php b/library/eden/sql/update.php new file mode 100755 index 0000000..55082fe --- /dev/null +++ b/library/eden/sql/update.php @@ -0,0 +1,82 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Generates update query string syntax + * + * @package Eden + * @category sql + * @author Christian Blanquera cblanquera@openovate.com + */ +class Eden_Sql_Update extends Eden_Sql_Delete { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_set = array(); + + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + /* Public Methods + -------------------------------*/ + /** + * Returns the string version of the query + * + * @param bool + * @return string + * @notes returns the query based on the registry + */ + public function getQuery() { + + $set = array(); + foreach($this->_set as $key => $value) { + $set[] = "{$key} = {$value}"; + } + + return 'UPDATE '. $this->_table . ' SET ' . implode(', ', $set) . ' WHERE '. implode(' AND ', $this->_where).';'; + } + + /** + * Set clause that assigns a given field name to a given value. + * + * @param string + * @param string + * @return this + * @notes loads a set into registry + */ + public function set($key, $value) { + //argument test + Eden_Sql_Error::i() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'scalar', 'null'); //Argument 2 must be scalar or null + + if(is_null($value)) { + $value = 'NULL'; + } else if(is_bool($value)) { + $value = $value ? 1 : 0; + } + + $this->_set[$key] = $value; + + return $this; + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/sqlite.php b/library/eden/sqlite.php new file mode 100644 index 0000000..74f976b --- /dev/null +++ b/library/eden/sqlite.php @@ -0,0 +1,281 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +require_once dirname(__FILE__).'/sql/database.php'; +require_once dirname(__FILE__).'/sqlite/error.php'; +require_once dirname(__FILE__).'/sqlite/alter.php'; +require_once dirname(__FILE__).'/sqlite/create.php'; +require_once dirname(__FILE__).'/sqlite/utility.php'; + +/** + * Abstractly defines a layout of available methods to + * connect to and query a SQLite database. This class also + * lays out query building methods that auto renders a + * valid query the specific database will understand without + * actually needing to know the query language. Extending + * all SQL classes, comes coupled with loosely defined + * searching, collections and models. + * + * @package Eden + * @category sql + * @author Christian Blanquera cblanquera@openovate.com + */ +class Eden_Sqlite extends Eden_Sql_Database { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_file = NULL; + + protected $_model = self::MODEL; + protected $_collection = self::COLLECTION; + + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + public function __construct($file) { + //argument test + Eden_Sqlite_Error::i()->argument(1, 'string'); + $this->_file = $file; + } + + /* Public Methods + -------------------------------*/ + /** + * Returns the alter query builder + * + * @return Eden_Sql_Alter + */ + public function alter($name = NULL) { + //Argument 1 must be a string or null + Eden_Sqlite_Error::i()->argument(1, 'string', 'null'); + + return Eden_Sqlite_Alter::i($name); + } + /** + * Connects to the database + * + * @param array the connection options + * @return this + */ + public function connect(array $options = array()) { + $this->_connection = new PDO('sqlite:'.$this->_file); + $this->_connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + $this->trigger('connect'); + + return $this; + } + + /** + * Returns the create query builder + * + * @return Eden_Sql_Create + */ + public function create($name = NULL) { + //Argument 1 must be a string or null + Eden_Sqlite_Error::i()->argument(1, 'string', 'null'); + + return Eden_Sqlite_Create::i($name); + } + + /** + * Returns the columns and attributes given the table name + * + * @param the name of the table + * @return attay|false + */ + public function getColumns($table) { + //Argument 1 must be a string + Eden_Sqlite_Error::i()->argument(1, 'string'); + + $query = $this->utility()->showColumns($table); + $results = $this->query($query, $this->getBinds()); + + $columns = array(); + foreach($results as $column) { + $key = NULL; + if($column['pk'] == 1) { + $key = 'PRI'; + } + + $columns[] = array( + 'Field' => $column['name'], + 'Type' => $column['type'], + 'Default' => $column['dflt_value'], + 'Null' => $column['notnull'] != 1, + 'Key' => $key); + } + + return $columns; + } + + /** + * Peturns the primary key name given the table + * + * @param string table + * @return string + */ + public function getPrimaryKey($table) { + //Argument 1 must be a string + Eden_Sqlite_Error::i()->argument(1, 'string'); + + $query = $this->utility(); + $results = $this->getColumns($table, "`Key` = 'PRI'"); + return isset($results[0]['Field']) ? $results[0]['Field'] : NULL; + } + + /** + * Returns the whole enitre schema and rows + * of the current databse + * + * @return string + */ + public function getSchema() { + $backup = array(); + $tables = $this->getTables(); + foreach($tables as $table) { + $backup[] = $this->getBackup(); + } + + return implode("\n\n", $backup); + } + + /** + * Returns the whole enitre schema and rows + * of the current table + * + * @return string + */ + public function getTableSchema($table) { + //Argument 1 must be a string + Eden_Sqlite_Error::i()->argument(1, 'string'); + + $backup = array(); + //get the schema + $schema = $this->getColumns($table); + if(count($schema)) { + //lets rebuild this schema + $query = $this->create()->setName($table); + foreach($schema as $field) { + //first try to parse what we can from each field + $fieldTypeArray = explode(' ', $field['Type']); + $typeArray = explode('(', $fieldTypeArray[0]); + + $type = $typeArray[0]; + $length = str_replace(')', '', $typeArray[1]); + $attribute = isset($fieldTypeArray[1]) ? $fieldTypeArray[1] : NULL; + + $null = strtolower($field['Null']) == 'no' ? false : true; + + $increment = strtolower($field['Extra']) == 'auto_increment' ? true : false; + + //lets now add a field to our schema class + $q->addField($field['Field'], array( + 'type' => $type, + 'length' => $length, + 'attribute' => $attribute, + 'null' => $null, + 'default' => $field['Default'], + 'auto_increment' => $increment)); + + //set keys where found + switch($field['Key']) + { + case 'PRI': + $query->addPrimaryKey($field['Field']); + break; + case 'UNI': + $query->addUniqueKey($field['Field'], array($field['Field'])); + break; + case 'MUL': + $query->addKey($field['Field'], array($field['Field'])); + break; + } + } + + //store the query but dont run it + $backup[] = $query; + } + + //get the rows + $rows = $this->query($this->select->from($table)->getQuery()); + if(count($rows)) { + //lets build an insert query + $query = $this->insert($table); + foreach($rows as $index => $row) { + foreach($row as $key => $value) { + $query->set($key, $this->getBinds($value), $index); + } + } + + //store the query but dont run it + $backup[] = $query->getQuery(true); + } + + return implode("\n\n", $backup); + } + + /** + * Returns a listing of tables in the DB + * + * @param the like pattern + * @return attay|false + */ + public function getTables($like = NULL) { + //Argument 1 must be a string or null + Eden_Sqlite_Error::i()->argument(1, 'string', 'null'); + + $query = $this->utility(); + $like = $like ? $this->bind($like) : NULL; + $results = $this->query($query->showTables($like), $q->getBinds()); + $newResults = array(); + foreach($results as $result) { + foreach($result as $key => $value) { + $newResults[] = $value; + break; + } + } + + return $newResults; + } + + /** + * Returns the select query builder + * + * @return Eden_Sql_Select + */ + public function select($select = 'ROWID,*') { + //Argument 1 must be a string or array + Eden_Sqlite_Error::i()->argument(1, 'string', 'array'); + + return Eden_Sql_Select::i($select); + } + + /** + * Returns the alter query builder + * + * @return Eden_Sql_Utility + */ + public function utility() { + return Eden_Sqlite_Utility::i(); + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} + diff --git a/library/eden/sqlite/alter.php b/library/eden/sqlite/alter.php new file mode 100644 index 0000000..e646d2a --- /dev/null +++ b/library/eden/sqlite/alter.php @@ -0,0 +1,278 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Generates alter query string syntax + * + * @package Eden + * @category sql + * @author Christian Blanquera cblanquera@openovate.com + */ +class Eden_Sqlite_Alter extends Eden_Sql_Query { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_name = NULL; + protected $_changeFields = array(); + protected $_addFields = array(); + protected $_removeFields = array(); + protected $_addKeys = array(); + protected $_removeKeys = array(); + protected $_addUniqueKeys = array(); + protected $_removeUniqueKeys = array(); + protected $_addPrimaryKeys = array(); + protected $_removePrimaryKeys = array(); + + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + public function __construct($name = NULL) { + if(is_string($name)) { + $this->setName($name); + } + } + + /* Public Methods + -------------------------------*/ + /** + * Adds a field in the table + * + * @param string name + * @param array attributes + * @return this + */ + public function addField($name, array $attributes) { + //Argument 1 must be a string + Eden_Sqlite_Error::i()->argument(1, 'string'); + + $this->_addFields[$name] = $attributes; + return $this; + } + + /** + * Adds an index key + * + * @param string name + * @return this + */ + public function addForeignKey($name, $table, $key) { + //argument test + Eden_Sqlite_Error::i() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'string') //Argument 2 must be a string + ->argument(3, 'string'); //Argument 3 must be a string + + $this->_addKeys[$name] = array($table, $key); + return $this; + } + + /** + * Adds a unique key + * + * @param string name + * @return this + */ + public function addUniqueKey($name) { + //Argument 1 must be a string + Eden_Sqlite_Error::i()->argument(1, 'string'); + + $this->_addUniqueKeys[] = '"'.$name.'"'; + return $this; + } + + /** + * Changes attributes of the table given + * the field name + * + * @param string name + * @param array attributes + * @return this + */ + public function changeField($name, array $attributes) { + //Argument 1 must be a string + Eden_Sqlite_Error::i()->argument(1, 'string'); + + $this->_changeFields[$name] = $attributes; + return $this; + } + + /** + * Returns the string version of the query + * + * @param bool + * @return string + * @notes returns the query based on the registry + */ + public function getQuery($unbind = false) { + $fields = array(); + $table = '"'.$this->_name.'"'; + + foreach($this->_removeFields as $name) { + $fields[] = 'DROP "'.$name.'"'; + } + + foreach($this->_addFields as $name => $attr) { + $field = array('ADD "'.$name.'"'); + if(isset($attr['type'])) { + $field[] = isset($attr['length']) ? $attr['type'] . '('.$attr['length'].')' : $attr['type']; + } + + if(isset($attr['attribute'])) { + $field[] = $attr['attribute']; + } + + if(isset($attr['null'])) { + if($attr['null'] == false) { + $field[] = 'NOT NULL'; + } else { + $field[] = 'DEFAULT NULL'; + } + } + + if(isset($attr['default'])&& $attr['default'] !== false) { + if(!isset($attr['null']) || $attr['null'] == false) { + if(is_string($attr['default'])) { + $field[] = 'DEFAULT \''.$attr['default'] . '\''; + } else if(is_numeric($attr['default'])) { + $field[] = 'DEFAULT '.$attr['default']; + } + } + } + + $fields[] = implode(' ', $field); + } + + foreach($this->_changeFields as $name => $attr) { + $field = array('CHANGE "'.$name.'" "'.$name.'"'); + + if(isset($attr['name'])) { + $field = array('CHANGE "'.$name.'" "'.$attr['name'].'"'); + } + + if(isset($attr['type'])) { + $field[] = isset($attr['length']) ? $attr['type'] . '('.$attr['length'].')' : $attr['type']; + } + + if(isset($attr['attribute'])) { + $field[] = $attr['attribute']; + } + + if(isset($attr['null'])) { + if($attr['null'] == false) { + $field[] = 'NOT NULL'; + } else { + $field[] = 'DEFAULT NULL'; + } + } + + if(isset($attr['default'])&& $attr['default'] !== false) { + if(!isset($attr['null']) || $attr['null'] == false) { + if(is_string($attr['default'])) { + $field[] = 'DEFAULT \''.$attr['default'] . '\''; + } else if(is_numeric($attr['default'])) { + $field[] = 'DEFAULT '.$attr['default']; + } + } + } + + $fields[] = implode(' ', $field); + } + + foreach($this->_removeKeys as $key) { + $fields[] = 'DROP FOREIGN KEY "'.$key.'"'; + } + + foreach($this->_keys as $key => $value) { + $fields[] = 'ADD FOREIGN KEY "'. $key .'" REFERENCES '.$value[0].'('.$value[1].')'; + } + + foreach($this->_removeUniqueKeys as $key) { + $fields[] = 'DROP UNIQUE "'.$key.'"'; + } + + if(!empty($this->_addUniqueKeys)) { + $fields[] = 'ADD UNIQUE ('.implode(', ', $this->_addUniqueKeys).')'; + } + + $fields = implode(", \n", $fields); + + return sprintf( + 'ALTER TABLE %s %s;', + $table, $fields); + } + + /** + * Removes a field + * + * @param string name + * @return this + */ + public function removeField($name) { + //Argument 1 must be a string + Eden_Sqlite_Error::i()->argument(1, 'string'); + + $this->_removeFields[] = $name; + return $this; + } + + /** + * Removes an index key + * + * @param string name + * @return this + */ + public function removeForeignKey($name) { + //Argument 1 must be a string + Eden_Sqlite_Error::i()->argument(1, 'string'); + + $this->_removeKeys[] = $name; + return $this; + } + + /** + * Removes a unique key + * + * @param string name + * @return this + */ + public function removeUniqueKey($name) { + //Argument 1 must be a string + Eden_Sqlite_Error::i()->argument(1, 'string'); + + $this->_removeUniqueKeys[] = $name; + return $this; + } + + /** + * Sets the name of the table you wish to create + * + * @param string name + * @return this + */ + public function setName($name) { + //Argument 1 must be a string + Eden_Sqlite_Error::i()->argument(1, 'string'); + + $this->_name = $name; + return $this; + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/sqlite/create.php b/library/eden/sqlite/create.php new file mode 100644 index 0000000..a31bf9c --- /dev/null +++ b/library/eden/sqlite/create.php @@ -0,0 +1,227 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Generates create table query string syntax + * + * @package Eden + * @category sql + * @author Christian Blanquera cblanquera@openovate.com + */ +class Eden_Sqlite_Create extends Eden_Sql_Query { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_name = NULL; + protected $_comments = NULL; + protected $_fields = array(); + protected $_keys = array(); + protected $_uniqueKeys = array(); + protected $_primaryKeys = array(); + + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + public function __construct($name = NULL) { + if(is_string($name)) { + $this->setName($name); + } + } + + /* Public Methods + -------------------------------*/ + /** + * Adds a field in the table + * + * @param string name + * @param array attributes + * @return this + */ + public function addField($name, array $attributes) { + //Argument 1 must be a string + Eden_Sqlite_Error::i()->argument(1, 'string'); + + $this->_fields[$name] = $attributes; + return $this; + } + + /** + * Adds an index key + * + * @param string name + * @param array fields + * @return this + */ + public function addForeignKey($name, $table, $key) { + //argument test + Eden_Sqlite_Error::i() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'string') //Argument 2 must be a string + ->argument(3, 'string'); //Argument 3 must be a string + + $this->_keys[$name] = array($table, $key); + return $this; + } + + /** + * Adds a unique key + * + * @param string name + * @param array fields + * @return this + */ + public function addUniqueKey($name, array $fields) { + //Argument 1 must be a string + Eden_Sqlite_Error::i()->argument(1, 'string'); + + $this->_uniqueKeys[$name] = $fields; + return $this; + } + + /** + * Returns the string version of the query + * + * @param bool + * @return string + * @notes returns the query based on the registry + */ + public function getQuery($unbind = false) { + $table = '"'.$this->_name.'"'; + + $fields = array(); + foreach($this->_fields as $name => $attr) { + $field = array('"'.$name.'"'); + if(isset($attr['type'])) { + $field[] = isset($attr['length']) ? $attr['type'] . '('.$attr['length'].')' : $attr['type']; + } + + if(isset($attr['primary'])) { + $field[] = 'PRIMARY KEY'; + } + + if(isset($attr['attribute'])) { + $field[] = $attr['attribute']; + } + + if(isset($attr['null'])) { + if($attr['null'] == false) { + $field[] = 'NOT NULL'; + } else { + $field[] = 'DEFAULT NULL'; + } + } + + if(isset($attr['default'])&& $attr['default'] !== false) { + if(!isset($attr['null']) || $attr['null'] == false) { + if(is_string($attr['default'])) { + $field[] = 'DEFAULT \''.$attr['default'] . '\''; + } else if(is_numeric($attr['default'])) { + $field[] = 'DEFAULT '.$attr['default']; + } + } + } + + $fields[] = implode(' ', $field); + } + + $fields = !empty($fields) ? implode(', ', $fields) : ''; + + $uniques = array(); + foreach($this->_uniqueKeys as $key => $value) { + $uniques[] = 'UNIQUE "'. $key .'" ("'.implode('", "', $value).'")'; + } + + $uniques = !empty($uniques) ? ', ' . implode(", \n", $uniques) : ''; + + $keys = array(); + foreach($this->_keys as $key => $value) { + $keys[] = 'FOREIGN KEY "'. $key .'" REFERENCES '.$value[0].'('.$value[1].')'; + } + + $keys = !empty($keys) ? ', ' . implode(", \n", $keys) : ''; + + return sprintf( + 'CREATE TABLE %s (%s%s%s)', + $table, $fields, $unique, $keys); + } + + /** + * Sets comments + * + * @param string comments + * @return this + */ + public function setComments($comments) { + //Argument 1 must be a string + Eden_Sqlite_Error::i()->argument(1, 'string'); + + $this->_comments = $comments; + return $this; + } + + /** + * Sets a list of fields to the table + * + * @param array fields + * @return this + */ + public function setFields(array $fields) { + $this->_fields = $fields; + return $this; + } + + /** + * Sets a list of keys to the table + * + * @param array keys + * @return this + */ + public function setForiegnKeys(array $keys) { + $this->_keys = $keys; + return $this; + } + + /** + * Sets the name of the table you wish to create + * + * @param string name + * @return this + */ + public function setName($name) { + //Argument 1 must be a string + Eden_Sqlite_Error::i()->argument(1, 'string'); + + $this->_name = $name; + return $this; + } + + /** + * Sets a list of unique keys to the table + * + * @param array uniqueKeys + * @return this + */ + public function setUniqueKeys(array $uniqueKeys) { + $this->_uniqueKeys = $uniqueKeys; + return $this; + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/sqlite/error.php b/library/eden/sqlite/error.php new file mode 100644 index 0000000..16e9a41 --- /dev/null +++ b/library/eden/sqlite/error.php @@ -0,0 +1,39 @@ + +/* + * This file is part of the Eden package. + * (c) 2010-2012 Christian Blanquera + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * MySql Errors + * + * @package Eden + * @category sql + * @author Christian Blanquera cblanquera@openovate.com + */ +class Eden_Sqlite_Error extends Eden_Error { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i($message = NULL, $code = 0) { + $class = __CLASS__; + return new $class($message, $code); + } + + /* Public Methods + -------------------------------*/ + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/sqlite/utility.php b/library/eden/sqlite/utility.php new file mode 100644 index 0000000..5e21e8d --- /dev/null +++ b/library/eden/sqlite/utility.php @@ -0,0 +1,120 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Generates utility query strings + * + * @package Eden + * @category sql + * @author Christian Blanquera cblanquera@openovate.com + */ +class Eden_Sqlite_Utility extends Eden_Sql_Query +{ + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_query = NULL; + + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + /* Public Methods + -------------------------------*/ + /** + * Query for dropping a table + * + * @param string the name of the table + * @return this + */ + public function dropTable($table) { + //Argument 1 must be a string + Eden_Sqlite_Error::i()->argument(1, 'string'); + + $this->_query = 'DROP TABLE "' . $table .'"'; + return $this; + } + + /** + * Returns the string version of the query + * + * @return string + */ + public function getQuery() { + return $this->_query.';'; + } + + /** + * Query for renaming a table + * + * @param string the name of the table + * @param string the new name of the table + * @return this + */ + public function renameTable($table, $name) { + //Argument 1 must be a string, 2 must be string + Eden_Sqlite_Error::i()->argument(1, 'string')->argument(2, 'string'); + + $this->_query = 'RENAME TABLE "' . $table . '" TO "' . $name . '"'; + return $this; + } + /** + * Query for showing all columns of a table + * + * @param string the name of the table + * @return this + */ + public function showColumns($table) { + //Argument 1 must be a string + Eden_Sqlite_Error::i()->argument(1, 'string'); + + + $this->_query = 'PRAGMA table_info('.$table.')'; + return $this; + } + + /** + * Query for showing all tables + * + * @param string like + * @return this + */ + public function showTables() { + $this->_query = 'SELECT * FROM dbname.sqlite_master WHERE type=\'table\''; + return $this; + } + + /** + * Query for truncating a table + * + * @param string the name of the table + * @return this + */ + public function truncate($table) { + //Argument 1 must be a string + Eden_Sqlite_Error::i()->argument(1, 'string'); + + $this->_query = 'TRUNCATE "' . $table .'"'; + return $this; + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/template.php b/library/eden/template.php new file mode 100755 index 0000000..73fb8e8 --- /dev/null +++ b/library/eden/template.php @@ -0,0 +1,129 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +require_once dirname(__FILE__).'/class.php'; + +/** + * General available methods for common templating procedures + * + * @package Eden + * @category utility + * @author Christian Blanquera cblanquera@openovate.com + */ +class Eden_Template extends Eden_Class { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_data = array(); + + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + /* Public Methods + -------------------------------*/ + /** + * Sets template variables + * + * @param array|string + * @param mixed + * @return this + */ + public function set($data, $value = NULL) { + Eden_Template_Error::i()->argument(1, 'array', 'string'); + + if(is_array($data)) { + $this->_data = $data; + return $this; + } + + $this->_data[$data] = $value; + + return $this; + } + + /** + * Simple string replace template parser + * + * @param *string template file + * @return string + */ + public function parseString($string) { + Eden_Template_Error::i()->argument(1, 'string'); + foreach($this->_data as $key => $value) { + $string = str_replace($key, $value, $string); + } + + return $string; + } + + /** + * For PHP templates, this will transform the given document to an actual page or partial + * + * @param *string template file or PHP template string + * @param bool whether to evaluate the first argument + * @return string + */ + public function parsePhp($____file, $___evalString = false) { + Eden_Template_Error::i() + ->argument(1, $____file, 'string') + ->argument(2, $___evalString, 'bool'); + + extract($this->_data, EXTR_SKIP); // Extract the values to a local namespace + + if($___evalString) { + return eval('?>'.$___file.' +require_once dirname(__FILE__).'/class.php'; +require_once dirname(__FILE__).'/timezone/validation.php'; +require_once dirname(__FILE__).'/timezone/error.php'; + +/** + * Timezone convert-o-matic + * + * @package Eden + * @category utility + * @author Christian Blanquera cblanquera@openovate.com + */ +class Eden_Timezone extends Eden_Class { + /* Constants + -------------------------------*/ + const GMT = 'GMT'; + const UTC = 'UTC'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + public function __construct($zone, $time = NULL) { + Eden_Timezone_Error::i() + ->argument(1, 'string') + ->argument(1, 'location', 'utc', 'abbr') + ->argument(2, 'int', 'string', 'null'); + + if(is_null($time)) { + $time = time(); + } + + $this->_offset = $this->_getOffset($zone); + $this->setTime($time); + } + + /* Public Methods + -------------------------------*/ + + /** + * Convert current time set here to another time zone + * + * @param string valid UTC, GMT, PHP Location or TZ Abbreviation + * @param string|null + * @return string|int + */ + public function convertTo($zone, $format = NULL) { + Eden_Timezone_Error::i() + ->argument(1, 'string') + ->argument(1, 'location', 'utc', 'abbr') + ->argument(2, 'string', 'null'); + + $time = $this->_time + $this->_getOffset($zone); + + if(!is_null($format)) { + return date($format, $time); + } + + return $time; + } + + /** + * Returns the GMT Format + * + * @return string + */ + public function getGMT($prefix = self::GMT) { + Eden_Timezone_Error::i()->argument(1, 'string'); + list($hour, $minute, $sign) = $this->_getUtcParts($this->_offset); + return $prefix.$sign.$hour.$minute; + } + + /** + * Returns a list of GMT formats and dates in a 24 hour period + * + * @param string + * @param int + * @param string|null + * @return array + */ + public function getGMTDates($format, $interval = 30, $prefix = self::GMT) { + Eden_Timezone_Error::i() + ->argument(1, 'string') + ->argument(2, 'int') + ->argument(3, 'string', 'null'); + + $offsets = $this->getOffsetDates($format, $interval); + $dates = array(); + + foreach($offsets as $offset => $date) { + list($hour, $minute, $sign) = $this->_getUtcParts($offset); + $gmt = $prefix.$sign.$hour.$minute; + $dates[$gmt] = $date; + } + + return $dates; + } + + /** + * Returns the current offset of this timezone + * + * @return int + */ + public function getOffset() { + return $this->_offset; + } + + /** + * Returns a list of offsets and dates in a 24 hour period + * + * @param string + * @param int + * @return array + */ + public function getOffsetDates($format, $interval = 30) { + Eden_Timezone_Error::i() + ->argument(1, 'string') + ->argument(2, 'int'); + + $dates = array(); + $interval *= 60; + + for($i=-12*3600; $i <= (12*3600); $i+=$interval) { + $time = $this->_time + $i; + $dates[$i] = date($format, $time); + } + + return $dates; + } + + /** + * Returns the time or date + * + * @return string|null + */ + public function getTime($format = NULL) { + Eden_Timezone_Error::i()->argument(1, 'string', 'null'); + + $time = $this->_time + $this->_offset; + + if(!is_null($format)) { + return date($format, $time); + } + + return $time; + } + + /** + * Returns the UTC Format + * + * @return string + */ + public function getUTC($prefix = self::UTC) { + Eden_Timezone_Error::i()->argument(1, 'string'); + list($hour, $minute, $sign) = $this->_getUtcParts($this->_offset); + return $prefix.$sign.$hour.':'.$minute; + } + + /** + * Returns a list of UTC formats and dates in a 24 hour period + * + * @param string + * @param int + * @param string|null + * @return array + */ + public function getUTCDates($format, $interval = 30, $prefix = self::UTC) { + Eden_Timezone_Error::i() + ->argument(1, 'string') + ->argument(2, 'int') + ->argument(3, 'string', 'null'); + + $offsets = $this->getOffsetDates($format, $interval); + $dates = array(); + + foreach($offsets as $offset => $date) { + list($hour, $minute, $sign) = $this->_getUtcParts($offset); + $utc = $prefix.$sign.$hour.':'.$minute; + $dates[$utc] = $date; + } + + return $dates; + } + + /** + * Sets a new time + * + * @param int|string + * @return this + */ + public function setTime($time) { + Eden_Timezone_Error::i()->argument(1, 'int', 'string'); + if(is_string($time)) { + $time = strtotime($time); + } + + $this->_time = $time - $this->_offset; + return $this; + } + + /** + * Returns timezone's validation methods + * + * @return Eden_Timezone_Validation + */ + public function validation() { + return Eden_Timezone_Validation::i(); + } + + /* Protected Methods + -------------------------------*/ + protected function _getOffset($zone) { + if($this->validation()->isLocation($zone)) { + return $this->_getOffsetFromLocation($zone); + } + + if($this->validation()->isUtc($zone)) { + return $this->_getOffsetFromUtc($zone); + } + + if($this->validation()->isAbbr($zone)) { + return $this->_getOffsetFromAbbr($zone); + } + + return 0; + } + + protected function _getOffsetFromAbbr($zone) { + $zone = timezone_name_from_abbr(strtolower($zone)); + return $this->_getOffsetFromLocation($zone); + } + + protected function _getOffsetFromLocation($zone) { + $zone = new DateTimeZone($zone); + $gmt = new DateTimeZone(self::GMT); + + return $zone->getOffset(new DateTime('now', $gmt)); + } + + protected function _getOffsetFromUtc($zone) { + $zone = str_replace(array('GMT','UTC'), '', $zone); + $zone = str_replace(':', '', $zone); + + $add = $zone[0] == '+'; + $zone = substr($zone, 1); + + switch(strlen($zone)) { + case 1: + case 2: + return $zone * 3600 * ($add?1:-1); + case 3: + $hour = substr($zone, 0, 1) * 3600; + $minute = substr($zone, 1) * 60; + return ($hour+$minute) * ($add?1:-1); + case 4: + $hour = substr($zone, 0, 2) * 3600; + $minute = substr($zone, 2) * 60; + return ($hour+$minute) * ($add?1:-1); + + } + + return 0; + } + + /* Private Methods + -------------------------------*/ + private function _getUtcParts($offset) { + $minute = '0'.(floor(abs($offset/60)) % 60); + + return array( + floor(abs($offset/3600)), + substr($minute, strlen($minute)-2), + $offset < 0 ? '-':'+'); + } +} \ No newline at end of file diff --git a/library/eden/timezone/error.php b/library/eden/timezone/error.php new file mode 100644 index 0000000..48cf8a5 --- /dev/null +++ b/library/eden/timezone/error.php @@ -0,0 +1,55 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Timezone Errors + * + * @package Eden + * @category utility + * @author Christian Blanquera cblanquera@openovate.com + */ +class Eden_Timezone_Error extends Eden_Error { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i($message = NULL, $code = 0) { + $class = __CLASS__; + return new $class($message, $code); + } + + /* Public Methods + -------------------------------*/ + /* Protected Methods + -------------------------------*/ + protected function _isValid($type, $data) { + $valid = Eden_Timezone_Validation::i(); + + switch($type) { + case 'location': + return $valid->isLocation($data); + case 'utc': + return $valid->isUtc($data); + case 'abbr': + return $valid->isAbbr($data); + default: break; + } + + return parent::_isValid($type, $data); + } + + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/timezone/validation.php b/library/eden/timezone/validation.php new file mode 100644 index 0000000..4502cab --- /dev/null +++ b/library/eden/timezone/validation.php @@ -0,0 +1,50 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Timezone Validation + * + * @package Eden + * @category utility + * @author Christian Blanquera cblanquera@openovate.com + */ +class Eden_Timezone_Validation extends Eden_Class { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getSingleton(__CLASS__); + } + + /* Public Methods + -------------------------------*/ + public function isAbbr($value) { + return preg_match('/^[A-Z]{1,5}$/', $value); + } + + public function isLocation($value) { + return in_array($value, DateTimeZone::listIdentifiers()); + } + + public function isUtc($value) { + return preg_match('/^(GMT|UTC){0,1}(\-|\+)[0-9]{1,2}(\:{0,1}[0-9]{2}){0,1}$/', $value); + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/tumblr.php b/library/eden/tumblr.php new file mode 100644 index 0000000..5d7f031 --- /dev/null +++ b/library/eden/tumblr.php @@ -0,0 +1,106 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +require_once dirname(__FILE__).'/oauth.php'; +require_once dirname(__FILE__).'/tumblr/error.php'; +require_once dirname(__FILE__).'/tumblr/base.php'; +require_once dirname(__FILE__).'/tumblr/oauth.php'; +require_once dirname(__FILE__).'/tumblr/blog.php'; +require_once dirname(__FILE__).'/tumblr/user.php'; + +/** + * Tumblr API factory. This is a factory class with + * methods that will load up different tumblr classes. + * Tumblr classes are organized as described on their + * developer site: blog and user. + * + * @package Eden + * @category tumblr + * @author Christian Symon M. Buenavista sbuenavista@openovate.com + */ +class Eden_Tumblr extends Eden_Class { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function i() { + return self::_getSingleton(__CLASS__); + } + + /* Magic + -------------------------------*/ + /* Public Methods + -------------------------------*/ + /** + * Returns tumblr auth method + * + * @param *string + * @param *string + * @return Eden_Tumblr_Oauth + */ + public function auth($key, $secret) { + //Argument test + Eden_Tumblr_Error::i() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'string'); //Argument 2 must be a string + + return Eden_Tumblr_Oauth::i($key, $secret); + } + + /** + * Returns tumblr blog method + * + * @param *string + * @param *string + * @param *string + * @param *string + * @return Eden_Tumblr_Blog + */ + public function blog($consumerKey, $consumerSecret, $accessToken, $accessSecret) { + //argument test + Eden_Tumblr_Error::i() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'string') //Argument 2 must be a string + ->argument(3, 'string') //Argument 3 must be a string + ->argument(4, 'string'); //Argument 4 must be a string + + return Eden_Tumblr_Blog::i($consumerKey, $consumerSecret, $accessToken, $accessSecret); + } + + /** + * Returns tumblr blog method + * + * @param *string + * @param *string + * @param *string + * @param *string + * @return Eden_Tumblr_User + */ + public function user($consumerKey, $consumerSecret, $accessToken, $accessSecret) { + //argument test + Eden_Tumblr_Error::i() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'string') //Argument 2 must be a string + ->argument(3, 'string') //Argument 3 must be a string + ->argument(4, 'string'); //Argument 4 must be a string + + return Eden_Tumblr_User::i($consumerKey, $consumerSecret, $accessToken, $accessSecret); + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/tumblr/base.php b/library/eden/tumblr/base.php new file mode 100644 index 0000000..183ef01 --- /dev/null +++ b/library/eden/tumblr/base.php @@ -0,0 +1,226 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Tumblr base + * + * @package Eden + * @category tumblr + * @author Christian Blanquera cblanquera@openovate.com + */ +class Eden_Tumblr_Base extends Eden_Oauth_Base { + /* Constants + -------------------------------*/ + const API_KEY = 'api_key'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_consumerKey = NULL; + protected $_consumerSecret = NULL; + protected $_accessToken = NULL; + protected $_accessSecret = NULL; + + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + /* Magic + -------------------------------*/ + public function __construct($consumerKey, $consumerSecret, $accessToken, $accessSecret) { + //argument test + Eden_Tumblr_Error::i() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'string') //Argument 2 must be a string + ->argument(3, 'string') //Argument 3 must be a string + ->argument(4, 'string'); //Argument 4 must be a string + + $this->_consumerKey = $consumerKey; + $this->_consumerSecret = $consumerSecret; + $this->_accessToken = $accessToken; + $this->_accessSecret = $accessSecret; + + } + /* Public Methods + -------------------------------*/ + /** + * Returns the meta of the last call + * + * @return array + */ + public function getMeta($key = NULL) { + Eden_Tumblr_Error::i()->argument(1, 'string', 'null'); + + if(isset($this->_meta[$key])) { + return $this->_meta[$key]; + } + + return $this->_meta; + } + + /* Protected Methods + -------------------------------*/ + protected function _accessKey($array) { + foreach($array as $key => $val) { + if(is_array($val)) { + $array[$key] = $this->_accessKey($val); + } + //if value is null + if(is_null($val) || empty($val)) { + //remove it to query + unset($array[$key]); + } else if($val === false) { + $array[$key] = 0; + } else if($val === true) { + $array[$key] = 1; + } + + } + + return $array; + } + + protected function _reset() { + //foreach this as key => value + foreach ($this as $key => $value) { + //if the value of key is not array + if(!is_array($this->$key)) { + //if key name starts at underscore, probably it is protected variable + if(preg_match('/^_/', $key)) { + //if the protected variable is not equal to token + //we dont want to unset the access token + if($key != '_token') { + //reset all protected variables that currently use + $this->$key = NULL; + } + } + } + } + + return $this; + } + + protected function _getResponse($url, array $query = array()) { + //if needed, add developer id to the query + if(!is_null($this->_consumerKey)) { + $query[self::API_KEY] = $this->_consumerKey; + } + + //prevent sending fields with no value + $query = $this->_accessKey($query); + //build url query + $url = $url.'?'.http_build_query($query); + //set curl + $curl = Eden_Curl::i() + ->setUrl($url) + ->verifyHost(false) + ->verifyPeer(false) + ->setTimeout(60); + //get response from curl + $response = $curl->getJsonResponse(); + //get curl infomation + $this->_meta['url'] = $url; + $this->_meta['query'] = $query; + $this->_meta['curl'] = $curl->getMeta(); + $this->_meta['response'] = $response; + + //reset variables + $this->_reset(); + + return $response; + } + + protected function _getAuthResponse($url, array $query = array()) { + //prevent sending fields with no value + $query = $this->_accessKey($query); + //make oauth signature + $rest = Eden_Oauth::i() + ->consumer($url, $this->_consumerKey, $this->_consumerSecret) + ->useAuthorization() + ->setToken($this->_accessToken, $this->_accessSecret) + ->setSignatureToHmacSha1(); + //get response from curl + $response = $rest->getResponse($query); + + //get curl infomation + $this->_meta['url'] = $url; + $this->_meta['query'] = $query; + $this->_meta['response'] = $response; + + //reset variables + $this->_reset(); + + return $response; + } + + protected function _post($url, array $query = array()) { + //prevent sending fields with no value + $query = $this->_accessKey($query); + //set headers + $headers = array(); + $headers[] = Eden_Oauth_Consumer::POST_HEADER; + //make oauth signature + $rest = Eden_Oauth::i() + ->consumer($url, $this->_consumerKey, $this->_consumerSecret) + ->setMethodToPost() + ->setToken($this->_accessToken, $this->_accessSecret) + ->setSignatureToHmacSha1(); + + //get the authorization parameters as an array + $signature = $rest->getSignature($query); + $authorization = $rest->getAuthorization($signature, false); + $authorization = $this->_buildQuery($authorization); + //if query is in array + if(is_array($query)) { + //build a http query + $query = $this->_buildQuery($query); + } + + //determine the conector + $connector = NULL; + + //if there is no question mark + if(strpos($url, '?') === false) { + $connector = '?'; + //if the redirect doesn't end with a question mark + } else if(substr($url, -1) != '?') { + $connector = '&'; + } + + //now add the authorization to the url + $url .= $connector.$authorization; + + //set curl + $curl = Eden_Curl::i() + ->verifyHost(false) + ->verifyPeer(false) + ->setUrl($url) + ->setPost(true) + ->setPostFields($query) + ->setHeaders($headers); + + //get the response + $response = $curl->getJsonResponse(); + + $this->_meta = $curl->getMeta(); + $this->_meta['url'] = $url; + $this->_meta['authorization'] = $authorization; + $this->_meta['headers'] = $headers; + $this->_meta['query'] = $query; + + //reset variables + $this->_reset(); + + return $response; + } + + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/tumblr/blog.php b/library/eden/tumblr/blog.php new file mode 100644 index 0000000..be801e9 --- /dev/null +++ b/library/eden/tumblr/blog.php @@ -0,0 +1,595 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Tumblr blog + * + * @package Eden + * @category tumblr + * @author Christian Symon M. Buenavista sbuenavista@openovate.com + */ +class Eden_Tumblr_Blog extends Eden_Tumblr_Base { + /* Constants + -------------------------------*/ + const URL_BLOG_GET = 'http://api.tumblr.com/v2/blog/%s/info'; + const URL_BLOG_GET_AVATAR = 'http://api.tumblr.com/v2/blog/%s/avatar/%s'; + const URL_BLOG_GET_FOLLOWER = 'http://api.tumblr.com/v2/blog/%s/followers'; + const URL_BLOG_GET_POST = 'http://api.tumblr.com/v2/blog/%s/posts/%s'; + const URL_BLOG_GET_QUEUE = 'http://api.tumblr.com/v2/blog/%s/posts/queue'; + const URL_BLOG_GET_DRAFT = 'http://api.tumblr.com/v2/blog/%s/posts/draft'; + const URL_BLOG_GET_SUBMISSION = 'http://api.tumblr.com/v2/blog/%s/posts/submission'; + + const URL_BLOG_CREATE_POST = 'http://api.tumblr.com/v2/blog/%s/post'; + const URL_BLOG_DELETE_POST = 'http://api.tumblr.com/v2/blog/%s/post/delete'; + const URL_BLOG_EDIT_POST = 'api.tumblr.com/v2/blog/%s/post/edit'; + const URL_BLOG_REBLOG_POST = 'api.tumblr.com/v2/blog/%s/post/reblog'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_size = 64; + protected $_postType = 'text'; + protected $_limit = NULL; + protected $_offset = NULL; + protected $_postId = NULL; + protected $_tag = NULL; + protected $_reblogInfo = NULL; + protected $_notesInfo = NULL; + protected $_state = NULL; + protected $_format = NULL; + protected $_slug = NULL; + protected $_caption = NULL; + protected $_link = NULL; + protected $_source = NULL; + protected $_data = NULL; + protected $_description = NULL; + + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + /* Public Methods + -------------------------------*/ + /** + * The size of the avatar (square, + * one value for both length and width). + * Must be one of the values: + * 16, 24, 30, 40, 48, 64, 96, 128, 512 + * + * @param integer + * @return this + */ + public function setSize($size) { + //Argument 1 must be a integer + Eden_Tumblr_Error::i()->argument(1, 'int'); + $this->_size = $size; + + return $this; + + } + + /** + * The number of results to return: 1–20, inclusive + * + * @param integer + * @return this + */ + public function setLimit($limit) { + //Argument 1 must be a integer + Eden_Tumblr_Error::i()->argument(1, 'int'); + $this->_limit = $limit; + + return $this; + + } + + /** + * Result to start at + * + * @param integer + * @return this + */ + public function setOffset($offset) { + //Argument 1 must be a integer + Eden_Tumblr_Error::i()->argument(1, 'int'); + $this->_offset = $offset; + + return $this; + + } + + /** + * A specific post ID. Returns the single post + * specified or (if not found) a 404 error. + * + * @param integer + * @return this + */ + public function setPostId($postId) { + //Argument 1 must be a integer + Eden_Tumblr_Error::i()->argument(1, 'int'); + $this->_postId = $postId; + + return $this; + + } + + /** + * The type of post to return. Specify one of the following: + * "text, quote, link, answer, video, audio, photo, chat" + * + * @param string + * @return this + */ + public function setPostType($postType) { + //Argument 1 must be a string + Eden_Tumblr_Error::i()->argument(1, 'string'); + $this->_postType = $postType; + + return $this; + + } + + /** + * Limits the response to posts with the specified tag + * + * @param string + * @return this + */ + public function setTag($tag) { + //Argument 1 must be a string + Eden_Tumblr_Error::i()->argument(1, 'string'); + $this->_tag = $tag; + + return $this; + + } + + /** + * The state of the post. Specify one of the following: + * published, draft, queue, private + * + * @param string + * @return this + */ + public function setState($state) { + //Argument 1 must be a string + Eden_Tumblr_Error::i()->argument(1, 'string'); + $this->_state = $state; + + return $this; + + } + + /** + * Sets the format type of post. Supported formats + * are: html & markdown + * + * @param string + * @return this + */ + public function setFormat($format) { + //Argument 1 must be a string + Eden_Tumblr_Error::i()->argument(1, 'string'); + $this->_format = $format; + + return $this; + + } + + /** + * Add a short text summary to the end of the post URL + * + * @param string + * @return this + */ + public function setSlug($slug) { + //Argument 1 must be a string + Eden_Tumblr_Error::i()->argument(1, 'string'); + $this->_slug = $slug; + + return $this; + + } + + /** + * The user-supplied caption, HTML allowed + * + * @param string + * @return this + */ + public function setCaption($caption) { + //Argument 1 must be a string + Eden_Tumblr_Error::i()->argument(1, 'string'); + $this->_caption = $caption; + + return $this; + + } + + /** + * The "click-through URL" for the photo + * + * @param url + * @return this + */ + public function setLink($link) { + //Argument 1 must be a url + Eden_Tumblr_Error::i()->argument(1, 'url'); + $this->_link = $link; + + return $this; + + } + + /** + * A user-supplied description, HTML allowed + * + * @param string + * @return this + */ + public function setDescription($description) { + //Argument 1 must be a string + Eden_Tumblr_Error::i()->argument(1, 'string'); + $this->_description = $description; + + return $this; + + } + /** + * Returns general information about the blog, + * such as the title, number of posts, and other high-level data. + * + * @param string The standard or custom blog hostname + * @return this + */ + public function getInfo($baseHostName) { + //Argument 1 must be a string + Eden_Tumblr_Error::i()->argument(1, 'string'); + + return $this->_getResponse(sprintf(self::URL_BLOG_GET, $baseHostName)); + } + + /** + * Returns users Avatar + * + * @param string The standard or custom blog hostname + * @return this + */ + public function getAvatar($baseHostName) { + //Argument 1 must be a string + Eden_Tumblr_Error::i()->argument(1, 'string'); + + return $this->_getResponse(sprintf(self::URL_BLOG_GET_AVATAR, $baseHostName, $this->_size)); + } + + /** + * Returns users follower + * + * @param string The standard or custom blog hostname + * @return this + */ + public function getFollower($baseHostName) { + //Argument 1 must be a string + Eden_Tumblr_Error::i()->argument(1, 'string'); + + //populate fields + $query = array( + 'limit' => $this->_limit, //optional + 'offset' => $this->_offset); //optional + + return $this->_getAuthResponse(sprintf(self::URL_BLOG_GET_FOLLOWER, $baseHostName)); + } + + /** + * Retrieve Published Posts + * + * @param string The standard or custom blog hostname + * @return this + */ + public function getPost($baseHostName) { + //Argument 1 must be a string + Eden_Tumblr_Error::i()->argument(1, 'string'); + + //populate fields + $query = array( + 'id' => $this->_postId, //optional + 'tag' => $this->_tag, //optional + 'limit' => $this->_limit, //optional + 'offset' => $this->_offset, //optional + 'reblog_info' => $this->_reblogInfo, //optional + 'notes_info' => $this->_notesInfo); //optional + + return $this->_getResponse(sprintf(self::URL_BLOG_GET_POST, $baseHostName, $this->_postType), $query); + } + + /** + * Retrieve Queued Posts + * + * @param string The standard or custom blog hostname + * @return this + */ + public function getQueuedPost($baseHostName) { + //Argument 1 must be a string + Eden_Tumblr_Error::i()->argument(1, 'string'); + + return $this->_getAuthResponse(sprintf(self::URL_BLOG_GET_QUEUE, $baseHostName)); + } + + /** + * Retrieve Draft Posts + * + * @param string The standard or custom blog hostname + * @return this + */ + public function getDraftPost($baseHostName) { + //Argument 1 must be a string + Eden_Tumblr_Error::i()->argument(1, 'string'); + + return $this->_getAuthResponse(sprintf(self::URL_BLOG_GET_DRAFT, $baseHostNamee)); + } + + /** + * Retrieve Submission Posts + * + * @param string The standard or custom blog hostname + * @return this + */ + public function getSubmissionPost($baseHostName) { + //Argument 1 must be a string + Eden_Tumblr_Error::i()->argument(1, 'string'); + + return $this->_getAuthResponse(sprintf(self::URL_BLOG_GET_SUBMISSION, $baseHostName)); + } + + /** + * Create a New Blog Text Post + * + * @param string The standard or custom blog hostname + * @param string The full post body, HTML allowed + * @param string|null Title of the post, HTML entities must be escaped + * @return this + */ + public function postText($baseHostName, $body, $title = NULL) { + //Argument test + Eden_Tumblr_Error::i() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'string') //Argument 2 must be a string + ->argument(3, 'string', 'null'); //Argument 3 must be a string or null + + $query = array( + 'type' => 'text', + 'body' => $body, + 'title' => $title, //optional + 'state' => $this->_state, //optional + 'tags' => $this->_tag, //optional + 'format' => $this->_format, //optional + 'slug' => $this->_slug); //optional + + return $this->_post(sprintf(self::URL_BLOG_CREATE_POST, $baseHostName),$query); + } + + /** + * Create a New Blog Photo Post + * Either source or data is required + * + * @param string The standard or custom blog hostname + * @param string|null The photo source URL + * @param string|null One or more image files (submit multiple times to create a slide show) + * @return this + */ + public function postPhoto($baseHostName, $source = NULL, $data = NULL) { + //Argument test + Eden_Tumblr_Error::i() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'string', 'null') //Argument 2 must be a string or null + ->argument(3, 'string', 'null'); //Argument 3 must be a string or null + + $query = array( + 'type' => 'photo', + 'source' => $source, + 'data' => $data, + 'caption' => $this->_caption, //optional + 'link' => $this->_link, //optional + 'state' => $this->_state, //optional + 'tags' => $this->_tag, //optional + 'format' => $this->_format, //optional + 'slug' => $this->_slug); //optional + + return $this->_post(sprintf(self::URL_BLOG_CREATE_POST, $baseHostName),$query); + } + + /** + * Create a New Blog Quote Post + * + * @param string The standard or custom blog hostname + * @param string The full text of the quote, HTML entities must be escpaed + * @param string|null One or more image files (submit multiple times to create a slide show) + * @return this + */ + public function postQuote($baseHostName ,$quote, $source = NULL) { + //Argument test + Eden_Tumblr_Error::i() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'string') //Argument 2 must be a string + ->argument(3, 'string', 'null'); //Argument 3 must be a string or null + + $query = array( + 'type' => 'quote', + 'source' => $source, + 'quote' => $quote, + 'state' => $this->_state, //optional + 'tags' => $this->_tag, //optional + 'format' => $this->_format, //optional + 'slug' => $this->_slug); //optional + + return $this->_post(sprintf(self::URL_BLOG_CREATE_POST, $baseHostName),$query); + } + + /** + * Create a New Blog link Post + * + * @param string The standard or custom blog hostname + * @param string The link + * @return this + */ + public function postLink($baseHostName ,$url) { + //Argument test + Eden_Tumblr_Error::i() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'string'); //Argument 2 must be a string + + $query = array( + 'type' => 'link', + 'url' => $url, + 'title' => $this->_title, //optional + 'description' => $this->_description, //optional + 'state' => $this->_state, //optional + 'tags' => $this->_tag, //optional + 'format' => $this->_format, //optional + 'slug' => $this->_slug); //optional + + return $this->_post(sprintf(self::URL_BLOG_CREATE_POST, $baseHostName),$query); + } + + /** + * Create a New Blog Chat Post + * + * @param string The standard or custom blog hostname + * @param string The text of the conversation/chat, with dialogue labels (no HTML) + * @return this + */ + public function postChat($baseHostName ,$conversation) { + //Argument test + Eden_Tumblr_Error::i() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'string'); //Argument 2 must be a string + + $query = array( + 'type' => 'chat', + 'conversation' => $conversation, + 'state' => $this->_state, //optional + 'tags' => $this->_tag, //optional + 'format' => $this->_format, //optional + 'slug' => $this->_slug); //optional + + return $this->_post(sprintf(self::URL_BLOG_CREATE_POST, $baseHostName),$query); + } + + /** + * Create a New Blog Audio Post + * either external_url or data is requred + * + * @param string The standard or custom blog hostname + * @param string|null The URL of the site that hosts the audio file (not tumblr) + * @param string|null An audio file + * @return this + */ + public function postAudio($baseHostName ,$externalUrl = NULL, $data = NULL) { + //Argument test + Eden_Tumblr_Error::i() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'string', 'null') //Argument 2 must be a string or null + ->argument(3, 'string', 'null'); //Argument 3 must be a string or null + + $query = array( + 'type' => 'audio', + 'external_url' => $externalUrl, + 'data' => $data, + 'caption' => $this->_caption, + 'state' => $this->_state, //optional + 'tags' => $this->_tag, //optional + 'format' => $this->_format, //optional + 'slug' => $this->_slug); //optional + + return $this->_post(sprintf(self::URL_BLOG_CREATE_POST, $baseHostName),$query); + } + + /** + * Create a New Blog Video Post + * either external_url or data is requred + * + * @param string The standard or custom blog hostname + * @param string|null HTML embed code for the video + * @param string|null An audio file + * @return this + */ + public function postVideo($baseHostName ,$embed = NULL, $data = NULL) { + //Argument test + Eden_Tumblr_Error::i() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'string', 'null') //Argument 2 must be a string or null + ->argument(3, 'string', 'null'); //Argument 3 must be a string or null + + $query = array( + 'type' => 'video', + 'embed' => $embed, + 'data' => $data, + 'caption' => $this->_caption, + 'state' => $this->_state, //optional + 'tags' => $this->_tag, //optional + 'format' => $this->_format, //optional + 'slug' => $this->_slug); //optional + + return $this->_post(sprintf(self::URL_BLOG_CREATE_POST, $baseHostName),$query); + } + + /** + * Reblog a Post + * + * @param string The standard or custom blog hostname + * @param string The ID of the reblogged post on tumblelog + * @param string The reblog key for the reblogged post – get the reblog key with a /posts request + * @param string|null A comment added to the reblogged post + * @return this + */ + public function editPost($baseHostName ,$postId, $reblogKey, $comment = NULL) { + //Argument test + Eden_Tumblr_Error::i() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'string') //Argument 2 must be a string + ->argument(3, 'string') //Argument 3 must be a string + ->argument(4, 'string', 'null'); //Argument 4 must be a string or null + + $query = array( + 'id' => $postId, + 'reblog_key' => $reblogKey, + 'comment' => $comment); + + return $this->_post(sprintf(self::URL_BLOG_REBLOG_POST, $baseHostName),$query); + } + + /** + * Delete Post + * + * @param string The ID of the post to delete + * @param string The standard or custom blog hostname + * @return this + */ + public function delete($baseHostName, $postId) { + //Argument test + Eden_Tumblr_Error::i() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'string'); //Argument 2 must be a string + + //populate fields + $query = array('id' => $postId); + + return $this->_post(sprintf(self::URL_BLOG_DELETE_POST, $baseHostName), $query); + } + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/tumblr/error.php b/library/eden/tumblr/error.php new file mode 100644 index 0000000..e5cf1b0 --- /dev/null +++ b/library/eden/tumblr/error.php @@ -0,0 +1,39 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Tumblr error + * + * @package Eden + * @category Tumblr + * @author Christian Blanquera cblanquera@openovate.com + */ +class Eden_Tumblr_Error extends Eden_Error { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i($message = NULL, $code = 0) { + $class = __CLASS__; + return new $class($message, $code); + } + + /* Public Methods + -------------------------------*/ + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/tumblr/oauth.php b/library/eden/tumblr/oauth.php new file mode 100644 index 0000000..d301bce --- /dev/null +++ b/library/eden/tumblr/oauth.php @@ -0,0 +1,121 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Tumblr oauth + * + * @package Eden + * @category tumblr + * @author Christian Blanquera cblanquera@openovate.com + */ +class Eden_Tumblr_Oauth extends Eden_Class { + /* Constants + -------------------------------*/ + const REQUEST_URL = 'http://www.tumblr.com/oauth/request_token'; + const AUTHORIZE_URL = 'http://www.tumblr.com/oauth/authorize'; + const ACCESS_URL = 'http://www.tumblr.com/oauth/access_token'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_key = NULL; + protected $_secret = NULL; + + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + public function __construct($key, $secret) { + //argument test + Eden_Tumblr_Error::i() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'string'); //Argument 2 must be a string + + $this->_key = $key; + $this->_secret = $secret; + } + + /* Public Methods + -------------------------------*/ + /** + * Returns the access token + * + * @param string the response key; from the url usually + * @param string the request secret; from getRequestToken() usually + * @return string the response verifier; from the url usually + */ + public function getAccessToken($token, $secret, $verifier) { + //argument test + Eden_Tumblr_Error::i() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'string') //Argument 2 must be a string + ->argument(3, 'string'); //Argument 3 must be a string + + return Eden_Oauth::i() + ->consumer( + self::ACCESS_URL, + $this->_key, + $this->_secret) + ->useAuthorization() + ->setMethodToPost() + ->setToken($token, $secret) + ->setVerifier($verifier) + ->setSignatureToHmacSha1() + ->getQueryResponse(); + } + + /** + * Returns the URL used for login. + * + * @param string the request key + * @param string + * @return string + */ + public function getLoginUrl($token, $redirect) { + //Argument tests + Eden_Tumblr_Error::i() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'string'); //Argument 2 must be a string + + //build the query + $query = array('oauth_token' => $token, 'oauth_callback' => $redirect); + $query = http_build_query($query); + + return self::AUTHORIZE_URL.'?'.$query; + } + + /** + * Return a request token + * + * @return string + */ + public function getRequestToken() { + return Eden_Oauth::i() + ->consumer( + self::REQUEST_URL, + $this->_key, + $this->_secret) + ->useAuthorization() + ->setMethodToPost() + ->setSignatureToHmacSha1() + ->getQueryResponse(); + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/tumblr/user.php b/library/eden/tumblr/user.php new file mode 100644 index 0000000..a204a29 --- /dev/null +++ b/library/eden/tumblr/user.php @@ -0,0 +1,262 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Tumblr user + * + * @package Eden + * @category tumblr + * @author Christian Symon M. Buenavista sbuenavista@openovate.com + */ +class Eden_Tumblr_User extends Eden_Tumblr_Base { + /* Constants + -------------------------------*/ + const URL_GET_INFO = 'http://api.tumblr.com/v2/user/info'; + const URL_GET_DASHBOARD = 'http://api.tumblr.com/v2/user/dashboard'; + const URL_GET_LIKES = 'http://api.tumblr.com/v2/user/likes'; + const URL_GET_FOLLOWING = 'http://api.tumblr.com/v2/user/following'; + const URL_FOLLOW = 'http://api.tumblr.com/v2/user/follow'; + const URL_UNFOLLOW = 'http://api.tumblr.com/v2/user/unfollow'; + const URL_LIKE = 'http://api.tumblr.com/v2/user/like'; + const URL_UNLIKE = 'http://api.tumblr.com/v2/user/unlike'; + + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_limit = NULL; + protected $_offset = NULL; + protected $_type = NULL; + protected $_since = NULL; + protected $_reblog = true; + protected $_notes = true; + + + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + /* Public Methods + -------------------------------*/ + /** + * Follow a blog + * + * @param string + * @return array + */ + public function follow($url) { + //Argument 1 must be a string + Eden_Tumblr_Error::i()->argument(1, 'string'); + + $query = array('url' => $url); + + $url = sprintf(self::URL_FOLLOW, $url); + return $this->_post($url, $query); + } + + /** + * Use this method to retrieve the dashboard that matches + * the OAuth credentials submitted with the request. + * + * @return array + */ + public function getDashboard() { + //populate fields + $query = array( + 'limit' => $this->_limit, + 'offset' => $this->_offset, + 'type' => $this->_type, + 'since_id' => $this->_since, + 'reblog_info' => $this->_reblog, + 'notes_info' => $this->_notes); + + return $this->_getResponse(self::URL_GET_DASHBOARD, $query); + } + + /** + * Use this method to retrieve the blogs followed by the user + * whose OAuth credentials are submitted with the request. + * + * @return array + */ + public function getFollowing() { + //populate fields + $query = array( + 'limit' => $this->_limit, + 'offset' => $this->_offset); + + return $this->_getResponse(self::URL_GET_FOLLOWING, $query); + } + + /** + * Use this method to retrieve the user's account information + * that matches the OAuth credentials submitted with the request. + * + * @return array + */ + public function getInfo() { + $url = self::URL_GET_INFO; + return $this->_getResponse($url); + } + + /** + * Use this method to retrieve the liked posts that + * match the OAuth credentials submitted with the request. + * + * @return array + */ + public function getLikes() { + //populate fields + $query = array( + 'limit' => $this->_limit, + 'offset' => $this->_offset); + + return $this->_getResponse(self::URL_GET_LIKES, $query); + } + + /** + * Like a post + * + * @param integer + * @param string + * @return array + */ + public function like($id, $reblog) { + //Argument Test + Eden_Tumblr_Error::i() + ->argument(1, 'integer') //Argument 1 must be a integer + ->argument(2, 'string'); //Argument 2 must be a string + + $query = array('url' => $url, 'reblog_key' => $reblog); + + $url = sprintf(self::URL_LIKE, $url); + return $this->_post($url, $query); + } + + /** + * Set limit + * + * @param integer + * @return this + */ + public function setLimit($limit) { + //Argument 1 must be an integer + Eden_Tumblr_Error::i()->argument(1, 'int'); + + $this->_limit = $limit; + return $this; + } + + /** + * Set notes + * + * @return this + */ + public function setNotes() { + $this->_notes = false; + return $this; + } + + /** + * Set offset + * + * @param integer + * @return this + */ + public function setOffset($offset) { + //Argument 1 must be an integer + Eden_Tumblr_Error::i()->argument(1, 'int'); + + $this->_offset = $offset; + return $this; + } + + /** + * Set reblog + * + * @return this + */ + public function setReblog() { + $this->_reblog = false; + return $this; + } + + /** + * Set since + * + * @param integer + * @return this + */ + public function setSince($since) { + //Argument 1 must be an integer + Eden_Tumblr_Error::i()->argument(1, 'int'); + + $this->_since = $since; + return $this; + } + + /** + * Set type + * + * @param string + * @return this + */ + public function setType($type) { + //Argument 1 must be a string + Eden_Tumblr_Error::i()->argument(1, 'string'); + + $this->_type = $type; + return $this; + } + + /** + * Unfollow a blog + * + * @param string + * @return array + */ + public function unfollow($url) { + //Argument 1 must be a string + Eden_Tumblr_Error::i()->argument(1, 'string'); + + $query = array('url' => $url); + + $url = sprintf(self::URL_UNFOLLOW, $url); + return $this->_post($url, $query); + } + + /** + * Unlike a post + * + * @param integer + * @param string + * @return array + */ + public function unlike($id, $reblog) { + //Argument Test + Eden_Tumblr_Error::i() + ->argument(1, 'integer') //Argument 1 must be a integer + ->argument(2, 'string'); //Argument 2 must be a string + + $query = array('url' => $url, 'reblog_key' => $reblog); + + $url = sprintf(self::URL_UNLIKE, $url); + return $this->_post($url, $query); + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/twitter.php b/library/eden/twitter.php new file mode 100644 index 0000000..7b13fad --- /dev/null +++ b/library/eden/twitter.php @@ -0,0 +1,465 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +require_once dirname(__FILE__).'/oauth.php'; +require_once dirname(__FILE__).'/twitter/error.php'; +require_once dirname(__FILE__).'/twitter/base.php'; +require_once dirname(__FILE__).'/twitter/oauth.php'; +require_once dirname(__FILE__).'/twitter/accounts.php'; +require_once dirname(__FILE__).'/twitter/block.php'; +require_once dirname(__FILE__).'/twitter/directmessage.php'; +require_once dirname(__FILE__).'/twitter/favorites.php'; +require_once dirname(__FILE__).'/twitter/friends.php'; +require_once dirname(__FILE__).'/twitter/geo.php'; +require_once dirname(__FILE__).'/twitter/help.php'; +require_once dirname(__FILE__).'/twitter/legal.php'; +require_once dirname(__FILE__).'/twitter/list.php'; +require_once dirname(__FILE__).'/twitter/localtrends.php'; +require_once dirname(__FILE__).'/twitter/notification.php'; +require_once dirname(__FILE__).'/twitter/saved.php'; +require_once dirname(__FILE__).'/twitter/search.php'; +require_once dirname(__FILE__).'/twitter/spam.php'; +require_once dirname(__FILE__).'/twitter/suggestions.php'; +require_once dirname(__FILE__).'/twitter/timeline.php'; +require_once dirname(__FILE__).'/twitter/trends.php'; +require_once dirname(__FILE__).'/twitter/tweets.php'; +require_once dirname(__FILE__).'/twitter/users.php'; + +/** + * Twitter API factory. This is a factory class with + * methods that will load up different twitter classes. + * Twitter classes are organized as described on their + * developer site: account, block, direct message, favorites, friends, geo, + * help, legal, list, local trends, notification, saved searches, search, spam, + * suggestions, timelines, trends, tweets and users. + * + * @package Eden + * @category twitter + * @author Christian Symon M. Buenavista sbuenavista@openovate.com + */ +class Eden_Twitter extends Eden_Class { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function i() { + return self::_getSingleton(__CLASS__); + } + + /* Magic + -------------------------------*/ + /* Public Methods + -------------------------------*/ + /** + * Returns twitter account method + * + * @param *string + * @param *string + * @param *string + * @param *string + * @return Eden_Twitter_Accounts + */ + public function account($consumerKey, $consumerSecret, $accessToken, $accessSecret) { + //Argument test + Eden_Twitter_Error::i() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'string') //Argument 2 must be a string + ->argument(3, 'string') //Argument 3 must be a string + ->argument(4, 'string'); //Argument 4 must be a string + + return Eden_Twitter_Accounts::i($consumerKey, $consumerSecret, $accessToken, $accessSecret); + } + + /** + * Returns twitter oauth method + * + * @param *string + * @param *string + * @return Eden_Twitter_Oauth + */ + public function auth($key, $secret) { + //Argument test + Eden_Twitter_Error::i() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'string'); //Argument 2 must be a string + + return Eden_Twitter_Oauth::i($key, $secret); + } + + /** + * Returns twitter block method + * + * @param *string + * @param *string + * @param *string + * @param *string + * @return Eden_Twitter_Block + */ + public function block($consumerKey, $consumerSecret, $accessToken, $accessSecret) { + //Argument test + Eden_Twitter_Error::i() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'string') //Argument 2 must be a string + ->argument(3, 'string') //Argument 3 must be a string + ->argument(4, 'string'); //Argument 4 must be a string + + return Eden_Twitter_Block::i($consumerKey, $consumerSecret, $accessToken, $accessSecret); + } + + /** + * Returns twitter direct message method + * + * @param *string + * @param *string + * @param *string + * @param *string + * @return Eden_Twitter_Directmessage + */ + public function directMessage($consumerKey, $consumerSecret, $accessToken, $accessSecret) { + //Argument test + Eden_Twitter_Error::i() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'string') //Argument 2 must be a string + ->argument(3, 'string') //Argument 3 must be a string + ->argument(4, 'string'); //Argument 4 must be a string + + return Eden_Twitter_Directmessage::i($consumerKey, $consumerSecret, $accessToken, $accessSecret); + } + + /** + * Returns twitter favorites method + * + * @param *string + * @param *string + * @param *string + * @param *string + * @return Eden_Twitter_Favorites + */ + public function favorites($consumerKey, $consumerSecret, $accessToken, $accessSecret) { + //Argument test + Eden_Twitter_Error::i() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'string') //Argument 2 must be a string + ->argument(3, 'string') //Argument 3 must be a string + ->argument(4, 'string'); //Argument 4 must be a string + + return Eden_Twitter_Favorites::i($consumerKey, $consumerSecret, $accessToken, $accessSecret); + } + + /** + * Returns twitter friends method + * + * @param *string + * @param *string + * @param *string + * @param *string + * @return Eden_Twitter_Friends + */ + public function friends($consumerKey, $consumerSecret, $accessToken, $accessSecret) { + //Argument test + Eden_Twitter_Error::i() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'string') //Argument 2 must be a string + ->argument(3, 'string') //Argument 3 must be a string + ->argument(4, 'string'); //Argument 4 must be a string + + return Eden_Twitter_Friends::i($consumerKey, $consumerSecret, $accessToken, $accessSecret); + } + + /** + * Returns twitter geo method + * + * @param *string + * @param *string + * @param *string + * @param *string + * @return Eden_Twitter_Geo + */ + public function geo($consumerKey, $consumerSecret, $accessToken, $accessSecret) { + //Argument test + Eden_Twitter_Error::i() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'string') //Argument 2 must be a string + ->argument(3, 'string') //Argument 3 must be a string + ->argument(4, 'string'); //Argument 4 must be a string + + return Eden_Twitter_Geo::i($consumerKey, $consumerSecret, $accessToken, $accessSecret); + } + + /** + * Returns twitter help method + * + * @param *string + * @param *string + * @param *string + * @param *string + * @return Eden_Twitter_Help + */ + public function help($consumerKey, $consumerSecret, $accessToken, $accessSecret) { + //Argument test + Eden_Twitter_Error::i() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'string') //Argument 2 must be a string + ->argument(3, 'string') //Argument 3 must be a string + ->argument(4, 'string'); //Argument 4 must be a string + + return Eden_Twitter_Help::i($consumerKey, $consumerSecret, $accessToken, $accessSecret); + } + + /** + * Returns twitter legal method + * + * @param *string + * @param *string + * @param *string + * @param *string + * @return Eden_Twitter_Legal + */ + public function legal($consumerKey, $consumerSecret, $accessToken, $accessSecret) { + //Argument test + Eden_Twitter_Error::i() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'string') //Argument 2 must be a string + ->argument(3, 'string') //Argument 3 must be a string + ->argument(4, 'string'); //Argument 4 must be a string + + return Eden_Twitter_Legal::i($consumerKey, $consumerSecret, $accessToken, $accessSecret); + } + + /** + * Returns twitter list method + * + * @param *string + * @param *string + * @param *string + * @param *string + * @return Eden_Twitter_List + */ + public function lists($consumerKey, $consumerSecret, $accessToken, $accessSecret) { + //Argument test + Eden_Twitter_Error::i() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'string') //Argument 2 must be a string + ->argument(3, 'string') //Argument 3 must be a string + ->argument(4, 'string'); //Argument 4 must be a string + + return Eden_Twitter_List::i($consumerKey, $consumerSecret, $accessToken, $accessSecret); + } + + /** + * Returns twitter localTrends method + * + * @param *string + * @param *string + * @param *string + * @param *string + * @return Eden_Twitter_LocalTrends + */ + public function localTrends($consumerKey, $consumerSecret, $accessToken, $accessSecret) { + //Argument test + Eden_Twitter_Error::i() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'string') //Argument 2 must be a string + ->argument(3, 'string') //Argument 3 must be a string + ->argument(4, 'string'); //Argument 4 must be a string + + return Eden_Twitter_LocalTrends::i($consumerKey, $consumerSecret, $accessToken, $accessSecret); + } + + /** + * Returns twitter notification method + * + * @param *string + * @param *string + * @param *string + * @param *string + * @return Eden_Twitter_Notification + */ + public function notification($consumerKey, $consumerSecret, $accessToken, $accessSecret) { + //Argument test + Eden_Twitter_Error::i() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'string') //Argument 2 must be a string + ->argument(3, 'string') //Argument 3 must be a string + ->argument(4, 'string'); //Argument 4 must be a string + + return Eden_Twitter_Notification::i($consumerKey, $consumerSecret, $accessToken, $accessSecret); + } + + /** + * Returns twitter saved method + * + * @param *string + * @param *string + * @param *string + * @param *string + * @return Eden_Twitter_Saved + */ + public function saved($consumerKey, $consumerSecret, $accessToken, $accessSecret) { + //Argument test + Eden_Twitter_Error::i() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'string') //Argument 2 must be a string + ->argument(3, 'string') //Argument 3 must be a string + ->argument(4, 'string'); //Argument 4 must be a string + + return Eden_Twitter_Saved::i($consumerKey, $consumerSecret, $accessToken, $accessSecret); + } + + /** + * Returns twitter search method + * + * @param *string + * @param *string + * @param *string + * @param *string + * @return Eden_Twitter_Search + */ + public function search($consumerKey, $consumerSecret, $accessToken, $accessSecret) { + //Argument test + Eden_Twitter_Error::i() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'string') //Argument 2 must be a string + ->argument(3, 'string') //Argument 3 must be a string + ->argument(4, 'string'); //Argument 4 must be a string + + return Eden_Twitter_Search::i($consumerKey, $consumerSecret, $accessToken, $accessSecret); + } + + /** + * Returns twitter spam method + * + * @param *string + * @param *string + * @param *string + * @param *string + * @return Eden_Twitter_Spam + */ + public function spam($consumerKey, $consumerSecret, $accessToken, $accessSecret) { + //Argument test + Eden_Twitter_Error::i() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'string') //Argument 2 must be a string + ->argument(3, 'string') //Argument 3 must be a string + ->argument(4, 'string'); //Argument 4 must be a string + + return Eden_Twitter_Spam::i($consumerKey, $consumerSecret, $accessToken, $accessSecret); + } + + /** + * Returns twitter suggestions method + * + * @param *string + * @param *string + * @param *string + * @param *string + * @return Eden_Twitter_Suggestions + */ + public function suggestions($consumerKey, $consumerSecret, $accessToken, $accessSecret) { + //Argument test + Eden_Twitter_Error::i() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'string') //Argument 2 must be a string + ->argument(3, 'string') //Argument 3 must be a string + ->argument(4, 'string'); //Argument 4 must be a string + + return Eden_Twitter_Suggestions::i($consumerKey, $consumerSecret, $accessToken, $accessSecret); + } + + /** + * Returns twitter timelines method + * + * @param *string + * @param *string + * @param *string + * @param *string + * @return Eden_Twitter_Timeline + */ + public function timeline($consumerKey, $consumerSecret, $accessToken, $accessSecret) { + //Argument test + Eden_Twitter_Error::i() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'string') //Argument 2 must be a string + ->argument(3, 'string') //Argument 3 must be a string + ->argument(4, 'string'); //Argument 4 must be a string + + return Eden_Twitter_Timeline::i($consumerKey, $consumerSecret, $accessToken, $accessSecret); + } + + /** + * Returns twitter trends method + * + * @param *string + * @param *string + * @param *string + * @param *string + * @return Eden_Twitter_Trends + */ + public function trends($consumerKey, $consumerSecret, $accessToken, $accessSecret) { + //Argument test + Eden_Twitter_Error::i() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'string') //Argument 2 must be a string + ->argument(3, 'string') //Argument 3 must be a string + ->argument(4, 'string'); //Argument 4 must be a string + + return Eden_Twitter_Trends::i($consumerKey, $consumerSecret, $accessToken, $accessSecret); + } + + /** + * Returns twitter tweets method + * + * @param *string + * @param *string + * @param *string + * @param *string + * @return Eden_Twitter_Tweets + */ + public function tweets($consumerKey, $consumerSecret, $accessToken, $accessSecret) { + //Argument test + Eden_Twitter_Error::i() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'string') //Argument 2 must be a string + ->argument(3, 'string') //Argument 3 must be a string + ->argument(4, 'string'); //Argument 4 must be a string + + return Eden_Twitter_Tweets::i($consumerKey, $consumerSecret, $accessToken, $accessSecret); + } + + /** + * Returns twitter users method + * + * @param *string + * @param *string + * @param *string + * @param *string + * @return Eden_Twitter_Users + */ + public function users($consumerKey, $consumerSecret, $accessToken, $accessSecret) { + //Argument test + Eden_Twitter_Error::i() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'string') //Argument 2 must be a string + ->argument(3, 'string') //Argument 3 must be a string + ->argument(4, 'string'); //Argument 4 must be a string + + return Eden_Twitter_Users::i($consumerKey, $consumerSecret, $accessToken, $accessSecret); + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/twitter/accounts.php b/library/eden/twitter/accounts.php new file mode 100644 index 0000000..f1edf3e --- /dev/null +++ b/library/eden/twitter/accounts.php @@ -0,0 +1,349 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Twitter Account + * + * @package Eden + * @category twitter + * @author Christian Symon M. Buenavista sbuenavista@openovate.com + */ +class Eden_Twitter_Accounts extends Eden_Twitter_Base { + /* Constants + -------------------------------*/ + const URL_LIMIT_STATUS = 'https://api.twitter.com/1/account/rate_limit_status.json'; + const URL_VERIFY_CREDENTIALS = 'https://api.twitter.com/1/account/verify_credentials.json'; + const URL_END_SESSION = 'https://api.twitter.com/1/account/end_session.json'; + const URL_UPDATE_PROFILE = 'https://api.twitter.com/1/account/update_profile.json'; + const URL_UPDATE_BACKGROUND = 'https://api.twitter.com/1/account/update_profile_background_image.json'; + const URL_UPDATE_PROFILE_COLOR = 'https://api.twitter.com/1/account/update_profile_colors.json'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_entities = NULL; + protected $_status = NULL; + protected $_use = NULL; + protected $_name = NULL; + protected $_url = NULL; + protected $_location = NULL; + protected $_description = NULL; + protected $_image = NULL; + protected $_tile = NULL; + protected $_background = NULL; + protected $_link = NULL; + protected $_border = NULL; + protected $_fill = NULL; + protected $_text = NULL; + + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + /* Public Methods + -------------------------------*/ + + /** + * Returns an HTTP 200 OK response code and + * a representation of the requesting user + * if authentication was successful + * + * @return array + */ + public function getCredentials() { + //populate fields + $query = array( + 'include_entities' => $this->_entities, + 'skip_status' => $this->_status); + + return $this->_getResponse(self::URL_VERIFY_CREDENTIALS, $query); + } + + /** + * Returns the remaining number of API + * requests available to the requesting + * user before the API limit is reached + * for the current hour. + * + * @return array + */ + public function getLimit() { + return $this->_getResponse(self::URL_LIMIT_STATUS); + } + + /** + * Ends the session of the authenticating user, returning a null cookie. + * Use this method to sign users out of client-facing applications like widgets. + * + * @return string + */ + public function logOut() { + return $this->_post(self::URL_END_SESSION); + } + /** + * Set profile background color + * + * @param string + * @return this + */ + public function setBackgroundColor($background) { + //Argument 3 must be a string + Eden_Twitter_Error::i()->argument(1, 'string'); + + $this->_background = $background; + return $this; + } + + /** + * Set profile sibebar border color + * + * @param string + * @return this + */ + public function setBorderColor($border) { + //Argument 3 must be a string + Eden_Twitter_Error::i()->argument(1, 'string'); + + $this->_border = $border; + return $this; + } + + /** + * Set description + * + * @param string + * @return this + */ + public function setDescriptione($description) { + //Argument 1 must be a string or null + Eden_Twitter_Error::i()->argument(1, 'string'); + + $this->_description = $description; + return $this; + + } + + /** + * Set include entities + * + * @return this + */ + public function setEntities() { + $this->_entities = true; + return $this; + } + + /** + * Set profile sibebar fill color + * + * @param string + * @return this + */ + public function setFillColor($fill) { + //Argument 3 must be a string + Eden_Twitter_Error::i()->argument(1, 'string'); + + $this->_fill = $fill; + return $this; + } + + /** + * Set image + * + * @param string + * @return this + */ + public function setImage($image) { + //Argument 1 must be a string or null + Eden_Twitter_Error::i()->argument(1, 'string'); + + $this->_image = $image; + return $this; + } + + /** + * Set profile link color + * + * @param string + * @return this + */ + public function setLinkColor($link) { + //Argument 3 must be a string + Eden_Twitter_Error::i()->argument(1, 'string'); + + $this->_link = $link; + return $this; + } + + /** + * Set location + * + * @param string + * @return this + */ + public function setLocation($location) { + //Argument 1 must be a string or null + Eden_Twitter_Error::i()->argument(1, 'string'); + + $this->_location = $location; + return $this; + + } + + /** + * Set name + * + * @param string + * @return this + */ + public function setName($name) { + //Argument 1 must be a string or null + Eden_Twitter_Error::i()->argument(1, 'string'); + + $this->_name = $name; + return $this; + + } + + /** + * Set skip status + * + * @return this + */ + public function setStatus() { + $this->_status = true; + return $this; + } + + /** + * Set profile text color + * + * @param string + * @return this + */ + public function setTextColor($text) { + //Argument 3 must be a string + Eden_Twitter_Error::i()->argument(1, 'string'); + + $this->_text = $text; + return $this; + } + + /** + * Set tile + * + * @param string + * @return this + */ + public function setTile($tile) { + //Argument 1 must be a string or null + Eden_Twitter_Error::i()->argument(1, 'string'); + + $this->_tile = $tile; + return $this; + } + + /** + * Set url + * + * @param string + * @return this + */ + public function setUrl($url) { + //Argument 1 must be a string or null + Eden_Twitter_Error::i()->argument(1, 'string'); + + $this->_url = $url; + return $this; + + } + + /** + * Determines whether to display the profile background image or not + * + * @return this + */ + public function show() { + $this->_use = true; + return $this; + } + + /** + * Updates the authenticating user's profile background image. + * This method can also be used to enable or disable the profile + * background image + * + * @return array + */ + public function updateBackground() { + //populate fields + $query = array( + 'include_entities' => $this->_entities, + 'skip_status' => $this->_status, + 'use' => $this->_use, + 'image' => $this->_image, + 'tile' => $this->_tile); + + return $this->_post(self::URL_UPDATE_BACKGROUND, $query); + } + + /** + * Sets values that users are able to + * set under the Account tab of their + * settings page. Only the parameters + * specified will be updated. + * + * @return array + */ + public function updateColor() { + //populate fields + $query = array( + 'include_entities' => $this->_entities, + 'skip_status' => $this->_status, + 'profile_background_color' => $this->_background, + 'profile_link_color' => $this->_link, + 'profile_sidebar_border_color' => $this->_border, + 'profile_sidebar_fill_color' => $this->_fill, + 'profile_text_color' => $this->_text); + + return $this->_post(self::URL_UPDATE_PROFILE_COLOR, $query); + + } + + /** + * Sets values that users are able to set + * under the "Account" tab of their settings + * page. Only the parameters specified + * will be updated. + * + * @return array + */ + public function updateProfile() { + //populate fields + $query = array( + 'include_entities' => $this->_entities, + 'skip_status' => $this->_status, + 'name' => $this->_name, + 'url' => $this->_url, + 'location' => $this->_location, + 'description' => $this->_description); + + return $this->_post(self::URL_UPDATE_PROFILE, $query); + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/twitter/base.php b/library/eden/twitter/base.php new file mode 100644 index 0000000..5ed9f5c --- /dev/null +++ b/library/eden/twitter/base.php @@ -0,0 +1,265 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Twitter oauth + * + * @package Eden + * @category twitter + * @author Christian Blanquera cblanquera@openovate.com + */ +class Eden_Twitter_Base extends Eden_Oauth_Base { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_consumerKey = NULL; + protected $_consumerSecret = NULL; + protected $_accessToken = NULL; + protected $_accessSecret = NULL; + protected $_signingKey = NULL; + protected $_baseString = NULL; + protected $_signingParams = NULL; + protected $_url = NULL; + protected $_authParams = NULL; + protected $_authHeader = NULL; + protected $_headers = NULL; + + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + /* Magic + -------------------------------*/ + public function __construct($consumerKey, $consumerSecret, $accessToken, $accessSecret) { + //argument test + Eden_Twitter_Error::i() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'string') //Argument 2 must be a string + ->argument(3, 'string') //Argument 3 must be a string + ->argument(4, 'string'); //Argument 4 must be a string + + $this->_consumerKey = $consumerKey; + $this->_consumerSecret = $consumerSecret; + $this->_accessToken = $accessToken; + $this->_accessSecret = $accessSecret; + } + + /* Public Methods + -------------------------------*/ + /** + * Returns the meta of the last call + * + * @return array + */ + public function getMeta($key = NULL) { + Eden_Twitter_Error::i()->argument(1, 'string', 'null'); + + if(isset($this->_meta[$key])) { + return $this->_meta[$key]; + } + + return $this->_meta; + } + + /* Protected Methods + -------------------------------*/ + protected function _accessKey($array) { + foreach($array as $key => $val) { + if(is_array($val)) { + $array[$key] = $this->_accessKey($val); + } + //if value is null + if(is_null($val) || empty($val)) { + unset($array[$key]); + } else if($val === false) { + $array[$key] = 0; + } else if($val === true) { + $array[$key] = 1; + } + + } + + return $array; + } + + protected function _getResponse($url, array $query = array()) { + //prevent sending fields with no value + $query = $this->_accessKey($query); + + $rest = Eden_Oauth::i() + ->consumer($url, $this->_consumerKey, $this->_consumerSecret) + ->setMethodToPost() + ->setToken($this->_accessToken, $this->_accessSecret) + ->setSignatureToHmacSha1(); + + $response = $rest->getJsonResponse($query); + + $this->_meta = $rest->getMeta(); + + return $response; + } + + protected function _post($url, array $query = array()) { + //prevent sending fields with no value + $query = $this->_accessKey($query); + + $rest = Eden_Oauth::i() + ->consumer($url, $this->_consumerKey, $this->_consumerSecret) + ->setMethodToPost() + ->setToken($this->_accessToken, $this->_accessSecret) + ->setSignatureToHmacSha1(); + + //get the authorization parameters as an array + $signature = $rest->getSignature($query); + $authorization = $rest->getAuthorization($signature, false); + $authorization = $this->_buildQuery($authorization); + + if(is_array($query)) { + $query = $this->_buildQuery($query); + } + + $headers = array(); + $headers[] = Eden_Oauth_Consumer::POST_HEADER; + + //determine the conector + $connector = NULL; + + //if there is no question mark + if(strpos($url, '?') === false) { + $connector = '?'; + //if the redirect doesn't end with a question mark + } else if(substr($url, -1) != '?') { + $connector = '&'; + } + + //now add the authorization to the url + $url .= $connector.$authorization; + //set curl + $curl = Eden_Curl::i() + ->verifyHost(false) + ->verifyPeer(false) + ->setUrl($url) + ->setPost(true) + ->setPostFields($query) + ->setHeaders($headers); + + //get the response + $response = $curl->getJsonResponse(); + + $this->_meta = $curl->getMeta(); + $this->_meta['url'] = $url; + $this->_meta['authorization'] = $authorization; + $this->_meta['headers'] = $headers; + $this->_meta['query'] = $query; + + return $response; + } + + protected function _upload($url, array $query = array()) { + //prevent sending fields with no value + $query = $this->_accessKey($query); + //set url + $this->_url = $url; + //make authorization for twitter + $this->_getAuthentication(); + //set headers + $this->_headers['Expect'] = ''; + //at this point, the authentication header si already set + foreach($this->_headers as $k => $v) { + //trim header + $headers[] = trim($k . ': ' . $v); + } + //set curl + $curl = Eden_Curl::i() + ->verifyHost(false) + ->verifyPeer(false) + ->setUrl($url) + ->setPost(true) + ->setPostFields($query) + ->setHeaders($headers); + //json decode the response + $response = $curl->getJsonResponse(); + + $this->_meta = $curl->getMeta(); + $this->_meta['url'] = $url; + $this->_meta['headers'] = $headers; + $this->_meta['query'] = $query; + + return $response; + } + + protected function _getAuthentication() { + //populate fields + $defaults = array( + 'oauth_version' => '1.0', + 'oauth_nonce' => md5(uniqid(rand(), true)), + 'oauth_timestamp' => time(), + 'oauth_consumer_key' => $this->_consumerKey, + 'oauth_signature_method' => 'HMAC-SHA1', + 'oauth_token' => $this->_accessToken); + + //encode the parameters + foreach ($defaults as $k => $v) { + $this->_signingParams[$this->safeEncode($k)] = $this->safeEncode($v); + } + //sort an array by keys using a user-defined comparison function + uksort($this->_signingParams, 'strcmp'); + + foreach ($this->_signingParams as $k => $v) { + //encode key + $k = $this->safeEncode($k); + //encode value + $v = $this->safeEncode($v); + $_signing_params[$k] = $v; + $kv[] = "{$k}={$v}"; + } + //implode signingParams to make it a string + $this->_signingParams = implode('&', $kv); + //check if they have the same value + $this->_authParams = array_intersect_key($defaults, $_signing_params); + //make a base string + $base = array('POST', $this->_url, $this->_signingParams); + //convert array to string and safely encode it + $this->_baseString = implode('&', $this->safeEncode($base)); + //make a signing key by combining consumer secret and access secret + $this->_signingKey = $this->safeEncode($this->_consumerSecret).'&'.$this->safeEncode($this->_accessSecret); + //generate signature + $this->_authParams['oauth_signature'] = $this->safeEncode( + base64_encode(hash_hmac('sha1', $this->_baseString, $this->_signingKey, true))); + + foreach ($this->_authParams as $k => $v) { + $kv[] = "{$k}=\"{$v}\""; + } + //implode authHeader to make it ia string + $this->_authHeader = 'OAuth ' . implode(', ', $kv); + //put it in the authorization headera + $this->_headers['Authorization'] = $this->_authHeader; + } + + protected function safeEncode($data) { + //if data is in array + if (is_array($data)) { + //array map the data + return array_map(array($this, 'safeEncode'), $data); + //else it is not array + } else if (is_scalar($data)) { + //str ireplace data, it is case-insensitive version of str_replace() + return str_ireplace(array('+', '%7E'), array(' ', '~'), rawurlencode($data)); + //else it is null or uempty + } else { + return ''; + } + + } + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/twitter/block.php b/library/eden/twitter/block.php new file mode 100644 index 0000000..e611d35 --- /dev/null +++ b/library/eden/twitter/block.php @@ -0,0 +1,222 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Twitter block + * + * @package Eden + * @category twitter + * @author Christian Symon M. Buenavista sbuenavista@openovate.com + */ +class Eden_Twitter_Block extends Eden_Twitter_Base { + /* Constants + -------------------------------*/ + const URL_GET_USER_BLOCK = 'https://api.twitter.com/1/blocks/blocking.json'; + const URL_GET_BLOCKING_ID = 'https://api.twitter.com/1/blocks/blocking/ids.json'; + const URL_GET_BLOCKING = 'https://api.twitter.com/1/blocks/exists.json'; + const URL_CREATE_BLOCKING = 'https://api.twitter.com/1/blocks/create.json'; + const URL_REMOVE_BLOCKING = 'https://api.twitter.com/1/blocks/destroy.json'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + /* Public Methods + -------------------------------*/ + /** + * Blocks the specified user from following the authenticating user. + * + * @param string|integer either the screen name or user ID + * @param boolean + * @param boolean + * @return array + */ + public function blockUser($id, $entities = false, $status = false) { + //Argument Test + Eden_Twitter_Error::i() + ->argument(1, 'string', 'int') //Argument 1 must be a string, integer + ->argument(2, 'bool') //Argument 2 must be a boolean + ->argument(3, 'bool'); //Argument 3 must be a boolean + + $query = array(); + + //if it is integer + if(is_int($id)) { + //lets put it in our query + $query['user_id'] = $id; + //else it is string + } else { + //lets put it in our query + $query['screen_name'] = $id; + } + + //if entities + if($entities) { + $query['include_entities'] = 1; + } + //if status + if($status) { + $query['skip_status'] = 1; + } + + return $this->_post(self::URL_CREATE_BLOCKING, $query); + } + + /** + * Returns if the authenticating user is blocking a target user. + * + * @param string|integer either the screen name or user ID + * @param boolean + * @param boolean + * @return array + */ + public function isBlocked($id = NULL, $entities = false, $status = false) { + //Argument Test + Eden_Twitter_Error::i() + ->argument(1, 'string', 'int') //Argument 1 must be a string, integer + ->argument(2, 'bool') //Argument 2 must be a boolean + ->argument(3, 'bool'); //Argument 3 must be a boolean + + $query = array(); + + //if it is integer + if(is_int($id)) { + //lets put it in our query + $query['user_id'] = $id; + //else it is string + } else { + //lets put it in our query + $query['screen_name'] = $id; + } + + //if entities + if($entities) { + $query['include_entities'] = 1; + } + //if status + if($status) { + $query['skip_status'] = 1; + } + + return $this->_getResponse(self::URL_GET_BLOCKING, $query); + } + + /** + * Returns an array of numeric user ids + * the authenticating user is blocking. + * + * @param boolean + * @return integer + */ + public function getBlockedUserIds($stringify = false) { + //Argument Test + Eden_Twitter_Error::i() + ->argument(1, 'bool'); //Argument 1 must be a boolean + + $query = array('stringify_ids' => $stringify); + + return $this->_getResponse(self::URL_GET_BLOCKING_ID, $query); + } + + /** + * Returns an array of user objects that + * the authenticating user is blocking. + * + * @param integer|null + * @param integer|null + * @param boolean + * @param boolean + * @return array + */ + public function getBlockedUsers($page = NULL, $perPage = NULL, $entities = false, $status = false) { + //Argument Test + Eden_Twitter_Error::i() + ->argument(1, 'int', 'null') //Argument 1 must be a integer or null + ->argument(2, 'int', 'null') //Argument 2 must be a integer or null + ->argument(3, 'bool') //Argument 3 must be a boolean + ->argument(4, 'bool'); //Argument 4 must be a boolean + + $query = array(); + + //if it is not empty + if(!is_null($page)) { + //lets put it in query + $query['page'] = $page; + } + //if it is not empty + if(!is_null($perPage)) { + //lets put it in query + $query['per_page'] = $perPage; + } + //if entities + if($entities) { + $query['include_entities'] = 1; + } + //if entities + if($status) { + $query['skip_status'] = 1; + } + + return $this->_getResponse(self::URL_GET_USER_BLOCK, $query); + } + + /** + * Un-blocks the user specified in the ID parameter for the + * authenticating user. + * + * @param string|integer either the screen name or user ID + * @param boolean + * @param boolean + * @return array + */ + public function unblock($id, $entities = false, $status = false) { + //Argument Test + Eden_Twitter_Error::i() + ->argument(1, 'string', 'int') //Argument 1 must be a string, integer + ->argument(2, 'bool') //Argument 2 must be a boolean + ->argument(3, 'bool'); //Argument 3 must be a boolean + + $query = array(); + + //if it is integer + if(is_int($id)) { + //lets put it in our query + $query['user_id'] = $id; + //else it is string + } else { + //lets put it in our query + $query['screen_name'] = $id; + } + + //if entities + if($entities) { + $query['include_entities'] = 1; + } + + //if status + if($status) { + $query['skip_status'] = 1; + } + + return $this->_post(self::URL_REMOVE_BLOCKING, $query); + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/twitter/directmessage.php b/library/eden/twitter/directmessage.php new file mode 100644 index 0000000..6ee9cf7 --- /dev/null +++ b/library/eden/twitter/directmessage.php @@ -0,0 +1,279 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Twitter direct message + * + * @package Eden + * @category twitter + * @author Christian Symon M. Buenavista sbuenavista@openovate.com + * @author Christian Blanquera cblanquera@openovate.com + */ +class Eden_Twitter_Directmessage extends Eden_Twitter_Base { + /* Constants + -------------------------------*/ + const URL_DIRECT_MESSAGE = 'https://api.twitter.com/1/direct_messages.json'; + const URL_SENT_MESSAGE = 'https://api.twitter.com/1/direct_messages/sent.json'; + const URL_REMOVE_MESSAGE = 'https://api.twitter.com/1/direct_messages/destroy/%d.json'; + const URL_NEW_MESSAGE = 'https://api.twitter.com/1/direct_messages/new.json'; + const URL_SHOW_MESSAGE = 'https://api.twitter.com/1/direct_messages/show/%d.json'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_entities = false; + protected $_wrap = NULL; + protected $_since = NULL; + protected $_max = 0; + protected $_count = 0; + protected $_page = 0; + protected $_status = false; + + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + /* Public Methods + -------------------------------*/ + /** + * Returns a single direct message, + * specified by an id parameter. + * + * @param int message ID + * @return array + */ + public function getDetail($id) { + //Argument 1 must be an integer + Eden_Twitter_Error::i()->argument(1, 'int'); + + $url = sprintf(self::URL_SHOW_MESSAGE,$id); + return $this->_getResponse($url); + } + + /** + * Returns the 20 most recent direct messages + * sent to the authenticating user. + * + * @return array + */ + public function getList() { + $query = array(); + + if($this->_entities) { + $query['include_entities'] = 1; + } + + if($this->_status) { + $query['skip_status'] = 1; + } + + if($this->_since) { + $query['since_id'] = $this->_since; + } + + if($this->_max) { + $query['max_id'] = $this->_max; + } + + if($this->_page) { + $query['page'] = $this->_page; + } + + if($this->_count) { + $query['count'] = $this->_count; + } + + return $this->_getResponse(self::URL_DIRECT_MESSAGE, $query); + } + + /** + * Returns the 20 most recent direct messages + * sent by the authenticating user. + * + * @return array + */ + public function getSent() { + $query = array(); + + if($this->_entities) { + $query['include_entities'] = 1; + } + + if($this->_since) { + $query['since_id'] = $this->_since; + } + + if($this->_max) { + $query['max_id'] = $this->_max; + } + + if($this->_page) { + $query['page'] = $this->_page; + } + + if($this->_count) { + $query['count'] = $this->_count; + } + + return $this->_getResponse(self::URL_SENT_MESSAGE, $query); + } + + /** + * Each tweet will include a node called "entities". This node offers a variety + * of metadata about the tweet in a discreet structure, including: user_mentions, + * urls, and hashtags. + * + * @return this + */ + public function includeEntities() { + $this->_entities = true; + return $this; + } + + /** + * Destroys the direct message specified in the required + * ID parameter. The authenticating user must be the + * recipient of the specified direct message. + * + * @param int message ID + * @return array + */ + public function remove($id) { + //Argument 1 must be an integer + Eden_Twitter_Error::i()->argument(1, 'int'); + + $query = array('id' => $id); + + if($this->_entities) { + $query['include_entities'] = 1; + } + + return $this->_post(self::URL_REMOVE_MESSAGE,$query); + } + + /** + * Sends a new direct message to the specified + * user from the authenticating user. + * + * @param string|int user ID or screen name + * @param string + * @return array + */ + public function send($id, $text) { + Eden_Twitter_Error::i() + ->argument(1, 'string', 'int') //Argument 1 must be a string or int + ->argument(2, 'string'); //Argument 2 must be a string + + //poulate fields + $query = array( + 'text' => $text, + 'wrap_links' => $this->_wrap); + + //if it is integer + if(is_int($id)) { + //lets put it in query + $query['user_id'] = $id; + } else { + //lets put it in query + $query['screen_name'] = $id; + } + + return $this->_post(self::URL_NEW_MESSAGE, $query); + } + + /** + * Set count + * + * @param integer|null + * @return this + */ + public function setCount($count) { + //Argument 1 must be an integer or null + Eden_Twitter_Error::i()->argument(1, 'int', 'null'); + + $this->_count = $count; + return $this; + } + + /** + * Set max id + * + * @param integer|null + * @return this + */ + public function setMax($max) { + //Argument 1 must be an integer or null + Eden_Twitter_Error::i()->argument(1, 'int', 'null'); + + $this->_max = $max; + return $this; + } + + /** + * Set page + * + * @param integer|null + * @return this + */ + public function setPage($page) { + //Argument 1 must be an integer or null + Eden_Twitter_Error::i()->argument(1, 'int', 'null'); + + $this->_page = $page; + return $this; + } + + /** + * Set since id + * + * @param integer|null + * @return this + */ + public function setSince($since) { + //Argument 1 must be an integer or null + Eden_Twitter_Error::i()->argument(1, 'int', 'null'); + + $this->_since = $since; + return $this; + } + + /** + * Set wrap link + * + * @param boolean + * @return this + */ + public function setWrap($wrap) { + //Argument 1 must be a boolean + Eden_Twitter_Error::i()->argument(1, 'bool'); + + $this->_wrap = $wrap; + return $this; + } + + /** + * Statuses will not be included in the returned user objects. + * + * @return this + */ + public function skipStatus() { + $this->_status = true; + return $this; + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/twitter/error.php b/library/eden/twitter/error.php new file mode 100644 index 0000000..24f6f6d --- /dev/null +++ b/library/eden/twitter/error.php @@ -0,0 +1,39 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Twitter error + * + * @package Eden + * @category twitter + * @author Christian Blanquera cblanquera@openovate.com + */ +class Eden_Twitter_Error extends Eden_Error { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i($message = NULL, $code = 0) { + $class = __CLASS__; + return new $class($message, $code); + } + + /* Public Methods + -------------------------------*/ + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/twitter/favorites.php b/library/eden/twitter/favorites.php new file mode 100644 index 0000000..7b5f8ec --- /dev/null +++ b/library/eden/twitter/favorites.php @@ -0,0 +1,130 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Twitter favorites + * + * @package Eden + * @category twitter + * @author Christian Symon M. Buenavista sbuenavista@openovate.com + */ +class Eden_Twitter_Favorites extends Eden_Twitter_Base { + /* Constants + -------------------------------*/ + const URL_GET_FAVORITES = 'https://api.twitter.com/1/favorites.json'; + const URL_FAVORITE_STATUS = 'https://api.twitter.com/1/favorites/create/%s.json'; + const URL_UNFAVORITE_STATUS = 'https://api.twitter.com/1/favorites/destroy/%s.json'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + /* Public Methods + -------------------------------*/ + /** + * Favorites the status specified in the ID parameter as + * the authenticating user. + * + * @param int the tweet ID + * @param bool + * @return array + */ + public function add($id, $entities = false) { + //Argument Test + Eden_Twitter_Error::i() + ->argument(1, 'int') //Argument 1 must be an integer + ->argument(2, 'bool'); //Argument 2 must be a boolean + + $query = array('id' => $id); + + //if entities + if($entities) { + $query['include_entities'] = 1; + } + + $url = sprintf(self::URL_FAVORITE_STATUS, $id); + return $this->_post($url, $query); + } + + /** + * Returns the 20 most recent favorite statuses for the authenticating + * user or user specified by the ID parameter in the requested format. + * + * @param bool + * @param string|int|null + * @param int|null + * @param int|null + * @return array + */ + public function getList($entities = false, $id = NULL, $since = NULL, $page = NULL) { + //Argument Test + Eden_Twitter_Error::i() + ->argument(1, 'bool') //Argument 1 must be a boolean + ->argument(2, 'int', 'string', 'null') //Argument 2 must be a string, integer or null + ->argument(3, 'int', 'null') //Argument 3 must be an integer or null + ->argument(4, 'int', 'null'); //Argument 4 must be an integer or null + + $query = array(); + + //if entities + if($entities) { + $query['include_entities'] = 1; + } + + //if it is not empty + if(!is_null($id)) { + //lets put it in our query + $query['id'] = $id; + } + + //if it is not empty + if(!is_null($since)) { + //lets put it in our query + $query['since_id'] = $since; + } + + //if it is not empty + if(!is_null($page)) { + //lets put it in our query + $query['page'] = $page; + } + + return $this->_getResponse(self::URL_GET_FAVORITES, $query); + } + + /** + * Un-favorites the status specified in the ID + * parameter as the authenticating user. + * + * @param int the tweet ID + * @return array + */ + public function remove($id) { + //Argument 1 must be na integer + Eden_Twitter_Error::i()->argument(1, 'int'); + + $query = array('id' => $id); + + $url = sprintf(self::URL_UNFAVORITE_STATUS, $id); + return $this->_post($url, $query); + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/twitter/friends.php b/library/eden/twitter/friends.php new file mode 100644 index 0000000..69c60b8 --- /dev/null +++ b/library/eden/twitter/friends.php @@ -0,0 +1,439 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Twitter friends and followers + * + * @package Eden + * @category twitter + * @author Christian Symon M. Buenavista sbuenavista@openovate.com + */ +class Eden_Twitter_Friends extends Eden_Twitter_Base { + /* Constants + -------------------------------*/ + const URL_FOLLOWERS = 'https://api.twitter.com/1/followers/ids.json'; + const URL_FRIENDS = 'https://api.twitter.com/1/friends/ids.json'; + const URL_FRIENDS_EXIST = 'https://api.twitter.com/1/friendships/exists.json'; + const URL_INCOMING_FRIENDS = 'https://api.twitter.com/1/friendships/incoming.json'; + const URL_OUTGOING_FRIENDS = 'https://api.twitter.com/1/friendships/outgoing.json'; + const URL_SHOW_FRIENDS = 'https://api.twitter.com/1/friendships/show.json'; + const URL_FOLLOW_FRIENDS = 'https://api.twitter.com/1/friendships/create.json'; + const URL_UNFOLLOW_FRIENDS = 'https://api.twitter.com/1/friendships/destroy.json'; + const URL_LOOKUP_FRIENDS = 'https://api.twitter.com/1/friendships/lookup.json'; + const URL_UPDATE = 'https://api.twitter.com/1/friendships/update.json'; + const URL_NO_RETWEETS_IDS = 'https://api.twitter.com/1/friendships/no_retweet_ids.json'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + /* Public Methods + -------------------------------*/ + /** + * Test for the existence of friendship between two users. + * + * @param int|string user ID or screen name + * @param int|string user ID or screen name + * @return bool + */ + public function areFriends($userA, $userB) { + //Argument Test + Eden_Twitter_Error::i() + ->argument(1, 'string', 'int') //Argument 1 must be an integer, string + ->argument(2, 'string', 'int'); //Argument 2 must be an integer, string + + $query = array(); + + //if it is integer + if(is_int($userA)) { + //lets put it in query + $query['user_id_a'] = $userA; + //if it is string + } else { + //lets put it in query + $query['screen_name_a'] = $userA; + } + + //if it is integer + if(is_int($userB)) { + //lets put it in query + $query['user_id_b'] = $userB; + //if it is string + } else { + //lets put it in query + $query['screen_name_b'] = $userB; + } + + return $this->_getResponse(self::URL_FRIENDS_EXIST, $query); + } + + /** + * Allows the authenticating users to follow the + * user specified in the ID parameter.. + * + * @param string|int or screen name + * @param bool + * @return array + */ + public function follow($id, $notify = false) { + //Argument Test + Eden_Twitter_Error::i() + ->argument(1, 'string', 'int') //Argument 1 must be an integer, string + ->argument(2, 'bool'); //Argument 1 must be a boolean + + $query = array(); + + //if it is integer + if(is_int($id)) { + //lets put it in our query + $query['user_id'] = $id; + //else it is string + } else { + //lets put it in our query + $query['screen_name'] = $id; + } + + return $this->_post(self::URL_FOLLOW_FRIENDS, $query); + } + + /** + * Returns an array of numeric IDs for every + * user following the specified user. + * + * @param bool + * @param int|string|null + * @param int|null + * @return array + */ + public function getFollowers($stringify = false, $id = NULL, $cursor = NULL) { + //Argument Test + Eden_Twitter_Error::i() + ->argument(1, 'bool') //Argument 1 must be a boolean + ->argument(2, 'int', 'string', 'null') //Argument 2 must be an integer, string or null + ->argument(3, 'int', 'null'); //Argument 3 must be an integer or null + + $query = array(); + + //if it is not empty + if(!is_null($id)) { + //if it is integer + if(is_int($id)) { + //lets put it in query + $query['user_id'] = $id; + } + + //if it is string + if(is_string($id)) { + //lets put it in query + $query['string_name'] = $id; + } + } + + //if it is not empty + if(!is_null($cursor)) { + //lets put it in query + $query['cursor'] = $cursor; + } + + //if stringify + if($stringify) { + $query['stringify_ids'] = 1; + } + + return $this->_getResponse(self::URL_FOLLOWERS, $query); + } + + /** + * Returns an array of numeric IDs for + * every user the specified user is following. + * + * @param bool + * @param int|string|null user ID or screen name + * @param int|null + * @return array + */ + public function getFollowing($stringify = false, $id = NULL, $cursor = NULL) { + //Argument Test + Eden_Twitter_Error::i() + ->argument(1, 'bool') //Argument 1 must be an boolean + ->argument(2, 'int','string', 'null') //Argument 2 must be an integer, string or null + ->argument(3, 'int', 'null'); //Argument 3 must be an integer or null + + $query = array(); + + //if stringify + if($stringify) { + $query['stringify_ids'] = 1; + } + //if it is not empty + if(!is_null($id)) { + //if it is integer + if(is_int($id)) { + //lets put it in query + $query['user_id'] = $id; + //if it is string + } else { + //lets put it in query + $query['screen_name'] = $id; + } + } + //if it is not empty + if(!is_null($cursor)) { + //lets put it in query + $query['cursor'] = $cursor; + } + + return $this->_getResponse(self::URL_FRIENDS, $query); + } + + /** + * Returns an array of numeric IDs for every protected user + * for whom the authenticating user has a pending follow request. + * + * @param boolean + * @param integer|null + * @return array + */ + public function getPendingFollowing($stringify = false, $cursor = NULL) { + //Argument Test + Eden_Twitter_Error::i() + ->argument(1, 'boolean') //Argument 1 must be a boolean + ->argument(2, 'int', 'null'); //Argument 2 must be an integer or null + + $query = array(); + + //if stringify + if($stringify) { + $query['stringify_ids'] = 1; + } + + //if it is not empty + if(!is_null($cursor)) { + //lets put it in query + $query['cursor'] = $cursor; + } + + return $this->_getResponse(self::URL_OUTGOING_FRIENDS, $query); + } + + /** + * Returns an array of numeric IDs for every user + * who has a pending request to follow the authenticating user. + * + * @param bool + * @param int|null + * @return array + */ + public function getPendingFollowers($stringify = false, $cursor = NULL) { + //Argument Test + Eden_Twitter_Error::i() + ->argument(1, 'boolean') //Argument 1 must be a boolean + ->argument(2, 'int', 'null'); //Argument 2 must be an integer or null + + $query = array(); + + //if stringify + if($stringify) { + $query['stringify_ids'] = 1; + } + + //if it is not empty + if(!is_null($cursor)) { + //lets put it in query + $query['cursor'] = $cursor; + } + + return $this->_getResponse(self::URL_INCOMING_FRIENDS, $query); + } + + /** + * Returns detailed information about the + * relationship between two users. + * + * @param int|string user ID or screen name + * @param int|string user ID or screen name + * @return array + */ + public function getRelationship($id, $target = NULL) { + //Argument Test + Eden_Twitter_Error::i() + ->argument(1, 'string', 'int') //Argument 1 must be an integer, string + ->argument(2, 'string', 'int'); //Argument 2 must be an integer, string + + $query = array(); + + //if it is integer + if(is_int($id)) { + //lets put it in query + $query['source_id'] = $id; + //if it is string + } else { + //lets put it in query + $query['source_screen_name'] = $id; + } + + //if it is integer + if(is_int($target)) { + //lets put it in query + $query['target_id'] = $target; + //if it is string + } else { + //lets put it in query + $query['target_screen_name'] = $target; + } + + return $this->_getResponse(self::URL_SHOW_FRIENDS, $query); + } + + /** + * Returns the relationship of the authenticating user to + * the comma separated list + * + * @param int[,int]|string[,string]|array|null list of user IDs or screen names + * @return array + */ + public function getRelationships($id = NULL) { + //Argument 1 must be an integer, string or null + Eden_Twitter_Error::i() ->argument(1, 'int', 'string', 'array', 'null'); + + $query = array(); + + //if it is empty + if(is_null($id)) { + return $this->_getResponse(self::URL_LOOKUP_FRIENDS, $query); + } + + //if it's not an array + if(!is_array($id)) { + //make it into one + $id = func_get_args(); + } + + //if id is integer + if(is_int($id[0])) { + //lets put it in query + $query['user_id'] = implode(',',$id); + //if it is streing + } else { + //lets put it in query + $query['screen_name'] = implode(',',$id); + } + + return $this->_getResponse(self::URL_LOOKUP_FRIENDS, $query); + } + + /** + * Returns an array of user_ids that the + * currently authenticated user does not + * want to see retweets from. + * + * @param bool + * @return array + */ + public function getUsersNoRetweets($stringify = false) { + //Argument 1 must be an boolean + Eden_Twitter_Error::i()->argument(1, 'bool'); + + $query = array(); + + if($stringify) { + //lets put it in query + $query['stringify_ids'] = 1; + } + + return $this->_getResponse(self::URL_NO_RETWEETS_IDS, $query); + } + + /** + * Allows the authenticating users to unfollow + * the user specified in the ID parameter. + * + * @param string|int user ID or screen name + * @param bool + * @return array + */ + public function unfollow($id, $entities = false) { + //Argument Test + Eden_Twitter_Error::i() + ->argument(1, 'string', 'int') //Argument 1 must be a string or int + ->argument(2, 'boolean'); //Argument 2 must be an boolean + + $query = array(); + + //if it is integer + if(is_int($id)) { + //lets put it in query + $query['user_id'] = $id; + } else { + //lets put it in query + $query['string_name'] = $id; + } + + //if entities + if($entities) { + $query['include_entities'] = $entities; + } + + return $this->_post(self::URL_UNFOLLOW_FRIENDS, $query); + } + + /** + * Allows one to enable or disable retweets and device notifications + * from the specified user. + * + * @param string|int user ID or screen name + * @param boolean + * @param boolean + * @return array + */ + public function update($id, $device = false, $retweets = false) { + //Argument Test + Eden_Twitter_Error::i() + ->argument(1, 'string', 'int') //Argument 1 must be a string or int + ->argument(2, 'bool') //Argument 2 must be a boolean + ->argument(3, 'bool'); //Argument 3 must be a boolean + + $query = array(); + + //if id is string + if(is_string($id)) { + //lets put it in query + $query['screen_name'] = $id; + //else it is integer + } else { + //lets put it in query + $query['user_id'] = $id; + } + + if($device) { + //lets put it in query + $query['device'] = 1; + } + + if($retweets) { + //lets put it in query + $query['retweets'] = 1; + } + + return $this->_post(self::URL_UPDATE, $query); + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/twitter/geo.php b/library/eden/twitter/geo.php new file mode 100644 index 0000000..706c465 --- /dev/null +++ b/library/eden/twitter/geo.php @@ -0,0 +1,320 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Twitter places and geo + * + * @package Eden + * @category twitter + * @author Christian Symon M. Buenavista sbuenavista@openovate.com + */ +class Eden_Twitter_Geo extends Eden_Twitter_Base { + /* Constants + -------------------------------*/ + const URL_GET_PLACE = 'https://api.twitter.com/1/geo/id/%d.json'; + const URL_GET_GEOCODE = 'https://api.twitter.com/1/geo/reverse_geocode.json'; + const URL_SEARCH = 'https://api.twitter.com/1/geo/search.json'; + const URL_GET_SIMILAR_PLACES = 'https://api.twitter.com/1/geo/similar_places.json'; + const URL_CREATE_PLACE = 'https://api.twitter.com/1/geo/place.json'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_accuracy = NULL; + protected $_granularity = NULL; + protected $_max = NULL; + protected $_callback = NULL; + protected $_latitude = NULL; + protected $_longtitude = NULL; + protected $_input = NULL; + protected $_ip = NULL; + protected $_contained = NULL; + protected $_address = NULL; + + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + /* Public Methods + -------------------------------*/ + /** + * Creates a new place object at the given + * latitude and longitude. + * + * @param string + * @param string + * @param string + * @param float + * @param float + * @return array + */ + public function createPlace($name, $contained, $token, $lat, $long) { + //Argument Test + Eden_Twitter_Error::i() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'string') //Argument 2 must be a string + ->argument(3, 'string') //Argument 3 must be a string + ->argument(4, 'float') //Argument 4 must be a float + ->argument(5, 'float'); //Argument 5 must be a float + + //populate fields + $query = array( + 'name' => $name, + 'contained_within' => $contained, + 'token' => $token, + 'lat' => $lat, + 'long' => $long, + 'attribute:street_address' => $this->_address, + 'callback' => $this->_callback); + + return $this->_post(self::URL_CREATE_PLACE, $query); + } + + /** + * Given a latitude and a longitude, searches + * for up to 20 places that can be used as a + * place_id when updating a status + * + * @param float + * @param float + * @return array + */ + public function getGeocode($lat, $long) { + //Argument Test + Eden_Twitter_Error::i() + ->argument(1, 'float') //Argument 1 must be a float + ->argument(2, 'float'); //Argument 2 must be a float + + //populate fields + $query = array( + 'lat' => $lat, + 'long' => $long, + 'accuracy' => $this->_accuracy, + 'granularity' => $this->_granularity, + 'max_results' => $this->_max, + 'callback' => $this->_callback); + + return $this->_getResponse(self::URL_GET_GEOCODE, $query); + } + + /** + * Returns all the information about a known place. + * + * @param int place ID + * @return array + */ + public function getPlace($id) { + //Argument 1 must be an integer + Eden_Twitter_Error::i()->argument(1, 'int'); + + $query = array('place_id' => $id); + + return $this->_getResponse(self::URL_GET_PLACE, $query); + } + + /** + * Locates places near the given coordinates + * which are similar in name. + * + * @param float + * @param float + * @param string + * @return array + */ + public function getSimilarPlaces($lat, $long, $name) { + //Argument Test + Eden_Twitter_Error::i() + ->argument(1, 'float') //Argument 1 must be a float + ->argument(2, 'float') //Argument 2 must be a float + ->argument(3, 'string'); //Argument 3 must be a string + + //populate fields + $query = array( + 'lat' => $lat, + 'long' => $long, + 'name' => $name, + 'contained_within' => $this->_contained, + 'attribute:street_address' => $this->_address, + 'callback' => $this->_callback); + + return $this->_getResponse(self::URL_GET_SIMILAR_PLACES, $query); + } + + /** + * Search for places that can be attached + * to a statuses/update. + * + * @return array + */ + public function search() { + //populate fields + $query = array( + 'lat' => $this->_latitude, + 'long' => $this->_longtitude, + 'query' => $this->_input, + 'accuracy' => $this->_accuracy, + 'granularity' => $this->_granularity, + 'max_results' => $this->_max, + 'contained_within' => $this->_contained, + 'attribute:street_address' => $this->_address, + 'callback' => $this->_callback); + + return $this->_getResponse(self::URL_SEARCH, $query); + } + + /** + * Set accuracy + * + * @param string + * @return this + */ + public function setAccuracy($accuracy) { + //Argument 1 must be a string + Eden_Twitter_Error::i()->argument(1, 'string'); + + $this->_accuracy = $accuracy; + return $this; + } + + /** + * Set street address + * + * @param string + * @return this + */ + public function setAddress($address) { + //Argument 1 must be a string + Eden_Twitter_Error::i()->argument(1, 'string'); + + $this->_address = $address; + return $this; + } + + /** + * Set callback + * + * @param string + * @return this + */ + public function setCallback($callback) { + //Argument 1 must be a string + Eden_Twitter_Error::i()->argument(1, 'string'); + + $this->_callback = $callback; + return $this; + } + + /** + * Set contained within + * + * @param string + * @return this + */ + public function setContained($contained) { + //Argument 1 must be a string + Eden_Twitter_Error::i()->argument(1, 'string'); + + $this->_contained = $contained; + return $this; + } + + /** + * Set granularity + * + * @param string + * @return this + */ + public function setGranularity($granularity) { + //Argument 1 must be a string + Eden_Twitter_Error::i()->argument(1, 'string'); + + $this->_granularity = $granularity; + return $this; + } + + /** + * Set query + * + * @param string + * @return this + */ + public function setInput($input) { + //Argument 1 must be a string + Eden_Twitter_Error::i()->argument(1, 'string'); + + $this->_input = $input; + return $this; + } + + /** + * Set ip address + * + * @param string + * @return this + */ + public function setIp($ip) { + //Argument 1 must be a string + Eden_Twitter_Error::i()->argument(1, 'string'); + + $this->_ip = $ip; + return $this; + } + + /** + * Set latitude + * + * @param float + * @return this + */ + public function setLatitude($latitude) { + //Argument 1 must be a float + Eden_Twitter_Error::i()->argument(1, 'float'); + + $this->_latitude = $latitude; + return $this; + } + + /** + * Set longtitude + * + * @param float + * @return this + */ + public function setLongtitude($longtitude) { + //Argument 1 must be a float + Eden_Twitter_Error::i()->argument(1, 'float'); + + $this->_longtitude = $longtitude; + return $this; + } + + /** + * Set max results + * + * @param integer + * @return this + */ + public function setMax($max) { + //Argument 1 must be an integer + Eden_Twitter_Error::i()->argument(1, 'int'); + + $this->_max = $max; + return $this; + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/twitter/help.php b/library/eden/twitter/help.php new file mode 100644 index 0000000..51fc7c5 --- /dev/null +++ b/library/eden/twitter/help.php @@ -0,0 +1,74 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Twitter help + * + * @package Eden + * @category twitter + * @author Christian Symon M. Buenavista sbuenavista@openovate.com + */ +class Eden_Twitter_Help extends Eden_Twitter_Base { + /* Constants + -------------------------------*/ + const URL_TEST = 'https://api.twitter.com/1/help/test.json'; + const URL_CONFIGURATION = 'https://api.twitter.com/1/help/configuration.json'; + const URL_LANGUAGES = 'https://api.twitter.com/1/help/languages.json'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + /* Public Methods + -------------------------------*/ + /** + * Returns the current configuration used by + * Twitter including twitter.com slugs which + * are not usernames, maximum photo resolutions, + * and t.co URL lengths. + * + * @return array + */ + public function setConfiguration() { + return $this->_getResponse(self::URL_CONFIGURATION); + } + + /** + * Returns the list of languages supported by + * Twitter along with their ISO 639-1 code. + * + * @return array + */ + public function setLanguages() { + return $this->_getResponse(self::URL_LANGUAGES); + } + + /** + * Returns the string "ok" in the requested + * format with a 200 OK HTTP status code. + * + * @return string + */ + public function setTest() { + return $this->_getResponse(self::URL_TEST); + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/twitter/legal.php b/library/eden/twitter/legal.php new file mode 100644 index 0000000..2654483 --- /dev/null +++ b/library/eden/twitter/legal.php @@ -0,0 +1,62 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Twitter legal + * + * @package Eden + * @category twitter + * @author Christian Symon M. Buenavista sbuenavista@openovate.com + */ +class Eden_Twitter_Legal extends Eden_Twitter_Base { + /* Constants + -------------------------------*/ + const URL_PRIVACY = 'https://api.twitter.com/1/legal/privacy.json'; + const URL_TERMS = 'https://api.twitter.com/1/legal/tos.json'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + /* Public Methods + -------------------------------*/ + /** + * Returns Twitter's Privacy Policy + * in the requested format. + * + * @return string + */ + public function getPrivacy() { + return $this->_getResponse(self::URL_PRIVACY); + } + + /** + * Returns the Twitter Terms of Service in + * the requested format. These are not the + * same as the Developer Rules of the Road. + * + * @return string + */ + public function getTerms() { + return $this->_getResponse(self::URL_TERMS); + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/twitter/list.php b/library/eden/twitter/list.php new file mode 100644 index 0000000..8d4ae58 --- /dev/null +++ b/library/eden/twitter/list.php @@ -0,0 +1,980 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Twitter list + * + * @package Eden + * @category twitter + * @author Christian Symon M. Buenavista sbuenavista@openovate.com + * @author Christian Blanquera cblanquera@openovate.com + */ +class Eden_Twitter_List extends Eden_Twitter_Base { + /* Constants + -------------------------------*/ + const URL_ALL_LIST = 'https://api.twitter.com/1/lists/all.json'; + const URL_GET_STATUS = 'https://api.twitter.com/1/lists/statuses.json'; + const URL_REMOVE = 'https://api.twitter.com/1/lists/destroy.json'; + const URL_MEMBERSHIP = 'https://api.twitter.com/1/lists/memberships.json'; + const URL_SUBSCRIBER = 'https://api.twitter.com/1/lists/subscribers.json'; + const URL_CREATE_SUBCRIBER = 'https://api.twitter.com/1/lists/subscribers/create.json'; + const URL_SHOW_SUBSCRIBER = 'https://api.twitter.com/1/lists/subscribers/show.json'; + const URL_REMOVE_SUBCRIBER = 'https://api.twitter.com/1/lists/subscribers/destroy.json'; + const URL_CREATE_ALL = 'https://api.twitter.com/1/lists/members/create_all.json'; + const URL_GET_MEMBER = 'https://api.twitter.com/1/lists/members/show.json'; + const URL_GET_DETAIL = 'https://api.twitter.com/1/lists/members.json'; + const URL_CREATE_MEMBER = 'https://api.twitter.com/1/lists/members/create.json'; + const URL_REMOVE_MEMBER = 'https://api.twitter.com/1/lists/members/destroy'; + const URL_UPDATE = 'https://api.twitter.com/lists/update.json'; + const URL_CREATE_USER = 'https://api.twitter.com/1/lists/create.json'; + const URL_GET_LISTS = 'https://api.twitter.com/1/lists.json'; + const URL_SHOW = 'https://api.twitter.com/1/lists/show.json'; + const URL_GET_SUBSCRITION = 'https://api.twitter.com/1/lists/subscriptions.json'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_since = NULL; + protected $_max = 0; + protected $_perpage = 0; + protected $_cursor = -1; + protected $_entities = false; + protected $_rts = false; + protected $_filter = false; + protected $_status = false; + protected $_count = 0; + + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + /* Public Methods + -------------------------------*/ + /** + * Add a member to a list. The authenticated user + * must own the list to be able to add members + * to it. Note that lists can't have more than 500 members. + * + * @param int|string user ID or screen name + * @param int|string list ID or slug + * @param int|string|null owner ID or screen name + * @return array + */ + public function addMember($userId, $listId, $ownerId = NULL) { + Eden_Twitter_Error::i() + ->argument(1, 'int', 'string') //Argument 1 must be an integer or string + ->argument(2, 'int', 'string') //Argument 2 must be an integer or string + ->argument(3, 'int', 'string', 'null'); //Argument 3 must be an integer, null or string + + $query = array(); + + //if it is integer + if(is_int($listId)) { + //lets put it in our query + $query['list_id'] = $listId; + //else it is string + } else { + //lets put it in our query + $query['slug'] = $listId; + } + + if(!is_null($ownerId)) { + //if it is integer + if(is_int($ownerId)) { + //lets put it in our query + $query['owner_id'] = $ownerId; + //else it is string + } else { + //lets put it in our query + $query['owner_screen_name'] = $ownerId; + } + } + + //if it is integer + if(is_int($user_id)) { + //lets put it in our query + $query['user_id'] = $user_id; + //else it is string + } else { + //lets put it in our query + $query['screen_name'] = $user_id; + } + + return $this->_post(self::URL_CREATE_MEMBER, $query); + } + + /** + * Adds multiple members to a list, by specifying a + * comma-separated list of member ids or screen names. + * + * @param int|string list ID or slug + * @param array list of user IDs + * @param int|string ownder ID or screen name + * @return array + */ + public function addMembers($listId, $userIds, $ownerId = NULL) { + Eden_Twitter_Error::i() + ->argument(1, 'int', 'string') //Argument 1 must be an integer or string + ->argument(2, 'array') //Argument 2 must be an array + ->argument(3, 'int', 'string'); //Argument 3 must be an integer or string + + $query = array(); + + //if it is integer + if(is_int($listId)) { + //lets put it in our query + $query['list_id'] = $listId; + //else it is string + } else { + //lets put it in our query + $query['slug'] = $listId; + } + + //if it is integer + if(is_int($ownerId)) { + //lets put it in our query + $query['owner_id'] = $ownerId; + //else it is string + } else { + //lets put it in our query + $query['owner_screen_name'] = $ownerId; + } + + //if id is integer + if(is_int($userIds[0])) { + //lets put it in query + $query['user_id'] = implode(',',$userIds); + //if it is streing + } else { + //lets put it in query + $query['screen_name'] = implode(',',$userIds); + } + + return $this->_post(self::URL_CREATE_ALL, $query); + } + + /** + * Creates a new list for the authenticated user. + * Note that you can't create more than 20 lists per account. + * + * @param string + * @param string|null + * @param bool + * @return array + */ + public function createList($name, $description = NULL, $public = true) { + Eden_Twitter_Error::i() + ->argument(1, 'string') + ->argument(2, 'string', 'null') + ->argument(3, 'bool'); + + $query = array('name' => $name); + + if($description) { + $query['description'] = $description; + } + + if(!$public) { + $query['mode'] = 'private'; + } + + return $this->_post(self::URL_CREATE_USER, $query); + } + + /** + * Returns the members of the specified list. + * Private list members will only be shown if + * the authenticated user owns the specified list. + * + * @param int|string list ID or slug + * @param int|string|null owner ID or screen name + * @return array + */ + public function getMembers($listId, $ownerId = NULL) { + Eden_Twitter_Error::i() + ->argument(1, 'int', 'string') //Argument 1 must be an integer or string + ->argument(2, 'int', 'string', 'null'); //Argument 2 must be an integer, null or string + + $query = array(); + + //if it is integer + if(is_int($listId)) { + //lets put it in our query + $query['list_id'] = $listId; + //else it is string + } else { + //lets put it in our query + $query['slug'] = $listId; + } + + if(!is_null($ownerId)) { + //if it is integer + if(is_int($ownerId)) { + //lets put it in our query + $query['owner_id'] = $ownerId; + //else it is string + } else { + //lets put it in our query + $query['owner_screen_name'] = $ownerId; + } + } + + if($this->_entities) { + $query['include_entities'] = 1; + } + + if($this->_status) { + $query['skip_status'] = 1; + } + + if($this->_cursor != -1) { + $query['cursor'] = $this->_cursor; + } + + return $this->_getResponse(self::URL_GET_DETAIL, $query); + } + + /** + * Returns all lists the authenticating or specified user + * subscribes to, including their own. + * + * @return array + */ + public function getAllLists() { + //populate fields + $query = array( + 'user_id' => $this->_id, + 'screen_name' => $this->_name); + + return $this->_getResponse(self::URL_ALL_LIST, $query); + } + + /** + * Returns the lists of the specified (or authenticated) + * user. Private lists will be included if the + * authenticated user is the same as the user whose + * lists are being returned. + * + * @param int + * @param string + * @return array + */ + public function getLists($id, $name) { + //Argument Test + Eden_Twitter_Error::i() + ->argument(1, 'int') //Argument 1 must be an integer + ->argument(2, 'string'); //Argument 2 must be a string + + //populate fields + $query = array( + 'user_id' => $id, + 'screen_name' => $name); + + if($this->_cursor != -1) { + $query['cursor'] = $this->_cursor; + } + + return $this->_getResponse(self::URL_GET_LISTS, $query); + } + + /** + * Returns the specified list. Private lists will only + * be shown if the authenticated user owns the specified list. + * + * @param int|string list ID or slug + * @param int|string|null owner ID or screen name + * @return array + */ + public function getList($listId, $ownerId = NULL) { + Eden_Twitter_Error::i() + ->argument(1, 'int', 'string') //Argument 1 must be an integer or string + ->argument(2, 'int', 'string', 'null'); //Argument 2 must be an integer, null or string + + $query = array(); + + //if it is integer + if(is_int($listId)) { + //lets put it in our query + $query['list_id'] = $listId; + //else it is string + } else { + //lets put it in our query + $query['slug'] = $listId; + } + + if(!is_null($ownerId)) { + //if it is integer + if(is_int($ownerId)) { + //lets put it in our query + $query['owner_id'] = $ownerId; + //else it is string + } else { + //lets put it in our query + $query['owner_screen_name'] = $ownerId; + } + } + + return $this->_getResponse(self::URL_SHOW, $query); + } + + /** + * Returns the lists the specified user has been + * added to. If user_id or screen_name are not + * provided the memberships for the authenticating + * user are returned. + * + * @param int|string|null user ID or screen name + * @return array + */ + public function getMemberships($id = NULL) { + //Argument 1 must be an integer, null or string + Eden_Twitter_Error::i()->argument(1, 'int', 'string', 'null'); + + $query = array(); + + if(!is_null($id)) { + //if it is integer + if(is_int($id)) { + //lets put it in our query + $query['user_id'] = $id; + //else it is string + } else { + //lets put it in our query + $query['screen_name'] = $id; + } + } + + if($this->_cursor != -1) { + $query['cursor'] = $this->_cursor; + } + + if($this->_filter) { + $query['filter_to_owned_lists'] = 1; + } + + return $this->_getResponse(self::URL_MEMBERSHIP, $query); + } + + /** + * Returns tweet timeline for members + * of the specified list. + * + * @param int|string list ID or slug + * @param int|string|null owner ID or screen name + * @return array + */ + public function getTweets($listId, $ownerId = NULL) { + Eden_Twitter_Error::i() + ->argument(1, 'int', 'string') //Argument 1 must be an integer or string + ->argument(2, 'int', 'string', 'null'); //Argument 2 must be an integer, null or string + + $query = array(); + + //if it is integer + if(is_int($listId)) { + //lets put it in our query + $query['list_id'] = $listId; + //else it is string + } else { + //lets put it in our query + $query['slug'] = $listId; + } + + if(!is_null($ownerId)) { + //if it is integer + if(is_int($ownerId)) { + //lets put it in our query + $query['owner_id'] = $ownerId; + //else it is string + } else { + //lets put it in our query + $query['owner_screen_name'] = $ownerId; + } + } + + if($this->_entities) { + $query['include_entities'] = 1; + } + + if($this->_rts) { + $query['include_rts'] = 1; + } + + if($this->_since) { + $query['since_id'] = $this->_since; + } + + if($this->_max) { + $query['max_id'] = $this->_max; + } + + if($this->_perpage) { + $query['per_page'] = $this->_perpage; + } + + return $this->_getResponse(self::URL_GET_STATUS, $query); + } + + /** + * Returns the subscribers of the specified list. Private list + * subscribers will only be shown if the authenticated user owns + * the specified list. + * + * @param int|string list ID or slug + * @param int|string|null owner ID or screen name + * @return array + */ + public function getSubscribers($listId, $ownerId = NULL) { + Eden_Twitter_Error::i() + ->argument(1, 'int', 'string') //Argument 1 must be an integer or string + ->argument(2, 'int', 'string', 'null'); //Argument 2 must be an integer, null or string + + $query = array(); + + //if it is integer + if(is_int($listId)) { + //lets put it in our query + $query['list_id'] = $listId; + //else it is string + } else { + //lets put it in our query + $query['slug'] = $listId; + } + + if(!is_null($ownerId)) { + //if it is integer + if(is_int($ownerId)) { + //lets put it in our query + $query['owner_id'] = $ownerId; + //else it is string + } else { + //lets put it in our query + $query['owner_screen_name'] = $ownerId; + } + } + + if($this->_entities) { + $query['include_entities'] = 1; + } + + if($this->_status) { + $query['skip_status'] = 1; + } + + if($this->_cursor != -1) { + $query['cursor'] = $this->_cursor; + } + + return $this->_getResponse(self::URL_SUBSCRIBER,$query); + } + + /** + * Obtain a collection of the lists the specified user is subscribed to, + * 20 lists per page by default. Does not include the user's own lists. + * + * @param int|string user ID or screen name + * @return array + */ + public function getSubscriptions($id) { + //Argument 1 must be an integer or string + Eden_Twitter_Error::i()->argument(1, 'int', 'string'); + + $query = array(); + + //if it is integer + if(is_int($id)) { + //lets put it in our query + $query['user_id'] = $id; + //else it is string + } else { + //lets put it in our query + $query['screen_name'] = $id; + } + + if($this->_cursor != -1) { + $query['cursor'] = $this->_cursor; + } + + if($this->_count) { + $query['count'] = $this->_count; + } + + return $this->_getResponse(self::URL_GET_SUBSCRITION, $query); + } + + /** + * Will return just lists the authenticating user owns, and the user + * represented by user_id or screen_name is a member of. + * + * @return this + */ + public function filterToOwn() { + $this->_filter = true; + return $this; + } + + /** + * Each tweet will include a node called "entities". This node offers a variety + * of metadata about the tweet in a discreet structure, including: user_mentions, + * urls, and hashtags. + * + * @return this + */ + public function includeEntities() { + $this->_entities = true; + return $this; + } + + /** + * The list timeline will contain native retweets (if they exist) in addition to the + * standard stream of tweets. The output format of retweeted tweets is identical to + * the representation you see in home_timeline. + * + * @return this + */ + public function includeRts() { + $this->_rts = true; + return $this; + } + + /** + * Check if the specified user is a member of the specified list. + * + * @param int|string user ID or screen name + * @param int|string list ID or slug + * @param int|string|null owner ID or screen name + * @return array + */ + public function isMember($userId, $listId, $ownerId = NULL) { + Eden_Twitter_Error::i() + ->argument(1, 'int', 'string') //Argument 1 must be an integer or string + ->argument(2, 'int', 'string') //Argument 2 must be an integer or string + ->argument(3, 'int', 'string', 'null'); //Argument 3 must be an integer, null or string + + $query = array(); + + //if it is integer + if(is_int($listId)) { + //lets put it in our query + $query['list_id'] = $listId; + //else it is string + } else { + //lets put it in our query + $query['slug'] = $listId; + } + + if(!is_null($ownerId)) { + //if it is integer + if(is_int($ownerId)) { + //lets put it in our query + $query['owner_id'] = $ownerId; + //else it is string + } else { + //lets put it in our query + $query['owner_screen_name'] = $ownerId; + } + } + + //if it is integer + if(is_int($user_id)) { + //lets put it in our query + $query['user_id'] = $user_id; + //else it is string + } else { + //lets put it in our query + $query['screen_name'] = $user_id; + } + + if($this->_entities) { + $query['include_entities'] = 1; + } + + if($this->_status) { + $query['skip_status'] = 1; + } + + return $this->_getResponse(self::URL_GET_MEMBER, $query); + } + + /** + * Check if the specified user is a subscriber of the specified list. + * Returns the user if they are subscriber. + * + * @param int|string user ID or screen name + * @param int|string list ID or slug + * @param int|string|null owner ID or screen name + * @return array + */ + public function isSubsciber($userId, $listId, $ownerId = NULL) { + Eden_Twitter_Error::i() + ->argument(1, 'int', 'string') //Argument 1 must be an integer or string + ->argument(2, 'int', 'string') //Argument 2 must be an integer or string + ->argument(3, 'int', 'string', 'null'); //Argument 3 must be an integer, null or string + + $query = array(); + + //if it is integer + if(is_int($listId)) { + //lets put it in our query + $query['list_id'] = $listId; + //else it is string + } else { + //lets put it in our query + $query['slug'] = $listId; + } + + if(!is_null($ownerId)) { + //if it is integer + if(is_int($ownerId)) { + //lets put it in our query + $query['owner_id'] = $ownerId; + //else it is string + } else { + //lets put it in our query + $query['owner_screen_name'] = $ownerId; + } + } + + //if it is integer + if(is_int($user_id)) { + //lets put it in our query + $query['user_id'] = $user_id; + //else it is string + } else { + //lets put it in our query + $query['screen_name'] = $user_id; + } + + if($this->_entities) { + $query['include_entities'] = 1; + } + + if($this->_status) { + $query['skip_status'] = 1; + } + + return $this->_getResponse(self::URL_SHOW_SUBSCRIBER, $query); + } + + /** + * Deletes the specified list. The authenticated + * user must own the list to be able to destroy it + * + * @param int|string list ID or slug + * @param int|string|null owner ID or screen name + * @return array + */ + public function remove($listId, $ownerId = NULL) { + Eden_Twitter_Error::i() + ->argument(1, 'int', 'string') //Argument 1 must be an integer or string + ->argument(2, 'int', 'string', 'null'); //Argument 2 must be an integer, null or string + + $query = array(); + + //if it is integer + if(is_int($listId)) { + //lets put it in our query + $query['list_id'] = $listId; + //else it is string + } else { + //lets put it in our query + $query['slug'] = $listId; + } + + if(!is_null($ownerId)) { + //if it is integer + if(is_int($ownerId)) { + //lets put it in our query + $query['owner_id'] = $ownerId; + //else it is string + } else { + //lets put it in our query + $query['owner_screen_name'] = $ownerId; + } + } + + return $this->_post(self::URL_REMOVE,$query); + } + + /** + * Removes the specified member from the list. + * The authenticated user must be the list's + * owner to remove members from the list. + * + * @param int|string user ID or screen name + * @param int|string list ID or slug + * @param int|string|null owner ID or screen name + * @return array + */ + public function removeMember($userId, $listId, $ownerId = NULL) { + Eden_Twitter_Error::i() + ->argument(1, 'int', 'string') //Argument 1 must be an integer or string + ->argument(2, 'int', 'string') //Argument 2 must be an integer or string + ->argument(3, 'int', 'string', 'null'); //Argument 3 must be an integer, null or string + + $query = array(); + + //if it is integer + if(is_int($listId)) { + //lets put it in our query + $query['list_id'] = $listId; + //else it is string + } else { + //lets put it in our query + $query['slug'] = $listId; + } + + if(!is_null($ownerId)) { + //if it is integer + if(is_int($ownerId)) { + //lets put it in our query + $query['owner_id'] = $ownerId; + //else it is string + } else { + //lets put it in our query + $query['owner_screen_name'] = $ownerId; + } + } + + //if it is integer + if(is_int($user_id)) { + //lets put it in our query + $query['user_id'] = $ownerId; + //else it is string + } else { + //lets put it in our query + $query['screen_name'] = $ownerId; + } + + return $this->_post(self::URL_REMOVE_MEMBER, $query); + } + + /** + * Sets count + * + * @param integer + * @return this + */ + public function setCount($count) { + //Argument 1 must be an integer + Eden_Twitter_Error::i()->argument(1, 'int'); + + $this->_count = $count; + return $this; + } + + /** + * Causes the list of connections to be broken into pages of no more than 5000 + * IDs at a time. The number of IDs returned is not guaranteed to be 5000 as + * suspended users are filtered out after connections are queried. + * + * @param string + * @return this + */ + public function setCursor($cursor) { + //Argument 1 must be a string + Eden_Twitter_Error::i()->argument(1, 'string'); + + $this->_cursor = $cursor; + return $this; + } + + /** + * Set max id + * + * @param integer + * @return this + */ + public function setMax($max) { + //Argument 1 must be an integer + Eden_Twitter_Error::i()->argument(1, 'int'); + + $this->_max = $max; + return $this; + } + + /** + * Sets page + * + * @param integer + * @return this + */ + public function setPage($perpage) { + //Argument 1 must be an integer + Eden_Twitter_Error::i()->argument(1, 'int'); + + $this->_perpage = $perpage; + return $this; + } + + /** + * Set since id + * + * @param integer the tweet ID + * @return array + */ + public function setSince($since) { + //Argument 1 must be an integer + Eden_Twitter_Error::i()->argument(1, 'int'); + + $this->_since = $since; + return $this; + } + + /** + * Statuses will not be included in the returned user objects. + * + * @return this + */ + public function skipStatus() { + $this->_status = true; + return $this; + } + + /** + * Subscribes the authenticated + * user to the specified list. + * + * @param int|string list ID or slug + * @param int|string|null owner ID or screen name + * @return array + */ + public function subscribe($listId, $ownerId = NULL) { + Eden_Twitter_Error::i() + ->argument(1, 'int', 'string') //Argument 1 must be an integer or string + ->argument(2, 'int', 'string', 'null'); //Argument 2 must be an integer, null or string + + $query = array(); + + //if it is integer + if(is_int($listId)) { + //lets put it in our query + $query['list_id'] = $listId; + //else it is string + } else { + //lets put it in our query + $query['slug'] = $listId; + } + + if(!is_null($ownerId)) { + //if it is integer + if(is_int($ownerId)) { + //lets put it in our query + $query['owner_id'] = $ownerId; + //else it is string + } else { + //lets put it in our query + $query['owner_screen_name'] = $ownerId; + } + } + + return $this->_post(self::URL_CREATE_SUBCRIBER, $query); + } + + /** + * Unsubscribes the authenticated + * user from the specified list. + * + * @param int|string list ID or slug + * @param int|string|null owner ID or screen name + * @return array + */ + public function unsubscribe($listId, $ownerId = NULL) { + Eden_Twitter_Error::i() + ->argument(1, 'int', 'string') //Argument 1 must be an integer or string + ->argument(2, 'int', 'string', 'null'); //Argument 2 must be an integer, null or string + + $query = array(); + + //if it is integer + if(is_int($listId)) { + //lets put it in our query + $query['list_id'] = $listId; + //else it is string + } else { + //lets put it in our query + $query['slug'] = $listId; + } + + if(!is_null($ownerId)) { + //if it is integer + if(is_int($ownerId)) { + //lets put it in our query + $query['owner_id'] = $ownerId; + //else it is string + } else { + //lets put it in our query + $query['owner_screen_name'] = $ownerId; + } + } + + return $this->_post(self::URL_REMOVE_SUBCRIBER, $query); + } + + /** + * Updates the specified list. The authenticated user must own + * the list to be able to update it. + * + * @param int|string list ID or slug + * @param string + * @param string + * @param int|string|null owner ID or screen name + * @param bool + * @return array + */ + public function update($listId, $name, $description, $ownerId = NULL, $public = true) { + Eden_Twitter_Error::i() + ->argument(1, 'int', 'string') //Argument 1 must be an integer or string + ->argument(2, 'string') //Argument 2 must be an string + ->argument(3, 'string') //Argument 3 must be an string + ->argument(4, 'int', 'string', 'null') //Argument 4 must be an integer, string or null + ->argument(5, 'bool'); //Argument 3 must be an boolean + $query = array( + 'name' => $name, + 'description' => $description); + + //if it is integer + if(is_int($listId)) { + //lets put it in our query + $query['list_id'] = $listId; + //else it is string + } else { + //lets put it in our query + $query['slug'] = $listId; + } + + if(!is_null($ownerId)) { + //if it is integer + if(is_int($ownerId)) { + //lets put it in our query + $query['owner_id'] = $ownerId; + //else it is string + } else { + //lets put it in our query + $query['owner_screen_name'] = $ownerId; + } + } + + if(!$public) { + $query['mode'] = 'private'; + } + + return $this->_post(self::URL_UPDATE, $query); + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/twitter/localtrends.php b/library/eden/twitter/localtrends.php new file mode 100644 index 0000000..a2bcdbb --- /dev/null +++ b/library/eden/twitter/localtrends.php @@ -0,0 +1,96 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Twitter local trends + * + * @package Eden + * @category twitter + * @author Christian Symon M. Buenavista sbuenavista@openovate.com + */ +class Eden_Twitter_LocalTrends extends Eden_Twitter_Base { + /* Constants + -------------------------------*/ + const URL_GET_LIST = 'https://api.twitter.com/1/trends/1.json'; + const URL_GET_DETAIL = 'https://api.twitter.com/1/trends/available.json'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + /* Public Methods + -------------------------------*/ + /** + * Returns the locations that Twitter has + * trending topic information + * + * @param float|null + * @param float|null + * @return array + */ + public function getDetail($lat = NULL, $long = NULL) { + //Argument Test + Eden_Twitter_Error::i() + ->argument(1, 'float', 'null') //Argument 1 must be a float or null + ->argument(2, 'float', 'null'); //Argument 2 must be a float or null + + $query = array(); + + //if it is not empty + if(!is_null($lat)) { + //lets put it in query + $query['lat'] = $lat; + } + + //if it is not empty + if(!is_null($long)) { + //lets put it in query + $query['long'] = $long; + } + + return $this->_getResponse(self::URL_GET_DETAIL); + } + + /** + * Returns the top 10 trending topics for a specific + * WOEID, if trending information is available for it. + * + * @param integer + * @param string|null + * @return array + */ + public function getList($id, $exclude = NULL) { + //Argument Test + Eden_Twitter_Error::i() + ->argument(1, 'int') //Argument 1 must be an integer + ->argument(2, 'string', 'null'); //Argument 2 must be a string or null + + $query = array('woeid' => $id); + //if it is not empty + if(!is_null($exclude)) { + //lets put it in query + $query['exclude'] = $exclude; + } + + return $this->_getResponse(self::URL_GET_LIST); + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/twitter/notification.php b/library/eden/twitter/notification.php new file mode 100644 index 0000000..0005822 --- /dev/null +++ b/library/eden/twitter/notification.php @@ -0,0 +1,95 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Twitter notification + * + * @package Eden + * @category twitter + * @author Christian Symon M. Buenavista sbuenavista@openovate.com + */ +class Eden_Twitter_Notification extends Eden_Twitter_Base { + /* Constants + -------------------------------*/ + const URL_FOLLOW = 'https://api.twitter.com/1/notifications/follow.json'; + const URL_LEAVE = 'https://api.twitter.com/1/notifications/leave.json'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + /* Public Methods + -------------------------------*/ + /** + * Enables device notifications for updates + * from the specified user. Returns the + * specified user when successful. + * + * @param string|int user ID or screen name + * @return array + */ + public function follow($id) { + //Argument 1 must be a string or integer + Eden_Twitter_Error::i()->argument(1, 'string', 'int'); + + $query = array(); + + //if it is integer + if(is_int($id)) { + //lets put it in our query + $query['user_id'] = $id; + //else it is string + } else { + //lets put it in our query + $query['screen_name'] = $id; + } + + return $this->_post(self::URL_FOLLOW, $query); + } + + /** + * Disables notifications for updates from the + * specified user to the authenticating user. + * Returns the specified user when successful. + * + * @param string|int user ID or screen name + * @return array + */ + public function leave($id) { + //Argument 1 must be a string or integer + Eden_Twitter_Error::i()->argument(1, 'string', 'int'); + + $query = array(); + + //if it is integer + if(is_int($id)) { + //lets put it in our query + $query['user_id'] = $id; + //else it is string + } else { + //lets put it in our query + $query['screen_name'] = $id; + } + + return $this->_post(self::URL_LEAVE, $query); + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/twitter/oauth.php b/library/eden/twitter/oauth.php new file mode 100644 index 0000000..3fa1531 --- /dev/null +++ b/library/eden/twitter/oauth.php @@ -0,0 +1,123 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Twitter oauth + * + * @package Eden + * @category twitter + * @author Christian Blanquera cblanquera@openovate.com + */ +class Eden_Twitter_Oauth extends Eden_Class { + /* Constants + -------------------------------*/ + const REQUEST_URL = 'https://api.twitter.com/oauth/request_token'; + const AUTHORIZE_URL = 'https://api.twitter.com/oauth/authorize'; + const ACCESS_URL = 'https://api.twitter.com/oauth/access_token'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_key = NULL; + protected $_secret = NULL; + + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + public function __construct($key, $secret) { + //argument test + Eden_Twitter_Error::i() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'string'); //Argument 2 must be a string + + $this->_key = $key; + $this->_secret = $secret; + } + + /* Public Methods + -------------------------------*/ + /** + * Returns the access token + * + * @param string the response key; from the url usually + * @param string the request secret; from getRequestToken() usually + * @return string the response verifier; from the url usually + */ + public function getAccessToken($token, $secret, $verifier) { + //argument test + Eden_Twitter_Error::i() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'string') //Argument 2 must be a string + ->argument(3, 'string'); //Argument 3 must be a string + + return Eden_Oauth::i() + ->consumer( + self::ACCESS_URL, + $this->_key, + $this->_secret) + ->useAuthorization() + ->setMethodToPost() + ->setToken($token, $secret) + ->setVerifier($verifier) + ->setSignatureToHmacSha1() + ->getQueryResponse(); + } + + /** + * Returns the URL used for login. + * + * @param string the request key + * @param string + * @param boolean force user re-login + * @return string + */ + public function getLoginUrl($token, $redirect, $force_login = false) { + //Argument tests + Eden_Twitter_Error::i() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'string') //Argument 2 must be a string + ->argument(3, 'bool'); //Argument 3 must be a boolean + + //build the query + $query = array('oauth_token' => $token, 'oauth_callback' => $redirect, 'force_login' => (int)$force_login); + $query = http_build_query($query); + + return self::AUTHORIZE_URL.'?'.$query; + } + + /** + * Return a request token + * + * @return string + */ + public function getRequestToken() { + return Eden_Oauth::i() + ->consumer( + self::REQUEST_URL, + $this->_key, + $this->_secret) + ->useAuthorization() + ->setMethodToPost() + ->setSignatureToHmacSha1() + ->getQueryResponse(); + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/twitter/saved.php b/library/eden/twitter/saved.php new file mode 100644 index 0000000..3928168 --- /dev/null +++ b/library/eden/twitter/saved.php @@ -0,0 +1,105 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Twitter saved searches + * + * @package Eden + * @category twitter + * @author Christian Symon M. Buenavista sbuenavista@openovate.com + */ +class Eden_Twitter_Saved extends Eden_Twitter_Base { + /* Constants + -------------------------------*/ + const URL_SAVED_SEARCHES = 'https://api.twitter.com/1/saved_searches.json'; + const URL_GET_DETAIL = 'https://api.twitter.com/1/saved_searches/show/%d.json'; + const URL_CREATE_SEARCH = 'https://api.twitter.com/1/saved_searches/create.json'; + const URL_REMOVE = 'https://api.twitter.com/1/saved_searches/destroy/%d.json'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + /* Public Methods + -------------------------------*/ + /** + * Create a new saved search for the authenticated user. + * A user may only have 25 saved searches. + * + * @param string + * @return array + */ + public function createSearch($input) { + //Argument 1 must be a integer + Eden_Twitter_Error::i()->argument(1, 'string'); + + $query = array('query' => $input); + + $url = sprintf(self::URL_CREATE_SEARCH, $input); + return $this->_post($url,$query); + } + + /** + * Retrieve the information for the saved search represented + * by the given id. The authenticating user must be the + * owner of saved search ID being requested. + * + * @param int search ID + * @return array + */ + public function getDetail($id) { + //Argument 1 must be a integer + Eden_Twitter_Error::i()->argument(1, 'int'); + + $query = array('id' => $id); + + return $this->_getResponse(self::URL_GET_DETAIL, $query); + } + + /** + * Returns the authenticated user's + * saved search queries. + * + * @return array + */ + public function getSavedSearches() { + return $this->_getResponse(self::URL_SAVED_SEARCHES); + } + + /** + * Destroys a saved search for the authenticating user. + * The authenticating user must be the owner of + * saved search id being destroyed. + * + * @param int search ID + * @return array + */ + public function remove($id) { + //Argument 1 must be a integer + Eden_Twitter_Error::i()->argument(1, 'int'); + + $query = array('id' => $id); + + $url = sprintf(self::URL_REMOVE, $id); + return $this->_post($url,$query); + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/twitter/search.php b/library/eden/twitter/search.php new file mode 100644 index 0000000..fa6c9d6 --- /dev/null +++ b/library/eden/twitter/search.php @@ -0,0 +1,284 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Twitter search + * + * @package Eden + * @category twitter + * @author Christian Symon M. Buenavista sbuenavista@openovate.com + */ +class Eden_Twitter_Search extends Eden_Twitter_Base { + /* Constants + -------------------------------*/ + const URL_SEARCH = 'http://search.twitter.com/search.json'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected static $_validResult = array('mixed', 'recent', 'popular'); + + protected $_callback = NULL; + protected $_geocode = NULL; + protected $_lang = NULL; + protected $_locale = NULL; + protected $_page = NULL; + protected $_result = NULL; + protected $_rpp = 25; + protected $_until = NULL; + protected $_since = 0; + protected $_show = 0; + protected $_entities = false; + + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + /* Public Methods + -------------------------------*/ + /** + * Returns tweets that match a specified query + * + * @param string|integer + * @return array + */ + public function search($search) { + //Argument 1 must be a string or integer + Eden_Twitter_Error::i()->argument(1, 'string', 'integer'); + + $query = array('q' => $search); + + if($this->_callback) { + $query['callback'] = $this->_callback; + } + + if($this->_geocode) { + $query['geocode'] = $this->_geocode; + } + + if($this->_lang) { + $query['lang'] = $this->_lang; + } + + if($this->_locale) { + $query['locale'] = $this->_locale; + } + + if($this->_page) { + $query['page'] = $this->_page; + } + + if($this->_result) { + $query['result_type'] = $this->_result; + } + + if($this->_rpp) { + $query['rpp'] = $this->_rpp; + } + + if($this->_show) { + $query['show_user'] = $this->_show; + } + + if($this->_until) { + $query['until'] = $this->_until; + } + + if($this->_since) { + $query['since_id'] = $this->_since; + } + + if($this->_entities) { + $query['include_entities'] = 1; + } + + return $this->_getResponse(self::URL_SEARCH, $query); + } + + /** + * Set callback + * + * @param string + * @return this + */ + public function setCallback($callback) { + //Argument 1 must be a string + Eden_Twitter_Error::i()->argument(1, 'string'); + + $this->_callback = $callback; + return $this; + } + + /** + * Set include entites + * + * @return this + */ + public function includeEntities() { + $this->_entities = true; + return $this; + } + + /** + * Set geocode + * + * @param string + * @return this + */ + public function setGeocode($geocode) { + //Argument 1 must be a string + Eden_Twitter_Error::i()->argument(1, 'string'); + + $this->_geocode = $geocode; + return $this; + } + + /** + * Set lang + * + * @param string + * @return this + */ + public function setLang($lang) { + //Argument 1 must be a string + Eden_Twitter_Error::i()->argument(1, 'string'); + + $this->_lang = $lang; + return $this; + } + + /** + * Set locale + * + * @param string + * @return this + */ + public function setLocale($locale) { + //Argument 1 must be a string + Eden_Twitter_Error::i()->argument(1, 'string'); + + $this->_locale = $locale; + return $this; + } + + /** + * Set page + * + * @param integer + * @return this + */ + public function setPage($page) { + //Argument 1 must be an integer + Eden_Twitter_Error::i()->argument(1, 'int'); + + $this->_page = $page; + return $this; + } + + /** + * Set mixed result + * + * @return this + */ + public function setMixedResultType() { + $this->_result = 'mixed'; + return $this; + } + + /** + * Set recent result + * + * @return this + */ + public function setRecentResultType() { + $this->_result = 'recent'; + return $this; + } + + /** + * Set populat result + * + * @return this + */ + public function setPopularResultType() { + $this->_result = 'popular'; + return $this; + } + + /** + * Set rpp + * + * @param int The number of tweets to return per page, up to a max of 100 + * @return this + */ + public function setRpp($rpp) { + //Argument 1 must be a string + Eden_Twitter_Error::i()->argument(1, 'string'); + + if($this->_rpp > 100) { + $this->_rpp = 100; + } + + $this->_rpp = $rpp; + return $this; + } + + /** + * Set since id + * + * @param int + * @return this + */ + public function setSince($since) { + //Argument 1 must be a string + Eden_Twitter_Error::i()->argument(1, 'int'); + + $this->_since = $since; + return $this; + } + + /** + * Set show user + * + * @return this + */ + public function showUser() { + $this->_show = true; + return $this; + } + + /** + * Set until + * + * @param string|int unix time for date format + * @return this + */ + public function setUntil($until) { + //Argument 1 must be a string + Eden_Twitter_Error::i()->argument(1, 'string', 'int'); + + if(is_string($until)) { + $until = strtotime($until); + } + + $until = date('Y-m-d', $until); + $this->_until = $until; + return $this; + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/twitter/spam.php b/library/eden/twitter/spam.php new file mode 100644 index 0000000..2d8d236 --- /dev/null +++ b/library/eden/twitter/spam.php @@ -0,0 +1,71 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Twitter spam reporting + * + * @package Eden + * @category twitter + * @author Christian Symon M. Buenavista sbuenavista@openovate.com + */ +class Eden_Twitter_Spam extends Eden_Twitter_Base { + /* Constants + -------------------------------*/ + const URL_REPORT_SPAM = 'http://api.twitter.com/1/report_spam.json'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + /* Public Methods + -------------------------------*/ + /** + * The user specified in the id is blocked by the + * authenticated user and reported as a spammer + * + * @param sting|null + * @param string|null + * @return array + */ + public function reportSpam($id = NULL, $name = NULL) { + //Argument Test + Eden_Twitter_Error::i() + ->argument(1, 'string', 'null') //Argument 1 must be a string or null + ->argument(2, 'string', 'null'); //Argument 2 must be a string or null + + $query = array(); + + //if it is not empty + if(!is_null($id)) { + //lets put it in query + $query['user_id'] = $id; + } + + //if it is not empty + if(!is_null($name)) { + //lets put it in query + $query['screen_name'] = $name; + } + + return $this->_post(self::URL_REPORT_SPAM, $query); + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/twitter/suggestions.php b/library/eden/twitter/suggestions.php new file mode 100644 index 0000000..a319cbd --- /dev/null +++ b/library/eden/twitter/suggestions.php @@ -0,0 +1,103 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Twitter suggestion + * + * @package Eden + * @category twitter + * @author Christian Symon M. Buenavista sbuenavista@openovate.com + */ +class Eden_Twitter_Suggestions extends Eden_Twitter_Base { + /* Constants + -------------------------------*/ + const URL_SUGGESTION = 'https://api.twitter.com/1/users/suggestions.json'; + const URL_GET_CATEGORY = 'https://api.twitter.com/1/users/suggestions/twitter.json'; + const URL_GET_RECENT_STATUS = 'https://api.twitter.com/1/users/suggestions/funny/members.json'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + /* Public Methods + -------------------------------*/ + /** + * Access the users in a given category of the + * Twitter suggested user list. + * + * @param string + * @param string|null + * @return array + */ + public function getCategory($slug, $lang = NULL) { + //Argument Test + Eden_Twitter_Error::i() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'string', 'null'); //Argument 2 must be a string or null + + $query = array('slug' => $slug); + + //if it is not empty + if(!is_null($lang)) { + //lets put it in our query + $query['lang'] = $lang; + } + + return $this->_getResponse(self::URL_GET_CATEGORY, $query); + } + + /** + * Access the users in a given category of the Twitter + * suggested user list and return their most recent + * status if they are not a protected user. + * + * @param string + * @return array + */ + public function getRecentStatus($slug) { + //Argument 1 must be a string + Eden_Twitter_Error::i()->argument(1, 'string'); + + $query = array('slug' => $slug); + + return $this->_getResponse(self::URL_GET_RECENT_STATUS, $query); + } + + /** + * Access to Twitter's suggested user list. + * + * @param string|null + * @return array + */ + public function getSuggestion($lang = NULL) { + //Argument 1 must be a string or null + Eden_Twitter_Error::i()->argument(1, 'string', 'null'); + + //if it is not empty + if(!is_null($lang)) { + //lets put it in our query + $query = array('lang' => $lang); + } + + return $this->_getResponse(self::URL_SUGGESTION, $query); + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/twitter/timeline.php b/library/eden/twitter/timeline.php new file mode 100644 index 0000000..c581417 --- /dev/null +++ b/library/eden/twitter/timeline.php @@ -0,0 +1,492 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Twitter timelines + * + * @package Eden + * @category twitter + * @author Christian Symon M. Buenavista sbuenavista@openovate.com + * @author Christian Blanquera cblanquera@openovate.com + */ +class Eden_Twitter_Timeline extends Eden_Twitter_Base { + /* Constants + -------------------------------*/ + const URL_TIMELINE = 'https://api.twitter.com/1/statuses/home_timeline.json'; + const URL_MENTION = 'https://api.twitter.com/1/statuses/mentions.json'; + const URL_PUBLIC = 'https://api.twitter.com/1/statuses/public_timeline.json'; + const URL_BY_ME = 'https://api.twitter.com/1/statuses/retweeted_by_me.json'; + const URL_TO_ME = 'https://api.twitter.com/1/statuses/retweeted_to_me.json'; + const URL_OF_ME = 'https://api.twitter.com/1/statuses/retweets_of_me.json'; + const URL_USER = 'https://api.twitter.com/1/statuses/user_timeline.json'; + const URL_TO_USER = 'https://api.twitter.com/1/statuses/retweeted_to_user.json'; + const URL_BY_USER = 'https://api.twitter.com/1/statuses/retweeted_by_user.json'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_count = NULL; + protected $_since = NULL; + protected $_max = NULL; + protected $_page = NULL; + protected $_trim = NULL; + protected $_entities = false; + protected $_rts = false; + protected $_replies = false; + protected $_detail = false; + + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + /* Public Methods + -------------------------------*/ + /** + * Set contributors details + * + * @return array + */ + public function addContributorDetail() { + $this->_detail = true; + return $this; + } + + /** + * Set exclude replies + * + * @return array + */ + public function excludeReplies() { + $this->_replies = true; + return $this; + } + + /** + * Returns the 20 most recent retweets posted + * by the authenticating user. + * + * @param string|int|null user ID or screen name + * @return array + */ + public function getRetweets($id = NULL) { + //Argument 1 must be an integer, string or null + Eden_Twitter_Error::i()->argument(1, 'int', 'string', 'null'); + + $query = array(); + + if($this->_entities) { + $query['include_entities'] = 1; + } + + if($this->_trim) { + $query['trim_user'] = 1; + } + + if($this->_since) { + $query['since_id'] = $this->_since; + } + + if($this->_max) { + $query['max_id'] = $this->_max; + } + + if($this->_page) { + $query['page'] = $this->_page; + } + + if($this->_count) { + $query['count'] = $this->_count; + } + + if(!is_null($id)) { + //if it is integer + if(is_int($id)) { + //lets put it in our query + $query['user_id'] = $id; + //else it is string + } else { + //lets put it in our query + $query['screen_name'] = $id; + } + return $this->_getResponse(self::URL_BY_USER, $query); + } + + return $this->_getResponse(self::URL_BY_ME, $query); + } + + /** + * Returns the 20 most recent statuses posted by the + * authenticating user. It is also possible to request + * another user's timeline by using the screen_name + * or user_id parameter + * + * @param string|int|null user ID or screen name + * @return array + */ + public function getStatuses($id = NULL) { + //Argument 1 must be an integer, string or null + Eden_Twitter_Error::i()->argument(1, 'int', 'string', 'null'); + + $query = array(); + + if(!is_null($id)) { + //if it is integer + if(is_int($id)) { + //lets put it in our query + $query['user_id'] = $id; + //else it is string + } else { + //lets put it in our query + $query['screen_name'] = $id; + } + } + + if($this->_entities) { + $query['include_entities'] = 1; + } + + if($this->_rts) { + $query['include_rts'] = 1; + } + + if($this->_replies) { + $query['exclude_replies'] = 1; + } + + if($this->_trim) { + $query['trim_user'] = 1; + } + + if($this->_detail) { + $query['contributor_details'] = 1; + } + + if($this->_since) { + $query['since_id'] = $this->_since; + } + + if($this->_max) { + $query['max_id'] = $this->_max; + } + + if($this->_page) { + $query['page'] = $this->_page; + } + + if($this->_count) { + $query['count'] = $this->_count; + } + + return $this->_getResponse(self::URL_USER, $query); + } + + /** + * Returns the 20 most recent mentions (status containing @username) + * for the authenticating user + * + * @return array + */ + public function getMentions() { + $query = array(); + + if($this->_entities) { + $query['include_entities'] = 1; + } + + if($this->_rts) { + $query['include_rts'] = 1; + } + + if($this->_trim) { + $query['trim_user'] = 1; + } + + if($this->_detail) { + $query['contributor_details'] = 1; + } + + if($this->_since) { + $query['since_id'] = $this->_since; + } + + if($this->_max) { + $query['max_id'] = $this->_max; + } + + if($this->_page) { + $query['page'] = $this->_page; + } + + if($this->_count) { + $query['count'] = $this->_count; + } + + return $this->_getResponse(self::URL_MENTION, $query); + } + + /** + * Returns the 20 most recent tweets of the authenticated + * user that have been retweeted by others. + * + * @return array + */ + public function getRetweeted() { + $query = array(); + + if($this->_entities) { + $query['include_entities'] = 1; + } + + if($this->_trim) { + $query['trim_user'] = 1; + } + + if($this->_since) { + $query['since_id'] = $this->_since; + } + + if($this->_max) { + $query['max_id'] = $this->_max; + } + + if($this->_page) { + $query['page'] = $this->_page; + } + + if($this->_count) { + $query['count'] = $this->_count; + } + + return $this->_getResponse(self::URL_OF_ME, $query); + } + + /** + * Returns the 20 most recent statuses, including + * retweets if they exist. + * + * @return array + */ + public function getAllTweets() { + $query = array(); + + if($this->_entities) { + $query['include_entities'] = 1; + } + + if($this->_trim) { + $query['trim_user'] = 1; + } + + return $this->_getResponse(self::URL_PUBLIC, $query); + } + + /** + * Returns the 20 most recent statuses, including retweets + * if they exist, posted by the authenticating user and + * the user's they follow. This is the same timeline seen + * by a user when they login to twitter.com. + * + * @return array + */ + public function getTimeline() { + $query = array(); + + if($this->_entities) { + $query['include_entities'] = 1; + } + + if($this->_rts) { + $query['include_rts'] = 1; + } + + if($this->_replies) { + $query['exclude_replies'] = 1; + } + + if($this->_trim) { + $query['trim_user'] = 1; + } + + if($this->_detail) { + $query['contributor_details'] = 1; + } + + if($this->_since) { + $query['since_id'] = $this->_since; + } + + if($this->_max) { + $query['max_id'] = $this->_max; + } + + if($this->_page) { + $query['page'] = $this->_page; + } + + if($this->_count) { + $query['count'] = $this->_count; + } + + return $this->_getResponse(self::URL_TIMELINE, $query); + } + + /** + * Returns the 20 most recent retweets posted by + * users the authenticating user follow + * + * @param string|int|null user ID or screen name + * @return array + */ + public function getFollowingRetweets($id = NULL) { + //Argument 1 must be an integer, string or null + Eden_Twitter_Error::i()->argument(1, 'int', 'string', 'null'); + + $query = array(); + + if($this->_entities) { + $query['include_entities'] = 1; + } + + if($this->_trim) { + $query['trim_user'] = 1; + } + + if($this->_since) { + $query['since_id'] = $this->_since; + } + + if($this->_max) { + $query['max_id'] = $this->_max; + } + + if($this->_page) { + $query['page'] = $this->_page; + } + + if($this->_count) { + $query['count'] = $this->_count; + } + + if(!is_null($id)) { + //if it is integer + if(is_int($id)) { + //lets put it in our query + $query['user_id'] = $id; + //else it is string + } else { + //lets put it in our query + $query['screen_name'] = $id; + } + + return $this->_getResponse(self::URL_TO_USER, $query); + } + + return $this->_getResponse(self::URL_TO_ME, $query); + } + + /** + * Each tweet will include a node called "entities". This node offers a variety + * of metadata about the tweet in a discreet structure, including: user_mentions, + * urls, and hashtags. + * + * @return this + */ + public function includeEntities() { + $this->_entities = true; + return $this; + } + + /** + * The list timeline will contain native retweets (if they exist) in addition to the + * standard stream of tweets. The output format of retweeted tweets is identical to + * the representation you see in home_timeline. + * + * @return this + */ + public function includeRts() { + $this->_rts = true; + return $this; + } + + /** + * Set count + * + * @param integer + * @return array + */ + public function setCount($count) { + //Argument 1 must be an integer + Eden_Twitter_Error::i()->argument(1, 'int'); + + $this->_count = $count; + return $this; + } + + /** + * Set max id + * + * @param integer + * @return array + */ + public function setMax($max) { + //Argument 1 must be an integer + Eden_Twitter_Error::i()->argument(1, 'int'); + + $this->_max = $max; + return $this; + } + + /** + * Set page + * + * @param integer + * @return array + */ + public function setPage($page) { + //Argument 1 must be an integer + Eden_Twitter_Error::i()->argument(1, 'int'); + + $this->_page = $page; + return $this; + } + + /** + * Set since id + * + * @param integer + * @return array + */ + public function setSince($since) { + //Argument 1 must be an integer + Eden_Twitter_Error::i()->argument(1, 'int'); + + $this->_since = $since; + return $this; + } + + /** + * Set trim user + * + * @return array + */ + public function trimUser() { + $this->_trim = true; + return $this; + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/twitter/trends.php b/library/eden/twitter/trends.php new file mode 100644 index 0000000..21d01a2 --- /dev/null +++ b/library/eden/twitter/trends.php @@ -0,0 +1,103 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Twitter trends + * + * @package Eden + * @category twitter + * @author Christian Symon M. Buenavista sbuenavista@openovate.com + */ +class Eden_Twitter_Trends extends Eden_Twitter_Base { + /* Constants + -------------------------------*/ + const URL_GET_DAILY_TRENDS = 'https://api.twitter.com/1/trends/daily.json'; + const URL_GET_WEEKLY_TRENS = 'http://api.twitter.com/version/trends/weekly.json'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + /* Public Methods + -------------------------------*/ + /** + * Returns the top 20 trending topics + * for each hour in a given day. + * + * @param sting|null + * @param string|null + * @return array + */ + public function getDailyTrends($date = NULL, $exclude = NULL) { + //Argument Test + Eden_Twitter_Error::i() + ->argument(1, 'string', 'null') //Argument 1 must be a string or null + ->argument(2, 'string', 'null'); //Argument 2 must be a string or null + + $query = array(); + + //if it is not empty + if(!is_null($date)) { + //lets put it in query + $query['date'] = date('Y-m-d', strtotime($date)); + } + + //if it is not empty + if(!is_null($exclude)) { + //lets put it in query + $query['exclude'] = $exclude; + } + + return $this->_getResponse(self::URL_GET_DAILY_TRENDS, $query); + } + + /** + * Returns the top 30 trending topics + * for each day in a given week. + * + * @param sting|null + * @param string|null + * @return array + */ + public function getWeeklyTrends($date = NULL, $exclude = NULL) { + //Argument Test + Eden_Twitter_Error::i() + ->argument(1, 'string', 'null') //Argument 1 must be a string or null + ->argument(2, 'string', 'null'); //Argument 2 must be a string or null + + $query = array(); + + //if it is not empty + if(!is_null($date)) { + //lets put it in query + $query['date'] = date('Y-m-d', strtotime($date)); + } + + //if it is not empty + if(!is_null($exclude)) { + //lets put it in query + $query['exclude'] = $exclude; + } + + return $this->_getResponse(self::URL_GET_WEEKLY_TRENDS, $query); + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/twitter/tweets.php b/library/eden/twitter/tweets.php new file mode 100644 index 0000000..c95e013 --- /dev/null +++ b/library/eden/twitter/tweets.php @@ -0,0 +1,455 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Twitter tweets + * + * @package Eden + * @category twitter + * @author Christian Symon M. Buenavista sbuenavista@openovate.com + * @author Christian Blanquera cblanquera@openovate.com + */ +class Eden_Twitter_Tweets extends Eden_Twitter_Base { + /* Constants + -------------------------------*/ + const URL_WHO_RETWEETED = 'https://api.twitter.com/1/statuses/%s/retweeted_by.json'; + const URL_GET_WHO_RETWEETED_IDS = 'https://api.twitter.com/1/statuses/%d/retweeted_by/ids.json'; + const URL_GET_RETWEETS = 'https://api.twitter.com/1/statuses/retweets/%s.json'; + const URL_GET_LIST = 'https://api.twitter.com/1/statuses/show.json'; + const URL_REMOVE = 'http://api.twitter.com/1/statuses/destroy/%s.json'; + const URL_RETWEET = 'http://api.twitter.com/1/statuses/retweet/%d.json'; + const URL_UPDATE = 'https://api.twitter.com/1/statuses/update.json'; + const URL_UPDATE_MEDIA = 'https://upload.twitter.com/1/statuses/update_with_media.json'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_latitude = NULL; + protected $_longtitude = NULL; + protected $_count = 0; + protected $_page = 0; + protected $_reply = NULL; + protected $_place = NULL; + protected $_stringify = false; + protected $_entities = false; + protected $_trim = false; + protected $_display = false; + protected $_wrap = false; + protected $_sensitive = false; + + + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + /* Public Methods + -------------------------------*/ + /** + * Set display coordinates + * + * @return array + */ + public function displayCoordinates() { + $this->_display = true; + return $this; + } + + /** + * Set include entities + * + * @return array + */ + public function includeEntities() { + $this->_entities = true; + return $this; + } + + /** + * Set possibly sensitive + * + * @return array + */ + public function isSensitive() { + $this->_sensitive = true; + return $this; + } + + /** + * Returns a single status, specified by the id parameter below. + * The status's author will be returned inline. + * + * @param integer + * @return array + */ + public function getDetail($id) { + //Argument 1 must be an integer + Eden_Twitter_Error::i()->argument(1, 'int'); + + $query = array('id' => $id); + + if($this->_entities) { + $query['include_entities'] = 1; + } + + if($this->_trim) { + $query['trim_user'] = 1; + } + + return $this->_getResponse(self::URL_GET_LIST, $query); + } + + /** + * Returns up to 100 of the first retweets of a given tweet. + * + * @param integer + * @return array + */ + public function getRetweets($id) { + //Argument 1 must be an integer + Eden_Twitter_Error::i()->argument(1, 'int'); + + $query = array('id' => $id); + + if($this->_entities) { + $query['include_entities'] = 1; + } + + if($this->_trim) { + $query['trim_user'] = 1; + } + + if($this->_count) { + $query['count'] = $this->_count; + } + + $url = sprintf(self::URL_GET_RETWEETS, $id); + return $this->_post($url, $query); + } + + /** + * Show user objects of up to 100 members + * who retweeted the status. + * + * @param integer + * @return array + */ + public function getWhoRetweeted($id) { + //Argument 1 must be an integer + Eden_Twitter_Error::i()->argument(1, 'int'); + + $query = array('id' => $id); + + if($this->_page) { + $query['page'] = $this->_page; + } + + if($this->_count) { + $query['count'] = $this->_count; + } + } + + /** + * Show user ids of up to 100 users who + * retweeted the status. + * + * @param integer + * @return array + */ + public function getWhoRetweetedIds($id) { + //Argument 1 must be an integer + Eden_Twitter_Error::i()->argument(1, 'int'); + + $query = array('id' => $id); + + if($this->_page) { + $query['page'] = $this->_page; + } + + if($this->_count) { + $query['count'] = $this->_count; + } + + if($this->_stringify) { + $query['stringify_ids'] = 1; + } + + $url = sprintf(self::URL_GET_WHO_RETWEETED_IDS, $id); + return $this->_post($url, $query); + } + + /** + * Destroys the status specified by the required ID parameter. + * The authenticating user must be the author of the specified . + * status. Returns the destroyed status if successful. + * + * @param integer + * @return array + */ + public function remove($id) { + //Argument 1 must be an integer + Eden_Twitter_Error::i()->argument(1, 'int'); + + $query = array('id' => $id); + + if($this->_entities) { + $query['include_entities'] = 1; + } + + if($this->_trim) { + $query['trim_user'] = 1; + } + + $url = sprintf(self::URL_REMOVE, $id); + return $this->_post($url,$query); + } + + /** + * Set in reply to status id + * + * @param string + * @return array + */ + public function replyTo($reply) { + //Argument 1 must be a string + Eden_Twitter_Error::i()->argument(1, 'string'); + + $this->_reply = $reply; + return $this; + } + + /** + * Retweets a tweet. Returns the original tweet + * with retweet details embedded + * + * @param integer + * @return array + */ + public function retweet($id) { + //Argument 1 must be an integer + Eden_Twitter_Error::i()->argument(1, 'int'); + + //populate fields + $query = array('id' => $id); + + if($this->_entities) { + $query['include_entities'] = 1; + } + + if($this->_trim) { + $query['trim_user'] = 1; + } + + $url = sprintf(self::URL_RETWEET, $id); + return $this->_post($url, $query); + } + + /** + * Set count + * + * @param integer + * @return array + */ + public function setCount($count) { + //Argument 1 must be an integer + Eden_Twitter_Error::i()->argument(1, 'int'); + + $this->_count = $count; + return $this; + } + + /** + * Set latitude + * + * @param float + * @return this + */ + public function setLatitude($latitude) { + //Argument 1 must be a float + Eden_Twitter_Error::i()->argument(1, 'float'); + + $this->_latitude = $latitude; + return $this; + } + + /** + * Set longtitude + * + * @param float + * @return this + */ + public function setLongtitude($longtitude) { + //Argument 1 must be a float + Eden_Twitter_Error::i()->argument(1, 'float'); + + $this->_longtitude = $longtitude; + return $this; + } + + /** + * Set page + * + * @param integer + * @return array + */ + public function setPage($page) { + //Argument 1 must be an integer + Eden_Twitter_Error::i()->argument(1, 'int'); + + $this->_page = $page; + return $this; + } + + /** + * Set place id + * + * @param string|integer + * @return array + */ + public function setPlace($place) { + //Argument 1 must be a string or integer + Eden_Twitter_Error::i()->argument(1, 'string', 'int'); + + $this->_place = $place; + return $this; + } + + /** + * Set stringify ids + * + * @return array + */ + public function stringify() { + $this->_stringify = true; + return $this; + } + + /** + * Set trim user + * + * @return array + */ + public function trimUser() { + $this->_trim = true; + return $this; + } + + /** + * Updates the authenticating user's status, + * also known as tweeting. + * + * @param string + * @return array + */ + public function update($status) { + //Argument 1 must be a string + Eden_Twitter_Error::i()->argument(1, 'string'); + + $query = array('status' => $status); + + if($this->_reply) { + $query['in_reply_to_status_id'] = $this->_reply; + } + + if($this->_latitude) { + $query['lat'] = $this->_latitude; + } + + if($this->_longtitude) { + $query['long'] = $this->_longtitude; + } + + if($this->_place) { + $query['place_id'] = $this->_place; + } + + if($this->_display) { + $query['display_coordinates'] = 1; + } + + if($this->_trim) { + $query['trim_user'] = 1; + } + + if($this->_entities) { + $query['include_entities'] = 1; + } + + if($this->_wrap) { + $query['wrap_links'] = 1; + } + + return $this->_post(self::URL_UPDATE, $query); + } + + /** + * Updates the authenticating user's status, + * also known as tweeting. + * + * @param string + * @param string + * @return array + */ + public function updateMedia($status, $media) { + //Argument Test + Eden_Twitter_Error::i() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'string'); //Argument 2 must be a string + + //populate fields + $query = array( + 'media[]' => $media, + 'status' => $status); + + if($this->_reply) { + $query['in_reply_to_status_id'] = $this->_reply; + } + + if($this->_latitude) { + $query['lat'] = $this->_latitude; + } + + if($this->_longtitude) { + $query['long'] = $this->_longtitude; + } + + if($this->_place) { + $query['place_id'] = $this->_place; + } + + if($this->_sensitive) { + $query['possibly_sensitive'] = 1; + } + + if($this->_display) { + $query['display_coordinates'] = 1; + } + + return $this->_upload(self::URL_UPDATE_MEDIA, $query); + } + + /** + * Set wrap links + * + * @return array + */ + public function wrapLinks() { + $this->_wrap = true; + return $this; + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/twitter/users.php b/library/eden/twitter/users.php new file mode 100644 index 0000000..fd757b2 --- /dev/null +++ b/library/eden/twitter/users.php @@ -0,0 +1,295 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Twitter users + * + * @package Eden + * @category twitter + * @author Christian Symon M. Buenavista sbuenavista@openovate.com + */ +class Eden_Twitter_Users extends Eden_Twitter_Base { + /* Constants + -------------------------------*/ + const URL_LOOK_UP = 'https://api.twitter.com/1/users/lookup.json'; + const URL_PROFILE_IMAGE = 'https://api.twitter.com/1/users/profile_image.json'; + const URL_SEARCH = 'https://api.twitter.com/1/users/search.json'; + const URL_SHOW = 'https://api.twitter.com/1/users/show.json'; + const URL_CONTRIBUTEES = 'https://api.twitter.com/1/users/contributees.json'; + const URL_CONTRIBUTORS = 'https://api.twitter.com/1/users/contributors.json'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_id = NULL; + protected $_name = NULL; + protected $_size = NULL; + protected $_page = NULL; + protected $_perpage = NULL; + protected $_entities = NULL; + protected $_status = NULL; + + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + /* Public Methods + -------------------------------*/ + /** + * Returns an array of users that + * the specified user can contribute to. + * + * @return array + */ + public function getContributees() { + $query = array(); + + if($this->_id) { + $query['user_id'] = $this->_id; + } + + if($this->_name) { + $query['screen_name'] = $this->_name; + } + + if($this->_entities) { + $query['include_entities'] = 1; + } + + if($this->_status) { + $query['skip_status'] = 1; + } + + return $this->_getResponse(self::URL_CONTRIBUTEES, $query); + } + + /** + * Returns an array of users that + * the specified user can contribute to. + * + * @return array + */ + public function getContributors() { + $query = array(); + + if($this->_id) { + $query['user_id'] = $this->_id; + } + + if($this->_name) { + $query['screen_name'] = $this->_name; + } + + if($this->_entities) { + $query['include_entities'] = 1; + } + + if($this->_status) { + $query['skip_status'] = 1; + } + + return $this->_getResponse(self::URL_CONTRIBUTORS, $query); + } + + /** + * Returns extended information of a given user, specified + * by ID or screen name as per the required id parameter. + * + * @param int user ID + * @return array + */ + public function getDetail($id) { + //Argument 1 must be an integer + Eden_Twitter_Error::i()->argument(1,'int'); + + $query = array('user_id' => $id); + + if($this->_entities) { + $query['include_entities'] = 1; + } + + return $this->_getResponse(self::URL_SHOW, $query); + } + + /** + * Access the profile image in various sizes + * for the user with the indicated screen_name. + * If no size is provided the normal image is returned. + * + * @return array + */ + public function getProfileImage() { + //populate fields + $query = array( + 'screen_name' => $this->_name, + 'size' => $this->_size); + + return $this->_getResponse(self::URL_PROFILE_IMAGE, $query); + } + + /** + * Return up to 100 users worth of extended information, + * specified by either ID, screen name, or combination of the two. + * + * @return array + */ + public function lookupFriends() { + $query = array(); + + if($this->_entities) { + $query['include_entities'] = 1; + } + + //if id is integer + if(is_int($this->_id)) { + $this->_id = explode(',', $this->_id); + //at this point id will be an array + $this->_id = array(); + //lets put it in query + $query['user_id'] = $this->_id; + } + + //if name is string + if(is_string($this->_name)) { + $this->_name = explode(',', $this->_name); + //at this point id will be an array + $this->_name = array(); + $query['screen_name'] = $this->_name; + } + + return $this->_getResponse(self::URL_LOOK_UP, $query); + } + + /** + * Set include entities + * + * @return array + */ + public function includeEntities() { + $this->_entities = true; + return $this; + } + + /** + * Set user id + * + * @param integer + * @return array + */ + public function setUserId($id) { + //Argument 1 must be an integer + Eden_Twitter_Error::i()->argument(1, 'int'); + + $this->_id = $id; + return $this; + } + + /** + * Set screen name + * + * @param string + * @return array + */ + public function setScreenName($name) { + //Argument 1 must be an integer + Eden_Twitter_Error::i()->argument(1, 'string'); + + $this->_name = $name; + return $this; + } + + /** + * Set page + * + * @param integer + * @return array + */ + public function setPage($page) { + //Argument 1 must be an integer + Eden_Twitter_Error::i()->argument(1, 'int'); + + $this->_page = $page; + return $this; + } + + /** + * Set per page + * + * @param integer + * @return array + */ + public function setPerpage($perpage) { + //Argument 1 must be an integer + Eden_Twitter_Error::i()->argument(1, 'int'); + + $this->_perpage = $perpage; + return $this; + } + + /** + * Set size + * + * @param string + * @return array + */ + public function setSize($size) { + //Argument 1 must be an integer + Eden_Twitter_Error::i()->argument(1, 'string'); + + $this->_size = $size; + return $this; + } + + /** + * Set skip status + * + * @return array + */ + public function skipStatus() { + $this->_status = true; + return $this; + } + + /** + * Runs a search for users similar to find people + * + * @param string + * @return array + */ + public function search($search) { + //Argument 1 must be a string + Eden_Twitter_Error::i()->argument(1, 'string'); + + $query = array('q' => $search); + + if($this->_page) { + $query['page'] = $this->_page; + } + + if($this->_perpage) { + $query['per_page'] = $this->_perpage; + } + + if($this->_entities) { + $query['include_entities'] = 1; + } + + return $this->_getResponse(self::URL_SEARCH, $query); + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} diff --git a/library/eden/type.php b/library/eden/type.php new file mode 100644 index 0000000..804d3e0 --- /dev/null +++ b/library/eden/type.php @@ -0,0 +1,83 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +require_once dirname(__FILE__).'/class.php'; +require_once dirname(__FILE__).'/type/error.php'; +require_once dirname(__FILE__).'/type/abstract.php'; +require_once dirname(__FILE__).'/type/array.php'; +require_once dirname(__FILE__).'/type/string.php'; + +/** + * Controller for Data Types + * + * @package Eden + * @category type + * @author Christian Blanquera cblanquera@openovate.com + */ +class Eden_Type extends Eden_Class { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function i($type = NULL) { + if(func_num_args() > 1) { + $type = func_get_args(); + } + + if(is_array($type)) { + return Eden_Type_Array::i($type); + } + + if(is_string($type)) { + return Eden_Type_String::i($type); + } + + return self::_getSingleton(__CLASS__); + } + + /* Magic + -------------------------------*/ + /* Public Methods + -------------------------------*/ + /** + * Returns the array class + * + * @param array|mixed[,mixed..] + * @return Eden_Type_Array + */ + public function getArray($array) { + $args = func_get_args(); + if(count($args) > 1 || !is_array($array)) { + $array = $args; + } + + return Eden_Type_Array::i($array); + } + + /** + * Returns the string class + * + * @param string + * @return Eden_Type_String + */ + public function getString($string) { + return Eden_Type_String::i($string); + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/type/abstract.php b/library/eden/type/abstract.php new file mode 100755 index 0000000..febc40c --- /dev/null +++ b/library/eden/type/abstract.php @@ -0,0 +1,145 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Base class for data type classes + * + * @package Eden + * @category core + * @author Christian Blanquera cblanquera@openovate.com + */ +abstract class Eden_Type_Abstract extends Eden_Class { + /* Constants + -------------------------------*/ + const PRE = 'pre'; + const POST = 'post'; + const REFERENCE = 'reference'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_data = NULL; + protected $_original = NULL; + + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + /* Magic + -------------------------------*/ + public function __call($name, $args) { + $type = $this->_getMethodType($name); + + //if no type + if(!$type) { + //we don't process anything else + try { + //call the parent + return parent::__call($name, $args); + } catch(Eden_Error $e) { + Eden_Type_Error::i($e->getMessage())->trigger(); + } + } + + //case different types + switch($type) { + case self::PRE: + //if pre, we add it first into the args + array_unshift($args, $this->_data); + break; + case self::POST: + //if post, we add it last into the args + array_push($args, $this->_data); + break; + case self::REFERENCE: + //if reference, we add it first + //into the args and call it + call_user_func_array($name, array_merge(array(&$this->_data), $args)); + return $this; + } + + //call the method + $result = call_user_func_array($name, $args); + + //if the result is a string + if(is_string($result)) { + //if this class is a string type + if($this instanceof Eden_Type_String) { + //set value + $this->_data = $result; + return $this; + } + + //return string class + return Eden_Type_String::i($result); + } + + //if the result is an array + if(is_array($result)) { + //if this class is a array type + if($this instanceof Eden_Type_Array) { + //set value + $this->_data = $result; + return $this; + } + + //return array class + return Eden_Type_Array::i($result); + } + + return $result; + } + + public function __construct($data) { + $this->_original = $this->_data = $data; + } + + /* Public Methods + -------------------------------*/ + /** + * Returns the value + * + * @param bool whether to get the modified or original version + * @return string + */ + public function get($modified = true) { + //argument 1 must be a bool + Eden_Type_Error::i()->argument(1, 'bool'); + + return $modified ? $this->_data : $this->_original; + } + + /** + * Reverts changes back to the original + * + * @return this + */ + public function revert() { + $this->_data = $this->_original; + return $this; + } + + /** + * Sets data + * + * @return this + */ + public function set($value) { + $this->_data = $value; + return $this; + } + + /* Protected Methods + -------------------------------*/ + abstract protected function _getMethodType(&$name); + + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/type/array.php b/library/eden/type/array.php new file mode 100644 index 0000000..769d11f --- /dev/null +++ b/library/eden/type/array.php @@ -0,0 +1,410 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Array object + * + * @package Eden + * @category core + * @author Christian Blanquera cblanquera@openovate.com + */ +class Eden_Type_Array extends Eden_Type_Abstract implements ArrayAccess, Iterator, Serializable, Countable { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_data = array(); + protected $_original = array(); + + protected static $_methods = array( + 'array_change_key_case' => self::PRE, 'array_chunk' => self::PRE, + 'array_combine' => self::PRE, 'array_count_datas' => self::PRE, + 'array_diff_assoc' => self::PRE, 'array_diff_key' => self::PRE, + 'array_diff_uassoc' => self::PRE, 'array_diff_ukey' => self::PRE, + 'array_diff' => self::PRE, 'array_fill_keys' => self::PRE, + 'array_filter' => self::PRE, 'array_flip' => self::PRE, + 'array_intersect_assoc' => self::PRE, 'array_intersect_key' => self::PRE, + 'array_intersect_uassoc' => self::PRE, 'array_intersect_ukey' => self::PRE, + 'array_intersect' => self::PRE, 'array_keys' => self::PRE, + 'array_merge_recursive' => self::PRE, 'array_merge' => self::PRE, + 'array_pad' => self::PRE, + 'array_reverse' => self::PRE, 'array_shift' => self::PRE, + 'array_slice' => self::PRE, 'array_splice' => self::PRE, + 'array_sum' => self::PRE, 'array_udiff_assoc' => self::PRE, + 'array_udiff_uassoc' => self::PRE, 'array_udiff' => self::PRE, + 'array_uintersect_assoc' => self::PRE, 'array_uintersect_uassoc' => self::PRE, + 'array_uintersect' => self::PRE, 'array_unique' => self::PRE, + 'array_datas' => self::PRE, 'count' => self::PRE, + 'current' => self::PRE, 'each' => self::PRE, + 'end' => self::PRE, 'extract' => self::PRE, + 'key' => self::PRE, 'next' => self::PRE, + 'prev' => self::PRE, 'sizeof' => self::PRE, + + 'array_fill' => self::POST, 'array_map' => self::POST, + 'array_search' => self::POST, 'compact' => self::POST, + 'implode' => self::POST, 'in_array' => self::POST, + + 'array_unshift' => self::REFERENCE, 'array_walk_recursive' => self::REFERENCE, + 'array_walk' => self::REFERENCE, 'arsort' => self::REFERENCE, + 'asort' => self::REFERENCE, 'krsort' => self::REFERENCE, + 'ksort' => self::REFERENCE, 'natcasesort' => self::REFERENCE, + 'natsort' => self::REFERENCE, 'reset' => self::REFERENCE, + 'rsort' => self::REFERENCE, 'shuffle' => self::REFERENCE, + 'sort' => self::REFERENCE, 'uasort' => self::REFERENCE, + 'uksort' => self::REFERENCE, 'usort' => self::REFERENCE, + 'array_push' => self::REFERENCE); + + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + public function __call($name, $args) { + //if the method starts with get + if(strpos($name, 'get') === 0) { + //getUserName('-') + $separator = '_'; + if(isset($args[0]) && is_scalar($args[0])) { + $separator = (string) $args[0]; + } + + $key = preg_replace("/([A-Z0-9])/", $separator."$1", $name); + //get rid of get + $key = strtolower(substr($key, 3+strlen($separator))); + + if(isset($this->_data[$key])) { + return $this->_data[$key]; + } + + return NULL; + + } else if (strpos($name, 'set') === 0) { + //setUserName('Chris', '-') + $separator = '_'; + if(isset($args[1]) && is_scalar($args[1])) { + $separator = (string) $args[1]; + } + + $key = preg_replace("/([A-Z0-9])/", $separator."$1", $name); + + //get rid of set + $key = strtolower(substr($key, 3+strlen($separator))); + + $this->__set($key, isset($args[0]) ? $args[0] : NULL); + + return $this; + } + + try { + return parent::__call($name, $args); + } catch(Eden_Error $e) { + Eden_Type_Error::i($e->getMessage())->trigger(); + } + } + + public function __construct($data = array()) { + //if there is more arguments or data is not an array + if(func_num_args() > 1 || !is_array($data)) { + //just get the args + $data = func_get_args(); + } + + parent::__construct($data); + } + + public function __set($name, $value) { + $this->_data[$name] = $value; + } + + public function __toString() { + return json_encode($this->get()); + } + + /* Public Methods + -------------------------------*/ + /** + * Copies the value of source key into destination key + * + * @param string + * @param string + */ + public function copy($source, $destination) { + $this->_data[$destination] = $this->_data[$source]; + return $this; + } + + /** + * returns size using the Countable interface + * + * @return string + */ + public function count() { + return count($this->_data); + } + + /** + * Removes a row in an array and adjusts all the indexes + * + * @param *string the key to leave out + * @return this + */ + public function cut($key) { + //argument 1 must be scalar + Eden_Type_Error::i()->argument(1, 'scalar'); + + //if nothing to cut + if(!isset($this->_data[$key])) { + //do nothing + return $this; + } + + //unset the value + unset($this->_data[$key]); + //reindex the list + $this->_data = array_values($this->_data); + return $this; + } + + /** + * Returns the current item + * For Iterator interface + * + * @return void + */ + public function current() { + return current($this->_data); + } + + /** + * Loops through returned result sets + * + * @param *callable + * @return this + */ + public function each($callback) { + Eden_Error::i()->argument(1, 'callable'); + + foreach($this->_data as $key => $value) { + call_user_func($callback, $key, $value); + } + + return $this; + } + + /** + * Returns if the data is empty + * + * @return bool + */ + public function isEmpty() { + return empty($this->_data); + } + + /** + * Returns th current position + * For Iterator interface + * + * @return void + */ + public function key() { + return key($this->_data); + } + + /** + * Increases the position + * For Iterator interface + * + * @return void + */ + public function next() { + next($this->_data); + } + + /** + * isset using the ArrayAccess interface + * + * @param number + * @return bool + */ + public function offsetExists($offset) { + return isset($this->_data[$offset]); + } + + /** + * returns data using the ArrayAccess interface + * + * @param number + * @return bool + */ + public function offsetGet($offset) { + return isset($this->_data[$offset]) ? $this->_data[$offset] : NULL; + } + + /** + * Sets data using the ArrayAccess interface + * + * @param number + * @param mixed + * @return void + */ + public function offsetSet($offset, $value) { + if (is_null($offset)) { + $this->_data[] = $value; + } else { + $this->_data[$offset] = $value; + } + } + + /** + * unsets using the ArrayAccess interface + * + * @param number + * @return bool + */ + public function offsetUnset($offset) { + unset($this->_data[$offset]); + } + + /** + * Inserts a row in an array after the given index and adjusts all the indexes + * + * @param *scalar the key we are looking for to past after + * @param *mixed the value to paste + * @param scalar the key to paste along with the value + * @return this + */ + public function paste($after, $value, $key = NULL) { + //Argument test + Eden_Type_Error::i() + ->argument(1, 'scalar') //Argument 1 must be a scalar + ->argument(3, 'scalar', 'null'); //Argument 3 must be a scalar or null + + $list = array(); + //for each row + foreach($this->_data as $i => $val) { + //add this row back to the list + $list[$i] = $val; + + //if this is not the key we are + //suppose to paste after + if($after != $i) { + //do nothing more + continue; + } + + //if there was a key involved + if(!is_null($key)) { + //lets add the new value + $list[$key] = $value; + continue; + } + + //lets add the new value + $list[] = $arrayValue; + } + + //if there was no key involved + if(is_null($key)) { + //reindex the array + $list = array_values($list); + } + + //give it back + $this->_data = $list; + + return $this; + } + + /** + * Rewinds the position + * For Iterator interface + * + * @return void + */ + public function rewind() { + reset($this->_data); + } + + /** + * returns serialized data using the Serializable interface + * + * @return string + */ + public function serialize() { + return json_encode($this->_data); + } + + /** + * Sets data + * + * @return this + */ + public function set($value) { + Eden_Type_Error::i()->argument(1, 'array'); + $this->_data = $value; + return $this; + } + + /** + * sets data using the Serializable interface + * + * @param string + * @return void + */ + public function unserialize($data) { + $this->_data = json_decode($data, true); + return $this; + } + + /** + * Validates whether if the index is set + * For Iterator interface + * + * @return void + */ + public function valid() { + return isset($this->_data[$this->key()]); + } + + /* Protected Methods + -------------------------------*/ + protected function _getMethodType(&$name) { + + if(isset(self::$_methods[$name])) { + return self::$_methods[$name]; + } + + if(isset(self::$_methods['array_'.$name])) { + $name = 'array_'.$name; + return self::$_methods[$name]; + } + + $uncamel = strtolower(preg_replace("/([A-Z])/", "_$1", $name)); + + if(isset(self::$_methods[$uncamel])) { + $name = $uncamel; + return self::$_methods[$name]; + } + + if(isset(self::$_methods['array_'.$uncamel])) { + $name = 'array_'.$uncamel; + return self::$_methods[$name]; + } + + return false; + } + + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/type/error.php b/library/eden/type/error.php new file mode 100755 index 0000000..e2fcbc1 --- /dev/null +++ b/library/eden/type/error.php @@ -0,0 +1,39 @@ + +/* + * This file is part of the Eden package. + * (c) 2010-2012 Christian Blanquera + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Type Errors + * + * @package Eden + * @category core + * @author Christian Blanquera cblanquera@openovate.com + */ +class Eden_Type_Error extends Eden_Error { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i($message = NULL, $code = 0) { + $class = __CLASS__; + return new $class($message, $code); + } + + /* Public Methods + -------------------------------*/ + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/type/string.php b/library/eden/type/string.php new file mode 100644 index 0000000..79ca1b5 --- /dev/null +++ b/library/eden/type/string.php @@ -0,0 +1,185 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * String Object + * + * @package Eden + * @category core + * @author Christian Blanquera cblanquera@openovate.com + */ +class Eden_Type_String extends Eden_Type_Abstract { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected static $_methods = array( + 'addslashes' => self::PRE, + 'bin2hex' => self::PRE, 'chunk_split' => self::PRE, + 'convert_uudecode' => self::PRE, 'convert_uuencode' => self::PRE, + 'crypt' => self::PRE, 'html_entity_decode' => self::PRE, + 'htmlentities' => self::PRE, 'htmlspecialchars_decode' => self::PRE, + 'htmlspecialchars' => self::PRE, 'lcfirst' => self::PRE, + 'ltrim' => self::PRE, 'md5' => self::PRE, + 'nl2br' => self::PRE, 'quoted_printable_decode' => self::PRE, + 'quoted_printable_encode' => self::PRE, 'quotemeta' => self::PRE, + 'rtrim' => self::PRE, 'sha1' => self::PRE, + 'sprintf' => self::PRE, 'str_pad' => self::PRE, + 'str_repeat' => self::PRE, 'str_rot13' => self::PRE, + 'str_shuffle' => self::PRE, 'strip_tags' => self::PRE, + 'stripcslashes' => self::PRE, 'stripslashes' => self::PRE, + 'strpbrk' => self::PRE, 'stristr' => self::PRE, + 'strrev' => self::PRE, 'strstr' => self::PRE, + 'strtok' => self::PRE, 'strtolower' => self::PRE, + 'strtoupper' => self::PRE, 'strtr' => self::PRE, + 'substr_replace' => self::PRE, 'substr' => self::PRE, + 'trim' => self::PRE, 'ucfirst' => self::PRE, + 'ucwords' => self::PRE, 'vsprintf' => self::PRE, + 'wordwrap' => self::PRE, 'count_chars' => self::PRE, + 'hex2bin' => self::PRE, 'strlen' => self::PRE, + 'strpos' => self::PRE, 'substr_compare' => self::PRE, + 'substr_count' => self::PRE, + + 'str_ireplace' => self::POST, 'str_replace' => self::POST, + 'preg_replace' => self::POST, 'explode' => self::POST); + + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + public function __construct($data) { + //argument 1 must be scalar + Eden_Type_Error::i()->argument(1, 'scalar'); + $data = (string) $data; + + parent::__construct($data); + } + + public function __toString() { + return $this->_data; + } + + /* Public Methods + -------------------------------*/ + /** + * Camelizes a string + * + * @param string prefix + * @return this + */ + public function camelize($prefix = '-') { + //argument 1 must be a string + Eden_Type_Error::i()->argument(1, 'string'); + + $this->_data = str_replace($prefix, ' ', $this->_data); + $this->_data = str_replace(' ', '', ucwords($this->_data)); + + $this->_data = strtolower(substr($name, 0, 1)).substr($name, 1); + + return $this; + } + + /** + * Transforms a string with caps and + * space to a lower case dash string + * + * @return this + */ + public function dasherize() { + $this->_data = preg_replace("/[^a-zA-Z0-9_-\s]/i", '', $this->_data); + $this->_data = str_replace(' ', '-', trim($this->_data)); + $this->_data = preg_replace("/-+/i", '-', $this->_data); + $this->_data = strtolower($this->_data); + + return $this; + } + + /** + * Titlizes a string + * + * @param string prefix + * @return this + */ + public function titlize($prefix = '-') { + //argument 1 must be a string + Eden_Type_Error::i()->argument(1, 'string'); + + $this->_data = ucwords(str_replace($prefix, ' ', $this->_data)); + + return $this; + } + + /** + * Uncamelizes a string + * + * @param string prefix + * @return this + */ + public function uncamelize($prefix = '-') { + //argument 1 must be a string + Eden_Type_Error::i()->argument(1, 'string'); + + $this->_data = strtolower(preg_replace("/([A-Z])/", $prefix."$1", $this->_data)); + + return $this; + } + + /** + * Summarizes a text + * + * @param int number of words + * @return this + */ + public function summarize($words) { + //argument 1 must be a string + Eden_Type_Error::i()->argument(1, 'int'); + + $this->_data = explode(' ', strip_tags($this->_data), $words); + array_pop($this->_data); + $this->_data = implode(' ', $this->_data); + + return $this; + } + + /* Protected Methods + -------------------------------*/ + protected function _getMethodType(&$name) { + if(isset(self::$_methods[$name])) { + return self::$_methods[$name]; + } + + if(isset(self::$_methods['str_'.$name])) { + $name = 'str_'.$name; + return self::$_methods[$name]; + } + + $uncamel = strtolower(preg_replace("/([A-Z])/", "_$1", $name)); + + if(isset(self::$_methods[$uncamel])) { + $name = $uncamel; + return self::$_methods[$name]; + } + + if(isset(self::$_methods['str_'.$uncamel])) { + $name = 'str_'.$uncamel; + return self::$_methods[$name]; + } + + return false; + } + + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/unit.php b/library/eden/unit.php new file mode 100755 index 0000000..5312932 --- /dev/null +++ b/library/eden/unit.php @@ -0,0 +1,389 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Lightweight unit testing class. + * + * @package Eden + * @category core + * @author Christian Blanquera cblanquera@openovate.com + */ +class Eden_Unit { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_last = array(); + protected $_start = 0; + protected $_end = 0; + protected $_report = array(); + protected $_package = 'main'; + + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + $class = __CLASS__; + return new $class(); + } + + public function __construct() { + $this->_start = time(); + } + + public function __destruct() { + $this->_end = time(); + } + + public function __call($name, $args) { + if(method_exists($this, '_'.$name)) { + $method = '_'.$name; + $message = array_pop($args); + $test = array( + 'name' => $name, + 'start' => isset($this->_last['end']) ? $this->_last['end'] : $this->_start, + 'message' => $message); + + try { + $test['pass'] = call_user_func_array(array(&$this, $method), $args); + } catch(Exception $e) { + $test['pass'] = false; + $test['error'] = array(get_class($e), $e->getMessage()); + } + + $test['end'] = time(); + $test['trace'] = debug_backtrace(); + + $this->_report[$this->_package][] = $this->_last = $test; + + return $this; + } + } + + /* Public Methods + -------------------------------*/ + public function getPassFail($package = NULL) { + //Argument 1 must be a string or null + Eden_Unit_Error::i()->argument(1, 'string', 'null'); + $passFail = array(0, 0); + if(isset($this->_report[$package])) { + foreach($this->_report[$package] as $test) { + if($test['pass']) { + $passFail[0]++; + continue; + } + + $passFail[1]++; + } + + return $passFail; + } + + foreach($this->_report as $package => $tests) { + $packagePassFail = $this->getPassFail($package); + $passFail[0] += $packagePassFail[0]; + $passFail[1] += $packagePassFail[1]; + } + + return $passFail; + } + + public function getReport() { + return $this->_report; + } + + public function getTotalTests($package = NULL) { + //Argument 1 must be a string or null + Eden_Unit_Error::i()->argument(1, 'string', 'null'); + + if(isset($this->_report[$package])) { + return count($this->_report[$package]); + } + + $total = 0; + foreach($this->_report as $package => $tests) { + $total += $tests; + } + + return $tests; + } + + public function setPackage($name) { + //Argument 1 must be a string + Eden_Unit_Error::i()->argument(1, 'string'); + + $this->_package = $name; + return $this; + } + + /* Protected Methods + -------------------------------*/ + protected function _assertArrayHasKey($needle, $haystack) { + try { + Eden_Unit_Error::i() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'array'); //Argument 2 must be an array + } catch(Eden_Unit_Error $e) { + return false; + } + + return array_key_exists($needle, $haystack); + } + + protected function _assertClassHasAttribute($needle, $haystack) { + try { //try to validate arguments + Eden_Unit_Error::i() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'object', 'string'); //Argument 2 must be an object or string + } catch(Eden_Unit_Error $e) { + return false; + } + + return property_exists($needle, $haystack); + } + + protected function _assertContains($needle, $haystack) { + try { //try to validate arguments + Eden_Unit_Error::i() + ->argument(1, 'string') + ->argument(2, 'array', 'string'); + } catch(Eden_Unit_Error $e) { + return false; + } + + if(is_string($haystack)) { + return strstr($haystack, $needle) !== false; + } + + return in_array($needle, $haystack); + } + + protected function _assertContainsOnly($type, $haystack) { + try { //try to validate arguments + Eden_Unit_Error::i() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'object', 'array'); //Argument 2 must be an object or array + } catch(Eden_Unit_Error $e) { + return false; + } + + $method = 'is_'.$type; + + if(function_exists($method)) { + foreach($haystack as $needle) { + if(!$method($needle)) { + return false; + } + } + + return true; + } + + if(class_exists($type)) { + foreach($haystack as $needle) { + if(get_class($needle) != $type) { + return false; + } + } + + return true; + } + + return false; + } + + protected function _assertCount($number, $haystack) { + try { //try to validate arguments + Eden_Unit_Error::i() + ->argument(1, 'int') //Argument 1 must be a integer + ->argument(2, 'array', 'string'); //Argument 2 must be an array or string + } catch(Eden_Unit_Error $e) { + return false; + } + + if(is_string($haystack)) { + return strlen($haystack) == $number; + } + + return count($haystack) == $number; + } + + protected function _assertEmpty($actual) { + return empty($actual); + } + + protected function _assertEquals($expected, $actual) { + return $expected === $actual; + } + + protected function _assertFalse($condition) { + return $condition === false; + } + + protected function _assertGreaterThan($number, $actual) { + try { //try to validate arguments + Eden_Unit_Error::i() + ->argument(1, 'numeric') //Argument 1 must be a number + ->argument(2, 'numeric'); //Argument 2 must be a number + } catch(Eden_Unit_Error $e) { + return false; + } + + return $actual > $number; + } + + protected function _assertGreaterThanOrEqual($number, $actual) { + try { //try to validate arguments + Eden_Unit_Error::i() + ->argument(1, 'numeric') //Argument 1 must be a number + ->argument(2, 'numeric'); //Argument 2 must be a number + } catch(Eden_Unit_Error $e) { + return false; + } + + return $actual >= $number; + } + + protected function _assertInstanceOf($expected, $actual) { + try { //try to validate arguments + Eden_Unit_Error::i() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'object'); //Argument 2 must be an object + } catch(Eden_Unit_Error $e) { + return false; + } + + return $actual instanceof $expected; + } + + protected function _assertInternalType($type, $actual) { + try { //try to validate arguments + Eden_Unit_Error::i()->argument(1, 'string'); //Argument 1 must be a string + } catch(Eden_Unit_Error $e) { + return false; + } + + $method = 'is_'.$type; + + if(function_exists($method)) { + return !$method($actual); + } + + if(class_exists($type)) { + return get_class($actual) != $type; + } + + return false; + } + + protected function _assertLessThan($number, $actual) { + try { //try to validate arguments + Eden_Unit_Error::i() + ->argument(1, 'numeric') //Argument 1 must be a number + ->argument(2, 'numeric'); //Argument 2 must be a number + } catch(Eden_Unit_Error $e) { + return false; + } + + return $actual < $number; + } + + protected function _assertLessThanOrEqual($number, $actual) { + try { //try to validate arguments + Eden_Unit_Error::i() + ->argument(1, 'numeric') //Argument 1 must be a number + ->argument(2, 'numeric'); //Argument 2 must be a number + } catch(Eden_Unit_Error $e) { + return false; + } + + return $actual <= $number; + } + + protected function _assertNull($mixed) { + return is_null($mixed); + } + + protected function _assertRegExp($pattern, $string) { + try { //try to validate arguments + Eden_Unit_Error::i() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'string'); //Argument 2 must be a string + } catch(Eden_Unit_Error $e) { + return false; + } + + return preg_match($pattern, $string); + } + + protected function _assertSame($expected, $actual) { + return $expected == $actual; + } + + protected function _assertStringEndsWith($suffix, $string) { + try { //try to validate arguments + Eden_Unit_Error::i() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'string'); //Argument 2 must be a string + } catch(Eden_Unit_Error $e) { + return false; + } + + return substr_compare($string, $suffix, -strlen($suffix), strlen($suffix)) === 0; + } + + protected function _assertStringStartsWith($prefix, $string) { + try { //try to validate arguments + Eden_Unit_Error::i() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'string'); //Argument 2 must be a string + } catch(Eden_Unit_Error $e) { + return false; + } + + return strpos($string, $prefix) === 0; + } + + protected function _assertTrue($condition) { + return $condition === true; + } + + /* Private Methods + -------------------------------*/ +} + +/** + * Unit Errors + */ +class Eden_Unit_Error extends Eden_Error { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i($message = NULL, $code = 0) { + $class = __CLASS__; + return new $class($message, $code); + } + + /* Public Methods + -------------------------------*/ + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/validation.php b/library/eden/validation.php new file mode 100644 index 0000000..2512462 --- /dev/null +++ b/library/eden/validation.php @@ -0,0 +1,180 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +require_once dirname(__FILE__).'/class.php'; + +/** + * Validation + * + * @package Eden + * @category core + * @author Christian Blanquera cblanquera@openovate.com + */ +class Eden_Validation extends Eden_Class { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_value = NULL; + + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + public function __construct($value) { + $this->_value = $value; + } + + /* Public Methods + -------------------------------*/ + public function isType($type) { + switch($type) { + case 'number': + return is_numeric($this->_value); + case 'integer': + case 'int': + return is_numeric($this->_value) && strpos((string) $this->_value, '.') === false; + case 'float': + return is_numeric($this->_value) && strpos((string) $this->_value, '.') !== false; + case 'file': + return is_string($this->_value) && file_exists($this->_value); + case 'folder': + return is_string($this->_value) && is_dir($this->_value); + case 'email': + return is_string($this->_value) && $this->_isEmail($this->_value); + case 'url': + return is_string($this->_value) && $this->_isUrl($this->_value); + case 'html': + return is_string($this->_value) && $this->_isHtml($this->_value); + case 'creditcard': + case 'cc': + return (is_string($this->_value) || is_int($this->_value)) && $this->_isCreditCard($this->_value); + case 'hex': + return is_string($this->_value) && $this->_isHex($this->_value); + case 'slug': + case 'shortname': + case 'short': + return !preg_match("/[^a-z0-9_]/i", $this->_value); + default: break; + } + + $method = 'is_'.$type; + if(function_exists($method)) { + return $method($data); + } + + if(class_exists($type)) { + return $data instanceof $type; + } + + return true; + } + + /* Public Number Methods + -------------------------------*/ + public function greaterThan($number) { + return $this->_value > (float)$number; + } + + public function greaterThanEqualTo($number) { + return $this->_value >= (float)$number; + } + + public function lessThan($number) { + return $this->_value < (float)$number; + } + + public function lessThanEqualTo($number) { + return $this->_value <= (float)$number; + } + + /* Public String Methods + -------------------------------*/ + public function lengthGreaterThan($number) { + return strlen((string)$this->_value) > (float)$number; + } + + public function lengthGreaterThanEqualTo($number) { + return strlen((string)$this->_value) >= (float)$number; + } + + public function lengthLessThan($number) { + return strlen((string)$this->_value) < (float)$number; + } + + public function lengthLessThanEqualTo($number) { + return strlen((string)$this->_value) <= (float)$number; + } + + public function notEmpty() { + return !empty($this->_value); + } + + public function startsWithLetter() { + return !preg_match("/^[a-zA-Z]/i", $this->_value); + } + + public function alphaNumeric() { + return preg_match('/^[a-zA-Z0-9]+$/', (string) $this->_value); + } + + public function alphaNumericUnderScore() { + return preg_match('/^[a-zA-Z0-9_]+$/', (string) $this->_value); + } + + public function alphaNumericHyphen() { + return preg_match('/^[a-zA-Z0-9-]+$/', (string) $this->_value); + } + + public function alphaNumericLine() { + return preg_match('/^[a-zA-Z0-9-_]+$/', (string) $this->_value); + } + + /* Protected Methods + -------------------------------*/ + protected function _isCreditCard($value) { + return preg_match('/^(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]'. + '{14}|6(?:011|5[0-9][0-9])[0-9]{12}|3[47][0-9]{13}|3(?:0[0-'. + '5]|[68][0-9])[0-9]{11}|(?:2131|1800|35\d{3})\d{11})$/', $value); + } + + protected function _isEmail($value) { + return preg_match('/^(?:(?:(?:[^@,"\[\]\x5c\x00-\x20\x7f-\xff\.]|\x5c(?=[@,"\[\]'. + '\x5c\x00-\x20\x7f-\xff]))(?:[^@,"\[\]\x5c\x00-\x20\x7f-\xff\.]|(?<=\x5c)[@,"\[\]'. + '\x5c\x00-\x20\x7f-\xff]|\x5c(?=[@,"\[\]\x5c\x00-\x20\x7f-\xff])|\.(?=[^\.])){1,62'. + '}(?:[^@,"\[\]\x5c\x00-\x20\x7f-\xff\.]|(?<=\x5c)[@,"\[\]\x5c\x00-\x20\x7f-\xff])|'. + '[^@,"\[\]\x5c\x00-\x20\x7f-\xff\.]{1,2})|"(?:[^"]|(?<=\x5c)"){1,62}")@(?:(?!.{64})'. + '(?:[a-zA-Z0-9][a-zA-Z0-9-]{1,61}[a-zA-Z0-9]\.?|[a-zA-Z0-9]\.?)+\.(?:xn--[a-zA-Z0-9]'. + '+|[a-zA-Z]{2,6})|\[(?:[0-1]?\d?\d|2[0-4]\d|25[0-5])(?:\.(?:[0-1]?\d?\d|2[0-4]\d|25'. + '[0-5])){3}\])$/', $value); + } + + protected function _isHtml($value) { + return preg_match("/<\/?\w+((\s+(\w|\w[\w-]*\w)(\s*=\s*". + "(?:\".*?\"|'.*?'|[^'\">\s]+))?)+\s*|\s*)\/?>/i", $value); + } + + protected function _isUrl($value) { + return preg_match('/^(http|https|ftp):\/\/([A-Z0-9][A-Z0'. + '-9_-]*(?:.[A-Z0-9][A-Z0-9_-]*)+):?(d+)?\/?/i', $value); + } + + protected function _isHex($value) { + return preg_match("/^[0-9a-fA-F]{6}$/", $value); + } + + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/webcharge.php b/library/eden/webcharge.php new file mode 100644 index 0000000..38025df --- /dev/null +++ b/library/eden/webcharge.php @@ -0,0 +1,255 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +require_once dirname(__FILE__).'/curl.php'; + +/** + * Intuit Innovative Gateway Solution WebCharge application + * model for payment processing. + * + * @package Eden + * @category webcharge + * @author Christian Blanquera cblanquera@openovate.com + */ +class Eden_Webcharge_Model extends Eden_Class +{ + /* Constants + -------------------------------*/ + const PAYMENT_URL = 'https://transactions.innovativegateway.com/servlet/com.gateway.aai.Aai'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_user = NULL; + protected $_agent = 'Mozilla/4.0'; + protected $_password = NULL; + protected $_proxy = NULL; + protected $_timeout = 120; + protected $_error = NULL; + + protected $_template = array( + //merchant authentication + 'username' => NULL, + 'pw' => NULL, + //payment mode + 'test_override_errors' => 'true', + //transaction information + 'response_mode' => 'simple', + 'response_fmt' => 'delimited', + 'upg_auth' => 'zxcvlkjh', + 'fulltotal' => NULL, // Total amount WITHOUT dollar sign. + 'authamount' => '', // Only valid for POSTAUTH and is equal to the original preauth amount. + 'trantype' => 'sale', // Options: preauth, postauth, sale, credit, void + 'reference' => '', // Blank for new sales; required for VOID, POSTAUTH, and CREDITS; Will be original Approval value. + 'trans_id' => '', // Blank for new sales; required for VOID, POSTAUTH, and CREDITS; Will be original ANATRANSID value. + //credit card information + 'cardtype' => NULL, // Options visa, mc, amex, diners, discover, jcb + 'ccnumber' => NULL, // CC# may include spaces or dashes. + 'month' => NULL, // Must be TWO DIGIT month. + 'year' => NULL, // Must be TWO or FOUR DIGIT year. + 'ccname' => NULL, + //customer information + 'baddress' => NULL, + 'baddress1' => NULL, + 'bcity' => NULL, + 'bstate' => NULL, + 'bcountry' => 'US', // TWO DIGIT COUNTRY (United States = "US") + 'zip' => NULL, + 'phone' => NULL, + 'email' => NULL, + //things that do not usually change + 'target_app' => 'WebEden_Chargev5.06', + 'delimited_fmt_field_delimiter' => '=', + 'delimited_fmt_include_fields' => 'true', + 'delimited_fmt_value_delimiter' => '|'); + + protected $_creditCards = array('visa', 'mc', 'amex', 'diners', 'discover', 'jcb'); + protected $_transactionTypes = array('preauth', 'postauth', 'sale', 'credit', 'void'); + + protected $_transaction = array(); + + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + public function __construct($user = NULL, $password = NULL, array $options = array()) { + $this->setUser($user)->setPassword($password); + + $this->_proxy = isset($options['proxy']) ? $options['proxy'] : NULL; + $this->_agent = isset($options['agent']) ? $options['agent'] : 'Mozilla/4.0'; + $this->_timeout = isset($options['timeout']) ? $options['timeout'] : 120; + } + + /* Public Methods + -------------------------------*/ + /** + * Validates required transaction parameters and sends + * the transaction to Innovative Gateway Solutions. + * + * @return string the cURL result + */ + public function send() { + //test for valid amount + if(!$this->_transaction['fulltotal'] || !is_numeric($this->_transaction['fulltotal'])) { + //throw exception + Eden_Webcharge_Error::i() + ->setMessage(Eden_Webcharge_Error::INVALID_AMOUNT) + ->addVariable((string) $this->_transaction['fulltotal']); + } + + //test for valid transaction type + if(!$this->_transaction['trantype'] || !in_array($this->_transaction['trantype'], $this->_transactionTypes)) { + //throw exception + Eden_Webcharge_Error::i() + ->setMessage(Eden_Webcharge_Error::INVALID_TRANSACTION_TYPE) + ->addVariable((string) $this->_transaction['trantype']) + ->trigger(); + } + + //test for valid card type + if(!$this->_transaction['cardtype'] || !in_array($this->_transaction['cardtype'], $this->creditCards)) { + //throw exception + Eden_Webcharge_Error::i() + ->setMessage(Eden_Webcharge_Error::INVALID_CARD_TYPE) + ->addVariable((string) $this->_transaction['cardtype']) + ->trigger(); + } + + //test for valid month + if(!$this->_transaction['month'] || !is_numeric($this->_transaction['month']) || strlen((string) $this->_transaction['month']) != 2) { + //throw exception + Eden_Webcharge_Error::i() + ->setMessage(Eden_Webcharge_Error::INVALID_CREDIT_CARD_MONTH) + ->addVariable((string) $this->_transaction['month']) + ->trigger(); + } + + //test for valid year + if(!$this->_transaction['year'] || !is_numeric($this->_transaction['year']) || !in_array(strlen((string) $this->_transaction['year']), array(2, 4))) { + //throw exception + Eden_Webcharge_Error::i() + ->setMessage(Eden_Webcharge_Error::INVALID_CREDIT_CARD_YEAR) + ->addVariable((string) $this->_transaction['year']) + ->trigger(); + } + + //test for valid creditcard name + if(!$this->_transaction['ccname']) { + //throw exception + Eden_Webcharge_Error::i(Eden_Webcharge_Error::INVALID_CREDIT_CARD_NAME)->trigger(); + } + + // Create the connection through the cURL extension + return Eden_Curl::i() + ->setUrl(self::PAYMENT_URL) + ->when($this->_proxy != NULL) + ->setProxy($this->_proxy) + ->endWhen() + ->setUserAgent($this->_agent) + ->setPost(true) + ->setPostFields($this->_transaction) + ->setFollowLocation(true) + ->setTimeout($this->_timeout) + ->getResponse(); + } + + /** + * Sets the merchant password + * + * @param string password + * @return this + */ + public function setPassword($password) { + Eden_Webcharge_Error::i() + ->setMessage()->argument(1, 'string'); + $this->_transaction['pw'] = $password; + return $this; + } + + /** + * Set a transaction to send. + * + * @param array the transaction to set + * @return string the cURL result + */ + public function setTransaction(array $transaction) { + //we loop through the template because + //these are the keys WebCharge will take + //and we do not want to add any extra variables + //when we query their server + foreach($this->_template as $key => $value) { + //if the passed in transaction + if(isset($transaction[$key])) { + //allow this transaction to be set by it + $this->_transaction[$key] = $transaction[$key]; + //else if it is not set in this transaction + } else if(!isset($this->_transaction[$key])) { + //set it using the template's value + $this->_transaction[$key] = $value; + } + } + + return $this; + } + + /** + * Sets the Merchant user name + * + * @param string user name + * @return this + */ + public function setUser($user) { + Eden_Webcharge_Error::i() + ->setMessage()->argument(1, 'string'); + $this->_transaction['username'] = $user; + return $this; + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} + +/** + * WebCharge exception + */ +class Eden_Webcharge_Error extends Eden_Error +{ + /* Constants + -------------------------------*/ + const INVALID_AMOUNT = 'The amount set in the transaction (fulltotal) must be a number. %s was given.'; + const INVALID_TRANSACTION_TYPE = 'The transaction type (trantype) is invalid. "preauth", "postauth", "sale", "credit", "void" are allowed. %s was given.'; + const INVALID_CARD_TYPE = 'The credit card type (cardtype) is invalid. "visa", "mc", "amex", "diners", "discover", "jcb" are allowed. %s was given.'; + const INVALID_CREDIT_CARD_MONTH = 'The credit card month (month) must be a 2 digit number. %s was given.'; + const INVALID_CREDIT_CARD_YEAR = 'The credit card year (year) must be a 2 or 4 digit number. %s was given.'; + const INVALID_CREDIT_CARD_NAME = 'The credit card name cannot be empty.'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + /* Magic + -------------------------------*/ + /* Public Methods + -------------------------------*/ + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/when.php b/library/eden/when.php new file mode 100755 index 0000000..cd1033b --- /dev/null +++ b/library/eden/when.php @@ -0,0 +1,145 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +require_once dirname(__FILE__).'/class.php'; + +/** + * Trigger when something is false + * + * @package Eden + * @category core + * @author Christian Blanquera cblanquera@openovate.com + */ +class Eden_When extends Eden_Class implements ArrayAccess, Iterator { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_scope = NULL; + protected $_increment = 1; + protected $_lines = 0; + + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + public function __construct($scope, $lines = 0) { + $this->_scope = $scope; + $this->_lines = $lines; + } + + public function __call($name, $args) { + if($this->_lines > 0 && $this->_increment == $this->_lines) { + return $this->_scope; + } + + $this->_increment++; + return $this; + } + + /* Public Methods + -------------------------------*/ + /** + * Returns the current item + * For Iterator interface + * + * @return void + */ + public function current() { + return $this->_scope->current(); + } + + /** + * Returns th current position + * For Iterator interface + * + * @return void + */ + public function key() { + return $this->_scope->key(); + } + + /** + * Increases the position + * For Iterator interface + * + * @return void + */ + public function next() { + $this->_scope->next(); + } + + /** + * isset using the ArrayAccess interface + * + * @param number + * @return bool + */ + public function offsetExists($offset) { + return $this->_scope->offsetExists($offset); + } + + /** + * returns data using the ArrayAccess interface + * + * @param number + * @return bool + */ + public function offsetGet($offset) { + return $this->_scope->offsetGet($offset); + } + + /** + * Sets data using the ArrayAccess interface + * + * @param number + * @param mixed + * @return void + */ + public function offsetSet($offset, $value) {} + + /** + * unsets using the ArrayAccess interface + * + * @param number + * @return bool + */ + public function offsetUnset($offset) {} + + /** + * Rewinds the position + * For Iterator interface + * + * @return void + */ + public function rewind() { + $this->_scope->rewind(); + } + + /** + * Validates whether if the index is set + * For Iterator interface + * + * @return void + */ + public function valid() { + return $this->_scope->valid(); + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/xend.php b/library/eden/xend.php new file mode 100644 index 0000000..7a4b819 --- /dev/null +++ b/library/eden/xend.php @@ -0,0 +1,95 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +require_once dirname(__FILE__).'/class.php'; +require_once dirname(__FILE__).'/xend/base.php'; +require_once dirname(__FILE__).'/xend/error.php'; +require_once dirname(__FILE__).'/xend/booking.php'; +require_once dirname(__FILE__).'/xend/rate.php'; +require_once dirname(__FILE__).'/xend/shipment.php'; +require_once dirname(__FILE__).'/xend/tracking.php'; + +/** + * Xend API factory. This is a factory class with + * methods that will load up different Xend classes. + * Xend classes are organized as described on their + * developer site: booking, rate, shipment and tracking service. + * + * @package Eden + * @category xend + * @author Christian Symon M. Buenavista sbuenavista@openovate.com + */ +class Eden_Xend extends Eden_Class { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function i() { + return self::_getSingleton(__CLASS__); + } + + /* Magic + -------------------------------*/ + /* Public Methods + -------------------------------*/ + /** + * Returns xend booking service + * + * @param *string User token + * @param *boolean test mode + * @return Eden_Xend_Booking + */ + public function booking($userToken, $test = true) { + return Eden_Xend_Booking::i($userToken, $test = true); + } + + /** + * Returns xend rate service + * + * @param *string User token + * @param *boolean test mode + * @return Eden_Xend_Rate + */ + public function rate($userToken, $test = true) { + return Eden_Xend_Rate::i($userToken, $test = true); + } + + /** + * Returns xend shipment service + * + * @param *string User token + * @param *boolean test mode + * @return Eden_Xend_Shipment + */ + public function shipment($userToken, $test = true) { + return Eden_Xend_Shipment::i($userToken, $test = true); + } + + /** + * Returns xend tracking service + * + * @param *string User token + * @param *boolean test mode + * @return Eden_Xend_Tracking + */ + public function tracking($userToken, $test = true) { + return Eden_Xend_Tracking::i($userToken, $test = true); + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/xend/base.php b/library/eden/xend/base.php new file mode 100644 index 0000000..37b4784 --- /dev/null +++ b/library/eden/xend/base.php @@ -0,0 +1,78 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Xend Express - Base + * + * @package Eden + * @category xend + * @author Christian Symon M. Buenavista sbuenavista@openovate.com + */ +class Eden_Xend_Base extends Eden_Class { + /* Constants + -------------------------------*/ + const SHIPMENT_WSDL = 'https://www.xend.com.ph/api/ShipmentService.asmx?wsdl'; + const TRACKING_WSDL = 'https://www.xend.com.ph/api/TrackingService.asmx?wsdl'; + const RATE_WSDL = 'https://www.xend.com.ph/api/RateService.asmx?wsdl'; + const BOOKING_WSDL = 'https://xend.com.ph/api/BookingService.asmx?wsdl'; + const HEADER = 'https://www.xend.com.ph/api/'; + const WAY_BILL_NO = 'WaybillNo'; + const USER_TOKEN = 'UserToken'; + const AUTH_HEADER = 'AuthHeader'; + const LENGTH = 'DimensionL'; + const WIDTH = 'DimensionW'; + const HEIGHT = 'DimensionH'; + const VALUE = 'DeclaredValue'; + + const TEST_SHIPMENT_WSDL = 'https://www.xend.com.ph/apitest/ShipmentService.asmx?wsdl'; + const TEST_BOOKING_WSDL = 'https://xend.com.ph/apitest/BookingService.asmx?wsdl'; + const TEST_HEADER = 'https://www.xend.com.ph/apitest/'; + const METRO_MANILA_EXPRESS = 'MetroManilaExpress'; + const PROVINCIAL_EXPRESS = 'ProvincialExpress'; + const INTERNATIONAL_POSTAL = 'InternationalPostal'; + const INTERNATIONAL_EMS = 'InternationalEMS'; + const INTERNATIONAL_EXPRESS = 'InternationalExpress'; + const RIZAL_METRO_MANILA_EXPRESS = 'RizalMetroManilaExpress'; + const DOCUMENT = 'Document'; + const PARCEL = 'Parcel'; + const BOOKING_DATE = 'BookingDate'; + const REFERENCE_NUMBER = 'AddressRefNo'; + const REMARKS = 'Remarks'; + const WEIGHT = 'Weight'; + const DESTINATION_VALUE = 'DestinationValue'; + const INSURANCE = 'AddInsurance'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_userToken = NULL; + protected $_test = NULL; + + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + /* Magic + -------------------------------*/ + public function __construct($userToken, $test = true) { + //Argument 1 must be a string + Eden_Xend_Error::i()->argument(1, 'string'); + + $this->_userToken = $userToken; + $this->_test = $test; + } + + /* Public Methods + -------------------------------*/ + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/xend/booking.php b/library/eden/xend/booking.php new file mode 100644 index 0000000..50671c6 --- /dev/null +++ b/library/eden/xend/booking.php @@ -0,0 +1,340 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Xend Express - Booking Service + * + * @package Eden + * @category xend + * @author Christian Symon M. Buenavista sbuenavista@openovate.com + */ +class Eden_Xend_Booking extends Eden_Xend_Base{ + /* Constants + -------------------------------*/ + const FIRST_NAME = 'FirstName'; + const LAST_NAME = 'LastName'; + const STREET1 = 'Street1'; + const STREET2 = 'Street2'; + const CITY = 'City'; + const PROVINCE = 'Province'; + const POSTAL_CODE = 'PostalCode'; + const LANDMARK = 'Landmark'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_url = self::BOOKING_WSDL; + protected $_header = self::HEADER; + protected $_exceptionFlag = false; + protected $_date = NULL; + protected $_addressRefNo = NULL; + protected $_remarks = NULL; + protected $_firstName = NULL; + protected $_lastName = NULL; + protected $_street1 = NULL; + protected $_street2 = NULL; + protected $_city = NULL; + protected $_province = NULL; + protected $_postalCode = NULL; + protected $_landmark = NULL; + + + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + /* Magic + -------------------------------*/ + /* Public Methods + -------------------------------*/ + /** + * Retrieves the list of addresses in the account. + * + * return array + */ + public function getDetail() { + //if it is in test mode + if($this->_test) { + $this->_url = self::TEST_BOOKING_WSDL; + $this->_header = self::TEST_HEADER; + } + + //initialize SOAP client + $client = new SoapClient($this->_url, array()); + $funcs = $client->__getFunctions(); + + //initialize SOAP header + $headerbody = array(self::USER_TOKEN => $this->_userToken); + $header = new SoapHeader($this->_header, self::AUTH_HEADER, $headerbody); + $client->__setSoapHeaders($header); + + //execute SOAP method + try { + $result = $client->GetAddress(); + //catch soap fault + } catch(SoapFault $soapfault) { + $this->_exceptionFlag = true; + $exception = $soapfault->getMessage(); + preg_match_all('/: (.*?). at/s', $exception, $error, PREG_SET_ORDER); + //Print error + return $error[0][1]; + } + + return $result->GetAddressResult->Address; + } + + /** + * Creates a booking for pickup. + * + * return array + */ + public function getResponse() { + // initialize SOAP client + $client= new SoapClient($this->_url, array()); + $funcs = $client->__getFunctions(); + + // initialize SOAP header + $headerbody = array(self::USER_TOKEN => $this->_userToken); + $header = new SoapHeader($this->_header, self::AUTH_HEADER, $headerbody); + $client->__setSoapHeaders($header); + + // prepare parameters + $param = array( + self::BOOKING_DATE => $this->_date, + self::REFERENCE_NUMBER => $this->_addressRefNo, + self::REMARKS => $this->_remarks); + + // execute SOAP method + try + { + $result = $client->Schedule($param); + } + catch (SoapFault $soapfault) + { + $this->_exceptionFlag = true; + $exception = $soapfault->getMessage(); + preg_match_all('/: (.*?). at/s', $exception, $error, PREG_SET_ORDER); + //print error + return $error[0][1]; + } + + return $result; + } + + /** + * Creates a booking for pickup with specific + * pickup address. + * + * return array + */ + public function getSpecific() { + // initialize SOAP client + $client= new SoapClient($this->_url, array()); + $funcs = $client->__getFunctions(); + + // initialize SOAP header + $headerbody = array(self::USER_TOKEN => $this->_userToken); + $header = new SoapHeader($this->_header, self::AUTH_HEADER, $headerbody); + $client->__setSoapHeaders($header); + + // prepare parameters + $param = array( + self::BOOKING_DATE => $this->_date, + self::REMARKS => $this->_remarks, + self::FIRST_NAME => $this->_firstName, //shippers first name + self::LAST_NAME => $this->_lastName, //shippers last name + self::STREET1 => $this->_street1, //shippers street 1 + self::STREET2 => $this->_street2, //shippers street 2 + self::CITY => $this->_city, //shippers city + self::PROVINCE => $this->_province, //shippers province + self::POSTAL_CODE => $this->_postalCode, //shippers postal code + self::LANDMARK => $this->_landmark); //shippers landmark + + // execute SOAP method + try + { + $result = $client->ScheduleDev($param); + } + catch (SoapFault $soapfault) + { + $this->_exceptionFlag = true; + $exception = $soapfault->getMessage(); + preg_match_all('/: (.*?). at/s', $exception, $error, PREG_SET_ORDER); + //print error + return $error[0][1]; + } + + return $result; + } + + /** + * Set address reference number + * + * @param *integer + * @return this + */ + public function setAddressNumber($addressNumber) { + //Argument 1 must be an integer + Eden_Xend_Error::i()->argument(1, 'int'); + + $this->_addressRefNo = $addressNumber; + return $this; + } + + /** + * Set shippers city + * + * @param *string + * @return this + */ + public function setCity($city) { + //Argument 1 must be a string + Eden_Xend_Error::i()->argument(1, 'string'); + + $this->_city = $city; + return $this; + } + + /** + * Set date + * + * @param *string + * @return this + */ + public function setDate($date) { + //Argument 1 must be a string + Eden_Xend_Error::i()->argument(1, 'string'); + + $start = strtotime($date); + $this->_date = date('Y-m-d\TH\:i\:s\.u', $start); + return $this; + } + + /** + * Set shippers first name + * + * @param *string + * @return this + */ + public function setFirstName($firstName) { + //Argument 1 must be a string + Eden_Xend_Error::i()->argument(1, 'string'); + + $this->_firstName = $firstName; + return $this; + } + + /** + * Set shippers landmark + * + * @param *string + * @return this + */ + public function setLandmark($landmark) { + //Argument 1 must be a string + Eden_Xend_Error::i()->argument(1, 'string'); + + $this->_landmark = $landmark; + return $this; + } + + /** + * Set shippers last name + * + * @param *string + * @return this + */ + public function setLastName($lastName) { + //Argument 1 must be a string + Eden_Xend_Error::i()->argument(1, 'string'); + + $this->_lastName = $lastName; + return $this; + } + + /** + * Set shippers postal code + * + * @param *string + * @return this + */ + public function setPostalCode($postalCode) { + //Argument 1 must be a string + Eden_Xend_Error::i()->argument(1, 'string'); + + $this->_postalCode = $postalCode; + return $this; + } + + /** + * Set shippers province + * + * @param *string + * @return this + */ + public function setProvince($province) { + //Argument 1 must be a string + Eden_Xend_Error::i()->argument(1, 'string'); + + $this->_province = $province; + return $this; + } + + /** + * Set remarks + * + * @param *string + * @return this + */ + public function setRemarks($remarks) { + //Argument 1 must be a string + Eden_Xend_Error::i()->argument(1, 'string'); + + $this->_remarks = $remarks; + return $this; + } + + /** + * Set shippers street 1 + * + * @param *string + * @return this + */ + public function setStreet1($street1) { + //Argument 1 must be a string + Eden_Xend_Error::i()->argument(1, 'string'); + + $this->_street1 = $street1; + return $this; + } + + /** + * Set shippers street 2 + * + * @param *string + * @return this + */ + public function setStreet2($street2) { + //Argument 1 must be a string + Eden_Xend_Error::i()->argument(1, 'string'); + + $this->_street2 = $street2; + return $this; + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/xend/error.php b/library/eden/xend/error.php new file mode 100644 index 0000000..576ec35 --- /dev/null +++ b/library/eden/xend/error.php @@ -0,0 +1,41 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Xend Errors + * + * @package Eden + * @category xend + * @author Christian Symon M. Buenavista sbuenavista@openovate.com + */ +class Eden_Xend_Error extends Eden_Error { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function i($message = NULL, $code = 0) { + $class = __CLASS__; + return new $class($message, $code); + } + + /* Magic + -------------------------------*/ + /* Public Methods + -------------------------------*/ + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/xend/rate.php b/library/eden/xend/rate.php new file mode 100644 index 0000000..e29d2f5 --- /dev/null +++ b/library/eden/xend/rate.php @@ -0,0 +1,259 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + + +/** + * Xend Express - Rate Service + * + * @package Eden + * @category xend + * @author Christian Symon M. Buenavista sbuenavista@openovate.com + */ +class Eden_Xend_Rate extends Eden_Xend_Base{ + /* Constants + -------------------------------*/ + const SERVICE_TYPE = 'ServiceTypeValue'; + const SHIPMENT_TYPE = 'ShipmentTypeValue'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_exceptionFlag = false; + protected $_serviceType = NULL; + protected $_shipmentType = NULL; + protected $_weight = NULL; + protected $_lenght = NULL; + protected $_width = NULL; + protected $_height = NULL; + protected $_declaredValue = NULL; + protected $_destinationValue = NULL; + + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + /* Magic + -------------------------------*/ + /* Public Methods + -------------------------------*/ + /** + * Retrieves the calculated rate based on the shipment information. + * + * @return integer|float + */ + public function getResponse() { + // initialize SOAP client + $client = new SoapClient(self::RATE_WSDL); + $funcs = $client->__getFunctions(); + + // initialize SOAP header + $headerbody = array(self::USER_TOKEN => $this->_userToken); + $header = new SoapHeader(self::HEADER, self::AUTH_HEADER, $headerbody); + $client->__setSoapHeaders($header); + + // prepare parameters + $query = array( + self::SERVICE_TYPE => $this->_serviceType, + self::SHIPMENT_TYPE => $this->_shipmentType, + self::DESTINATION_VALUE => $this->_destinationValue, //Destination of item + self::WEIGHT => $this->_weight, //Weight of item in kilogram + self::LENGTH => $this->_length, //Length of item in centimeter + self::WIDTH => $this->_width, //Width of item in centimeter + self::HEIGHT => $this->_height, //Height of item in centimeter + self::VALUE => $this->_declaredValue, //Declared value of item in peso + self::INSURANCE => true); + + // execute SOAP method + try { + $result = $client->Calculate($query); + //catch soap fault + } catch(SoapFault $soapfault) { + $this->_exceptionFlag = true; + $exception = $soapfault->getMessage(); + preg_match_all('/: (.*?). at/s', $exception, $error, PREG_SET_ORDER); + //Print error + return $error[0][1]; + } + + return $result->CalculateResult; + } + + /** + * Set item declared value + * + * @param *integer|float + * @return this + */ + public function setDeclaredValue($declaredValue) { + //Argument 1 must be an integer or float + Eden_Xend_Error::i()->argument(1, 'int', 'float'); + + $this->_declaredValue = $declaredValue; + return $this; + } + + /** + * Set item destination + * + * @param *string + * @return this + */ + public function setDestinationValue($destinationValue) { + //Argument 1 must be a string + Eden_Xend_Error::i()->argument(1, 'string'); + + $this->_destinationValue = $destinationValue; + return $this; + } + + /** + * Set shipment type to document + * + * @return this + */ + public function setDocument() { + $this->_shipmentType = self::DOCUMENT; + return $this; + } + + /** + * Set item height + * + * @param *integer|float In centimeter + * @return this + */ + public function setHeight($height) { + //Argument 1 must be an integer or float + Eden_Xend_Error::i()->argument(1, 'int', 'float'); + + $this->_height = $height; + return $this; + } + + /** + * Set service type to international EMS + * + * @return this + */ + public function setInternationalEms() { + $this->_serviceType = self::INTERNATIONAL_EMS; + return $this; + } + + /** + * Set service type to international Express + * + * @return this + */ + public function setInternationalExpress() { + $this->_serviceType = self::INTERNATIONAL_EXPRESS; + return $this; + } + + /** + * Set service type to international postal + * + * @return this + */ + public function setInternationalPostal() { + $this->_serviceType = self::INTERNATIONAL_POSTAL; + return $this; + } + + /** + * Set item length + * + * @param *integer|float In centimeter + * @return this + */ + public function setLenght($length) { + //Argument 1 must be an integer or float + Eden_Xend_Error::i()->argument(1, 'int', 'float'); + + $this->_length = $length; + return $this; + } + + /** + * Set service type to metro manila express + * + * @return this + */ + public function setMetroManilaExpress() { + $this->_serviceType = self::METRO_MANILA_EXPRESS; + return $this; + } + + /** + * Set shipment type to parcel + * + * @return this + */ + public function setParcel() { + $this->_shipmentType = self::PARCEL; + return $this; + } + + /** + * Set service type to provincial express + * + * @return this + */ + public function setProvincialExpress() { + $this->_serviceType = self::PROVINCIAL_EXPRESS; + return $this; + } + + /** + * Set service type to rizal metro manila express + * + * @return this + */ + public function setRizalMetroManilaExpress() { + $this->_serviceType = self::RIZAL_METRO_MANILA_EXPRESS; + return $this; + } + + /* Set item weight + * + * @param *integer|float In kilogram + * @return this + */ + public function setWeight($weight) { + //Argument 1 must be an integer or float + Eden_Xend_Error::i()->argument(1, 'int', 'float'); + + $this->_weight = $weight; + return $this; + } + + /** + * Set item width + * + * @param *integer|float In centimeter + * @return this + */ + public function setWidth($width) { + //Argument 1 must be an integer or float + Eden_Xend_Error::i()->argument(1, 'int', 'float'); + + $this->_width = $width; + return $this; + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/xend/shipment.php b/library/eden/xend/shipment.php new file mode 100644 index 0000000..11a59b5 --- /dev/null +++ b/library/eden/xend/shipment.php @@ -0,0 +1,550 @@ + +/* + * This file is part of the Eden package. + * (c) 2009-2011 Christian Blanquera + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Xend Express - Shipment Service + * + * @package Eden + * @category Xend + * @author Christian Symon M. Buenavista + * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ + */ +class Eden_Xend_Shipment extends Eden_Xend_Base { + /* Constants + -------------------------------*/ + const SHIPMENT = 'shipment'; + const SERVICE_TYPE = 'ServiceTypeValue'; + const SHIPMENT_TYPE = 'ShipmentTypeValue' ; + const PURPOSE = 'PurposeOfExportValue'; + const NAME = 'RecipientName'; + const COMPANY = 'RecipientCompanyName'; + const ADDRESS1 = 'RecipientAddress1'; + const ADDRESS2 = 'RecipientAddress2'; + const CITY = 'RecipientCity'; + const PROVINCE = 'RecipientProvince'; + const COUNTRY = 'RecipientCountry'; + const INSURED = 'IsInsured'; + const INSTRUCTION = 'SpecialInstructions'; + const DESCRIPTION = 'Description'; + const CLIENT = 'ClientReference'; + const DATE_CREATED = 'DateCreated'; + const DATE_PRINTED = 'DatePrinted'; + const POSTAL_CODE = 'RecipientPostalCode'; + const PHONE_NUMBER = 'RecipientPhoneNo'; + const EMAIL = 'RecipientEmailAddress'; + const MANUFACTURED = 'CountryManufactured'; + const SHIPPING_FEE = 'ShippingFee'; + const INSURANCE_FEE = 'InsuranceFee'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_test = true; + protected $_exceptionFlag = false; + protected $_url = self::SHIPMENT_WSDL; + protected $_header = self::HEADER; + + protected $_wayBillNo = NULL; + protected $_serviceType = NULL; + protected $_shipmentType = NULL; + protected $_purpose = NULL; + protected $_weight = NULL; + protected $_length = NULL; + protected $_width = NULL; + protected $_height = NULL; + protected $_declaredValue = NULL; + protected $_name = NULL; + protected $_address1 = NULL; + protected $_address2 = NULL; + protected $_city = NULL; + protected $_provice = NULL; + protected $_country = NULL; + protected $_specialInstruction = NULL; + protected $_description = NULL; + protected $_company = NULL; + protected $_shippingFee = NULL; + protected $_postalCode = NULL; + protected $_phoneNumber = NULL; + protected $_email = NULL; + protected $_wayBill = NULL; + protected $_fee = 0; + + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + /* Magic + -------------------------------*/ + /* Public Methods + -------------------------------*/ + /** + * Retrieves the information of a shipment given a waybill number + * + * return array + */ + public function getDetail() { + $exceptionFlag = false; + + // initialize SOAP client + $client = new SoapClient($this->_url, array()); + $funcs = $client->__getFunctions(); + + // initialize SOAP header + $headerbody = array(self::USER_TOKEN => $this->_userToken); + $header = new SoapHeader($this->_header, self::AUTH_HEADER, $headerbody); + $client->__setSoapHeaders($header); + + // execute SOAP method + try { + $result = $client->Get(array(self::WAY_BILL_NO => $this->_wayBill)); + } catch(SoapFault $soapfault) { + $this->_exceptionFlag = true; + $exception = $soapfault->getMessage(); + preg_match_all('/: (.*?). at/s', $exception, $error, PREG_SET_ORDER); + //Print error + return $error[0][1]; + } + + return $result->GetResult; + } + + /** + * Creates a new shipment and returns the waybill number + * + * return array + */ + public function getResponse() { + // initialize SOAP client + $client = new SoapClient($this->_url, array()); + $funcs = $client->__getFunctions(); + + // initialize SOAP header + $headerbody = array(self::USER_TOKEN => $this->_userToken); + $header = new SoapHeader($this->_header, self::AUTH_HEADER, $headerbody); + + $client->__setSoapHeaders($header); + + // prepare parameters + $query = array( + self::SERVICE_TYPE => $this->_serviceType, + self::SHIPMENT_TYPE => $this->_shipmentType, + self::PURPOSE => $this->_purpose, + self::WEIGHT => $this->_weight, + self::LENGTH => $this->_length, + self::WIDTH => $this->_width, + self::HEIGHT => $this->_height, + self::VALUE => $this->_declaredValue, + self::NAME => $this->_name, + self::COMPANY => $this->_company, + self::ADDRESS1 => $this->_address1, + self::ADDRESS2 => $this->_address2, + self::CITY => $this->_city, + self::PROVINCE => $this->_provice, + self::COUNTRY => $this->_country, + self::INSURED => TRUE, + self::INSTRUCTION => $this->_specialInstruction, + self::DESCRIPTION => $this->_description, + self::CLIENT => '', + self::MANUFACTURED => '', + self::POSTAL_CODE => $this->_postalCode, + self::PHONE_NUMBER => $this->_phoneNumber, + self::EMAIL => $this->_email, + self::DATE_CREATED => time(), + self::DATE_PRINTED => time(), + self::SHIPPING_FEE => $this->_fee, + self::INSURANCE_FEE => '1'); + + // execute SOAP method + try { + + //create a Shipment method + $result = $client->Create(array(self::SHIPMENT => $query)); + + } catch(SoapFault $soapfault) { + + $this->_exceptionFlag = true; + $exception = $soapfault->getMessage(); + preg_match_all('/: (.*?). at/s', $exception, $error, PREG_SET_ORDER); + //Print error + return $error[0][1]; + } + //fetch way bill number + $this->_wayBill = $result->CreateResult; + + return $this->getDetail(); + } + + /** + * Set recipient address1 + * + * @param *string + * @return this + */ + public function setAddress1($address1) { + //Argument 1 must be a string + Eden_Xend_Error::i()->argument(1, 'string'); + + $this->_address1 = $address1; + return $this; + } + + /** + * Set recipient address2 + * + * @param *string + * @return this + */ + public function setAddress2($address2) { + //Argument 1 must be a string + Eden_Xend_Error::i()->argument(1, 'string'); + + $this->_address1 = $address2; + return $this; + } + + /** + * Set recipient city + * + * @param *string + * @return this + */ + public function setCity($city) { + //Argument 1 must be a string + Eden_Xend_Error::i()->argument(1, 'string'); + + $this->_city = $city; + return $this; + } + + /** + * Set company + * + * @param *string + * @return this + */ + public function setCompany($company) { + //Argument 1 must be a string + Eden_Xend_Error::i()->argument(1, 'string'); + $this->_company = $company; + return $this; + } + + /** + * Set recipient country + * + * @param *string + * @return this + */ + public function setCountry($country) { + //Argument 1 must be a string + Eden_Xend_Error::i()->argument(1, 'string'); + + $this->_country = $country; + return $this; + } + + /** + * Set item declared value + * + * @param *integer|float + * @return this + */ + public function setDeclaredValue($declaredValue) { + //Argument 1 must be an integer or float + Eden_Xend_Error::i()->argument(1, 'int', 'float'); + + $this->_declaredValue = $declaredValue; + return $this; + } + + /** + * Set item description + * + * @param *string + * @return this + */ + public function setDescription($description) { + //Argument 1 must be a string + Eden_Xend_Error::i()->argument(1, 'string'); + + $this->_description = $description; + return $this; + } + + /** + * Set shipment type to document + * + * @return this + */ + public function setDocument() { + $this->_shipmentType = self::DOCUMENT; + return $this; + } + + /** + * Set email + * + * @param *string + * @return this + */ + public function setEmail($email) { + //Argument 1 must be a string + Eden_Xend_Error::i()->argument(1, 'string'); + + $this->_email = $email; + return $this; + } + + /** + * Set item height + * + * @param *integer|float In centimeter + * @return this + */ + public function setHeight($height) { + //Argument 1 must be an integer or float + Eden_Xend_Error::i()->argument(1, 'int', 'float'); + + $this->_height = $height; + return $this; + } + + /** + * Set service type to international EMS + * + * @return this + */ + public function setInternationalEMS() { + $this->_serviceType = self::INTERNATIONAL_EMS; + return $this; + } + + /** + * Set service type to international Express + * + * @return this + */ + public function setInternationalExpress() { + $this->_serviceType = self::INTERNATIONAL_EXPRESS; + return $this; + } + + /** + * Set service type to international postal + * + * @return this + */ + public function setInternationalPostal() { + $this->_serviceType = self::INTERNATIONAL_POSTAL; + return $this; + } + + /** + * Set item length + * + * @param *integer|float In centimeter + * @return this + */ + public function setLength($length) { + //Argument 1 must be an integer or float + Eden_Xend_Error::i()->argument(1, 'int', 'float'); + + $this->_length = $length; + return $this; + } + + /** + * Set service type to metro manila express + * + * @return this + */ + public function setMetroManilaExpress() { + $this->_serviceType = self::METRO_MANILA_EXPRESS; + return $this; + } + + /** + * Set recipient name + * + * @param *string + * @return this + */ + public function setName($name) { + //Argument 1 must be a string + Eden_Xend_Error::i()->argument(1, 'string'); + + $this->_name = $name; + return $this; + } + + /** + * Set shipment type to parcel + * + * @return this + */ + public function setParcel() { + $this->_shipmentType = self::PARCEL; + return $this; + } + + /** + * Set phone number + * + * @param *string + * @return this + */ + public function setPhoneNumber($phoneNumber) { + //Argument 1 must be a string + Eden_Xend_Error::i()->argument(1, 'string'); + + $this->_phoneNumber = $phoneNumber; + return $this; + } + + /** + * Set postal code + * + * @param *string + * @return this + */ + public function setPostalCode($postalCode) { + //Argument 1 must be a string + Eden_Xend_Error::i()->argument(1, 'string'); + + $this->_postalCode = $postalCode; + return $this; + } + + /** + * Set recipient provice + * + * @param *string + * @return this + */ + public function setProvince($province) { + //Argument 1 must be a string + Eden_Xend_Error::i()->argument(1, 'string'); + + $this->province = $province; + return $this; + } + + /** + * Set service type to provincial express + * + * @return this + */ + public function setProvincialExpress() { + $this->_serviceType = self::PROVINCIAL_EXPRESS; + return $this; + } + + /** + * Set purpose of export + * + * @param *string + * @return this + */ + public function setPurpose($purpose) { + //Argument 1 must be a string + Eden_Xend_Error::i()->argument(1, 'string'); + $this->_purpose = $purpose; + return $this; + } + + /** + * Set service type to rizal metro manila express + * + * @return this + */ + public function setRizalMetroManilaExpress() { + $this->_serviceType = self::RIZAL_METRO_MANILA_EXPRESS; + return $this; + } + + /** + * Set shipping feee + * + * @param *integer|float + * @return this + */ + public function setShippingFee($fee) { + //Argument 1 must be an integer or float + Eden_Xend_Error::i()->argument(1, 'int','float'); + + $this->_fee = $fee; + return $this; + } + + /** + * Set item special instruction + * + * @param *string + * @return this + */ + public function setSpecialInstruction($specialInstruction) { + //Argument 1 must be a string + Eden_Xend_Error::i()->argument(1, 'string'); + + $this->_specialInstruction = $specialInstruction; + return $this; + } + + /** + * Set way bill number + * + * @param *string + * @return this + */ + public function setWayBillNumber($wayBillNo) { + //Argument 1 must be a string + Eden_Xend_Error::i()->argument(1, 'string'); + + $this->_wayBillNo = $wayBillNo; + return $this; + } + + /** + * Set item weight + * + * @param *integer|float In kilogram + * @return this + */ + public function setWeight($weight) { + //Argument 1 must be an integer or float + Eden_Xend_Error::i()->argument(1, 'int', 'float'); + + $this->_weight = $weight; + return $this; + } + + /** + * Set item width + * + * @param *integer|float In centimeter + * @return this + */ + public function setWidth($width) { + //Argument 1 must be an integer or float + Eden_Xend_Error::i()->argument(1, 'int', 'float'); + + $this->_width = $width; + return $this; + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/xend/tracking.php b/library/eden/xend/tracking.php new file mode 100644 index 0000000..724b078 --- /dev/null +++ b/library/eden/xend/tracking.php @@ -0,0 +1,92 @@ + +/* + * This file is part of the Eden package. + * (c) 2009-2011 Christian Blanquera + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Xend Express - Tracking Service + * + * @package Eden + * @category Xend + * @author Christian Symon M. Buenavista + * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ + */ + +class Eden_Xend_Tracking extends Eden_Xend_Base{ + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_exceptionFlag = false; + protected $_wayBillNo = NULL; + + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + /* Magic + -------------------------------*/ + /* Public Methods + -------------------------------*/ + /** + * Retrieving tracking information given the waybill number of the + * shipment. + * + * @return array + */ + public function getTracking() { + // initialize SOAP client + $client = new SoapClient(self::TRACKING_WSDL, array()); + $funcs = $client->__getFunctions(); + + // initialize SOAP header + $headerbody = array(self::USER_TOKEN => $this->_userToken); + $header = new SoapHeader(self::HEADER, self::AUTH_HEADER, $headerbody); + $client->__setSoapHeaders($header); + + // prepare parameters + $query = array(self::WAY_BILL_NO => $this->_wayBillNo); + + // execute SOAP method + try { + $result = $client->GetList($query); + //catch soap fault + } catch (SoapFault $soapfault) { + $this->_exceptionFlag = true; + $exception = $soapfault->getMessage(); + preg_match_all('/: (.*?). at/s', $exception, $error, PREG_SET_ORDER); + //Print error + return $error[0][1]; + } + return $result; + } + + /** + * Set way bill number + * + * @param *string + * @return this + */ + public function setWayBillNumber($wayBillNumber) { + //Argument 1 must be a string + Eden_Xend_Error::i()->argument(1, 'string'); + + $this->_wayBillNo = $wayBillNumber; + return $this; + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/yahoo.php b/library/eden/yahoo.php new file mode 100644 index 0000000..2d875b2 --- /dev/null +++ b/library/eden/yahoo.php @@ -0,0 +1,59 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Yahoo API factory. This is a factory class with + * methods that will load up different Yahoo classes. + * + * @package Eden + * @category Yahoo + * @author Christian Symon M. Buenavista sbuenavista@openovate.com + */ +class Eden_Yahoo extends Eden_Class { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function i() { + return self::_getSingleton(__CLASS__); + } + + /* Magic + -------------------------------*/ + /* Public Methods + -------------------------------*/ + /** + * Returns FQL + * + * @return Eden_Yahoo_Yql + */ + public function yql() { + return Eden_Yahoo_Yql::i(); + } + + /** + * Returns Yahoo Oauth + * + * @return Eden_Yahoo_Oauth + */ + public function oauth($key, $secret) { + return Eden_Yahoo_Oauth::i($key, $secret); + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/yahoo/columns.php b/library/eden/yahoo/columns.php new file mode 100644 index 0000000..7420e30 --- /dev/null +++ b/library/eden/yahoo/columns.php @@ -0,0 +1,288 @@ + +return array( + 'album' => array( + 'aid', 'object_id', 'owner', + 'cover_pid', 'cover_object_id', 'name', + 'created', 'modified', 'description', + 'location', 'size', 'link', + 'visible', 'modified_major', 'edit_link', + 'type', 'can_upload', 'photo_count', + 'video_count'), + 'application' => array( + 'app_id', 'api_key', + 'canvas_name', 'display_name', + 'icon_url', 'logo_url', + 'company_name', 'developers', + 'description', 'daily_active_users', + 'weekly_active_users', 'monthly_active_users', + 'category', 'subcategory', + 'is_facebook_app', 'restriction_info', + 'app_domains', 'auth_dialog_data_help_url', + 'auth_dialog_description', 'auth_dialog_headline', + 'auth_dialog_perms_explanation', 'auth_referral_user_perms', + 'auth_referral_friend_perms', 'auth_referral_default_activity_privacy', + 'auth_referral_enabled', 'auth_referral_extended_perms', + 'auth_referral_response_type', 'canvas_fluid_height', + 'canvas_fluid_width', 'canvas_url', + 'contact_email', 'created_time', + 'creator_uid', 'deauth_callback_url', + 'iphone_app_store_id', 'hosting_url', + 'mobile_web_url', 'page_tab_default_name', + 'page_tab_url', 'privacy_policy_url', + 'secure_canvas_url', 'secure_page_tab_url', + 'server_ip_whitelist', 'social_discovery', + 'terms_of_service_url', 'update_ip_whitelist', + 'user_support_email', 'user_support_url', + 'website_url'), + 'apprequest' => array( + 'request_id', 'app_id', 'recipient_uid', + 'sender_uid', 'message', 'data', + 'created_time'), + 'checkin' => array( + 'checkin_id', 'author_uid', 'page_id', + 'app_id', 'post_id', 'coords', + 'timestamp', 'tagged_uids', 'message'), + 'comment' => array( + 'xid', 'object_id', 'post_id', + 'fromid', 'time', 'text', + 'id', 'username ', 'reply_xid', + 'post_fbid', 'app_id', 'likes', + 'comments', 'user_likes', 'is_private'), + 'comments_info' => array( + 'app_id', 'xid', + 'count', 'updated_time'), + 'connection' => array( + 'source_id', 'target_id', + 'target_type', 'is_following'), + 'cookies' => array( + 'uid', 'name', 'value', + 'expires', 'path'), + 'developer' => array('developer_id', 'application_id', 'role'), + 'domain' => array('domain_id', 'domain_name'), + 'domain_admin' => array('owner_id', 'domain_id'), + 'event' => array( + 'eid', 'name', 'tagline', + 'nid', 'pic_small', 'pic_big', + 'pic_square', 'pic', 'host', + 'description', 'event_type', 'event_subtype', + 'start_time', 'end_time', 'creator', + 'update_time', 'location', 'venue', + 'privacy', 'hide_guest_list', 'can_invite_friends'), + 'event_member' => array( + 'uid', 'eid', + 'rsvp_status', 'start_time'), + 'family' => array( + 'profile_id', 'uid', + 'name', 'birthday', + 'relationship'), + 'friend' => array('uid1', 'uid2'), + 'friend_request' => array( + 'uid_to', 'uid_from', + 'time', 'message', + 'unread'), + 'friendlist' => array('owner', 'flid', 'name'), + 'friendlist_member' => array('flid', 'uid'), + 'group' => array( + 'gid', 'name', 'nid', + 'pic_small', 'pic_big', 'pic', + 'description', 'group_type', 'group_subtype', + 'recent_news', 'creator', 'update_time', + 'office', 'website', 'venue', + 'privacy', 'icon', 'icon34', + 'icon68', 'email', 'version'), + 'group_member' => array( + 'uid', 'gid', 'administrator', + 'positions', 'unread', 'bookmark_order'), + 'insights' => array('object_id', 'metric', 'end_time', 'period', 'value'), + 'like' => array('object_id', 'post_id', 'user_id', 'object_type'), + 'link' => array( + 'link_id', 'owner', 'owner_comment', + 'created_time', 'title', 'summary', + 'url', 'picture', 'image_urls'), + 'link_stat' => array( + 'url', 'normalized_url', 'share_count', + 'like_count', 'comment_count', 'total_count', + 'click_count', 'comments_fbid', 'commentsbox_count'), + 'mailbox_folder' => array( + 'folder_id', 'viewer_id', 'name', + 'unread_count', 'total_count'), + 'message' => array( + 'message_id', 'thread_id', 'author_id', + 'body', 'created_time', 'attachment', + 'viewer_id'), + 'note' => array( + 'uid', 'note_id', 'created_time', + 'updated_time', 'content', 'content_html', + 'title'), + 'notification' => array( + 'notification_id', 'sender_id', 'recipient_id', + 'created_time', 'updated_time', 'title_html', + 'title_text', 'body_html', 'body_text', + 'href', 'app_id', 'is_unread', + 'is_hidden', 'object_id', 'object_type', + 'icon_url'), + 'object_url' => array( + 'url', 'id', + 'type', 'site'), + 'page' => array( + 'page_id', 'name', 'username', + 'description', 'categories', 'is_community_page', + 'pic_small', 'pic_big', 'pic_square', + 'pic', 'pic_large', 'page_url', + 'fan_count', 'type', 'website', + 'has_added_app', 'general_info', 'can_post', + 'checkins', 'founded', 'company_overview', + 'mission', 'products', 'location', + 'parking', 'hours', 'pharma_safety_info', + 'public_transit', 'attire', 'payment_options', + 'culinary_team', 'general_manager', 'price_range', + 'restaurant_services', 'restaurant_specialties', 'phone', + 'release_date', 'genre', 'starring', + 'screenplay_by', 'directed_by', 'produced_by', + 'studio', 'awards', 'plot_outline', + 'season', 'network', 'schedule', + 'written_by', 'band_members', 'hometown', + 'current_location', 'record_label', 'booking_agent', + 'press_contact', 'artists_we_like', 'influences', + 'band_interests', 'bio', 'affiliation', + 'birthday', 'personal_info', 'personal_interests', + 'built', 'features', 'mpg'), + 'page_admin' => array('uid', 'page_id', 'type'), + 'page_blocked_user' => array('page_id', 'uid'), + 'page_fan' => array( + 'uid', 'page_id', + 'type', 'profile_section', + 'created_time'), + 'permissions' => array('uid', 'PERMISSION_NAME'), + 'permissions_info' => array('permission_name', 'header', 'summary'), + 'photo' => array( + 'pid', 'aid', 'owner', + 'src_small', 'src_small_width', 'src_small_height', + 'src_big', 'src_big_width', 'src_big_height', + 'src', 'src_width', 'src_height', + 'link', 'caption', 'created', + 'modified', 'position', 'object_id', + 'album_object_id', 'images'), + 'photo_tag' => array( + 'pid', 'subject', 'object_id', + 'text', 'xcoord', 'ycoord', + 'created'), + 'place' => array( + 'page_id', 'name', 'description', + 'geometry', 'latitude', 'longitude', + 'checkin_count', 'display_subtext'), + 'privacy' => array( + 'id', 'object_id', 'value ', + 'description', 'allow', 'deny', + 'owner_id', 'networks', 'friends'), + 'privacy_setting' => array( + 'name', 'value ', 'description', + 'allow', 'deny', 'networks', + 'friends'), + 'profile' => array( + 'id', 'can_post', 'name', + 'url', 'pic', 'pic_square', + 'pic_small', 'pic_big', 'pic_crop', + 'type', 'username'), + 'question' => array( + 'id', 'owner', 'question', + 'created_time', 'updated_time'), + 'question_option' => array( + 'id', 'question_id', 'name', + 'votes', 'object_id', 'owner', + 'created_time'), + 'question_option_votes' => array('option_id', 'voter_id'), + 'review' => array( + 'reviewee_id', 'reviewer_id', 'review_id', + 'message', 'created_time', 'rating'), + 'standard_friend_info' => array('uid1', 'uid2'), + 'standard_user_info' => array( + 'uid', 'name', 'username', + 'third_party_id', 'first_name', 'last_name', + 'locale', 'affiliations', 'profile_url', + 'timezone', 'birthday', 'sex', + 'proxied_email', 'current_location', 'allowed_restrictions'), + 'status' => array( + 'uid', 'status_id', + 'time', 'source', + 'message'), + 'stream' => array( + 'post_id', 'viewer_id ', 'app_id', + 'source_id ', 'updated_time', 'created_time', + 'filter_key', 'attribution ', 'actor_id', + 'target_id', 'message', 'app_data', + 'action_links', 'attachment', 'impressions', + 'comments', 'likes', 'privacy', + 'permalink', 'xid', 'tagged_ids', + 'message_tags', 'description', 'description_tags'), + 'stream_filter' => array( + 'uid', 'filter_key ', 'name', + 'rank ', 'icon_url', 'is_visible', + 'type', 'value'), + 'stream_tag' => array('post_id', 'actor_id', 'target_id'), + 'thread' => array( + 'thread_id', 'folder_id', 'subject', + 'recipients', 'updated_time', 'parent_message_id', + 'parent_thread_id', 'message_count', 'snippet', + 'snippet_author', 'object_id', 'unread', + 'viewer_id'), + 'translation' => array( + 'locale', 'native_hash', 'native_string', + 'description', 'translation', 'approval_status', + 'pre_hash_string', 'best_string'), + 'unified_message' => array( + 'message_id', 'thread_id', 'subject', + 'body', 'unread', 'action_id', + 'timestamp', 'tags', 'sender', + 'recipients', 'object_sender', 'html_body', + 'attachments', 'attachment_map', 'shares', + 'share_map'), + 'unified_thread' => array( + 'action_id', 'archived', 'can_reply', + 'folder', 'former_participants', 'has_attachments', + 'is_subscribed', 'last_visible_add_action_id', 'name', + 'num_messages', 'num_unread', 'object_participants', + 'participants', 'senders', 'single_recipient', + 'snippet', 'snippet_sender', 'snippet_message_has_attachment', + 'subject', 'tags', 'thread_id', + 'thread_participants', 'timestamp', 'unread'), + 'unified_thread_action' => array( + 'action_id', 'actor', 'thread_id', + 'timestamp', 'type', 'users'), + 'unified_thread_count' => array( + 'folder', 'unread_count', 'unseen_count', + 'last_action_id', 'last_seen_time', 'total_threads'), + 'url_like' => array('user_id', 'url'), + 'user' => array( + 'uid', 'username', 'first_name', + 'middle_name', 'last_name', 'name', + 'pic_small', 'pic_big', 'pic_square', + 'pic', 'affiliations', 'profile_update_time', + 'timezone', 'religion', 'birthday', + 'birthday_date', 'sex', 'hometown_location', + 'meeting_sex', 'meeting_for', 'relationship_status', + 'significant_other_id', 'political', 'current_location', + 'activities', 'interests', 'is_app_user', + 'music', 'tv', 'movies', + 'books', 'quotes', 'about_me', + 'hs_info', 'education_history', 'work_history', + 'notes_count', 'wall_count', 'status', + 'has_added_app', 'online_presence', 'locale', + 'proxied_email', 'profile_url', 'email_hashes', + 'pic_small_with_logo', 'pic_big_with_logo', 'pic_square_with_logo', + 'pic_with_logo', 'allowed_restrictions', 'verified', + 'profile_blurb', 'family', 'website', + 'is_blocked', 'contact_email', 'email', + 'third_party_id', 'name_format', 'video_upload_limits', + 'games', 'is_minor', 'work', + 'education', 'sports', 'favorite_athletes', + 'favorite_teams', 'inspirational_people', 'languages', + 'likes_count', 'friend_count', 'mutual_friend_count', + 'can_post'), + 'video' => array( + 'vid', 'owner', 'album_id', + 'title', 'description', 'link', + 'thumbnail_link', 'embed_html', 'updated_time', + 'created_time', 'length', 'src', + 'src_hq'), + 'video_tag' => array('vid', 'subject', 'updated_time', 'created_time')); \ No newline at end of file diff --git a/library/eden/yahoo/error.php b/library/eden/yahoo/error.php new file mode 100644 index 0000000..e506e77 --- /dev/null +++ b/library/eden/yahoo/error.php @@ -0,0 +1,40 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Yahoo Errors + * + * @package Eden + * @category facebook + * @author Christian Blanquera cblanquera@openovate.com + */ +class Eden_Yahoo_Error extends Eden_Error { + /* Constants + -------------------------------*/ + const AUTHENTICATION_FAILED = 'Application authentication failed. Yahoo returned %s: %s'; + const GRAPH_FAILED = 'Call to graph.facebook.com failed. Yahoo returned %s: %s'; + const REQUIRES_AUTH = 'Call to %s requires authentication. Please set token first or set argument 4 in setObject() to false.'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + /* Magic + -------------------------------*/ + /* Public Methods + -------------------------------*/ + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/yahoo/oauth.php b/library/eden/yahoo/oauth.php new file mode 100644 index 0000000..daa18a3 --- /dev/null +++ b/library/eden/yahoo/oauth.php @@ -0,0 +1,188 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Abstractly defines a layout of available methods to + * connect to and query a database. This class also lays out + * query building methods that auto renders a valid query + * the specific database will understand without actually + * needing to know the query language. + * + * @package Eden + * @category sql + * @author Christian Blanquera cblanquera@openovate.com + */ +class Eden_Yahoo_Oauth extends Eden_Class { + /* Constants + -------------------------------*/ + const TOKEN_URL = 'https://api.login.yahoo.com/oauth/v2/get_request_token'; + const CONSUMER_KEY_URL = 'http://developer.apps.yahoo.com/projects/createconsumerkey'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_secret = NULL; + protected $_params = array(); + protected $_scopes = array(); + protected $_debug = true; + + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + /* Public Methods + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + public function __construct($key, $secret) { + $this->_params['oauth_consumer_key'] = $key; + $this->_secret = $secret; + } + + public function setAppid($appId) { + $this->_params['appid'] = $appId; + return $this; + } + + public function setName($name) { + $this->_params['name'] = $name; + return $this; + } + + public function setDescription($description) { + $this->_params['description'] = $description; + return $this; + } + + public function setFavicon($favicon) { + $this->_params['favicon'] = $favicon; + return $this; + } + + public function setThirdParty($thirdParty) { + $this->_params['third_party'] = $thirdParty; + return $this; + } + + public function returnUrl($url) { + $this->_params['return_to'] = $url; + return $this; + } + + public function addScope($scope) { + $this->_scopes[] = $scope; + return $this; + } + + public function setAppUrl($url) { + $this->_params['application_url'] = $url; + return $this; + } + + public function setDebug($debug = true) { + $this->_debug = $debug; + return $this; + } + + public function setDomain($domain) { + $this->_params['domain'] = $domain; + return $this; + } + + public function setTimestamp($timestamp = NULL) { + if(is_null($timestamp)) { + $this->_params['oauth_timestamp'] = time(); + } + + if(!is_numeric($timestamp)) { + $this->_params['oauth_timestamp'] = strtotime($timestamp); + } + + $this->_params['oauth_timestamp'] = $timestamp; + return $this; + } + + public function setSignatureMethod($method = 'PLAINTEXT') { + $this->_params['oauth_signature_method'] = $method; + return $this; + } + + public function setCallBack($callback) { + $this->_params['oauth_callback'] = $callback; + return $this; + } + + public function getToken() { + $this->_params['oauth_signature_method'] = ($this->_params['oauth_signature_method']) ? $this->_params['oauth_signature_method'] : 'PLAINTEXT'; + $this->_params['oauth_version'] = '1.0'; + $this->_params['xoauth_lang_pref'] = 'en-us'; + $this->_params['oauth_nonce'] = md5($this->_params['oauth_timestamp']); + $this->_params['oauth_signature'] = $this->_setSignature(); + + $query = http_build_query($this->_params); + + $headers = array(); + $headers[] = 'Content-Type: application/x-www-form-urlencoded'; + + $curl = Eden_Curl::i() + ->verifyHost(false) + ->verifyPeer(false) + ->setUrl(self::TOKEN_URL) + ->setPost(true) + ->setPostFields($query) + ->setHeaders($headers); + + //get the response + $response = $curl->getResponse(); + + return $response; + } + + public function getConsumerKey() { + $this->_params['scopes'] = implode(', ', $this->_scopes); + $url = ($this->_debug) ? self::CONSUMER_KEY_URL.'?debug=true' : self::CONSUMER_KEY_URL; + unset($this->_params['oauth_consumer_key']); + front()->output($this->_params); exit; + $params = http_build_query($this->_params); + + $headers = array(); + $headers[] = 'Content-Type: application/x-www-form-urlencoded'; + + $curl = Eden_Curl::i() + ->verifyHost(false) + ->verifyPeer(false) + ->setUrl($url) + ->setPost(true) + ->setPostFields($params) + ->setHeaders($headers); + + //get the response + $response = $curl->getResponse(); + return $response; + } + + /* Protected Methods + -------------------------------*/ + protected function _setSignature() { + $signature = 'POST&'.urlencode(self::TOKEN_URL).'&'; + $signature .= http_build_query($this->_params); + + if($this->_params['oauth_signature_method'] == 'HMAC-SHA1') { + $signature = hash_hmac("sha1", $signature, $this->_params['oauth_consumer_key'], TRUE); + } + + return $signature; + } + + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/yahoo/search.php b/library/eden/yahoo/search.php new file mode 100644 index 0000000..d76a175 --- /dev/null +++ b/library/eden/yahoo/search.php @@ -0,0 +1,360 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Facebook Search + * + * @package Eden + * @category sql + * @author Christian Blanquera cblanquera@openovate.com + */ +class Eden_Facebook_Search extends Eden_Class { + /* Constants + -------------------------------*/ + const ASC = 'ASC'; + const DESC = 'DESC'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_database = NULL; + protected $_table = NULL; + protected $_columns = array(); + protected $_filter = array(); + protected $_sort = array(); + protected $_start = 0; + protected $_range = 0; + + protected $_group = array(); + + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + public function __construct(Eden_Yahoo_Fql $database) { + $this->_database = $database; + } + + public function __call($name, $args) { + if(strpos($name, 'filterBy') === 0) { + //filterByUserName('Chris', '-') + $separator = '_'; + if(isset($args[1]) && is_scalar($args[1])) { + $separator = (string) $args[1]; + } + + $key = Eden_Type_String::i($name) + ->substr(8) + ->preg_replace("/([A-Z])/", $separator."$1") + ->substr(strlen($separator)) + ->strtolower() + ->get(); + + if(!isset($args[0])) { + $args[0] = NULL; + } + + $key = $key.'=%s'; + + $this->addFilter($key, $args[0]); + + return $this; + } + + if(strpos($name, 'sortBy') === 0) { + //filterByUserName('Chris', '-') + $separator = '_'; + if(isset($args[1]) && is_scalar($args[1])) { + $separator = (string) $args[1]; + } + + $key = Eden_Type_String::i($name) + ->substr(6) + ->preg_replace("/([A-Z])/", $separator."$1") + ->substr(strlen($separator)) + ->strtolower() + ->get(); + + if(!isset($args[0])) { + $args[0] = self::ASC; + } + + $this->addSort($key, $args[0]); + + return $this; + } + + try { + return parent::__call($name, $args); + } catch(Eden_Error $e) { + Eden_Yahoo_Error::i($e->getMessage())->trigger(); + } + } + + /* Public Methods + -------------------------------*/ + /** + * Sets Columns + * + * @param string[,string..]|array + * @return this + */ + public function setColumns($columns) { + if(!is_array($columns)) { + $columns = func_get_args(); + } + + $this->_columns = $columns; + + return $this; + } + + /** + * Sets Table + * + * @param string + * @return this + */ + public function setTable($table) { + Eden_Yahoo_Error::i()->argument(1, 'string'); + $this->_table = $table; + return $this; + } + + /** + * Adds filter + * + * @param string + * @param string[,string..] + * @return this + */ + public function addFilter() { + Eden_Yahoo_Error::i()->argument(1, 'string'); + + $this->_filter[] = func_get_args(); + + return $this; + } + + /** + * Adds sort + * + * @param string + * @param string + * @return this + */ + public function addSort($column, $order = self::ASC) { + Eden_Yahoo_Error::i() + ->argument(1, 'string') + ->argument(2, 'string'); + + if($order != self::DESC) { + $order = self::ASC; + } + + $this->_sort[$column] = $order; + + return $this; + } + + /** + * Sets the pagination start + * + * @param int + * @return this + */ + public function setStart($start) { + Eden_Yahoo_Error::i()->argument(1, 'int'); + + if($start < 0) { + $start = 0; + } + + $this->_start = $start; + + return $this; + } + + /** + * Sets the pagination range + * + * @param int + * @return this + */ + public function setRange($range) { + Eden_Yahoo_Error::i()->argument(1, 'int'); + + if($range < 0) { + $range = 25; + } + + $this->_range = $range; + + return $this; + } + + /** + * Sets the pagination page + * + * @param int + * @return this + */ + public function setPage($page) { + Eden_Yahoo_Error::i()->argument(1, 'int'); + + if($page < 1) { + $page = 1; + } + + $this->_start = ($page - 1) * $this->_range; + + return $this; + } + + /** + * Stores this search and resets class. + * Useful for multiple queries. + * + * @param scalar + * @return this + */ + public function group($key) { + Eden_Yahoo_Error::i()->argument(1, 'scalar'); + if(is_null($this->_table)) { + return $this; + } + + $this->_group[$key] = array( + 'table' => $this->_table, + 'columns' => $this->_columns, + 'filter' => $this->_filter, + 'sort' => $this->_sort, + 'start' => $this->_start, + 'range' => $this->_range); + + $this->_table = NULL; + $this->_columns = array(); + $this->_filter = array(); + $this->_sort = array(); + $this->_start = 0; + $this->_range = 0; + + return $this; + } + + /** + * Returns the results in a collection + * + * @return Eden_Facebook_Collection + */ + public function getCollection($key = 'last') { + $rows = $this->getRows($key); + + if(count($this->_group) == 1) { + return Eden_Collection::i($rows); + } + + foreach($rows as $key => $collection) { + $rows[$key] = Eden_Collection::i($collection['fql_result_set']); + } + + return $rows; + } + + /** + * Returns the array rows + * + * @return array + */ + public function getRows($key = 'last') { + $this->group($key); + + if(empty($this->_group)) { + return array(); + } + + $group = array(); + foreach($this->_group as $key => $query) { + $this->_table = $query['table']; + $this->_columns = $query['columns']; + $this->_filter = $query['filter']; + $this->_sort = $query['sort']; + $this->_start = $query['start']; + $this->_range = $query['range']; + + $query = $this->_getQuery(); + + if(!empty($this->_columns)) { + $query->select(implode(', ', $this->_columns)); + } + + foreach($this->_sort as $name => $value) { + $query->sortBy($name, $value); + } + + if($this->_range) { + $query->limit($this->_start, $this->_range); + } + + $group[$key] = $query; + } + + $query = $group; + + if(count($query) == 1) { + $query = $group[$key]; + } + + $results = $this->_database->query($query); + return $results; + } + + /** + * Returns the total results + * + * @return int + */ + public function getTotal() { + $query = $this->_getQuery()->select('COUNT(*) as total'); + + $rows = $this->_database->query($query); + + if(!isset($rows[0]['total'])) { + return 0; + } + + return $rows[0]['total']; + } + + /* Protected Methods + -------------------------------*/ + protected function _getQuery() { + $query = $this->_database->select()->from($this->_table); + + foreach($this->_filter as $i => $filter) { + //array('post_id=%s AND post_title IN %s', 123, array('asd')); + $where = array_shift($filter); + if(!empty($filter)) { + $where = vsprintf($where, $filter); + } + + $query->where($where); + } + + return $query; + } + + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/yahoo/select.php b/library/eden/yahoo/select.php new file mode 100644 index 0000000..4c70289 --- /dev/null +++ b/library/eden/yahoo/select.php @@ -0,0 +1,173 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Generates select query string syntax + * + * @package Eden + * @category sql + * @author Christian Blanquera cblanquera@openovate.com + */ +class Eden_Yahoo_Select extends Eden_Class { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_select = NULL; + protected $_from = NULL; + protected $_where = array(); + protected $_sortBy = array(); + protected $_page = NULL; + protected $_length = NULL; + + protected static $_columns = array(); + + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + public function __construct() { + self::$_columns = include(dirname(__FILE__).'/columns.php'); + } + + public function __toString() { + return $this->getQuery(); + } + + /* Public Methods + -------------------------------*/ + /** + * Select clause + * + * @param string select + * @return this + * @notes loads select phrase into registry + */ + public function select($select = '*') { + //Argument 1 must be a string or array + Eden_Yahoo_Error::i()->argument(1, 'string', 'array'); + + //if select is an array + if(is_array($select)) { + //transform into a string + $select = implode(', ', $select); + } + + $this->_select = $select; + return $this; + } + + /** + * From clause + * + * @param string from + * @return this + * @notes loads from phrase into registry + */ + public function from($from) { + //Argument 1 must be a string + Eden_Yahoo_Error::i()->argument(1, 'string'); + + $this->_from = $from; + return $this; + } + + /** + * Where clause + * + * @param array|string where + * @return this + * @notes loads a where phrase into registry + */ + public function where($where) { + //Argument 1 must be a string or array + Eden_Yahoo_Error::i()->argument(1, 'string', 'array'); + + if(is_string($where)) { + $where = array($where); + } + + $this->_where = array_merge($this->_where, $where); + + return $this; + } + + /** + * Order by clause + * + * @param string field + * @param string order + * @return this + * @notes loads field and order into registry + */ + public function sortBy($field, $order = 'ASC') { + //argument test + Eden_Yahoo_Error::i() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'string'); //Argument 2 must be a string + + $this->_sortBy[] = $field . ' ' . $order; + + return $this; + } + + /** + * Limit clause + * + * @param string|int page + * @param string|int length + * @return this + * @notes loads page and length into registry + */ + public function limit($page, $length) { + //argument test + Eden_Yahoo_Error::i() + ->argument(1, 'numeric') //Argument 1 must be a number + ->argument(2, 'numeric'); //Argument 2 must be a number + + $this->_page = $page; + $this->_length = $length; + + return $this; + } + + /** + * Returns the string version of the query + * + * @param bool + * @return string + * @notes returns the query based on the registry + */ + public function getQuery() { + $where = empty($this->_where) ? '' : 'WHERE '.implode(' AND ', $this->_where); + $sort = empty($this->_sortBy) ? '' : 'ORDER BY '.implode(', ', $this->_sortBy); + $limit = is_null($this->_page) ? '' : 'LIMIT ' . $this->_page .',' .$this->_length; + //if(empty($this->_select) || $this->_select == '*') { + //$this->_select = implode(', ', $this->_select); + //} + + $query = sprintf( + 'SELECT %s FROM %s %s %s %s;', + $this->_select, $this->_from, + $where, $sort, $limit); + + return str_replace(' ', ' ', $query); + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/yahoo/yql.php b/library/eden/yahoo/yql.php new file mode 100644 index 0000000..0ad4922 --- /dev/null +++ b/library/eden/yahoo/yql.php @@ -0,0 +1,341 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Abstractly defines a layout of available methods to + * connect to and query a database. This class also lays out + * query building methods that auto renders a valid query + * the specific database will understand without actually + * needing to know the query language. + * + * @package Eden + * @category sql + * @author Christian Blanquera cblanquera@openovate.com + */ +class Eden_Yahoo_Yql extends Eden_Class { + /* Constants + -------------------------------*/ + const SELECT = 'Eden_Yahoo_Select'; + const YQL_URL = 'http://query.yahooapis.com/v1/public/yql'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_queries = array(); + protected $_token = NULL; + + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + public function __construct() { + //$this->_token = $token; + } + + /* Public Methods + -------------------------------*/ + /** + * Returns the select query builder + * + * @return Eden_Yahoo_Select + */ + public function select($select = '*') { + //Argument 1 must be a string or array + Eden_Yahoo_Error::i()->argument(1, 'string', 'array'); + + return Eden_Yahoo_Select::i()->select($select); + } + + /** + * Returns search + * + * @return Eden_Facebook_Search + */ + public function search() { + return Eden_Yahoo_Search::i($this); + } + + /** + * Returns a 1 row result given the column name and the value + * + * @param string table + * @param string name + * @param string value + * @return array + */ + public function getRow($table, $name, $value) { + //argument test + Eden_Yahoo_Error::i() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'string') //Argument 2 must be a string + ->argument(3, 'string', 'numeric'); //Argument 3 must be a string or number + + $query = $this->select() + ->from($table) + ->where($name.' = '.$value) + ->limit(0, 1); + + $results = $this->query($query); + + return isset($results[0]) ? $results[0] : NULL; + } + + /** + * Returns a list of results given the query parameters + * + * @param string table + * @param array filter + * @param array sort + * @param int start + * @param int range + * @return array + */ + public function getRows($table, $filters = NULL, array $sort = array(), $start = 0, $range = 0, $index = NULL) { + //argument test + Eden_Yahoo_Error::i() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'string', 'array', 'null') //Argument 3 must be a string number or null + ->argument(4, 'numeric') //Argument 5 must be a number + ->argument(5, 'numeric') //Argument 6 must be a number + ->argument(6, 'numeric', 'null'); //Argument 7 must be a number or null + + $query = $this->select()->from($table); + + if(is_array($filters)) { + foreach($filters as $i => $filter) { + if(!is_array($filter)) { + continue; + } + + //array('post_id=%s AND post_title IN %s', 123, array('asd')); + $format = array_shift($filter); + $filters[$i] = vsprintf($format, $filter); + } + } + + if(!is_null($filters)) { + $query->where($filters); + } + + if(!empty($sort)) { + foreach($sort as $key => $value) { + if(is_string($key) && trim($key)) { + $query->sortBy($key, $value); + } + } + } + + if($range) { + $query->limit($start, $range); + } + + $results = $this->query($query); + + if(!is_null($index)) { + if(empty($results)) { + $results = NULL; + } else { + if($index == self::FIRST) { + $index = 0; + } + + if($index == self::LAST) { + $index = count($results)-1; + } + + if(isset($results[$index])) { + $results = $results[$index]; + } else { + $results = NULL; + } + } + } + + return $results; + } + + /** + * Returns the number of results given the query parameters + * + * @param string table + * @param array filter + * @return int | false + */ + public function getRowsCount($table, $filters = NULL) { + //argument test + Eden_Yahoo_Error::i() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'string', 'array', 'null'); //Argument 3 must be a string number or null + + $query = $this->select('COUNT(*) as count')->from($table); + + if(is_array($filters)) { + foreach($filters as $i => $filter) { + if(!is_array($filter)) { + continue; + } + + $format = array_shift($filter); + $filters[$i] = vsprintf($format, $filter); + } + } + + if(!is_null($filters)) { + $query->where($filters); + } + + $results = $this->query($query); + + if(isset($results[0]['count'])) { + return $results[0]['count']; + } + + return false; + } + + /** + * Returns a model given the column name and the value + * + * @param string table + * @param string name + * @param string value + * @return array|NULL + */ + public function getModel($table, $name, $value) { + //argument test + Eden_Yahoo_Error::i() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'string') //Argument 2 must be a string + ->argument(3, 'string', 'numeric'); //Argument 3 must be a string or number + + $result = $this->getRow($table, $name, $value); + + $model = Eden_Model::i(); + + if(is_null($result)) { + return $model; + } + + return $model->set($result); + } + + /** + * Returns a collection given the query parameters + * + * @param string table + * @param array filter + * @param array sort + * @param int start + * @param int range + * @return array + */ + public function getCollection($table, $filters = NULL, array $sort = array(), $start = 0, $range = 0, $index = NULL) { + //argument test + Eden_Yahoo_Error::i() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'string', 'array', 'null') //Argument 3 must be a string number or null + ->argument(4, 'numeric') //Argument 5 must be a number + ->argument(5, 'numeric') //Argument 6 must be a number + ->argument(6, 'numeric', 'null'); //Argument 7 must be a number or null + + $results = $this->getRows($table, $filters, $sort, $start, $range, $index); + + $collection = Eden_Collection::i(); + + if(is_null($results)) { + return $collection; + } + + if(!is_null($index)) { + return $this->model($results); + } + + return $collection->set($results); + } + + /** + * Queries the database + * + * @param string query + * @return array|object + */ + public function query($query) { + //Argument 1 must be a string or null + Eden_Yahoo_Error::i()->argument(1, 'string', 'array', self::SELECT); + + if(!is_array($query)) { + $query = array('q' => (string) $query); + } else { + foreach($query as $key => $select) { + $query[$key] = (string) $select; + } + + $query = array('q' => json_encode($query)); + } + + $query['access_token'] = $this->_token; + $url = str_replace('+', '%20', self::YQL_URL.'?'.http_build_query($query + array('format' => 'json'))); + + $results = Eden_Curl::i() + ->setUrl($url) + ->setConnectTimeout(10) + ->setFollowLocation(true) + ->setTimeout(60) + ->verifyPeer(false) + ->setUserAgent(Eden_Facebook_Auth::USER_AGENT) + ->setHeaders('Expect') + ->getJsonResponse(); + + $this->_queries[] = array( + 'query' => $query['q'], + 'results' => $results); + + if(isset($results['error']['message'])) { + Eden_Facebook_Error::i($query['q'].$results['error']['message'])->trigger(); + } + + return $results; + } + + + /** + * Returns the history of queries made still in memory + * + * @return array the queries + */ + public function getQueries($index = NULL) { + if(is_null($index)) { + return $this->_queries; + } + + if($index == self::FIRST) { + $index = 0; + } + + if($index == self::LAST) { + $index = count($this->_queries) - 1; + } + + if(isset($this->_queries[$index])) { + return $this->_queries[$index]; + } + + return NULL; + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/zappos.php b/library/eden/zappos.php new file mode 100644 index 0000000..c5b96c2 --- /dev/null +++ b/library/eden/zappos.php @@ -0,0 +1,146 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +require_once dirname(__FILE__).'/oauth.php'; +require_once dirname(__FILE__).'/zappos/base.php'; +require_once dirname(__FILE__).'/zappos/error.php'; +require_once dirname(__FILE__).'/zappos/autocomplete.php'; +require_once dirname(__FILE__).'/zappos/brand.php'; +require_once dirname(__FILE__).'/zappos/image.php'; +require_once dirname(__FILE__).'/zappos/product.php'; +require_once dirname(__FILE__).'/zappos/review.php'; +require_once dirname(__FILE__).'/zappos/search.php'; +require_once dirname(__FILE__).'/zappos/similarity.php'; +require_once dirname(__FILE__).'/zappos/statistics.php'; +require_once dirname(__FILE__).'/zappos/values.php'; + +/** + * Zappos API factory. This is a factory class with + * methods that will load up different Zappos classes. + * Xend classes are organized as described on their + * developer site: search, image, product, statistics + * brand, review, core values, autocomplete and similarity. + * + * @package Eden + * @category Zappos + * @author Christian Symon M. Buenavista sbuenavista@openovate.com + */ +class Eden_Zappos extends Eden_Class { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getSingleton(__CLASS__); + } + + /* Public Methods + -------------------------------*/ + + /** + * Returns Zappos Auto complete + * + * @param *string api key + * @return Eden_Zappos_AutoComplete + */ + public function autocomplete($apiKey) { + return Eden_Zappos_AutoComplete::i($apiKey); + } + + /** + * Returns Zappos brand + * + * @param *string api key + * @return Eden_Zappos_Brand + */ + public function brand($apiKey) { + return Eden_Zappos_Brand::i($apiKey); + } + + /** + * Returns Zappos core values + * + * @param *string api key + * @return Eden_Zappos_AutoComplete + */ + public function values($apiKey) { + return Eden_Zappos_Values::i($apiKey); + } + + /** + * Returns Zappos images + * + * @param *string api key + * @return Eden_Zappos_Search + */ + public function image($apiKey) { + return Eden_Zappos_Image::i($apiKey); + } + + /** + * Returns Zappos products + * + * @param *string api key + * @return Eden_Zappos_Product + */ + public function product($apiKey) { + return Eden_Zappos_Product::i($apiKey); + } + + /** + * Returns Zappos review + * + * @param *string api key + * @return Eden_Zappos_Review + */ + public function review($apiKey) { + return Eden_Zappos_Review::i($apiKey); + } + + /** + * Returns Zappos search results + * + * @param *string api key + * @return Eden_Zappos_Search + */ + public function search($apiKey) { + return Eden_Zappos_Search::i($apiKey); + } + + /** + * Returns Zappos similarity + * + * @param *string api key + * @return Eden_Zappos_Similarity + */ + public function similarity($apiKey) { + return Eden_Zappos_Similarity::i($apiKey); + } + + /** + * Returns Zappos statistics + * + * @param *string api key + * @return Eden_Zappos_Statistics + */ + public function statistics($apiKey) { + return Eden_Zappos_Statistics::i($apiKey); + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} diff --git a/library/eden/zappos/autocomplete.php b/library/eden/zappos/autocomplete.php new file mode 100644 index 0000000..7643f9f --- /dev/null +++ b/library/eden/zappos/autocomplete.php @@ -0,0 +1,65 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Zappos review + * + * @package Eden + * @category review + * @author Christian Symon M. Buenavista sbuenavista@openovate.com + */ +class Eden_Zappos_AutoComplete extends Eden_Zappos_Base { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_term = NULL; + + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + /* Public Methods + -------------------------------*/ + /** + * set term + * + * @param string + * @return this + */ + public function setTerm($term) { + //Argument 1 must be a string + Eden_Zappos_Error::i()->argument(1, 'string'); + + $this->_term = $term; + return $this; + } + + /** + * Search Brand + * + * @return this + */ + public function getResponse() { + //populate fields + $query = array(self::TERM => $this->_term); + + return $this->_getResponse(self::URL_REVIEW, $query); + } + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/zappos/base.php b/library/eden/zappos/base.php new file mode 100644 index 0000000..96f8a9b --- /dev/null +++ b/library/eden/zappos/base.php @@ -0,0 +1,108 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Zappos base + * + * @package Eden + * @category zappos + * @author Christian Blanquera cblanquera@openovate.com + */ +class Eden_Zappos_Base extends Eden_Oauth_Base { + /* Constants + -------------------------------*/ + const URL_SEARCH = 'http://api.zappos.com/Search'; + const URL_IMAGE = 'http://api.zappos.com/Image'; + const URL_PRODUCT = 'http://api.zappos.com/Product'; + const URL_STATISTICS = 'http://api.zappos.com/Statistics'; + const URL_BRAND = 'http://api.zappos.com/Brand/'; + const URL_REVIEW = 'http://api.zappos.com/Review'; + const URL_AUTOCOMPLETE = 'http://api.zappos.com/AutoComplete'; + const URL_VALUE = 'http://api.zappos.com/CoreValue/'; + const URL_SIMILARITY = 'http://api.zappos.com/Search/Similarity'; + + const KEY = 'key'; + const TERM = 'term'; + const PRODUCT_ID = 'productId'; + const INCLUDES = 'includes'; + const PAGE = 'page'; + const LIMITS = 'limit'; + const STYLE_ID = 'styleId'; + const TYPE = 'type'; + const FILTER = 'filters'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_apiKey = NULL; + + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + /* Magic + -------------------------------*/ + public function __construct($apiKey) { + //Argument 1 must be a string + Eden_Zappos_Error::i()->argument(1, 'string'); + + $this->_apiKey = $apiKey; + } + + /* Public Methods + -------------------------------*/ + /* Protected Methods + -------------------------------*/ + protected function _getResponse($method, array $query = array()) { + //Argument 1 must be a string + Eden_Zappos_Error::i()->argument(1, 'string'); + + //Our request parameters + $default = array(self::KEY => $this->_apiKey); + + //generate URL-encoded query string to build our NVP string + $query = http_build_query($query + $default); + + $curl = Eden_Curl::i() + ->setUrl($method.'?'.$query) + ->setReturnTransfer(TRUE) + ->setHeader(false); + + $results = $curl->getQueryResponse(); + + foreach($results as $key => $value) { + + if(!is_array($value)) { + return $value; + } + + if(!empty($value) && isset($value)) { + + foreach($value as $k => $v) { + + $response = json_decode($k.']}', false); + + if(empty($response)) { + $response = json_decode($k, false); + } + + break; + } + } else { + + return $key; + } + } + return $response; + } + + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/zappos/brand.php b/library/eden/zappos/brand.php new file mode 100644 index 0000000..f3d5ba0 --- /dev/null +++ b/library/eden/zappos/brand.php @@ -0,0 +1,64 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Zappos brand + * + * @package Eden + * @category brand + * @author Christian Symon M. Buenavista sbuenavista@openovate.com + */ +class Eden_Zappos_Brand extends Eden_Zappos_Base { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_brandId = NULL; + + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + /* Public Methods + -------------------------------*/ + /** + * set brand id + * + * @param string|int + * @return this + */ + public function setBrandId($brandId) { + //Argument 1 must be a string or int + Eden_Zappos_Error::i()->argument(1, 'string', 'int'); + + $this->_brandId = $brandId; + return $this; + } + + /** + * Search Brand + * + * @return this + */ + public function getResponse() { + + return $this->_getResponse(self::URL_BRAND.$this->_brandId); + + } + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/zappos/error.php b/library/eden/zappos/error.php new file mode 100644 index 0000000..0ec60af --- /dev/null +++ b/library/eden/zappos/error.php @@ -0,0 +1,39 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Zappos error + * + * @package Eden + * @category Zappos + * @author Christian Blanquera cblanquera@openovate.com + */ +class Eden_Zappos_Error extends Eden_Error { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i($message = NULL, $code = 0) { + $class = __CLASS__; + return new $class($message, $code); + } + + /* Public Methods + -------------------------------*/ + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/zappos/image.php b/library/eden/zappos/image.php new file mode 100644 index 0000000..e01f7d4 --- /dev/null +++ b/library/eden/zappos/image.php @@ -0,0 +1,185 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Zappos Image + * + * @package Eden + * @category image + * @author Christian Symon M. Buenavista sbuenavista@openovate.com + */ +class Eden_Zappos_Image extends Eden_Zappos_Base { + /* Constants + -------------------------------*/ + const RECIPE = 'recipe'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_productId = NULL; + protected $_styleId = NULL; + protected $_include = NULL; + protected $_imageType = NULL; + + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + /* Public Methods + -------------------------------*/ + /** + * Set product id + * + * @param string|int + * @return this + */ + public function setProductId($productId) { + //Argument 1 must be a string or integer + Eden_Zappos_Error::i()->argument(1, 'string', 'int'); + + $this->_productId = $productId; + return $this; + } + + /** + * Set style id + * + * @param string|int + * @return this + */ + public function setStyleId($styleId) { + //Argument 1 must be a string or integer + Eden_Zappos_Error::i()->argument(1, 'string', 'int'); + + $this->_styleId = '["'.$styleId.'"]'; + return $this; + } + + /** + * Include color id in reusult + * + * @return this + */ + public function includeColorId() { + + $this->_include = '["colorId"]'; + return $this; + } + + /** + * Include width in reusult + * + * @return this + */ + public function includeWidth() { + + $this->_include = '["width"]'; + return $this; + } + + /** + * Include height in reusult + * + * @return this + */ + public function includeHeight() { + + $this->_include = '["height"]'; + return $this; + } + + /** + * Include upload date in reusult + * + * @return this + */ + public function includeUploadDate() { + + $this->_include = '["uploadDate"]'; + return $this; + } + + /** + * Include resolution id in reusult + * + * @return this + */ + public function includeResolution() { + + $this->_include = '["isHighResolution"]'; + return $this; + } + + /** + * Include title in reusult + * + * @return this + */ + public function includeTitle() { + + $this->_include = '["title"]'; + return $this; + } + + /** + * Set image type. An image Type is a particular angle shot + * of an item. e.g. PAIR, LEFT, RIGHT, TOP and etc. + * + * @param string + * @return this + */ + public function setImageType($imageType) { + //Argument 1 must be a string + Eden_Zappos_Error::i()->argument(1, 'string'); + + $this->_imageType = '["'.$imageType.'"]'; + return $this; + } + + /** + * Set sizing transformation for an image + * + * @param string + * @return this + */ + public function setImageRecipe($imageRecipe) { + //Argument 1 must be a string + Eden_Zappos_Error::i()->argument(1, 'string'); + + $this->_imageRecipe = '["'.$imageRecipe.'"]'; + return $this; + } + + /** + * Search Image + * + * @return this + */ + public function getResponse() { + //populate fields + $query = array( + self::PRODUCT_ID => $this->_productId, + self::STYLE_ID => $this->_styleId, + self::INCLUDES => $this->_include, + self::TYPE => $this->_imageType, + self::RECIPE => $this->_imageRecipe); + + return $this->_getResponse(self::URL_IMAGE, $query); + + } + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/zappos/product.php b/library/eden/zappos/product.php new file mode 100644 index 0000000..07faa45 --- /dev/null +++ b/library/eden/zappos/product.php @@ -0,0 +1,131 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Zappos Product + * + * @package Eden + * @category product + * @author Christian Symon M. Buenavista sbuenavista@openovate.com + */ +class Eden_Zappos_Product extends Eden_Zappos_Base { + /* Constants + -------------------------------*/ + const SKU = 'id'; + const UPC = 'upc'; + const STOCK_ID = 'stockId'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_upc = NULL; + protected $_stockId = NULL; + protected $_sku = NULL; + protected $_style = NULL; + + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + /* Public Methods + -------------------------------*/ + /** + * Set SKU or product id + * + * @param string|int + * @return this + */ + public function setSKU($sku) { + //Argument 1 must be a string or integer + Eden_Zappos_Error::i()->argument(1, 'string', 'int'); + + $this->_sku = $sku; + return $this; + } + + /** + * Set UPC + * + * @param string|int + * @return this + */ + public function setUPC($upc) { + //Argument 1 must be a string or integer + Eden_Zappos_Error::i()->argument(1, 'string', 'int'); + + $this->_upc = $upc; + return $this; + } + + /** + * Set stock id + * + * @param string|int + * @return this + */ + public function setStockId($stockId) { + //Argument 1 must be a string or integer + Eden_Zappos_Error::i()->argument(1, 'string', 'int'); + + $this->_stockId = $stockId; + return $this; + } + + /** + * Include style in the results + * + * @param string|int + * @return this + */ + public function includeStyle() { + + $this->_style = '["styles"]'; + return $this; + } + + /** + * Include specific style in the results + * + * @param string + * @return this + */ + public function includeSpecific($style) { + //Argument 1 must be a string + Eden_Zappos_Error::i()->argument(1, 'string'); + + $this->_style = '["'.$style.'"]'; + return $this; + } + + /** + * Search Image + * + * @return this + */ + public function getResponse() { + //populate fields + $query = array( + self::SKU => $this->_sku, + self::INCLUDES => $this->_style, + self::UPC => $this->_upc, + self::STOCK_ID => $this->_stockId); + + return $this->_getResponse(self::URL_PRODUCT, $query); + + } + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/zappos/review.php b/library/eden/zappos/review.php new file mode 100644 index 0000000..ac2c87b --- /dev/null +++ b/library/eden/zappos/review.php @@ -0,0 +1,117 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Zappos review + * + * @package Eden + * @category review + * @author Christian Symon M. Buenavista sbuenavista@openovate.com + */ +class Eden_Zappos_Review extends Eden_Zappos_Base { + /* Constants + -------------------------------*/ + const START_ID = 'startId'; + const START_DATE = 'startDate'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_productId = NULL; + protected $_page = NULL; + protected $_startId = NULL; + protected $_startDate = NULL; + + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + /* Public Methods + -------------------------------*/ + /** + * set product id + * + * @param string|int + * @return this + */ + public function setProductId($productId) { + //Argument 1 must be a string or int + Eden_Zappos_Error::i()->argument(1, 'string', 'int'); + + $this->_productId = $productId; + return $this; + } + + /** + * set page + * + * @param string|int + * @return this + */ + public function setPage($page) { + //Argument 1 must be a string or int + Eden_Zappos_Error::i()->argument(1, 'string', 'int'); + + $this->_page = $page; + return $this; + } + + /** + * set start id + * + * @param string|int + * @return this + */ + public function setStartId($startId) { + //Argument 1 must be a string or int + Eden_Zappos_Error::i()->argument(1, 'string', 'int'); + + $this->_startId = $startId; + return $this; + } + + /** + * set start Date + * + * @param string|int + * @return this + */ + public function setStartDate($startDate) { + //Argument 1 must be a string or int + Eden_Zappos_Error::i()->argument(1, 'string', 'int'); + + $this->_startDate = $startDate; + return $this; + } + + /** + * Search Brand + * + * @return this + */ + public function getResponse() { + //populate fields + $query = array( + self::PRODUCT_ID => $this->_productId, + self::PAGE => $this->_page, + self::START_ID => $this->_startId, + self::START_DATE => $this->_startDate); + + return $this->_getResponse(self::URL_REVIEW, $query); + } + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/zappos/search.php b/library/eden/zappos/search.php new file mode 100644 index 0000000..9f894e1 --- /dev/null +++ b/library/eden/zappos/search.php @@ -0,0 +1,343 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Zappos Search + * + * @package Eden + * @category search + * @author Christian Symon M. Buenavista sbuenavista@openovate.com + */ +class Eden_Zappos_Search extends Eden_Zappos_Base { + /* Constants + -------------------------------*/ + const ITEMS = 'list'; + const SORT = 'sort'; + const EXCLUDE = 'excludes'; + const EXPRESSION = 'filterExpression'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_terms = NULL; + protected $_limits = NULL; + protected $_list = NULL; + protected $_sort = NULL; + protected $_exclude = NULL; + protected $_page = NULL; + protected $_include = NULL; + protected $_expression = NULL; + protected $_filter = NULL; + protected $_order = 'desc'; + + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + /* Public Methods + -------------------------------*/ + /** + * Set search terms + * + * @param string + * @return this + */ + public function setTerms($terms) { + //Argument 1 must be a string + Eden_Zappos_Error::i()->argument(1, 'string'); + + $this->_terms = $terms; + return $this; + } + + /** + * Set limits in the search query + * + * @param string|int + * @return this + */ + public function setLimits($limits) { + //Argument 1 must be a string or integer + Eden_Zappos_Error::i()->argument(1, 'string', 'int'); + + $this->_limits = $limits; + return $this; + } + + /** + * Set face fields list. + * SetTerms and setList + * cannot call at the same time + * + * @return this + */ + public function setList() { + + $this->_list = 'facetFields'; + return $this; + } + + /** + * Sort result to ascending order + * by default in is set to descending + * + * @return this + */ + public function ascendingOrder() { + + $this->_order = 'asc'; + return $this; + } + + /** + * Sort results by price + * + * @return this + */ + public function sortByPrice(){ + + $this->_sort = '{"price":"'.$this->_order.'"}'; + return $this; + } + + /** + * Sort results by live date + * + * @return this + */ + public function sortGoLiveDate(){ + + $this->_sort = '{"goLiveDate":".'.$this->_order.'."}'; + return $this; + } + + /** + * Sort results by product populariry + * + * @return this + */ + public function sortByPopularity (){ + + $this->_sort = '{"productPopularity":"'.$this->_order.'"}'; + return $this; + } + + /** + * Sort results by recent sale + * + * @return this + */ + public function sortByRecentSale() { + + $this->_sort = '{"recentSales":"'.$this->_order.'"}'; + return $this; + } + + public function sortByBrandNameFacet() { + + $this->_post = '{"brandNameFacet":"'.$this->_order.'"}'; + return $this; + } + + /** + * Exclude results by style Id + * + * @return this + */ + public function excludeByStyleId() { + + $this->_exclude = '["results","styleId"]'; + return $this; + } + + /** + * Exclude results by price + * + * @return this + */ + public function excludeByPrice() { + + $this->_exclude = '["results","price"]'; + return $this; + } + + /** + * Exclude results by original price + * + * @return this + */ + public function excludeOriginalPrice() { + + $this->_exclude = '["results","originalPrice"]'; + return $this; + } + + /** + * Exclude results by product url + * + * @return this + */ + public function excludeProductUrl() { + + $this->_exclude = '["results","productUrl"]'; + return $this; + } + + /** + * Exclude results by color id + * + * @return this + */ + public function excludeColorId() { + + $this->_exclude = '["results","colorId"]'; + return $this; + } + + /** + * Exclude results by product name + * + * @return this + */ + public function excludeProductName() { + + $this->_exclude = '["results","productName"]'; + return $this; + } + + /** + * Exclude results by brand name + * + * @return this + */ + public function excludeBrandName() { + + $this->_exclude = '["results","brandName"]'; + return $this; + } + + /** + * Exclude results by image url + * + * @return this + */ + public function excludeImageUrl() { + + $this->_exclude = '["results","thumbnailImageUrl"]'; + return $this; + } + + /** + * Exclude results by percent off + * + * @return this + */ + public function excludePercentOff() { + + $this->_exclude = '["results","percentOff"]'; + return $this; + } + + /** + * Exclude results by product id + * + * @return this + */ + public function excludeProductId() { + + $this->_exclude = '["results","percentOff"]'; + return $this; + } + + /** + * include facet in resuts + * + * @return this + */ + public function includeFacets() { + $this->_include = '["facets"]'; + return $this; + } + + /** + * Set page number + * + * @param string|int + * @return this + */ + public function setPage($page) { + //Argument 1 must be a string or integer + Eden_Zappos_Error::i()->argument(1, 'string', 'int'); + + $this->_page = $page; + return $this; + } + + /** + * filter results with specific expression + * + * @param string + * @return this + */ + public function filterExpression($expression) { + //Argument 1 must be a string + Eden_Zappos_Error::i()->argument(1, 'string'); + + $this->_expression = $expression; + return $this; + } + + /** + * filter results with distinct expression + * + * @param string + * @param string + * @return this + */ + public function filterProduct($facetFields, $facetValue) { + + Eden_Zappos_Error::i() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'string'); //Argument 2 must be a string + + $this->_filter = '{".'.$facetFields.'.":[".'.$facetValue.'."]}'; + return $this; + } + + /** + * search zappos products + * + * @return array + */ + public function search() { + //populate fields + $query = array( + self::TERM => $this->_terms, + self::LIMIT => $this->_limits, + self::ITEMS => $this->_list, + self::SORT => $this->_sort, + self::EXCLUDES => $this->_exclude, + self::PAGE => $this->_page, + self::INCLUDES => $this->_include, + self::EXPRESSION => $this->_expression, + self::FILTER => $this->_filter); + + return $this->_getResponse(self::URL_SEARCH, $query); + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/zappos/similarity.php b/library/eden/zappos/similarity.php new file mode 100644 index 0000000..ffd05d3 --- /dev/null +++ b/library/eden/zappos/similarity.php @@ -0,0 +1,116 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Zappos similarity + * + * @package Eden + * @category similarity + * @author Christian Symon M. Buenavista sbuenavista@openovate.com + */ +class Eden_Zappos_Similarity extends Eden_Zappos_Base { + /* Constants + -------------------------------*/ + const EMPHASIS = 'emphasis'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_type = NULL; + protected $_limits = NULL; + protected $_styleId = NULL; + protected $_emphasis = NULL; + + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + /* Public Methods + -------------------------------*/ + /** + * set similarity to visual search + * + * @return this + */ + public function setToVisualSearch() { + + $this->_type = 'visualSearch'; + return $this; + } + + /** + * set similarity to more like this + * + * @return this + */ + public function setToMoreLikeThis() { + + $this->_type = 'moreLikeThis'; + return $this; + } + + /** + * set style id + * + * @return this + */ + public function setStyleId($styleId) { + + $this->_styleId = $styleId; + return $this; + } + + /** + * set limits it results + * + * @return this + */ + public function setLimits($limits) { + + $this->_limits = $limits; + return $this; + } + + /** + * set emphasis + * + * @return this + */ + public function setEmphasis($emphasis) { + + $this->_emphasis = $emphasis; + return $this; + } + + /** + * get zapppos core values + * + * @return this + */ + public function getResponse() { + //populate fields + $query = array( + self::TYPE => $this->_type, + self::LIMITS => $this->_limits, + self::STYLE_ID => $this->_styleId, + self::EMPHASIS => $this->_emphasis); + + return $this->_getResponse(self::URL_SIMILARITY, $query); + + } + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/zappos/statistics.php b/library/eden/zappos/statistics.php new file mode 100644 index 0000000..1bf6f8b --- /dev/null +++ b/library/eden/zappos/statistics.php @@ -0,0 +1,213 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Zappos statistics + * + * @package Eden + * @category statistics + * @author Christian Symon M. Buenavista sbuenavista@openovate.com + */ +class Eden_Zappos_Statistics extends Eden_Zappos_Base { + /* Constants + -------------------------------*/ + const LOCATION = 'location'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_statistics = NULL; + protected $_filter = NULL; + + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + /* Public Methods + -------------------------------*/ + /** + * Get statistics latest styles + * + * @param string + * @return this + */ + public function getLatestStyles() { + + $this->_statistics = 'latestStyles'; + return $this; + } + + /** + * Get statistics top styles + * + * @param string + * @return this + */ + public function getTopStyles() { + + $this->_statistics = 'topStyles '; + return $this; + } + + /** + * Filter by brand name + * + * @param string + * @return this + */ + public function filterByBrandName($brandName) { + //Argument 1 must be a string + Eden_Zappos_Error::i()->argument(1, 'string'); + + $this->_filter = '{"brand":{"name":"'.$brandName.'"}}'; + return $this; + } + + /** + * Filter by brand id + * + * @param string + * @return this + */ + public function filterByBrandId($brandId) { + //Argument 1 must be a string + Eden_Zappos_Error::i()->argument(1, 'string'); + + $this->_filter = '{"brand":{"id":"'.$brandid.'"}}'; + return $this; + } + + /** + * Filter by product type + * + * @param string + * @return this + */ + public function filterByProductType($productValue) { + //Argument 1 must be a string + Eden_Zappos_Error::i()->argument(1, 'string'); + + $this->_filter = '{"categorization":{"productType":"'.$productValue.'"}}'; + return $this; + } + + /** + * Filter by category type + * + * @param string + * @return this + */ + public function filterByCategoryType($productValue) { + //Argument 1 must be a string + Eden_Zappos_Error::i()->argument(1, 'string'); + + $this->_filter = '{"categorization":{"categoryType":"'.$productValue.'"}}'; + return $this; + } + + /** + * Filter by sub category type + * + * @param string + * @return this + */ + public function filterBySubCategoryType($productValue) { + //Argument 1 must be a string + Eden_Zappos_Error::i()->argument(1, 'string'); + + $this->_filter = '{"categorization":{"subcategoryType":"'.$productValue.'"}}'; + return $this; + } + + /** + * Filter male + * + * @return this + */ + public function filterByMale() { + + $this->_filter = '{"gender":"M"}'; + return $this; + } + + /** + * Filter female + * + * @return this + */ + public function filterByFemale() { + + $this->_filter = '{"gender":"F"}'; + return $this; + } + + /** + * Filter unisex + * + * @return this + */ + public function filterByUnisex() { + + $this->_filter = '{"gender":"U"}'; + return $this; + } + + /** + * filter by zip location + * + * @param string + * @return this + */ + public function setZipLocation($locationValue) { + //Argument 1 must be a string + Eden_Zappos_Error::i()->argument(1, 'string'); + + $this->_location = '{"zip":"'.$locationValue.'"}'; + return $this; + } + + /** + * filter by state location + * + * @param string + * @return this + */ + public function setStateLocation($locationValue) { + //Argument 1 must be a string + Eden_Zappos_Error::i()->argument(1, 'string'); + + $this->_location = '{"state":"'.$locationValue.'"}'; + return $this; + } + + /** + * Search Image + * + * @return this + */ + public function getResponse() { + //populate fields + $query = array( + self::TYPE => $this->_statistics, + self::FILTER => $this->_filter, + self::LOCATION => $this->_location); + + return $this->_getResponse(self::URL_STATISTICS, $query); + + } + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/zappos/values.php b/library/eden/zappos/values.php new file mode 100644 index 0000000..80fa97f --- /dev/null +++ b/library/eden/zappos/values.php @@ -0,0 +1,75 @@ + +/* + * This file is part of the Eden package. + * (c) 2011-2012 Openovate Labs + * + * Copyright and license information can be found at LICENSE.txt + * distributed with this package. + */ + +/** + * Zappos values + * + * @package Eden + * @category values + * @author Christian Symon M. Buenavista sbuenavista@openovate.com + */ +class Eden_Zappos_Values extends Eden_Zappos_Base { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_values = NULL; + + /* Private Properties + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + /* Public Methods + -------------------------------*/ + /** + * set values id + * + * @param string|int + * @return this + */ + public function setValuesId($values) { + //Argument 1 must be a string or int + Eden_Zappos_Error::i()->argument(1, 'string', 'int'); + + $this->_values = $values; + return $this; + } + + /** + * set values to random + * + * @return this + */ + public function setRandomValues() { + + $this->_random = 'random'; + return $this; + } + + /** + * get zapppos core values + * + * @return this + */ + public function getResponse() { + + return $this->_getResponse(self::URL_VALUE.$this->_values); + + } + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file