From 057aa3c73e059aae70120624a190577133067f19 Mon Sep 17 00:00:00 2001 From: cblanquera Date: Tue, 15 Nov 2011 12:18:55 +0000 Subject: [PATCH 001/330] initital checkout git-svn-id: http://svn.openovate.com/edenv2/trunk@1 38ede93f-50f4-44af-b0b3-68ccca78c181 --- library/eden.php | 158 ++++ library/eden/amazon/error.php | 42 ++ library/eden/amazon/s3.php | 903 +++++++++++++++++++++++ library/eden/apc.php | 150 ++++ library/eden/array.php | 458 ++++++++++++ library/eden/cache.php | 195 +++++ library/eden/class.php | 191 +++++ library/eden/cookie.php | 304 ++++++++ library/eden/curl.php | 534 ++++++++++++++ library/eden/error.php | 402 ++++++++++ library/eden/error/event.php | 193 +++++ library/eden/event.php | 225 ++++++ library/eden/eventbrite/base.php | 126 ++++ library/eden/eventbrite/discount.php | 128 ++++ library/eden/eventbrite/error.php | 54 ++ library/eden/eventbrite/event.php | 99 +++ library/eden/eventbrite/event/search.php | 245 ++++++ library/eden/eventbrite/event/set.php | 328 ++++++++ library/eden/eventbrite/organizer.php | 82 ++ library/eden/eventbrite/payment.php | 142 ++++ library/eden/eventbrite/ticket.php | 10 + library/eden/eventbrite/user.php | 10 + library/eden/eventbrite/venue.php | 10 + library/eden/facebook/auth.php | 96 +++ library/eden/facebook/error.php | 42 ++ library/eden/facebook/graph.php | 534 ++++++++++++++ library/eden/facebook/post.php | 207 ++++++ library/eden/file.php | 252 +++++++ library/eden/file/error.php | 44 ++ library/eden/file/mimetypes.php | 173 +++++ library/eden/folder.php | 294 ++++++++ library/eden/google/base.php | 223 ++++++ library/eden/google/calendar.php | 62 ++ library/eden/google/contacts.php | 54 ++ library/eden/google/docs.php | 54 ++ library/eden/google/error.php | 42 ++ library/eden/google/gmail.php | 54 ++ library/eden/google/oauth.php | 57 ++ library/eden/google/shortener.php | 217 ++++++ library/eden/image.php | 729 ++++++++++++++++++ library/eden/javascript.php | 52 ++ library/eden/javascript/class.php | 131 ++++ library/eden/javascript/error.php | 42 ++ library/eden/loader.php | 106 +++ library/eden/memcache.php | 202 +++++ library/eden/model.php | 228 ++++++ library/eden/mysql.php | 722 ++++++++++++++++++ library/eden/mysql/alter.php | 322 ++++++++ library/eden/mysql/create.php | 256 +++++++ library/eden/mysql/error.php | 42 ++ library/eden/mysql/subselect.php | 76 ++ library/eden/mysql/utility.php | 116 +++ library/eden/oauth.php | 609 +++++++++++++++ library/eden/oauth/base.php | 142 ++++ library/eden/oauth/consumer.php | 451 +++++++++++ library/eden/oauth/error.php | 42 ++ library/eden/oauth/server.php | 41 + library/eden/path.php | 305 ++++++++ library/eden/paypal/error.php | 10 + library/eden/paypal/payflowpro.php | 10 + library/eden/registry.php | 305 ++++++++ library/eden/route.php | 399 ++++++++++ library/eden/session.php | 351 +++++++++ library/eden/sql/database.php | 93 +++ library/eden/sql/delete.php | 94 +++ library/eden/sql/error.php | 42 ++ library/eden/sql/insert.php | 103 +++ library/eden/sql/query.php | 51 ++ library/eden/sql/select.php | 292 ++++++++ library/eden/sql/update.php | 79 ++ library/eden/string.php | 209 ++++++ library/eden/template.php | 194 +++++ library/eden/timezone.php | 136 ++++ library/eden/tool.php | 109 +++ library/eden/type/abstract.php | 132 ++++ library/eden/type/error.php | 42 ++ library/eden/unit.php | 394 ++++++++++ library/eden/validation.php | 333 +++++++++ library/eden/webcharge.php | 264 +++++++ library/eden/when.php | 148 ++++ site/front.php | 607 +++++++++++++++ site/front/config/classes.php | 2 + site/front/config/methods.php | 2 + site/front/config/pages.php | 2 + site/front/error.php | 42 ++ site/front/handler.php | 46 ++ site/front/page.php | 100 +++ site/front/page/index.php | 47 ++ site/front/template/_foot.php | 1 + site/front/template/_head.php | 1 + site/front/template/_message.php | 7 + site/front/template/_page.php | 25 + site/front/template/error.php | 12 + site/front/template/index.php | 1 + site/web/index.php | 90 +++ unit/tests/class.php | 103 +++ unit/tests/cookie.php | 34 + unit/tests/file.php | 30 + unit/tests/folder.php | 24 + unit/tests/model.php | 68 ++ unit/tests/session.php | 38 + unit/tests/string.php | 96 +++ unit/unit.php | 45 ++ 103 files changed, 17221 insertions(+) create mode 100644 library/eden.php create mode 100644 library/eden/amazon/error.php create mode 100644 library/eden/amazon/s3.php create mode 100755 library/eden/apc.php create mode 100755 library/eden/array.php create mode 100755 library/eden/cache.php create mode 100755 library/eden/class.php create mode 100755 library/eden/cookie.php create mode 100644 library/eden/curl.php create mode 100755 library/eden/error.php create mode 100755 library/eden/error/event.php create mode 100755 library/eden/event.php create mode 100644 library/eden/eventbrite/base.php create mode 100644 library/eden/eventbrite/discount.php create mode 100644 library/eden/eventbrite/error.php create mode 100644 library/eden/eventbrite/event.php create mode 100644 library/eden/eventbrite/event/search.php create mode 100644 library/eden/eventbrite/event/set.php create mode 100644 library/eden/eventbrite/organizer.php create mode 100644 library/eden/eventbrite/payment.php create mode 100644 library/eden/eventbrite/ticket.php create mode 100644 library/eden/eventbrite/user.php create mode 100644 library/eden/eventbrite/venue.php create mode 100644 library/eden/facebook/auth.php create mode 100644 library/eden/facebook/error.php create mode 100644 library/eden/facebook/graph.php create mode 100644 library/eden/facebook/post.php create mode 100644 library/eden/file.php create mode 100755 library/eden/file/error.php create mode 100755 library/eden/file/mimetypes.php create mode 100644 library/eden/folder.php create mode 100644 library/eden/google/base.php create mode 100644 library/eden/google/calendar.php create mode 100644 library/eden/google/contacts.php create mode 100644 library/eden/google/docs.php create mode 100644 library/eden/google/error.php create mode 100644 library/eden/google/gmail.php create mode 100644 library/eden/google/oauth.php create mode 100644 library/eden/google/shortener.php create mode 100644 library/eden/image.php create mode 100644 library/eden/javascript.php create mode 100644 library/eden/javascript/class.php create mode 100644 library/eden/javascript/error.php create mode 100755 library/eden/loader.php create mode 100755 library/eden/memcache.php create mode 100755 library/eden/model.php create mode 100755 library/eden/mysql.php create mode 100755 library/eden/mysql/alter.php create mode 100755 library/eden/mysql/create.php create mode 100755 library/eden/mysql/error.php create mode 100755 library/eden/mysql/subselect.php create mode 100755 library/eden/mysql/utility.php create mode 100644 library/eden/oauth.php create mode 100644 library/eden/oauth/base.php create mode 100644 library/eden/oauth/consumer.php create mode 100644 library/eden/oauth/error.php create mode 100644 library/eden/oauth/server.php create mode 100644 library/eden/path.php create mode 100644 library/eden/paypal/error.php create mode 100644 library/eden/paypal/payflowpro.php create mode 100755 library/eden/registry.php create mode 100755 library/eden/route.php create mode 100755 library/eden/session.php create mode 100755 library/eden/sql/database.php create mode 100755 library/eden/sql/delete.php create mode 100755 library/eden/sql/error.php create mode 100755 library/eden/sql/insert.php create mode 100755 library/eden/sql/query.php create mode 100755 library/eden/sql/select.php create mode 100755 library/eden/sql/update.php create mode 100755 library/eden/string.php create mode 100755 library/eden/template.php create mode 100644 library/eden/timezone.php create mode 100644 library/eden/tool.php create mode 100755 library/eden/type/abstract.php create mode 100755 library/eden/type/error.php create mode 100755 library/eden/unit.php create mode 100644 library/eden/validation.php create mode 100644 library/eden/webcharge.php create mode 100755 library/eden/when.php create mode 100644 site/front.php create mode 100755 site/front/config/classes.php create mode 100755 site/front/config/methods.php create mode 100755 site/front/config/pages.php create mode 100644 site/front/error.php create mode 100644 site/front/handler.php create mode 100644 site/front/page.php create mode 100644 site/front/page/index.php create mode 100644 site/front/template/_foot.php create mode 100644 site/front/template/_head.php create mode 100644 site/front/template/_message.php create mode 100644 site/front/template/_page.php create mode 100644 site/front/template/error.php create mode 100644 site/front/template/index.php create mode 100644 site/web/index.php create mode 100644 unit/tests/class.php create mode 100644 unit/tests/cookie.php create mode 100644 unit/tests/file.php create mode 100644 unit/tests/folder.php create mode 100644 unit/tests/model.php create mode 100644 unit/tests/session.php create mode 100644 unit/tests/string.php create mode 100644 unit/unit.php diff --git a/library/eden.php b/library/eden.php new file mode 100644 index 0000000..f1013b2 --- /dev/null +++ b/library/eden.php @@ -0,0 +1,158 @@ + +/* + * 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 'eden/event.php'; + +/** + * The starting point of every framework call. + * + * @author Christian Blanquera + * @version $Id: framework.php 9 2010-01-12 15:42:40Z blanquera $ + */ +function eden() { + //return the results + return Eden::get(); +} + +/** + * Defines the starting point of every framework call. + * Starts laying out how classes and methods are handled. + * + * @package Eden + * @category framework + * @author Christian Blanquera + * @version $Id: framework.php 9 2010-01-12 15:42:40Z blanquera $ + */ +class Eden extends Eden_Event { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function get() { + return self::_getSingleton(__CLASS__); + } + + /* Magic + -------------------------------*/ + 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 function __construct() { + //require autoload + require dirname(__FILE__).'/eden/loader.php'; + + //set autoload class as the autoload handler + spl_autoload_register(array(Eden_Loader::get(), 'handler')); + } + + /* Public Methods + -------------------------------*/ + /** + * Adds a root path to search in when a class does not exist. + * Being as specific as possible will reduce the time it takes + * to find the class. + * + * @param string|array path + * @return Eden_Framework + */ + public function addRoot($path) { + Eden_Error::get()->argument(1, 'string'); + Eden_Loader::get()->addRoot($path); + return $this; + } + + /** + * Sets class routes + * + * @param string|array routes + * @return Eden_Framework + */ + public function setClasses($routes) { + Eden_Error::get()->argument(1, 'string', 'array'); + $route = Eden_Route::get(); + + if(is_string($routes)) { + $routes = include($routes); + } + + foreach($routes as $alias => $class) { + $route->routeClass($alias, $class); + } + + return $this; + } + + /** + * Sets method routes + * + * @param string|array routes + * @return Eden_Framework + */ + public function setMethods($routes) { + Eden_Error::get()->argument(1, 'string', 'array'); + + 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 + $this->routeMethod($method, $routePath[0], $routePath[1]); + } + } + + return $this; + } + + /** + * Starts a session + * + * @return this + */ + public function startSession() { + //get the session class + Eden_Session::get()->start(); + + return $this; + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/amazon/error.php b/library/eden/amazon/error.php new file mode 100644 index 0000000..a14f9df --- /dev/null +++ b/library/eden/amazon/error.php @@ -0,0 +1,42 @@ + +/* + * 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 + * @version $Id: exception.php 1 2010-01-02 23:06:36Z blanquera $ + */ +class Eden_Amazon_Error extends Eden_Error { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function get($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/amazon/s3.php b/library/eden/amazon/s3.php new file mode 100644 index 0000000..7c3b45e --- /dev/null +++ b/library/eden/amazon/s3.php @@ -0,0 +1,903 @@ + +/* + * 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. + */ + +/** + * Amazon S3 + * + * @package Eden + * @subpackage amazon + * @author Christian Blanquera + * @version $Id: abstract.php 1 2010-01-02 23:06:36Z blanquera $ + */ +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 + -------------------------------*/ + /* Get + -------------------------------*/ + public static function get($user, $pass, $host = 's3.amazonaws.com', $ssl = false) { + return self::_getMultiple(__CLASS__, $user, $pass, $host, $ssl); + } + + /* Magic + -------------------------------*/ + 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 + -------------------------------*/ + /** + * 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 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::get() + ->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 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::get() + ->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); + } + + /** + * 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::get() + ->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); + } + + /** + * 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::get() + ->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; + } + + /** + * Delete an empty bucket + * + * @param string $bucket Bucket name + * @return boolean + */ + public function deleteBucket($bucket) { + //Argument 1 must be string + Eden_Amazon_Error::get()->argument(1, 'string'); + $this->_setResponse('DELETE', $bucket); + + if(!empty($this->_meta['error']) || empty($this->_response)) { + return false; + } + + return true; + } + + /** + * 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::get() + ->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; + } + + /** + * 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::get() + ->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; + } + + /** + * 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::get() + ->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'] = $this->Eden_File()->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; + } + + /** + * 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::get() + ->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::get() + ->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']; + } + + /** + * 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::get() + ->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::get() + ->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; + } + + /** + * 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::get() + ->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; + } + + /* Protected Methods + -------------------------------*/ + 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::get() + ->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; + } + + /* Protected Methods + -------------------------------*/ + protected function _getHost($bucket = NULL) { + if(!$bucket) { + return $this->_host; + } + + return strtolower($bucket).'.'.$this->_host; + } + + 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 _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 _responseWriteCallback(&$curl, &$data) { + $this->_response .= $data; + return strlen($data); + } + + 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; + } + + /* Private Methods + -------------------------------*/ +} diff --git a/library/eden/apc.php b/library/eden/apc.php new file mode 100755 index 0000000..847cbde --- /dev/null +++ b/library/eden/apc.php @@ -0,0 +1,150 @@ + +/* + * 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__).'/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 + * @subpackage apc + * @category cache + * @author Christian Blanquera + * @version $Id: apc.php 1 2010-01-02 23:06:36Z blanquera $ + */ +class Eden_Apc extends Eden_Class { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + public static function get() { + return self::_getSingleton(__CLASS__); + } + + /* Magic + -------------------------------*/ + public function __construct() { + //if apc_cache_info is not a function + if(!function_exists('apc_cache_info')) { + //throw exception + throw new Eden_Apc_Error(Eden_Apc_Error::NOT_INSTALLED); + } + } + + /* Magic + -------------------------------*/ + /* Public Methods + -------------------------------*/ + /** + * 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 setData($key, $data, $expire = NULL) { + //argument test + Eden_Apc_Error::get() + ->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; + } + + /** + * Gets a data cache + * + * @param string|array the key to the data + * @param int MemCache flag + * @return variable + */ + public function getData($key) { + //Argument 1 must be a string or array + Eden_Memcache_Error::get()->argument(1, 'string', 'array'); + + return apc_fetch($key); + } + + /** + * deletes data of a cache + * + * @param string the key to the data + * @return this + */ + public function deleteData($key) { + //Argument 1 must be a string or array + Eden_Memcache_Error::get()->argument(1, 'string', 'array'); + + apc_delete($key); + + return $this; + } + + /** + * Flushes the cache + * + * @return this + */ + public function clear() { + apc_clear_cache(); + + 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 + -------------------------------*/ + /* Get + -------------------------------*/ + public static function get($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/array.php b/library/eden/array.php new file mode 100755 index 0000000..4e0a59b --- /dev/null +++ b/library/eden/array.php @@ -0,0 +1,458 @@ + +/* + * 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__).'/class.php'; +require_once dirname(__FILE__).'/type/abstract.php'; +require_once dirname(__FILE__).'/type/error.php'; +require_once dirname(__FILE__).'/string.php'; + +/** + * + * @package Eden + * @category registry + * @author Christian Blanquera + * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ + */ +class Eden_Array extends Eden_Type_Abstract implements ArrayAccess, Iterator, Serializable, Countable { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected static $_preMethods = array( + 'array_change_key_case', 'array_chunk', + 'array_combine', 'array_count_datas', + 'array_diff_assoc', 'array_diff_key', + 'array_diff_uassoc', 'array_diff_ukey', + 'array_diff', 'array_fill_keys', + 'array_filter', 'array_flip', + 'array_intersect_assoc', 'array_intersect_key', + 'array_intersect_uassoc', 'array_intersect_ukey', + 'array_intersect', 'array_keys', + 'array_merge_recursive', 'array_merge', + 'array_pad', 'array_push', + 'array_reverse', 'array_shift', + 'array_slice', 'array_splice', + 'array_sum', 'array_udiff_assoc', + 'array_udiff_uassoc', 'array_udiff', + 'array_uintersect_assoc', 'array_uintersect_uassoc', + 'array_uintersect', 'array_unique', + 'array_datas', 'count', + 'current', 'each', + 'end', 'extract', + 'in_array', 'key', + 'next', 'prev', + 'sizeof'); + + protected static $_postMethods = array( + 'array_fill', 'array_map', + 'array_search', 'compact', + 'implode'); + + protected static $_referenceMethods = array( + 'array_unshift', 'array_walk_recursive', + 'array_walk', 'arsort', + 'asort', 'krsort', + 'ksort', 'natcasesort', + 'natsort', 'reset', + 'rsort', 'shuffle', + 'sort', 'uasort', + 'uksort', 'usort'); + + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function get(array $data = array()) { + return self::_getMultiple(__CLASS__, $data); + } + + /* Magic + -------------------------------*/ + public function __construct(array $data = array()) { + parent::__construct($data); + } + + public function __toString() { + return json_encode($this->_data); + } + + public function __get($name) { + if(isset($this->_data[$name])) { + return $this->_data[$name]; + } + + return NULL; + } + + public function __set($name, $value) { + $this->_data[$name] = $value; + } + + /* Public Methods + -------------------------------*/ + /** + * Removes a row in an array and adjusts all the indexes + * + * @param *string the key to leave out + * @param bool is this a value or key value array? + * @return this + */ + public function cut($arrayKey, $isValueArray = true) { + //argument 1 must be a string, argument 2 must be a boolean + Eden_Array_Error::get() + ->argument(1, 'string') + ->argument(2, 'bool'); + + $array = array(); + foreach($this->_data as $key => $value) { + //if the key does not equal + //the key to to leave out + if($arrayKey != $key) { + //we want to add it to the new array + if($isValueArray) { + $array[] = $value; + } else { + $array[$key] = $value; + } + } + } + + $this->_data = $array; + + return $this; + } + + /** + * Inserts a row in an array after the given index and adjusts all the indexes + * + * @param *string the key we are looking for to past after + * @param *mixed the value to paste + * @param string the key to paste along with the value + * @return this + */ + public function paste($afterKey, $arrayValue, $arrayKey = NULL) { + //argument 1 must be a string, argument 3 must be a string or null + Eden_Array_Error::get() + ->argument(1, 'string') + ->argument(3, 'string', 'null'); + + $array = array(); + foreach($this->_data as $key => $value) { + //if the array key is not null + //we know they ment to make this + //array an key value array + if(!is_null($arrayKey)) { + //lets add it + $array[$key] = $value; + //if the current key is the key we + //want to add the new value after + if($afterKey == $key) { + //lets add the new value + $array[$arrayKey] = $arrayValue; + } + } else { + //lets add it + $array[] = $value; + //if the current key is the key we + //want to add the new value after + if($afterKey == $key) { + //lets add the new value + $array[] = $arrayValue; + } + } + } + + $this->_data = $array; + + return $this; + } + + /** + * Converts a multidimensional array with similar rows to an accociate array + * + * @param *array the table to key + * @param *string the name of the key we are looking for + * @return this + */ + public function associateTable($key, $many = false) { + //argument 1 must be a string, argument 2 must be a boolean + Eden_Array_Error::get() + ->argument(1, 'string') + ->argument(2, 'bool'); + + $table = array(); + foreach($this->_data as $i => $row) { + $newKey = isset($row[$key]) ? $row[$key] : $i; + + if($many) { + $table[$newKey][] = $row; + } else { + $table[$newKey] = $row; + } + } + + $this->_data = $table; + + return $this; + } + + /** + * Returns a list of values of a given column + * + * @param *string the key to look for + * @param string the value of the key that + * needs to be returned + * @return mixed + */ + public function getKeyValue($key, $index = NULL) { + //argument 1 must be a string, argument 2 must be a string or null + Eden_Array_Error::get() + ->argument(1, 'string') + ->argument(2, 'string', 'null'); + + $table = $this->associateTable($table, $key); + + if(is_null($index)) { + return Eden_Array::get(array_keys($table)); + } + + return isset($table[$index]) ? $table[$index] : false; + } + + /** + * Sorts a table + * TODO: array_multisort + * + * @param *string sort field + * @param string order + * @param int start + * @param int range + * @return array + */ + public function paginate($field, $order = 'ASC', $start = 0, $range = 0) { + Eden_Array_Error::get() + ->argument(1, 'string') //argument 1 must be a string + ->argument(2, 'string') //argument 2 must be a string + ->argument(3, 'int') //argument 3 must be a number + ->argument(4, 'int'); //argument 4 must be a number + + //do the sorting first + //first lets take the field column + //and put it in a new array + $fields = array(); + foreach($this->_data as $i =>$row) { + $fields[$i] = $row[$field]; + } + + $order = strtoupper($order) == 'ASC' ? SORT_ASC : SORT_DESC; + + array_multisort($fields, $order, SORT_STRING, $this->_data); + + //now do the pagination + $this->_data = array_slice($this->_data, $start, $range); + + return $this; + } + + /** + * Rewinds the position + * For Iterator interface + * + * @return void + */ + public function rewind() { + reset($this->_data); + } + + /** + * Returns the current item + * For Iterator interface + * + * @return void + */ + public function current() { + return current($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); + } + + /** + * Validates whether if the index is set + * For Iterator interface + * + * @return void + */ + public function valid() { + return isset($this->_data[$this->key()]); + } + + /** + * 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; + } + } + + /** + * isset using the ArrayAccess interface + * + * @param number + * @return bool + */ + public function offsetExists($offset) { + return isset($this->_data[$offset]); + } + + /** + * unsets using the ArrayAccess interface + * + * @param number + * @return bool + */ + public function offsetUnset($offset) { + unset($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; + } + + /** + * returns serialized data using the Serializable interface + * + * @return string + */ + public function serialize() { + return json_encode($this->_data); + } + + /** + * sets data using the Serializable interface + * + * @param string + * @return void + */ + public function unserialize($data) { + $this->_data = json_decode($data, true); + return $this; + } + + /** + * returns size using the Countable interface + * + * @return string + */ + public function count() { + return count($this->_data); + } + + /* Protected Methods + -------------------------------*/ + protected function _getPreMethod($name) { + if(in_array($name, self::$_preMethods)) { + return $name; + } + + if(in_array('array_'.$name, self::$_preMethods)) { + return 'array_'.$name; + } + + return false; + } + + protected function _getPostMethod($name) { + if(in_array($name, self::$_postMethods)) { + return $name; + } + + if(in_array('array_'.$name, self::$_postMethods)) { + return 'array_'.$name; + } + + return false; + } + + protected function _getReferenceMethod($name) { + if(in_array($name, self::$_postMethods)) { + return $name; + } + + if(in_array('array_'.$name, self::$_postMethods)) { + return 'array_'.$name; + } + + return false; + } + + /* Private Methods + -------------------------------*/ +} + +/** + * Array Errors + */ +class Eden_Array_Error extends Eden_Type_Error { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function get($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/cache.php b/library/eden/cache.php new file mode 100755 index 0000000..e80b498 --- /dev/null +++ b/library/eden/cache.php @@ -0,0 +1,195 @@ + +/* + * 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__).'/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 + * @subpackage cache + * @category cache + * @author Christian Blanquera + * @version $Id: model.php 1 2010-01-02 23:06:36Z blanquera $ + */ +class Eden_Cache extends Eden_Class { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_key = NULL; + protected $_path = NULL; + protected $_cache = array(); + + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function get($root, $key = 'key.php') { + $class = __CLASS__; + return new $class($root, $key); + } + + /* Magic + -------------------------------*/ + public function __construct($root, $key = 'key.php') { + Eden_Cache_Error::get() + ->argument(1, 'string') + ->argument(2, 'string'); + + $this->setKey($key)->setRoot($root)->build(); + } + + /* Public Methods + -------------------------------*/ + /** + * 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::get()->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::get()->argument(1, 'string'); + + $this->_path = (string) Eden_Path::get($root)->absolute(); + + return $this; + } + + /** + * Builds the cache into memory + * + * @return Eden_CacheModel + */ + public function build() { + try { + $this->_cache = Eden_File::get($this->_path.'/'.$this->_key)->getData(); + } catch(Eden_File_Error $e) { + $this->_cache = array(); + } + 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 setData($key, $path, $data) { + //argument test + Eden_Cache_Error::get() + ->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::get($path); + //set the data to the file + Eden_File::get($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::get($this->_path.'/'.$this->_key)->setData($this->_cache); + + return $this; + } + + /** + * Gets a data cache + * + * @param *string the key to the data + * @param string|null returns this variable by default + * @return mixed + */ + public function getData($key, $default = NULL) { + //argument 1 must be a string + Eden_Cache_Error::get()->argument(1, 'string'); + + //if the key exists + if($this->keyExists($key)) { + //return it + return Eden_File::get($this->_cache[$key])->getData($default); + } + + //return the defauit + return $default; + } + + /** + * 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::get()->argument(1, 'string'); + + return isset($this->_cache[$key]) && file_exists($this->_cache[$key]); + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} + +/** + * Cache Errors + */ +class Eden_Cache_Error extends Eden_Error { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function get($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/class.php b/library/eden/class.php new file mode 100755 index 0000000..92e179f --- /dev/null +++ b/library/eden/class.php @@ -0,0 +1,191 @@ + +/* + * 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__).'/error.php'; +require_once dirname(__FILE__).'/route.php'; +require_once dirname(__FILE__).'/when.php'; + +/** + * The base class for all classes wishing to integrate with Eve. + * 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 framework + * @author Christian Blanquera + * @version $Id: class.php 1 2010-01-02 23:06:36Z blanquera $ + */ +class Eden_Class { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_event = NULL; + protected $_observers = array(); + + /* Private Properties + -------------------------------*/ + private static $_instances = array(); + + /* Get + -------------------------------*/ + /* Magic + -------------------------------*/ + public function __toString() { + return get_class($this); + } + + 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::get()->getClassArray($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::get()->callMethod($this, $name, true, $args); + } catch(Eden_Route_Error $e) { + throw new Eden_Error($e->getMessage()); + } + } + + /* Public Methods + -------------------------------*/ + /** + * 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::get()->argument(1, 'string'); + + Eden_Route::get()->routeClass($route, get_class($this)); + return $this; + } + + /** + * Creates a method route for this class. + * + * @param *string the method route name + * @param *string the class name to route to + * @param *string the method name to route to + * @return Eden_Class + */ + public function routeMethod($routeMethod, $class, $method) { + //argument 1-3 must be a string + Eden_Error::get() + ->argument(1, 'string') + ->argument(2, 'string') + ->argument(3, 'string'); + + Eden_Route::get()->routeMethod(get_class($this), $routeMethod, $class, $method); + return $this; + } + + /** + * Calls a method in this class and allows + * argumetns to be passed as an array + * + * @param string + * @param array + * @return mixed + */ + public function callThisMethod($method, array $args = array()) { + //argument 1 must be a string + Eden_Error::get()->argument(1,'string'); + + return Eden_Route::get()->callMethod($this, $method, $args); + } + + /** + * Invokes Noop if conditional is false + * + * @param bool + * @return this|Eden_Noop + */ + public function when($isTrue) { + if($isTrue) { + return $this; + } + + return Eden_When::get($this); + } + + /** + * Returns the original class + * + * @param bool + * @return this|Eden_Noop + */ + public function endWhen() { + return $this; + } + + /* Protected Methods + -------------------------------*/ + protected static function _getSingleton($class) { + if(!isset(self::$_instances[$class])) { + $args = func_get_args(); + $class = array_shift($args); + + try { + self::$_instances[$class] = self::_getInstance($class, $args); + } catch(Reflection_Exception $e) { + Eden_Error::get() + ->setMessage(Eden_Error::REFLECTION_ERROR) + ->addVariable($class) + ->addVariable('new') + ->trigger(); + } + } + + return self::$_instances[$class]; + } + + protected static function _getMultiple($class) { + $args = func_get_args(); + $class = array_shift($args); + + try { + return self::_getInstance($class, $args); + } catch(Reflection_Exception $e) { + Eden_Error::get() + ->setMessage(Eden_Error::REFLECTION_ERROR) + ->addVariable($class) + ->addVariable('new') + ->trigger(); + } + } + + /* Private Methods + -------------------------------*/ + private static function _getInstance($class, $args) { + if(count($args) === 0 || !method_exists($class, '__construct')) { + return new $class; + } + + $reflect = new ReflectionClass($class); + return $reflect->newInstanceArgs($args); + } +} \ No newline at end of file diff --git a/library/eden/cookie.php b/library/eden/cookie.php new file mode 100755 index 0000000..b1715cc --- /dev/null +++ b/library/eden/cookie.php @@ -0,0 +1,304 @@ + +/* + * 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__).'/class.php'; + +/** + * General available methods for common cookie procedures. + * + * @package Eden + * @subpackage cookie + * @category tool + * @author Christian Blanquera + * @version $Id: cookie.php 1 2010-01-02 23:06:36Z blanquera $ + */ +class Eden_Cookie extends Eden_Class implements ArrayAccess, Iterator { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function get() { + return self::_getSingleton(__CLASS__); + } + + /* Magic + -------------------------------*/ + /* Public Methods + -------------------------------*/ + /** + * 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::get() + ->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 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) { + try { + return $this->set($key, $data, $expires, $path, $domain, true, false); + } catch(Eden_Cookie_Error $e) { + throw new Eden_Cookie_Error($e->getMessage()); + } + } + + /** + * 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) { + try { + $this->set($key, $value, $expires, $path, $domain, $secure, $httponly); + } catch(Eden_Cookie_Error $e) { + throw new Eden_Cookie_Error($e->getMessage()); + } + } + + return $this; + } + + /** + * 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) { + try { + $this->setData($data, $expires, $path, $domain, true, false); + } catch(Eden_Cookie_Error $e) { + throw new Eden_Cookie_Error($e->getMessage()); + } + + return $this; + } + + /** + * Returns data + * + * @param string|null + * @return mixed + */ + public function getData($key = NULL) { + Eden_Cookie_Error::get()->argument(1, 'string', 'null'); + + if(is_null($key)) { + return $_COOKIE; + } + + if(isset($_COOKIE[$key])) { + return $_COOKIE[$key]; + } + + return NULL; + } + + /** + * Removes a cookie. + * + * @param *string cookie name + * @return Eden_Cookie + */ + public function remove($name) { + Eden_Cookie_Error::get()->argument(1, 'string'); + + $this->set($name, NULL, time() - 3600); + + if(isset($_COOKIE[$name])) { + unset($_COOKIE[$name]); + } + + return $this; + } + + /** + * Removes all cookies. + * + * @return Eden_Cookie + */ + public function clear() { + foreach($_COOKIE as $key => $value) { + $this->remove($key); + } + + return $this; + } + + /** + * Rewinds the position + * For Iterator interface + * + * @return void + */ + public function rewind() { + reset($_COOKIE); + } + + /** + * Returns the current item + * For Iterator interface + * + * @return void + */ + public function current() { + return current($_COOKIE); + } + + /** + * 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); + } + + /** + * Validates whether if the index is set + * For Iterator interface + * + * @return void + */ + public function valid() { + return isset($_COOKIE[$this->key()]); + } + + /** + * Sets data using the ArrayAccess interface + * + * @param number + * @param mixed + * @return void + */ + public function offsetSet($offset, $value) { + try { + $this->set($offset, $value, strtotime('+10 years')); + } catch(Eden_Error $e) { + throw new Eden_Error($e->getMessage()); + } + } + + /** + * isset using the ArrayAccess interface + * + * @param number + * @return bool + */ + public function offsetExists($offset) { + return isset($_COOKIE[$offset]); + } + + /** + * unsets using the ArrayAccess interface + * + * @param number + * @return bool + */ + public function offsetUnset($offset) { + $this->remove($offset); + } + + /** + * returns data using the ArrayAccess interface + * + * @param number + * @return bool + */ + public function offsetGet($offset) { + return isset($_COOKIE[$offset]) ? $_COOKIE[$offset] : NULL; + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} + +/** + * Cookie Errors + */ +class Eden_Cookie_Error extends Eden_Error { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function get($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/curl.php b/library/eden/curl.php new file mode 100644 index 0000000..f11186e --- /dev/null +++ b/library/eden/curl.php @@ -0,0 +1,534 @@ + +/* + * 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__).'/class.php'; + +/** + * cURL wrapper + * + * @package Eden + * @category curl + * @author Christian Blanquera + * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ + */ +/** + * cURL wrapper + * + * @package Eden + * @category curl + * @author Christian Blanquera + * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ + */ +class Eden_Curl extends Eden_Class implements ArrayAccess { + /* Constants + -------------------------------*/ + /* 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, + 'CertInfo' => CURLOPT_CERTINFO, + '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, + 'Protocols' => CURLOPT_PROTOCOLS, + 'ProxyAuth' => CURLOPT_PROXYAUTH, + 'ProxyPort' => CURLOPT_PROXYPORT, + 'ProxyType' => CURLOPT_PROXYTYPE, + 'RedirProtocols' => CURLOPT_REDIR_PROTOCOLS, + '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, + 'ProgressFunction' => CURLOPT_PROGRESSFUNCTION, + 'ReadFunction' => CURLOPT_READFUNCTION, + 'WriteFunction' => CURLOPT_WRITEFUNCTION); + + + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function get() { + $class = __CLASS__; + return new $class(); + } + + /* Magic + -------------------------------*/ + public function __call($name, $args) { + if(strpos($name, 'set') === 0) { + $method = substr($name, 3); + + if(isset(self::$_setBoolKeys[$method])) { + Eden_Curl_Error::get()->vargument($name, $args, 1, 'bool'); + $key = self::$_setBoolKeys[$method]; + $this->_options[$key] = $args[0]; + + return $this; + } + + if(isset(self::$_setIntegerKeys[$method])) { + Eden_Curl_Error::get()->vargument($name, $args, 1, 'int'); + $key = self::$_setIntegerKeys[$method]; + $this->_options[$key] = $args[0]; + + return $this; + } + + if(isset(self::$_setStringKeys[$method])) { + Eden_Curl_Error::get()->vargument($name, $args, 1, 'string'); + $key = self::$_setStringKeys[$method]; + $this->_options[$key] = $args[0]; + + return $this; + } + + if(isset(self::$_setArrayKeys[$method])) { + Eden_Curl_Error::get()->vargument($name, $args, 1, 'array'); + $key = self::$_setArrayKeys[$method]; + $this->_options[$key] = $args[0]; + + return $this; + } + + if(isset(self::$_setFileKeys[$method])) { + $key = $this->_setFileKeys[$method]; + $this->_options[$key] = $args[0]; + + return $this; + } + + if(isset(self::$_setCallbackKeys[$method])) { + Eden_Curl_Error::get()->vargument($name, $args, 1, 'array', 'string'); + $key = self::$_setCallbackKeys[$method]; + $this->_options[$key] = $args[0]; + + return $this; + } + } + + parent::__call($name, $args); + } + + /* Public Methods + -------------------------------*/ + /** + * Sets CURLOPT_SSL_VERIFYHOST + * + * @param bool + * @return this + */ + public function verifyHost($on = true) { + Eden_Curl_Error::get()->argument(1, 'bool'); + $this->options[CURLOPT_SSL_VERIFYHOST] = $on; + return $this; + } + + /** + * Sets CURLOPT_SSL_VERIFYPEER + * + * @param bool + * @return this + */ + public function verifyPeer($on = true) { + Eden_Curl_Error::get()->argument(1, 'bool'); + $this->options[CURLOPT_SSL_VERIFYPEER] = $on; + return $this; + } + + /** + * Sets url parameter + * + * @param array|string + * @return this + */ + public function setUrlParameter($key, $value = NULL) { + Eden_Curl_Error::get() + ->argument(1, 'array', 'string') + ->argument(2, 'scalar'); + + if(is_array($key)) { + $this->_param = $key; + return $this; + } + + $this->_param[$key] = $value; + } + + /** + * Sets request headers + * + * @param array|string + * @return this + */ + public function setHeaders($key, $value = NULL) { + Eden_Curl_Error::get() + ->argument(1, 'array', 'string') + ->argument(2, 'scalar','null'); + + if(is_array($key)) { + $this->_headers = $key; + return $this; + } + + $this->_headers[] = $key.': '.$value; + return $this; + } + + /** + * 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; + } + + /** + * 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 JSON + * + * @return array + */ + public function getJsonResponse($assoc = true) { + $this->_meta['response'] = $this->getResponse(); + Eden_Curl_Error::get()->argument(1, 'bool'); + return json_decode($this->_meta['response'], $assoc); + } + + /** + * 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 + * parsed as SimpleXml + * + * @return SimpleXmlElement + */ + public function getSimpleXmlResponse() { + $this->_meta['response'] = $this->getResponse(); + return simplexml_load_string($this->_meta['response']); + } + + /** + * 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; + } + + /** + * Returns the meta of the last call + * + * @return array + */ + public function getMeta($key = NULL) { + Eden_Curl_Error::get()->argument(1, 'string', 'null'); + + if(isset($this->_meta[$key])) { + return $this->_meta[$key]; + } + + return $this->_meta; + } + + /** + * 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)); + } + } + } + + /** + * isset using the ArrayAccess interface + * + * @param number + * @return bool + */ + public function offsetExists($offset) { + return isset($this->_option[$offset]); + } + + /** + * unsets using the ArrayAccess interface + * + * @param number + * @return bool + */ + public function offsetUnset($offset) { + unset($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; + } + + /* Protected Methods + -------------------------------*/ + 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; + } + + protected function _addHeaders() { + if(empty($this->_headers)) { + return $this; + } + + $this->_options[CURLOPT_HTTPHEADER] = $this->_headers; + return $this; + } + + /* Private Methods + -------------------------------*/ +} + +/** + * cUrl Errors + */ +class Eden_Curl_Error extends Eden_Error { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function get($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/error.php b/library/eden/error.php new file mode 100755 index 0000000..6074ed2 --- /dev/null +++ b/library/eden/error.php @@ -0,0 +1,402 @@ + +/* + * 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. + */ + +/* + * 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. + */ + +/** + * 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 + * @version $Id: exception.php 1 2010-01-02 23:06:36Z blanquera $ + */ +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 + + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_reporter = NULL; + protected $_type = NULL; + protected $_level = NULL; + protected $_offset = 1; + protected $_variables = array(); + + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function get($message = NULL, $code = 0) { + $class = __CLASS__; + return new $class($message, $code); + } + + /* Magic + -------------------------------*/ + public function __construct($message = NULL, $code = 0) { + $this->_type = self::LOGIC; + $this->_level = self::ERROR; + $this->_reporter = $this->_getReporter(); + parent::__construct($message, $code); + } + + /* Public Methods + -------------------------------*/ + /** + * 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; + } + + /** + * Returns the trace offset; where we should start the trace + * + * @return this + */ + public function getTraceOffset() { + return $this->_offset; + } + + /** + * Sets exception level + * + * @param string + * @return this + */ + public function setLevel($level) { + $this->_level = $level; + return $this; + } + + /** + * Sets exception level to WARNING + * + * @return this + */ + public function setLevelWarning() { + return $this->setLevel(self::WARNING); + } + + /** + * Sets exception level to ERROR + * + * @return this + */ + public function setLevelError() { + return $this->setLevel(self::WARNING); + } + + /** + * Sets exception level to DEBUG + * + * @return this + */ + public function setLevelDebug() { + return $this->setLevel(self::DEBUG); + } + + /** + * Sets exception level to INFORMATION + * + * @return this + */ + public function setLevelInformation() { + return $this->setLevel(self::INFORMATION); + } + + /** + * Returns the exception level + * + * @return string + */ + public function getLevel() { + return $this->_level; + } + + /** + * 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 LOGIC + * + * @return this + */ + public function setTypeLogic() { + return $this->setType(self::CRITICAL); + } + + /** + * Sets exception type to GENERAL + * + * @return this + */ + public function setTypeGeneral() { + return $this->setType(self::GENERAL); + } + + /** + * Sets exception type to CRITICAL + * + * @return this + */ + public function setTypeCritical() { + return $this->setType(self::CRITICAL); + } + + /** + * Returns the exception type + * + * @return string + */ + public function getType() { + return $this->_type; + } + + /** + * REturns the class or method that caught this + * + * @return string + */ + public function getReporter() { + return $this->_reporter; + } + + /** + * Adds parameters used in the message + * + * @return this + */ + public function addVariable($variable) { + $this->_variables[] = $variable; + return $this; + } + + /** + * Combines parameters with message and throws it + * + * @return void + */ + public function trigger() { + if(!empty($this->_variables)) { + $this->message = vsprintf($this->message, $this->_variables); + } + + throw $this; + } + + /** + * Tests arguments for valid data types + * + * @param *int + * @param *mixed + * @param *string[,string..] + * @return this + */ + public function argument($index, $types) { + $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) { + $method = 'is_'.$type; + if(function_exists($method) && $method($argument)) { + return $this; + } + + if(class_exists($type) && $argument instanceof $type) { + return $this; + } + } + + //lets formulate the method + $method = $trace['function']; + if(isset($trace['class'])) { + $method = $trace['class'].'->'.$method; + } + + $type = 'unknown'; + if(is_string($argument)) { + $type = "'".$argument."'"; + } else if(is_numeric($argument)) { + $type = $argument; + } else if(is_array($argument)) { + $type = 'Array'; + } else if(is_bool($argument)) { + $type = $argument ? 'true' : 'false'; + } else if(is_object($argument)) { + $type = get_class($argument); + } else if(is_null($argument)) { + $type = 'null'; + } + + $this->setMessage(self::INVALID_ARGUMENT) + ->addVariable($index + 1) + ->addVariable($method) + ->addVariable(implode(' or ', $types)) + ->addVariable($type) + ->setTypeLogic() + ->setTraceOffset(2) + ->trigger(); + } + + /** + * Tests virtual arguments for valid data types + * + * @param *int + * @param *mixed + * @param *string[,string..] + * @return this + */ + public function vargument($method, $args, $index, $types) { + $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) { + $method = 'is_'.$type; + if(function_exists($method) && $method($argument)) { + return $this; + } + + if(class_exists($type) && $argument instanceof $type) { + return $this; + } + } + + $method = $trace['class'].'->'.$method; + + $type = 'unknown'; + if(is_string($argument)) { + $type = "'".$argument."'"; + } else if(is_numeric($argument)) { + $type = $argument; + } else if(is_array($argument)) { + $type = 'Array'; + } else if(is_bool($argument)) { + $type = $argument ? 'true' : 'false'; + } else if(is_object($argument)) { + $type = get_class($argument); + } else if(is_null($argument)) { + $type = 'null'; + } + + $this->setMessage(self::INVALID_ARGUMENT) + ->addVariable($index + 1) + ->addVariable($method) + ->addVariable(implode(' or ', $types)) + ->addVariable($type) + ->setTypeLogic() + ->setTraceOffset(2) + ->trigger(); + } + + /* Protected Methods + -------------------------------*/ + protected function _getReporter() { + $trace = $this->getTrace(); + + if(isset($trace[0]['class'])) { + return $trace[0]['class']; + } + + return get_class($this); + } + + /* Private Methods + -------------------------------*/ +} \ 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..6eb63fb --- /dev/null +++ b/library/eden/error/event.php @@ -0,0 +1,193 @@ + +/* + * 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 + * @version $Id: exception.php 1 2010-01-02 23:06:36Z blanquera $ + */ +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 + -------------------------------*/ + protected static $_instance = NULL; + + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function get() { + $class = __CLASS__; + if(is_null(self::$_instance)) { + self::$_instance = new $class(); + } + + return self::$_instance; + } + + /* Magic + -------------------------------*/ + /* 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', $trace, 1, + $type, $level, $class, + $errfile, $errline, $errstr); + + //Don't execute PHP internal error handler + return true; + } + + /** + * Registers this class' error handler to PHP + * + * @return this + */ + public function setErrorHandler() { + set_error_handler(array($this, 'errorHandler')); + return $this; + } + + /** + * Returns default handler back to PHP + * + * @return this + */ + public function releaseErrorHandler() { + restore_error_handler(); + return $this; + } + + /** + * 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); + + //if the exception is an eden exception + if($e instanceof Eden_Error) { + //set type and level from that + $type = $e->getType(); + $level = $e->getLevel(); + $offset = $e->getTraceOffset(); + $reporter = $e->getReporter(); + } + + //get trace + $trace = $e->getTrace(); + + $this->trigger( + 'exception', $trace, $offset, + $type, $level, $reporter, + $e->getFile(), $e->getLine(), $e->getMessage()); + } + + /** + * Registers this class' exception handler to PHP + * + * @return this + */ + public function setExceptionHandler() { + set_exception_handler(array($this, 'exceptionHandler')); + return $this; + } + + /** + * Returns default handler back to PHP + * + * @return this + */ + public function releaseExceptionHandler() { + restore_exception_handler(); + 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..4e0e30b --- /dev/null +++ b/library/eden/event.php @@ -0,0 +1,225 @@ + +/* + * 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__).'/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 + * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ + */ +class Eden_Event extends Eden_Class { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_observers = array(); + + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function get() { + return self::_getMultiple(__CLASS__); + } + + /* Magic + -------------------------------*/ + /* Public Methods + -------------------------------*/ + /** + * Attaches an instance to be notified + * when an event has been triggered + * + * @param *string + * @param *string|object + * @param string|null + * @param bool + * @return this + */ + public function listen($event, $instance, $method = NULL, $important = true) { + Eden_Event_Error::get() + ->argument(1, 'string') //argument 1 must be string + ->argument(2, 'object', 'string') //argument 2 must be object or string + ->argument(3, 'null', 'string', 'bool') //argument 3 must be string or null + ->argument(4, 'bool'); //argument 4 must be boolean + + //get the instance unique id + $id = is_object($instance) ? spl_object_hash($instance) : false; + + //if method is bool + if(is_bool($method)) { + //this was meant to be impoertant + $important = $method; + } + + //if the method is string + if(is_string($method)) { + //set up a class call + $method = array($instance, $method); + } else { + //instance must be a function call + $method = $instance; + } + + //set up the observer + $observer = array($event, $id, $method); + + //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; + } + + /** + * Stops listening to an event + * + * @param object + * @param string|null + * @return this + */ + public function unlisten($event, $instance, $method = NULL) { + Eden_Event_Error::get() + ->argument(1, 'string', 'null') //argument 1 must be string or null + ->argument(2, 'object', 'string') //argument 2 must be instance + ->argument(3, 'string', 'null'); //argument 3 must be string or null + + $id = false; + $class = $instance; + + //if instance is an object + if(is_object($instance)) { + //set the id + $id = spl_object_hash($instance); + //get the class name + $class = get_class($instance); + } + + + //for each observer + foreach($this->_observers as $i => $observer) { + //if there is an event and event is not being listened to + if(!is_null($event) && $event != $observer[0]) { + //skip it + continue; + } + + //if id is not equal to observer + if($id != $observer[1]) { + //skip it + continue; + } + + //if this is a class call + if(is_array($observer[2])) { + //instance is a string and instance equals class + if(is_string($observer[2][0]) && $observer[2][0] != $class) { + //skip it + continue; + } + + //instance either equals class or is an object + //observer is a function call + } else if($observer[2] != $class) { + //skip it + continue; + } + + //unset it + unset($this->_observers[$i]); + } + + 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::get()->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); + + //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; + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} + +/** + * Event Errors + */ +class Eden_Event_Error extends Eden_Error { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function get($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/eventbrite/base.php b/library/eden/eventbrite/base.php new file mode 100644 index 0000000..ca217fa --- /dev/null +++ b/library/eden/eventbrite/base.php @@ -0,0 +1,126 @@ + +/* + * 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. + */ + +/** + * Eventbrite oauth + * + * @package Eden + * @category google + * @author Christian Blanquera + * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ + */ +class Eden_Eventbrite_Base extends Eden_Class { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_user = NULL; + protected $_api = NULL; + protected $_meta = array(); + + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function get($user, $api) { + return self::_getMultiple(__CLASS__, $user, $api); + } + + /* Magic + -------------------------------*/ + public function __construct($user, $api) { + //argument test + Eden_Google_Error::get() + ->argument(1, 'string','array') //Argument 1 must be a string or array + ->argument(2, 'string'); //Argument 2 must be a string + + $this->_api = $api; + $this->_user = $user; + } + + /* Public Methods + -------------------------------*/ + /** + * Returns the meta of the last call + * + * @return array + */ + public function getMeta($key = NULL) { + Eden_Google_Error::get()->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($reponse, true); + } + + protected function _getXmlResponse($url, array $query = array()) { + $response = $this->_getResponse($url, $query); + return simplexml_load_string($reponse); + } + + protected function _getResponse($url, array $query = array()) { + $headers = array(); + $headers[] = 'Content-Type: application/json'; + + $query['app_key'] = $this->_api; + if(is_array($this->_user)) { + $query['user'] = $this->_user[0]; + $query['password'] = $this->_user[1]; + } else { + $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::get() + ->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; + } + + /* 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..2e197d3 --- /dev/null +++ b/library/eden/eventbrite/discount.php @@ -0,0 +1,128 @@ + +/* + * 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. + */ + +/** + * Eventbrite new or update discount + * + * @package Eden + * @category eventbrite + * @author Christian Blanquera + * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ + */ +class Eden_Eventbrite_Event_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 + -------------------------------*/ + /* Get + -------------------------------*/ + public static function get($user, $api) { + return self::_getMultiple(__CLASS__, $user, $api); + } + + /* Magic + -------------------------------*/ + /* Public Methods + -------------------------------*/ + public function add($event, $code, $amount, $percent, $tickets, $quantity, $start, $end) { + //Argument Test + Eden_Eventbrite_Error::get() + ->argument(1, 'int') //Argument 1 must be an integer + ->argument(2, 'string') //Argument 2 must be a string + ->argument(3, 'float') //Argument 3 must be a float + ->argument(4, 'float') //Argument 4 must be a float + ->argument(5, 'string', 'array') //Argument 5 must be a string or array + ->argument(6, 'int') //Argument 6 must be an array + ->argument(7, 'string') //Argument 7 must be a string + ->argument(8, 'string'); //Argument 8 must be a string + + if(is_array($tickets)) { + $tickets = implode(',', $tickets); + } + + if(is_string($start)) { + $start = strtotime($start); + } + + $start = date('Y-m-d H:i:s', $start); + + if(is_string($end)) { + $end = strtotime($end); + } + + $end = date('Y-m-d H:i:s', $end); + + $query = array( + 'event_id' => $event, + 'code' => $code, + 'amount_off' => $amount, + 'percent_off' => $percent, + 'tickets' => $tickets, + 'quantity_available' => $quantity, + 'start_date' => $start, + 'end_date' => $end); + + return $this->_getJsonResponse(self::URL_NEW, $query); + } + + public function update($id, $code, $amount, $percent, $tickets, $quantity, $start, $end) { + //Argument Test + Eden_Eventbrite_Error::get() + ->argument(1, 'int') //Argument 1 must be an integer + ->argument(2, 'string') //Argument 2 must be a string + ->argument(3, 'float') //Argument 3 must be a float + ->argument(4, 'float') //Argument 4 must be a float + ->argument(5, 'string', 'array') //Argument 5 must be a string or array + ->argument(6, 'int') //Argument 6 must be an array + ->argument(7, 'string') //Argument 7 must be a string + ->argument(8, 'string'); //Argument 8 must be a string + + if(is_array($tickets)) { + $tickets = implode(',', $tickets); + } + + if(is_string($start)) { + $start = strtotime($start); + } + + $start = date('Y-m-d H:i:s', $start); + + if(is_string($end)) { + $end = strtotime($end); + } + + $end = date('Y-m-d H:i:s', $end); + + $query = array( + 'id' => $id, + 'code' => $code, + 'amount_off' => $amount, + 'percent_off' => $percent, + 'tickets' => $tickets, + 'quantity_available' => $quantity, + 'start_date' => $start, + 'end_date' => $end); + + 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..fe5f0b6 --- /dev/null +++ b/library/eden/eventbrite/error.php @@ -0,0 +1,54 @@ + +/* + * 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. + */ + +/** + * Eventbrite Errors + * + * @package Eden + * @category google + * @author Christian Blanquera + * @version $Id: exception.php 1 2010-01-02 23:06:36Z blanquera $ + */ +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()'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function get($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/eventbrite/event.php b/library/eden/eventbrite/event.php new file mode 100644 index 0000000..0556364 --- /dev/null +++ b/library/eden/eventbrite/event.php @@ -0,0 +1,99 @@ + +/* + * 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. + */ + +/** + * Google calendar + * + * @package Eden + * @category google + * @author Christian Blanquera + * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ + */ +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 + -------------------------------*/ + /* Get + -------------------------------*/ + public static function get($user, $api) { + return self::_getMultiple(__CLASS__, $user, $api); + } + + /* Magic + -------------------------------*/ + /* Public Methods + -------------------------------*/ + public function copy($id, $name) { + //argument test + Eden_Eventbrite_Error::get() + ->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); + } + + public function getDetail($id) { + //Argument 1 must be numeric + Eden_Eventbrite_Error::get()->argument(1, 'numeric'); + + $query = array('id' => $id); + + return $this->_getJsonResponse(self::URL_GET, $query); + } + + public function getAttendees($id, $count = 50, $page = 1, $display = NULL, $barcodes = false) { + //argument test + $error = Eden_Eventbrite_Error::get() + ->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); + } + + public function getDiscounts($id) { + //Argument 1 must be numeric + Eden_Eventbrite_Error::get()->argument(1, 'numeric'); + + $query = array('id' => $id); + + return $this->_getJsonResponse(self::URL_LIST_DISCOUNTS, $query); + } + + /* 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..ae3f758 --- /dev/null +++ b/library/eden/eventbrite/event/search.php @@ -0,0 +1,245 @@ + +/* + * 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. + */ + +/** + * Eventbrite search + * + * @package Eden + * @category eventbrite + * @author Christian Blanquera + * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ + */ +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 + -------------------------------*/ + /* Get + -------------------------------*/ + public static function get($user, $api) { + return self::_getMultiple(__CLASS__, $user, $api); + } + + /* Magic + -------------------------------*/ + /* Public Methods + -------------------------------*/ + public function setKeywords($keywords) { + //Argument 1 must be a string + Eden_Eventbrite_Error::get()->argument(1, 'string'); + + $query['keywords'] = $keywords; + + return $this; + } + + public function setCategory($category) { + //Argument 1 must be a string or array + Eden_Eventbrite_Error::get()->argument(1, 'string', 'array'); + + if(is_array($tickets)) { + $tickets = implode(',', $tickets); + } + + $query['category'] = $category; + + return $this; + } + + public function setAddress($address) { + //Argument 1 must be a string + Eden_Eventbrite_Error::get()->argument(1, 'string'); + + $query['address'] = $address; + + return $this; + } + + public function setCity($city) { + //Argument 1 must be a string + Eden_Eventbrite_Error::get()->argument(1, 'string'); + + $query['city'] = $city; + + return $this; + } + + public function setRegion($region) { + //Argument 1 must be a string + Eden_Eventbrite_Error::get()->argument(1, 'string'); + + $query['region'] = $region; + + return $this; + } + + public function setPostal($postal) { + //Argument 1 must be a string or integer + Eden_Eventbrite_Error::get()->argument(1, 'string', 'int'); + + $query['postal_code'] = $postal; + + return $this; + } + + public function setCountry($country) { + //Argument 1 must be a string + Eden_Eventbrite_Error::get()->argument(1, 'string'); + + $query['country'] = $country; + + return $this; + } + + public function setWithin($within) { + //Argument 1 must be a int + Eden_Eventbrite_Error::get()->argument(1, 'int'); + + $query['within'] = $within; + + return $this; + } + + public function setWithinUnit($unit) { + //Argument 1 must be a string + Eden_Eventbrite_Error::get()->argument(1, 'string'); + + $query['within_unit'] = $unit; + + return $this; + } + + public function setLatitude($latitude) { + //Argument 1 must be a float + Eden_Eventbrite_Error::get()->argument(1, 'float'); + + $query['latitude'] = $latitude; + + return $this; + } + + public function setLongitude($longitude) { + //Argument 1 must be a float + Eden_Eventbrite_Error::get()->argument(1, 'float'); + + $query['longitude'] = $longitude; + + return $this; + } + + public function setDate($date) { + //Argument 1 must be a string + Eden_Eventbrite_Error::get()->argument(1, 'string'); + + $query['date'] = $date; + + return $this; + } + + public function setDateCreated($date) { + //Argument 1 must be a string + Eden_Eventbrite_Error::get()->argument(1, 'string'); + + $query['date_created'] = $date; + + return $this; + } + + public function setDateModified($date) { + //Argument 1 must be a string + Eden_Eventbrite_Error::get()->argument(1, 'string'); + + $query['date_modified'] = $date; + + return $this; + } + + public function setOrganizer($organizer) { + //Argument 1 must be a string + Eden_Eventbrite_Error::get()->argument(1, 'string'); + + $query['organizer'] = $organizer; + + return $this; + } + + public function setMax($max) { + //Argument 1 must be a int + Eden_Eventbrite_Error::get()->argument(1, 'int'); + + if($max > 100) { + $max = 100; + } + + $query['max'] = $max; + + return $this; + } + + public function countOnly() { + $query['count_only'] = 'true'; + + return $this; + } + + public function sort($column) { + //Argument 1 must be a string + Eden_Eventbrite_Error::get()->argument(1, 'string'); + + if(in_array($column, $this->_validSort)) { + $query['sort_by'] = $column; + } + + return $this; + } + + public function setPage($page) { + //Argument 1 must be a int + Eden_Eventbrite_Error::get()->argument(1, 'int'); + + $query['page'] = $page; + + return $this; + } + + public function setSince($since) { + //Argument 1 must be a int + Eden_Eventbrite_Error::get()->argument(1, 'int'); + + $query['since_id'] = $since; + + return $this; + } + + public function setTracking($tracking) { + //Argument 1 must be a string + Eden_Eventbrite_Error::get()->argument(1, 'string'); + + $query['tracking_link'] = $tracking; + + return $this; + } + + public function send() { + return $this->_getJsonResponse(self::URL, $this->_query); + } + + /* 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..d66e60c --- /dev/null +++ b/library/eden/eventbrite/event/set.php @@ -0,0 +1,328 @@ + +/* + * 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. + */ + +/** + * Eventbrite new or update event + * + * @package Eden + * @category eventbrite + * @author Christian Blanquera + * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ + */ +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'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_query = array(); + + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function get($user, $api) { + return self::_getMultiple(__CLASS__, $user, $api); + } + + /* Magic + -------------------------------*/ + /* Public Methods + -------------------------------*/ + public function setId($id) { + //Argument 1 must be int + Eden_Eventbrite_Error::get()->argument(1, 'int'); + + $query['event_id'] = $id; + + return $this; + } + + public function setTitle($title) { + //Argument 1 must be a string + Eden_Eventbrite_Error::get()->argument(1, 'string'); + + $query['title'] = $title; + + return $this; + } + + public function setDescription($description) { + //Argument 1 must be a string + Eden_Eventbrite_Error::get()->argument(1, 'string'); + + $query['description'] = $description; + + return $this; + } + + public function setStart($start) { + //Argument 1 must be a string + Eden_Eventbrite_Error::get()->argument(1, 'string', 'int'); + + if(is_string($start)) { + $start = strtotime($start); + } + + $start = date('Y-m-d H:i:s', $start); + + $query['start_date'] = $start; + + return $this; + } + + public function setEnd($end) { + //Argument 1 must be a string + Eden_Eventbrite_Error::get()->argument(1, 'string', 'int'); + + if(is_string($end)) { + $end = strtotime($end); + } + + $end = date('Y-m-d H:i:s', $end); + + $query['end_date'] = $end; + + return $this; + } + + public function setTimezone($zone) { + //Argument 1 must be a string + Eden_Eventbrite_Error::get()->argument(1, 'string'); + + $query['timezone'] = $zone; + + return $this; + } + + public function isPublic() { + $query['privacy'] = 1; + + return $this; + } + + public function isPrivate() { + $query['privacy'] = 0; + + return $this; + } + + public function setUrl($url) { + //Argument 1 must be a string + Eden_Eventbrite_Error::get()->argument(1, 'string'); + + $query['personalized_url'] = $url; + + return $this; + } + + public function setVenue($venue) { + //Argument 1 must be a numeric + Eden_Eventbrite_Error::get()->argument(1, 'numeric'); + + $query['venue_id'] = $venue; + + return $this; + } + + public function setOrganizer($organizer) { + //Argument 1 must be a numeric + Eden_Eventbrite_Error::get()->argument(1, 'numeric'); + + $query['organizer_id'] = $organizer; + + return $this; + } + + public function setCapacity($capacity) { + //Argument 1 must be a numeric + Eden_Eventbrite_Error::get()->argument(1, 'numeric'); + + $query['capacity'] = $capacity; + + return $this; + } + + public function setCurrency($currency) { + //Argument 1 must be a string + Eden_Eventbrite_Error::get()->argument(1, 'string'); + + $query['currency'] = $currency; + + return $this; + } + + public function setStatus($status) { + //Argument 1 must be a string + Eden_Eventbrite_Error::get()->argument(1, 'string'); + + $query['status'] = $status; + + return $this; + } + + public function setHeader($html) { + //Argument 1 must be a string + Eden_Eventbrite_Error::get()->argument(1, 'string'); + + $query['custom_header'] = $html; + + return $this; + } + + public function setFooter($html) { + //Argument 1 must be a string + Eden_Eventbrite_Error::get()->argument(1, 'string'); + + $query['custom_footer'] = $html; + + return $this; + } + + public function setBackground($color) { + //Argument 1 must be a string + Eden_Eventbrite_Error::get()->argument(1, 'string'); + + $query['background_color'] = $color; + + return $this; + } + + public function setTextColor($color) { + //Argument 1 must be a string + Eden_Eventbrite_Error::get()->argument(1, 'string'); + + $query['text_color'] = $color; + + return $this; + } + + public function setLinkColor($color) { + //Argument 1 must be a string + Eden_Eventbrite_Error::get()->argument(1, 'string'); + + $query['link_color'] = $color; + + return $this; + } + + public function setTitleColor($color) { + //Argument 1 must be a string + Eden_Eventbrite_Error::get()->argument(1, 'string'); + + $query['title_text_color'] = $color; + + return $this; + } + + public function setBoxBackground($color) { + //Argument 1 must be a string + Eden_Eventbrite_Error::get()->argument(1, 'string'); + + $query['box_background_color'] = $color; + + return $this; + } + + public function setBoxColor($color) { + //Argument 1 must be a string + Eden_Eventbrite_Error::get()->argument(1, 'string'); + + $query['box_text_color'] = $color; + + return $this; + } + + public function setBorderColor($color) { + //Argument 1 must be a string + Eden_Eventbrite_Error::get()->argument(1, 'string'); + + $query['box_border_color'] = $color; + + return $this; + } + + public function setHeaderBackground($color) { + //Argument 1 must be a string + Eden_Eventbrite_Error::get()->argument(1, 'string'); + + $query['box_header_background_color'] = $color; + + return $this; + } + + public function setHeaderColor($color) { + //Argument 1 must be a string + Eden_Eventbrite_Error::get()->argument(1, 'string'); + + $query['box_header_text_color'] = $color; + + return $this; + } + + public function send() { + if(!isset($this->_query['title'])) { + Eden_Eventbrite_Error::get()->setMessage(Eden_Eventbrite_Error::TITLE_NOT_SET)->trigger(); + } + + if(!isset($this->_query['start_date'])) { + Eden_Eventbrite_Error::get()->setMessage(Eden_Eventbrite_Error::START_NOT_SET)->trigger(); + } + + + if(!isset($this->_query['end_date'])) { + Eden_Eventbrite_Error::get()->setMessage(Eden_Eventbrite_Error::END_NOT_SET)->trigger(); + } + + if(!isset($this->_query['timezone'])) { + Eden_Eventbrite_Error::get()->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::get()->setMessage(Eden_Eventbrite_Error::PRIVACY_NOT_SET)->trigger(); + } + + if(!isset($this->_query['personalized_url'])) { + Eden_Eventbrite_Error::get()->setMessage(Eden_Eventbrite_Error::URL_NOT_SET)->trigger(); + } + + if(!isset($this->_query['organizer_id'])) { + Eden_Eventbrite_Error::get()->setMessage(Eden_Eventbrite_Error::ORGANIZER_NOT_SET)->trigger(); + } + + if(!isset($this->_query['venue_id'])) { + Eden_Eventbrite_Error::get()->setMessage(Eden_Eventbrite_Error::VENUE_NOT_SET)->trigger(); + } + + if(!isset($this->_query['capacity'])) { + Eden_Eventbrite_Error::get()->setMessage(Eden_Eventbrite_Error::CAPACITY_NOT_SET)->trigger(); + } + + if(!isset($this->_query['currency'])) { + Eden_Eventbrite_Error::get()->setMessage(Eden_Eventbrite_Error::CURRENCY_NOT_SET)->trigger(); + } + } + + return $this->_getJsonResponse($url, $this->_query); + } + + /* 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..6c2ba5b --- /dev/null +++ b/library/eden/eventbrite/organizer.php @@ -0,0 +1,82 @@ + +/* + * 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. + */ + +/** + * Eventbrite Organizer + * + * @package Eden + * @category eventbrite + * @author Christian Blanquera + * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ + */ +class Eden_Eventbrite_Event_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 + -------------------------------*/ + /* Get + -------------------------------*/ + public static function get($user, $api) { + return self::_getMultiple(__CLASS__, $user, $api); + } + + /* Magic + -------------------------------*/ + /* Public Methods + -------------------------------*/ + public function add($name, $description = NULL) { + //Argument Test + Eden_Eventbrite_Error::get() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'string'); //Argument 2 must be a string + + $query = array( + 'name' => $name, + 'description' => $description); + + return $this->_getJsonResponse(self::URL_NEW, $query); + } + + public function update($id, $name, $description = NULL) { + //Argument Test + Eden_Eventbrite_Error::get() + ->argument(1, 'int') //Argument 1 must be an integer + ->argument(2, 'string') //Argument 2 must be a string + ->argument(3, 'string'); //Argument 3 must be a string + + $query = array( + 'id' => $id, + 'name' => $name, + 'description' => $description); + + return $this->_getJsonResponse(self::URL_UPDATE, $query); + } + + public function getEvents($id) { + //Argument 1 must be an int + Eden_Eventbrite_Error::get()->argument(1, 'int'); + + $query = array('id' => $id); + + return $this->_getJsonResponse(self::URL_EVENTS, $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..2080994 --- /dev/null +++ b/library/eden/eventbrite/payment.php @@ -0,0 +1,142 @@ + +/* + * 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. + */ + +/** + * Eventbrite payment + * + * @package Eden + * @category eventbrite + * @author Christian Blanquera + * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ + */ +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 + -------------------------------*/ + /* Get + -------------------------------*/ + public static function get($user, $api) { + return self::_getMultiple(__CLASS__, $user, $api); + } + + /* Magic + -------------------------------*/ + /* Public Methods + -------------------------------*/ + public function setEvent($id) { + //Argument 1 must be int + Eden_Eventbrite_Error::get()->argument(1, 'int'); + + $query['event_id'] = $id; + + return $this; + } + + public function acceptPaypal() { + $query['accept_paypal'] = 1; + + return $this; + } + + public function setPaypalEmail($email) { + //Argument 1 must be a string + Eden_Eventbrite_Error::get()->argument(1, 'string'); + + $query['paypal_email'] = $email; + + return $this; + } + + public function acceptGoogle() { + $query['accept_google'] = 1; + + return $this; + } + + public function setGoogleMerchantId($id) { + //Argument 1 must be a string + Eden_Eventbrite_Error::get()->argument(1, 'string'); + + $query['google_merchant_id'] = $id; + + return $this; + } + + public function setGoogleMerchantKey($key) { + //Argument 1 must be a string + Eden_Eventbrite_Error::get()->argument(1, 'string'); + + $query['google_merchant_key'] = $key; + + return $this; + } + + public function acceptCheck() { + $query['accept_check'] = 1; + + return $this; + } + + public function setCheckInstructions($check) { + //Argument 1 must be a string + Eden_Eventbrite_Error::get()->argument(1, 'string'); + + $query['insrtructions_check'] = $check; + + return $this; + } + + public function acceptCash() { + $query['accept_check'] = 1; + + return $this; + } + + public function setCashInstructions($check) { + //Argument 1 must be a string + Eden_Eventbrite_Error::get()->argument(1, 'string'); + + $query['insrtructions_cash'] = $check; + + return $this; + } + + public function acceptInovice() { + $query['accept_invoice'] = 1; + + return $this; + } + + public function setInvoiceInstructions($check) { + //Argument 1 must be a string + Eden_Eventbrite_Error::get()->argument(1, 'string'); + + $query['insrtructions_invoice'] = $check; + + return $this; + } + + public function send() { + 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..baec7d6 --- /dev/null +++ b/library/eden/eventbrite/ticket.php @@ -0,0 +1,10 @@ + + + + +Untitled Document + + + + + \ No newline at end of file diff --git a/library/eden/eventbrite/user.php b/library/eden/eventbrite/user.php new file mode 100644 index 0000000..baec7d6 --- /dev/null +++ b/library/eden/eventbrite/user.php @@ -0,0 +1,10 @@ + + + + +Untitled Document + + + + + \ 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..baec7d6 --- /dev/null +++ b/library/eden/eventbrite/venue.php @@ -0,0 +1,10 @@ + + + + +Untitled Document + + + + + \ 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..619a130 --- /dev/null +++ b/library/eden/facebook/auth.php @@ -0,0 +1,96 @@ + +/* + * 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.st. + */ + +/** + * Facebook Authentication + * + * @package Eden + * @subpackage file + * @category path + * @author Christian Blanquera + * @version $Id: model.php 4 2010-01-06 04:41:07Z blanquera $ + */ +class Eden_Facebook_Auth extends Eden_Class { + /* Constants + -------------------------------*/ + const AUTHENTICATION_USER_URL = 'https://www.facebook.com/dialog/oauth'; + const AUTHENTICATION_APP_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; + + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function get($key, $secret) { + return self::_getMultiple(__CLASS__, $key, $secret); + } + + /* Magic + -------------------------------*/ + public function __construct($key, $secret) { + $this->_key = $key; + $this->_secret = $secret; + } + + /* Public Methods + -------------------------------*/ + public function getLoginUrl($redirect, array $scope = array(), $state = NULL) { + $parameters = array( + 'client_id' => $this->_key, + 'redirect_uri' => $redirect, + 'scope' => implode(',',$scope), + 'state' => $state); + + if(empty($scope)) { + unset($parameters['scope']); + } + + if(!$state) { + unset($parameters['state']); + } + + $parameters = http_build_query($parameters); + + return self::AUTHENTICATION_USER_URL.'?'.$parameters; + } + + public function getToken($code, $redirect) { + $parameters = array( + 'client_id' => $this->_key, + 'client_secret' => $this->_secret, + 'redirect_uri' => $redirect, + 'code' => $code); + + $parameters = http_build_query($parameters); + $url = self::AUTHENTICATION_APP_URL.'?'.$parameters; + + $response = Eden_Curl::get() + ->setUrl($url) + ->setConnectTimeout(10) + ->setTimeout(60) + ->setUserAgent(self::USER_AGENT) + ->setHeaders('Expect') + ->verifyPeer(false) + ->getQueryResponse(); + + return $response['access_token']; + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ 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..997fd08 --- /dev/null +++ b/library/eden/facebook/error.php @@ -0,0 +1,42 @@ + +/* + * 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. + */ + +/** + * Facebook Errors + * + * @package Eden + * @subpackage facebook + * @category path + * @author Christian Blanquera + * @version $Id: exception.php 1 2010-01-02 23:06:36Z blanquera $ + */ +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/graph.php b/library/eden/facebook/graph.php new file mode 100644 index 0000000..cf759c4 --- /dev/null +++ b/library/eden/facebook/graph.php @@ -0,0 +1,534 @@ + +/* + * 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.st. + */ + +/** + * Facebook Authentication + * + * @package Eden + * @subpackage file + * @category path + * @author Christian Blanquera + * @version $Id: model.php 4 2010-01-06 04:41:07Z blanquera $ + */ +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; + + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function get($token) { + return self::_getMultiple(__CLASS__, $token); + } + + /* Magic + -------------------------------*/ + public function __construct($token) { + $this->_token = $token; + } + + /* Public Methods + -------------------------------*/ + public function getObject($id = 'me', $connection = NULL, array $query = array(), $auth = true) { + if($connection) { + $connection = '/'.$connection; + } + + $url = self::GRAPH_URL.$id.$connection; + + if($auth) { + if(!$this->_token) { + throw new Eden_Facebook_Exception(sprintf(Eden_Facebook_Exception::REQUIRES_AUTH, $url)); + } + + $query['access_token'] = $this->_token; + } + + if(!empty($query)) { + $url .= '?'.http_build_query($query); + } + + $object = $this->_call($url); + $object = json_decode($object, true); + + if (isset($object['error'])) { + throw new Eden_Facebook_Exception(sprintf( + Eden_Facebook_Exception::GRAPH_FAILED, + $url, $object['error']['type'], + $object['error']['message'])); + } + + return $object; + } + + public function getFields($id = 'me', $fields) { + if(is_array($fields)) { + $fields = implode(',', $fields); + } + + return $this->getObject($id, NULL, array('fields' => $fields)); + } + + public function getUser() { + return $this->getObject('me'); + } + + public function getPictureUrl($id = 'me', $token = true) { + $url = self::GRAPH_URL.$id.'/picture'; + + if($token) { + $url .= '?access_token='.$this->_token; + } + + return $url; + } + + public function getLogoutUrl($redirect) { + return sprintf(self::LOGOUT_URL, urlencode($redirect), $this->_token); + } + + public function getFriends($id = 'me', $start = 0, $range = 0, $since = 0, $until = 0, $dateFormat = NULL) { + return $this->_getList($id, 'friends', $start, $range, $since, $until, $dateFormat); + } + + public function getNews($id = 'me', $start = 0, $range = 0, $since = 0, $until = 0, $dateFormat = NULL) { + return $this->_getList($id, 'home', $start, $range, $since, $until, $dateFormat); + } + + public function getWall($id = 'me', $start = 0, $range = 0, $since = 0, $until = 0, $dateFormat = NULL) { + return $this->_getList($id, 'wall', $start, $range, $since, $until, $dateFormat); + } + + public function getLikes($id = 'me', $start = 0, $range = 0, $since = 0, $until = 0, $dateFormat = NULL) { + return $this->_getList($id, 'likes', $start, $range, $since, $until, $dateFormat); + } + + public function getMovies($id = 'me', $start = 0, $range = 0, $since = 0, $until = 0, $dateFormat = NULL) { + return $this->_getList($id, 'movies', $start, $range, $since, $until, $dateFormat); + } + + public function getMusic($id = 'me', $start = 0, $range = 0, $since = 0, $until = 0, $dateFormat = NULL) { + return $this->_getList($id, 'music', $start, $range, $since, $until, $dateFormat); + } + + public function getBooks($id = 'me', $start = 0, $range = 0, $since = 0, $until = 0, $dateFormat = NULL) { + return $this->_getList($id, 'books', $start, $range, $since, $until, $dateFormat); + } + + public function getPermissions($id = 'me') { + $permissions = $this->getObject($id, 'permissions'); + return $permissions['data']; + } + + public function getPhotos($id = 'me', $start = 0, $range = 0, $since = 0, $until = 0, $dateFormat = NULL) { + return $this->_getList($id, 'photos', $start, $range, $since, $until, $dateFormat); + } + + public function getAlbums($id = 'me', $start = 0, $range = 0, $since = 0, $until = 0, $dateFormat = NULL) { + return $this->_getList($id, 'albums', $start, $range, $since, $until, $dateFormat); + } + + public function getVideos($id = 'me', $start = 0, $range = 0, $since = 0, $until = 0, $dateFormat = NULL) { + return $this->_getList($id, 'videos', $start, $range, $since, $until, $dateFormat); + } + + public function getVideoUploads($id = 'me', $start = 0, $range = 0, $since = 0, $until = 0, $dateFormat = NULL) { + return $this->_getList($id, 'videos/uploaded', $start, $range, $since, $until, $dateFormat); + } + + public function getEvents($id = 'me', $start = 0, $range = 0, $since = 0, $until = 0, $dateFormat = NULL) { + return $this->_getList($id, 'events', $start, $range, $since, $until, $dateFormat); + } + + public function getGroups($id = 'me', $start = 0, $range = 0, $since = 0, $until = 0, $dateFormat = NULL) { + return $this->_getList($id, 'groups', $start, $range, $since, $until, $dateFormat); + } + + public function getCheckIns($id = 'me', $start = 0, $range = 0, $since = 0, $until = 0, $dateFormat = NULL) { + return $this->_getList($id, 'checkins', $start, $range, $since, $until, $dateFormat); + } + + public function searchPosts($query, $fields = NULL) { + return $this->_search('post', $query, $fields); + } + + public function searchUsers($query, $fields = NULL) { + return $this->_search('user', $query, $fields); + } + + public function searchPages($query, $fields = NULL) { + return $this->_search('page', $query, $fields); + } + + public function searchEvents($query, $fields = NULL) { + return $this->_search('event', $query, $fields); + } + + public function searchGroups($query, $fields = NULL) { + return $this->_search('group', $query, $fields); + } + + public function searchPlaces($query, $fields = NULL) { + return $this->_search('place', $query, $fields); + } + + public function searchCheckins($query, $fields = NULL) { + return $this->_search('checkin', $query, $fields); + } + + public function addPost($message, $id = 'me', $link = NULL, $picture = NULL, + $video = NULL, $caption = NULL, $linkName = NULL, $linkDescription = NULL) { + + if(!$this->_token) { + throw new Eden_Facebook_Exception(sprintf(Eden_Facebook_Exception::REQUIRES_AUTH, $url)); + } + + $post = array('message' => $message); + + if($link) { + $post['link'] = $link; + } + + if($picture) { + $post['picture'] = $picture; + } + + if($video) { + $post['source'] = $video; + } + + if($caption) { + $post['caption'] = $caption; + } + + if($linkName) { + $post['name'] = $linkName; + } + + if($linkDescription) { + $post['description'] = $linkDescription; + } + + $url = self::GRAPH_URL.$id.'/feed'; + + $query = array('access_token' => $this->_token); + + if(!empty($query)) { + $url .= '?'.http_build_query($query); + } + + $results = json_decode($this->_call($url, $post), true); + return $results['id']; + } + + public function addComment($id, $message) { + if(!$this->_token) { + throw new Eden_Facebook_Exception(sprintf(Eden_Facebook_Exception::REQUIRES_AUTH, $url)); + } + + $post = array('message' => $message); + + $url = self::GRAPH_URL.$id.'/comments'; + + $query = array('access_token' => $this->_token); + + if(!empty($query)) { + $url .= '?'.http_build_query($query); + } + + $results = json_decode($this->_call($url, $post), true); + return $results['id']; + } + + public function like($id) { + if(!$this->_token) { + throw new Eden_Facebook_Exception(sprintf(Eden_Facebook_Exception::REQUIRES_AUTH, $url)); + } + + $url = self::GRAPH_URL.$id.'/likes'; + + $query = array('access_token' => $this->_token); + + if(!empty($query)) { + $url .= '?'.http_build_query($query); + } + + $this->_call($url); + + return $this; + } + + public function addNote($id, $subject, $message) { + if(!$this->_token) { + throw new Eden_Facebook_Exception(sprintf(Eden_Facebook_Exception::REQUIRES_AUTH, $url)); + } + + $post = array('subject' => $subject, 'message' => $message); + + $url = self::GRAPH_URL.$id.'/notes'; + + $query = array('access_token' => $this->_token); + + if(!empty($query)) { + $url .= '?'.http_build_query($query); + } + + $results = json_decode($this->_call($url, $post), true); + return $results['id']; + } + + public function addEvent($name, $start, $end) { + if(!$this->_token) { + throw new Eden_Facebook_Exception(sprintf(Eden_Facebook_Exception::REQUIRES_AUTH, $url)); + } + + $post = array('name'=>$name,'start_time'=>$start,'end_time'=>$end); + + $url = self::GRAPH_URL.$id.'/events'; + + $query = array('access_token' => $this->_token); + + if(!empty($query)) { + $url .= '?'.http_build_query($query); + } + + $results = json_decode($this->_call($url, $post), true); + return $results['id']; + } + + public function attendEvent($id) { + if(!$this->_token) { + throw new Eden_Facebook_Exception(sprintf(Eden_Facebook_Exception::REQUIRES_AUTH, $url)); + } + + $url = self::GRAPH_URL.$id.'/attending'; + + $query = array('access_token' => $this->_token); + + if(!empty($query)) { + $url .= '?'.http_build_query($query); + } + + json_decode($this->_call($url), true); + + return $this; + } + + public function maybeEvent($id) { + if(!$this->_token) { + throw new Eden_Facebook_Exception(sprintf(Eden_Facebook_Exception::REQUIRES_AUTH, $url)); + } + + $url = self::GRAPH_URL.$id.'/maybe'; + + $query = array('access_token' => $this->_token); + + if(!empty($query)) { + $url .= '?'.http_build_query($query); + } + + json_decode($this->_call($url), true); + + return $this; + } + + public function declineEvent($id) { + if(!$this->_token) { + throw new Eden_Facebook_Exception(sprintf(Eden_Facebook_Exception::REQUIRES_AUTH, $url)); + } + + $url = self::GRAPH_URL.$id.'/declined'; + + $query = array('access_token' => $this->_token); + + if(!empty($query)) { + $url .= '?'.http_build_query($query); + } + + json_decode($this->_call($url), true); + + return $this; + } + + public function addLink($id, $url, $message = NULL, $name = NULL, $description = NULL, $picture = NULL, $caption = NULL) { + if(!$this->_token) { + throw new Eden_Facebook_Exception(sprintf(Eden_Facebook_Exception::REQUIRES_AUTH, $url)); + } + + $post = array('url' => $url); + + if($message) { + $post['message'] = $message; + } + + if($name) { + $post['name'] = $name; + } + + if($description) { + $post['description'] = $description; + } + + if($picture) { + $post['picture'] = $picture; + } + + if($caption) { + $post['caption'] = $caption; + } + + $url = self::GRAPH_URL.$id.'/links'; + + $query = array('access_token' => $this->_token); + + if(!empty($query)) { + $url .= '?'.http_build_query($query); + } + + $results = json_decode($this->_call($url, $post), true); + return $results['id']; + } + + public function addAlbum($id, $name, $message) { + if(!$this->_token) { + throw new Eden_Facebook_Exception(sprintf(Eden_Facebook_Exception::REQUIRES_AUTH, $url)); + } + + $post = array('name'=>$name,'message'=>$message); + + $url = self::GRAPH_URL.$id.'/albums'; + + $query = array('access_token' => $this->_token); + + if(!empty($query)) { + $url .= '?'.http_build_query($query); + } + + $results = json_decode($this->_call($url, $post), true); + return $results['id']; + } + + public function addPhoto($id, $data) {} + + public function addCheckin($id, $message, $coordinates, $place, $tags) { + if(!$this->_token) { + throw new Eden_Facebook_Exception(sprintf(Eden_Facebook_Exception::REQUIRES_AUTH, $url)); + } + + $post = array('message' => $message); + + if($message) { + $post['message'] = $message; + } + + if($coordinates) { + $post['coordinates'] = $coordinates; + } + + if($place) { + $post['place'] = $place; + } + + if($tags) { + $post['tags'] = $tags; + } + + $url = self::GRAPH_URL.$id.'/checkins'; + + $query = array('access_token' => $this->_token); + + if(!empty($query)) { + $url .= '?'.http_build_query($query); + } + + $results = json_decode($this->_call($url, $post), true); + return $results['id']; + } + + /* Protected Methods + -------------------------------*/ + protected function _call($url, array $post = array()) { + //Argument 1 must be a string + Eden_Curl_Error::get()->argument(1, 'string'); + + return Eden_Curl::get() + ->setUrl($url) + ->setConnectTimeout(10) + ->setFollowLocation(true) + ->setTimeout(60) + ->verifyPeer(false) + ->setUserAgent(Eden_Facebook_Auth::USER_AGENT) + ->setHeaders('Expect') + ->when(!empty($post)) + ->setPost(true) + ->setPostFields(http_build_query($post)) + ->endWhen() + ->getResponse(); + + } + + protected function _getList($id, $connection, $start, $range, $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) { + $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/post.php b/library/eden/facebook/post.php new file mode 100644 index 0000000..50baaab --- /dev/null +++ b/library/eden/facebook/post.php @@ -0,0 +1,207 @@ + +/* + * 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. + */ + +/** + * Facebook post + * + * @package Eden + * @category facebook + * @author Christian Blanquera + * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ + */ +class Eden_Facebook_Post extends Eden_Class { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_token = NULL; + protected $_message = NULL; + protected $_link = NULL; + protected $_picture = NULL; + protected $_video = NULL; + protected $_title = NULL; + protected $_description = NULL; + protected $_icon = NULL; + + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function get($token) { + return self::_getMultiple(__CLASS__, $token); + } + + /* Magic + -------------------------------*/ + public function __construct($token) { + //Argument 1 must be a string + Eden_Facebook_Error::get()->argument(1, 'string'); + + $this->_token = $token; + } + + /* Public Methods + -------------------------------*/ + /** + * sets the message to your post + * + * @param string + * @return this + */ + public function setMessage($message) { + //Argument 1 must be a string + Eden_Facebook_Error::get()->argument(1, 'string'); + + $this->_message = $message; + return $this; + } + + public function setTitle($title){ + //Argument 1 must be a string + Eden_Facebook_Error::get()->argument(1, 'string'); + + $this->_title = $title; + return $this; + } + + public function setDescription($description){ + //Argument 1 must be a string + Eden_Facebook_Error::get()->argument(1, 'string'); + + $this->_description = $description; + return $this; + } + + public function setIcon($url){ + //Argument 1 must be a string + Eden_Facebook_Error::get()->argument(1, 'string'); + + $this->_icon = $url; + return $this; + } + + /** + * sets the link to your post + * + * @param string + * @param string|null + * @param string|null + * @return this + */ + public function setLink($url) { + //Argument 1 must be a string + Eden_Facebook_Error::get()->argument(1, 'string'); + + $this->_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::get()->argument(1, 'string'); + + $this->_picture = $url; + 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::get()->argument(1, 'string'); + + $this->_video = $url; + return $this; + } + + /** + * sends the post to facebook + * + * @return this + */ + public function send() { + //post variable must be array + $post = array(); + + //if there is a name set it into post + if($this->_title) { + $post['name'] = $this->_title; + } + + if($this->_icon) { + $post['icon'] = $this->_icon; + } + + //if there is a description set it into post + if($this->_description) { + $post['description'] = $this->_description; + } + + //if there is a message set it into post + if($this->_message) { + $post['message'] = $this->_message; + } + + //if there is a link set it into post + if($this->_link) { + $post['link'] = $this->_link; + } + + //if there is a picture set it into post + if($this->_picture) { + $post['picture'] = $this->_picture; + } + + //if there is a video set it into post + if($this->_video) { + $post['source'] = $this->_video; + } + + print_r($post); + + //get the facebook graph url + $url = Eden_Facebook_Graph::GRAPH_URL.$id.'/feed'; + $query = array('access_token' => $this->_token); + $url .= '?'.http_build_query($query); + + //send it into curl + $response = Eden_Curl::get() + ->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 + ->when(!empty($post)) //if post is not empty + ->setPost(true) //set post to true + ->setPostFields(http_build_query($post)) //set post fields + ->endWhen() //endif/endwhen + ->getJsonResponse(); //get the json response + print_r($response); + return $response['id']; //return the id + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/file.php b/library/eden/file.php new file mode 100644 index 0000000..c6abd63 --- /dev/null +++ b/library/eden/file.php @@ -0,0 +1,252 @@ + +/* + * 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__).'/path.php'; +require_once dirname(__FILE__).'/file/error.php'; + +/** + * General available methods for common file + * manipulations and information per file + * + * @package Eden + * @category path + * @author Christian Blanquera + * @version $Id: model.php 4 2010-01-06 04:41:07Z blanquera $ + */ +class Eden_File extends Eden_Path { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_path = NULL; + + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function get($path) { + return self::_getMultiple(__CLASS__, $path); + } + + /* Magic + -------------------------------*/ + /* Public Methods + -------------------------------*/ + /** + * Returns the file name + * + * @return string + */ + public function getName() { + return basename($this->_path); + } + + /** + * Returns the file path + * + * @return string + */ + public function getFolder() { + return dirname($this->_path); + } + + /** + * Returns the base file name with out the extension + * + * @return string + */ + public function getBase() { + $pathInfo = pathinfo($this->_path); + return $pathInfo['filename']; + } + + /** + * Returns the base file name extension + * + * @return string + */ + public function getExtension() { + $pathInfo = pathinfo($this->_path); + + if(!isset($pathInfo['extension'])) { + return NULL; + } + + return $pathInfo['extension']; + } + + /** + * Returns the executes the specified file and returns the final value + * + * @return * + */ + public function getData() { + $this->absolute(); + + return include($path); + } + + /** + * 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($path)) { + //throw an exception + Eden_File_Error::get() + ->setMessage(Eden_File_Error::PATH_IS_NOT_FILE) + ->addVariable($path) + ->trigger(); + } + + return file_get_contents($path); + } + + /** + * 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->_path); + } + + //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->_path); + 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 = include('file/mimetypes.php'); + //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 size of a file in bytes + * + * @return string + */ + public function getSize() { + $this->absolute(); + + return filesize($this->_path); + } + + /** + * Returns the last time file was modified in UNIX time + * + * @return int + */ + public function getTime() { + $this->absolute(); + + return filemtime($this->_path); + } + + /** + * Checks to see if this + * path is a real file + * + * @return bool + */ + public function isFile() { + return file_exists($this->_path); + } + + /** + * 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::get()->argument(1, 'string'); + + $this->absolute(); + + file_put_contents($this->_path, $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).";"); + } + + /** + * 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->_path); + + return $this; + } + + /** + * Removes a file + * + * @return bool + */ + public function remove() { + $this->absolute(); + + //if it's a file + if(is_file($this->_path)) { + //remove it + unlink($this->_path); + + return $this; + } + + return $this; + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/file/error.php b/library/eden/file/error.php new file mode 100755 index 0000000..c8ac5ba --- /dev/null +++ b/library/eden/file/error.php @@ -0,0 +1,44 @@ + +/* + * 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. + */ + +/** + * File Errors + * + * @package Eden + * @category path + * @author Christian Blanquera + * @version $Id: exception.php 1 2010-01-02 23:06:36Z blanquera $ + */ +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 + -------------------------------*/ + /* Get + -------------------------------*/ + public static function get($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/file/mimetypes.php b/library/eden/file/mimetypes.php new file mode 100755 index 0000000..7ef03f8 --- /dev/null +++ b/library/eden/file/mimetypes.php @@ -0,0 +1,173 @@ + +return 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'); \ No newline at end of file diff --git a/library/eden/folder.php b/library/eden/folder.php new file mode 100644 index 0000000..960c350 --- /dev/null +++ b/library/eden/folder.php @@ -0,0 +1,294 @@ + +/* + * 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__).'/path.php'; + +/** + * This is an abstract definition of common + * folder manipulation listing and information + * per folder. + * + * @package Eden + * @category path + * @author Christian Blanquera + * @version $Id: abstract.php 1 2010-01-02 23:06:36Z blanquera $ + */ +class Eden_Folder extends Eden_Path { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function get($path) { + return self::_getMultiple(__CLASS__, $path); + } + + /* Magic + -------------------------------*/ + /* 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 + throw new Eden_Folder_Error(Eden_Folder_Exception::CHMOD_IS_INVALID); + } + + //if it's not a directory + if(!is_dir($this->_path)) { + //then make it + mkdir($this->_path, $chmod, true); + } + + return $this; + } + + /** + * 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 and folder given a path + * + * @return this + */ + public function truncate() { + $this->removeFolders(); + $this->removeFiles(); + + return $this; + } + + + /** + * Returns the name of the directory.. just the name + * + * @return string the name + */ + public function getName() { + $pathArray = $this->getArray(); + return array_pop($pathArray); + } + + /** + * 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::get() + ->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->_path)) { + //for each file + while (false !== ($file = readdir($handle))) { + // If this is infact a file + if(filetype($this->_path . '/' . $file) == 'file' + && (!$regex || preg_match($regex, $file))) { + //add it + $files[] = Eden_File::get($this->_path . '/' . $file); + // recursive and this is infact a directory + } else if($recursive && $file != '.' && $file != '..' + && filetype($this->_path .'/'. $file) == 'dir') { + $subfiles = self::get($this->_path.'/'.$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::get() + ->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->_path)) { + //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->_path .'/'. $folder) == 'dir' + && (!$regex || preg_match($regex, $folder))) { + + //add it + $folders[] = Eden_Folder::get($this->_path . '/' . $folder); + if($recursive) { + $subfolders = Eden_Folder::get($this->_path.'/'.$folder); + $folders = array_merge($folders, $subfolders->getFolders($regex, $recursive)); + } + + } + } + closedir($handle); + } + + return $folders; + } + + /** + * 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::get()->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 given the path and optionally a regular expression + * + * @param string regular expression + * @return bool + */ + public function removeFiles($regex = NULL) { + Eden_Folder_Error::get()->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; + } + + /** + * Checks to see if this + * path is a real file + * + * @return bool + */ + public function isFolder($path = NULL) { + Eden_Folder_Error::get()->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->_path.'/'.$path); + } + + return is_dir($this->_path); + } + + /** + * Checks to see if this + * path is a real file + * + * @return bool + */ + public function isFile() { + return file_exists($this->_path); + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} + +/** + * Folder Errors + */ +class Eden_Folder_Error extends Eden_Error { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function get($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/google/base.php b/library/eden/google/base.php new file mode 100644 index 0000000..a0efbc4 --- /dev/null +++ b/library/eden/google/base.php @@ -0,0 +1,223 @@ + +/* + * 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. + */ + +/** + * Google oauth + * + * @package Eden + * @category google + * @author Christian Blanquera + * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ + */ +class Eden_Google_Base extends Eden_Oauth_Base { + /* Constants + -------------------------------*/ + const REQUEST_URL = 'https://www.google.com/accounts/OAuthGetRequestToken'; + const ACCESS_URL = 'https://www.google.com/accounts/OAuthGetAccessToken'; + const AUTHORIZE_URL = 'https://www.google.com/accounts/OAuthAuthorizeToken'; + + const SECRET_KEY = 'google_token_secret'; + + const DEFAULT_USER = 'default'; + const VERSION_HEADER = 'GData-Version'; + const GDATA_VERSION = 2; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_key = NULL; + protected $_secret = NULL; + protected $_scope = NULL; + + protected $_meta = array(); + + protected $_accessToken = NULL; + protected $_accessSecret = NULL; + + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + /* Magic + -------------------------------*/ + /* Public Methods + -------------------------------*/ + /** + * Returns the URL used for login. + * + * @param string + * @return string + */ + public function getLoginUrl($redirect) { + //Argument 1 must be a string + Eden_Google_Error::get()->argument(1, 'string'); + + //get the token + $token = Eden_Oauth::get() + ->getConsumer(self::REQUEST_URL, $this->_key, $this->_secret) + ->useAuthorization() + ->setMethodToPost() + ->setSignatureToHmacSha1() + ->getQueryResponse(array('scope' => $this->_scope)); + + //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; + } + + /** + * Returns the access token + * + * @param string + * @param string + * @return string + */ + public function getAccessToken($token, $secret) { + //argument test + Eden_Google_Error::get() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'string'); //Argument 2 must be a string + + return Eden_Oauth::get() + ->getConsumer(self::ACCESS_URL, $this->_key, $this->_secret) + ->useAuthorization() + ->setMethodToPost() + ->setToken($token, $secret) + ->setSignatureToHmacSha1() + ->getQueryResponse(array('scope' => $this->_scope)); + } + + public function setAccessToken($token, $secret) { + $this->_accessToken = $token; + $this->_accessSecret = $secret; + + return $this; + } + + + /** + * Returns the meta of the last call + * + * @return array + */ + public function getMeta($key = NULL) { + Eden_Google_Error::get()->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()) { + $query['alt'] = 'jsonc'; + + $rest = Eden_Oauth::get() + ->getConsumer($url, $this->_key, $this->_secret) + ->setHeaders(self::VERSION_HEADER, self::GDATA_VERSION) + ->setToken($this->_accessToken, $this->_accessSecret) + ->setSignatureToHmacSha1(); + + $response = $rest->getJsonResponse($query); + + $this->_meta = $rest->getMeta(); + + return $response; + } + + /** + * Returns the token from the server + * + * @param array + * @return array + */ + protected function _post($url, $query = array()) { + $headers = array(); + $headers[] = self::VERSION_HEADER.': '.self::GDATA_VERSION; + $headers[] = Eden_Oauth_Consumer::POST_HEADER; + $headers[] = 'Content-Type: application/json'; + + $rest = Eden_Oauth::get() + ->getConsumer($url, $this->_key, $this->_secret) + ->setToken($this->_accessToken, $this->_accessSecret) + ->setSignatureToHmacSha1(); + + //get the authorization parameters as an array + $signature = $rest->getSignature(); + $authorization = $rest->getAuthorization($signature, false); + $authorization = $this->_buildQuery($authorization); + + if(is_array($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::get() + ->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['authorization'] = $authorization; + $this->_meta['headers'] = $headers; + $this->_meta['query'] = $query; + + 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..f0d7a92 --- /dev/null +++ b/library/eden/google/calendar.php @@ -0,0 +1,62 @@ + +/* + * 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. + */ + +/** + * Google calendar + * + * @package Eden + * @category google + * @author Christian Blanquera + * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ + */ +class Eden_Google_Calendar extends Eden_Google_Base { + /* Constants + -------------------------------*/ + const SCOPE = 'https://www.google.com/calendar/feeds/'; + const URL_CALENDAR_LIST = 'https://www.google.com/calendar/feeds/%s/allcalendars/full'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function get($key, $secret) { + return self::_getMultiple(__CLASS__, $key, $secret); + } + + /* Magic + -------------------------------*/ + public function __construct($key, $secret) { + //argument test + Eden_Google_Error::get() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'string'); //Argument 2 must be a string + + $this->_key = $key; + $this->_secret = $secret; + $this->_scope = self::SCOPE; + } + + /* Public Methods + -------------------------------*/ + public function getCalendarList($user = self::DEFAULT_USER) { + $url = sprintf(self::URL_CALENDAR_LIST, $user); + //Argument 1 must be a string + Eden_Google_Error::get()->argument(1, 'string'); + return $this->_getResponse($url); + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ 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..020999d --- /dev/null +++ b/library/eden/google/contacts.php @@ -0,0 +1,54 @@ + +/* + * 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. + */ + +/** + * Google Contacts + * + * @package Eden + * @category google + * @author Christian Blanquera + * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ + */ +class Eden_Google_Contacts extends Eden_Google_Base { + /* Constants + -------------------------------*/ + const SCOPE = 'https://www.google.com/m8/feeds'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function get($key, $secret) { + return self::_getMultiple(__CLASS__, $key, $secret); + } + + /* Magic + -------------------------------*/ + public function __construct($key, $secret) { + //argument test + Eden_Google_Error::get() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'string'); //Argument 2 must be a string + + $this->_key = $key; + $this->_secret = $secret; + $this->_scope = self::SCOPE; + } + + /* Public Methods + -------------------------------*/ + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/google/docs.php b/library/eden/google/docs.php new file mode 100644 index 0000000..ab9e5fb --- /dev/null +++ b/library/eden/google/docs.php @@ -0,0 +1,54 @@ + +/* + * 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. + */ + +/** + * Google docs + * + * @package Eden + * @category google + * @author Christian Blanquera + * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ + */ +class Eden_Google_Docs extends Eden_Google_Base { + /* Constants + -------------------------------*/ + const SCOPE = 'https://docs.google.com/feeds/'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function get($key, $secret) { + return self::_getMultiple(__CLASS__, $key, $secret); + } + + /* Magic + -------------------------------*/ + public function __construct($key, $secret) { + //argument test + Eden_Google_Error::get() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'string'); //Argument 2 must be a string + + $this->_key = $key; + $this->_secret = $secret; + $this->_scope = self::SCOPE; + } + + /* Public Methods + -------------------------------*/ + /* 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..0d16ed0 --- /dev/null +++ b/library/eden/google/error.php @@ -0,0 +1,42 @@ + +/* + * 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. + */ + +/** + * Google Errors + * + * @package Eden + * @category google + * @author Christian Blanquera + * @version $Id: exception.php 1 2010-01-02 23:06:36Z blanquera $ + */ +class Eden_Google_Error extends Eden_Error { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function get($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/google/gmail.php b/library/eden/google/gmail.php new file mode 100644 index 0000000..2ef6366 --- /dev/null +++ b/library/eden/google/gmail.php @@ -0,0 +1,54 @@ + +/* + * 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. + */ + +/** + * Google gmail + * + * @package Eden + * @category google + * @author Christian Blanquera + * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ + */ +class Eden_Google_Gmail extends Eden_Google_Base { + /* Constants + -------------------------------*/ + const SCOPE = 'https://mail.google.com/'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function get($key, $secret) { + return self::_getMultiple(__CLASS__, $key, $secret); + } + + /* Magic + -------------------------------*/ + public function __construct($key, $secret) { + //argument test + Eden_Google_Error::get() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'string'); //Argument 2 must be a string + + $this->_key = $key; + $this->_secret = $secret; + $this->_scope = self::SCOPE; + } + + /* Public Methods + -------------------------------*/ + /* 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..d0c6681 --- /dev/null +++ b/library/eden/google/oauth.php @@ -0,0 +1,57 @@ + +/* + * 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. + */ + +/** + * Google oauth + * + * @package Eden + * @category google + * @author Christian Blanquera + * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ + */ +class Eden_Google_Oauth extends Eden_Google_Base { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_key = NULL; + protected $_secret = NULL; + protected $_scope = NULL; + + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function get($key, $secret, $scope) { + return self::_getMultiple(__CLASS__, $key, $secret, $scope); + } + + /* Magic + -------------------------------*/ + public function __construct($key, $secret, $scope) { + //argument test + Eden_Google_Error::get() + ->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->_key = $key; + $this->_secret = $secret; + $this->_scope = $scope; + } + + /* Public Methods + -------------------------------*/ + /* 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..e256de2 --- /dev/null +++ b/library/eden/google/shortener.php @@ -0,0 +1,217 @@ + +/* + * 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. + */ + +/** + * Google calendar + * + * @package Eden + * @category google + * @author Christian Blanquera + * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ + */ +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 + -------------------------------*/ + /* Get + -------------------------------*/ + public static function get($key) { + return self::_getMultiple(__CLASS__, $key); + } + + /* Magic + -------------------------------*/ + public function __construct($key) { + //Argument 1 must be a string + Eden_Google_Error::get()->argument(1, 'string'); + + $this->_key = $key; + } + + /* Public Methods + -------------------------------*/ + /** + * 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']; + } + + /** + * 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 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 meta of the last call + * + * @return array + */ + public function getMeta($key = NULL) { + Eden_Google_Error::get()->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()) { + $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::get() + ->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::get() + ->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/image.php b/library/eden/image.php new file mode 100644 index 0000000..90998b1 --- /dev/null +++ b/library/eden/image.php @@ -0,0 +1,729 @@ + +/* + * 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. + */ + +/** + * 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 + * @subpackage image + * @category path + * @author Christian Blanquera + * @version $Id: abstract.php 1 2010-01-02 23:06:36Z blanquera $ + */ +abstract class Eden_Image_Abstract extends Eden_Class { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_resource = NULL; + protected $_width = 0; + protected $_height = 0; + + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function get($data, $type = NULL, $path = true, $quality = 75) { + $class = __CLASS__; + return new $class($data, $type, $path, $quality); + } + + /* Magic + -------------------------------*/ + public function __construct($data, $type = NULL, $path = true, $quality = 75) { + Eden_Image_Error::get() + ->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 + -------------------------------*/ + /** + * 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::get() + ->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; + } + + /** + * 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::get() + ->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; + } + + /** + * 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::get() + ->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::get() + ->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; + } + + /** + * 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::get()->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 greyscale filter. Converts the image into grayscale. + * + * @return Eden_Image_Model + */ + public function greyscale() { + //apply filter + imagefilter($this->_resource, IMG_FILTER_GRAYSCALE); + + 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; + } + + /** + * 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::get()->argument(1, 'numeric'); + + //apply filter + imagefilter($this->_resource, IMG_FILTER_BRIGHTNESS, $level); + + 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::get()->argument(1, 'numeric'); + + //apply filter + imagefilter($this->_resource, IMG_FILTER_CONTRAST, $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::get() + ->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 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; + } + + /** + * 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 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 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::get()->argument(1, 'numeric'); + + //apply filter + imagefilter($this->_resource, IMG_FILTER_SMOOTH, $level); + + return $this; + } + + /** + * Returns the size of the image + * + * @return array + */ + public function getDimensions() { + return array(imagesx($this->_resource), imagesy($this->_resource)); + } + + /** + * 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::get()->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 _getResource($data, $path) { + //if the GD Library is not installed + if(!function_exists('gd_info')) { + //throw error + throw new Eden_Image_Error(Eden_Image_Error::GD_NOT_INSTALLED); + } + + # 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::get() + ->setMessage(Eden_Image_Error::NOT_VALID_IMAGE_FILE) + ->addVariable($this->_path); + } + + return $resource; + } + + protected function _getWidthAspectRatio($sourceWidth, $sourceHeight, $destinationHeight) { + $ratio = $destinationHeight / $sourceHeight; + return $sourceWidth * $ratio; + } + + protected function _getHeightAspectRatio($sourceWidth, $sourceHeight, $destinationWidth) { + $ratio = $destinationWidth / $sourceWidth; + return $sourceHeight * $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/javascript.php b/library/eden/javascript.php new file mode 100644 index 0000000..78f30e7 --- /dev/null +++ b/library/eden/javascript.php @@ -0,0 +1,52 @@ + +/* + * 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. + */ + +/** + * Allows you to create JavaScript calls (not properties) in PHP + * + * @package Eden + * @subpackage javascript + * @category javascript + * @author Christian Blanquera + * @version $Id: javascript.php 1 2010-01-02 23:06:36Z blanquera $ + */ +class Eden_Javascript extends Eden_Class { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function get() { + return self::_getSingleton(__CLASS__); + } + + /* Magic + -------------------------------*/ + /* Public Methods + -------------------------------*/ + public function load() { + return Eden_Javascript_Class::get(); + } + + public function render() { + $args = func_get_args(); + return ''; + } + + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/javascript/class.php b/library/eden/javascript/class.php new file mode 100644 index 0000000..885e90c --- /dev/null +++ b/library/eden/javascript/class.php @@ -0,0 +1,131 @@ + +/* + * 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. + */ + +/** + * Allows you to create JavaScript calls (not properties) in PHP + * + * @package Eden + * @category javascript + * @author Christian Blanquera + * @version $Id: model.php 1 2010-01-02 23:06:36Z blanquera $ + */ +class Eden_Javascript_Class extends Eden_Class { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_script = array(); + + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function get() { + return self::_getMultiple(__CLASS__); + } + + /* Magic + -------------------------------*/ + public function __toString() { + $output = NULL; + foreach($this->_script as $script) { + if(is_null($output) || substr($output, -1, 1) == ';') { + $output .= $script; + } else { + $output .= '.'.$script; + } + } + return $output; + } + + public function __call($name, $args) { + //for each argument + foreach($args as $i => $arg) { + //encode the argument in javascript + $args[$i] = $this->___encode($arg); + } + + //add to script + $this->_script[] = $name.'('.implode(',', $args).')'; + + return $this; + } + + public function __get($name) { + //add to script + $this->_script[] = $name; + + return $this; + } + + public function __set($name, $value) { + //add to script + $this->_script[] = $name.'='.$this->___encode($value).';'; + + return $this; + } + + /* Public Methods + -------------------------------*/ + /* Protected Methods + -------------------------------*/ + protected function ___encode($value) { + $type = Eden_Tool::get()->type($value); + switch($type) { + case 'array': + case 'object': + $jsonType = substr(json_encode($value), 0, 1); + if($jsonType == '[') { + $value = $this->____encodeArray($value); + } else { + $value = $this->____encodeObject($value); + } + break; + default: + $value = json_encode($value); + break; + } + + return $value; + } + + protected function ____encodeObject($object) { + $encoded = array(); + $class = __CLASS__; + foreach($object as $key => $value) { + $key = json_encode($key); + if(!($value instanceof $class)) { + $value = $this->___encode($value); + } + + $encoded[] = $key.':'.$value; + } + + return '{'.implode(',', $encoded).'}'; + } + + protected function ____encodeArray($array) { + $encoded = array(); + $class = __CLASS__; + foreach($array as $value) { + if(!($value instanceof $class)) { + $value = $this->___encode($value); + } + + $encoded[] = $value; + } + + return '['.implode(',', $encoded).']'; + } + + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/javascript/error.php b/library/eden/javascript/error.php new file mode 100644 index 0000000..32a5dbb --- /dev/null +++ b/library/eden/javascript/error.php @@ -0,0 +1,42 @@ + +/* + * 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. + */ + +/** + * Javascript Errors + * + * @package Eden + * @category javascript + * @author Christian Blanquera + * @version $Id: exception.php 1 2010-01-02 23:06:36Z blanquera $ + */ +class Eden_Javascript_Error extends Eden_Error { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function get($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/loader.php b/library/eden/loader.php new file mode 100755 index 0000000..a642753 --- /dev/null +++ b/library/eden/loader.php @@ -0,0 +1,106 @@ + +/* + * 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__).'/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 + * @subpackage autoload + * @category framework + * @author Christian Blanquera + * @version $Id: autoload.php 1 2010-01-02 23:06:36Z blanquera $ + */ +class Eden_Loader extends Eden_Class { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_root = array(); + + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function get() { + return self::_getSingleton(__CLASS__); + } + + /* Magic + -------------------------------*/ + public function __construct() { + $this->addRoot(realpath(dirname(__FILE__).'/..')); + } + + /* 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 = '/'.strtolower(str_replace('_', '/', $class)); + 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) { + $this->handler($class); + return $this; + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/memcache.php b/library/eden/memcache.php new file mode 100755 index 0000000..94e7830 --- /dev/null +++ b/library/eden/memcache.php @@ -0,0 +1,202 @@ + +/* + * 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__).'/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 + * @subpackage memcache + * @category cache + * @author Christian Blanquera + * @version $Id: model.php 1 2010-01-02 23:06:36Z blanquera $ + */ +class Eden_Memcache extends Eden_Class { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_memcache = NULL; + + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function get($host = 'localhost', $port = 11211, $timeout = 1) { + $class = __CLASS__; + return new $class($host, $port, $timeout); + } + + /* Magic + -------------------------------*/ + public function __construct($host = 'localhost', $port = 11211, $timeout = 1) { + //argument test + $error = Eden_Memcache_Error::get() + ->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::get() + ->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; + } + + /** + * 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 setData($key, $data, $flag = NULL, $expire = NULL) { + //argument test + Eden_Memcache_Error::get() + ->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; + } + + /** + * Gets a data cache + * + * @param string|array the key to the data + * @param int MemCache flag + * @return variable + */ + public function getData($key, $flag = NULL) { + //argument test + Eden_Memcache_Error::get() + ->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 deleteData($key) { + //Argument 1 must be a string or array + Eden_Memcache_Error::get()->argument(1, 'string', 'array'); + + $this->_memcache->delete($key); + + return $this; + } + + /** + * Flushes the cache + * + * return this + */ + public function clear() { + $this->_memcache->flush(); + + 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 + -------------------------------*/ + /* Get + -------------------------------*/ + public static function get($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/model.php b/library/eden/model.php new file mode 100755 index 0000000..3afed41 --- /dev/null +++ b/library/eden/model.php @@ -0,0 +1,228 @@ + +/* + * 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__).'/array.php'; + +/** + * + * @package Eden + * @category registry + * @author Christian Blanquera + * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ + */ +class Eden_Model extends Eden_Array { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_meta = array(); + + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function get(array $data = array()) { + return self::_getMultiple(__CLASS__); + } + + /* Magic + -------------------------------*/ + public function __call($name, $args) { + //if the method starts with get + if(strpos($name, 'get') === 0) { + $key = preg_replace("/([A-Z])/", "_$1", $name); + //get rid of get_ + $key = strtolower(substr($key, 4)); + + if(isset($this->_meta[$key])) { + return $this->_data[$key]; + } + } else if (strpos($name, 'set') === 0) { + $key = preg_replace("/([A-Z])/", "_$1", $name); + //get rid of get_ + $key = strtolower(substr($key, 4)); + + return $this->__set($key, $args[0]); + } + + try { + return parent::__call($name, $args); + } catch(Eden_Type_Error $e) { + throw new Eden_Model_Error($e->getMessage()); + } + } + + public function __get($name) { + if(isset($this->_data[$name])) { + return $this->_data[$name]; + } + + return NULL; + } + + public function __set($name, $value) { + if(isset($this->_meta[$name])) { + $this->_data[$name] = $value; + return $this; + } + + //throw an error + Eden_Model_Error::get() + ->setMessage(Eden_Model_Error::SET_INVALID) + ->addVariable($name)->trigger(); + } + + /* Public Methods + -------------------------------*/ + /** + * Loads data into the model + * + * @param array + * @return this + */ + public function load(array $data) { + //for each data + foreach($data as $name => $value) { + //if this is not set in the meta data + if(!isset($this->_meta[$name])) { + //throw an error + Eden_Model_Error::get() + ->setMessage(Eden_Model_Error::SET_INVALID) + ->addVariable($name)->trigger(); + } + + $this->_data[$name] = $value; + } + + return $this; + } + + /** + * Sets meta data about the given property + * + * @param string + * @param array + * @return this + */ + public function setMetaData($name, $meta = array(), $value = NULL) { + //argument test + Eden_Model_Error::get() + ->argument(1, 'string') //argument 1 must be a string + ->argument(2, 'string', 'array') //argument 2 must be a string or array + ->argument(3, 'string', 'null'); //argument 3 must be a string or null + + if(is_array($meta)) { + $this->_meta[$name] = $meta; + return $this; + } + + $this->_meta[$name][$meta] = $value; + + return $this; + } + + /** + * Returns meta data + * + * @param string + * @param string + * @return array + */ + public function getMetaData($name = NULL, $key = NULL) { + //argument test + Eden_Model_Error::get() + ->argument(1, 'string', 'null') //argument 1 must be a string or null + ->argument(2, 'string', 'null'); //argument 2 must be a string or null + + if(!is_null($name) && isset($this->_meta[$name])) { + if(!is_null($key) && isset($this->_meta[$name][$key])) { + return $this->_meta[$name][$key]; + } + return $this->_meta[$name]; + } + + return $this->_meta; + } + + /** + * Sets data using the ArrayAccess interface + * We overloaded this to not allow creating new + * columns. + * + * @param number + * @param mixed + * @return void + */ + public function offsetSet($offset, $value) { + //if this is not set in the meta data + if(!isset($this->_meta[$offset])) { + //throw an error + Eden_Model_Error::get() + ->setMessage(Eden_Model_Error::SET_INVALID) + ->addVariable($offset)->trigger(); + } + + $this->_data[$offset] = $value; + } + + /** + * unsets using the ArrayAccess interface + * We overloaded this because an attributes + * must never be removed. Instead we set it to + * null. + * + * @param number + * @return void + */ + public function offsetUnset($offset) { + //if it is set in the meta + if(isset($this->_meta[$offset])) { + //set it to null + $this->_data[$offset] = NULL; + } + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} + +/** + * Model Errors + */ +class Eden_Model_Error extends Eden_Error { + /* Constants + -------------------------------*/ + const SET_INVALID = 'Setting %s refused. You need to set it first using setMetaData().'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function get($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/mysql.php b/library/eden/mysql.php new file mode 100755 index 0000000..5b2bb1b --- /dev/null +++ b/library/eden/mysql.php @@ -0,0 +1,722 @@ + +/* + * 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__).'/event.php'; +require_once dirname(__FILE__).'/sql/error.php'; +require_once dirname(__FILE__).'/mysql/error.php'; +require_once dirname(__FILE__).'/sql/database.php'; +require_once dirname(__FILE__).'/sql/query.php'; +require_once dirname(__FILE__).'/sql/delete.php'; +require_once dirname(__FILE__).'/sql/select.php'; +require_once dirname(__FILE__).'/sql/update.php'; +require_once dirname(__FILE__).'/sql/insert.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 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 + * @version $Id: abstract.php 1 2010-01-02 23:06:36Z blanquera $ + */ +class Eden_Mysql extends Eden_Sql_Database { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_type = NULL; + protected $_host = 'localhost'; + protected $_name = NULL; + protected $_user = NULL; + protected $_pass = NULL; + protected $_queries = array(); + + protected $_connection = NULL; + protected $_binds = array(); + + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function get($host = NULL, $name = NULL, $user = NULL, $pass = NULL) { + $class = __CLASS__; + return new $class($host, $name, $user, $pass); + } + + /* Magic + -------------------------------*/ + public function __construct($host, $name, $user, $pass = NULL) { + //argument test + Eden_Mysql_Error::get() + ->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 number or null + + $this->_host = $host; + $this->_name = $name; + $this->_user = $user; + $this->_pass = $pass; + } + + /* Public Methods + -------------------------------*/ + /** + * Connects to the database + * + * @param array the connection options + * @return this + */ + public function connect(array $options = array()) { + $connection = 'mysql:host='.$this->_host.';dbname='.$this->_name; + + $this->_connection = new PDO($connection, $this->_user, $this->_pass, $options); + + $this->trigger(); + + return $this; + } + + /** + * 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() { + return $this->_connection; + } + + /** + * Returns the history of queries made still in memory + * + * @return array the queries + */ + public function getQueries() { + return $this->_queries; + } + + /** + * Returns the last inserted id + * + * @return int the id + */ + public function getLastInsertedId() { + return $this->getConnection()->lastInsertId(); + } + + + /** + * 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::get()->argument(1, 'string', 'null'); + + return Eden_Mysql_Alter::get($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::get()->argument(1, 'string', 'null'); + + return Eden_Mysql_Create::get($name); + } + + /** + * Returns the Subselect query builder + * + * @return Eden_Sql_Subselect + */ + public function subselect($parentQuery, $select = '*') { + //Argument 2 must be a string + Eden_Mysql_Error::get()->argument(2, 'string'); + + return Eden_Mysql_Subselect::get($parentQuery, $select); + } + + /** + * Returns the alter query builder + * + * @return Eden_Sql_Utility + */ + public function utility() { + return Eden_Mysql_Utility::get(); + } + + /** + * 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_Mysql_Error::get() + ->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_Mysql_Error::get() + ->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); + $filter = $this->bind($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, $this->getBinds()); + + if($index == 'first' && count($result) > 0) { + return $results[0]; + } + + else if($index == 'last' && count($results) > 0) { + return array_pop($results); + } + + else if(is_numeric($index)) { + if(isset($results[$index])) { + return $results[$index]; + } + } + + $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_Mysql_Error::get() + ->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; + } + + /** + * Inserts data into a table and returns the ID + * + * @param string table + * @param array setting + * @return int + */ + public function insertRow($table, array $setting) { + //Argument 1 must be a string + Eden_Mysql_Error::get()->argument(1, 'string'); + + $query = $this->insert($table); + + foreach($setting as $key => $value) { + $query->set($key, $this->bind($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) { + //Argument 1 must be a string + Eden_Mysql_Error::get()->argument(1, 'string'); + + $query = $this->insert($table); + + foreach($settings as $index => $setting) { + foreach($setting as $key => $value) { + $query->set($key, $this->bind($value), $index); + } + } + + //run the query + $this->query($query, $this->getBinds()); + + $this->trigger($table, $settings); + + return $this; + } + + /** + * 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) { + //Argument 1 must be a string + Eden_Mysql_Error::get()->argument(1, 'string'); + + $query = $this->update($table); + + foreach($setting as $key => $value) { + $query->set($key, $this->bind($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); + $filter = $this->bind($filter); + $filters[$i] = vsprintf($format, $filter); + } + } + + //run the query + $this->query($query, $this->getBinds()); + + $this->trigger($table, $setting, $filters); + + 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_Mysql_Error::get() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'string') //Argument 2 must be a string + ->argument(3, 'string', 'number'); //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, 'eq', $value))); + } + } + + /** + * Removes rows that match a filter + * + * @param string table + * @param array filter + * @return var + */ + public function deleteRows($table, $filter = NULL) { + //Argument 1 must be a string + Eden_Mysql_Error::get()->argument(1, 'string'); + + $query = $this->delete($table); + + foreach($setting as $key => $value) { + $query->set($key, $this->bind($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); + $filter = $this->bind($filter); + $filters[$i] = vsprintf($format, $filter); + } + } + + //run the query + $this->query($query, $this->getBinds()); + + $this->trigger($table, $filters); + + return $this; + } + + /** + * 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::get()->argument(1, 'string'); + + $query = $this->utility(); + $results = $this->getColumns($table, "`Key` = 'PRI'"); + return isset($results[0]['Field']) ? $results[0]['Field'] : NULL; + } + + /** + * Returns the columns and attributes given the table name + * + * @param the name of the table + * @return attay|false + */ + public function getColumns($table, $filter = NULL) { + //Argument 1 must be a string + Eden_Mysql_Error::get()->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, $filter); + return $this->query($query, $this->getBinds()); + } + + /** + * 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::get()->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_Mysql_Error::get()->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 databse + * + * @return string + */ + public function getSchema() { + $backup = array(); + $tables = $this->getTables(); + foreach($tables as $table) { + $backup[] = $this->getBackup(); + } + + return implode("\n\n", $backup); + } + + /** + * 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_Mysql_Error::get()->argument(1, 'string', 'Eden_Sql_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($bound as $key => $value) { + $query = str_replace($key, "'$value'", $query); + } + + Eden_Mysql_Error::get() + ->setMessage(Eden_Mysql_Exception::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; + } + + /** + * 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_Mysql_Error::get()->argument(1, 'array', 'string', 'numeric'); + + 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->_bind).'bind'; + $this->_binds[$name] = $value; + return $name; + } + + /** + * Returns all the bound values of this query + * + * @param void + * @return array + * @notes returns all the binds stored in registry + */ + public function getBinds() { + return $this->_binds; + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/mysql/alter.php b/library/eden/mysql/alter.php new file mode 100755 index 0000000..495f5fa --- /dev/null +++ b/library/eden/mysql/alter.php @@ -0,0 +1,322 @@ + +/* + * 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. + */ + +/** + * Generates alter query string syntax + * + * @package Eden + * @category sql + * @author Christian Blanquera + * @version $Id: alter.php 1 2010-01-02 23:06:36Z blanquera $ + */ +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 + -------------------------------*/ + /* Get + -------------------------------*/ + public static function get($name = NULL) { + return self::_getMultiple(__CLASS__, $name); + } + + /* Magic + -------------------------------*/ + public function __construct($name = NULL) { + if(is_string($name)) { + $this->setName($name); + } + } + + /* Public Methods + -------------------------------*/ + /** + * 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::get()->argument(1, 'string'); + + $this->_name = $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::get()->argument(1, 'string'); + + $this->_changeFields[$name] = $attributes; + return $this; + } + + /** + * 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::get()->argument(1, 'string'); + + $this->_addFields[$name] = $attributes; + return $this; + } + + /** + * Removes a field + * + * @param string name + * @return this + */ + public function removeField($name) { + //Argument 1 must be a string + Eden_Mysql_Error::get()->argument(1, 'string'); + + $this->_removeFields[] = $name; + return $this; + } + + /** + * Adds an index key + * + * @param string name + * @return this + */ + public function addKey($name) { + //Argument 1 must be a string + Eden_Mysql_Error::get()->argument(1, 'string'); + + $this->_addKeys[] = '`'.$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::get()->argument(1, 'string'); + + $this->_removeKeys[] = $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::get()->argument(1, 'string'); + + $this->_addUniqueKeys[] = '`'.$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::get()->argument(1, 'string'); + + $this->_removeUniqueKeys[] = $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::get()->argument(1, 'string'); + + $this->_addPrimaryKeys[] = '`'.$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::get()->argument(1, 'string'); + + $this->_removePrimaryKeys[] = $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) { + $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); + } + + /* 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..e876a36 --- /dev/null +++ b/library/eden/mysql/create.php @@ -0,0 +1,256 @@ + +/* + * 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. + */ + +/** + * Generates create table query string syntax + * + * @package Eden + * @category sql + * @author Christian Blanquera + * @version $Id: create.php 1 2010-01-02 23:06:36Z blanquera $ + */ +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 + -------------------------------*/ + /* Get + -------------------------------*/ + public static function get($name = NULL) { + $class = __CLASS__; + return new $class($name); + } + + /* Magic + -------------------------------*/ + public function __construct($name = NULL) { + if(is_string($name)) { + $this->setName($name); + } + } + + /* Public Methods + -------------------------------*/ + /** + * 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::get()->argument(1, 'string'); + + $this->_name = $name; + return $this; + } + + /** + * Sets comments + * + * @param string comments + * @return this + */ + public function setComments($comments) { + //Argument 1 must be a string + Eden_Mysql_Error::get()->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 a list of unique keys to the table + * + * @param array uniqueKeys + * @return this + */ + public function setUniqueKeys(array $uniqueKeys) { + $this->_uniqueKeys = $uniqueKeys; + 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; + } + + /** + * 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::get()->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::get()->argument(1, 'string'); + + $this->_keys[$name] = $fields; + 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::get()->argument(1, 'string'); + + $this->_uniqueKeys[$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::get()->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['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); + } + + /* 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..4535e72 --- /dev/null +++ b/library/eden/mysql/error.php @@ -0,0 +1,42 @@ + +/* + * 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 + * @version $Id: exception.php 1 2010-01-02 23:06:36Z blanquera $ + */ +class Eden_Mysql_Error extends Eden_Error { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function get($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/mysql/subselect.php b/library/eden/mysql/subselect.php new file mode 100755 index 0000000..f7ae592 --- /dev/null +++ b/library/eden/mysql/subselect.php @@ -0,0 +1,76 @@ + +/* + * 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. + */ + +/** + * Generates subselect query string syntax + * + * @package Eden + * @subpackage database + * @category database + * @author Christian Blanquera + * @version $Id: subselect.php 1 2010-01-02 23:06:36Z blanquera $ + */ +class Eden_Mysql_Subselect extends Eden_Class { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_parentQuery; + + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function get(Eden_Sql_Select $parentQuery, $select = '*') { + $class = __CLASS__; + return new $class($parentQuery, $select); + } + + /* Magic + -------------------------------*/ + public function __construct(Eden_Sql_Select $parentQuery, $select = '*') { + //Argument 2 must be a string + Eden_Mysql_Error::get()->argument(2, 'string'); + + $this->setParentQuery($parentQuery); + $this->_select = is_array($select) ? implode(', ', $select) : $select; + } + + /* Public Methods + -------------------------------*/ + /** + * 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; + } + + /** + * 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).')'; + } + + /* 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..fb6486d --- /dev/null +++ b/library/eden/mysql/utility.php @@ -0,0 +1,116 @@ + +/* + * 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. + */ + +/** + * Generates utility query strings + * + * @package Eden + * @subpackage database + * @category database + * @author Christian Blanquera + * @version $Id: utility.php 1 2010-01-02 23:06:36Z blanquera $ + */ +class Eden_Mysql_Utility extends Eden_Sql_Query +{ + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_query = NULL; + + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + /* Magic + -------------------------------*/ + public static function get() { + return self::_getMultiple(__CLASS__); + } + + /* Public Methods + -------------------------------*/ + /** + * Query for showing all tables + * + * @param string like + * @return this + */ + public function showTables($like = NULL) { + //if like is not null a string + if(!is_null($like) && !is_string($like)) { + //throw error + throw new Eden_Database_Utility_Exception(sprintf(Eden_Exception::NOT_STRING_NULL, 1)); + } + + $like = $like ? ' LIKE '.$like : NULL; + $this->_query = 'SHOW TABLES'.$like; + 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::get()->argument(1, 'string')->argument(2, 'string', 'null'); + + $where = $where ? ' WHERE '.$where : NULL; + $this->_query = 'SHOW FULL COLUMNS FROM `' . $table .'`' . $where; + return $this; + } + + /** + * 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::get()->argument(1, 'string'); + + $this->_query = 'DROP TABLE `' . $table .'`'; + return $this; + } + + /** + * 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::get()->argument(1, 'string')->argument(2, 'string'); + + $this->_query = 'RENAME TABLE `' . $table . '` TO `' . $name . '`'; + return $this; + } + + /** + * Returns the string version of the query + * + * @return string + */ + public function getQuery() { + return $this->_query.';'; + } + + /* 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..1df6aae --- /dev/null +++ b/library/eden/oauth.php @@ -0,0 +1,609 @@ + +/* + * 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__).'/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'; + +/** + * Trigger when something is false + * + * @package Eden + * @category core + * @author Christian Blanquera + * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ + */ +class Eden_Oauth extends Eden_Class { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function get() { + return self::_getSingleton(__CLASS__); + } + + /* Magic + -------------------------------*/ + /* Public Methods + -------------------------------*/ + /** + * Returns the oauth consumer class + * + * @return Eden_Oauth_Consumer + */ + public function getConsumer($url, $key, $secret) { + return Eden_Oauth_Consumer::get($url, $key, $secret); + } + + /** + * Returns the oauth server class + * + * @return Eden_Oauth_Server + */ + public function getServer() { + return Eden_Oauth_Server::get(); + } + + /** + * 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::get() + ->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->getConsumer($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 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::get() + ->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->getConsumer($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 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::get() + ->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->getConsumer($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, 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::get() + ->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->getConsumer($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 + * 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::get() + ->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->getConsumer($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 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::get() + ->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->getConsumer($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 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::get() + ->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->getConsumer($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, 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::get() + ->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->getConsumer($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 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::get() + ->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->getConsumer($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, 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::get() + ->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->getConsumer($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, 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::get() + ->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->getConsumer($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 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::get() + ->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->getConsumer($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 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::get() + ->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->getConsumer($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, 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::get() + ->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->getConsumer($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, 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::get() + ->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->getConsumer($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 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::get() + ->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->getConsumer($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 + } + + /* 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..f084512 --- /dev/null +++ b/library/eden/oauth/base.php @@ -0,0 +1,142 @@ + +/* + * 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. + */ + +/** + * Trigger when something is false + * + * @package Eden + * @category core + * @author Christian Blanquera + * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ + */ +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) { + 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 + $query = array(); + 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); + foreach ($value as $item) { + if(!$noQuotes) { + $item = '"'.$item.'"'; + } + + array_push($query, $key . '=' . $item); + } + } else { + + if(!$noQuotes) { + $value = '"'.$value.'"'; + } + + // For each parameter, the name is separated from the corresponding + // value by an '=' character (ASCII code 61). OAuth Spec: 9.1.1 (2) + array_push($query, $key . '=' . $value); + } + } + + // Each name-value pair is separated by an '&' character, ASCII code 38. + // OAuth Spec: 9.1.1 (2) + return implode($separator, $query); + } + + 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; + } + + 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); + } + + /* 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..5288c8b --- /dev/null +++ b/library/eden/oauth/consumer.php @@ -0,0 +1,451 @@ + +/* + * 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. + */ + +/** + * Oauth consumer methods + * + * @package Eden + * @category oauth + * @author Christian Blanquera + * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ + */ +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 $_signature = NULL; + protected $_meta = array(); + protected $_headers = array(); + + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function get($url, $key, $secret) { + return self::_getMultiple(__CLASS__, $url, $key, $secret); + } + + /* Magic + -------------------------------*/ + public function __construct($url, $key, $secret) { + //argument test + Eden_Oauth_Error::get() + ->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 meta of the last call + * + * @return array + */ + public function getMeta($key = NULL) { + Eden_Oauth_Error::get()->argument(1, 'string', 'null'); + + if(isset($this->_meta[$key])) { + return $this->_meta[$key]; + } + + return $this->_meta; + } + + /** + * Sets request headers + * + * @param array|string + * @return this + */ + public function setHeaders($key, $value = NULL) { + Eden_Oauth_Error::get() + ->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, sends the parameters as post fields + * + * @return this + */ + public function setMethodToPost() { + $this->_method = self::POST; + return $this; + } + + /** + * When sent, appends the parameters to the URL + * + * @return this + */ + public function setMethodToGet() { + $this->_method = self::GET; + 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; + } + + /** + * When sent, appends the authroization to the headers + * + * @param bool + * @return this + */ + public function useAuthorization($use = true) { + Eden_Oauth_Error::get()->argument(1, 'bool'); + $this->_useAuthorization = $use; + return $this; + } + + /** + * Some Oauth servers requires a realm to be set + * + * @param string + * @return this + */ + public function setRealm($realm) { + Eden_Oauth_Error::get()->argument(1, 'string'); + $this->_realm = $realm; + 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::get()->argument(1, 'scalar'); + $this->_verifier = $verifier; + 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::get() + ->argument(1, 'string') + ->argument(2, 'string'); + + $this->_requestToken = $token; + $this->_requestSecret = $secret; + + return $this; + } + + /** + * Returns the authorization header string + * + * @param string + * @return string + */ + public function getAuthorization($signature, $string = true) { + //argument test + Eden_Oauth_Error::get() + ->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); + + //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(!$string) { + return $params; + } + + return sprintf(self::AUTH_HEADER, $this->_buildQuery($params, ',', false)); + } + + /** + * 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); + + //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']); + } + + $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 signature + * + * @return string + */ + public function getHmacPlainTextSignature() { + return $this->_consumerSecret . '&' . $this->_tokenSecret; + } + + /** + * 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 token from the server + * + * @param array + * @return array + */ + public function getResponse(array $query = array()) { + $headers = $this->_headers; + + //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::get()->verifyHost(false)->verifyPeer(false); + + //if post + if($this->_method == self::POST) { + $headers[] = self::POST_HEADER; + + //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 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 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 results + * parsed as SimpleXml + * + * @return SimpleXmlElement + */ + public function getSimpleXmlResponse(array $query = array()) { + return simplexml_load_string($this->getResponse($query)); + } + + /** + * Returns the results + * parsed as DOMDocument + * + * @return DOMDOcument + */ + public function getDomDocumentResponse(array $query = array()) { + $xml = new DOMDocument(); + $xml->loadXML($this->getResponse($query)); + return $xml; + } + + /* 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..83bd539 --- /dev/null +++ b/library/eden/oauth/error.php @@ -0,0 +1,42 @@ + +/* + * 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 + * @version $Id: exception.php 1 2010-01-02 23:06:36Z blanquera $ + */ +class Eden_Oauth_Error extends Eden_Error { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function get($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/oauth/server.php b/library/eden/oauth/server.php new file mode 100644 index 0000000..a90872a --- /dev/null +++ b/library/eden/oauth/server.php @@ -0,0 +1,41 @@ + +/* + * 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. + */ + +/** + * Oauth server methods + * + * @package Eden + * @category oauth + * @author Christian Blanquera + * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ + */ +class Eden_Oauth_Server extends Eden_Oauth_Base { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function get() { + return self::_getMultiple(__CLASS__); + } + + /* Magic + -------------------------------*/ + /* 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..2791f04 --- /dev/null +++ b/library/eden/path.php @@ -0,0 +1,305 @@ + +/* + * 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__).'/class.php'; + +/** + * General available methods for common pathing issues + * + * @package Eden + * @subpackage path + * @category path + * @author Christian Blanquera + * @version $Id: path.php 3 2010-01-06 01:16:54Z blanquera $ + */ +class Eden_Path extends Eden_Class implements ArrayAccess { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function get($path) { + return self::_getMultiple(__CLASS__, $path); + } + + /* Magic + -------------------------------*/ + public function __construct($path) { + //argument 1 must be a string + Eden_Path_Error::get()->argument(1, 'string'); + $this->_path = $this->_format($path); + } + + public function __toString() { + return $this->_path; + } + + /* 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::get()->argument(1, 'string', 'null'); + + //if path is a directory or file + if(is_dir($this->_path) || is_file($this->_path)) { + 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->_path; + + //if absolute is a directory or file + if(is_dir($absolute) || is_file($absolute)) { + $this->_path = $absolute; + return $this; + } + + //if we are here then it means that no path was found so we should throw an exception + Eden_Path_Error::get() + ->setMessage(Eden_Path_Error::FULL_PATH_NOT_FOUND) + ->addVariable($this->_path) + ->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::get()->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->_path .= $this->_format($path); + } + + return $this; + } + + /** + * 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::get()->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->_path = $this->_format($path).$this-_path; + } + + return $this; + } + + /** + * Replaces the last path with this one + * + * @param string + * @return string + */ + public function replace($path) { + //argument 1 must be a string + Eden_Path_Error::get()->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->_path = implode('/', $pathArray); + + return $this; + } + + /** + * Remove the last path + * + * @return this + */ + public function pop(){ + //get the path array + $pathArray = $this->getArray(); + + //remove the last + array_pop($pathArray); + + //set path + $this->_path = implode('/', $pathArray); + + return $this; + } + + /** + * Returns the path array + * + * @return array + */ + public function getArray() { + return explode('/', $this->_path); + } + + /** + * 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->_path = implode('/', $pathArray); + } + } + } + + /** + * isset using the ArrayAccess interface + * + * @param number + * @return bool + */ + public function offsetExists($offset) { + return in_array($offset, $this->getArray()); + } + + /** + * unsets using the ArrayAccess interface + * + * @param number + * @return bool + */ + public function offsetUnset($offset) {} + + /** + * returns data using the ArrayAccess interface + * + * @param number + * @return bool + */ + public function offsetGet($offset) { + if(is_numeric($offset)) { + $pathArray = $this->getArray(); + return isset($pathArray[$offset]) ? $pathArray[$offset] : NULL; + } + + return NULL; + } + + /* 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 + -------------------------------*/ + /* Get + -------------------------------*/ + public static function get($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/paypal/error.php b/library/eden/paypal/error.php new file mode 100644 index 0000000..baec7d6 --- /dev/null +++ b/library/eden/paypal/error.php @@ -0,0 +1,10 @@ + + + + +Untitled Document + + + + + \ No newline at end of file diff --git a/library/eden/paypal/payflowpro.php b/library/eden/paypal/payflowpro.php new file mode 100644 index 0000000..baec7d6 --- /dev/null +++ b/library/eden/paypal/payflowpro.php @@ -0,0 +1,10 @@ + + + + +Untitled Document + + + + + \ No newline at end of file diff --git a/library/eden/registry.php b/library/eden/registry.php new file mode 100755 index 0000000..841a9fd --- /dev/null +++ b/library/eden/registry.php @@ -0,0 +1,305 @@ + +/* + * 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__).'/array.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 + * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ + */ +class Eden_Registry extends Eden_Array { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_data = array(); //data registry + + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function get(array $data = array()) { + return self::_getMultiple(__CLASS__, $data); + } + + /* Magic + -------------------------------*/ + /* Public Methods + -------------------------------*/ + /** + * Gets a value given the path in the registry. + * + * @return variable + */ + public function getData() { + //get the arguments + $args = func_get_args(); + //what object are we looking into? + //if the first argument is not an object + //use global registry + $data = $this->_data; + if(isset($args[0]) && (is_array($args[0]) || is_object($args[0]))) { + $data = array_shift($args); + } + + //set the remaining length + $length = count($args); + + if($length > 0) { + $result = NULL; + + //foreach argument + foreach($args as $key => $value) { + if(!is_string($value) && !is_numeric($value)) { + return $value; + } + + //this is the last item + if(($key+1) == $length) { + //assign it to result + //exit loop + try { + $result = NULL; + if(is_array($data) && isset($data[$value])) { + $result = $data[$value]; + } else if(is_object($data) && isset($data->{$value})) { + $result = $data->{$value}; + } + } catch(Exception $e) { + $result = NULL; + } + break; + } + + //the name does not exist + if(is_array($data) && !isset($data[$value])) { + //assign result to null + //exit loop + $result = NULL; + break; + } else if(is_object($data) && !isset($data->{$value})) { + //assign result to null + //exit loop + $result = NULL; + break; + } + + //walk the object + $data = is_array($data) ? $data[$value] : $data->{$value}; + } + return $result; + } + + //if no arguments + //return the whole object + return $data; + } + + /** + * Creates the name space given the space + * and sets the value to that name space + * + * @return Eden_RegistryModel + **/ + public function setData() { + //get the arguments + $args = func_get_args(); + //what object are we looking into? + //if the first argument is not an object + //use Eve's registry + $data = &$this->_data; + if(is_array($args[0]) || is_object($args[0])) { + $data = &array_shift($args); + } + + //set the remaining length + $length = count($args); + + if($length > 0) { + $last = NULL; + $index = NULL; + + //foreach argument + foreach($args as $key => $value) { + + //this is the last item + if(($key+1) == $length) { + //set it to the value + //exit loop + if(is_array($last)) { + $last[$index] = $value; + } else if(is_object($last)) { + $last->{$index} = $value; + } + + break; + } + + if(!is_string($value) && !is_numeric($value)) { + //set it to the value + //exit loop + if(is_array($last)) { + $last[$index] = $value; + } else if(is_object($last)) { + $last->{$index} = $value; + } + } + + //the name does not exist + if(is_array($data) && !isset($data[$value])) { + //create the namespace + $data[$value] = array(); + } else if(is_object($data) && !isset($data->{$value})) { + //create the namespace + $data->{$value} = new stdClass(); + } + + //walk the object + $last = &$data; + $index = $value; + if(is_array($data)) { + $data = &$data[$value]; + } else { + $data = &$data->{$value}; + } + } + } + + return $this; + } + + /** + * Unset a name space + * + * @return Eden_RegistryModel + **/ + public function unsetData() { + //get the arguments + $args = func_get_args(); + + //what object are we looking into? + //if the first argument is not an object + //use Eve's registry + $data = &$this->_data; + if(is_array($args[0]) || is_object($args[0])) { + $data = &array_shift($args); + } + + //set the remaining length + $length = count($args); + + if($length > 0) { + //foreach argument + foreach($args as $key => $value) { + if(!is_string($value) && !is_numeric($value)) { + //delete it + //exit loop + if(is_array($data)) + { + unset($data[$value]); + } else if(is_object($data)) { + unset($data->{$value}); + } + + return $this; + } + + //this is the last item + if(($key+1) == $length) { + //delete it + //exit loop + if(is_array($data)) + { + unset($data[$value]); + } else if(is_object($data)) { + unset($data->{$value}); + } + + return $this; + } + + //walk the object + if(is_array($data)) { + $data = &$data[$value]; + } else { + $data = &$data->{$value}; + } + } + } + + return $this; + } + + /** + * Checks to see if a name is taken + * + * @return bool + **/ + public function issetData() { + //get the arguments + $args = func_get_args(); + //what object are we looking into? + //if the first argument is not an object + //use Eve's registry + $data = $this->_data; + if(is_array($args[0]) || is_object($args[0])) { + $data = array_shift($args); + } + + //set the remaining length + $length = count($args); + + if($length > 0) { + //foreach argument + foreach($args as $key => $value) { + if(!is_string($value) && !is_numeric($value)) { + return false; + } + + //walk the object + if(is_array($data)) + { + if(isset($data[$value])) { + $data = $data[$value]; + } else { + return false; + } + } else { + if(isset($data->{$value})) { + $data = $data->{$value}; + } else { + return false; + } + } + } + + return true; + } + + //if no arguments + //then return false + return false; + } + + /* 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..934a419 --- /dev/null +++ b/library/eden/route.php @@ -0,0 +1,399 @@ + +/* + * 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__).'/class.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 + * @subpackage route + * @category framework + * @author Christian Blanquera + * @version $Id: route.php 1 2010-01-02 23:06:36Z blanquera $ + */ +class Eden_Route extends Eden_Class { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected static $_instance = NULL; + protected $_classes = array(); //class registry + protected $_methods = array(); //tracks methods for classes + + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function get() { + $class = __CLASS__; + if(is_null(self::$_instance)) { + self::$_instance = new $class(); + } + + return self::$_instance; + } + + /* Magic + -------------------------------*/ + /* Public Methods + -------------------------------*/ + /** + * Routes a class + * + * @param *string the class route name + * @param *string the name of the class to route to + * @return Eden_Route + */ + public function routeClass($route, $class) { + Eden_Route_Error::get() + ->argument(1, 'string') //argument 1 must be a string + ->argument(2, 'string'); //argument 2 must be a string + + $this->_classes[$route] = $class; + return $this; + } + + /** + * 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 getRouteClass($route, $default = NULL) { + //argument 1 must be a string + Eden_Route_Error::get()->argument(1, 'string'); + + if(isset($this->_classes[$route])) { + return $this->_classes[$route]; + } + + return $default; + } + + /** + * Returns the class route name that will be routed to given the class. + * + * @param *string the name of the class + * @param string|null returns this variable if no route is found + * @return string|variable + */ + public function getClassRoute($class, $default = NULL) { + //argument 1 must be a string + Eden_Route_Error::get()->argument(1, 'string'); + + foreach($this->_classes as $i => $to) { + if($to == $class) { + return $i; + } + } + + return $default; + } + + /** + * Returns all class routes + * + * @return array + */ + public function getClassRoutes() { + return $this->_classes; + } + + /** + * Checks to see if a name is a route + * + * @param string + * @return bool + */ + public function isClassRoute($route) { + return isset($this->_classes[$route]); + } + + /** + * 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 routeMethod($routeClass, $routeMethod, $class, $method = NULL) { + //argument test + Eden_Route_Error::get() + ->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 method is not a string + if(!is_string($method)) { + $method = $routeMethod; + } + + $routeClass = $this->getRouteClass($routeClass, $routeClass); + $class = $this->getRouteClass($class, $class); + + $this->_methods[$routeClass][$routeMethod] = array($class, $method); + + return $this; + } + + /** + * 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 getRouteMethod($class, $method, $default = NULL) { + Eden_Route_Error::get() + ->argument(1, 'string') //argument 1 must be a string + ->argument(2, 'string'); //argument 2 must be a string + + $class = $this->getRouteClass($class, $class); + + if(isset($this->_methods[$class][$method])) { + return $this->_methods[$class][$method]; + } + + return $default; + } + + /** + * Returns the route name that will be routed to given the class and method. + * + * @param *string the name of the class + * @param *string the name of the method + * @param string|null returns this variable if no route is found + * @return array|variable + */ + public function getMethodRoute($class, $method, $default = NULL) { + Eden_Route_Error::get() + ->argument(1, 'string') //argument 1 must be a string + ->argument(2, 'string'); //argument 2 must be a string + + $class = $this->getRouteClass($class, $class); + + foreach($this->_methods as $routeClass => $routeMethods) { + foreach($routeMethods as $routeMethod => $to) { + if($to[0] == $class && $to[1] == $method) { + return array($routeClass, $routeMethod); + } + } + } + return $default; + } + + /** + * Checks to see if a name is a route + * + * @param string + * @param string + * @return bool + */ + public function isMethodRoute($class, $method) { + return isset($this->_methods[$class][$method]); + } + + /** + * Returns all method routes + * + * @return array + */ + public function getMethodRoutes() { + return $this->_methods; + } + + /** + * Gets a class considering all routes. + * + * @param *string class + * @param [variable..] arguments + * @return object + */ + public function getClass($class) { + //argument 1 must be a string + Eden_Route_Error::get()->argument(1, 'string'); + + $args = func_get_args(); + $class = array_shift($args); + + + return $this->getClassArray($class, $args); + } + + /** + * Gets a class considering all routes. + * + * @param *string class + * @param array arguments + * @return object + */ + public function getClassArray($class, array $args = array()) { + //argument 1 must be a string + Eden_Route_Error::get()->argument(1, 'string'); + + return $this->callMethod($class, 'get', NULL, $args); + } + + /** + * Calls a method considering all routes + * + * @param *string|null the class name + * @param *string|null the method name + * @param true|null|object the instance; + * if null then the call will be treated as a + * static class; if true then an instance will + * be generated + * @param array the arguments you want to pass + * into the method + * @return mixed + */ + public function callMethod($class, $method, $instance = NULL, array $args = array()) { + //argument test + Eden_Route_Error::get() + ->argument(1, 'string', 'object') //argument 1 must be string or object + ->argument(2, 'string') //argument 2 must be string + ->argument(3, 'object', 'bool', 'null'); //argument 3 must be object, bool or null + + if(is_object($class)) { + $class = get_class($class); + } + + //class might be a route + //lets make sure that we are dealing with the right class + $class = $this->getRouteClass($class, $class); + + //method might be a route + //lets make sure we are dealing with the right method + list($class, $method) = $this->getRouteMethod($class, $method, array($class, $method)); + + //class does not exist + if(!class_exists($class)) { + //throw exception + Eden_Route_Error::get() + ->setMessage(Eden_Route_Error::CLASS_NOT_EXISTS) + ->addVariable($class) + ->addVariable($method) + ->trigger(); + } + + //method does not exist + if(!method_exists($class, $method)) { + Eden_Route_Error::get() + ->setMessage(Eden_Route_Error::METHOD_NOT_EXISTS) + ->addVariable($class) + ->addVariable($method) + ->trigger(); + } + + //if instance is true + //we want to load the + //instance for the user + if($instance === true) { + $instance = $this->getClass($class); + } + + //if instance is not an object + if(!is_object($instance)) { + if(!method_exists($class, $method)) { + //throw exception + Eden_Route_Error::get() + ->setMessage(Eden_Route_Error::STATIC_ERROR) + ->addVariable($class) + ->addVariable($method) + ->trigger(); + } + + return call_user_func_array($class.'::'.$method, $args); // As of 5.2.3 + } + + //instance is an object + //if method does not exist + if(!method_exists($instance, $method)) { + //throw exception + Eden_Route_Error::get() + ->setMessage(Eden_Route_Error::METHOD_NOT_EXISTS) + ->addVariable(get_class($instance)) + ->addVariable($method) + ->trigger(); + } + + return call_user_func_array(array(&$instance, $method), $args); + } + + /** + * Calls a function in a controlled environment + * + * @param *string the name of the function + * @param array the arguments you want to pass into the method + * @return mixed + */ + public function callFunction($func, array $args = array()) { + Eden_Error_Validate::get()->argument(0, 'string'); //argument 1 must be a string + + try { + //try to run the function using PHP call_user_func_array + return call_user_func_array($func, $args); + } catch(_Exception $e) { + Eden_Route_Error::get() + ->setMessage(Eden_Route_Error::FUNCTION_ERROR) + ->addVariable($func) + ->trigger(); + } + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} + +/** + * 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 + -------------------------------*/ + /* Get + -------------------------------*/ + public static function get($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/session.php b/library/eden/session.php new file mode 100755 index 0000000..09baaa5 --- /dev/null +++ b/library/eden/session.php @@ -0,0 +1,351 @@ + +/* + * 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__).'/class.php'; + +/** + * General available methods for common + * server session procedures. + * + * @package Eden + * @subpackage session + * @category tool + * @author Christian Blanquera + * @version $Id: session.php 1 2010-01-02 23:06:36Z blanquera $ + */ +class Eden_Session extends Eden_Class implements ArrayAccess, Iterator { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected static $_session = false; + + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function get() { + return self::_getSingleton(__CLASS__); + } + + /* Magic + -------------------------------*/ + public function __toString() { + if(!self::$_session) { + throw new Eden_Session_Error(Eden_Session_Error::ERROR_NOT_STARTED); + } + + return json_encode($_SESSION); + } + + /* Public Methods + -------------------------------*/ + /** + * Starts a session + * + * @return bool + */ + public function start() { + if (isset($_COOKIE['PHPSESSID'])) { + self::$_session = $_COOKIE['PHPSESSID']; + return $this; + } + + self::$_session = session_start(); + return $this; + } + + /** + * Starts a session + * + * @return Eden_SessionServer + */ + public function stop() { + self::$_session = false; + session_write_close(); + return $this; + } + + /** + * Sets data + * + * @param array|string + * @param mixed + * @return this + */ + public function setData($data, $value = NULL) { + $error = Eden_Session_Error::get()->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; + } + + /** + * Returns data + * + * @param string|null + * @return mixed + */ + public function getData($key = NULL) { + $error = Eden_Session_Error::get()->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) { + throw new Eden_Session_Error(Eden_Session_Error::ERROR_NOT_STARTED); + } + + return session_id(); + } + + /** + * Sets the session ID + * + * @param *int + * @return int + */ + public function setId($sid) { + $error = Eden_Session_Error::get()->argument(1, 'numeric'); + + if(!self::$_session) { + $error->setMessage(Eden_Session_Error::ERROR_ERROR_NOT_STARTED)->trigger(); + } + + return session_id((int) $sid); + } + + /** + * Removes a session. + * + * @param *string session name + * @return this + */ + public function remove($name) { + Eden_Session_Error::get()->argument(1, 'string'); + + if(isset($_SESSION[$name])) { + unset($_SESSION[$name]); + } + + return $this; + } + + /** + * Removes all session data + * + * @return bool + */ + public function clear() { + if(!self::$_session) { + throw new Eden_Session_Error(Eden_Session_Error::ERROR_NOT_STARTED); + } + + $_SESSION = array(); + + return $this; + } + + /** + * Rewinds the position + * For Iterator interface + * + * @return void + */ + public function rewind() { + if(!self::$_session) { + throw new Eden_Session_Error(Eden_Session_Error::ERROR_NOT_STARTED); + } + + reset($_SESSION); + } + + /** + * Returns the current item + * For Iterator interface + * + * @return void + */ + public function current() { + if(!self::$_session) { + throw new Eden_Session_Error(Eden_Session_Error::ERROR_NOT_STARTED); + } + + return current($_SESSION); + } + + /** + * Returns th current position + * For Iterator interface + * + * @return void + */ + public function key() { + if(!self::$_session) { + throw new Eden_Session_Error(Eden_Session_Error::ERROR_NOT_STARTED); + } + + return key($_SESSION); + } + + /** + * Increases the position + * For Iterator interface + * + * @return void + */ + public function next() { + if(!self::$_session) { + throw new Eden_Session_Error(Eden_Session_Error::ERROR_NOT_STARTED); + } + + next($_SESSION); + } + + /** + * Validates whether if the index is set + * For Iterator interface + * + * @return void + */ + public function valid() { + if(!self::$_session) { + throw new Eden_Session_Error(Eden_Session_Error::ERROR_NOT_STARTED); + } + + return isset($_SESSION[$this->key()]); + } + + /** + * Sets data using the ArrayAccess interface + * + * @param number + * @param mixed + * @return void + */ + public function offsetSet($offset, $value) { + if(!self::$_session) { + throw new Eden_Session_Error(Eden_Session_Error::ERROR_NOT_STARTED); + } + + if (is_null($offset)) { + $_SESSION[] = $value; + } else { + $_SESSION[$offset] = $value; + } + } + + /** + * isset using the ArrayAccess interface + * + * @param number + * @return bool + */ + public function offsetExists($offset) { + if(!self::$_session) { + throw new Eden_Session_Error(Eden_Session_Error::ERROR_NOT_STARTED); + } + + return isset($_SESSION[$offset]); + } + + /** + * unsets using the ArrayAccess interface + * + * @param number + * @return bool + */ + public function offsetUnset($offset) { + if(!self::$_session) { + throw new Eden_Session_Error(Eden_Session_Error::ERROR_NOT_STARTED); + } + + unset($_SESSION[$offset]); + } + + /** + * returns data using the ArrayAccess interface + * + * @param number + * @return bool + */ + public function offsetGet($offset) { + if(!self::$_session) { + throw new Eden_Session_Error(Eden_Session_Error::ERROR_NOT_STARTED); + } + + return isset($_SESSION[$offset]) ? $_SESSION[$offset] : NULL; + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} + +/** + * Session Errors + */ +class Eden_Session_Error extends Eden_Error { + /* Constants + -------------------------------*/ + const ERROR_ERROR_NOT_STARTED = 'Session is not started. Try using Eden_Session->start() first.'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function get($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/sql/database.php b/library/eden/sql/database.php new file mode 100755 index 0000000..bf2e958 --- /dev/null +++ b/library/eden/sql/database.php @@ -0,0 +1,93 @@ + +/* + * 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. + */ + +/** + * 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 + * @version $Id: abstract.php 1 2010-01-02 23:06:36Z blanquera $ + */ +class Eden_Sql_Database extends Eden_Event { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function get() { + return self::_getSingleton(__CLASS__); + } + + /* Magic + -------------------------------*/ + /* Public Methods + -------------------------------*/ + /** + * 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::get()->argument(1, 'string', 'null'); + + return Eden_Sql_Delete::get($table); + } + + /** + * 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::get()->argument(1, 'string', 'null'); + + return Eden_Sql_Insert::get($table); + } + + /** + * Returns the select query builder + * + * @return Eden_Sql_Select + */ + public function select($select = '*') { + //Argument 1 must be a string or array + Eden_Sql_Error::get()->argument(1, 'string', 'array'); + + return Eden_Sql_Select::get($select); + } + + /** + * 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::get()->argument(1, 'string', 'null'); + + return Eden_Sql_Update::get($table); + } + + /* 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..5d06d92 --- /dev/null +++ b/library/eden/sql/delete.php @@ -0,0 +1,94 @@ + +/* + * 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. + */ + +/** + * Generates delete query string syntax + * + * @package Eden + * @category sql + * @author Christian Blanquera + * @version $Id: delete.php 1 2010-01-02 23:06:36Z blanquera $ + */ +class Eden_Sql_Delete extends Eden_Sql_Query { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_table = NULL; + protected $_where = array(); + + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function get($table = NULL) { + return self::_getMultiple(__CLASS__, $table); + } + + /* Magic + -------------------------------*/ + public function __construct($table = NULL) { + if(is_string($table)) { + $this->setTable($table); + } + } + + /* Public Methods + -------------------------------*/ + /** + * 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::get()->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::get()->argument(1, 'string', 'array'); + + if(is_string($where)) { + $where = array($where); + } + + $this->_where = array_merge($this->_where, $where); + + return $this; + } + + /** + * 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/sql/error.php b/library/eden/sql/error.php new file mode 100755 index 0000000..614f08b --- /dev/null +++ b/library/eden/sql/error.php @@ -0,0 +1,42 @@ + +/* + * 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 + * @version $Id: exception.php 1 2010-01-02 23:06:36Z blanquera $ + */ +class Eden_Sql_Error extends Eden_Error { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function get($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/sql/insert.php b/library/eden/sql/insert.php new file mode 100755 index 0000000..4f264fe --- /dev/null +++ b/library/eden/sql/insert.php @@ -0,0 +1,103 @@ + +/* + * 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. + */ + +/** + * Generates insert query string syntax + * + * @package Eden + * @category sql + * @author Christian Blanquera + * @version $Id: insert.php 1 2010-01-02 23:06:36Z blanquera $ + */ +class Eden_Sql_Insert extends Eden_Sql_Query { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_setKey = array(); + protected $_setVal = array(); + + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function get($table = NULL) { + return self::_getMultiple(__CLASS__, $table); + } + + /* Magic + -------------------------------*/ + public function __construct($table = NULL) { + if(is_string($table)) { + $this->setTable($table); + } + } + + /* Public Methods + -------------------------------*/ + /** + * 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::get()->argument(1, 'string'); + + $this->_table = $table; + return $this; + } + + /** + * 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::get() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'string', 'number'); //Argument 2 must be a string or number + + if(!in_array($key, $this->_setKey)) { + $this->_setKey[] = $key; + } + + $this->_setVal[$index][] = $value; + return $this; + } + + /** + * 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).';'; + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} diff --git a/library/eden/sql/query.php b/library/eden/sql/query.php new file mode 100755 index 0000000..968d790 --- /dev/null +++ b/library/eden/sql/query.php @@ -0,0 +1,51 @@ + +/* + * 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. + */ + +/** + * Generates select query string syntax + * + * @package Eden + * @category sql + * @author Christian Blanquera + * @version $Id: select.php 1 2010-01-02 23:06:36Z blanquera $ + */ +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/select.php b/library/eden/sql/select.php new file mode 100755 index 0000000..deb8819 --- /dev/null +++ b/library/eden/sql/select.php @@ -0,0 +1,292 @@ + +/* + * 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. + */ + +/** + * Generates select query string syntax + * + * @package Eden + * @category sql + * @author Christian Blanquera + * @version $Id: select.php 1 2010-01-02 23:06:36Z blanquera $ + */ +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 + -------------------------------*/ + /* Get + -------------------------------*/ + public static function get($select = '*') { + return self::_getMultiple(__CLASS__, $select); + } + + /* Magic + -------------------------------*/ + public function __construct($select = '*') { + $this->select($select); + } + + /* 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_Sql_Error::get()->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_Sql_Error::get()->argument(1, 'string'); + + $this->_from = $from; + return $this; + } + + /** + * 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::get() + ->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; + } + + /** + * 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::get() + ->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->joined('INNER', $table, $where, $using); + } + + /** + * 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::get() + ->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->joined('OUTER', $table, $where, $using); + } + + /** + * 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::get() + ->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->joined('LEFT', $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::get() + ->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->joined('RIGHT', $table, $where, $using); + } + + /** + * 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::get()->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_Sql_Error::get() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'string'); //Argument 2 must be a string + + $this->_sortBy[] = $field . ' ' . $order; + + return $this; + } + + /** + * 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::get()->argument(1, 'string', 'array'); + + if(is_string($group)) { + $this->_group = array($group); + } + + $this->_group = $group; + 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_Sql_Error::get() + ->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() { + $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, $sort, $limit, $group); + + return str_replace(' ', ' ', $query); + } + + /* 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..ece069d --- /dev/null +++ b/library/eden/sql/update.php @@ -0,0 +1,79 @@ + +/* + * 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. + */ + +/** + * Generates update query string syntax + * + * @package Eden + * @category sql + * @author Christian Blanquera + * @version $Id: update.php 1 2010-01-02 23:06:36Z blanquera $ + */ +class Eden_Sql_Update extends Eden_Sql_Delete { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_set = array(); + + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function get($table = NULL) { + return self::_getMultiple(__CLASS__, $table); + } + + /* Magic + -------------------------------*/ + /* Public Methods + -------------------------------*/ + /** + * 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::get() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'string', 'number'); //Argument 2 must be a string or number + + $this->_set[$key] = $value; + + return $this; + } + + /** + * 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).';'; + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/string.php b/library/eden/string.php new file mode 100755 index 0000000..3af4a39 --- /dev/null +++ b/library/eden/string.php @@ -0,0 +1,209 @@ + +/* + * 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__).'/class.php'; +require_once dirname(__FILE__).'/type/abstract.php'; +require_once dirname(__FILE__).'/type/error.php'; +require_once dirname(__FILE__).'/array.php'; + +/** + * + * @package Eden + * @category registry + * @author Christian Blanquera + * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ + */ +class Eden_String extends Eden_Type_Abstract { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected static $_preMethods = array( + 'addslashes', + 'bin2hex', 'chunk_split', + 'convert_uudecode', 'convert_uuencode', + 'crypt', 'html_entity_decode', + 'htmlentities', 'htmlspecialchars_decode', + 'htmlspecialchars', 'lcfirst', + 'ltrim', 'md5', + 'nl2br', 'quoted_printable_decode', + 'quoted_printable_encode', 'quotemeta', + 'rtrim', 'sha1', + 'sprintf', 'str_pad', + 'str_repeat', 'str_rot13', + 'str_shuffle', 'strip_tags', + 'stripcslashes', 'stripslashes', + 'strpbrk', 'stristr', + 'strrev', 'strstr', + 'strtok', 'strtolower', + 'strtoupper', 'strtr', + 'substr_replace', 'substr', + 'trim', 'ucfirst', + 'ucwords', 'vsprintf', + 'wordwrap', 'count_chars', + 'hex2bin', 'strlen', + 'strpos', 'substr_compare', + 'substr_count'); + + protected static $_postMethods = array('str_ireplace', 'str_replace', 'explode'); + + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function get($data) { + //argument 1 must be a string + Eden_String_Error::get()->argument(1, 'string'); + + return self::_getMultiple(__CLASS__, $data); + } + + /* Magic + -------------------------------*/ + 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_String_Error::get()->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; + } + + /** + * Uncamelizes a string + * + * @param string prefix + * @return this + */ + public function uncamelize($prefix = '-') { + //argument 1 must be a string + Eden_String_Error::get()->argument(1, 'string'); + + $this->_data = strtolower(preg_replace("/([A-Z])/", $prefix."$1", $this->_data)); + + 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_String_Error::get()->argument(1, 'string'); + + $this->_data = ucwords(str_replace($prefix, ' ', $this->_data)); + + return $this; + } + + /* Protected Methods + -------------------------------*/ + protected function _getPreMethod($name) { + if(in_array($name, self::$_preMethods)) { + return $name; + } + + if(in_array('str'.$name, self::$_preMethods)) { + return 'str'.$name; + } + + if(in_array('str_'.$name, self::$_preMethods)) { + return 'str_'.$name; + } + + return false; + } + + protected function _getPostMethod($name) { + if(in_array($name, self::$_postMethods)) { + return $name; + } + + if(in_array('str'.$name, self::$_postMethods)) { + return 'str'.$name; + } + + if(in_array('str_'.$name, self::$_postMethods)) { + return 'str_'.$name; + } + + return false; + } + + protected function _getReferenceMethod($name) { + return false; + } + + /* Private Methods + -------------------------------*/ +} + +/** + * String Errors + */ +class Eden_String_Error extends Eden_Type_Error { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function get($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/template.php b/library/eden/template.php new file mode 100755 index 0000000..a406d06 --- /dev/null +++ b/library/eden/template.php @@ -0,0 +1,194 @@ + +/* + * 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__).'/class.php'; + +/** + * General available methods for common templating procedures + * + * @package Eden + * @subpackage template + * @category tool + * @author Christian Blanquera + * @version $Id: template.php 1 2010-01-02 23:06:36Z blanquera $ + */ +class Eden_Template extends Eden_Class { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_data = array(); + + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function get() { + return self::_getMultiple(__CLASS__); + } + + /* Magic + -------------------------------*/ + /* Public Methods + -------------------------------*/ + /** + * Sets template variables + * + * @param array|string + * @param mixed + * @return this + */ + public function setData($data, $value = NULL) { + Eden_Template_Error::get()->argument(0, '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::get()->argument(0, '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 + * @return string + */ + public function parsePhp($____file) { + Eden_Template_Error::get()->argument(0, $____file, 'string'); + + extract($this->_data, EXTR_SKIP); // Extract the values to a local namespace + ob_start(); // Start output buffering + include $____file; // Include the template file + $____contents = ob_get_contents(); // Get the contents of the buffer + ob_end_clean(); // End buffering and discard + return $____contents; // Return the contents + } + + /** + * For non PHP templates, this will transform the given document to an actual page or partial + * + * @param *string template file + * @return string + */ + public function parseEngine($template) { + Eden_Template_Error::get()->argument(0, 'string'); + + $lines = explode("\n", $template); + $count = count($lines); + for($i = 0; $i < $count; $i++) { + $patterns = array(); + + //handle all the easy values + preg_match_all("/{(.*?)}/", $lines[$i], $patterns); + if(!empty($patterns[0]) && !empty($patterns[1])) { + foreach($patterns[1] as $j => $key) { + $value = isset($this->_data[$key]) ? $this->_data[$key] : ''; + $lines[$i] = str_replace($patterns[0][$j], $value, $lines[$i]); + } + } + + preg_match_all("//", $lines[$i], $patterns); + if(!empty($patterns[0]) && !empty($patterns[1])) { + foreach($patterns[1] as $j => $key) { + $value = isset($this->_data[$key]) ? $this->_data[$key] : ''; + $lines[$i] = str_replace($patterns[0][$j], $value, $lines[$i]); + } + } + + //handle advanced pattern + preg_match_all("//", $lines[$i], $patterns); + if(!empty($patterns[0]) && !empty($patterns[1])) { + foreach($patterns[1] as $j => $key) { + $subTemplate = array(); + $closePattern = str_replace('', '', $lines[$i]); + unset($lines[$i]); + $i++; + while($i < $count && $lines[$i] != $closePattern) { + $subTemplate[] = $lines[$i]; + + unset($lines[$i]); + $i++; + + } + + $lines[$i] = array(); + + if(isset($this->_data[$key]) && is_array($this->_data[$key])) { + foreach($this->_data[$key] as $value) { + if(is_array($value)) { + $lines[$i][] = Eden_Template::get() + ->setData($value) + ->parseEngine(implode("\n", $subTemplate)); + } + } + } + + $lines[$i] = implode("\n", $lines[$i]); + } + } + } + + return implode("\n", $lines); + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} + +/** + * Template Errors + */ +class Eden_Template_Error extends Eden_Error { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function get($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/timezone.php b/library/eden/timezone.php new file mode 100644 index 0000000..97c813f --- /dev/null +++ b/library/eden/timezone.php @@ -0,0 +1,136 @@ + +/* + * 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__).'/class.php'; + +/** + * General available methods for common time zone procedures. + * + * @package Eden + * @subpackage timezone + * @category tool + * @author Christian Blanquera + * @version $Id: timezone.php 1 2010-01-02 23:06:36Z blanquera $ + */ +class Eden_Timezone extends Eden_Class { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function get() { + return self::_getSingleton(__CLASS__); + } + + /* Magic + -------------------------------*/ + /* Public Methods + -------------------------------*/ + /** + * Returns a list of timezones + * + * @param string key + * @return array + */ + public function getTimeZones($key = NULL) { + //Argument 1 must be a string or null + Eden_Timezone_Error::get()->argument(1, 'string', 'null'); + + $zones = array(); + $zonesProcessed = array(); + for($i = -43200; $i < 52200; $i += 3600) { + $zoneStandard = timezone_name_from_abbr(NULL, $i, 0); + $zoneDaylightSavings = timezone_name_from_abbr(NULL, $i, 1); + + $name = $zoneDaylightSavings ? $zoneDaylightSavings : $zoneStandard; + + if($name && !in_array($name, $zonesProcessed)) { + $date = new DateTime( 'now', new DateTimeZone($name) ); + $alias = explode('/', $name); + $alias = str_replace('_', ' ', $alias[1]); + $zone = array( + 'name' => $name, + 'offset' => $i, + 'abbr' => $date->format('T'), + 'alias' => $alias, + //PHP BUG: $date->format('U') returns the system unix time + 'time' => $date->format('Y m d g i s')); + if(isset($zone[$key])) { + $zones[$zone[$key]] = $zone; + } else { + $zones[] = $zone; + } + + $zonesProcessed[] = $name; + } + } + + return $zones; + } + + /** + * Returns the current system unix time in another zone + * + * @param *string zoneName + * @param int systemTime + * @return int + */ + public function getTimeInZone($zoneName, $systemTime = NULL) { + //argument testing + Eden_Timezone_Error::get() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'int', 'null'); //Argument 2 must be a string or null + + $systemTime = $systemTime ? $systemTime : time(); + + $systemOffset = date('Z'); + $zoneOffset = new DateTime("now", new DateTimeZone($zoneName)); + $zoneOffset = $zoneOffset->getOffset(); + return ($systemOffset * -1) + $zoneOffset + $systemTime; + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} + +/** + * Timezone Errors + */ +class Eden_Timezone_Error extends Eden_Error { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function get($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/tool.php b/library/eden/tool.php new file mode 100644 index 0000000..e19a199 --- /dev/null +++ b/library/eden/tool.php @@ -0,0 +1,109 @@ + +/* + * 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. + */ + +/** + * Every other random method that can't be grouped as a class + * + * @package Eden + * @subpackage tool + * @category tool + * @author Christian Blanquera + * @version $Id: tool.php 3 2010-01-06 01:16:54Z blanquera $ + */ +class Eden_Tool extends Eden_Class { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_uid = 0; + + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function get() { + return self::_getSingleton(__CLASS__); + } + + /* Magic + -------------------------------*/ + /* Public Methods + -------------------------------*/ + /** + * Returns a unique token that can be used for anything + * + * @return int + */ + public function uid() { + $this->_uid++; + return $this->_uid; + } + + /** + * Returns the data type given the variable + * + * @param *mixed data + * @param string data type to compare to + * @return string|bool + */ + public function type( $obj, $value = false) { + $value = is_string($value) ? array($value) : $value; + + switch(true) { + case is_array($obj): + $obj = 'array'; + break; + case is_object($obj): + $obj = 'object'; + break; + case is_bool($obj): + $obj = 'bool'; + break; + case is_numeric($obj): + $obj = 'number'; + break; + case is_string($obj): + $obj = 'string'; + break; + case is_null($obj): + $obj = 'null'; + break; + default: + $obj = 'unknown'; + break; + } + return $value ? in_array($obj, $value) : $obj; + } + + /** + * 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 + -------------------------------*/ + /* 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..238bdc9 --- /dev/null +++ b/library/eden/type/abstract.php @@ -0,0 +1,132 @@ + +/* + * 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. + */ + +/** + * + * @package Eden + * @category registry + * @author Christian Blanquera + * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ + */ +abstract class Eden_Type_Abstract extends Eden_Class { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_methods = array(); + + protected $_data = NULL; + protected $_original = NULL; + + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + /* Magic + -------------------------------*/ + public function __construct($data) { + $this->_original = $this->_data = $data; + } + + public function __call($name, $args) { + $method = $this->_getPreMethod($name); + + //if this is a pre method + if($method) { + //add the string as first arg + array_unshift($args, $this->_data); + } else { + $method = $this->_getPostMethod($name); + + //if this is a post method + if($method) { + //add string at the end of the arguments + array_push($args, $this->_data); + } else { + $method = $this->_getReferenceMethod($name); + //if this is a reference method + if($method) { + //call the method + $name($this->_data); + return $this; + } + } + } + + //if this is a method + if($method) { + //call the method + $result = call_user_func_array($method, $args); + + //if the result is a string + if(is_string($result)) { + //if this class is a string type + if($this instanceof Eden_String) { + //set value + $this->_data = $result; + return $this; + } + + //return string class + return Eden_String::get($result); + } + + //if the result is an array + if(is_array($result)) { + //if this class is a array type + if($this instanceof Eden_Array) { + //set value + $this->_data = $result; + return $this; + } + + //return array class + return Eden_Array::get($result); + } + + return $result; + } + + //we don't process anything else + try { + //call the parent + return parent::__call($name, $args); + } catch(Eden_Error $e) { + throw new Eden_Type_Error($e->getMessage()); + } + } + + /* Public Methods + -------------------------------*/ + /** + * Returns the string + * + * @param bool whether to get the modified or original version + * @return string + */ + public function getValue($modified = true) { + //argument 1 must be a bool + Eden_Type_Validate::get()->argument(1, 'bool'); + + return $modified ? $this->_data : $this->_original; + } + + /* Protected Methods + -------------------------------*/ + abstract protected function _getPreMethod($name); + + abstract protected function _getPostMethod($name); + + abstract protected function _getReferenceMethod($name); + + /* 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..d0fe7f1 --- /dev/null +++ b/library/eden/type/error.php @@ -0,0 +1,42 @@ + +/* + * 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 type + * @author Christian Blanquera + * @version $Id: exception.php 1 2010-01-02 23:06:36Z blanquera $ + */ +class Eden_Type_Error extends Eden_Error { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function get($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/unit.php b/library/eden/unit.php new file mode 100755 index 0000000..6acf80a --- /dev/null +++ b/library/eden/unit.php @@ -0,0 +1,394 @@ + +/* + * 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. + */ + +/** + * + * + * @package Eden + * @category core + * @author Christian Blanquera + * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ + */ +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 + -------------------------------*/ + /* Get + -------------------------------*/ + public static function get() { + $class = __CLASS__; + return new $class; + } + + /* Magic + -------------------------------*/ + 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 setPackage($name) { + //Argument 1 must be a string + Eden_Unit_Error::get()->argument(1, 'string'); + + $this->_package = $name; + return $this; + } + + public function getTotalTests($package = NULL) { + //Argument 1 must be a string or null + Eden_Unit_Error::get()->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 getPassFail($package = NULL) { + //Argument 1 must be a string or null + Eden_Unit_Error::get()->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; + } + + /* Protected Methods + -------------------------------*/ + protected function _assertArrayHasKey($needle, $haystack) { + try { + Eden_Unit_Error::get() + ->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::get() + ->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::get() + ->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::get() + ->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::get() + ->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::get() + ->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::get() + ->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::get() + ->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::get()->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::get() + ->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::get() + ->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::get() + ->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::get() + ->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::get() + ->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 + -------------------------------*/ + /* Get + -------------------------------*/ + public static function get($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/validation.php b/library/eden/validation.php new file mode 100644 index 0000000..b1e3b63 --- /dev/null +++ b/library/eden/validation.php @@ -0,0 +1,333 @@ + +/* + * 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. + */ + +/** + * Validation + * + * @package Eden + * @category validation + * @author Christian Blanquera + * @version $Id: abstract.php 5 2010-01-08 22:21:29Z blanquera $ + */ +class Eden_Validation extends Eden_Class { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_value = NULL; + + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function get($value) { + return self::_getMultiple(__CLASS__, $value); + } + + /* Magic + -------------------------------*/ + public function __construct($value) { + $this->_value = $value; + } + + /* Public Methods + -------------------------------*/ + public function getErrors(array $tests = array()) { + $errors = array(); + foreach($tests as $test) { + + $method = $test['method']; + + $message = false; + if(isset($test['message'])) { + $message = $test['message']; + } + + $value = NULL; + if(isset($test['value'])) { + $value = $test['value']; + } + + if(method_exists($this, $method) && !$this->$method($value)) { + $errors[$method] = $message; + } + } + + return $errors; + } + + /** + * Test for data type array + * + * @return bool + */ + public function isArray() { + return is_array($this->_value); + } + + /** + * Test for data type number + * + * @return bool + */ + public function isNumber() { + return is_numeric($this->_value); + } + + /** + * Test for data type boolean + * + * @return bool + */ + public function isBool() { + return is_bool($this->_value); + } + + /* Public String Methods + -------------------------------*/ + /** + * Test for string not empty + * + * @return bool + */ + public function isNotEmpty() { + return !empty($this->_value); + } + + /** + * Test for string is email + * + * @return bool + */ + public function isEmail() { + 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}\])$/', $this->_value); + } + + /** + * Test for string is url + * + * @return bool + */ + public function isUrl() { + return preg_match('/^(http|https|ftp)://([A-Z0-9][A-Z0-9_-]*(?:.[A-Z0-9][A-Z0-9_-]*)+):?(d+)?/?/i', $this->_value); + } + + /** + * Test for string is HTML + * + * @return bool + */ + public function isHtml() { + return preg_match("/<\/?\w+((\s+(\w|\w[\w-]*\w)(\s*=\s*(?:\".*?\"|'.*?'|[^'\">\s]+))?)+\s*|\s*)\/?>/i", $this->_value); + } + + /** + * Test for string is short name + * + * @return bool + */ + public function isShortName() { + return !preg_match("/[^a-z0-9_]/i", $this->_value); + } + + /** + * Test for string starting with any letter + * + * @return bool + */ + public function startsWithLetter() { + return !preg_match("/^[a-zA-Z]/i", $this->_value); + } + + /** + * Test for string length greater than + * + * @param number + * @return bool + */ + public function lengthGreaterThan($number) { + Eden_Validation_Error::get()->argument('int'); + return strlen((string)$this->_value) > $number; + } + + /** + * Test for string length less than + * + * @param number + * @return bool + */ + public function lengthLessThan($number) { + Eden_Validation_Error::get()->argument('int'); + return strlen((string)$this->_value) < $number; + } + + /** + * Test for string length greater than equal to + * + * @param number + * @return bool + */ + public function lengthGreaterThanEqualTo($number) { + Eden_Validation_Error::get()->argument('int'); + return strlen((string)$this->_value) >= $number; + } + + /** + * Test for string length less than equal to + * + * @param number + * @return bool + */ + public function lengthLessThanEqualTo($number) { + Eden_Validation_Error::get()->argument('int'); + return strlen((string)$this->_value) <= $number; + } + + /** + * Test for words equal to + * + * @param number + * @return bool + */ + public function wordCountEquals($number) { + Eden_Validation_Error::get()->argument('int'); + $words = explode(' ', $this->_value); + return count($words) === $number; + } + + /** + * Test for words greater than + * + * @param number + * @return bool + */ + public function wordCountGreaterThan($number) { + Eden_Validation_Error::get()->argument('int'); + $words = explode(' ', $this->_value); + return count($words) > $number; + } + + /** + * Test for words less than + * + * @param number + * @return bool + */ + public function wordCountLessThan($number) { + Eden_Validation_Error::get()->argument('int'); + $words = explode(' ', $this->_value); + return count($words) < $number; + } + + /** + * Test for words greater than equal to + * + * @param number + * @return bool + */ + public function wordCountGreaterThanEqualTo($number) { + Eden_Validation_Error::get()->argument('int'); + $words = explode(' ', $this->_value); + return count($words) >= $number; + } + + /** + * Test for words less than equal to + * + * @param number + * @return bool + */ + public function wordCountLessThanEqualTo($number) { + Eden_Validation_Error::get()->argument('int'); + $words = explode(' ', $this->_value); + return count($words) <= $number; + } + + /* Public Number Methods + -------------------------------*/ + /** + * Test for number greater than + * + * @param number + * @return bool + */ + public function greaterThan($number) { + Eden_Validation_Error::get()->argument('numeric'); + return $this->_value > (float)$number; + } + + /** + * Test for number less than + * + * @param number + * @return bool + */ + public function lessThan($number) { + Eden_Validation_Error::get()->argument('numeric'); + return $this->_value < (float)$number; + } + + /** + * Test for number greater than equal to + * + * @param number + * @return bool + */ + public function greaterThanEqualTo($number) { + Eden_Validation_Error::get()->argument('numeric'); + return $this->_value >= (float)$number; + } + + /** + * Test for number less than equal to + * + * @param number + * @return bool + */ + public function lessThanEqualTo($number) { + Eden_Validation_Error::get()->argument('numeric'); + return $this->_value <= (float)$number; + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} + +/** + * Javascript Errors + */ +class Eden_Validation_Error extends Eden_Error { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function get($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/webcharge.php b/library/eden/webcharge.php new file mode 100644 index 0000000..f5490bf --- /dev/null +++ b/library/eden/webcharge.php @@ -0,0 +1,264 @@ + +/* + * 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. + */ + +/** + * Intuit Innovative Gateway Solution WebCharge application + * model for payment processing. + * + * @package Eden + * @subpackage webcharge + * @category service + * @author Christian Blanquera + * @version $Id: model.php 1 2010-01-02 23:06:36Z blanquera $ + */ +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 + -------------------------------*/ + /* Get + -------------------------------*/ + public static function get($user, $password, array $options = array()) { + $class = __CLASS__; + return new $class($user, $password, $options); + } + + /* Magic + -------------------------------*/ + public function __construct($user = NULL, $password = NULL, array $options = array()) { + //test for no cURL + if(!function_exists('curl_init')) { + //throw exception + throw new Eden_Service_Exception(Eden_Service_Exception::NO_CURL); + } + + $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 + -------------------------------*/ + /** + * Sets the Merchant user name + * + * @param string user name + * @return this + */ + public function setUser($user) { + Eden_Webcharge_Error::get() + ->setMessage()->argument(1, 'string'); + $this->_transaction['username'] = $user; + return $this; + } + + /** + * Sets the merchant password + * + * @param string password + * @return this + */ + public function setPassword($password) { + Eden_Webcharge_Error::get() + ->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; + } + + /** + * 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::get() + ->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::get() + ->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::get() + ->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::get() + ->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::get() + ->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 + throw new Eden_Webcharge_Error(Eden_Webcharge_Error::INVALID_CREDIT_CARD_NAME); + } + + // Create the connection through the cURL extension + return Eden_Curl::get() + ->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(); + } + + /* 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..d905c5c --- /dev/null +++ b/library/eden/when.php @@ -0,0 +1,148 @@ + +/* + * 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__).'/class.php'; + +/** + * Trigger when something is false + * + * @package Eden + * @category core + * @author Christian Blanquera + * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ + */ +class Eden_When extends Eden_Class implements ArrayAccess, Iterator { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function get($scope) { + return self::_getSingleton(__CLASS__, $scope); + } + + /* Magic + -------------------------------*/ + public function __construct($scope) { + $this->_scope = $scope; + } + + public function __call($name, $args) { + return $this; + } + + /* Public Methods + -------------------------------*/ + /** + * Returns the original class + * + * @param bool + * @return this|Eden_Noop + */ + public function endWhen() { + return $this->_scope; + } + + /** + * Rewinds the position + * For Iterator interface + * + * @return void + */ + public function rewind() { + $this->_scope->rewind(); + } + + /** + * 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(); + } + + /** + * Validates whether if the index is set + * For Iterator interface + * + * @return void + */ + public function valid() { + return $this->_scope->valid(); + } + + /** + * Sets data using the ArrayAccess interface + * + * @param number + * @param mixed + * @return void + */ + public function offsetSet($offset, $value) {} + + /** + * isset using the ArrayAccess interface + * + * @param number + * @return bool + */ + public function offsetExists($offset) { + return $this->_scope->offsetExists($offset); + } + + /** + * unsets using the ArrayAccess interface + * + * @param number + * @return bool + */ + public function offsetUnset($offset) {} + + /** + * returns data using the ArrayAccess interface + * + * @param number + * @return bool + */ + public function offsetGet($offset) { + return $this->_scope->offsetGet($offset); + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/site/front.php b/site/front.php new file mode 100644 index 0000000..0ae5f02 --- /dev/null +++ b/site/front.php @@ -0,0 +1,607 @@ + +/* + * 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.php'; + +/** + * The starting point of every application call. If you are only + * using the framework you can rename this function to whatever you + * like. + * + * @author Christian Blanquera + * @version $Id: application.php 21 2010-01-06 01:19:17Z blanquera $ + */ +function front() { + return Front::get(); +} + +/** + * Defines the starting point of every site call. + * Starts laying out how classes and methods are handled. + * + * @package Eden + * @category site + * @author Christian Blanquera + * @version $Id: application.php 9 2010-01-12 15:42:40Z blanquera $ + */ +class Front extends Eden { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_database = NULL; + protected $_cache = NULL; + protected $_registry = NULL; + protected $_pages = array(); + + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function get() { + return self::_getSingleton(__CLASS__); + } + + /* Magic + -------------------------------*/ + public function __construct() { + parent::__construct(); + + //require registry + $this->_registry = Eden_Loader::get() + ->load('Eden_Registry') + ->Eden_Registry(); + } + + /* Public R/R Methods + -------------------------------*/ + /** + * Lets the framework handle exceptions. + * This is useful in the case that you + * use this framework on a server with + * no xdebug installed. + * + * @param string|null the error type to report + * @param bool|null true will turn debug on + * @return this + */ + public function setDebug($reporting = NULL, $default = NULL) { + Eden_Error::get()->argument(1, 'int', 'null')->argument(2, 'bool', 'null'); + + Eden_Loader::get() + ->load('Eden_Template') + ->Eden_Error_Event() + ->when(!is_null($reporting)) + ->setReporting($reporting) + ->endWhen() + ->when($default === true) + ->setErrorHandler() + ->setExceptionHandler() + ->listen('error', $this, 'outputError') + ->listen('exception', $this, 'outputError') + ->endWhen() + ->when($default === false) + ->releaseErrorHandler() + ->releaseExceptionHandler() + ->unlisten('error', $this, 'outputError') + ->unlisten('exception', $this, 'outputError') + ->endWhen(); + + return $this; + } + + /** + * Sets the application absolute paths + * for later referencing + * + * @return this + */ + public function setPaths(array $paths = array()) { + //this is the default paths + $root = dirname(__FILE__); + + $default = array( + 'root' => $root, + 'model' => $root.'/model', + 'web' => $root.'/web', + 'assets' => $root.'/web/assets', + 'cache' => $root.'/front/cache', + 'config' => $root.'/front/config', + 'template' => $root.'/front/template'); + + //foreach default path + foreach($default as $key => $path) { + $this->_registry->setData('path', $key, $path); + } + + //for each path + foreach($paths as $key => $path) { + //make them absolute + $path = (string) Eden_Path::get($path)->absolute(); + //set it + $this->_registry->setData('path', $key, $path); + } + + return $this; + } + + /** + * Sets page aliases + * + * @return this + */ + public function setPages($pages, $absolute = false) { + Front_Error::get() + ->argument(1, 'string', 'array') + ->argument(2, 'bool'); + + if(is_string($pages)) { + if(!$absolute) { + $pages = $this->_registry->getData('path', 'config').'/'.$pages; + } + + $pages = include($pages); + } + + $this->_pages = $pages; + return $this; + } + + /** + * Sets request + * + * @param EdenRegistry|null the request object + * @return this + */ + public function setRequest(Eden_Registry $request = NULL) { + //if no request + if(is_null($request)) { + //set the request + $request = $this->_registry; + } + + $path = '/'; + if(isset($_GET['request_path'])) { + $path = $_GET['request_path']; + unset($_GET['request_path']); + } + + //determine a request path + $path = str_replace('favicon.ico', '/', $path); + + //fix the request path + $path = (string) Eden_Path::get($path); + + //get the path array + $pathArray = explode('/', $path); + + + //determine the page suggestions + $suggestions = array(); + //for each of the page pattern to paths + foreach($this->_pages as $pagePattern => $pagePath) { + //we need to replace % with .* + //so for example /page/%/edit is the same as /page/.*/edit + $pattern = '%'.str_replace('%', '.*', $pagePattern).'%'; + //if the path matches the response path key + if(preg_match($pattern, $path)) { + //add the path and the length to the suggestions + //we do this because we need to sort the suggestions + //by relavancy + $suggestions[strlen($pagePattern)][] = array($pagePattern, $pagePath); + } + } + + //by default the page is the home page + $page = NULL; + //when given a path like /page/1/edit + //and a pattern like /page/%/edit + //we can determine one of the path variables is 1 + //make a place holder for path variables + //which we will find later + $variables = array(); + //to do that we need suggestions + //so if we have suggestions + if(!empty($suggestions)) { + //sort suggestions by length because the more detailed the + //page link the more probable this is the page they actually want + krsort($suggestions); + + //for the page to fetch we only care about the first suggestion and + //second index in array($pagePattern, $pagePath) + $suggestions = array_shift($suggestions); + $suggestions = array_shift($suggestions); + $page = $suggestions[1]; + + //lets determine the path variables + $variables = $this->_getPageVariables($path, $suggestions[0]); + } else { + $classBuffer = $pathArray; + while(count($classBuffer) > 1) { + $classParts = ucwords(implode(' ', $classBuffer)); + $page = 'Front_Page'.str_replace(' ', '_', $classParts); + if(class_exists($page)) { + break; + } + + $variable = array_pop($classBuffer); + array_unshift($variables, $variable); + } + + if(count($classBuffer) == 1) { + $page = NULL; + } + } + + $path = array( + 'string' => $path, + 'array' => $pathArray, + 'variables' => $variables); + + //set the request + $request->setData('server', $_SERVER) + ->setData('cookie', $_COOKIE) + ->setData('request', $_REQUEST) + ->setData('get', $_GET) + ->setData('post', $_POST) + ->setData('files', $_FILES) + ->setData('request', $path) + ->setData('page', $page); + + return $this; + } + + /** + * Sets response + * + * @param EdenRegistry|null the request object + * @return this + */ + public function setResponse($default, Eden_Registry $request = NULL) { + //if no request + if(is_null($request)) { + //set the request + $request = $this->_registry; + } + + $page = $request->getData('page'); + + if(!$page || !class_exists($page)) { + $page = $default; + } + + //set the response data + try { + $response = $this->$page($request); + } catch(Exception $e) { + $exception = new Front_Error($e->getMessage()); + exit; + } + + $request->setData('response', $response); + + return $this; + } + + /** + * returns the response + * + * @param EdenRegistry|null the request object + * @return string + */ + public function getResponse(Eden_Registry $request = NULL) { + //if no request + if(is_null($request)) { + //set the request + $request = $this->_registry; + } + + return $request->getData('response'); + } + + /* Public Database Methods + -------------------------------*/ + /** + * Sets up the default database connection + * + * @return this + */ + public function addDatabase($key, $type = NULL, + $host = NULL, $name = NULL, + $user = NULL, $pass = NULL, + $default = true) { + Front_Error::get() + ->argument(1, 'string', 'array', 'null') + ->argument(2, 'string', 'null') + ->argument(3, 'string', 'null') + ->argument(4, 'string', 'null') + ->argument(5, 'string', 'null') + ->argument(6, 'string', 'null') + ->argument(7, 'bool'); + + if(is_array($key)) { + $type = isset($key['type']) ? $key['type'] : NULL; + $host = isset($key['host']) ? $key['host'] : NULL; + $name = isset($key['name']) ? $key['name'] : NULL; + $user = isset($key['user']) ? $key['user'] : NULL; + $pass = isset($key['pass']) ? $key['pass'] : NULL; + $default = isset($key['default']) ? $key['default'] : true; + $key = isset($key['key']) ? $key['key'] : NULL; + } + + //connect to the data as described in the config + switch($type) { + case 'postgre': + $database = Eden_Pgsql::get($host, $name, $user, $pass); + break; + case 'mysql': + $database = Eden_Mysql::get($host, $name, $user, $pass); + break; + } + + $this->setData('database', $key, $database); + + if($default) { + $this->_database = $database; + } + + return $this; + } + + /** + * Returns the default database instance + * + * @return Eden_Database_Abstract + */ + public function getDatabase($key = NULL) { + if(is_null($key)) { + //return the default database + return $this->_database; + } + + return $this->_registry->getData('database', $key); + } + + /** + * Sets the default database + * + * @param string key + * @return this + */ + public function setDefaultDatabase($key) { + Front_Error::get()->argument(1, 'string'); + + $args = func_get_args(); + //if the args are greater than 5 + //they mean to add it + if(count($args) > 5) { + $this->addDatabase($args[0], $args[1], $args[2], $args[3], $args[4], $args[5]); + } + + //now set it + $this->_database = $this->_registry->getData('database', $key); + + return $this; + } + + /* Public Event Methods + -------------------------------*/ + /** + * Starts filters. Filters will handle when to run. + * + * @param string|array handlers + * @return Eden_Application + */ + public function startFilters($filters) { + Front_Error::get()->argument(1, 'string', 'array'); + + if(is_string($filters)) { + $filters = include($filters); + } + + //for each handler as class + foreach($filters as $class) { + //try to + try { + //instantiate the class + $this->$class($this); + //when there's an error do nothing + } catch(Exception $e){} + } + + return $this; + } + + /* Public Misc Methods + -------------------------------*/ + /** + * Sets the cache + * + * @return this + */ + public function setCache($root) { + // Start the Global Cache + Eden_Cache::get($root); + + return $this; + } + + /** + * Sets the PHP timezone + * + * @return this + */ + public function setTimezone($zone) { + //if zone is not string + if(!is_string($zone)) { + //throw exception + throw new Eden_Site_Exception(sprintf(Eden_Exception::NOT_STRING, 1)); + } + + date_default_timezone_set($zone); + + return $this; + } + + /** + * Returns the current Registry + * + * @return Eden_Registry + */ + public function getRegistry() { + return $this->_registry; + } + + /** + * Returns the template loaded with specified data + * + * @param array + * @return Eden_Template + */ + public function template($file, array $data = array()) { + Front_Error::get()->argument(1, 'string'); + return Eden_Template::get()->setData($data)->parsePhp($file); + } + + /** + * Error trigger output + * + * @return void + */ + public function outputError($event, $trace, $offset, $type, $level, $class, $file, $line, $message) { + //if there is a trace template and there's at least 2 leads + if(count($trace) > $offset) { + //for each trace + foreach($trace as $i => $call) { + //if we are at the first one + if($i < $offset) { + //ignore it because it will be the actual + //call to the error or exception + unset($trace[$i]); + continue; + } + + //either way make this array to a comma separated string + $argments = NULL; + if(isset($call['args'])) { + $argments = implode(', ', $this->_getArguments($call['args'])); + } + //lets formulate the method + $method = $call['function'].'('.$argments.')'; + if(isset($call['class'])) { + $method = $call['class'].'->'.$method; + } + + $tline = isset($call['line']) ? $call['line'] : 'N/A'; + $tfile = isset($call['file']) ? $call['file'] : 'Virtual Call'; + + //convert trace from array to string + $trace[$i] = array($method, $tfile, $tline); + } + } else { + $trace = array(); + } + + echo $this->Eden_Template() + ->setData('trace', $trace) + ->setData('type', $type) + ->setData('level', $level) + ->setData('class', $class) + ->setData('file', $file) + ->setData('line', $line) + ->setData('message', $message) + ->parsePhp(dirname(__FILE__).'/front/template/error.php'); + } + + /* Protected Methods + -------------------------------*/ + protected function _getPageVariables($requestPath, $pagePath) { + //if requestPath is not string + if(!is_string($requestPath)) { + //throw exception + throw new Eden_Site_Exception(sprintf(Eden_Exception::NOT_STRING, 1)); + } + + //if pagePath is not string + if(!is_string($pagePath)) { + //throw exception + throw new Eden_Site_Exception(sprintf(Eden_Exception::NOT_STRING, 2)); + } + + $variables = array(); + + //fix paths + $requestPath = $this->getFormattedPath($requestPath); + + //if the request path equals / + if($requestPath == '/') { + //there would be no page variables + return array(); + } + + $pagePath = $this->getFormattedPath($pagePath); + + //get the arrays + $requestPathArray = explode('/', $requestPath); + $pagePathArray = explode('/', $pagePath); + + //we do not need the first path because + // /page/1 is [null,page,1] in an array + array_shift($requestPathArray); + array_shift($pagePathArray); + + //for each request path + foreach($requestPathArray as $i => $value) { + //if the page path is not set, is null or is '%' + if(!isset($pagePathArray[$i]) + || trim($pagePathArray[$i]) == NULL + || $pagePathArray[$i] == '%') { + //then we can assume it's a variable + $variables[] = $requestPathArray[$i]; + } + } + + return $variables; + } + + protected function _getArguments($arguments) { + if(empty($arguments)) { + return array(); + } + + //for each argument + foreach($arguments as $i => $argument) { + //is it a string ? + if(is_string($argument)) { + $argument = "'".$argument."'"; + //is it an array ? + } else if(is_array($argument)) { + $argument = 'Array'; + //is it an object ? + } else if(is_object($argument)) { + $argument = get_class($argument); + //is it a bool ? + } else if(is_bool($argument)) { + $argument = $argument ? 'true' : 'false'; + //is it null ? + } else if(is_null($argument)) { + $argument = 'null'; + } + + $arguments[$i] = $argument; + } + + return $arguments; + } + + /* Private Methods + -------------------------------*/ +} diff --git a/site/front/config/classes.php b/site/front/config/classes.php new file mode 100755 index 0000000..0f17a54 --- /dev/null +++ b/site/front/config/classes.php @@ -0,0 +1,2 @@ + +return array(); \ No newline at end of file diff --git a/site/front/config/methods.php b/site/front/config/methods.php new file mode 100755 index 0000000..945b1fd --- /dev/null +++ b/site/front/config/methods.php @@ -0,0 +1,2 @@ + +return array('output' => 'Eden_Tool'); \ No newline at end of file diff --git a/site/front/config/pages.php b/site/front/config/pages.php new file mode 100755 index 0000000..0f17a54 --- /dev/null +++ b/site/front/config/pages.php @@ -0,0 +1,2 @@ + +return array(); \ No newline at end of file diff --git a/site/front/error.php b/site/front/error.php new file mode 100644 index 0000000..547d5e2 --- /dev/null +++ b/site/front/error.php @@ -0,0 +1,42 @@ + +/* + * 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. + */ + +/** + * Front application exception + * + * @author Christian Blanquera + * @version $Id: exception.php 9 2010-01-03 00:28:47Z blanquera $ + */ +class Front_Error extends Eden_Error { + /* Constants + -------------------------------*/ + const BLOCK_NOT_EXIST = 'Block %s does not exist.'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function get($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/site/front/handler.php b/site/front/handler.php new file mode 100644 index 0000000..a17e154 --- /dev/null +++ b/site/front/handler.php @@ -0,0 +1,46 @@ + +/* + * This file is part a custom application package. + * (c) 2009-2011 Christian Blanquera + */ + +/** + * Defines the starting point of every application call. + * Starts laying out how classes and methods are handled. + * + * @package Back + * @author Christian Blanquera + * @version $Id: application.php 21 2010-01-06 01:19:17Z blanquera $ + */ +class Front_Handler extends Eden_Class { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function get(Eden $app) { + return self::_getSingleton(__CLASS__, $app); + } + + /* Magic + -------------------------------*/ + public function __construct(Eden $app) { + $app->listen('request', $this, 'sessionStart'); + } + + /* Public Methods + -------------------------------*/ + public function sessionStart() { + return $this; + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/site/front/page.php b/site/front/page.php new file mode 100644 index 0000000..58b0cbc --- /dev/null +++ b/site/front/page.php @@ -0,0 +1,100 @@ + +/* + * 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. + */ + +/** + * The base class for any class that defines a view. + * A view controls how templates are loaded as well as + * being the final point where data manipulation can occur. + * + * @package Eden + * @author Christian Blanquera + * @version $Id: page.php 8 2010-01-09 07:04:02Z blanquera $ + */ +abstract class Front_Page extends Eden_Class { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_request = NULL; + protected $_messages = array(); + + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + /* Magic + -------------------------------*/ + public function __construct(Eden_Registry $request = NULL) { + $this->_request = $request; + } + + public function __toString() { + try { + $output = $this->render(); + } catch(Exception $e) { + Eden_Error_Event::get()->exceptionHandler($e); + + return ''; + } + + if(is_null($output)) { + return ''; + } + + return $output; + } + + /* Public Methods + -------------------------------*/ + /** + * Returns a string rendered version of the output + * + * @return string + */ + abstract public function render(); + + /* Protected Methods + -------------------------------*/ + protected function _setMessage($message, $type = NULL) { + $this->_messages[] = array('type' => $type, 'message' => $message); + + return $this; + } + + protected function _renderPage() { + $tpl = $this->_request->getData('path', 'template'); + + $messages = $this->_request->getData('message'); + + if(is_array($messages)) { + foreach($messages as $message) { + $this->_setMessage($message[0], $message[1]); + } + } + + $this->_body['messages'] = $this->_messages; + + $head = front()->template($tpl.'/_head.php'); + $body = front()->template($tpl.$this->_template, $this->_body); + $foot = front()->template($tpl.'/_foot.php'); + + return front()->template($tpl.'/_page.php', array( + 'meta' => $this->_meta, + 'title' => $this->_title, + 'class' => $this->_class, + 'head' => $head, + 'body' => $body, + 'foot' => $foot)); + } + + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/site/front/page/index.php b/site/front/page/index.php new file mode 100644 index 0000000..3faf888 --- /dev/null +++ b/site/front/page/index.php @@ -0,0 +1,47 @@ + +/* + * This file is part a custom application package. + * (c) 2009-2011 Christian Blanquera + */ + +/** + * Default logic to output a page + * + * @author Christian Blanquera + * @version $Id: index.php 14 2010-01-13 03:39:03Z blanquera $ + */ +class Front_Page_Index extends Front_Page { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_meta = array(); + protected $_body = array(); + protected $_title = 'Eden'; + protected $_class = 'home'; + protected $_template = '/index.php'; + protected $_session = false; + + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function get(Eden_Registry $request = NULL) { + return self::_getMultiple(__CLASS__, $request); + } + + /* Magic + -------------------------------*/ + /* Public Methods + -------------------------------*/ + public function render() { + return $this->_renderPage(); + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} diff --git a/site/front/template/_foot.php b/site/front/template/_foot.php new file mode 100644 index 0000000..eab7a9a --- /dev/null +++ b/site/front/template/_foot.php @@ -0,0 +1 @@ +FOOT \ No newline at end of file diff --git a/site/front/template/_head.php b/site/front/template/_head.php new file mode 100644 index 0000000..e5517e4 --- /dev/null +++ b/site/front/template/_head.php @@ -0,0 +1 @@ +HEAD \ No newline at end of file diff --git a/site/front/template/_message.php b/site/front/template/_message.php new file mode 100644 index 0000000..c24b7b1 --- /dev/null +++ b/site/front/template/_message.php @@ -0,0 +1,7 @@ + +
    + +
  • + +
+ \ No newline at end of file diff --git a/site/front/template/_page.php b/site/front/template/_page.php new file mode 100644 index 0000000..c81ff83 --- /dev/null +++ b/site/front/template/_page.php @@ -0,0 +1,25 @@ + + + + + <?php print $title; ?> + + + + $content): ?> + + + + + + + + +
+
+
+
+
+ + + diff --git a/site/front/template/error.php b/site/front/template/error.php new file mode 100644 index 0000000..ebac5a9 --- /dev/null +++ b/site/front/template/error.php @@ -0,0 +1,12 @@ +

+ from + in + on line + +

+

Eden Says:

+ + + + +
()
\ No newline at end of file diff --git a/site/front/template/index.php b/site/front/template/index.php new file mode 100644 index 0000000..edab3ac --- /dev/null +++ b/site/front/template/index.php @@ -0,0 +1 @@ +BODY \ No newline at end of file diff --git a/site/web/index.php b/site/web/index.php new file mode 100644 index 0000000..f29c9cd --- /dev/null +++ b/site/web/index.php @@ -0,0 +1,90 @@ + +/* + * 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 dirname(__FILE__).'/../front.php'; + +/* Get Application +-------------------------------*/ +print front() + +/* Set Debug +-------------------------------*/ +->setDebug(E_ALL, true) + +/* Set Autoload +-------------------------------*/ +->addRoot(dirname(__FILE__).'/..') +->addRoot(dirname(__FILE__).'/../model') + +/* Set Class Routing +-------------------------------*/ +->setClasses('front/config/classes.php') + +/* Set Method Routing +-------------------------------*/ +->setMethods('front/config/methods.php') + +/* Set Paths +-------------------------------*/ +->setPaths() + +/* Start Filters +-------------------------------*/ +->startFilters(array('Front_Handler')) + +/* Trigger Init Event +-------------------------------*/ +->trigger('init') + +/* Set Timezone +-------------------------------*/ +->setTimezone('America/Los_Angeles') + +/* Set Database +-------------------------------*/ +//->addDatabase(include('front/config/database.php')) + +/* Set Cache +-------------------------------*/ +//->setCache('front/cache') + +/* Set Page Routes +-------------------------------*/ +->setPages('pages.php') + +/* Trigger Init Event +-------------------------------*/ +->trigger('config') + +/* Start Session +-------------------------------*/ +->startSession() + +/* Trigger Session Event +-------------------------------*/ +->trigger('session') + +/* Set Request +-------------------------------*/ +->setRequest() + +/* Trigger Request Event +-------------------------------*/ +->trigger('request') + +/* Set Response +-------------------------------*/ +->setResponse('Front_Page_Index') + +/* Trigger Response Event +-------------------------------*/ +->trigger('response') + +/* Get the Response +-------------------------------*/ +->getResponse(); diff --git a/unit/tests/class.php b/unit/tests/class.php new file mode 100644 index 0000000..5a3d055 --- /dev/null +++ b/unit/tests/class.php @@ -0,0 +1,103 @@ + +class Class_1 extends Eden_Class{ + public $data = 123; + public static function get() { + return self::_getSingleton(__CLASS__); + } + + public function setData($value) { + $this->data = $value; + return $this; + } + + public function getData() { + return $this->data; + } + + public function sayHello() { + return 'hi'; + } +} + +class Class_2 extends Eden_Class{ + public static function get() { + return self::_getSingleton(__CLASS__); + } + + public function sayHello() { + return 'hello'; + } +} + +class Class_3 extends Class_1 { + public static function get() { + return self::_getMultiple(__CLASS__); + } +} + +$unit->setPackage('Eden_Class Tests'); + +//-------------------------// +// Test 1 +$test = Class_1::get() + ->setData(789) + ->Class_1() + ->getData(); + +$unit->assertEquals(789, $test, 'Singleton Test.'); + +//-------------------------// +// Test 2 +$test = Class_1::get() + ->Class_3() + ->setData(789) + ->Class_3() + ->getData(); + +$unit->assertEquals(123, $test, 'Multiple Test.'); + +//-------------------------// +// Test 3 +$test = Class_1::get() + ->routeThis('Class_4') + ->Class_4() + ->sayHello(); + +$unit->assertEquals('hi', $test, "routeThisClass('Class_3')"); + +//-------------------------// +// Test 4 +$test = Class_1::get() + ->routeMethod('sayHi', 'Class_2', 'sayHello') + ->sayHi(); + +$unit->assertEquals('hello', $test, "routeThisMethod('sayHi', 'Class_2', 'sayHello')"); + +//-------------------------// +// Test 5 +$test = Class_1::get() + ->Class_2() + ->sayHello(); + +$unit->assertEquals('hello', $test, 'Loading from one class to another.'); + +//-------------------------// +// Test 6 +$test = Class_1::get() + ->Class_3() + ->when(false) + ->setData(456) + ->endWhen() + ->getData(); + +$unit->assertEquals(123, $test, 'Conditional test to Noop and return to original class.'); + +//-------------------------// +// Test 7 +$test = Class_1::get() + ->when(true) + ->setData(456) + ->endWhen() + ->getData(); + +$unit->assertEquals(456, $test, 'Conditional test that passes and acts like normal.'); \ No newline at end of file diff --git a/unit/tests/cookie.php b/unit/tests/cookie.php new file mode 100644 index 0000000..bd9c718 --- /dev/null +++ b/unit/tests/cookie.php @@ -0,0 +1,34 @@ + +$loader->load('Eden_Cookie'); +$unit->setPackage('Eden_Cookie Tests'); + +$cookie = Eden_Cookie::get(); + +//-------------------------// +// Test 1 +$cookie->set('test', 456); +$unit->assertSame(456, $cookie->getData('test'), 'Basic setting and getting.'); + +$cookie['test2'] = 123; +$unit->assertSame(123, $cookie['test2'], 'Setting and getting using arrays.'); + +//-------------------------// +// Test 2 +$cookie->remove('test'); +$unit->assertNull($cookie->getData('test'), 'Removing a cookie.'); + +$cookie->clear(); +$unit->assertNull($cookie->getData('test2'), 'Removing all cookies.'); + +//-------------------------// +// Test 3 +$cookie->setSecure('test3', 789); +$unit->assertSame(789, $cookie->getData('test3'), 'Setting and getting secure.'); + +//-------------------------// +// Test 4 +$cookie->clear(); +$cookie->setData(array('test20' => 3, 'test22' => 2, 'test23' => 1)); +$unit->assertSame(2, $cookie->getData('test22'), 'Setting multiple cookies.'); + +$cookie->clear(); \ No newline at end of file diff --git a/unit/tests/file.php b/unit/tests/file.php new file mode 100644 index 0000000..a629099 --- /dev/null +++ b/unit/tests/file.php @@ -0,0 +1,30 @@ + +$loader->load('Eden_File'); +$unit->setPackage('Eden_File Tests'); + +//-------------------------// +// Test 1 +$file = Eden_File::get('home//openovate\public/eden.openovate.com/web/workspace.php'); +$unit->assertEquals('/projects/openovate/eden/v2/workspace.php', (string) $file, 'Format File Test.'); +$unit->assertEquals('workspace.php', $file->getName(), 'getName()'); +$unit->assertEquals('/projects/openovate/eden/v2', $file->getFolder(), 'getFolder()'); +$unit->assertEquals('workspace', $file->getBase(), 'getBase()'); +$unit->assertEquals('php', $file->getExtension(), 'getExtension()'); + +//-------------------------// +// Test 2 +$unit->assertEquals('application/octet-stream', $file->touch()->getMime(), 'touch() and getMime()'); +$unit->assertGreaterThanOrEquals(0, $file->getSize(), 'getSize()'); +$unit->assertGreaterThan(time()-100, $file->getTime(), 'getTime()'); +$unit->assertTrue($file->isFile(), 'isFile() [true]'); +$unit->assertEquals('test123', $file->setContent('test123')->getContent(), 'setContent() and getContent()'); +$unit->assertEquals('test123', $file->setData('test123')->getData(), 'setData() and getData()'); +$unit->assertCount(2, $file->setData(array(3,4))->getData(), 'setData() and getData()'); +$unit->assertGreaterThan(time()-100, $file->getTime(), 'getTime()'); +$unit->assertFalse($file->remove()->isFile(), ' remove() and isFile() [false]'); + +//-------------------------// +// Test 3 +$unit->assertEquals('openovate', $file[2], 'accessing file path with index'); +$file['replace'] = 'work2.php'; +$unit->assertEquals('/home/openovate/public/eden.openovate.com/web/work2.php', (string) $file, 'replacing with array'); \ No newline at end of file diff --git a/unit/tests/folder.php b/unit/tests/folder.php new file mode 100644 index 0000000..04f9736 --- /dev/null +++ b/unit/tests/folder.php @@ -0,0 +1,24 @@ + +$loader->load('Eden_Folder'); +$unit->setPackage('Eden_Folder Tests'); + +//-------------------------// +// Test 1 +$folder = Eden_Folder::get('home//openovate\public/eden.openovate.com/web'); +$folder[] = 'test'; +$unit->assertEquals('/home/openovate/public/eden.openovate.com/web/test', (string) $folder, 'Format Folder Test.'); +$unit->assertTrue($folder->create()->isFolder(), 'create() and isFolder()[true]'); +$unit->assertEquals('test', $folder->getName(), 'getName() - Folder name'); + +$folder->create()->append('dan')->create(); +$unit->assertEquals(array(), $folder->getFiles(), 'getFiles()[array]'); +$unit->assertTrue($folder->removeFiles()->isFile(), 'removeFiles()[true]'); + +$unit->assertFalse($folder->remove()->pop()->isFolder('dan'), 'remove() and isFolder()[false]'); + +$folder->create()->append('dan')->create()->pop()->truncate(); +$unit->assertCount(0, $folder->getFolders(), 'truncate()'); +$folder->remove(); + +$folder = Eden_Folder::get('home//openovate\public/eden.openovate.com/web/'); +$unit->assertCount(2, $folder->getFolders(), 'getFolders()'); \ No newline at end of file diff --git a/unit/tests/model.php b/unit/tests/model.php new file mode 100644 index 0000000..99d3405 --- /dev/null +++ b/unit/tests/model.php @@ -0,0 +1,68 @@ + +$loader->load('Eden_Model'); +$unit->setPackage('Eden_Model Tests'); + +$post = Eden_Model::get() + ->setMetaData('post_id') + ->setMetaData('post_title') + ->setMetaData('post_detail'); + +//-------------------------// +// Test 1 +$post['post_title'] = 'Title1'; +$unit->assertEquals('Title1', $post['post_title'], 'Setting values with array.'); + +$post->setPostTitle('Title2'); +$unit->assertEquals('Title2', $post['post_title'], 'Setting values with method.'); + +$post->post_title = 'Title3'; +$unit->assertEquals('Title3', $post['post_title'], 'Setting values with object.'); + +//-------------------------// +// Test 2 +$e1 = $e2 = $e3 = NULL; + +try { + $post['author'] = 'Chris'; +} catch(Exception $e1) {} + +$unit->assertInstanceOf('Eden_Model_Error', $e1, 'Setting invalid values with array.'); + +try { + $post->setAuthor('Chris'); +} catch(Exception $e2) {} + +$unit->assertInstanceOf('Eden_Model_Error', $e2, 'Setting invalid values with method.'); + +try { + $post->author = 'Chris'; +} catch(Exception $e3) {} + +$unit->assertInstanceOf('Eden_Model_Error', $e3, 'Setting invalid values with object.'); + +//-------------------------// +// Test 3 +$post['post_detail'] = 'Some Detail'; +$unit->assertEquals('Some Detail', $post['post_detail'], 'Getting values with array.'); +$unit->assertEquals('Some Detail', $post->getPostDetail(), 'Getting values with method.'); +$unit->assertEquals('Some Detail', $post->post_detail, 'Getting values with object.'); + +//-------------------------// +// Test 4 +$post['post_detail'] = 'Some Detail 2'; +unset($post['post_detail']); +$unit->assertNull($post['post_detail'], 'Disabled unset on array.'); + +$post->post_detail = 'Some Detail 3'; +unset($post->post_detail); +$unit->assertNull($post['post_detail'], 'Disabled unset on object.'); + +//-------------------------// +// Test 5 +$post->setMetaData('post_author', array('validation' => array('char', 255))); +$test = $post->getMetaData('post_author', 'validation'); +$unit->assertEquals(255, $test[1], "setMetaData('post_author', array('validation' => array('char', 255)))"); + +$post->setMetaData('post_author', 'format', 'BY: %s'); +$test = $post->getMetaData('post_author', 'format'); +$unit->assertEquals('BY: %s', $test, "setMetaData('post_author', 'format', 'BY: %s')"); \ No newline at end of file diff --git a/unit/tests/session.php b/unit/tests/session.php new file mode 100644 index 0000000..d1c72c3 --- /dev/null +++ b/unit/tests/session.php @@ -0,0 +1,38 @@ + +$loader->load('Eden_Session'); +$unit->setPackage('Eden_Session Tests'); + +$session = Eden_Session::get(); + +//-------------------------// +// Test 1 +try { + $session->setData('test', 456); +} catch(Exception $e1) {} + +$unit->assertInstanceOf('Eden_Session_Error', $e1, 'Error while doing something before session was started.'); + + +//-------------------------// +// Test 1 +$session->stop()->start()->setData('test', 456); +$unit->assertSame(456, $session->getData('test'), 'Basic setting and getting.'); + +$session['test2'] = 123; +$unit->assertSame(123, $session['test2'], 'Setting and getting using arrays.'); + +//-------------------------// +// Test 2 +$session->remove('test'); +$unit->assertNull($session->getData('test'), 'Removing a session.'); + +$session->clear(); +$unit->assertNull($session->getData('test2'), 'Removing all sessions.'); + +//-------------------------// +// Test 3 +$session->clear(); +$session->setData(array('test20' => 3, 'test22' => 2, 'test23' => 1)); +$unit->assertSame(2, $session->getData('test22'), 'Setting multiple sessions.'); + +$session->stop(); \ No newline at end of file diff --git a/unit/tests/string.php b/unit/tests/string.php new file mode 100644 index 0000000..1d98006 --- /dev/null +++ b/unit/tests/string.php @@ -0,0 +1,96 @@ + + +$loader->load('Eden_String'); +$unit->setPackage('Eden_String Tests'); + +//-------------------------// +// Test 1 +$string = Eden_String::get("Unit Test Eden V2"); + +$unit->assertEquals('Unit Test Eden V2', (string) $string, 'String Format Test'); +$unit->assertEquals('unitTestEdenV2', (string) $string->camelize(), 'camelize String'); +$unit->assertEquals('unit-test-eden-v2', (string) $string->uncamelize(), 'uncamelize string'); +$unit->assertEquals('unit-test-eden-v2', (string) $string->dasherize(), 'dasherize string'); +$unit->assertEquals('Unit Test Eden V2', (string) $string->titlize(), 'titlize string'); + +//pre methods +//Test 1 +//--------------------> +$string = Eden_String::get("Unit Test for Dan's Window"); + +$unit->assertEquals("unit test for dan's window", (string) $string->addslashes()->stripslashes()->strtolower(), "addslashes then stripslashes and strtolower"); +$unit->assertEquals(94, $string->bin2hex()->strlen(), 'bin2hex the string then strlen'); + + +//Test 2 +//---------------------> +$string = Eden_String::get("Unit Test"); +$unit->assertSame("Un\r\nit\r\n T\r\nes\r\nt\r\n", (string) $string->chunk_split(2), 'chunk_split'); //not working + +$string = Eden_String::get("Unit Test"); +$unit->assertEquals('Unit Test', (string) $string->convert_uuencode()->convert_uudecode(), 'convert_uuencode and back to convert_uudecode'); +//echo $string->crypt(CRYPT_MD5); + + +//Test 3 +//---------------------> +$string = Eden_String::get("I'll make a 'history!'"); +//echo $string->htmlentities()->html_entity_decode(); +$unit->assertSame("I'll make a 'history!'", (string) $string->htmlentities()->html_entity_decode(), 'htmlentities() then html_entity_decode'); //now working +//echo $string; +$unit->assertEquals("I'll make a 'history!'", (string) $string->htmlspecialchars()->htmlspecialchars_decode(), 'htmlspecialchars() to htmlspecialchars_decode()'); +$unit->assertEquals("6c24d06f9e32721ed8a6ee445bbf6bb1", (string) $string->ltrim()->md5(), "ltrim string the convert into md5"); + + +//Test 4 +//---------------------> +$string = Eden_String::get("Have a good Day!"); + +$unit->assertEquals("Have-a-good-Day!", (string) $string->str_replace(' ', "-"), "replace space to (-)"); +//echo $string->quotemeta(); + + +//Test 5 +//---------------------> +$string = Eden_String::get("\t\tThese are a few words"); +$unit->assertEquals("\t\tThese are a few words", (string) $string->rtrim(), "rtrim test"); +$unit->assertEquals("78d3808d95626fdd53151c50094f02a3859dd0dd", (string) $string->sha1(), "sha1 test"); + +$string = Eden_String::get("%d word for sprintf %s"); +$d = 2; +$s = "data"; +$unit->assertEquals("2 word for sprintf data", (string) $string->sprintf($d, $s), "sprintf test"); +$unit->assertEquals("2 word for sprintf data_-", (string) $string->str_pad(25, '_-'), "str_pad for string"); +$unit->assertEquals("2 word for sprintf data_-2 word for sprintf data_-", (string) $string->str_repeat(2), "str_pad for string"); + +$string = Eden_String::get("php string"); +$unit->assertEquals("cuc fgevat", (string) $string->str_rot13(), "str_rot13 encode"); +//echo $string->str_shuffle(); + +$string = Eden_String::get("php string"); +$unit->assertEquals("php ()string", (string) $string->strip_tags('')->str_replace("", "()"), "strip_tags allowsb tag"); + +$string = Eden_String::get("d\u\z"); +$unit->assertEquals("duz", (string) $string->stripcslashes()->stripslashes(), "stripcslashes() and stripslashes()"); +$unit->assertEquals("uz", (string) $string->strpbrk("u"), "strpbrk()"); + +$string = Eden_String::get("Returns the matched"); +$unit->assertEquals("turns the matched", (string) $string->stristr('t'), "stristr()"); +$unit->assertEquals("CTAM E", (string) $string->strrev()->strstr('h')->strtok('h')->strtoupper(), "strrev(), strstr(), strtok() and strtoupper()"); +$unit->assertEquals("AM d", (string) $string->strtr('E', 'd')->substr_replace('TAM', 0, 4)->substr(1, 4), "strtr() and substr_replace() then substr()"); + +$string = Eden_String::get("programming techniques "); +$unit->assertEquals("Programming Techniques", (string) $string->trim()->ucfirst()->ucwords(), "trim() and ucfirst() then ucwords()"); +$unit->assertEquals("Programming-Techniques", (string) $string->wordwrap(3, '
')->str_replace("
", "-"), "wordwrap() then str_replace()"); + +$unit->assertEquals("-PTaceghimnoqrsu", (string) $string->count_chars(3), "count_chars()"); +//echo $string->hex2bin(); => undifined= + +$string = Eden_String::get("programming %s techniques"); +$unit->assertEquals('12', (string) $string->vsprintf(array('29'))->strpos('2'), "vsprintf() and strpos()"); + +$string = Eden_String::get("dan"); +$unit->assertEquals('1', (string) $string->substr_compare('a', 0, 2), "substr_compare"); + +$string = Eden_String::get("this is it"); +$unit->assertEquals('3', (string) $string->substr_count('i'), "substr_count()"); \ No newline at end of file diff --git a/unit/unit.php b/unit/unit.php new file mode 100644 index 0000000..e82eba3 --- /dev/null +++ b/unit/unit.php @@ -0,0 +1,45 @@ + +include '../eden.php'; +include '../eden/loader.php'; + +$loader = Eden_Loader::get()->load('Eden_Unit'); +$unit = $loader->Eden_Unit(); + +include 'unit/class.php'; +include 'unit/cookie.php'; +include 'unit/session.php'; +//include 'unit/file.php'; +include 'unit/folder.php'; +include 'unit/string.php'; +include 'unit/model.php'; + +?> +

+ +getReport() as $package => $tests): ?> + getPassFail($package); ?> + + + + $results): ?> + + + + + + + + + + + + + +
+

getTotalTests($package) * 100); ?>%

+ + PASS: , + FAIL: , + TOTAL TESTS: getTotalTests($package); ?> + +
msPASSFAIL
\ No newline at end of file From a944b8a637421cd1b847839621aa2529035f63dc Mon Sep 17 00:00:00 2001 From: cblanquera Date: Tue, 15 Nov 2011 12:45:21 +0000 Subject: [PATCH 002/330] unit tests git-svn-id: http://svn.openovate.com/edenv2/trunk@2 38ede93f-50f4-44af-b0b3-68ccca78c181 --- unit/tests/class.php | 103 ----------------------------------------- unit/tests/cookie.php | 34 -------------- unit/tests/file.php | 30 ------------ unit/tests/folder.php | 24 ---------- unit/tests/model.php | 68 --------------------------- unit/tests/session.php | 38 --------------- unit/tests/string.php | 96 -------------------------------------- 7 files changed, 393 deletions(-) delete mode 100644 unit/tests/class.php delete mode 100644 unit/tests/cookie.php delete mode 100644 unit/tests/file.php delete mode 100644 unit/tests/folder.php delete mode 100644 unit/tests/model.php delete mode 100644 unit/tests/session.php delete mode 100644 unit/tests/string.php diff --git a/unit/tests/class.php b/unit/tests/class.php deleted file mode 100644 index 5a3d055..0000000 --- a/unit/tests/class.php +++ /dev/null @@ -1,103 +0,0 @@ - -class Class_1 extends Eden_Class{ - public $data = 123; - public static function get() { - return self::_getSingleton(__CLASS__); - } - - public function setData($value) { - $this->data = $value; - return $this; - } - - public function getData() { - return $this->data; - } - - public function sayHello() { - return 'hi'; - } -} - -class Class_2 extends Eden_Class{ - public static function get() { - return self::_getSingleton(__CLASS__); - } - - public function sayHello() { - return 'hello'; - } -} - -class Class_3 extends Class_1 { - public static function get() { - return self::_getMultiple(__CLASS__); - } -} - -$unit->setPackage('Eden_Class Tests'); - -//-------------------------// -// Test 1 -$test = Class_1::get() - ->setData(789) - ->Class_1() - ->getData(); - -$unit->assertEquals(789, $test, 'Singleton Test.'); - -//-------------------------// -// Test 2 -$test = Class_1::get() - ->Class_3() - ->setData(789) - ->Class_3() - ->getData(); - -$unit->assertEquals(123, $test, 'Multiple Test.'); - -//-------------------------// -// Test 3 -$test = Class_1::get() - ->routeThis('Class_4') - ->Class_4() - ->sayHello(); - -$unit->assertEquals('hi', $test, "routeThisClass('Class_3')"); - -//-------------------------// -// Test 4 -$test = Class_1::get() - ->routeMethod('sayHi', 'Class_2', 'sayHello') - ->sayHi(); - -$unit->assertEquals('hello', $test, "routeThisMethod('sayHi', 'Class_2', 'sayHello')"); - -//-------------------------// -// Test 5 -$test = Class_1::get() - ->Class_2() - ->sayHello(); - -$unit->assertEquals('hello', $test, 'Loading from one class to another.'); - -//-------------------------// -// Test 6 -$test = Class_1::get() - ->Class_3() - ->when(false) - ->setData(456) - ->endWhen() - ->getData(); - -$unit->assertEquals(123, $test, 'Conditional test to Noop and return to original class.'); - -//-------------------------// -// Test 7 -$test = Class_1::get() - ->when(true) - ->setData(456) - ->endWhen() - ->getData(); - -$unit->assertEquals(456, $test, 'Conditional test that passes and acts like normal.'); \ No newline at end of file diff --git a/unit/tests/cookie.php b/unit/tests/cookie.php deleted file mode 100644 index bd9c718..0000000 --- a/unit/tests/cookie.php +++ /dev/null @@ -1,34 +0,0 @@ - -$loader->load('Eden_Cookie'); -$unit->setPackage('Eden_Cookie Tests'); - -$cookie = Eden_Cookie::get(); - -//-------------------------// -// Test 1 -$cookie->set('test', 456); -$unit->assertSame(456, $cookie->getData('test'), 'Basic setting and getting.'); - -$cookie['test2'] = 123; -$unit->assertSame(123, $cookie['test2'], 'Setting and getting using arrays.'); - -//-------------------------// -// Test 2 -$cookie->remove('test'); -$unit->assertNull($cookie->getData('test'), 'Removing a cookie.'); - -$cookie->clear(); -$unit->assertNull($cookie->getData('test2'), 'Removing all cookies.'); - -//-------------------------// -// Test 3 -$cookie->setSecure('test3', 789); -$unit->assertSame(789, $cookie->getData('test3'), 'Setting and getting secure.'); - -//-------------------------// -// Test 4 -$cookie->clear(); -$cookie->setData(array('test20' => 3, 'test22' => 2, 'test23' => 1)); -$unit->assertSame(2, $cookie->getData('test22'), 'Setting multiple cookies.'); - -$cookie->clear(); \ No newline at end of file diff --git a/unit/tests/file.php b/unit/tests/file.php deleted file mode 100644 index a629099..0000000 --- a/unit/tests/file.php +++ /dev/null @@ -1,30 +0,0 @@ - -$loader->load('Eden_File'); -$unit->setPackage('Eden_File Tests'); - -//-------------------------// -// Test 1 -$file = Eden_File::get('home//openovate\public/eden.openovate.com/web/workspace.php'); -$unit->assertEquals('/projects/openovate/eden/v2/workspace.php', (string) $file, 'Format File Test.'); -$unit->assertEquals('workspace.php', $file->getName(), 'getName()'); -$unit->assertEquals('/projects/openovate/eden/v2', $file->getFolder(), 'getFolder()'); -$unit->assertEquals('workspace', $file->getBase(), 'getBase()'); -$unit->assertEquals('php', $file->getExtension(), 'getExtension()'); - -//-------------------------// -// Test 2 -$unit->assertEquals('application/octet-stream', $file->touch()->getMime(), 'touch() and getMime()'); -$unit->assertGreaterThanOrEquals(0, $file->getSize(), 'getSize()'); -$unit->assertGreaterThan(time()-100, $file->getTime(), 'getTime()'); -$unit->assertTrue($file->isFile(), 'isFile() [true]'); -$unit->assertEquals('test123', $file->setContent('test123')->getContent(), 'setContent() and getContent()'); -$unit->assertEquals('test123', $file->setData('test123')->getData(), 'setData() and getData()'); -$unit->assertCount(2, $file->setData(array(3,4))->getData(), 'setData() and getData()'); -$unit->assertGreaterThan(time()-100, $file->getTime(), 'getTime()'); -$unit->assertFalse($file->remove()->isFile(), ' remove() and isFile() [false]'); - -//-------------------------// -// Test 3 -$unit->assertEquals('openovate', $file[2], 'accessing file path with index'); -$file['replace'] = 'work2.php'; -$unit->assertEquals('/home/openovate/public/eden.openovate.com/web/work2.php', (string) $file, 'replacing with array'); \ No newline at end of file diff --git a/unit/tests/folder.php b/unit/tests/folder.php deleted file mode 100644 index 04f9736..0000000 --- a/unit/tests/folder.php +++ /dev/null @@ -1,24 +0,0 @@ - -$loader->load('Eden_Folder'); -$unit->setPackage('Eden_Folder Tests'); - -//-------------------------// -// Test 1 -$folder = Eden_Folder::get('home//openovate\public/eden.openovate.com/web'); -$folder[] = 'test'; -$unit->assertEquals('/home/openovate/public/eden.openovate.com/web/test', (string) $folder, 'Format Folder Test.'); -$unit->assertTrue($folder->create()->isFolder(), 'create() and isFolder()[true]'); -$unit->assertEquals('test', $folder->getName(), 'getName() - Folder name'); - -$folder->create()->append('dan')->create(); -$unit->assertEquals(array(), $folder->getFiles(), 'getFiles()[array]'); -$unit->assertTrue($folder->removeFiles()->isFile(), 'removeFiles()[true]'); - -$unit->assertFalse($folder->remove()->pop()->isFolder('dan'), 'remove() and isFolder()[false]'); - -$folder->create()->append('dan')->create()->pop()->truncate(); -$unit->assertCount(0, $folder->getFolders(), 'truncate()'); -$folder->remove(); - -$folder = Eden_Folder::get('home//openovate\public/eden.openovate.com/web/'); -$unit->assertCount(2, $folder->getFolders(), 'getFolders()'); \ No newline at end of file diff --git a/unit/tests/model.php b/unit/tests/model.php deleted file mode 100644 index 99d3405..0000000 --- a/unit/tests/model.php +++ /dev/null @@ -1,68 +0,0 @@ - -$loader->load('Eden_Model'); -$unit->setPackage('Eden_Model Tests'); - -$post = Eden_Model::get() - ->setMetaData('post_id') - ->setMetaData('post_title') - ->setMetaData('post_detail'); - -//-------------------------// -// Test 1 -$post['post_title'] = 'Title1'; -$unit->assertEquals('Title1', $post['post_title'], 'Setting values with array.'); - -$post->setPostTitle('Title2'); -$unit->assertEquals('Title2', $post['post_title'], 'Setting values with method.'); - -$post->post_title = 'Title3'; -$unit->assertEquals('Title3', $post['post_title'], 'Setting values with object.'); - -//-------------------------// -// Test 2 -$e1 = $e2 = $e3 = NULL; - -try { - $post['author'] = 'Chris'; -} catch(Exception $e1) {} - -$unit->assertInstanceOf('Eden_Model_Error', $e1, 'Setting invalid values with array.'); - -try { - $post->setAuthor('Chris'); -} catch(Exception $e2) {} - -$unit->assertInstanceOf('Eden_Model_Error', $e2, 'Setting invalid values with method.'); - -try { - $post->author = 'Chris'; -} catch(Exception $e3) {} - -$unit->assertInstanceOf('Eden_Model_Error', $e3, 'Setting invalid values with object.'); - -//-------------------------// -// Test 3 -$post['post_detail'] = 'Some Detail'; -$unit->assertEquals('Some Detail', $post['post_detail'], 'Getting values with array.'); -$unit->assertEquals('Some Detail', $post->getPostDetail(), 'Getting values with method.'); -$unit->assertEquals('Some Detail', $post->post_detail, 'Getting values with object.'); - -//-------------------------// -// Test 4 -$post['post_detail'] = 'Some Detail 2'; -unset($post['post_detail']); -$unit->assertNull($post['post_detail'], 'Disabled unset on array.'); - -$post->post_detail = 'Some Detail 3'; -unset($post->post_detail); -$unit->assertNull($post['post_detail'], 'Disabled unset on object.'); - -//-------------------------// -// Test 5 -$post->setMetaData('post_author', array('validation' => array('char', 255))); -$test = $post->getMetaData('post_author', 'validation'); -$unit->assertEquals(255, $test[1], "setMetaData('post_author', array('validation' => array('char', 255)))"); - -$post->setMetaData('post_author', 'format', 'BY: %s'); -$test = $post->getMetaData('post_author', 'format'); -$unit->assertEquals('BY: %s', $test, "setMetaData('post_author', 'format', 'BY: %s')"); \ No newline at end of file diff --git a/unit/tests/session.php b/unit/tests/session.php deleted file mode 100644 index d1c72c3..0000000 --- a/unit/tests/session.php +++ /dev/null @@ -1,38 +0,0 @@ - -$loader->load('Eden_Session'); -$unit->setPackage('Eden_Session Tests'); - -$session = Eden_Session::get(); - -//-------------------------// -// Test 1 -try { - $session->setData('test', 456); -} catch(Exception $e1) {} - -$unit->assertInstanceOf('Eden_Session_Error', $e1, 'Error while doing something before session was started.'); - - -//-------------------------// -// Test 1 -$session->stop()->start()->setData('test', 456); -$unit->assertSame(456, $session->getData('test'), 'Basic setting and getting.'); - -$session['test2'] = 123; -$unit->assertSame(123, $session['test2'], 'Setting and getting using arrays.'); - -//-------------------------// -// Test 2 -$session->remove('test'); -$unit->assertNull($session->getData('test'), 'Removing a session.'); - -$session->clear(); -$unit->assertNull($session->getData('test2'), 'Removing all sessions.'); - -//-------------------------// -// Test 3 -$session->clear(); -$session->setData(array('test20' => 3, 'test22' => 2, 'test23' => 1)); -$unit->assertSame(2, $session->getData('test22'), 'Setting multiple sessions.'); - -$session->stop(); \ No newline at end of file diff --git a/unit/tests/string.php b/unit/tests/string.php deleted file mode 100644 index 1d98006..0000000 --- a/unit/tests/string.php +++ /dev/null @@ -1,96 +0,0 @@ - - -$loader->load('Eden_String'); -$unit->setPackage('Eden_String Tests'); - -//-------------------------// -// Test 1 -$string = Eden_String::get("Unit Test Eden V2"); - -$unit->assertEquals('Unit Test Eden V2', (string) $string, 'String Format Test'); -$unit->assertEquals('unitTestEdenV2', (string) $string->camelize(), 'camelize String'); -$unit->assertEquals('unit-test-eden-v2', (string) $string->uncamelize(), 'uncamelize string'); -$unit->assertEquals('unit-test-eden-v2', (string) $string->dasherize(), 'dasherize string'); -$unit->assertEquals('Unit Test Eden V2', (string) $string->titlize(), 'titlize string'); - -//pre methods -//Test 1 -//--------------------> -$string = Eden_String::get("Unit Test for Dan's Window"); - -$unit->assertEquals("unit test for dan's window", (string) $string->addslashes()->stripslashes()->strtolower(), "addslashes then stripslashes and strtolower"); -$unit->assertEquals(94, $string->bin2hex()->strlen(), 'bin2hex the string then strlen'); - - -//Test 2 -//---------------------> -$string = Eden_String::get("Unit Test"); -$unit->assertSame("Un\r\nit\r\n T\r\nes\r\nt\r\n", (string) $string->chunk_split(2), 'chunk_split'); //not working - -$string = Eden_String::get("Unit Test"); -$unit->assertEquals('Unit Test', (string) $string->convert_uuencode()->convert_uudecode(), 'convert_uuencode and back to convert_uudecode'); -//echo $string->crypt(CRYPT_MD5); - - -//Test 3 -//---------------------> -$string = Eden_String::get("I'll make a 'history!'"); -//echo $string->htmlentities()->html_entity_decode(); -$unit->assertSame("I'll make a 'history!'", (string) $string->htmlentities()->html_entity_decode(), 'htmlentities() then html_entity_decode'); //now working -//echo $string; -$unit->assertEquals("I'll make a 'history!'", (string) $string->htmlspecialchars()->htmlspecialchars_decode(), 'htmlspecialchars() to htmlspecialchars_decode()'); -$unit->assertEquals("6c24d06f9e32721ed8a6ee445bbf6bb1", (string) $string->ltrim()->md5(), "ltrim string the convert into md5"); - - -//Test 4 -//---------------------> -$string = Eden_String::get("Have a good Day!"); - -$unit->assertEquals("Have-a-good-Day!", (string) $string->str_replace(' ', "-"), "replace space to (-)"); -//echo $string->quotemeta(); - - -//Test 5 -//---------------------> -$string = Eden_String::get("\t\tThese are a few words"); -$unit->assertEquals("\t\tThese are a few words", (string) $string->rtrim(), "rtrim test"); -$unit->assertEquals("78d3808d95626fdd53151c50094f02a3859dd0dd", (string) $string->sha1(), "sha1 test"); - -$string = Eden_String::get("%d word for sprintf %s"); -$d = 2; -$s = "data"; -$unit->assertEquals("2 word for sprintf data", (string) $string->sprintf($d, $s), "sprintf test"); -$unit->assertEquals("2 word for sprintf data_-", (string) $string->str_pad(25, '_-'), "str_pad for string"); -$unit->assertEquals("2 word for sprintf data_-2 word for sprintf data_-", (string) $string->str_repeat(2), "str_pad for string"); - -$string = Eden_String::get("php string"); -$unit->assertEquals("cuc fgevat", (string) $string->str_rot13(), "str_rot13 encode"); -//echo $string->str_shuffle(); - -$string = Eden_String::get("php string"); -$unit->assertEquals("php ()string", (string) $string->strip_tags('')->str_replace("", "()"), "strip_tags allowsb tag"); - -$string = Eden_String::get("d\u\z"); -$unit->assertEquals("duz", (string) $string->stripcslashes()->stripslashes(), "stripcslashes() and stripslashes()"); -$unit->assertEquals("uz", (string) $string->strpbrk("u"), "strpbrk()"); - -$string = Eden_String::get("Returns the matched"); -$unit->assertEquals("turns the matched", (string) $string->stristr('t'), "stristr()"); -$unit->assertEquals("CTAM E", (string) $string->strrev()->strstr('h')->strtok('h')->strtoupper(), "strrev(), strstr(), strtok() and strtoupper()"); -$unit->assertEquals("AM d", (string) $string->strtr('E', 'd')->substr_replace('TAM', 0, 4)->substr(1, 4), "strtr() and substr_replace() then substr()"); - -$string = Eden_String::get("programming techniques "); -$unit->assertEquals("Programming Techniques", (string) $string->trim()->ucfirst()->ucwords(), "trim() and ucfirst() then ucwords()"); -$unit->assertEquals("Programming-Techniques", (string) $string->wordwrap(3, '
')->str_replace("
", "-"), "wordwrap() then str_replace()"); - -$unit->assertEquals("-PTaceghimnoqrsu", (string) $string->count_chars(3), "count_chars()"); -//echo $string->hex2bin(); => undifined= - -$string = Eden_String::get("programming %s techniques"); -$unit->assertEquals('12', (string) $string->vsprintf(array('29'))->strpos('2'), "vsprintf() and strpos()"); - -$string = Eden_String::get("dan"); -$unit->assertEquals('1', (string) $string->substr_compare('a', 0, 2), "substr_compare"); - -$string = Eden_String::get("this is it"); -$unit->assertEquals('3', (string) $string->substr_count('i'), "substr_count()"); \ No newline at end of file From 9f369299ef2025bb324b1c031171d0b027fddb7e Mon Sep 17 00:00:00 2001 From: cblanquera Date: Tue, 15 Nov 2011 12:49:17 +0000 Subject: [PATCH 003/330] unit tests git-svn-id: http://svn.openovate.com/edenv2/trunk@3 38ede93f-50f4-44af-b0b3-68ccca78c181 --- unit/tests/class.php | 103 +++++++++++++++++++++++++++++++++++++++++ unit/tests/cookie.php | 34 ++++++++++++++ unit/tests/file.php | 30 ++++++++++++ unit/tests/folder.php | 24 ++++++++++ unit/tests/model.php | 68 +++++++++++++++++++++++++++ unit/tests/session.php | 38 +++++++++++++++ unit/tests/string.php | 96 ++++++++++++++++++++++++++++++++++++++ 7 files changed, 393 insertions(+) create mode 100644 unit/tests/class.php create mode 100644 unit/tests/cookie.php create mode 100644 unit/tests/file.php create mode 100644 unit/tests/folder.php create mode 100644 unit/tests/model.php create mode 100644 unit/tests/session.php create mode 100644 unit/tests/string.php diff --git a/unit/tests/class.php b/unit/tests/class.php new file mode 100644 index 0000000..5a3d055 --- /dev/null +++ b/unit/tests/class.php @@ -0,0 +1,103 @@ + +class Class_1 extends Eden_Class{ + public $data = 123; + public static function get() { + return self::_getSingleton(__CLASS__); + } + + public function setData($value) { + $this->data = $value; + return $this; + } + + public function getData() { + return $this->data; + } + + public function sayHello() { + return 'hi'; + } +} + +class Class_2 extends Eden_Class{ + public static function get() { + return self::_getSingleton(__CLASS__); + } + + public function sayHello() { + return 'hello'; + } +} + +class Class_3 extends Class_1 { + public static function get() { + return self::_getMultiple(__CLASS__); + } +} + +$unit->setPackage('Eden_Class Tests'); + +//-------------------------// +// Test 1 +$test = Class_1::get() + ->setData(789) + ->Class_1() + ->getData(); + +$unit->assertEquals(789, $test, 'Singleton Test.'); + +//-------------------------// +// Test 2 +$test = Class_1::get() + ->Class_3() + ->setData(789) + ->Class_3() + ->getData(); + +$unit->assertEquals(123, $test, 'Multiple Test.'); + +//-------------------------// +// Test 3 +$test = Class_1::get() + ->routeThis('Class_4') + ->Class_4() + ->sayHello(); + +$unit->assertEquals('hi', $test, "routeThisClass('Class_3')"); + +//-------------------------// +// Test 4 +$test = Class_1::get() + ->routeMethod('sayHi', 'Class_2', 'sayHello') + ->sayHi(); + +$unit->assertEquals('hello', $test, "routeThisMethod('sayHi', 'Class_2', 'sayHello')"); + +//-------------------------// +// Test 5 +$test = Class_1::get() + ->Class_2() + ->sayHello(); + +$unit->assertEquals('hello', $test, 'Loading from one class to another.'); + +//-------------------------// +// Test 6 +$test = Class_1::get() + ->Class_3() + ->when(false) + ->setData(456) + ->endWhen() + ->getData(); + +$unit->assertEquals(123, $test, 'Conditional test to Noop and return to original class.'); + +//-------------------------// +// Test 7 +$test = Class_1::get() + ->when(true) + ->setData(456) + ->endWhen() + ->getData(); + +$unit->assertEquals(456, $test, 'Conditional test that passes and acts like normal.'); \ No newline at end of file diff --git a/unit/tests/cookie.php b/unit/tests/cookie.php new file mode 100644 index 0000000..bd9c718 --- /dev/null +++ b/unit/tests/cookie.php @@ -0,0 +1,34 @@ + +$loader->load('Eden_Cookie'); +$unit->setPackage('Eden_Cookie Tests'); + +$cookie = Eden_Cookie::get(); + +//-------------------------// +// Test 1 +$cookie->set('test', 456); +$unit->assertSame(456, $cookie->getData('test'), 'Basic setting and getting.'); + +$cookie['test2'] = 123; +$unit->assertSame(123, $cookie['test2'], 'Setting and getting using arrays.'); + +//-------------------------// +// Test 2 +$cookie->remove('test'); +$unit->assertNull($cookie->getData('test'), 'Removing a cookie.'); + +$cookie->clear(); +$unit->assertNull($cookie->getData('test2'), 'Removing all cookies.'); + +//-------------------------// +// Test 3 +$cookie->setSecure('test3', 789); +$unit->assertSame(789, $cookie->getData('test3'), 'Setting and getting secure.'); + +//-------------------------// +// Test 4 +$cookie->clear(); +$cookie->setData(array('test20' => 3, 'test22' => 2, 'test23' => 1)); +$unit->assertSame(2, $cookie->getData('test22'), 'Setting multiple cookies.'); + +$cookie->clear(); \ No newline at end of file diff --git a/unit/tests/file.php b/unit/tests/file.php new file mode 100644 index 0000000..a629099 --- /dev/null +++ b/unit/tests/file.php @@ -0,0 +1,30 @@ + +$loader->load('Eden_File'); +$unit->setPackage('Eden_File Tests'); + +//-------------------------// +// Test 1 +$file = Eden_File::get('home//openovate\public/eden.openovate.com/web/workspace.php'); +$unit->assertEquals('/projects/openovate/eden/v2/workspace.php', (string) $file, 'Format File Test.'); +$unit->assertEquals('workspace.php', $file->getName(), 'getName()'); +$unit->assertEquals('/projects/openovate/eden/v2', $file->getFolder(), 'getFolder()'); +$unit->assertEquals('workspace', $file->getBase(), 'getBase()'); +$unit->assertEquals('php', $file->getExtension(), 'getExtension()'); + +//-------------------------// +// Test 2 +$unit->assertEquals('application/octet-stream', $file->touch()->getMime(), 'touch() and getMime()'); +$unit->assertGreaterThanOrEquals(0, $file->getSize(), 'getSize()'); +$unit->assertGreaterThan(time()-100, $file->getTime(), 'getTime()'); +$unit->assertTrue($file->isFile(), 'isFile() [true]'); +$unit->assertEquals('test123', $file->setContent('test123')->getContent(), 'setContent() and getContent()'); +$unit->assertEquals('test123', $file->setData('test123')->getData(), 'setData() and getData()'); +$unit->assertCount(2, $file->setData(array(3,4))->getData(), 'setData() and getData()'); +$unit->assertGreaterThan(time()-100, $file->getTime(), 'getTime()'); +$unit->assertFalse($file->remove()->isFile(), ' remove() and isFile() [false]'); + +//-------------------------// +// Test 3 +$unit->assertEquals('openovate', $file[2], 'accessing file path with index'); +$file['replace'] = 'work2.php'; +$unit->assertEquals('/home/openovate/public/eden.openovate.com/web/work2.php', (string) $file, 'replacing with array'); \ No newline at end of file diff --git a/unit/tests/folder.php b/unit/tests/folder.php new file mode 100644 index 0000000..04f9736 --- /dev/null +++ b/unit/tests/folder.php @@ -0,0 +1,24 @@ + +$loader->load('Eden_Folder'); +$unit->setPackage('Eden_Folder Tests'); + +//-------------------------// +// Test 1 +$folder = Eden_Folder::get('home//openovate\public/eden.openovate.com/web'); +$folder[] = 'test'; +$unit->assertEquals('/home/openovate/public/eden.openovate.com/web/test', (string) $folder, 'Format Folder Test.'); +$unit->assertTrue($folder->create()->isFolder(), 'create() and isFolder()[true]'); +$unit->assertEquals('test', $folder->getName(), 'getName() - Folder name'); + +$folder->create()->append('dan')->create(); +$unit->assertEquals(array(), $folder->getFiles(), 'getFiles()[array]'); +$unit->assertTrue($folder->removeFiles()->isFile(), 'removeFiles()[true]'); + +$unit->assertFalse($folder->remove()->pop()->isFolder('dan'), 'remove() and isFolder()[false]'); + +$folder->create()->append('dan')->create()->pop()->truncate(); +$unit->assertCount(0, $folder->getFolders(), 'truncate()'); +$folder->remove(); + +$folder = Eden_Folder::get('home//openovate\public/eden.openovate.com/web/'); +$unit->assertCount(2, $folder->getFolders(), 'getFolders()'); \ No newline at end of file diff --git a/unit/tests/model.php b/unit/tests/model.php new file mode 100644 index 0000000..99d3405 --- /dev/null +++ b/unit/tests/model.php @@ -0,0 +1,68 @@ + +$loader->load('Eden_Model'); +$unit->setPackage('Eden_Model Tests'); + +$post = Eden_Model::get() + ->setMetaData('post_id') + ->setMetaData('post_title') + ->setMetaData('post_detail'); + +//-------------------------// +// Test 1 +$post['post_title'] = 'Title1'; +$unit->assertEquals('Title1', $post['post_title'], 'Setting values with array.'); + +$post->setPostTitle('Title2'); +$unit->assertEquals('Title2', $post['post_title'], 'Setting values with method.'); + +$post->post_title = 'Title3'; +$unit->assertEquals('Title3', $post['post_title'], 'Setting values with object.'); + +//-------------------------// +// Test 2 +$e1 = $e2 = $e3 = NULL; + +try { + $post['author'] = 'Chris'; +} catch(Exception $e1) {} + +$unit->assertInstanceOf('Eden_Model_Error', $e1, 'Setting invalid values with array.'); + +try { + $post->setAuthor('Chris'); +} catch(Exception $e2) {} + +$unit->assertInstanceOf('Eden_Model_Error', $e2, 'Setting invalid values with method.'); + +try { + $post->author = 'Chris'; +} catch(Exception $e3) {} + +$unit->assertInstanceOf('Eden_Model_Error', $e3, 'Setting invalid values with object.'); + +//-------------------------// +// Test 3 +$post['post_detail'] = 'Some Detail'; +$unit->assertEquals('Some Detail', $post['post_detail'], 'Getting values with array.'); +$unit->assertEquals('Some Detail', $post->getPostDetail(), 'Getting values with method.'); +$unit->assertEquals('Some Detail', $post->post_detail, 'Getting values with object.'); + +//-------------------------// +// Test 4 +$post['post_detail'] = 'Some Detail 2'; +unset($post['post_detail']); +$unit->assertNull($post['post_detail'], 'Disabled unset on array.'); + +$post->post_detail = 'Some Detail 3'; +unset($post->post_detail); +$unit->assertNull($post['post_detail'], 'Disabled unset on object.'); + +//-------------------------// +// Test 5 +$post->setMetaData('post_author', array('validation' => array('char', 255))); +$test = $post->getMetaData('post_author', 'validation'); +$unit->assertEquals(255, $test[1], "setMetaData('post_author', array('validation' => array('char', 255)))"); + +$post->setMetaData('post_author', 'format', 'BY: %s'); +$test = $post->getMetaData('post_author', 'format'); +$unit->assertEquals('BY: %s', $test, "setMetaData('post_author', 'format', 'BY: %s')"); \ No newline at end of file diff --git a/unit/tests/session.php b/unit/tests/session.php new file mode 100644 index 0000000..d1c72c3 --- /dev/null +++ b/unit/tests/session.php @@ -0,0 +1,38 @@ + +$loader->load('Eden_Session'); +$unit->setPackage('Eden_Session Tests'); + +$session = Eden_Session::get(); + +//-------------------------// +// Test 1 +try { + $session->setData('test', 456); +} catch(Exception $e1) {} + +$unit->assertInstanceOf('Eden_Session_Error', $e1, 'Error while doing something before session was started.'); + + +//-------------------------// +// Test 1 +$session->stop()->start()->setData('test', 456); +$unit->assertSame(456, $session->getData('test'), 'Basic setting and getting.'); + +$session['test2'] = 123; +$unit->assertSame(123, $session['test2'], 'Setting and getting using arrays.'); + +//-------------------------// +// Test 2 +$session->remove('test'); +$unit->assertNull($session->getData('test'), 'Removing a session.'); + +$session->clear(); +$unit->assertNull($session->getData('test2'), 'Removing all sessions.'); + +//-------------------------// +// Test 3 +$session->clear(); +$session->setData(array('test20' => 3, 'test22' => 2, 'test23' => 1)); +$unit->assertSame(2, $session->getData('test22'), 'Setting multiple sessions.'); + +$session->stop(); \ No newline at end of file diff --git a/unit/tests/string.php b/unit/tests/string.php new file mode 100644 index 0000000..1d98006 --- /dev/null +++ b/unit/tests/string.php @@ -0,0 +1,96 @@ + + +$loader->load('Eden_String'); +$unit->setPackage('Eden_String Tests'); + +//-------------------------// +// Test 1 +$string = Eden_String::get("Unit Test Eden V2"); + +$unit->assertEquals('Unit Test Eden V2', (string) $string, 'String Format Test'); +$unit->assertEquals('unitTestEdenV2', (string) $string->camelize(), 'camelize String'); +$unit->assertEquals('unit-test-eden-v2', (string) $string->uncamelize(), 'uncamelize string'); +$unit->assertEquals('unit-test-eden-v2', (string) $string->dasherize(), 'dasherize string'); +$unit->assertEquals('Unit Test Eden V2', (string) $string->titlize(), 'titlize string'); + +//pre methods +//Test 1 +//--------------------> +$string = Eden_String::get("Unit Test for Dan's Window"); + +$unit->assertEquals("unit test for dan's window", (string) $string->addslashes()->stripslashes()->strtolower(), "addslashes then stripslashes and strtolower"); +$unit->assertEquals(94, $string->bin2hex()->strlen(), 'bin2hex the string then strlen'); + + +//Test 2 +//---------------------> +$string = Eden_String::get("Unit Test"); +$unit->assertSame("Un\r\nit\r\n T\r\nes\r\nt\r\n", (string) $string->chunk_split(2), 'chunk_split'); //not working + +$string = Eden_String::get("Unit Test"); +$unit->assertEquals('Unit Test', (string) $string->convert_uuencode()->convert_uudecode(), 'convert_uuencode and back to convert_uudecode'); +//echo $string->crypt(CRYPT_MD5); + + +//Test 3 +//---------------------> +$string = Eden_String::get("I'll make a 'history!'"); +//echo $string->htmlentities()->html_entity_decode(); +$unit->assertSame("I'll make a 'history!'", (string) $string->htmlentities()->html_entity_decode(), 'htmlentities() then html_entity_decode'); //now working +//echo $string; +$unit->assertEquals("I'll make a 'history!'", (string) $string->htmlspecialchars()->htmlspecialchars_decode(), 'htmlspecialchars() to htmlspecialchars_decode()'); +$unit->assertEquals("6c24d06f9e32721ed8a6ee445bbf6bb1", (string) $string->ltrim()->md5(), "ltrim string the convert into md5"); + + +//Test 4 +//---------------------> +$string = Eden_String::get("Have a good Day!"); + +$unit->assertEquals("Have-a-good-Day!", (string) $string->str_replace(' ', "-"), "replace space to (-)"); +//echo $string->quotemeta(); + + +//Test 5 +//---------------------> +$string = Eden_String::get("\t\tThese are a few words"); +$unit->assertEquals("\t\tThese are a few words", (string) $string->rtrim(), "rtrim test"); +$unit->assertEquals("78d3808d95626fdd53151c50094f02a3859dd0dd", (string) $string->sha1(), "sha1 test"); + +$string = Eden_String::get("%d word for sprintf %s"); +$d = 2; +$s = "data"; +$unit->assertEquals("2 word for sprintf data", (string) $string->sprintf($d, $s), "sprintf test"); +$unit->assertEquals("2 word for sprintf data_-", (string) $string->str_pad(25, '_-'), "str_pad for string"); +$unit->assertEquals("2 word for sprintf data_-2 word for sprintf data_-", (string) $string->str_repeat(2), "str_pad for string"); + +$string = Eden_String::get("php string"); +$unit->assertEquals("cuc fgevat", (string) $string->str_rot13(), "str_rot13 encode"); +//echo $string->str_shuffle(); + +$string = Eden_String::get("php string"); +$unit->assertEquals("php ()string", (string) $string->strip_tags('')->str_replace("", "()"), "strip_tags allowsb tag"); + +$string = Eden_String::get("d\u\z"); +$unit->assertEquals("duz", (string) $string->stripcslashes()->stripslashes(), "stripcslashes() and stripslashes()"); +$unit->assertEquals("uz", (string) $string->strpbrk("u"), "strpbrk()"); + +$string = Eden_String::get("Returns the matched"); +$unit->assertEquals("turns the matched", (string) $string->stristr('t'), "stristr()"); +$unit->assertEquals("CTAM E", (string) $string->strrev()->strstr('h')->strtok('h')->strtoupper(), "strrev(), strstr(), strtok() and strtoupper()"); +$unit->assertEquals("AM d", (string) $string->strtr('E', 'd')->substr_replace('TAM', 0, 4)->substr(1, 4), "strtr() and substr_replace() then substr()"); + +$string = Eden_String::get("programming techniques "); +$unit->assertEquals("Programming Techniques", (string) $string->trim()->ucfirst()->ucwords(), "trim() and ucfirst() then ucwords()"); +$unit->assertEquals("Programming-Techniques", (string) $string->wordwrap(3, '
')->str_replace("
", "-"), "wordwrap() then str_replace()"); + +$unit->assertEquals("-PTaceghimnoqrsu", (string) $string->count_chars(3), "count_chars()"); +//echo $string->hex2bin(); => undifined= + +$string = Eden_String::get("programming %s techniques"); +$unit->assertEquals('12', (string) $string->vsprintf(array('29'))->strpos('2'), "vsprintf() and strpos()"); + +$string = Eden_String::get("dan"); +$unit->assertEquals('1', (string) $string->substr_compare('a', 0, 2), "substr_compare"); + +$string = Eden_String::get("this is it"); +$unit->assertEquals('3', (string) $string->substr_count('i'), "substr_count()"); \ No newline at end of file From 36c8977ce2add7abcc0fc097e49788470e0507c0 Mon Sep 17 00:00:00 2001 From: cblanquera Date: Tue, 15 Nov 2011 12:50:00 +0000 Subject: [PATCH 004/330] eventbrite git-svn-id: http://svn.openovate.com/edenv2/trunk@4 38ede93f-50f4-44af-b0b3-68ccca78c181 --- library/eden/eventbrite/base.php | 126 --------- library/eden/eventbrite/discount.php | 128 --------- library/eden/eventbrite/error.php | 54 ---- library/eden/eventbrite/event.php | 99 ------- library/eden/eventbrite/event/search.php | 245 ----------------- library/eden/eventbrite/event/set.php | 328 ----------------------- library/eden/eventbrite/organizer.php | 82 ------ library/eden/eventbrite/payment.php | 142 ---------- library/eden/eventbrite/ticket.php | 10 - library/eden/eventbrite/user.php | 10 - library/eden/eventbrite/venue.php | 10 - 11 files changed, 1234 deletions(-) delete mode 100644 library/eden/eventbrite/base.php delete mode 100644 library/eden/eventbrite/discount.php delete mode 100644 library/eden/eventbrite/error.php delete mode 100644 library/eden/eventbrite/event.php delete mode 100644 library/eden/eventbrite/event/search.php delete mode 100644 library/eden/eventbrite/event/set.php delete mode 100644 library/eden/eventbrite/organizer.php delete mode 100644 library/eden/eventbrite/payment.php delete mode 100644 library/eden/eventbrite/ticket.php delete mode 100644 library/eden/eventbrite/user.php delete mode 100644 library/eden/eventbrite/venue.php diff --git a/library/eden/eventbrite/base.php b/library/eden/eventbrite/base.php deleted file mode 100644 index ca217fa..0000000 --- a/library/eden/eventbrite/base.php +++ /dev/null @@ -1,126 +0,0 @@ - -/* - * 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. - */ - -/** - * Eventbrite oauth - * - * @package Eden - * @category google - * @author Christian Blanquera - * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ - */ -class Eden_Eventbrite_Base extends Eden_Class { - /* Constants - -------------------------------*/ - /* Public Properties - -------------------------------*/ - /* Protected Properties - -------------------------------*/ - protected $_user = NULL; - protected $_api = NULL; - protected $_meta = array(); - - /* Private Properties - -------------------------------*/ - /* Get - -------------------------------*/ - public static function get($user, $api) { - return self::_getMultiple(__CLASS__, $user, $api); - } - - /* Magic - -------------------------------*/ - public function __construct($user, $api) { - //argument test - Eden_Google_Error::get() - ->argument(1, 'string','array') //Argument 1 must be a string or array - ->argument(2, 'string'); //Argument 2 must be a string - - $this->_api = $api; - $this->_user = $user; - } - - /* Public Methods - -------------------------------*/ - /** - * Returns the meta of the last call - * - * @return array - */ - public function getMeta($key = NULL) { - Eden_Google_Error::get()->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($reponse, true); - } - - protected function _getXmlResponse($url, array $query = array()) { - $response = $this->_getResponse($url, $query); - return simplexml_load_string($reponse); - } - - protected function _getResponse($url, array $query = array()) { - $headers = array(); - $headers[] = 'Content-Type: application/json'; - - $query['app_key'] = $this->_api; - if(is_array($this->_user)) { - $query['user'] = $this->_user[0]; - $query['password'] = $this->_user[1]; - } else { - $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::get() - ->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; - } - - /* Private Methods - -------------------------------*/ -} \ No newline at end of file diff --git a/library/eden/eventbrite/discount.php b/library/eden/eventbrite/discount.php deleted file mode 100644 index 2e197d3..0000000 --- a/library/eden/eventbrite/discount.php +++ /dev/null @@ -1,128 +0,0 @@ - -/* - * 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. - */ - -/** - * Eventbrite new or update discount - * - * @package Eden - * @category eventbrite - * @author Christian Blanquera - * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ - */ -class Eden_Eventbrite_Event_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 - -------------------------------*/ - /* Get - -------------------------------*/ - public static function get($user, $api) { - return self::_getMultiple(__CLASS__, $user, $api); - } - - /* Magic - -------------------------------*/ - /* Public Methods - -------------------------------*/ - public function add($event, $code, $amount, $percent, $tickets, $quantity, $start, $end) { - //Argument Test - Eden_Eventbrite_Error::get() - ->argument(1, 'int') //Argument 1 must be an integer - ->argument(2, 'string') //Argument 2 must be a string - ->argument(3, 'float') //Argument 3 must be a float - ->argument(4, 'float') //Argument 4 must be a float - ->argument(5, 'string', 'array') //Argument 5 must be a string or array - ->argument(6, 'int') //Argument 6 must be an array - ->argument(7, 'string') //Argument 7 must be a string - ->argument(8, 'string'); //Argument 8 must be a string - - if(is_array($tickets)) { - $tickets = implode(',', $tickets); - } - - if(is_string($start)) { - $start = strtotime($start); - } - - $start = date('Y-m-d H:i:s', $start); - - if(is_string($end)) { - $end = strtotime($end); - } - - $end = date('Y-m-d H:i:s', $end); - - $query = array( - 'event_id' => $event, - 'code' => $code, - 'amount_off' => $amount, - 'percent_off' => $percent, - 'tickets' => $tickets, - 'quantity_available' => $quantity, - 'start_date' => $start, - 'end_date' => $end); - - return $this->_getJsonResponse(self::URL_NEW, $query); - } - - public function update($id, $code, $amount, $percent, $tickets, $quantity, $start, $end) { - //Argument Test - Eden_Eventbrite_Error::get() - ->argument(1, 'int') //Argument 1 must be an integer - ->argument(2, 'string') //Argument 2 must be a string - ->argument(3, 'float') //Argument 3 must be a float - ->argument(4, 'float') //Argument 4 must be a float - ->argument(5, 'string', 'array') //Argument 5 must be a string or array - ->argument(6, 'int') //Argument 6 must be an array - ->argument(7, 'string') //Argument 7 must be a string - ->argument(8, 'string'); //Argument 8 must be a string - - if(is_array($tickets)) { - $tickets = implode(',', $tickets); - } - - if(is_string($start)) { - $start = strtotime($start); - } - - $start = date('Y-m-d H:i:s', $start); - - if(is_string($end)) { - $end = strtotime($end); - } - - $end = date('Y-m-d H:i:s', $end); - - $query = array( - 'id' => $id, - 'code' => $code, - 'amount_off' => $amount, - 'percent_off' => $percent, - 'tickets' => $tickets, - 'quantity_available' => $quantity, - 'start_date' => $start, - 'end_date' => $end); - - 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 deleted file mode 100644 index fe5f0b6..0000000 --- a/library/eden/eventbrite/error.php +++ /dev/null @@ -1,54 +0,0 @@ - -/* - * 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. - */ - -/** - * Eventbrite Errors - * - * @package Eden - * @category google - * @author Christian Blanquera - * @version $Id: exception.php 1 2010-01-02 23:06:36Z blanquera $ - */ -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()'; - - /* Public Properties - -------------------------------*/ - /* Protected Properties - -------------------------------*/ - /* Private Properties - -------------------------------*/ - /* Get - -------------------------------*/ - public static function get($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/eventbrite/event.php b/library/eden/eventbrite/event.php deleted file mode 100644 index 0556364..0000000 --- a/library/eden/eventbrite/event.php +++ /dev/null @@ -1,99 +0,0 @@ - -/* - * 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. - */ - -/** - * Google calendar - * - * @package Eden - * @category google - * @author Christian Blanquera - * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ - */ -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 - -------------------------------*/ - /* Get - -------------------------------*/ - public static function get($user, $api) { - return self::_getMultiple(__CLASS__, $user, $api); - } - - /* Magic - -------------------------------*/ - /* Public Methods - -------------------------------*/ - public function copy($id, $name) { - //argument test - Eden_Eventbrite_Error::get() - ->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); - } - - public function getDetail($id) { - //Argument 1 must be numeric - Eden_Eventbrite_Error::get()->argument(1, 'numeric'); - - $query = array('id' => $id); - - return $this->_getJsonResponse(self::URL_GET, $query); - } - - public function getAttendees($id, $count = 50, $page = 1, $display = NULL, $barcodes = false) { - //argument test - $error = Eden_Eventbrite_Error::get() - ->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); - } - - public function getDiscounts($id) { - //Argument 1 must be numeric - Eden_Eventbrite_Error::get()->argument(1, 'numeric'); - - $query = array('id' => $id); - - return $this->_getJsonResponse(self::URL_LIST_DISCOUNTS, $query); - } - - /* 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 deleted file mode 100644 index ae3f758..0000000 --- a/library/eden/eventbrite/event/search.php +++ /dev/null @@ -1,245 +0,0 @@ - -/* - * 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. - */ - -/** - * Eventbrite search - * - * @package Eden - * @category eventbrite - * @author Christian Blanquera - * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ - */ -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 - -------------------------------*/ - /* Get - -------------------------------*/ - public static function get($user, $api) { - return self::_getMultiple(__CLASS__, $user, $api); - } - - /* Magic - -------------------------------*/ - /* Public Methods - -------------------------------*/ - public function setKeywords($keywords) { - //Argument 1 must be a string - Eden_Eventbrite_Error::get()->argument(1, 'string'); - - $query['keywords'] = $keywords; - - return $this; - } - - public function setCategory($category) { - //Argument 1 must be a string or array - Eden_Eventbrite_Error::get()->argument(1, 'string', 'array'); - - if(is_array($tickets)) { - $tickets = implode(',', $tickets); - } - - $query['category'] = $category; - - return $this; - } - - public function setAddress($address) { - //Argument 1 must be a string - Eden_Eventbrite_Error::get()->argument(1, 'string'); - - $query['address'] = $address; - - return $this; - } - - public function setCity($city) { - //Argument 1 must be a string - Eden_Eventbrite_Error::get()->argument(1, 'string'); - - $query['city'] = $city; - - return $this; - } - - public function setRegion($region) { - //Argument 1 must be a string - Eden_Eventbrite_Error::get()->argument(1, 'string'); - - $query['region'] = $region; - - return $this; - } - - public function setPostal($postal) { - //Argument 1 must be a string or integer - Eden_Eventbrite_Error::get()->argument(1, 'string', 'int'); - - $query['postal_code'] = $postal; - - return $this; - } - - public function setCountry($country) { - //Argument 1 must be a string - Eden_Eventbrite_Error::get()->argument(1, 'string'); - - $query['country'] = $country; - - return $this; - } - - public function setWithin($within) { - //Argument 1 must be a int - Eden_Eventbrite_Error::get()->argument(1, 'int'); - - $query['within'] = $within; - - return $this; - } - - public function setWithinUnit($unit) { - //Argument 1 must be a string - Eden_Eventbrite_Error::get()->argument(1, 'string'); - - $query['within_unit'] = $unit; - - return $this; - } - - public function setLatitude($latitude) { - //Argument 1 must be a float - Eden_Eventbrite_Error::get()->argument(1, 'float'); - - $query['latitude'] = $latitude; - - return $this; - } - - public function setLongitude($longitude) { - //Argument 1 must be a float - Eden_Eventbrite_Error::get()->argument(1, 'float'); - - $query['longitude'] = $longitude; - - return $this; - } - - public function setDate($date) { - //Argument 1 must be a string - Eden_Eventbrite_Error::get()->argument(1, 'string'); - - $query['date'] = $date; - - return $this; - } - - public function setDateCreated($date) { - //Argument 1 must be a string - Eden_Eventbrite_Error::get()->argument(1, 'string'); - - $query['date_created'] = $date; - - return $this; - } - - public function setDateModified($date) { - //Argument 1 must be a string - Eden_Eventbrite_Error::get()->argument(1, 'string'); - - $query['date_modified'] = $date; - - return $this; - } - - public function setOrganizer($organizer) { - //Argument 1 must be a string - Eden_Eventbrite_Error::get()->argument(1, 'string'); - - $query['organizer'] = $organizer; - - return $this; - } - - public function setMax($max) { - //Argument 1 must be a int - Eden_Eventbrite_Error::get()->argument(1, 'int'); - - if($max > 100) { - $max = 100; - } - - $query['max'] = $max; - - return $this; - } - - public function countOnly() { - $query['count_only'] = 'true'; - - return $this; - } - - public function sort($column) { - //Argument 1 must be a string - Eden_Eventbrite_Error::get()->argument(1, 'string'); - - if(in_array($column, $this->_validSort)) { - $query['sort_by'] = $column; - } - - return $this; - } - - public function setPage($page) { - //Argument 1 must be a int - Eden_Eventbrite_Error::get()->argument(1, 'int'); - - $query['page'] = $page; - - return $this; - } - - public function setSince($since) { - //Argument 1 must be a int - Eden_Eventbrite_Error::get()->argument(1, 'int'); - - $query['since_id'] = $since; - - return $this; - } - - public function setTracking($tracking) { - //Argument 1 must be a string - Eden_Eventbrite_Error::get()->argument(1, 'string'); - - $query['tracking_link'] = $tracking; - - return $this; - } - - public function send() { - return $this->_getJsonResponse(self::URL, $this->_query); - } - - /* 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 deleted file mode 100644 index d66e60c..0000000 --- a/library/eden/eventbrite/event/set.php +++ /dev/null @@ -1,328 +0,0 @@ - -/* - * 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. - */ - -/** - * Eventbrite new or update event - * - * @package Eden - * @category eventbrite - * @author Christian Blanquera - * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ - */ -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'; - - /* Public Properties - -------------------------------*/ - /* Protected Properties - -------------------------------*/ - protected $_query = array(); - - /* Private Properties - -------------------------------*/ - /* Get - -------------------------------*/ - public static function get($user, $api) { - return self::_getMultiple(__CLASS__, $user, $api); - } - - /* Magic - -------------------------------*/ - /* Public Methods - -------------------------------*/ - public function setId($id) { - //Argument 1 must be int - Eden_Eventbrite_Error::get()->argument(1, 'int'); - - $query['event_id'] = $id; - - return $this; - } - - public function setTitle($title) { - //Argument 1 must be a string - Eden_Eventbrite_Error::get()->argument(1, 'string'); - - $query['title'] = $title; - - return $this; - } - - public function setDescription($description) { - //Argument 1 must be a string - Eden_Eventbrite_Error::get()->argument(1, 'string'); - - $query['description'] = $description; - - return $this; - } - - public function setStart($start) { - //Argument 1 must be a string - Eden_Eventbrite_Error::get()->argument(1, 'string', 'int'); - - if(is_string($start)) { - $start = strtotime($start); - } - - $start = date('Y-m-d H:i:s', $start); - - $query['start_date'] = $start; - - return $this; - } - - public function setEnd($end) { - //Argument 1 must be a string - Eden_Eventbrite_Error::get()->argument(1, 'string', 'int'); - - if(is_string($end)) { - $end = strtotime($end); - } - - $end = date('Y-m-d H:i:s', $end); - - $query['end_date'] = $end; - - return $this; - } - - public function setTimezone($zone) { - //Argument 1 must be a string - Eden_Eventbrite_Error::get()->argument(1, 'string'); - - $query['timezone'] = $zone; - - return $this; - } - - public function isPublic() { - $query['privacy'] = 1; - - return $this; - } - - public function isPrivate() { - $query['privacy'] = 0; - - return $this; - } - - public function setUrl($url) { - //Argument 1 must be a string - Eden_Eventbrite_Error::get()->argument(1, 'string'); - - $query['personalized_url'] = $url; - - return $this; - } - - public function setVenue($venue) { - //Argument 1 must be a numeric - Eden_Eventbrite_Error::get()->argument(1, 'numeric'); - - $query['venue_id'] = $venue; - - return $this; - } - - public function setOrganizer($organizer) { - //Argument 1 must be a numeric - Eden_Eventbrite_Error::get()->argument(1, 'numeric'); - - $query['organizer_id'] = $organizer; - - return $this; - } - - public function setCapacity($capacity) { - //Argument 1 must be a numeric - Eden_Eventbrite_Error::get()->argument(1, 'numeric'); - - $query['capacity'] = $capacity; - - return $this; - } - - public function setCurrency($currency) { - //Argument 1 must be a string - Eden_Eventbrite_Error::get()->argument(1, 'string'); - - $query['currency'] = $currency; - - return $this; - } - - public function setStatus($status) { - //Argument 1 must be a string - Eden_Eventbrite_Error::get()->argument(1, 'string'); - - $query['status'] = $status; - - return $this; - } - - public function setHeader($html) { - //Argument 1 must be a string - Eden_Eventbrite_Error::get()->argument(1, 'string'); - - $query['custom_header'] = $html; - - return $this; - } - - public function setFooter($html) { - //Argument 1 must be a string - Eden_Eventbrite_Error::get()->argument(1, 'string'); - - $query['custom_footer'] = $html; - - return $this; - } - - public function setBackground($color) { - //Argument 1 must be a string - Eden_Eventbrite_Error::get()->argument(1, 'string'); - - $query['background_color'] = $color; - - return $this; - } - - public function setTextColor($color) { - //Argument 1 must be a string - Eden_Eventbrite_Error::get()->argument(1, 'string'); - - $query['text_color'] = $color; - - return $this; - } - - public function setLinkColor($color) { - //Argument 1 must be a string - Eden_Eventbrite_Error::get()->argument(1, 'string'); - - $query['link_color'] = $color; - - return $this; - } - - public function setTitleColor($color) { - //Argument 1 must be a string - Eden_Eventbrite_Error::get()->argument(1, 'string'); - - $query['title_text_color'] = $color; - - return $this; - } - - public function setBoxBackground($color) { - //Argument 1 must be a string - Eden_Eventbrite_Error::get()->argument(1, 'string'); - - $query['box_background_color'] = $color; - - return $this; - } - - public function setBoxColor($color) { - //Argument 1 must be a string - Eden_Eventbrite_Error::get()->argument(1, 'string'); - - $query['box_text_color'] = $color; - - return $this; - } - - public function setBorderColor($color) { - //Argument 1 must be a string - Eden_Eventbrite_Error::get()->argument(1, 'string'); - - $query['box_border_color'] = $color; - - return $this; - } - - public function setHeaderBackground($color) { - //Argument 1 must be a string - Eden_Eventbrite_Error::get()->argument(1, 'string'); - - $query['box_header_background_color'] = $color; - - return $this; - } - - public function setHeaderColor($color) { - //Argument 1 must be a string - Eden_Eventbrite_Error::get()->argument(1, 'string'); - - $query['box_header_text_color'] = $color; - - return $this; - } - - public function send() { - if(!isset($this->_query['title'])) { - Eden_Eventbrite_Error::get()->setMessage(Eden_Eventbrite_Error::TITLE_NOT_SET)->trigger(); - } - - if(!isset($this->_query['start_date'])) { - Eden_Eventbrite_Error::get()->setMessage(Eden_Eventbrite_Error::START_NOT_SET)->trigger(); - } - - - if(!isset($this->_query['end_date'])) { - Eden_Eventbrite_Error::get()->setMessage(Eden_Eventbrite_Error::END_NOT_SET)->trigger(); - } - - if(!isset($this->_query['timezone'])) { - Eden_Eventbrite_Error::get()->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::get()->setMessage(Eden_Eventbrite_Error::PRIVACY_NOT_SET)->trigger(); - } - - if(!isset($this->_query['personalized_url'])) { - Eden_Eventbrite_Error::get()->setMessage(Eden_Eventbrite_Error::URL_NOT_SET)->trigger(); - } - - if(!isset($this->_query['organizer_id'])) { - Eden_Eventbrite_Error::get()->setMessage(Eden_Eventbrite_Error::ORGANIZER_NOT_SET)->trigger(); - } - - if(!isset($this->_query['venue_id'])) { - Eden_Eventbrite_Error::get()->setMessage(Eden_Eventbrite_Error::VENUE_NOT_SET)->trigger(); - } - - if(!isset($this->_query['capacity'])) { - Eden_Eventbrite_Error::get()->setMessage(Eden_Eventbrite_Error::CAPACITY_NOT_SET)->trigger(); - } - - if(!isset($this->_query['currency'])) { - Eden_Eventbrite_Error::get()->setMessage(Eden_Eventbrite_Error::CURRENCY_NOT_SET)->trigger(); - } - } - - return $this->_getJsonResponse($url, $this->_query); - } - - /* Protected Methods - -------------------------------*/ - /* Private Methods - -------------------------------*/ -} \ No newline at end of file diff --git a/library/eden/eventbrite/organizer.php b/library/eden/eventbrite/organizer.php deleted file mode 100644 index 6c2ba5b..0000000 --- a/library/eden/eventbrite/organizer.php +++ /dev/null @@ -1,82 +0,0 @@ - -/* - * 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. - */ - -/** - * Eventbrite Organizer - * - * @package Eden - * @category eventbrite - * @author Christian Blanquera - * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ - */ -class Eden_Eventbrite_Event_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 - -------------------------------*/ - /* Get - -------------------------------*/ - public static function get($user, $api) { - return self::_getMultiple(__CLASS__, $user, $api); - } - - /* Magic - -------------------------------*/ - /* Public Methods - -------------------------------*/ - public function add($name, $description = NULL) { - //Argument Test - Eden_Eventbrite_Error::get() - ->argument(1, 'string') //Argument 1 must be a string - ->argument(2, 'string'); //Argument 2 must be a string - - $query = array( - 'name' => $name, - 'description' => $description); - - return $this->_getJsonResponse(self::URL_NEW, $query); - } - - public function update($id, $name, $description = NULL) { - //Argument Test - Eden_Eventbrite_Error::get() - ->argument(1, 'int') //Argument 1 must be an integer - ->argument(2, 'string') //Argument 2 must be a string - ->argument(3, 'string'); //Argument 3 must be a string - - $query = array( - 'id' => $id, - 'name' => $name, - 'description' => $description); - - return $this->_getJsonResponse(self::URL_UPDATE, $query); - } - - public function getEvents($id) { - //Argument 1 must be an int - Eden_Eventbrite_Error::get()->argument(1, 'int'); - - $query = array('id' => $id); - - return $this->_getJsonResponse(self::URL_EVENTS, $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 deleted file mode 100644 index 2080994..0000000 --- a/library/eden/eventbrite/payment.php +++ /dev/null @@ -1,142 +0,0 @@ - -/* - * 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. - */ - -/** - * Eventbrite payment - * - * @package Eden - * @category eventbrite - * @author Christian Blanquera - * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ - */ -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 - -------------------------------*/ - /* Get - -------------------------------*/ - public static function get($user, $api) { - return self::_getMultiple(__CLASS__, $user, $api); - } - - /* Magic - -------------------------------*/ - /* Public Methods - -------------------------------*/ - public function setEvent($id) { - //Argument 1 must be int - Eden_Eventbrite_Error::get()->argument(1, 'int'); - - $query['event_id'] = $id; - - return $this; - } - - public function acceptPaypal() { - $query['accept_paypal'] = 1; - - return $this; - } - - public function setPaypalEmail($email) { - //Argument 1 must be a string - Eden_Eventbrite_Error::get()->argument(1, 'string'); - - $query['paypal_email'] = $email; - - return $this; - } - - public function acceptGoogle() { - $query['accept_google'] = 1; - - return $this; - } - - public function setGoogleMerchantId($id) { - //Argument 1 must be a string - Eden_Eventbrite_Error::get()->argument(1, 'string'); - - $query['google_merchant_id'] = $id; - - return $this; - } - - public function setGoogleMerchantKey($key) { - //Argument 1 must be a string - Eden_Eventbrite_Error::get()->argument(1, 'string'); - - $query['google_merchant_key'] = $key; - - return $this; - } - - public function acceptCheck() { - $query['accept_check'] = 1; - - return $this; - } - - public function setCheckInstructions($check) { - //Argument 1 must be a string - Eden_Eventbrite_Error::get()->argument(1, 'string'); - - $query['insrtructions_check'] = $check; - - return $this; - } - - public function acceptCash() { - $query['accept_check'] = 1; - - return $this; - } - - public function setCashInstructions($check) { - //Argument 1 must be a string - Eden_Eventbrite_Error::get()->argument(1, 'string'); - - $query['insrtructions_cash'] = $check; - - return $this; - } - - public function acceptInovice() { - $query['accept_invoice'] = 1; - - return $this; - } - - public function setInvoiceInstructions($check) { - //Argument 1 must be a string - Eden_Eventbrite_Error::get()->argument(1, 'string'); - - $query['insrtructions_invoice'] = $check; - - return $this; - } - - public function send() { - 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 deleted file mode 100644 index baec7d6..0000000 --- a/library/eden/eventbrite/ticket.php +++ /dev/null @@ -1,10 +0,0 @@ - - - - -Untitled Document - - - - - \ No newline at end of file diff --git a/library/eden/eventbrite/user.php b/library/eden/eventbrite/user.php deleted file mode 100644 index baec7d6..0000000 --- a/library/eden/eventbrite/user.php +++ /dev/null @@ -1,10 +0,0 @@ - - - - -Untitled Document - - - - - \ No newline at end of file diff --git a/library/eden/eventbrite/venue.php b/library/eden/eventbrite/venue.php deleted file mode 100644 index baec7d6..0000000 --- a/library/eden/eventbrite/venue.php +++ /dev/null @@ -1,10 +0,0 @@ - - - - -Untitled Document - - - - - \ No newline at end of file From 77025c0b8085f305534fce66e763186a5eca7b92 Mon Sep 17 00:00:00 2001 From: cblanquera Date: Tue, 15 Nov 2011 12:51:16 +0000 Subject: [PATCH 005/330] eventbrite git-svn-id: http://svn.openovate.com/edenv2/trunk@5 38ede93f-50f4-44af-b0b3-68ccca78c181 --- library/eden/eventbrite/base.php | 126 ++++++++ library/eden/eventbrite/discount.php | 128 ++++++++ library/eden/eventbrite/error.php | 56 ++++ library/eden/eventbrite/event.php | 99 +++++++ library/eden/eventbrite/event/abstract.php | 261 ++++++++++++++++ library/eden/eventbrite/event/new.php | 328 +++++++++++++++++++++ library/eden/eventbrite/event/search.php | 245 +++++++++++++++ library/eden/eventbrite/event/set.php | 328 +++++++++++++++++++++ library/eden/eventbrite/organizer.php | 82 ++++++ library/eden/eventbrite/payment.php | 142 +++++++++ library/eden/eventbrite/ticket.php | 202 +++++++++++++ library/eden/eventbrite/user.php | 229 ++++++++++++++ library/eden/eventbrite/venues.php | 139 +++++++++ 13 files changed, 2365 insertions(+) create mode 100644 library/eden/eventbrite/base.php create mode 100644 library/eden/eventbrite/discount.php create mode 100644 library/eden/eventbrite/error.php create mode 100644 library/eden/eventbrite/event.php create mode 100644 library/eden/eventbrite/event/abstract.php create mode 100644 library/eden/eventbrite/event/new.php create mode 100644 library/eden/eventbrite/event/search.php create mode 100644 library/eden/eventbrite/event/set.php create mode 100644 library/eden/eventbrite/organizer.php create mode 100644 library/eden/eventbrite/payment.php create mode 100644 library/eden/eventbrite/ticket.php create mode 100644 library/eden/eventbrite/user.php create mode 100644 library/eden/eventbrite/venues.php diff --git a/library/eden/eventbrite/base.php b/library/eden/eventbrite/base.php new file mode 100644 index 0000000..ca217fa --- /dev/null +++ b/library/eden/eventbrite/base.php @@ -0,0 +1,126 @@ + +/* + * 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. + */ + +/** + * Eventbrite oauth + * + * @package Eden + * @category google + * @author Christian Blanquera + * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ + */ +class Eden_Eventbrite_Base extends Eden_Class { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_user = NULL; + protected $_api = NULL; + protected $_meta = array(); + + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function get($user, $api) { + return self::_getMultiple(__CLASS__, $user, $api); + } + + /* Magic + -------------------------------*/ + public function __construct($user, $api) { + //argument test + Eden_Google_Error::get() + ->argument(1, 'string','array') //Argument 1 must be a string or array + ->argument(2, 'string'); //Argument 2 must be a string + + $this->_api = $api; + $this->_user = $user; + } + + /* Public Methods + -------------------------------*/ + /** + * Returns the meta of the last call + * + * @return array + */ + public function getMeta($key = NULL) { + Eden_Google_Error::get()->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($reponse, true); + } + + protected function _getXmlResponse($url, array $query = array()) { + $response = $this->_getResponse($url, $query); + return simplexml_load_string($reponse); + } + + protected function _getResponse($url, array $query = array()) { + $headers = array(); + $headers[] = 'Content-Type: application/json'; + + $query['app_key'] = $this->_api; + if(is_array($this->_user)) { + $query['user'] = $this->_user[0]; + $query['password'] = $this->_user[1]; + } else { + $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::get() + ->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; + } + + /* 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..2e197d3 --- /dev/null +++ b/library/eden/eventbrite/discount.php @@ -0,0 +1,128 @@ + +/* + * 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. + */ + +/** + * Eventbrite new or update discount + * + * @package Eden + * @category eventbrite + * @author Christian Blanquera + * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ + */ +class Eden_Eventbrite_Event_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 + -------------------------------*/ + /* Get + -------------------------------*/ + public static function get($user, $api) { + return self::_getMultiple(__CLASS__, $user, $api); + } + + /* Magic + -------------------------------*/ + /* Public Methods + -------------------------------*/ + public function add($event, $code, $amount, $percent, $tickets, $quantity, $start, $end) { + //Argument Test + Eden_Eventbrite_Error::get() + ->argument(1, 'int') //Argument 1 must be an integer + ->argument(2, 'string') //Argument 2 must be a string + ->argument(3, 'float') //Argument 3 must be a float + ->argument(4, 'float') //Argument 4 must be a float + ->argument(5, 'string', 'array') //Argument 5 must be a string or array + ->argument(6, 'int') //Argument 6 must be an array + ->argument(7, 'string') //Argument 7 must be a string + ->argument(8, 'string'); //Argument 8 must be a string + + if(is_array($tickets)) { + $tickets = implode(',', $tickets); + } + + if(is_string($start)) { + $start = strtotime($start); + } + + $start = date('Y-m-d H:i:s', $start); + + if(is_string($end)) { + $end = strtotime($end); + } + + $end = date('Y-m-d H:i:s', $end); + + $query = array( + 'event_id' => $event, + 'code' => $code, + 'amount_off' => $amount, + 'percent_off' => $percent, + 'tickets' => $tickets, + 'quantity_available' => $quantity, + 'start_date' => $start, + 'end_date' => $end); + + return $this->_getJsonResponse(self::URL_NEW, $query); + } + + public function update($id, $code, $amount, $percent, $tickets, $quantity, $start, $end) { + //Argument Test + Eden_Eventbrite_Error::get() + ->argument(1, 'int') //Argument 1 must be an integer + ->argument(2, 'string') //Argument 2 must be a string + ->argument(3, 'float') //Argument 3 must be a float + ->argument(4, 'float') //Argument 4 must be a float + ->argument(5, 'string', 'array') //Argument 5 must be a string or array + ->argument(6, 'int') //Argument 6 must be an array + ->argument(7, 'string') //Argument 7 must be a string + ->argument(8, 'string'); //Argument 8 must be a string + + if(is_array($tickets)) { + $tickets = implode(',', $tickets); + } + + if(is_string($start)) { + $start = strtotime($start); + } + + $start = date('Y-m-d H:i:s', $start); + + if(is_string($end)) { + $end = strtotime($end); + } + + $end = date('Y-m-d H:i:s', $end); + + $query = array( + 'id' => $id, + 'code' => $code, + 'amount_off' => $amount, + 'percent_off' => $percent, + 'tickets' => $tickets, + 'quantity_available' => $quantity, + 'start_date' => $start, + 'end_date' => $end); + + 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..8351751 --- /dev/null +++ b/library/eden/eventbrite/error.php @@ -0,0 +1,56 @@ + +/* + * 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. + */ + +/** + * Eventbrite Errors + * + * @package Eden + * @category google + * @author Christian Blanquera + * @version $Id: exception.php 1 2010-01-02 23:06:36Z blanquera $ + */ +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 + -------------------------------*/ + /* Get + -------------------------------*/ + public static function get($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/eventbrite/event.php b/library/eden/eventbrite/event.php new file mode 100644 index 0000000..0556364 --- /dev/null +++ b/library/eden/eventbrite/event.php @@ -0,0 +1,99 @@ + +/* + * 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. + */ + +/** + * Google calendar + * + * @package Eden + * @category google + * @author Christian Blanquera + * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ + */ +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 + -------------------------------*/ + /* Get + -------------------------------*/ + public static function get($user, $api) { + return self::_getMultiple(__CLASS__, $user, $api); + } + + /* Magic + -------------------------------*/ + /* Public Methods + -------------------------------*/ + public function copy($id, $name) { + //argument test + Eden_Eventbrite_Error::get() + ->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); + } + + public function getDetail($id) { + //Argument 1 must be numeric + Eden_Eventbrite_Error::get()->argument(1, 'numeric'); + + $query = array('id' => $id); + + return $this->_getJsonResponse(self::URL_GET, $query); + } + + public function getAttendees($id, $count = 50, $page = 1, $display = NULL, $barcodes = false) { + //argument test + $error = Eden_Eventbrite_Error::get() + ->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); + } + + public function getDiscounts($id) { + //Argument 1 must be numeric + Eden_Eventbrite_Error::get()->argument(1, 'numeric'); + + $query = array('id' => $id); + + return $this->_getJsonResponse(self::URL_LIST_DISCOUNTS, $query); + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/eventbrite/event/abstract.php b/library/eden/eventbrite/event/abstract.php new file mode 100644 index 0000000..eb22d17 --- /dev/null +++ b/library/eden/eventbrite/event/abstract.php @@ -0,0 +1,261 @@ + +/* + * 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. + */ + +/** + * Google calendar + * + * @package Eden + * @category google + * @author Christian Blanquera + * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ + */ +abstract class Eden_Eventbrite_Event_Abstract extends Eden_Eventbrite_Base { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_query = array(); + + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + /* Magic + -------------------------------*/ + /* Public Methods + -------------------------------*/ + public function setTitle($title) { + //Argument 1 must be a string + Eden_Eventbrite_Error::get()->argument(1, 'string'); + + $query['title'] = $title; + + return $this; + } + + public function setDescription($description) { + //Argument 1 must be a string + Eden_Eventbrite_Error::get()->argument(1, 'string'); + + $query['description'] = $description; + + return $this; + } + + public function setStart($start) { + //Argument 1 must be a string + Eden_Eventbrite_Error::get()->argument(1, 'string', 'int'); + + if(is_string($start)) { + $start = strtotime($start); + } + + $start = date('Y-m-d H:i:s', $start); + + $query['start_date'] = $start; + + return $this; + } + + public function setEnd($end) { + //Argument 1 must be a string + Eden_Eventbrite_Error::get()->argument(1, 'string', 'int'); + + if(is_string($end)) { + $end = strtotime($end); + } + + $end = date('Y-m-d H:i:s', $end); + + $query['end_date'] = $end; + + return $this; + } + + public function setTimezone($zone) { + //Argument 1 must be a string + Eden_Eventbrite_Error::get()->argument(1, 'string'); + + if(strpos($zone, 'GMT') !== 0) { + $zone = 'GMT'.$zone; + } + + $query['timezone'] = $zone; + + return $this; + } + + public function isPublic() { + $query['privacy'] = 1; + + return $this; + } + + public function setUrl($url) { + //Argument 1 must be a string + Eden_Eventbrite_Error::get()->argument(1, 'string'); + + $query['personalized_url'] = $url; + + return $this; + } + + public function setVenue($venue) { + //Argument 1 must be a numeric + Eden_Eventbrite_Error::get()->argument(1, 'numeric'); + + $query['venue'] = $venue; + + return $this; + } + + public function setOrganizer($organizer) { + //Argument 1 must be a numeric + Eden_Eventbrite_Error::get()->argument(1, 'numeric'); + + $query['organizer'] = $organizer; + + return $this; + } + + public function setCapacity($capacity) { + //Argument 1 must be a numeric + Eden_Eventbrite_Error::get()->argument(1, 'numeric'); + + $query['capacity'] = $capacity; + + return $this; + } + + public function setCurrency($currency) { + //Argument 1 must be a string + Eden_Eventbrite_Error::get()->argument(1, 'string'); + + $query['currency'] = $currency; + + return $this; + } + + public function setStatus($status) { + //Argument 1 must be a string + Eden_Eventbrite_Error::get()->argument(1, 'string'); + + $query['status'] = $status; + + return $this; + } + + public function setHeader($html) { + //Argument 1 must be a string + Eden_Eventbrite_Error::get()->argument(1, 'string'); + + $query['custom_header'] = $html; + + return $this; + } + + public function setFooter($html) { + //Argument 1 must be a string + Eden_Eventbrite_Error::get()->argument(1, 'string'); + + $query['custom_footer'] = $html; + + return $this; + } + + public function setBackground($color) { + //Argument 1 must be a string + Eden_Eventbrite_Error::get()->argument(1, 'string'); + + $query['background_color'] = $color; + + return $this; + } + + public function setTextColor($color) { + //Argument 1 must be a string + Eden_Eventbrite_Error::get()->argument(1, 'string'); + + $query['text_color'] = $color; + + return $this; + } + + public function setLinkColor($color) { + //Argument 1 must be a string + Eden_Eventbrite_Error::get()->argument(1, 'string'); + + $query['link_color'] = $color; + + return $this; + } + + public function setTitleColor($color) { + //Argument 1 must be a string + Eden_Eventbrite_Error::get()->argument(1, 'string'); + + $query['title_text_color'] = $color; + + return $this; + } + + public function setBoxBackground($color) { + //Argument 1 must be a string + Eden_Eventbrite_Error::get()->argument(1, 'string'); + + $query['box_background_color'] = $color; + + return $this; + } + + public function setBoxColor($color) { + //Argument 1 must be a string + Eden_Eventbrite_Error::get()->argument(1, 'string'); + + $query['box_text_color'] = $color; + + return $this; + } + + public function setBorderColor($color) { + //Argument 1 must be a string + Eden_Eventbrite_Error::get()->argument(1, 'string'); + + $query['box_border_color'] = $color; + + return $this; + } + + public function setHeaderBackground($color) { + //Argument 1 must be a string + Eden_Eventbrite_Error::get()->argument(1, 'string'); + + $query['box_header_background_color'] = $color; + + return $this; + } + + public function setHeaderColor($color) { + //Argument 1 must be a string + Eden_Eventbrite_Error::get()->argument(1, 'string'); + + $query['box_header_text_color'] = $color; + + return $this; + } + + abstract public function send(); + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/eventbrite/event/new.php b/library/eden/eventbrite/event/new.php new file mode 100644 index 0000000..c688d77 --- /dev/null +++ b/library/eden/eventbrite/event/new.php @@ -0,0 +1,328 @@ + +/* + * 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. + */ + +/** + * Eventbrite calendar + * + * @package Eden + * @category eventbrite + * @author Christian Blanquera + * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ + */ +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'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_query = array(); + + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function get($user, $api) { + return self::_getMultiple(__CLASS__, $user, $api); + } + + /* Magic + -------------------------------*/ + /* Public Methods + -------------------------------*/ + public function setId($id) { + //Argument 1 must be numeric + Eden_Eventbrite_Error::get()->argument(1, 'numeric'); + + $query['id'] = $id; + + return $this; + } + + public function setTitle($title) { + //Argument 1 must be a string + Eden_Eventbrite_Error::get()->argument(1, 'string'); + + $query['title'] = $title; + + return $this; + } + + public function setDescription($description) { + //Argument 1 must be a string + Eden_Eventbrite_Error::get()->argument(1, 'string'); + + $query['description'] = $description; + + return $this; + } + + public function setStart($start) { + //Argument 1 must be a string + Eden_Eventbrite_Error::get()->argument(1, 'string', 'int'); + + if(is_string($start)) { + $start = strtotime($start); + } + + $start = date('Y-m-d H:i:s', $start); + + $query['start_date'] = $start; + + return $this; + } + + public function setEnd($end) { + //Argument 1 must be a string + Eden_Eventbrite_Error::get()->argument(1, 'string', 'int'); + + if(is_string($end)) { + $end = strtotime($end); + } + + $end = date('Y-m-d H:i:s', $end); + + $query['end_date'] = $end; + + return $this; + } + + public function setTimezone($zone) { + //Argument 1 must be a string + Eden_Eventbrite_Error::get()->argument(1, 'string'); + + $query['timezone'] = $zone; + + return $this; + } + + public function isPublic() { + $query['privacy'] = 1; + + return $this; + } + + public function isPrivate() { + $query['privacy'] = 0; + + return $this; + } + + public function setUrl($url) { + //Argument 1 must be a string + Eden_Eventbrite_Error::get()->argument(1, 'string'); + + $query['personalized_url'] = $url; + + return $this; + } + + public function setVenue($venue) { + //Argument 1 must be a numeric + Eden_Eventbrite_Error::get()->argument(1, 'numeric'); + + $query['venue_id'] = $venue; + + return $this; + } + + public function setOrganizer($organizer) { + //Argument 1 must be a numeric + Eden_Eventbrite_Error::get()->argument(1, 'numeric'); + + $query['organizer_id'] = $organizer; + + return $this; + } + + public function setCapacity($capacity) { + //Argument 1 must be a numeric + Eden_Eventbrite_Error::get()->argument(1, 'numeric'); + + $query['capacity'] = $capacity; + + return $this; + } + + public function setCurrency($currency) { + //Argument 1 must be a string + Eden_Eventbrite_Error::get()->argument(1, 'string'); + + $query['currency'] = $currency; + + return $this; + } + + public function setStatus($status) { + //Argument 1 must be a string + Eden_Eventbrite_Error::get()->argument(1, 'string'); + + $query['status'] = $status; + + return $this; + } + + public function setHeader($html) { + //Argument 1 must be a string + Eden_Eventbrite_Error::get()->argument(1, 'string'); + + $query['custom_header'] = $html; + + return $this; + } + + public function setFooter($html) { + //Argument 1 must be a string + Eden_Eventbrite_Error::get()->argument(1, 'string'); + + $query['custom_footer'] = $html; + + return $this; + } + + public function setBackground($color) { + //Argument 1 must be a string + Eden_Eventbrite_Error::get()->argument(1, 'string'); + + $query['background_color'] = $color; + + return $this; + } + + public function setTextColor($color) { + //Argument 1 must be a string + Eden_Eventbrite_Error::get()->argument(1, 'string'); + + $query['text_color'] = $color; + + return $this; + } + + public function setLinkColor($color) { + //Argument 1 must be a string + Eden_Eventbrite_Error::get()->argument(1, 'string'); + + $query['link_color'] = $color; + + return $this; + } + + public function setTitleColor($color) { + //Argument 1 must be a string + Eden_Eventbrite_Error::get()->argument(1, 'string'); + + $query['title_text_color'] = $color; + + return $this; + } + + public function setBoxBackground($color) { + //Argument 1 must be a string + Eden_Eventbrite_Error::get()->argument(1, 'string'); + + $query['box_background_color'] = $color; + + return $this; + } + + public function setBoxColor($color) { + //Argument 1 must be a string + Eden_Eventbrite_Error::get()->argument(1, 'string'); + + $query['box_text_color'] = $color; + + return $this; + } + + public function setBorderColor($color) { + //Argument 1 must be a string + Eden_Eventbrite_Error::get()->argument(1, 'string'); + + $query['box_border_color'] = $color; + + return $this; + } + + public function setHeaderBackground($color) { + //Argument 1 must be a string + Eden_Eventbrite_Error::get()->argument(1, 'string'); + + $query['box_header_background_color'] = $color; + + return $this; + } + + public function setHeaderColor($color) { + //Argument 1 must be a string + Eden_Eventbrite_Error::get()->argument(1, 'string'); + + $query['box_header_text_color'] = $color; + + return $this; + } + + public function send() { + if(!isset($this->_query['title'])) { + Eden_Eventbrite_Error::get()->setMessage(Eden_Eventbrite_Error::TITLE_NOT_SET)->trigger(); + } + + if(!isset($this->_query['start_date'])) { + Eden_Eventbrite_Error::get()->setMessage(Eden_Eventbrite_Error::START_NOT_SET)->trigger(); + } + + + if(!isset($this->_query['end_date'])) { + Eden_Eventbrite_Error::get()->setMessage(Eden_Eventbrite_Error::END_NOT_SET)->trigger(); + } + + if(!isset($this->_query['timezone'])) { + Eden_Eventbrite_Error::get()->setMessage(Eden_Eventbrite_Error::ZONE_NOT_SET)->trigger(); + } + + $url = self::URL_NEW; + + if(isset($this->_query['id'])) { + $url = self::URL_UPDATE; + + if(!isset($this->_query['privacy'])) { + Eden_Eventbrite_Error::get()->setMessage(Eden_Eventbrite_Error::PRIVACY_NOT_SET)->trigger(); + } + + if(!isset($this->_query['personalized_url'])) { + Eden_Eventbrite_Error::get()->setMessage(Eden_Eventbrite_Error::URL_NOT_SET)->trigger(); + } + + if(!isset($this->_query['organizer_id'])) { + Eden_Eventbrite_Error::get()->setMessage(Eden_Eventbrite_Error::ORGANIZER_NOT_SET)->trigger(); + } + + if(!isset($this->_query['venue_id'])) { + Eden_Eventbrite_Error::get()->setMessage(Eden_Eventbrite_Error::VENUE_NOT_SET)->trigger(); + } + + if(!isset($this->_query['capacity'])) { + Eden_Eventbrite_Error::get()->setMessage(Eden_Eventbrite_Error::CAPACITY_NOT_SET)->trigger(); + } + + if(!isset($this->_query['currency'])) { + Eden_Eventbrite_Error::get()->setMessage(Eden_Eventbrite_Error::CURRENCY_NOT_SET)->trigger(); + } + } + + return $this->_getJsonResponse($url, $this->_query); + } + + /* 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..ae3f758 --- /dev/null +++ b/library/eden/eventbrite/event/search.php @@ -0,0 +1,245 @@ + +/* + * 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. + */ + +/** + * Eventbrite search + * + * @package Eden + * @category eventbrite + * @author Christian Blanquera + * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ + */ +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 + -------------------------------*/ + /* Get + -------------------------------*/ + public static function get($user, $api) { + return self::_getMultiple(__CLASS__, $user, $api); + } + + /* Magic + -------------------------------*/ + /* Public Methods + -------------------------------*/ + public function setKeywords($keywords) { + //Argument 1 must be a string + Eden_Eventbrite_Error::get()->argument(1, 'string'); + + $query['keywords'] = $keywords; + + return $this; + } + + public function setCategory($category) { + //Argument 1 must be a string or array + Eden_Eventbrite_Error::get()->argument(1, 'string', 'array'); + + if(is_array($tickets)) { + $tickets = implode(',', $tickets); + } + + $query['category'] = $category; + + return $this; + } + + public function setAddress($address) { + //Argument 1 must be a string + Eden_Eventbrite_Error::get()->argument(1, 'string'); + + $query['address'] = $address; + + return $this; + } + + public function setCity($city) { + //Argument 1 must be a string + Eden_Eventbrite_Error::get()->argument(1, 'string'); + + $query['city'] = $city; + + return $this; + } + + public function setRegion($region) { + //Argument 1 must be a string + Eden_Eventbrite_Error::get()->argument(1, 'string'); + + $query['region'] = $region; + + return $this; + } + + public function setPostal($postal) { + //Argument 1 must be a string or integer + Eden_Eventbrite_Error::get()->argument(1, 'string', 'int'); + + $query['postal_code'] = $postal; + + return $this; + } + + public function setCountry($country) { + //Argument 1 must be a string + Eden_Eventbrite_Error::get()->argument(1, 'string'); + + $query['country'] = $country; + + return $this; + } + + public function setWithin($within) { + //Argument 1 must be a int + Eden_Eventbrite_Error::get()->argument(1, 'int'); + + $query['within'] = $within; + + return $this; + } + + public function setWithinUnit($unit) { + //Argument 1 must be a string + Eden_Eventbrite_Error::get()->argument(1, 'string'); + + $query['within_unit'] = $unit; + + return $this; + } + + public function setLatitude($latitude) { + //Argument 1 must be a float + Eden_Eventbrite_Error::get()->argument(1, 'float'); + + $query['latitude'] = $latitude; + + return $this; + } + + public function setLongitude($longitude) { + //Argument 1 must be a float + Eden_Eventbrite_Error::get()->argument(1, 'float'); + + $query['longitude'] = $longitude; + + return $this; + } + + public function setDate($date) { + //Argument 1 must be a string + Eden_Eventbrite_Error::get()->argument(1, 'string'); + + $query['date'] = $date; + + return $this; + } + + public function setDateCreated($date) { + //Argument 1 must be a string + Eden_Eventbrite_Error::get()->argument(1, 'string'); + + $query['date_created'] = $date; + + return $this; + } + + public function setDateModified($date) { + //Argument 1 must be a string + Eden_Eventbrite_Error::get()->argument(1, 'string'); + + $query['date_modified'] = $date; + + return $this; + } + + public function setOrganizer($organizer) { + //Argument 1 must be a string + Eden_Eventbrite_Error::get()->argument(1, 'string'); + + $query['organizer'] = $organizer; + + return $this; + } + + public function setMax($max) { + //Argument 1 must be a int + Eden_Eventbrite_Error::get()->argument(1, 'int'); + + if($max > 100) { + $max = 100; + } + + $query['max'] = $max; + + return $this; + } + + public function countOnly() { + $query['count_only'] = 'true'; + + return $this; + } + + public function sort($column) { + //Argument 1 must be a string + Eden_Eventbrite_Error::get()->argument(1, 'string'); + + if(in_array($column, $this->_validSort)) { + $query['sort_by'] = $column; + } + + return $this; + } + + public function setPage($page) { + //Argument 1 must be a int + Eden_Eventbrite_Error::get()->argument(1, 'int'); + + $query['page'] = $page; + + return $this; + } + + public function setSince($since) { + //Argument 1 must be a int + Eden_Eventbrite_Error::get()->argument(1, 'int'); + + $query['since_id'] = $since; + + return $this; + } + + public function setTracking($tracking) { + //Argument 1 must be a string + Eden_Eventbrite_Error::get()->argument(1, 'string'); + + $query['tracking_link'] = $tracking; + + return $this; + } + + public function send() { + return $this->_getJsonResponse(self::URL, $this->_query); + } + + /* 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..d66e60c --- /dev/null +++ b/library/eden/eventbrite/event/set.php @@ -0,0 +1,328 @@ + +/* + * 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. + */ + +/** + * Eventbrite new or update event + * + * @package Eden + * @category eventbrite + * @author Christian Blanquera + * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ + */ +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'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_query = array(); + + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function get($user, $api) { + return self::_getMultiple(__CLASS__, $user, $api); + } + + /* Magic + -------------------------------*/ + /* Public Methods + -------------------------------*/ + public function setId($id) { + //Argument 1 must be int + Eden_Eventbrite_Error::get()->argument(1, 'int'); + + $query['event_id'] = $id; + + return $this; + } + + public function setTitle($title) { + //Argument 1 must be a string + Eden_Eventbrite_Error::get()->argument(1, 'string'); + + $query['title'] = $title; + + return $this; + } + + public function setDescription($description) { + //Argument 1 must be a string + Eden_Eventbrite_Error::get()->argument(1, 'string'); + + $query['description'] = $description; + + return $this; + } + + public function setStart($start) { + //Argument 1 must be a string + Eden_Eventbrite_Error::get()->argument(1, 'string', 'int'); + + if(is_string($start)) { + $start = strtotime($start); + } + + $start = date('Y-m-d H:i:s', $start); + + $query['start_date'] = $start; + + return $this; + } + + public function setEnd($end) { + //Argument 1 must be a string + Eden_Eventbrite_Error::get()->argument(1, 'string', 'int'); + + if(is_string($end)) { + $end = strtotime($end); + } + + $end = date('Y-m-d H:i:s', $end); + + $query['end_date'] = $end; + + return $this; + } + + public function setTimezone($zone) { + //Argument 1 must be a string + Eden_Eventbrite_Error::get()->argument(1, 'string'); + + $query['timezone'] = $zone; + + return $this; + } + + public function isPublic() { + $query['privacy'] = 1; + + return $this; + } + + public function isPrivate() { + $query['privacy'] = 0; + + return $this; + } + + public function setUrl($url) { + //Argument 1 must be a string + Eden_Eventbrite_Error::get()->argument(1, 'string'); + + $query['personalized_url'] = $url; + + return $this; + } + + public function setVenue($venue) { + //Argument 1 must be a numeric + Eden_Eventbrite_Error::get()->argument(1, 'numeric'); + + $query['venue_id'] = $venue; + + return $this; + } + + public function setOrganizer($organizer) { + //Argument 1 must be a numeric + Eden_Eventbrite_Error::get()->argument(1, 'numeric'); + + $query['organizer_id'] = $organizer; + + return $this; + } + + public function setCapacity($capacity) { + //Argument 1 must be a numeric + Eden_Eventbrite_Error::get()->argument(1, 'numeric'); + + $query['capacity'] = $capacity; + + return $this; + } + + public function setCurrency($currency) { + //Argument 1 must be a string + Eden_Eventbrite_Error::get()->argument(1, 'string'); + + $query['currency'] = $currency; + + return $this; + } + + public function setStatus($status) { + //Argument 1 must be a string + Eden_Eventbrite_Error::get()->argument(1, 'string'); + + $query['status'] = $status; + + return $this; + } + + public function setHeader($html) { + //Argument 1 must be a string + Eden_Eventbrite_Error::get()->argument(1, 'string'); + + $query['custom_header'] = $html; + + return $this; + } + + public function setFooter($html) { + //Argument 1 must be a string + Eden_Eventbrite_Error::get()->argument(1, 'string'); + + $query['custom_footer'] = $html; + + return $this; + } + + public function setBackground($color) { + //Argument 1 must be a string + Eden_Eventbrite_Error::get()->argument(1, 'string'); + + $query['background_color'] = $color; + + return $this; + } + + public function setTextColor($color) { + //Argument 1 must be a string + Eden_Eventbrite_Error::get()->argument(1, 'string'); + + $query['text_color'] = $color; + + return $this; + } + + public function setLinkColor($color) { + //Argument 1 must be a string + Eden_Eventbrite_Error::get()->argument(1, 'string'); + + $query['link_color'] = $color; + + return $this; + } + + public function setTitleColor($color) { + //Argument 1 must be a string + Eden_Eventbrite_Error::get()->argument(1, 'string'); + + $query['title_text_color'] = $color; + + return $this; + } + + public function setBoxBackground($color) { + //Argument 1 must be a string + Eden_Eventbrite_Error::get()->argument(1, 'string'); + + $query['box_background_color'] = $color; + + return $this; + } + + public function setBoxColor($color) { + //Argument 1 must be a string + Eden_Eventbrite_Error::get()->argument(1, 'string'); + + $query['box_text_color'] = $color; + + return $this; + } + + public function setBorderColor($color) { + //Argument 1 must be a string + Eden_Eventbrite_Error::get()->argument(1, 'string'); + + $query['box_border_color'] = $color; + + return $this; + } + + public function setHeaderBackground($color) { + //Argument 1 must be a string + Eden_Eventbrite_Error::get()->argument(1, 'string'); + + $query['box_header_background_color'] = $color; + + return $this; + } + + public function setHeaderColor($color) { + //Argument 1 must be a string + Eden_Eventbrite_Error::get()->argument(1, 'string'); + + $query['box_header_text_color'] = $color; + + return $this; + } + + public function send() { + if(!isset($this->_query['title'])) { + Eden_Eventbrite_Error::get()->setMessage(Eden_Eventbrite_Error::TITLE_NOT_SET)->trigger(); + } + + if(!isset($this->_query['start_date'])) { + Eden_Eventbrite_Error::get()->setMessage(Eden_Eventbrite_Error::START_NOT_SET)->trigger(); + } + + + if(!isset($this->_query['end_date'])) { + Eden_Eventbrite_Error::get()->setMessage(Eden_Eventbrite_Error::END_NOT_SET)->trigger(); + } + + if(!isset($this->_query['timezone'])) { + Eden_Eventbrite_Error::get()->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::get()->setMessage(Eden_Eventbrite_Error::PRIVACY_NOT_SET)->trigger(); + } + + if(!isset($this->_query['personalized_url'])) { + Eden_Eventbrite_Error::get()->setMessage(Eden_Eventbrite_Error::URL_NOT_SET)->trigger(); + } + + if(!isset($this->_query['organizer_id'])) { + Eden_Eventbrite_Error::get()->setMessage(Eden_Eventbrite_Error::ORGANIZER_NOT_SET)->trigger(); + } + + if(!isset($this->_query['venue_id'])) { + Eden_Eventbrite_Error::get()->setMessage(Eden_Eventbrite_Error::VENUE_NOT_SET)->trigger(); + } + + if(!isset($this->_query['capacity'])) { + Eden_Eventbrite_Error::get()->setMessage(Eden_Eventbrite_Error::CAPACITY_NOT_SET)->trigger(); + } + + if(!isset($this->_query['currency'])) { + Eden_Eventbrite_Error::get()->setMessage(Eden_Eventbrite_Error::CURRENCY_NOT_SET)->trigger(); + } + } + + return $this->_getJsonResponse($url, $this->_query); + } + + /* 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..6c2ba5b --- /dev/null +++ b/library/eden/eventbrite/organizer.php @@ -0,0 +1,82 @@ + +/* + * 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. + */ + +/** + * Eventbrite Organizer + * + * @package Eden + * @category eventbrite + * @author Christian Blanquera + * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ + */ +class Eden_Eventbrite_Event_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 + -------------------------------*/ + /* Get + -------------------------------*/ + public static function get($user, $api) { + return self::_getMultiple(__CLASS__, $user, $api); + } + + /* Magic + -------------------------------*/ + /* Public Methods + -------------------------------*/ + public function add($name, $description = NULL) { + //Argument Test + Eden_Eventbrite_Error::get() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'string'); //Argument 2 must be a string + + $query = array( + 'name' => $name, + 'description' => $description); + + return $this->_getJsonResponse(self::URL_NEW, $query); + } + + public function update($id, $name, $description = NULL) { + //Argument Test + Eden_Eventbrite_Error::get() + ->argument(1, 'int') //Argument 1 must be an integer + ->argument(2, 'string') //Argument 2 must be a string + ->argument(3, 'string'); //Argument 3 must be a string + + $query = array( + 'id' => $id, + 'name' => $name, + 'description' => $description); + + return $this->_getJsonResponse(self::URL_UPDATE, $query); + } + + public function getEvents($id) { + //Argument 1 must be an int + Eden_Eventbrite_Error::get()->argument(1, 'int'); + + $query = array('id' => $id); + + return $this->_getJsonResponse(self::URL_EVENTS, $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..2080994 --- /dev/null +++ b/library/eden/eventbrite/payment.php @@ -0,0 +1,142 @@ + +/* + * 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. + */ + +/** + * Eventbrite payment + * + * @package Eden + * @category eventbrite + * @author Christian Blanquera + * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ + */ +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 + -------------------------------*/ + /* Get + -------------------------------*/ + public static function get($user, $api) { + return self::_getMultiple(__CLASS__, $user, $api); + } + + /* Magic + -------------------------------*/ + /* Public Methods + -------------------------------*/ + public function setEvent($id) { + //Argument 1 must be int + Eden_Eventbrite_Error::get()->argument(1, 'int'); + + $query['event_id'] = $id; + + return $this; + } + + public function acceptPaypal() { + $query['accept_paypal'] = 1; + + return $this; + } + + public function setPaypalEmail($email) { + //Argument 1 must be a string + Eden_Eventbrite_Error::get()->argument(1, 'string'); + + $query['paypal_email'] = $email; + + return $this; + } + + public function acceptGoogle() { + $query['accept_google'] = 1; + + return $this; + } + + public function setGoogleMerchantId($id) { + //Argument 1 must be a string + Eden_Eventbrite_Error::get()->argument(1, 'string'); + + $query['google_merchant_id'] = $id; + + return $this; + } + + public function setGoogleMerchantKey($key) { + //Argument 1 must be a string + Eden_Eventbrite_Error::get()->argument(1, 'string'); + + $query['google_merchant_key'] = $key; + + return $this; + } + + public function acceptCheck() { + $query['accept_check'] = 1; + + return $this; + } + + public function setCheckInstructions($check) { + //Argument 1 must be a string + Eden_Eventbrite_Error::get()->argument(1, 'string'); + + $query['insrtructions_check'] = $check; + + return $this; + } + + public function acceptCash() { + $query['accept_check'] = 1; + + return $this; + } + + public function setCashInstructions($check) { + //Argument 1 must be a string + Eden_Eventbrite_Error::get()->argument(1, 'string'); + + $query['insrtructions_cash'] = $check; + + return $this; + } + + public function acceptInovice() { + $query['accept_invoice'] = 1; + + return $this; + } + + public function setInvoiceInstructions($check) { + //Argument 1 must be a string + Eden_Eventbrite_Error::get()->argument(1, 'string'); + + $query['insrtructions_invoice'] = $check; + + return $this; + } + + public function send() { + 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..f9b13b3 --- /dev/null +++ b/library/eden/eventbrite/ticket.php @@ -0,0 +1,202 @@ + +/* + * 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. + */ + +/** + * Eventbrite new or update discount + * + * @package Eden + * @category eventbrite + * @author Christian Blanquera + * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ + */ +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 + -------------------------------*/ + /* Get + -------------------------------*/ + public static function get($user, $api) { + return self::_getMultiple(__CLASS__, $user, $api); + } + + /* Magic + -------------------------------*/ + /* Public Methods + -------------------------------*/ + public function add($event, $name, $price, $quantity, $description = NULL, $donation = false, $start = NULL, $end = NULL, $fee = false, $min = NULL, $max = NULL) { + //argument test + Eden_Eventbrite_Error::get() + ->argument(1, 'numeric') //Argument 1 must be numeric + ->argument(2, 'string') //Argument 2 must be a string + ->argument(3, 'float') //Argument 3 must a float + ->argument(4, 'int') //Argument 4 must be an integer + ->argument(5, 'string', 'null') //Argument 5 must be a string or null + ->argument(6, 'bool') //Argument 6 must be an integer + ->argument(7, 'string', 'int', 'null') //Argument 7 must be a string, integer or null + ->argument(8, 'string', 'int', 'null') //Argument 8 must be a string, integer or null + ->argument(9, 'bool') //Argument 9 must be an integer + ->argument(10, 'int') //Argument 10 must be an integer + ->argument(11, 'int', 'null') //Argument 11 must be an integer or null + ->argument(12, 'int', 'null'); //Argument 12 must be an integer or null + + $query = array ( + 'event_id' => $event, + 'name' => $name, + 'price' => $price, + 'quantity' => $quantity); + + if($donation){ + $query['is_donation'] = 1; + } + //if description is not empty + if(!is_null($description)){ + //add it to our query + $query['description'] = $description; + } + //if start is not empty + if(!is_null($start)){ + //if start is a string + if(is_string($start)) { + //then convert it to unixcode + $start = strtotime($start); + } + + $start = date('Y-m-d H:i:s', $start); + //add it to our query + $query['start_sales'] = $start; + } + //if end is not empty + if(!is_null($end)){ + //if end is a string + if(is_string($end)){ + //then convert it to unixcode + $end = strtotime($end); + } + + $end = date('Y-m-d H:i:s', $end); + //add it to our query + $query['end_sales'] = $end; + } + + if($fee){ + $query['include_fee'] = 1; + } + //if min is not empty and min is not greater than 0 + if(!is_null($min) && $min > 0){ + //add it to our query + $query['min'] = $min; + } + //if maqx is not empty and max is not greater than equal to min + if(!is_null($max) && $max > 0 && $max >= $min){ + //add it to our query + $query['max'] = $max; + } + return $this->_getJsonResponse(self::URL_NEW, $query); + + } + + public function update($event, $name, $price, $quantity, $description = NULL, $donation = false, $start = NULL, $end = NULL, $fee = false, $min = NULL, $max = NULL, $hide = NULL) { + //argument test + Eden_Eventbrite_Error::get() + ->argument(1, 'numeric') //Argument 1 must be numeric + ->argument(2, 'string') //Argument 2 must be a string + ->argument(3, 'float') //Argument 3 must a float + ->argument(4, 'int') //Argument 4 must be an integer + ->argument(5, 'string', 'null') //Argument 5 must be a string or null + ->argument(6, 'bool') //Argument 6 must be an integer + ->argument(7, 'string', 'int', 'null') //Argument 7 must be a string, integer or null + ->argument(8, 'string', 'int', 'null') //Argument 8 must be a string, integer or null + ->argument(9, 'bool') //Argument 9 must be an integer + ->argument(10, 'int') //Argument 10 must be an integer + ->argument(11, 'int', 'null') //Argument 11 must be an integer or null + ->argument(12, 'int', 'null') //Argument 12 must be an integer or null + ->argument(13, 'bool', 'null'); //Argument 13 must be a boolean or null + + $query = array ( + 'event_id' => $event, + 'name' => $name, + 'price' => $price, + 'quantity' => $quantity); + + if($donation){ + $query['is_donation'] = 1; + } + //if description is not empty + if(!is_null($description)){ + //add it to our query + $query['description'] = $description; + } + //if start is not empty + if(!is_null($start)){ + //if start is a string + if(is_string($start)) { + //then convert it to unixcode + $start = strtotime($start); + } + + $start = date('Y-m-d H:i:s', $start); + //add it to our query + $query['start_sales'] = $start; + } + //if start is not empty + if(!is_null($end)) { + //if start is a string + if(is_string($end)){ + //then convert it to unixcode + $end = strtotime($end); + } + + $end = date('Y-m-d H:i:s', $end); + //add it to our query + $query['end_sales'] = $end; + } + + if($fee) { + $query['include_fee'] = 1; + } + //if min is not empty and min is not greater than 0 + if(!is_null($min) && $min > 0 ){ + //add it to our query + $query['min'] = $min; + } + //if maqx is not empty and max is not greater than equal to min + if(!is_null($max) && $max > 0 && $max >= $min ){ + //add it to our query + $query['max'] = $max; + } + //if the string hide is show + if($hide) { + //hide is equal to yes + $query['hide'] = 'y'; + } else if($hide === false) { + //hide is equal to no + $query['hide'] = 'n'; + } + + return $this->_getJsonResponse(self::URL_UPDATE, $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..5360983 --- /dev/null +++ b/library/eden/eventbrite/user.php @@ -0,0 +1,229 @@ + +/* + * 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. + */ + +/** + * Eventbrite new or update discount + * + * @package Eden + * @category eventbrite + * @author Christian Blanquera + * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ + */ +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 + -------------------------------*/ + /* Get + -------------------------------*/ + public static function get($user, $api) { + return self::_getMultiple(__CLASS__, $user, $api); + } + + /* Magic + -------------------------------*/ + /* Public Methods + -------------------------------*/ + public function getDetail($id = NULL, $email = NULL) { + //argument test + Eden_Eventbrite_Error::get() + ->argument(1, 'int', 'null') //Argument 1 must be a integer 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($email)) { + //add it to query + $query['email'] = $email; + } + + return $this->_getJsonResponse(self::URL_GET, $query); + + } + + public function getEvents($user = NULL, $hide = NULL, $status = NULL, $order = NULL) { + //argument test + Eden_Eventbrite_Error::get() + ->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_NEW, $query); + } + + + public function getOrganizers($user, $pass) { + //argument test + Eden_Eventbrite_Error::get() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'string'); //Argument 2 must be a string + + $query = array( + 'user' => $user, + 'password' => $pass); + + return $this->_getJsonResponse(self::URL_LIST_ORGANIZERS, $query); + + } + + public function getTicket(){ + return this->_getJsonResponse(self::URL_LIST_TICKETS); + } + + public function getVenue($user, $pass) { + //argument test + Eden_Eventbrite_Error::get() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'string'); //Argument 2 must be a string + + $query = array( + 'user' => $user, + 'password' => $pass); + + return $this->_getJsonResponse(self::URL_LIST_VENUES, $query); + } + + public function add($user, $pass) { + //argument test + $error = Eden_Eventbrite_Error::get() + ->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); + + } + + public function update($email = NULL, $pass = NULL) { + //argument test + Eden_Eventbrite_Error::get() + ->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/venues.php b/library/eden/eventbrite/venues.php new file mode 100644 index 0000000..96d9c74 --- /dev/null +++ b/library/eden/eventbrite/venues.php @@ -0,0 +1,139 @@ + +/* + * 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. + */ + +/** + * Eventbrite new or update discount + * + * @package Eden + * @category eventbrite + * @author Christian Blanquera + * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ + */ +class Eden_Eventbrite_Venues 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 get($user, $api) { + return self::_getMultiple(__CLASS__, $user, $api); + } + /* Magic + -------------------------------*/ + /* Public Methods + -------------------------------*/ + public function add($organizer, $venue, $country, $region, $address1 = NULL, $address2 = NULL, $city = NULL, $postal = NULL) { + //argument test + Eden_Eventbrite_Error::get() + ->argument(1, 'string') //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 + ->argument(5, 'string', 'null') //Argument must be a string or null + ->argument(6, 'string', 'null') //Argument must be a string or null + ->argument(7, 'string', 'null') //Argument must be a string or null + ->argument(8, 'string', 'null'); //Argument must be a string or null + + $query = array( + 'organizer_id' => $organizer, + 'venue' => $venue, + 'country' => $country_code, + 'region' => $region); + //if address1 is not empty + if(!is_null($address1)) { + //add it to our query + $query['adress'] = > $address1; + } + //if address2 is not empty + if(!is_null($address2)) { + //add it to our query + $query['adress_2'] => $address2; + } + //if city is not empty + if(!is_null($city)) { + //add it to our query + $query['city'] => $city; + } + //if postal is not empty + if(!is_null($postal) { + //add it to our query + $query['postal_code'] => $postal; + } + + return $this->_getJsonResponse(self::URL_NEW, $query); + } + + public function update($id, $venue, $address1 = NULL, $address2 = NULL, $city = NULL, $region = NULL, $postal = NULL, $country = NULL){ + //argument test + Eden_Eventbrite_Error::get() + ->argument(1, 'int') //Argument must be a integer + ->argument(2, 'string') //Argument must be a string + ->argument(3, 'string', 'null') //Argument must be a string or null + ->argument(4, 'string', 'null') //Argument must be a string or null + ->argument(5, 'string', 'null') //Argument must be a string or null + ->argument(6, 'string', 'null') //Argument must be a string or null + ->argument(7, 'string', 'null'); //Argument must be a string or null + + $query = array( + 'id' => $id, + 'venue' => $venue); + //if address1 is not empty + if(!is_null($address1)) { + //add it to our query + $query['adress'] = $address1; + } + //if address2 is not empty + if(!is_null($adress2)) { + //add it to our query + $query['adress_2'] = $address2; + } + //if city is not empty + if(!is_null($city)) { + //add it to our query + $query['city'] = $city; + } + //if postal is not empty + if(!is_null($postal)) { + //add it to our query + $query['postal_code'] = $postal; + ] + //if country is not a empty + if(!is_null($country)) { + //add it to our query + $query['country_code'] = $country; + } + + return $this->getJsonResponse(self::URL_UPDATE, $query); + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} + + + + + + + + + + From 2c825d0b7c5a8f4a6002ce972b07936a411c8165 Mon Sep 17 00:00:00 2001 From: cblanquera Date: Wed, 16 Nov 2011 17:13:01 +0000 Subject: [PATCH 006/330] Eventbrite git-svn-id: http://svn.openovate.com/edenv2/trunk@6 38ede93f-50f4-44af-b0b3-68ccca78c181 --- library/eden.php | 10 +- library/eden/eventbrite/event/abstract.php | 261 ---------------- library/eden/eventbrite/event/new.php | 328 --------------------- site/front.php | 2 +- site/web/index.php | 4 +- 5 files changed, 9 insertions(+), 596 deletions(-) delete mode 100644 library/eden/eventbrite/event/abstract.php delete mode 100644 library/eden/eventbrite/event/new.php diff --git a/library/eden.php b/library/eden.php index f1013b2..563bdaa 100644 --- a/library/eden.php +++ b/library/eden.php @@ -58,11 +58,13 @@ public function __call($name, $args) { } public function __construct() { - //require autoload - require dirname(__FILE__).'/eden/loader.php'; + 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::get(), 'handler')); + //set autoload class as the autoload handler + spl_autoload_register(array(Eden_Loader::get(), 'handler')); + } } /* Public Methods diff --git a/library/eden/eventbrite/event/abstract.php b/library/eden/eventbrite/event/abstract.php deleted file mode 100644 index eb22d17..0000000 --- a/library/eden/eventbrite/event/abstract.php +++ /dev/null @@ -1,261 +0,0 @@ - -/* - * 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. - */ - -/** - * Google calendar - * - * @package Eden - * @category google - * @author Christian Blanquera - * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ - */ -abstract class Eden_Eventbrite_Event_Abstract extends Eden_Eventbrite_Base { - /* Constants - -------------------------------*/ - /* Public Properties - -------------------------------*/ - /* Protected Properties - -------------------------------*/ - protected $_query = array(); - - /* Private Properties - -------------------------------*/ - /* Get - -------------------------------*/ - /* Magic - -------------------------------*/ - /* Public Methods - -------------------------------*/ - public function setTitle($title) { - //Argument 1 must be a string - Eden_Eventbrite_Error::get()->argument(1, 'string'); - - $query['title'] = $title; - - return $this; - } - - public function setDescription($description) { - //Argument 1 must be a string - Eden_Eventbrite_Error::get()->argument(1, 'string'); - - $query['description'] = $description; - - return $this; - } - - public function setStart($start) { - //Argument 1 must be a string - Eden_Eventbrite_Error::get()->argument(1, 'string', 'int'); - - if(is_string($start)) { - $start = strtotime($start); - } - - $start = date('Y-m-d H:i:s', $start); - - $query['start_date'] = $start; - - return $this; - } - - public function setEnd($end) { - //Argument 1 must be a string - Eden_Eventbrite_Error::get()->argument(1, 'string', 'int'); - - if(is_string($end)) { - $end = strtotime($end); - } - - $end = date('Y-m-d H:i:s', $end); - - $query['end_date'] = $end; - - return $this; - } - - public function setTimezone($zone) { - //Argument 1 must be a string - Eden_Eventbrite_Error::get()->argument(1, 'string'); - - if(strpos($zone, 'GMT') !== 0) { - $zone = 'GMT'.$zone; - } - - $query['timezone'] = $zone; - - return $this; - } - - public function isPublic() { - $query['privacy'] = 1; - - return $this; - } - - public function setUrl($url) { - //Argument 1 must be a string - Eden_Eventbrite_Error::get()->argument(1, 'string'); - - $query['personalized_url'] = $url; - - return $this; - } - - public function setVenue($venue) { - //Argument 1 must be a numeric - Eden_Eventbrite_Error::get()->argument(1, 'numeric'); - - $query['venue'] = $venue; - - return $this; - } - - public function setOrganizer($organizer) { - //Argument 1 must be a numeric - Eden_Eventbrite_Error::get()->argument(1, 'numeric'); - - $query['organizer'] = $organizer; - - return $this; - } - - public function setCapacity($capacity) { - //Argument 1 must be a numeric - Eden_Eventbrite_Error::get()->argument(1, 'numeric'); - - $query['capacity'] = $capacity; - - return $this; - } - - public function setCurrency($currency) { - //Argument 1 must be a string - Eden_Eventbrite_Error::get()->argument(1, 'string'); - - $query['currency'] = $currency; - - return $this; - } - - public function setStatus($status) { - //Argument 1 must be a string - Eden_Eventbrite_Error::get()->argument(1, 'string'); - - $query['status'] = $status; - - return $this; - } - - public function setHeader($html) { - //Argument 1 must be a string - Eden_Eventbrite_Error::get()->argument(1, 'string'); - - $query['custom_header'] = $html; - - return $this; - } - - public function setFooter($html) { - //Argument 1 must be a string - Eden_Eventbrite_Error::get()->argument(1, 'string'); - - $query['custom_footer'] = $html; - - return $this; - } - - public function setBackground($color) { - //Argument 1 must be a string - Eden_Eventbrite_Error::get()->argument(1, 'string'); - - $query['background_color'] = $color; - - return $this; - } - - public function setTextColor($color) { - //Argument 1 must be a string - Eden_Eventbrite_Error::get()->argument(1, 'string'); - - $query['text_color'] = $color; - - return $this; - } - - public function setLinkColor($color) { - //Argument 1 must be a string - Eden_Eventbrite_Error::get()->argument(1, 'string'); - - $query['link_color'] = $color; - - return $this; - } - - public function setTitleColor($color) { - //Argument 1 must be a string - Eden_Eventbrite_Error::get()->argument(1, 'string'); - - $query['title_text_color'] = $color; - - return $this; - } - - public function setBoxBackground($color) { - //Argument 1 must be a string - Eden_Eventbrite_Error::get()->argument(1, 'string'); - - $query['box_background_color'] = $color; - - return $this; - } - - public function setBoxColor($color) { - //Argument 1 must be a string - Eden_Eventbrite_Error::get()->argument(1, 'string'); - - $query['box_text_color'] = $color; - - return $this; - } - - public function setBorderColor($color) { - //Argument 1 must be a string - Eden_Eventbrite_Error::get()->argument(1, 'string'); - - $query['box_border_color'] = $color; - - return $this; - } - - public function setHeaderBackground($color) { - //Argument 1 must be a string - Eden_Eventbrite_Error::get()->argument(1, 'string'); - - $query['box_header_background_color'] = $color; - - return $this; - } - - public function setHeaderColor($color) { - //Argument 1 must be a string - Eden_Eventbrite_Error::get()->argument(1, 'string'); - - $query['box_header_text_color'] = $color; - - return $this; - } - - abstract public function send(); - - /* Protected Methods - -------------------------------*/ - /* Private Methods - -------------------------------*/ -} \ No newline at end of file diff --git a/library/eden/eventbrite/event/new.php b/library/eden/eventbrite/event/new.php deleted file mode 100644 index c688d77..0000000 --- a/library/eden/eventbrite/event/new.php +++ /dev/null @@ -1,328 +0,0 @@ - -/* - * 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. - */ - -/** - * Eventbrite calendar - * - * @package Eden - * @category eventbrite - * @author Christian Blanquera - * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ - */ -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'; - - /* Public Properties - -------------------------------*/ - /* Protected Properties - -------------------------------*/ - protected $_query = array(); - - /* Private Properties - -------------------------------*/ - /* Get - -------------------------------*/ - public static function get($user, $api) { - return self::_getMultiple(__CLASS__, $user, $api); - } - - /* Magic - -------------------------------*/ - /* Public Methods - -------------------------------*/ - public function setId($id) { - //Argument 1 must be numeric - Eden_Eventbrite_Error::get()->argument(1, 'numeric'); - - $query['id'] = $id; - - return $this; - } - - public function setTitle($title) { - //Argument 1 must be a string - Eden_Eventbrite_Error::get()->argument(1, 'string'); - - $query['title'] = $title; - - return $this; - } - - public function setDescription($description) { - //Argument 1 must be a string - Eden_Eventbrite_Error::get()->argument(1, 'string'); - - $query['description'] = $description; - - return $this; - } - - public function setStart($start) { - //Argument 1 must be a string - Eden_Eventbrite_Error::get()->argument(1, 'string', 'int'); - - if(is_string($start)) { - $start = strtotime($start); - } - - $start = date('Y-m-d H:i:s', $start); - - $query['start_date'] = $start; - - return $this; - } - - public function setEnd($end) { - //Argument 1 must be a string - Eden_Eventbrite_Error::get()->argument(1, 'string', 'int'); - - if(is_string($end)) { - $end = strtotime($end); - } - - $end = date('Y-m-d H:i:s', $end); - - $query['end_date'] = $end; - - return $this; - } - - public function setTimezone($zone) { - //Argument 1 must be a string - Eden_Eventbrite_Error::get()->argument(1, 'string'); - - $query['timezone'] = $zone; - - return $this; - } - - public function isPublic() { - $query['privacy'] = 1; - - return $this; - } - - public function isPrivate() { - $query['privacy'] = 0; - - return $this; - } - - public function setUrl($url) { - //Argument 1 must be a string - Eden_Eventbrite_Error::get()->argument(1, 'string'); - - $query['personalized_url'] = $url; - - return $this; - } - - public function setVenue($venue) { - //Argument 1 must be a numeric - Eden_Eventbrite_Error::get()->argument(1, 'numeric'); - - $query['venue_id'] = $venue; - - return $this; - } - - public function setOrganizer($organizer) { - //Argument 1 must be a numeric - Eden_Eventbrite_Error::get()->argument(1, 'numeric'); - - $query['organizer_id'] = $organizer; - - return $this; - } - - public function setCapacity($capacity) { - //Argument 1 must be a numeric - Eden_Eventbrite_Error::get()->argument(1, 'numeric'); - - $query['capacity'] = $capacity; - - return $this; - } - - public function setCurrency($currency) { - //Argument 1 must be a string - Eden_Eventbrite_Error::get()->argument(1, 'string'); - - $query['currency'] = $currency; - - return $this; - } - - public function setStatus($status) { - //Argument 1 must be a string - Eden_Eventbrite_Error::get()->argument(1, 'string'); - - $query['status'] = $status; - - return $this; - } - - public function setHeader($html) { - //Argument 1 must be a string - Eden_Eventbrite_Error::get()->argument(1, 'string'); - - $query['custom_header'] = $html; - - return $this; - } - - public function setFooter($html) { - //Argument 1 must be a string - Eden_Eventbrite_Error::get()->argument(1, 'string'); - - $query['custom_footer'] = $html; - - return $this; - } - - public function setBackground($color) { - //Argument 1 must be a string - Eden_Eventbrite_Error::get()->argument(1, 'string'); - - $query['background_color'] = $color; - - return $this; - } - - public function setTextColor($color) { - //Argument 1 must be a string - Eden_Eventbrite_Error::get()->argument(1, 'string'); - - $query['text_color'] = $color; - - return $this; - } - - public function setLinkColor($color) { - //Argument 1 must be a string - Eden_Eventbrite_Error::get()->argument(1, 'string'); - - $query['link_color'] = $color; - - return $this; - } - - public function setTitleColor($color) { - //Argument 1 must be a string - Eden_Eventbrite_Error::get()->argument(1, 'string'); - - $query['title_text_color'] = $color; - - return $this; - } - - public function setBoxBackground($color) { - //Argument 1 must be a string - Eden_Eventbrite_Error::get()->argument(1, 'string'); - - $query['box_background_color'] = $color; - - return $this; - } - - public function setBoxColor($color) { - //Argument 1 must be a string - Eden_Eventbrite_Error::get()->argument(1, 'string'); - - $query['box_text_color'] = $color; - - return $this; - } - - public function setBorderColor($color) { - //Argument 1 must be a string - Eden_Eventbrite_Error::get()->argument(1, 'string'); - - $query['box_border_color'] = $color; - - return $this; - } - - public function setHeaderBackground($color) { - //Argument 1 must be a string - Eden_Eventbrite_Error::get()->argument(1, 'string'); - - $query['box_header_background_color'] = $color; - - return $this; - } - - public function setHeaderColor($color) { - //Argument 1 must be a string - Eden_Eventbrite_Error::get()->argument(1, 'string'); - - $query['box_header_text_color'] = $color; - - return $this; - } - - public function send() { - if(!isset($this->_query['title'])) { - Eden_Eventbrite_Error::get()->setMessage(Eden_Eventbrite_Error::TITLE_NOT_SET)->trigger(); - } - - if(!isset($this->_query['start_date'])) { - Eden_Eventbrite_Error::get()->setMessage(Eden_Eventbrite_Error::START_NOT_SET)->trigger(); - } - - - if(!isset($this->_query['end_date'])) { - Eden_Eventbrite_Error::get()->setMessage(Eden_Eventbrite_Error::END_NOT_SET)->trigger(); - } - - if(!isset($this->_query['timezone'])) { - Eden_Eventbrite_Error::get()->setMessage(Eden_Eventbrite_Error::ZONE_NOT_SET)->trigger(); - } - - $url = self::URL_NEW; - - if(isset($this->_query['id'])) { - $url = self::URL_UPDATE; - - if(!isset($this->_query['privacy'])) { - Eden_Eventbrite_Error::get()->setMessage(Eden_Eventbrite_Error::PRIVACY_NOT_SET)->trigger(); - } - - if(!isset($this->_query['personalized_url'])) { - Eden_Eventbrite_Error::get()->setMessage(Eden_Eventbrite_Error::URL_NOT_SET)->trigger(); - } - - if(!isset($this->_query['organizer_id'])) { - Eden_Eventbrite_Error::get()->setMessage(Eden_Eventbrite_Error::ORGANIZER_NOT_SET)->trigger(); - } - - if(!isset($this->_query['venue_id'])) { - Eden_Eventbrite_Error::get()->setMessage(Eden_Eventbrite_Error::VENUE_NOT_SET)->trigger(); - } - - if(!isset($this->_query['capacity'])) { - Eden_Eventbrite_Error::get()->setMessage(Eden_Eventbrite_Error::CAPACITY_NOT_SET)->trigger(); - } - - if(!isset($this->_query['currency'])) { - Eden_Eventbrite_Error::get()->setMessage(Eden_Eventbrite_Error::CURRENCY_NOT_SET)->trigger(); - } - } - - return $this->_getJsonResponse($url, $this->_query); - } - - /* Protected Methods - -------------------------------*/ - /* Private Methods - -------------------------------*/ -} \ No newline at end of file diff --git a/site/front.php b/site/front.php index 0ae5f02..3a2d959 100644 --- a/site/front.php +++ b/site/front.php @@ -7,7 +7,7 @@ * distributed with this package. */ -require_once dirname(__FILE__).'/eden.php'; +require_once dirname(__FILE__).'/../library/eden.php'; /** * The starting point of every application call. If you are only diff --git a/site/web/index.php b/site/web/index.php index f29c9cd..cd46c27 100644 --- a/site/web/index.php +++ b/site/web/index.php @@ -23,11 +23,11 @@ /* Set Class Routing -------------------------------*/ -->setClasses('front/config/classes.php') +->setClasses('../front/config/classes.php') /* Set Method Routing -------------------------------*/ -->setMethods('front/config/methods.php') +->setMethods('../front/config/methods.php') /* Set Paths -------------------------------*/ From 4afef3830432c33b6ba13156e54e29074e0332e5 Mon Sep 17 00:00:00 2001 From: cblanquera Date: Thu, 17 Nov 2011 03:27:34 +0000 Subject: [PATCH 007/330] eventbrite git-svn-id: http://svn.openovate.com/edenv2/trunk@7 38ede93f-50f4-44af-b0b3-68ccca78c181 --- library/eden/eventbrite/base.php | 6 +- library/eden/eventbrite/discount.php | 2 +- library/eden/eventbrite/ticket.php | 421 ++++++++-------- library/eden/eventbrite/user.php | 456 +++++++++--------- .../eden/eventbrite/{venues.php => venue.php} | 283 +++++------ 5 files changed, 595 insertions(+), 573 deletions(-) rename library/eden/eventbrite/{venues.php => venue.php} (91%) diff --git a/library/eden/eventbrite/base.php b/library/eden/eventbrite/base.php index ca217fa..b7e70b7 100644 --- a/library/eden/eventbrite/base.php +++ b/library/eden/eventbrite/base.php @@ -38,7 +38,7 @@ public static function get($user, $api) { -------------------------------*/ public function __construct($user, $api) { //argument test - Eden_Google_Error::get() + Eden_Eventbrite_Error::get() ->argument(1, 'string','array') //Argument 1 must be a string or array ->argument(2, 'string'); //Argument 2 must be a string @@ -67,12 +67,12 @@ public function getMeta($key = NULL) { -------------------------------*/ protected function _getJsonResponse($url, array $query = array()) { $response = $this->_getResponse($url, $query); - return json_decode($reponse, true); + return json_decode($response, true); } protected function _getXmlResponse($url, array $query = array()) { $response = $this->_getResponse($url, $query); - return simplexml_load_string($reponse); + return simplexml_load_string($response); } protected function _getResponse($url, array $query = array()) { diff --git a/library/eden/eventbrite/discount.php b/library/eden/eventbrite/discount.php index 2e197d3..43c8171 100644 --- a/library/eden/eventbrite/discount.php +++ b/library/eden/eventbrite/discount.php @@ -15,7 +15,7 @@ * @author Christian Blanquera * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ */ -class Eden_Eventbrite_Event_Discount extends Eden_Eventbrite_Base { +class Eden_Eventbrite_Discount extends Eden_Eventbrite_Base { /* Constants -------------------------------*/ const URL_NEW = 'https://www.eventbrite.com/json/discount_new'; diff --git a/library/eden/eventbrite/ticket.php b/library/eden/eventbrite/ticket.php index f9b13b3..dd0e3fb 100644 --- a/library/eden/eventbrite/ticket.php +++ b/library/eden/eventbrite/ticket.php @@ -1,202 +1,219 @@ - -/* - * 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. - */ - -/** - * Eventbrite new or update discount - * - * @package Eden - * @category eventbrite - * @author Christian Blanquera - * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ - */ -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 - -------------------------------*/ - /* Get - -------------------------------*/ - public static function get($user, $api) { - return self::_getMultiple(__CLASS__, $user, $api); - } - - /* Magic - -------------------------------*/ - /* Public Methods - -------------------------------*/ - public function add($event, $name, $price, $quantity, $description = NULL, $donation = false, $start = NULL, $end = NULL, $fee = false, $min = NULL, $max = NULL) { - //argument test - Eden_Eventbrite_Error::get() - ->argument(1, 'numeric') //Argument 1 must be numeric - ->argument(2, 'string') //Argument 2 must be a string - ->argument(3, 'float') //Argument 3 must a float - ->argument(4, 'int') //Argument 4 must be an integer - ->argument(5, 'string', 'null') //Argument 5 must be a string or null - ->argument(6, 'bool') //Argument 6 must be an integer - ->argument(7, 'string', 'int', 'null') //Argument 7 must be a string, integer or null - ->argument(8, 'string', 'int', 'null') //Argument 8 must be a string, integer or null - ->argument(9, 'bool') //Argument 9 must be an integer - ->argument(10, 'int') //Argument 10 must be an integer - ->argument(11, 'int', 'null') //Argument 11 must be an integer or null - ->argument(12, 'int', 'null'); //Argument 12 must be an integer or null - - $query = array ( - 'event_id' => $event, - 'name' => $name, - 'price' => $price, - 'quantity' => $quantity); - - if($donation){ - $query['is_donation'] = 1; - } - //if description is not empty - if(!is_null($description)){ - //add it to our query - $query['description'] = $description; - } - //if start is not empty - if(!is_null($start)){ - //if start is a string - if(is_string($start)) { - //then convert it to unixcode - $start = strtotime($start); - } - - $start = date('Y-m-d H:i:s', $start); - //add it to our query - $query['start_sales'] = $start; - } - //if end is not empty - if(!is_null($end)){ - //if end is a string - if(is_string($end)){ - //then convert it to unixcode - $end = strtotime($end); - } - - $end = date('Y-m-d H:i:s', $end); - //add it to our query - $query['end_sales'] = $end; - } - - if($fee){ - $query['include_fee'] = 1; - } - //if min is not empty and min is not greater than 0 - if(!is_null($min) && $min > 0){ - //add it to our query - $query['min'] = $min; - } - //if maqx is not empty and max is not greater than equal to min - if(!is_null($max) && $max > 0 && $max >= $min){ - //add it to our query - $query['max'] = $max; - } - return $this->_getJsonResponse(self::URL_NEW, $query); - - } - - public function update($event, $name, $price, $quantity, $description = NULL, $donation = false, $start = NULL, $end = NULL, $fee = false, $min = NULL, $max = NULL, $hide = NULL) { - //argument test - Eden_Eventbrite_Error::get() - ->argument(1, 'numeric') //Argument 1 must be numeric - ->argument(2, 'string') //Argument 2 must be a string - ->argument(3, 'float') //Argument 3 must a float - ->argument(4, 'int') //Argument 4 must be an integer - ->argument(5, 'string', 'null') //Argument 5 must be a string or null - ->argument(6, 'bool') //Argument 6 must be an integer - ->argument(7, 'string', 'int', 'null') //Argument 7 must be a string, integer or null - ->argument(8, 'string', 'int', 'null') //Argument 8 must be a string, integer or null - ->argument(9, 'bool') //Argument 9 must be an integer - ->argument(10, 'int') //Argument 10 must be an integer - ->argument(11, 'int', 'null') //Argument 11 must be an integer or null - ->argument(12, 'int', 'null') //Argument 12 must be an integer or null - ->argument(13, 'bool', 'null'); //Argument 13 must be a boolean or null - - $query = array ( - 'event_id' => $event, - 'name' => $name, - 'price' => $price, - 'quantity' => $quantity); - - if($donation){ - $query['is_donation'] = 1; - } - //if description is not empty - if(!is_null($description)){ - //add it to our query - $query['description'] = $description; - } - //if start is not empty - if(!is_null($start)){ - //if start is a string - if(is_string($start)) { - //then convert it to unixcode - $start = strtotime($start); - } - - $start = date('Y-m-d H:i:s', $start); - //add it to our query - $query['start_sales'] = $start; - } - //if start is not empty - if(!is_null($end)) { - //if start is a string - if(is_string($end)){ - //then convert it to unixcode - $end = strtotime($end); - } - - $end = date('Y-m-d H:i:s', $end); - //add it to our query - $query['end_sales'] = $end; - } - - if($fee) { - $query['include_fee'] = 1; - } - //if min is not empty and min is not greater than 0 - if(!is_null($min) && $min > 0 ){ - //add it to our query - $query['min'] = $min; - } - //if maqx is not empty and max is not greater than equal to min - if(!is_null($max) && $max > 0 && $max >= $min ){ - //add it to our query - $query['max'] = $max; - } - //if the string hide is show - if($hide) { - //hide is equal to yes - $query['hide'] = 'y'; - } else if($hide === false) { - //hide is equal to no - $query['hide'] = 'n'; - } - - return $this->_getJsonResponse(self::URL_UPDATE, $query); - } - - /* Protected Methods - -------------------------------*/ - /* Private Methods - -------------------------------*/ -} - - - + +/* + * 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. + */ + +/** + * Eventbrite new or update discount + * + * @package Eden + * @category eventbrite + * @author Christian Blanquera + * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ + */ +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 + -------------------------------*/ + /* Get + -------------------------------*/ + public static function get($user, $api) { + return self::_getMultiple(__CLASS__, $user, $api); + } + + /* Magic + -------------------------------*/ + /* Public Methods + -------------------------------*/ + public function setEvent($id) { + //Argument 1 must be numeric + Eden_Eventbrite_Error::get()->argument(1, 'numeric'); + $this->_query['event_id'] = $id; + + return $this; + } + + public function setName($name) { + //Argument 1 must be numeric + Eden_Eventbrite_Error::get()->argument(1, 'string'); + $this->_query['name'] = $name; + + return $this; + } + + public function setPrice($price) { + //Argument 1 must be float + Eden_Eventbrite_Error::get()->argument(1, 'float'); + $this->_query['price'] = $price; + + return $this; + } + + public function setQuantity($quantity) { + //Argument 1 must be an integer + Eden_Eventbrite_Error::get()->argument(1, 'int'); + $this->_query['quantity'] = $quantity; + + return $this; + } + + public function setDonation() { + $this->_query['is_donation'] = 1; + + return $this; + } + + public function setDescription($description) { + //Argument 1 must be a string + Eden_Eventbrite_Error::get()->argument(1, 'string'); + $this->_query['description'] = $description; + + return $this; + } + + public function setStart($start) { + //Argument 1 must be an integer or string + Eden_Eventbrite_Error::get()->argument(1, 'int', 'string'); + //if start is a string + if(is_string($start)) { + //then convert it to unixcode + $start = strtotime($start); + } + + $start = date('Y-m-d H:i:s', $start); + //add it to our query + $query['start_sales'] = $start; + + return $this; + } + + public function setEnd($end) { + //Argument 1 must be an integer or string + Eden_Eventbrite_Error::get()->argument(1, 'int', 'string'); + //if start is a string + if(is_string($start)) { + //then convert it to unixcode + $end = strtotime($end); + } + + $end = date('Y-m-d H:i:s', $end); + //add it to our query + $query['end_sales'] = $end; + + return $this; + } + + public function setFee() { + $this->_query['include_fee'] = 1; + + return $this; + } + + public function setMin($quantity) { + //Argument 1 must be an integer + Eden_Eventbrite_Error::get()->argument(1, 'int'); + if($min < 0) { + $min = 0; + } + $this->_query['min'] = $min; + + return $this; + } + + public function setMax($max) { + //Argument 1 must be an integer + Eden_Eventbrite_Error::get()->argument(1, 'int'); + if($max < 1) { + $max = 1; + } + + $this->_query['max'] = $max; + + return $this; + } + + public function setHide($hide) { + //Argument 1 must be a boolean + Eden_Eventbrite_Error::get()->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; + } + + public function add() { + if(!isset($this->_query['event_id'])) { + Eden_Eventbrite_Error::get()->setMessage(Eden_Eventbrite_Error::EVENT_NOT_SET)->trigger(); + } + + if(!isset($this->_query['name'])) { + Eden_Eventbrite_Error::get()->setMessage(Eden_Eventbrite_Error::NAME_NOT_SET)->trigger(); + } + + + if(!isset($this->_query['price'])) { + Eden_Eventbrite_Error::get()->setMessage(Eden_Eventbrite_Error::PRICE_NOT_SET)->trigger(); + } + + if(!isset($this->_query['quantity'])) { + Eden_Eventbrite_Error::get()->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); + } + + public function update() { + if(!isset($this->_query['event_id'])) { + Eden_Eventbrite_Error::get()->setMessage(Eden_Eventbrite_Error::EVENT_NOT_SET)->trigger(); + } + + if(!isset($this->_query['name'])) { + Eden_Eventbrite_Error::get()->setMessage(Eden_Eventbrite_Error::NAME_NOT_SET)->trigger(); + } + + + if(!isset($this->_query['price'])) { + Eden_Eventbrite_Error::get()->setMessage(Eden_Eventbrite_Error::PRICE_NOT_SET)->trigger(); + } + + if(!isset($this->_query['quantity'])) { + Eden_Eventbrite_Error::get()->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 index 5360983..223703f 100644 --- a/library/eden/eventbrite/user.php +++ b/library/eden/eventbrite/user.php @@ -1,229 +1,229 @@ - -/* - * 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. - */ - -/** - * Eventbrite new or update discount - * - * @package Eden - * @category eventbrite - * @author Christian Blanquera - * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ - */ -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 - -------------------------------*/ - /* Get - -------------------------------*/ - public static function get($user, $api) { - return self::_getMultiple(__CLASS__, $user, $api); - } - - /* Magic - -------------------------------*/ - /* Public Methods - -------------------------------*/ - public function getDetail($id = NULL, $email = NULL) { - //argument test - Eden_Eventbrite_Error::get() - ->argument(1, 'int', 'null') //Argument 1 must be a integer 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($email)) { - //add it to query - $query['email'] = $email; - } - - return $this->_getJsonResponse(self::URL_GET, $query); - - } - - public function getEvents($user = NULL, $hide = NULL, $status = NULL, $order = NULL) { - //argument test - Eden_Eventbrite_Error::get() - ->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_NEW, $query); - } - - - public function getOrganizers($user, $pass) { - //argument test - Eden_Eventbrite_Error::get() - ->argument(1, 'string') //Argument 1 must be a string - ->argument(2, 'string'); //Argument 2 must be a string - - $query = array( - 'user' => $user, - 'password' => $pass); - - return $this->_getJsonResponse(self::URL_LIST_ORGANIZERS, $query); - - } - - public function getTicket(){ - return this->_getJsonResponse(self::URL_LIST_TICKETS); - } - - public function getVenue($user, $pass) { - //argument test - Eden_Eventbrite_Error::get() - ->argument(1, 'string') //Argument 1 must be a string - ->argument(2, 'string'); //Argument 2 must be a string - - $query = array( - 'user' => $user, - 'password' => $pass); - - return $this->_getJsonResponse(self::URL_LIST_VENUES, $query); - } - - public function add($user, $pass) { - //argument test - $error = Eden_Eventbrite_Error::get() - ->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); - - } - - public function update($email = NULL, $pass = NULL) { - //argument test - Eden_Eventbrite_Error::get() - ->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 - -------------------------------*/ -} - - - - - - + +/* + * 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. + */ + +/** + * Eventbrite new or update discount + * + * @package Eden + * @category eventbrite + * @author Christian Blanquera + * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ + */ +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 + -------------------------------*/ + /* Get + -------------------------------*/ + public static function get($user, $api) { + return self::_getMultiple(__CLASS__, $user, $api); + } + + /* Magic + -------------------------------*/ + /* Public Methods + -------------------------------*/ + public function getDetail($id = NULL, $email = NULL) { + //argument test + Eden_Eventbrite_Error::get() + ->argument(1, 'int', 'null') //Argument 1 must be a integer 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($email)) { + //add it to query + $query['email'] = $email; + } + + return $this->_getJsonResponse(self::URL_GET, $query); + + } + + public function getEvents($user = NULL, $hide = NULL, $status = NULL, $order = NULL) { + //argument test + Eden_Eventbrite_Error::get() + ->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_NEW, $query); + } + + + public function getOrganizers($user, $pass) { + //argument test + Eden_Eventbrite_Error::get() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'string'); //Argument 2 must be a string + + $query = array( + 'user' => $user, + 'password' => $pass); + + return $this->_getJsonResponse(self::URL_LIST_ORGANIZERS, $query); + + } + + public function getTicket(){ + return this->_getJsonResponse(self::URL_LIST_TICKETS); + } + + public function getVenue($user, $pass) { + //argument test + Eden_Eventbrite_Error::get() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'string'); //Argument 2 must be a string + + $query = array( + 'user' => $user, + 'password' => $pass); + + return $this->_getJsonResponse(self::URL_LIST_VENUES, $query); + } + + public function add($user, $pass) { + //argument test + $error = Eden_Eventbrite_Error::get() + ->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); + + } + + public function update($email = NULL, $pass = NULL) { + //argument test + Eden_Eventbrite_Error::get() + ->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/venues.php b/library/eden/eventbrite/venue.php similarity index 91% rename from library/eden/eventbrite/venues.php rename to library/eden/eventbrite/venue.php index 96d9c74..2e21f6c 100644 --- a/library/eden/eventbrite/venues.php +++ b/library/eden/eventbrite/venue.php @@ -1,139 +1,144 @@ - -/* - * 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. - */ - -/** - * Eventbrite new or update discount - * - * @package Eden - * @category eventbrite - * @author Christian Blanquera - * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ - */ -class Eden_Eventbrite_Venues 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 get($user, $api) { - return self::_getMultiple(__CLASS__, $user, $api); - } - /* Magic - -------------------------------*/ - /* Public Methods - -------------------------------*/ - public function add($organizer, $venue, $country, $region, $address1 = NULL, $address2 = NULL, $city = NULL, $postal = NULL) { - //argument test - Eden_Eventbrite_Error::get() - ->argument(1, 'string') //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 - ->argument(5, 'string', 'null') //Argument must be a string or null - ->argument(6, 'string', 'null') //Argument must be a string or null - ->argument(7, 'string', 'null') //Argument must be a string or null - ->argument(8, 'string', 'null'); //Argument must be a string or null - - $query = array( - 'organizer_id' => $organizer, - 'venue' => $venue, - 'country' => $country_code, - 'region' => $region); - //if address1 is not empty - if(!is_null($address1)) { - //add it to our query - $query['adress'] = > $address1; - } - //if address2 is not empty - if(!is_null($address2)) { - //add it to our query - $query['adress_2'] => $address2; - } - //if city is not empty - if(!is_null($city)) { - //add it to our query - $query['city'] => $city; - } - //if postal is not empty - if(!is_null($postal) { - //add it to our query - $query['postal_code'] => $postal; - } - - return $this->_getJsonResponse(self::URL_NEW, $query); - } - - public function update($id, $venue, $address1 = NULL, $address2 = NULL, $city = NULL, $region = NULL, $postal = NULL, $country = NULL){ - //argument test - Eden_Eventbrite_Error::get() - ->argument(1, 'int') //Argument must be a integer - ->argument(2, 'string') //Argument must be a string - ->argument(3, 'string', 'null') //Argument must be a string or null - ->argument(4, 'string', 'null') //Argument must be a string or null - ->argument(5, 'string', 'null') //Argument must be a string or null - ->argument(6, 'string', 'null') //Argument must be a string or null - ->argument(7, 'string', 'null'); //Argument must be a string or null - - $query = array( - 'id' => $id, - 'venue' => $venue); - //if address1 is not empty - if(!is_null($address1)) { - //add it to our query - $query['adress'] = $address1; - } - //if address2 is not empty - if(!is_null($adress2)) { - //add it to our query - $query['adress_2'] = $address2; - } - //if city is not empty - if(!is_null($city)) { - //add it to our query - $query['city'] = $city; - } - //if postal is not empty - if(!is_null($postal)) { - //add it to our query - $query['postal_code'] = $postal; - ] - //if country is not a empty - if(!is_null($country)) { - //add it to our query - $query['country_code'] = $country; - } - - return $this->getJsonResponse(self::URL_UPDATE, $query); - } - - /* Protected Methods - -------------------------------*/ - /* Private Methods - -------------------------------*/ -} - - - - - - - - - - + +/* + * 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. + */ + +/** + * Eventbrite new or update discount + * + * @package Eden + * @category eventbrite + * @author Christian Blanquera + * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ + */ +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 get($user, $api) { + return self::_getMultiple(__CLASS__, $user, $api); + } + /* Magic + -------------------------------*/ + /* Public Methods + -------------------------------*/ + public function add($organizer, $venue, $country, $region, $address1 = NULL, $address2 = NULL, $city = NULL, $postal = NULL) { + //argument test + Eden_Eventbrite_Error::get() + ->argument(1, 'string') //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 + ->argument(5, 'string', 'null') //Argument must be a string or null + ->argument(6, 'string', 'null') //Argument must be a string or null + ->argument(7, 'string', 'null') //Argument must be a string or null + ->argument(8, 'string', 'null'); //Argument must be a string or null + + $query = array( + 'organizer_id' => $organizer, + 'venue' => $venue, + 'country' => $country_code, + 'region' => $region); + + //if address1 is not empty + if(!is_null($address1)) { + //add it to our query + $query['adress'] = $address1; + } + + //if address2 is not empty + if(!is_null($address2)) { + //add it to our query + $query['adress_2'] = $address2; + } + + //if city is not empty + if(!is_null($city)) { + //add it to our query + $query['city'] = $city; + } + + //if postal is not empty + if(!is_null($postal)) { + //add it to our query + $query['postal_code'] = $postal; + } + + return $this->_getJsonResponse(self::URL_NEW, $query); + } + + public function update($id, $venue, $address1 = NULL, $address2 = NULL, $city = NULL, $region = NULL, $postal = NULL, $country = NULL){ + //argument test + Eden_Eventbrite_Error::get() + ->argument(1, 'int') //Argument must be a integer + ->argument(2, 'string') //Argument must be a string + ->argument(3, 'string', 'null') //Argument must be a string or null + ->argument(4, 'string', 'null') //Argument must be a string or null + ->argument(5, 'string', 'null') //Argument must be a string or null + ->argument(6, 'string', 'null') //Argument must be a string or null + ->argument(7, 'string', 'null'); //Argument must be a string or null + + $query = array( + 'id' => $id, + 'venue' => $venue); + //if address1 is not empty + if(!is_null($address1)) { + //add it to our query + $query['adress'] = $address1; + } + //if address2 is not empty + if(!is_null($adress2)) { + //add it to our query + $query['adress_2'] = $address2; + } + //if city is not empty + if(!is_null($city)) { + //add it to our query + $query['city'] = $city; + } + //if postal is not empty + if(!is_null($postal)) { + //add it to our query + $query['postal_code'] = $postal; + } + + //if country is not a empty + if(!is_null($country)) { + //add it to our query + $query['country_code'] = $country; + } + + return $this->getJsonResponse(self::URL_UPDATE, $query); + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} + + + + + + + + + + From fdb9654456b9ad5575af6a6f1eee704d9d30a4e8 Mon Sep 17 00:00:00 2001 From: cblanquera Date: Fri, 18 Nov 2011 04:49:03 +0000 Subject: [PATCH 008/330] Add twitter folder(timelines.php, tweets.php, search.php, directmessage.php, friends.php) git-svn-id: http://svn.openovate.com/edenv2/trunk@8 38ede93f-50f4-44af-b0b3-68ccca78c181 --- library/eden/twitter/base.php | 0 library/eden/twitter/directmessage.php | 232 ++++++++++ library/eden/twitter/friends.php | 414 +++++++++++++++++ library/eden/twitter/search.php | 149 ++++++ library/eden/twitter/timelines.php | 614 +++++++++++++++++++++++++ library/eden/twitter/tweets.php | 365 +++++++++++++++ 6 files changed, 1774 insertions(+) create mode 100644 library/eden/twitter/base.php create mode 100644 library/eden/twitter/directmessage.php create mode 100644 library/eden/twitter/friends.php create mode 100644 library/eden/twitter/search.php create mode 100644 library/eden/twitter/timelines.php create mode 100644 library/eden/twitter/tweets.php diff --git a/library/eden/twitter/base.php b/library/eden/twitter/base.php new file mode 100644 index 0000000..e69de29 diff --git a/library/eden/twitter/directmessage.php b/library/eden/twitter/directmessage.php new file mode 100644 index 0000000..be28c76 --- /dev/null +++ b/library/eden/twitter/directmessage.php @@ -0,0 +1,232 @@ + +/* + * 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. + */ + +/** + * Eventbrite new or update discount + * + * @package Eden + * @category eventbrite + * @author Christian Blanquera + * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ + */ +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/1270516771.json'; + const URL_NEW_MESSAGE = 'httsp://api.twitter.com/1/direct_messages/new.format '; + const URL_SHOW_MESSAGE = 'https://api.twitter.com/1/direct_messages/show/:id.format '; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_query = array(); + + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function get($user, $api) { + return self::_getMultiple(__CLASS__, $user, $api); + } + /* Magic + -------------------------------*/ + /* Public Methods + -------------------------------*/ + /** + * Returns the 20 most recent direct messages + * sent to the authenticating user. + * + * @param since is integer + * @param max is integer + * @param count is integer + * @param page is integer + * @param entities is boolean + * @param skip is boolean + * @return $this + */ + public function directMessage($since = NULL, $max = NULL $count = NULL,, $page = NULL, $entities = false, $skip = false) { + //Argument Test + Eden_Twitter_Error::get() + ->argument(1, 'int') //Argument 1 must be an integer + ->argument(2, 'int') //Argument 2 must be an integer + ->argument(3, 'int') //Argument 3 must be an integer + ->argument(4, 'int') //Argument 4 must be an integer + ->argument(5, 'bool') //Argument 5 must be an boolean + ->argument(6, 'bool'); //Argument 6 must be a boolean + + $query = array(); + + //if it is not empty a + if(!is_null($since)) { + //lets put it in query + $query['since_id'] = $since; + } + //if it is not empty and max is not less than count + if(!is_null(max) && $max <= $count) { + //lets put it in query + $query['max_id'] = $max; + } + //if it is not empty and its less than equal to 100 + if(!is_null($count) && $count <= 200) { + //lets put it in query + $query['count'] = $count; + } + //if it is not empty + if(!is_null($page)) { + //lets put it in query + $query['page'] = $page; + } + //if entities + if($entities) { + $query['include_entities'] = 1; + } + //if replies + if($skip) { + $query['skip_status'] = 1; + } + return $this->_getResponse(self::URL_DIRECT_MESSAGE, $query); + } + /** + * Returns the 20 most recent direct messages + * sent by the authenticating user. + * + * @param since is integer + * @param max is integer + * @param count is integer + * @param page is integer + * @param entities is boolean + * @return $this + */ + public function sentMessage($since = NULL, $max = NULL $count = NULL,, $page = NULL, $entities = false) { + //Argument Test + Eden_Twitter_Error::get() + ->argument(1, 'int') //Argument 1 must be an integer + ->argument(2, 'int') //Argument 2 must be an integer + ->argument(3, 'int') //Argument 3 must be an integer + ->argument(4, 'int') //Argument 4 must be an integer + ->argument(5, 'bool'); //Argument 5 must be an boolean + + $query = array(); + + //if it is not empty a + if(!is_null($since)) { + //lets put it in query + $query['since_id'] = $since; + } + //if it is not empty and max is not less than count + if(!is_null(max) && $max <= $count) { + //lets put it in query + $query['max_id'] = $max; + } + //if it is not empty and its less than equal to 100 + if(!is_null($count) && $count <= 200) { + //lets put it in query + $query['count'] = $count; + } + //if it is not empty + if(!is_null($page)) { + //lets put it in query + $query['page'] = $page; + } + //if entities + if($entities) { + $query['include_entities'] = 1; + } + + return $this->_getResponse(self::URL_SENT_MESSAGE, $query); + } + /** + * Destroys the direct message specified in the required + * ID parameter. The authenticating user must be the + * recipient of the specified direct message. + * + * @param since is integer + * @param max is integer + * @param count is integer + * @param page is integer + * @param entities is boolean + * @return $this + */ + public function removeMessage($id, $entities = false) { + //Argument Test + Eden_Twitter_Error::get() + ->argument(1, 'int') //Argument 1 must be an integer + ->argument(2, 'bool'); //Argument 2 must be an boolean + + $query = array('id' => $id); + + //if entities + if($entities) { + $query['include_entities'] = 1; + } + + return $this->_getResponse(self::URL_REMOVE_MESSAGE, $query); + } + /** + * Sends a new direct message to the specified + * user from the authenticating user. + * + * @param text is string + * @param user is integer + * @param name is string + * @param wrap is boolean + * @return $this + */ + public function newMessage($text, $user = NULL, $name = NULL, $wrap = false) { + //Argument Test + Eden_Twitter_Error::get() + ->argument(1, 'string') //Argument 1 must be an string + ->argument(2, 'int') //Argument 2 must be an integer + ->argument(2, 'string') //Argument 2 must be an string + ->argument(2, 'bool'); //Argument 2 must be an boolean + + $query = array('text' => $text); + //if it is not empty + if(!is_null($user)) { + //lets put it in query + $query['user_id'] = $user; + } + //if it is not empty + if(!is_null($name)) { + //lets put it in query + $query['screen_name'] = $name; + } + //if wrap + if($wrap) { + $query['wrap_links'] = 1; + } + + return $this->_getResponse(self::URL_NEW_MESSAGE, $query); + } + /** + * Returns a single direct message, + * specified by an id parameter. + * + * @param id is integer + * @return $this + */ + public function showMessage($id) { + //Argument Test + Eden_Twitter_Error::get() + ->argument(1, 'id') //Argument 1 must be an integer + + $query = array('id' => $id); + + return $this->_getResponse(self::URL_SHOW_MESSAGE, $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..1139399 --- /dev/null +++ b/library/eden/twitter/friends.php @@ -0,0 +1,414 @@ + +/* + * 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. + */ + +/** + * Eventbrite new or update discount + * + * @package Eden + * @category eventbrite + * @author Christian Blanquera + * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ + */ +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 = '____________________________________'; + const URL_UNFOLLOW_FRIENDS = '____________________________________'; + const URL_LOOKUP_FRIENDS = 'https://api.twitter.com/1/friendships/lookup.json'; + const URL_UPDATE = '____________________________________'; + const URL_NO_RETWEETS_IDS = 'https://api.twitter.com/1/friendships/no_retweet_ids.json'; + + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_query = array(); + + protected static $_validName = array('twitterapi','twitter'); + + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function get($user, $api) { + return self::_getMultiple(__CLASS__, $user, $api); + } + /* Magic + -------------------------------*/ + /* Public Methods + -------------------------------*/ + /** + * Returns an array of numeric IDs for every + * user following the specified user. + * + * @param id is integer + * @param name is string + * @param cursor is integer + * @param stringify is boolean + * @return $this + */ + public function followers($id = NULL, $name = NULL, $cursor = NULL, $stringify = false) { + //Argument Test + Eden_Twitter_Error::get() + ->argument(1, 'int') //Argument 1 must be an integer + ->argument(2, 'string') //Argument 2 must be an string + ->argument(3, 'int') //Argument 3 must be an integer + ->argument(4, 'bool'); //Argument 4 must be an boolean + + $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['string_name'] = $name; + } + //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 id is integer + * @param name is string + * @param cursor is integer + * @param stringify is boolean + * @return $this + */ + public function friends($id = NULL, $name = NULL, $cursor = NULL, $stringify = false) { + //Argument Test + Eden_Twitter_Error::get() + ->argument(1, 'int') //Argument 1 must be an integer + ->argument(2, 'string') //Argument 2 must be an string + ->argument(3, 'int') //Argument 3 must be an integer + ->argument(4, 'bool'); //Argument 4 must be an boolean + + $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['string_name'] = $name; + } + //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_FRIENDS, $query); + } + /** + * Test for the existence of friendship between two users. + * + * @param userA is integer + * @param userB is string + * @param nameA is integer + * @param nameB is boolean + * @return $this + */ + public function friendsExist($userA = NULL, $userB = NULL, $nameA = NULL, $nameB = false) { + //Argument Test + Eden_Twitter_Error::get() + ->argument(1, 'int') //Argument 1 must be an integer + ->argument(2, 'int') //Argument 2 must be an integer + ->argument(3, 'string') //Argument 3 must be an string + ->argument(4, 'string'); //Argument 4 must be an string + + $query = array(); + //if it is not empty + if(!is_null($userA)) { + //lets put it in query + $query['user_id_a'] = $userA; + } + //if it is not empty + if(!is_null($userB)) { + //lets put it in query + $query['user_id_b'] = $userB; + } + //if it is not empty + if(!is_null($nameA)) { + //lets put it in query + $query['screen_name_a'] = $nameA; + } + //if it is not empty + if(!is_null($nameB)) { + //lets put it in query + $query['screen_name_b'] = $nameB; + } + + return $this->_getResponse(self::URL_FRIENDS_EXIST, $query); + } + /** + * Returns an array of numeric IDs for every user + * who has a pending request to follow the authenticating user. + * + * @param cursor is integer + * @param stringify is boolean + * @return $this + */ + public function incomingFriends($cursor = NULL, $stringify = false) { + //Argument Test + Eden_Twitter_Error::get() + ->argument(1, 'int') //Argument 1 must be an integer + ->argument(2, 'boolean'); //Argument 2 must be an integer + + $query = array(); + //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_INCOMING_FRIENDS, $query); + } + /** + * Returns an array of numeric IDs for every protected user + * for whom the authenticating user has a pending follow request. + * + * @param cursor is integer + * @param stringify is boolean + * @return $this + */ + public function outgoingFriends($cursor = NULL, $stringify = false) { + //Argument Test + Eden_Twitter_Error::get() + ->argument(1, 'int') //Argument 1 must be an integer + ->argument(2, 'boolean'); //Argument 2 must be an integer + + $query = array(); + //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_OUTGOING_FRIENDS, $query); + } + /** + * Returns detailed information about the relationship between two users. + * + * @param cursor is integer + * @param stringify is boolean + * @return $this + */ + public function outgoingFriends($id = NULL, $name = NULL, $target = NULL, $screen = NULL) { + //Argument Test + Eden_Twitter_Error::get() + ->argument(1, 'string') //Argument 1 must be an string + ->argument(2, 'int') //Argument 2 must be an integer + ->argument(3, 'string') //Argument 3 must be an string + ->argument(4, 'int'); //Argument 4 must be an integer + + + + + $query = array(); + //if it is not empty + if(!is_null($id)) { + //lets put it in query + $query['source_id'] = $id; + } + //if it is not empty + if(!is_null($name)) { + //lets put it in query + $query['source_screen_name'] = $name; + }//if it is not empty + if(!is_null($target)) { + //lets put it in query + $query['target_id'] = $target; + } + //if it is not empty + if(!is_null($screen)) { + //lets put it in query + $query['target_screen_name'] = $screen; + } + + return $this->_getResponse(self::URL_OUTGOING_FRIENDS, $query); + } + /** + * Allows the authenticating users to follow the user specified in the ID parameter.. + * + * @param name is string + * @param id is integer + * @param follow is boolean + * @return $this + */ + public function followFriends($name = NULL, $id = NULL, $follow = false) { + //Argument Test + Eden_Twitter_Error::get() + ->argument(1, 'string') //Argument 1 must be an string + ->argument(2, 'int') //Argument 2 must be an integer + ->argument(3, 'boolean'); //Argument 3 must be an boolean + + + + $query = array(); + + //if it is not empty + if(!is_null($name)) { + //lets put it in query + $query['screen_name'] = $name; + } + //if it is not empty + if(!is_null($id)) { + //lets put it in query + $query['user_id'] = $id; + } + //if follow + if($follow) { + $query['follow'] = $follow; + } + + return $this->_getResponse(self::URL_FOLLOW_FRIENDS, $query); + } + /** + * Allows the authenticating users to unfollow the user specified in the ID parameter. + * + * @param id is integer + * @param name is string + * @param entities is boolean + * @return $this + */ + public function unfollowFriends($id = NULL, $name = NULL, $entities = false) { + //Argument Test + Eden_Twitter_Error::get() + ->argument(1, 'int') //Argument 1 must be an string + ->argument(2, 'string') //Argument 2 must be an integer + ->argument(3, 'boolean'); //Argument 3 must be an boolean + + + + $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; + } + //if entities + if($entities) { + $query['include_entities'] = $entities; + } + + return $this->_getResponse(self::URL_UNFOLLOW_FRIENDS, $query); + } + /** + * Returns the relationship of the authenticating user to + * the comma separated list of up to 100 screen_names or user_ids provided. + * + * @param id is integer + * @param name is string + * @param entities is boolean + * @return $this + */ + public function unfollowFriends($id = NULL, $name = NULL, $entities = false) { + //Argument Test + Eden_Twitter_Error::get() + ->argument(1, 'int') //Argument 1 must be an string + ->argument(2, 'string') //Argument 2 must be an integer + ->argument(3, 'boolean'); //Argument 3 must be an boolean + + + + $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; + } + //if entities + if($entities) { + $query['include_entities'] = $entities; + } + + return $this->_getResponse(self::URL_UNFOLLOW_FRIENDS, $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..89f761a --- /dev/null +++ b/library/eden/twitter/search.php @@ -0,0 +1,149 @@ + +/* + * 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. + */ + +/** + * Eventbrite new or update discount + * + * @package Eden + * @category eventbrite + * @author Christian Blanquera + * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ + */ +class Eden_Twitter_Search extends Eden_Twitter_Base { + /* Constants + -------------------------------*/ + const URL_SEARCH = 'http://search.twitter.com/search.json'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_query = array(); + + protected static $_validResult = array('mixed', 'recent', 'popular'); + + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function get($user, $api) { + return self::_getMultiple(__CLASS__, $user, $api); + } + /* Magic + -------------------------------*/ + /* Public Methods + -------------------------------*/ + /** + * Returns tweets that match a specified query + * + * @param id is integer. + * @param count is integer. + * @param page is integer + * @return $this + */ + public function search($q, $callback = NULL, $geocode = NULL, $lang = NULL, $locale = NULL, $page = NULL, $result = NULL, $rpp = NULL, $show = false, $until = NULL, $since = NULL, $entities = NULL) { + //Argument Test + Eden_Twitter_Error::get() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'string') //Argument 2 must be a string + ->argument(3, 'float') //Argument 3 must be a flaot + ->argument(4, 'string') //Argument 4 must be a string + ->argument(5, 'string') //Argument 5 must be a string + ->argument(6, 'int') //Argument 6 must be an integer + ->argument(7, 'string') //Argument 7 must be as string + ->argument(8, 'string') //Argument 8 must be as integer + ->argument(9, 'boolean') //Argument 9 must be a boolean + ->argument(10, 'string') //Argument 10 must be a string + ->argument(11, 'string') //Argument 11 must be a string + ->argument(12, 'boolean'); //Argument 12 must be a boolean + + $query = array('q' => $q); + //if it is not empty + if(!is_null($callback)) { + //lets put it in query + $query['callback'] = $callback; + } + //if it is not empty + if(!is_null($geocode)) { + //lets put it in query + $query['geocode'] = $geocode; + } + //if it is not empty + if(!is_null($lang)) { + //lets put it in query + $query['lang'] = $lang; + } + //if it is not empty + if(!is_null($locale)) { + //lets put it in query + $query['locale'] = $locale; + } + //if it is not empty + if(!is_null($page)) { + //lets put it in query + $query['page'] = $count; + } + //if there is a result + if(!is_null($result)) { + //if result is a string + if(is_string($result)) { + //lets make it an array + $result = explode(',', $result); + } + //at this point result will be an array + $results = array(); + //for each result + foreach($result as $event) { + //if this result is a valid result + if(in_array($result, $this->_validResult)) { + //lets add this to our valid resulr list + $results[] = $event; + } + } + //if we have at least one valid result + if(!empty($results)) { + //lets make results into a string + $result = implode(',', $result); + //and add to query + $query['result_type'] = $result; + } + + } + //if rpp is not empty and less than equal to 100 + if(!is_null($rpp) && $rpp <= 100) { + //lets put in in query + $query['rpp'] = $rpp; + } + //if show + if($show) { + $query['show_user'] = 1; + } + //if it is not empty + if(!is_null($until)) { + $until = date('Y-m-d', $until); + //add it to our query + $query['until'] = $until; + } + //if it is not empty and + if(!is_null($since)) { + //lets put it in query + $query['since_id'] = $since; + } + //if entities + if($entities) { + $query['include_entities'] = 1; + } + + return $this->_getResponse(self::URL_SEARCH, $query); + } + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/twitter/timelines.php b/library/eden/twitter/timelines.php new file mode 100644 index 0000000..98341cd --- /dev/null +++ b/library/eden/twitter/timelines.php @@ -0,0 +1,614 @@ + +/* + * 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. + */ + +/** + * Eventbrite new or update discount + * + * @package Eden + * @category eventbrite + * @author Christian Blanquera + * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ + */ +class Eden_Twitter_Timelines 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 $_query = array(); + + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function get($user, $api) { + return self::_getMultiple(__CLASS__, $user, $api); + } + /* Magic + -------------------------------*/ + /* Public Methods + -------------------------------*/ + /** + * 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. + * + * @param count is integer + * @param since is integer + * @param max is integer + * @param page is integer + * @param trim is boolean + * @param include is boolean + * @param entities is boolean + * @param replies is boolean + * @param detail is boolean + * @return $this + */ + public function getTimeline($count = NULL, $since = NULL, $max = NULL, $page = NULL, $trim = false, $include = false, $entities = false, $replies = false, $detail =false) { + //Argument Test + Eden_Twitter_Error::get() + ->argument(1, 'int') //Argument 1 must be an integer + ->argument(2, 'int') //Argument 2 must be an integer + ->argument(3, 'int') //Argument 3 must be an integer + ->argument(4, 'int') //Argument 4 must be an integer + ->argument(5, 'bool') //Argument 5 must be an boolean + ->argument(6, 'bool') //Argument 6 must be a boolean + ->argument(7, 'bool') //Argument 7 must be an boolean + ->argument(8, 'bool') //Argument 8 must be an boolean + ->argument(9, 'bool'); //Argument 9 must be an boolean + + $query = array(); + //if it is not empty and its less than equal to 100 + if(!is_null($count) && $count <= 200) { + //lets put it in query + $query['count'] = $count; + } + //if it is not empty a + if(!is_null($since)) { + //lets put it in query + $query['since_id'] = $since; + } + //if it is not empty and max is not less than count + if(!is_null(max) && $max <= $count) { + //lets put it in query + $query['max_id'] = $max; + } + //if it is not empty + if(!is_null($page)) { + //lets put it in query + $query['page'] = $page; + } + //if trim + if($trim) { + $query['trim_user'] = 1; + } + //if include + if($include) { + $query['include_rts'] = 1; + } + //if entities + if($entities) { + $query['include_entities'] = 1; + } + //if replies + if($replies) { + $query['exclude_replies'] = 1; + } + //if datails + if($detail) { + $query['contributor_details'] = 1; + } + + return $this->_getResponse(self::URL_TIMELINE, $query); + } + /** + * Returns the 20 most recent mentions (status containing @username) for the authenticating user + * + * @param count is integer + * @param since is integer + * @param max is integer + * @param page is integer + * @param trim is boolean + * @param include is boolean + * @param entities is boolean + * @param detail is boolean + * @return $this + */ + public function getMention($count = NULL, $since = NULL, $max = NULL, $page = NULL, $trim = false, $include = false, $entities = false, $detail =false) { + //Argument Test + Eden_Twitter_Error::get() + ->argument(1, 'int') //Argument 1 must be an integer + ->argument(2, 'int') //Argument 2 must be an integer + ->argument(3, 'int') //Argument 3 must be an integer + ->argument(4, 'int') //Argument 4 must be an integer + ->argument(5, 'bool') //Argument 5 must be an boolean + ->argument(6, 'bool') //Argument 6 must be a boolean + ->argument(7, 'bool') //Argument 7 must be an boolean + ->argument(8, 'bool'); //Argument 8 must be an boolean + + $query = array(); + + //if it is not empty and + if(!is_null($count) && $count <= 200) { + //lets put it in query + $query['count'] = $count; + } + //if it is not empty and + if(!is_null($since)) { + //lets put it in query + $query['since_id'] = $since; + } + //if it is not empty and max is not less than count + if(!is_null(max) && $max <= $count) { + //lets put it in query + $query['max_id'] = $max; + } + //if it is not empty and + if(!is_null($page)) { + //lets put it in query + $query['page'] = $page; + } + //if trim + if($trim) { + $query['trim_user'] = 1; + } + //if include + if($include) { + $query['include_rts'] = 1; + } + //if entities + if($entities) { + $query['include_entities'] = 1; + } + //if datails + if($detail) { + $query['contributor_details'] = 1; + } + + return $this->_getResponse(self::URL_MENTION, $query); + } + /** + * Returns the 20 most recent statuses, including + * retweets if they exist, from non-protected users. + * + * @param trim is boolean + * @param entities is boolean + * @return $this + */ + public function getPublic($trim = false, $entities = false) { + //Argument Test + Eden_Twitter_Error::get() + ->argument(1, 'bool') //Argument 1 must be an boolean + ->argument(2, 'bool'); //Argument 2 must be an boolean + + $query = array(); + //if trim + if($trim) { + $query['trim_user'] = 1; + } + //if entities + if($entities) { + $query['include_entities'] = 1; + } + + return $this->_getResponse(self::URL_PUBLIC, $query); + } + /** + * Returns the 20 most recent retweets posted by the authenticating user. + * + * @param count is integer + * @param since is integer + * @param max is integer + * @param page is integer + * @param trim is boolean + * @param entities is boolean + * @return $this + */ + public function getBy($count = NULL, $since = NULL, $max = NULL, $page = NULL, $trim = false, $entities = false) { + //Argument Test + Eden_Twitter_Error::get() + ->argument(1, 'int') //Argument 1 must be an integer + ->argument(2, 'int') //Argument 2 must be an integer + ->argument(3, 'int') //Argument 3 must be an integer + ->argument(4, 'int') //Argument 4 must be an integer + ->argument(5, 'bool') //Argument 5 must be an boolean + ->argument(6, 'bool'); //Argument 6 must be a boolean + + $query = array(); + + //if it is not empty and + if(!is_null($count) && $count <= 200) { + //lets put it in query + $query['count'] = $count; + } + //if it is not empty and + if(!is_null($since)) { + //lets put it in query + $query['since_id'] = $since; + } + //if it is not empty and max is not less than count + if(!is_null(max) && $max <= $count) { + //lets put it in query + $query['max_id'] = $max; + } + //if it is not empty and + if(!is_null($page)) { + //lets put it in query + $query['page'] = $page; + } + //if trim + if($trim) { + $query['trim_user'] = 1; + } + //if entities + if($entities) { + $query['include_entities'] = 1; + } + + return $this->_getResponse(self::URL_BY_ME, $query); + } + /** + * Returns the 20 most recent retweets posted by users the authenticating user follow + * + * @param count is integer + * @param since is integer + * @param max is integer + * @param page is integer + * @param trim is boolean + * @param entities is boolean + * @return $this + */ + public function getTo($count = NULL, $since = NULL, $max = NULL, $page = NULL, $trim = false, $entities = false) { + //Argument Test + Eden_Twitter_Error::get() + ->argument(1, 'int') //Argument 1 must be an integer + ->argument(2, 'int') //Argument 2 must be an integer + ->argument(3, 'int') //Argument 3 must be an integer + ->argument(4, 'int') //Argument 4 must be an integer + ->argument(5, 'bool') //Argument 5 must be an boolean + ->argument(6, 'bool'); //Argument 6 must be a boolean + + $query = array(); + + //if it is not empty and + if(!is_null($count) && $count <= 200) { + //lets put it in query + $query['count'] = $count; + } + //if it is not empty and + if(!is_null($since)) { + //lets put it in query + $query['since_id'] = $since; + } + //if it is not empty and max is not less than count + if(!is_null(max) && $max <= $count) { + //lets put it in query + $query['max_id'] = $max; + } + //if it is not empty and + if(!is_null($page)) { + //lets put it in query + $query['page'] = $page; + } + //if trim + if($trim) { + $query['trim_user'] = 1; + } + //if entities + if($entities) { + $query['include_entities'] = 1; + } + + return $this->_getResponse(self::URL_TO_ME, $query); + } + /** + * Returns the 20 most recent tweets of the authenticated user that have been retweeted by others. + * + * @param count is integer + * @param since is integer + * @param max is integer + * @param page is integer + * @param trim is boolean + * @param entities is boolean + * @return $this + */ + public function getOf($count = NULL, $since = NULL, $max = NULL, $page = NULL, $trim = false, $entities = false) { + //Argument Test + Eden_Twitter_Error::get() + ->argument(1, 'int') //Argument 1 must be an integer + ->argument(2, 'int') //Argument 2 must be an integer + ->argument(3, 'int') //Argument 3 must be an integer + ->argument(4, 'int') //Argument 4 must be an integer + ->argument(5, 'bool') //Argument 5 must be an boolean + ->argument(6, 'bool'); //Argument 6 must be a boolean + + $query = array(); + + //if it is not empty and + if(!is_null($count) && $count <= 200) { + //lets put it in query + $query['count'] = $count; + } + //if it is not empty and + if(!is_null($since)) { + //lets put it in query + $query['since_id'] = $since; + } + //if it is not empty and max is not less than count + if(!is_null(max) && $max <= $count) { + //lets put it in query + $query['max_id'] = $max; + } + //if it is not empty and + if(!is_null($page)) { + //lets put it in query + $query['page'] = $page; + } + //if trim + if($trim) { + $query['trim_user'] = 1; + } + //if entities + if($entities) { + $query['include_entities'] = 1; + } + + return $this->_getResponse(self::URL_OF_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 id is a integer + * @param name is a string + * @param since is integer + * @param count is integer + * @param max is integer + * @param page is integer + * @param trim is boolean + * @param include is boolean + * @param entities is boolean + * @param replies is boolean + * @param detail is boolean + * @return $this + */ + public function getUser($id = NULL, $name = NULL, $since = NULL, $count = NULL,$max = NULL, $page = NULL, $trim = false, $include = false, $entities = false, $replies = false, $detail =false) { + //Argument Test + Eden_Twitter_Error::get() + ->argument(1, 'int') //Argument 1 must be an integer + ->argument(2, 'string') //Argument 2 must be an string + ->argument(3, 'int') //Argument 3 must be an integer + ->argument(4, 'int') //Argument 4 must be an integer + ->argument(5, 'int') //Argument 5 must be an boolean + ->argument(6, 'int') //Argument 6 must be a boolean + ->argument(7, 'bool') //Argument 7 must be an boolean + ->argument(8, 'bool') //Argument 8 must be an boolean + ->argument(9, 'bool') //Argument 9 must be an boolean + ->argument(10, 'bool') //Argument 10 must be an boolean + ->argument(11, 'bool'); //Argument 11 must be an boolean + + $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; + } + //if it is not empty + if(!is_null($since)) { + //lets put it in query + $query['since_id'] = $since; + //if it is not empty and + if(!is_null($count) && $count <= 200) { + //lets put it in query + $query['count'] = $count; + } + } + //if it is not empty and max is not less than count + if(!is_null(max) && $max <= $count) { + //lets put it in query + $query['max_id'] = $max; + } + //if it is not empty and + if(!is_null($page)) { + //lets put it in query + $query['page'] = $page; + } + //if trim + if($trim) { + $query['trim_user'] = 1; + } + //if include + if($include) { + $query['include_rts'] = 1; + } + //if entities + if($entities) { + $query['include_entities'] = 1; + } + //if replies + if($replies) { + $query['exclude_replies'] = 1; + } + //if datails + if($detail) { + $query['contributor_details'] = 1; + } + + return $this->_getResponse(self::URL_USER, $query); + } + /** + * Returns the 20 most recent retweets posted + * by users the specified user follows. + * + * @param name is a string + * @param id is a integer or string + * @param since is integer + * @param count is integer + * @param max is integer + * @param page is integer + * @param trim is boolean + * @param include is boolean + * @param entities is boolean + * @param replies is boolean + * @param detail is boolean + * @return $this + */ + public function getToUser($name = NULL, $id = NULL, $since = NULL, $count = NULL,$max = NULL, $page = NULL, $trim = false, $entities = false) { + //Argument Test + Eden_Twitter_Error::get() + ->argument(1, 'string') //Argument 1 must be an string + ->argument(2, 'string', 'int') //Argument 2 must be an string or integer + ->argument(3, 'int') //Argument 3 must be an integer + ->argument(4, 'int') //Argument 4 must be an integer + ->argument(5, 'int') //Argument 5 must be an boolean + ->argument(6, 'int') //Argument 6 must be a boolean + ->argument(7, 'bool') //Argument 7 must be an boolean + ->argument(8, 'bool') //Argument 8 must be an boolean + ->argument(9, 'bool') //Argument 9 must be an boolean + ->argument(10, 'bool') //Argument 10 must be an boolean + ->argument(11, 'bool'); //Argument 11 must be an boolean + + $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; + } + //if it is not empty + if(!is_null($since)) { + //lets put it in query + $query['since_id'] = $since; + //if it is not empty and + if(!is_null($count) && $count <= 200) { + //lets put it in query + $query['count'] = $count; + } + //if it is not empty and max is not less than count + if(!is_null(max) && $max <= $count) { + //lets put it in query + $query['max_id'] = $max; + } + //if it is not empty and + if(!is_null($page)) { + //lets put it in query + $query['page'] = $page; + } + //if trim + if($trim) { + $query['trim_user'] = 1; + } + //if entities + if($entities) { + $query['include_entities'] = 1; + } + return $this->_getResponse(self::URL_TO_USER, $query); + } + /** + * Returns the 20 most recent retweets posted by + * the specified user. The user is specified using + * the user_id or screen_name parameters + * + * @param name is a string + * @param id is a integer or string + * @param since is integer + * @param count is integer + * @param max is integer + * @param page is integer + * @param trim is boolean + * @param include is boolean + * @param entities is boolean + * @param replies is boolean + * @param detail is boolean + * @return $this + */ + public function getByUser($name = NULL, $id = NULL, $since = NULL, $count = NULL,$max = NULL, $page = NULL, $trim = false, $entities = false) { + //Argument Test + Eden_Twitter_Error::get() + ->argument(1, 'string') //Argument 1 must be an string + ->argument(2, 'string', 'int') //Argument 2 must be an string or integer + ->argument(3, 'int') //Argument 3 must be an integer + ->argument(4, 'int') //Argument 4 must be an integer + ->argument(5, 'int') //Argument 5 must be an boolean + ->argument(6, 'int') //Argument 6 must be a boolean + ->argument(7, 'bool') //Argument 7 must be an boolean + ->argument(8, 'bool') //Argument 8 must be an boolean + ->argument(9, 'bool') //Argument 9 must be an boolean + ->argument(10, 'bool') //Argument 10 must be an boolean + ->argument(11, 'bool'); //Argument 11 must be an boolean + + $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; + } + //if it is not empty + if(!is_null($since)) { + //lets put it in query + $query['since_id'] = $since; + //if it is not empty and + if(!is_null($count) && $count <= 200) { + //lets put it in query + $query['count'] = $count; + } + //if it is not empty and max is not less than count + if(!is_null(max) && $max <= $count) { + //lets put it in query + $query['max_id'] = $max; + } + //if it is not empty and + if(!is_null($page)) { + //lets put it in query + $query['page'] = $page; + } + //if trim + if($trim) { + $query['trim_user'] = 1; + } + //if entities + if($entities) { + $query['include_entities'] = 1; + } + return $this->_getResponse(self::URL_BY_USER, $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..1cc9034 --- /dev/null +++ b/library/eden/twitter/tweets.php @@ -0,0 +1,365 @@ + +/* + * 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. + */ + +/** + * Eventbrite new or update discount + * + * @package Eden + * @category eventbrite + * @author Christian Blanquera + * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ + */ +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/%s/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/%s.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 $_query = array(); + + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function get($user, $api) { + return self::_getMultiple(__CLASS__, $user, $api); + } + /* Magic + -------------------------------*/ + /* Public Methods + -------------------------------*/ + /** + * Show user objects of up to 100 members + * who retweeted the status. + * + * @param id is integer. + * @param count is integer. + * @param page is integer + * @return $this + */ + public function getWhoRetweeted($id, $count = NULL, $page, = NULL) { + //Argument Test + Eden_Twitter_Error::get() + ->argument(1, 'int') //Argument 1 must be an integer + ->argument(2, 'int') //Argument 2 must be an integer + ->argument(3, 'int'); //Argument 3 must be an integer + + $query = array('id' => $id); + //if it is not empty and not up to a maximum of 100 + if(!is_null($count) && $count <= 100) { + //lets put it in query + $query['count'] = $count; + } + //if it is not empty + if(!is_null($page)) { + //lets put it in query + $query['page'] = $count; + } + + return $this->_getResponse(self::URL_WHO_RETWEETED, $query); + } + /** + * Show user ids of up to 100 users who retweeted the status. + * + * @param id is integer. + * @param count is integer. + * @param page is integer + * @param stringify is boolean + * @return $this + */ + public function getWhoRetweetedIds($id, $count = NULL, $page = NULL, stringify = false) { + //Argument Test + Eden_Twitter_Error::get() + ->argument(1, 'int') //Argument 1 must be an integer + ->argument(2, 'int') //Argument 2 must be an integer + ->argument(3, 'int') //Argument 3 must be an integer + ->argument(4, 'bool'); //Argument 4 must be a boolean + + $query = array('id' => $id); + //if it is not empty and not up to a maximum of 100 + if(!is_null($count) && $count <= 100) { + //lets put it in query + $query['count'] = $count; + } + //if it is not empty + if(!is_null($page)) { + //lets put it in query + $query['page'] = $count; + } + //if stringify + if($stringify) { + + $query['stringify_ids'] = 1; + } + + return $this->_getResponse(self::URL_GET_WHO_RETWEETED_IDS, $query); + } + /** + * Returns up to 100 of the first retweets of a given tweet. + * + * @param id is integer + * @param count is integer + * @param trim is boolean + * @param entities is boolean + * @return $this + */ + public function getRetweets($id, $count = NULL, $trim = false, $entities = false) { + //Argument Test + Eden_Twitter_Error::get() + ->argument(1, 'int') //Argument 1 must be an integer + ->argument(2, 'int') //Argument 2 must be an integer + ->argument(3, 'bool') //Argument 3 must be an boolean + ->argument(4, 'bool'); //Argument 4 must be an boolean + + $query = array('id' => $id); + //if count is not empty and less than equal to 100 + if(!is_null($coutn) && $count <= 100) { + //Lets put it in query + $query['count'] = $count; + } + //if trim + if($trim) { + $query['trim_user'] = 1; + } + //if entities + if($entities) { + $query['include_entities'] = 1; + } + + return $this->_getResponse(self::URL_GET_RETWEETS, $query); + } + /** + * Returns a single status, specified by the id parameter below. + * The status's author will be returned inline. + * + * @param id is integer + * @param trim is boolean + * @param entities is boolean + * @return $this + */ + public function getList($id, $trim = false, $entities = false) { + //Argument Test + Eden_Twitter_Error::get() + ->argument(1, 'int') //Argument 1 must be an integer + ->argument(2, 'bool') //Argument 2 must be an boolean + ->argument(3, 'bool'); //Argument 3 must be an boolean + + $query = array('id' => $id); + //if trim + if($trim) { + $query['trim_user'] = 1; + } + //if entities + if($entities) { + $query['include_entities'] = 1; + } + + return $this->_getResponse(self::URL_GET_LIST, $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 id is integer + * @param trim is boolean + * @param entities is boolean + * @return $this + */ + public function remove($id, $entities = false, $trim = false) { + //Argument Test + Eden_Twitter_Error::get() + ->argument(1, 'int') //Argument 1 must be an integer + ->argument(2, 'bool') //Argument 2 must be an boolean + ->argument(3, 'bool'); //Argument 3 must be an boolean + + $query = array('id' => $id); + //if entities + if($entities) { + $query['include_entities'] = 1; + } + //if trim + if($trim) { + $query['trim_user'] = 1; + } + + return $this->_getResponse(self::URL_REMOVE, $query); + } + /** + * Retweets a tweet. Returns the original tweet + * with retweet details embedded + * + * @param id is integer + * @param trim is boolean + * @param entities is boolean + * @return $this + */ + public function retweet($id, $entities = false, $trim = false) { + //Argument Test + Eden_Twitter_Error::get() + ->argument(1, 'int') //Argument 1 must be an integer + ->argument(2, 'bool') //Argument 2 must be an boolean + ->argument(3, 'bool'); //Argument 3 must be an boolean + + $query = array('id' => $id); + //if entities + if($entities) { + $query['include_entities'] = 1; + } + //if trim + if($trim) { + $query['trim_user'] = 1; + } + + return $this->_getResponse(self::URL_RETWEET, $query); + } + /** + * Updates the authenticating user's status, + * also known as tweeting. + * + * @param status is integer + * @param reply is string + * @param lat is float + * @param long is float + * @param place is string or integer + * @param display is boolean + * @param trim is boolean + * @param entities is boolean + * @param wrap is boolean + * @return $this + */ + public function update($status, $reply = NULL, $lat = NULL, $long = NULL, $place = NULL, $display = NULL, $trim = FALSE, $entities = FALSE, $wrap = FALSE) { + //Argument Test + Eden_Twitter_Error::get() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'string') //Argument 2 must be a string + ->argument(3, 'float') //Argument 3 must be a float + ->argument(4, 'float') //Argument 4 must be a float + ->argument(5, 'string', 'int') //Argument 5 must be an string or integer + ->argument(6, 'boolean') //Argument 6 must be an boolean + ->argument(7, 'boolean') //Argument 7 must be an boolean + ->argument(8, 'boolean'); //Argument 8 must be an boolean + + + $query = array('status' => $status); + //if reply is not empty + if(!is_null($reply)) { + //lets put it in query + $query['in_reply_to_status_id '] = $reply; + } + //if reply is not empty + if(!is_null($lat) && $lat >= -90.0 && $lat <= +90.0) { + //lets put it in query + $query ['lat'] = $lat; + } + //if reply is not empty + if(!is_null($long) && $long >= -180.0 && $lat <= +180.0) { + //lets put it in query + $query ['long'] = $long; + } + //if reply is not empty + if(!is_null($place)) { + //lets put it in query + $query['place_id '] = $place + } + //if entities + if($display) { + $query['display_coordinates'] = 1; + } + //if trim + if($trim) { + $query['trim_user'] = 1; + } + //if entities + if($entities) { + $query['include_entities'] = 1; + } + //if wrap + if($wrap) { + $query['wrap_links'] = 1; + } + + return $this->_getResponse(self::URL_UPDATE, $query); + } + /** + * Updates the authenticating user's status, + * also known as tweeting. + * + * @param status is integer + * @param reply is string + * @param lat is float + * @param long is float + * @param place is string or integer + * @param display is boolean + * @param trim is boolean + * @param entities is boolean + * @param wrap is boolean + * @return $this + */ + public function updateMedia($status, $media, $sensitive = NULL, $id = NULL, $lat = NULL, $long = NULL, $place = NULL, $display = NULL) { + //Argument Test + Eden_Twitter_Error::get() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'string') //Argument 2 must be a string + ->argument(3, 'boolean') //Argument 3 must be a boolean + ->argument(4, 'string') //Argument 4 must be an string + ->argument(5, 'boolean') //Argument 5 must be an boolena + ->argument(6, 'boolean') //Argument 6 must be an boolean + ->argument(7, 'boolean') //Argument 7 must be an boolean + ->argument(8, 'boolean'); //Argument 8 must be an boolean + + + $query = array('status' => $status, 'media[]' => $media); + //if sensitive + if($sensitive) { + $query['possibly_sensitive'] = 1; + } + //if reply is not empty + if(!is_null($id)) { + //lets put it in query + $query['in_reply_to_status_id'] = $id; + //if reply is not empty + if(!is_null($lat) && $lat >= -90.0 && $lat <= +90.0) { + //lets put it in query + $query ['lat'] = $lat; + } + //if reply is not empty + if(!is_null($long) && $long >= -180.0 && $lat <= +180.0) { + //lets put it in query + $query ['long'] = $long; + } + //if reply is not empty + if(!is_null($place)) { + //lets put it in query + $query['place_id '] = $place; + } + //if entities + if($display) { + $query['display_coordinates'] = 1; + } + + return $this->_getResponse(self::URL_UPDATE_MEDIA, $query); + } + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ + + +} \ No newline at end of file From b24b538b18970cec0a3f2115db40c0461d694a34 Mon Sep 17 00:00:00 2001 From: cblanquera Date: Mon, 21 Nov 2011 03:39:18 +0000 Subject: [PATCH 009/330] twitter git-svn-id: http://svn.openovate.com/edenv2/trunk@9 38ede93f-50f4-44af-b0b3-68ccca78c181 --- library/eden/twitter/base.php | 218 +++++++++++++++++++++++++++++++++ library/eden/twitter/oauth.php | 44 +++++++ 2 files changed, 262 insertions(+) create mode 100644 library/eden/twitter/oauth.php diff --git a/library/eden/twitter/base.php b/library/eden/twitter/base.php index e69de29..35a9a88 100644 --- a/library/eden/twitter/base.php +++ b/library/eden/twitter/base.php @@ -0,0 +1,218 @@ + +/* + * 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. + */ + +/** + * Twitter oauth + * + * @package Eden + * @category twitter + * @author Christian Blanquera + * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ + */ +class Eden_Twitter_Base extends Eden_Oauth_Base { + /* Constants + -------------------------------*/ + const REQUEST_URL = 'http://api.twitter.com/oauth/request_token'; + const AUTHORIZE_URL = 'http://api.twitter.com/oauth/authorize'; + + const SECRET_KEY = 'twitter_token_secret'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_key = NULL; + protected $_secret = NULL; + + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + /* Magic + -------------------------------*/ + public function __construct($key, $secret) { + //argument test + Eden_Twitter_Error::get() + ->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 URL used for login. + * + * @param string + * @return string + */ + public function getLoginUrl($redirect) { + //Argument 1 must be a string + Eden_Google_Error::get()->argument(1, 'string'); + + //get the token + $token = Eden_Oauth::get() + ->getConsumer(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; + } + + /** + * Returns the access token + * + * @param string + * @param string + * @return string + */ + public function getAccessToken($token, $secret) { + //argument test + Eden_Google_Error::get() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'string'); //Argument 2 must be a string + + return Eden_Oauth::get() + ->getConsumer(self::ACCESS_URL, $this->_key, $this->_secret) + ->useAuthorization() + ->setMethodToPost() + ->setToken($token, $secret) + ->setSignatureToHmacSha1() + ->getQueryResponse(); + } + + public function setAccessToken($token, $secret) { + $this->_accessToken = $token; + $this->_accessSecret = $secret; + + return $this; + } + + + /** + * Returns the meta of the last call + * + * @return array + */ + public function getMeta($key = NULL) { + Eden_Google_Error::get()->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::get() + ->getConsumer($url, $this->_key, $this->_secret) + ->setHeaders(self::VERSION_HEADER, self::GDATA_VERSION) + ->setToken($this->_accessToken, $this->_accessSecret) + ->setSignatureToHmacSha1(); + + $response = $rest->getJsonResponse($query); + + $this->_meta = $rest->getMeta(); + + return $response; + } + + /** + * Returns the token from the server + * + * @param array + * @return array + */ + protected function _post($url, $query = array()) { + $headers = array(); + $headers[] = Eden_Oauth_Consumer::POST_HEADER; + + $rest = Eden_Oauth::get() + ->getConsumer($url, $this->_key, $this->_secret) + ->setToken($this->_accessToken, $this->_accessSecret) + ->setSignatureToHmacSha1(); + + //get the authorization parameters as an array + $signature = $rest->getSignature(); + $authorization = $rest->getAuthorization($signature, false); + $authorization = $this->_buildQuery($authorization); + + if(is_array($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::get() + ->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['authorization'] = $authorization; + $this->_meta['headers'] = $headers; + $this->_meta['query'] = $query; + + return $response; + } + + /* 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..5dc401b --- /dev/null +++ b/library/eden/twitter/oauth.php @@ -0,0 +1,44 @@ + +/* + * 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. + */ + +/** + * Twitter oauth + * + * @package Eden + * @category google + * @author Christian Blanquera + * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ + */ +class Eden_Twitter_Oauth extends Eden_Twitter_Base { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_key = NULL; + protected $_secret = NULL; + + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function get($key, $secret) { + return self::_getMultiple(__CLASS__, $key, $secret); + } + + /* Magic + -------------------------------*/ + /* Public Methods + -------------------------------*/ + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file From 40b8255f365826a796f89c7f6af6f0fafae75311 Mon Sep 17 00:00:00 2001 From: sy Date: Fri, 25 Nov 2011 02:11:22 +0000 Subject: [PATCH 010/330] twitter git-svn-id: http://svn.openovate.com/edenv2/trunk@10 38ede93f-50f4-44af-b0b3-68ccca78c181 --- library/eden/twitter/directmessage.php | 83 ++++----- library/eden/twitter/friends.php | 247 ++++++++++++++++--------- library/eden/twitter/search.php | 34 ++-- library/eden/twitter/timelines.php | 215 ++++++++++----------- library/eden/twitter/tweets.php | 50 ++--- 5 files changed, 349 insertions(+), 280 deletions(-) diff --git a/library/eden/twitter/directmessage.php b/library/eden/twitter/directmessage.php index be28c76..b7ee6f4 100644 --- a/library/eden/twitter/directmessage.php +++ b/library/eden/twitter/directmessage.php @@ -20,9 +20,9 @@ class Eden_Twitter_Directmessage extends Eden_Twitter_Base { -------------------------------*/ 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/1270516771.json'; - const URL_NEW_MESSAGE = 'httsp://api.twitter.com/1/direct_messages/new.format '; - const URL_SHOW_MESSAGE = 'https://api.twitter.com/1/direct_messages/show/:id.format '; + 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 -------------------------------*/ @@ -53,13 +53,13 @@ public static function get($user, $api) { * @param skip is boolean * @return $this */ - public function directMessage($since = NULL, $max = NULL $count = NULL,, $page = NULL, $entities = false, $skip = false) { + public function getList($since = NULL, $max = NULL, $count = NULL, $page = NULL, $entities = false, $skip = false) { //Argument Test Eden_Twitter_Error::get() - ->argument(1, 'int') //Argument 1 must be an integer - ->argument(2, 'int') //Argument 2 must be an integer - ->argument(3, 'int') //Argument 3 must be an integer - ->argument(4, 'int') //Argument 4 must be an integer + ->argument(1, 'int', 'null') //Argument 1 must be an integer + ->argument(2, 'int', 'null') //Argument 2 must be an integer + ->argument(3, 'int', 'null') //Argument 3 must be an integer + ->argument(4, 'int', 'null') //Argument 4 must be an integer ->argument(5, 'bool') //Argument 5 must be an boolean ->argument(6, 'bool'); //Argument 6 must be a boolean @@ -71,7 +71,7 @@ public function directMessage($since = NULL, $max = NULL $count = NULL,, $page = $query['since_id'] = $since; } //if it is not empty and max is not less than count - if(!is_null(max) && $max <= $count) { + if(!is_null($max) && $max <= $count) { //lets put it in query $query['max_id'] = $max; } @@ -106,13 +106,13 @@ public function directMessage($since = NULL, $max = NULL $count = NULL,, $page = * @param entities is boolean * @return $this */ - public function sentMessage($since = NULL, $max = NULL $count = NULL,, $page = NULL, $entities = false) { + public function getSent($since = NULL, $max = NULL, $count = NULL, $page = NULL, $entities = false) { //Argument Test Eden_Twitter_Error::get() - ->argument(1, 'int') //Argument 1 must be an integer - ->argument(2, 'int') //Argument 2 must be an integer - ->argument(3, 'int') //Argument 3 must be an integer - ->argument(4, 'int') //Argument 4 must be an integer + ->argument(1, 'int', 'null') //Argument 1 must be an integer + ->argument(2, 'int', 'null') //Argument 2 must be an integer + ->argument(3, 'int', 'null') //Argument 3 must be an integer + ->argument(4, 'int', 'null') //Argument 4 must be an integer ->argument(5, 'bool'); //Argument 5 must be an boolean $query = array(); @@ -123,7 +123,7 @@ public function sentMessage($since = NULL, $max = NULL $count = NULL,, $page = N $query['since_id'] = $since; } //if it is not empty and max is not less than count - if(!is_null(max) && $max <= $count) { + if(!is_null($max) && $max <= $count) { //lets put it in query $query['max_id'] = $max; } @@ -149,27 +149,23 @@ public function sentMessage($since = NULL, $max = NULL $count = NULL,, $page = N * ID parameter. The authenticating user must be the * recipient of the specified direct message. * - * @param since is integer - * @param max is integer - * @param count is integer - * @param page is integer + * @param id is integer * @param entities is boolean * @return $this */ - public function removeMessage($id, $entities = false) { + public function remove($id, $entities = false) { //Argument Test Eden_Twitter_Error::get() ->argument(1, 'int') //Argument 1 must be an integer - ->argument(2, 'bool'); //Argument 2 must be an boolean - - $query = array('id' => $id); + ->argument(2, 'bool'); //Argument 2 must be a boolean + $query = array(); //if entities if($entities) { $query['include_entities'] = 1; } - - return $this->_getResponse(self::URL_REMOVE_MESSAGE, $query); + $url = sprintf(self::URL_REMOVE_MESSAGE, $id); + return $this->_post($url,$query); } /** * Sends a new direct message to the specified @@ -177,35 +173,31 @@ public function removeMessage($id, $entities = false) { * * @param text is string * @param user is integer - * @param name is string * @param wrap is boolean * @return $this */ - public function newMessage($text, $user = NULL, $name = NULL, $wrap = false) { + public function add($text, $user = NULL, $wrap = false) { //Argument Test Eden_Twitter_Error::get() - ->argument(1, 'string') //Argument 1 must be an string - ->argument(2, 'int') //Argument 2 must be an integer - ->argument(2, 'string') //Argument 2 must be an string - ->argument(2, 'bool'); //Argument 2 must be an boolean + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'int','string','null') //Argument 2 must be an integer or string + ->argument(3, 'bool'); //Argument 2 must be a boolean $query = array('text' => $text); //if it is not empty if(!is_null($user)) { - //lets put it in query - $query['user_id'] = $user; - } - //if it is not empty - if(!is_null($name)) { - //lets put it in query - $query['screen_name'] = $name; + //if it is integer + if(is_int($user)) { + $query['user_id'] = $user; + } else { + $query['screen_name'] = $user; + } } //if wrap if($wrap) { $query['wrap_links'] = 1; } - - return $this->_getResponse(self::URL_NEW_MESSAGE, $query); + return $this->_post(self::URL_NEW_MESSAGE, $query); } /** * Returns a single direct message, @@ -214,17 +206,14 @@ public function newMessage($text, $user = NULL, $name = NULL, $wrap = false) { * @param id is integer * @return $this */ - public function showMessage($id) { + public function getDetail($id) { //Argument Test Eden_Twitter_Error::get() - ->argument(1, 'id') //Argument 1 must be an integer - - $query = array('id' => $id); - - return $this->_getResponse(self::URL_SHOW_MESSAGE, $query); + ->argument(1, 'int'); //Argument 1 must be an integer + $url = sprintf(self::URL_SHOW_MESSAGE,$id); + return $this->_getResponse($url); } - /* Protected Methods -------------------------------*/ /* Private Methods diff --git a/library/eden/twitter/friends.php b/library/eden/twitter/friends.php index 1139399..9b12ffd 100644 --- a/library/eden/twitter/friends.php +++ b/library/eden/twitter/friends.php @@ -1,3 +1,4 @@ + /* * This file is part of the Eden package. @@ -24,10 +25,10 @@ class Eden_Twitter_Friends extends Eden_Twitter_Base { 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 = '____________________________________'; - const URL_UNFOLLOW_FRIENDS = '____________________________________'; + const URL_FOLLOW_FRIENDS = 'http://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 = '____________________________________'; + 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'; @@ -60,24 +61,26 @@ public static function get($user, $api) { * @param stringify is boolean * @return $this */ - public function followers($id = NULL, $name = NULL, $cursor = NULL, $stringify = false) { + public function getFollowers($id = NULL, $cursor = NULL, $stringify = false) { //Argument Test Eden_Twitter_Error::get() - ->argument(1, 'int') //Argument 1 must be an integer - ->argument(2, 'string') //Argument 2 must be an string - ->argument(3, 'int') //Argument 3 must be an integer - ->argument(4, 'bool'); //Argument 4 must be an boolean + ->argument(1, 'int', 'string') //Argument 1 must be an integer + ->argument(2, 'int') //Argument 2 must be an integer + ->argument(3, 'bool'); //Argument 3 must be an boolean $query = array(); //if it is not empty if(!is_null($id)) { - //lets put it in query + //if it is integer + if(is_int($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['string_name'] = $name; + } + //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)) { @@ -100,26 +103,23 @@ public function followers($id = NULL, $name = NULL, $cursor = NULL, $stringify = * @param stringify is boolean * @return $this */ - public function friends($id = NULL, $name = NULL, $cursor = NULL, $stringify = false) { + public function getFriends($id = NULL, $cursor = NULL, $stringify = false) { //Argument Test Eden_Twitter_Error::get() - ->argument(1, 'int') //Argument 1 must be an integer - ->argument(2, 'string') //Argument 2 must be an string - ->argument(3, 'int') //Argument 3 must be an integer - ->argument(4, 'bool'); //Argument 4 must be an boolean + ->argument(1, 'int','string') //Argument 1 must be an integer + ->argument(2, 'int') //Argument 3 must be an integer + ->argument(3, 'bool'); //Argument 4 must be an boolean $query = array(); //if it is not empty if(!is_null($id)) { + if(is_int($id)) { + $query['user_id'] = $id; + } else { //lets put it in query - $query['user_id'] = $id; - } - //if it is not empty - if(!is_null($name)) { - //lets put it in query - $query['string_name'] = $name; + $query['screen_name'] = $id; + } } - //if it is not empty if(!is_null($cursor)) { //lets put it in query $query['cursor'] = $cursor; @@ -139,36 +139,33 @@ public function friends($id = NULL, $name = NULL, $cursor = NULL, $stringify = f * @param nameB is boolean * @return $this */ - public function friendsExist($userA = NULL, $userB = NULL, $nameA = NULL, $nameB = false) { + public function friendsExist($userA = NULL, $userB = NULL) { //Argument Test Eden_Twitter_Error::get() - ->argument(1, 'int') //Argument 1 must be an integer - ->argument(2, 'int') //Argument 2 must be an integer - ->argument(3, 'string') //Argument 3 must be an string - ->argument(4, 'string'); //Argument 4 must be an string + ->argument(1, 'string','int') //Argument 1 must be an integer + ->argument(2, 'string','int'); //Argument 2 must be an integer $query = array(); //if it is not empty if(!is_null($userA)) { + + if(is_int($userA)) { //lets put it in query - $query['user_id_a'] = $userA; + $query['user_id_a'] = $userA; + } else { + $query['screen_name_a'] = $userA; + } } //if it is not empty if(!is_null($userB)) { - //lets put it in query - $query['user_id_b'] = $userB; - } - //if it is not empty - if(!is_null($nameA)) { - //lets put it in query - $query['screen_name_a'] = $nameA; - } - //if it is not empty - if(!is_null($nameB)) { - //lets put it in query - $query['screen_name_b'] = $nameB; - } - + + if(is_int($userB)) { + //lets put it in query + $query['user_id_b'] = $userB; + } else { + $query['screen_name_b'] = $userB; + } + } return $this->_getResponse(self::URL_FRIENDS_EXIST, $query); } /** @@ -225,46 +222,50 @@ public function outgoingFriends($cursor = NULL, $stringify = false) { return $this->_getResponse(self::URL_OUTGOING_FRIENDS, $query); } - /** + /** * Returns detailed information about the relationship between two users. * * @param cursor is integer * @param stringify is boolean * @return $this */ - public function outgoingFriends($id = NULL, $name = NULL, $target = NULL, $screen = NULL) { + public function getDetails($id = NULL, $target = NULL) { //Argument Test Eden_Twitter_Error::get() - ->argument(1, 'string') //Argument 1 must be an string - ->argument(2, 'int') //Argument 2 must be an integer - ->argument(3, 'string') //Argument 3 must be an string - ->argument(4, 'int'); //Argument 4 must be an integer - - - + ->argument(1, 'string','int') //Argument 1 must be an string + ->argument(2, 'string','int'); //Argument 2 must be an string $query = array(); //if it is not empty if(!is_null($id)) { - //lets put it in query - $query['source_id'] = $id; + + if(is_int($id)) { + //lets put it in query + $query['source_id'] = $id; + } + + if(is_string($id)) { + //lets put it in query + $query['source_screen_name'] = $id; + } } //if it is not empty - if(!is_null($name)) { - //lets put it in query - $query['source_screen_name'] = $name; - }//if it is not empty if(!is_null($target)) { - //lets put it in query - $query['target_id'] = $target; - } - //if it is not empty - if(!is_null($screen)) { - //lets put it in query - $query['target_screen_name'] = $screen; + //if it is integer + if(is_int($target)) { + //lets put it in query + $query['target_id'] = $target; + } + //if it is string + if(is_string($target)) { + //lets put it in query + $query['target_screen_name'] = $target; + } } - return $this->_getResponse(self::URL_OUTGOING_FRIENDS, $query); + + + return $this->_getResponse(self::URL_SHOW_FRIENDS, $query); } /** * Allows the authenticating users to follow the user specified in the ID parameter.. @@ -300,7 +301,7 @@ public function followFriends($name = NULL, $id = NULL, $follow = false) { $query['follow'] = $follow; } - return $this->_getResponse(self::URL_FOLLOW_FRIENDS, $query); + return $this->_post(self::URL_FOLLOW_FRIENDS, $query); } /** * Allows the authenticating users to unfollow the user specified in the ID parameter. @@ -310,11 +311,11 @@ public function followFriends($name = NULL, $id = NULL, $follow = false) { * @param entities is boolean * @return $this */ - public function unfollowFriends($id = NULL, $name = NULL, $entities = false) { + public function unfollowFriends($name = NULL, $id = NULL, $entities = false) { //Argument Test Eden_Twitter_Error::get() - ->argument(1, 'int') //Argument 1 must be an string - ->argument(2, 'string') //Argument 2 must be an integer + ->argument(1, 'string') //Argument 1 must be an string + ->argument(2, 'int') //Argument 2 must be an integer ->argument(3, 'boolean'); //Argument 3 must be an boolean @@ -336,45 +337,109 @@ public function unfollowFriends($id = NULL, $name = NULL, $entities = false) { $query['include_entities'] = $entities; } - return $this->_getResponse(self::URL_UNFOLLOW_FRIENDS, $query); + return $this->_post(self::URL_UNFOLLOW_FRIENDS, $query); } /** * Returns the relationship of the authenticating user to * the comma separated list of up to 100 screen_names or user_ids provided. * - * @param id is integer * @param name is string - * @param entities is boolean + * @param id is integer * @return $this */ - public function unfollowFriends($id = NULL, $name = NULL, $entities = false) { + public function lookupFriends($id = NULL) { //Argument Test Eden_Twitter_Error::get() - ->argument(1, 'int') //Argument 1 must be an string - ->argument(2, 'string') //Argument 2 must be an integer - ->argument(3, 'boolean'); //Argument 3 must be an boolean - + ->argument(1, 'int', 'string'); //Argument 1 must be an string + $query = array(); + //if it is not empty + if(!is_null($id)) { + //if id is integer + if(is_int($id)) { + $id = explode(',', $id); + //lets put it in query + $query['user_id'] = $id; + } + //if id is string + if(is_string($id)) { + $id = explode(',', $id); + //at this poit id will be an array + $id = array(); + $query['screen_name'] = $id; + + + //lets put it in query + //$query['screen_name'] = $id; + } + } + + return $this->_getResponse(self::URL_LOOKUP_FRIENDS, $query); + } + /** + * Allows one to enable or disable retweets and device notifications from the specified user. + * + * @param id is string or integer + * @param device is boolean + * @param retweets is boolean + * @return $this + */ + public function update($id = NULL, $device = NULL, $retweets = NULL) { + //Argument Test + Eden_Twitter_Error::get() + ->argument(1, 'string','int') //Argument 1 must be a string or integer + ->argument(2, 'boolean') //Argument 2 must be a boolean + ->argument(3, 'boolean'); //Argument 3 must be a boolean $query = array(); //if it is not empty if(!is_null($id)) { + //if id is string + if(is_string($id)) { + //lets put it in query + $query['screen_name'] = $id; + } + //if id is integer + if(is_int($id)) { + //lets put it in query + $query['user_id'] = $id; + } + } + + if(!is_null($device)) { //lets put it in query - $query['user_id'] = $id; + $query['device'] = $device; } - //if it is not empty - if(!is_null($name)) { + + if(!is_null($retweets)) { //lets put it in query - $query['screen_name'] = $name; + $query['retweets'] = $dretweets; } - //if entities - if($entities) { - $query['include_entities'] = $entities; + + return $this->_post(self::URL_UPDATE, $query); + } + /** + * Returns an array of user_ids that the currently authenticated user does not want to see retweets from. + * + * @param stringify is string + * @return $this + */ + public function getNoRetweets($stringify = NULL) { + //Argument Test + Eden_Twitter_Error::get() + ->argument(1, 'boolean'); //Argument 1 must be an boolean + + $query = array(); + + if(!is_null($stringify)) { + //lets put it in query + $query['stringify_ids'] = $stringify; } - return $this->_getResponse(self::URL_UNFOLLOW_FRIENDS, $query); + return $this->_getResponse(self::URL_NO_RETWEETS_IDS, $query); } + @@ -411,4 +476,6 @@ public function unfollowFriends($id = NULL, $name = NULL, $entities = false) { -------------------------------*/ /* Private Methods -------------------------------*/ -} \ No newline at end of file +} + +?> \ No newline at end of file diff --git a/library/eden/twitter/search.php b/library/eden/twitter/search.php index 89f761a..56a5ad1 100644 --- a/library/eden/twitter/search.php +++ b/library/eden/twitter/search.php @@ -42,25 +42,34 @@ public static function get($user, $api) { /** * Returns tweets that match a specified query * - * @param id is integer. - * @param count is integer. + * @param q is integer or string. + * @param callback is string. + * @param geocode is float. + * @param lang is string. + * @param locale is string. * @param page is integer + * @param result is string. + * @param rpp is string. + * @param show is boolean + * @param until is string + * @param since is string + * @param entities is boolean * @return $this */ public function search($q, $callback = NULL, $geocode = NULL, $lang = NULL, $locale = NULL, $page = NULL, $result = NULL, $rpp = NULL, $show = false, $until = NULL, $since = NULL, $entities = NULL) { //Argument Test Eden_Twitter_Error::get() - ->argument(1, 'string') //Argument 1 must be a string - ->argument(2, 'string') //Argument 2 must be a string - ->argument(3, 'float') //Argument 3 must be a flaot - ->argument(4, 'string') //Argument 4 must be a string - ->argument(5, 'string') //Argument 5 must be a string - ->argument(6, 'int') //Argument 6 must be an integer - ->argument(7, 'string') //Argument 7 must be as string - ->argument(8, 'string') //Argument 8 must be as integer + ->argument(1, 'string','int') //Argument 1 must be a string or int + ->argument(2, 'string', 'null') //Argument 2 must be a string + ->argument(3, 'float', 'null') //Argument 3 must be a flaot + ->argument(4, 'string', 'null') //Argument 4 must be a string + ->argument(5, 'string', 'null') //Argument 5 must be a string + ->argument(6, 'int', 'null') //Argument 6 must be an integer + ->argument(7, 'string', 'null') //Argument 7 must be a string + ->argument(8, 'string', 'null') //Argument 8 must be an integer ->argument(9, 'boolean') //Argument 9 must be a boolean - ->argument(10, 'string') //Argument 10 must be a string - ->argument(11, 'string') //Argument 11 must be a string + ->argument(10, 'string', 'null') //Argument 10 must be a string + ->argument(11, 'string', 'null') //Argument 11 must be a string ->argument(12, 'boolean'); //Argument 12 must be a boolean $query = array('q' => $q); @@ -113,7 +122,6 @@ public function search($q, $callback = NULL, $geocode = NULL, $lang = NULL, $loc //and add to query $query['result_type'] = $result; } - } //if rpp is not empty and less than equal to 100 if(!is_null($rpp) && $rpp <= 100) { diff --git a/library/eden/twitter/timelines.php b/library/eden/twitter/timelines.php index 98341cd..cb37cd3 100644 --- a/library/eden/twitter/timelines.php +++ b/library/eden/twitter/timelines.php @@ -64,15 +64,15 @@ public static function get($user, $api) { public function getTimeline($count = NULL, $since = NULL, $max = NULL, $page = NULL, $trim = false, $include = false, $entities = false, $replies = false, $detail =false) { //Argument Test Eden_Twitter_Error::get() - ->argument(1, 'int') //Argument 1 must be an integer - ->argument(2, 'int') //Argument 2 must be an integer - ->argument(3, 'int') //Argument 3 must be an integer - ->argument(4, 'int') //Argument 4 must be an integer - ->argument(5, 'bool') //Argument 5 must be an boolean + ->argument(1, 'int', 'null') //Argument 1 must be an integer + ->argument(2, 'int', 'null') //Argument 2 must be an integer + ->argument(3, 'int', 'null') //Argument 3 must be an integer + ->argument(4, 'int', 'null') //Argument 4 must be an integer + ->argument(5, 'bool') //Argument 5 must be a boolean ->argument(6, 'bool') //Argument 6 must be a boolean - ->argument(7, 'bool') //Argument 7 must be an boolean - ->argument(8, 'bool') //Argument 8 must be an boolean - ->argument(9, 'bool'); //Argument 9 must be an boolean + ->argument(7, 'bool') //Argument 7 must be a boolean + ->argument(8, 'bool') //Argument 8 must be a boolean + ->argument(9, 'bool'); //Argument 9 must be a boolean $query = array(); //if it is not empty and its less than equal to 100 @@ -80,15 +80,15 @@ public function getTimeline($count = NULL, $since = NULL, $max = NULL, $page = N //lets put it in query $query['count'] = $count; } - //if it is not empty a + //if it is not empty if(!is_null($since)) { //lets put it in query $query['since_id'] = $since; } //if it is not empty and max is not less than count - if(!is_null(max) && $max <= $count) { + if(!is_null($max) && $$max <= $count) { //lets put it in query - $query['max_id'] = $max; + $query['$max_id'] = $$max; } //if it is not empty if(!is_null($page)) { @@ -134,14 +134,14 @@ public function getTimeline($count = NULL, $since = NULL, $max = NULL, $page = N public function getMention($count = NULL, $since = NULL, $max = NULL, $page = NULL, $trim = false, $include = false, $entities = false, $detail =false) { //Argument Test Eden_Twitter_Error::get() - ->argument(1, 'int') //Argument 1 must be an integer - ->argument(2, 'int') //Argument 2 must be an integer - ->argument(3, 'int') //Argument 3 must be an integer - ->argument(4, 'int') //Argument 4 must be an integer + ->argument(1, 'int', 'null') //Argument 1 must be an integer + ->argument(2, 'int', 'null') //Argument 2 must be an integer + ->argument(3, 'int', 'null') //Argument 3 must be an integer + ->argument(4, 'int', 'null') //Argument 4 must be an integer ->argument(5, 'bool') //Argument 5 must be an boolean ->argument(6, 'bool') //Argument 6 must be a boolean - ->argument(7, 'bool') //Argument 7 must be an boolean - ->argument(8, 'bool'); //Argument 8 must be an boolean + ->argument(7, 'bool') //Argument 7 must be a boolean + ->argument(8, 'bool'); //Argument 8 must be a boolean $query = array(); @@ -155,10 +155,10 @@ public function getMention($count = NULL, $since = NULL, $max = NULL, $page = NU //lets put it in query $query['since_id'] = $since; } - //if it is not empty and max is not less than count - if(!is_null(max) && $max <= $count) { + //if it is not empty and $max is not less than count + if(!is_null($max) && $$max <= $count) { //lets put it in query - $query['max_id'] = $max; + $query['$max_id'] = $$max; } //if it is not empty and if(!is_null($page)) { @@ -195,8 +195,8 @@ public function getMention($count = NULL, $since = NULL, $max = NULL, $page = NU public function getPublic($trim = false, $entities = false) { //Argument Test Eden_Twitter_Error::get() - ->argument(1, 'bool') //Argument 1 must be an boolean - ->argument(2, 'bool'); //Argument 2 must be an boolean + ->argument(1, 'bool') //Argument 1 must be a boolean + ->argument(2, 'bool'); //Argument 2 must be a boolean $query = array(); //if trim @@ -215,7 +215,7 @@ public function getPublic($trim = false, $entities = false) { * * @param count is integer * @param since is integer - * @param max is integer + * @param $max is integer * @param page is integer * @param trim is boolean * @param entities is boolean @@ -224,12 +224,12 @@ public function getPublic($trim = false, $entities = false) { public function getBy($count = NULL, $since = NULL, $max = NULL, $page = NULL, $trim = false, $entities = false) { //Argument Test Eden_Twitter_Error::get() - ->argument(1, 'int') //Argument 1 must be an integer - ->argument(2, 'int') //Argument 2 must be an integer - ->argument(3, 'int') //Argument 3 must be an integer - ->argument(4, 'int') //Argument 4 must be an integer + ->argument(1, 'int', 'null') //Argument 1 must be an integer + ->argument(2, 'int', 'null') //Argument 2 must be an integer + ->argument(3, 'int', 'null') //Argument 3 must be an integer + ->argument(4, 'int', 'null') //Argument 4 must be an integer ->argument(5, 'bool') //Argument 5 must be an boolean - ->argument(6, 'bool'); //Argument 6 must be a boolean + ->argument(6, 'bool'); //Argument 6 must be an boolean $query = array(); @@ -243,10 +243,10 @@ public function getBy($count = NULL, $since = NULL, $max = NULL, $page = NULL, $ //lets put it in query $query['since_id'] = $since; } - //if it is not empty and max is not less than count - if(!is_null(max) && $max <= $count) { + //if it is not empty and $max is not less than count + if(!is_null($max) && $$max <= $count) { //lets put it in query - $query['max_id'] = $max; + $query['$max_id'] = $$max; } //if it is not empty and if(!is_null($page)) { @@ -269,7 +269,7 @@ public function getBy($count = NULL, $since = NULL, $max = NULL, $page = NULL, $ * * @param count is integer * @param since is integer - * @param max is integer + * @param $max is integer * @param page is integer * @param trim is boolean * @param entities is boolean @@ -278,11 +278,11 @@ public function getBy($count = NULL, $since = NULL, $max = NULL, $page = NULL, $ public function getTo($count = NULL, $since = NULL, $max = NULL, $page = NULL, $trim = false, $entities = false) { //Argument Test Eden_Twitter_Error::get() - ->argument(1, 'int') //Argument 1 must be an integer - ->argument(2, 'int') //Argument 2 must be an integer - ->argument(3, 'int') //Argument 3 must be an integer - ->argument(4, 'int') //Argument 4 must be an integer - ->argument(5, 'bool') //Argument 5 must be an boolean + ->argument(1, 'int', 'null') //Argument 1 must be an integer + ->argument(2, 'int', 'null') //Argument 2 must be an integer + ->argument(3, 'int', 'null') //Argument 3 must be an integer + ->argument(4, 'int', 'null') //Argument 4 must be an integer + ->argument(5, 'bool') //Argument 5 must be a boolean ->argument(6, 'bool'); //Argument 6 must be a boolean $query = array(); @@ -297,10 +297,10 @@ public function getTo($count = NULL, $since = NULL, $max = NULL, $page = NULL, $ //lets put it in query $query['since_id'] = $since; } - //if it is not empty and max is not less than count - if(!is_null(max) && $max <= $count) { + //if it is not empty and $max is not less than count + if(!is_null($max) && $$max <= $count) { //lets put it in query - $query['max_id'] = $max; + $query['$max_id'] = $$max; } //if it is not empty and if(!is_null($page)) { @@ -323,7 +323,7 @@ public function getTo($count = NULL, $since = NULL, $max = NULL, $page = NULL, $ * * @param count is integer * @param since is integer - * @param max is integer + * @param $max is integer * @param page is integer * @param trim is boolean * @param entities is boolean @@ -332,11 +332,11 @@ public function getTo($count = NULL, $since = NULL, $max = NULL, $page = NULL, $ public function getOf($count = NULL, $since = NULL, $max = NULL, $page = NULL, $trim = false, $entities = false) { //Argument Test Eden_Twitter_Error::get() - ->argument(1, 'int') //Argument 1 must be an integer - ->argument(2, 'int') //Argument 2 must be an integer - ->argument(3, 'int') //Argument 3 must be an integer - ->argument(4, 'int') //Argument 4 must be an integer - ->argument(5, 'bool') //Argument 5 must be an boolean + ->argument(1, 'int', 'null') //Argument 1 must be an integer + ->argument(2, 'int', 'null') //Argument 2 must be an integer + ->argument(3, 'int', 'null') //Argument 3 must be an integer + ->argument(4, 'int', 'null') //Argument 4 must be an integer + ->argument(5, 'bool') //Argument 5 must be a boolean ->argument(6, 'bool'); //Argument 6 must be a boolean $query = array(); @@ -346,15 +346,15 @@ public function getOf($count = NULL, $since = NULL, $max = NULL, $page = NULL, $ //lets put it in query $query['count'] = $count; } - //if it is not empty and + //if it is not empty if(!is_null($since)) { //lets put it in query $query['since_id'] = $since; } - //if it is not empty and max is not less than count - if(!is_null(max) && $max <= $count) { + //if it is not empty and $max is not less than count + if(!is_null($max) && $$max <= $count) { //lets put it in query - $query['max_id'] = $max; + $query['$max_id'] = $$max; } //if it is not empty and if(!is_null($page)) { @@ -382,7 +382,7 @@ public function getOf($count = NULL, $since = NULL, $max = NULL, $page = NULL, $ * @param name is a string * @param since is integer * @param count is integer - * @param max is integer + * @param $max is integer * @param page is integer * @param trim is boolean * @param include is boolean @@ -391,31 +391,33 @@ public function getOf($count = NULL, $since = NULL, $max = NULL, $page = NULL, $ * @param detail is boolean * @return $this */ - public function getUser($id = NULL, $name = NULL, $since = NULL, $count = NULL,$max = NULL, $page = NULL, $trim = false, $include = false, $entities = false, $replies = false, $detail =false) { + public function getList($id = NULL, $since = NULL, $count = NULL, $max = NULL, $page = NULL, $trim = false, $include = false, $entities = false, $replies = false, $detail =false) { //Argument Test Eden_Twitter_Error::get() - ->argument(1, 'int') //Argument 1 must be an integer - ->argument(2, 'string') //Argument 2 must be an string - ->argument(3, 'int') //Argument 3 must be an integer - ->argument(4, 'int') //Argument 4 must be an integer - ->argument(5, 'int') //Argument 5 must be an boolean - ->argument(6, 'int') //Argument 6 must be a boolean - ->argument(7, 'bool') //Argument 7 must be an boolean - ->argument(8, 'bool') //Argument 8 must be an boolean - ->argument(9, 'bool') //Argument 9 must be an boolean - ->argument(10, 'bool') //Argument 10 must be an boolean - ->argument(11, 'bool'); //Argument 11 must be an boolean + ->argument(1, 'int','string', 'null') //Argument 1 must be an integer + ->argument(2, 'int', 'null') //Argument 2 must be an integer + ->argument(3, 'int', 'null') //Argument 3 must be an integer + ->argument(4, 'int', 'null') //Argument 4 must be a boolean + ->argument(5, 'int', 'null') //Argument 5 must be a boolean + ->argument(6, 'bool') //Argument 6 must be a boolean + ->argument(7, 'bool') //Argument 7 must be a boolean + ->argument(8, 'bool') //Argument 8 must be a boolean + ->argument(9, 'bool') //Argument 9 must be a boolean + ->argument(10, 'bool'); //Argument 10 must be a boolean $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; + + if(is_int($id)) { + //Lets put it in query + $query['user_id'] = $id; + } + + if(is_string($id)) { + //Lets put it in query + $query['screen_name'] = $id; + } } //if it is not empty if(!is_null($since)) { @@ -427,10 +429,10 @@ public function getUser($id = NULL, $name = NULL, $since = NULL, $count = NULL,$ $query['count'] = $count; } } - //if it is not empty and max is not less than count - if(!is_null(max) && $max <= $count) { + //if it is not empty and $max is not less than count + if(!is_null($max) && $$max <= $count) { //lets put it in query - $query['max_id'] = $max; + $query['$max_id'] = $$max; } //if it is not empty and if(!is_null($page)) { @@ -468,7 +470,7 @@ public function getUser($id = NULL, $name = NULL, $since = NULL, $count = NULL,$ * @param id is a integer or string * @param since is integer * @param count is integer - * @param max is integer + * @param $max is integer * @param page is integer * @param trim is boolean * @param include is boolean @@ -477,20 +479,20 @@ public function getUser($id = NULL, $name = NULL, $since = NULL, $count = NULL,$ * @param detail is boolean * @return $this */ - public function getToUser($name = NULL, $id = NULL, $since = NULL, $count = NULL,$max = NULL, $page = NULL, $trim = false, $entities = false) { + public function getToUser($name = NULL, $id = NULL, $since = NULL, $count = NULL, $max = NULL, $page = NULL, $trim = false, $entities = false) { //Argument Test Eden_Twitter_Error::get() - ->argument(1, 'string') //Argument 1 must be an string - ->argument(2, 'string', 'int') //Argument 2 must be an string or integer - ->argument(3, 'int') //Argument 3 must be an integer - ->argument(4, 'int') //Argument 4 must be an integer - ->argument(5, 'int') //Argument 5 must be an boolean - ->argument(6, 'int') //Argument 6 must be a boolean - ->argument(7, 'bool') //Argument 7 must be an boolean - ->argument(8, 'bool') //Argument 8 must be an boolean - ->argument(9, 'bool') //Argument 9 must be an boolean - ->argument(10, 'bool') //Argument 10 must be an boolean - ->argument(11, 'bool'); //Argument 11 must be an boolean + ->argument(1, 'string', 'null') //Argument 1 must be a string + ->argument(2, 'string', 'int', 'null') //Argument 2 must be a string or integer + ->argument(3, 'int', 'null') //Argument 3 must be an integer + ->argument(4, 'int', 'null') //Argument 4 must be an integer + ->argument(5, 'int', 'null') //Argument 5 must be a boolean + ->argument(6, 'int', 'null') //Argument 6 must be a boolean + ->argument(7, 'bool') //Argument 7 must be a boolean + ->argument(8, 'bool') //Argument 8 must be a boolean + ->argument(9, 'bool') //Argument 9 must be a boolean + ->argument(10, 'bool') //Argument 10 must be a boolean + ->argument(11, 'bool'); //Argument 11 must be a boolean $query = array(); //If it is not empty @@ -507,15 +509,16 @@ public function getToUser($name = NULL, $id = NULL, $since = NULL, $count = NULL if(!is_null($since)) { //lets put it in query $query['since_id'] = $since; - //if it is not empty and + } + //if it is not empty and if(!is_null($count) && $count <= 200) { //lets put it in query $query['count'] = $count; } - //if it is not empty and max is not less than count - if(!is_null(max) && $max <= $count) { + //if it is not empty and $max is not less than count + if(!is_null($max) && $$max <= $count) { //lets put it in query - $query['max_id'] = $max; + $query['$max_id'] = $$max; } //if it is not empty and if(!is_null($page)) { @@ -541,7 +544,7 @@ public function getToUser($name = NULL, $id = NULL, $since = NULL, $count = NULL * @param id is a integer or string * @param since is integer * @param count is integer - * @param max is integer + * @param $max is integer * @param page is integer * @param trim is boolean * @param include is boolean @@ -550,20 +553,17 @@ public function getToUser($name = NULL, $id = NULL, $since = NULL, $count = NULL * @param detail is boolean * @return $this */ - public function getByUser($name = NULL, $id = NULL, $since = NULL, $count = NULL,$max = NULL, $page = NULL, $trim = false, $entities = false) { + public function getByUser($name = NULL, $id = NULL, $since = NULL, $count = NULL, $max = NULL, $page = NULL, $trim = false, $entities = false) { //Argument Test Eden_Twitter_Error::get() - ->argument(1, 'string') //Argument 1 must be an string - ->argument(2, 'string', 'int') //Argument 2 must be an string or integer - ->argument(3, 'int') //Argument 3 must be an integer - ->argument(4, 'int') //Argument 4 must be an integer - ->argument(5, 'int') //Argument 5 must be an boolean - ->argument(6, 'int') //Argument 6 must be a boolean - ->argument(7, 'bool') //Argument 7 must be an boolean - ->argument(8, 'bool') //Argument 8 must be an boolean - ->argument(9, 'bool') //Argument 9 must be an boolean - ->argument(10, 'bool') //Argument 10 must be an boolean - ->argument(11, 'bool'); //Argument 11 must be an boolean + ->argument(1, 'string', 'null') //Argument 1 must be a string + ->argument(2, 'string', 'int', 'null') //Argument 2 must be a string or integer + ->argument(3, 'int', 'null') //Argument 3 must be a integer + ->argument(4, 'int', 'null') //Argument 4 must be a integer + ->argument(5, 'int', 'null') //Argument 5 must be a boolean + ->argument(6, 'int', 'null') //Argument 6 must be a boolean + ->argument(7, 'bool') //Argument 7 must be a boolean + ->argument(8, 'bool'); //Argument 8 must be a boolean $query = array(); //If it is not empty @@ -580,15 +580,16 @@ public function getByUser($name = NULL, $id = NULL, $since = NULL, $count = NULL if(!is_null($since)) { //lets put it in query $query['since_id'] = $since; - //if it is not empty and + } + //if it is not empty and if(!is_null($count) && $count <= 200) { //lets put it in query $query['count'] = $count; } - //if it is not empty and max is not less than count - if(!is_null(max) && $max <= $count) { + //if it is not empty and $max is not less than count + if(!is_null($max) && $$max <= $count) { //lets put it in query - $query['max_id'] = $max; + $query['$max_id'] = $$max; } //if it is not empty and if(!is_null($page)) { diff --git a/library/eden/twitter/tweets.php b/library/eden/twitter/tweets.php index 1cc9034..9b14a06 100644 --- a/library/eden/twitter/tweets.php +++ b/library/eden/twitter/tweets.php @@ -19,11 +19,11 @@ 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/%s/retweeted_by/ids.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/%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'; @@ -37,9 +37,10 @@ class Eden_Twitter_Tweets extends Eden_Twitter_Base { -------------------------------*/ /* Get -------------------------------*/ - public static function get($user, $api) { - return self::_getMultiple(__CLASS__, $user, $api); + public static function get($key, $secret) { + return self::_getMultiple(__CLASS__, $key, $secret); } + /* Magic -------------------------------*/ /* Public Methods @@ -53,14 +54,14 @@ public static function get($user, $api) { * @param page is integer * @return $this */ - public function getWhoRetweeted($id, $count = NULL, $page, = NULL) { + public function getWhoRetweeted($id, $count = NULL, $page = NULL) { //Argument Test Eden_Twitter_Error::get() ->argument(1, 'int') //Argument 1 must be an integer ->argument(2, 'int') //Argument 2 must be an integer ->argument(3, 'int'); //Argument 3 must be an integer - $query = array('id' => $id); + $query = array(); //if it is not empty and not up to a maximum of 100 if(!is_null($count) && $count <= 100) { //lets put it in query @@ -71,8 +72,8 @@ public function getWhoRetweeted($id, $count = NULL, $page, = NULL) { //lets put it in query $query['page'] = $count; } - - return $this->_getResponse(self::URL_WHO_RETWEETED, $query); + $url = sprintf(self::URL_WHO_RETWEETED, $id); + return $this->_post($url, $query); } /** * Show user ids of up to 100 users who retweeted the status. @@ -83,7 +84,7 @@ public function getWhoRetweeted($id, $count = NULL, $page, = NULL) { * @param stringify is boolean * @return $this */ - public function getWhoRetweetedIds($id, $count = NULL, $page = NULL, stringify = false) { + public function getWhoRetweetedIds($id, $count = NULL, $page = NULL, $stringify = false) { //Argument Test Eden_Twitter_Error::get() ->argument(1, 'int') //Argument 1 must be an integer @@ -91,7 +92,7 @@ public function getWhoRetweetedIds($id, $count = NULL, $page = NULL, stringify = ->argument(3, 'int') //Argument 3 must be an integer ->argument(4, 'bool'); //Argument 4 must be a boolean - $query = array('id' => $id); + $query = array(); //if it is not empty and not up to a maximum of 100 if(!is_null($count) && $count <= 100) { //lets put it in query @@ -107,8 +108,9 @@ public function getWhoRetweetedIds($id, $count = NULL, $page = NULL, stringify = $query['stringify_ids'] = 1; } - - return $this->_getResponse(self::URL_GET_WHO_RETWEETED_IDS, $query); + + $url = sprintf(self::URL_GET_WHO_RETWEETED_IDS, $id); + return $this->_post($url, $query); } /** * Returns up to 100 of the first retweets of a given tweet. @@ -129,7 +131,7 @@ public function getRetweets($id, $count = NULL, $trim = false, $entities = false $query = array('id' => $id); //if count is not empty and less than equal to 100 - if(!is_null($coutn) && $count <= 100) { + if(!is_null($count) && $count <= 100) { //Lets put it in query $query['count'] = $count; } @@ -141,8 +143,8 @@ public function getRetweets($id, $count = NULL, $trim = false, $entities = false if($entities) { $query['include_entities'] = 1; } - - return $this->_getResponse(self::URL_GET_RETWEETS, $query); + $url = sprintf(self::URL_GET_RETWEETS, $id); + return $this->_post($url, $query); } /** * Returns a single status, specified by the id parameter below. @@ -153,7 +155,7 @@ public function getRetweets($id, $count = NULL, $trim = false, $entities = false * @param entities is boolean * @return $this */ - public function getList($id, $trim = false, $entities = false) { + public function getDetail($id, $trim = false, $entities = false) { //Argument Test Eden_Twitter_Error::get() ->argument(1, 'int') //Argument 1 must be an integer @@ -189,7 +191,7 @@ public function remove($id, $entities = false, $trim = false) { ->argument(2, 'bool') //Argument 2 must be an boolean ->argument(3, 'bool'); //Argument 3 must be an boolean - $query = array('id' => $id); + $query = array(); //if entities if($entities) { $query['include_entities'] = 1; @@ -199,7 +201,8 @@ public function remove($id, $entities = false, $trim = false) { $query['trim_user'] = 1; } - return $this->_getResponse(self::URL_REMOVE, $query); + $url = sprintf(self::URL_REMOVE, $id); + return $this->_post($url,$query); } /** * Retweets a tweet. Returns the original tweet @@ -217,7 +220,7 @@ public function retweet($id, $entities = false, $trim = false) { ->argument(2, 'bool') //Argument 2 must be an boolean ->argument(3, 'bool'); //Argument 3 must be an boolean - $query = array('id' => $id); + $query = array(); //if entities if($entities) { $query['include_entities'] = 1; @@ -226,8 +229,8 @@ public function retweet($id, $entities = false, $trim = false) { if($trim) { $query['trim_user'] = 1; } - - return $this->_getResponse(self::URL_RETWEET, $query); + $url = sprintf(self::URL_RETWEET, $id); + return $this->_post($url, $query); } /** * Updates the authenticating user's status, @@ -276,7 +279,7 @@ public function update($status, $reply = NULL, $lat = NULL, $long = NULL, $place //if reply is not empty if(!is_null($place)) { //lets put it in query - $query['place_id '] = $place + $query['place_id '] = $place; } //if entities if($display) { @@ -295,7 +298,7 @@ public function update($status, $reply = NULL, $lat = NULL, $long = NULL, $place $query['wrap_links'] = 1; } - return $this->_getResponse(self::URL_UPDATE, $query); + return $this->_post(self::URL_UPDATE, $query); } /** * Updates the authenticating user's status, @@ -334,6 +337,7 @@ public function updateMedia($status, $media, $sensitive = NULL, $id = NULL, $lat if(!is_null($id)) { //lets put it in query $query['in_reply_to_status_id'] = $id; + } //if reply is not empty if(!is_null($lat) && $lat >= -90.0 && $lat <= +90.0) { //lets put it in query From c3dfdceacea78402d3d41e87a4837af8ce135ad9 Mon Sep 17 00:00:00 2001 From: sy Date: Thu, 8 Dec 2011 02:33:42 +0000 Subject: [PATCH 011/330] update twitter API and add Get Satisfaction and Tumblr API git-svn-id: http://svn.openovate.com/edenv2/trunk@11 38ede93f-50f4-44af-b0b3-68ccca78c181 --- library/eden/getsatisfaction/base.php | 219 ++++++++++ library/eden/getsatisfaction/company.php | 258 ++++++++++++ library/eden/getsatisfaction/people.php | 81 ++++ library/eden/getsatisfaction/replies.php | 171 ++++++++ library/eden/getsatisfaction/topic.php | 356 ++++++++++++++++ library/eden/tumblr/base.php | 207 +++++++++ library/eden/tumblr/blog.php | 513 +++++++++++++++++++++++ library/eden/tumblr/error.php | 56 +++ library/eden/tumblr/oauth.php | 44 ++ library/eden/tumblr/user.php | 248 +++++++++++ library/eden/twitter/accounts.php | 280 +++++++++++++ library/eden/twitter/base.php | 373 +++++++--------- library/eden/twitter/favorites.php | 130 ++++++ library/eden/twitter/list.php | 163 +++++++ library/eden/twitter/suggestions.php | 110 +++++ library/eden/twitter/users.php | 277 ++++++++++++ site/web/sy.php | 48 +++ site/web/symon.php | 368 ++++++++++++++++ 18 files changed, 3685 insertions(+), 217 deletions(-) create mode 100644 library/eden/getsatisfaction/base.php create mode 100644 library/eden/getsatisfaction/company.php create mode 100644 library/eden/getsatisfaction/people.php create mode 100644 library/eden/getsatisfaction/replies.php create mode 100644 library/eden/getsatisfaction/topic.php create mode 100644 library/eden/tumblr/base.php create mode 100644 library/eden/tumblr/blog.php create mode 100644 library/eden/tumblr/error.php create mode 100644 library/eden/tumblr/oauth.php create mode 100644 library/eden/tumblr/user.php create mode 100644 library/eden/twitter/accounts.php create mode 100644 library/eden/twitter/favorites.php create mode 100644 library/eden/twitter/list.php create mode 100644 library/eden/twitter/suggestions.php create mode 100644 library/eden/twitter/users.php create mode 100644 site/web/sy.php create mode 100644 site/web/symon.php diff --git a/library/eden/getsatisfaction/base.php b/library/eden/getsatisfaction/base.php new file mode 100644 index 0000000..1bb7529 --- /dev/null +++ b/library/eden/getsatisfaction/base.php @@ -0,0 +1,219 @@ + +/* + * 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. + */ + +/** + * get satisfaction oauth + * + * @package Eden + * @category get satisfaction + * @author Christian Blanquera + * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ + */ +class Eden_GetSatisfaction_Base extends Eden_Oauth_Base { + /* Constants + -------------------------------*/ + const REQUEST_URL = ''; + const AUTHORIZE_URL = ''; + + const SECRET_KEY = ''; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_key = NULL; + protected $_secret = NULL; + + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + /* Magic + -------------------------------*/ + public function __construct($key, $secret) { + //argument test + Eden_Twitter_Error::get() + ->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 URL used for login. + * + * @param string + * @return string + */ + public function getLoginUrl($redirect) { + //Argument 1 must be a string + Eden_Google_Error::get()->argument(1, 'string'); + + //get the token + $token = Eden_Oauth::get() + ->getConsumer(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; + } + + /** + * Returns the access token + * + * @param string + * @param string + * @return string + */ + public function getAccessToken($token, $secret) { + //argument test + Eden_Google_Error::get() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'string'); //Argument 2 must be a string + + return Eden_Oauth::get() + ->getConsumer(self::ACCESS_URL, $this->_key, $this->_secret) + ->useAuthorization() + ->setMethodToPost() + ->setToken($token, $secret) + ->setSignatureToHmacSha1() + ->getQueryResponse(); + } + + public function setAccessToken($token, $secret) { + $this->_accessToken = $token; + $this->_accessSecret = $secret; + + return $this; + } + + + /** + * Returns the meta of the last call + * + * @return array + */ + public function getMeta($key = NULL) { + Eden_Google_Error::get()->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::get() + ->getConsumer($url, $this->_key, $this->_secret) + ->setHeaders(self::VERSION_HEADER, self::GDATA_VERSION) + ->setToken($this->_accessToken, $this->_accessSecret) + ->setSignatureToHmacSha1(); + + $response = $rest->getJsonResponse($query); + + $this->_meta = $rest->getMeta(); + + return $response; + } + + /** + * Returns the token from the server + * + * @param array + * @return array + */ + protected function _post($url, $query = array()) { + $headers = array(); + $headers[] = Eden_Oauth_Consumer::POST_HEADER; + + $rest = Eden_Oauth::get() + ->getConsumer($url, $this->_key, $this->_secret) + ->setToken($this->_accessToken, $this->_accessSecret) + ->setSignatureToHmacSha1(); + + //get the authorization parameters as an array + $signature = $rest->getSignature(); + $authorization = $rest->getAuthorization($signature, false); + $authorization = $this->_buildQuery($authorization); + + if(is_array($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::get() + ->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['authorization'] = $authorization; + $this->_meta['headers'] = $headers; + $this->_meta['query'] = $query; + + 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..3917b2b --- /dev/null +++ b/library/eden/getsatisfaction/company.php @@ -0,0 +1,258 @@ + +/* + * 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. + */ + +/** + * + * + * @package Eden + * @category Get Satisfaction + * @author Christian Blanquera + * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ + */ +class Eden_GetSatisfaction_Company extends Eden_GetSatisfaction_Base { + /* Constants + -------------------------------*/ + const URL_GET_LIST = 'http://api.getsatisfaction.com/companies.json'; + const URL_GET_USER = 'http://api.getsatisfaction.com/people/%s/companies.json'; + const URL_GET_PRODUCT = 'http://api.getsatisfaction.com/products/%s/companies.json'; + const URL_GET_COMPANY = 'http://api.getsatisfaction.com/companies/%s/last_activity_at.json'; + const URL_SEARCH = 'http://api.getsatisfaction.com?query=%s.json'; + + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_query = array(); + + protected $_validShow = array('public','not_hidden','private','not_hidden'); + + protected $_validSort = array( + 'created' => 'recently_created', + 'active' => 'recently_active', + 'alpha' => 'alpha'); + + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function get($user, $api) { + return self::_getMultiple(__CLASS__, $user, $api); + } + + /* Magic + -------------------------------*/ + /* Public Methods + -------------------------------*/ + /** + * Get all the public Get Satisfaction communities + * + * @param show is string + * @param sort is string + * @return this + */ + public function getList($show = NULL, $sort = NULL) { + //Argument testing + Eden_Tumblr_Error::get() + ->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 the show is a short version of a valid show + if(isset($this->_validShow[$show])) { + //make show the long version + $filter = $this->_validShow[$show]; + //lets set show to show + $query['show'] = $show; + + } + + //if the show is a short version of a valid show + if(isset($this->_validSort[$sort])) { + //make filter the long version + $filter = $this->_validSort[$sort]; + //lets set sort to sort + $query['sort'] = $sort; + + } + + return $this->_getResponse(self::URL_GET_LIST, $query); + } + + /** + * Get all the public Get Satisfaction + * communities created by the specified user + * + * @param name is string + * @param id is integer + * @param show is string + * @param sort is string + * @return this + */ + public function getUser($name = NULL, $id = NULL, $show = NULL, $sort = NULL) { + //Argument testing + Eden_Tumblr_Error::get() + ->argument(1, 'string' ,'null') //Argument 1 must be a string or null + ->argument(2, 'integer' ,'null') //Argument 2 must be a integer or null + ->argument(3, 'string' ,'null') //Argument 3 must be a string or null + ->argument(4, 'string' ,'null'); //Argument 2 must be a string or null + + $query = array(); + + //if name is not empty + if(!is_null($name)) { + //lets set user name to user + $query['user_name'] = $name; + } + //if id is not empty + if(!is_null($id)) { + //lets set user id to id + $query['user_id'] = $id; + } + + //if the show is a short version of a valid show + if(isset($this->_validShow[$show])) { + //make show the long version + $filter = $this->_validShow[$show]; + //lets set show to show + $query['show'] = $show; + } + + //if the show is a short version of a valid show + if(isset($this->_validSort[$sort])) { + //make filter the long version + $filter = $this->_validSort[$sort]; + //lets set sort to sort + $query['sort'] = $sort; + } + + return $this->_getResponse(self::URL_GET_USER, $query); + } + + /** + * Get all the public Get Satisfaction communities + * related to the specified product + * + * @param name is string + * @param id is integer + * @param show is string + * @param sort is string + * @return this + */ + public function getUser($name = NULL, $id = NULL, $show = NULL, $sort = NULL) { + //Argument testing + Eden_Tumblr_Error::get() + ->argument(1, 'string' ,'null') //Argument 1 must be a string or null + ->argument(2, 'integer' ,'null') //Argument 2 must be a integer or null + ->argument(3, 'string' ,'null') //Argument 3 must be a string or null + ->argument(4, 'string' ,'null'); //Argument 2 must be a string or null + + $query = array(); + + //if name is not empty + if(!is_null($name)) { + //lets set user name to user + $query['user_name'] = $name; + } + //if id is not empty + if(!is_null($id)) { + //lets set user id to id + $query['user_id'] = $id; + } + + //if the show is a short version of a valid show + if(isset($this->_validShow[$show])) { + //make show the long version + $filter = $this->_validShow[$show]; + //lets set show to show + $query['show'] = $show; + } + + //if the show is a short version of a valid show + if(isset($this->_validSort[$sort])) { + //make filter the long version + $filter = $this->_validSort[$sort]; + //lets set sort to sort + $query['sort'] = $sort; + } + + return $this->_getResponse(self::URL_GET_PRODUCT, $query); + } + + /** + * Get the date and time of the last activity + * in the specified community + * + * @param name is string + * @param id is integer + * @param show is string + * @param sort is string + * @return this + */ + public function getUser($name = NULL, $id = NULL, $show = NULL, $sort = NULL) { + //Argument testing + Eden_Tumblr_Error::get() + ->argument(1, 'string' ,'null') //Argument 1 must be a string or null + ->argument(2, 'integer' ,'null') //Argument 2 must be a integer or null + ->argument(3, 'string' ,'null') //Argument 3 must be a string or null + ->argument(4, 'string' ,'null'); //Argument 2 must be a string or null + + $query = array(); + + //if name is not empty + if(!is_null($name)) { + //lets set user name to user + $query['user_name'] = $name; + } + //if id is not empty + if(!is_null($id)) { + //lets set user id to id + $query['user_id'] = $id; + } + + //if the show is a short version of a valid show + if(isset($this->_validShow[$show])) { + //make show the long version + $filter = $this->_validShow[$show]; + //lets set show to show + $query['show'] = $show; + } + + //if the show is a short version of a valid show + if(isset($this->_validSort[$sort])) { + //make filter the long version + $filter = $this->_validSort[$sort]; + //lets set sort to sort + $query['sort'] = $sort; + } + + return $this->_getResponse(self::URL_GET_COMPANY, $query); + } + + /** + * Search for a particular string + * + * @param search is string + * @return this + */ + public function search($search) { + //Argument testing + Eden_Tumblr_Error::get() + ->argument(1, 'string'); //Argument 1 must be a string + + $query = array('search' => $search); + + return $this->_getResponse(self::URL_SEARCH, $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..3a76f3f --- /dev/null +++ b/library/eden/getsatisfaction/people.php @@ -0,0 +1,81 @@ + +/* + * 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. + */ + +/** + * + * + * @package Eden + * @category Get Satisfaction + * @author Christian Blanquera + * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ + */ +class Eden_GetSatisfaction_People extends Eden_GetSatisfaction_Base { + /* Constants + -------------------------------*/ + const URL_GET_LIST = 'http://api.getsatisfaction.com/people.json'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_query = array(); + + protected $_validShow = array('public','not_hidden','private','not_hidden'); + + protected $_validSort = array( + 'created' => 'recently_created', + 'active' => 'recently_active', + 'alpha' => 'alpha'); + + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function get($user, $api) { + return self::_getMultiple(__CLASS__, $user, $api); + } + + /* Magic + -------------------------------*/ + /* Public Methods + -------------------------------*/ + /** + * People with accounts in communities at Get Satisfaction + * + * @return this + */ + public function getList() { + + return $this->_getResponse(self::URL_GET_LIST); + } + + /** + * Goes to page 3 of the people list, showing 10 people. + * (A limit of 30 is max.) + * + * @return this + */ + public function getList($page, $limit = NULL) { + //Argument testing + Eden_Tumblr_Error::get() + ->argument(1, 'integer') //Argument 1 must be a string + ->argument(2, 'integer' ,'null'); //Argument 2 must be a string or null + + $query = array(); + + return $this->_getResponse(self::URL_GET_LIST); + } + + + + /* 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..2cde0ed --- /dev/null +++ b/library/eden/getsatisfaction/replies.php @@ -0,0 +1,171 @@ + +/* + * 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. + */ + +/** + * + * + * @package Eden + * @category Get Satisfaction + * @author Christian Blanquera + * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ + */ +class Eden_GetSatisfaction_Replies extends Eden_GetSatisfaction_Base { + /* Constants + -------------------------------*/ + const URL_GET_LIST = 'http://api.getsatisfaction.com/replies.json'; + const URL_GET_TOPICS = 'http://api.getsatisfaction.com/topics/%s/replies.json'; + const URL_GET_USERS = 'http://api.getsatisfaction.com/people/%s/replies.json'; + + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_query = array(); + + protected $_validFilters = array( + 'best' => 'best', + 'star' => 'star_promoted', + 'company' => 'company_promoted', + 'flat' => 'flat_promotion'); + + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function get($user, $api) { + return self::_getMultiple(__CLASS__, $user, $api); + } + + /* Magic + -------------------------------*/ + /* Public Methods + -------------------------------*/ + /** + * Get all replies to all topics in all public Get Satisfaction communities + * + * @return this + */ + public function getList($filter = NULL) { + //Argument 1 must be a string or null + Eden_Tumblr_Error::get()->argument(1, 'string' ,'null'); + + $query = array(); + + //if the filter is a short version of a valid filter + if(isset($this->_validFilters[$filter])) { + //make filter the long version + $filter = $this->_validFilters[$filter]; + } + + //if filter is valid + if(in_array($filter, $this->_validFilters)) { + //if filter is flat promotion + if($filter == 'flat_promotion') { + //lets set type to filter + $query['type'] = $filter; + //it is not a flat promotion + } else { + //lets set filter to filter + $query['filter'] = $filter; + } + } + + return $this->_getResponse(self::URL_GET_LIST, $query); + } + + /** + * Get all replies from the specified topic + * + * @param id is integer + * @param slug is a string + * @return this + */ + public function getTopics($id = NULL, $slug = NULL, $filter = NULL) { + //argument testing + Eden_Tumblr_Error::get() + ->argument(1, 'integer' ,'null') //Argument 2 must be a integer or null + ->argument(2, 'string' ,'null') //Argument 1 must be a string or null + ->argument(3, 'string' ,'null'); //Argument 3 must be a string or null + + $query = array(); + //if the id is not empty + if(!is_null($id)) { + //lets set topic id to id + $query['topic_id'] = $id; + } + + //if the slug is not empty + if(!is_null($slug)) { + //lets set slug to slug + $query['slug'] = $slug; + } + + //if the filter is a short version of a valid filter + if(isset($this->_validFilters[$filter])) { + //make filter the long version + $filter = $this->_validFilters[$filter]; + } + + //if filter is valid + if(in_array($filter, $this->_validFilters)) { + //if filter is flat promotion + if($filter == 'flat_promotion') { + //lets set type to filter + $query['type'] = $filter; + //it is not a flat promotion + } else { + //lets set filter to filter + $query['filter'] = $filter; + } + } + + return $this->_getResponse(self::URL_GET_TOPICS, $query); + } + + /** + * Get all replies that a particular user has posted + * + * @param id is integer + * @return this + */ + public function getUserReplies($id, $filter = NULL) { + //argument testing + Eden_Tumblr_Error::get() + ->argument(1, 'integer') //Argument 1 must be a integer + ->argument(2, 'string' ,'null'); //Argument 2 must be a string or null + + $query = array('user_id' => $id); + //if the filter is a short version of a valid filter + if(isset($this->_validFilters[$filter])) { + //make filter the long version + $filter = $this->_validFilters[$filter]; + } + + //if filter is valid + if(in_array($filter, $this->_validFilters)) { + //if filter is flat promotion + if($filter == 'flat_promotion') { + //lets set type to filter + $query['type'] = $filter; + //it is not a flat promotion + } else { + //lets set filter to filter + $query['filter'] = $filter; + } + } + + return $this->_getResponse(self::URL_GET_USERS, $query); + } + + /* 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..c34dd3d --- /dev/null +++ b/library/eden/getsatisfaction/topic.php @@ -0,0 +1,356 @@ + +/* + * 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. + */ + +/** + * + * + * @package Eden + * @category Get Satisfaction + * @author Christian Blanquera + * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ + */ +class Eden_GetSatisfaction_Topic extends Eden_GetSatisfaction_Base { + /* Constants + -------------------------------*/ + const URL_GET_LIST = 'http://api.getsatisfaction.com/topics/%s'; + const URL_GET_ALL_TOPICS = 'http://api.getsatisfaction.com/topics.json'; + const URL_GET_PARTICULAR = 'http://api.getsatisfaction.com/companies/%s/topics.json'; + const URL_GET_SPECIFIC = 'http://api.getsatisfaction.com/products/%s/topics.json'; + const URL_GET_TOPICS_TAG = 'http://api.getsatisfaction.com/companies/%s/tags/%s/topics.json'; + const URL_GET_USER_TOPICS = 'http://api.getsatisfaction.com/people/%s/topics.json'; + const URL_GET_USER_FOLLOWING = 'http://api.getsatisfaction.com/people/%s/followed/topics.json'; + const URL_GET_PRODUCT_TOPICS = 'http://api.getsatisfaction.com/products/%s/topics.json'; + + const URL_SEARCH = 'http://api.getsatisfaction.com?query=%s'; + + const URL_LAST_ACTIVITY = 'http://api.getsatisfaction.com?active_since=%s'; + const URL_USER_ID = 'http://api.getsatisfaction.com?user=%s'; + const URL_COMPANY_ID = 'http://api.getsatisfaction.com?company=%s'; + const URL_PRODUCT_NAME = 'http://api.getsatisfaction.com?product=%s'; + const URL_TAG = 'http://api.getsatisfaction.com?tag=%s'; + const URL_STATUS = 'http://api.getsatisfaction.com?status=%s'; + const URL_UDC = 'http://api.getsatisfaction.com?user_defined_code=%s'; + + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_query = array(); + + protected $_validSort = array( + 'created' => 'recently_created', + 'active' => 'recently_active', + 'replies' => 'most_replies', + 'toos' => 'most_me_toos', + 'priority' => 'priority', + 'answered' => 'answered'); + + protected $_validStyle = array('question','problem','praise','idea','update'); + + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function get($user, $api) { + return self::_getMultiple(__CLASS__, $user, $api); + } + /* Magic + -------------------------------*/ + /* Public Methods + -------------------------------*/ + /** + * Get a specific topic + * + * @param topic is a string + * @param slug is a string + * @param id is a integer + * @return this + */ + public function getList($topic = NULL, $slug = NULL, $id = NULL) { + //Argument Test + Eden_Tumblr_Error::get() + ->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, 'integer' ,'null'); //Argument 3 must be a integer or null + + $query = array(); + //if it is not empty + if(!is_null($topic)) { + //lets put it in query + $query['topic'] = $topic; + } + //if it is not empty + if(!is_null($slug)) { + //lets put it in query + $query['slug'] = $slug; + } + //if it is not empty + if(!is_null($id)) { + //lets put it in query + $query['id'] = $id; + } + + return $this->_getResponse(self::URL_GET_LIST, $query); + } + /** + * Get all topics in all public + * Get Satisfaction communities + * + * @return this + */ + public function getAll() { + + return $this->_getResponse(self::URL_GET_ALL_TOPICS); + } + /** + * Get all topics related to a specific + * product in a particular community + * + * @param id is a integer + * @param name is a string + * @return this + */ + public function getParticular($id = NULL, $name = NULL) { + //Argument Test + Eden_Tumblr_Error::get() + ->argument(1, 'integer', 'null') //Argument 1 must be a integer 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['company_id'] = $id; + } + //if it is not empty + if(!is_null($name)) { + //lets put it in query + $query['company_name'] = $name; + } + + return $this->_getResponse(self::URL_GET_PARTICULAR, $query); + } + /** + * Get all topics related to a specific + * product in a particular community + * + * @param id is a integer + * @param product is a string + * @param name is a string + * @return this + */ + public function getSpecific($id, $product, $name = NULL) { + //Argument Test + Eden_Tumblr_Error::get() + ->argument(1, 'integer') //Argument 1 must be a integer + ->argument(2, 'string') //Argument 2 must be a string + ->argument(3, 'string'); //Argument 3 must be a string + + $query = array('company_id' => $id, 'product_name' => $product); + //if it is not empty + if(!is_null($name)) { + //lets put it in query + $query['company_name'] = $name; + } + + return $this->_getResponse(self::URL_GET_SPECIFIC, $query); + } + /** + * Get all topics tagged with a specific + * tag within a particular community + * + * @param id is a integer + * @param product is a string + * @param name is a string + * @return this + */ + public function getTopicsTag($id, $tag, $name = NULL) { + //Argument Test + Eden_Tumblr_Error::get() + ->argument(1, 'integer') //Argument 1 must be a integer + ->argument(2, 'string') //Argument 2 must be a string + ->argument(3, 'string'); //Argument 3 must be a string + + $query = array('company_id' => $id, 'product_name' => $product); + //if it is not empty + if(!is_null($name)) { + //lets put it in query + $query['company_name'] = $name; + } + + return $this->_getResponse(self::URL_GET_TOPICS_TAG, $query); + } + /** + * Get all topics that a particular user has posted + * (*there is a question about how these numbers are calculated) + * + * @param id is a integer + * @return this + */ + public function getUserTopics($id) { + //Argument Test + Eden_Tumblr_Error::get() + ->argument(1, 'integer'); //Argument 1 must be a integer + + $query = array('id' => $id); + + return $this->_getResponse(self::URL_GET_USER_TOPICS, $query); + } + /** + * Get all topics that a particular user is following + * + * @param id is a integer + * @return this + */ + public function getUserFollowing($id) { + //Argument Test + Eden_Tumblr_Error::get() + ->argument(1, 'integer'); //Argument 1 must be a integer + + $query = array('id' => $id); + + return $this->_getResponse(self::URL_GET_TOPICS_TAG, $query); + } + /** + * Get all topics identified with a specific product + * + * @param name is a string + * @return this + */ + public function getProductTopics($name) { + //Argument Test + Eden_Tumblr_Error::get() + ->argument(1, 'string'); //Argument 1 must be a string + + $query = array('product_name' => $name); + + return $this->_getResponse(self::URL_GET_PRODUCT_TOPICS, $query); + } + /** + * Search for a particular string + * + * @param searh is a string + * @return this + */ + public function search($search) { + //Argument Test + Eden_Tumblr_Error::get() + ->argument(1, 'string'); //Argument 1 must be a string + + $query = array('searh' => $searh); + + return $this->_getResponse(self::URL_SEARCH, $query); + } + /** + * Sort + * + * @return this + */ + public function sort($sort = NULL) { + //Argument Test + Eden_Tumblr_Error::get() + ->argument(1, 'string'); //Argument 1 must be a string + + $query = array(); + //if the sort is a short version of a valid sort + if(isset($this->_validSort[$sort])) { + //make sort the long version + $sort = $this->_validSort[$sort]; + //lets set sort to sort + $query['sort'] = $sort; + } + + return $this->_getResponse(self::URL_TOPICS_CREATED); + } + ////////////////////////////////////////////////////// + public function sortStyle($style) { + //Argumement + Eden_Tumblr_Error::get() + ->argument(1, 'string'); + + $query = array(); + //if the style is a short version of a valid style + if(isset($this->_validStyle[$style])) { + //make style the long style + $sort = $this->_validStyle[$style]; + //lets set style to style + $query['style'] = $style; + } + } + + /** + * Filter by the time of the last activity in + * the community. Time is set in seconds since epoch. + * + * @return this + */ + public function filterLastActivity() { + + return $this->_getResponse(self::URL_LAST_ACTIVITY); + } + /** + * Filter by user ID + * + * @return this + */ + public function filterUser() { + + return $this->_getResponse(self::URL_USER_ID); + } + /** + * Filter by company ID + * + * @return this + */ + public function filterCompany() { + + return $this->_getResponse(self::URL_COMPANY_ID); + } + /** + * Filter by product name + * + * @return this + */ + public function filterProduct() { + + return $this->_getResponse(self::URL_PRODUCT_NAME); + } + /** + * Filter by tag + * + * @return this + */ + public function filterTag() { + + return $this->_getResponse(self::URL_TAG); + } + /** + * Filter by status + * + * @return this + */ + public function filterStatus() { + + return $this->_getResponse(self::URL_STATUS); + } + /** + * Filter by User Defined Code + * + * @return this + */ + public function filterUdc() { + + return $this->_getResponse(self::URL_UDC); + } + /* 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..13f6146 --- /dev/null +++ b/library/eden/tumblr/base.php @@ -0,0 +1,207 @@ + +/* + * 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. + */ + +/** + * Twitter oauth + * + * @package Eden + * @category twitter + * @author Christian Blanquera + * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ + */ +class Eden_Tumblr_Base extends Eden_Oauth_Base { + /* 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'; + const SECRET_KEY = 'akHvmf5Fsoo7U9ztx3triIx2mczWfze3SEgIgaiGBYTlkqD0kN'; + const VERSION_HEADER = 'GData-Version'; + const GDATA_VERSION = 2; + + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_key = NULL; + protected $_secret = NULL; + + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + /* Magic + -------------------------------*/ + public function __construct($key, $secret) { + //argument test + Eden_Twitter_Error::get() + ->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 + -------------------------------*/ + public function getRequestToken() { + return Eden_Oauth::get() + ->getConsumer(self::REQUEST_URL, $this->_key, $this->_secret) + ->useAuthorization() + ->setMethodToPost() + ->setSignatureToHmacSha1() + ->getQueryResponse(); + } + + /** + * Returns the URL used for login. + * + * @param array + * @param string + * @return string + */ + public function getLoginUrl($token, $redirect) { + //Argument tests + Eden_Twitter_Error::get() + ->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; + } + + /** + * Returns the access token + * + * @param string + * @param string + * @return string + */ + public function getAccessToken($token, $secret, $verifier) { + //argument test + Eden_Google_Error::get() + ->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::get() + ->getConsumer(self::ACCESS_URL, $this->_key, $this->_secret) + ->useAuthorization() + ->setMethodToPost() + ->setToken($token, $secret) + ->setVerifier($verifier) + ->setSignatureToHmacSha1() + ->getQueryResponse(); + } + + public function setAccessToken($token, $secret) { + $this->_accessToken = $token; + $this->_accessSecret = $secret; + + return $this; + } + + + /** + * Returns the meta of the last call + * + * @return array + */ + public function getMeta($key = NULL) { + Eden_Google_Error::get()->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::get() + ->getConsumer($url, $this->_key, $this->_secret) + ->setHeaders(self::VERSION_HEADER, self::GDATA_VERSION) + ->setToken($this->_accessToken, $this->_accessSecret) + ->setSignatureToHmacSha1(); + + $response = $rest->getJsonResponse($query); + + $this->_meta = $rest->getMeta(); + + return $response; + } + + /** + * Returns the token from the server + * + * @param array + * @return array + */ + protected function _post($url, $query = array()) { + $headers = array(); + $headers[] = Eden_Oauth_Consumer::POST_HEADER; + + $rest = Eden_Oauth::get() + ->getConsumer($url, $this->_key, $this->_secret) + ->setToken($this->_accessToken, $this->_accessSecret) + ->setSignatureToHmacSha1(); + + //get the authorization parameters as an array + $signature = $rest->getSignature(); + $authorization = $rest->getAuthorization($signature, false); + $authorization = $this->_buildQuery($authorization); + + if(is_array($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::get() + ->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['authorization'] = $authorization; + $this->_meta['headers'] = $headers; + $this->_meta['query'] = $query; + + 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..4952573 --- /dev/null +++ b/library/eden/tumblr/blog.php @@ -0,0 +1,513 @@ + +/* + * 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. + */ + +/** + * + * + * @package Eden + * @category tumblr + * @author Christian Blanquera + * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ + */ +class Eden_Tumblr_Blog extends Eden_Tumblr_Base { + /* Constants + -------------------------------*/ + const URL_GET_LIST = 'http://api.tumblr.com/v2/blog/kamoteche.tumblr.com/info'; + const URL_GET_AVATAR = 'http://api.tumblr.com/v2/blog/kamoteche.tumblr.com/avatar/512'; + const URL_GET_FOLLOWER = 'api.tumblr.com/v2/blog/{tumblr.poptech.org}/followers'; + const URL_GET_POST = 'http://api.tumblr.com/v2/blog/posts.json'; + const URL_GET_DRAFT = 'api.tumblr.com/v2/blog/{kamoteche.tumblr.com}/posts/draft'; + const URL_GET_SUBMISION = 'http://api.tumblr.com/v2/blog/posts/submission.json'; + const URL_ADD_BLOG = 'http://api.tumblr.com/v2/blog/posts.json'; + const URL_UPDATE = 'http://api.tumblr.com/v2/blog/edit.json'; + const URL_REBLOG = 'http://api.tumblr.com/v2/blog/reblog.json'; + const URL_REMOVE = 'http://api.tumblr.com/v2/blog/kamoteche.tumblr.com/post/delete'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_query = array(); + + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function get($user, $api) { + return self::_getMultiple(__CLASS__, $user, $api); + } + /* Magic + -------------------------------*/ + /* Public Methods + -------------------------------*/ + /** + * This method returns general information about the blog, + * such as the title, number of posts, and other high-level data. + * + * @param hostName is a string + * @param apiKey is a string + * @return $this + */ + public function getList($hostName, $apiKey) { + //Argument Test + Eden_Tumblr_Error::get() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'string'); //Argument 2 must be a string + + $query = array('base-hostname' => $hostName, 'api_key' => $apiKey); + + return $this->_getResponse(self::URL_GET_LIST, $query); + } + /** + * You can get a blog's avatar in 9 different sizes. + * The default size is 64x64. + * + * @param hostName is a string + * @param size is an integer + * @return $this + */ + public function getAvatar($hostName, $size = NULL) { + //Argument Test + Eden_Tumblr_Error::get() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'integer', 'null'); //Argument 2 must be a integer or null + + $query = array('base-hostname' => $hostName); + //if it is not empty + if(!is_null($size)) { + //lets put it in the query + $query['size'] = $size; + } + + return $this->_getResponse(self::URL_GET_AVATAR, $query); + } + /** + * Get followers + * + * @param hostName is a string + * @param limit is an integer + * @param offset is an integer + * @return $this + */ + public function getFollower($hostName, $limit = NULL, $offset = NULL) { + //Argument Test + Eden_Tumblr_Error::get() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'integer', 'null') //Argument 2 must be a integer or null + ->argument(3, 'integer', 'null'); //Argument 2 must be a integer or null + + $query = array('base-hostname' => $hostName); + //if it is not empty + if(!is_null($limit)) { + //lets put it in the query + $query['limit'] = $limit; + } + //if it is not empty + if(!is_null($offset)) { + //lets put it in the query + $query['offset'] = $offset; + } + + return $this->_getResponse(self::URL_GET_FOLLOWER, $query); + } + /** + * Retrieve published post such as text, photo, quote, link + * Chat, Audio, Video and Answer + * + * @param hostName is a string + * @param apiKey is a string + * @param type is a string + * @param id is integer + * @param tag is a string + * @param limit is integer + * @param offset is a string + * @param reblog is a boolean + * @param notes is a boolean + * @param format is a string + * @return $this + */ + public function getPost($hostName, $apiKey, $type = NULL, $id = NULL, $tag = NULL, + $limit = NULL, $offset = NULL, $reblog = NULL, $notes = NULL, $format = NULL) { + //Argument Test + Eden_Tumblr_Error::get() + ->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 + ->argument(4, 'integer', 'null') //Argument 4 must be a integer or null + ->argument(5, 'string', 'null') //Argument 5 must be a string or null + ->argument(6, 'integer', 'null') //Argument 6 must be a integer or null + ->argument(7, 'integer', 'null') //Argument 7 must be a integer or null + ->argument(8, 'boolean', 'null') //Argument 8 must be a boolean or null + ->argument(9, 'boolean', 'null') //Argument 9 must be a boolean or null + ->argument(10, 'string', 'null'); //Argument 10 must be a string or null + + + $query = array('base-hostname' => $hostName, 'api_key' => $apiKey); + //if it is not empty + if(!is_null($type)) { + //lets put it in the query + $query['type'] = $type; + } + //if it is not empty + if(!is_null($id)) { + //lets put it in the query + $query['id'] = $id; + } + //if it is not empty + if(!is_null($tag)) { + //lets put it in the query + $query['tag'] = $tag; + } + //if it is not empty + if(!is_null($limit)) { + //lets put it in the query + $query['limit'] = $limit; + } + //if it is not empty + if(!is_null($offset)) { + //lets put it in the query + $query['offset'] = $offset; + } + //if its reblog + if($reblog) { + $query['reblog_info'] = 0; + } + //if its reblog + if($notes) { + $query['notes_info'] = 0; + } + //if it is not empty + if(!is_null($format)) { + //lets put it in the query + $query['format'] = $format; + } + + return $this->_getResponse(self::URL_GET_POST, $query); + } + /** + * Get complete set draft post + * + * @return $this + */ + public function getDraft() { + return $this->_getResponse(self::URL_GET_DRAFT); + } + /** + * Get complete set submmision post + * + * @return $this + */ + public function getSubmission() { + return $this->_getResponse(self::URL_GET_SUBMISION); + } + /** + * Add or create a blog + * + * @param type is string + * @param state is string + * @param tag is string + * @param tweets is string + * @param date is string + * @param markdown is boolean + * @param slug is string + * @return $this + */ + public function add($type, $state = NULL, $tag = NULL, $tweets = NULL, $date = NULL, $markdown = NULL, $slug = NULL) { + //Argument Test + Eden_Tumblr_Error::get() + ->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 + ->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, 'boolean', 'null') //Argument 6 must be a boolean or null + ->argument(7, 'string', 'null'); //Argument 7 must be a string or null + + $query = array('type' => $type); + //if it is not empty + if(!is_null($state)) { + //lets put it in query + $query['state'] = $state; + } + //if it is not empty + if(!is_null($tag)) { + //lets put it in query + $query['tag'] = $tag; + } + //if it is not empty + if(!is_null($tweets)) { + //lets put it in query + $query['tweets'] = $tweets; + } + //if it is not empty + if(!is_null($tweets)) { + //lets put it in query + $query['tweets'] = $tweets; + } + //if it is not empty + if(!is_null($date)) { + //lets put it in query + $query['date'] = $date; + } + //if its markdown + if($markdown) { + $query['markdown'] = 0; + } + //if it is not empty + if(!is_null($slug)) { + //lets put it in query + $query['slug'] = $slug; + } + + $url = sprintf(self::URL_ADD_BLOG, $type); + return $this->_post($url,$query); + } + /** + * Add text + * + * @param body is string + * @param title is string + * @return $this + */ + public function addText($body, $title = NULL) { + //Argument Test + Eden_Tumblr_Error::get() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'string', 'null'); //Argument 2 must be a string or null + + $query = array('body' => $body); + //if it is not empty + if(!is_null($title)) { + //lets put it in query + $query['title'] = $title; + } + + $url = sprintf(self::URL_ADD_BLOG, $body); + return $this->_post($url,$query); + } + /** + * Add photo + * + * @param source is a string + * @param data is array + * @param caption is a string + * @param link is a string + * @return $this + */ + public function addPhoto($source, $data, $caption = NULL, $link = NULL) { + //Argument Test + Eden_Tumblr_Error::get() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'array') //Argument 1 must be a array + ->argument(3, 'string', 'null') //Argument 1 must be a array + ->argument(4, 'string', 'null'); //Argument 2 must be a string or null + + $query = array('body' => $body,'data' =>$data); + //if it is not empty + if(!is_null($caption)) { + //lets put it in query + $query['caption'] = $caption; + } + //if it is not empty + if(!is_null($link)) { + //lets put it in query + $query['link'] = $link; + } + + $url = sprintf(self::URL_ADD_BLOG, $source); + return $this->_post($url,$query); + } + /** + * Add quote + * + * @param quote is a string + * @param source is a string + * @return $this + */ + public function addQuote($quote, $source = NULL) { + //Argument Test + Eden_Tumblr_Error::get() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'string', 'null'); //Argument 1 must be a string + + $query = array('qoute' => $qoute); + //if it is not empty + if(!is_null($source)) { + //lets put it in query + $query['source'] = $source; + } + + $url = sprintf(self::URL_ADD_BLOG, $qoute); + return $this->_post($url,$query); + } + /** + * Add link + * + * @param url is a string + * @param title is a string + * @param description is string + * @return $this + */ + public function addLink($url, $title = NULL, $description = NULL) { + //Argument Test + Eden_Tumblr_Error::get() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'string', 'null') //Argument 2 must be a string + ->argument(3, 'string', 'null'); //Argument 3 must be a string + + $query = array('url' => $url); + //if it is not empty + if(!is_null($title)) { + //lets put it in query + $query['title'] = $title; + } + //if it is not empty + if(!is_null($description)) { + //lets put it in query + $query['description'] = $description; + } + + $url = sprintf(self::URL_ADD_BLOG, $url); + return $this->_post($url,$query); + } + /** + * Add chat + * + * @param conversation is a string + * @param title is a string + * @return $this + */ + public function addChat($conversation, $title = NULL) { + //Argument Test + Eden_Tumblr_Error::get() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'string', 'null'); //Argument 2 must be a string + + $query = array('conversation' => $conversation); + //if it is not empty + if(!is_null($title)) { + //lets put it in query + $query['title'] = $title; + } + + $url = sprintf(self::URL_ADD_BLOG, $conversation); + return $this->_post($url,$query); + } + /** + * Add audio + * + * @param data is a string + * @param externalis a string + * @param caption is a string + * @return $this + */ + public function addAudio($data, $external, $caption = NULL) { + //Argument Test + Eden_Tumblr_Error::get() + ->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 + + $query = array('data' => $data, 'external_url' => $external); + //if it is not empty + if(!is_null($caption)) { + //lets put it in query + $query['caption'] = $caption; + } + + $url = sprintf(self::URL_ADD_BLOG, $data); + return $this->_post($url,$query); + } + /** + * Add video + * + * @param data is string + * @param embed is string + * @param caption is string + * @return $this + */ + public function addVideo($data, $embed, $caption = NULL) { + //Argument Test + Eden_Tumblr_Error::get() + ->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 + + $query = array('data' => $data, 'embed' => $embed); + //if it is not empty + if(!is_null($caption)) { + //lets put it in query + $query['caption'] = $caption; + } + + $url = sprintf(self::URL_ADD_BLOG, $data); + return $this->_post($url,$query); + } + /** + * update blog post + * + * @param $id is a integer + * @return $this + */ + public function update($Id) { + //Argument Test + Eden_Tumblr_Error::get() + ->argument(1, 'integer'); //Argument 1 must be a integer + + $query = array('Id' => $Id); + + $url = sprintf(self::URL_UPDATE, $Id); + return $this->_post($url,$query); + } + /** + * reblog a post + * + * @param id is a integer + * @param reblog is a integer + * @param comment is a string + * @return $this + */ + public function reblog($Id, $reblog, $comment) { + //Argument Test + Eden_Tumblr_Error::get() + ->argument(1, 'integer') //Argument 1 must be a integer + ->argument(2, 'integer') //Argument 2 must be a integer + ->argument(3, 'string'); //Argument 3 must be a integer + + $query = array('Id' => $Id, 'reblog_key' => $reblog); + //if it is not empty + if(!is_null($comment)) { + $query['comment'] = $comment; + } + + $url = sprintf(self::URL_REBLOG, $Id); + return $this->_post($url,$query); + } + /** + * delete a post + * + * @param id is a integer + * @return $this + */ + public function remove($Id) { + //Argument Test + Eden_Tumblr_Error::get() + ->argument(1, 'integer'); //Argument 1 must be a integer + + $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/tumblr/error.php b/library/eden/tumblr/error.php new file mode 100644 index 0000000..d69547a --- /dev/null +++ b/library/eden/tumblr/error.php @@ -0,0 +1,56 @@ + +/* + * 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. + */ + +/** + * Eventbrite Errors + * + * @package Eden + * @category google + * @author Christian Blanquera + * @version $Id: exception.php 1 2010-01-02 23:06:36Z blanquera $ + */ +class Eden_Tumblr_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 + -------------------------------*/ + /* Get + -------------------------------*/ + public static function get($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/tumblr/oauth.php b/library/eden/tumblr/oauth.php new file mode 100644 index 0000000..806cb07 --- /dev/null +++ b/library/eden/tumblr/oauth.php @@ -0,0 +1,44 @@ + +/* + * 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. + */ + +/** + * Twitter oauth + * + * @package Eden + * @category google + * @author Christian Blanquera + * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ + */ +class Eden_Tumblr_Oauth extends Eden_Tumblr_Base { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_key = NULL; + protected $_secret = NULL; + + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function get($key, $secret) { + return self::_getMultiple(__CLASS__, $key, $secret); + } + + /* Magic + -------------------------------*/ + /* Public Methods + -------------------------------*/ + /* 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..37f0b7b --- /dev/null +++ b/library/eden/tumblr/user.php @@ -0,0 +1,248 @@ + +/* + * 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. + */ + +/** + * + * + * @package Eden + * @category tumblr + * @author Christian Blanquera + * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ + */ +class Eden_Tumblr_User extends Eden_Tumblr_Base { + /* Constants + -------------------------------*/ + const URL_GET_LIST = 'http://api.tumblr.com/v2/user/info'; + const URL_GET_USER = '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 $_query = array(); + + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function get($user, $api) { + return self::_getMultiple(__CLASS__, $user, $api); + } + /* Magic + -------------------------------*/ + /* Public Methods + -------------------------------*/ + /** + * Use this method to retrieve the user's account information + * that matches the OAuth credentials submitted with the request. + * + * @return $this + */ + public function getList() { + $url = sprintf(self::URL_GET_LIST); + return $this->_post($url); + } + /** + * Use this method to retrieve the dashboard that matches + * the OAuth credentials submitted with the request. + * + * @param limit is integer + * @param offset is integer + * @param type is string + * @param since is integer + * @param reblog is boolean + * @param notes is boolean + * @return $this + */ + public function getUser($limit = NULL, $offset = NULL, $type = NULL, $since = NULL, $reblog = NULL, $notes = NULL) { + //Argument Test + Eden_Tumblr_Error::get() + ->argument(1, 'integer') //Argument 1 must be a integer + ->argument(2, 'integer') //Argument 2 must be a integer + ->argument(3, 'string') //Argument 3 must be a string + ->argument(4, 'integer') //Argument 4 must be a integer + ->argument(5, 'boolean') //Argument 5 must be a boolean + ->argument(6, 'boolean'); //Argument 6 must be a boolean + + $query = array(); + //if it is not empty + if(!is_null($limit)) { + //lets put it in the query + $query['limit'] = $limit; + } + //if it is not empty + if(!is_null($offset)) { + //lets put it in the query + $query['offset'] = $offset; + } + //if it is not empty + if(!is_null($type)) { + //lets put it in the query + $query['type'] = $type; + } + //if it is not empty + if(!is_null($since)) { + //lets put it in the query + $query['since_id'] = $since; + } + //if it is reblog + if($reblog) { + $query['reblog_info'] = 0; + } + //if it is notes + if($notes) { + $query['notes_info'] = 0; + } + + return $this->_getResponse(self::URL_GET_USER); + } + /** + * Use this method to retrieve the liked posts that + * match the OAuth credentials submitted with the request. + * + * @param limit is integer + * @param offset is integer + * @return $this + */ + public function getLikes($limit = NULL, $offset = NULL) { + //Argument Test + Eden_Tumblr_Error::get() + ->argument(1, 'integer') //Argument 1 must be a integer + ->argument(2, 'integer'); //Argument 2 must be a integer + + $query = array(); + //if it is not empty + if(!is_null($limit)) { + //lets put it in the query + $query['limit'] = $limit; + } + //if it is not empty + if(!is_null($offset)) { + //lets put it in the query + $query['offset'] = $offset; + } + + return $this->_getResponse(self::URL_GET_LIKES); + } + /** + * Use this method to retrieve the blogs followed by the user + * whose OAuth credentials are submitted with the request. + * + * @param limit is integer + * @param offset is integer + * @return $this + */ + public function getFollowing($limit = NULL, $offset = NULL) { + //Argument Test + Eden_Tumblr_Error::get() + ->argument(1, 'integer') //Argument 1 must be a integer + ->argument(2, 'integer'); //Argument 2 must be a integer + + $query = array(); + //if it is not empty + if(!is_null($limit)) { + //lets put it in the query + $query['limit'] = $limit; + } + //if it is not empty + if(!is_null($offset)) { + //lets put it in the query + $query['offset'] = $offset; + } + + return $this->_getResponse(self::URL_GET_FOLLOWING); + } + /** + * Follow a blog + * + * @param url is string + * @return $this + */ + public function follow($url) { + //Argument Test + Eden_Tumblr_Error::get() + ->argument(1, 'string'); //Argument 1 must be a string + + $query = array('url' => $url); + + $url = sprintf(self::URL_FOLLOW, $url); + return $this->_post($url,$query); + } + /** + * Unfollow a blog + * + * @param url is string + * @return $this + */ + public function unfollow($url) { + //Argument Test + Eden_Tumblr_Error::get() + ->argument(1, 'string'); //Argument 1 must be a string + + $query = array('url' => $url); + + $url = sprintf(self::URL_UNFOLLOW, $url); + return $this->_post($url,$query); + } + /** + * Like a post + * + * @param id is integer + * @param reblog is string + * @return $this + */ + public function like($id, $reblog) { + //Argument Test + Eden_Tumblr_Error::get() + ->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); + } + /** + * Unlike a post + * + * @param id is integer + * @param reblog is string + * @return $this + */ + public function unlike($id, $reblog) { + //Argument Test + Eden_Tumblr_Error::get() + ->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/accounts.php b/library/eden/twitter/accounts.php new file mode 100644 index 0000000..7b5f5a0 --- /dev/null +++ b/library/eden/twitter/accounts.php @@ -0,0 +1,280 @@ + +/* + * 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. + */ + +/** + * Eventbrite new or update discount + * + * @package Eden + * @category eventbrite + * @author Christian Blanquera + * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ + */ +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 $_query = array(); + + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function get($key, $secret) { + return self::_getMultiple(__CLASS__, $key, $secret); + } + + /* Magic + -------------------------------*/ + /* Public Methods + -------------------------------*/ + /** + * Returns the remaining number of API requests available to the + * requesting user before the API limit is reached for the current hour. + * + * @return $this + */ + public function getLimit() { + + return $this->_getResponse(self::URL_LIMIT_STATUS); + } + /** + * Returns an HTTP 200 OK response code and a representation of the requesting user + * if authentication was successful; returns a 401 status code and an error message if not. + * + * @param name is string + * @param size is integer + * @return $this + */ + public function getCredentials($entities = false, $status = false) { + //Argument Test + Eden_Twitter_Error::get() + ->argument(1, 'boolean') //Argument 1 must be a string or integer + ->argument(2, 'boolean'); //Argument 2 must be a string or integer + + $query = array(); + //if entities + if($entities) { + $query['include_entities'] = 1; + } + //if status + if($status) { + $query['skip_status'] = 1; + } + + return $this->_getResponse(self::URL_VERIFY_CREDENTIALS, $query); + } + /** + * 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 $this + */ + public function logOut() { + + return $this->_post(self::URL_END_SESSION); + } + /** + * Sets values that users are able to set under the "Account" tab + * of their settings page. Only the parameters specified will be updated. + * + * @param name is string + * @param size is integer + * @return $this + */ + public function updateProfile($name = NULL, $url = NULL, $location = NULL, $description = NULL, $entities = NULL, $status = NULL) { + //Argument Test + Eden_Twitter_Error::get() + ->argument(1, 'string') //Argument 1 must be a string or integer + ->argument(2, 'string') //Argument 1 must be a string or integer + ->argument(3, 'string') //Argument 1 must be a string or integer + ->argument(4, 'string') //Argument 1 must be a string or integer + ->argument(5, 'boolean') //Argument 1 must be a string or integer + ->argument(8, 'boolean'); //Argument 2 must be a string or integer + + $query = array(); + //if it is not empty + if(!is_null($name) && $name <= 20) { + //lets put it in query + $query['name'] = $name; + } + //if it is not empty + if(!is_null($url) && $url <= 100) { + //lets put it in query + $query['url'] = $url; + } + //if it is not empty + if(!is_null($location) && $location <= 30) { + //lets put it in query + $query['location'] = $location; + } + //if it is not empty + if(!is_null($description) && $description <= 160) { + //lets put it in query + $query['description'] = $description; + } + //if entities + if($entities) { + $query['include_entities'] = 1; + } + //if status + if($status) { + $query['skip_status'] = 1; + } + + return $this->_post(self::URL_UPDATE_PROFILE, $query); + } + /** + * Sets values that users are able to set under the "Account" tab + * of their settings page. Only the parameters specified will be updated. + * + * @param name is string + * @param size is integer + * @return $this + */ + public function updateBackground($image = NULL, $tile = NULL, $entities = NULL, $status = NULL, $use = false) { + //Argument Test + Eden_Twitter_Error::get() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'string') //Argument 1 must be a string + ->argument(3, 'boolean') //Argument 1 must be a boolean + ->argument(4, 'boolean') //Argument 1 must be a boolean + ->argument(5, 'boolean'); //Argument 1 must be a boolean + + $query = array(); + //if it is not empty + if(!is_null($image)) { + //lets put it in query + $query['image'] = $image; + } + //if it is not empty + if(!is_null($tile)) { + //lets put it in query + $query['tile'] = $tile; + } + //if entities + if($entities) { + $query['include_entities'] = 1; + } + //if status + if($status) { + $query['skip_status'] = 1; + } + //if status + if($use) { + $query['use'] = 1; + } + + 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. + * + * @param name is string + * @param size is integer + * @return $this + */ + public function updateColor($background = NULL, $link = NULL, $border = NULL, $fill = NULL, $text = NULL, $entities = false, $status = false) { + //Argument Test + Eden_Twitter_Error::get() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'string') //Argument 1 must be a string + ->argument(3, 'string') //Argument 1 must be a string + ->argument(4, 'string') //Argument 1 must be a string + ->argument(5, 'string') //Argument 1 must be a string + ->argument(6, 'boolean') //Argument 1 must be a boolean + ->argument(7, 'boolean'); //Argument 1 must be a boolean + + $query = array(); + //if it is not empty + if(!is_null($background)) { + //lets put it in query + $query['profile_background_color'] = $background; + } + //if it is not empty + if(!is_null($link)) { + //lets put it in query + $query['profile_link_color'] = $link; + } + //if it is not empty + if(!is_null($border)) { + //lets put it in query + $query['profile_sidebar_border_color'] = $border; + } + //if it is not empty + if(!is_null($fill)) { + //lets put it in query + $query['profile_sidebar_fill_color'] = $fill; + } + //if it is not empty + if(!is_null($text)) { + //lets put it in query + $query['profile_text_color '] = $text; + } + //if entities + if($entities) { + $query['include_entities'] = 1; + } + //if status + if($status) { + $query['skip_status'] = 1; + } + + return $this->_post(self::URL_UPDATE_PROFILE_COLOR, $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 index 35a9a88..5929023 100644 --- a/library/eden/twitter/base.php +++ b/library/eden/twitter/base.php @@ -1,218 +1,157 @@ - -/* - * 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. - */ - -/** - * Twitter oauth - * - * @package Eden - * @category twitter - * @author Christian Blanquera - * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ - */ -class Eden_Twitter_Base extends Eden_Oauth_Base { - /* Constants - -------------------------------*/ - const REQUEST_URL = 'http://api.twitter.com/oauth/request_token'; - const AUTHORIZE_URL = 'http://api.twitter.com/oauth/authorize'; - - const SECRET_KEY = 'twitter_token_secret'; - - /* Public Properties - -------------------------------*/ - /* Protected Properties - -------------------------------*/ - protected $_key = NULL; - protected $_secret = NULL; - - /* Private Properties - -------------------------------*/ - /* Get - -------------------------------*/ - /* Magic - -------------------------------*/ - public function __construct($key, $secret) { - //argument test - Eden_Twitter_Error::get() - ->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 URL used for login. - * - * @param string - * @return string - */ - public function getLoginUrl($redirect) { - //Argument 1 must be a string - Eden_Google_Error::get()->argument(1, 'string'); - - //get the token - $token = Eden_Oauth::get() - ->getConsumer(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; - } - - /** - * Returns the access token - * - * @param string - * @param string - * @return string - */ - public function getAccessToken($token, $secret) { - //argument test - Eden_Google_Error::get() - ->argument(1, 'string') //Argument 1 must be a string - ->argument(2, 'string'); //Argument 2 must be a string - - return Eden_Oauth::get() - ->getConsumer(self::ACCESS_URL, $this->_key, $this->_secret) - ->useAuthorization() - ->setMethodToPost() - ->setToken($token, $secret) - ->setSignatureToHmacSha1() - ->getQueryResponse(); - } - - public function setAccessToken($token, $secret) { - $this->_accessToken = $token; - $this->_accessSecret = $secret; - - return $this; - } - - - /** - * Returns the meta of the last call - * - * @return array - */ - public function getMeta($key = NULL) { - Eden_Google_Error::get()->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::get() - ->getConsumer($url, $this->_key, $this->_secret) - ->setHeaders(self::VERSION_HEADER, self::GDATA_VERSION) - ->setToken($this->_accessToken, $this->_accessSecret) - ->setSignatureToHmacSha1(); - - $response = $rest->getJsonResponse($query); - - $this->_meta = $rest->getMeta(); - - return $response; - } - - /** - * Returns the token from the server - * - * @param array - * @return array - */ - protected function _post($url, $query = array()) { - $headers = array(); - $headers[] = Eden_Oauth_Consumer::POST_HEADER; - - $rest = Eden_Oauth::get() - ->getConsumer($url, $this->_key, $this->_secret) - ->setToken($this->_accessToken, $this->_accessSecret) - ->setSignatureToHmacSha1(); - - //get the authorization parameters as an array - $signature = $rest->getSignature(); - $authorization = $rest->getAuthorization($signature, false); - $authorization = $this->_buildQuery($authorization); - - if(is_array($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::get() - ->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['authorization'] = $authorization; - $this->_meta['headers'] = $headers; - $this->_meta['query'] = $query; - - return $response; - } - - /* Private Methods - -------------------------------*/ + +/* + * 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. + */ + +/** + * Twitter oauth + * + * @package Eden + * @category twitter + * @author Christian Blanquera + * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ + */ +class Eden_Twitter_Base extends Eden_Oauth_Base { + /* Constants + -------------------------------*/ + const REQUEST_URL = 'http://api.twitter.com/oauth/request_token'; + const AUTHORIZE_URL = 'http://api.twitter.com/oauth/authorize'; + const ACCESS_URL = 'https://api.twitter.com/oauth/access_token'; + const SECRET_KEY = 'twitter_token_secret'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_key = NULL; + protected $_secret = NULL; + + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + /* Magic + -------------------------------*/ + public function __construct($key, $secret) { + //argument test + Eden_Twitter_Error::get() + ->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 + -------------------------------*/ + public function getRequestToken() { + return Eden_Oauth::get() + ->getConsumer(self::REQUEST_URL, $this->_key, $this->_secret) + ->useAuthorization() + ->setMethodToPost() + ->setSignatureToHmacSha1() + ->getQueryResponse(); + } + + /** + * Returns the URL used for login. + * + * @param array + * @param string + * @return string + */ + public function getLoginUrl($token, $redirect) { + //Argument tests + Eden_Twitter_Error::get() + ->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; + } + + /** + * Returns the access token + * + * @param string + * @param string + * @return string + */ + public function getAccessToken($token, $secret) { + //argument test + Eden_Google_Error::get() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'string'); //Argument 2 must be a string + + return Eden_Oauth::get() + ->getConsumer(self::ACCESS_URL, $this->_key, $this->_secret) + ->useAuthorization() + ->setMethodToPost() + ->setToken($token, $secret) + ->setSignatureToHmacSha1() + ->getQueryResponse(); + } + + public function setAccessToken($token, $secret) { + $this->_accessToken = $token; + $this->_accessSecret = $secret; + + return $this; + } + + + /** + * Returns the meta of the last call + * + * @return array + */ + public function getMeta($key = NULL) { + Eden_Google_Error::get()->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::get() + ->getConsumer($url, $this->_key, $this->_secret) + ->setToken($this->_accessToken, $this->_accessSecret) + ->setSignatureToHmacSha1(); + + $response = $rest->getJsonResponse($query); + + $this->_meta = $rest->getMeta(); + + return $response; + } + + protected function _post($url, $query = array()) { + $rest = Eden_Oauth::get() + ->getConsumer($url, $this->_key, $this->_secret) + ->setToken($this->_accessToken, $this->_accessSecret) + ->setMethodToPost() + ->useAuthorization() + ->setSignatureToHmacSha1(); + + $response = $rest->getJsonResponse($query); + + $this->_meta = $rest->getMeta(); + + return $response; + } + + /* 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..7888bcf --- /dev/null +++ b/library/eden/twitter/favorites.php @@ -0,0 +1,130 @@ + +/* + * 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. + */ + +/** + * Eventbrite new or update discount + * + * @package Eden + * @category eventbrite + * @author Christian Blanquera + * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ + */ +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 + -------------------------------*/ + protected $_query = array(); + + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function get($key, $secret) { + return self::_getMultiple(__CLASS__, $key, $secret); + } + + /* Magic + -------------------------------*/ + /* Public Methods + -------------------------------*/ + /** + * Returns the 20 most recent favorite statuses for the authenticating + * user or user specified by the ID parameter in the requested format. + * + * @param id is string or integer + * @param since is integer + * @param page is integer + * @param entities is boolean + * @return $this + */ + public function getList($id = NULL, $since = NULL, $page = NULL, $entities = false) { + //Argument Test + Eden_Twitter_Error::get() + ->argument(1, 'int', 'string', 'null') //Argument 1 must be a string or integer + ->argument(2, 'int', 'null') //Argument 1 must be an integer + ->argument(3, 'int', 'null') //Argument 4 must be an integer + ->argument(4, 'boolean'); //Argument 4 must be a boolean + + $query = array(); + //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; + } + //if entities + if($entities) { + $query['include_entities'] = 1; + } + + return $this->_getResponse(self::URL_GET_FAVORITES, $query); + } + /** + * Favorites the status specified in the ID parameter as the authenticating + * user. Returns the favorite status when successful. + * + * @param id is integer + * @param entities is boolean + * @return $this + */ + public function addFavorite($id, $entities = false) { + //Argument Test + Eden_Twitter_Error::get() + ->argument(1, 'int') //Argument 1 must be an integer + ->argument(2, 'boolean'); //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); + } + /** + * n-favorites the status specified in the ID parameter as the authenticating user. + * + * @param id is integer + * @return $this + */ + public function removeFavorite($id) { + //Argument Test + Eden_Twitter_Error::get() + ->argument(1, 'int'); //Argument 1 must be na integer + + $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/list.php b/library/eden/twitter/list.php new file mode 100644 index 0000000..e5d7a9b --- /dev/null +++ b/library/eden/twitter/list.php @@ -0,0 +1,163 @@ + +/* + * 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. + */ + +/** + * Eventbrite new or update discount + * + * @package Eden + * @category eventbrite + * @author Christian Blanquera + * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ + */ +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'; + + + + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_query = array(); + + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function get($key, $secret) { + return self::_getMultiple(__CLASS__, $key, $secret); + } + + /* Magic + -------------------------------*/ + /* Public Methods + -------------------------------*/ + /** + * Returns all lists the authenticating or specified user + * subscribes to, including their own. + * + * @param name is string + * @param size is integer + * @return $this + */ + public function getList($id = NULL, $name = NULL) { + //Argument Test + Eden_Twitter_Error::get() + ->argument(1, 'int','string','null') //Argument 1 must be a string or integer + ->argument(2, 'int','string','null'); //Argument 2 must be a string or integer + + $query = array(); + + //if it is not empty + if(!is_null($id)) { + //if it is integer + if(is_int($id)) { + //lets put it in our query + $query['user_id'] = $id; + } + //if it is string + if(is_string($id)) { + //lets put it in our query + $query['screen_name'] = $id; + } + } + //if it is not empty + if(!is_null($name)) { + //if it is string + if(is_string($name)) { + //lets put it in our query + $query['screen_name'] = $name; + } + //if it is integer + if(is_int($name)) { + //lets put it in our query + $query['user_name'] = $name; + } + } + + return $this->_getResponse(self::URL_ALL_LIST, $query); + } + /** + * Returns tweet timeline for members of the specified list. + * + * @param name is string + * @param size is integer + * @return $this + + public function getStatus($id, $slug, $ownerName = NULL, $ownerId = NULL, $since = NULL, $max = NULL, $perpage = NULL, $entities = NULL, $rts = NULL) { + //Argument Test + Eden_Twitter_Error::get() + ->argument(1, 'int') //Argument 1 must be a string or integer + ->argument(2, 'string') //Argument 2 must be a string or integer + ->argument(3, 'int','string','null') //Argument 2 must be a string or integer + ->argument(4, 'int','null') //Argument 2 must be a string or integer + ->argument(5, 'int','null') //Argument 2 must be a string or integer + ->argument(6, 'int','null') //Argument 2 must be a string or integer + ->argument(7, 'int','null') //Argument 2 must be a string or integer + ->argument(8, 'boolean','null') //Argument 2 must be a string or integer + ->argument(9, 'boolean','null'); //Argument 2 must be a string or integer + + $query = array('list_id' => $id, + 'slug' => $slug); + //if it is not empty + if(!is_null($ownerName)) { + //lets put it in our query + $query['owner_name'] = $ownerName; + } + //if it is not empty + if(!is_null($ownerId)) { + //lets put it in our query + $query['owner_id'] = $ownerId; + } + //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($max)) { + //lets put it in our query + $query['max_id'] = $max; + } + //if it is not empty + if(!is_null($perpage)) { + //lets put it in our query + $query['per_page'] = $perpage; + } + //if entities + if($entities) { + $query['include_entities'] = 1; + } + //if rts + if($rts) { + $query['rts'] = 1; + } + + return $this->_getResponse(self::URL_GET_STATUS, $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..73b180b --- /dev/null +++ b/library/eden/twitter/suggestions.php @@ -0,0 +1,110 @@ + +/* + * 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. + */ + +/** + * Eventbrite new or update discount + * + * @package Eden + * @category eventbrite + * @author Christian Blanquera + * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ + */ +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 + -------------------------------*/ + protected $_query = array(); + + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function get($key, $secret) { + return self::_getMultiple(__CLASS__, $key, $secret); + } + + /* Magic + -------------------------------*/ + /* Public Methods + -------------------------------*/ + /** + * Access to Twitter's suggested user list. + * + * @param lang is string + * @return $this + */ + public function getSuggestion($lang = NULL) { + //Argument Test + Eden_Twitter_Error::get() + ->argument(1, 'string', 'null'); //Argument 1 must be a string or integer + + $query = array(); + //if it is not empty + if(!is_null($lang)) { + //lets put it in our query + $query['lang'] = $lang; + } + + return $this->_getResponse(self::URL_SUGGESTION, $query); + } + /** + * Access the users in a given category of the + * Twitter suggested user list.. + * + * @param slug is string + * @param lang is integer + * @return $this + */ + public function getCategory($slug, $lang = NULL) { + //Argument Test + Eden_Twitter_Error::get() + ->argument(1, 'string', 'null') //Argument 1 must be a string + ->argument(2, 'string', 'null'); //Argument 1 must be a string + + $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 slug is string + * @return $this + */ + public function getRecentStatus($slug) { + //Argument Test + Eden_Twitter_Error::get() + ->argument(1, 'string', 'null'); //Argument 1 must be a string + + $query = array('slug' => $slug); + + return $this->_getResponse(self::URL_GET_RECENT_STATUS, $query); + } + + /* 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..5b54cf6 --- /dev/null +++ b/library/eden/twitter/users.php @@ -0,0 +1,277 @@ + +/* + * 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. + */ + +/** + * Eventbrite new or update discount + * + * @package Eden + * @category eventbrite + * @author Christian Blanquera + * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ + */ +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 $_query = array(); + + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function get($key, $secret) { + return self::_getMultiple(__CLASS__, $key, $secret); + } + + /* Magic + -------------------------------*/ + /* Public Methods + -------------------------------*/ + /** + * Return up to 100 users worth of extended information, + * specified by either ID, screen name, or combination of the two. + * + * @param id is string or integer + * @param netities is boolean + * @return $this + */ + public function lookupFriends($id = NULL, $entities = false) { + //Argument Test + Eden_Twitter_Error::get() + ->argument(1, 'int', 'string') //Argument 1 must be a string or integer + ->argument(2, 'boolean'); //Argument 1 must be a boolean + + $query = array(); + //if it is not empty + if(!is_null($id)) { + //if id is integer + if(is_int($id)) { + $id = explode(',', $id); + //lets put it in query + $query['user_id'] = $id; + } + //if id is string + if(is_string($id)) { + $id = explode(',', $id); + //at this poit id will be an array + $id = array(); + $query['screen_name'] = $id; + + + //lets put it in query + //$query['screen_name'] = $id; + } + } + + return $this->_getResponse(self::URL_LOOK_UP, $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. + * + * @param name is string + * @param size is integer + * @return $this + */ + public function getProfileImage($name = NULL, $size = NULL) { + //Argument Test + Eden_Twitter_Error::get() + ->argument(1, 'string', 'null') //Argument 1 must be a string + ->argument(2, 'string', 'null'); //Argument 2 must be a string + + $query = array(); + //if it is not empty + if(!is_null($name)) { + //lets put it in query + $query['screen_name'] = $name; + } + //if it is not empty + if(!is_null($size)) { + //lets put it in query + $query['size'] = $size; + } + + + return $this->_getResponse(self::URL_PROFILE_IMAGE, $query); + } + /** + * Runs a search for users similar to Find People button on Twitter.com. + * + * @param name is string + * @param size is integer + * @return $this + */ + public function search($q, $page = NULL, $perpage = NULL, $entities = false) { + //Argument Test + Eden_Twitter_Error::get() + ->argument(1, 'string','int','null') //Argument 1 must be a string or integer + ->argument(2, 'int', 'null') //Argument 2 must be an integer + ->argument(3, 'int', 'null') //Argument 3 must be an integer + ->argument(4, 'boolean'); //Argument 4 must be a boolean + + $query = array('q' => $q); + //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) && $perpage <= 20) { + //lets put it in query + $query['per_page'] = $perpage; + } + //if entities + if($entities) { + $query['include_entities'] = 1; + } + + + return $this->_getResponse(self::URL_SEARCH, $query); + } + /** + * Returns extended information of a given user, specified + * by ID or screen name as per the required id parameter. + * + * @param id is string or integer + * @param entities is boolean + * @return $this + */ + public function getDetail($id, $entities = false) { + //Argument Test + Eden_Twitter_Error::get() + ->argument(1, 'string','int') //Argument 1 must be a string or integer + ->argument(2, 'boolean'); //Argument 4 must be a boolean + + $query = array('user_id', 'screen_name' => $id); + //if entities + if($entities) { + $query['include_entities'] = 1; + } + + + return $this->_getResponse(self::URL_SHOW, $query); + } + /** + * Returns an array of users that the specified user can contribute to. + * + * @param name is string + * @param size is integer + * @return $this + */ + public function getContributees($id = NULL, $name = NULL, $entities = false, $status = false) { + //Argument Test + Eden_Twitter_Error::get() + ->argument(1, 'int', 'null') //Argument 1 must be a string or integer + ->argument(2, 'int','string', 'null') //Argument 1 must be a string or integer + ->argument(3, 'boolean') //Argument 4 must be a boolean + ->argument(4, 'boolean'); //Argument 4 must be a boolean + + $query = array(); + //if it is not empty + if(!is_null($id)) { + //lets put it in our query + $query['user_id'] = $id; + } + //if it is not empty + if(!is_null($name)) { + //lets put it in our query + $query['screen_name'] = $name; + } + //if entities + if($entities) { + $query['include_entities'] = 1; + } + //if entities + if($status) { + $query['skip_status'] = 1; + } + + return $this->_getResponse(self::URL_CONTRIBUTEES, $query); + } + /** + * Returns an array of users that the specified user can contribute to. + * + * @param name is string + * @param size is integer + * @return $this + */ + public function getContributors($id = NULL, $name = NULL, $entities = false, $status = false) { + //Argument Test + Eden_Twitter_Error::get() + ->argument(1, 'int', 'null') //Argument 1 must be a string or integer + ->argument(2, 'int','string', 'null') //Argument 1 must be a string or integer + ->argument(3, 'boolean') //Argument 4 must be a boolean + ->argument(4, 'boolean'); //Argument 4 must be a boolean + + $query = array(); + //if it is not empty + if(!is_null($id)) { + //lets put it in our query + $query['user_id'] = $id; + } + //if it is not empty + if(!is_null($name)) { + //lets put it in our query + $query['screen_name'] = $name; + } + //if entities + if($entities) { + $query['include_entities'] = 1; + } + //if entities + if($status) { + $query['skip_status'] = 1; + } + + return $this->_getResponse(self::URL_CONTRIBUTORS, $query); + } + + + + + + + + + + + + + + + + + + + + + + + + + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ + + +} diff --git a/site/web/sy.php b/site/web/sy.php new file mode 100644 index 0000000..f38449a --- /dev/null +++ b/site/web/sy.php @@ -0,0 +1,48 @@ + +require_once dirname(__FILE__).'/../../library/eden.php'; + +eden(); + +class Eden_Timezone extends Eden_Class { + + public static function get() { + return self::_getSingleton(__CLASS__); + } + + public function getOffset($source, $destination) { + //source and destination will be in abbr format + //we need to figure out the full text format + $source = timezone_name_from_abbr($source); //should now be Europe/Berlin for example + $destination = timezone_name_from_abbr($destination); //should now be Europe/Berlin for example + + //now lets put that into DateTimeZone to get the offset + $source = new DateTimeZone($source); + $destination = new DateTimeZone($destination); + $gmt = new DateTimeZone('UTC'); + + //get GMT now + $gmt = new DateTime('now', $gmt); + + //get offset for each + $source = $source->getOffset($gmt); + $destination = $destination->getOffset($gmt); + + //calculate difference + return $destination - $source; + } + + public function convertTime($time, $source ,$destination) { + //fugureout whats the diff of tw0 timezone + //add or subtract the time according from diff + return $time + $this->getOffset($source, $destination); + } + +} + +echo date('F d, Y g:iA', Eden_Timezone::get()->convertTime(time(), 'HKT', 'PDT')); + + + + + +//echo eden()->User('Chris')->getName(); diff --git a/site/web/symon.php b/site/web/symon.php new file mode 100644 index 0000000..2ca7c3a --- /dev/null +++ b/site/web/symon.php @@ -0,0 +1,368 @@ + +/* + * 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 dirname(__FILE__).'/../front.php'; + +/* Get Application +-------------------------------*/ +front() + +/* Set Debug +-------------------------------*/ +->setDebug(E_ALL, true) + +/* Set Autoload +-------------------------------*/ +->addRoot(dirname(__FILE__).'/..') +->addRoot(dirname(__FILE__).'/../model') + +/* Set Class Routing +-------------------------------*/ +->setClasses('../front/config/classes.php') + +/* Set Method Routing +-------------------------------*/ +->setMethods('../front/config/methods.php') + +/* Set Paths +-------------------------------*/ +->setPaths(); + +/////////////////////////////////////////////////////////////////////////////////////////////////// +session_start(); + +$tweets = front()->Eden_Twitter_Timelines('xm8mraLDw2mgA1b2SKAaA','dpUyjXhxSbO3inhlqX5DaSPlLsfV2gwMaEKaSQ0WKns'); + +echo 'GET
'.print_r($_GET, true).'
'; +echo 'SESSION
'.print_r($_SESSION, true).'
'; + +//if user wants to logout +if(isset($_GET['logout'])) { + //log them out + unset($_SESSION['request_token'], $_SESSION['request_token_secret'], $_SESSION['access_token'], $_SESSION['access_token_secret']); + header('Location: /symon.php'); +} + +//if the user is logged in +if(isset($_SESSION['access_token'], $_SESSION['access_token_secret'])) { + //lets do shit + //ACCOUNTS + //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->updateColor(); + //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->updateBackground(); + //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->updateProfile('sy buenavista','openovate.com','carmona','small'); + //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->logOut(); + //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->getCredentials(); + //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->getLimit(); + //LIST + //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->getStatus(); + //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->getList(297169759); + //FAVORITES + //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->removeFavorite(139245530340532224); + //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->addFavorite(139245530340532224); + //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->getList('sy'); + //SUGGESTIONS + //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->getRecentStatus('philippines'); + //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->getCategory('taylorswift13'); + //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->getSuggestion(); + //USERS + //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->getContributors(17919972,'taylorswift13'); + //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->getDetail('taylorswift13'); + //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->search('taylorswift13'); + //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->getProfileImage('iamsuperbianca'); + //SEARCH + //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->search('test'); + //TIMELINES + //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->getByUser('sy'); + //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->getToUser('symon','sy'); + //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->getList('Qginalyn'); + //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->getOf(3); + //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->getTo(3); + //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->getBy(3); + //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->getPublic(); + //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->getMention(5); + //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->getTimeline(5); + // + //DIRECTMESSAGE + //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->getSent(); + //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->getSent(); + //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->newMessage('sdaas','sybuena2') + //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->remove(138532788428226560); + //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->getList('kamoteche','cblanquera'); + //tweets + //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->getWhoRetweetedIds(139161266102079488); + //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->getRetweets(139161266102079488); + //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->remove(138542385809469440); + //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->retweet(138558867679354880); + //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->update('test api again'); + //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->getDetail(138507381846970369); + //FRIENDS + //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->getNoRetweets(); + //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->update('XianLimm'); + //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->getDetail('symon','sy'); + //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->getFollowers('sy'); + //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->incomingFriends(); + //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->outgoingFriends(); + //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->friendsExist('kamoteche','cblanquera'); + //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->getFriends('kamoteche'); + //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->unfollowFriends('iamjohnprats'); + //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->followFriends('iamjohnprats'); + + + + /* + $timeline = array(); + + //get tweets + $response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->getPublic(); + print_r($response); + //set default timezone to america/los angeles + date_default_timezone_set('America/Los_Angeles'); + //for each tweet + foreach($response as $tweet) { + //get the unix time this item was created + $time = strtotime($tweet['created_at']); + //mark item as twitter + $tweet['social_media'] = 'twitter'; + //put this item in our global timeline + $timeline[$time] = $tweet; + } + + //get tumblr list + //for each tumblr + //get the unix time this item was created + //mark item as tumblr + //put this item in our global timeline + + //get facebook list + //for each facebook + //get the unix time this item was created + //mark item as facebook + //put this item in our global timeline + + krsort($timeline); + + ?> + + ------------------!!!!!!!!!!!!!!!!!!!!!!!!!!!!----------------------
+ + +
+ +


+


+ + + + + + + ------------------!!!!!!!!!!!!!!!!!!!!!!!!!!!!---------------------- + */ + + //print_r($response); + //print_r($tweets->getMeta()); + +//if the user just authorized us +} else if(isset($_GET['oauth_token'])) { + //upgrade one time access token to another access token that will last for 1 hour + $token = $tweets->getAccessToken($_GET['oauth_token'], $_SESSION['request_token_secret']); + + //store this upgraded access token in our user session + $_SESSION['access_token'] = $token['oauth_token']; + $_SESSION['access_token_secret'] = $token['oauth_token_secret']; + + //redirect + header('Location: /symon.php'); + +//the user at this point is logged out +} else { + //get the request token + $token = $tweets->getRequestToken(); + $_SESSION['request_token'] = $token['oauth_token']; + $_SESSION['request_token_secret'] = $token['oauth_token_secret']; + + //prompt user to login + echo 'Login'; +} + + +//////////////////////////////////////////////////////////////////// + +$tumblr = front()->Eden_Tumblr_User('49Sb8LrxMKh4lErDN69yp6VwgCmOffYgOrigEMgM2wwvELx6Ew', + 'akHvmf5Fsoo7U9ztx3triIx2mczWfze3SEgIgaiGBYTlkqD0kN'); +$tumblrBlog = front()->Eden_Tumblr_Blog('49Sb8LrxMKh4lErDN69yp6VwgCmOffYgOrigEMgM2wwvELx6Ew', + 'akHvmf5Fsoo7U9ztx3triIx2mczWfze3SEgIgaiGBYTlkqD0kN'); + +echo 'GET
'.print_r($_GET, true).'
'; +echo 'SESSION
'.print_r($_SESSION, true).'
'; + +//if user wants to logout +if(isset($_GET['logout'])) { + //log them out + unset($_SESSION['request_token'], $_SESSION['request_token_secret'], $_SESSION['access_token'], $_SESSION['access_token_secret']); + header('Location: /symon.php'); +} + +//if the user is logged in +if(isset($_SESSION['access_token'], $_SESSION['access_token_secret'])) { + //lets do shit + + //set timezone + date_default_timezone_set('America/Los_Angeles'); + $timeline = array(); + + //get Tweets////////////////////////////////////////////////////////////////////////////////////////////// + $response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->getPublic(); + //print_r($response); + //for each tweet + foreach($response as $tweet) { + //get the unix time this item was created + $time = strtotime($tweet['created_at']); + //mark item as twitter + $tweet['social_media'] = 'twitter'; + //put this item in our global timeline + $timeline[$time] = $tweet; + } + + //get Tumblr list///////////////////////////////////////////////////////////////////////////////////////// + $response = $tumblr->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->getUser(); + //get Tumblr Avatar + //$avatar = $tumblrBlog->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->getAvatar(); + //for each tumblr + foreach($response['response']['posts'] as $tumbler) { + //get the unix time this item was created + $time = strtotime($tumbler['date']); + //mark item as tumbler + $tumbler['social_media'] = 'tumblr'; + //put this item in our global timeline + $timeline[$time] = $tumbler; + } + + //sort the date by the latest post to the older + krsort($timeline); + ?> + +
+ + + + +
_____________________________TUMBLR.COM_____________________________
+ +

+ + +

+ + + +

+ + + +
______________________________TWITTER.COM_______________________
+
+

+ +

'; ?> + + + + + + + + + + +

+ + + output($response); + //echo ""; print_r($response); echo ""; + //print_r($response); + //print_r($tumblr->getMeta()); + +//if the user just authorized us +} else if(isset($_GET['oauth_token'])) { + //upgrade one time access token to another access token that will last for 1 hour + $token = $tumblr->getAccessToken($_GET['oauth_token'], $_SESSION['request_token_secret'],$_GET['oauth_verifier']); + + //store this upgraded access token in our user session + $_SESSION['access_token'] = $token['oauth_token']; + $_SESSION['access_token_secret'] = $token['oauth_token_secret']; + + //redirect + header('Location: http://eden.openovate.com/symon.php'); + +//the user at this point is logged out +} else { + //get the request token + + $token = $tumblr->getRequestToken(); + $_SESSION['request_token'] = $token['oauth_token']; + $_SESSION['request_token_secret'] = $token['oauth_token_secret']; + + //prompt user to login + echo 'Login'; +} + +/////////////////////////////////////////////////// +/* +$satisfaction = front()->Eden_GetSatisfaction_Topic('ml57owkz0dl8', + '0uoub6rt8tx5tks7m76jln31sc4f98vh'); + +echo 'GET
'.print_r($_GET, true).'
'; +echo 'SESSION
'.print_r($_SESSION, true).'
'; + +//if user wants to logout +if(isset($_GET['logout'])) { + //log them out + unset($_SESSION['request_token'], $_SESSION['request_token_secret'], $_SESSION['access_token'], $_SESSION['access_token_secret']); + header('Location: /symon.php'); +} + +//if the user is logged in +if(isset($_SESSION['access_token'], $_SESSION['access_token_secret'])) { + //lets do shit + //ACCOUNTS + //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->updateColor(); + + print_r($response); + print_r($satisfaction->getMeta()); + +//if the user just authorized us +} else if(isset($_GET['oauth_token'])) { + //upgrade one time access token to another access token that will last for 1 hour + $token = $satisfaction->getAccessToken($_GET['oauth_token'], $_SESSION['request_token_secret']); + + //store this upgraded access token in our user session + $_SESSION['access_token'] = $token['oauth_token']; + $_SESSION['access_token_secret'] = $token['oauth_token_secret']; + + //redirect + header('Location: /symon.php'); + +//the user at this point is logged out +} else { + //get the request token + $token = $satisfaction->getRequestToken(); + $_SESSION['request_token'] = $token['oauth_token']; + $_SESSION['request_token_secret'] = $token['oauth_token_secret']; + + //prompt user to login + echo 'Login'; +} +*/ + +/////////////////////////////////////////// + +?> \ No newline at end of file From 78d8dc26997a3fde86f735a490b5240de6e93ea4 Mon Sep 17 00:00:00 2001 From: cblanquera Date: Thu, 8 Dec 2011 15:14:41 +0000 Subject: [PATCH 012/330] Assigning right error classes git-svn-id: http://svn.openovate.com/edenv2/trunk@12 38ede93f-50f4-44af-b0b3-68ccca78c181 --- library/eden/facebook/graph.php | 1066 +++++++++++++++---------------- 1 file changed, 533 insertions(+), 533 deletions(-) diff --git a/library/eden/facebook/graph.php b/library/eden/facebook/graph.php index cf759c4..267b611 100644 --- a/library/eden/facebook/graph.php +++ b/library/eden/facebook/graph.php @@ -1,534 +1,534 @@ - -/* - * 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.st. - */ - -/** - * Facebook Authentication - * - * @package Eden - * @subpackage file - * @category path - * @author Christian Blanquera - * @version $Id: model.php 4 2010-01-06 04:41:07Z blanquera $ - */ -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; - - /* Private Properties - -------------------------------*/ - /* Get - -------------------------------*/ - public static function get($token) { - return self::_getMultiple(__CLASS__, $token); - } - - /* Magic - -------------------------------*/ - public function __construct($token) { - $this->_token = $token; - } - - /* Public Methods - -------------------------------*/ - public function getObject($id = 'me', $connection = NULL, array $query = array(), $auth = true) { - if($connection) { - $connection = '/'.$connection; - } - - $url = self::GRAPH_URL.$id.$connection; - - if($auth) { - if(!$this->_token) { - throw new Eden_Facebook_Exception(sprintf(Eden_Facebook_Exception::REQUIRES_AUTH, $url)); - } - - $query['access_token'] = $this->_token; - } - - if(!empty($query)) { - $url .= '?'.http_build_query($query); - } - - $object = $this->_call($url); - $object = json_decode($object, true); - - if (isset($object['error'])) { - throw new Eden_Facebook_Exception(sprintf( - Eden_Facebook_Exception::GRAPH_FAILED, - $url, $object['error']['type'], - $object['error']['message'])); - } - - return $object; - } - - public function getFields($id = 'me', $fields) { - if(is_array($fields)) { - $fields = implode(',', $fields); - } - - return $this->getObject($id, NULL, array('fields' => $fields)); - } - - public function getUser() { - return $this->getObject('me'); - } - - public function getPictureUrl($id = 'me', $token = true) { - $url = self::GRAPH_URL.$id.'/picture'; - - if($token) { - $url .= '?access_token='.$this->_token; - } - - return $url; - } - - public function getLogoutUrl($redirect) { - return sprintf(self::LOGOUT_URL, urlencode($redirect), $this->_token); - } - - public function getFriends($id = 'me', $start = 0, $range = 0, $since = 0, $until = 0, $dateFormat = NULL) { - return $this->_getList($id, 'friends', $start, $range, $since, $until, $dateFormat); - } - - public function getNews($id = 'me', $start = 0, $range = 0, $since = 0, $until = 0, $dateFormat = NULL) { - return $this->_getList($id, 'home', $start, $range, $since, $until, $dateFormat); - } - - public function getWall($id = 'me', $start = 0, $range = 0, $since = 0, $until = 0, $dateFormat = NULL) { - return $this->_getList($id, 'wall', $start, $range, $since, $until, $dateFormat); - } - - public function getLikes($id = 'me', $start = 0, $range = 0, $since = 0, $until = 0, $dateFormat = NULL) { - return $this->_getList($id, 'likes', $start, $range, $since, $until, $dateFormat); - } - - public function getMovies($id = 'me', $start = 0, $range = 0, $since = 0, $until = 0, $dateFormat = NULL) { - return $this->_getList($id, 'movies', $start, $range, $since, $until, $dateFormat); - } - - public function getMusic($id = 'me', $start = 0, $range = 0, $since = 0, $until = 0, $dateFormat = NULL) { - return $this->_getList($id, 'music', $start, $range, $since, $until, $dateFormat); - } - - public function getBooks($id = 'me', $start = 0, $range = 0, $since = 0, $until = 0, $dateFormat = NULL) { - return $this->_getList($id, 'books', $start, $range, $since, $until, $dateFormat); - } - - public function getPermissions($id = 'me') { - $permissions = $this->getObject($id, 'permissions'); - return $permissions['data']; - } - - public function getPhotos($id = 'me', $start = 0, $range = 0, $since = 0, $until = 0, $dateFormat = NULL) { - return $this->_getList($id, 'photos', $start, $range, $since, $until, $dateFormat); - } - - public function getAlbums($id = 'me', $start = 0, $range = 0, $since = 0, $until = 0, $dateFormat = NULL) { - return $this->_getList($id, 'albums', $start, $range, $since, $until, $dateFormat); - } - - public function getVideos($id = 'me', $start = 0, $range = 0, $since = 0, $until = 0, $dateFormat = NULL) { - return $this->_getList($id, 'videos', $start, $range, $since, $until, $dateFormat); - } - - public function getVideoUploads($id = 'me', $start = 0, $range = 0, $since = 0, $until = 0, $dateFormat = NULL) { - return $this->_getList($id, 'videos/uploaded', $start, $range, $since, $until, $dateFormat); - } - - public function getEvents($id = 'me', $start = 0, $range = 0, $since = 0, $until = 0, $dateFormat = NULL) { - return $this->_getList($id, 'events', $start, $range, $since, $until, $dateFormat); - } - - public function getGroups($id = 'me', $start = 0, $range = 0, $since = 0, $until = 0, $dateFormat = NULL) { - return $this->_getList($id, 'groups', $start, $range, $since, $until, $dateFormat); - } - - public function getCheckIns($id = 'me', $start = 0, $range = 0, $since = 0, $until = 0, $dateFormat = NULL) { - return $this->_getList($id, 'checkins', $start, $range, $since, $until, $dateFormat); - } - - public function searchPosts($query, $fields = NULL) { - return $this->_search('post', $query, $fields); - } - - public function searchUsers($query, $fields = NULL) { - return $this->_search('user', $query, $fields); - } - - public function searchPages($query, $fields = NULL) { - return $this->_search('page', $query, $fields); - } - - public function searchEvents($query, $fields = NULL) { - return $this->_search('event', $query, $fields); - } - - public function searchGroups($query, $fields = NULL) { - return $this->_search('group', $query, $fields); - } - - public function searchPlaces($query, $fields = NULL) { - return $this->_search('place', $query, $fields); - } - - public function searchCheckins($query, $fields = NULL) { - return $this->_search('checkin', $query, $fields); - } - - public function addPost($message, $id = 'me', $link = NULL, $picture = NULL, - $video = NULL, $caption = NULL, $linkName = NULL, $linkDescription = NULL) { - - if(!$this->_token) { - throw new Eden_Facebook_Exception(sprintf(Eden_Facebook_Exception::REQUIRES_AUTH, $url)); - } - - $post = array('message' => $message); - - if($link) { - $post['link'] = $link; - } - - if($picture) { - $post['picture'] = $picture; - } - - if($video) { - $post['source'] = $video; - } - - if($caption) { - $post['caption'] = $caption; - } - - if($linkName) { - $post['name'] = $linkName; - } - - if($linkDescription) { - $post['description'] = $linkDescription; - } - - $url = self::GRAPH_URL.$id.'/feed'; - - $query = array('access_token' => $this->_token); - - if(!empty($query)) { - $url .= '?'.http_build_query($query); - } - - $results = json_decode($this->_call($url, $post), true); - return $results['id']; - } - - public function addComment($id, $message) { - if(!$this->_token) { - throw new Eden_Facebook_Exception(sprintf(Eden_Facebook_Exception::REQUIRES_AUTH, $url)); - } - - $post = array('message' => $message); - - $url = self::GRAPH_URL.$id.'/comments'; - - $query = array('access_token' => $this->_token); - - if(!empty($query)) { - $url .= '?'.http_build_query($query); - } - - $results = json_decode($this->_call($url, $post), true); - return $results['id']; - } - - public function like($id) { - if(!$this->_token) { - throw new Eden_Facebook_Exception(sprintf(Eden_Facebook_Exception::REQUIRES_AUTH, $url)); - } - - $url = self::GRAPH_URL.$id.'/likes'; - - $query = array('access_token' => $this->_token); - - if(!empty($query)) { - $url .= '?'.http_build_query($query); - } - - $this->_call($url); - - return $this; - } - - public function addNote($id, $subject, $message) { - if(!$this->_token) { - throw new Eden_Facebook_Exception(sprintf(Eden_Facebook_Exception::REQUIRES_AUTH, $url)); - } - - $post = array('subject' => $subject, 'message' => $message); - - $url = self::GRAPH_URL.$id.'/notes'; - - $query = array('access_token' => $this->_token); - - if(!empty($query)) { - $url .= '?'.http_build_query($query); - } - - $results = json_decode($this->_call($url, $post), true); - return $results['id']; - } - - public function addEvent($name, $start, $end) { - if(!$this->_token) { - throw new Eden_Facebook_Exception(sprintf(Eden_Facebook_Exception::REQUIRES_AUTH, $url)); - } - - $post = array('name'=>$name,'start_time'=>$start,'end_time'=>$end); - - $url = self::GRAPH_URL.$id.'/events'; - - $query = array('access_token' => $this->_token); - - if(!empty($query)) { - $url .= '?'.http_build_query($query); - } - - $results = json_decode($this->_call($url, $post), true); - return $results['id']; - } - - public function attendEvent($id) { - if(!$this->_token) { - throw new Eden_Facebook_Exception(sprintf(Eden_Facebook_Exception::REQUIRES_AUTH, $url)); - } - - $url = self::GRAPH_URL.$id.'/attending'; - - $query = array('access_token' => $this->_token); - - if(!empty($query)) { - $url .= '?'.http_build_query($query); - } - - json_decode($this->_call($url), true); - - return $this; - } - - public function maybeEvent($id) { - if(!$this->_token) { - throw new Eden_Facebook_Exception(sprintf(Eden_Facebook_Exception::REQUIRES_AUTH, $url)); - } - - $url = self::GRAPH_URL.$id.'/maybe'; - - $query = array('access_token' => $this->_token); - - if(!empty($query)) { - $url .= '?'.http_build_query($query); - } - - json_decode($this->_call($url), true); - - return $this; - } - - public function declineEvent($id) { - if(!$this->_token) { - throw new Eden_Facebook_Exception(sprintf(Eden_Facebook_Exception::REQUIRES_AUTH, $url)); - } - - $url = self::GRAPH_URL.$id.'/declined'; - - $query = array('access_token' => $this->_token); - - if(!empty($query)) { - $url .= '?'.http_build_query($query); - } - - json_decode($this->_call($url), true); - - return $this; - } - - public function addLink($id, $url, $message = NULL, $name = NULL, $description = NULL, $picture = NULL, $caption = NULL) { - if(!$this->_token) { - throw new Eden_Facebook_Exception(sprintf(Eden_Facebook_Exception::REQUIRES_AUTH, $url)); - } - - $post = array('url' => $url); - - if($message) { - $post['message'] = $message; - } - - if($name) { - $post['name'] = $name; - } - - if($description) { - $post['description'] = $description; - } - - if($picture) { - $post['picture'] = $picture; - } - - if($caption) { - $post['caption'] = $caption; - } - - $url = self::GRAPH_URL.$id.'/links'; - - $query = array('access_token' => $this->_token); - - if(!empty($query)) { - $url .= '?'.http_build_query($query); - } - - $results = json_decode($this->_call($url, $post), true); - return $results['id']; - } - - public function addAlbum($id, $name, $message) { - if(!$this->_token) { - throw new Eden_Facebook_Exception(sprintf(Eden_Facebook_Exception::REQUIRES_AUTH, $url)); - } - - $post = array('name'=>$name,'message'=>$message); - - $url = self::GRAPH_URL.$id.'/albums'; - - $query = array('access_token' => $this->_token); - - if(!empty($query)) { - $url .= '?'.http_build_query($query); - } - - $results = json_decode($this->_call($url, $post), true); - return $results['id']; - } - - public function addPhoto($id, $data) {} - - public function addCheckin($id, $message, $coordinates, $place, $tags) { - if(!$this->_token) { - throw new Eden_Facebook_Exception(sprintf(Eden_Facebook_Exception::REQUIRES_AUTH, $url)); - } - - $post = array('message' => $message); - - if($message) { - $post['message'] = $message; - } - - if($coordinates) { - $post['coordinates'] = $coordinates; - } - - if($place) { - $post['place'] = $place; - } - - if($tags) { - $post['tags'] = $tags; - } - - $url = self::GRAPH_URL.$id.'/checkins'; - - $query = array('access_token' => $this->_token); - - if(!empty($query)) { - $url .= '?'.http_build_query($query); - } - - $results = json_decode($this->_call($url, $post), true); - return $results['id']; - } - - /* Protected Methods - -------------------------------*/ - protected function _call($url, array $post = array()) { - //Argument 1 must be a string - Eden_Curl_Error::get()->argument(1, 'string'); - - return Eden_Curl::get() - ->setUrl($url) - ->setConnectTimeout(10) - ->setFollowLocation(true) - ->setTimeout(60) - ->verifyPeer(false) - ->setUserAgent(Eden_Facebook_Auth::USER_AGENT) - ->setHeaders('Expect') - ->when(!empty($post)) - ->setPost(true) - ->setPostFields(http_build_query($post)) - ->endWhen() - ->getResponse(); - - } - - protected function _getList($id, $connection, $start, $range, $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) { - $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 - -------------------------------*/ + +/* + * 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.st. + */ + +/** + * Facebook Authentication + * + * @package Eden + * @subpackage file + * @category path + * @author Christian Blanquera + * @version $Id: model.php 4 2010-01-06 04:41:07Z blanquera $ + */ +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; + + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function get($token) { + return self::_getMultiple(__CLASS__, $token); + } + + /* Magic + -------------------------------*/ + public function __construct($token) { + $this->_token = $token; + } + + /* Public Methods + -------------------------------*/ + public function getObject($id = 'me', $connection = NULL, array $query = array(), $auth = true) { + if($connection) { + $connection = '/'.$connection; + } + + $url = self::GRAPH_URL.$id.$connection; + + if($auth) { + if(!$this->_token) {echo 'no auth'; + throw new Eden_Facebook_Error(sprintf(Eden_Facebook_Error::REQUIRES_AUTH, $url)); + } + + $query['access_token'] = $this->_token; + } + + if(!empty($query)) { + $url .= '?'.http_build_query($query); + } + + $object = $this->_call($url); + $object = json_decode($object, true); + + if (isset($object['error'])) {print_r($object); + throw new Eden_Facebook_Error(sprintf( + Eden_Facebook_Error::GRAPH_FAILED, + $url, $object['error']['type'], + $object['error']['message'])); + } + + return $object; + } + + public function getFields($id = 'me', $fields) { + if(is_array($fields)) { + $fields = implode(',', $fields); + } + + return $this->getObject($id, NULL, array('fields' => $fields)); + } + + public function getUser() { + return $this->getObject('me'); + } + + public function getPictureUrl($id = 'me', $token = true) { + $url = self::GRAPH_URL.$id.'/picture'; + + if($token) { + $url .= '?access_token='.$this->_token; + } + + return $url; + } + + public function getLogoutUrl($redirect) { + return sprintf(self::LOGOUT_URL, urlencode($redirect), $this->_token); + } + + public function getFriends($id = 'me', $start = 0, $range = 0, $since = 0, $until = 0, $dateFormat = NULL) { + return $this->_getList($id, 'friends', $start, $range, $since, $until, $dateFormat); + } + + public function getNews($id = 'me', $start = 0, $range = 0, $since = 0, $until = 0, $dateFormat = NULL) { + return $this->_getList($id, 'home', $start, $range, $since, $until, $dateFormat); + } + + public function getWall($id = 'me', $start = 0, $range = 0, $since = 0, $until = 0, $dateFormat = NULL) { + return $this->_getList($id, 'feed', $start, $range, $since, $until, $dateFormat); + } + + public function getLikes($id = 'me', $start = 0, $range = 0, $since = 0, $until = 0, $dateFormat = NULL) { + return $this->_getList($id, 'likes', $start, $range, $since, $until, $dateFormat); + } + + public function getMovies($id = 'me', $start = 0, $range = 0, $since = 0, $until = 0, $dateFormat = NULL) { + return $this->_getList($id, 'movies', $start, $range, $since, $until, $dateFormat); + } + + public function getMusic($id = 'me', $start = 0, $range = 0, $since = 0, $until = 0, $dateFormat = NULL) { + return $this->_getList($id, 'music', $start, $range, $since, $until, $dateFormat); + } + + public function getBooks($id = 'me', $start = 0, $range = 0, $since = 0, $until = 0, $dateFormat = NULL) { + return $this->_getList($id, 'books', $start, $range, $since, $until, $dateFormat); + } + + public function getPermissions($id = 'me') { + $permissions = $this->getObject($id, 'permissions'); + return $permissions['data']; + } + + public function getPhotos($id = 'me', $start = 0, $range = 0, $since = 0, $until = 0, $dateFormat = NULL) { + return $this->_getList($id, 'photos', $start, $range, $since, $until, $dateFormat); + } + + public function getAlbums($id = 'me', $start = 0, $range = 0, $since = 0, $until = 0, $dateFormat = NULL) { + return $this->_getList($id, 'albums', $start, $range, $since, $until, $dateFormat); + } + + public function getVideos($id = 'me', $start = 0, $range = 0, $since = 0, $until = 0, $dateFormat = NULL) { + return $this->_getList($id, 'videos', $start, $range, $since, $until, $dateFormat); + } + + public function getVideoUploads($id = 'me', $start = 0, $range = 0, $since = 0, $until = 0, $dateFormat = NULL) { + return $this->_getList($id, 'videos/uploaded', $start, $range, $since, $until, $dateFormat); + } + + public function getEvents($id = 'me', $start = 0, $range = 0, $since = 0, $until = 0, $dateFormat = NULL) { + return $this->_getList($id, 'events', $start, $range, $since, $until, $dateFormat); + } + + public function getGroups($id = 'me', $start = 0, $range = 0, $since = 0, $until = 0, $dateFormat = NULL) { + return $this->_getList($id, 'groups', $start, $range, $since, $until, $dateFormat); + } + + public function getCheckIns($id = 'me', $start = 0, $range = 0, $since = 0, $until = 0, $dateFormat = NULL) { + return $this->_getList($id, 'checkins', $start, $range, $since, $until, $dateFormat); + } + + public function searchPosts($query, $fields = NULL) { + return $this->_search('post', $query, $fields); + } + + public function searchUsers($query, $fields = NULL) { + return $this->_search('user', $query, $fields); + } + + public function searchPages($query, $fields = NULL) { + return $this->_search('page', $query, $fields); + } + + public function searchEvents($query, $fields = NULL) { + return $this->_search('event', $query, $fields); + } + + public function searchGroups($query, $fields = NULL) { + return $this->_search('group', $query, $fields); + } + + public function searchPlaces($query, $fields = NULL) { + return $this->_search('place', $query, $fields); + } + + public function searchCheckins($query, $fields = NULL) { + return $this->_search('checkin', $query, $fields); + } + + public function addPost($message, $id = 'me', $link = NULL, $picture = NULL, + $video = NULL, $caption = NULL, $linkName = NULL, $linkDescription = NULL) { + + if(!$this->_token) { + throw new Eden_Facebook_Error(sprintf(Eden_Facebook_Error::REQUIRES_AUTH, $url)); + } + + $post = array('message' => $message); + + if($link) { + $post['link'] = $link; + } + + if($picture) { + $post['picture'] = $picture; + } + + if($video) { + $post['source'] = $video; + } + + if($caption) { + $post['caption'] = $caption; + } + + if($linkName) { + $post['name'] = $linkName; + } + + if($linkDescription) { + $post['description'] = $linkDescription; + } + + $url = self::GRAPH_URL.$id.'/feed'; + + $query = array('access_token' => $this->_token); + + if(!empty($query)) { + $url .= '?'.http_build_query($query); + } + + $results = json_decode($this->_call($url, $post), true); + return $results['id']; + } + + public function addComment($id, $message) { + if(!$this->_token) { + throw new Eden_Facebook_Error(sprintf(Eden_Facebook_Error::REQUIRES_AUTH, $url)); + } + + $post = array('message' => $message); + + $url = self::GRAPH_URL.$id.'/comments'; + + $query = array('access_token' => $this->_token); + + if(!empty($query)) { + $url .= '?'.http_build_query($query); + } + + $results = json_decode($this->_call($url, $post), true); + return $results['id']; + } + + public function like($id) { + if(!$this->_token) { + throw new Eden_Facebook_Error(sprintf(Eden_Facebook_Error::REQUIRES_AUTH, $url)); + } + + $url = self::GRAPH_URL.$id.'/likes'; + + $query = array('access_token' => $this->_token); + + if(!empty($query)) { + $url .= '?'.http_build_query($query); + } + + $this->_call($url); + + return $this; + } + + public function addNote($id, $subject, $message) { + if(!$this->_token) { + throw new Eden_Facebook_Error(sprintf(Eden_Facebook_Error::REQUIRES_AUTH, $url)); + } + + $post = array('subject' => $subject, 'message' => $message); + + $url = self::GRAPH_URL.$id.'/notes'; + + $query = array('access_token' => $this->_token); + + if(!empty($query)) { + $url .= '?'.http_build_query($query); + } + + $results = json_decode($this->_call($url, $post), true); + return $results['id']; + } + + public function addEvent($name, $start, $end) { + if(!$this->_token) { + throw new Eden_Facebook_Error(sprintf(Eden_Facebook_Error::REQUIRES_AUTH, $url)); + } + + $post = array('name'=>$name,'start_time'=>$start,'end_time'=>$end); + + $url = self::GRAPH_URL.$id.'/events'; + + $query = array('access_token' => $this->_token); + + if(!empty($query)) { + $url .= '?'.http_build_query($query); + } + + $results = json_decode($this->_call($url, $post), true); + return $results['id']; + } + + public function attendEvent($id) { + if(!$this->_token) { + throw new Eden_Facebook_Error(sprintf(Eden_Facebook_Error::REQUIRES_AUTH, $url)); + } + + $url = self::GRAPH_URL.$id.'/attending'; + + $query = array('access_token' => $this->_token); + + if(!empty($query)) { + $url .= '?'.http_build_query($query); + } + + json_decode($this->_call($url), true); + + return $this; + } + + public function maybeEvent($id) { + if(!$this->_token) { + throw new Eden_Facebook_Error(sprintf(Eden_Facebook_Error::REQUIRES_AUTH, $url)); + } + + $url = self::GRAPH_URL.$id.'/maybe'; + + $query = array('access_token' => $this->_token); + + if(!empty($query)) { + $url .= '?'.http_build_query($query); + } + + json_decode($this->_call($url), true); + + return $this; + } + + public function declineEvent($id) { + if(!$this->_token) { + throw new Eden_Facebook_Error(sprintf(Eden_Facebook_Error::REQUIRES_AUTH, $url)); + } + + $url = self::GRAPH_URL.$id.'/declined'; + + $query = array('access_token' => $this->_token); + + if(!empty($query)) { + $url .= '?'.http_build_query($query); + } + + json_decode($this->_call($url), true); + + return $this; + } + + public function addLink($id, $url, $message = NULL, $name = NULL, $description = NULL, $picture = NULL, $caption = NULL) { + if(!$this->_token) { + throw new Eden_Facebook_Error(sprintf(Eden_Facebook_Error::REQUIRES_AUTH, $url)); + } + + $post = array('url' => $url); + + if($message) { + $post['message'] = $message; + } + + if($name) { + $post['name'] = $name; + } + + if($description) { + $post['description'] = $description; + } + + if($picture) { + $post['picture'] = $picture; + } + + if($caption) { + $post['caption'] = $caption; + } + + $url = self::GRAPH_URL.$id.'/links'; + + $query = array('access_token' => $this->_token); + + if(!empty($query)) { + $url .= '?'.http_build_query($query); + } + + $results = json_decode($this->_call($url, $post), true); + return $results['id']; + } + + public function addAlbum($id, $name, $message) { + if(!$this->_token) { + throw new Eden_Facebook_Error(sprintf(Eden_Facebook_Error::REQUIRES_AUTH, $url)); + } + + $post = array('name'=>$name,'message'=>$message); + + $url = self::GRAPH_URL.$id.'/albums'; + + $query = array('access_token' => $this->_token); + + if(!empty($query)) { + $url .= '?'.http_build_query($query); + } + + $results = json_decode($this->_call($url, $post), true); + return $results['id']; + } + + public function addPhoto($id, $data) {} + + public function addCheckin($id, $message, $coordinates, $place, $tags) { + if(!$this->_token) { + throw new Eden_Facebook_Error(sprintf(Eden_Facebook_Error::REQUIRES_AUTH, $url)); + } + + $post = array('message' => $message); + + if($message) { + $post['message'] = $message; + } + + if($coordinates) { + $post['coordinates'] = $coordinates; + } + + if($place) { + $post['place'] = $place; + } + + if($tags) { + $post['tags'] = $tags; + } + + $url = self::GRAPH_URL.$id.'/checkins'; + + $query = array('access_token' => $this->_token); + + if(!empty($query)) { + $url .= '?'.http_build_query($query); + } + + $results = json_decode($this->_call($url, $post), true); + return $results['id']; + } + + /* Protected Methods + -------------------------------*/ + protected function _call($url, array $post = array()) { + //Argument 1 must be a string + Eden_Facebook_Error::get()->argument(1, 'string'); + + return Eden_Curl::get() + ->setUrl($url) + ->setConnectTimeout(10) + ->setFollowLocation(true) + ->setTimeout(60) + ->verifyPeer(false) + ->setUserAgent(Eden_Facebook_Auth::USER_AGENT) + ->setHeaders('Expect') + ->when(!empty($post)) + ->setPost(true) + ->setPostFields(http_build_query($post)) + ->endWhen() + ->getResponse(); + + } + + protected function _getList($id, $connection, $start, $range, $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) { + $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 From 0f0186de16f3aa7793a1726eed1f1654b044a5eb Mon Sep 17 00:00:00 2001 From: cblanquera Date: Thu, 8 Dec 2011 15:17:13 +0000 Subject: [PATCH 013/330] Assigning right error classes git-svn-id: http://svn.openovate.com/edenv2/trunk@13 38ede93f-50f4-44af-b0b3-68ccca78c181 --- library/eden/facebook/graph.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/library/eden/facebook/graph.php b/library/eden/facebook/graph.php index 267b611..bc77afe 100644 --- a/library/eden/facebook/graph.php +++ b/library/eden/facebook/graph.php @@ -52,7 +52,7 @@ public function getObject($id = 'me', $connection = NULL, array $query = array() $url = self::GRAPH_URL.$id.$connection; if($auth) { - if(!$this->_token) {echo 'no auth'; + if(!$this->_token) { throw new Eden_Facebook_Error(sprintf(Eden_Facebook_Error::REQUIRES_AUTH, $url)); } @@ -66,7 +66,7 @@ public function getObject($id = 'me', $connection = NULL, array $query = array() $object = $this->_call($url); $object = json_decode($object, true); - if (isset($object['error'])) {print_r($object); + if (isset($object['error'])) { throw new Eden_Facebook_Error(sprintf( Eden_Facebook_Error::GRAPH_FAILED, $url, $object['error']['type'], From 5d76e2711b572d9a6dd3ee8cc3dcffe2b36a2595 Mon Sep 17 00:00:00 2001 From: cblanquera Date: Tue, 13 Dec 2011 06:14:42 +0000 Subject: [PATCH 014/330] get satisfaction dev git-svn-id: http://svn.openovate.com/edenv2/trunk@14 38ede93f-50f4-44af-b0b3-68ccca78c181 --- library/eden/getsatisfaction/base.php | 436 ++++++++++++------------- library/eden/getsatisfaction/oauth.php | 44 +++ 2 files changed, 262 insertions(+), 218 deletions(-) create mode 100644 library/eden/getsatisfaction/oauth.php diff --git a/library/eden/getsatisfaction/base.php b/library/eden/getsatisfaction/base.php index 1bb7529..2b9cc8b 100644 --- a/library/eden/getsatisfaction/base.php +++ b/library/eden/getsatisfaction/base.php @@ -1,219 +1,219 @@ - -/* - * 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. - */ - -/** - * get satisfaction oauth - * - * @package Eden - * @category get satisfaction - * @author Christian Blanquera - * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ - */ -class Eden_GetSatisfaction_Base extends Eden_Oauth_Base { - /* Constants - -------------------------------*/ - const REQUEST_URL = ''; - const AUTHORIZE_URL = ''; - - const SECRET_KEY = ''; - - /* Public Properties - -------------------------------*/ - /* Protected Properties - -------------------------------*/ - protected $_key = NULL; - protected $_secret = NULL; - - /* Private Properties - -------------------------------*/ - /* Get - -------------------------------*/ - /* Magic - -------------------------------*/ - public function __construct($key, $secret) { - //argument test - Eden_Twitter_Error::get() - ->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 URL used for login. - * - * @param string - * @return string - */ - public function getLoginUrl($redirect) { - //Argument 1 must be a string - Eden_Google_Error::get()->argument(1, 'string'); - - //get the token - $token = Eden_Oauth::get() - ->getConsumer(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; - } - - /** - * Returns the access token - * - * @param string - * @param string - * @return string - */ - public function getAccessToken($token, $secret) { - //argument test - Eden_Google_Error::get() - ->argument(1, 'string') //Argument 1 must be a string - ->argument(2, 'string'); //Argument 2 must be a string - - return Eden_Oauth::get() - ->getConsumer(self::ACCESS_URL, $this->_key, $this->_secret) - ->useAuthorization() - ->setMethodToPost() - ->setToken($token, $secret) - ->setSignatureToHmacSha1() - ->getQueryResponse(); - } - - public function setAccessToken($token, $secret) { - $this->_accessToken = $token; - $this->_accessSecret = $secret; - - return $this; - } - - - /** - * Returns the meta of the last call - * - * @return array - */ - public function getMeta($key = NULL) { - Eden_Google_Error::get()->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::get() - ->getConsumer($url, $this->_key, $this->_secret) - ->setHeaders(self::VERSION_HEADER, self::GDATA_VERSION) - ->setToken($this->_accessToken, $this->_accessSecret) - ->setSignatureToHmacSha1(); - - $response = $rest->getJsonResponse($query); - - $this->_meta = $rest->getMeta(); - - return $response; - } - - /** - * Returns the token from the server - * - * @param array - * @return array - */ - protected function _post($url, $query = array()) { - $headers = array(); - $headers[] = Eden_Oauth_Consumer::POST_HEADER; - - $rest = Eden_Oauth::get() - ->getConsumer($url, $this->_key, $this->_secret) - ->setToken($this->_accessToken, $this->_accessSecret) - ->setSignatureToHmacSha1(); - - //get the authorization parameters as an array - $signature = $rest->getSignature(); - $authorization = $rest->getAuthorization($signature, false); - $authorization = $this->_buildQuery($authorization); - - if(is_array($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::get() - ->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['authorization'] = $authorization; - $this->_meta['headers'] = $headers; - $this->_meta['query'] = $query; - - return $response; - } - - /* Private Methods - -------------------------------*/ + +/* + * 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. + */ + +/** + * get satisfaction oauth + * + * @package Eden + * @category get satisfaction + * @author Christian Blanquera + * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ + */ +class Eden_Getsatisfaction_Base extends Eden_Oauth_Base { + /* Constants + -------------------------------*/ + const REQUEST_URL = 'http://api.getsatisfaction.com/api/request_token'; + const AUTHORIZE_URL = 'http://api.getsatisfaction.com/api/authorize'; + + const SECRET_KEY = 'getsatisfaction_token_secret'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_key = NULL; + protected $_secret = NULL; + + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + /* Magic + -------------------------------*/ + public function __construct($key, $secret) { + //argument test + Eden_Getsatisfaction_Error::get() + ->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 URL used for login. + * + * @param string + * @return string + */ + public function getLoginUrl($redirect) { + //Argument 1 must be a string + Eden_Google_Error::get()->argument(1, 'string'); + + //get the token + $token = Eden_Oauth::get() + ->getConsumer(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; + } + + /** + * Returns the access token + * + * @param string + * @param string + * @return string + */ + public function getAccessToken($token, $secret) { + //argument test + Eden_Google_Error::get() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'string'); //Argument 2 must be a string + + return Eden_Oauth::get() + ->getConsumer(self::ACCESS_URL, $this->_key, $this->_secret) + ->useAuthorization() + ->setMethodToPost() + ->setToken($token, $secret) + ->setSignatureToHmacSha1() + ->getQueryResponse(); + } + + public function setAccessToken($token, $secret) { + $this->_accessToken = $token; + $this->_accessSecret = $secret; + + return $this; + } + + + /** + * Returns the meta of the last call + * + * @return array + */ + public function getMeta($key = NULL) { + Eden_Google_Error::get()->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::get() + ->getConsumer($url, $this->_key, $this->_secret) + ->setHeaders(self::VERSION_HEADER, self::GDATA_VERSION) + ->setToken($this->_accessToken, $this->_accessSecret) + ->setSignatureToHmacSha1(); + + $response = $rest->getJsonResponse($query); + + $this->_meta = $rest->getMeta(); + + return $response; + } + + /** + * Returns the token from the server + * + * @param array + * @return array + */ + protected function _post($url, $query = array()) { + $headers = array(); + $headers[] = Eden_Oauth_Consumer::POST_HEADER; + + $rest = Eden_Oauth::get() + ->getConsumer($url, $this->_key, $this->_secret) + ->setToken($this->_accessToken, $this->_accessSecret) + ->setSignatureToHmacSha1(); + + //get the authorization parameters as an array + $signature = $rest->getSignature(); + $authorization = $rest->getAuthorization($signature, false); + $authorization = $this->_buildQuery($authorization); + + if(is_array($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::get() + ->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['authorization'] = $authorization; + $this->_meta['headers'] = $headers; + $this->_meta['query'] = $query; + + return $response; + } + + /* 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..8237c08 --- /dev/null +++ b/library/eden/getsatisfaction/oauth.php @@ -0,0 +1,44 @@ + +/* + * 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. + */ + +/** + * Twitter oauth + * + * @package Eden + * @category google + * @author Christian Blanquera + * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ + */ +class Eden_Getsatisfaction_Oauth extends Eden_Getsatisfaction_Base { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_key = NULL; + protected $_secret = NULL; + + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function get($key, $secret) { + return self::_getMultiple(__CLASS__, $key, $secret); + } + + /* Magic + -------------------------------*/ + /* Public Methods + -------------------------------*/ + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file From 7ffd27ca5d0b4a5db5a7e197840b12f721395923 Mon Sep 17 00:00:00 2001 From: cblanquera Date: Tue, 13 Dec 2011 06:29:16 +0000 Subject: [PATCH 015/330] get satisfaction dev git-svn-id: http://svn.openovate.com/edenv2/trunk@15 38ede93f-50f4-44af-b0b3-68ccca78c181 --- library/eden/getsatisfaction/base.php | 6 +++--- site/web/index.php | 3 +++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/library/eden/getsatisfaction/base.php b/library/eden/getsatisfaction/base.php index 2b9cc8b..28dd740 100644 --- a/library/eden/getsatisfaction/base.php +++ b/library/eden/getsatisfaction/base.php @@ -18,8 +18,8 @@ class Eden_Getsatisfaction_Base extends Eden_Oauth_Base { /* Constants -------------------------------*/ - const REQUEST_URL = 'http://api.getsatisfaction.com/api/request_token'; - const AUTHORIZE_URL = 'http://api.getsatisfaction.com/api/authorize'; + const REQUEST_URL = 'http://getsatisfaction.com/api/request_token'; + const AUTHORIZE_URL = 'http://getsatisfaction.com/api/authorize'; const SECRET_KEY = 'getsatisfaction_token_secret'; @@ -56,7 +56,7 @@ public function __construct($key, $secret) { */ public function getLoginUrl($redirect) { //Argument 1 must be a string - Eden_Google_Error::get()->argument(1, 'string'); + Eden_Getsatisfaction_Error::get()->argument(1, 'string'); //get the token $token = Eden_Oauth::get() diff --git a/site/web/index.php b/site/web/index.php index cd46c27..08b2c6b 100644 --- a/site/web/index.php +++ b/site/web/index.php @@ -88,3 +88,6 @@ /* Get the Response -------------------------------*/ ->getResponse(); + echo eden() + ->Eden_Getsatisfaction_Oauth("vbk4bs1klldy", "snw77ih836aoqoiylu2jgc286zy586as") + ->getLoginUrl('http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']); \ No newline at end of file From 8f6426ed8f6e0e20bb0031359cca7456fb87fc05 Mon Sep 17 00:00:00 2001 From: cblanquera Date: Tue, 13 Dec 2011 06:31:45 +0000 Subject: [PATCH 016/330] gs dev git-svn-id: http://svn.openovate.com/edenv2/trunk@16 38ede93f-50f4-44af-b0b3-68ccca78c181 --- library/eden/getsatisfaction/error.php | 42 ++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 library/eden/getsatisfaction/error.php diff --git a/library/eden/getsatisfaction/error.php b/library/eden/getsatisfaction/error.php new file mode 100644 index 0000000..ab1274b --- /dev/null +++ b/library/eden/getsatisfaction/error.php @@ -0,0 +1,42 @@ + +/* + * 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. + */ + +/** + * Get Satisfaction Errors + * + * @package Eden + * @category google + * @author Christian Blanquera + * @version $Id: exception.php 1 2010-01-02 23:06:36Z blanquera $ + */ +class Eden_Getsatisfaction_Error extends Eden_Error { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function get($message = NULL, $code = 0) { + $class = __CLASS__; + return new $class($message, $code); + } + + /* Magic + -------------------------------*/ + /* Public Methods + -------------------------------*/ + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file From 20b69caf6488c783de179c0373db93409e94cdf1 Mon Sep 17 00:00:00 2001 From: cblanquera Date: Thu, 15 Dec 2011 11:17:25 +0000 Subject: [PATCH 017/330] get satisfaction git-svn-id: http://svn.openovate.com/edenv2/trunk@17 38ede93f-50f4-44af-b0b3-68ccca78c181 --- library/eden/getsatisfaction/base.php | 74 +-- library/eden/getsatisfaction/company.php | 396 +++++--------- library/eden/getsatisfaction/people.php | 189 ++++--- library/eden/getsatisfaction/replies.php | 315 ++++++----- library/eden/getsatisfaction/topic.php | 635 ++++++++++------------- library/eden/oauth/base.php | 26 +- library/eden/oauth/consumer.php | 26 +- library/eden/twitter/base.php | 312 +++++------ 8 files changed, 883 insertions(+), 1090 deletions(-) diff --git a/library/eden/getsatisfaction/base.php b/library/eden/getsatisfaction/base.php index 28dd740..fc40434 100644 --- a/library/eden/getsatisfaction/base.php +++ b/library/eden/getsatisfaction/base.php @@ -20,15 +20,17 @@ class Eden_Getsatisfaction_Base extends Eden_Oauth_Base { -------------------------------*/ 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; + protected $_key = NULL; + protected $_secret = NULL; + protected $_accessToken = NULL; + protected $_accessSecret = NULL; /* Private Properties -------------------------------*/ @@ -115,6 +117,14 @@ public function getAccessToken($token, $secret) { ->getQueryResponse(); } + /** + * Sets the access token, usually for + * when we get it from the authenticator + * + * @param string + * @param string + * @return this + */ public function setAccessToken($token, $secret) { $this->_accessToken = $token; $this->_accessSecret = $secret; @@ -122,7 +132,6 @@ public function setAccessToken($token, $secret) { return $this; } - /** * Returns the meta of the last call * @@ -140,7 +149,6 @@ public function getMeta($key = NULL) { /* Protected Methods -------------------------------*/ - protected function _getResponse($url, array $query = array()) { $rest = Eden_Oauth::get() ->getConsumer($url, $this->_key, $this->_secret) @@ -155,61 +163,21 @@ protected function _getResponse($url, array $query = array()) { return $response; } - /** - * Returns the token from the server - * - * @param array - * @return array - */ - protected function _post($url, $query = array()) { - $headers = array(); - $headers[] = Eden_Oauth_Consumer::POST_HEADER; - + protected function _post($url, $query = array(), $jsonEncode = false) { $rest = Eden_Oauth::get() ->getConsumer($url, $this->_key, $this->_secret) ->setToken($this->_accessToken, $this->_accessSecret) + ->setMethodToPost() + ->useAuthorization() ->setSignatureToHmacSha1(); - //get the authorization parameters as an array - $signature = $rest->getSignature(); - $authorization = $rest->getAuthorization($signature, false); - $authorization = $this->_buildQuery($authorization); - - if(is_array($query)) { - $query = $this->_buildQuery($query); + if($jsonEncode) { + $rest->jsonEncodeQuery(); } - //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::get() - ->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['authorization'] = $authorization; - $this->_meta['headers'] = $headers; - $this->_meta['query'] = $query; + $response = $rest->getJsonResponse($query); + + $this->_meta = $rest->getMeta(); return $response; } diff --git a/library/eden/getsatisfaction/company.php b/library/eden/getsatisfaction/company.php index 3917b2b..b64ebf8 100644 --- a/library/eden/getsatisfaction/company.php +++ b/library/eden/getsatisfaction/company.php @@ -1,258 +1,140 @@ - -/* - * 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. - */ - -/** - * - * - * @package Eden - * @category Get Satisfaction - * @author Christian Blanquera - * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ - */ -class Eden_GetSatisfaction_Company extends Eden_GetSatisfaction_Base { - /* Constants - -------------------------------*/ - const URL_GET_LIST = 'http://api.getsatisfaction.com/companies.json'; - const URL_GET_USER = 'http://api.getsatisfaction.com/people/%s/companies.json'; - const URL_GET_PRODUCT = 'http://api.getsatisfaction.com/products/%s/companies.json'; - const URL_GET_COMPANY = 'http://api.getsatisfaction.com/companies/%s/last_activity_at.json'; - const URL_SEARCH = 'http://api.getsatisfaction.com?query=%s.json'; - - - /* Public Properties - -------------------------------*/ - /* Protected Properties - -------------------------------*/ - protected $_query = array(); - - protected $_validShow = array('public','not_hidden','private','not_hidden'); - - protected $_validSort = array( - 'created' => 'recently_created', - 'active' => 'recently_active', - 'alpha' => 'alpha'); - - /* Private Properties - -------------------------------*/ - /* Get - -------------------------------*/ - public static function get($user, $api) { - return self::_getMultiple(__CLASS__, $user, $api); - } - - /* Magic - -------------------------------*/ - /* Public Methods - -------------------------------*/ - /** - * Get all the public Get Satisfaction communities - * - * @param show is string - * @param sort is string - * @return this - */ - public function getList($show = NULL, $sort = NULL) { - //Argument testing - Eden_Tumblr_Error::get() - ->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 the show is a short version of a valid show - if(isset($this->_validShow[$show])) { - //make show the long version - $filter = $this->_validShow[$show]; - //lets set show to show - $query['show'] = $show; - - } - - //if the show is a short version of a valid show - if(isset($this->_validSort[$sort])) { - //make filter the long version - $filter = $this->_validSort[$sort]; - //lets set sort to sort - $query['sort'] = $sort; - - } - - return $this->_getResponse(self::URL_GET_LIST, $query); - } - - /** - * Get all the public Get Satisfaction - * communities created by the specified user - * - * @param name is string - * @param id is integer - * @param show is string - * @param sort is string - * @return this - */ - public function getUser($name = NULL, $id = NULL, $show = NULL, $sort = NULL) { - //Argument testing - Eden_Tumblr_Error::get() - ->argument(1, 'string' ,'null') //Argument 1 must be a string or null - ->argument(2, 'integer' ,'null') //Argument 2 must be a integer or null - ->argument(3, 'string' ,'null') //Argument 3 must be a string or null - ->argument(4, 'string' ,'null'); //Argument 2 must be a string or null - - $query = array(); - - //if name is not empty - if(!is_null($name)) { - //lets set user name to user - $query['user_name'] = $name; - } - //if id is not empty - if(!is_null($id)) { - //lets set user id to id - $query['user_id'] = $id; - } - - //if the show is a short version of a valid show - if(isset($this->_validShow[$show])) { - //make show the long version - $filter = $this->_validShow[$show]; - //lets set show to show - $query['show'] = $show; - } - - //if the show is a short version of a valid show - if(isset($this->_validSort[$sort])) { - //make filter the long version - $filter = $this->_validSort[$sort]; - //lets set sort to sort - $query['sort'] = $sort; - } - - return $this->_getResponse(self::URL_GET_USER, $query); - } - - /** - * Get all the public Get Satisfaction communities - * related to the specified product - * - * @param name is string - * @param id is integer - * @param show is string - * @param sort is string - * @return this - */ - public function getUser($name = NULL, $id = NULL, $show = NULL, $sort = NULL) { - //Argument testing - Eden_Tumblr_Error::get() - ->argument(1, 'string' ,'null') //Argument 1 must be a string or null - ->argument(2, 'integer' ,'null') //Argument 2 must be a integer or null - ->argument(3, 'string' ,'null') //Argument 3 must be a string or null - ->argument(4, 'string' ,'null'); //Argument 2 must be a string or null - - $query = array(); - - //if name is not empty - if(!is_null($name)) { - //lets set user name to user - $query['user_name'] = $name; - } - //if id is not empty - if(!is_null($id)) { - //lets set user id to id - $query['user_id'] = $id; - } - - //if the show is a short version of a valid show - if(isset($this->_validShow[$show])) { - //make show the long version - $filter = $this->_validShow[$show]; - //lets set show to show - $query['show'] = $show; - } - - //if the show is a short version of a valid show - if(isset($this->_validSort[$sort])) { - //make filter the long version - $filter = $this->_validSort[$sort]; - //lets set sort to sort - $query['sort'] = $sort; - } - - return $this->_getResponse(self::URL_GET_PRODUCT, $query); - } - - /** - * Get the date and time of the last activity - * in the specified community - * - * @param name is string - * @param id is integer - * @param show is string - * @param sort is string - * @return this - */ - public function getUser($name = NULL, $id = NULL, $show = NULL, $sort = NULL) { - //Argument testing - Eden_Tumblr_Error::get() - ->argument(1, 'string' ,'null') //Argument 1 must be a string or null - ->argument(2, 'integer' ,'null') //Argument 2 must be a integer or null - ->argument(3, 'string' ,'null') //Argument 3 must be a string or null - ->argument(4, 'string' ,'null'); //Argument 2 must be a string or null - - $query = array(); - - //if name is not empty - if(!is_null($name)) { - //lets set user name to user - $query['user_name'] = $name; - } - //if id is not empty - if(!is_null($id)) { - //lets set user id to id - $query['user_id'] = $id; - } - - //if the show is a short version of a valid show - if(isset($this->_validShow[$show])) { - //make show the long version - $filter = $this->_validShow[$show]; - //lets set show to show - $query['show'] = $show; - } - - //if the show is a short version of a valid show - if(isset($this->_validSort[$sort])) { - //make filter the long version - $filter = $this->_validSort[$sort]; - //lets set sort to sort - $query['sort'] = $sort; - } - - return $this->_getResponse(self::URL_GET_COMPANY, $query); - } - - /** - * Search for a particular string - * - * @param search is string - * @return this - */ - public function search($search) { - //Argument testing - Eden_Tumblr_Error::get() - ->argument(1, 'string'); //Argument 1 must be a string - - $query = array('search' => $search); - - return $this->_getResponse(self::URL_SEARCH, $query); - } - /* Protected Methods - -------------------------------*/ - /* Private Methods - -------------------------------*/ + +/* + * 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. + */ + +/** + * Get Satisfaction Company Methods + * + * @package Eden + * @category Get Satisfaction + * @author Christian Blanquera + * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ + */ +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 + -------------------------------*/ + /* Get + -------------------------------*/ + public static function get($key, $secret) { + return self::_getMultiple(__CLASS__, $key, $secret); + } + + /* Magic + -------------------------------*/ + /* Public Methods + -------------------------------*/ + public function setActivity($company) { + Eden_Getsatisfaction_Error::get()->argument(1, 'string', 'numeric'); + + $this->_url = sprintf(self::URL_ACTIVITY, $company); + return $this; + } + + public function setUser($user) { + Eden_Getsatisfaction_Error::get()->argument(1, 'string', 'numeric'); + + $this->_url = sprintf(self::URL_PEOPLE, $user); + return $this; + } + + public function setProduct($product) { + Eden_Getsatisfaction_Error::get()->argument(1, 'string', 'numeric'); + + $this->_url = sprintf(self::URL_PRODUCT, $product); + return $this; + } + + public function setKeyword($keyword) { + Eden_Getsatisfaction_Error::get()->argument(1, 'string'); + + $this->_query['query'] = $keyword; + + return $this; + } + + public function showPublic() { + $this->_query['show'] = 'public'; + return $this; + } + + public function showVisible() { + $this->_query['show'] = 'not_hidden'; + return $this; + } + + public function showPrivate() { + $this->_query['show'] = 'private'; + return $this; + } + + public function sortByCreated() { + $this->_query['sort'] = 'recently_created'; + return $this; + } + + public function sortByActive() { + $this->_query['sort'] = 'recently_active'; + return $this; + } + + public function sortByAlphabet() { + $this->_query['sort'] = 'alpha'; + return $this; + } + + public function setPage($page = 0) { + Eden_Getsatisfaction_Error::get()->argument(1, 'int'); + + if($page < 0) { + $page = 0; + } + + $this->_query['page'] = $page; + + return $this; + } + + public function setLimit($limit = 10) { + Eden_Getsatisfaction_Error::get()->argument(1, 'int'); + + if($limit < 0) { + $limit = 10; + } + + $this->_query['limit'] = $limit; + + return $this; + } + + public function getList() { + if(isset($this->_query['status']) && is_array($this->_query['status'])) { + $this->_query['status'] = implode(',', $this->_query['status']); + } + + return $this->_getResponse($this->_url, $this->_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 index 3a76f3f..6329f8c 100644 --- a/library/eden/getsatisfaction/people.php +++ b/library/eden/getsatisfaction/people.php @@ -1,81 +1,110 @@ - -/* - * 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. - */ - -/** - * - * - * @package Eden - * @category Get Satisfaction - * @author Christian Blanquera - * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ - */ -class Eden_GetSatisfaction_People extends Eden_GetSatisfaction_Base { - /* Constants - -------------------------------*/ - const URL_GET_LIST = 'http://api.getsatisfaction.com/people.json'; - - /* Public Properties - -------------------------------*/ - /* Protected Properties - -------------------------------*/ - protected $_query = array(); - - protected $_validShow = array('public','not_hidden','private','not_hidden'); - - protected $_validSort = array( - 'created' => 'recently_created', - 'active' => 'recently_active', - 'alpha' => 'alpha'); - - /* Private Properties - -------------------------------*/ - /* Get - -------------------------------*/ - public static function get($user, $api) { - return self::_getMultiple(__CLASS__, $user, $api); - } - - /* Magic - -------------------------------*/ - /* Public Methods - -------------------------------*/ - /** - * People with accounts in communities at Get Satisfaction - * - * @return this - */ - public function getList() { - - return $this->_getResponse(self::URL_GET_LIST); - } - - /** - * Goes to page 3 of the people list, showing 10 people. - * (A limit of 30 is max.) - * - * @return this - */ - public function getList($page, $limit = NULL) { - //Argument testing - Eden_Tumblr_Error::get() - ->argument(1, 'integer') //Argument 1 must be a string - ->argument(2, 'integer' ,'null'); //Argument 2 must be a string or null - - $query = array(); - - return $this->_getResponse(self::URL_GET_LIST); - } - - - - /* Protected Methods - -------------------------------*/ - /* Private Methods - -------------------------------*/ + +/* + * 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. + */ + +/** + * Get Satisfaction People Methods + * + * @package Eden + * @category Get Satisfaction + * @author Christian Blanquera + * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ + */ +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 + -------------------------------*/ + /* Get + -------------------------------*/ + public static function get($key, $secret) { + return self::_getMultiple(__CLASS__, $key, $secret); + } + + /* Magic + -------------------------------*/ + /* Public Methods + -------------------------------*/ + public function setCompany($company) { + Eden_Getsatisfaction_Error::get()->argument(1, 'string', 'numeric'); + + $this->_url = sprintf(self::URL_COMPANY, $company); + return $this; + } + + public function setEmployee($company) { + Eden_Getsatisfaction_Error::get()->argument(1, 'string', 'numeric'); + + $this->_url = sprintf(self::URL_EMPLOYEE, $company); + return $this; + } + + public function setTopic($topic) { + Eden_Getsatisfaction_Error::get()->argument(1, 'string', 'numeric'); + + $this->_url = sprintf(self::URL_TOPIC, $topic); + return $this; + } + + public function setKeyword($keyword) { + Eden_Getsatisfaction_Error::get()->argument(1, 'string'); + + $this->_query['query'] = $keyword; + + return $this; + } + + public function setPage($page = 0) { + Eden_Getsatisfaction_Error::get()->argument(1, 'int'); + + if($page < 0) { + $page = 0; + } + + $this->_query['page'] = $page; + + return $this; + } + + public function setLimit($limit = 10) { + Eden_Getsatisfaction_Error::get()->argument(1, 'int'); + + if($limit < 0) { + $limit = 10; + } + + $this->_query['limit'] = $limit; + + return $this; + } + + public function getList() { + if(isset($this->_query['status']) && is_array($this->_query['status'])) { + $this->_query['status'] = implode(',', $this->_query['status']); + } + + return $this->_getResponse($this->_url, $this->_query); + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ } \ No newline at end of file diff --git a/library/eden/getsatisfaction/replies.php b/library/eden/getsatisfaction/replies.php index 2cde0ed..46da272 100644 --- a/library/eden/getsatisfaction/replies.php +++ b/library/eden/getsatisfaction/replies.php @@ -1,171 +1,146 @@ - -/* - * 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. - */ - -/** - * - * - * @package Eden - * @category Get Satisfaction - * @author Christian Blanquera - * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ - */ -class Eden_GetSatisfaction_Replies extends Eden_GetSatisfaction_Base { - /* Constants - -------------------------------*/ - const URL_GET_LIST = 'http://api.getsatisfaction.com/replies.json'; - const URL_GET_TOPICS = 'http://api.getsatisfaction.com/topics/%s/replies.json'; - const URL_GET_USERS = 'http://api.getsatisfaction.com/people/%s/replies.json'; - - - /* Public Properties - -------------------------------*/ - /* Protected Properties - -------------------------------*/ - protected $_query = array(); - - protected $_validFilters = array( - 'best' => 'best', - 'star' => 'star_promoted', - 'company' => 'company_promoted', - 'flat' => 'flat_promotion'); - - /* Private Properties - -------------------------------*/ - /* Get - -------------------------------*/ - public static function get($user, $api) { - return self::_getMultiple(__CLASS__, $user, $api); - } - - /* Magic - -------------------------------*/ - /* Public Methods - -------------------------------*/ - /** - * Get all replies to all topics in all public Get Satisfaction communities - * - * @return this - */ - public function getList($filter = NULL) { - //Argument 1 must be a string or null - Eden_Tumblr_Error::get()->argument(1, 'string' ,'null'); - - $query = array(); - - //if the filter is a short version of a valid filter - if(isset($this->_validFilters[$filter])) { - //make filter the long version - $filter = $this->_validFilters[$filter]; - } - - //if filter is valid - if(in_array($filter, $this->_validFilters)) { - //if filter is flat promotion - if($filter == 'flat_promotion') { - //lets set type to filter - $query['type'] = $filter; - //it is not a flat promotion - } else { - //lets set filter to filter - $query['filter'] = $filter; - } - } - - return $this->_getResponse(self::URL_GET_LIST, $query); - } - - /** - * Get all replies from the specified topic - * - * @param id is integer - * @param slug is a string - * @return this - */ - public function getTopics($id = NULL, $slug = NULL, $filter = NULL) { - //argument testing - Eden_Tumblr_Error::get() - ->argument(1, 'integer' ,'null') //Argument 2 must be a integer or null - ->argument(2, 'string' ,'null') //Argument 1 must be a string or null - ->argument(3, 'string' ,'null'); //Argument 3 must be a string or null - - $query = array(); - //if the id is not empty - if(!is_null($id)) { - //lets set topic id to id - $query['topic_id'] = $id; - } - - //if the slug is not empty - if(!is_null($slug)) { - //lets set slug to slug - $query['slug'] = $slug; - } - - //if the filter is a short version of a valid filter - if(isset($this->_validFilters[$filter])) { - //make filter the long version - $filter = $this->_validFilters[$filter]; - } - - //if filter is valid - if(in_array($filter, $this->_validFilters)) { - //if filter is flat promotion - if($filter == 'flat_promotion') { - //lets set type to filter - $query['type'] = $filter; - //it is not a flat promotion - } else { - //lets set filter to filter - $query['filter'] = $filter; - } - } - - return $this->_getResponse(self::URL_GET_TOPICS, $query); - } - - /** - * Get all replies that a particular user has posted - * - * @param id is integer - * @return this - */ - public function getUserReplies($id, $filter = NULL) { - //argument testing - Eden_Tumblr_Error::get() - ->argument(1, 'integer') //Argument 1 must be a integer - ->argument(2, 'string' ,'null'); //Argument 2 must be a string or null - - $query = array('user_id' => $id); - //if the filter is a short version of a valid filter - if(isset($this->_validFilters[$filter])) { - //make filter the long version - $filter = $this->_validFilters[$filter]; - } - - //if filter is valid - if(in_array($filter, $this->_validFilters)) { - //if filter is flat promotion - if($filter == 'flat_promotion') { - //lets set type to filter - $query['type'] = $filter; - //it is not a flat promotion - } else { - //lets set filter to filter - $query['filter'] = $filter; - } - } - - return $this->_getResponse(self::URL_GET_USERS, $query); - } - - /* Protected Methods - -------------------------------*/ - /* Private Methods - -------------------------------*/ + +/* + * 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. + */ + +/** + * Get Satisfaction Reply Methods + * + * @package Eden + * @category Get Satisfaction + * @author Christian Blanquera + * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ + */ +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 + -------------------------------*/ + /* Get + -------------------------------*/ + public static function get($key, $secret) { + return self::_getMultiple(__CLASS__, $key, $secret); + } + + /* Magic + -------------------------------*/ + /* Public Methods + -------------------------------*/ + public function setUser($user) { + Eden_Getsatisfaction_Error::get()->argument(1, 'string', 'numeric'); + + $this->_url = sprintf(self::URL_PEOPLE, $user); + return $this; + } + + public function setTopic($topic) { + Eden_Getsatisfaction_Error::get()->argument(1, 'string', 'numeric'); + + $this->_url = sprintf(self::URL_TOPIC, $topic); + return $this; + } + + public function filterBest() { + $this->_query['filter'] = 'best'; + + return $this; + } + + public function filterStarPromoted() { + $this->_query['filter'] = 'star_promoted'; + + return $this; + } + + public function filterCompanyPromoted() { + $this->_query['filter'] = 'company_promoted'; + + return $this; + } + + public function filterFlatPromoted() { + $this->_query['filter'] = 'flat_promoted'; + + return $this; + } + + public function setPage($page = 0) { + Eden_Getsatisfaction_Error::get()->argument(1, 'int'); + + if($page < 0) { + $page = 0; + } + + $this->_query['page'] = $page; + + return $this; + } + + public function setLimit($limit = 10) { + Eden_Getsatisfaction_Error::get()->argument(1, 'int'); + + if($limit < 0) { + $limit = 10; + } + + $this->_query['limit'] = $limit; + + return $this; + } + + public function getList() { + if(isset($this->_query['status']) && is_array($this->_query['status'])) { + $this->_query['status'] = implode(',', $this->_query['status']); + } + + return $this->_getResponse($this->_url, $this->_query); + } + + public function reply($topic, $content, $face = NULL, $feeling = NULL, $intensity = NULL) { + Eden_Getsatisfaction_Error::get() + ->argument(1, 'string', 'numeric') + ->argument(2, 'string') + ->argument(3, 'string', 'null') + ->argument(4, 'string', 'null') + ->argument(5, 'int', 'null'); + + $url = sprintf(self::URL_REPLY, $topic); + + $query = array('content' => $content); + + if($face && in_array($face, $this->_validFaces)) { + $query['emotitag']['face'] = $face; + } + + if($feeling) { + $query['emotitag']['feeling'] = $feeling; + } + + if($intensity && $intensity > -1 && $intensity < 4) { + $query['emotitag']['intensity'] = $intensity; + } + + return $this->_post($url, array('reply' => $query)); + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ } \ No newline at end of file diff --git a/library/eden/getsatisfaction/topic.php b/library/eden/getsatisfaction/topic.php index c34dd3d..82eb27f 100644 --- a/library/eden/getsatisfaction/topic.php +++ b/library/eden/getsatisfaction/topic.php @@ -1,356 +1,281 @@ - -/* - * 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. - */ - -/** - * - * - * @package Eden - * @category Get Satisfaction - * @author Christian Blanquera - * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ - */ -class Eden_GetSatisfaction_Topic extends Eden_GetSatisfaction_Base { - /* Constants - -------------------------------*/ - const URL_GET_LIST = 'http://api.getsatisfaction.com/topics/%s'; - const URL_GET_ALL_TOPICS = 'http://api.getsatisfaction.com/topics.json'; - const URL_GET_PARTICULAR = 'http://api.getsatisfaction.com/companies/%s/topics.json'; - const URL_GET_SPECIFIC = 'http://api.getsatisfaction.com/products/%s/topics.json'; - const URL_GET_TOPICS_TAG = 'http://api.getsatisfaction.com/companies/%s/tags/%s/topics.json'; - const URL_GET_USER_TOPICS = 'http://api.getsatisfaction.com/people/%s/topics.json'; - const URL_GET_USER_FOLLOWING = 'http://api.getsatisfaction.com/people/%s/followed/topics.json'; - const URL_GET_PRODUCT_TOPICS = 'http://api.getsatisfaction.com/products/%s/topics.json'; - - const URL_SEARCH = 'http://api.getsatisfaction.com?query=%s'; - - const URL_LAST_ACTIVITY = 'http://api.getsatisfaction.com?active_since=%s'; - const URL_USER_ID = 'http://api.getsatisfaction.com?user=%s'; - const URL_COMPANY_ID = 'http://api.getsatisfaction.com?company=%s'; - const URL_PRODUCT_NAME = 'http://api.getsatisfaction.com?product=%s'; - const URL_TAG = 'http://api.getsatisfaction.com?tag=%s'; - const URL_STATUS = 'http://api.getsatisfaction.com?status=%s'; - const URL_UDC = 'http://api.getsatisfaction.com?user_defined_code=%s'; - - - /* Public Properties - -------------------------------*/ - /* Protected Properties - -------------------------------*/ - protected $_query = array(); - - protected $_validSort = array( - 'created' => 'recently_created', - 'active' => 'recently_active', - 'replies' => 'most_replies', - 'toos' => 'most_me_toos', - 'priority' => 'priority', - 'answered' => 'answered'); - - protected $_validStyle = array('question','problem','praise','idea','update'); - - /* Private Properties - -------------------------------*/ - /* Get - -------------------------------*/ - public static function get($user, $api) { - return self::_getMultiple(__CLASS__, $user, $api); - } - /* Magic - -------------------------------*/ - /* Public Methods - -------------------------------*/ - /** - * Get a specific topic - * - * @param topic is a string - * @param slug is a string - * @param id is a integer - * @return this - */ - public function getList($topic = NULL, $slug = NULL, $id = NULL) { - //Argument Test - Eden_Tumblr_Error::get() - ->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, 'integer' ,'null'); //Argument 3 must be a integer or null - - $query = array(); - //if it is not empty - if(!is_null($topic)) { - //lets put it in query - $query['topic'] = $topic; - } - //if it is not empty - if(!is_null($slug)) { - //lets put it in query - $query['slug'] = $slug; - } - //if it is not empty - if(!is_null($id)) { - //lets put it in query - $query['id'] = $id; - } - - return $this->_getResponse(self::URL_GET_LIST, $query); - } - /** - * Get all topics in all public - * Get Satisfaction communities - * - * @return this - */ - public function getAll() { - - return $this->_getResponse(self::URL_GET_ALL_TOPICS); - } - /** - * Get all topics related to a specific - * product in a particular community - * - * @param id is a integer - * @param name is a string - * @return this - */ - public function getParticular($id = NULL, $name = NULL) { - //Argument Test - Eden_Tumblr_Error::get() - ->argument(1, 'integer', 'null') //Argument 1 must be a integer 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['company_id'] = $id; - } - //if it is not empty - if(!is_null($name)) { - //lets put it in query - $query['company_name'] = $name; - } - - return $this->_getResponse(self::URL_GET_PARTICULAR, $query); - } - /** - * Get all topics related to a specific - * product in a particular community - * - * @param id is a integer - * @param product is a string - * @param name is a string - * @return this - */ - public function getSpecific($id, $product, $name = NULL) { - //Argument Test - Eden_Tumblr_Error::get() - ->argument(1, 'integer') //Argument 1 must be a integer - ->argument(2, 'string') //Argument 2 must be a string - ->argument(3, 'string'); //Argument 3 must be a string - - $query = array('company_id' => $id, 'product_name' => $product); - //if it is not empty - if(!is_null($name)) { - //lets put it in query - $query['company_name'] = $name; - } - - return $this->_getResponse(self::URL_GET_SPECIFIC, $query); - } - /** - * Get all topics tagged with a specific - * tag within a particular community - * - * @param id is a integer - * @param product is a string - * @param name is a string - * @return this - */ - public function getTopicsTag($id, $tag, $name = NULL) { - //Argument Test - Eden_Tumblr_Error::get() - ->argument(1, 'integer') //Argument 1 must be a integer - ->argument(2, 'string') //Argument 2 must be a string - ->argument(3, 'string'); //Argument 3 must be a string - - $query = array('company_id' => $id, 'product_name' => $product); - //if it is not empty - if(!is_null($name)) { - //lets put it in query - $query['company_name'] = $name; - } - - return $this->_getResponse(self::URL_GET_TOPICS_TAG, $query); - } - /** - * Get all topics that a particular user has posted - * (*there is a question about how these numbers are calculated) - * - * @param id is a integer - * @return this - */ - public function getUserTopics($id) { - //Argument Test - Eden_Tumblr_Error::get() - ->argument(1, 'integer'); //Argument 1 must be a integer - - $query = array('id' => $id); - - return $this->_getResponse(self::URL_GET_USER_TOPICS, $query); - } - /** - * Get all topics that a particular user is following - * - * @param id is a integer - * @return this - */ - public function getUserFollowing($id) { - //Argument Test - Eden_Tumblr_Error::get() - ->argument(1, 'integer'); //Argument 1 must be a integer - - $query = array('id' => $id); - - return $this->_getResponse(self::URL_GET_TOPICS_TAG, $query); - } - /** - * Get all topics identified with a specific product - * - * @param name is a string - * @return this - */ - public function getProductTopics($name) { - //Argument Test - Eden_Tumblr_Error::get() - ->argument(1, 'string'); //Argument 1 must be a string - - $query = array('product_name' => $name); - - return $this->_getResponse(self::URL_GET_PRODUCT_TOPICS, $query); - } - /** - * Search for a particular string - * - * @param searh is a string - * @return this - */ - public function search($search) { - //Argument Test - Eden_Tumblr_Error::get() - ->argument(1, 'string'); //Argument 1 must be a string - - $query = array('searh' => $searh); - - return $this->_getResponse(self::URL_SEARCH, $query); - } - /** - * Sort - * - * @return this - */ - public function sort($sort = NULL) { - //Argument Test - Eden_Tumblr_Error::get() - ->argument(1, 'string'); //Argument 1 must be a string - - $query = array(); - //if the sort is a short version of a valid sort - if(isset($this->_validSort[$sort])) { - //make sort the long version - $sort = $this->_validSort[$sort]; - //lets set sort to sort - $query['sort'] = $sort; - } - - return $this->_getResponse(self::URL_TOPICS_CREATED); - } - ////////////////////////////////////////////////////// - public function sortStyle($style) { - //Argumement - Eden_Tumblr_Error::get() - ->argument(1, 'string'); - - $query = array(); - //if the style is a short version of a valid style - if(isset($this->_validStyle[$style])) { - //make style the long style - $sort = $this->_validStyle[$style]; - //lets set style to style - $query['style'] = $style; - } - } - - /** - * Filter by the time of the last activity in - * the community. Time is set in seconds since epoch. - * - * @return this - */ - public function filterLastActivity() { - - return $this->_getResponse(self::URL_LAST_ACTIVITY); - } - /** - * Filter by user ID - * - * @return this - */ - public function filterUser() { - - return $this->_getResponse(self::URL_USER_ID); - } - /** - * Filter by company ID - * - * @return this - */ - public function filterCompany() { - - return $this->_getResponse(self::URL_COMPANY_ID); - } - /** - * Filter by product name - * - * @return this - */ - public function filterProduct() { - - return $this->_getResponse(self::URL_PRODUCT_NAME); - } - /** - * Filter by tag - * - * @return this - */ - public function filterTag() { - - return $this->_getResponse(self::URL_TAG); - } - /** - * Filter by status - * - * @return this - */ - public function filterStatus() { - - return $this->_getResponse(self::URL_STATUS); - } - /** - * Filter by User Defined Code - * - * @return this - */ - public function filterUdc() { - - return $this->_getResponse(self::URL_UDC); - } - /* Protected Methods - -------------------------------*/ - /* Private Methods - -------------------------------*/ + +/* + * 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. + */ + +/** + * Get Satisfaction Topic Methods + * + * @package Eden + * @category Get Satisfaction + * @author Christian Blanquera + * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ + */ +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 + -------------------------------*/ + /* Get + -------------------------------*/ + public static function get($key, $secret) { + return self::_getMultiple(__CLASS__, $key, $secret); + } + + /* Magic + -------------------------------*/ + /* Public Methods + -------------------------------*/ + public function setCompany($company) { + Eden_Getsatisfaction_Error::get()->argument(1, 'string', 'numeric'); + + $this->_url = sprintf(self::URL_COMPANY, $company); + return $this; + } + + public function setCompanyProduct($company, $product) { + Eden_Getsatisfaction_Error::get() + ->argument(1, 'string', 'numeric') + ->argument(2, 'string', 'numeric'); + + $this->_url = sprintf(self::URL_COMPANY_PRODUCT, $company, $product); + return $this; + } + + public function setCompanyTag($company, $tag) { + Eden_Getsatisfaction_Error::get() + ->argument(1, 'string', 'numeric') + ->argument(2, 'string', 'numeric'); + + $this->_url = sprintf(self::URL_COMPANY_TAG, $company, $tag); + return $this; + } + + public function setProduct($product) { + Eden_Getsatisfaction_Error::get()->argument(1, 'string', 'numeric'); + + $this->_url = sprintf(self::URL_PRODUCT, $product); + return $this; + } + + public function setUser($user) { + Eden_Getsatisfaction_Error::get()->argument(1, 'string', 'numeric'); + + $this->_url = sprintf(self::URL_PEOPLE, $user); + return $this; + } + + public function setFollowed($user) { + Eden_Getsatisfaction_Error::get()->argument(1, 'string', 'numeric'); + + $this->_url = sprintf(self::URL_PEOPLE_FOLLOWED, $user); + return $this; + } + + public function sortByCreated() { + $this->_query['sort'] = 'recently_created'; + return $this; + } + + public function sortByActive() { + $this->_query['sort'] = 'recently_active'; + return $this; + } + + public function sortByReplies() { + $this->_query['sort'] = 'most_replies'; + return $this; + } + + public function sortByVotes() { + $this->_query['sort'] = 'most_me_toos'; + return $this; + } + + public function sortByPriority() { + $this->_query['sort'] = 'priority'; + return $this; + } + + public function sortByUnanswered() { + $this->_query['sort'] = 'answered'; + return $this; + } + + public function showQuestions() { + $this->_query['style'] = 'question'; + return $this; + } + + public function showProblems() { + $this->_query['style'] = 'question'; + return $this; + } + + public function showPraise() { + $this->_query['style'] = 'praise'; + return $this; + } + + public function showIdeas() { + $this->_query['style'] = 'idea'; + return $this; + } + + public function showUpdates() { + $this->_query['style'] = 'update'; + return $this; + } + + public function filterSince($since) { + Eden_Getsatisfaction_Error::get()->argument(1, 'string', 'int'); + + if(is_string($since)) { + $since = strtotime($since); + } + + $this->_query['active_since'] = $since; + + return $this; + } + + public function filterUser($user) { + Eden_Getsatisfaction_Error::get()->argument(1, 'string', 'int'); + + $this->_query['user'] = $user; + + return $this; + } + + public function filterCompany($company) { + Eden_Getsatisfaction_Error::get()->argument(1, 'string', 'int'); + + $this->_query['company'] = $company; + + return $this; + } + + public function filterProduct($product) { + Eden_Getsatisfaction_Error::get()->argument(1, 'string', 'int', 'array'); + + if(is_array($product)) { + $product = implode(',', $product); + } + + $this->_query['product'] = $product; + + return $this; + } + + public function filterTag($tag) { + Eden_Getsatisfaction_Error::get()->argument(1, 'string'); + + $this->_query['tag'] = $tag; + + return $this; + } + + public function filterDefined($defined) { + Eden_Getsatisfaction_Error::get()->argument(1, 'string', 'int'); + + $this->_query['user_defined_code'] = $defined; + + return $this; + } + + public function addStatusNone() { + if(!isset($this->_filter['status']) || !in_array('none', $this->_filter['status'])) { + $this->_filter['status'][] = 'none'; + } + + return $this; + } + + public function addStatusPending() { + if(!isset($this->_filter['status']) || !in_array('pending', $this->_filter['status'])) { + $this->_filter['status'][] = 'pending'; + } + + return $this; + } + + public function addStatusActive() { + if(!isset($this->_filter['status']) || !in_array('active', $this->_filter['status'])) { + $this->_filter['status'][] = 'active'; + } + + return $this; + } + + public function addStatusComplete() { + if(!isset($this->_filter['status']) || !in_array('complete', $this->_filter['status'])) { + $this->_filter['status'][] = 'complete'; + } + + return $this; + } + + public function addStatusRejected() { + if(!isset($this->_filter['status']) || !in_array('rejected', $this->_filter['status'])) { + $this->_filter['status'][] = 'rejected'; + } + + return $this; + } + + public function setPage($page = 0) { + Eden_Getsatisfaction_Error::get()->argument(1, 'int'); + + if($page < 0) { + $page = 0; + } + + $this->_query['page'] = $page; + + return $this; + } + + public function setLimit($limit = 10) { + Eden_Getsatisfaction_Error::get()->argument(1, 'int'); + + if($limit < 0) { + $limit = 10; + } + + $this->_query['limit'] = $limit; + + return $this; + } + + public function getList() { + if(isset($this->_query['status']) && is_array($this->_query['status'])) { + $this->_query['status'] = implode(',', $this->_query['status']); + } + + return $this->_getResponse($this->_url, $this->_query); + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ } \ No newline at end of file diff --git a/library/eden/oauth/base.php b/library/eden/oauth/base.php index f084512..51952f0 100644 --- a/library/eden/oauth/base.php +++ b/library/eden/oauth/base.php @@ -41,7 +41,7 @@ class Eden_Oauth_Base extends Eden_Class { -------------------------------*/ /* Protected Methods -------------------------------*/ - protected function _buildQuery($params, $separator = '&', $noQuotes = true) { + protected function _buildQuery($params, $noQuotes = true, $subList = false) { if(empty($params)) { return ''; } @@ -57,34 +57,28 @@ protected function _buildQuery($params, $separator = '&', $noQuotes = true) { uksort($params, 'strcmp'); // Turn params array into an array of "key=value" strings - $query = array(); 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); - foreach ($value as $item) { - if(!$noQuotes) { - $item = '"'.$item.'"'; - } - - array_push($query, $key . '=' . $item); - } + $params[$key] = $this->_buildQuery($value, $noQuotes, true); } else { if(!$noQuotes) { $value = '"'.$value.'"'; } - // For each parameter, the name is separated from the corresponding - // value by an '=' character (ASCII code 61). OAuth Spec: 9.1.1 (2) - array_push($query, $key . '=' . $value); + $params[$key] = $value; } } - - // Each name-value pair is separated by an '&' character, ASCII code 38. - // OAuth Spec: 9.1.1 (2) - return implode($separator, $query); + + if($subList) { + return $params; + } + + return urldecode(http_build_query($params)); + } protected function _parseString($string) { diff --git a/library/eden/oauth/consumer.php b/library/eden/oauth/consumer.php index 5288c8b..4f31fb2 100644 --- a/library/eden/oauth/consumer.php +++ b/library/eden/oauth/consumer.php @@ -40,6 +40,8 @@ class Eden_Oauth_Consumer extends Eden_Oauth_Base { protected $_signature = NULL; protected $_meta = array(); protected $_headers = array(); + + protected $_json = false; /* Private Properties -------------------------------*/ @@ -116,6 +118,16 @@ public function setMethodToPost() { return $this; } + /** + * When sent, sends the parameters as post fields + * + * @return this + */ + public function jsonEncodeQuery() { + $this->_json = true; + return $this; + } + /** * When sent, appends the parameters to the URL * @@ -337,11 +349,16 @@ public function getSignature(array $query = array()) { * @return array */ public function getResponse(array $query = array()) { - $headers = $this->_headers; + $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 @@ -363,13 +380,16 @@ public function getResponse(array $query = array()) { 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 diff --git a/library/eden/twitter/base.php b/library/eden/twitter/base.php index 5929023..4d0411d 100644 --- a/library/eden/twitter/base.php +++ b/library/eden/twitter/base.php @@ -1,157 +1,157 @@ - -/* - * 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. - */ - -/** - * Twitter oauth - * - * @package Eden - * @category twitter - * @author Christian Blanquera - * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ - */ -class Eden_Twitter_Base extends Eden_Oauth_Base { - /* Constants - -------------------------------*/ - const REQUEST_URL = 'http://api.twitter.com/oauth/request_token'; - const AUTHORIZE_URL = 'http://api.twitter.com/oauth/authorize'; - const ACCESS_URL = 'https://api.twitter.com/oauth/access_token'; - const SECRET_KEY = 'twitter_token_secret'; - - /* Public Properties - -------------------------------*/ - /* Protected Properties - -------------------------------*/ - protected $_key = NULL; - protected $_secret = NULL; - - /* Private Properties - -------------------------------*/ - /* Get - -------------------------------*/ - /* Magic - -------------------------------*/ - public function __construct($key, $secret) { - //argument test - Eden_Twitter_Error::get() - ->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 - -------------------------------*/ - public function getRequestToken() { - return Eden_Oauth::get() - ->getConsumer(self::REQUEST_URL, $this->_key, $this->_secret) - ->useAuthorization() - ->setMethodToPost() - ->setSignatureToHmacSha1() - ->getQueryResponse(); - } - - /** - * Returns the URL used for login. - * - * @param array - * @param string - * @return string - */ - public function getLoginUrl($token, $redirect) { - //Argument tests - Eden_Twitter_Error::get() - ->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; - } - - /** - * Returns the access token - * - * @param string - * @param string - * @return string - */ - public function getAccessToken($token, $secret) { - //argument test - Eden_Google_Error::get() - ->argument(1, 'string') //Argument 1 must be a string - ->argument(2, 'string'); //Argument 2 must be a string - - return Eden_Oauth::get() - ->getConsumer(self::ACCESS_URL, $this->_key, $this->_secret) - ->useAuthorization() - ->setMethodToPost() - ->setToken($token, $secret) - ->setSignatureToHmacSha1() - ->getQueryResponse(); - } - - public function setAccessToken($token, $secret) { - $this->_accessToken = $token; - $this->_accessSecret = $secret; - - return $this; - } - - - /** - * Returns the meta of the last call - * - * @return array - */ - public function getMeta($key = NULL) { - Eden_Google_Error::get()->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::get() - ->getConsumer($url, $this->_key, $this->_secret) - ->setToken($this->_accessToken, $this->_accessSecret) - ->setSignatureToHmacSha1(); - - $response = $rest->getJsonResponse($query); - - $this->_meta = $rest->getMeta(); - - return $response; - } - - protected function _post($url, $query = array()) { - $rest = Eden_Oauth::get() - ->getConsumer($url, $this->_key, $this->_secret) - ->setToken($this->_accessToken, $this->_accessSecret) - ->setMethodToPost() - ->useAuthorization() - ->setSignatureToHmacSha1(); - - $response = $rest->getJsonResponse($query); - - $this->_meta = $rest->getMeta(); - - return $response; - } - - /* Private Methods - -------------------------------*/ + +/* + * 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. + */ + +/** + * Twitter oauth + * + * @package Eden + * @category twitter + * @author Christian Blanquera + * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ + */ +class Eden_Twitter_Base extends Eden_Oauth_Base { + /* Constants + -------------------------------*/ + const REQUEST_URL = 'http://api.twitter.com/oauth/request_token'; + const AUTHORIZE_URL = 'http://api.twitter.com/oauth/authorize'; + const ACCESS_URL = 'https://api.twitter.com/oauth/access_token'; + const SECRET_KEY = 'twitter_token_secret'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_key = NULL; + protected $_secret = NULL; + + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + /* Magic + -------------------------------*/ + public function __construct($key, $secret) { + //argument test + Eden_Twitter_Error::get() + ->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 + -------------------------------*/ + public function getRequestToken() { + return Eden_Oauth::get() + ->getConsumer(self::REQUEST_URL, $this->_key, $this->_secret) + ->useAuthorization() + ->setMethodToPost() + ->setSignatureToHmacSha1() + ->getQueryResponse(); + } + + /** + * Returns the URL used for login. + * + * @param array + * @param string + * @return string + */ + public function getLoginUrl($token, $redirect) { + //Argument tests + Eden_Twitter_Error::get() + ->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; + } + + /** + * Returns the access token + * + * @param string + * @param string + * @return string + */ + public function getAccessToken($token, $secret) { + //argument test + Eden_Google_Error::get() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'string'); //Argument 2 must be a string + + return Eden_Oauth::get() + ->getConsumer(self::ACCESS_URL, $this->_key, $this->_secret) + ->useAuthorization() + ->setMethodToPost() + ->setToken($token, $secret) + ->setSignatureToHmacSha1() + ->getQueryResponse(); + } + + public function setAccessToken($token, $secret) { + $this->_accessToken = $token; + $this->_accessSecret = $secret; + + return $this; + } + + + /** + * Returns the meta of the last call + * + * @return array + */ + public function getMeta($key = NULL) { + Eden_Google_Error::get()->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::get() + ->getConsumer($url, $this->_key, $this->_secret) + ->setToken($this->_accessToken, $this->_accessSecret) + ->setSignatureToHmacSha1(); + + $response = $rest->getJsonResponse($query); + + $this->_meta = $rest->getMeta(); + + return $response; + } + + protected function _post($url, $query = array()) { + $rest = Eden_Oauth::get() + ->getConsumer($url, $this->_key, $this->_secret) + ->setToken($this->_accessToken, $this->_accessSecret) + ->setMethodToPost() + ->useAuthorization() + ->setSignatureToHmacSha1(); + + $response = $rest->getJsonResponse($query); + + $this->_meta = $rest->getMeta(); + + return $response; + } + + /* Private Methods + -------------------------------*/ } \ No newline at end of file From 9fa29a51cfad50631f367f5db112a6e8186300eb Mon Sep 17 00:00:00 2001 From: cblanquera Date: Thu, 15 Dec 2011 11:25:45 +0000 Subject: [PATCH 018/330] get satisfaction git-svn-id: http://svn.openovate.com/edenv2/trunk@18 38ede93f-50f4-44af-b0b3-68ccca78c181 --- library/eden/getsatisfaction/detail.php | 49 +++++++ library/eden/getsatisfaction/post.php | 161 +++++++++++++++++++++++ library/eden/getsatisfaction/product.php | 134 +++++++++++++++++++ library/eden/getsatisfaction/tag.php | 94 +++++++++++++ 4 files changed, 438 insertions(+) create mode 100644 library/eden/getsatisfaction/detail.php create mode 100644 library/eden/getsatisfaction/post.php create mode 100644 library/eden/getsatisfaction/product.php create mode 100644 library/eden/getsatisfaction/tag.php diff --git a/library/eden/getsatisfaction/detail.php b/library/eden/getsatisfaction/detail.php new file mode 100644 index 0000000..051556c --- /dev/null +++ b/library/eden/getsatisfaction/detail.php @@ -0,0 +1,49 @@ + +/* + * 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. + */ + +/** + * Get Satisfaction Topic Methods + * + * @package Eden + * @category Get Satisfaction + * @author Christian Blanquera + * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ + */ +class Eden_GetSatisfaction_Detail extends Eden_GetSatisfaction_Base { + /* Constants + -------------------------------*/ + const URL = 'http://api.getsatisfaction.com/topics/%s.json'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function get($key, $secret) { + return self::_getMultiple(__CLASS__, $key, $secret); + } + + /* Magic + -------------------------------*/ + /* Public Methods + -------------------------------*/ + public function getTopic($topic) { + Eden_Getsatisfaction_Error::get()->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/post.php b/library/eden/getsatisfaction/post.php new file mode 100644 index 0000000..56fbf04 --- /dev/null +++ b/library/eden/getsatisfaction/post.php @@ -0,0 +1,161 @@ + +/* + * 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. + */ + +/** + * Get Satisfaction Post Methods + * + * @package Eden + * @category Get Satisfaction + * @author Christian Blanquera + * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ + */ +class Eden_Getsatisfaction_Post extends Eden_Getsatisfaction_Base { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_query = array(); + protected $_url = self::URL_LIST; + + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function get($key, $secret) { + return self::_getMultiple(__CLASS__, $key, $secret); + } + + /* Magic + -------------------------------*/ + /* Public Methods + -------------------------------*/ + public function setTitle($title) { + $this->_query['subject'] = $title; + return $this; + } + + public function setDetail($detail) { + $this->_query['additional_detail'] = $detail; + return $this; + } + + public function setQuestion() { + $this->_query['style'] = 'question'; + return $this; + } + + public function setProblem() { + $this->_query['style'] = 'problem'; + return $this; + } + + public function setPraise() { + $this->_query['style'] = 'praise'; + return $this; + } + + public function setIdea() { + $this->_query['style'] = 'idea'; + return $this; + } + + public function setUpdate() { + $this->_query['style'] = 'update'; + return $this; + } + + public function setTags($tags) { + Eden_Getsatisfaction_Error::get()->argument(1, 'string', 'array'); + + if(is_array($tags)) { + $tags = implode(',', $tags); + } + + $this->_query['keywords'] = $tags; + } + + public function setOverwriteKeywords() { + $this->_query['overwrite_keywords'] = 'true'; + return $this; + } + + public function setProducts($products) { + Eden_Getsatisfaction_Error::get()->argument(1, 'string', 'array'); + + if(is_array($products)) { + $tags = implode(',', $products); + } + + $this->_query['products'] = $products; + return $this; + } + + public function setFeeling($feeling) { + Eden_Getsatisfaction_Error::get()->argument(1, 'string'); + + $this->_query['emotitag']['feeling'] = $feeling; + return $this; + } + + public function setHappyFace() { + $this->_query['emotitag']['face'] = 'happy'; + return $this; + } + + public function setSadFace() { + $this->_query['emotitag']['face'] = 'sad'; + return $this; + } + + public function setSillyFace() { + $this->_query['emotitag']['face'] = 'silly'; + return $this; + } + + public function setIndifferentFace() { + $this->_query['emotitag']['face'] = 'indifferent'; + return $this; + } + + public function setIntensity($intensity) { + Eden_Getsatisfaction_Error::get()->argument(1, 'int'); + + if($intensity < 0) { + $intensity = 0; + } else if($intensity > 5) { + $intensity = 5; + } + + $this->_query['emotitag']['intensity'] = $intensity; + return $this; + } + + public function add($company) { + Eden_Getsatisfaction_Error::get()->argument(1, 'string', 'numeric'); + + $url = sprintf(Eden_GetSatisfaction_Topic::URL_COMPANY, $company); + + return $this->_post($url, array('topic' => $this->_query), true); + } + + public function edit($topic) { + Eden_Getsatisfaction_Error::get()->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..644660f --- /dev/null +++ b/library/eden/getsatisfaction/product.php @@ -0,0 +1,134 @@ + + + + +Untitled Document + + + + + +/* + * 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. + */ + +/** + * Get Satisfaction Product Methods + * + * @package Eden + * @category Get Satisfaction + * @author Christian Blanquera + * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ + */ +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 + -------------------------------*/ + /* Get + -------------------------------*/ + public static function get($key, $secret) { + return self::_getMultiple(__CLASS__, $key, $secret); + } + + /* Magic + -------------------------------*/ + /* Public Methods + -------------------------------*/ + public function setCompany($company) { + Eden_Getsatisfaction_Error::get()->argument(1, 'string', 'numeric'); + + $this->_url = sprintf(self::URL_COMPANY, $company); + return $this; + } + + public function setUser($user) { + Eden_Getsatisfaction_Error::get()->argument(1, 'string', 'numeric'); + + $this->_url = sprintf(self::URL_PEOPLE, $user); + return $this; + } + + public function setTopic($topic) { + Eden_Getsatisfaction_Error::get()->argument(1, 'string', 'numeric'); + + $this->_url = sprintf(self::URL_TOPIC, $topic); + return $this; + } + + public function setKeyword($keyword) { + Eden_Getsatisfaction_Error::get()->argument(1, 'string'); + + $this->_query['query'] = $keyword; + + return $this; + } + + public function sortByMostPopular() { + $this->_query['sort'] = 'most_popular'; + return $this; + } + + public function sortByLeastPopular() { + $this->_query['sort'] = 'least_popular'; + return $this; + } + + public function sortByAlphabet() { + $this->_query['sort'] = 'alpha'; + return $this; + } + + public function setPage($page = 0) { + Eden_Getsatisfaction_Error::get()->argument(1, 'int'); + + if($page < 0) { + $page = 0; + } + + $this->_query['page'] = $page; + + return $this; + } + + public function setLimit($limit = 10) { + Eden_Getsatisfaction_Error::get()->argument(1, 'int'); + + if($limit < 0) { + $limit = 10; + } + + $this->_query['limit'] = $limit; + + return $this; + } + + public function getList() { + if(isset($this->_query['status']) && is_array($this->_query['status'])) { + $this->_query['status'] = implode(',', $this->_query['status']); + } + + return $this->_getResponse($this->_url, $this->_query); + } + + /* 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..f09d30b --- /dev/null +++ b/library/eden/getsatisfaction/tag.php @@ -0,0 +1,94 @@ + +/* + * 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. + */ + +/** + * Get Satisfaction Tag Methods + * + * @package Eden + * @category Get Satisfaction + * @author Christian Blanquera + * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ + */ +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 + -------------------------------*/ + /* Get + -------------------------------*/ + public static function get($key, $secret) { + return self::_getMultiple(__CLASS__, $key, $secret); + } + + /* Magic + -------------------------------*/ + /* Public Methods + -------------------------------*/ + public function setCompany($company) { + Eden_Getsatisfaction_Error::get()->argument(1, 'string', 'numeric'); + + $this->_url = sprintf(self::URL_COMPANY, $company); + return $this; + } + + public function setTopic($topic) { + Eden_Getsatisfaction_Error::get()->argument(1, 'string', 'numeric'); + + $this->_url = sprintf(self::URL_TOPIC, $topic); + return $this; + } + + public function setPage($page = 0) { + Eden_Getsatisfaction_Error::get()->argument(1, 'int'); + + if($page < 0) { + $page = 0; + } + + $this->_query['page'] = $page; + + return $this; + } + + public function setLimit($limit = 10) { + Eden_Getsatisfaction_Error::get()->argument(1, 'int'); + + if($limit < 0) { + $limit = 10; + } + + $this->_query['limit'] = $limit; + + return $this; + } + + public function getList() { + if(isset($this->_query['status']) && is_array($this->_query['status'])) { + $this->_query['status'] = implode(',', $this->_query['status']); + } + + return $this->_getResponse($this->_url, $this->_query); + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file From 42281f8727d7d1e50c2a8d559204e66f1afba3ec Mon Sep 17 00:00:00 2001 From: sy Date: Mon, 19 Dec 2011 08:29:38 +0000 Subject: [PATCH 019/330] git-svn-id: http://svn.openovate.com/edenv2/trunk@19 38ede93f-50f4-44af-b0b3-68ccca78c181 --- library/eden/paypal/error.php | 52 ++++++++++++++++++++++++++++------- 1 file changed, 42 insertions(+), 10 deletions(-) diff --git a/library/eden/paypal/error.php b/library/eden/paypal/error.php index baec7d6..504e70f 100644 --- a/library/eden/paypal/error.php +++ b/library/eden/paypal/error.php @@ -1,10 +1,42 @@ - - - - -Untitled Document - - - - - \ No newline at end of file + +/* + * 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. + */ + +/** + * Eventbrite Errors + * + * @package Eden + * @category Paypal + * @author Christian Blanquera + * @version $Id: exception.php 1 2010-01-02 23:06:36Z blanquera $ + */ +class Eden_Paypal_Error extends Eden_Error { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function get($message = NULL, $code = 0) { + $class = __CLASS__; + return new $class($message, $code); + } + + /* Magic + -------------------------------*/ + /* Public Methods + -------------------------------*/ + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file From fd02c2a7cf896b059062a5c57c07075c8273f3b0 Mon Sep 17 00:00:00 2001 From: cblanquera Date: Tue, 20 Dec 2011 01:04:18 +0000 Subject: [PATCH 020/330] remove curl params git-svn-id: http://svn.openovate.com/edenv2/trunk@20 38ede93f-50f4-44af-b0b3-68ccca78c181 --- library/eden/curl.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/library/eden/curl.php b/library/eden/curl.php index f11186e..cbd9cc5 100644 --- a/library/eden/curl.php +++ b/library/eden/curl.php @@ -41,7 +41,6 @@ class Eden_Curl extends Eden_Class implements ArrayAccess { 'AutoReferer' => CURLOPT_AUTOREFERER, 'BinaryTransfer' => CURLOPT_BINARYTRANSFER, 'CookieSession' => CURLOPT_COOKIESESSION, - 'CertInfo' => CURLOPT_CERTINFO, 'CrlF' => CURLOPT_CRLF, 'DnsUseGlobalCache' => CURLOPT_DNS_USE_GLOBAL_CACHE, 'FailOnError' => CURLOPT_FAILONERROR, @@ -85,11 +84,9 @@ class Eden_Curl extends Eden_Class implements ArrayAccess { 'MaxConnects' => CURLOPT_MAXCONNECTS, 'MaxRedirs' => CURLOPT_MAXREDIRS, 'Port' => CURLOPT_PORT, - 'Protocols' => CURLOPT_PROTOCOLS, 'ProxyAuth' => CURLOPT_PROXYAUTH, 'ProxyPort' => CURLOPT_PROXYPORT, 'ProxyType' => CURLOPT_PROXYTYPE, - 'RedirProtocols' => CURLOPT_REDIR_PROTOCOLS, 'ResumeFrom' => CURLOPT_RESUME_FROM, 'SslVerifyHost' => CURLOPT_SSL_VERIFYHOST, 'SslVersion' => CURLOPT_SSLVERSION, @@ -143,7 +140,6 @@ class Eden_Curl extends Eden_Class implements ArrayAccess { protected static $_setCallbackKeys = array( 'HeaderFunction' => CURLOPT_HEADERFUNCTION, - 'ProgressFunction' => CURLOPT_PROGRESSFUNCTION, 'ReadFunction' => CURLOPT_READFUNCTION, 'WriteFunction' => CURLOPT_WRITEFUNCTION); From ba947230f09c92b80e64166122043fff775e07b4 Mon Sep 17 00:00:00 2001 From: cblanquera Date: Thu, 22 Dec 2011 03:27:19 +0000 Subject: [PATCH 021/330] cleanup git-svn-id: http://svn.openovate.com/edenv2/trunk@21 38ede93f-50f4-44af-b0b3-68ccca78c181 --- library/eden/getsatisfaction/post.php | 3 +- site/web/index.php | 5 +- site/web/sy.php | 48 ---- site/web/symon.php | 368 -------------------------- 4 files changed, 2 insertions(+), 422 deletions(-) delete mode 100644 site/web/sy.php delete mode 100644 site/web/symon.php diff --git a/library/eden/getsatisfaction/post.php b/library/eden/getsatisfaction/post.php index 56fbf04..a0335b6 100644 --- a/library/eden/getsatisfaction/post.php +++ b/library/eden/getsatisfaction/post.php @@ -23,7 +23,6 @@ class Eden_Getsatisfaction_Post extends Eden_Getsatisfaction_Base { /* Protected Properties -------------------------------*/ protected $_query = array(); - protected $_url = self::URL_LIST; /* Private Properties -------------------------------*/ @@ -141,7 +140,7 @@ public function setIntensity($intensity) { public function add($company) { Eden_Getsatisfaction_Error::get()->argument(1, 'string', 'numeric'); - $url = sprintf(Eden_GetSatisfaction_Topic::URL_COMPANY, $company); + $url = sprintf(Eden_Getsatisfaction_Topic::URL_COMPANY, $company); return $this->_post($url, array('topic' => $this->_query), true); } diff --git a/site/web/index.php b/site/web/index.php index 08b2c6b..530b593 100644 --- a/site/web/index.php +++ b/site/web/index.php @@ -87,7 +87,4 @@ /* Get the Response -------------------------------*/ -->getResponse(); - echo eden() - ->Eden_Getsatisfaction_Oauth("vbk4bs1klldy", "snw77ih836aoqoiylu2jgc286zy586as") - ->getLoginUrl('http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']); \ No newline at end of file +->getResponse(); \ No newline at end of file diff --git a/site/web/sy.php b/site/web/sy.php deleted file mode 100644 index f38449a..0000000 --- a/site/web/sy.php +++ /dev/null @@ -1,48 +0,0 @@ - -require_once dirname(__FILE__).'/../../library/eden.php'; - -eden(); - -class Eden_Timezone extends Eden_Class { - - public static function get() { - return self::_getSingleton(__CLASS__); - } - - public function getOffset($source, $destination) { - //source and destination will be in abbr format - //we need to figure out the full text format - $source = timezone_name_from_abbr($source); //should now be Europe/Berlin for example - $destination = timezone_name_from_abbr($destination); //should now be Europe/Berlin for example - - //now lets put that into DateTimeZone to get the offset - $source = new DateTimeZone($source); - $destination = new DateTimeZone($destination); - $gmt = new DateTimeZone('UTC'); - - //get GMT now - $gmt = new DateTime('now', $gmt); - - //get offset for each - $source = $source->getOffset($gmt); - $destination = $destination->getOffset($gmt); - - //calculate difference - return $destination - $source; - } - - public function convertTime($time, $source ,$destination) { - //fugureout whats the diff of tw0 timezone - //add or subtract the time according from diff - return $time + $this->getOffset($source, $destination); - } - -} - -echo date('F d, Y g:iA', Eden_Timezone::get()->convertTime(time(), 'HKT', 'PDT')); - - - - - -//echo eden()->User('Chris')->getName(); diff --git a/site/web/symon.php b/site/web/symon.php deleted file mode 100644 index 2ca7c3a..0000000 --- a/site/web/symon.php +++ /dev/null @@ -1,368 +0,0 @@ - -/* - * 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 dirname(__FILE__).'/../front.php'; - -/* Get Application --------------------------------*/ -front() - -/* Set Debug --------------------------------*/ -->setDebug(E_ALL, true) - -/* Set Autoload --------------------------------*/ -->addRoot(dirname(__FILE__).'/..') -->addRoot(dirname(__FILE__).'/../model') - -/* Set Class Routing --------------------------------*/ -->setClasses('../front/config/classes.php') - -/* Set Method Routing --------------------------------*/ -->setMethods('../front/config/methods.php') - -/* Set Paths --------------------------------*/ -->setPaths(); - -/////////////////////////////////////////////////////////////////////////////////////////////////// -session_start(); - -$tweets = front()->Eden_Twitter_Timelines('xm8mraLDw2mgA1b2SKAaA','dpUyjXhxSbO3inhlqX5DaSPlLsfV2gwMaEKaSQ0WKns'); - -echo 'GET
'.print_r($_GET, true).'
'; -echo 'SESSION
'.print_r($_SESSION, true).'
'; - -//if user wants to logout -if(isset($_GET['logout'])) { - //log them out - unset($_SESSION['request_token'], $_SESSION['request_token_secret'], $_SESSION['access_token'], $_SESSION['access_token_secret']); - header('Location: /symon.php'); -} - -//if the user is logged in -if(isset($_SESSION['access_token'], $_SESSION['access_token_secret'])) { - //lets do shit - //ACCOUNTS - //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->updateColor(); - //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->updateBackground(); - //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->updateProfile('sy buenavista','openovate.com','carmona','small'); - //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->logOut(); - //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->getCredentials(); - //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->getLimit(); - //LIST - //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->getStatus(); - //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->getList(297169759); - //FAVORITES - //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->removeFavorite(139245530340532224); - //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->addFavorite(139245530340532224); - //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->getList('sy'); - //SUGGESTIONS - //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->getRecentStatus('philippines'); - //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->getCategory('taylorswift13'); - //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->getSuggestion(); - //USERS - //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->getContributors(17919972,'taylorswift13'); - //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->getDetail('taylorswift13'); - //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->search('taylorswift13'); - //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->getProfileImage('iamsuperbianca'); - //SEARCH - //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->search('test'); - //TIMELINES - //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->getByUser('sy'); - //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->getToUser('symon','sy'); - //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->getList('Qginalyn'); - //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->getOf(3); - //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->getTo(3); - //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->getBy(3); - //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->getPublic(); - //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->getMention(5); - //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->getTimeline(5); - // - //DIRECTMESSAGE - //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->getSent(); - //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->getSent(); - //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->newMessage('sdaas','sybuena2') - //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->remove(138532788428226560); - //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->getList('kamoteche','cblanquera'); - //tweets - //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->getWhoRetweetedIds(139161266102079488); - //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->getRetweets(139161266102079488); - //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->remove(138542385809469440); - //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->retweet(138558867679354880); - //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->update('test api again'); - //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->getDetail(138507381846970369); - //FRIENDS - //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->getNoRetweets(); - //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->update('XianLimm'); - //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->getDetail('symon','sy'); - //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->getFollowers('sy'); - //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->incomingFriends(); - //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->outgoingFriends(); - //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->friendsExist('kamoteche','cblanquera'); - //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->getFriends('kamoteche'); - //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->unfollowFriends('iamjohnprats'); - //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->followFriends('iamjohnprats'); - - - - /* - $timeline = array(); - - //get tweets - $response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->getPublic(); - print_r($response); - //set default timezone to america/los angeles - date_default_timezone_set('America/Los_Angeles'); - //for each tweet - foreach($response as $tweet) { - //get the unix time this item was created - $time = strtotime($tweet['created_at']); - //mark item as twitter - $tweet['social_media'] = 'twitter'; - //put this item in our global timeline - $timeline[$time] = $tweet; - } - - //get tumblr list - //for each tumblr - //get the unix time this item was created - //mark item as tumblr - //put this item in our global timeline - - //get facebook list - //for each facebook - //get the unix time this item was created - //mark item as facebook - //put this item in our global timeline - - krsort($timeline); - - ?> - - ------------------!!!!!!!!!!!!!!!!!!!!!!!!!!!!----------------------
- - -
- -


-


- - - - - - - ------------------!!!!!!!!!!!!!!!!!!!!!!!!!!!!---------------------- - */ - - //print_r($response); - //print_r($tweets->getMeta()); - -//if the user just authorized us -} else if(isset($_GET['oauth_token'])) { - //upgrade one time access token to another access token that will last for 1 hour - $token = $tweets->getAccessToken($_GET['oauth_token'], $_SESSION['request_token_secret']); - - //store this upgraded access token in our user session - $_SESSION['access_token'] = $token['oauth_token']; - $_SESSION['access_token_secret'] = $token['oauth_token_secret']; - - //redirect - header('Location: /symon.php'); - -//the user at this point is logged out -} else { - //get the request token - $token = $tweets->getRequestToken(); - $_SESSION['request_token'] = $token['oauth_token']; - $_SESSION['request_token_secret'] = $token['oauth_token_secret']; - - //prompt user to login - echo 'Login'; -} - - -//////////////////////////////////////////////////////////////////// - -$tumblr = front()->Eden_Tumblr_User('49Sb8LrxMKh4lErDN69yp6VwgCmOffYgOrigEMgM2wwvELx6Ew', - 'akHvmf5Fsoo7U9ztx3triIx2mczWfze3SEgIgaiGBYTlkqD0kN'); -$tumblrBlog = front()->Eden_Tumblr_Blog('49Sb8LrxMKh4lErDN69yp6VwgCmOffYgOrigEMgM2wwvELx6Ew', - 'akHvmf5Fsoo7U9ztx3triIx2mczWfze3SEgIgaiGBYTlkqD0kN'); - -echo 'GET
'.print_r($_GET, true).'
'; -echo 'SESSION
'.print_r($_SESSION, true).'
'; - -//if user wants to logout -if(isset($_GET['logout'])) { - //log them out - unset($_SESSION['request_token'], $_SESSION['request_token_secret'], $_SESSION['access_token'], $_SESSION['access_token_secret']); - header('Location: /symon.php'); -} - -//if the user is logged in -if(isset($_SESSION['access_token'], $_SESSION['access_token_secret'])) { - //lets do shit - - //set timezone - date_default_timezone_set('America/Los_Angeles'); - $timeline = array(); - - //get Tweets////////////////////////////////////////////////////////////////////////////////////////////// - $response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->getPublic(); - //print_r($response); - //for each tweet - foreach($response as $tweet) { - //get the unix time this item was created - $time = strtotime($tweet['created_at']); - //mark item as twitter - $tweet['social_media'] = 'twitter'; - //put this item in our global timeline - $timeline[$time] = $tweet; - } - - //get Tumblr list///////////////////////////////////////////////////////////////////////////////////////// - $response = $tumblr->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->getUser(); - //get Tumblr Avatar - //$avatar = $tumblrBlog->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->getAvatar(); - //for each tumblr - foreach($response['response']['posts'] as $tumbler) { - //get the unix time this item was created - $time = strtotime($tumbler['date']); - //mark item as tumbler - $tumbler['social_media'] = 'tumblr'; - //put this item in our global timeline - $timeline[$time] = $tumbler; - } - - //sort the date by the latest post to the older - krsort($timeline); - ?> - -
- - - - -
_____________________________TUMBLR.COM_____________________________
- -

- - -

- - - -

- - - -
______________________________TWITTER.COM_______________________
-
-

- -

'; ?> - - - - - - - - - - -

- - - output($response); - //echo ""; print_r($response); echo ""; - //print_r($response); - //print_r($tumblr->getMeta()); - -//if the user just authorized us -} else if(isset($_GET['oauth_token'])) { - //upgrade one time access token to another access token that will last for 1 hour - $token = $tumblr->getAccessToken($_GET['oauth_token'], $_SESSION['request_token_secret'],$_GET['oauth_verifier']); - - //store this upgraded access token in our user session - $_SESSION['access_token'] = $token['oauth_token']; - $_SESSION['access_token_secret'] = $token['oauth_token_secret']; - - //redirect - header('Location: http://eden.openovate.com/symon.php'); - -//the user at this point is logged out -} else { - //get the request token - - $token = $tumblr->getRequestToken(); - $_SESSION['request_token'] = $token['oauth_token']; - $_SESSION['request_token_secret'] = $token['oauth_token_secret']; - - //prompt user to login - echo 'Login'; -} - -/////////////////////////////////////////////////// -/* -$satisfaction = front()->Eden_GetSatisfaction_Topic('ml57owkz0dl8', - '0uoub6rt8tx5tks7m76jln31sc4f98vh'); - -echo 'GET
'.print_r($_GET, true).'
'; -echo 'SESSION
'.print_r($_SESSION, true).'
'; - -//if user wants to logout -if(isset($_GET['logout'])) { - //log them out - unset($_SESSION['request_token'], $_SESSION['request_token_secret'], $_SESSION['access_token'], $_SESSION['access_token_secret']); - header('Location: /symon.php'); -} - -//if the user is logged in -if(isset($_SESSION['access_token'], $_SESSION['access_token_secret'])) { - //lets do shit - //ACCOUNTS - //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->updateColor(); - - print_r($response); - print_r($satisfaction->getMeta()); - -//if the user just authorized us -} else if(isset($_GET['oauth_token'])) { - //upgrade one time access token to another access token that will last for 1 hour - $token = $satisfaction->getAccessToken($_GET['oauth_token'], $_SESSION['request_token_secret']); - - //store this upgraded access token in our user session - $_SESSION['access_token'] = $token['oauth_token']; - $_SESSION['access_token_secret'] = $token['oauth_token_secret']; - - //redirect - header('Location: /symon.php'); - -//the user at this point is logged out -} else { - //get the request token - $token = $satisfaction->getRequestToken(); - $_SESSION['request_token'] = $token['oauth_token']; - $_SESSION['request_token_secret'] = $token['oauth_token_secret']; - - //prompt user to login - echo 'Login'; -} -*/ - -/////////////////////////////////////////// - -?> \ No newline at end of file From c0b111e394c62807213302a651b469446bf112ea Mon Sep 17 00:00:00 2001 From: sy Date: Thu, 22 Dec 2011 03:28:24 +0000 Subject: [PATCH 022/330] git-svn-id: http://svn.openovate.com/edenv2/trunk@22 38ede93f-50f4-44af-b0b3-68ccca78c181 --- site/web/symon.php | 371 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 371 insertions(+) create mode 100644 site/web/symon.php diff --git a/site/web/symon.php b/site/web/symon.php new file mode 100644 index 0000000..7c20efc --- /dev/null +++ b/site/web/symon.php @@ -0,0 +1,371 @@ + +/* + * 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 dirname(__FILE__).'/../front.php'; + +/* Get Application +-------------------------------*/ +front() + +/* Set Debug +-------------------------------*/ +->setDebug(E_ALL, true) + +/* Set Autoload +-------------------------------*/ +->addRoot(dirname(__FILE__).'/..') +->addRoot(dirname(__FILE__).'/../model') + +/* Set Class Routing +-------------------------------*/ +->setClasses('../front/config/classes.php') + +/* Set Method Routing +-------------------------------*/ +->setMethods('../front/config/methods.php') + +/* Set Paths +-------------------------------*/ +->setPaths(); + +/////////////////////////////////////////////////////////////////////////////////////////////////// +session_start(); + +$tweets = front()->Eden_Twitter_Timelines('xm8mraLDw2mgA1b2SKAaA','dpUyjXhxSbO3inhlqX5DaSPlLsfV2gwMaEKaSQ0WKns'); + +echo 'GET
'.print_r($_GET, true).'
'; +echo 'SESSION
'.print_r($_SESSION, true).'
'; + +//if user wants to logout +if(isset($_GET['logout'])) { + //log them out + unset($_SESSION['request_token'], $_SESSION['request_token_secret'], $_SESSION['access_token'], $_SESSION['access_token_secret']); + header('Location: /symon.php'); +} + +//if the user is logged in +if(isset($_SESSION['access_token'], $_SESSION['access_token_secret'])) { + //lets do shit + //ACCOUNTS + //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->updateColor(); + //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->updateBackground(); + //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->updateProfile('sy buenavista','openovate.com','carmona','small'); + //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->logOut(); + //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->getCredentials(); + //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->getLimit(); + //LIST + //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->getStatus(); + //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->getList(297169759); + //FAVORITES + //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->removeFavorite(139245530340532224); + //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->addFavorite(139245530340532224); + //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->getList('sy'); + //SUGGESTIONS + //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->getRecentStatus('philippines'); + //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->getCategory('taylorswift13'); + //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->getSuggestion(); + //USERS + //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->getContributors(17919972,'taylorswift13'); + //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->getDetail('taylorswift13'); + //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->search('taylorswift13'); + //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->getProfileImage('iamsuperbianca'); + //SEARCH + //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->search('test'); + //TIMELINES + //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->getByUser('sy'); + //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->getToUser('symon','sy'); + //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->getList('Qginalyn'); + //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->getOf(3); + //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->getTo(3); + //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->getBy(3); + //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->getPublic(); + //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->getMention(5); + //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->getTimeline(5); + // + //DIRECTMESSAGE + //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->getSent(); + //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->getSent(); + //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->newMessage('sdaas','sybuena2') + //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->remove(138532788428226560); + //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->getList('kamoteche','cblanquera'); + //tweets + //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->getWhoRetweetedIds(139161266102079488); + //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->getRetweets(139161266102079488); + //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->remove(138542385809469440); + //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->retweet(138558867679354880); + //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->update('test api again'); + //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->getDetail(138507381846970369); + //FRIENDS + //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->getNoRetweets(); + //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->update('XianLimm'); + //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->getDetail('symon','sy'); + //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->getFollowers('sy'); + //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->incomingFriends(); + //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->outgoingFriends(); + //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->friendsExist('kamoteche','cblanquera'); + //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->getFriends('kamoteche'); + //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->unfollowFriends('iamjohnprats'); + //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->followFriends('iamjohnprats'); + + + + /* + $timeline = array(); + + //get tweets + $response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->getPublic(); + print_r($response); + //set default timezone to america/los angeles + date_default_timezone_set('America/Los_Angeles'); + //for each tweet + foreach($response as $tweet) { + //get the unix time this item was created + $time = strtotime($tweet['created_at']); + //mark item as twitter + $tweet['social_media'] = 'twitter'; + //put this item in our global timeline + $timeline[$time] = $tweet; + } + + //get tumblr list + //for each tumblr + //get the unix time this item was created + //mark item as tumblr + //put this item in our global timeline + + //get facebook list + //for each facebook + //get the unix time this item was created + //mark item as facebook + //put this item in our global timeline + + krsort($timeline); + + ?> + + ------------------!!!!!!!!!!!!!!!!!!!!!!!!!!!!----------------------
+ + +
+ +


+


+ + + + + + */ + ------------------!!!!!!!!!!!!!!!!!!!!!!!!!!!!---------------------- + + + //print_r($response); + //print_r($tweets->getMeta()); + +//if the user just authorized us +} else if(isset($_GET['oauth_token'])) { + //upgrade one time access token to another access token that will last for 1 hour + $token = $tweets->getAccessToken($_GET['oauth_token'], $_SESSION['request_token_secret']); + + //store this upgraded access token in our user session + $_SESSION['access_token'] = $token['oauth_token']; + $_SESSION['access_token_secret'] = $token['oauth_token_secret']; + + //redirect + header('Location: /symon.php'); + +//the user at this point is logged out +} else { + //get the request token + $token = $tweets->getRequestToken(); + $_SESSION['request_token'] = $token['oauth_token']; + $_SESSION['request_token_secret'] = $token['oauth_token_secret']; + + //prompt user to login + echo 'Login'; +} + + +//////////////////////////////////////////////////////////////////// + +$tumblr = front()->Eden_Tumblr_User('49Sb8LrxMKh4lErDN69yp6VwgCmOffYgOrigEMgM2wwvELx6Ew', + 'akHvmf5Fsoo7U9ztx3triIx2mczWfze3SEgIgaiGBYTlkqD0kN'); +$tumblrBlog = front()->Eden_Tumblr_Blog('49Sb8LrxMKh4lErDN69yp6VwgCmOffYgOrigEMgM2wwvELx6Ew', + 'akHvmf5Fsoo7U9ztx3triIx2mczWfze3SEgIgaiGBYTlkqD0kN'); + +echo 'GET
'.print_r($_GET, true).'
'; +echo 'SESSION
'.print_r($_SESSION, true).'
'; + +//if user wants to logout +if(isset($_GET['logout'])) { + //log them out + unset($_SESSION['request_token'], $_SESSION['request_token_secret'], $_SESSION['access_token'], $_SESSION['access_token_secret']); + header('Location: /symon.php'); +} + +//if the user is logged in +if(isset($_SESSION['access_token'], $_SESSION['access_token_secret'])) { + //lets do shit + + //set timezone + date_default_timezone_set('America/Los_Angeles'); + $timeline = array(); + + //get Tweets////////////////////////////////////////////////////////////////////////////////////////////// + $response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->getPublic(); + //print_r($response); + //for each tweet + foreach($response as $tweet) { + //get the unix time this item was created + $time = strtotime($tweet['created_at']); + //mark item as twitter + $tweet['social_media'] = 'twitter'; + //put this item in our global timeline + $timeline[$time] = $tweet; + } + + //get Tumblr list///////////////////////////////////////////////////////////////////////////////////////// + $response = $tumblr->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->getUser(); + //get Tumblr Avatar + //$avatar = $tumblrBlog->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->getAvatar(); + //for each tumblr + foreach($response['response']['posts'] as $tumbler) { + //get the unix time this item was created + $time = strtotime($tumbler['date']); + //mark item as tumbler + $tumbler['social_media'] = 'tumblr'; + //put this item in our global timeline + $timeline[$time] = $tumbler; + } + + //sort the date by the latest post to the older + krsort($timeline); + ?> + +
+ + + + +
_____________________________TUMBLR.COM_____________________________
+ +

+ + +

+ + + +

+ + + +
______________________________TWITTER.COM_______________________
+
+

+ +

'; ?> + + + + + + + + + + +

+ + + output($response); + //echo ""; print_r($response); echo ""; + //print_r($response); + //print_r($tumblr->getMeta()); + +//if the user just authorized us +} else if(isset($_GET['oauth_token'])) { + //upgrade one time access token to another access token that will last for 1 hour + $token = $tumblr->getAccessToken($_GET['oauth_token'], $_SESSION['request_token_secret'],$_GET['oauth_verifier']); + + //store this upgraded access token in our user session + $_SESSION['access_token'] = $token['oauth_token']; + $_SESSION['access_token_secret'] = $token['oauth_token_secret']; + + //redirect + header('Location: http://eden.openovate.com/symon.php'); + +//the user at this point is logged out +} else { + //get the request token + + $token = $tumblr->getRequestToken(); + $_SESSION['request_token'] = $token['oauth_token']; + $_SESSION['request_token_secret'] = $token['oauth_token_secret']; + + //prompt user to login + echo 'Login'; +} + +/////////////////////////////////////////////////// +/* +$satisfaction = front()->Eden_GetSatisfaction_Topic('ml57owkz0dl8', + '0uoub6rt8tx5tks7m76jln31sc4f98vh'); + +echo 'GET
'.print_r($_GET, true).'
'; +echo 'SESSION
'.print_r($_SESSION, true).'
'; + +//if user wants to logout +if(isset($_GET['logout'])) { + //log them out + unset($_SESSION['request_token'], $_SESSION['request_token_secret'], $_SESSION['access_token'], $_SESSION['access_token_secret']); + header('Location: /symon.php'); +} + +//if the user is logged in +if(isset($_SESSION['access_token'], $_SESSION['access_token_secret'])) { + //lets do shit + //ACCOUNTS + //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->updateColor(); + + print_r($response); + print_r($satisfaction->getMeta()); + +//if the user just authorized us +} else if(isset($_GET['oauth_token'])) { + //upgrade one time access token to another access token that will last for 1 hour + $token = $satisfaction->getAccessToken($_GET['oauth_token'], $_SESSION['request_token_secret']); + + //store this upgraded access token in our user session + $_SESSION['access_token'] = $token['oauth_token']; + $_SESSION['access_token_secret'] = $token['oauth_token_secret']; + + //redirect + header('Location: /symon.php'); + +//the user at this point is logged out +} else { + //get the request token + $token = $satisfaction->getRequestToken(); + $_SESSION['request_token'] = $token['oauth_token']; + $_SESSION['request_token_secret'] = $token['oauth_token_secret']; + + //prompt user to login + echo 'Login'; +} +*/ + +/////////////////////////////////////////// + + + + +?> \ No newline at end of file From 22e9ae667adcc380938b93c2600c945d6460b0ac Mon Sep 17 00:00:00 2001 From: sy Date: Thu, 22 Dec 2011 03:28:45 +0000 Subject: [PATCH 023/330] git-svn-id: http://svn.openovate.com/edenv2/trunk@23 38ede93f-50f4-44af-b0b3-68ccca78c181 --- site/web/symon.php | 371 --------------------------------------------- 1 file changed, 371 deletions(-) delete mode 100644 site/web/symon.php diff --git a/site/web/symon.php b/site/web/symon.php deleted file mode 100644 index 7c20efc..0000000 --- a/site/web/symon.php +++ /dev/null @@ -1,371 +0,0 @@ - -/* - * 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 dirname(__FILE__).'/../front.php'; - -/* Get Application --------------------------------*/ -front() - -/* Set Debug --------------------------------*/ -->setDebug(E_ALL, true) - -/* Set Autoload --------------------------------*/ -->addRoot(dirname(__FILE__).'/..') -->addRoot(dirname(__FILE__).'/../model') - -/* Set Class Routing --------------------------------*/ -->setClasses('../front/config/classes.php') - -/* Set Method Routing --------------------------------*/ -->setMethods('../front/config/methods.php') - -/* Set Paths --------------------------------*/ -->setPaths(); - -/////////////////////////////////////////////////////////////////////////////////////////////////// -session_start(); - -$tweets = front()->Eden_Twitter_Timelines('xm8mraLDw2mgA1b2SKAaA','dpUyjXhxSbO3inhlqX5DaSPlLsfV2gwMaEKaSQ0WKns'); - -echo 'GET
'.print_r($_GET, true).'
'; -echo 'SESSION
'.print_r($_SESSION, true).'
'; - -//if user wants to logout -if(isset($_GET['logout'])) { - //log them out - unset($_SESSION['request_token'], $_SESSION['request_token_secret'], $_SESSION['access_token'], $_SESSION['access_token_secret']); - header('Location: /symon.php'); -} - -//if the user is logged in -if(isset($_SESSION['access_token'], $_SESSION['access_token_secret'])) { - //lets do shit - //ACCOUNTS - //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->updateColor(); - //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->updateBackground(); - //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->updateProfile('sy buenavista','openovate.com','carmona','small'); - //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->logOut(); - //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->getCredentials(); - //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->getLimit(); - //LIST - //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->getStatus(); - //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->getList(297169759); - //FAVORITES - //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->removeFavorite(139245530340532224); - //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->addFavorite(139245530340532224); - //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->getList('sy'); - //SUGGESTIONS - //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->getRecentStatus('philippines'); - //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->getCategory('taylorswift13'); - //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->getSuggestion(); - //USERS - //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->getContributors(17919972,'taylorswift13'); - //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->getDetail('taylorswift13'); - //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->search('taylorswift13'); - //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->getProfileImage('iamsuperbianca'); - //SEARCH - //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->search('test'); - //TIMELINES - //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->getByUser('sy'); - //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->getToUser('symon','sy'); - //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->getList('Qginalyn'); - //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->getOf(3); - //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->getTo(3); - //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->getBy(3); - //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->getPublic(); - //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->getMention(5); - //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->getTimeline(5); - // - //DIRECTMESSAGE - //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->getSent(); - //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->getSent(); - //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->newMessage('sdaas','sybuena2') - //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->remove(138532788428226560); - //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->getList('kamoteche','cblanquera'); - //tweets - //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->getWhoRetweetedIds(139161266102079488); - //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->getRetweets(139161266102079488); - //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->remove(138542385809469440); - //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->retweet(138558867679354880); - //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->update('test api again'); - //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->getDetail(138507381846970369); - //FRIENDS - //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->getNoRetweets(); - //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->update('XianLimm'); - //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->getDetail('symon','sy'); - //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->getFollowers('sy'); - //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->incomingFriends(); - //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->outgoingFriends(); - //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->friendsExist('kamoteche','cblanquera'); - //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->getFriends('kamoteche'); - //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->unfollowFriends('iamjohnprats'); - //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->followFriends('iamjohnprats'); - - - - /* - $timeline = array(); - - //get tweets - $response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->getPublic(); - print_r($response); - //set default timezone to america/los angeles - date_default_timezone_set('America/Los_Angeles'); - //for each tweet - foreach($response as $tweet) { - //get the unix time this item was created - $time = strtotime($tweet['created_at']); - //mark item as twitter - $tweet['social_media'] = 'twitter'; - //put this item in our global timeline - $timeline[$time] = $tweet; - } - - //get tumblr list - //for each tumblr - //get the unix time this item was created - //mark item as tumblr - //put this item in our global timeline - - //get facebook list - //for each facebook - //get the unix time this item was created - //mark item as facebook - //put this item in our global timeline - - krsort($timeline); - - ?> - - ------------------!!!!!!!!!!!!!!!!!!!!!!!!!!!!----------------------
- - -
- -


-


- - - - - - */ - ------------------!!!!!!!!!!!!!!!!!!!!!!!!!!!!---------------------- - - - //print_r($response); - //print_r($tweets->getMeta()); - -//if the user just authorized us -} else if(isset($_GET['oauth_token'])) { - //upgrade one time access token to another access token that will last for 1 hour - $token = $tweets->getAccessToken($_GET['oauth_token'], $_SESSION['request_token_secret']); - - //store this upgraded access token in our user session - $_SESSION['access_token'] = $token['oauth_token']; - $_SESSION['access_token_secret'] = $token['oauth_token_secret']; - - //redirect - header('Location: /symon.php'); - -//the user at this point is logged out -} else { - //get the request token - $token = $tweets->getRequestToken(); - $_SESSION['request_token'] = $token['oauth_token']; - $_SESSION['request_token_secret'] = $token['oauth_token_secret']; - - //prompt user to login - echo 'Login'; -} - - -//////////////////////////////////////////////////////////////////// - -$tumblr = front()->Eden_Tumblr_User('49Sb8LrxMKh4lErDN69yp6VwgCmOffYgOrigEMgM2wwvELx6Ew', - 'akHvmf5Fsoo7U9ztx3triIx2mczWfze3SEgIgaiGBYTlkqD0kN'); -$tumblrBlog = front()->Eden_Tumblr_Blog('49Sb8LrxMKh4lErDN69yp6VwgCmOffYgOrigEMgM2wwvELx6Ew', - 'akHvmf5Fsoo7U9ztx3triIx2mczWfze3SEgIgaiGBYTlkqD0kN'); - -echo 'GET
'.print_r($_GET, true).'
'; -echo 'SESSION
'.print_r($_SESSION, true).'
'; - -//if user wants to logout -if(isset($_GET['logout'])) { - //log them out - unset($_SESSION['request_token'], $_SESSION['request_token_secret'], $_SESSION['access_token'], $_SESSION['access_token_secret']); - header('Location: /symon.php'); -} - -//if the user is logged in -if(isset($_SESSION['access_token'], $_SESSION['access_token_secret'])) { - //lets do shit - - //set timezone - date_default_timezone_set('America/Los_Angeles'); - $timeline = array(); - - //get Tweets////////////////////////////////////////////////////////////////////////////////////////////// - $response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->getPublic(); - //print_r($response); - //for each tweet - foreach($response as $tweet) { - //get the unix time this item was created - $time = strtotime($tweet['created_at']); - //mark item as twitter - $tweet['social_media'] = 'twitter'; - //put this item in our global timeline - $timeline[$time] = $tweet; - } - - //get Tumblr list///////////////////////////////////////////////////////////////////////////////////////// - $response = $tumblr->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->getUser(); - //get Tumblr Avatar - //$avatar = $tumblrBlog->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->getAvatar(); - //for each tumblr - foreach($response['response']['posts'] as $tumbler) { - //get the unix time this item was created - $time = strtotime($tumbler['date']); - //mark item as tumbler - $tumbler['social_media'] = 'tumblr'; - //put this item in our global timeline - $timeline[$time] = $tumbler; - } - - //sort the date by the latest post to the older - krsort($timeline); - ?> - -
- - - - -
_____________________________TUMBLR.COM_____________________________
- -

- - -

- - - -

- - - -
______________________________TWITTER.COM_______________________
-
-

- -

'; ?> - - - - - - - - - - -

- - - output($response); - //echo ""; print_r($response); echo ""; - //print_r($response); - //print_r($tumblr->getMeta()); - -//if the user just authorized us -} else if(isset($_GET['oauth_token'])) { - //upgrade one time access token to another access token that will last for 1 hour - $token = $tumblr->getAccessToken($_GET['oauth_token'], $_SESSION['request_token_secret'],$_GET['oauth_verifier']); - - //store this upgraded access token in our user session - $_SESSION['access_token'] = $token['oauth_token']; - $_SESSION['access_token_secret'] = $token['oauth_token_secret']; - - //redirect - header('Location: http://eden.openovate.com/symon.php'); - -//the user at this point is logged out -} else { - //get the request token - - $token = $tumblr->getRequestToken(); - $_SESSION['request_token'] = $token['oauth_token']; - $_SESSION['request_token_secret'] = $token['oauth_token_secret']; - - //prompt user to login - echo 'Login'; -} - -/////////////////////////////////////////////////// -/* -$satisfaction = front()->Eden_GetSatisfaction_Topic('ml57owkz0dl8', - '0uoub6rt8tx5tks7m76jln31sc4f98vh'); - -echo 'GET
'.print_r($_GET, true).'
'; -echo 'SESSION
'.print_r($_SESSION, true).'
'; - -//if user wants to logout -if(isset($_GET['logout'])) { - //log them out - unset($_SESSION['request_token'], $_SESSION['request_token_secret'], $_SESSION['access_token'], $_SESSION['access_token_secret']); - header('Location: /symon.php'); -} - -//if the user is logged in -if(isset($_SESSION['access_token'], $_SESSION['access_token_secret'])) { - //lets do shit - //ACCOUNTS - //$response = $tweets->setAccessToken($_SESSION['access_token'], $_SESSION['access_token_secret'])->updateColor(); - - print_r($response); - print_r($satisfaction->getMeta()); - -//if the user just authorized us -} else if(isset($_GET['oauth_token'])) { - //upgrade one time access token to another access token that will last for 1 hour - $token = $satisfaction->getAccessToken($_GET['oauth_token'], $_SESSION['request_token_secret']); - - //store this upgraded access token in our user session - $_SESSION['access_token'] = $token['oauth_token']; - $_SESSION['access_token_secret'] = $token['oauth_token_secret']; - - //redirect - header('Location: /symon.php'); - -//the user at this point is logged out -} else { - //get the request token - $token = $satisfaction->getRequestToken(); - $_SESSION['request_token'] = $token['oauth_token']; - $_SESSION['request_token_secret'] = $token['oauth_token_secret']; - - //prompt user to login - echo 'Login'; -} -*/ - -/////////////////////////////////////////// - - - - -?> \ No newline at end of file From af9076da76c2a70c11cbe01166e9c407ddf40fe5 Mon Sep 17 00:00:00 2001 From: cblanquera Date: Thu, 22 Dec 2011 04:17:43 +0000 Subject: [PATCH 024/330] overriding classes git-svn-id: http://svn.openovate.com/edenv2/trunk@24 38ede93f-50f4-44af-b0b3-68ccca78c181 --- library/eden/class.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/library/eden/class.php b/library/eden/class.php index 92e179f..6a1e187 100755 --- a/library/eden/class.php +++ b/library/eden/class.php @@ -149,6 +149,8 @@ protected static function _getSingleton($class) { $args = func_get_args(); $class = array_shift($args); + $class = Eden_Route::get()->getRouteClass($class, $class); + try { self::$_instances[$class] = self::_getInstance($class, $args); } catch(Reflection_Exception $e) { @@ -167,6 +169,8 @@ protected static function _getMultiple($class) { $args = func_get_args(); $class = array_shift($args); + $class = Eden_Route::get()->getRouteClass($class, $class); + try { return self::_getInstance($class, $args); } catch(Reflection_Exception $e) { From 83f0895c0758e7604ac5eec90ab6832b61eb9f1e Mon Sep 17 00:00:00 2001 From: cblanquera Date: Thu, 22 Dec 2011 04:48:23 +0000 Subject: [PATCH 025/330] model git-svn-id: http://svn.openovate.com/edenv2/trunk@25 38ede93f-50f4-44af-b0b3-68ccca78c181 --- library/eden/mysql/model.php | 313 +++++++++++++++++++++++++++++++++++ 1 file changed, 313 insertions(+) create mode 100644 library/eden/mysql/model.php diff --git a/library/eden/mysql/model.php b/library/eden/mysql/model.php new file mode 100644 index 0000000..3acfebc --- /dev/null +++ b/library/eden/mysql/model.php @@ -0,0 +1,313 @@ + +/* + * 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. + */ + +/** + * + * @package Eden + * @category registry + * @author Christian Blanquera + * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ + */ +class Eden_Mysql_Model extends Eden_Class implements ArrayAccess, Iterator { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_primary = NULL; + protected $_meta = array(); + protected $_data = array(); + + protected $_database = NULL; + protected $_table = NULL; + + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function get(Eden_Mysql $database, $table) { + return self::_getMultiple(__CLASS__, $database, $table); + } + + /* Magic + -------------------------------*/ + public function __construct($database, $table) { + $this->_database = $database; + $this->_table = $table; + + //set meta data + $this->_setMetaData(); + } + + public function __call($name, $args) { + //if the method starts with get + if(strpos($name, 'get') === 0) { + $key = preg_replace("/([A-Z])/", "_$1", $name); + //get rid of get_ + $key = strtolower(substr($key, 4)); + + if(isset($this->_meta[$key])) { + return $this->_data[$key]; + } + } else if (strpos($name, 'set') === 0) { + $key = preg_replace("/([A-Z])/", "_$1", $name); + //get rid of get_ + $key = strtolower(substr($key, 4)); + + return $this->__set($key, $args[0]); + } + + try { + return parent::__call($name, $args); + } catch(Eden_Type_Error $e) { + throw new Eden_Mysql_Error($e->getMessage()); + } + } + + public function __get($name) { + if(isset($this->_data[$name])) { + return $this->_data[$name]; + } + + return NULL; + } + + public function __set($name, $value) { + if(isset($this->_meta[$name])) { + $this->_data[$name] = $value; + return $this; + } + + //throw an error + Eden_Mysql_Error::get() + ->setMessage(Eden_Mysql_Error::SET_INVALID) + ->addVariable($name) + ->addVariable($this->_table) + ->trigger(); + } + + public function __toString() { + return json_encode($this->_data); + } + + /* Public Methods + -------------------------------*/ + /** + * Loads data into the model + * + * @param array + * @return this + */ + public function load($data, $column = NULL) { + Eden_Mysql_Error::get() + ->argument(1, 'numeric', 'array', 'string') + ->argument(2, 'string', 'null'); + + if(is_scalar($data)) { + if(!is_string($column)) { + $column = $this->_primary; + } + + $this->_data = $this->_database->getRow($this->_table, $column, $data); + + return $this; + } + + //for each data + foreach($data as $name => $value) { + //if this is not set in the meta data + if(!isset($this->_meta[$name])) { + //throw an error + Eden_Mysql_Error::get() + ->setMessage(Eden_Mysql_Error::SET_INVALID) + ->addVariable($name) + ->addVariable($this->_table) + ->trigger(); + } + + $this->_data[$name] = $value; + } + + return $this; + } + + public function save() { + if(isset($this->_data[$this->_primary])) { + $this->_database->updateRows($this->_table, + $this->_data, $this->_primary.'='.$this->_data[$this->_primary]); + } else { + $this->_database->insertRow($this->_table, $this->_data); + $this->_data[$this->_primary] = $this->_database->getLastInsertedId(); + } + + return $this; + } + + public function remove() { + $this->_database->deleteRows($this->_table, $this->_primary.'='.$this->_data[$this->_primary]); + $this->_data = array(); + return $this; + } + + /** + * Returns meta data + * + * @param string + * @param string + * @return array + */ + public function getMetaData($name = NULL, $key = NULL) { + //argument test + Eden_Mysql_Error::get() + ->argument(1, 'string', 'null') //argument 1 must be a string or null + ->argument(2, 'string', 'null'); //argument 2 must be a string or null + + if(!is_null($name) && isset($this->_meta[$name])) { + if(!is_null($key) && isset($this->_meta[$name][$key])) { + return $this->_meta[$name][$key]; + } + return $this->_meta[$name]; + } + + return $this->_meta; + } + + /** + * Sets data using the ArrayAccess interface + * We overloaded this to not allow creating new + * columns. + * + * @param number + * @param mixed + * @return void + */ + public function offsetSet($offset, $value) { + //if this is not set in the meta data + if(!isset($this->_meta[$offset])) { + //throw an error + Eden_Mysql_Error::get() + ->setMessage(Eden_Mysql_Error::SET_INVALID) + ->addVariable($offset) + ->addVariable($this->_table) + ->trigger(); + } + + $this->_data[$offset] = $value; + } + + /** + * unsets using the ArrayAccess interface + * We overloaded this because an attributes + * must never be removed. Instead we set it to + * null. + * + * @param number + * @return void + */ + public function offsetUnset($offset) { + //if it is set in the meta + if(isset($this->_meta[$offset])) { + //set it to null + $this->_data[$offset] = NULL; + } + } + + /** + * Rewinds the position + * For Iterator interface + * + * @return void + */ + public function rewind() { + reset($this->_data); + } + + /** + * Returns the current item + * For Iterator interface + * + * @return void + */ + public function current() { + return current($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); + } + + /** + * Validates whether if the index is set + * For Iterator interface + * + * @return void + */ + public function valid() { + return isset($this->_data[$this->key()]); + } + + /** + * 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; + } + + /* Protected Methods + -------------------------------*/ + protected function _setMetaData() { + $columns = $this->_database->getColumns($this->_table); + + foreach($columns as $column) { + $this->_meta[$column['Field']] = array( + 'type' => $column['Type'], + 'key' => $column['Key'], + 'default' => $column['Default'], + 'empty' => $column['Null'] == 'YES'); + + if($column['Key'] == 'PRI') { + $this->_primary = $column['Field']; + } + } + } + + /* Private Methods + -------------------------------*/ +} + From 56dbfc0944ab2d44636656ded5dc439d81ea49ef Mon Sep 17 00:00:00 2001 From: cblanquera Date: Thu, 22 Dec 2011 06:03:19 +0000 Subject: [PATCH 026/330] framework MVC changed rules git-svn-id: http://svn.openovate.com/edenv2/trunk@26 38ede93f-50f4-44af-b0b3-68ccca78c181 --- library/eden.php | 116 ++++++- library/eden/mysql.php | 29 +- library/eden/mysql/model.php | 442 ++++++++------------------ library/eden/mysql/model/abstract.php | 230 ++++++++++++++ site/front.php | 60 ++-- site/front/config/classes.php | 2 - site/front/config/methods.php | 2 - site/front/config/pages.php | 2 - site/web/index.php | 64 +--- 9 files changed, 512 insertions(+), 435 deletions(-) create mode 100644 library/eden/mysql/model/abstract.php delete mode 100755 site/front/config/classes.php delete mode 100755 site/front/config/methods.php delete mode 100755 site/front/config/pages.php diff --git a/library/eden.php b/library/eden.php index 563bdaa..7b755d5 100644 --- a/library/eden.php +++ b/library/eden.php @@ -36,6 +36,8 @@ class Eden extends Eden_Event { -------------------------------*/ /* Protected Properties -------------------------------*/ + protected $_root = NULL; + /* Private Properties -------------------------------*/ /* Get @@ -46,6 +48,10 @@ public static function get() { /* Magic -------------------------------*/ + public function __construct() { + $this->_root = dirname(__FILE__); + } + public function __call($name, $args) { //first try to call the parent call try { @@ -57,29 +63,93 @@ public function __call($name, $args) { } } - public function __construct() { - if(!class_exists('Eden_Loader')) { - //require autoload - require_once dirname(__FILE__).'/eden/loader.php'; + /* Public Methods + -------------------------------*/ + /** + * Sets the root path + * + * @param string + * @return this + */ + public function setRoot($root) { + Eden_Error::get()->argument(1, 'string'); - //set autoload class as the autoload handler - spl_autoload_register(array(Eden_Loader::get(), 'handler')); + if(!class_exists('Eden_Path')) { + Eden_Loader::get()->load('Eden_Path'); } + + $this->_root = (string) Eden_Path::get($root); + + return $this; + } + + /** + * Returns the root path + * + * @return string + */ + public function getRoot() { + return $this->_root; } - /* Public Methods - -------------------------------*/ /** - * Adds a root path to search in when a class does not exist. - * Being as specific as possible will reduce the time it takes - * to find the class. + * Sets up Autoloading * * @param string|array path - * @return Eden_Framework + * @return this */ - public function addRoot($path) { - Eden_Error::get()->argument(1, 'string'); - Eden_Loader::get()->addRoot($path); + 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::get(), 'handler')); + } + + //get paths + $paths = func_get_args(); + + //if no paths + if(empty($paths)) { + //do nothing more + return $this; + } + + //we need Eden_Path to fix the path formatting + if(!class_exists('Eden_Path')) { + Eden_Loader::get()->load('Eden_Path'); + } + + //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::get($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::get()->addRoot($path); + } + } + return $this; } @@ -112,6 +182,7 @@ public function setClasses($routes) { */ public function setMethods($routes) { Eden_Error::get()->argument(1, 'string', 'array'); + $route = Eden_Route::get(); if(is_string($routes)) { $routes = include($routes); @@ -134,7 +205,7 @@ public function setMethods($routes) { } //route the method - $this->routeMethod($method, $routePath[0], $routePath[1]); + $route->routeMethod($method, $routePath[0], $routePath[1]); } } @@ -153,6 +224,19 @@ public function startSession() { return $this; } + /** + * Sets the PHP timezone + * + * @return this + */ + public function setTimezone($zone) { + Eden_Error::get()->argument(1, 'string'); + + date_default_timezone_set($zone); + + return $this; + } + /* Protected Methods -------------------------------*/ /* Private Methods diff --git a/library/eden/mysql.php b/library/eden/mysql.php index 5b2bb1b..fecae05 100755 --- a/library/eden/mysql.php +++ b/library/eden/mysql.php @@ -102,6 +102,10 @@ public function connect(array $options = array()) { * @return PDO connection resource */ public function getConnection() { + if(!$this->_connection) { + $this->connect(); + } + return $this->_connection; } @@ -406,6 +410,8 @@ public function updateRows($table, array $setting, $filters = NULL) { } } + $query->where($filters); + //run the query $this->query($query, $this->getBinds()); @@ -428,7 +434,7 @@ public function setRow($table, $name, $value, array $setting) { Eden_Mysql_Error::get() ->argument(1, 'string') //Argument 1 must be a string ->argument(2, 'string') //Argument 2 must be a string - ->argument(3, 'string', 'number'); //Argument 3 must be a string or number + ->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); @@ -450,16 +456,12 @@ public function setRow($table, $name, $value, array $setting) { * @param array filter * @return var */ - public function deleteRows($table, $filter = NULL) { + public function deleteRows($table, $filters = NULL) { //Argument 1 must be a string Eden_Mysql_Error::get()->argument(1, 'string'); $query = $this->delete($table); - foreach($setting as $key => $value) { - $query->set($key, $this->bind($value)); - } - if(is_array($filters)) { foreach($filters as $i => $filter) { //array('post_id=%s AND post_title IN %s', 123, array('asd')); @@ -469,6 +471,8 @@ public function deleteRows($table, $filter = NULL) { } } + $query->where($filters); + //run the query $this->query($query, $this->getBinds()); @@ -498,7 +502,7 @@ public function getPrimaryKey($table) { * @param the name of the table * @return attay|false */ - public function getColumns($table, $filter = NULL) { + public function getColumns($table, $filters = NULL) { //Argument 1 must be a string Eden_Mysql_Error::get()->argument(1, 'string'); @@ -513,7 +517,7 @@ public function getColumns($table, $filter = NULL) { } } - $query->showColumns($table, $filter); + $query->showColumns($table, $filters); return $this->query($query, $this->getBinds()); } @@ -654,12 +658,12 @@ public function query($query, array $binds = array()) { if(!$stmt->execute()) { $error = $stmt->errorInfo(); - foreach($bound as $key => $value) { + foreach($binds as $key => $value) { $query = str_replace($key, "'$value'", $query); } Eden_Mysql_Error::get() - ->setMessage(Eden_Mysql_Exception::QUERY_ERROR) + ->setMessage(Eden_Mysql_Error::QUERY_ERROR) ->addVariable($query) ->addVariable($error[2]) ->trigger(); @@ -699,7 +703,7 @@ public function bind($value) { return $value; } - $name = ':bind'.count($this->_bind).'bind'; + $name = ':bind'.count($this->_binds).'bind'; $this->_binds[$name] = $value; return $name; } @@ -719,4 +723,5 @@ public function getBinds() { -------------------------------*/ /* Private Methods -------------------------------*/ -} \ No newline at end of file +} + diff --git a/library/eden/mysql/model.php b/library/eden/mysql/model.php index 3acfebc..7b2e4d0 100644 --- a/library/eden/mysql/model.php +++ b/library/eden/mysql/model.php @@ -1,313 +1,129 @@ - -/* - * 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. - */ - -/** - * - * @package Eden - * @category registry - * @author Christian Blanquera - * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ - */ -class Eden_Mysql_Model extends Eden_Class implements ArrayAccess, Iterator { - /* Constants - -------------------------------*/ - /* Public Properties - -------------------------------*/ - /* Protected Properties - -------------------------------*/ - protected $_primary = NULL; - protected $_meta = array(); - protected $_data = array(); - - protected $_database = NULL; - protected $_table = NULL; - - /* Private Properties - -------------------------------*/ - /* Get - -------------------------------*/ - public static function get(Eden_Mysql $database, $table) { - return self::_getMultiple(__CLASS__, $database, $table); - } - - /* Magic - -------------------------------*/ - public function __construct($database, $table) { - $this->_database = $database; - $this->_table = $table; - - //set meta data - $this->_setMetaData(); - } - - public function __call($name, $args) { - //if the method starts with get - if(strpos($name, 'get') === 0) { - $key = preg_replace("/([A-Z])/", "_$1", $name); - //get rid of get_ - $key = strtolower(substr($key, 4)); - - if(isset($this->_meta[$key])) { - return $this->_data[$key]; - } - } else if (strpos($name, 'set') === 0) { - $key = preg_replace("/([A-Z])/", "_$1", $name); - //get rid of get_ - $key = strtolower(substr($key, 4)); - - return $this->__set($key, $args[0]); - } - - try { - return parent::__call($name, $args); - } catch(Eden_Type_Error $e) { - throw new Eden_Mysql_Error($e->getMessage()); - } - } - - public function __get($name) { - if(isset($this->_data[$name])) { - return $this->_data[$name]; - } - - return NULL; - } - - public function __set($name, $value) { - if(isset($this->_meta[$name])) { - $this->_data[$name] = $value; - return $this; - } - - //throw an error - Eden_Mysql_Error::get() - ->setMessage(Eden_Mysql_Error::SET_INVALID) - ->addVariable($name) - ->addVariable($this->_table) - ->trigger(); - } - - public function __toString() { - return json_encode($this->_data); - } - - /* Public Methods - -------------------------------*/ - /** - * Loads data into the model - * - * @param array - * @return this - */ - public function load($data, $column = NULL) { - Eden_Mysql_Error::get() - ->argument(1, 'numeric', 'array', 'string') - ->argument(2, 'string', 'null'); - - if(is_scalar($data)) { - if(!is_string($column)) { - $column = $this->_primary; - } - - $this->_data = $this->_database->getRow($this->_table, $column, $data); - - return $this; - } - - //for each data - foreach($data as $name => $value) { - //if this is not set in the meta data - if(!isset($this->_meta[$name])) { - //throw an error - Eden_Mysql_Error::get() - ->setMessage(Eden_Mysql_Error::SET_INVALID) - ->addVariable($name) - ->addVariable($this->_table) - ->trigger(); - } - - $this->_data[$name] = $value; - } - - return $this; - } - - public function save() { - if(isset($this->_data[$this->_primary])) { - $this->_database->updateRows($this->_table, - $this->_data, $this->_primary.'='.$this->_data[$this->_primary]); - } else { - $this->_database->insertRow($this->_table, $this->_data); - $this->_data[$this->_primary] = $this->_database->getLastInsertedId(); - } - - return $this; - } - - public function remove() { - $this->_database->deleteRows($this->_table, $this->_primary.'='.$this->_data[$this->_primary]); - $this->_data = array(); - return $this; - } - - /** - * Returns meta data - * - * @param string - * @param string - * @return array - */ - public function getMetaData($name = NULL, $key = NULL) { - //argument test - Eden_Mysql_Error::get() - ->argument(1, 'string', 'null') //argument 1 must be a string or null - ->argument(2, 'string', 'null'); //argument 2 must be a string or null - - if(!is_null($name) && isset($this->_meta[$name])) { - if(!is_null($key) && isset($this->_meta[$name][$key])) { - return $this->_meta[$name][$key]; - } - return $this->_meta[$name]; - } - - return $this->_meta; - } - - /** - * Sets data using the ArrayAccess interface - * We overloaded this to not allow creating new - * columns. - * - * @param number - * @param mixed - * @return void - */ - public function offsetSet($offset, $value) { - //if this is not set in the meta data - if(!isset($this->_meta[$offset])) { - //throw an error - Eden_Mysql_Error::get() - ->setMessage(Eden_Mysql_Error::SET_INVALID) - ->addVariable($offset) - ->addVariable($this->_table) - ->trigger(); - } - - $this->_data[$offset] = $value; - } - - /** - * unsets using the ArrayAccess interface - * We overloaded this because an attributes - * must never be removed. Instead we set it to - * null. - * - * @param number - * @return void - */ - public function offsetUnset($offset) { - //if it is set in the meta - if(isset($this->_meta[$offset])) { - //set it to null - $this->_data[$offset] = NULL; - } - } - - /** - * Rewinds the position - * For Iterator interface - * - * @return void - */ - public function rewind() { - reset($this->_data); - } - - /** - * Returns the current item - * For Iterator interface - * - * @return void - */ - public function current() { - return current($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); - } - - /** - * Validates whether if the index is set - * For Iterator interface - * - * @return void - */ - public function valid() { - return isset($this->_data[$this->key()]); - } - - /** - * 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; - } - - /* Protected Methods - -------------------------------*/ - protected function _setMetaData() { - $columns = $this->_database->getColumns($this->_table); - - foreach($columns as $column) { - $this->_meta[$column['Field']] = array( - 'type' => $column['Type'], - 'key' => $column['Key'], - 'default' => $column['Default'], - 'empty' => $column['Null'] == 'YES'); - - if($column['Key'] == 'PRI') { - $this->_primary = $column['Field']; - } - } - } - - /* Private Methods - -------------------------------*/ -} - + +/* + * 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. + */ + +/** + * + * @package Eden + * @category registry + * @author Christian Blanquera + * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ + */ +class Eden_Mysql_Model extends Eden_Mysql_Model_Abstract { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_primary = NULL; + protected $_meta = array(); + protected $_data = array(); + + protected $_database = NULL; + protected $_table = NULL; + + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function get(Eden_Mysql $database, $table) { + return self::_getMultiple(__CLASS__, $database, $table); + } + + /* Magic + -------------------------------*/ + public function __construct($database, $table) { + $this->_database = $database; + $this->_table = $table; + + //set meta data + $this->_setMetaData(); + } + + /* Public Methods + -------------------------------*/ + /** + * Loads data into the model + * + * @param array + * @return this + */ + public function load($data, $column = NULL) { + Eden_Mysql_Error::get() + ->argument(1, 'numeric', 'array', 'string') + ->argument(2, 'string', 'null'); + + if(is_scalar($data)) { + if(!is_string($column)) { + $column = $this->_primary; + } + + $this->_data = $this->_database->getRow($this->_table, $column, $data); + + return $this; + } + + //for each data + foreach($data as $name => $value) { + //if this is not set in the meta data + if(!isset($this->_meta[$name])) { + //throw an error + Eden_Mysql_Error::get() + ->setMessage(Eden_Mysql_Error::SET_INVALID) + ->addVariable($name) + ->addVariable($this->_table) + ->trigger(); + } + + $this->_data[$name] = $value; + } + + return $this; + } + + public function save() { + if(isset($this->_data[$this->_primary])) { + $this->_database->updateRows($this->_table, + $this->_data, $this->_primary.'='.$this->_data[$this->_primary]); + } else { + $this->_database->insertRow($this->_table, $this->_data); + $this->_data[$this->_primary] = $this->_database->getLastInsertedId(); + } + + return $this; + } + + public function remove() { + $this->_database->deleteRows($this->_table, $this->_primary.'='.$this->_data[$this->_primary]); + $this->_data = array(); + return $this; + } + + /* Protected Methods + -------------------------------*/ + protected function _setMetaData() { + $columns = $this->_database->getColumns($this->_table); + + foreach($columns as $column) { + $this->_meta[$column['Field']] = array( + 'type' => $column['Type'], + 'key' => $column['Key'], + 'default' => $column['Default'], + 'empty' => $column['Null'] == 'YES'); + + if($column['Key'] == 'PRI') { + $this->_primary = $column['Field']; + } + } + } + + /* Private Methods + -------------------------------*/ +} + diff --git a/library/eden/mysql/model/abstract.php b/library/eden/mysql/model/abstract.php new file mode 100644 index 0000000..4feea72 --- /dev/null +++ b/library/eden/mysql/model/abstract.php @@ -0,0 +1,230 @@ + +/* + * 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. + */ + +/** + * + * @package Eden + * @category registry + * @author Christian Blanquera + * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ + */ +abstract class Eden_Mysql_Model_Abstract extends Eden_Class implements ArrayAccess, Iterator { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_primary = NULL; + protected $_meta = array(); + protected $_data = array(); + + protected $_database = NULL; + protected $_table = NULL; + + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + /* Magic + -------------------------------*/ + public function __call($name, $args) { + //if the method starts with get + if(strpos($name, 'get') === 0) { + $key = preg_replace("/([A-Z])/", "_$1", $name); + //get rid of get_ + $key = strtolower(substr($key, 4)); + + if(isset($this->_meta[$key])) { + return $this->_data[$key]; + } + } else if (strpos($name, 'set') === 0) { + $key = preg_replace("/([A-Z])/", "_$1", $name); + //get rid of get_ + $key = strtolower(substr($key, 4)); + + return $this->__set($key, $args[0]); + } + + try { + return parent::__call($name, $args); + } catch(Eden_Type_Error $e) { + throw new Eden_Mysql_Error($e->getMessage()); + } + } + + public function __get($name) { + if(isset($this->_data[$name])) { + return $this->_data[$name]; + } + + return NULL; + } + + public function __set($name, $value) { + if(isset($this->_meta[$name])) { + $this->_data[$name] = $value; + return $this; + } + + //throw an error + Eden_Mysql_Error::get() + ->setMessage(Eden_Mysql_Error::SET_INVALID) + ->addVariable($name) + ->addVariable($this->_table) + ->trigger(); + } + + public function __toString() { + return json_encode($this->_data); + } + + /* Public Methods + -------------------------------*/ + abstract public function save(); + + /** + * Returns meta data + * + * @param string + * @param string + * @return array + */ + public function getMetaData($name = NULL, $key = NULL) { + //argument test + Eden_Mysql_Error::get() + ->argument(1, 'string', 'null') //argument 1 must be a string or null + ->argument(2, 'string', 'null'); //argument 2 must be a string or null + + if(!is_null($name) && isset($this->_meta[$name])) { + if(!is_null($key) && isset($this->_meta[$name][$key])) { + return $this->_meta[$name][$key]; + } + return $this->_meta[$name]; + } + + return $this->_meta; + } + + /** + * Sets data using the ArrayAccess interface + * We overloaded this to not allow creating new + * columns. + * + * @param number + * @param mixed + * @return void + */ + public function offsetSet($offset, $value) { + //if this is not set in the meta data + if(!isset($this->_meta[$offset])) { + //throw an error + Eden_Mysql_Error::get() + ->setMessage(Eden_Mysql_Error::SET_INVALID) + ->addVariable($offset) + ->addVariable($this->_table) + ->trigger(); + } + + $this->_data[$offset] = $value; + } + + /** + * unsets using the ArrayAccess interface + * We overloaded this because an attributes + * must never be removed. Instead we set it to + * null. + * + * @param number + * @return void + */ + public function offsetUnset($offset) { + //if it is set in the meta + if(isset($this->_meta[$offset])) { + //set it to null + $this->_data[$offset] = NULL; + } + } + + /** + * Rewinds the position + * For Iterator interface + * + * @return void + */ + public function rewind() { + reset($this->_data); + } + + /** + * Returns the current item + * For Iterator interface + * + * @return void + */ + public function current() { + return current($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); + } + + /** + * Validates whether if the index is set + * For Iterator interface + * + * @return void + */ + public function valid() { + return isset($this->_data[$this->key()]); + } + + /** + * 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; + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} + diff --git a/site/front.php b/site/front.php index 3a2d959..f6e86ac 100644 --- a/site/front.php +++ b/site/front.php @@ -53,7 +53,9 @@ public static function get() { /* Magic -------------------------------*/ public function __construct() { - parent::__construct(); + $this->_root = dirname(__FILE__); + + $this->setLoader(); //require registry $this->_registry = Eden_Loader::get() @@ -85,14 +87,14 @@ public function setDebug($reporting = NULL, $default = NULL) { ->when($default === true) ->setErrorHandler() ->setExceptionHandler() - ->listen('error', $this, 'outputError') - ->listen('exception', $this, 'outputError') + ->listen('error', $this, 'error') + ->listen('exception', $this, 'error') ->endWhen() ->when($default === false) ->releaseErrorHandler() ->releaseExceptionHandler() - ->unlisten('error', $this, 'outputError') - ->unlisten('exception', $this, 'outputError') + ->unlisten('error', $this, 'error') + ->unlisten('exception', $this, 'error') ->endWhen(); return $this; @@ -105,17 +107,14 @@ public function setDebug($reporting = NULL, $default = NULL) { * @return this */ public function setPaths(array $paths = array()) { - //this is the default paths - $root = dirname(__FILE__); - $default = array( - 'root' => $root, - 'model' => $root.'/model', - 'web' => $root.'/web', - 'assets' => $root.'/web/assets', - 'cache' => $root.'/front/cache', - 'config' => $root.'/front/config', - 'template' => $root.'/front/template'); + 'root' => $this->_root, + 'model' => $this->_root.'/model', + 'web' => $this->_root.'/web', + 'assets' => $this->_root.'/web/assets', + 'cache' => $this->_root.'/front/cache', + 'config' => $this->_root.'/front/config', + 'template' => $this->_root.'/front/template'); //foreach default path foreach($default as $key => $path) { @@ -347,7 +346,7 @@ public function addDatabase($key, $type = NULL, break; } - $this->setData('database', $key, $database); + $this->_registry->setData('database', $key, $database); if($default) { $this->_database = $database; @@ -400,7 +399,7 @@ public function setDefaultDatabase($key) { * @param string|array handlers * @return Eden_Application */ - public function startFilters($filters) { + public function setFilters($filters) { Front_Error::get()->argument(1, 'string', 'array'); if(is_string($filters)) { @@ -428,25 +427,16 @@ public function startFilters($filters) { * @return this */ public function setCache($root) { - // Start the Global Cache - Eden_Cache::get($root); - - return $this; - } - - /** - * Sets the PHP timezone - * - * @return this - */ - public function setTimezone($zone) { - //if zone is not string - if(!is_string($zone)) { - //throw exception - throw new Eden_Site_Exception(sprintf(Eden_Exception::NOT_STRING, 1)); + //we need Eden_Path to fix the path formatting + if(!class_exists('Eden_Path')) { + Eden_Loader::get()->load('Eden_Path'); } - date_default_timezone_set($zone); + //format the path + $root = (string) Eden_Path::get($root); + + // Start the Global Cache + Eden_Cache::get($root); return $this; } @@ -476,7 +466,7 @@ public function template($file, array $data = array()) { * * @return void */ - public function outputError($event, $trace, $offset, $type, $level, $class, $file, $line, $message) { + public function error($event, $trace, $offset, $type, $level, $class, $file, $line, $message) { //if there is a trace template and there's at least 2 leads if(count($trace) > $offset) { //for each trace diff --git a/site/front/config/classes.php b/site/front/config/classes.php deleted file mode 100755 index 0f17a54..0000000 --- a/site/front/config/classes.php +++ /dev/null @@ -1,2 +0,0 @@ - -return array(); \ No newline at end of file diff --git a/site/front/config/methods.php b/site/front/config/methods.php deleted file mode 100755 index 945b1fd..0000000 --- a/site/front/config/methods.php +++ /dev/null @@ -1,2 +0,0 @@ - -return array('output' => 'Eden_Tool'); \ No newline at end of file diff --git a/site/front/config/pages.php b/site/front/config/pages.php deleted file mode 100755 index 0f17a54..0000000 --- a/site/front/config/pages.php +++ /dev/null @@ -1,2 +0,0 @@ - -return array(); \ No newline at end of file diff --git a/site/web/index.php b/site/web/index.php index 530b593..91c3498 100644 --- a/site/web/index.php +++ b/site/web/index.php @@ -11,80 +11,38 @@ /* Get Application -------------------------------*/ print front() - /* Set Debug -------------------------------*/ ->setDebug(E_ALL, true) /* Set Autoload -------------------------------*/ -->addRoot(dirname(__FILE__).'/..') -->addRoot(dirname(__FILE__).'/../model') - -/* Set Class Routing --------------------------------*/ -->setClasses('../front/config/classes.php') - -/* Set Method Routing --------------------------------*/ -->setMethods('../front/config/methods.php') +->setLoader(NULL, '/model') /* Set Paths -------------------------------*/ ->setPaths() -/* Start Filters --------------------------------*/ -->startFilters(array('Front_Handler')) - -/* Trigger Init Event --------------------------------*/ -->trigger('init') - -/* Set Timezone --------------------------------*/ -->setTimezone('America/Los_Angeles') - /* Set Database -------------------------------*/ -//->addDatabase(include('front/config/database.php')) - -/* Set Cache --------------------------------*/ -//->setCache('front/cache') - -/* Set Page Routes --------------------------------*/ -->setPages('pages.php') - -/* Trigger Init Event --------------------------------*/ -->trigger('config') - -/* Start Session --------------------------------*/ -->startSession() - -/* Trigger Session Event --------------------------------*/ -->trigger('session') +->addDatabase(array( + 'key' => 'test', + 'type' => 'mysql', + 'default' => true, + 'host' => '127.0.0.1', + 'name' => 'expresso_prod', + 'user' => 'root', + 'pass' => '')) /* Set Request -------------------------------*/ ->setRequest() -/* Trigger Request Event --------------------------------*/ -->trigger('request') - /* Set Response -------------------------------*/ ->setResponse('Front_Page_Index') -/* Trigger Response Event --------------------------------*/ -->trigger('response') - /* Get the Response -------------------------------*/ -->getResponse(); \ No newline at end of file +->getResponse(); +echo Eden_MySql_Model::get(front()->getDatabase(), 'store')->load(1)->getStoreName(); \ No newline at end of file From 992937bca48104e61317559945071a4092291d68 Mon Sep 17 00:00:00 2001 From: cblanquera Date: Thu, 22 Dec 2011 13:22:36 +0000 Subject: [PATCH 027/330] mysql finalizing git-svn-id: http://svn.openovate.com/edenv2/trunk@27 38ede93f-50f4-44af-b0b3-68ccca78c181 --- library/eden/class.php | 1 + library/eden/mysql/error.php | 2 ++ library/eden/mysql/model.php | 27 +++++---------------------- library/eden/mysql/model/abstract.php | 22 ++++++++++++++++++++++ 4 files changed, 30 insertions(+), 22 deletions(-) diff --git a/library/eden/class.php b/library/eden/class.php index 6a1e187..7ecc546 100755 --- a/library/eden/class.php +++ b/library/eden/class.php @@ -51,6 +51,7 @@ public function __call($name, $args) { //lets first consider that they may just //want to load a class so lets try try { + //return the class return Eden_Route::get()->getClassArray($name, $args); //only if there's a route exception do we want to catch it diff --git a/library/eden/mysql/error.php b/library/eden/mysql/error.php index 4535e72..e9e9ee5 100755 --- a/library/eden/mysql/error.php +++ b/library/eden/mysql/error.php @@ -18,6 +18,8 @@ class Eden_Mysql_Error extends Eden_Error { /* Constants -------------------------------*/ + const QUERY_ERROR = '%s Query: %s'; + /* Public Properties -------------------------------*/ /* Protected Properties diff --git a/library/eden/mysql/model.php b/library/eden/mysql/model.php index 7b2e4d0..f6c6051 100644 --- a/library/eden/mysql/model.php +++ b/library/eden/mysql/model.php @@ -87,6 +87,11 @@ public function load($data, $column = NULL) { return $this; } + /** + * Inserts or updates model to database + * + * @return this + */ public function save() { if(isset($this->_data[$this->_primary])) { $this->_database->updateRows($this->_table, @@ -99,30 +104,8 @@ public function save() { return $this; } - public function remove() { - $this->_database->deleteRows($this->_table, $this->_primary.'='.$this->_data[$this->_primary]); - $this->_data = array(); - return $this; - } - /* Protected Methods -------------------------------*/ - protected function _setMetaData() { - $columns = $this->_database->getColumns($this->_table); - - foreach($columns as $column) { - $this->_meta[$column['Field']] = array( - 'type' => $column['Type'], - 'key' => $column['Key'], - 'default' => $column['Default'], - 'empty' => $column['Null'] == 'YES'); - - if($column['Key'] == 'PRI') { - $this->_primary = $column['Field']; - } - } - } - /* Private Methods -------------------------------*/ } diff --git a/library/eden/mysql/model/abstract.php b/library/eden/mysql/model/abstract.php index 4feea72..c6d3c7f 100644 --- a/library/eden/mysql/model/abstract.php +++ b/library/eden/mysql/model/abstract.php @@ -24,6 +24,7 @@ abstract class Eden_Mysql_Model_Abstract extends Eden_Class implements ArrayAcce protected $_primary = NULL; protected $_meta = array(); protected $_data = array(); + protected $_join = array(); protected $_database = NULL; protected $_table = NULL; @@ -41,6 +42,7 @@ public function __call($name, $args) { //get rid of get_ $key = strtolower(substr($key, 4)); + //if it's a data key if(isset($this->_meta[$key])) { return $this->_data[$key]; } @@ -89,6 +91,10 @@ public function __toString() { -------------------------------*/ abstract public function save(); + public function getTable() { + return $this->_table; + } + /** * Returns meta data * @@ -224,6 +230,22 @@ public function offsetGet($offset) { /* Protected Methods -------------------------------*/ + protected function _setMetaData() { + $columns = $this->_database->getColumns($this->_table); + + foreach($columns as $column) { + $this->_meta[$column['Field']] = array( + 'type' => $column['Type'], + 'key' => $column['Key'], + 'default' => $column['Default'], + 'empty' => $column['Null'] == 'YES'); + + if($column['Key'] == 'PRI') { + $this->_primary = $column['Field']; + } + } + } + /* Private Methods -------------------------------*/ } From 1b44100c0675b2be10022313faaa1fa1d5e325d9 Mon Sep 17 00:00:00 2001 From: cblanquera Date: Tue, 27 Dec 2011 02:21:35 +0000 Subject: [PATCH 028/330] mysql changes based on expresso experiences git-svn-id: http://svn.openovate.com/edenv2/trunk@28 38ede93f-50f4-44af-b0b3-68ccca78c181 --- library/eden/file.php | 8 +++---- library/eden/image.php | 22 ++++++++++++++--- library/eden/mysql.php | 34 ++++++++++++++++++--------- library/eden/mysql/error.php | 1 + library/eden/mysql/model/abstract.php | 25 ++++++++++++++++++-- library/eden/sql/insert.php | 2 +- library/eden/sql/select.php | 4 ++-- library/eden/sql/update.php | 2 +- 8 files changed, 74 insertions(+), 24 deletions(-) diff --git a/library/eden/file.php b/library/eden/file.php index c6abd63..1002aa5 100644 --- a/library/eden/file.php +++ b/library/eden/file.php @@ -91,7 +91,7 @@ public function getExtension() { public function getData() { $this->absolute(); - return include($path); + return include($this->_path); } /** @@ -104,15 +104,15 @@ public function getContent() { $this->absolute(); //if the pat is not a real file - if(!is_file($path)) { + if(!is_file($this->_path)) { //throw an exception Eden_File_Error::get() ->setMessage(Eden_File_Error::PATH_IS_NOT_FILE) - ->addVariable($path) + ->addVariable($this->_path) ->trigger(); } - return file_get_contents($path); + return file_get_contents($this->_path); } /** diff --git a/library/eden/image.php b/library/eden/image.php index 90998b1..97d35d8 100644 --- a/library/eden/image.php +++ b/library/eden/image.php @@ -24,7 +24,7 @@ * @author Christian Blanquera * @version $Id: abstract.php 1 2010-01-02 23:06:36Z blanquera $ */ -abstract class Eden_Image_Abstract extends Eden_Class { +class Eden_Image extends Eden_Class { /* Constants -------------------------------*/ /* Public Properties @@ -482,7 +482,7 @@ public function colorize($red, $blue, $green, $alpha = 0) { ->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 + ->argument(4, 'numeric'); //Argument 4 must be a number //apply filter imagefilter($this->_resource, IMG_FILTER_COLORIZE, $red, $blue, $green, $alpha); @@ -566,6 +566,13 @@ public function smooth($level) { return $this; } + public function setTransparency() { + imagealphablending( $this->_resource, false ); + imagesavealpha( $this->_resource, true ); + + return $this; + } + /** * Returns the size of the image * @@ -575,6 +582,15 @@ 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; + } + /** * Saves the image data to a file * @@ -680,7 +696,7 @@ protected function _getResource($data, $path) { //throw error Eden_Image_Error::get() ->setMessage(Eden_Image_Error::NOT_VALID_IMAGE_FILE) - ->addVariable($this->_path); + ->addVariable($path); } return $resource; diff --git a/library/eden/mysql.php b/library/eden/mysql.php index fecae05..77191d5 100755 --- a/library/eden/mysql.php +++ b/library/eden/mysql.php @@ -262,7 +262,7 @@ public function getRows($table, array $joins = array(), $filters = NULL, $results = $this->query($query, $this->getBinds()); - if($index == 'first' && count($result) > 0) { + if($index == 'first' && count($results) > 0) { return $results[0]; } @@ -338,14 +338,18 @@ public function getRowsCount($table, array $joins = array(), $filters = NULL) { * @param array setting * @return int */ - public function insertRow($table, array $setting) { + public function insertRow($table, array $setting, $bind = true) { //Argument 1 must be a string - Eden_Mysql_Error::get()->argument(1, 'string'); + Eden_Mysql_Error::get()->argument(1, 'string')->argument(3, 'array', 'bool'); $query = $this->insert($table); foreach($setting as $key => $value) { - $query->set($key, $this->bind($value)); + if((is_bool($bind) && $bind) || (is_array($bind) && in_array($key, $bind))) { + $value = $this->bind($value); + } + + $query->set($key, $value); } //run the query @@ -363,15 +367,19 @@ public function insertRow($table, array $setting) { * @param array settings * @return void */ - public function insertRows($table, array $settings) { + public function insertRows($table, array $settings, $bind = true) { //Argument 1 must be a string - Eden_Mysql_Error::get()->argument(1, 'string'); + Eden_Mysql_Error::get()->argument(1, 'string')->argument(3, 'array', 'bool'); $query = $this->insert($table); foreach($settings as $index => $setting) { foreach($setting as $key => $value) { - $query->set($key, $this->bind($value), $index); + if((is_bool($bind) && $bind) || (is_array($bind) && in_array($key, $bind))) { + $value = $this->bind($value); + } + + $query->set($key, $value, $index); } } @@ -391,14 +399,18 @@ public function insertRows($table, array $settings) { * @param array filter * @return var */ - public function updateRows($table, array $setting, $filters = NULL) { + public function updateRows($table, array $setting, $filters = NULL, $bind = true) { //Argument 1 must be a string - Eden_Mysql_Error::get()->argument(1, 'string'); + Eden_Mysql_Error::get()->argument(1, 'string')->argument(4, 'array', 'bool'); $query = $this->update($table); foreach($setting as $key => $value) { - $query->set($key, $this->bind($value)); + if((is_bool($bind) && $bind) || (is_array($bind) && in_array($key, $bind))) { + $value = $this->bind($value); + } + + $query->set($key, $value); } if(is_array($filters)) { @@ -691,7 +703,7 @@ public function query($query, array $binds = array()) { */ public function bind($value) { //Argument 1 must be an array, string or number - Eden_Mysql_Error::get()->argument(1, 'array', 'string', 'numeric'); + Eden_Mysql_Error::get()->argument(1, 'array', 'string', 'numeric', 'null'); if(is_array($value)) { foreach($value as $i => $item) { diff --git a/library/eden/mysql/error.php b/library/eden/mysql/error.php index e9e9ee5..0377ab8 100755 --- a/library/eden/mysql/error.php +++ b/library/eden/mysql/error.php @@ -19,6 +19,7 @@ class Eden_Mysql_Error extends Eden_Error { /* Constants -------------------------------*/ const QUERY_ERROR = '%s Query: %s'; + const SET_INVALID = 'No column %s exists in table %s.'; /* Public Properties -------------------------------*/ diff --git a/library/eden/mysql/model/abstract.php b/library/eden/mysql/model/abstract.php index c6d3c7f..0caf3ff 100644 --- a/library/eden/mysql/model/abstract.php +++ b/library/eden/mysql/model/abstract.php @@ -91,6 +91,27 @@ public function __toString() { -------------------------------*/ abstract public function save(); + /** + * Returns an array version of the model + * + * @return array + */ + public function getData() { + $data = $this->_data; + foreach($this->_meta as $name => $data) { + if(!isset($data[$name])) { + $data[$name] = NULL; + } + } + + return $data; + } + + /** + * Returns the table name + * + * @return string + */ public function getTable() { return $this->_table; } @@ -138,7 +159,7 @@ public function offsetSet($offset, $value) { ->trigger(); } - $this->_data[$offset] = $value; + $this->__set($offset, $value); } /** @@ -154,7 +175,7 @@ public function offsetUnset($offset) { //if it is set in the meta if(isset($this->_meta[$offset])) { //set it to null - $this->_data[$offset] = NULL; + $this->__set($offset, NULL); } } diff --git a/library/eden/sql/insert.php b/library/eden/sql/insert.php index 4f264fe..d18e9e3 100755 --- a/library/eden/sql/insert.php +++ b/library/eden/sql/insert.php @@ -70,7 +70,7 @@ public function set($key, $value, $index = 0) { //argument test Eden_Sql_Error::get() ->argument(1, 'string') //Argument 1 must be a string - ->argument(2, 'string', 'number'); //Argument 2 must be a string or number + ->argument(2, 'string', 'numeric'); //Argument 2 must be a string or number if(!in_array($key, $this->_setKey)) { $this->_setKey[] = $key; diff --git a/library/eden/sql/select.php b/library/eden/sql/select.php index deb8819..84a872b 100755 --- a/library/eden/sql/select.php +++ b/library/eden/sql/select.php @@ -236,7 +236,7 @@ public function groupBy($group) { Eden_Sql_Error::get()->argument(1, 'string', 'array'); if(is_string($group)) { - $this->_group = array($group); + $group = array($group); } $this->_group = $group; @@ -280,7 +280,7 @@ public function getQuery() { $query = sprintf( 'SELECT %s FROM %s %s %s %s %s %s;', $this->_select, $this->_from, $joins, - $where, $sort, $limit, $group); + $where, $sort, $group, $limit); return str_replace(' ', ' ', $query); } diff --git a/library/eden/sql/update.php b/library/eden/sql/update.php index ece069d..b629949 100755 --- a/library/eden/sql/update.php +++ b/library/eden/sql/update.php @@ -48,7 +48,7 @@ public function set($key, $value) { //argument test Eden_Sql_Error::get() ->argument(1, 'string') //Argument 1 must be a string - ->argument(2, 'string', 'number'); //Argument 2 must be a string or number + ->argument(2, 'string', 'numeric'); //Argument 2 must be a string or number $this->_set[$key] = $value; From 84520febd1a2e556c7d6a9f6f8890b4f5c0ac9bc Mon Sep 17 00:00:00 2001 From: cblanquera Date: Tue, 27 Dec 2011 07:39:10 +0000 Subject: [PATCH 029/330] still was using joined which is depricated git-svn-id: http://svn.openovate.com/edenv2/trunk@29 38ede93f-50f4-44af-b0b3-68ccca78c181 --- library/eden/sql/select.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/library/eden/sql/select.php b/library/eden/sql/select.php index 84a872b..6fb7c6f 100755 --- a/library/eden/sql/select.php +++ b/library/eden/sql/select.php @@ -125,7 +125,7 @@ public function innerJoin($table, $where, $using = true) { ->argument(2, 'string') //Argument 2 must be a string ->argument(3, 'bool'); //Argument 3 must be a boolean - return $this->joined('INNER', $table, $where, $using); + return $this->join('INNER', $table, $where, $using); } /** @@ -144,7 +144,7 @@ public function outerJoin($table, $where, $using = true) { ->argument(2, 'string') //Argument 2 must be a string ->argument(3, 'bool'); //Argument 3 must be a boolean - return $this->joined('OUTER', $table, $where, $using); + return $this->join('OUTER', $table, $where, $using); } /** @@ -163,7 +163,7 @@ public function leftJoin($table, $where, $using = true) { ->argument(2, 'string') //Argument 2 must be a string ->argument(3, 'bool'); //Argument 3 must be a boolean - return $this->joined('LEFT', $table, $where, $using); + return $this->join('LEFT', $table, $where, $using); } /** @@ -182,7 +182,7 @@ public function rightJoin($table, $where, $using = true) { ->argument(2, 'string') //Argument 2 must be a string ->argument(3, 'bool'); //Argument 3 must be a boolean - return $this->joined('RIGHT', $table, $where, $using); + return $this->join('RIGHT', $table, $where, $using); } /** From 6263abd6de4119d87d76df1b3e8fbe46689440c2 Mon Sep 17 00:00:00 2001 From: cblanquera Date: Sat, 31 Dec 2011 19:05:54 +0000 Subject: [PATCH 030/330] fixes, added blocks git-svn-id: http://svn.openovate.com/edenv2/trunk@30 38ede93f-50f4-44af-b0b3-68ccca78c181 --- library/eden/block.php | 72 +++++++ library/eden/block/pagination.php | 207 +++++++++++++++++++++ library/eden/block/search.php | 139 ++++++++++++++ library/eden/block/template/pagination.php | 16 ++ library/eden/block/template/search.php | 9 + library/eden/mysql/model/abstract.php | 12 ++ library/eden/session.php | 8 +- library/eden/sql/select.php | 2 +- 8 files changed, 459 insertions(+), 6 deletions(-) create mode 100644 library/eden/block.php create mode 100644 library/eden/block/pagination.php create mode 100644 library/eden/block/search.php create mode 100644 library/eden/block/template/pagination.php create mode 100644 library/eden/block/template/search.php diff --git a/library/eden/block.php b/library/eden/block.php new file mode 100644 index 0000000..6ed4634 --- /dev/null +++ b/library/eden/block.php @@ -0,0 +1,72 @@ + +/* + * 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. + */ + +/** + * Base class for any class that defines an output block. + * A block is a default and customizable piece of output. + * + * @package Eden + * @category site + * @author Christian Blanquera + * @version $Id: abstract.php 5 2010-01-08 22:21:29Z blanquera $ + */ +abstract class Eden_Block extends Eden_Class { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + /* Magic + -------------------------------*/ + public function __toString() { + try { + return (string) $this->render(); + } catch(Exception $e) { + Eden_Error_Event::get()->exceptionHandler($e); + } + + return ''; + } + + /* Public Methods + -------------------------------*/ + /** + * returns variables used for templating + * + * @return array + */ + abstract public function getVariables(); + + /** + * returns location of template file + * + * @return string + */ + abstract public function getTemplate(); + + /** + * Transform block to string + * + * @param array + * @return string + */ + public function render() { + return Eden_Template::get()->setData($this->getVariables())->parsePhp($this->getTemplate()); + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/block/pagination.php b/library/eden/block/pagination.php new file mode 100644 index 0000000..caaa045 --- /dev/null +++ b/library/eden/block/pagination.php @@ -0,0 +1,207 @@ + +/* + * 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. + */ + +/** + * Pagination block + * + * @package Eden + * @category site + * @author Christian Blanquera + * @version $Id: form.php 1 2010-01-02 23:06:36Z blanquera $ + */ +class Eden_Block_Pagination extends Eden_Block { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_start = 0; + protected $_range = 25; + protected $_total = 0; + protected $_show = 5; + protected $_query = array(); + protected $_url = NULL; + protected $_class = NULL; + protected $_title = NULL; + + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function get($total) { + return self::_getMultiple(__CLASS__, $total); + } + + /* Magic + -------------------------------*/ + public function __construct($total) { + $this->_total = $total; + } + + /* Public Methods + -------------------------------*/ + /** + * Sets start + * + * @param int + * @return this + */ + public function setStart($start) { + Front_Error::get()->argument(1, 'int'); + if($start < 0) { + $start = 0; + } + + $this->_start = $start; + + return $this; + } + + /** + * Sets range + * + * @param int + * @return this + */ + public function setRange($range) { + Front_Error::get()->argument(1, 'int'); + if($range < 0) { + $range = 1; + } + + $this->_range = $range; + + return $this; + } + + /** + * Sets page + * + * @param int + * @return this + */ + public function setPage($page) { + Front_Error::get()->argument(1, 'int'); + if($page < 1) { + $page = 1; + } + + $this->_start = ( $page - 1 ) * $this->_range; + + return $this; + } + + /** + * Sets pages to show left and right of the current page + * + * @param int + * @return this + */ + public function setShow($show) { + Front_Error::get()->argument(1, 'int'); + if($show < 1) { + $show = 1; + } + + $this->_show = $show; + + return $this; + } + + /** + * This Block has pagination we need to pass in the GET query + * + * @param array + * @return this + */ + public function setQuery(array $query) { + $this->_query = $query; + return $this; + } + + /** + * This Block has pagination we need to pass in the url + * + * @param array + * @return this + */ + public function setUrl($url) { + $this->_url = $url; + return $this; + } + + /** + * Sets class for each page link + * + * @param array + * @return this + */ + public function setClass($class) { + $this->_class = $class; + return $this; + } + + + /** + * Sets a label + * + * @param array + * @return this + */ + public function setLabel($label) { + $this->_label = $label; + return $this; + } + + /** + * Returns the template variables in key value format + * + * @param array data + * @return array + */ + public function getVariables() { + $pages = ceil($this->_total / $this->_range); + $page = floor($this->_start / $this->_range) + 1; + $min = $page - $this->_show; + $max = $page + $this->_show; + + if($min < 1) { + $min = 1; + } + + if($max > $pages) { + $max = $pages; + } + + return array( + 'class' => $this->_class, + 'label' => $this->_title, + 'url' => $this->_url, + 'query' => $this->_query, + 'start' => $this->_start, + 'range' => $this->_range, + 'total' => $this->_total, + 'show' => $this->_show, + 'min' => $min, + 'max' => $max, + 'pages' => $pages, + 'page' => $page); + } + + /** + * Returns a template file + * + * @param array data + * @return string + */ + public function getTemplate() { + return realpath(dirname(__FILE__).'/template/pagination.php'); + } +} \ No newline at end of file diff --git a/library/eden/block/search.php b/library/eden/block/search.php new file mode 100644 index 0000000..ec54733 --- /dev/null +++ b/library/eden/block/search.php @@ -0,0 +1,139 @@ + +/* + * 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. + */ + +/** + * Pagination block + * + * @package Eden + * @category site + * @author Christian Blanquera + * @version $Id: form.php 1 2010-01-02 23:06:36Z blanquera $ + */ +class Eden_Block_Search extends Eden_Block { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_name = NULL; + protected $_keyword = NULL; + protected $_query = array(); + protected $_url = NULL; + protected $_class = NULL; + protected $_title = NULL; + + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function get() { + return self::_getMultiple(__CLASS__); + } + + /* Magic + -------------------------------*/ + /* Public Methods + -------------------------------*/ + + /** + * Sets keyword + * + * @param string + * @return this + */ + public function setKeyword($keyword) { + Front_Error::get()->argument(1, 'string', 'null'); + $this->_keyword = $keyword; + + return $this; + } + + /** + * This Block has pagination we need to pass in the GET query + * + * @param array + * @return this + */ + public function setQuery(array $query) { + $this->_query = $query; + return $this; + } + + /** + * This Block has pagination we need to pass in the url + * + * @param array + * @return this + */ + public function setUrl($url) { + $this->_url = $url; + return $this; + } + + /** + * Sets class for each page link + * + * @param array + * @return this + */ + public function setClass($class) { + $this->_class = $class; + return $this; + } + + + /** + * Sets a label + * + * @param array + * @return this + */ + public function setLabel($label) { + $this->_label = $label; + return $this; + } + + /** + * Sets a label + * + * @param array + * @return this + */ + public function setName($name) { + $this->_name = $name; + return $this; + } + + /** + * Returns the template variables in key value format + * + * @param array data + * @return array + */ + public function getVariables() { + return array( + 'name' => $this->_name, + 'class' => $this->_class, + 'label' => $this->_title, + 'url' => $this->_url, + 'query' => $this->_query, + 'keyword' => $this->_keyword); + } + + /** + * Returns a template file + * + * @param array data + * @return string + */ + public function getTemplate() { + return realpath(dirname(__FILE__).'/template/search.php'); + } +} \ No newline at end of file diff --git a/library/eden/block/template/pagination.php b/library/eden/block/template/pagination.php new file mode 100644 index 0000000..98436a7 --- /dev/null +++ b/library/eden/block/template/pagination.php @@ -0,0 +1,16 @@ + 1): ?> + + \ No newline at end of file diff --git a/library/eden/block/template/search.php b/library/eden/block/template/search.php new file mode 100644 index 0000000..af1198c --- /dev/null +++ b/library/eden/block/template/search.php @@ -0,0 +1,9 @@ +
+ + + + + +
\ No newline at end of file diff --git a/library/eden/mysql/model/abstract.php b/library/eden/mysql/model/abstract.php index 0caf3ff..e06754d 100644 --- a/library/eden/mysql/model/abstract.php +++ b/library/eden/mysql/model/abstract.php @@ -29,6 +29,8 @@ abstract class Eden_Mysql_Model_Abstract extends Eden_Class implements ArrayAcce protected $_database = NULL; protected $_table = NULL; + protected static $_cache = array(); + /* Private Properties -------------------------------*/ /* Get @@ -252,6 +254,12 @@ public function offsetGet($offset) { /* Protected Methods -------------------------------*/ protected function _setMetaData() { + if(isset(self::$_cache[$this->_table])) { + $this->_meta = self::$_cache[$this->_table]['meta']; + $this->_primary = self::$_cache[$this->_table]['primary']; + return $this; + } + $columns = $this->_database->getColumns($this->_table); foreach($columns as $column) { @@ -265,6 +273,10 @@ protected function _setMetaData() { $this->_primary = $column['Field']; } } + + self::$_cache[$this->_table]['meta'] = $this->_meta; + self::$_cache[$this->_table]['primary'] = $this->_primary; + return $this; } /* Private Methods diff --git a/library/eden/session.php b/library/eden/session.php index 09baaa5..b011432 100755 --- a/library/eden/session.php +++ b/library/eden/session.php @@ -54,12 +54,10 @@ public function __toString() { * @return bool */ public function start() { - if (isset($_COOKIE['PHPSESSID'])) { - self::$_session = $_COOKIE['PHPSESSID']; - return $this; - } + if(!session_id()) { + self::$_session = session_start(); + } - self::$_session = session_start(); return $this; } diff --git a/library/eden/sql/select.php b/library/eden/sql/select.php index 6fb7c6f..15a780d 100755 --- a/library/eden/sql/select.php +++ b/library/eden/sql/select.php @@ -280,7 +280,7 @@ public function getQuery() { $query = sprintf( 'SELECT %s FROM %s %s %s %s %s %s;', $this->_select, $this->_from, $joins, - $where, $sort, $group, $limit); + $where, $group, $sort, $limit); return str_replace(' ', ' ', $query); } From 28763666df1116b671e540307ed8723ebb86a6a5 Mon Sep 17 00:00:00 2001 From: cblanquera Date: Tue, 3 Jan 2012 15:10:55 +0000 Subject: [PATCH 031/330] doc fix git-svn-id: http://svn.openovate.com/edenv2/trunk@31 38ede93f-50f4-44af-b0b3-68ccca78c181 --- library/eden/curl.php | 8 -------- 1 file changed, 8 deletions(-) diff --git a/library/eden/curl.php b/library/eden/curl.php index cbd9cc5..50880f8 100644 --- a/library/eden/curl.php +++ b/library/eden/curl.php @@ -9,14 +9,6 @@ require_once dirname(__FILE__).'/class.php'; -/** - * cURL wrapper - * - * @package Eden - * @category curl - * @author Christian Blanquera - * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ - */ /** * cURL wrapper * From a7d7737430b6099e04569cd9e5bc1487eb231517 Mon Sep 17 00:00:00 2001 From: cblanquera Date: Wed, 4 Jan 2012 09:20:11 +0000 Subject: [PATCH 032/330] Logic error when calling getData fixed git-svn-id: http://svn.openovate.com/edenv2/trunk@32 38ede93f-50f4-44af-b0b3-68ccca78c181 --- library/eden/mysql/model/abstract.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/eden/mysql/model/abstract.php b/library/eden/mysql/model/abstract.php index e06754d..99a02ec 100644 --- a/library/eden/mysql/model/abstract.php +++ b/library/eden/mysql/model/abstract.php @@ -100,7 +100,7 @@ abstract public function save(); */ public function getData() { $data = $this->_data; - foreach($this->_meta as $name => $data) { + foreach($this->_meta as $name => $meta) { if(!isset($data[$name])) { $data[$name] = NULL; } From f6bd03d4e1348e41ef3da75fac091e5ac429755e Mon Sep 17 00:00:00 2001 From: cblanquera Date: Thu, 5 Jan 2012 02:06:19 +0000 Subject: [PATCH 033/330] public static function get no longer a requirement git-svn-id: http://svn.openovate.com/edenv2/trunk@33 38ede93f-50f4-44af-b0b3-68ccca78c181 --- library/eden/route.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/library/eden/route.php b/library/eden/route.php index 934a419..3209049 100755 --- a/library/eden/route.php +++ b/library/eden/route.php @@ -248,7 +248,13 @@ public function getClassArray($class, array $args = array()) { //argument 1 must be a string Eden_Route_Error::get()->argument(1, 'string'); - return $this->callMethod($class, 'get', NULL, $args); + $route = $this->getRouteClass($class, $class); + if(method_exists($route, 'get')) { + return $this->callMethod($class, 'get', NULL, $args); + } + + $reflect = new ReflectionClass($route); + return $reflect->newInstanceArgs($args); } /** From 3c02f34309202398aa49f431ebd662c72552f781 Mon Sep 17 00:00:00 2001 From: cblanquera Date: Thu, 5 Jan 2012 02:46:00 +0000 Subject: [PATCH 034/330] pass by reference methods like array_unshift in Eden_Array now is working git-svn-id: http://svn.openovate.com/edenv2/trunk@34 38ede93f-50f4-44af-b0b3-68ccca78c181 --- library/eden/array.php | 4 ++-- library/eden/type/abstract.php | 8 +++++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/library/eden/array.php b/library/eden/array.php index 4e0a59b..4aed22b 100755 --- a/library/eden/array.php +++ b/library/eden/array.php @@ -413,11 +413,11 @@ protected function _getPostMethod($name) { } protected function _getReferenceMethod($name) { - if(in_array($name, self::$_postMethods)) { + if(in_array($name, self::$_referenceMethods)) { return $name; } - if(in_array('array_'.$name, self::$_postMethods)) { + if(in_array('array_'.$name, self::$_referenceMethods)) { return 'array_'.$name; } diff --git a/library/eden/type/abstract.php b/library/eden/type/abstract.php index 238bdc9..6a97b71 100755 --- a/library/eden/type/abstract.php +++ b/library/eden/type/abstract.php @@ -55,7 +55,13 @@ public function __call($name, $args) { //if this is a reference method if($method) { //call the method - $name($this->_data); + $data = &$this->_data; + //This doesn't work for reference methods as + //described in ticket 44139 of PHP Bugs + //array_unshift($args, $this->_data); + //the work around is as follows + call_user_func_array($method, array_merge(array(&$this->_data), $args)); + return $this; } } From 0a62e5e63dc6a997660a122e4cbac5af7b029793 Mon Sep 17 00:00:00 2001 From: dmolina Date: Thu, 5 Jan 2012 05:03:35 +0000 Subject: [PATCH 035/330] added a method to get the primary key or value without knowing the name of the primary git-svn-id: http://svn.openovate.com/edenv2/trunk@35 38ede93f-50f4-44af-b0b3-68ccca78c181 --- library/eden/mysql/error.php | 88 ++-- library/eden/mysql/model/abstract.php | 587 +++++++++++++------------- 2 files changed, 346 insertions(+), 329 deletions(-) diff --git a/library/eden/mysql/error.php b/library/eden/mysql/error.php index 0377ab8..b34a5b6 100755 --- a/library/eden/mysql/error.php +++ b/library/eden/mysql/error.php @@ -1,45 +1,45 @@ - -/* - * 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 - * @version $Id: exception.php 1 2010-01-02 23:06:36Z blanquera $ - */ -class Eden_Mysql_Error extends Eden_Error { - /* Constants - -------------------------------*/ - const QUERY_ERROR = '%s Query: %s'; - const SET_INVALID = 'No column %s exists in table %s.'; - - /* Public Properties - -------------------------------*/ - /* Protected Properties - -------------------------------*/ - /* Private Properties - -------------------------------*/ - /* Get - -------------------------------*/ - public static function get($message = NULL, $code = 0) { - $class = __CLASS__; - return new $class($message, $code); - } - - /* Magic - -------------------------------*/ - /* Public Methods - -------------------------------*/ - /* Protected Methods - -------------------------------*/ - /* Private Methods - -------------------------------*/ + +/* + * 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 + * @version $Id: exception.php 1 2010-01-02 23:06:36Z blanquera $ + */ +class Eden_Mysql_Error extends Eden_Error { + /* Constants + -------------------------------*/ + const QUERY_ERROR = '%s Query: %s'; + const SET_INVALID = 'No column %s exists in table %s.'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function get($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/mysql/model/abstract.php b/library/eden/mysql/model/abstract.php index 99a02ec..96211e9 100644 --- a/library/eden/mysql/model/abstract.php +++ b/library/eden/mysql/model/abstract.php @@ -1,285 +1,302 @@ - -/* - * 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. - */ - -/** - * - * @package Eden - * @category registry - * @author Christian Blanquera - * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ - */ -abstract class Eden_Mysql_Model_Abstract extends Eden_Class implements ArrayAccess, Iterator { - /* Constants - -------------------------------*/ - /* Public Properties - -------------------------------*/ - /* Protected Properties - -------------------------------*/ - protected $_primary = NULL; - protected $_meta = array(); - protected $_data = array(); - protected $_join = array(); - - protected $_database = NULL; - protected $_table = NULL; - - protected static $_cache = array(); - - /* Private Properties - -------------------------------*/ - /* Get - -------------------------------*/ - /* Magic - -------------------------------*/ - public function __call($name, $args) { - //if the method starts with get - if(strpos($name, 'get') === 0) { - $key = preg_replace("/([A-Z])/", "_$1", $name); - //get rid of get_ - $key = strtolower(substr($key, 4)); - - //if it's a data key - if(isset($this->_meta[$key])) { - return $this->_data[$key]; - } - } else if (strpos($name, 'set') === 0) { - $key = preg_replace("/([A-Z])/", "_$1", $name); - //get rid of get_ - $key = strtolower(substr($key, 4)); - - return $this->__set($key, $args[0]); - } - - try { - return parent::__call($name, $args); - } catch(Eden_Type_Error $e) { - throw new Eden_Mysql_Error($e->getMessage()); - } - } - - public function __get($name) { - if(isset($this->_data[$name])) { - return $this->_data[$name]; - } - - return NULL; - } - - public function __set($name, $value) { - if(isset($this->_meta[$name])) { - $this->_data[$name] = $value; - return $this; - } - - //throw an error - Eden_Mysql_Error::get() - ->setMessage(Eden_Mysql_Error::SET_INVALID) - ->addVariable($name) - ->addVariable($this->_table) - ->trigger(); - } - - public function __toString() { - return json_encode($this->_data); - } - - /* Public Methods - -------------------------------*/ - abstract public function save(); - - /** - * Returns an array version of the model - * - * @return array - */ - public function getData() { - $data = $this->_data; - foreach($this->_meta as $name => $meta) { - if(!isset($data[$name])) { - $data[$name] = NULL; - } - } - - return $data; - } - - /** - * Returns the table name - * - * @return string - */ - public function getTable() { - return $this->_table; - } - - /** - * Returns meta data - * - * @param string - * @param string - * @return array - */ - public function getMetaData($name = NULL, $key = NULL) { - //argument test - Eden_Mysql_Error::get() - ->argument(1, 'string', 'null') //argument 1 must be a string or null - ->argument(2, 'string', 'null'); //argument 2 must be a string or null - - if(!is_null($name) && isset($this->_meta[$name])) { - if(!is_null($key) && isset($this->_meta[$name][$key])) { - return $this->_meta[$name][$key]; - } - return $this->_meta[$name]; - } - - return $this->_meta; - } - - /** - * Sets data using the ArrayAccess interface - * We overloaded this to not allow creating new - * columns. - * - * @param number - * @param mixed - * @return void - */ - public function offsetSet($offset, $value) { - //if this is not set in the meta data - if(!isset($this->_meta[$offset])) { - //throw an error - Eden_Mysql_Error::get() - ->setMessage(Eden_Mysql_Error::SET_INVALID) - ->addVariable($offset) - ->addVariable($this->_table) - ->trigger(); - } - - $this->__set($offset, $value); - } - - /** - * unsets using the ArrayAccess interface - * We overloaded this because an attributes - * must never be removed. Instead we set it to - * null. - * - * @param number - * @return void - */ - public function offsetUnset($offset) { - //if it is set in the meta - if(isset($this->_meta[$offset])) { - //set it to null - $this->__set($offset, NULL); - } - } - - /** - * Rewinds the position - * For Iterator interface - * - * @return void - */ - public function rewind() { - reset($this->_data); - } - - /** - * Returns the current item - * For Iterator interface - * - * @return void - */ - public function current() { - return current($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); - } - - /** - * Validates whether if the index is set - * For Iterator interface - * - * @return void - */ - public function valid() { - return isset($this->_data[$this->key()]); - } - - /** - * 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; - } - - /* Protected Methods - -------------------------------*/ - protected function _setMetaData() { - if(isset(self::$_cache[$this->_table])) { - $this->_meta = self::$_cache[$this->_table]['meta']; - $this->_primary = self::$_cache[$this->_table]['primary']; - return $this; - } - - $columns = $this->_database->getColumns($this->_table); - - foreach($columns as $column) { - $this->_meta[$column['Field']] = array( - 'type' => $column['Type'], - 'key' => $column['Key'], - 'default' => $column['Default'], - 'empty' => $column['Null'] == 'YES'); - - if($column['Key'] == 'PRI') { - $this->_primary = $column['Field']; - } - } - - self::$_cache[$this->_table]['meta'] = $this->_meta; - self::$_cache[$this->_table]['primary'] = $this->_primary; - return $this; - } - - /* Private Methods - -------------------------------*/ -} - + +/* + * 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. + */ + +/** + * + * @package Eden + * @category registry + * @author Christian Blanquera + * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ + */ +abstract class Eden_Mysql_Model_Abstract extends Eden_Class implements ArrayAccess, Iterator { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_primary = NULL; + protected $_meta = array(); + protected $_data = array(); + protected $_join = array(); + + protected $_database = NULL; + protected $_table = NULL; + + protected static $_cache = array(); + + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + /* Magic + -------------------------------*/ + public function __call($name, $args) { + //if the method starts with get + if(strpos($name, 'get') === 0) { + $key = preg_replace("/([A-Z])/", "_$1", $name); + //get rid of get_ + $key = strtolower(substr($key, 4)); + + //if it's a data key + if(isset($this->_meta[$key])) { + return $this->_data[$key]; + } + } else if (strpos($name, 'set') === 0) { + $key = preg_replace("/([A-Z])/", "_$1", $name); + //get rid of get_ + $key = strtolower(substr($key, 4)); + + return $this->__set($key, $args[0]); + } + + try { + return parent::__call($name, $args); + } catch(Eden_Type_Error $e) { + throw new Eden_Mysql_Error($e->getMessage()); + } + } + + public function __get($name) { + if(isset($this->_data[$name])) { + return $this->_data[$name]; + } + + return NULL; + } + + public function __set($name, $value) { + if(isset($this->_meta[$name])) { + $this->_data[$name] = $value; + return $this; + } + + //throw an error + Eden_Mysql_Error::get() + ->setMessage(Eden_Mysql_Error::SET_INVALID) + ->addVariable($name) + ->addVariable($this->_table) + ->trigger(); + } + + public function __toString() { + return json_encode($this->_data); + } + + /* Public Methods + -------------------------------*/ + abstract public function save(); + + /** + * Get the primary key name or value + * + * @param bool + * @return string|number + */ + public function getPrimary($value = false) { + //argument 1 must be a string or null + Eden_Mysql_Error::get()->argument(1, 'bool'); + + if($value) { + return $this[$this->_primary]; + } + + return $this->_primary; + } + + /** + * Returns an array version of the model + * + * @return array + */ + public function getData() { + $data = $this->_data; + foreach($this->_meta as $name => $meta) { + if(!isset($data[$name])) { + $data[$name] = NULL; + } + } + + return $data; + } + + /** + * Returns the table name + * + * @return string + */ + public function getTable() { + return $this->_table; + } + + /** + * Returns meta data + * + * @param string + * @param string + * @return array + */ + public function getMetaData($name = NULL, $key = NULL) { + //argument test + Eden_Mysql_Error::get() + ->argument(1, 'string', 'null') //argument 1 must be a string or null + ->argument(2, 'string', 'null'); //argument 2 must be a string or null + + if(!is_null($name) && isset($this->_meta[$name])) { + if(!is_null($key) && isset($this->_meta[$name][$key])) { + return $this->_meta[$name][$key]; + } + return $this->_meta[$name]; + } + + return $this->_meta; + } + + /** + * Sets data using the ArrayAccess interface + * We overloaded this to not allow creating new + * columns. + * + * @param number + * @param mixed + * @return void + */ + public function offsetSet($offset, $value) { + //if this is not set in the meta data + if(!isset($this->_meta[$offset])) { + //throw an error + Eden_Mysql_Error::get() + ->setMessage(Eden_Mysql_Error::SET_INVALID) + ->addVariable($offset) + ->addVariable($this->_table) + ->trigger(); + } + + $this->__set($offset, $value); + } + + /** + * unsets using the ArrayAccess interface + * We overloaded this because an attributes + * must never be removed. Instead we set it to + * null. + * + * @param number + * @return void + */ + public function offsetUnset($offset) { + //if it is set in the meta + if(isset($this->_meta[$offset])) { + //set it to null + $this->__set($offset, NULL); + } + } + + /** + * Rewinds the position + * For Iterator interface + * + * @return void + */ + public function rewind() { + reset($this->_data); + } + + /** + * Returns the current item + * For Iterator interface + * + * @return void + */ + public function current() { + return current($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); + } + + /** + * Validates whether if the index is set + * For Iterator interface + * + * @return void + */ + public function valid() { + return isset($this->_data[$this->key()]); + } + + /** + * 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; + } + + /* Protected Methods + -------------------------------*/ + protected function _setMetaData() { + if(isset(self::$_cache[$this->_table])) { + $this->_meta = self::$_cache[$this->_table]['meta']; + $this->_primary = self::$_cache[$this->_table]['primary']; + return $this; + } + + $columns = $this->_database->getColumns($this->_table); + + foreach($columns as $column) { + $this->_meta[$column['Field']] = array( + 'type' => $column['Type'], + 'key' => $column['Key'], + 'default' => $column['Default'], + 'empty' => $column['Null'] == 'YES'); + + if($column['Key'] == 'PRI') { + $this->_primary = $column['Field']; + } + } + + self::$_cache[$this->_table]['meta'] = $this->_meta; + self::$_cache[$this->_table]['primary'] = $this->_primary; + return $this; + } + + /* Private Methods + -------------------------------*/ +} + From fad2b37a6464d36a526a362e1b09c548b81993d9 Mon Sep 17 00:00:00 2001 From: cblanquera Date: Thu, 5 Jan 2012 05:59:38 +0000 Subject: [PATCH 036/330] public static function get no longer a requirement git-svn-id: http://svn.openovate.com/edenv2/trunk@36 38ede93f-50f4-44af-b0b3-68ccca78c181 --- library/eden/route.php | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/library/eden/route.php b/library/eden/route.php index 3209049..6e57b58 100755 --- a/library/eden/route.php +++ b/library/eden/route.php @@ -249,11 +249,19 @@ public function getClassArray($class, array $args = array()) { Eden_Route_Error::get()->argument(1, 'string'); $route = $this->getRouteClass($class, $class); + $reflect = new ReflectionClass($route); + if(method_exists($route, 'get')) { - return $this->callMethod($class, 'get', NULL, $args); + $declared = $reflect + ->getMethod('get') + ->getDeclaringClass() + ->getName(); + + if($declared == $route) { + return $this->callMethod($class, 'get', NULL, $args); + } } - $reflect = new ReflectionClass($route); return $reflect->newInstanceArgs($args); } @@ -351,7 +359,7 @@ public function callMethod($class, $method, $instance = NULL, array $args = arra * @return mixed */ public function callFunction($func, array $args = array()) { - Eden_Error_Validate::get()->argument(0, 'string'); //argument 1 must be a string + Eden_Route_Error::get()->argument(0, 'string'); //argument 1 must be a string try { //try to run the function using PHP call_user_func_array From 815a95d3b3bd954bb2487811060b768c31825140 Mon Sep 17 00:00:00 2001 From: cblanquera Date: Thu, 5 Jan 2012 09:11:11 +0000 Subject: [PATCH 037/330] public static function get is now a requirement. Some changes to support PHP5.3 still working on how namespaces work with the router git-svn-id: http://svn.openovate.com/edenv2/trunk@37 38ede93f-50f4-44af-b0b3-68ccca78c181 --- library/eden/class.php | 31 ++++++++++++------------------- library/eden/loader.php | 5 ++++- 2 files changed, 16 insertions(+), 20 deletions(-) diff --git a/library/eden/class.php b/library/eden/class.php index 7ecc546..abb194c 100755 --- a/library/eden/class.php +++ b/library/eden/class.php @@ -152,15 +152,7 @@ protected static function _getSingleton($class) { $class = Eden_Route::get()->getRouteClass($class, $class); - try { - self::$_instances[$class] = self::_getInstance($class, $args); - } catch(Reflection_Exception $e) { - Eden_Error::get() - ->setMessage(Eden_Error::REFLECTION_ERROR) - ->addVariable($class) - ->addVariable('new') - ->trigger(); - } + self::$_instances[$class] = self::_getInstance($class, $args); } return self::$_instances[$class]; @@ -172,15 +164,7 @@ protected static function _getMultiple($class) { $class = Eden_Route::get()->getRouteClass($class, $class); - try { - return self::_getInstance($class, $args); - } catch(Reflection_Exception $e) { - Eden_Error::get() - ->setMessage(Eden_Error::REFLECTION_ERROR) - ->addVariable($class) - ->addVariable('new') - ->trigger(); - } + return self::_getInstance($class, $args); } /* Private Methods @@ -191,6 +175,15 @@ private static function _getInstance($class, $args) { } $reflect = new ReflectionClass($class); - return $reflect->newInstanceArgs($args); + + try { + return $reflect->newInstanceArgs($args); + } catch(Reflection_Exception $e) { + Eden_Error::get() + ->setMessage(Eden_Error::REFLECTION_ERROR) + ->addVariable($class) + ->addVariable('new') + ->trigger(); + } } } \ No newline at end of file diff --git a/library/eden/loader.php b/library/eden/loader.php index a642753..b55818e 100755 --- a/library/eden/loader.php +++ b/library/eden/loader.php @@ -75,7 +75,10 @@ public function handler($class) { return false; } - $path = '/'.strtolower(str_replace('_', '/', $class)); + $path = str_replace(array('_', '\\'), '/', $class); + $path = '/'.strtolower($path); + $path = str_replace('//', '/', $path); + foreach($this->_root as $root) { $file = $root.$path.'.php'; From 96d9ba447f52523d739716ab633849f2410a7170 Mon Sep 17 00:00:00 2001 From: cblanquera Date: Thu, 5 Jan 2012 09:47:34 +0000 Subject: [PATCH 038/330] using parent _getMultiple or _getSingleton to allow class overrides git-svn-id: http://svn.openovate.com/edenv2/trunk@38 38ede93f-50f4-44af-b0b3-68ccca78c181 --- library/eden/cache.php | 3 +- library/eden/class.php | 6 +-- library/eden/curl.php | 3 +- library/eden/error/event.php | 9 +--- library/eden/image.php | 3 +- library/eden/memcache.php | 3 +- library/eden/mysql.php | 3 +- library/eden/mysql/create.php | 3 +- library/eden/mysql/error.php | 87 ++++++++++++++++---------------- library/eden/mysql/subselect.php | 3 +- library/eden/unit.php | 3 +- library/eden/webcharge.php | 3 +- 12 files changed, 56 insertions(+), 73 deletions(-) diff --git a/library/eden/cache.php b/library/eden/cache.php index e80b498..74ebf06 100755 --- a/library/eden/cache.php +++ b/library/eden/cache.php @@ -40,8 +40,7 @@ class Eden_Cache extends Eden_Class { /* Get -------------------------------*/ public static function get($root, $key = 'key.php') { - $class = __CLASS__; - return new $class($root, $key); + return self::_getMultiple(__CLASS__, $root, $key); } /* Magic diff --git a/library/eden/class.php b/library/eden/class.php index abb194c..6e7f380 100755 --- a/library/eden/class.php +++ b/library/eden/class.php @@ -146,11 +146,11 @@ public function endWhen() { /* Protected Methods -------------------------------*/ protected static function _getSingleton($class) { + $class = Eden_Route::get()->getRouteClass($class, $class); + if(!isset(self::$_instances[$class])) { $args = func_get_args(); - $class = array_shift($args); - - $class = Eden_Route::get()->getRouteClass($class, $class); + array_shift($args); self::$_instances[$class] = self::_getInstance($class, $args); } diff --git a/library/eden/curl.php b/library/eden/curl.php index 50880f8..c998b64 100644 --- a/library/eden/curl.php +++ b/library/eden/curl.php @@ -141,8 +141,7 @@ class Eden_Curl extends Eden_Class implements ArrayAccess { /* Get -------------------------------*/ public static function get() { - $class = __CLASS__; - return new $class(); + return self::_getMultiple(__CLASS__); } /* Magic diff --git a/library/eden/error/event.php b/library/eden/error/event.php index 6eb63fb..9daadd9 100755 --- a/library/eden/error/event.php +++ b/library/eden/error/event.php @@ -29,19 +29,12 @@ class Eden_Error_Event extends Eden_Event { -------------------------------*/ /* Protected Properties -------------------------------*/ - protected static $_instance = NULL; - /* Private Properties -------------------------------*/ /* Get -------------------------------*/ public static function get() { - $class = __CLASS__; - if(is_null(self::$_instance)) { - self::$_instance = new $class(); - } - - return self::$_instance; + return self::_getSingleton(__CLASS__); } /* Magic diff --git a/library/eden/image.php b/library/eden/image.php index 97d35d8..549f5aa 100644 --- a/library/eden/image.php +++ b/library/eden/image.php @@ -40,8 +40,7 @@ class Eden_Image extends Eden_Class { /* Get -------------------------------*/ public static function get($data, $type = NULL, $path = true, $quality = 75) { - $class = __CLASS__; - return new $class($data, $type, $path, $quality); + return self::_getMultiple(__CLASS__, $data, $type, $path, $quality); } /* Magic diff --git a/library/eden/memcache.php b/library/eden/memcache.php index 94e7830..984c36e 100755 --- a/library/eden/memcache.php +++ b/library/eden/memcache.php @@ -39,8 +39,7 @@ class Eden_Memcache extends Eden_Class { /* Get -------------------------------*/ public static function get($host = 'localhost', $port = 11211, $timeout = 1) { - $class = __CLASS__; - return new $class($host, $port, $timeout); + return self::_getMultiple(__CLASS__, $host, $port, $timeout); } /* Magic diff --git a/library/eden/mysql.php b/library/eden/mysql.php index 77191d5..484cda1 100755 --- a/library/eden/mysql.php +++ b/library/eden/mysql.php @@ -55,8 +55,7 @@ class Eden_Mysql extends Eden_Sql_Database { /* Get -------------------------------*/ public static function get($host = NULL, $name = NULL, $user = NULL, $pass = NULL) { - $class = __CLASS__; - return new $class($host, $name, $user, $pass); + return self::_getMultiple(__CLASS__, $host, $name, $user, $pass); } /* Magic diff --git a/library/eden/mysql/create.php b/library/eden/mysql/create.php index e876a36..b14a8e0 100755 --- a/library/eden/mysql/create.php +++ b/library/eden/mysql/create.php @@ -34,8 +34,7 @@ class Eden_Mysql_Create extends Eden_Sql_Query { /* Get -------------------------------*/ public static function get($name = NULL) { - $class = __CLASS__; - return new $class($name); + return self::_getMultiple(__CLASS__, $name); } /* Magic diff --git a/library/eden/mysql/error.php b/library/eden/mysql/error.php index b34a5b6..7087f84 100755 --- a/library/eden/mysql/error.php +++ b/library/eden/mysql/error.php @@ -1,45 +1,44 @@ - -/* - * 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 - * @version $Id: exception.php 1 2010-01-02 23:06:36Z blanquera $ - */ -class Eden_Mysql_Error extends Eden_Error { - /* Constants - -------------------------------*/ - const QUERY_ERROR = '%s Query: %s'; - const SET_INVALID = 'No column %s exists in table %s.'; - - /* Public Properties - -------------------------------*/ - /* Protected Properties - -------------------------------*/ - /* Private Properties - -------------------------------*/ - /* Get - -------------------------------*/ - public static function get($message = NULL, $code = 0) { - $class = __CLASS__; - return new $class($message, $code); - } - - /* Magic - -------------------------------*/ - /* Public Methods - -------------------------------*/ - /* Protected Methods - -------------------------------*/ - /* Private Methods - -------------------------------*/ + +/* + * 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 + * @version $Id: exception.php 1 2010-01-02 23:06:36Z blanquera $ + */ +class Eden_Mysql_Error extends Eden_Error { + /* Constants + -------------------------------*/ + const QUERY_ERROR = '%s Query: %s'; + const SET_INVALID = 'No column %s exists in table %s.'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function get($message = NULL, $code = 0) { + return self::_getMultiple(__CLASS__, $message, $code); + } + + /* Magic + -------------------------------*/ + /* 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 index f7ae592..ffe5f9c 100755 --- a/library/eden/mysql/subselect.php +++ b/library/eden/mysql/subselect.php @@ -30,8 +30,7 @@ class Eden_Mysql_Subselect extends Eden_Class { /* Get -------------------------------*/ public static function get(Eden_Sql_Select $parentQuery, $select = '*') { - $class = __CLASS__; - return new $class($parentQuery, $select); + return self::_getMultiple(__CLASS__, $parentQuery, $select); } /* Magic diff --git a/library/eden/unit.php b/library/eden/unit.php index 6acf80a..0c65b2d 100755 --- a/library/eden/unit.php +++ b/library/eden/unit.php @@ -33,8 +33,7 @@ class Eden_Unit { /* Get -------------------------------*/ public static function get() { - $class = __CLASS__; - return new $class; + return self::_getMultiple(__CLASS__); } /* Magic diff --git a/library/eden/webcharge.php b/library/eden/webcharge.php index f5490bf..85b269d 100644 --- a/library/eden/webcharge.php +++ b/library/eden/webcharge.php @@ -80,8 +80,7 @@ class Eden_Webcharge_Model extends Eden_Class /* Get -------------------------------*/ public static function get($user, $password, array $options = array()) { - $class = __CLASS__; - return new $class($user, $password, $options); + return self::_getMultiple(__CLASS__, $user, $password, $options); } /* Magic From 94a1e62cf402e0a45d3ad3a382fbf4f95c9e07e6 Mon Sep 17 00:00:00 2001 From: cblanquera Date: Thu, 5 Jan 2012 09:48:27 +0000 Subject: [PATCH 039/330] using parent _getMultiple or _getSingleton to allow class overrides git-svn-id: http://svn.openovate.com/edenv2/trunk@39 38ede93f-50f4-44af-b0b3-68ccca78c181 --- library/eden/mysql/error.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/library/eden/mysql/error.php b/library/eden/mysql/error.php index 7087f84..0377ab8 100755 --- a/library/eden/mysql/error.php +++ b/library/eden/mysql/error.php @@ -30,7 +30,8 @@ class Eden_Mysql_Error extends Eden_Error { /* Get -------------------------------*/ public static function get($message = NULL, $code = 0) { - return self::_getMultiple(__CLASS__, $message, $code); + $class = __CLASS__; + return new $class($message, $code); } /* Magic From 3b47fe8a5a987f281794062fe01331ef80f9cee1 Mon Sep 17 00:00:00 2001 From: sy Date: Thu, 5 Jan 2012 11:43:46 +0000 Subject: [PATCH 040/330] verify host is an integer option not a boolean option git-svn-id: http://svn.openovate.com/edenv2/trunk@40 38ede93f-50f4-44af-b0b3-68ccca78c181 --- library/eden/curl.php | 1045 +++++++++++++++++++++-------------------- 1 file changed, 525 insertions(+), 520 deletions(-) diff --git a/library/eden/curl.php b/library/eden/curl.php index c998b64..9bdef49 100644 --- a/library/eden/curl.php +++ b/library/eden/curl.php @@ -1,521 +1,526 @@ - -/* - * 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__).'/class.php'; - -/** - * cURL wrapper - * - * @package Eden - * @category curl - * @author Christian Blanquera - * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ - */ -class Eden_Curl extends Eden_Class implements ArrayAccess { - /* Constants - -------------------------------*/ - /* 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 - -------------------------------*/ - /* Get - -------------------------------*/ - public static function get() { - return self::_getMultiple(__CLASS__); - } - - /* Magic - -------------------------------*/ - public function __call($name, $args) { - if(strpos($name, 'set') === 0) { - $method = substr($name, 3); - - if(isset(self::$_setBoolKeys[$method])) { - Eden_Curl_Error::get()->vargument($name, $args, 1, 'bool'); - $key = self::$_setBoolKeys[$method]; - $this->_options[$key] = $args[0]; - - return $this; - } - - if(isset(self::$_setIntegerKeys[$method])) { - Eden_Curl_Error::get()->vargument($name, $args, 1, 'int'); - $key = self::$_setIntegerKeys[$method]; - $this->_options[$key] = $args[0]; - - return $this; - } - - if(isset(self::$_setStringKeys[$method])) { - Eden_Curl_Error::get()->vargument($name, $args, 1, 'string'); - $key = self::$_setStringKeys[$method]; - $this->_options[$key] = $args[0]; - - return $this; - } - - if(isset(self::$_setArrayKeys[$method])) { - Eden_Curl_Error::get()->vargument($name, $args, 1, 'array'); - $key = self::$_setArrayKeys[$method]; - $this->_options[$key] = $args[0]; - - return $this; - } - - if(isset(self::$_setFileKeys[$method])) { - $key = $this->_setFileKeys[$method]; - $this->_options[$key] = $args[0]; - - return $this; - } - - if(isset(self::$_setCallbackKeys[$method])) { - Eden_Curl_Error::get()->vargument($name, $args, 1, 'array', 'string'); - $key = self::$_setCallbackKeys[$method]; - $this->_options[$key] = $args[0]; - - return $this; - } - } - - parent::__call($name, $args); - } - - /* Public Methods - -------------------------------*/ - /** - * Sets CURLOPT_SSL_VERIFYHOST - * - * @param bool - * @return this - */ - public function verifyHost($on = true) { - Eden_Curl_Error::get()->argument(1, 'bool'); - $this->options[CURLOPT_SSL_VERIFYHOST] = $on; - return $this; - } - - /** - * Sets CURLOPT_SSL_VERIFYPEER - * - * @param bool - * @return this - */ - public function verifyPeer($on = true) { - Eden_Curl_Error::get()->argument(1, 'bool'); - $this->options[CURLOPT_SSL_VERIFYPEER] = $on; - return $this; - } - - /** - * Sets url parameter - * - * @param array|string - * @return this - */ - public function setUrlParameter($key, $value = NULL) { - Eden_Curl_Error::get() - ->argument(1, 'array', 'string') - ->argument(2, 'scalar'); - - if(is_array($key)) { - $this->_param = $key; - return $this; - } - - $this->_param[$key] = $value; - } - - /** - * Sets request headers - * - * @param array|string - * @return this - */ - public function setHeaders($key, $value = NULL) { - Eden_Curl_Error::get() - ->argument(1, 'array', 'string') - ->argument(2, 'scalar','null'); - - if(is_array($key)) { - $this->_headers = $key; - return $this; - } - - $this->_headers[] = $key.': '.$value; - return $this; - } - - /** - * 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; - } - - /** - * 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 JSON - * - * @return array - */ - public function getJsonResponse($assoc = true) { - $this->_meta['response'] = $this->getResponse(); - Eden_Curl_Error::get()->argument(1, 'bool'); - return json_decode($this->_meta['response'], $assoc); - } - - /** - * 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 - * parsed as SimpleXml - * - * @return SimpleXmlElement - */ - public function getSimpleXmlResponse() { - $this->_meta['response'] = $this->getResponse(); - return simplexml_load_string($this->_meta['response']); - } - - /** - * 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; - } - - /** - * Returns the meta of the last call - * - * @return array - */ - public function getMeta($key = NULL) { - Eden_Curl_Error::get()->argument(1, 'string', 'null'); - - if(isset($this->_meta[$key])) { - return $this->_meta[$key]; - } - - return $this->_meta; - } - - /** - * 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)); - } - } - } - - /** - * isset using the ArrayAccess interface - * - * @param number - * @return bool - */ - public function offsetExists($offset) { - return isset($this->_option[$offset]); - } - - /** - * unsets using the ArrayAccess interface - * - * @param number - * @return bool - */ - public function offsetUnset($offset) { - unset($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; - } - - /* Protected Methods - -------------------------------*/ - 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; - } - - protected function _addHeaders() { - if(empty($this->_headers)) { - return $this; - } - - $this->_options[CURLOPT_HTTPHEADER] = $this->_headers; - return $this; - } - - /* Private Methods - -------------------------------*/ -} - -/** - * cUrl Errors - */ -class Eden_Curl_Error extends Eden_Error { - /* Constants - -------------------------------*/ - /* Public Properties - -------------------------------*/ - /* Protected Properties - -------------------------------*/ - /* Private Properties - -------------------------------*/ - /* Get - -------------------------------*/ - public static function get($message = NULL, $code = 0) { - $class = __CLASS__; - return new $class($message, $code); - } - - /* Magic - -------------------------------*/ - /* Public Methods - -------------------------------*/ - /* Protected Methods - -------------------------------*/ - /* Private Methods - -------------------------------*/ + +/* + * 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__).'/class.php'; + +/** + * cURL wrapper + * + * @package Eden + * @category curl + * @author Christian Blanquera + * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ + */ +class Eden_Curl extends Eden_Class implements ArrayAccess { + /* Constants + -------------------------------*/ + /* 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 + -------------------------------*/ + /* Get + -------------------------------*/ + public static function get() { + return self::_getMultiple(__CLASS__); + } + + /* Magic + -------------------------------*/ + public function __call($name, $args) { + if(strpos($name, 'set') === 0) { + $method = substr($name, 3); + + if(isset(self::$_setBoolKeys[$method])) { + Eden_Curl_Error::get()->vargument($name, $args, 1, 'bool'); + $key = self::$_setBoolKeys[$method]; + $this->_options[$key] = $args[0]; + + return $this; + } + + if(isset(self::$_setIntegerKeys[$method])) { + Eden_Curl_Error::get()->vargument($name, $args, 1, 'int'); + $key = self::$_setIntegerKeys[$method]; + $this->_options[$key] = $args[0]; + + return $this; + } + + if(isset(self::$_setStringKeys[$method])) { + Eden_Curl_Error::get()->vargument($name, $args, 1, 'string'); + $key = self::$_setStringKeys[$method]; + $this->_options[$key] = $args[0]; + + return $this; + } + + if(isset(self::$_setArrayKeys[$method])) { + Eden_Curl_Error::get()->vargument($name, $args, 1, 'array'); + $key = self::$_setArrayKeys[$method]; + $this->_options[$key] = $args[0]; + + return $this; + } + + if(isset(self::$_setFileKeys[$method])) { + $key = $this->_setFileKeys[$method]; + $this->_options[$key] = $args[0]; + + return $this; + } + + if(isset(self::$_setCallbackKeys[$method])) { + Eden_Curl_Error::get()->vargument($name, $args, 1, 'array', 'string'); + $key = self::$_setCallbackKeys[$method]; + $this->_options[$key] = $args[0]; + + return $this; + } + } + + parent::__call($name, $args); + } + + /* Public Methods + -------------------------------*/ + /** + * Sets CURLOPT_SSL_VERIFYHOST + * + * @param bool + * @return this + */ + public function verifyHost($value) { + $error = Eden_Curl_Error::get()->argument(1, 'int'); + if($value != 1 && $value != 2) { + $error->setMessage(Eden_Curl_Error::NOT_ONE_OR_TWO)->trigger(); + } + $this->options[CURLOPT_SSL_VERIFYHOST] = $on; + return $this; + } + + /** + * Sets CURLOPT_SSL_VERIFYPEER + * + * @param bool + * @return this + */ + public function verifyPeer($on = true) { + Eden_Curl_Error::get()->argument(1, 'bool'); + $this->options[CURLOPT_SSL_VERIFYPEER] = $on; + return $this; + } + + /** + * Sets url parameter + * + * @param array|string + * @return this + */ + public function setUrlParameter($key, $value = NULL) { + Eden_Curl_Error::get() + ->argument(1, 'array', 'string') + ->argument(2, 'scalar'); + + if(is_array($key)) { + $this->_param = $key; + return $this; + } + + $this->_param[$key] = $value; + } + + /** + * Sets request headers + * + * @param array|string + * @return this + */ + public function setHeaders($key, $value = NULL) { + Eden_Curl_Error::get() + ->argument(1, 'array', 'string') + ->argument(2, 'scalar','null'); + + if(is_array($key)) { + $this->_headers = $key; + return $this; + } + + $this->_headers[] = $key.': '.$value; + return $this; + } + + /** + * 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; + } + + /** + * 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 JSON + * + * @return array + */ + public function getJsonResponse($assoc = true) { + $this->_meta['response'] = $this->getResponse(); + Eden_Curl_Error::get()->argument(1, 'bool'); + return json_decode($this->_meta['response'], $assoc); + } + + /** + * 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 + * parsed as SimpleXml + * + * @return SimpleXmlElement + */ + public function getSimpleXmlResponse() { + $this->_meta['response'] = $this->getResponse(); + return simplexml_load_string($this->_meta['response']); + } + + /** + * 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; + } + + /** + * Returns the meta of the last call + * + * @return array + */ + public function getMeta($key = NULL) { + Eden_Curl_Error::get()->argument(1, 'string', 'null'); + + if(isset($this->_meta[$key])) { + return $this->_meta[$key]; + } + + return $this->_meta; + } + + /** + * 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)); + } + } + } + + /** + * isset using the ArrayAccess interface + * + * @param number + * @return bool + */ + public function offsetExists($offset) { + return isset($this->_option[$offset]); + } + + /** + * unsets using the ArrayAccess interface + * + * @param number + * @return bool + */ + public function offsetUnset($offset) { + unset($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; + } + + /* Protected Methods + -------------------------------*/ + 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; + } + + protected function _addHeaders() { + if(empty($this->_headers)) { + return $this; + } + + $this->_options[CURLOPT_HTTPHEADER] = $this->_headers; + return $this; + } + + /* Private Methods + -------------------------------*/ +} + +/** + * cUrl Errors + */ +class Eden_Curl_Error extends Eden_Error { + /* Constants + -------------------------------*/ + const NOT_ONE_OR_TWO = 'Value passed into setVerifyHost or verifyHost must be 1 or 2'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function get($message = NULL, $code = 0) { + $class = __CLASS__; + return new $class($message, $code); + } + + /* Magic + -------------------------------*/ + /* Public Methods + -------------------------------*/ + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ } \ No newline at end of file From c5cfb140fa72e3b1d48939d772e7c87b706815e1 Mon Sep 17 00:00:00 2001 From: sy Date: Thu, 5 Jan 2012 11:46:58 +0000 Subject: [PATCH 041/330] verify host is an integer option not a boolean option git-svn-id: http://svn.openovate.com/edenv2/trunk@41 38ede93f-50f4-44af-b0b3-68ccca78c181 --- library/eden/curl.php | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/library/eden/curl.php b/library/eden/curl.php index 9bdef49..f6b37c8 100644 --- a/library/eden/curl.php +++ b/library/eden/curl.php @@ -209,12 +209,9 @@ public function __call($name, $args) { * @param bool * @return this */ - public function verifyHost($value) { - $error = Eden_Curl_Error::get()->argument(1, 'int'); - if($value != 1 && $value != 2) { - $error->setMessage(Eden_Curl_Error::NOT_ONE_OR_TWO)->trigger(); - } - $this->options[CURLOPT_SSL_VERIFYHOST] = $on; + public function verifyHost($on = true) { + Eden_Curl_Error::get()->argument(1, 'bool'); + $this->options[CURLOPT_SSL_VERIFYHOST] = $on ? 1 : 2; return $this; } @@ -500,8 +497,6 @@ protected function _addHeaders() { class Eden_Curl_Error extends Eden_Error { /* Constants -------------------------------*/ - const NOT_ONE_OR_TWO = 'Value passed into setVerifyHost or verifyHost must be 1 or 2'; - /* Public Properties -------------------------------*/ /* Protected Properties From 8c8f35d4b6b363060bdfb627e257a026384ff048 Mon Sep 17 00:00:00 2001 From: cblanquera Date: Fri, 6 Jan 2012 07:05:57 +0000 Subject: [PATCH 042/330] Route can call classes with new, error handler with false positives fix, argument method no longer require a strict int or float, when testing against those types. Also number is a type. git-svn-id: http://svn.openovate.com/edenv2/trunk@42 38ede93f-50f4-44af-b0b3-68ccca78c181 --- library/eden/error.php | 128 +++++++++++++---------------------- library/eden/error/event.php | 25 ++++--- library/eden/loader.php | 4 +- library/eden/route.php | 5 ++ 4 files changed, 72 insertions(+), 90 deletions(-) diff --git a/library/eden/error.php b/library/eden/error.php index 6074ed2..0491312 100755 --- a/library/eden/error.php +++ b/library/eden/error.php @@ -56,6 +56,7 @@ class Eden_Error extends Exception { protected $_level = NULL; protected $_offset = 1; protected $_variables = array(); + protected $_trace = array(); /* Private Properties -------------------------------*/ @@ -71,7 +72,7 @@ public static function get($message = NULL, $code = 0) { public function __construct($message = NULL, $code = 0) { $this->_type = self::LOGIC; $this->_level = self::ERROR; - $this->_reporter = $this->_getReporter(); + parent::__construct($message, $code); } @@ -238,14 +239,43 @@ public function addVariable($variable) { return $this; } + /** + * Returns variables + * + * @return array + */ + public function getVariables() { + return $this->_variables; + } + + /** + * Returns raw trace + * + * @return array + */ + public function getRawTrace() { + return $this->_trace; + } + /** * Combines parameters with message and throws it * * @return void */ public function trigger() { - if(!empty($this->_variables)) { - $this->message = vsprintf($this->message, $this->_variables); + $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']; } throw $this; @@ -286,79 +316,27 @@ public function argument($index, $types) { if(class_exists($type) && $argument instanceof $type) { return $this; } - } - - //lets formulate the method - $method = $trace['function']; - if(isset($trace['class'])) { - $method = $trace['class'].'->'.$method; - } - - $type = 'unknown'; - if(is_string($argument)) { - $type = "'".$argument."'"; - } else if(is_numeric($argument)) { - $type = $argument; - } else if(is_array($argument)) { - $type = 'Array'; - } else if(is_bool($argument)) { - $type = $argument ? 'true' : 'false'; - } else if(is_object($argument)) { - $type = get_class($argument); - } else if(is_null($argument)) { - $type = 'null'; - } - - $this->setMessage(self::INVALID_ARGUMENT) - ->addVariable($index + 1) - ->addVariable($method) - ->addVariable(implode(' or ', $types)) - ->addVariable($type) - ->setTypeLogic() - ->setTraceOffset(2) - ->trigger(); - } - - /** - * Tests virtual arguments for valid data types - * - * @param *int - * @param *mixed - * @param *string[,string..] - * @return this - */ - public function vargument($method, $args, $index, $types) { - $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) { - $method = 'is_'.$type; - if(function_exists($method) && $method($argument)) { + + if($type == 'number' && is_numeric($argument)) { return $this; } - if(class_exists($type) && $argument instanceof $type) { + if($type == 'int' && is_numeric($argument) + && strpos((string) $argument, '.') === false) { + return $this; + } + + if($type == 'float' && is_numeric($argument) + && strpos((string) $argument, '.') !== false) { return $this; } } - $method = $trace['class'].'->'.$method; + //lets formulate the method + $method = $trace['function']; + if(isset($trace['class'])) { + $method = $trace['class'].'->'.$method; + } $type = 'unknown'; if(is_string($argument)) { @@ -381,22 +359,12 @@ public function vargument($method, $args, $index, $types) { ->addVariable(implode(' or ', $types)) ->addVariable($type) ->setTypeLogic() - ->setTraceOffset(2) + ->setTraceOffset(1) ->trigger(); } /* Protected Methods -------------------------------*/ - protected function _getReporter() { - $trace = $this->getTrace(); - - if(isset($trace[0]['class'])) { - return $trace[0]['class']; - } - - return get_class($this); - } - /* Private Methods -------------------------------*/ } \ No newline at end of file diff --git a/library/eden/error/event.php b/library/eden/error/event.php index 9daadd9..ada5f18 100755 --- a/library/eden/error/event.php +++ b/library/eden/error/event.php @@ -87,9 +87,9 @@ public function errorHandler($errno, $errstr, $errfile, $errline) { } $this->trigger( - 'error', $trace, 1, - $type, $level, $class, - $errfile, $errline, $errstr); + 'error', $type, $level, + $class, $errfile, $errline, + $errstr, $trace, 1); //Don't execute PHP internal error handler return true; @@ -129,22 +129,29 @@ public function exceptionHandler(Exception $e) { $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(); + $variables = $e->getVariables(); + + if(!empty($variables)) { + $message = vsprintf($message, $variables); + } } - //get trace - $trace = $e->getTrace(); - $this->trigger( - 'exception', $trace, $offset, - $type, $level, $reporter, - $e->getFile(), $e->getLine(), $e->getMessage()); + 'exception', $type, $level, + $reporter, $e->getFile(), $e->getLine(), + $message, $trace, $offset); } /** diff --git a/library/eden/loader.php b/library/eden/loader.php index b55818e..4dc00c8 100755 --- a/library/eden/loader.php +++ b/library/eden/loader.php @@ -98,7 +98,9 @@ public function handler($class) { * @return this */ public function load($class) { - $this->handler($class); + if(!class_exists($class)) { + $this->handler($class); + } return $this; } diff --git a/library/eden/route.php b/library/eden/route.php index 6e57b58..74ec525 100755 --- a/library/eden/route.php +++ b/library/eden/route.php @@ -61,6 +61,11 @@ public function routeClass($route, $class) { ->argument(1, 'string') //argument 1 must be a string ->argument(2, 'string'); //argument 2 must be a string + if(isset($this->_classes[$class])) { + $this->_classes[$route] = $this->_classes[$class]; + return $this; + } + $this->_classes[$route] = $class; return $this; } From 2b54708e1e4d8dea441933487bb94365899f9fa1 Mon Sep 17 00:00:00 2001 From: cblanquera Date: Sun, 8 Jan 2012 07:45:42 +0000 Subject: [PATCH 043/330] rebuilt mysql to be more robust and add to the chain. made array make more sense and added collections fixed some outdated code git-svn-id: http://svn.openovate.com/edenv2/trunk@43 38ede93f-50f4-44af-b0b3-68ccca78c181 --- library/eden.php | 44 ++- library/eden/apc.php | 2 +- library/eden/array.php | 458 ----------------------- library/eden/class.php | 20 +- library/eden/collection.php | 377 +++++++++++++++++++ library/eden/cookie.php | 25 +- library/eden/error.php | 85 +++++ library/eden/error/event.php | 5 - library/eden/facebook/graph.php | 117 ++++-- library/eden/folder.php | 2 +- library/eden/image.php | 2 +- library/eden/map.php | 82 +++++ library/eden/model.php | 167 +-------- library/eden/mysql.php | 159 +++++++- library/eden/mysql/collection.php | 126 +++++++ library/eden/mysql/error.php | 6 +- library/eden/mysql/model.php | 296 ++++++++++++--- library/eden/mysql/model/abstract.php | 302 ---------------- library/eden/mysql/search.php | 503 ++++++++++++++++++++++++++ library/eden/mysql/utility.php | 20 +- library/eden/registry.php | 324 ++++++----------- library/eden/route.php | 22 +- library/eden/session.php | 26 +- library/eden/sql/insert.php | 8 +- library/eden/sql/update.php | 8 +- library/eden/string.php | 209 ----------- library/eden/type.php | 98 +++++ library/eden/type/abstract.php | 145 ++++---- library/eden/type/array.php | 400 ++++++++++++++++++++ library/eden/type/string.php | 171 +++++++++ library/eden/webcharge.php | 10 +- library/eden/when.php | 16 +- 32 files changed, 2633 insertions(+), 1602 deletions(-) delete mode 100755 library/eden/array.php create mode 100644 library/eden/collection.php create mode 100644 library/eden/map.php create mode 100644 library/eden/mysql/collection.php delete mode 100644 library/eden/mysql/model/abstract.php create mode 100644 library/eden/mysql/search.php delete mode 100755 library/eden/string.php create mode 100644 library/eden/type.php create mode 100644 library/eden/type/array.php create mode 100644 library/eden/type/string.php diff --git a/library/eden.php b/library/eden.php index 7b755d5..3ae5194 100644 --- a/library/eden.php +++ b/library/eden.php @@ -37,6 +37,7 @@ class Eden extends Eden_Event { /* Protected Properties -------------------------------*/ protected $_root = NULL; + protected static $_active = NULL; /* Private Properties -------------------------------*/ @@ -49,6 +50,10 @@ public static function get() { /* Magic -------------------------------*/ public function __construct() { + if(!self::$_active) { + self::$_active = $this; + } + $this->_root = dirname(__FILE__); } @@ -92,6 +97,15 @@ public function getRoot() { return $this->_root; } + /** + * Get Active Application + * + * @return Eden + */ + public function getActiveApp() { + return self::$_active; + } + /** * Sets up Autoloading * @@ -159,10 +173,34 @@ public function setLoader() { * @param string|array routes * @return Eden_Framework */ - public function setClasses($routes) { - Eden_Error::get()->argument(1, 'string', 'array'); + public function routeClasses($routes) { + Eden_Error::get()->argument(1, 'string', 'array', 'bool'); $route = Eden_Route::get(); + if($routes === true) { + $route->routeClass('Cache', 'Eden_Cache') + ->routeClass('String', 'Eden_Type_String') + ->routeClass('Array', 'Eden_Type_Array') + ->routeClass('Registry', 'Eden_Registry') + ->routeClass('Model', 'Eden_Model') + ->routeClass('Collection', 'Eden_Collection') + ->routeClass('Cookie', 'Eden_Cookie') + ->routeClass('Session', 'Eden_Session') + ->routeClass('Template', 'Eden_Template') + ->routeClass('Curl', 'Eden_Curl') + ->routeClass('Event', 'Eden_Event') + ->routeClass('Path', 'Eden_Path') + ->routeClass('File', 'Eden_File') + ->routeClass('Folder', 'Eden_Folder') + ->routeClass('Image', 'Eden_Image') + ->routeClass('Mysql', 'Eden_Mysql') + ->routeClass('Array', 'Eden_Type_Array') + ->routeClass('String', 'Eden_Type_String') + ->routeClass('Validation', 'Eden_Validation'); + + return $this; + } + if(is_string($routes)) { $routes = include($routes); } @@ -180,7 +218,7 @@ public function setClasses($routes) { * @param string|array routes * @return Eden_Framework */ - public function setMethods($routes) { + public function routeMethods($routes) { Eden_Error::get()->argument(1, 'string', 'array'); $route = Eden_Route::get(); diff --git a/library/eden/apc.php b/library/eden/apc.php index 847cbde..dd69f1a 100755 --- a/library/eden/apc.php +++ b/library/eden/apc.php @@ -45,7 +45,7 @@ public function __construct() { //if apc_cache_info is not a function if(!function_exists('apc_cache_info')) { //throw exception - throw new Eden_Apc_Error(Eden_Apc_Error::NOT_INSTALLED); + Eden_Apc_Error::get(Eden_Apc_Error::NOT_INSTALLED)->trigger(); } } diff --git a/library/eden/array.php b/library/eden/array.php deleted file mode 100755 index 4aed22b..0000000 --- a/library/eden/array.php +++ /dev/null @@ -1,458 +0,0 @@ - -/* - * 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__).'/class.php'; -require_once dirname(__FILE__).'/type/abstract.php'; -require_once dirname(__FILE__).'/type/error.php'; -require_once dirname(__FILE__).'/string.php'; - -/** - * - * @package Eden - * @category registry - * @author Christian Blanquera - * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ - */ -class Eden_Array extends Eden_Type_Abstract implements ArrayAccess, Iterator, Serializable, Countable { - /* Constants - -------------------------------*/ - /* Public Properties - -------------------------------*/ - /* Protected Properties - -------------------------------*/ - protected static $_preMethods = array( - 'array_change_key_case', 'array_chunk', - 'array_combine', 'array_count_datas', - 'array_diff_assoc', 'array_diff_key', - 'array_diff_uassoc', 'array_diff_ukey', - 'array_diff', 'array_fill_keys', - 'array_filter', 'array_flip', - 'array_intersect_assoc', 'array_intersect_key', - 'array_intersect_uassoc', 'array_intersect_ukey', - 'array_intersect', 'array_keys', - 'array_merge_recursive', 'array_merge', - 'array_pad', 'array_push', - 'array_reverse', 'array_shift', - 'array_slice', 'array_splice', - 'array_sum', 'array_udiff_assoc', - 'array_udiff_uassoc', 'array_udiff', - 'array_uintersect_assoc', 'array_uintersect_uassoc', - 'array_uintersect', 'array_unique', - 'array_datas', 'count', - 'current', 'each', - 'end', 'extract', - 'in_array', 'key', - 'next', 'prev', - 'sizeof'); - - protected static $_postMethods = array( - 'array_fill', 'array_map', - 'array_search', 'compact', - 'implode'); - - protected static $_referenceMethods = array( - 'array_unshift', 'array_walk_recursive', - 'array_walk', 'arsort', - 'asort', 'krsort', - 'ksort', 'natcasesort', - 'natsort', 'reset', - 'rsort', 'shuffle', - 'sort', 'uasort', - 'uksort', 'usort'); - - /* Private Properties - -------------------------------*/ - /* Get - -------------------------------*/ - public static function get(array $data = array()) { - return self::_getMultiple(__CLASS__, $data); - } - - /* Magic - -------------------------------*/ - public function __construct(array $data = array()) { - parent::__construct($data); - } - - public function __toString() { - return json_encode($this->_data); - } - - public function __get($name) { - if(isset($this->_data[$name])) { - return $this->_data[$name]; - } - - return NULL; - } - - public function __set($name, $value) { - $this->_data[$name] = $value; - } - - /* Public Methods - -------------------------------*/ - /** - * Removes a row in an array and adjusts all the indexes - * - * @param *string the key to leave out - * @param bool is this a value or key value array? - * @return this - */ - public function cut($arrayKey, $isValueArray = true) { - //argument 1 must be a string, argument 2 must be a boolean - Eden_Array_Error::get() - ->argument(1, 'string') - ->argument(2, 'bool'); - - $array = array(); - foreach($this->_data as $key => $value) { - //if the key does not equal - //the key to to leave out - if($arrayKey != $key) { - //we want to add it to the new array - if($isValueArray) { - $array[] = $value; - } else { - $array[$key] = $value; - } - } - } - - $this->_data = $array; - - return $this; - } - - /** - * Inserts a row in an array after the given index and adjusts all the indexes - * - * @param *string the key we are looking for to past after - * @param *mixed the value to paste - * @param string the key to paste along with the value - * @return this - */ - public function paste($afterKey, $arrayValue, $arrayKey = NULL) { - //argument 1 must be a string, argument 3 must be a string or null - Eden_Array_Error::get() - ->argument(1, 'string') - ->argument(3, 'string', 'null'); - - $array = array(); - foreach($this->_data as $key => $value) { - //if the array key is not null - //we know they ment to make this - //array an key value array - if(!is_null($arrayKey)) { - //lets add it - $array[$key] = $value; - //if the current key is the key we - //want to add the new value after - if($afterKey == $key) { - //lets add the new value - $array[$arrayKey] = $arrayValue; - } - } else { - //lets add it - $array[] = $value; - //if the current key is the key we - //want to add the new value after - if($afterKey == $key) { - //lets add the new value - $array[] = $arrayValue; - } - } - } - - $this->_data = $array; - - return $this; - } - - /** - * Converts a multidimensional array with similar rows to an accociate array - * - * @param *array the table to key - * @param *string the name of the key we are looking for - * @return this - */ - public function associateTable($key, $many = false) { - //argument 1 must be a string, argument 2 must be a boolean - Eden_Array_Error::get() - ->argument(1, 'string') - ->argument(2, 'bool'); - - $table = array(); - foreach($this->_data as $i => $row) { - $newKey = isset($row[$key]) ? $row[$key] : $i; - - if($many) { - $table[$newKey][] = $row; - } else { - $table[$newKey] = $row; - } - } - - $this->_data = $table; - - return $this; - } - - /** - * Returns a list of values of a given column - * - * @param *string the key to look for - * @param string the value of the key that - * needs to be returned - * @return mixed - */ - public function getKeyValue($key, $index = NULL) { - //argument 1 must be a string, argument 2 must be a string or null - Eden_Array_Error::get() - ->argument(1, 'string') - ->argument(2, 'string', 'null'); - - $table = $this->associateTable($table, $key); - - if(is_null($index)) { - return Eden_Array::get(array_keys($table)); - } - - return isset($table[$index]) ? $table[$index] : false; - } - - /** - * Sorts a table - * TODO: array_multisort - * - * @param *string sort field - * @param string order - * @param int start - * @param int range - * @return array - */ - public function paginate($field, $order = 'ASC', $start = 0, $range = 0) { - Eden_Array_Error::get() - ->argument(1, 'string') //argument 1 must be a string - ->argument(2, 'string') //argument 2 must be a string - ->argument(3, 'int') //argument 3 must be a number - ->argument(4, 'int'); //argument 4 must be a number - - //do the sorting first - //first lets take the field column - //and put it in a new array - $fields = array(); - foreach($this->_data as $i =>$row) { - $fields[$i] = $row[$field]; - } - - $order = strtoupper($order) == 'ASC' ? SORT_ASC : SORT_DESC; - - array_multisort($fields, $order, SORT_STRING, $this->_data); - - //now do the pagination - $this->_data = array_slice($this->_data, $start, $range); - - return $this; - } - - /** - * Rewinds the position - * For Iterator interface - * - * @return void - */ - public function rewind() { - reset($this->_data); - } - - /** - * Returns the current item - * For Iterator interface - * - * @return void - */ - public function current() { - return current($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); - } - - /** - * Validates whether if the index is set - * For Iterator interface - * - * @return void - */ - public function valid() { - return isset($this->_data[$this->key()]); - } - - /** - * 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; - } - } - - /** - * isset using the ArrayAccess interface - * - * @param number - * @return bool - */ - public function offsetExists($offset) { - return isset($this->_data[$offset]); - } - - /** - * unsets using the ArrayAccess interface - * - * @param number - * @return bool - */ - public function offsetUnset($offset) { - unset($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; - } - - /** - * returns serialized data using the Serializable interface - * - * @return string - */ - public function serialize() { - return json_encode($this->_data); - } - - /** - * sets data using the Serializable interface - * - * @param string - * @return void - */ - public function unserialize($data) { - $this->_data = json_decode($data, true); - return $this; - } - - /** - * returns size using the Countable interface - * - * @return string - */ - public function count() { - return count($this->_data); - } - - /* Protected Methods - -------------------------------*/ - protected function _getPreMethod($name) { - if(in_array($name, self::$_preMethods)) { - return $name; - } - - if(in_array('array_'.$name, self::$_preMethods)) { - return 'array_'.$name; - } - - return false; - } - - protected function _getPostMethod($name) { - if(in_array($name, self::$_postMethods)) { - return $name; - } - - if(in_array('array_'.$name, self::$_postMethods)) { - return 'array_'.$name; - } - - return false; - } - - protected function _getReferenceMethod($name) { - if(in_array($name, self::$_referenceMethods)) { - return $name; - } - - if(in_array('array_'.$name, self::$_referenceMethods)) { - return 'array_'.$name; - } - - return false; - } - - /* Private Methods - -------------------------------*/ -} - -/** - * Array Errors - */ -class Eden_Array_Error extends Eden_Type_Error { - /* Constants - -------------------------------*/ - /* Public Properties - -------------------------------*/ - /* Protected Properties - -------------------------------*/ - /* Private Properties - -------------------------------*/ - /* Get - -------------------------------*/ - public static function get($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/class.php b/library/eden/class.php index 6e7f380..5fd7348 100755 --- a/library/eden/class.php +++ b/library/eden/class.php @@ -10,6 +10,7 @@ require_once dirname(__FILE__).'/error.php'; require_once dirname(__FILE__).'/route.php'; require_once dirname(__FILE__).'/when.php'; +require_once dirname(__FILE__).'/map.php'; /** * The base class for all classes wishing to integrate with Eve. @@ -51,7 +52,6 @@ public function __call($name, $args) { //lets first consider that they may just //want to load a class so lets try try { - //return the class return Eden_Route::get()->getClassArray($name, $args); //only if there's a route exception do we want to catch it @@ -65,7 +65,7 @@ public function __call($name, $args) { //let the router handle this return Eden_Route::get()->callMethod($this, $name, true, $args); } catch(Eden_Route_Error $e) { - throw new Eden_Error($e->getMessage()); + Eden_Error::get($e->getMessage())->trigger(); } } @@ -120,17 +120,27 @@ public function callThisMethod($method, array $args = array()) { } /** - * Invokes Noop if conditional is false + * Invokes When if conditional is false * * @param bool * @return this|Eden_Noop */ - public function when($isTrue) { + public function when($isTrue, $lines) { if($isTrue) { return $this; } - return Eden_When::get($this); + return Eden_When::get($this, $lines); + } + + /** + * Invokes Chain map + * + * @param bool + * @return this|Eden_Noop + */ + public function map(array &$list, $lines = 0) { + return Eden_Map::get($this, $list, $lines); } /** diff --git a/library/eden/collection.php b/library/eden/collection.php new file mode 100644 index 0000000..5e2fc7f --- /dev/null +++ b/library/eden/collection.php @@ -0,0 +1,377 @@ + +/* + * 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. + */ + +/** + * Collection handler complements models for mass updating and handling + * + * @package Eden + * @category collection + * @author Christian Blanquera + * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ + */ +class Eden_Collection extends Eden_Class implements ArrayAccess, Iterator, Serializable, Countable { + /* Constants + -------------------------------*/ + const FIRST = 'first'; + const LAST = 'last'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_list = array(); + protected $_model = 'Eden_Model'; + + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function get(array $data = array()) { + return self::_getMultiple(__CLASS__,$data); + } + + /* Magic + -------------------------------*/ + public function __construct(array $data = array()) { + foreach($data as $row) { + $this->add($row); + } + } + + 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::get(); + //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; + } + + //nothing more, just see what the parent has to say + try { + return parent::__call($name, $args); + } catch(Eden_Error $e) { + Eden_Collection_Error::get($e->getMessage())->trigger(); + } + } + + public function __get($name) { + //get all rows column values + $list = Eden_Model::get(); + + //for each row + foreach($this->_list as $i => $row) { + //ad just the name + $list[] = $row[$name]; + } + + return $list; + } + + 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->getArray()); + } + + /* 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::get()->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; + } + + /** + * Adds a row to the collection + * + * @param string + * @param string + * @return this + */ + public function copy($source, $destination) { + //Argument Test + Eden_Collection_Error::get() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'string'); //Argument 2 must be a string + + //for each row + foreach($this->_list as $row) { + //let the model handle the copying + $row->copy($source, $destination); + } + + return $this; + } + + public function cut($index = self::LAST) { + //Argument 1 must be a string or integer + Eden_Collection_Error::get()->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; + } + + /** + * Returns the row array + * + * @param bool + * @return array + */ + public function getArray($modified = true) { + //Argument 1 must be a boolean + Eden_Collection_Error::get()->argument(1, 'bool'); + + $array = array(); + //for each row + foreach($this->_list as $i => $row) { + //get the array of that (recursive) + $array[$i] = $row->getData($modified); + } + + return $array; + } + + /** + * Rewinds the position + * For Iterator interface + * + * @return void + */ + public function rewind() { + reset($this->_data); + } + + /** + * Returns the current item + * For Iterator interface + * + * @return void + */ + public function current() { + return current($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); + } + + /** + * Validates whether if the index is set + * For Iterator interface + * + * @return void + */ + public function valid() { + return isset($this->_list[key($this->_list)]); + } + + /** + * 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::get()->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; + } + } + + /** + * isset using the ArrayAccess interface + * + * @param number + * @return bool + */ + public function offsetExists($offset) { + return isset($this->_list[$offset]); + } + + /** + * unsets using the ArrayAccess interface + * + * @param number + * @return bool + */ + public function offsetUnset($offset) { + $this->_list = Eden_Model::get($this->_list) + ->cut($offset) + ->getData(); + } + + /** + * returns data using the ArrayAccess interface + * + * @param number + * @return bool + */ + public function offsetGet($offset) { + return isset($this->_list[$offset]) ? $this->_list[$offset] : NULL; + } + + /** + * returns serialized data using the Serializable interface + * + * @return string + */ + public function serialize() { + return $this->__toString(); + } + + /** + * sets data using the Serializable interface + * + * @param string + * @return void + */ + public function unserialize($data) { + $this->_list = json_decode($data, true); + return $this; + } + + /** + * returns size using the Countable interface + * + * @return string + */ + public function count() { + return count($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.'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function get($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/cookie.php b/library/eden/cookie.php index b1715cc..124483e 100755 --- a/library/eden/cookie.php +++ b/library/eden/cookie.php @@ -75,11 +75,7 @@ public function set($key, $data = NULL, $expires = 0, $path = NULL, $domain = NU * @return this */ public function setSecure($key, $data = NULL, $expires = 0, $path = NULL, $domain = NULL) { - try { - return $this->set($key, $data, $expires, $path, $domain, true, false); - } catch(Eden_Cookie_Error $e) { - throw new Eden_Cookie_Error($e->getMessage()); - } + return $this->set($key, $data, $expires, $path, $domain, true, false); } /** @@ -93,11 +89,7 @@ public function setSecure($key, $data = NULL, $expires = 0, $path = NULL, $domai */ public function setData(array $data, $expires = 0, $path = NULL, $domain = NULL, $secure = false, $httponly = false) { foreach($data as $key => $value) { - try { - $this->set($key, $value, $expires, $path, $domain, $secure, $httponly); - } catch(Eden_Cookie_Error $e) { - throw new Eden_Cookie_Error($e->getMessage()); - } + $this->set($key, $value, $expires, $path, $domain, $secure, $httponly); } return $this; @@ -113,12 +105,7 @@ public function setData(array $data, $expires = 0, $path = NULL, $domain = NULL, * @return this */ public function setSecureData(array $data, $expires = 0, $path = NULL, $domain = NULL) { - try { - $this->setData($data, $expires, $path, $domain, true, false); - } catch(Eden_Cookie_Error $e) { - throw new Eden_Cookie_Error($e->getMessage()); - } - + $this->setData($data, $expires, $path, $domain, true, false); return $this; } @@ -231,11 +218,7 @@ public function valid() { * @return void */ public function offsetSet($offset, $value) { - try { - $this->set($offset, $value, strtotime('+10 years')); - } catch(Eden_Error $e) { - throw new Eden_Error($e->getMessage()); - } + $this->set($offset, $value, strtotime('+10 years')); } /** diff --git a/library/eden/error.php b/library/eden/error.php index 0491312..63cd2d0 100755 --- a/library/eden/error.php +++ b/library/eden/error.php @@ -278,6 +278,11 @@ public function trigger() { $this->line = $this->_trace[$this->_offset]['line']; } + if(!empty($this->_variables)) { + $this->message = vsprintf($this->message, $this->_variables); + $this->_variables = array(); + } + throw $this; } @@ -363,6 +368,86 @@ public function argument($index, $types) { ->trigger(); } + /** + * Tests virtual arguments for valid data types + * + * @param *int + * @param *mixed + * @param *string[,string..] + * @return this + */ + public function vargument($method, $args, $index, $types) { + $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) { + $method = 'is_'.$type; + if(function_exists($method) && $method($argument)) { + return $this; + } + + if(class_exists($type) && $argument instanceof $type) { + return $this; + } + + if($type == 'number' && is_numeric($argument)) { + return $this; + } + + if($type == 'int' && is_numeric($argument) + && strpos((string) $argument, '.') === false) { + return $this; + } + + if($type == 'float' && is_numeric($argument) + && strpos((string) $argument, '.') !== false) { + return $this; + } + } + + $method = $trace['class'].'->'.$method; + + $type = 'unknown'; + if(is_string($argument)) { + $type = "'".$argument."'"; + } else if(is_numeric($argument)) { + $type = $argument; + } else if(is_array($argument)) { + $type = 'Array'; + } else if(is_bool($argument)) { + $type = $argument ? 'true' : 'false'; + } else if(is_object($argument)) { + $type = get_class($argument); + } else if(is_null($argument)) { + $type = 'null'; + } + + $this->setMessage(self::INVALID_ARGUMENT) + ->addVariable($index + 1) + ->addVariable($method) + ->addVariable(implode(' or ', $types)) + ->addVariable($type) + ->setTypeLogic() + ->setTraceOffset(1) + ->trigger(); + } + /* Protected Methods -------------------------------*/ /* Private Methods diff --git a/library/eden/error/event.php b/library/eden/error/event.php index ada5f18..d068e65 100755 --- a/library/eden/error/event.php +++ b/library/eden/error/event.php @@ -141,11 +141,6 @@ public function exceptionHandler(Exception $e) { $level = $e->getLevel(); $offset = $e->getTraceOffset(); $reporter = $e->getReporter(); - $variables = $e->getVariables(); - - if(!empty($variables)) { - $message = vsprintf($message, $variables); - } } $this->trigger( diff --git a/library/eden/facebook/graph.php b/library/eden/facebook/graph.php index bc77afe..ffc1593 100644 --- a/library/eden/facebook/graph.php +++ b/library/eden/facebook/graph.php @@ -53,7 +53,10 @@ public function getObject($id = 'me', $connection = NULL, array $query = array() if($auth) { if(!$this->_token) { - throw new Eden_Facebook_Error(sprintf(Eden_Facebook_Error::REQUIRES_AUTH, $url)); + Eden_Facebook_Error::get() + ->setMessage(Eden_Facebook_Error::REQUIRES_AUTH) + ->addVariable($url) + ->trigger(); } $query['access_token'] = $this->_token; @@ -67,10 +70,12 @@ public function getObject($id = 'me', $connection = NULL, array $query = array() $object = json_decode($object, true); if (isset($object['error'])) { - throw new Eden_Facebook_Error(sprintf( - Eden_Facebook_Error::GRAPH_FAILED, - $url, $object['error']['type'], - $object['error']['message'])); + Eden_Facebook_Error::get() + ->setMessage(Eden_Facebook_Error::GRAPH_FAILED) + ->addVariable($url) + ->addVariable($object['error']['type']) + ->addVariable($object['error']['message']) + ->trigger(); } return $object; @@ -194,8 +199,13 @@ public function searchCheckins($query, $fields = NULL) { public function addPost($message, $id = 'me', $link = NULL, $picture = NULL, $video = NULL, $caption = NULL, $linkName = NULL, $linkDescription = NULL) { + $url = self::GRAPH_URL.$id.'/feed'; + if(!$this->_token) { - throw new Eden_Facebook_Error(sprintf(Eden_Facebook_Error::REQUIRES_AUTH, $url)); + Eden_Facebook_Error::get() + ->setMessage(Eden_Facebook_Error::REQUIRES_AUTH) + ->addVariable($url) + ->trigger(); } $post = array('message' => $message); @@ -224,8 +234,6 @@ public function addPost($message, $id = 'me', $link = NULL, $picture = NULL, $post['description'] = $linkDescription; } - $url = self::GRAPH_URL.$id.'/feed'; - $query = array('access_token' => $this->_token); if(!empty($query)) { @@ -237,14 +245,17 @@ public function addPost($message, $id = 'me', $link = NULL, $picture = NULL, } public function addComment($id, $message) { + $url = self::GRAPH_URL.$id.'/comments'; + if(!$this->_token) { - throw new Eden_Facebook_Error(sprintf(Eden_Facebook_Error::REQUIRES_AUTH, $url)); + Eden_Facebook_Error::get() + ->setMessage(Eden_Facebook_Error::REQUIRES_AUTH) + ->addVariable($url) + ->trigger(); } $post = array('message' => $message); - $url = self::GRAPH_URL.$id.'/comments'; - $query = array('access_token' => $this->_token); if(!empty($query)) { @@ -256,12 +267,15 @@ public function addComment($id, $message) { } public function like($id) { + $url = self::GRAPH_URL.$id.'/likes'; + if(!$this->_token) { - throw new Eden_Facebook_Error(sprintf(Eden_Facebook_Error::REQUIRES_AUTH, $url)); + Eden_Facebook_Error::get() + ->setMessage(Eden_Facebook_Error::REQUIRES_AUTH) + ->addVariable($url) + ->trigger(); } - $url = self::GRAPH_URL.$id.'/likes'; - $query = array('access_token' => $this->_token); if(!empty($query)) { @@ -274,14 +288,17 @@ public function like($id) { } public function addNote($id, $subject, $message) { + $url = self::GRAPH_URL.$id.'/notes'; + if(!$this->_token) { - throw new Eden_Facebook_Error(sprintf(Eden_Facebook_Error::REQUIRES_AUTH, $url)); + Eden_Facebook_Error::get() + ->setMessage(Eden_Facebook_Error::REQUIRES_AUTH) + ->addVariable($url) + ->trigger(); } $post = array('subject' => $subject, 'message' => $message); - $url = self::GRAPH_URL.$id.'/notes'; - $query = array('access_token' => $this->_token); if(!empty($query)) { @@ -293,14 +310,17 @@ public function addNote($id, $subject, $message) { } public function addEvent($name, $start, $end) { + $url = self::GRAPH_URL.$id.'/events'; + if(!$this->_token) { - throw new Eden_Facebook_Error(sprintf(Eden_Facebook_Error::REQUIRES_AUTH, $url)); + Eden_Facebook_Error::get() + ->setMessage(Eden_Facebook_Error::REQUIRES_AUTH) + ->addVariable($url) + ->trigger(); } $post = array('name'=>$name,'start_time'=>$start,'end_time'=>$end); - $url = self::GRAPH_URL.$id.'/events'; - $query = array('access_token' => $this->_token); if(!empty($query)) { @@ -312,12 +332,15 @@ public function addEvent($name, $start, $end) { } public function attendEvent($id) { + $url = self::GRAPH_URL.$id.'/attending'; + if(!$this->_token) { - throw new Eden_Facebook_Error(sprintf(Eden_Facebook_Error::REQUIRES_AUTH, $url)); + Eden_Facebook_Error::get() + ->setMessage(Eden_Facebook_Error::REQUIRES_AUTH) + ->addVariable($url) + ->trigger(); } - $url = self::GRAPH_URL.$id.'/attending'; - $query = array('access_token' => $this->_token); if(!empty($query)) { @@ -330,12 +353,15 @@ public function attendEvent($id) { } public function maybeEvent($id) { + $url = self::GRAPH_URL.$id.'/maybe'; + if(!$this->_token) { - throw new Eden_Facebook_Error(sprintf(Eden_Facebook_Error::REQUIRES_AUTH, $url)); + Eden_Facebook_Error::get() + ->setMessage(Eden_Facebook_Error::REQUIRES_AUTH) + ->addVariable($url) + ->trigger(); } - $url = self::GRAPH_URL.$id.'/maybe'; - $query = array('access_token' => $this->_token); if(!empty($query)) { @@ -348,12 +374,15 @@ public function maybeEvent($id) { } public function declineEvent($id) { + $url = self::GRAPH_URL.$id.'/declined'; + if(!$this->_token) { - throw new Eden_Facebook_Error(sprintf(Eden_Facebook_Error::REQUIRES_AUTH, $url)); + Eden_Facebook_Error::get() + ->setMessage(Eden_Facebook_Error::REQUIRES_AUTH) + ->addVariable($url) + ->trigger(); } - $url = self::GRAPH_URL.$id.'/declined'; - $query = array('access_token' => $this->_token); if(!empty($query)) { @@ -366,8 +395,13 @@ public function declineEvent($id) { } public function addLink($id, $url, $message = NULL, $name = NULL, $description = NULL, $picture = NULL, $caption = NULL) { + $url = self::GRAPH_URL.$id.'/links'; + if(!$this->_token) { - throw new Eden_Facebook_Error(sprintf(Eden_Facebook_Error::REQUIRES_AUTH, $url)); + Eden_Facebook_Error::get() + ->setMessage(Eden_Facebook_Error::REQUIRES_AUTH) + ->addVariable($url) + ->trigger(); } $post = array('url' => $url); @@ -392,8 +426,6 @@ public function addLink($id, $url, $message = NULL, $name = NULL, $description = $post['caption'] = $caption; } - $url = self::GRAPH_URL.$id.'/links'; - $query = array('access_token' => $this->_token); if(!empty($query)) { @@ -405,14 +437,17 @@ public function addLink($id, $url, $message = NULL, $name = NULL, $description = } public function addAlbum($id, $name, $message) { + $url = self::GRAPH_URL.$id.'/albums'; + if(!$this->_token) { - throw new Eden_Facebook_Error(sprintf(Eden_Facebook_Error::REQUIRES_AUTH, $url)); + Eden_Facebook_Error::get() + ->setMessage(Eden_Facebook_Error::REQUIRES_AUTH) + ->addVariable($url) + ->trigger(); } $post = array('name'=>$name,'message'=>$message); - $url = self::GRAPH_URL.$id.'/albums'; - $query = array('access_token' => $this->_token); if(!empty($query)) { @@ -426,8 +461,13 @@ public function addAlbum($id, $name, $message) { public function addPhoto($id, $data) {} public function addCheckin($id, $message, $coordinates, $place, $tags) { + $url = self::GRAPH_URL.$id.'/checkins'; + if(!$this->_token) { - throw new Eden_Facebook_Error(sprintf(Eden_Facebook_Error::REQUIRES_AUTH, $url)); + Eden_Facebook_Error::get() + ->setMessage(Eden_Facebook_Error::REQUIRES_AUTH) + ->addVariable($url) + ->trigger(); } $post = array('message' => $message); @@ -448,8 +488,6 @@ public function addCheckin($id, $message, $coordinates, $place, $tags) { $post['tags'] = $tags; } - $url = self::GRAPH_URL.$id.'/checkins'; - $query = array('access_token' => $this->_token); if(!empty($query)) { @@ -474,10 +512,9 @@ protected function _call($url, array $post = array()) { ->verifyPeer(false) ->setUserAgent(Eden_Facebook_Auth::USER_AGENT) ->setHeaders('Expect') - ->when(!empty($post)) + ->when(!empty($post), 2) ->setPost(true) ->setPostFields(http_build_query($post)) - ->endWhen() ->getResponse(); } diff --git a/library/eden/folder.php b/library/eden/folder.php index 960c350..69fa58a 100644 --- a/library/eden/folder.php +++ b/library/eden/folder.php @@ -48,7 +48,7 @@ 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 - throw new Eden_Folder_Error(Eden_Folder_Exception::CHMOD_IS_INVALID); + Eden_Folder_Error::get(Eden_Folder_Exception::CHMOD_IS_INVALID)->trigger(); } //if it's not a directory diff --git a/library/eden/image.php b/library/eden/image.php index 549f5aa..91f7f66 100644 --- a/library/eden/image.php +++ b/library/eden/image.php @@ -643,7 +643,7 @@ protected function _getResource($data, $path) { //if the GD Library is not installed if(!function_exists('gd_info')) { //throw error - throw new Eden_Image_Error(Eden_Image_Error::GD_NOT_INSTALLED); + Eden_Image_Error::get(Eden_Image_Error::GD_NOT_INSTALLED)->trigger(); } # imagecreatefromgd — Create a new image from GD file or URL diff --git a/library/eden/map.php b/library/eden/map.php new file mode 100644 index 0000000..01c1e49 --- /dev/null +++ b/library/eden/map.php @@ -0,0 +1,82 @@ + +/* + * 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__).'/class.php'; + +/** + * Trigger when something is false + * + * @package Eden + * @category core + * @author Christian Blanquera + * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ + */ +class Eden_Map extends Eden_Class { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_scope = NULL; + protected $_increment = 1; + protected $_lines = 0; + protected $_list = array(); + protected $_map = array(); + + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function get($scope, array &$list, $lines = 0) { + return self::_getMultiple(__CLASS__, $scope, $list, $lines); + } + + /* Magic + -------------------------------*/ + public function __construct($scope, array &$list, $lines = 0) { + $this->_scope = $scope; + $this->_list = &$list; + $this->_lines = $lines; + } + + public function __call($name, $args) { + if($this->_lines > 0 && $this->_increment == $this->_lines) { + $this->_map[] = array($name, $args); + return $this->endMap(); + } + + $this->_increment++; + $this->_map[] = array($name, $args); + return $this; + } + + /* Public Methods + -------------------------------*/ + /** + * Returns the original class + * Eden_Sesison()->map($products)->setData('name', 'chris'); + * @param bool + * @return this|Eden_Noop + */ + public function endMap() { + foreach($this->_list as $key => $object) { + foreach($this->_map as $action) { + $this->_list[$key] = Eden_Route::get()->callMethod($object, $action[0], NULL, $action[1]); + } + } + + return $this->_scope; + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/model.php b/library/eden/model.php index 3afed41..ab9ef94 100755 --- a/library/eden/model.php +++ b/library/eden/model.php @@ -7,7 +7,7 @@ * distributed with this package. */ -require_once dirname(__FILE__).'/array.php'; +require_once dirname(__FILE__).'/type.php'; /** * @@ -16,182 +16,31 @@ * @author Christian Blanquera * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ */ -class Eden_Model extends Eden_Array { +class Eden_Model extends Eden_Type_Array { /* Constants -------------------------------*/ /* Public Properties -------------------------------*/ /* Protected Properties -------------------------------*/ - protected $_meta = array(); - /* Private Properties -------------------------------*/ /* Get -------------------------------*/ - public static function get(array $data = array()) { + public static function get() { return self::_getMultiple(__CLASS__); } /* Magic -------------------------------*/ - public function __call($name, $args) { - //if the method starts with get - if(strpos($name, 'get') === 0) { - $key = preg_replace("/([A-Z])/", "_$1", $name); - //get rid of get_ - $key = strtolower(substr($key, 4)); - - if(isset($this->_meta[$key])) { - return $this->_data[$key]; - } - } else if (strpos($name, 'set') === 0) { - $key = preg_replace("/([A-Z])/", "_$1", $name); - //get rid of get_ - $key = strtolower(substr($key, 4)); - - return $this->__set($key, $args[0]); - } - - try { - return parent::__call($name, $args); - } catch(Eden_Type_Error $e) { - throw new Eden_Model_Error($e->getMessage()); - } - } - - public function __get($name) { - if(isset($this->_data[$name])) { - return $this->_data[$name]; - } - - return NULL; - } - - public function __set($name, $value) { - if(isset($this->_meta[$name])) { - $this->_data[$name] = $value; - return $this; - } - - //throw an error - Eden_Model_Error::get() - ->setMessage(Eden_Model_Error::SET_INVALID) - ->addVariable($name)->trigger(); - } - /* Public Methods -------------------------------*/ - /** - * Loads data into the model - * - * @param array - * @return this - */ - public function load(array $data) { - //for each data - foreach($data as $name => $value) { - //if this is not set in the meta data - if(!isset($this->_meta[$name])) { - //throw an error - Eden_Model_Error::get() - ->setMessage(Eden_Model_Error::SET_INVALID) - ->addVariable($name)->trigger(); - } - - $this->_data[$name] = $value; - } - - return $this; - } - - /** - * Sets meta data about the given property - * - * @param string - * @param array - * @return this - */ - public function setMetaData($name, $meta = array(), $value = NULL) { - //argument test - Eden_Model_Error::get() - ->argument(1, 'string') //argument 1 must be a string - ->argument(2, 'string', 'array') //argument 2 must be a string or array - ->argument(3, 'string', 'null'); //argument 3 must be a string or null - - if(is_array($meta)) { - $this->_meta[$name] = $meta; - return $this; - } - - $this->_meta[$name][$meta] = $value; - - return $this; - } - - /** - * Returns meta data - * - * @param string - * @param string - * @return array - */ - public function getMetaData($name = NULL, $key = NULL) { - //argument test - Eden_Model_Error::get() - ->argument(1, 'string', 'null') //argument 1 must be a string or null - ->argument(2, 'string', 'null'); //argument 2 must be a string or null - - if(!is_null($name) && isset($this->_meta[$name])) { - if(!is_null($key) && isset($this->_meta[$name][$key])) { - return $this->_meta[$name][$key]; - } - return $this->_meta[$name]; - } - - return $this->_meta; - } - - /** - * Sets data using the ArrayAccess interface - * We overloaded this to not allow creating new - * columns. - * - * @param number - * @param mixed - * @return void - */ - public function offsetSet($offset, $value) { - //if this is not set in the meta data - if(!isset($this->_meta[$offset])) { - //throw an error - Eden_Model_Error::get() - ->setMessage(Eden_Model_Error::SET_INVALID) - ->addVariable($offset)->trigger(); - } - - $this->_data[$offset] = $value; - } - - /** - * unsets using the ArrayAccess interface - * We overloaded this because an attributes - * must never be removed. Instead we set it to - * null. - * - * @param number - * @return void - */ - public function offsetUnset($offset) { - //if it is set in the meta - if(isset($this->_meta[$offset])) { - //set it to null - $this->_data[$offset] = NULL; - } - } - /* Protected Methods -------------------------------*/ + protected function _getMethodType(&$name) { + return false; + } + /* Private Methods -------------------------------*/ } @@ -202,8 +51,6 @@ public function offsetUnset($offset) { class Eden_Model_Error extends Eden_Error { /* Constants -------------------------------*/ - const SET_INVALID = 'Setting %s refused. You need to set it first using setMetaData().'; - /* Public Properties -------------------------------*/ /* Protected Properties diff --git a/library/eden/mysql.php b/library/eden/mysql.php index 484cda1..94800ba 100755 --- a/library/eden/mysql.php +++ b/library/eden/mysql.php @@ -20,6 +20,9 @@ require_once dirname(__FILE__).'/mysql/create.php'; require_once dirname(__FILE__).'/mysql/subselect.php'; require_once dirname(__FILE__).'/mysql/utility.php'; +require_once dirname(__FILE__).'/mysql/collection.php'; +require_once dirname(__FILE__).'/mysql/model.php'; +require_once dirname(__FILE__).'/mysql/search.php'; /** * Abstractly defines a layout of available methods to @@ -36,6 +39,9 @@ class Eden_Mysql extends Eden_Sql_Database { /* Constants -------------------------------*/ + const FIRST = 'first'; + const LAST = 'last'; + /* Public Properties -------------------------------*/ /* Protected Properties @@ -113,8 +119,24 @@ public function getConnection() { * * @return array the queries */ - public function getQueries() { - return $this->_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; } /** @@ -126,6 +148,32 @@ public function getLastInsertedId() { return $this->getConnection()->lastInsertId(); } + /** + * Returns search + * + * @return Eden_Mysql_Search + */ + public function search() { + return Eden_Mysql_Search::get($this); + } + + /** + * Returns model + * + * @return Eden_Mysql_Model + */ + public function model(array $data = array()) { + return Eden_Mysql_Model::get($data)->setDatabase($this); + } + + /** + * Returns collection + * + * @return Eden_Mysql_Collection + */ + public function collection(array $data = array()) { + return Eden_Mysql_Collection::get($data)->setDatabase($this); + } /** * Returns the alter query builder @@ -261,23 +309,87 @@ public function getRows($table, array $joins = array(), $filters = NULL, $results = $this->query($query, $this->getBinds()); - if($index == 'first' && count($results) > 0) { - return $results[0]; + 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; + } + } } - else if($index == 'last' && count($results) > 0) { - return array_pop($results); + $this->trigger($table, $joins, $filters, $sort, $start, $range, $index, $results); + + return $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_Mysql_Error::get() + ->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); + + if(is_null($result)) { + return NULL; } - else if(is_numeric($index)) { - if(isset($results[$index])) { - return $results[$index]; - } + return Eden_Mysql_Model::get($result)->setDatabase($this)->setTable($table); + } + + /** + * 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_Mysql_Error::get() + ->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); + + if(is_null($results)) { + return NULL; } - $this->trigger($table, $joins, $filters, $sort, $start, $range, $index, $results); + if(!is_null($index)) { + return Eden_Mysql_Model::get($results); + } - return $results; + return Eden_Mysql_Collection::get($results)->setDatabase($this)->setTable($table); } /** @@ -344,6 +456,11 @@ public function insertRow($table, array $setting, $bind = true) { $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); } @@ -374,6 +491,11 @@ public function insertRows($table, array $settings, $bind = true) { 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); } @@ -405,6 +527,11 @@ public function updateRows($table, array $setting, $filters = NULL, $bind = true $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); } @@ -682,10 +809,10 @@ public function query($query, array $binds = array()) { $results = $stmt->fetchAll( PDO::FETCH_ASSOC ); - $this->queries[] = array( - 'query' => $query, - 'binds' => $binds, - 'results' => $results); + $this->_queries[] = array( + 'query' => $query, + 'binds' => $binds, + 'results' => $results); $this->_binds = array(); diff --git a/library/eden/mysql/collection.php b/library/eden/mysql/collection.php new file mode 100644 index 0000000..efe194c --- /dev/null +++ b/library/eden/mysql/collection.php @@ -0,0 +1,126 @@ + +/* + * 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. + */ + +/** + * Mysql Collection handler + * + * @package Eden + * @category mysql + * @author Christian Blanquera + * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ + */ +class Eden_Mysql_Collection extends Eden_Collection { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_model = 'Eden_Mysql_Model'; + + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function get(array $data = array()) { + return self::_getMultiple(__CLASS__,$data); + } + + /* Magic + -------------------------------*/ + /* Public Methods + -------------------------------*/ + /** + * Sets the default database + * + * @param Eden_Mysql + */ + public function setDatabase(Eden_Mysql $database) { + //for each row + foreach($this->_list as $row) { + //let the row handle this + $row->setDatabase($database); + } + + return $this; + } + + /** + * Sets the default database + * + * @param string + */ + public function setTable($table) { + //Argument 1 must be a string + Eden_Mysql_Error::get()->argument(1, 'string'); + + //for each row + foreach($this->_list as $row) { + //let the row handle this + $row->setTable($table); + } + + return $this; + } + + /** + * Useful method for formating a time column. + * + * @param string + * @param string + * @return this + */ + public function formatTime($column, $format = self::DATETIME) { + //for each row + foreach($this->_list as $row) { + //let the row handle this + $row->formatTime($column, $format); + } + + return $this; + } + + /** + * Inserts or updates collection to database + * + * @param string + * @param Eden_Mysql + * @return this + */ + public function save($table = NULL, Eden_Mysql $database = NULL) { + //for each row + foreach($this->_list as $i => $row) { + $row->save($table, $database); + } + + return $this; + } + + /** + * Removes collection from database + * + * @param string + * @param Eden_Mysql + * @return this + */ + public function remove($table = NULL, Eden_Mysql $database = NULL) { + //for each row + foreach($this->_list as $i => $row) { + //let the row handle this + $row->remove($table, $database); + } + + 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 index 0377ab8..8ec53f1 100755 --- a/library/eden/mysql/error.php +++ b/library/eden/mysql/error.php @@ -18,8 +18,10 @@ class Eden_Mysql_Error extends Eden_Error { /* Constants -------------------------------*/ - const QUERY_ERROR = '%s Query: %s'; - const SET_INVALID = 'No column %s exists in table %s.'; + const QUERY_ERROR = '%s Query: %s'; + const SET_INVALID = 'No column %s exists in table %s.'; + const TABLE_NOT_SET = 'No default table set or was passed.'; + const DATABASE_NOT_SET = 'No default database set or was passed.'; /* Public Properties -------------------------------*/ diff --git a/library/eden/mysql/model.php b/library/eden/mysql/model.php index f6c6051..5345d38 100644 --- a/library/eden/mysql/model.php +++ b/library/eden/mysql/model.php @@ -8,104 +8,308 @@ */ /** + * Mysql Model * * @package Eden - * @category registry + * @category mysql * @author Christian Blanquera * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ */ -class Eden_Mysql_Model extends Eden_Mysql_Model_Abstract { +class Eden_Mysql_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 $_primary = NULL; - protected $_meta = array(); - protected $_data = array(); - - protected $_database = NULL; protected $_table = NULL; + protected $_database = NULL; + + protected static $_meta = array(); /* Private Properties -------------------------------*/ /* Get -------------------------------*/ - public static function get(Eden_Mysql $database, $table) { - return self::_getMultiple(__CLASS__, $database, $table); + public static function get() { + $data = self::_getStart(func_get_args()); + return self::_getMultiple(__CLASS__, $data); } /* Magic -------------------------------*/ - public function __construct($database, $table) { - $this->_database = $database; - $this->_table = $table; - - //set meta data - $this->_setMetaData(); - } - /* Public Methods -------------------------------*/ /** - * Loads data into the model + * Sets the default database + * + * @param Eden_Mysql + */ + public function setDatabase(Eden_Mysql $database) { + $this->_database = $database; + return $this; + } + + /** + * Sets the default database * - * @param array + * @param string + */ + public function setTable($table) { + //Argument 1 must be a string + Eden_Mysql_Error::get()->argument(1, 'string'); + + $this->_table = $table; + return $this; + } + + /** + * Useful method for formating a time column. + * + * @param string + * @param string * @return this */ - public function load($data, $column = NULL) { + public function formatTime($column, $format = self::DATETIME) { + //Argument Test Eden_Mysql_Error::get() - ->argument(1, 'numeric', 'array', 'string') - ->argument(2, 'string', 'null'); + ->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 or updates model to database + * + * @param string + * @param Eden_Mysql + * @return this + */ + public function save($table = NULL, Eden_Mysql $database = NULL) { + //Argument 1 must be a string + $error = Eden_Mysql_Error::get()->argument(1, 'string', 'null'); - if(is_scalar($data)) { - if(!is_string($column)) { - $column = $this->_primary; + //if no table + if(is_null($table)) { + //if no default table either + if(!$this->_table) { + //throw error + $error->setMessage(Eden_Mysql_Error::TABLE_NOT_SET)->trigger(); } - $this->_data = $this->_database->getRow($this->_table, $column, $data); + $table = $this->_table; + } + + //if no database + if(is_null($database)) { + //and no default database + if(!$this->_database) { + $error->setMessage(Eden_Mysql_Error::DATABASE_NOT_SET)->trigger(); + } - return $this; + $database = $this->_database; } - //for each data - foreach($data as $name => $value) { - //if this is not set in the meta data - if(!isset($this->_meta[$name])) { - //throw an error - Eden_Mysql_Error::get() - ->setMessage(Eden_Mysql_Error::SET_INVALID) - ->addVariable($name) - ->addVariable($this->_table) - ->trigger(); + //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])); + $primarySet = $this->_isPrimarySet($meta[self::PRIMARY]); + + //update original data + $this->_original = $this->_data; + + //if no primary meta or primary values are not set + if(empty($meta[self::PRIMARY]) || !$primarySet) { + //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(); } - $this->_data[$name] = $value; + return $this; } + //from here it means that this table has primary + //columns and all primary values are set + + $filter = array(); + //for each primary key + foreach($meta[self::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; } /** - * Inserts or updates model to database + * Removes model from database * + * @param string + * @param Eden_Mysql * @return this */ - public function save() { - if(isset($this->_data[$this->_primary])) { - $this->_database->updateRows($this->_table, - $this->_data, $this->_primary.'='.$this->_data[$this->_primary]); - } else { - $this->_database->insertRow($this->_table, $this->_data); - $this->_data[$this->_primary] = $this->_database->getLastInsertedId(); + public function remove($table = NULL, Eden_Mysql $database = NULL) { + //Argument 1 must be a string + $error = Eden_Mysql_Error::get()->argument(1, 'string', 'null'); + + //if no table + if(is_null($table)) { + //if no default table either + if(!$this->_table) { + //throw error + $error->setMessage(Eden_Mysql_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_Mysql_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])); + + $filter = array(); + //for each primary key + foreach($meta[self::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; } /* Protected Methods -------------------------------*/ + protected function _isPrimarySet(array $primary) { + foreach($primary as $column) { + if(is_null($this[$column])) { + return false; + } + } + + return true; + } + + protected function _getValidColumns($columns) { + $valid = array(); + foreach($columns as $column) { + if(!isset($this->_data[$column])) { + continue; + } + + $valid[$column] = $this->_data[$column]; + } + + return $valid; + } + + 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 _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]); + } + /* Private Methods -------------------------------*/ } diff --git a/library/eden/mysql/model/abstract.php b/library/eden/mysql/model/abstract.php deleted file mode 100644 index 96211e9..0000000 --- a/library/eden/mysql/model/abstract.php +++ /dev/null @@ -1,302 +0,0 @@ - -/* - * 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. - */ - -/** - * - * @package Eden - * @category registry - * @author Christian Blanquera - * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ - */ -abstract class Eden_Mysql_Model_Abstract extends Eden_Class implements ArrayAccess, Iterator { - /* Constants - -------------------------------*/ - /* Public Properties - -------------------------------*/ - /* Protected Properties - -------------------------------*/ - protected $_primary = NULL; - protected $_meta = array(); - protected $_data = array(); - protected $_join = array(); - - protected $_database = NULL; - protected $_table = NULL; - - protected static $_cache = array(); - - /* Private Properties - -------------------------------*/ - /* Get - -------------------------------*/ - /* Magic - -------------------------------*/ - public function __call($name, $args) { - //if the method starts with get - if(strpos($name, 'get') === 0) { - $key = preg_replace("/([A-Z])/", "_$1", $name); - //get rid of get_ - $key = strtolower(substr($key, 4)); - - //if it's a data key - if(isset($this->_meta[$key])) { - return $this->_data[$key]; - } - } else if (strpos($name, 'set') === 0) { - $key = preg_replace("/([A-Z])/", "_$1", $name); - //get rid of get_ - $key = strtolower(substr($key, 4)); - - return $this->__set($key, $args[0]); - } - - try { - return parent::__call($name, $args); - } catch(Eden_Type_Error $e) { - throw new Eden_Mysql_Error($e->getMessage()); - } - } - - public function __get($name) { - if(isset($this->_data[$name])) { - return $this->_data[$name]; - } - - return NULL; - } - - public function __set($name, $value) { - if(isset($this->_meta[$name])) { - $this->_data[$name] = $value; - return $this; - } - - //throw an error - Eden_Mysql_Error::get() - ->setMessage(Eden_Mysql_Error::SET_INVALID) - ->addVariable($name) - ->addVariable($this->_table) - ->trigger(); - } - - public function __toString() { - return json_encode($this->_data); - } - - /* Public Methods - -------------------------------*/ - abstract public function save(); - - /** - * Get the primary key name or value - * - * @param bool - * @return string|number - */ - public function getPrimary($value = false) { - //argument 1 must be a string or null - Eden_Mysql_Error::get()->argument(1, 'bool'); - - if($value) { - return $this[$this->_primary]; - } - - return $this->_primary; - } - - /** - * Returns an array version of the model - * - * @return array - */ - public function getData() { - $data = $this->_data; - foreach($this->_meta as $name => $meta) { - if(!isset($data[$name])) { - $data[$name] = NULL; - } - } - - return $data; - } - - /** - * Returns the table name - * - * @return string - */ - public function getTable() { - return $this->_table; - } - - /** - * Returns meta data - * - * @param string - * @param string - * @return array - */ - public function getMetaData($name = NULL, $key = NULL) { - //argument test - Eden_Mysql_Error::get() - ->argument(1, 'string', 'null') //argument 1 must be a string or null - ->argument(2, 'string', 'null'); //argument 2 must be a string or null - - if(!is_null($name) && isset($this->_meta[$name])) { - if(!is_null($key) && isset($this->_meta[$name][$key])) { - return $this->_meta[$name][$key]; - } - return $this->_meta[$name]; - } - - return $this->_meta; - } - - /** - * Sets data using the ArrayAccess interface - * We overloaded this to not allow creating new - * columns. - * - * @param number - * @param mixed - * @return void - */ - public function offsetSet($offset, $value) { - //if this is not set in the meta data - if(!isset($this->_meta[$offset])) { - //throw an error - Eden_Mysql_Error::get() - ->setMessage(Eden_Mysql_Error::SET_INVALID) - ->addVariable($offset) - ->addVariable($this->_table) - ->trigger(); - } - - $this->__set($offset, $value); - } - - /** - * unsets using the ArrayAccess interface - * We overloaded this because an attributes - * must never be removed. Instead we set it to - * null. - * - * @param number - * @return void - */ - public function offsetUnset($offset) { - //if it is set in the meta - if(isset($this->_meta[$offset])) { - //set it to null - $this->__set($offset, NULL); - } - } - - /** - * Rewinds the position - * For Iterator interface - * - * @return void - */ - public function rewind() { - reset($this->_data); - } - - /** - * Returns the current item - * For Iterator interface - * - * @return void - */ - public function current() { - return current($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); - } - - /** - * Validates whether if the index is set - * For Iterator interface - * - * @return void - */ - public function valid() { - return isset($this->_data[$this->key()]); - } - - /** - * 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; - } - - /* Protected Methods - -------------------------------*/ - protected function _setMetaData() { - if(isset(self::$_cache[$this->_table])) { - $this->_meta = self::$_cache[$this->_table]['meta']; - $this->_primary = self::$_cache[$this->_table]['primary']; - return $this; - } - - $columns = $this->_database->getColumns($this->_table); - - foreach($columns as $column) { - $this->_meta[$column['Field']] = array( - 'type' => $column['Type'], - 'key' => $column['Key'], - 'default' => $column['Default'], - 'empty' => $column['Null'] == 'YES'); - - if($column['Key'] == 'PRI') { - $this->_primary = $column['Field']; - } - } - - self::$_cache[$this->_table]['meta'] = $this->_meta; - self::$_cache[$this->_table]['primary'] = $this->_primary; - return $this; - } - - /* Private Methods - -------------------------------*/ -} - diff --git a/library/eden/mysql/search.php b/library/eden/mysql/search.php new file mode 100644 index 0000000..7df19dd --- /dev/null +++ b/library/eden/mysql/search.php @@ -0,0 +1,503 @@ + +/* + * 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. + */ + +/** + * Mysql Collection handler + * + * @package Eden + * @category mysql + * @author Christian Blanquera + * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ + */ +class Eden_Mysql_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 $_join = array(); + protected $_filter = array(); + protected $_sort = array(); + protected $_group = array(); + protected $_start = 0; + protected $_range = 0; + + protected $_collection = 'Eden_Mysql_Collection'; + + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function get(Eden_Mysql $database) { + return self::_getMultiple(__CLASS__,$database); + } + + /* Magic + -------------------------------*/ + public function __construct(Eden_Mysql $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::get($name) + ->substr(8) + ->preg_replace("/([A-Z0-9])/", $separator."$1") + ->substr(strlen($separator)) + ->strtolower() + ->getData(); + + if(!isset($args[0])) { + $args[0] = NULL; + } + + $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::get($name) + ->substr(6) + ->preg_replace("/([A-Z0-9])/", $separator."$1") + ->substr(strlen($separator)) + ->strtolower() + ->getData(); + + 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_Mysql_Error::get($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_Mysql_Error::get()->argument(1, 'string'); + $this->_table = $table; + return $this; + } + + /** + * Adds Inner Join On + * + * @param string + * @param string[,string..] + * @return this + */ + public function addInnerJoinOn($table, $where) { + Eden_Mysql_Error::get() + ->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_Mysql_Error::get() + ->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_Mysql_Error::get() + ->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_Mysql_Error::get() + ->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 Right Join On + * + * @param string + * @param string[,string..] + * @return this + */ + public function addRightJoinOn($table, $where) { + Eden_Mysql_Error::get() + ->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_Mysql_Error::get() + ->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 Outer Join On + * + * @param string + * @param string[,string..] + * @return this + */ + public function addOuterJoinOn($table, $where) { + Eden_Mysql_Error::get() + ->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_Mysql_Error::get() + ->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 filter + * + * @param string + * @param string[,string..] + * @return this + */ + public function addFilter() { + Eden_Mysql_Error::get()->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_Mysql_Error::get() + ->argument(1, 'string') + ->argument(2, 'string'); + + if($order != self::DESC) { + $order = self::ASC; + } + + $this->_sort[$column] = $order; + + 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_Mysql_Error::get()->argument(1, 'string', 'array'); + + if(is_string($group)) { + $group = array($group); + } + + $this->_group = $group; + return $this; + } + + /** + * Sets the pagination start + * + * @param int + * @return this + */ + public function setStart($start) { + Eden_Mysql_Error::get()->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_Mysql_Error::get()->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_Mysql_Error::get()->argument(1, 'int'); + + if($page < 1) { + $page = 1; + } + + $this->_start = ($page - 1) * $this->_range; + + return $this; + } + + /** + * Returns the results in a collection + * + * @return Eden_Mysql_Collection + */ + public function getCollection() { + $collection = $this->_collection; + return $this->$collection($this->getRows()) + ->setDatabase($this->_database) + ->setTable($this->_table); + } + + /** + * Returns the array rows + * + * @return array + */ + public function getRows() { + $database = $this->_database; + + $query = $this->_getQuery($database); + + 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 $database->query($query, $database->getBinds()); + } + + /** + * Returns the total results + * + * @return int + */ + public function getTotal() { + $database = $this->_database; + $query = $this->_getQuery($database)->select('COUNT(*) as total'); + + $rows = $database->query($query, $database->getBinds()); + + return $rows[0]['total']; + } + + /* Protected Methods + -------------------------------*/ + protected function _getQuery($database) { + $query = $database->select()->from($this->_table); + + foreach($this->_join as $join) { + + $where = array_shift($join[2]); + if(!empty($join[2])) { + foreach($join[2] as $i => $value) { + $join[2][$i] = $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] = $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/mysql/utility.php b/library/eden/mysql/utility.php index fb6486d..defe83c 100755 --- a/library/eden/mysql/utility.php +++ b/library/eden/mysql/utility.php @@ -45,11 +45,7 @@ public static function get() { * @return this */ public function showTables($like = NULL) { - //if like is not null a string - if(!is_null($like) && !is_string($like)) { - //throw error - throw new Eden_Database_Utility_Exception(sprintf(Eden_Exception::NOT_STRING_NULL, 1)); - } + Eden_Mysql_Error::get()->argument(1, 'string', 'null'); $like = $like ? ' LIKE '.$like : NULL; $this->_query = 'SHOW TABLES'.$like; @@ -71,6 +67,20 @@ public function showColumns($table, $where = NULL) { 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::get()->argument(1, 'string'); + + $this->_query = 'TRUNCATE `' . $table .'`'; + return $this; + } + /** * Query for dropping a table * diff --git a/library/eden/registry.php b/library/eden/registry.php index 841a9fd..b9b8059 100755 --- a/library/eden/registry.php +++ b/library/eden/registry.php @@ -7,7 +7,7 @@ * distributed with this package. */ -require_once dirname(__FILE__).'/array.php'; +require_once dirname(__FILE__).'/type.php'; /** * This class allows the reference of a global registry. This @@ -22,20 +22,26 @@ * @author Christian Blanquera * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ */ -class Eden_Registry extends Eden_Array { +class Eden_Registry extends Eden_Type_Array { /* Constants -------------------------------*/ /* Public Properties -------------------------------*/ /* Protected Properties -------------------------------*/ - protected $_data = array(); //data registry - /* Private Properties -------------------------------*/ /* Get -------------------------------*/ - public static function get(array $data = array()) { + public static function get() { + $data = self::_getStart(func_get_args()); + + foreach($data as $key => $value) { + if(is_array($value)) { + $data[$key] = self::get($value); + } + } + return self::_getMultiple(__CLASS__, $data); } @@ -46,256 +52,152 @@ public static function get(array $data = array()) { /** * Gets a value given the path in the registry. * - * @return variable + * @return mixed */ - public function getData() { - //get the arguments + public function getData($modified = true) { $args = func_get_args(); - //what object are we looking into? - //if the first argument is not an object - //use global registry - $data = $this->_data; - if(isset($args[0]) && (is_array($args[0]) || is_object($args[0]))) { - $data = array_shift($args); + + if(count($args) == 0) { + return $this; } - //set the remaining length - $length = count($args); + $key = array_shift($args); - if($length > 0) { - $result = NULL; - - //foreach argument - foreach($args as $key => $value) { - if(!is_string($value) && !is_numeric($value)) { - return $value; - } - - //this is the last item - if(($key+1) == $length) { - //assign it to result - //exit loop - try { - $result = NULL; - if(is_array($data) && isset($data[$value])) { - $result = $data[$value]; - } else if(is_object($data) && isset($data->{$value})) { - $result = $data->{$value}; - } - } catch(Exception $e) { - $result = NULL; - } - break; - } - - //the name does not exist - if(is_array($data) && !isset($data[$value])) { - //assign result to null - //exit loop - $result = NULL; - break; - } else if(is_object($data) && !isset($data->{$value})) { - //assign result to null - //exit loop - $result = NULL; - break; - } - - //walk the object - $data = is_array($data) ? $data[$value] : $data->{$value}; + if($key === false) { + if(count($args) == 0) { + return $this->getArray(); } - return $result; + + $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); } - //if no arguments - //return the whole object - return $data; + return NULL; } /** * Creates the name space given the space * and sets the value to that name space * - * @return Eden_RegistryModel - **/ + * @return Eden_Registry + */ public function setData() { - //get the arguments $args = func_get_args(); - //what object are we looking into? - //if the first argument is not an object - //use Eve's registry - $data = &$this->_data; - if(is_array($args[0]) || is_object($args[0])) { - $data = &array_shift($args); + + if(count($args) < 2) { + return $this; } - //set the remaining length - $length = count($args); + $key = array_shift($args); - if($length > 0) { - $last = NULL; - $index = NULL; - - //foreach argument - foreach($args as $key => $value) { - - //this is the last item - if(($key+1) == $length) { - //set it to the value - //exit loop - if(is_array($last)) { - $last[$index] = $value; - } else if(is_object($last)) { - $last->{$index} = $value; - } - - break; - } - - if(!is_string($value) && !is_numeric($value)) { - //set it to the value - //exit loop - if(is_array($last)) { - $last[$index] = $value; - } else if(is_object($last)) { - $last->{$index} = $value; - } - } - - //the name does not exist - if(is_array($data) && !isset($data[$value])) { - //create the namespace - $data[$value] = array(); - } else if(is_object($data) && !isset($data->{$value})) { - //create the namespace - $data->{$value} = new stdClass(); - } - - //walk the object - $last = &$data; - $index = $value; - if(is_array($data)) { - $data = &$data[$value]; - } else { - $data = &$data->{$value}; - } + if(count($args) == 1) { + if(is_array($args[0])) { + $args[0] = self::get($args[0]); } + + $this->_data[$key] = $args[0]; + + return $this; + } + + if(!isset($this->_data[$key]) || !($this->_data[$key] instanceof Eden_Registry)) { + $this->_data[$key] = self::get(); } + call_user_func_array(array($this->_data[$key], __FUNCTION__), $args); + return $this; } /** - * Unset a name space - * - * @return Eden_RegistryModel - **/ - public function unsetData() { - //get the arguments + * Checks to see if a key is set + * + * @return bool + */ + public function isKey() { $args = func_get_args(); - //what object are we looking into? - //if the first argument is not an object - //use Eve's registry - $data = &$this->_data; - if(is_array($args[0]) || is_object($args[0])) { - $data = &array_shift($args); + if(count($args) == 0) { + return $this; } - //set the remaining length - $length = count($args); + $key = array_shift($args); - if($length > 0) { - //foreach argument - foreach($args as $key => $value) { - if(!is_string($value) && !is_numeric($value)) { - //delete it - //exit loop - if(is_array($data)) - { - unset($data[$value]); - } else if(is_object($data)) { - unset($data->{$value}); - } - - return $this; - } - - //this is the last item - if(($key+1) == $length) { - //delete it - //exit loop - if(is_array($data)) - { - unset($data[$value]); - } else if(is_object($data)) { - unset($data->{$value}); - } - - return $this; - } - - //walk the object - if(is_array($data)) { - $data = &$data[$value]; - } else { - $data = &$data->{$value}; - } - } + if(!isset($this->_data[$key])) { + return false; } - return $this; + 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; } /** - * Checks to see if a name is taken - * - * @return bool - **/ - public function issetData() { - //get the arguments + * Removes a key and everything associated with it + * + * @return Eden_Registry + */ + public function removeKey() { $args = func_get_args(); - //what object are we looking into? - //if the first argument is not an object - //use Eve's registry - $data = $this->_data; - if(is_array($args[0]) || is_object($args[0])) { - $data = array_shift($args); + + if(count($args) == 0) { + return $this; + } + + $key = array_shift($args); + + if(!isset($this->_data[$key])) { + return $this; } - //set the remaining length - $length = count($args); + if(count($args) == 0) { + unset($this->_data[$key]); + return $this; + } - if($length > 0) { - //foreach argument - foreach($args as $key => $value) { - if(!is_string($value) && !is_numeric($value)) { - return false; - } - - //walk the object - if(is_array($data)) - { - if(isset($data[$value])) { - $data = $data[$value]; - } else { - return false; - } - } else { - if(isset($data->{$value})) { - $data = $data->{$value}; - } else { - return false; - } - } + if($this->_data[$key] instanceof Eden_Registry) { + return call_user_func_array(array($this->_data[$key], __FUNCTION__), $args); + } + + return $this; + } + + /** + * 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; } - return true; + $array[$key] = $data; } - //if no arguments - //then return false - return false; + return $array; } /* Protected Methods diff --git a/library/eden/route.php b/library/eden/route.php index 74ec525..bf00700 100755 --- a/library/eden/route.php +++ b/library/eden/route.php @@ -139,10 +139,10 @@ public function isClassRoute($route) { public function routeMethod($routeClass, $routeMethod, $class, $method = NULL) { //argument test Eden_Route_Error::get() - ->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(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 method is not a string if(!is_string($method)) { @@ -291,6 +291,7 @@ public function callMethod($class, $method, $instance = NULL, array $args = arra ->argument(3, 'object', 'bool', 'null'); //argument 3 must be object, bool or null if(is_object($class)) { + $instance = $class; $class = get_class($class); } @@ -312,8 +313,8 @@ public function callMethod($class, $method, $instance = NULL, array $args = arra ->trigger(); } - //method does not exist if(!method_exists($class, $method)) { + //throw exception Eden_Route_Error::get() ->setMessage(Eden_Route_Error::METHOD_NOT_EXISTS) ->addVariable($class) @@ -340,17 +341,6 @@ public function callMethod($class, $method, $instance = NULL, array $args = arra } return call_user_func_array($class.'::'.$method, $args); // As of 5.2.3 - } - - //instance is an object - //if method does not exist - if(!method_exists($instance, $method)) { - //throw exception - Eden_Route_Error::get() - ->setMessage(Eden_Route_Error::METHOD_NOT_EXISTS) - ->addVariable(get_class($instance)) - ->addVariable($method) - ->trigger(); } return call_user_func_array(array(&$instance, $method), $args); diff --git a/library/eden/session.php b/library/eden/session.php index b011432..d20d066 100755 --- a/library/eden/session.php +++ b/library/eden/session.php @@ -40,7 +40,7 @@ public static function get() { -------------------------------*/ public function __toString() { if(!self::$_session) { - throw new Eden_Session_Error(Eden_Session_Error::ERROR_NOT_STARTED); + return '[]'; } return json_encode($_SESSION); @@ -127,7 +127,7 @@ public function getData($key = NULL) { */ public function getId() { if(!self::$_session) { - throw new Eden_Session_Error(Eden_Session_Error::ERROR_NOT_STARTED); + Eden_Session_Error::get(Eden_Session_Error::ERROR_NOT_STARTED)->trigger(); } return session_id(); @@ -172,7 +172,7 @@ public function remove($name) { */ public function clear() { if(!self::$_session) { - throw new Eden_Session_Error(Eden_Session_Error::ERROR_NOT_STARTED); + Eden_Session_Error::get(Eden_Session_Error::ERROR_NOT_STARTED)->trigger(); } $_SESSION = array(); @@ -188,7 +188,7 @@ public function clear() { */ public function rewind() { if(!self::$_session) { - throw new Eden_Session_Error(Eden_Session_Error::ERROR_NOT_STARTED); + Eden_Session_Error::get(Eden_Session_Error::ERROR_NOT_STARTED)->trigger(); } reset($_SESSION); @@ -202,7 +202,7 @@ public function rewind() { */ public function current() { if(!self::$_session) { - throw new Eden_Session_Error(Eden_Session_Error::ERROR_NOT_STARTED); + Eden_Session_Error::get(Eden_Session_Error::ERROR_NOT_STARTED)->trigger(); } return current($_SESSION); @@ -216,7 +216,7 @@ public function current() { */ public function key() { if(!self::$_session) { - throw new Eden_Session_Error(Eden_Session_Error::ERROR_NOT_STARTED); + Eden_Session_Error::get(Eden_Session_Error::ERROR_NOT_STARTED)->trigger(); } return key($_SESSION); @@ -230,7 +230,7 @@ public function key() { */ public function next() { if(!self::$_session) { - throw new Eden_Session_Error(Eden_Session_Error::ERROR_NOT_STARTED); + Eden_Session_Error::get(Eden_Session_Error::ERROR_NOT_STARTED)->trigger(); } next($_SESSION); @@ -244,7 +244,7 @@ public function next() { */ public function valid() { if(!self::$_session) { - throw new Eden_Session_Error(Eden_Session_Error::ERROR_NOT_STARTED); + Eden_Session_Error::get(Eden_Session_Error::ERROR_NOT_STARTED)->trigger(); } return isset($_SESSION[$this->key()]); @@ -259,7 +259,7 @@ public function valid() { */ public function offsetSet($offset, $value) { if(!self::$_session) { - throw new Eden_Session_Error(Eden_Session_Error::ERROR_NOT_STARTED); + Eden_Session_Error::get(Eden_Session_Error::ERROR_NOT_STARTED)->trigger(); } if (is_null($offset)) { @@ -277,7 +277,7 @@ public function offsetSet($offset, $value) { */ public function offsetExists($offset) { if(!self::$_session) { - throw new Eden_Session_Error(Eden_Session_Error::ERROR_NOT_STARTED); + Eden_Session_Error::get(Eden_Session_Error::ERROR_NOT_STARTED)->trigger(); } return isset($_SESSION[$offset]); @@ -291,7 +291,7 @@ public function offsetExists($offset) { */ public function offsetUnset($offset) { if(!self::$_session) { - throw new Eden_Session_Error(Eden_Session_Error::ERROR_NOT_STARTED); + Eden_Session_Error::get(Eden_Session_Error::ERROR_NOT_STARTED)->trigger(); } unset($_SESSION[$offset]); @@ -305,7 +305,7 @@ public function offsetUnset($offset) { */ public function offsetGet($offset) { if(!self::$_session) { - throw new Eden_Session_Error(Eden_Session_Error::ERROR_NOT_STARTED); + Eden_Session_Error::get(Eden_Session_Error::ERROR_NOT_STARTED)->trigger(); } return isset($_SESSION[$offset]) ? $_SESSION[$offset] : NULL; @@ -323,7 +323,7 @@ public function offsetGet($offset) { class Eden_Session_Error extends Eden_Error { /* Constants -------------------------------*/ - const ERROR_ERROR_NOT_STARTED = 'Session is not started. Try using Eden_Session->start() first.'; + const ERROR_NOT_STARTED = 'Session is not started. Try using Eden_Session->start() first.'; /* Public Properties -------------------------------*/ diff --git a/library/eden/sql/insert.php b/library/eden/sql/insert.php index d18e9e3..68207b0 100755 --- a/library/eden/sql/insert.php +++ b/library/eden/sql/insert.php @@ -70,12 +70,18 @@ public function set($key, $value, $index = 0) { //argument test Eden_Sql_Error::get() ->argument(1, 'string') //Argument 1 must be a string - ->argument(2, 'string', 'numeric'); //Argument 2 must be a string or number + ->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; } diff --git a/library/eden/sql/update.php b/library/eden/sql/update.php index b629949..56b6c02 100755 --- a/library/eden/sql/update.php +++ b/library/eden/sql/update.php @@ -48,7 +48,13 @@ public function set($key, $value) { //argument test Eden_Sql_Error::get() ->argument(1, 'string') //Argument 1 must be a string - ->argument(2, 'string', 'numeric'); //Argument 2 must be a string or number + ->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; diff --git a/library/eden/string.php b/library/eden/string.php deleted file mode 100755 index 3af4a39..0000000 --- a/library/eden/string.php +++ /dev/null @@ -1,209 +0,0 @@ - -/* - * 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__).'/class.php'; -require_once dirname(__FILE__).'/type/abstract.php'; -require_once dirname(__FILE__).'/type/error.php'; -require_once dirname(__FILE__).'/array.php'; - -/** - * - * @package Eden - * @category registry - * @author Christian Blanquera - * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ - */ -class Eden_String extends Eden_Type_Abstract { - /* Constants - -------------------------------*/ - /* Public Properties - -------------------------------*/ - /* Protected Properties - -------------------------------*/ - protected static $_preMethods = array( - 'addslashes', - 'bin2hex', 'chunk_split', - 'convert_uudecode', 'convert_uuencode', - 'crypt', 'html_entity_decode', - 'htmlentities', 'htmlspecialchars_decode', - 'htmlspecialchars', 'lcfirst', - 'ltrim', 'md5', - 'nl2br', 'quoted_printable_decode', - 'quoted_printable_encode', 'quotemeta', - 'rtrim', 'sha1', - 'sprintf', 'str_pad', - 'str_repeat', 'str_rot13', - 'str_shuffle', 'strip_tags', - 'stripcslashes', 'stripslashes', - 'strpbrk', 'stristr', - 'strrev', 'strstr', - 'strtok', 'strtolower', - 'strtoupper', 'strtr', - 'substr_replace', 'substr', - 'trim', 'ucfirst', - 'ucwords', 'vsprintf', - 'wordwrap', 'count_chars', - 'hex2bin', 'strlen', - 'strpos', 'substr_compare', - 'substr_count'); - - protected static $_postMethods = array('str_ireplace', 'str_replace', 'explode'); - - /* Private Properties - -------------------------------*/ - /* Get - -------------------------------*/ - public static function get($data) { - //argument 1 must be a string - Eden_String_Error::get()->argument(1, 'string'); - - return self::_getMultiple(__CLASS__, $data); - } - - /* Magic - -------------------------------*/ - 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_String_Error::get()->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; - } - - /** - * Uncamelizes a string - * - * @param string prefix - * @return this - */ - public function uncamelize($prefix = '-') { - //argument 1 must be a string - Eden_String_Error::get()->argument(1, 'string'); - - $this->_data = strtolower(preg_replace("/([A-Z])/", $prefix."$1", $this->_data)); - - 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_String_Error::get()->argument(1, 'string'); - - $this->_data = ucwords(str_replace($prefix, ' ', $this->_data)); - - return $this; - } - - /* Protected Methods - -------------------------------*/ - protected function _getPreMethod($name) { - if(in_array($name, self::$_preMethods)) { - return $name; - } - - if(in_array('str'.$name, self::$_preMethods)) { - return 'str'.$name; - } - - if(in_array('str_'.$name, self::$_preMethods)) { - return 'str_'.$name; - } - - return false; - } - - protected function _getPostMethod($name) { - if(in_array($name, self::$_postMethods)) { - return $name; - } - - if(in_array('str'.$name, self::$_postMethods)) { - return 'str'.$name; - } - - if(in_array('str_'.$name, self::$_postMethods)) { - return 'str_'.$name; - } - - return false; - } - - protected function _getReferenceMethod($name) { - return false; - } - - /* Private Methods - -------------------------------*/ -} - -/** - * String Errors - */ -class Eden_String_Error extends Eden_Type_Error { - /* Constants - -------------------------------*/ - /* Public Properties - -------------------------------*/ - /* Protected Properties - -------------------------------*/ - /* Private Properties - -------------------------------*/ - /* Get - -------------------------------*/ - public static function get($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/type.php b/library/eden/type.php new file mode 100644 index 0000000..fda4e6e --- /dev/null +++ b/library/eden/type.php @@ -0,0 +1,98 @@ + +/* + * 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__).'/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 + * @version $Id: javascript.php 1 2010-01-02 23:06:36Z blanquera $ + */ +class Eden_Type extends Eden_Class { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function get($type = NULL) { + if(func_num_args() > 1) { + $type = func_get_args(); + } + + if(is_array($type)) { + return Eden_Type_Array::get($type); + } + + if(is_string($type)) { + return Eden_Type_String::get($type); + } + + if(is_object($type)) { + return Eden_Type_Object::get($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::get($array); + } + + /** + * Returns the string class + * + * @param string + * @return Eden_Type_String + */ + public function getString($string) { + return Eden_Type_String::get($string); + } + + /** + * Returns the object class + * + * @param object + * @return Eden_Type_Object + */ + public function getObject($object) { + return Eden_Type_Object::get($object); + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/type/abstract.php b/library/eden/type/abstract.php index 6a97b71..5dd877a 100755 --- a/library/eden/type/abstract.php +++ b/library/eden/type/abstract.php @@ -17,14 +17,16 @@ abstract class Eden_Type_Abstract extends Eden_Class { /* Constants -------------------------------*/ + const PRE = 'pre'; + const POST = 'post'; + const REFERENCE = 'reference'; + /* Public Properties -------------------------------*/ /* Protected Properties -------------------------------*/ - protected $_methods = array(); - - protected $_data = NULL; - protected $_original = NULL; + protected $_data = NULL; + protected $_original = NULL; /* Private Properties -------------------------------*/ @@ -37,101 +39,96 @@ public function __construct($data) { } public function __call($name, $args) { - $method = $this->_getPreMethod($name); + $type = $this->_getMethodType($name); - //if this is a pre method - if($method) { - //add the string as first arg - array_unshift($args, $this->_data); - } else { - $method = $this->_getPostMethod($name); - - //if this is a post method - if($method) { - //add string at the end of the arguments - array_push($args, $this->_data); - } else { - $method = $this->_getReferenceMethod($name); - //if this is a reference method - if($method) { - //call the method - $data = &$this->_data; - //This doesn't work for reference methods as - //described in ticket 44139 of PHP Bugs - //array_unshift($args, $this->_data); - //the work around is as follows - call_user_func_array($method, array_merge(array(&$this->_data), $args)); - - return $this; - } + //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::get($e->getMessage())->trigger(); } } - //if this is a method - if($method) { - //call the method - $result = call_user_func_array($method, $args); - - //if the result is a string - if(is_string($result)) { - //if this class is a string type - if($this instanceof Eden_String) { - //set value - $this->_data = $result; - return $this; - } - - //return string class - return Eden_String::get($result); - } + //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; + } - //if the result is an array - if(is_array($result)) { - //if this class is a array type - if($this instanceof Eden_Array) { - //set value - $this->_data = $result; - return $this; - } - - //return array class - return Eden_Array::get($result); + //return string class + return Eden_Type_String::get($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 $result; + //return array class + return Eden_Type_Array::get($result); } - //we don't process anything else - try { - //call the parent - return parent::__call($name, $args); - } catch(Eden_Error $e) { - throw new Eden_Type_Error($e->getMessage()); - } + return $result; } /* Public Methods -------------------------------*/ /** - * Returns the string + * Reverts changes back to the original + * + * @return this + */ + public function revert() { + $this->_data = $this->_original; + return $this; + } + + /** + * Returns the value * * @param bool whether to get the modified or original version * @return string */ - public function getValue($modified = true) { + public function getData($modified = true) { //argument 1 must be a bool - Eden_Type_Validate::get()->argument(1, 'bool'); + Eden_Type_Error::get()->argument(1, 'bool'); return $modified ? $this->_data : $this->_original; } /* Protected Methods -------------------------------*/ - abstract protected function _getPreMethod($name); - - abstract protected function _getPostMethod($name); - - abstract protected function _getReferenceMethod($name); + abstract protected function _getMethodType(&$name); /* Private Methods -------------------------------*/ diff --git a/library/eden/type/array.php b/library/eden/type/array.php new file mode 100644 index 0000000..be4f6fe --- /dev/null +++ b/library/eden/type/array.php @@ -0,0 +1,400 @@ + +/* + * 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. + */ + +/** + * + * @package Eden + * @category registry + * @author Christian Blanquera + * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ + */ +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, + 'in_array' => 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, + + '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 + -------------------------------*/ + /* Get + -------------------------------*/ + public static function get() { + $data = self::_getStart(func_get_args()); + return self::_getMultiple(__CLASS__, $data); + } + + /* Magic + -------------------------------*/ + 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 __toString() { + return json_encode($this->getData()); + } + + public function __get($name) { + if(isset($this->_data[$name])) { + return $this->_data[$name]; + } + + return NULL; + } + + public function __set($name, $value) { + $this->_data[$name] = $value; + } + + 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))); + + return $this->__get($key); + + } 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::get($e->getMessage())->trigger(); + } + } + + /* 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; + } + + /** + * 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::get()->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; + } + + /** + * 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::get() + ->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 the current item + * For Iterator interface + * + * @return void + */ + public function current() { + return current($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); + } + + /** + * Validates whether if the index is set + * For Iterator interface + * + * @return void + */ + public function valid() { + return isset($this->_data[$this->key()]); + } + + /** + * 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; + } + } + + /** + * isset using the ArrayAccess interface + * + * @param number + * @return bool + */ + public function offsetExists($offset) { + return isset($this->_data[$offset]); + } + + /** + * unsets using the ArrayAccess interface + * + * @param number + * @return bool + */ + public function offsetUnset($offset) { + unset($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; + } + + /** + * returns serialized data using the Serializable interface + * + * @return string + */ + public function serialize() { + return json_encode($this->_data); + } + + /** + * sets data using the Serializable interface + * + * @param string + * @return void + */ + public function unserialize($data) { + $this->_data = json_decode($data, true); + return $this; + } + + /** + * returns size using the Countable interface + * + * @return string + */ + public function count() { + return count($this->_data); + } + + /* Protected Methods + -------------------------------*/ + protected static function _getStart(array $args) { + if(count($args) != 1) { + return $args; + } + + $data = $args[0]; + + if($data instanceof Eden_Type_Array) { + $data = $data->getData(); + } + + if(!is_array($data)) { + $data = array($data); + } + + return $data; + } + + 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/string.php b/library/eden/type/string.php new file mode 100644 index 0000000..5db2ada --- /dev/null +++ b/library/eden/type/string.php @@ -0,0 +1,171 @@ + +/* + * 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. + */ + +/** + * + * @package Eden + * @category registry + * @author Christian Blanquera + * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ + */ +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 + -------------------------------*/ + /* Get + -------------------------------*/ + public static function get($data) { + if($data instanceof Eden_Type_String) { + return $data; + } + + //argument 1 must be scalar + Eden_Type_Error::get()->argument(1, 'scalar'); + + $data = (string) $data; + + return self::_getMultiple(__CLASS__, $data); + } + + /* Magic + -------------------------------*/ + 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::get()->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; + } + + /** + * Uncamelizes a string + * + * @param string prefix + * @return this + */ + public function uncamelize($prefix = '-') { + //argument 1 must be a string + Eden_Type_Error::get()->argument(1, 'string'); + + $this->_data = strtolower(preg_replace("/([A-Z])/", $prefix."$1", $this->_data)); + + 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::get()->argument(1, 'string'); + + $this->_data = ucwords(str_replace($prefix, ' ', $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/webcharge.php b/library/eden/webcharge.php index 85b269d..dd8a179 100644 --- a/library/eden/webcharge.php +++ b/library/eden/webcharge.php @@ -86,12 +86,6 @@ public static function get($user, $password, array $options = array()) { /* Magic -------------------------------*/ public function __construct($user = NULL, $password = NULL, array $options = array()) { - //test for no cURL - if(!function_exists('curl_init')) { - //throw exception - throw new Eden_Service_Exception(Eden_Service_Exception::NO_CURL); - } - $this->setUser($user)->setPassword($password); $this->_proxy = isset($options['proxy']) ? $options['proxy'] : NULL; @@ -205,9 +199,9 @@ public function send() { } //test for valid creditcard name - if(!$this->_transaction['ccname'])) { + if(!$this->_transaction['ccname']) { //throw exception - throw new Eden_Webcharge_Error(Eden_Webcharge_Error::INVALID_CREDIT_CARD_NAME); + Eden_Webcharge_Error::get(Eden_Webcharge_Error::INVALID_CREDIT_CARD_NAME)->trigger(); } // Create the connection through the cURL extension diff --git a/library/eden/when.php b/library/eden/when.php index d905c5c..280792e 100755 --- a/library/eden/when.php +++ b/library/eden/when.php @@ -24,21 +24,31 @@ class Eden_When extends Eden_Class implements ArrayAccess, Iterator { -------------------------------*/ /* Protected Properties -------------------------------*/ + protected $_scope = NULL; + protected $_increment = 1; + protected $_lines = 0; + /* Private Properties -------------------------------*/ /* Get -------------------------------*/ - public static function get($scope) { - return self::_getSingleton(__CLASS__, $scope); + public static function get($scope, $lines = 0) { + return self::_getMultiple(__CLASS__, $scope, $lines); } /* Magic -------------------------------*/ - public function __construct($scope) { + 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->endWhen(); + } + + $this->_increment++; return $this; } From 9db791b968c9e51e5a3ecaae05c09d10824d7054 Mon Sep 17 00:00:00 2001 From: cblanquera Date: Sun, 8 Jan 2012 17:46:52 +0000 Subject: [PATCH 044/330] big changes. made all static get methods to i. Added facebook controller. path now extends string. renamed things with set data and get data to just set and get. git-svn-id: http://svn.openovate.com/edenv2/trunk@44 38ede93f-50f4-44af-b0b3-68ccca78c181 --- library/eden.php | 80 +- library/eden/amazon/error.php | 2 +- library/eden/amazon/s3.php | 30 +- library/eden/apc.php | 18 +- library/eden/block.php | 4 +- library/eden/block/pagination.php | 10 +- library/eden/block/search.php | 4 +- library/eden/cache.php | 32 +- library/eden/class.php | 84 +- library/eden/collection.php | 30 +- library/eden/cookie.php | 16 +- library/eden/curl.php | 1040 +++++++++--------- library/eden/error.php | 2 +- library/eden/error/event.php | 2 +- library/eden/event.php | 10 +- library/eden/eventbrite/base.php | 8 +- library/eden/eventbrite/discount.php | 6 +- library/eden/eventbrite/error.php | 110 +- library/eden/eventbrite/event.php | 10 +- library/eden/eventbrite/event/search.php | 42 +- library/eden/eventbrite/event/set.php | 68 +- library/eden/eventbrite/organizer.php | 8 +- library/eden/eventbrite/payment.php | 16 +- library/eden/eventbrite/ticket.php | 38 +- library/eden/eventbrite/user.php | 14 +- library/eden/eventbrite/venue.php | 6 +- library/eden/facebook.php | 89 ++ library/eden/facebook/auth.php | 190 ++-- library/eden/facebook/graph.php | 32 +- library/eden/facebook/post.php | 412 ++++---- library/eden/file.php | 40 +- library/eden/file/error.php | 2 +- library/eden/folder.php | 44 +- library/eden/getsatisfaction/base.php | 16 +- library/eden/getsatisfaction/company.php | 14 +- library/eden/getsatisfaction/detail.php | 4 +- library/eden/getsatisfaction/error.php | 2 +- library/eden/getsatisfaction/oauth.php | 2 +- library/eden/getsatisfaction/people.php | 14 +- library/eden/getsatisfaction/post.php | 14 +- library/eden/getsatisfaction/product.php | 14 +- library/eden/getsatisfaction/replies.php | 12 +- library/eden/getsatisfaction/tag.php | 10 +- library/eden/getsatisfaction/topic.php | 30 +- library/eden/google/base.php | 16 +- library/eden/google/calendar.php | 6 +- library/eden/google/contacts.php | 4 +- library/eden/google/docs.php | 4 +- library/eden/google/error.php | 2 +- library/eden/google/gmail.php | 4 +- library/eden/google/oauth.php | 4 +- library/eden/google/shortener.php | 10 +- library/eden/image.php | 28 +- library/eden/javascript.php | 4 +- library/eden/javascript/class.php | 4 +- library/eden/javascript/error.php | 2 +- library/eden/loader.php | 2 +- library/eden/map.php | 6 +- library/eden/memcache.php | 20 +- library/eden/model.php | 4 +- library/eden/mysql.php | 64 +- library/eden/mysql/alter.php | 22 +- library/eden/mysql/collection.php | 4 +- library/eden/mysql/create.php | 14 +- library/eden/mysql/error.php | 2 +- library/eden/mysql/model.php | 10 +- library/eden/mysql/search.php | 42 +- library/eden/mysql/subselect.php | 4 +- library/eden/mysql/utility.php | 12 +- library/eden/oauth.php | 38 +- library/eden/oauth/consumer.php | 20 +- library/eden/oauth/error.php | 2 +- library/eden/oauth/server.php | 2 +- library/eden/path.php | 42 +- library/eden/paypal/error.php | 82 +- library/eden/registry.php | 18 +- library/eden/route.php | 362 +------ library/eden/route/class.php | 161 +++ library/eden/route/error.php | 34 + library/eden/route/function.php | 139 +++ library/eden/route/method.php | 253 +++++ library/eden/session.php | 38 +- library/eden/sql/database.php | 18 +- library/eden/sql/delete.php | 6 +- library/eden/sql/error.php | 2 +- library/eden/sql/insert.php | 6 +- library/eden/sql/select.php | 24 +- library/eden/sql/update.php | 4 +- library/eden/template.php | 18 +- library/eden/timezone.php | 8 +- library/eden/tool.php | 2 +- library/eden/tumblr/base.php | 412 ++++---- library/eden/tumblr/blog.php | 1024 +++++++++--------- library/eden/tumblr/error.php | 110 +- library/eden/tumblr/oauth.php | 86 +- library/eden/tumblr/user.php | 494 ++++----- library/eden/twitter/accounts.php | 558 +++++----- library/eden/twitter/base.php | 16 +- library/eden/twitter/directmessage.php | 440 ++++---- library/eden/twitter/favorites.php | 258 ++--- library/eden/twitter/friends.php | 960 ++++++++--------- library/eden/twitter/list.php | 324 +++--- library/eden/twitter/oauth.php | 2 +- library/eden/twitter/search.php | 312 +++--- library/eden/twitter/suggestions.php | 218 ++-- library/eden/twitter/timelines.php | 1228 +++++++++++----------- library/eden/twitter/tweets.php | 736 ++++++------- library/eden/twitter/users.php | 554 +++++----- library/eden/type.php | 22 +- library/eden/type/abstract.php | 10 +- library/eden/type/array.php | 28 +- library/eden/type/error.php | 2 +- library/eden/type/string.php | 10 +- library/eden/unit.php | 38 +- library/eden/validation.php | 30 +- library/eden/webcharge.php | 20 +- library/eden/when.php | 2 +- 117 files changed, 6228 insertions(+), 5870 deletions(-) create mode 100644 library/eden/facebook.php create mode 100644 library/eden/route/class.php create mode 100644 library/eden/route/error.php create mode 100644 library/eden/route/function.php create mode 100644 library/eden/route/method.php diff --git a/library/eden.php b/library/eden.php index 3ae5194..a79a9c3 100644 --- a/library/eden.php +++ b/library/eden.php @@ -17,7 +17,7 @@ */ function eden() { //return the results - return Eden::get(); + return Eden::i(); } /** @@ -43,7 +43,7 @@ class Eden extends Eden_Event { -------------------------------*/ /* Get -------------------------------*/ - public static function get() { + public static function i() { return self::_getSingleton(__CLASS__); } @@ -77,13 +77,13 @@ public function __call($name, $args) { * @return this */ public function setRoot($root) { - Eden_Error::get()->argument(1, 'string'); + Eden_Error::i()->argument(1, 'string'); if(!class_exists('Eden_Path')) { - Eden_Loader::get()->load('Eden_Path'); + Eden_Loader::i()->load('Eden_Path'); } - $this->_root = (string) Eden_Path::get($root); + $this->_root = (string) Eden_Path::i($root); return $this; } @@ -118,7 +118,7 @@ public function setLoader() { require_once dirname(__FILE__).'/eden/loader.php'; //set autoload class as the autoload handler - spl_autoload_register(array(Eden_Loader::get(), 'handler')); + spl_autoload_register(array(Eden_Loader::i(), 'handler')); } //get paths @@ -132,7 +132,7 @@ public function setLoader() { //we need Eden_Path to fix the path formatting if(!class_exists('Eden_Path')) { - Eden_Loader::get()->load('Eden_Path'); + Eden_Loader::i()->load('Eden_Path'); } //no dupes @@ -146,7 +146,7 @@ public function setLoader() { if($path) { //format the path - $path = (string) Eden_Path::get($path); + $path = (string) Eden_Path::i($path); } else { $path = $this->_root; } @@ -160,7 +160,7 @@ public function setLoader() { //if the path is still a real path if(is_dir($path)) { //add the root - Eden_Loader::get()->addRoot($path); + Eden_Loader::i()->addRoot($path); } } @@ -174,29 +174,29 @@ public function setLoader() { * @return Eden_Framework */ public function routeClasses($routes) { - Eden_Error::get()->argument(1, 'string', 'array', 'bool'); - $route = Eden_Route::get(); + Eden_Error::i()->argument(1, 'string', 'array', 'bool'); + $route = Eden_Route::i()->getClass(); if($routes === true) { - $route->routeClass('Cache', 'Eden_Cache') - ->routeClass('String', 'Eden_Type_String') - ->routeClass('Array', 'Eden_Type_Array') - ->routeClass('Registry', 'Eden_Registry') - ->routeClass('Model', 'Eden_Model') - ->routeClass('Collection', 'Eden_Collection') - ->routeClass('Cookie', 'Eden_Cookie') - ->routeClass('Session', 'Eden_Session') - ->routeClass('Template', 'Eden_Template') - ->routeClass('Curl', 'Eden_Curl') - ->routeClass('Event', 'Eden_Event') - ->routeClass('Path', 'Eden_Path') - ->routeClass('File', 'Eden_File') - ->routeClass('Folder', 'Eden_Folder') - ->routeClass('Image', 'Eden_Image') - ->routeClass('Mysql', 'Eden_Mysql') - ->routeClass('Array', 'Eden_Type_Array') - ->routeClass('String', 'Eden_Type_String') - ->routeClass('Validation', 'Eden_Validation'); + $route->route('Cache', 'Eden_Cache') + ->route('String', 'Eden_Type_String') + ->route('Array', 'Eden_Type_Array') + ->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('Array', 'Eden_Type_Array') + ->route('String', 'Eden_Type_String') + ->route('Validation', 'Eden_Validation'); return $this; } @@ -206,7 +206,7 @@ public function routeClasses($routes) { } foreach($routes as $alias => $class) { - $route->routeClass($alias, $class); + $route->route($alias, $class); } return $this; @@ -219,8 +219,16 @@ public function routeClasses($routes) { * @return Eden_Framework */ public function routeMethods($routes) { - Eden_Error::get()->argument(1, 'string', 'array'); - $route = Eden_Route::get(); + Eden_Error::i()->argument(1, 'string', 'array', 'bool'); + $route = Eden_Route::i()->getMethod(); + + if(is_bool($routes)) { + $route->route(NULL, 'output', 'Eden_Tool') + ->route(NULL, 'uid', 'Eden_Tool') + ->route(NULL, 'type', 'Eden_Tool'); + + return $this; + } if(is_string($routes)) { $routes = include($routes); @@ -243,7 +251,7 @@ public function routeMethods($routes) { } //route the method - $route->routeMethod($method, $routePath[0], $routePath[1]); + $route->route($method, $routePath[0], $routePath[1]); } } @@ -257,7 +265,7 @@ public function routeMethods($routes) { */ public function startSession() { //get the session class - Eden_Session::get()->start(); + Eden_Session::i()->start(); return $this; } @@ -268,7 +276,7 @@ public function startSession() { * @return this */ public function setTimezone($zone) { - Eden_Error::get()->argument(1, 'string'); + Eden_Error::i()->argument(1, 'string'); date_default_timezone_set($zone); diff --git a/library/eden/amazon/error.php b/library/eden/amazon/error.php index a14f9df..ea4accc 100644 --- a/library/eden/amazon/error.php +++ b/library/eden/amazon/error.php @@ -26,7 +26,7 @@ class Eden_Amazon_Error extends Eden_Error { -------------------------------*/ /* Get -------------------------------*/ - public static function get($message = NULL, $code = 0) { + public static function i($message = NULL, $code = 0) { $class = __CLASS__; return new $class($message, $code); } diff --git a/library/eden/amazon/s3.php b/library/eden/amazon/s3.php index 7c3b45e..502c2fa 100644 --- a/library/eden/amazon/s3.php +++ b/library/eden/amazon/s3.php @@ -39,7 +39,7 @@ class Eden_Amazon_S3 extends Eden_Class { -------------------------------*/ /* Get -------------------------------*/ - public static function get($user, $pass, $host = 's3.amazonaws.com', $ssl = false) { + public static function i($user, $pass, $host = 's3.amazonaws.com', $ssl = false) { return self::_getMultiple(__CLASS__, $user, $pass, $host, $ssl); } @@ -89,7 +89,7 @@ public function getBuckets() { */ public function getBucket($name, $prefix = NULL, $marker = NULL, $maxKeys = NULL, $delimiter = NULL) { //argument test - Eden_Amazon_Error::get() + 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 @@ -167,7 +167,7 @@ public function getBucket($name, $prefix = NULL, $marker = NULL, $maxKeys = NULL */ public function getFolders($bucket, $path = NULL, $prefix = NULL, $marker = NULL, $maxKeys = NULL, $delimiter = NULL) { //argument test - Eden_Amazon_Error::get() + 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 @@ -228,7 +228,7 @@ public function getFolders($bucket, $path = NULL, $prefix = NULL, $marker = NULL */ public function getFiles($bucket, $path = NULL, $prefix = NULL, $marker = NULL, $maxKeys = NULL, $delimiter = NULL) { //argument test - Eden_Amazon_Error::get() + 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 @@ -283,7 +283,7 @@ public function getFiles($bucket, $path = NULL, $prefix = NULL, $marker = NULL, */ public function addBucket($bucket, $acl = self::ACL_PRIVATE, $location = false) { //argument test - Eden_Amazon_Error::get() + 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 @@ -321,7 +321,7 @@ public function addBucket($bucket, $acl = self::ACL_PRIVATE, $location = false) */ public function deleteBucket($bucket) { //Argument 1 must be string - Eden_Amazon_Error::get()->argument(1, 'string'); + Eden_Amazon_Error::i()->argument(1, 'string'); $this->_setResponse('DELETE', $bucket); if(!empty($this->_meta['error']) || empty($this->_response)) { @@ -341,7 +341,7 @@ public function deleteBucket($bucket) { */ public function setPermissions($bucket, $path = '/', array $acp = array()) { //argument test - Eden_Amazon_Error::get() + Eden_Amazon_Error::i() ->argument(1, 'string') //Argument 1 must be string ->argument(2, 'string'); //Argument 2 must be string @@ -403,7 +403,7 @@ public function setPermissions($bucket, $path = '/', array $acp = array()) { */ public function getPermissions($bucket, $path = '/') { //argument test - Eden_Amazon_Error::get() + Eden_Amazon_Error::i() ->argument(1, 'string') //Argument 1 must be string ->argument(2, 'string'); //Argument 2 must be string @@ -468,7 +468,7 @@ public function getPermissions($bucket, $path = '/') { */ public function addFile($bucket, $path, $data, $acl = self::ACL_PRIVATE, $file = false) { //argument test - Eden_Amazon_Error::get() + 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 @@ -523,7 +523,7 @@ public function addFile($bucket, $path, $data, $acl = self::ACL_PRIVATE, $file = */ public function getFile($bucket, $path) { //argument test - Eden_Amazon_Error::get() + Eden_Amazon_Error::i() ->argument(1, 'string') //Argument 1 must be string ->argument(2, 'string'); //Argument 2 must be string @@ -546,7 +546,7 @@ public function getFile($bucket, $path) { */ public function getFileInfo($bucket, $path) { //argument test - Eden_Amazon_Error::get() + Eden_Amazon_Error::i() ->argument(1, 'string') //Argument 1 must be string ->argument(2, 'string'); //Argument 2 must be string @@ -572,7 +572,7 @@ public function getFileInfo($bucket, $path) { */ public function deleteFile($bucket, $path) { //argument test - Eden_Amazon_Error::get() + Eden_Amazon_Error::i() ->argument(1, 'string') //Argument 1 must be string ->argument(2, 'string'); //Argument 2 must be string @@ -594,7 +594,7 @@ public function deleteFile($bucket, $path) { */ public function deleteFolder($bucket, $path) { //argument test - Eden_Amazon_Error::get() + Eden_Amazon_Error::i() ->argument(1, 'string') //Argument 1 must be string ->argument(2, 'string'); //Argument 2 must be string @@ -632,7 +632,7 @@ public function deleteFolder($bucket, $path) { */ public function getFolderSize($bucket, $path) { //argument test - Eden_Amazon_Error::get() + Eden_Amazon_Error::i() ->argument(1, 'string') //Argument 1 must be string ->argument(2, 'string'); //Argument 2 must be string @@ -730,7 +730,7 @@ protected function _setResponse($action, $bucket = NULL, $path = '/', array $que $curlHeaders[] = 'Authorization: ' . $this->_getSignature($signature); //setup curl - $curl = Eden_Curl::get() + $curl = Eden_Curl::i() ->setUserAgent('S3/php') ->setUrl($url) ->setHeaders($curlHeaders) diff --git a/library/eden/apc.php b/library/eden/apc.php index dd69f1a..45fd607 100755 --- a/library/eden/apc.php +++ b/library/eden/apc.php @@ -35,7 +35,7 @@ class Eden_Apc extends Eden_Class { -------------------------------*/ /* Private Properties -------------------------------*/ - public static function get() { + public static function i() { return self::_getSingleton(__CLASS__); } @@ -45,7 +45,7 @@ public function __construct() { //if apc_cache_info is not a function if(!function_exists('apc_cache_info')) { //throw exception - Eden_Apc_Error::get(Eden_Apc_Error::NOT_INSTALLED)->trigger(); + Eden_Apc_Error::i(Eden_Apc_Error::NOT_INSTALLED)->trigger(); } } @@ -61,9 +61,9 @@ public function __construct() { * @param int expire * @return bool */ - public function setData($key, $data, $expire = NULL) { + public function set($key, $data, $expire = NULL) { //argument test - Eden_Apc_Error::get() + 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 @@ -79,9 +79,9 @@ public function setData($key, $data, $expire = NULL) { * @param int MemCache flag * @return variable */ - public function getData($key) { + public function get($key) { //Argument 1 must be a string or array - Eden_Memcache_Error::get()->argument(1, 'string', 'array'); + Eden_Memcache_Error::i()->argument(1, 'string', 'array'); return apc_fetch($key); } @@ -92,9 +92,9 @@ public function getData($key) { * @param string the key to the data * @return this */ - public function deleteData($key) { + public function remove($key) { //Argument 1 must be a string or array - Eden_Memcache_Error::get()->argument(1, 'string', 'array'); + Eden_Memcache_Error::i()->argument(1, 'string', 'array'); apc_delete($key); @@ -134,7 +134,7 @@ class Eden_Apc_Error extends Eden_Error { -------------------------------*/ /* Get -------------------------------*/ - public static function get($message = NULL, $code = 0) { + public static function i($message = NULL, $code = 0) { $class = __CLASS__; return new $class($message, $code); } diff --git a/library/eden/block.php b/library/eden/block.php index 6ed4634..046b080 100644 --- a/library/eden/block.php +++ b/library/eden/block.php @@ -33,7 +33,7 @@ public function __toString() { try { return (string) $this->render(); } catch(Exception $e) { - Eden_Error_Event::get()->exceptionHandler($e); + Eden_Error_Event::i()->exceptionHandler($e); } return ''; @@ -62,7 +62,7 @@ abstract public function getTemplate(); * @return string */ public function render() { - return Eden_Template::get()->setData($this->getVariables())->parsePhp($this->getTemplate()); + return Eden_Template::i()->set($this->getVariables())->parsePhp($this->getTemplate()); } /* Protected Methods diff --git a/library/eden/block/pagination.php b/library/eden/block/pagination.php index caaa045..68a2793 100644 --- a/library/eden/block/pagination.php +++ b/library/eden/block/pagination.php @@ -35,7 +35,7 @@ class Eden_Block_Pagination extends Eden_Block { -------------------------------*/ /* Get -------------------------------*/ - public static function get($total) { + public static function i($total) { return self::_getMultiple(__CLASS__, $total); } @@ -54,7 +54,7 @@ public function __construct($total) { * @return this */ public function setStart($start) { - Front_Error::get()->argument(1, 'int'); + Front_Error::i()->argument(1, 'int'); if($start < 0) { $start = 0; } @@ -71,7 +71,7 @@ public function setStart($start) { * @return this */ public function setRange($range) { - Front_Error::get()->argument(1, 'int'); + Front_Error::i()->argument(1, 'int'); if($range < 0) { $range = 1; } @@ -88,7 +88,7 @@ public function setRange($range) { * @return this */ public function setPage($page) { - Front_Error::get()->argument(1, 'int'); + Front_Error::i()->argument(1, 'int'); if($page < 1) { $page = 1; } @@ -105,7 +105,7 @@ public function setPage($page) { * @return this */ public function setShow($show) { - Front_Error::get()->argument(1, 'int'); + Front_Error::i()->argument(1, 'int'); if($show < 1) { $show = 1; } diff --git a/library/eden/block/search.php b/library/eden/block/search.php index ec54733..f577351 100644 --- a/library/eden/block/search.php +++ b/library/eden/block/search.php @@ -33,7 +33,7 @@ class Eden_Block_Search extends Eden_Block { -------------------------------*/ /* Get -------------------------------*/ - public static function get() { + public static function i() { return self::_getMultiple(__CLASS__); } @@ -49,7 +49,7 @@ public static function get() { * @return this */ public function setKeyword($keyword) { - Front_Error::get()->argument(1, 'string', 'null'); + Front_Error::i()->argument(1, 'string', 'null'); $this->_keyword = $keyword; return $this; diff --git a/library/eden/cache.php b/library/eden/cache.php index 74ebf06..b3ba6e5 100755 --- a/library/eden/cache.php +++ b/library/eden/cache.php @@ -39,14 +39,14 @@ class Eden_Cache extends Eden_Class { -------------------------------*/ /* Get -------------------------------*/ - public static function get($root, $key = 'key.php') { + public static function i($root, $key = 'key.php') { return self::_getMultiple(__CLASS__, $root, $key); } /* Magic -------------------------------*/ public function __construct($root, $key = 'key.php') { - Eden_Cache_Error::get() + Eden_Cache_Error::i() ->argument(1, 'string') ->argument(2, 'string'); @@ -63,7 +63,7 @@ public function __construct($root, $key = 'key.php') { */ public function setKey($key) { //argument 1 must be a string - Eden_Cache_Error::get()->argument(1, 'string'); + Eden_Cache_Error::i()->argument(1, 'string'); $this->_key = $key; return $this; @@ -77,9 +77,9 @@ public function setKey($key) { */ public function setRoot($root) { //argument 1 must be a string - Eden_Cache_Error::get()->argument(1, 'string'); + Eden_Cache_Error::i()->argument(1, 'string'); - $this->_path = (string) Eden_Path::get($root)->absolute(); + $this->_path = (string) Eden_Path::i($root)->absolute(); return $this; } @@ -91,7 +91,7 @@ public function setRoot($root) { */ public function build() { try { - $this->_cache = Eden_File::get($this->_path.'/'.$this->_key)->getData(); + $this->_cache = Eden_File::i($this->_path.'/'.$this->_key)->getData(); } catch(Eden_File_Error $e) { $this->_cache = array(); } @@ -106,20 +106,20 @@ public function build() { * @param *mixed the data to be cached * @return Eden_CacheModel */ - public function setData($key, $path, $data) { + public function set($key, $path, $data) { //argument test - Eden_Cache_Error::get() + 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::get($path); + $path = $this->_path.Eden_Path::i($path); //set the data to the file - Eden_File::get($path)->setData($data); + 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::get($this->_path.'/'.$this->_key)->setData($this->_cache); + Eden_File::i($this->_path.'/'.$this->_key)->setData($this->_cache); return $this; } @@ -131,14 +131,14 @@ public function setData($key, $path, $data) { * @param string|null returns this variable by default * @return mixed */ - public function getData($key, $default = NULL) { + public function get($key, $default = NULL) { //argument 1 must be a string - Eden_Cache_Error::get()->argument(1, 'string'); + Eden_Cache_Error::i()->argument(1, 'string'); //if the key exists if($this->keyExists($key)) { //return it - return Eden_File::get($this->_cache[$key])->getData($default); + return Eden_File::i($this->_cache[$key])->getData($default); } //return the defauit @@ -153,7 +153,7 @@ public function getData($key, $default = NULL) { */ public function keyExists($key) { //argument 1 must be a string - Eden_Cache_Error::get()->argument(1, 'string'); + Eden_Cache_Error::i()->argument(1, 'string'); return isset($this->_cache[$key]) && file_exists($this->_cache[$key]); } @@ -178,7 +178,7 @@ class Eden_Cache_Error extends Eden_Error { -------------------------------*/ /* Get -------------------------------*/ - public static function get($message = NULL, $code = 0) { + public static function i($message = NULL, $code = 0) { $class = __CLASS__; return new $class($message, $code); } diff --git a/library/eden/class.php b/library/eden/class.php index 5fd7348..b2ce2a9 100755 --- a/library/eden/class.php +++ b/library/eden/class.php @@ -8,9 +8,6 @@ */ require_once dirname(__FILE__).'/error.php'; -require_once dirname(__FILE__).'/route.php'; -require_once dirname(__FILE__).'/when.php'; -require_once dirname(__FILE__).'/map.php'; /** * The base class for all classes wishing to integrate with Eve. @@ -53,7 +50,7 @@ public function __call($name, $args) { //want to load a class so lets try try { //return the class - return Eden_Route::get()->getClassArray($name, $args); + 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 @@ -63,9 +60,9 @@ public function __call($name, $args) { try { //let the router handle this - return Eden_Route::get()->callMethod($this, $name, true, $args); + return Eden_Route::i()->getMethod()->call($this, $name, $args); } catch(Eden_Route_Error $e) { - Eden_Error::get($e->getMessage())->trigger(); + Eden_Error::i($e->getMessage())->trigger(); } } @@ -79,28 +76,29 @@ public function __call($name, $args) { */ public function routeThis($route) { //argument 1 must be a string - Eden_Error::get()->argument(1, 'string'); + Eden_Error::i()->argument(1, 'string'); - Eden_Route::get()->routeClass($route, get_class($this)); - return $this; - } - - /** - * Creates a method route for this class. - * - * @param *string the method route name - * @param *string the class name to route to - * @param *string the method name to route to - * @return Eden_Class - */ - public function routeMethod($routeMethod, $class, $method) { - //argument 1-3 must be a string - Eden_Error::get() - ->argument(1, 'string') - ->argument(2, 'string') - ->argument(3, '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(); - Eden_Route::get()->routeMethod(get_class($this), $routeMethod, $class, $method); + $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; } @@ -112,11 +110,11 @@ public function routeMethod($routeMethod, $class, $method) { * @param array * @return mixed */ - public function callThisMethod($method, array $args = array()) { + public function callThis($method, array $args = array()) { //argument 1 must be a string - Eden_Error::get()->argument(1,'string'); + Eden_Error::i()->argument(1,'string'); - return Eden_Route::get()->callMethod($this, $method, $args); + return Eden_Route::i()->getMethod($this, $method, $args); } /** @@ -130,7 +128,7 @@ public function when($isTrue, $lines) { return $this; } - return Eden_When::get($this, $lines); + return Eden_When::i($this, $lines); } /** @@ -139,24 +137,14 @@ public function when($isTrue, $lines) { * @param bool * @return this|Eden_Noop */ - public function map(array &$list, $lines = 0) { - return Eden_Map::get($this, $list, $lines); - } - - /** - * Returns the original class - * - * @param bool - * @return this|Eden_Noop - */ - public function endWhen() { - return $this; + public function loop(array &$list, $lines = 0) { + return Eden_Map::i($this, $list, $lines); } /* Protected Methods -------------------------------*/ protected static function _getSingleton($class) { - $class = Eden_Route::get()->getRouteClass($class, $class); + $class = Eden_Route::i()->getClass()->getRoute($class); if(!isset(self::$_instances[$class])) { $args = func_get_args(); @@ -172,7 +160,7 @@ protected static function _getMultiple($class) { $args = func_get_args(); $class = array_shift($args); - $class = Eden_Route::get()->getRouteClass($class, $class); + $class = Eden_Route::i()->getClass()->getRoute($class); return self::_getInstance($class, $args); } @@ -189,11 +177,15 @@ private static function _getInstance($class, $args) { try { return $reflect->newInstanceArgs($args); } catch(Reflection_Exception $e) { - Eden_Error::get() + Eden_Error::i() ->setMessage(Eden_Error::REFLECTION_ERROR) ->addVariable($class) ->addVariable('new') ->trigger(); } } -} \ No newline at end of file +} + +require_once dirname(__FILE__).'/route.php'; +require_once dirname(__FILE__).'/when.php'; +require_once dirname(__FILE__).'/map.php'; \ No newline at end of file diff --git a/library/eden/collection.php b/library/eden/collection.php index 5e2fc7f..767bbd5 100644 --- a/library/eden/collection.php +++ b/library/eden/collection.php @@ -32,7 +32,7 @@ class Eden_Collection extends Eden_Class implements ArrayAccess, Iterator, Seria -------------------------------*/ /* Get -------------------------------*/ - public static function get(array $data = array()) { + public static function i(array $data = array()) { return self::_getMultiple(__CLASS__,$data); } @@ -51,7 +51,7 @@ public function __call($name, $args) { $value = isset($args[0]) ? $args[0] : NULL; //make a new model - $list = Eden_Model::get(); + $list = Eden_Model::i(); //for each row foreach($this->_list as $i => $row) { //just add the column they want @@ -81,13 +81,13 @@ public function __call($name, $args) { try { return parent::__call($name, $args); } catch(Eden_Error $e) { - Eden_Collection_Error::get($e->getMessage())->trigger(); + Eden_Collection_Error::i($e->getMessage())->trigger(); } } public function __get($name) { //get all rows column values - $list = Eden_Model::get(); + $list = Eden_Model::i(); //for each row foreach($this->_list as $i => $row) { @@ -108,7 +108,7 @@ public function __set($name, $value) { } public function __toString() { - return json_encode($this->getArray()); + return json_encode($this->get()); } /* Public Methods @@ -121,7 +121,7 @@ public function __toString() { */ public function add($row = array()) { //Argument 1 must be an array or Eden_Model - Eden_Collection_Error::get()->argument(1, 'array', $this->_model); + Eden_Collection_Error::i()->argument(1, 'array', $this->_model); //if it's an array if(is_array($row)) { @@ -145,7 +145,7 @@ public function add($row = array()) { */ public function copy($source, $destination) { //Argument Test - Eden_Collection_Error::get() + Eden_Collection_Error::i() ->argument(1, 'string') //Argument 1 must be a string ->argument(2, 'string'); //Argument 2 must be a string @@ -160,7 +160,7 @@ public function copy($source, $destination) { public function cut($index = self::LAST) { //Argument 1 must be a string or integer - Eden_Collection_Error::get()->argument(1, 'string', 'int'); + Eden_Collection_Error::i()->argument(1, 'string', 'int'); //if index is first if($index == self::FIRST) { @@ -190,15 +190,15 @@ public function cut($index = self::LAST) { * @param bool * @return array */ - public function getArray($modified = true) { + public function get($modified = true) { //Argument 1 must be a boolean - Eden_Collection_Error::get()->argument(1, 'bool'); + 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->getData($modified); + $array[$i] = $row->get($modified); } return $array; @@ -263,7 +263,7 @@ public function valid() { */ public function offsetSet($offset, $value) { //Argument 2 must be an array or Eden_Model - Eden_Collection_Error::get()->argument(2, 'array', $this->_model); + Eden_Collection_Error::i()->argument(2, 'array', $this->_model); if(is_array($value)) { //make it a model @@ -295,9 +295,9 @@ public function offsetExists($offset) { * @return bool */ public function offsetUnset($offset) { - $this->_list = Eden_Model::get($this->_list) + $this->_list = Eden_Model::i($this->_list) ->cut($offset) - ->getData(); + ->get(); } /** @@ -361,7 +361,7 @@ class Eden_Collection_Error extends Eden_Error { -------------------------------*/ /* Get -------------------------------*/ - public static function get($message = NULL, $code = 0) { + public static function i($message = NULL, $code = 0) { $class = __CLASS__; return new $class($message, $code); } diff --git a/library/eden/cookie.php b/library/eden/cookie.php index 124483e..8876db7 100755 --- a/library/eden/cookie.php +++ b/library/eden/cookie.php @@ -29,7 +29,7 @@ class Eden_Cookie extends Eden_Class implements ArrayAccess, Iterator { -------------------------------*/ /* Get -------------------------------*/ - public static function get() { + public static function i() { return self::_getSingleton(__CLASS__); } @@ -49,7 +49,7 @@ public static function get() { */ public function set($key, $data = NULL, $expires = 0, $path = NULL, $domain = NULL, $secure = false, $httponly = false) { //argment test - Eden_Cookie_Error::get() + 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 @@ -87,7 +87,7 @@ public function setSecure($key, $data = NULL, $expires = 0, $path = NULL, $domai * @param string|null the domain * @return this */ - public function setData(array $data, $expires = 0, $path = NULL, $domain = NULL, $secure = false, $httponly = false) { + public function set(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); } @@ -105,7 +105,7 @@ public function setData(array $data, $expires = 0, $path = NULL, $domain = NULL, * @return this */ public function setSecureData(array $data, $expires = 0, $path = NULL, $domain = NULL) { - $this->setData($data, $expires, $path, $domain, true, false); + $this->set($data, $expires, $path, $domain, true, false); return $this; } @@ -115,8 +115,8 @@ public function setSecureData(array $data, $expires = 0, $path = NULL, $domain = * @param string|null * @return mixed */ - public function getData($key = NULL) { - Eden_Cookie_Error::get()->argument(1, 'string', 'null'); + public function get($key = NULL) { + Eden_Cookie_Error::i()->argument(1, 'string', 'null'); if(is_null($key)) { return $_COOKIE; @@ -136,7 +136,7 @@ public function getData($key = NULL) { * @return Eden_Cookie */ public function remove($name) { - Eden_Cookie_Error::get()->argument(1, 'string'); + Eden_Cookie_Error::i()->argument(1, 'string'); $this->set($name, NULL, time() - 3600); @@ -271,7 +271,7 @@ class Eden_Cookie_Error extends Eden_Error { -------------------------------*/ /* Get -------------------------------*/ - public static function get($message = NULL, $code = 0) { + public static function i($message = NULL, $code = 0) { $class = __CLASS__; return new $class($message, $code); } diff --git a/library/eden/curl.php b/library/eden/curl.php index f6b37c8..526204b 100644 --- a/library/eden/curl.php +++ b/library/eden/curl.php @@ -1,521 +1,521 @@ - -/* - * 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__).'/class.php'; - -/** - * cURL wrapper - * - * @package Eden - * @category curl - * @author Christian Blanquera - * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ - */ -class Eden_Curl extends Eden_Class implements ArrayAccess { - /* Constants - -------------------------------*/ - /* 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 - -------------------------------*/ - /* Get - -------------------------------*/ - public static function get() { - return self::_getMultiple(__CLASS__); - } - - /* Magic - -------------------------------*/ - public function __call($name, $args) { - if(strpos($name, 'set') === 0) { - $method = substr($name, 3); - - if(isset(self::$_setBoolKeys[$method])) { - Eden_Curl_Error::get()->vargument($name, $args, 1, 'bool'); - $key = self::$_setBoolKeys[$method]; - $this->_options[$key] = $args[0]; - - return $this; - } - - if(isset(self::$_setIntegerKeys[$method])) { - Eden_Curl_Error::get()->vargument($name, $args, 1, 'int'); - $key = self::$_setIntegerKeys[$method]; - $this->_options[$key] = $args[0]; - - return $this; - } - - if(isset(self::$_setStringKeys[$method])) { - Eden_Curl_Error::get()->vargument($name, $args, 1, 'string'); - $key = self::$_setStringKeys[$method]; - $this->_options[$key] = $args[0]; - - return $this; - } - - if(isset(self::$_setArrayKeys[$method])) { - Eden_Curl_Error::get()->vargument($name, $args, 1, 'array'); - $key = self::$_setArrayKeys[$method]; - $this->_options[$key] = $args[0]; - - return $this; - } - - if(isset(self::$_setFileKeys[$method])) { - $key = $this->_setFileKeys[$method]; - $this->_options[$key] = $args[0]; - - return $this; - } - - if(isset(self::$_setCallbackKeys[$method])) { - Eden_Curl_Error::get()->vargument($name, $args, 1, 'array', 'string'); - $key = self::$_setCallbackKeys[$method]; - $this->_options[$key] = $args[0]; - - return $this; - } - } - - parent::__call($name, $args); - } - - /* Public Methods - -------------------------------*/ - /** - * Sets CURLOPT_SSL_VERIFYHOST - * - * @param bool - * @return this - */ - public function verifyHost($on = true) { - Eden_Curl_Error::get()->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::get()->argument(1, 'bool'); - $this->options[CURLOPT_SSL_VERIFYPEER] = $on; - return $this; - } - - /** - * Sets url parameter - * - * @param array|string - * @return this - */ - public function setUrlParameter($key, $value = NULL) { - Eden_Curl_Error::get() - ->argument(1, 'array', 'string') - ->argument(2, 'scalar'); - - if(is_array($key)) { - $this->_param = $key; - return $this; - } - - $this->_param[$key] = $value; - } - - /** - * Sets request headers - * - * @param array|string - * @return this - */ - public function setHeaders($key, $value = NULL) { - Eden_Curl_Error::get() - ->argument(1, 'array', 'string') - ->argument(2, 'scalar','null'); - - if(is_array($key)) { - $this->_headers = $key; - return $this; - } - - $this->_headers[] = $key.': '.$value; - return $this; - } - - /** - * 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; - } - - /** - * 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 JSON - * - * @return array - */ - public function getJsonResponse($assoc = true) { - $this->_meta['response'] = $this->getResponse(); - Eden_Curl_Error::get()->argument(1, 'bool'); - return json_decode($this->_meta['response'], $assoc); - } - - /** - * 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 - * parsed as SimpleXml - * - * @return SimpleXmlElement - */ - public function getSimpleXmlResponse() { - $this->_meta['response'] = $this->getResponse(); - return simplexml_load_string($this->_meta['response']); - } - - /** - * 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; - } - - /** - * Returns the meta of the last call - * - * @return array - */ - public function getMeta($key = NULL) { - Eden_Curl_Error::get()->argument(1, 'string', 'null'); - - if(isset($this->_meta[$key])) { - return $this->_meta[$key]; - } - - return $this->_meta; - } - - /** - * 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)); - } - } - } - - /** - * isset using the ArrayAccess interface - * - * @param number - * @return bool - */ - public function offsetExists($offset) { - return isset($this->_option[$offset]); - } - - /** - * unsets using the ArrayAccess interface - * - * @param number - * @return bool - */ - public function offsetUnset($offset) { - unset($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; - } - - /* Protected Methods - -------------------------------*/ - 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; - } - - protected function _addHeaders() { - if(empty($this->_headers)) { - return $this; - } - - $this->_options[CURLOPT_HTTPHEADER] = $this->_headers; - return $this; - } - - /* Private Methods - -------------------------------*/ -} - -/** - * cUrl Errors - */ -class Eden_Curl_Error extends Eden_Error { - /* Constants - -------------------------------*/ - /* Public Properties - -------------------------------*/ - /* Protected Properties - -------------------------------*/ - /* Private Properties - -------------------------------*/ - /* Get - -------------------------------*/ - public static function get($message = NULL, $code = 0) { - $class = __CLASS__; - return new $class($message, $code); - } - - /* Magic - -------------------------------*/ - /* Public Methods - -------------------------------*/ - /* Protected Methods - -------------------------------*/ - /* Private Methods - -------------------------------*/ + +/* + * 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__).'/class.php'; + +/** + * cURL wrapper + * + * @package Eden + * @category curl + * @author Christian Blanquera + * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ + */ +class Eden_Curl extends Eden_Class implements ArrayAccess { + /* Constants + -------------------------------*/ + /* 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 + -------------------------------*/ + /* Get + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + /* Magic + -------------------------------*/ + public function __call($name, $args) { + if(strpos($name, 'set') === 0) { + $method = substr($name, 3); + + if(isset(self::$_setBoolKeys[$method])) { + Eden_Curl_Error::get()->vargument($name, $args, 1, 'bool'); + $key = self::$_setBoolKeys[$method]; + $this->_options[$key] = $args[0]; + + return $this; + } + + if(isset(self::$_setIntegerKeys[$method])) { + Eden_Curl_Error::get()->vargument($name, $args, 1, 'int'); + $key = self::$_setIntegerKeys[$method]; + $this->_options[$key] = $args[0]; + + return $this; + } + + if(isset(self::$_setStringKeys[$method])) { + Eden_Curl_Error::get()->vargument($name, $args, 1, 'string'); + $key = self::$_setStringKeys[$method]; + $this->_options[$key] = $args[0]; + + return $this; + } + + if(isset(self::$_setArrayKeys[$method])) { + Eden_Curl_Error::get()->vargument($name, $args, 1, 'array'); + $key = self::$_setArrayKeys[$method]; + $this->_options[$key] = $args[0]; + + return $this; + } + + if(isset(self::$_setFileKeys[$method])) { + $key = $this->_setFileKeys[$method]; + $this->_options[$key] = $args[0]; + + return $this; + } + + if(isset(self::$_setCallbackKeys[$method])) { + Eden_Curl_Error::get()->vargument($name, $args, 1, 'array', 'string'); + $key = self::$_setCallbackKeys[$method]; + $this->_options[$key] = $args[0]; + + return $this; + } + } + + parent::__call($name, $args); + } + + /* Public Methods + -------------------------------*/ + /** + * Sets CURLOPT_SSL_VERIFYHOST + * + * @param bool + * @return this + */ + public function verifyHost($on = true) { + Eden_Curl_Error::get()->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::get()->argument(1, 'bool'); + $this->options[CURLOPT_SSL_VERIFYPEER] = $on; + return $this; + } + + /** + * Sets url parameter + * + * @param array|string + * @return this + */ + public function setUrlParameter($key, $value = NULL) { + Eden_Curl_Error::get() + ->argument(1, 'array', 'string') + ->argument(2, 'scalar'); + + if(is_array($key)) { + $this->_param = $key; + return $this; + } + + $this->_param[$key] = $value; + } + + /** + * Sets request headers + * + * @param array|string + * @return this + */ + public function setHeaders($key, $value = NULL) { + Eden_Curl_Error::get() + ->argument(1, 'array', 'string') + ->argument(2, 'scalar','null'); + + if(is_array($key)) { + $this->_headers = $key; + return $this; + } + + $this->_headers[] = $key.': '.$value; + return $this; + } + + /** + * 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; + } + + /** + * 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 JSON + * + * @return array + */ + public function getJsonResponse($assoc = true) { + $this->_meta['response'] = $this->getResponse(); + Eden_Curl_Error::get()->argument(1, 'bool'); + return json_decode($this->_meta['response'], $assoc); + } + + /** + * 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 + * parsed as SimpleXml + * + * @return SimpleXmlElement + */ + public function getSimpleXmlResponse() { + $this->_meta['response'] = $this->getResponse(); + return simplexml_load_string($this->_meta['response']); + } + + /** + * 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; + } + + /** + * Returns the meta of the last call + * + * @return array + */ + public function getMeta($key = NULL) { + Eden_Curl_Error::get()->argument(1, 'string', 'null'); + + if(isset($this->_meta[$key])) { + return $this->_meta[$key]; + } + + return $this->_meta; + } + + /** + * 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)); + } + } + } + + /** + * isset using the ArrayAccess interface + * + * @param number + * @return bool + */ + public function offsetExists($offset) { + return isset($this->_option[$offset]); + } + + /** + * unsets using the ArrayAccess interface + * + * @param number + * @return bool + */ + public function offsetUnset($offset) { + unset($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; + } + + /* Protected Methods + -------------------------------*/ + 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; + } + + protected function _addHeaders() { + if(empty($this->_headers)) { + return $this; + } + + $this->_options[CURLOPT_HTTPHEADER] = $this->_headers; + return $this; + } + + /* Private Methods + -------------------------------*/ +} + +/** + * cUrl Errors + */ +class Eden_Curl_Error extends Eden_Error { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function get($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/error.php b/library/eden/error.php index 63cd2d0..7595ea2 100755 --- a/library/eden/error.php +++ b/library/eden/error.php @@ -62,7 +62,7 @@ class Eden_Error extends Exception { -------------------------------*/ /* Get -------------------------------*/ - public static function get($message = NULL, $code = 0) { + public static function i($message = NULL, $code = 0) { $class = __CLASS__; return new $class($message, $code); } diff --git a/library/eden/error/event.php b/library/eden/error/event.php index d068e65..3ee5add 100755 --- a/library/eden/error/event.php +++ b/library/eden/error/event.php @@ -33,7 +33,7 @@ class Eden_Error_Event extends Eden_Event { -------------------------------*/ /* Get -------------------------------*/ - public static function get() { + public static function i() { return self::_getSingleton(__CLASS__); } diff --git a/library/eden/event.php b/library/eden/event.php index 4e0e30b..386f33e 100755 --- a/library/eden/event.php +++ b/library/eden/event.php @@ -33,7 +33,7 @@ class Eden_Event extends Eden_Class { -------------------------------*/ /* Get -------------------------------*/ - public static function get() { + public static function i() { return self::_getMultiple(__CLASS__); } @@ -52,7 +52,7 @@ public static function get() { * @return this */ public function listen($event, $instance, $method = NULL, $important = true) { - Eden_Event_Error::get() + Eden_Event_Error::i() ->argument(1, 'string') //argument 1 must be string ->argument(2, 'object', 'string') //argument 2 must be object or string ->argument(3, 'null', 'string', 'bool') //argument 3 must be string or null @@ -99,7 +99,7 @@ public function listen($event, $instance, $method = NULL, $important = true) { * @return this */ public function unlisten($event, $instance, $method = NULL) { - Eden_Event_Error::get() + Eden_Event_Error::i() ->argument(1, 'string', 'null') //argument 1 must be string or null ->argument(2, 'object', 'string') //argument 2 must be instance ->argument(3, 'string', 'null'); //argument 3 must be string or null @@ -162,7 +162,7 @@ public function unlisten($event, $instance, $method = NULL) { */ public function trigger($event = NULL) { //argument 1 must be string - Eden_Event_Error::get()->argument(1, 'string', 'null'); + Eden_Event_Error::i()->argument(1, 'string', 'null'); if(is_null($event)) { $trace = debug_backtrace(); @@ -209,7 +209,7 @@ class Eden_Event_Error extends Eden_Error { -------------------------------*/ /* Get -------------------------------*/ - public static function get($message = NULL, $code = 0) { + public static function i($message = NULL, $code = 0) { $class = __CLASS__; return new $class($message, $code); } diff --git a/library/eden/eventbrite/base.php b/library/eden/eventbrite/base.php index b7e70b7..ec6f45d 100644 --- a/library/eden/eventbrite/base.php +++ b/library/eden/eventbrite/base.php @@ -30,7 +30,7 @@ class Eden_Eventbrite_Base extends Eden_Class { -------------------------------*/ /* Get -------------------------------*/ - public static function get($user, $api) { + public static function i($user, $api) { return self::_getMultiple(__CLASS__, $user, $api); } @@ -38,7 +38,7 @@ public static function get($user, $api) { -------------------------------*/ public function __construct($user, $api) { //argument test - Eden_Eventbrite_Error::get() + Eden_Eventbrite_Error::i() ->argument(1, 'string','array') //Argument 1 must be a string or array ->argument(2, 'string'); //Argument 2 must be a string @@ -54,7 +54,7 @@ public function __construct($user, $api) { * @return array */ public function getMeta($key = NULL) { - Eden_Google_Error::get()->argument(1, 'string', 'null'); + Eden_Google_Error::i()->argument(1, 'string', 'null'); if(isset($this->_meta[$key])) { return $this->_meta[$key]; @@ -104,7 +104,7 @@ protected function _getResponse($url, array $query = array()) { $url .= $connector.$query; //set curl - $curl = Eden_Curl::get() + $curl = Eden_Curl::i() ->verifyHost(false) ->verifyPeer(false) ->setUrl($url) diff --git a/library/eden/eventbrite/discount.php b/library/eden/eventbrite/discount.php index 43c8171..eff8122 100644 --- a/library/eden/eventbrite/discount.php +++ b/library/eden/eventbrite/discount.php @@ -31,7 +31,7 @@ class Eden_Eventbrite_Discount extends Eden_Eventbrite_Base { -------------------------------*/ /* Get -------------------------------*/ - public static function get($user, $api) { + public static function i($user, $api) { return self::_getMultiple(__CLASS__, $user, $api); } @@ -41,7 +41,7 @@ public static function get($user, $api) { -------------------------------*/ public function add($event, $code, $amount, $percent, $tickets, $quantity, $start, $end) { //Argument Test - Eden_Eventbrite_Error::get() + Eden_Eventbrite_Error::i() ->argument(1, 'int') //Argument 1 must be an integer ->argument(2, 'string') //Argument 2 must be a string ->argument(3, 'float') //Argument 3 must be a float @@ -82,7 +82,7 @@ public function add($event, $code, $amount, $percent, $tickets, $quantity, $star public function update($id, $code, $amount, $percent, $tickets, $quantity, $start, $end) { //Argument Test - Eden_Eventbrite_Error::get() + Eden_Eventbrite_Error::i() ->argument(1, 'int') //Argument 1 must be an integer ->argument(2, 'string') //Argument 2 must be a string ->argument(3, 'float') //Argument 3 must be a float diff --git a/library/eden/eventbrite/error.php b/library/eden/eventbrite/error.php index 8351751..3739bdb 100644 --- a/library/eden/eventbrite/error.php +++ b/library/eden/eventbrite/error.php @@ -1,56 +1,56 @@ - -/* - * 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. - */ - -/** - * Eventbrite Errors - * - * @package Eden - * @category google - * @author Christian Blanquera - * @version $Id: exception.php 1 2010-01-02 23:06:36Z blanquera $ - */ -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 - -------------------------------*/ - /* Get - -------------------------------*/ - public static function get($message = NULL, $code = 0) { - $class = __CLASS__; - return new $class($message, $code); - } - - /* Magic - -------------------------------*/ - /* Public Methods - -------------------------------*/ - /* Protected Methods - -------------------------------*/ - /* Private Methods - -------------------------------*/ + +/* + * 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. + */ + +/** + * Eventbrite Errors + * + * @package Eden + * @category google + * @author Christian Blanquera + * @version $Id: exception.php 1 2010-01-02 23:06:36Z blanquera $ + */ +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 + -------------------------------*/ + /* 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/eventbrite/event.php b/library/eden/eventbrite/event.php index 0556364..f48a2e3 100644 --- a/library/eden/eventbrite/event.php +++ b/library/eden/eventbrite/event.php @@ -33,7 +33,7 @@ class Eden_Eventbrite_Event extends Eden_Eventbrite_Base { -------------------------------*/ /* Get -------------------------------*/ - public static function get($user, $api) { + public static function i($user, $api) { return self::_getMultiple(__CLASS__, $user, $api); } @@ -43,7 +43,7 @@ public static function get($user, $api) { -------------------------------*/ public function copy($id, $name) { //argument test - Eden_Eventbrite_Error::get() + Eden_Eventbrite_Error::i() ->argument(1, 'numeric') //Argument 1 must be numeric ->argument(2, 'string'); //Argument 2 must be a string @@ -54,7 +54,7 @@ public function copy($id, $name) { public function getDetail($id) { //Argument 1 must be numeric - Eden_Eventbrite_Error::get()->argument(1, 'numeric'); + Eden_Eventbrite_Error::i()->argument(1, 'numeric'); $query = array('id' => $id); @@ -63,7 +63,7 @@ public function getDetail($id) { public function getAttendees($id, $count = 50, $page = 1, $display = NULL, $barcodes = false) { //argument test - $error = Eden_Eventbrite_Error::get() + $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 @@ -85,7 +85,7 @@ public function getAttendees($id, $count = 50, $page = 1, $display = NULL, $barc public function getDiscounts($id) { //Argument 1 must be numeric - Eden_Eventbrite_Error::get()->argument(1, 'numeric'); + Eden_Eventbrite_Error::i()->argument(1, 'numeric'); $query = array('id' => $id); diff --git a/library/eden/eventbrite/event/search.php b/library/eden/eventbrite/event/search.php index ae3f758..578287a 100644 --- a/library/eden/eventbrite/event/search.php +++ b/library/eden/eventbrite/event/search.php @@ -30,7 +30,7 @@ class Eden_Eventbrite_Event_Search extends Eden_Eventbrite_Base { -------------------------------*/ /* Get -------------------------------*/ - public static function get($user, $api) { + public static function i($user, $api) { return self::_getMultiple(__CLASS__, $user, $api); } @@ -40,7 +40,7 @@ public static function get($user, $api) { -------------------------------*/ public function setKeywords($keywords) { //Argument 1 must be a string - Eden_Eventbrite_Error::get()->argument(1, 'string'); + Eden_Eventbrite_Error::i()->argument(1, 'string'); $query['keywords'] = $keywords; @@ -49,7 +49,7 @@ public function setKeywords($keywords) { public function setCategory($category) { //Argument 1 must be a string or array - Eden_Eventbrite_Error::get()->argument(1, 'string', 'array'); + Eden_Eventbrite_Error::i()->argument(1, 'string', 'array'); if(is_array($tickets)) { $tickets = implode(',', $tickets); @@ -62,7 +62,7 @@ public function setCategory($category) { public function setAddress($address) { //Argument 1 must be a string - Eden_Eventbrite_Error::get()->argument(1, 'string'); + Eden_Eventbrite_Error::i()->argument(1, 'string'); $query['address'] = $address; @@ -71,7 +71,7 @@ public function setAddress($address) { public function setCity($city) { //Argument 1 must be a string - Eden_Eventbrite_Error::get()->argument(1, 'string'); + Eden_Eventbrite_Error::i()->argument(1, 'string'); $query['city'] = $city; @@ -80,7 +80,7 @@ public function setCity($city) { public function setRegion($region) { //Argument 1 must be a string - Eden_Eventbrite_Error::get()->argument(1, 'string'); + Eden_Eventbrite_Error::i()->argument(1, 'string'); $query['region'] = $region; @@ -89,7 +89,7 @@ public function setRegion($region) { public function setPostal($postal) { //Argument 1 must be a string or integer - Eden_Eventbrite_Error::get()->argument(1, 'string', 'int'); + Eden_Eventbrite_Error::i()->argument(1, 'string', 'int'); $query['postal_code'] = $postal; @@ -98,7 +98,7 @@ public function setPostal($postal) { public function setCountry($country) { //Argument 1 must be a string - Eden_Eventbrite_Error::get()->argument(1, 'string'); + Eden_Eventbrite_Error::i()->argument(1, 'string'); $query['country'] = $country; @@ -107,7 +107,7 @@ public function setCountry($country) { public function setWithin($within) { //Argument 1 must be a int - Eden_Eventbrite_Error::get()->argument(1, 'int'); + Eden_Eventbrite_Error::i()->argument(1, 'int'); $query['within'] = $within; @@ -116,7 +116,7 @@ public function setWithin($within) { public function setWithinUnit($unit) { //Argument 1 must be a string - Eden_Eventbrite_Error::get()->argument(1, 'string'); + Eden_Eventbrite_Error::i()->argument(1, 'string'); $query['within_unit'] = $unit; @@ -125,7 +125,7 @@ public function setWithinUnit($unit) { public function setLatitude($latitude) { //Argument 1 must be a float - Eden_Eventbrite_Error::get()->argument(1, 'float'); + Eden_Eventbrite_Error::i()->argument(1, 'float'); $query['latitude'] = $latitude; @@ -134,7 +134,7 @@ public function setLatitude($latitude) { public function setLongitude($longitude) { //Argument 1 must be a float - Eden_Eventbrite_Error::get()->argument(1, 'float'); + Eden_Eventbrite_Error::i()->argument(1, 'float'); $query['longitude'] = $longitude; @@ -143,7 +143,7 @@ public function setLongitude($longitude) { public function setDate($date) { //Argument 1 must be a string - Eden_Eventbrite_Error::get()->argument(1, 'string'); + Eden_Eventbrite_Error::i()->argument(1, 'string'); $query['date'] = $date; @@ -152,7 +152,7 @@ public function setDate($date) { public function setDateCreated($date) { //Argument 1 must be a string - Eden_Eventbrite_Error::get()->argument(1, 'string'); + Eden_Eventbrite_Error::i()->argument(1, 'string'); $query['date_created'] = $date; @@ -161,7 +161,7 @@ public function setDateCreated($date) { public function setDateModified($date) { //Argument 1 must be a string - Eden_Eventbrite_Error::get()->argument(1, 'string'); + Eden_Eventbrite_Error::i()->argument(1, 'string'); $query['date_modified'] = $date; @@ -170,7 +170,7 @@ public function setDateModified($date) { public function setOrganizer($organizer) { //Argument 1 must be a string - Eden_Eventbrite_Error::get()->argument(1, 'string'); + Eden_Eventbrite_Error::i()->argument(1, 'string'); $query['organizer'] = $organizer; @@ -179,7 +179,7 @@ public function setOrganizer($organizer) { public function setMax($max) { //Argument 1 must be a int - Eden_Eventbrite_Error::get()->argument(1, 'int'); + Eden_Eventbrite_Error::i()->argument(1, 'int'); if($max > 100) { $max = 100; @@ -198,7 +198,7 @@ public function countOnly() { public function sort($column) { //Argument 1 must be a string - Eden_Eventbrite_Error::get()->argument(1, 'string'); + Eden_Eventbrite_Error::i()->argument(1, 'string'); if(in_array($column, $this->_validSort)) { $query['sort_by'] = $column; @@ -209,7 +209,7 @@ public function sort($column) { public function setPage($page) { //Argument 1 must be a int - Eden_Eventbrite_Error::get()->argument(1, 'int'); + Eden_Eventbrite_Error::i()->argument(1, 'int'); $query['page'] = $page; @@ -218,7 +218,7 @@ public function setPage($page) { public function setSince($since) { //Argument 1 must be a int - Eden_Eventbrite_Error::get()->argument(1, 'int'); + Eden_Eventbrite_Error::i()->argument(1, 'int'); $query['since_id'] = $since; @@ -227,7 +227,7 @@ public function setSince($since) { public function setTracking($tracking) { //Argument 1 must be a string - Eden_Eventbrite_Error::get()->argument(1, 'string'); + Eden_Eventbrite_Error::i()->argument(1, 'string'); $query['tracking_link'] = $tracking; diff --git a/library/eden/eventbrite/event/set.php b/library/eden/eventbrite/event/set.php index d66e60c..5508d11 100644 --- a/library/eden/eventbrite/event/set.php +++ b/library/eden/eventbrite/event/set.php @@ -31,7 +31,7 @@ class Eden_Eventbrite_Event_Set extends Eden_Eventbrite_Base { -------------------------------*/ /* Get -------------------------------*/ - public static function get($user, $api) { + public static function i($user, $api) { return self::_getMultiple(__CLASS__, $user, $api); } @@ -41,7 +41,7 @@ public static function get($user, $api) { -------------------------------*/ public function setId($id) { //Argument 1 must be int - Eden_Eventbrite_Error::get()->argument(1, 'int'); + Eden_Eventbrite_Error::i()->argument(1, 'int'); $query['event_id'] = $id; @@ -50,7 +50,7 @@ public function setId($id) { public function setTitle($title) { //Argument 1 must be a string - Eden_Eventbrite_Error::get()->argument(1, 'string'); + Eden_Eventbrite_Error::i()->argument(1, 'string'); $query['title'] = $title; @@ -59,7 +59,7 @@ public function setTitle($title) { public function setDescription($description) { //Argument 1 must be a string - Eden_Eventbrite_Error::get()->argument(1, 'string'); + Eden_Eventbrite_Error::i()->argument(1, 'string'); $query['description'] = $description; @@ -68,7 +68,7 @@ public function setDescription($description) { public function setStart($start) { //Argument 1 must be a string - Eden_Eventbrite_Error::get()->argument(1, 'string', 'int'); + Eden_Eventbrite_Error::i()->argument(1, 'string', 'int'); if(is_string($start)) { $start = strtotime($start); @@ -83,7 +83,7 @@ public function setStart($start) { public function setEnd($end) { //Argument 1 must be a string - Eden_Eventbrite_Error::get()->argument(1, 'string', 'int'); + Eden_Eventbrite_Error::i()->argument(1, 'string', 'int'); if(is_string($end)) { $end = strtotime($end); @@ -98,7 +98,7 @@ public function setEnd($end) { public function setTimezone($zone) { //Argument 1 must be a string - Eden_Eventbrite_Error::get()->argument(1, 'string'); + Eden_Eventbrite_Error::i()->argument(1, 'string'); $query['timezone'] = $zone; @@ -119,7 +119,7 @@ public function isPrivate() { public function setUrl($url) { //Argument 1 must be a string - Eden_Eventbrite_Error::get()->argument(1, 'string'); + Eden_Eventbrite_Error::i()->argument(1, 'string'); $query['personalized_url'] = $url; @@ -128,7 +128,7 @@ public function setUrl($url) { public function setVenue($venue) { //Argument 1 must be a numeric - Eden_Eventbrite_Error::get()->argument(1, 'numeric'); + Eden_Eventbrite_Error::i()->argument(1, 'numeric'); $query['venue_id'] = $venue; @@ -137,7 +137,7 @@ public function setVenue($venue) { public function setOrganizer($organizer) { //Argument 1 must be a numeric - Eden_Eventbrite_Error::get()->argument(1, 'numeric'); + Eden_Eventbrite_Error::i()->argument(1, 'numeric'); $query['organizer_id'] = $organizer; @@ -146,7 +146,7 @@ public function setOrganizer($organizer) { public function setCapacity($capacity) { //Argument 1 must be a numeric - Eden_Eventbrite_Error::get()->argument(1, 'numeric'); + Eden_Eventbrite_Error::i()->argument(1, 'numeric'); $query['capacity'] = $capacity; @@ -155,7 +155,7 @@ public function setCapacity($capacity) { public function setCurrency($currency) { //Argument 1 must be a string - Eden_Eventbrite_Error::get()->argument(1, 'string'); + Eden_Eventbrite_Error::i()->argument(1, 'string'); $query['currency'] = $currency; @@ -164,7 +164,7 @@ public function setCurrency($currency) { public function setStatus($status) { //Argument 1 must be a string - Eden_Eventbrite_Error::get()->argument(1, 'string'); + Eden_Eventbrite_Error::i()->argument(1, 'string'); $query['status'] = $status; @@ -173,7 +173,7 @@ public function setStatus($status) { public function setHeader($html) { //Argument 1 must be a string - Eden_Eventbrite_Error::get()->argument(1, 'string'); + Eden_Eventbrite_Error::i()->argument(1, 'string'); $query['custom_header'] = $html; @@ -182,7 +182,7 @@ public function setHeader($html) { public function setFooter($html) { //Argument 1 must be a string - Eden_Eventbrite_Error::get()->argument(1, 'string'); + Eden_Eventbrite_Error::i()->argument(1, 'string'); $query['custom_footer'] = $html; @@ -191,7 +191,7 @@ public function setFooter($html) { public function setBackground($color) { //Argument 1 must be a string - Eden_Eventbrite_Error::get()->argument(1, 'string'); + Eden_Eventbrite_Error::i()->argument(1, 'string'); $query['background_color'] = $color; @@ -200,7 +200,7 @@ public function setBackground($color) { public function setTextColor($color) { //Argument 1 must be a string - Eden_Eventbrite_Error::get()->argument(1, 'string'); + Eden_Eventbrite_Error::i()->argument(1, 'string'); $query['text_color'] = $color; @@ -209,7 +209,7 @@ public function setTextColor($color) { public function setLinkColor($color) { //Argument 1 must be a string - Eden_Eventbrite_Error::get()->argument(1, 'string'); + Eden_Eventbrite_Error::i()->argument(1, 'string'); $query['link_color'] = $color; @@ -218,7 +218,7 @@ public function setLinkColor($color) { public function setTitleColor($color) { //Argument 1 must be a string - Eden_Eventbrite_Error::get()->argument(1, 'string'); + Eden_Eventbrite_Error::i()->argument(1, 'string'); $query['title_text_color'] = $color; @@ -227,7 +227,7 @@ public function setTitleColor($color) { public function setBoxBackground($color) { //Argument 1 must be a string - Eden_Eventbrite_Error::get()->argument(1, 'string'); + Eden_Eventbrite_Error::i()->argument(1, 'string'); $query['box_background_color'] = $color; @@ -236,7 +236,7 @@ public function setBoxBackground($color) { public function setBoxColor($color) { //Argument 1 must be a string - Eden_Eventbrite_Error::get()->argument(1, 'string'); + Eden_Eventbrite_Error::i()->argument(1, 'string'); $query['box_text_color'] = $color; @@ -245,7 +245,7 @@ public function setBoxColor($color) { public function setBorderColor($color) { //Argument 1 must be a string - Eden_Eventbrite_Error::get()->argument(1, 'string'); + Eden_Eventbrite_Error::i()->argument(1, 'string'); $query['box_border_color'] = $color; @@ -254,7 +254,7 @@ public function setBorderColor($color) { public function setHeaderBackground($color) { //Argument 1 must be a string - Eden_Eventbrite_Error::get()->argument(1, 'string'); + Eden_Eventbrite_Error::i()->argument(1, 'string'); $query['box_header_background_color'] = $color; @@ -263,7 +263,7 @@ public function setHeaderBackground($color) { public function setHeaderColor($color) { //Argument 1 must be a string - Eden_Eventbrite_Error::get()->argument(1, 'string'); + Eden_Eventbrite_Error::i()->argument(1, 'string'); $query['box_header_text_color'] = $color; @@ -272,20 +272,20 @@ public function setHeaderColor($color) { public function send() { if(!isset($this->_query['title'])) { - Eden_Eventbrite_Error::get()->setMessage(Eden_Eventbrite_Error::TITLE_NOT_SET)->trigger(); + Eden_Eventbrite_Error::i()->setMessage(Eden_Eventbrite_Error::TITLE_NOT_SET)->trigger(); } if(!isset($this->_query['start_date'])) { - Eden_Eventbrite_Error::get()->setMessage(Eden_Eventbrite_Error::START_NOT_SET)->trigger(); + Eden_Eventbrite_Error::i()->setMessage(Eden_Eventbrite_Error::START_NOT_SET)->trigger(); } if(!isset($this->_query['end_date'])) { - Eden_Eventbrite_Error::get()->setMessage(Eden_Eventbrite_Error::END_NOT_SET)->trigger(); + Eden_Eventbrite_Error::i()->setMessage(Eden_Eventbrite_Error::END_NOT_SET)->trigger(); } if(!isset($this->_query['timezone'])) { - Eden_Eventbrite_Error::get()->setMessage(Eden_Eventbrite_Error::ZONE_NOT_SET)->trigger(); + Eden_Eventbrite_Error::i()->setMessage(Eden_Eventbrite_Error::ZONE_NOT_SET)->trigger(); } $url = self::URL_NEW; @@ -294,27 +294,27 @@ public function send() { $url = self::URL_UPDATE; if(!isset($this->_query['privacy'])) { - Eden_Eventbrite_Error::get()->setMessage(Eden_Eventbrite_Error::PRIVACY_NOT_SET)->trigger(); + Eden_Eventbrite_Error::i()->setMessage(Eden_Eventbrite_Error::PRIVACY_NOT_SET)->trigger(); } if(!isset($this->_query['personalized_url'])) { - Eden_Eventbrite_Error::get()->setMessage(Eden_Eventbrite_Error::URL_NOT_SET)->trigger(); + Eden_Eventbrite_Error::i()->setMessage(Eden_Eventbrite_Error::URL_NOT_SET)->trigger(); } if(!isset($this->_query['organizer_id'])) { - Eden_Eventbrite_Error::get()->setMessage(Eden_Eventbrite_Error::ORGANIZER_NOT_SET)->trigger(); + Eden_Eventbrite_Error::i()->setMessage(Eden_Eventbrite_Error::ORGANIZER_NOT_SET)->trigger(); } if(!isset($this->_query['venue_id'])) { - Eden_Eventbrite_Error::get()->setMessage(Eden_Eventbrite_Error::VENUE_NOT_SET)->trigger(); + Eden_Eventbrite_Error::i()->setMessage(Eden_Eventbrite_Error::VENUE_NOT_SET)->trigger(); } if(!isset($this->_query['capacity'])) { - Eden_Eventbrite_Error::get()->setMessage(Eden_Eventbrite_Error::CAPACITY_NOT_SET)->trigger(); + Eden_Eventbrite_Error::i()->setMessage(Eden_Eventbrite_Error::CAPACITY_NOT_SET)->trigger(); } if(!isset($this->_query['currency'])) { - Eden_Eventbrite_Error::get()->setMessage(Eden_Eventbrite_Error::CURRENCY_NOT_SET)->trigger(); + Eden_Eventbrite_Error::i()->setMessage(Eden_Eventbrite_Error::CURRENCY_NOT_SET)->trigger(); } } diff --git a/library/eden/eventbrite/organizer.php b/library/eden/eventbrite/organizer.php index 6c2ba5b..7f0843b 100644 --- a/library/eden/eventbrite/organizer.php +++ b/library/eden/eventbrite/organizer.php @@ -30,7 +30,7 @@ class Eden_Eventbrite_Event_Organizer extends Eden_Eventbrite_Base { -------------------------------*/ /* Get -------------------------------*/ - public static function get($user, $api) { + public static function i($user, $api) { return self::_getMultiple(__CLASS__, $user, $api); } @@ -40,7 +40,7 @@ public static function get($user, $api) { -------------------------------*/ public function add($name, $description = NULL) { //Argument Test - Eden_Eventbrite_Error::get() + Eden_Eventbrite_Error::i() ->argument(1, 'string') //Argument 1 must be a string ->argument(2, 'string'); //Argument 2 must be a string @@ -53,7 +53,7 @@ public function add($name, $description = NULL) { public function update($id, $name, $description = NULL) { //Argument Test - Eden_Eventbrite_Error::get() + 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'); //Argument 3 must be a string @@ -68,7 +68,7 @@ public function update($id, $name, $description = NULL) { public function getEvents($id) { //Argument 1 must be an int - Eden_Eventbrite_Error::get()->argument(1, 'int'); + Eden_Eventbrite_Error::i()->argument(1, 'int'); $query = array('id' => $id); diff --git a/library/eden/eventbrite/payment.php b/library/eden/eventbrite/payment.php index 2080994..3de6816 100644 --- a/library/eden/eventbrite/payment.php +++ b/library/eden/eventbrite/payment.php @@ -30,7 +30,7 @@ class Eden_Eventbrite_Payment extends Eden_Eventbrite_Base { -------------------------------*/ /* Get -------------------------------*/ - public static function get($user, $api) { + public static function i($user, $api) { return self::_getMultiple(__CLASS__, $user, $api); } @@ -40,7 +40,7 @@ public static function get($user, $api) { -------------------------------*/ public function setEvent($id) { //Argument 1 must be int - Eden_Eventbrite_Error::get()->argument(1, 'int'); + Eden_Eventbrite_Error::i()->argument(1, 'int'); $query['event_id'] = $id; @@ -55,7 +55,7 @@ public function acceptPaypal() { public function setPaypalEmail($email) { //Argument 1 must be a string - Eden_Eventbrite_Error::get()->argument(1, 'string'); + Eden_Eventbrite_Error::i()->argument(1, 'string'); $query['paypal_email'] = $email; @@ -70,7 +70,7 @@ public function acceptGoogle() { public function setGoogleMerchantId($id) { //Argument 1 must be a string - Eden_Eventbrite_Error::get()->argument(1, 'string'); + Eden_Eventbrite_Error::i()->argument(1, 'string'); $query['google_merchant_id'] = $id; @@ -79,7 +79,7 @@ public function setGoogleMerchantId($id) { public function setGoogleMerchantKey($key) { //Argument 1 must be a string - Eden_Eventbrite_Error::get()->argument(1, 'string'); + Eden_Eventbrite_Error::i()->argument(1, 'string'); $query['google_merchant_key'] = $key; @@ -94,7 +94,7 @@ public function acceptCheck() { public function setCheckInstructions($check) { //Argument 1 must be a string - Eden_Eventbrite_Error::get()->argument(1, 'string'); + Eden_Eventbrite_Error::i()->argument(1, 'string'); $query['insrtructions_check'] = $check; @@ -109,7 +109,7 @@ public function acceptCash() { public function setCashInstructions($check) { //Argument 1 must be a string - Eden_Eventbrite_Error::get()->argument(1, 'string'); + Eden_Eventbrite_Error::i()->argument(1, 'string'); $query['insrtructions_cash'] = $check; @@ -124,7 +124,7 @@ public function acceptInovice() { public function setInvoiceInstructions($check) { //Argument 1 must be a string - Eden_Eventbrite_Error::get()->argument(1, 'string'); + Eden_Eventbrite_Error::i()->argument(1, 'string'); $query['insrtructions_invoice'] = $check; diff --git a/library/eden/eventbrite/ticket.php b/library/eden/eventbrite/ticket.php index dd0e3fb..7f717a8 100644 --- a/library/eden/eventbrite/ticket.php +++ b/library/eden/eventbrite/ticket.php @@ -31,7 +31,7 @@ class Eden_Eventbrite_Ticket extends Eden_Eventbrite_Base { -------------------------------*/ /* Get -------------------------------*/ - public static function get($user, $api) { + public static function i($user, $api) { return self::_getMultiple(__CLASS__, $user, $api); } @@ -41,7 +41,7 @@ public static function get($user, $api) { -------------------------------*/ public function setEvent($id) { //Argument 1 must be numeric - Eden_Eventbrite_Error::get()->argument(1, 'numeric'); + Eden_Eventbrite_Error::i()->argument(1, 'numeric'); $this->_query['event_id'] = $id; return $this; @@ -49,7 +49,7 @@ public function setEvent($id) { public function setName($name) { //Argument 1 must be numeric - Eden_Eventbrite_Error::get()->argument(1, 'string'); + Eden_Eventbrite_Error::i()->argument(1, 'string'); $this->_query['name'] = $name; return $this; @@ -57,7 +57,7 @@ public function setName($name) { public function setPrice($price) { //Argument 1 must be float - Eden_Eventbrite_Error::get()->argument(1, 'float'); + Eden_Eventbrite_Error::i()->argument(1, 'float'); $this->_query['price'] = $price; return $this; @@ -65,7 +65,7 @@ public function setPrice($price) { public function setQuantity($quantity) { //Argument 1 must be an integer - Eden_Eventbrite_Error::get()->argument(1, 'int'); + Eden_Eventbrite_Error::i()->argument(1, 'int'); $this->_query['quantity'] = $quantity; return $this; @@ -79,7 +79,7 @@ public function setDonation() { public function setDescription($description) { //Argument 1 must be a string - Eden_Eventbrite_Error::get()->argument(1, 'string'); + Eden_Eventbrite_Error::i()->argument(1, 'string'); $this->_query['description'] = $description; return $this; @@ -87,7 +87,7 @@ public function setDescription($description) { public function setStart($start) { //Argument 1 must be an integer or string - Eden_Eventbrite_Error::get()->argument(1, 'int', 'string'); + Eden_Eventbrite_Error::i()->argument(1, 'int', 'string'); //if start is a string if(is_string($start)) { //then convert it to unixcode @@ -103,7 +103,7 @@ public function setStart($start) { public function setEnd($end) { //Argument 1 must be an integer or string - Eden_Eventbrite_Error::get()->argument(1, 'int', 'string'); + Eden_Eventbrite_Error::i()->argument(1, 'int', 'string'); //if start is a string if(is_string($start)) { //then convert it to unixcode @@ -125,7 +125,7 @@ public function setFee() { public function setMin($quantity) { //Argument 1 must be an integer - Eden_Eventbrite_Error::get()->argument(1, 'int'); + Eden_Eventbrite_Error::i()->argument(1, 'int'); if($min < 0) { $min = 0; } @@ -136,7 +136,7 @@ public function setMin($quantity) { public function setMax($max) { //Argument 1 must be an integer - Eden_Eventbrite_Error::get()->argument(1, 'int'); + Eden_Eventbrite_Error::i()->argument(1, 'int'); if($max < 1) { $max = 1; } @@ -148,7 +148,7 @@ public function setMax($max) { public function setHide($hide) { //Argument 1 must be a boolean - Eden_Eventbrite_Error::get()->argument(1, 'bool'); + Eden_Eventbrite_Error::i()->argument(1, 'bool'); //if the string hide is show if($hide) { @@ -164,20 +164,20 @@ public function setHide($hide) { public function add() { if(!isset($this->_query['event_id'])) { - Eden_Eventbrite_Error::get()->setMessage(Eden_Eventbrite_Error::EVENT_NOT_SET)->trigger(); + Eden_Eventbrite_Error::i()->setMessage(Eden_Eventbrite_Error::EVENT_NOT_SET)->trigger(); } if(!isset($this->_query['name'])) { - Eden_Eventbrite_Error::get()->setMessage(Eden_Eventbrite_Error::NAME_NOT_SET)->trigger(); + Eden_Eventbrite_Error::i()->setMessage(Eden_Eventbrite_Error::NAME_NOT_SET)->trigger(); } if(!isset($this->_query['price'])) { - Eden_Eventbrite_Error::get()->setMessage(Eden_Eventbrite_Error::PRICE_NOT_SET)->trigger(); + Eden_Eventbrite_Error::i()->setMessage(Eden_Eventbrite_Error::PRICE_NOT_SET)->trigger(); } if(!isset($this->_query['quantity'])) { - Eden_Eventbrite_Error::get()->setMessage(Eden_Eventbrite_Error::QUANTITY_NOT_SET)->trigger(); + Eden_Eventbrite_Error::i()->setMessage(Eden_Eventbrite_Error::QUANTITY_NOT_SET)->trigger(); } $query = $this->_query; @@ -190,20 +190,20 @@ public function add() { public function update() { if(!isset($this->_query['event_id'])) { - Eden_Eventbrite_Error::get()->setMessage(Eden_Eventbrite_Error::EVENT_NOT_SET)->trigger(); + Eden_Eventbrite_Error::i()->setMessage(Eden_Eventbrite_Error::EVENT_NOT_SET)->trigger(); } if(!isset($this->_query['name'])) { - Eden_Eventbrite_Error::get()->setMessage(Eden_Eventbrite_Error::NAME_NOT_SET)->trigger(); + Eden_Eventbrite_Error::i()->setMessage(Eden_Eventbrite_Error::NAME_NOT_SET)->trigger(); } if(!isset($this->_query['price'])) { - Eden_Eventbrite_Error::get()->setMessage(Eden_Eventbrite_Error::PRICE_NOT_SET)->trigger(); + Eden_Eventbrite_Error::i()->setMessage(Eden_Eventbrite_Error::PRICE_NOT_SET)->trigger(); } if(!isset($this->_query['quantity'])) { - Eden_Eventbrite_Error::get()->setMessage(Eden_Eventbrite_Error::QUANTITY_NOT_SET)->trigger(); + Eden_Eventbrite_Error::i()->setMessage(Eden_Eventbrite_Error::QUANTITY_NOT_SET)->trigger(); } return $this->_getJsonResponse(self::URL_UPDATE, $this->_query); diff --git a/library/eden/eventbrite/user.php b/library/eden/eventbrite/user.php index 223703f..3e8674a 100644 --- a/library/eden/eventbrite/user.php +++ b/library/eden/eventbrite/user.php @@ -39,7 +39,7 @@ class Eden_Eventbrite_User extends Eden_Eventbrite_Base { -------------------------------*/ /* Get -------------------------------*/ - public static function get($user, $api) { + public static function i($user, $api) { return self::_getMultiple(__CLASS__, $user, $api); } @@ -49,7 +49,7 @@ public static function get($user, $api) { -------------------------------*/ public function getDetail($id = NULL, $email = NULL) { //argument test - Eden_Eventbrite_Error::get() + Eden_Eventbrite_Error::i() ->argument(1, 'int', 'null') //Argument 1 must be a integer or null ->argument(2, 'string', 'null'); //Argument 2 must be a string or null @@ -71,7 +71,7 @@ public function getDetail($id = NULL, $email = NULL) { public function getEvents($user = NULL, $hide = NULL, $status = NULL, $order = NULL) { //argument test - Eden_Eventbrite_Error::get() + 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 @@ -147,7 +147,7 @@ public function getEvents($user = NULL, $hide = NULL, $status = NULL, $order = N public function getOrganizers($user, $pass) { //argument test - Eden_Eventbrite_Error::get() + Eden_Eventbrite_Error::i() ->argument(1, 'string') //Argument 1 must be a string ->argument(2, 'string'); //Argument 2 must be a string @@ -165,7 +165,7 @@ public function getTicket(){ public function getVenue($user, $pass) { //argument test - Eden_Eventbrite_Error::get() + Eden_Eventbrite_Error::i() ->argument(1, 'string') //Argument 1 must be a string ->argument(2, 'string'); //Argument 2 must be a string @@ -178,7 +178,7 @@ public function getVenue($user, $pass) { public function add($user, $pass) { //argument test - $error = Eden_Eventbrite_Error::get() + $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 @@ -195,7 +195,7 @@ public function add($user, $pass) { public function update($email = NULL, $pass = NULL) { //argument test - Eden_Eventbrite_Error::get() + 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 diff --git a/library/eden/eventbrite/venue.php b/library/eden/eventbrite/venue.php index 2e21f6c..6abe055 100644 --- a/library/eden/eventbrite/venue.php +++ b/library/eden/eventbrite/venue.php @@ -31,7 +31,7 @@ class Eden_Eventbrite_Venue extends Eden_Eventbrite_Base { -------------------------------*/ /* Get -------------------------------*/ - public static function get($user, $api) { + public static function i($user, $api) { return self::_getMultiple(__CLASS__, $user, $api); } /* Magic @@ -40,7 +40,7 @@ public static function get($user, $api) { -------------------------------*/ public function add($organizer, $venue, $country, $region, $address1 = NULL, $address2 = NULL, $city = NULL, $postal = NULL) { //argument test - Eden_Eventbrite_Error::get() + Eden_Eventbrite_Error::i() ->argument(1, 'string') //Argument must be a string ->argument(2, 'string') //Argument msut be a string ->argument(3, 'string') //Argument must be a string @@ -85,7 +85,7 @@ public function add($organizer, $venue, $country, $region, $address1 = NULL, $ad public function update($id, $venue, $address1 = NULL, $address2 = NULL, $city = NULL, $region = NULL, $postal = NULL, $country = NULL){ //argument test - Eden_Eventbrite_Error::get() + Eden_Eventbrite_Error::i() ->argument(1, 'int') //Argument must be a integer ->argument(2, 'string') //Argument must be a string ->argument(3, 'string', 'null') //Argument must be a string or null diff --git a/library/eden/facebook.php b/library/eden/facebook.php new file mode 100644 index 0000000..a07ce8b --- /dev/null +++ b/library/eden/facebook.php @@ -0,0 +1,89 @@ + +/* + * 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. + */ + +/** + * Facebook + * + * @package Eden + * @category tool + * @author Christian Blanquera + * @version $Id: tool.php 3 2010-01-06 01:16:54Z blanquera $ + */ +class Eden_Facebook extends Eden_Class { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function i() { + return self::_getSingleton(__CLASS__); + } + + /* Magic + -------------------------------*/ + /* Public Methods + -------------------------------*/ + /** + * Returns Facebook Auth + * + * @param string + * @param string + * @return Eden_Facebook_Auth + */ + public function auth($key, $secret) { + Eden_Facebook_Error::i() + ->argument(1, 'string') + ->argument(1, 'string'); + + return Eden_Facebook_Auth::i($key, $secret); + } + + /** + * 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); + } + + /** + * Returns Facebook Post + * + * @param string + * @return Eden_Facebook_Post + */ + public function post($token) { + Eden_Facebook_Error::i()->argument(1, 'string'); + return Eden_Facebook_Post::i($token); + } + + /** + * 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); + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/facebook/auth.php b/library/eden/facebook/auth.php index 619a130..0ad559c 100644 --- a/library/eden/facebook/auth.php +++ b/library/eden/facebook/auth.php @@ -1,96 +1,96 @@ - -/* - * 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.st. - */ - -/** - * Facebook Authentication - * - * @package Eden - * @subpackage file - * @category path - * @author Christian Blanquera - * @version $Id: model.php 4 2010-01-06 04:41:07Z blanquera $ - */ -class Eden_Facebook_Auth extends Eden_Class { - /* Constants - -------------------------------*/ - const AUTHENTICATION_USER_URL = 'https://www.facebook.com/dialog/oauth'; - const AUTHENTICATION_APP_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; - - /* Private Properties - -------------------------------*/ - /* Get - -------------------------------*/ - public static function get($key, $secret) { - return self::_getMultiple(__CLASS__, $key, $secret); - } - - /* Magic - -------------------------------*/ - public function __construct($key, $secret) { - $this->_key = $key; - $this->_secret = $secret; - } - - /* Public Methods - -------------------------------*/ - public function getLoginUrl($redirect, array $scope = array(), $state = NULL) { - $parameters = array( - 'client_id' => $this->_key, - 'redirect_uri' => $redirect, - 'scope' => implode(',',$scope), - 'state' => $state); - - if(empty($scope)) { - unset($parameters['scope']); - } - - if(!$state) { - unset($parameters['state']); - } - - $parameters = http_build_query($parameters); - - return self::AUTHENTICATION_USER_URL.'?'.$parameters; - } - - public function getToken($code, $redirect) { - $parameters = array( - 'client_id' => $this->_key, - 'client_secret' => $this->_secret, - 'redirect_uri' => $redirect, - 'code' => $code); - - $parameters = http_build_query($parameters); - $url = self::AUTHENTICATION_APP_URL.'?'.$parameters; - - $response = Eden_Curl::get() - ->setUrl($url) - ->setConnectTimeout(10) - ->setTimeout(60) - ->setUserAgent(self::USER_AGENT) - ->setHeaders('Expect') - ->verifyPeer(false) - ->getQueryResponse(); - - return $response['access_token']; - } - - /* Protected Methods - -------------------------------*/ - /* Private Methods - -------------------------------*/ + +/* + * 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.st. + */ + +/** + * Facebook Authentication + * + * @package Eden + * @subpackage file + * @category path + * @author Christian Blanquera + * @version $Id: model.php 4 2010-01-06 04:41:07Z blanquera $ + */ +class Eden_Facebook_Auth extends Eden_Class { + /* Constants + -------------------------------*/ + const AUTHENTICATION_USER_URL = 'https://www.facebook.com/dialog/oauth'; + const AUTHENTICATION_APP_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; + + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function i($key, $secret) { + return self::_getMultiple(__CLASS__, $key, $secret); + } + + /* Magic + -------------------------------*/ + public function __construct($key, $secret) { + $this->_key = $key; + $this->_secret = $secret; + } + + /* Public Methods + -------------------------------*/ + public function getLoginUrl($redirect, array $scope = array(), $state = NULL) { + $parameters = array( + 'client_id' => $this->_key, + 'redirect_uri' => $redirect, + 'scope' => implode(',',$scope), + 'state' => $state); + + if(empty($scope)) { + unset($parameters['scope']); + } + + if(!$state) { + unset($parameters['state']); + } + + $parameters = http_build_query($parameters); + + return self::AUTHENTICATION_USER_URL.'?'.$parameters; + } + + public function getToken($code, $redirect) { + $parameters = array( + 'client_id' => $this->_key, + 'client_secret' => $this->_secret, + 'redirect_uri' => $redirect, + 'code' => $code); + + $parameters = http_build_query($parameters); + $url = self::AUTHENTICATION_APP_URL.'?'.$parameters; + + $response = Eden_Curl::i() + ->setUrl($url) + ->setConnectTimeout(10) + ->setTimeout(60) + ->setUserAgent(self::USER_AGENT) + ->setHeaders('Expect') + ->verifyPeer(false) + ->getQueryResponse(); + + return $response['access_token']; + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ } \ No newline at end of file diff --git a/library/eden/facebook/graph.php b/library/eden/facebook/graph.php index ffc1593..9c484b4 100644 --- a/library/eden/facebook/graph.php +++ b/library/eden/facebook/graph.php @@ -32,7 +32,7 @@ class Eden_Facebook_Graph extends Eden_Class { -------------------------------*/ /* Get -------------------------------*/ - public static function get($token) { + public static function i($token) { return self::_getMultiple(__CLASS__, $token); } @@ -53,7 +53,7 @@ public function getObject($id = 'me', $connection = NULL, array $query = array() if($auth) { if(!$this->_token) { - Eden_Facebook_Error::get() + Eden_Facebook_Error::i() ->setMessage(Eden_Facebook_Error::REQUIRES_AUTH) ->addVariable($url) ->trigger(); @@ -70,7 +70,7 @@ public function getObject($id = 'me', $connection = NULL, array $query = array() $object = json_decode($object, true); if (isset($object['error'])) { - Eden_Facebook_Error::get() + Eden_Facebook_Error::i() ->setMessage(Eden_Facebook_Error::GRAPH_FAILED) ->addVariable($url) ->addVariable($object['error']['type']) @@ -202,7 +202,7 @@ public function addPost($message, $id = 'me', $link = NULL, $picture = NULL, $url = self::GRAPH_URL.$id.'/feed'; if(!$this->_token) { - Eden_Facebook_Error::get() + Eden_Facebook_Error::i() ->setMessage(Eden_Facebook_Error::REQUIRES_AUTH) ->addVariable($url) ->trigger(); @@ -248,7 +248,7 @@ public function addComment($id, $message) { $url = self::GRAPH_URL.$id.'/comments'; if(!$this->_token) { - Eden_Facebook_Error::get() + Eden_Facebook_Error::i() ->setMessage(Eden_Facebook_Error::REQUIRES_AUTH) ->addVariable($url) ->trigger(); @@ -270,7 +270,7 @@ public function like($id) { $url = self::GRAPH_URL.$id.'/likes'; if(!$this->_token) { - Eden_Facebook_Error::get() + Eden_Facebook_Error::i() ->setMessage(Eden_Facebook_Error::REQUIRES_AUTH) ->addVariable($url) ->trigger(); @@ -291,7 +291,7 @@ public function addNote($id, $subject, $message) { $url = self::GRAPH_URL.$id.'/notes'; if(!$this->_token) { - Eden_Facebook_Error::get() + Eden_Facebook_Error::i() ->setMessage(Eden_Facebook_Error::REQUIRES_AUTH) ->addVariable($url) ->trigger(); @@ -313,7 +313,7 @@ public function addEvent($name, $start, $end) { $url = self::GRAPH_URL.$id.'/events'; if(!$this->_token) { - Eden_Facebook_Error::get() + Eden_Facebook_Error::i() ->setMessage(Eden_Facebook_Error::REQUIRES_AUTH) ->addVariable($url) ->trigger(); @@ -335,7 +335,7 @@ public function attendEvent($id) { $url = self::GRAPH_URL.$id.'/attending'; if(!$this->_token) { - Eden_Facebook_Error::get() + Eden_Facebook_Error::i() ->setMessage(Eden_Facebook_Error::REQUIRES_AUTH) ->addVariable($url) ->trigger(); @@ -356,7 +356,7 @@ public function maybeEvent($id) { $url = self::GRAPH_URL.$id.'/maybe'; if(!$this->_token) { - Eden_Facebook_Error::get() + Eden_Facebook_Error::i() ->setMessage(Eden_Facebook_Error::REQUIRES_AUTH) ->addVariable($url) ->trigger(); @@ -377,7 +377,7 @@ public function declineEvent($id) { $url = self::GRAPH_URL.$id.'/declined'; if(!$this->_token) { - Eden_Facebook_Error::get() + Eden_Facebook_Error::i() ->setMessage(Eden_Facebook_Error::REQUIRES_AUTH) ->addVariable($url) ->trigger(); @@ -398,7 +398,7 @@ public function addLink($id, $url, $message = NULL, $name = NULL, $description = $url = self::GRAPH_URL.$id.'/links'; if(!$this->_token) { - Eden_Facebook_Error::get() + Eden_Facebook_Error::i() ->setMessage(Eden_Facebook_Error::REQUIRES_AUTH) ->addVariable($url) ->trigger(); @@ -440,7 +440,7 @@ public function addAlbum($id, $name, $message) { $url = self::GRAPH_URL.$id.'/albums'; if(!$this->_token) { - Eden_Facebook_Error::get() + Eden_Facebook_Error::i() ->setMessage(Eden_Facebook_Error::REQUIRES_AUTH) ->addVariable($url) ->trigger(); @@ -464,7 +464,7 @@ public function addCheckin($id, $message, $coordinates, $place, $tags) { $url = self::GRAPH_URL.$id.'/checkins'; if(!$this->_token) { - Eden_Facebook_Error::get() + Eden_Facebook_Error::i() ->setMessage(Eden_Facebook_Error::REQUIRES_AUTH) ->addVariable($url) ->trigger(); @@ -502,9 +502,9 @@ public function addCheckin($id, $message, $coordinates, $place, $tags) { -------------------------------*/ protected function _call($url, array $post = array()) { //Argument 1 must be a string - Eden_Facebook_Error::get()->argument(1, 'string'); + Eden_Facebook_Error::i()->argument(1, 'string'); - return Eden_Curl::get() + return Eden_Curl::i() ->setUrl($url) ->setConnectTimeout(10) ->setFollowLocation(true) diff --git a/library/eden/facebook/post.php b/library/eden/facebook/post.php index 50baaab..5c5e7c8 100644 --- a/library/eden/facebook/post.php +++ b/library/eden/facebook/post.php @@ -1,207 +1,207 @@ - -/* - * 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. - */ - -/** - * Facebook post - * - * @package Eden - * @category facebook - * @author Christian Blanquera - * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ - */ -class Eden_Facebook_Post extends Eden_Class { - /* Constants - -------------------------------*/ - /* Public Properties - -------------------------------*/ - /* Protected Properties - -------------------------------*/ - protected $_token = NULL; - protected $_message = NULL; - protected $_link = NULL; - protected $_picture = NULL; - protected $_video = NULL; - protected $_title = NULL; - protected $_description = NULL; - protected $_icon = NULL; - - /* Private Properties - -------------------------------*/ - /* Get - -------------------------------*/ - public static function get($token) { - return self::_getMultiple(__CLASS__, $token); - } - - /* Magic - -------------------------------*/ - public function __construct($token) { - //Argument 1 must be a string - Eden_Facebook_Error::get()->argument(1, 'string'); - - $this->_token = $token; - } - - /* Public Methods - -------------------------------*/ - /** - * sets the message to your post - * - * @param string - * @return this - */ - public function setMessage($message) { - //Argument 1 must be a string - Eden_Facebook_Error::get()->argument(1, 'string'); - - $this->_message = $message; - return $this; - } - - public function setTitle($title){ - //Argument 1 must be a string - Eden_Facebook_Error::get()->argument(1, 'string'); - - $this->_title = $title; - return $this; - } - - public function setDescription($description){ - //Argument 1 must be a string - Eden_Facebook_Error::get()->argument(1, 'string'); - - $this->_description = $description; - return $this; - } - - public function setIcon($url){ - //Argument 1 must be a string - Eden_Facebook_Error::get()->argument(1, 'string'); - - $this->_icon = $url; - return $this; - } - - /** - * sets the link to your post - * - * @param string - * @param string|null - * @param string|null - * @return this - */ - public function setLink($url) { - //Argument 1 must be a string - Eden_Facebook_Error::get()->argument(1, 'string'); - - $this->_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::get()->argument(1, 'string'); - - $this->_picture = $url; - 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::get()->argument(1, 'string'); - - $this->_video = $url; - return $this; - } - - /** - * sends the post to facebook - * - * @return this - */ - public function send() { - //post variable must be array - $post = array(); - - //if there is a name set it into post - if($this->_title) { - $post['name'] = $this->_title; - } - - if($this->_icon) { - $post['icon'] = $this->_icon; - } - - //if there is a description set it into post - if($this->_description) { - $post['description'] = $this->_description; - } - - //if there is a message set it into post - if($this->_message) { - $post['message'] = $this->_message; - } - - //if there is a link set it into post - if($this->_link) { - $post['link'] = $this->_link; - } - - //if there is a picture set it into post - if($this->_picture) { - $post['picture'] = $this->_picture; - } - - //if there is a video set it into post - if($this->_video) { - $post['source'] = $this->_video; - } - - print_r($post); - - //get the facebook graph url - $url = Eden_Facebook_Graph::GRAPH_URL.$id.'/feed'; - $query = array('access_token' => $this->_token); - $url .= '?'.http_build_query($query); - - //send it into curl - $response = Eden_Curl::get() - ->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 - ->when(!empty($post)) //if post is not empty - ->setPost(true) //set post to true - ->setPostFields(http_build_query($post)) //set post fields - ->endWhen() //endif/endwhen - ->getJsonResponse(); //get the json response - print_r($response); - return $response['id']; //return the id - } - - /* Protected Methods - -------------------------------*/ - /* Private Methods - -------------------------------*/ + +/* + * 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. + */ + +/** + * Facebook post + * + * @package Eden + * @category facebook + * @author Christian Blanquera + * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ + */ +class Eden_Facebook_Post extends Eden_Class { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_token = NULL; + protected $_message = NULL; + protected $_link = NULL; + protected $_picture = NULL; + protected $_video = NULL; + protected $_title = NULL; + protected $_description = NULL; + protected $_icon = NULL; + + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function i($token) { + return self::_getMultiple(__CLASS__, $token); + } + + /* Magic + -------------------------------*/ + public function __construct($token) { + //Argument 1 must be a string + Eden_Facebook_Error::i()->argument(1, 'string'); + + $this->_token = $token; + } + + /* Public Methods + -------------------------------*/ + /** + * sets the message to your post + * + * @param string + * @return this + */ + public function setMessage($message) { + //Argument 1 must be a string + Eden_Facebook_Error::i()->argument(1, 'string'); + + $this->_message = $message; + return $this; + } + + public function setTitle($title){ + //Argument 1 must be a string + Eden_Facebook_Error::i()->argument(1, 'string'); + + $this->_title = $title; + return $this; + } + + public function setDescription($description){ + //Argument 1 must be a string + Eden_Facebook_Error::i()->argument(1, 'string'); + + $this->_description = $description; + return $this; + } + + public function setIcon($url){ + //Argument 1 must be a string + Eden_Facebook_Error::i()->argument(1, 'string'); + + $this->_icon = $url; + return $this; + } + + /** + * sets the link to your post + * + * @param string + * @param string|null + * @param string|null + * @return this + */ + public function setLink($url) { + //Argument 1 must be a string + Eden_Facebook_Error::i()->argument(1, 'string'); + + $this->_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, 'string'); + + $this->_picture = $url; + 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, 'string'); + + $this->_video = $url; + return $this; + } + + /** + * sends the post to facebook + * + * @return this + */ + public function send() { + //post variable must be array + $post = array(); + + //if there is a name set it into post + if($this->_title) { + $post['name'] = $this->_title; + } + + if($this->_icon) { + $post['icon'] = $this->_icon; + } + + //if there is a description set it into post + if($this->_description) { + $post['description'] = $this->_description; + } + + //if there is a message set it into post + if($this->_message) { + $post['message'] = $this->_message; + } + + //if there is a link set it into post + if($this->_link) { + $post['link'] = $this->_link; + } + + //if there is a picture set it into post + if($this->_picture) { + $post['picture'] = $this->_picture; + } + + //if there is a video set it into post + if($this->_video) { + $post['source'] = $this->_video; + } + + print_r($post); + + //get the facebook graph url + $url = Eden_Facebook_Graph::GRAPH_URL.$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 + ->when(!empty($post)) //if post is not empty + ->setPost(true) //set post to true + ->setPostFields(http_build_query($post)) //set post fields + ->endWhen() //endif/endwhen + ->getJsonResponse(); //get the json response + print_r($response); + return $response['id']; //return the id + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ } \ No newline at end of file diff --git a/library/eden/file.php b/library/eden/file.php index 1002aa5..13d86df 100644 --- a/library/eden/file.php +++ b/library/eden/file.php @@ -32,7 +32,7 @@ class Eden_File extends Eden_Path { -------------------------------*/ /* Get -------------------------------*/ - public static function get($path) { + public static function i($path) { return self::_getMultiple(__CLASS__, $path); } @@ -46,7 +46,7 @@ public static function get($path) { * @return string */ public function getName() { - return basename($this->_path); + return basename($this->_data); } /** @@ -55,7 +55,7 @@ public function getName() { * @return string */ public function getFolder() { - return dirname($this->_path); + return dirname($this->_data); } /** @@ -64,7 +64,7 @@ public function getFolder() { * @return string */ public function getBase() { - $pathInfo = pathinfo($this->_path); + $pathInfo = pathinfo($this->_data); return $pathInfo['filename']; } @@ -74,7 +74,7 @@ public function getBase() { * @return string */ public function getExtension() { - $pathInfo = pathinfo($this->_path); + $pathInfo = pathinfo($this->_data); if(!isset($pathInfo['extension'])) { return NULL; @@ -91,7 +91,7 @@ public function getExtension() { public function getData() { $this->absolute(); - return include($this->_path); + return include($this->_data); } /** @@ -104,15 +104,15 @@ public function getContent() { $this->absolute(); //if the pat is not a real file - if(!is_file($this->_path)) { + if(!is_file($this->_data)) { //throw an exception - Eden_File_Error::get() + Eden_File_Error::i() ->setMessage(Eden_File_Error::PATH_IS_NOT_FILE) - ->addVariable($this->_path) + ->addVariable($this->_data) ->trigger(); } - return file_get_contents($this->_path); + return file_get_contents($this->_data); } /** @@ -126,14 +126,14 @@ public function getMime() { //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->_path); + 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->_path); + $mime = finfo_file($resource, $this->_data); finfo_close($finfo); return $mime; @@ -163,7 +163,7 @@ public function getMime() { public function getSize() { $this->absolute(); - return filesize($this->_path); + return filesize($this->_data); } /** @@ -174,7 +174,7 @@ public function getSize() { public function getTime() { $this->absolute(); - return filemtime($this->_path); + return filemtime($this->_data); } /** @@ -184,7 +184,7 @@ public function getTime() { * @return bool */ public function isFile() { - return file_exists($this->_path); + return file_exists($this->_data); } /** @@ -195,11 +195,11 @@ public function isFile() { */ public function setContent($content) { //argument 1 must be string - Eden_File_Error::get()->argument(1, 'string'); + Eden_File_Error::i()->argument(1, 'string'); $this->absolute(); - file_put_contents($this->_path, $content); + file_put_contents($this->_data, $content); return $this; } @@ -221,7 +221,7 @@ public function setData($variable) { * @return bool */ public function touch() { - touch($this->_path); + touch($this->_data); return $this; } @@ -235,9 +235,9 @@ public function remove() { $this->absolute(); //if it's a file - if(is_file($this->_path)) { + if(is_file($this->_data)) { //remove it - unlink($this->_path); + unlink($this->_data); return $this; } diff --git a/library/eden/file/error.php b/library/eden/file/error.php index c8ac5ba..18c7f26 100755 --- a/library/eden/file/error.php +++ b/library/eden/file/error.php @@ -28,7 +28,7 @@ class Eden_File_Error extends Eden_Path_Error { -------------------------------*/ /* Get -------------------------------*/ - public static function get($message = NULL, $code = 0) { + public static function i($message = NULL, $code = 0) { $class = __CLASS__; return new $class($message, $code); } diff --git a/library/eden/folder.php b/library/eden/folder.php index 69fa58a..558c832 100644 --- a/library/eden/folder.php +++ b/library/eden/folder.php @@ -30,7 +30,7 @@ class Eden_Folder extends Eden_Path { -------------------------------*/ /* Get -------------------------------*/ - public static function get($path) { + public static function i($path) { return self::_getMultiple(__CLASS__, $path); } @@ -48,13 +48,13 @@ 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::get(Eden_Folder_Exception::CHMOD_IS_INVALID)->trigger(); + Eden_Folder_Error::i(Eden_Folder_Exception::CHMOD_IS_INVALID)->trigger(); } //if it's not a directory - if(!is_dir($this->_path)) { + if(!is_dir($this->_data)) { //then make it - mkdir($this->_path, $chmod, true); + mkdir($this->_data, $chmod, true); } return $this; @@ -109,7 +109,7 @@ public function getName() { */ public function getFiles($regex = NULL, $recursive = false) { //argument test - $error = Eden_Folder_Error::get() + $error = Eden_Folder_Error::i() ->argument(1, 'string', 'null') //argument 1 must be a string ->argument(2, 'bool'); //argument 2 must be a boolean @@ -117,18 +117,18 @@ public function getFiles($regex = NULL, $recursive = false) { $files = array(); - if ($handle = opendir($this->_path)) { + if ($handle = opendir($this->_data)) { //for each file while (false !== ($file = readdir($handle))) { // If this is infact a file - if(filetype($this->_path . '/' . $file) == 'file' + if(filetype($this->_data . '/' . $file) == 'file' && (!$regex || preg_match($regex, $file))) { //add it - $files[] = Eden_File::get($this->_path . '/' . $file); + $files[] = Eden_File::i($this->_data . '/' . $file); // recursive and this is infact a directory } else if($recursive && $file != '.' && $file != '..' - && filetype($this->_path .'/'. $file) == 'dir') { - $subfiles = self::get($this->_path.'/'.$file); + && filetype($this->_data .'/'. $file) == 'dir') { + $subfiles = self::i($this->_data.'/'.$file); $files = array_merge($files, $subfiles->getFiles($regex, $recursive)); } } @@ -147,7 +147,7 @@ public function getFiles($regex = NULL, $recursive = false) { */ public function getFolders($regex = NULL, $recursive = false) { //argument test - Eden_Folder_Error::get() + Eden_Folder_Error::i() ->argument(1, 'string', 'null') //argument 1 must be a string ->argument(2, 'bool'); //argument 2 must be a boolean @@ -155,19 +155,19 @@ public function getFolders($regex = NULL, $recursive = false) { $folders = array(); - if($handle = opendir($this->_path)) { + 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->_path .'/'. $folder) == 'dir' + && filetype($this->_data .'/'. $folder) == 'dir' && (!$regex || preg_match($regex, $folder))) { //add it - $folders[] = Eden_Folder::get($this->_path . '/' . $folder); + $folders[] = Eden_Folder::i($this->_data . '/' . $folder); if($recursive) { - $subfolders = Eden_Folder::get($this->_path.'/'.$folder); + $subfolders = Eden_Folder::i($this->_data.'/'.$folder); $folders = array_merge($folders, $subfolders->getFolders($regex, $recursive)); } @@ -186,7 +186,7 @@ public function getFolders($regex = NULL, $recursive = false) { * @return bool */ public function removeFolders($regex = NULL) { - Eden_Folder_Error::get()->argument(1, 'string', 'null'); //argument 1 must be a string + Eden_Folder_Error::i()->argument(1, 'string', 'null'); //argument 1 must be a string $this->absolute(); @@ -212,7 +212,7 @@ public function removeFolders($regex = NULL) { * @return bool */ public function removeFiles($regex = NULL) { - Eden_Folder_Error::get()->argument(1, 'string', 'null'); //argument 1 must be a string + Eden_Folder_Error::i()->argument(1, 'string', 'null'); //argument 1 must be a string //get the files $files = $this->getFiles($regex); @@ -237,15 +237,15 @@ public function removeFiles($regex = NULL) { * @return bool */ public function isFolder($path = NULL) { - Eden_Folder_Error::get()->argument(1, 'string', 'null'); //argument 1 must be a string + 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->_path.'/'.$path); + return is_dir($this->_data.'/'.$path); } - return is_dir($this->_path); + return is_dir($this->_data); } /** @@ -255,7 +255,7 @@ public function isFolder($path = NULL) { * @return bool */ public function isFile() { - return file_exists($this->_path); + return file_exists($this->_data); } /* Protected Methods @@ -278,7 +278,7 @@ class Eden_Folder_Error extends Eden_Error { -------------------------------*/ /* Get -------------------------------*/ - public static function get($message = NULL, $code = 0) { + public static function i($message = NULL, $code = 0) { $class = __CLASS__; return new $class($message, $code); } diff --git a/library/eden/getsatisfaction/base.php b/library/eden/getsatisfaction/base.php index fc40434..33e9d6d 100644 --- a/library/eden/getsatisfaction/base.php +++ b/library/eden/getsatisfaction/base.php @@ -40,7 +40,7 @@ class Eden_Getsatisfaction_Base extends Eden_Oauth_Base { -------------------------------*/ public function __construct($key, $secret) { //argument test - Eden_Getsatisfaction_Error::get() + Eden_Getsatisfaction_Error::i() ->argument(1, 'string') //Argument 1 must be a string ->argument(2, 'string'); //Argument 2 must be a string @@ -58,10 +58,10 @@ public function __construct($key, $secret) { */ public function getLoginUrl($redirect) { //Argument 1 must be a string - Eden_Getsatisfaction_Error::get()->argument(1, 'string'); + Eden_Getsatisfaction_Error::i()->argument(1, 'string'); //get the token - $token = Eden_Oauth::get() + $token = Eden_Oauth::i() ->getConsumer(self::REQUEST_URL, $this->_key, $this->_secret) ->useAuthorization() ->setMethodToPost() @@ -104,11 +104,11 @@ public function getLoginUrl($redirect) { */ public function getAccessToken($token, $secret) { //argument test - Eden_Google_Error::get() + Eden_Google_Error::i() ->argument(1, 'string') //Argument 1 must be a string ->argument(2, 'string'); //Argument 2 must be a string - return Eden_Oauth::get() + return Eden_Oauth::i() ->getConsumer(self::ACCESS_URL, $this->_key, $this->_secret) ->useAuthorization() ->setMethodToPost() @@ -138,7 +138,7 @@ public function setAccessToken($token, $secret) { * @return array */ public function getMeta($key = NULL) { - Eden_Google_Error::get()->argument(1, 'string', 'null'); + Eden_Google_Error::i()->argument(1, 'string', 'null'); if(isset($this->_meta[$key])) { return $this->_meta[$key]; @@ -150,7 +150,7 @@ public function getMeta($key = NULL) { /* Protected Methods -------------------------------*/ protected function _getResponse($url, array $query = array()) { - $rest = Eden_Oauth::get() + $rest = Eden_Oauth::i() ->getConsumer($url, $this->_key, $this->_secret) ->setHeaders(self::VERSION_HEADER, self::GDATA_VERSION) ->setToken($this->_accessToken, $this->_accessSecret) @@ -164,7 +164,7 @@ protected function _getResponse($url, array $query = array()) { } protected function _post($url, $query = array(), $jsonEncode = false) { - $rest = Eden_Oauth::get() + $rest = Eden_Oauth::i() ->getConsumer($url, $this->_key, $this->_secret) ->setToken($this->_accessToken, $this->_accessSecret) ->setMethodToPost() diff --git a/library/eden/getsatisfaction/company.php b/library/eden/getsatisfaction/company.php index b64ebf8..0763922 100644 --- a/library/eden/getsatisfaction/company.php +++ b/library/eden/getsatisfaction/company.php @@ -34,7 +34,7 @@ class Eden_GetSatisfaction_Company extends Eden_Getsatisfaction_Base { -------------------------------*/ /* Get -------------------------------*/ - public static function get($key, $secret) { + public static function i($key, $secret) { return self::_getMultiple(__CLASS__, $key, $secret); } @@ -43,28 +43,28 @@ public static function get($key, $secret) { /* Public Methods -------------------------------*/ public function setActivity($company) { - Eden_Getsatisfaction_Error::get()->argument(1, 'string', 'numeric'); + Eden_Getsatisfaction_Error::i()->argument(1, 'string', 'numeric'); $this->_url = sprintf(self::URL_ACTIVITY, $company); return $this; } public function setUser($user) { - Eden_Getsatisfaction_Error::get()->argument(1, 'string', 'numeric'); + Eden_Getsatisfaction_Error::i()->argument(1, 'string', 'numeric'); $this->_url = sprintf(self::URL_PEOPLE, $user); return $this; } public function setProduct($product) { - Eden_Getsatisfaction_Error::get()->argument(1, 'string', 'numeric'); + Eden_Getsatisfaction_Error::i()->argument(1, 'string', 'numeric'); $this->_url = sprintf(self::URL_PRODUCT, $product); return $this; } public function setKeyword($keyword) { - Eden_Getsatisfaction_Error::get()->argument(1, 'string'); + Eden_Getsatisfaction_Error::i()->argument(1, 'string'); $this->_query['query'] = $keyword; @@ -102,7 +102,7 @@ public function sortByAlphabet() { } public function setPage($page = 0) { - Eden_Getsatisfaction_Error::get()->argument(1, 'int'); + Eden_Getsatisfaction_Error::i()->argument(1, 'int'); if($page < 0) { $page = 0; @@ -114,7 +114,7 @@ public function setPage($page = 0) { } public function setLimit($limit = 10) { - Eden_Getsatisfaction_Error::get()->argument(1, 'int'); + Eden_Getsatisfaction_Error::i()->argument(1, 'int'); if($limit < 0) { $limit = 10; diff --git a/library/eden/getsatisfaction/detail.php b/library/eden/getsatisfaction/detail.php index 051556c..bd8baad 100644 --- a/library/eden/getsatisfaction/detail.php +++ b/library/eden/getsatisfaction/detail.php @@ -28,7 +28,7 @@ class Eden_GetSatisfaction_Detail extends Eden_GetSatisfaction_Base { -------------------------------*/ /* Get -------------------------------*/ - public static function get($key, $secret) { + public static function i($key, $secret) { return self::_getMultiple(__CLASS__, $key, $secret); } @@ -37,7 +37,7 @@ public static function get($key, $secret) { /* Public Methods -------------------------------*/ public function getTopic($topic) { - Eden_Getsatisfaction_Error::get()->argument(1, 'string', 'int'); + Eden_Getsatisfaction_Error::i()->argument(1, 'string', 'int'); return $this->_getResponse(sprintf(self::URL, $topic)); } diff --git a/library/eden/getsatisfaction/error.php b/library/eden/getsatisfaction/error.php index ab1274b..10f947f 100644 --- a/library/eden/getsatisfaction/error.php +++ b/library/eden/getsatisfaction/error.php @@ -26,7 +26,7 @@ class Eden_Getsatisfaction_Error extends Eden_Error { -------------------------------*/ /* Get -------------------------------*/ - public static function get($message = NULL, $code = 0) { + public static function i($message = NULL, $code = 0) { $class = __CLASS__; return new $class($message, $code); } diff --git a/library/eden/getsatisfaction/oauth.php b/library/eden/getsatisfaction/oauth.php index 8237c08..69ff42a 100644 --- a/library/eden/getsatisfaction/oauth.php +++ b/library/eden/getsatisfaction/oauth.php @@ -29,7 +29,7 @@ class Eden_Getsatisfaction_Oauth extends Eden_Getsatisfaction_Base { -------------------------------*/ /* Get -------------------------------*/ - public static function get($key, $secret) { + public static function i($key, $secret) { return self::_getMultiple(__CLASS__, $key, $secret); } diff --git a/library/eden/getsatisfaction/people.php b/library/eden/getsatisfaction/people.php index 6329f8c..39b4fc9 100644 --- a/library/eden/getsatisfaction/people.php +++ b/library/eden/getsatisfaction/people.php @@ -34,7 +34,7 @@ class Eden_GetSatisfaction_People extends Eden_GetSatisfaction_Base { -------------------------------*/ /* Get -------------------------------*/ - public static function get($key, $secret) { + public static function i($key, $secret) { return self::_getMultiple(__CLASS__, $key, $secret); } @@ -43,28 +43,28 @@ public static function get($key, $secret) { /* Public Methods -------------------------------*/ public function setCompany($company) { - Eden_Getsatisfaction_Error::get()->argument(1, 'string', 'numeric'); + Eden_Getsatisfaction_Error::i()->argument(1, 'string', 'numeric'); $this->_url = sprintf(self::URL_COMPANY, $company); return $this; } public function setEmployee($company) { - Eden_Getsatisfaction_Error::get()->argument(1, 'string', 'numeric'); + Eden_Getsatisfaction_Error::i()->argument(1, 'string', 'numeric'); $this->_url = sprintf(self::URL_EMPLOYEE, $company); return $this; } public function setTopic($topic) { - Eden_Getsatisfaction_Error::get()->argument(1, 'string', 'numeric'); + Eden_Getsatisfaction_Error::i()->argument(1, 'string', 'numeric'); $this->_url = sprintf(self::URL_TOPIC, $topic); return $this; } public function setKeyword($keyword) { - Eden_Getsatisfaction_Error::get()->argument(1, 'string'); + Eden_Getsatisfaction_Error::i()->argument(1, 'string'); $this->_query['query'] = $keyword; @@ -72,7 +72,7 @@ public function setKeyword($keyword) { } public function setPage($page = 0) { - Eden_Getsatisfaction_Error::get()->argument(1, 'int'); + Eden_Getsatisfaction_Error::i()->argument(1, 'int'); if($page < 0) { $page = 0; @@ -84,7 +84,7 @@ public function setPage($page = 0) { } public function setLimit($limit = 10) { - Eden_Getsatisfaction_Error::get()->argument(1, 'int'); + Eden_Getsatisfaction_Error::i()->argument(1, 'int'); if($limit < 0) { $limit = 10; diff --git a/library/eden/getsatisfaction/post.php b/library/eden/getsatisfaction/post.php index a0335b6..b318af2 100644 --- a/library/eden/getsatisfaction/post.php +++ b/library/eden/getsatisfaction/post.php @@ -28,7 +28,7 @@ class Eden_Getsatisfaction_Post extends Eden_Getsatisfaction_Base { -------------------------------*/ /* Get -------------------------------*/ - public static function get($key, $secret) { + public static function i($key, $secret) { return self::_getMultiple(__CLASS__, $key, $secret); } @@ -72,7 +72,7 @@ public function setUpdate() { } public function setTags($tags) { - Eden_Getsatisfaction_Error::get()->argument(1, 'string', 'array'); + Eden_Getsatisfaction_Error::i()->argument(1, 'string', 'array'); if(is_array($tags)) { $tags = implode(',', $tags); @@ -87,7 +87,7 @@ public function setOverwriteKeywords() { } public function setProducts($products) { - Eden_Getsatisfaction_Error::get()->argument(1, 'string', 'array'); + Eden_Getsatisfaction_Error::i()->argument(1, 'string', 'array'); if(is_array($products)) { $tags = implode(',', $products); @@ -98,7 +98,7 @@ public function setProducts($products) { } public function setFeeling($feeling) { - Eden_Getsatisfaction_Error::get()->argument(1, 'string'); + Eden_Getsatisfaction_Error::i()->argument(1, 'string'); $this->_query['emotitag']['feeling'] = $feeling; return $this; @@ -125,7 +125,7 @@ public function setIndifferentFace() { } public function setIntensity($intensity) { - Eden_Getsatisfaction_Error::get()->argument(1, 'int'); + Eden_Getsatisfaction_Error::i()->argument(1, 'int'); if($intensity < 0) { $intensity = 0; @@ -138,7 +138,7 @@ public function setIntensity($intensity) { } public function add($company) { - Eden_Getsatisfaction_Error::get()->argument(1, 'string', 'numeric'); + Eden_Getsatisfaction_Error::i()->argument(1, 'string', 'numeric'); $url = sprintf(Eden_Getsatisfaction_Topic::URL_COMPANY, $company); @@ -146,7 +146,7 @@ public function add($company) { } public function edit($topic) { - Eden_Getsatisfaction_Error::get()->argument(1, 'string', 'numeric'); + Eden_Getsatisfaction_Error::i()->argument(1, 'string', 'numeric'); $url = sprintf(Eden_GetSatisfaction_Detail::URL, $topic); diff --git a/library/eden/getsatisfaction/product.php b/library/eden/getsatisfaction/product.php index 644660f..e2cff6e 100644 --- a/library/eden/getsatisfaction/product.php +++ b/library/eden/getsatisfaction/product.php @@ -43,7 +43,7 @@ class Eden_GetSatisfaction_Product extends Eden_GetSatisfaction_Base { -------------------------------*/ /* Get -------------------------------*/ - public static function get($key, $secret) { + public static function i($key, $secret) { return self::_getMultiple(__CLASS__, $key, $secret); } @@ -52,28 +52,28 @@ public static function get($key, $secret) { /* Public Methods -------------------------------*/ public function setCompany($company) { - Eden_Getsatisfaction_Error::get()->argument(1, 'string', 'numeric'); + Eden_Getsatisfaction_Error::i()->argument(1, 'string', 'numeric'); $this->_url = sprintf(self::URL_COMPANY, $company); return $this; } public function setUser($user) { - Eden_Getsatisfaction_Error::get()->argument(1, 'string', 'numeric'); + Eden_Getsatisfaction_Error::i()->argument(1, 'string', 'numeric'); $this->_url = sprintf(self::URL_PEOPLE, $user); return $this; } public function setTopic($topic) { - Eden_Getsatisfaction_Error::get()->argument(1, 'string', 'numeric'); + Eden_Getsatisfaction_Error::i()->argument(1, 'string', 'numeric'); $this->_url = sprintf(self::URL_TOPIC, $topic); return $this; } public function setKeyword($keyword) { - Eden_Getsatisfaction_Error::get()->argument(1, 'string'); + Eden_Getsatisfaction_Error::i()->argument(1, 'string'); $this->_query['query'] = $keyword; @@ -96,7 +96,7 @@ public function sortByAlphabet() { } public function setPage($page = 0) { - Eden_Getsatisfaction_Error::get()->argument(1, 'int'); + Eden_Getsatisfaction_Error::i()->argument(1, 'int'); if($page < 0) { $page = 0; @@ -108,7 +108,7 @@ public function setPage($page = 0) { } public function setLimit($limit = 10) { - Eden_Getsatisfaction_Error::get()->argument(1, 'int'); + Eden_Getsatisfaction_Error::i()->argument(1, 'int'); if($limit < 0) { $limit = 10; diff --git a/library/eden/getsatisfaction/replies.php b/library/eden/getsatisfaction/replies.php index 46da272..61b81b4 100644 --- a/library/eden/getsatisfaction/replies.php +++ b/library/eden/getsatisfaction/replies.php @@ -34,7 +34,7 @@ class Eden_Getsatisfaction_Replies extends Eden_Getsatisfaction_Base { -------------------------------*/ /* Get -------------------------------*/ - public static function get($key, $secret) { + public static function i($key, $secret) { return self::_getMultiple(__CLASS__, $key, $secret); } @@ -43,14 +43,14 @@ public static function get($key, $secret) { /* Public Methods -------------------------------*/ public function setUser($user) { - Eden_Getsatisfaction_Error::get()->argument(1, 'string', 'numeric'); + Eden_Getsatisfaction_Error::i()->argument(1, 'string', 'numeric'); $this->_url = sprintf(self::URL_PEOPLE, $user); return $this; } public function setTopic($topic) { - Eden_Getsatisfaction_Error::get()->argument(1, 'string', 'numeric'); + Eden_Getsatisfaction_Error::i()->argument(1, 'string', 'numeric'); $this->_url = sprintf(self::URL_TOPIC, $topic); return $this; @@ -81,7 +81,7 @@ public function filterFlatPromoted() { } public function setPage($page = 0) { - Eden_Getsatisfaction_Error::get()->argument(1, 'int'); + Eden_Getsatisfaction_Error::i()->argument(1, 'int'); if($page < 0) { $page = 0; @@ -93,7 +93,7 @@ public function setPage($page = 0) { } public function setLimit($limit = 10) { - Eden_Getsatisfaction_Error::get()->argument(1, 'int'); + Eden_Getsatisfaction_Error::i()->argument(1, 'int'); if($limit < 0) { $limit = 10; @@ -113,7 +113,7 @@ public function getList() { } public function reply($topic, $content, $face = NULL, $feeling = NULL, $intensity = NULL) { - Eden_Getsatisfaction_Error::get() + Eden_Getsatisfaction_Error::i() ->argument(1, 'string', 'numeric') ->argument(2, 'string') ->argument(3, 'string', 'null') diff --git a/library/eden/getsatisfaction/tag.php b/library/eden/getsatisfaction/tag.php index f09d30b..7907e5c 100644 --- a/library/eden/getsatisfaction/tag.php +++ b/library/eden/getsatisfaction/tag.php @@ -33,7 +33,7 @@ class Eden_GetSatisfaction_Tag extends Eden_GetSatisfaction_Base { -------------------------------*/ /* Get -------------------------------*/ - public static function get($key, $secret) { + public static function i($key, $secret) { return self::_getMultiple(__CLASS__, $key, $secret); } @@ -42,21 +42,21 @@ public static function get($key, $secret) { /* Public Methods -------------------------------*/ public function setCompany($company) { - Eden_Getsatisfaction_Error::get()->argument(1, 'string', 'numeric'); + Eden_Getsatisfaction_Error::i()->argument(1, 'string', 'numeric'); $this->_url = sprintf(self::URL_COMPANY, $company); return $this; } public function setTopic($topic) { - Eden_Getsatisfaction_Error::get()->argument(1, 'string', 'numeric'); + Eden_Getsatisfaction_Error::i()->argument(1, 'string', 'numeric'); $this->_url = sprintf(self::URL_TOPIC, $topic); return $this; } public function setPage($page = 0) { - Eden_Getsatisfaction_Error::get()->argument(1, 'int'); + Eden_Getsatisfaction_Error::i()->argument(1, 'int'); if($page < 0) { $page = 0; @@ -68,7 +68,7 @@ public function setPage($page = 0) { } public function setLimit($limit = 10) { - Eden_Getsatisfaction_Error::get()->argument(1, 'int'); + Eden_Getsatisfaction_Error::i()->argument(1, 'int'); if($limit < 0) { $limit = 10; diff --git a/library/eden/getsatisfaction/topic.php b/library/eden/getsatisfaction/topic.php index 82eb27f..a03b682 100644 --- a/library/eden/getsatisfaction/topic.php +++ b/library/eden/getsatisfaction/topic.php @@ -37,7 +37,7 @@ class Eden_GetSatisfaction_Topic extends Eden_GetSatisfaction_Base { -------------------------------*/ /* Get -------------------------------*/ - public static function get($key, $secret) { + public static function i($key, $secret) { return self::_getMultiple(__CLASS__, $key, $secret); } @@ -46,14 +46,14 @@ public static function get($key, $secret) { /* Public Methods -------------------------------*/ public function setCompany($company) { - Eden_Getsatisfaction_Error::get()->argument(1, 'string', 'numeric'); + Eden_Getsatisfaction_Error::i()->argument(1, 'string', 'numeric'); $this->_url = sprintf(self::URL_COMPANY, $company); return $this; } public function setCompanyProduct($company, $product) { - Eden_Getsatisfaction_Error::get() + Eden_Getsatisfaction_Error::i() ->argument(1, 'string', 'numeric') ->argument(2, 'string', 'numeric'); @@ -62,7 +62,7 @@ public function setCompanyProduct($company, $product) { } public function setCompanyTag($company, $tag) { - Eden_Getsatisfaction_Error::get() + Eden_Getsatisfaction_Error::i() ->argument(1, 'string', 'numeric') ->argument(2, 'string', 'numeric'); @@ -71,21 +71,21 @@ public function setCompanyTag($company, $tag) { } public function setProduct($product) { - Eden_Getsatisfaction_Error::get()->argument(1, 'string', 'numeric'); + Eden_Getsatisfaction_Error::i()->argument(1, 'string', 'numeric'); $this->_url = sprintf(self::URL_PRODUCT, $product); return $this; } public function setUser($user) { - Eden_Getsatisfaction_Error::get()->argument(1, 'string', 'numeric'); + Eden_Getsatisfaction_Error::i()->argument(1, 'string', 'numeric'); $this->_url = sprintf(self::URL_PEOPLE, $user); return $this; } public function setFollowed($user) { - Eden_Getsatisfaction_Error::get()->argument(1, 'string', 'numeric'); + Eden_Getsatisfaction_Error::i()->argument(1, 'string', 'numeric'); $this->_url = sprintf(self::URL_PEOPLE_FOLLOWED, $user); return $this; @@ -147,7 +147,7 @@ public function showUpdates() { } public function filterSince($since) { - Eden_Getsatisfaction_Error::get()->argument(1, 'string', 'int'); + Eden_Getsatisfaction_Error::i()->argument(1, 'string', 'int'); if(is_string($since)) { $since = strtotime($since); @@ -159,7 +159,7 @@ public function filterSince($since) { } public function filterUser($user) { - Eden_Getsatisfaction_Error::get()->argument(1, 'string', 'int'); + Eden_Getsatisfaction_Error::i()->argument(1, 'string', 'int'); $this->_query['user'] = $user; @@ -167,7 +167,7 @@ public function filterUser($user) { } public function filterCompany($company) { - Eden_Getsatisfaction_Error::get()->argument(1, 'string', 'int'); + Eden_Getsatisfaction_Error::i()->argument(1, 'string', 'int'); $this->_query['company'] = $company; @@ -175,7 +175,7 @@ public function filterCompany($company) { } public function filterProduct($product) { - Eden_Getsatisfaction_Error::get()->argument(1, 'string', 'int', 'array'); + Eden_Getsatisfaction_Error::i()->argument(1, 'string', 'int', 'array'); if(is_array($product)) { $product = implode(',', $product); @@ -187,7 +187,7 @@ public function filterProduct($product) { } public function filterTag($tag) { - Eden_Getsatisfaction_Error::get()->argument(1, 'string'); + Eden_Getsatisfaction_Error::i()->argument(1, 'string'); $this->_query['tag'] = $tag; @@ -195,7 +195,7 @@ public function filterTag($tag) { } public function filterDefined($defined) { - Eden_Getsatisfaction_Error::get()->argument(1, 'string', 'int'); + Eden_Getsatisfaction_Error::i()->argument(1, 'string', 'int'); $this->_query['user_defined_code'] = $defined; @@ -243,7 +243,7 @@ public function addStatusRejected() { } public function setPage($page = 0) { - Eden_Getsatisfaction_Error::get()->argument(1, 'int'); + Eden_Getsatisfaction_Error::i()->argument(1, 'int'); if($page < 0) { $page = 0; @@ -255,7 +255,7 @@ public function setPage($page = 0) { } public function setLimit($limit = 10) { - Eden_Getsatisfaction_Error::get()->argument(1, 'int'); + Eden_Getsatisfaction_Error::i()->argument(1, 'int'); if($limit < 0) { $limit = 10; diff --git a/library/eden/google/base.php b/library/eden/google/base.php index a0efbc4..ffc16dd 100644 --- a/library/eden/google/base.php +++ b/library/eden/google/base.php @@ -57,10 +57,10 @@ class Eden_Google_Base extends Eden_Oauth_Base { */ public function getLoginUrl($redirect) { //Argument 1 must be a string - Eden_Google_Error::get()->argument(1, 'string'); + Eden_Google_Error::i()->argument(1, 'string'); //get the token - $token = Eden_Oauth::get() + $token = Eden_Oauth::i() ->getConsumer(self::REQUEST_URL, $this->_key, $this->_secret) ->useAuthorization() ->setMethodToPost() @@ -103,11 +103,11 @@ public function getLoginUrl($redirect) { */ public function getAccessToken($token, $secret) { //argument test - Eden_Google_Error::get() + Eden_Google_Error::i() ->argument(1, 'string') //Argument 1 must be a string ->argument(2, 'string'); //Argument 2 must be a string - return Eden_Oauth::get() + return Eden_Oauth::i() ->getConsumer(self::ACCESS_URL, $this->_key, $this->_secret) ->useAuthorization() ->setMethodToPost() @@ -130,7 +130,7 @@ public function setAccessToken($token, $secret) { * @return array */ public function getMeta($key = NULL) { - Eden_Google_Error::get()->argument(1, 'string', 'null'); + Eden_Google_Error::i()->argument(1, 'string', 'null'); if(isset($this->_meta[$key])) { return $this->_meta[$key]; @@ -144,7 +144,7 @@ public function getMeta($key = NULL) { protected function _getResponse($url, array $query = array()) { $query['alt'] = 'jsonc'; - $rest = Eden_Oauth::get() + $rest = Eden_Oauth::i() ->getConsumer($url, $this->_key, $this->_secret) ->setHeaders(self::VERSION_HEADER, self::GDATA_VERSION) ->setToken($this->_accessToken, $this->_accessSecret) @@ -169,7 +169,7 @@ protected function _post($url, $query = array()) { $headers[] = Eden_Oauth_Consumer::POST_HEADER; $headers[] = 'Content-Type: application/json'; - $rest = Eden_Oauth::get() + $rest = Eden_Oauth::i() ->getConsumer($url, $this->_key, $this->_secret) ->setToken($this->_accessToken, $this->_accessSecret) ->setSignatureToHmacSha1(); @@ -198,7 +198,7 @@ protected function _post($url, $query = array()) { $url .= $connector.$authorization; //set curl - $curl = Eden_Curl::get() + $curl = Eden_Curl::i() ->verifyHost(false) ->verifyPeer(false) ->setUrl($url) diff --git a/library/eden/google/calendar.php b/library/eden/google/calendar.php index f0d7a92..981198e 100644 --- a/library/eden/google/calendar.php +++ b/library/eden/google/calendar.php @@ -29,7 +29,7 @@ class Eden_Google_Calendar extends Eden_Google_Base { -------------------------------*/ /* Get -------------------------------*/ - public static function get($key, $secret) { + public static function i($key, $secret) { return self::_getMultiple(__CLASS__, $key, $secret); } @@ -37,7 +37,7 @@ public static function get($key, $secret) { -------------------------------*/ public function __construct($key, $secret) { //argument test - Eden_Google_Error::get() + Eden_Google_Error::i() ->argument(1, 'string') //Argument 1 must be a string ->argument(2, 'string'); //Argument 2 must be a string @@ -51,7 +51,7 @@ public function __construct($key, $secret) { public function getCalendarList($user = self::DEFAULT_USER) { $url = sprintf(self::URL_CALENDAR_LIST, $user); //Argument 1 must be a string - Eden_Google_Error::get()->argument(1, 'string'); + Eden_Google_Error::i()->argument(1, 'string'); return $this->_getResponse($url); } diff --git a/library/eden/google/contacts.php b/library/eden/google/contacts.php index 020999d..c9278e5 100644 --- a/library/eden/google/contacts.php +++ b/library/eden/google/contacts.php @@ -28,7 +28,7 @@ class Eden_Google_Contacts extends Eden_Google_Base { -------------------------------*/ /* Get -------------------------------*/ - public static function get($key, $secret) { + public static function i($key, $secret) { return self::_getMultiple(__CLASS__, $key, $secret); } @@ -36,7 +36,7 @@ public static function get($key, $secret) { -------------------------------*/ public function __construct($key, $secret) { //argument test - Eden_Google_Error::get() + Eden_Google_Error::i() ->argument(1, 'string') //Argument 1 must be a string ->argument(2, 'string'); //Argument 2 must be a string diff --git a/library/eden/google/docs.php b/library/eden/google/docs.php index ab9e5fb..5a0dae3 100644 --- a/library/eden/google/docs.php +++ b/library/eden/google/docs.php @@ -28,7 +28,7 @@ class Eden_Google_Docs extends Eden_Google_Base { -------------------------------*/ /* Get -------------------------------*/ - public static function get($key, $secret) { + public static function i($key, $secret) { return self::_getMultiple(__CLASS__, $key, $secret); } @@ -36,7 +36,7 @@ public static function get($key, $secret) { -------------------------------*/ public function __construct($key, $secret) { //argument test - Eden_Google_Error::get() + Eden_Google_Error::i() ->argument(1, 'string') //Argument 1 must be a string ->argument(2, 'string'); //Argument 2 must be a string diff --git a/library/eden/google/error.php b/library/eden/google/error.php index 0d16ed0..3e60910 100644 --- a/library/eden/google/error.php +++ b/library/eden/google/error.php @@ -26,7 +26,7 @@ class Eden_Google_Error extends Eden_Error { -------------------------------*/ /* Get -------------------------------*/ - public static function get($message = NULL, $code = 0) { + public static function i($message = NULL, $code = 0) { $class = __CLASS__; return new $class($message, $code); } diff --git a/library/eden/google/gmail.php b/library/eden/google/gmail.php index 2ef6366..011d07d 100644 --- a/library/eden/google/gmail.php +++ b/library/eden/google/gmail.php @@ -28,7 +28,7 @@ class Eden_Google_Gmail extends Eden_Google_Base { -------------------------------*/ /* Get -------------------------------*/ - public static function get($key, $secret) { + public static function i($key, $secret) { return self::_getMultiple(__CLASS__, $key, $secret); } @@ -36,7 +36,7 @@ public static function get($key, $secret) { -------------------------------*/ public function __construct($key, $secret) { //argument test - Eden_Google_Error::get() + Eden_Google_Error::i() ->argument(1, 'string') //Argument 1 must be a string ->argument(2, 'string'); //Argument 2 must be a string diff --git a/library/eden/google/oauth.php b/library/eden/google/oauth.php index d0c6681..f7588d3 100644 --- a/library/eden/google/oauth.php +++ b/library/eden/google/oauth.php @@ -30,7 +30,7 @@ class Eden_Google_Oauth extends Eden_Google_Base { -------------------------------*/ /* Get -------------------------------*/ - public static function get($key, $secret, $scope) { + public static function i($key, $secret, $scope) { return self::_getMultiple(__CLASS__, $key, $secret, $scope); } @@ -38,7 +38,7 @@ public static function get($key, $secret, $scope) { -------------------------------*/ public function __construct($key, $secret, $scope) { //argument test - Eden_Google_Error::get() + 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 diff --git a/library/eden/google/shortener.php b/library/eden/google/shortener.php index e256de2..ace62a9 100644 --- a/library/eden/google/shortener.php +++ b/library/eden/google/shortener.php @@ -32,7 +32,7 @@ class Eden_Google_Shortener extends Eden_Class { -------------------------------*/ /* Get -------------------------------*/ - public static function get($key) { + public static function i($key) { return self::_getMultiple(__CLASS__, $key); } @@ -40,7 +40,7 @@ public static function get($key) { -------------------------------*/ public function __construct($key) { //Argument 1 must be a string - Eden_Google_Error::get()->argument(1, 'string'); + Eden_Google_Error::i()->argument(1, 'string'); $this->_key = $key; } @@ -122,7 +122,7 @@ public function getAnalytics($url) { * @return array */ public function getMeta($key = NULL) { - Eden_Google_Error::get()->argument(1, 'string', 'null'); + Eden_Google_Error::i()->argument(1, 'string', 'null'); if(isset($this->_meta[$key])) { return $this->_meta[$key]; @@ -155,7 +155,7 @@ protected function _getResponse($url, array $query = array()) { $url .= $connector.$query; //set curl - $curl = Eden_Curl::get() + $curl = Eden_Curl::i() ->verifyHost(false) ->verifyPeer(false) ->setUrl($url) @@ -193,7 +193,7 @@ protected function _post($url, $query = array()) { $url .= $connector.'key='.$this->_key; //set curl - $curl = Eden_Curl::get() + $curl = Eden_Curl::i() ->verifyHost(false) ->verifyPeer(false) ->setUrl($url) diff --git a/library/eden/image.php b/library/eden/image.php index 91f7f66..31c3802 100644 --- a/library/eden/image.php +++ b/library/eden/image.php @@ -39,14 +39,14 @@ class Eden_Image extends Eden_Class { -------------------------------*/ /* Get -------------------------------*/ - public static function get($data, $type = NULL, $path = true, $quality = 75) { + public static function i($data, $type = NULL, $path = true, $quality = 75) { return self::_getMultiple(__CLASS__, $data, $type, $path, $quality); } /* Magic -------------------------------*/ public function __construct($data, $type = NULL, $path = true, $quality = 75) { - Eden_Image_Error::get() + Eden_Image_Error::i() ->argument(1, 'string') ->argument(2, 'string', 'null') ->argument(3, 'bool') @@ -118,7 +118,7 @@ public function __toString() { */ public function crop($width = NULL, $height = NULL) { //argument test - Eden_Image_Error::get() + 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 @@ -250,7 +250,7 @@ public function crop($width = NULL, $height = NULL) { */ public function scale($width = NULL, $height = NULL) { //argument test - Eden_Image_Error::get() + 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 @@ -300,7 +300,7 @@ public function scale($width = NULL, $height = NULL) { */ public function resize($width = NULL, $height = NULL) { //argument test - Eden_Image_Error::get() + 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 @@ -363,7 +363,7 @@ public function resize($width = NULL, $height = NULL) { */ public function rotate($degree, $background = 0) { //argument test - Eden_Image_Error::get() + Eden_Image_Error::i() ->argument(1, 'numeric') //Argument 1 must be a number ->argument(2, 'numeric'); //Argument 2 must be a number @@ -387,7 +387,7 @@ public function rotate($degree, $background = 0) { */ public function invert($vertical = false) { //Argument 1 must be a boolean - Eden_Image_Error::get()->argument(1, 'bool'); + Eden_Image_Error::i()->argument(1, 'bool'); //get the source width and height $orgWidth = imagesx($this->_resource); @@ -442,7 +442,7 @@ public function negative() { */ public function brightness($level) { //Argument 1 must be a number - Eden_Image_Error::get()->argument(1, 'numeric'); + Eden_Image_Error::i()->argument(1, 'numeric'); //apply filter imagefilter($this->_resource, IMG_FILTER_BRIGHTNESS, $level); @@ -458,7 +458,7 @@ public function brightness($level) { */ public function contrast($level) { //Argument 1 must be a number - Eden_Image_Error::get()->argument(1, 'numeric'); + Eden_Image_Error::i()->argument(1, 'numeric'); //apply filter imagefilter($this->_resource, IMG_FILTER_CONTRAST, $level); @@ -477,7 +477,7 @@ public function contrast($level) { */ public function colorize($red, $blue, $green, $alpha = 0) { //argument test - Eden_Image_Error::get() + 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 @@ -557,7 +557,7 @@ public function meanRemoval() { */ public function smooth($level) { //Argument 1 must be a number - Eden_Image_Error::get()->argument(1, 'numeric'); + Eden_Image_Error::i()->argument(1, 'numeric'); //apply filter imagefilter($this->_resource, IMG_FILTER_SMOOTH, $level); @@ -602,7 +602,7 @@ public function save($path, $type = NULL) { #imagegif() - Output image to browser or file #imagewbmp() - Output image to browser or file #imagejpeg() - Output image to browser or file - //$path = Eden_Path::get()->getAbsolute($path); + //$path = Eden_Path::i()->getAbsolute($path); if(!$type) { $type = $this->_type; @@ -643,7 +643,7 @@ protected function _getResource($data, $path) { //if the GD Library is not installed if(!function_exists('gd_info')) { //throw error - Eden_Image_Error::get(Eden_Image_Error::GD_NOT_INSTALLED)->trigger(); + Eden_Image_Error::i(Eden_Image_Error::GD_NOT_INSTALLED)->trigger(); } # imagecreatefromgd — Create a new image from GD file or URL @@ -693,7 +693,7 @@ protected function _getResource($data, $path) { //if there is no resource still if(!$resource) { //throw error - Eden_Image_Error::get() + Eden_Image_Error::i() ->setMessage(Eden_Image_Error::NOT_VALID_IMAGE_FILE) ->addVariable($path); } diff --git a/library/eden/javascript.php b/library/eden/javascript.php index 78f30e7..a380cad 100644 --- a/library/eden/javascript.php +++ b/library/eden/javascript.php @@ -27,7 +27,7 @@ class Eden_Javascript extends Eden_Class { -------------------------------*/ /* Get -------------------------------*/ - public static function get() { + public static function i() { return self::_getSingleton(__CLASS__); } @@ -36,7 +36,7 @@ public static function get() { /* Public Methods -------------------------------*/ public function load() { - return Eden_Javascript_Class::get(); + return Eden_Javascript_Class::i(); } public function render() { diff --git a/library/eden/javascript/class.php b/library/eden/javascript/class.php index 885e90c..2e9f8b2 100644 --- a/library/eden/javascript/class.php +++ b/library/eden/javascript/class.php @@ -28,7 +28,7 @@ class Eden_Javascript_Class extends Eden_Class { -------------------------------*/ /* Get -------------------------------*/ - public static function get() { + public static function i() { return self::_getMultiple(__CLASS__); } @@ -78,7 +78,7 @@ public function __set($name, $value) { /* Protected Methods -------------------------------*/ protected function ___encode($value) { - $type = Eden_Tool::get()->type($value); + $type = Eden_Tool::i()->type($value); switch($type) { case 'array': case 'object': diff --git a/library/eden/javascript/error.php b/library/eden/javascript/error.php index 32a5dbb..280be4b 100644 --- a/library/eden/javascript/error.php +++ b/library/eden/javascript/error.php @@ -26,7 +26,7 @@ class Eden_Javascript_Error extends Eden_Error { -------------------------------*/ /* Get -------------------------------*/ - public static function get($message = NULL, $code = 0) { + public static function i($message = NULL, $code = 0) { $class = __CLASS__; return new $class($message, $code); } diff --git a/library/eden/loader.php b/library/eden/loader.php index 4dc00c8..75954a1 100755 --- a/library/eden/loader.php +++ b/library/eden/loader.php @@ -39,7 +39,7 @@ class Eden_Loader extends Eden_Class { -------------------------------*/ /* Get -------------------------------*/ - public static function get() { + public static function i() { return self::_getSingleton(__CLASS__); } diff --git a/library/eden/map.php b/library/eden/map.php index 01c1e49..a5af27e 100644 --- a/library/eden/map.php +++ b/library/eden/map.php @@ -34,7 +34,7 @@ class Eden_Map extends Eden_Class { -------------------------------*/ /* Get -------------------------------*/ - public static function get($scope, array &$list, $lines = 0) { + public static function i($scope, array &$list, $lines = 0) { return self::_getMultiple(__CLASS__, $scope, $list, $lines); } @@ -61,14 +61,14 @@ public function __call($name, $args) { -------------------------------*/ /** * Returns the original class - * Eden_Sesison()->map($products)->setData('name', 'chris'); + * Eden_Sesison()->map($products)->set('name', 'chris'); * @param bool * @return this|Eden_Noop */ public function endMap() { foreach($this->_list as $key => $object) { foreach($this->_map as $action) { - $this->_list[$key] = Eden_Route::get()->callMethod($object, $action[0], NULL, $action[1]); + $this->_list[$key] = Eden_Route::i()->callMethod($object, $action[0], NULL, $action[1]); } } diff --git a/library/eden/memcache.php b/library/eden/memcache.php index 984c36e..cd88227 100755 --- a/library/eden/memcache.php +++ b/library/eden/memcache.php @@ -38,7 +38,7 @@ class Eden_Memcache extends Eden_Class { -------------------------------*/ /* Get -------------------------------*/ - public static function get($host = 'localhost', $port = 11211, $timeout = 1) { + public static function i($host = 'localhost', $port = 11211, $timeout = 1) { return self::_getMultiple(__CLASS__, $host, $port, $timeout); } @@ -46,7 +46,7 @@ public static function get($host = 'localhost', $port = 11211, $timeout = 1) { -------------------------------*/ public function __construct($host = 'localhost', $port = 11211, $timeout = 1) { //argument test - $error = Eden_Memcache_Error::get() + $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 @@ -88,7 +88,7 @@ public function __destruct() { */ public function addServer($host = 'localhost', $port = 11211, $persistent = true, $weight = NULL, $timeout = 1) { //argument test - Eden_Memcache_Error::get() + 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 @@ -109,9 +109,9 @@ public function addServer($host = 'localhost', $port = 11211, $persistent = true * @param int expire * @return bool */ - public function setData($key, $data, $flag = NULL, $expire = NULL) { + public function set($key, $data, $flag = NULL, $expire = NULL) { //argument test - Eden_Memcache_Error::get() + 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 @@ -128,9 +128,9 @@ public function setData($key, $data, $flag = NULL, $expire = NULL) { * @param int MemCache flag * @return variable */ - public function getData($key, $flag = NULL) { + public function get($key, $flag = NULL) { //argument test - Eden_Memcache_Error::get() + 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 @@ -143,9 +143,9 @@ public function getData($key, $flag = NULL) { * @param string the key to the data * @return this */ - public function deleteData($key) { + public function remove($key) { //Argument 1 must be a string or array - Eden_Memcache_Error::get()->argument(1, 'string', 'array'); + Eden_Memcache_Error::i()->argument(1, 'string', 'array'); $this->_memcache->delete($key); @@ -185,7 +185,7 @@ class Eden_Memcache_Error extends Eden_Error { -------------------------------*/ /* Get -------------------------------*/ - public static function get($message = NULL, $code = 0) { + public static function i($message = NULL, $code = 0) { $class = __CLASS__; return new $class($message, $code); } diff --git a/library/eden/model.php b/library/eden/model.php index ab9ef94..a9aea35 100755 --- a/library/eden/model.php +++ b/library/eden/model.php @@ -27,7 +27,7 @@ class Eden_Model extends Eden_Type_Array { -------------------------------*/ /* Get -------------------------------*/ - public static function get() { + public static function i() { return self::_getMultiple(__CLASS__); } @@ -59,7 +59,7 @@ class Eden_Model_Error extends Eden_Error { -------------------------------*/ /* Get -------------------------------*/ - public static function get($message = NULL, $code = 0) { + public static function i($message = NULL, $code = 0) { $class = __CLASS__; return new $class($message, $code); } diff --git a/library/eden/mysql.php b/library/eden/mysql.php index 94800ba..ca61485 100755 --- a/library/eden/mysql.php +++ b/library/eden/mysql.php @@ -60,7 +60,7 @@ class Eden_Mysql extends Eden_Sql_Database { -------------------------------*/ /* Get -------------------------------*/ - public static function get($host = NULL, $name = NULL, $user = NULL, $pass = NULL) { + public static function i($host = NULL, $name = NULL, $user = NULL, $pass = NULL) { return self::_getMultiple(__CLASS__, $host, $name, $user, $pass); } @@ -68,7 +68,7 @@ public static function get($host = NULL, $name = NULL, $user = NULL, $pass = NUL -------------------------------*/ public function __construct($host, $name, $user, $pass = NULL) { //argument test - Eden_Mysql_Error::get() + Eden_Mysql_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 @@ -154,7 +154,7 @@ public function getLastInsertedId() { * @return Eden_Mysql_Search */ public function search() { - return Eden_Mysql_Search::get($this); + return Eden_Mysql_Search::i($this); } /** @@ -163,7 +163,7 @@ public function search() { * @return Eden_Mysql_Model */ public function model(array $data = array()) { - return Eden_Mysql_Model::get($data)->setDatabase($this); + return Eden_Mysql_Model::i($data)->setDatabase($this); } /** @@ -172,7 +172,7 @@ public function model(array $data = array()) { * @return Eden_Mysql_Collection */ public function collection(array $data = array()) { - return Eden_Mysql_Collection::get($data)->setDatabase($this); + return Eden_Mysql_Collection::i($data)->setDatabase($this); } /** @@ -182,9 +182,9 @@ public function collection(array $data = array()) { */ public function alter($name = NULL) { //Argument 1 must be a string or null - Eden_Mysql_Error::get()->argument(1, 'string', 'null'); + Eden_Mysql_Error::i()->argument(1, 'string', 'null'); - return Eden_Mysql_Alter::get($name); + return Eden_Mysql_Alter::i($name); } /** @@ -194,9 +194,9 @@ public function alter($name = NULL) { */ public function create($name = NULL) { //Argument 1 must be a string or null - Eden_Mysql_Error::get()->argument(1, 'string', 'null'); + Eden_Mysql_Error::i()->argument(1, 'string', 'null'); - return Eden_Mysql_Create::get($name); + return Eden_Mysql_Create::i($name); } /** @@ -206,9 +206,9 @@ public function create($name = NULL) { */ public function subselect($parentQuery, $select = '*') { //Argument 2 must be a string - Eden_Mysql_Error::get()->argument(2, 'string'); + Eden_Mysql_Error::i()->argument(2, 'string'); - return Eden_Mysql_Subselect::get($parentQuery, $select); + return Eden_Mysql_Subselect::i($parentQuery, $select); } /** @@ -217,7 +217,7 @@ public function subselect($parentQuery, $select = '*') { * @return Eden_Sql_Utility */ public function utility() { - return Eden_Mysql_Utility::get(); + return Eden_Mysql_Utility::i(); } /** @@ -230,7 +230,7 @@ public function utility() { */ public function getRow($table, $name, $value) { //argument test - Eden_Mysql_Error::get() + Eden_Mysql_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 @@ -261,7 +261,7 @@ public function getRow($table, $name, $value) { public function getRows($table, array $joins = array(), $filters = NULL, array $sort = array(), $start = 0, $range = 0, $index = NULL) { //argument test - Eden_Mysql_Error::get() + Eden_Mysql_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 @@ -344,7 +344,7 @@ public function getRows($table, array $joins = array(), $filters = NULL, */ public function getModel($table, $name, $value) { //argument test - Eden_Mysql_Error::get() + Eden_Mysql_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 @@ -355,7 +355,7 @@ public function getModel($table, $name, $value) { return NULL; } - return Eden_Mysql_Model::get($result)->setDatabase($this)->setTable($table); + return Eden_Mysql_Model::i($result)->setDatabase($this)->setTable($table); } /** @@ -372,7 +372,7 @@ public function getModel($table, $name, $value) { public function getCollection($table, array $joins = array(), $filters = NULL, array $sort = array(), $start = 0, $range = 0, $index = NULL) { //argument test - Eden_Mysql_Error::get() + Eden_Mysql_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 @@ -386,10 +386,10 @@ public function getCollection($table, array $joins = array(), $filters = NULL, } if(!is_null($index)) { - return Eden_Mysql_Model::get($results); + return Eden_Mysql_Model::i($results); } - return Eden_Mysql_Collection::get($results)->setDatabase($this)->setTable($table); + return Eden_Mysql_Collection::i($results)->setDatabase($this)->setTable($table); } /** @@ -401,7 +401,7 @@ public function getCollection($table, array $joins = array(), $filters = NULL, */ public function getRowsCount($table, array $joins = array(), $filters = NULL) { //argument test - Eden_Mysql_Error::get() + Eden_Mysql_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 @@ -451,7 +451,7 @@ public function getRowsCount($table, array $joins = array(), $filters = NULL) { */ public function insertRow($table, array $setting, $bind = true) { //Argument 1 must be a string - Eden_Mysql_Error::get()->argument(1, 'string')->argument(3, 'array', 'bool'); + Eden_Mysql_Error::i()->argument(1, 'string')->argument(3, 'array', 'bool'); $query = $this->insert($table); @@ -485,7 +485,7 @@ public function insertRow($table, array $setting, $bind = true) { */ public function insertRows($table, array $settings, $bind = true) { //Argument 1 must be a string - Eden_Mysql_Error::get()->argument(1, 'string')->argument(3, 'array', 'bool'); + Eden_Mysql_Error::i()->argument(1, 'string')->argument(3, 'array', 'bool'); $query = $this->insert($table); @@ -522,7 +522,7 @@ public function insertRows($table, array $settings, $bind = true) { */ public function updateRows($table, array $setting, $filters = NULL, $bind = true) { //Argument 1 must be a string - Eden_Mysql_Error::get()->argument(1, 'string')->argument(4, 'array', 'bool'); + Eden_Mysql_Error::i()->argument(1, 'string')->argument(4, 'array', 'bool'); $query = $this->update($table); @@ -569,7 +569,7 @@ public function updateRows($table, array $setting, $filters = NULL, $bind = true */ public function setRow($table, $name, $value, array $setting) { //argument test - Eden_Mysql_Error::get() + Eden_Mysql_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 @@ -596,7 +596,7 @@ public function setRow($table, $name, $value, array $setting) { */ public function deleteRows($table, $filters = NULL) { //Argument 1 must be a string - Eden_Mysql_Error::get()->argument(1, 'string'); + Eden_Mysql_Error::i()->argument(1, 'string'); $query = $this->delete($table); @@ -627,7 +627,7 @@ public function deleteRows($table, $filters = NULL) { */ public function getPrimaryKey($table) { //Argument 1 must be a string - Eden_Mysql_Error::get()->argument(1, 'string'); + Eden_Mysql_Error::i()->argument(1, 'string'); $query = $this->utility(); $results = $this->getColumns($table, "`Key` = 'PRI'"); @@ -642,7 +642,7 @@ public function getPrimaryKey($table) { */ public function getColumns($table, $filters = NULL) { //Argument 1 must be a string - Eden_Mysql_Error::get()->argument(1, 'string'); + Eden_Mysql_Error::i()->argument(1, 'string'); $query = $this->utility(); @@ -667,7 +667,7 @@ public function getColumns($table, $filters = NULL) { */ public function getTableSchema($table) { //Argument 1 must be a string - Eden_Mysql_Error::get()->argument(1, 'string'); + Eden_Mysql_Error::i()->argument(1, 'string'); $backup = array(); //get the schema @@ -742,7 +742,7 @@ public function getTableSchema($table) { */ public function getTables($like = NULL) { //Argument 1 must be a string or null - Eden_Mysql_Error::get()->argument(1, 'string', 'null'); + Eden_Mysql_Error::i()->argument(1, 'string', 'null'); $query = $this->utility(); $like = $like ? $this->bind($like) : NULL; @@ -783,7 +783,7 @@ public function getSchema() { */ public function query($query, array $binds = array()) { //Argument 1 must be a string or null - Eden_Mysql_Error::get()->argument(1, 'string', 'Eden_Sql_Query'); + Eden_Mysql_Error::i()->argument(1, 'string', 'Eden_Sql_Query'); $connection = $this->getConnection(); $query = (string) $query; @@ -800,7 +800,7 @@ public function query($query, array $binds = array()) { $query = str_replace($key, "'$value'", $query); } - Eden_Mysql_Error::get() + Eden_Mysql_Error::i() ->setMessage(Eden_Mysql_Error::QUERY_ERROR) ->addVariable($query) ->addVariable($error[2]) @@ -829,7 +829,7 @@ public function query($query, array $binds = array()) { */ public function bind($value) { //Argument 1 must be an array, string or number - Eden_Mysql_Error::get()->argument(1, 'array', 'string', 'numeric', 'null'); + Eden_Mysql_Error::i()->argument(1, 'array', 'string', 'numeric', 'null'); if(is_array($value)) { foreach($value as $i => $item) { diff --git a/library/eden/mysql/alter.php b/library/eden/mysql/alter.php index 495f5fa..ac015b4 100755 --- a/library/eden/mysql/alter.php +++ b/library/eden/mysql/alter.php @@ -37,7 +37,7 @@ class Eden_Mysql_Alter extends Eden_Sql_Query { -------------------------------*/ /* Get -------------------------------*/ - public static function get($name = NULL) { + public static function i($name = NULL) { return self::_getMultiple(__CLASS__, $name); } @@ -59,7 +59,7 @@ public function __construct($name = NULL) { */ public function setName($name) { //Argument 1 must be a string - Eden_Mysql_Error::get()->argument(1, 'string'); + Eden_Mysql_Error::i()->argument(1, 'string'); $this->_name = $name; return $this; @@ -75,7 +75,7 @@ public function setName($name) { */ public function changeField($name, array $attributes) { //Argument 1 must be a string - Eden_Mysql_Error::get()->argument(1, 'string'); + Eden_Mysql_Error::i()->argument(1, 'string'); $this->_changeFields[$name] = $attributes; return $this; @@ -90,7 +90,7 @@ public function changeField($name, array $attributes) { */ public function addField($name, array $attributes) { //Argument 1 must be a string - Eden_Mysql_Error::get()->argument(1, 'string'); + Eden_Mysql_Error::i()->argument(1, 'string'); $this->_addFields[$name] = $attributes; return $this; @@ -104,7 +104,7 @@ public function addField($name, array $attributes) { */ public function removeField($name) { //Argument 1 must be a string - Eden_Mysql_Error::get()->argument(1, 'string'); + Eden_Mysql_Error::i()->argument(1, 'string'); $this->_removeFields[] = $name; return $this; @@ -118,7 +118,7 @@ public function removeField($name) { */ public function addKey($name) { //Argument 1 must be a string - Eden_Mysql_Error::get()->argument(1, 'string'); + Eden_Mysql_Error::i()->argument(1, 'string'); $this->_addKeys[] = '`'.$name.'`'; return $this; @@ -132,7 +132,7 @@ public function addKey($name) { */ public function removeKey($name) { //Argument 1 must be a string - Eden_Mysql_Error::get()->argument(1, 'string'); + Eden_Mysql_Error::i()->argument(1, 'string'); $this->_removeKeys[] = $name; return $this; @@ -146,7 +146,7 @@ public function removeKey($name) { */ public function addUniqueKey($name) { //Argument 1 must be a string - Eden_Mysql_Error::get()->argument(1, 'string'); + Eden_Mysql_Error::i()->argument(1, 'string'); $this->_addUniqueKeys[] = '`'.$name.'`'; return $this; @@ -160,7 +160,7 @@ public function addUniqueKey($name) { */ public function removeUniqueKey($name) { //Argument 1 must be a string - Eden_Mysql_Error::get()->argument(1, 'string'); + Eden_Mysql_Error::i()->argument(1, 'string'); $this->_removeUniqueKeys[] = $name; return $this; @@ -174,7 +174,7 @@ public function removeUniqueKey($name) { */ public function addPrimaryKey($name) { //Argument 1 must be a string - Eden_Mysql_Error::get()->argument(1, 'string'); + Eden_Mysql_Error::i()->argument(1, 'string'); $this->_addPrimaryKeys[] = '`'.$name.'`'; return $this; @@ -188,7 +188,7 @@ public function addPrimaryKey($name) { */ public function removePrimaryKey($name) { //Argument 1 must be a string - Eden_Mysql_Error::get()->argument(1, 'string'); + Eden_Mysql_Error::i()->argument(1, 'string'); $this->_removePrimaryKeys[] = $name; return $this; diff --git a/library/eden/mysql/collection.php b/library/eden/mysql/collection.php index efe194c..6df2825 100644 --- a/library/eden/mysql/collection.php +++ b/library/eden/mysql/collection.php @@ -28,7 +28,7 @@ class Eden_Mysql_Collection extends Eden_Collection { -------------------------------*/ /* Get -------------------------------*/ - public static function get(array $data = array()) { + public static function i(array $data = array()) { return self::_getMultiple(__CLASS__,$data); } @@ -58,7 +58,7 @@ public function setDatabase(Eden_Mysql $database) { */ public function setTable($table) { //Argument 1 must be a string - Eden_Mysql_Error::get()->argument(1, 'string'); + Eden_Mysql_Error::i()->argument(1, 'string'); //for each row foreach($this->_list as $row) { diff --git a/library/eden/mysql/create.php b/library/eden/mysql/create.php index b14a8e0..cbd99d0 100755 --- a/library/eden/mysql/create.php +++ b/library/eden/mysql/create.php @@ -33,7 +33,7 @@ class Eden_Mysql_Create extends Eden_Sql_Query { -------------------------------*/ /* Get -------------------------------*/ - public static function get($name = NULL) { + public static function i($name = NULL) { return self::_getMultiple(__CLASS__, $name); } @@ -55,7 +55,7 @@ public function __construct($name = NULL) { */ public function setName($name) { //Argument 1 must be a string - Eden_Mysql_Error::get()->argument(1, 'string'); + Eden_Mysql_Error::i()->argument(1, 'string'); $this->_name = $name; return $this; @@ -69,7 +69,7 @@ public function setName($name) { */ public function setComments($comments) { //Argument 1 must be a string - Eden_Mysql_Error::get()->argument(1, 'string'); + Eden_Mysql_Error::i()->argument(1, 'string'); $this->_comments = $comments; return $this; @@ -128,7 +128,7 @@ public function setPrimaryKeys(array $primaryKeys) { */ public function addField($name, array $attributes) { //Argument 1 must be a string - Eden_Mysql_Error::get()->argument(1, 'string'); + Eden_Mysql_Error::i()->argument(1, 'string'); $this->_fields[$name] = $attributes; return $this; @@ -143,7 +143,7 @@ public function addField($name, array $attributes) { */ public function addKey($name, array $fields) { //Argument 1 must be a string - Eden_Mysql_Error::get()->argument(1, 'string'); + Eden_Mysql_Error::i()->argument(1, 'string'); $this->_keys[$name] = $fields; return $this; @@ -158,7 +158,7 @@ public function addKey($name, array $fields) { */ public function addUniqueKey($name, array $fields) { //Argument 1 must be a string - Eden_Mysql_Error::get()->argument(1, 'string'); + Eden_Mysql_Error::i()->argument(1, 'string'); $this->_uniqueKeys[$name] = $fields; return $this; @@ -172,7 +172,7 @@ public function addUniqueKey($name, array $fields) { */ public function addPrimaryKey($name) { //Argument 1 must be a string - Eden_Mysql_Error::get()->argument(1, 'string'); + Eden_Mysql_Error::i()->argument(1, 'string'); $this->_primaryKeys[] = $name; return $this; diff --git a/library/eden/mysql/error.php b/library/eden/mysql/error.php index 8ec53f1..5e2ca3f 100755 --- a/library/eden/mysql/error.php +++ b/library/eden/mysql/error.php @@ -31,7 +31,7 @@ class Eden_Mysql_Error extends Eden_Error { -------------------------------*/ /* Get -------------------------------*/ - public static function get($message = NULL, $code = 0) { + public static function i($message = NULL, $code = 0) { $class = __CLASS__; return new $class($message, $code); } diff --git a/library/eden/mysql/model.php b/library/eden/mysql/model.php index 5345d38..84534ac 100644 --- a/library/eden/mysql/model.php +++ b/library/eden/mysql/model.php @@ -38,7 +38,7 @@ class Eden_Mysql_Model extends Eden_Model { -------------------------------*/ /* Get -------------------------------*/ - public static function get() { + public static function i() { $data = self::_getStart(func_get_args()); return self::_getMultiple(__CLASS__, $data); } @@ -64,7 +64,7 @@ public function setDatabase(Eden_Mysql $database) { */ public function setTable($table) { //Argument 1 must be a string - Eden_Mysql_Error::get()->argument(1, 'string'); + Eden_Mysql_Error::i()->argument(1, 'string'); $this->_table = $table; return $this; @@ -79,7 +79,7 @@ public function setTable($table) { */ public function formatTime($column, $format = self::DATETIME) { //Argument Test - Eden_Mysql_Error::get() + Eden_Mysql_Error::i() ->argument(1, 'string') //Argument 1 must be a string ->argument(2, 'string'); //Argument 1 must be a string @@ -116,7 +116,7 @@ public function formatTime($column, $format = self::DATETIME) { */ public function save($table = NULL, Eden_Mysql $database = NULL) { //Argument 1 must be a string - $error = Eden_Mysql_Error::get()->argument(1, 'string', 'null'); + $error = Eden_Mysql_Error::i()->argument(1, 'string', 'null'); //if no table if(is_null($table)) { @@ -186,7 +186,7 @@ public function save($table = NULL, Eden_Mysql $database = NULL) { */ public function remove($table = NULL, Eden_Mysql $database = NULL) { //Argument 1 must be a string - $error = Eden_Mysql_Error::get()->argument(1, 'string', 'null'); + $error = Eden_Mysql_Error::i()->argument(1, 'string', 'null'); //if no table if(is_null($table)) { diff --git a/library/eden/mysql/search.php b/library/eden/mysql/search.php index 7df19dd..095b4be 100644 --- a/library/eden/mysql/search.php +++ b/library/eden/mysql/search.php @@ -43,7 +43,7 @@ class Eden_Mysql_Search extends Eden_Class { -------------------------------*/ /* Get -------------------------------*/ - public static function get(Eden_Mysql $database) { + public static function i(Eden_Mysql $database) { return self::_getMultiple(__CLASS__,$database); } @@ -61,12 +61,12 @@ public function __call($name, $args) { $separator = (string) $args[1]; } - $key = Eden_Type_String::get($name) + $key = Eden_Type_String::i($name) ->substr(8) ->preg_replace("/([A-Z0-9])/", $separator."$1") ->substr(strlen($separator)) ->strtolower() - ->getData(); + ->get(); if(!isset($args[0])) { $args[0] = NULL; @@ -84,12 +84,12 @@ public function __call($name, $args) { $separator = (string) $args[1]; } - $key = Eden_Type_String::get($name) + $key = Eden_Type_String::i($name) ->substr(6) ->preg_replace("/([A-Z0-9])/", $separator."$1") ->substr(strlen($separator)) ->strtolower() - ->getData(); + ->get(); if(!isset($args[0])) { $args[0] = self::ASC; @@ -103,7 +103,7 @@ public function __call($name, $args) { try { return parent::__call($name, $args); } catch(Eden_Error $e) { - Eden_Mysql_Error::get($e->getMessage())->trigger(); + Eden_Mysql_Error::i($e->getMessage())->trigger(); } } @@ -132,7 +132,7 @@ public function setColumns($columns) { * @return this */ public function setTable($table) { - Eden_Mysql_Error::get()->argument(1, 'string'); + Eden_Mysql_Error::i()->argument(1, 'string'); $this->_table = $table; return $this; } @@ -145,7 +145,7 @@ public function setTable($table) { * @return this */ public function addInnerJoinOn($table, $where) { - Eden_Mysql_Error::get() + Eden_Mysql_Error::i() ->argument(1, 'string') ->argument(2, 'string'); @@ -165,7 +165,7 @@ public function addInnerJoinOn($table, $where) { * @return this */ public function addInnerJoinUsing($table, $where) { - Eden_Mysql_Error::get() + Eden_Mysql_Error::i() ->argument(1, 'string') ->argument(2, 'string'); @@ -185,7 +185,7 @@ public function addInnerJoinUsing($table, $where) { * @return this */ public function addLeftJoinOn($table, $where) { - Eden_Mysql_Error::get() + Eden_Mysql_Error::i() ->argument(1, 'string') ->argument(2, 'string'); @@ -205,7 +205,7 @@ public function addLeftJoinOn($table, $where) { * @return this */ public function addLeftJoinUsing($table, $where) { - Eden_Mysql_Error::get() + Eden_Mysql_Error::i() ->argument(1, 'string') ->argument(2, 'string'); @@ -225,7 +225,7 @@ public function addLeftJoinUsing($table, $where) { * @return this */ public function addRightJoinOn($table, $where) { - Eden_Mysql_Error::get() + Eden_Mysql_Error::i() ->argument(1, 'string') ->argument(2, 'string'); @@ -245,7 +245,7 @@ public function addRightJoinOn($table, $where) { * @return this */ public function addRightJoinUsing($table, $where) { - Eden_Mysql_Error::get() + Eden_Mysql_Error::i() ->argument(1, 'string') ->argument(2, 'string'); @@ -265,7 +265,7 @@ public function addRightJoinUsing($table, $where) { * @return this */ public function addOuterJoinOn($table, $where) { - Eden_Mysql_Error::get() + Eden_Mysql_Error::i() ->argument(1, 'string') ->argument(2, 'string'); @@ -285,7 +285,7 @@ public function addOuterJoinOn($table, $where) { * @return this */ public function addOuterJoinUsing($table, $where) { - Eden_Mysql_Error::get() + Eden_Mysql_Error::i() ->argument(1, 'string') ->argument(2, 'string'); @@ -305,7 +305,7 @@ public function addOuterJoinUsing($table, $where) { * @return this */ public function addFilter() { - Eden_Mysql_Error::get()->argument(1, 'string'); + Eden_Mysql_Error::i()->argument(1, 'string'); $this->_filter[] = func_get_args(); @@ -320,7 +320,7 @@ public function addFilter() { * @return this */ public function addSort($column, $order = self::ASC) { - Eden_Mysql_Error::get() + Eden_Mysql_Error::i() ->argument(1, 'string') ->argument(2, 'string'); @@ -342,7 +342,7 @@ public function addSort($column, $order = self::ASC) { */ public function setGroup($group) { //Argument 1 must be a string or array - Eden_Mysql_Error::get()->argument(1, 'string', 'array'); + Eden_Mysql_Error::i()->argument(1, 'string', 'array'); if(is_string($group)) { $group = array($group); @@ -359,7 +359,7 @@ public function setGroup($group) { * @return this */ public function setStart($start) { - Eden_Mysql_Error::get()->argument(1, 'int'); + Eden_Mysql_Error::i()->argument(1, 'int'); if($start < 0) { $start = 0; @@ -377,7 +377,7 @@ public function setStart($start) { * @return this */ public function setRange($range) { - Eden_Mysql_Error::get()->argument(1, 'int'); + Eden_Mysql_Error::i()->argument(1, 'int'); if($range < 0) { $range = 25; @@ -395,7 +395,7 @@ public function setRange($range) { * @return this */ public function setPage($page) { - Eden_Mysql_Error::get()->argument(1, 'int'); + Eden_Mysql_Error::i()->argument(1, 'int'); if($page < 1) { $page = 1; diff --git a/library/eden/mysql/subselect.php b/library/eden/mysql/subselect.php index ffe5f9c..7eb8fc8 100755 --- a/library/eden/mysql/subselect.php +++ b/library/eden/mysql/subselect.php @@ -29,7 +29,7 @@ class Eden_Mysql_Subselect extends Eden_Class { -------------------------------*/ /* Get -------------------------------*/ - public static function get(Eden_Sql_Select $parentQuery, $select = '*') { + public static function i(Eden_Sql_Select $parentQuery, $select = '*') { return self::_getMultiple(__CLASS__, $parentQuery, $select); } @@ -37,7 +37,7 @@ public static function get(Eden_Sql_Select $parentQuery, $select = '*') { -------------------------------*/ public function __construct(Eden_Sql_Select $parentQuery, $select = '*') { //Argument 2 must be a string - Eden_Mysql_Error::get()->argument(2, 'string'); + Eden_Mysql_Error::i()->argument(2, 'string'); $this->setParentQuery($parentQuery); $this->_select = is_array($select) ? implode(', ', $select) : $select; diff --git a/library/eden/mysql/utility.php b/library/eden/mysql/utility.php index defe83c..894e46e 100755 --- a/library/eden/mysql/utility.php +++ b/library/eden/mysql/utility.php @@ -32,7 +32,7 @@ class Eden_Mysql_Utility extends Eden_Sql_Query -------------------------------*/ /* Magic -------------------------------*/ - public static function get() { + public static function i() { return self::_getMultiple(__CLASS__); } @@ -45,7 +45,7 @@ public static function get() { * @return this */ public function showTables($like = NULL) { - Eden_Mysql_Error::get()->argument(1, 'string', 'null'); + Eden_Mysql_Error::i()->argument(1, 'string', 'null'); $like = $like ? ' LIKE '.$like : NULL; $this->_query = 'SHOW TABLES'.$like; @@ -60,7 +60,7 @@ public function showTables($like = NULL) { */ public function showColumns($table, $where = NULL) { //Argument 1 must be a string, 2 must be string null - Eden_Mysql_Error::get()->argument(1, 'string')->argument(2, '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; @@ -75,7 +75,7 @@ public function showColumns($table, $where = NULL) { */ public function truncate($table) { //Argument 1 must be a string - Eden_Mysql_Error::get()->argument(1, 'string'); + Eden_Mysql_Error::i()->argument(1, 'string'); $this->_query = 'TRUNCATE `' . $table .'`'; return $this; @@ -89,7 +89,7 @@ public function truncate($table) { */ public function dropTable($table) { //Argument 1 must be a string - Eden_Mysql_Error::get()->argument(1, 'string'); + Eden_Mysql_Error::i()->argument(1, 'string'); $this->_query = 'DROP TABLE `' . $table .'`'; return $this; @@ -104,7 +104,7 @@ public function dropTable($table) { */ public function renameTable($table, $name) { //Argument 1 must be a string, 2 must be string - Eden_Mysql_Error::get()->argument(1, 'string')->argument(2, 'string'); + Eden_Mysql_Error::i()->argument(1, 'string')->argument(2, 'string'); $this->_query = 'RENAME TABLE `' . $table . '` TO `' . $name . '`'; return $this; diff --git a/library/eden/oauth.php b/library/eden/oauth.php index 1df6aae..28587e6 100644 --- a/library/eden/oauth.php +++ b/library/eden/oauth.php @@ -32,7 +32,7 @@ class Eden_Oauth extends Eden_Class { -------------------------------*/ /* Get -------------------------------*/ - public static function get() { + public static function i() { return self::_getSingleton(__CLASS__); } @@ -46,7 +46,7 @@ public static function get() { * @return Eden_Oauth_Consumer */ public function getConsumer($url, $key, $secret) { - return Eden_Oauth_Consumer::get($url, $key, $secret); + return Eden_Oauth_Consumer::i($url, $key, $secret); } /** @@ -55,7 +55,7 @@ public function getConsumer($url, $key, $secret) { * @return Eden_Oauth_Server */ public function getServer() { - return Eden_Oauth_Server::get(); + return Eden_Oauth_Server::i(); } /** @@ -71,7 +71,7 @@ public function getServer() { */ public function getHmacPostRequestToken($url, $key, $secret, array $query = array(), $realm = NULL) { //argument test - Eden_Oauth_Error::get() + 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 @@ -99,7 +99,7 @@ public function getHmacPostRequestToken($url, $key, $secret, array $query = arra */ public function getPlainPostRequestToken($url, $key, $secret, array $query = array(), $realm = NULL) { //argument test - Eden_Oauth_Error::get() + 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 @@ -127,7 +127,7 @@ public function getPlainPostRequestToken($url, $key, $secret, array $query = arr */ public function getHmacPostAuthorizationRequestToken($url, $key, $secret, array $query = array(), $realm = NULL) { //argument test - Eden_Oauth_Error::get() + 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 @@ -156,7 +156,7 @@ public function getHmacPostAuthorizationRequestToken($url, $key, $secret, array */ public function getPlainPostAuthorizationRequestToken($url, $key, $secret, array $query = array(), $realm = NULL) { //argument test - Eden_Oauth_Error::get() + 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 @@ -185,7 +185,7 @@ public function getPlainPostAuthorizationRequestToken($url, $key, $secret, array */ public function getHmacGetRequestToken($url, $key, $secret, array $query = array(), $realm = NULL) { //argument test - Eden_Oauth_Error::get() + 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 @@ -213,7 +213,7 @@ public function getHmacGetRequestToken($url, $key, $secret, array $query = array */ public function getPlainGetRequestToken($url, $key, $secret, array $query = array(), $realm = NULL) { //argument test - Eden_Oauth_Error::get() + 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 @@ -241,7 +241,7 @@ public function getPlainGetRequestToken($url, $key, $secret, array $query = arra */ public function getHmacGetAuthorizationRequestToken($url, $key, $secret, array $query = array(), $realm = NULL) { //argument test - Eden_Oauth_Error::get() + 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 @@ -270,7 +270,7 @@ public function getHmacGetAuthorizationRequestToken($url, $key, $secret, array $ */ public function getPlainGetAuthorizationRequestToken($url, $key, $secret, array $query = array(), $realm = NULL) { //argument test - Eden_Oauth_Error::get() + 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 @@ -303,7 +303,7 @@ public function getPlainGetAuthorizationRequestToken($url, $key, $secret, array public function getHmacPostAccessToken($url, $key, $secret, $token, $tokenSecret, array $query = array(), $realm = NULL, $verifier = NULL) { //argument test - Eden_Oauth_Error::get() + 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 @@ -342,7 +342,7 @@ public function getHmacPostAccessToken($url, $key, $secret, $token, public function getPlainPostAccessToken($url, $key, $secret, $token, $tokenSecret, array $query = array(), $realm = NULL, $verifier = NULL) { //argument test - Eden_Oauth_Error::get() + 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 @@ -381,7 +381,7 @@ public function getPlainPostAccessToken($url, $key, $secret, $token, public function getHmacPostAuthorizationAccessToken($url, $key, $secret, $token, $tokenSecret, array $query = array(), $realm = NULL, $verifier = NULL) { //argument test - Eden_Oauth_Error::get() + 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 @@ -421,7 +421,7 @@ public function getHmacPostAuthorizationAccessToken($url, $key, $secret, $token, public function getPlainPostAuthorizationAccessToken($url, $key, $secret, $token, $tokenSecret, array $query = array(), $realm = NULL, $verifier = NULL) { //argument test - Eden_Oauth_Error::get() + 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 @@ -461,7 +461,7 @@ public function getPlainPostAuthorizationAccessToken($url, $key, $secret, $token public function getHmacGetAccessToken($url, $key, $secret, $token, $tokenSecret, array $query = array(), $realm = NULL, $verifier = NULL) { //argument test - Eden_Oauth_Error::get() + 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 @@ -500,7 +500,7 @@ public function getHmacGetAccessToken($url, $key, $secret, $token, public function getPlainGetAccessToken($url, $key, $secret, $token, $tokenSecret, array $query = array(), $realm = NULL, $verifier = NULL) { //argument test - Eden_Oauth_Error::get() + 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 @@ -539,7 +539,7 @@ public function getPlainGetAccessToken($url, $key, $secret, $token, public function getHmacGetAuthorizationAccessToken($url, $key, $secret, $token, $tokenSecret, array $query = array(), $realm = NULL, $verifier = NULL) { //argument test - Eden_Oauth_Error::get() + 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 @@ -579,7 +579,7 @@ public function getHmacGetAuthorizationAccessToken($url, $key, $secret, $token, public function getPlainGetAuthorizationAccessToken($url, $key, $secret, $token, $tokenSecret, array $query = array(), $realm = NULL, $verifier = NULL) { //argument test - Eden_Oauth_Error::get() + 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 diff --git a/library/eden/oauth/consumer.php b/library/eden/oauth/consumer.php index 4f31fb2..e8d6376 100644 --- a/library/eden/oauth/consumer.php +++ b/library/eden/oauth/consumer.php @@ -47,7 +47,7 @@ class Eden_Oauth_Consumer extends Eden_Oauth_Base { -------------------------------*/ /* Get -------------------------------*/ - public static function get($url, $key, $secret) { + public static function i($url, $key, $secret) { return self::_getMultiple(__CLASS__, $url, $key, $secret); } @@ -55,7 +55,7 @@ public static function get($url, $key, $secret) { -------------------------------*/ public function __construct($url, $key, $secret) { //argument test - Eden_Oauth_Error::get() + 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 @@ -79,7 +79,7 @@ public function __construct($url, $key, $secret) { * @return array */ public function getMeta($key = NULL) { - Eden_Oauth_Error::get()->argument(1, 'string', 'null'); + Eden_Oauth_Error::i()->argument(1, 'string', 'null'); if(isset($this->_meta[$key])) { return $this->_meta[$key]; @@ -95,7 +95,7 @@ public function getMeta($key = NULL) { * @return this */ public function setHeaders($key, $value = NULL) { - Eden_Oauth_Error::get() + Eden_Oauth_Error::i() ->argument(1, 'array', 'string') ->argument(2, 'scalar','null'); @@ -175,7 +175,7 @@ public function setSignatureToPlainText() { * @return this */ public function useAuthorization($use = true) { - Eden_Oauth_Error::get()->argument(1, 'bool'); + Eden_Oauth_Error::i()->argument(1, 'bool'); $this->_useAuthorization = $use; return $this; } @@ -187,7 +187,7 @@ public function useAuthorization($use = true) { * @return this */ public function setRealm($realm) { - Eden_Oauth_Error::get()->argument(1, 'string'); + Eden_Oauth_Error::i()->argument(1, 'string'); $this->_realm = $realm; return $this; } @@ -200,7 +200,7 @@ public function setRealm($realm) { * @return this */ public function setVerifier($verifier) { - Eden_Oauth_Error::get()->argument(1, 'scalar'); + Eden_Oauth_Error::i()->argument(1, 'scalar'); $this->_verifier = $verifier; return $this; } @@ -214,7 +214,7 @@ public function setVerifier($verifier) { * @return this */ public function setToken($token, $secret) { - Eden_Oauth_Error::get() + Eden_Oauth_Error::i() ->argument(1, 'string') ->argument(2, 'string'); @@ -232,7 +232,7 @@ public function setToken($token, $secret) { */ public function getAuthorization($signature, $string = true) { //argument test - Eden_Oauth_Error::get() + Eden_Oauth_Error::i() ->argument(1, 'string') //Argument 1 must be a string ->argument(2, 'bool'); //Argument 2 must be a boolean @@ -374,7 +374,7 @@ public function getResponse(array $query = array()) { $url = $this->_url; //set curl - $curl = Eden_Curl::get()->verifyHost(false)->verifyPeer(false); + $curl = Eden_Curl::i()->verifyHost(false)->verifyPeer(false); //if post if($this->_method == self::POST) { diff --git a/library/eden/oauth/error.php b/library/eden/oauth/error.php index 83bd539..77a8bbc 100644 --- a/library/eden/oauth/error.php +++ b/library/eden/oauth/error.php @@ -26,7 +26,7 @@ class Eden_Oauth_Error extends Eden_Error { -------------------------------*/ /* Get -------------------------------*/ - public static function get($message = NULL, $code = 0) { + public static function i($message = NULL, $code = 0) { $class = __CLASS__; return new $class($message, $code); } diff --git a/library/eden/oauth/server.php b/library/eden/oauth/server.php index a90872a..6fec013 100644 --- a/library/eden/oauth/server.php +++ b/library/eden/oauth/server.php @@ -26,7 +26,7 @@ class Eden_Oauth_Server extends Eden_Oauth_Base { -------------------------------*/ /* Get -------------------------------*/ - public static function get() { + public static function i() { return self::_getMultiple(__CLASS__); } diff --git a/library/eden/path.php b/library/eden/path.php index 2791f04..4f347f8 100644 --- a/library/eden/path.php +++ b/library/eden/path.php @@ -18,7 +18,7 @@ * @author Christian Blanquera * @version $Id: path.php 3 2010-01-06 01:16:54Z blanquera $ */ -class Eden_Path extends Eden_Class implements ArrayAccess { +class Eden_Path extends Eden_Type_String implements ArrayAccess { /* Constants -------------------------------*/ /* Public Properties @@ -29,7 +29,7 @@ class Eden_Path extends Eden_Class implements ArrayAccess { -------------------------------*/ /* Get -------------------------------*/ - public static function get($path) { + public static function i($path) { return self::_getMultiple(__CLASS__, $path); } @@ -37,12 +37,12 @@ public static function get($path) { -------------------------------*/ public function __construct($path) { //argument 1 must be a string - Eden_Path_Error::get()->argument(1, 'string'); - $this->_path = $this->_format($path); + Eden_Path_Error::i()->argument(1, 'string'); + $this->_data = $this->_format($path); } public function __toString() { - return $this->_path; + return $this->_data; } /* Public Methods @@ -57,10 +57,10 @@ public function __toString() { */ public function absolute($root = NULL) { //argument 1 must be a string or null - Eden_Path_Error::get()->argument(1, 'string', 'null'); + Eden_Path_Error::i()->argument(1, 'string', 'null'); //if path is a directory or file - if(is_dir($this->_path) || is_file($this->_path)) { + if(is_dir($this->_data) || is_file($this->_data)) { return $this; } @@ -71,18 +71,18 @@ public function absolute($root = NULL) { } //get the absolute path - $absolute = $this->_format($root).$this->_path; + $absolute = $this->_format($root).$this->_data; //if absolute is a directory or file if(is_dir($absolute) || is_file($absolute)) { - $this->_path = $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::get() + Eden_Path_Error::i() ->setMessage(Eden_Path_Error::FULL_PATH_NOT_FOUND) - ->addVariable($this->_path) + ->addVariable($this->_data) ->addVariable($absolute) ->trigger(); } @@ -95,7 +95,7 @@ public function absolute($root = NULL) { */ public function append($path) { //argument 1 must be a string - $error = Eden_Path_Error::get()->argument(1, 'string'); + $error = Eden_Path_Error::i()->argument(1, 'string'); //each argument will be a path $paths = func_get_args(); @@ -105,7 +105,7 @@ public function append($path) { //check for type errors $error->argument($i + 1, $path, 'string'); //add to path - $this->_path .= $this->_format($path); + $this->_data .= $this->_format($path); } return $this; @@ -119,7 +119,7 @@ public function append($path) { */ public function prepend($path) { //argument 1 must be a string - $error = Eden_Path_Error::get()->argument(1, 'string'); + $error = Eden_Path_Error::i()->argument(1, 'string'); //each argument will be a path $paths = func_get_args(); @@ -129,7 +129,7 @@ public function prepend($path) { //check for type errors $error->argument($i + 1, $path, 'string'); //add to path - $this->_path = $this->_format($path).$this-_path; + $this->_data = $this->_format($path).$this-_path; } return $this; @@ -143,7 +143,7 @@ public function prepend($path) { */ public function replace($path) { //argument 1 must be a string - Eden_Path_Error::get()->argument(1, 'string'); + Eden_Path_Error::i()->argument(1, 'string'); //get the path array $pathArray = $this->getArray(); @@ -155,7 +155,7 @@ public function replace($path) { $pathArray[] = $path; //assign back to path - $this->_path = implode('/', $pathArray); + $this->_data = implode('/', $pathArray); return $this; } @@ -173,7 +173,7 @@ public function pop(){ array_pop($pathArray); //set path - $this->_path = implode('/', $pathArray); + $this->_data = implode('/', $pathArray); return $this; } @@ -184,7 +184,7 @@ public function pop(){ * @return array */ public function getArray() { - return explode('/', $this->_path); + return explode('/', $this->_data); } /** @@ -205,7 +205,7 @@ public function offsetSet($offset, $value) { $pathArray = $this->getArray(); if($offset > 0 && $offset < count($pathArray)) { $pathArray[$offset] = $value; - $this->_path = implode('/', $pathArray); + $this->_data = implode('/', $pathArray); } } } @@ -289,7 +289,7 @@ class Eden_Path_Error extends Eden_Error { -------------------------------*/ /* Get -------------------------------*/ - public static function get($message = NULL, $code = 0) { + public static function i($message = NULL, $code = 0) { $class = __CLASS__; return new $class($message, $code); } diff --git a/library/eden/paypal/error.php b/library/eden/paypal/error.php index 504e70f..d8f8f14 100644 --- a/library/eden/paypal/error.php +++ b/library/eden/paypal/error.php @@ -1,42 +1,42 @@ - -/* - * 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. - */ - -/** - * Eventbrite Errors - * - * @package Eden - * @category Paypal - * @author Christian Blanquera - * @version $Id: exception.php 1 2010-01-02 23:06:36Z blanquera $ - */ -class Eden_Paypal_Error extends Eden_Error { - /* Constants - -------------------------------*/ - /* Public Properties - -------------------------------*/ - /* Protected Properties - -------------------------------*/ - /* Private Properties - -------------------------------*/ - /* Get - -------------------------------*/ - public static function get($message = NULL, $code = 0) { - $class = __CLASS__; - return new $class($message, $code); - } - - /* Magic - -------------------------------*/ - /* Public Methods - -------------------------------*/ - /* Protected Methods - -------------------------------*/ - /* Private Methods - -------------------------------*/ + +/* + * 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. + */ + +/** + * Eventbrite Errors + * + * @package Eden + * @category Paypal + * @author Christian Blanquera + * @version $Id: exception.php 1 2010-01-02 23:06:36Z blanquera $ + */ +class Eden_Paypal_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/registry.php b/library/eden/registry.php index b9b8059..752982e 100755 --- a/library/eden/registry.php +++ b/library/eden/registry.php @@ -33,12 +33,12 @@ class Eden_Registry extends Eden_Type_Array { -------------------------------*/ /* Get -------------------------------*/ - public static function get() { + public static function i() { $data = self::_getStart(func_get_args()); foreach($data as $key => $value) { if(is_array($value)) { - $data[$key] = self::get($value); + $data[$key] = self::i($value); } } @@ -47,6 +47,10 @@ public static function get() { /* Magic -------------------------------*/ + public function __toString() { + return json_encode($this->getArray()); + } + /* Public Methods -------------------------------*/ /** @@ -54,7 +58,7 @@ public static function get() { * * @return mixed */ - public function getData($modified = true) { + public function get($modified = true) { $args = func_get_args(); if(count($args) == 0) { @@ -94,7 +98,7 @@ public function getData($modified = true) { * * @return Eden_Registry */ - public function setData() { + public function set() { $args = func_get_args(); if(count($args) < 2) { @@ -105,7 +109,7 @@ public function setData() { if(count($args) == 1) { if(is_array($args[0])) { - $args[0] = self::get($args[0]); + $args[0] = self::i($args[0]); } $this->_data[$key] = $args[0]; @@ -114,7 +118,7 @@ public function setData() { } if(!isset($this->_data[$key]) || !($this->_data[$key] instanceof Eden_Registry)) { - $this->_data[$key] = self::get(); + $this->_data[$key] = self::i(); } call_user_func_array(array($this->_data[$key], __FUNCTION__), $args); @@ -156,7 +160,7 @@ public function isKey() { * * @return Eden_Registry */ - public function removeKey() { + public function remove() { $args = func_get_args(); if(count($args) == 0) { diff --git a/library/eden/route.php b/library/eden/route.php index bf00700..9244328 100755 --- a/library/eden/route.php +++ b/library/eden/route.php @@ -6,8 +6,12 @@ * 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. @@ -29,14 +33,12 @@ class Eden_Route extends Eden_Class { /* Protected Properties -------------------------------*/ protected static $_instance = NULL; - protected $_classes = array(); //class registry - protected $_methods = array(); //tracks methods for classes /* Private Properties -------------------------------*/ /* Get -------------------------------*/ - public static function get() { + public static function i() { $class = __CLASS__; if(is_null(self::$_instance)) { self::$_instance = new $class(); @@ -49,358 +51,36 @@ public static function get() { -------------------------------*/ /* Public Methods -------------------------------*/ - /** - * Routes a class - * - * @param *string the class route name - * @param *string the name of the class to route to - * @return Eden_Route - */ - public function routeClass($route, $class) { - Eden_Route_Error::get() - ->argument(1, 'string') //argument 1 must be a string - ->argument(2, 'string'); //argument 2 must be a string + public function getClass($class = NULL, array $args = array()) { + $route = Eden_Route_Class::i(); - if(isset($this->_classes[$class])) { - $this->_classes[$route] = $this->_classes[$class]; - return $this; + if(is_null($class)) { + return $route; } - $this->_classes[$route] = $class; - return $this; + return $route->callArray($class, $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 getRouteClass($route, $default = NULL) { - //argument 1 must be a string - Eden_Route_Error::get()->argument(1, 'string'); + public function getMethod($class = NULL, $method = NULL, array $args = array()) { + $route = Eden_Route_Method::i(); - if(isset($this->_classes[$route])) { - return $this->_classes[$route]; + if(is_null($class) || is_null($method)) { + return $route; } - return $default; + return $route->call($class, $method, $args); } - /** - * Returns the class route name that will be routed to given the class. - * - * @param *string the name of the class - * @param string|null returns this variable if no route is found - * @return string|variable - */ - public function getClassRoute($class, $default = NULL) { - //argument 1 must be a string - Eden_Route_Error::get()->argument(1, 'string'); + public function getFunction($function = NULL, array $args = array()) { + $route = Eden_Route_Function::i(); - foreach($this->_classes as $i => $to) { - if($to == $class) { - return $i; - } + if(is_null($function)) { + return $route; } - return $default; - } - - /** - * Returns all class routes - * - * @return array - */ - public function getClassRoutes() { - return $this->_classes; + return $route->callArray($function, $args); } - /** - * Checks to see if a name is a route - * - * @param string - * @return bool - */ - public function isClassRoute($route) { - return isset($this->_classes[$route]); - } - - /** - * 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 routeMethod($routeClass, $routeMethod, $class, $method = NULL) { - //argument test - Eden_Route_Error::get() - ->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 method is not a string - if(!is_string($method)) { - $method = $routeMethod; - } - - $routeClass = $this->getRouteClass($routeClass, $routeClass); - $class = $this->getRouteClass($class, $class); - - $this->_methods[$routeClass][$routeMethod] = array($class, $method); - - return $this; - } - - /** - * 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 getRouteMethod($class, $method, $default = NULL) { - Eden_Route_Error::get() - ->argument(1, 'string') //argument 1 must be a string - ->argument(2, 'string'); //argument 2 must be a string - - $class = $this->getRouteClass($class, $class); - - if(isset($this->_methods[$class][$method])) { - return $this->_methods[$class][$method]; - } - - return $default; - } - - /** - * Returns the route name that will be routed to given the class and method. - * - * @param *string the name of the class - * @param *string the name of the method - * @param string|null returns this variable if no route is found - * @return array|variable - */ - public function getMethodRoute($class, $method, $default = NULL) { - Eden_Route_Error::get() - ->argument(1, 'string') //argument 1 must be a string - ->argument(2, 'string'); //argument 2 must be a string - - $class = $this->getRouteClass($class, $class); - - foreach($this->_methods as $routeClass => $routeMethods) { - foreach($routeMethods as $routeMethod => $to) { - if($to[0] == $class && $to[1] == $method) { - return array($routeClass, $routeMethod); - } - } - } - return $default; - } - - /** - * Checks to see if a name is a route - * - * @param string - * @param string - * @return bool - */ - public function isMethodRoute($class, $method) { - return isset($this->_methods[$class][$method]); - } - - /** - * Returns all method routes - * - * @return array - */ - public function getMethodRoutes() { - return $this->_methods; - } - - /** - * Gets a class considering all routes. - * - * @param *string class - * @param [variable..] arguments - * @return object - */ - public function getClass($class) { - //argument 1 must be a string - Eden_Route_Error::get()->argument(1, 'string'); - - $args = func_get_args(); - $class = array_shift($args); - - - return $this->getClassArray($class, $args); - } - - /** - * Gets a class considering all routes. - * - * @param *string class - * @param array arguments - * @return object - */ - public function getClassArray($class, array $args = array()) { - //argument 1 must be a string - Eden_Route_Error::get()->argument(1, 'string'); - - $route = $this->getRouteClass($class, $class); - $reflect = new ReflectionClass($route); - - if(method_exists($route, 'get')) { - $declared = $reflect - ->getMethod('get') - ->getDeclaringClass() - ->getName(); - - if($declared == $route) { - return $this->callMethod($class, 'get', NULL, $args); - } - } - - return $reflect->newInstanceArgs($args); - } - - /** - * Calls a method considering all routes - * - * @param *string|null the class name - * @param *string|null the method name - * @param true|null|object the instance; - * if null then the call will be treated as a - * static class; if true then an instance will - * be generated - * @param array the arguments you want to pass - * into the method - * @return mixed - */ - public function callMethod($class, $method, $instance = NULL, array $args = array()) { - //argument test - Eden_Route_Error::get() - ->argument(1, 'string', 'object') //argument 1 must be string or object - ->argument(2, 'string') //argument 2 must be string - ->argument(3, 'object', 'bool', 'null'); //argument 3 must be object, bool or null - - if(is_object($class)) { - $instance = $class; - $class = get_class($class); - } - - //class might be a route - //lets make sure that we are dealing with the right class - $class = $this->getRouteClass($class, $class); - - //method might be a route - //lets make sure we are dealing with the right method - list($class, $method) = $this->getRouteMethod($class, $method, array($class, $method)); - - //class does not exist - if(!class_exists($class)) { - //throw exception - Eden_Route_Error::get() - ->setMessage(Eden_Route_Error::CLASS_NOT_EXISTS) - ->addVariable($class) - ->addVariable($method) - ->trigger(); - } - - if(!method_exists($class, $method)) { - //throw exception - Eden_Route_Error::get() - ->setMessage(Eden_Route_Error::METHOD_NOT_EXISTS) - ->addVariable($class) - ->addVariable($method) - ->trigger(); - } - - //if instance is true - //we want to load the - //instance for the user - if($instance === true) { - $instance = $this->getClass($class); - } - - //if instance is not an object - if(!is_object($instance)) { - if(!method_exists($class, $method)) { - //throw exception - Eden_Route_Error::get() - ->setMessage(Eden_Route_Error::STATIC_ERROR) - ->addVariable($class) - ->addVariable($method) - ->trigger(); - } - - return call_user_func_array($class.'::'.$method, $args); // As of 5.2.3 - } - - return call_user_func_array(array(&$instance, $method), $args); - } - - /** - * Calls a function in a controlled environment - * - * @param *string the name of the function - * @param array the arguments you want to pass into the method - * @return mixed - */ - public function callFunction($func, array $args = array()) { - Eden_Route_Error::get()->argument(0, 'string'); //argument 1 must be a string - - try { - //try to run the function using PHP call_user_func_array - return call_user_func_array($func, $args); - } catch(_Exception $e) { - Eden_Route_Error::get() - ->setMessage(Eden_Route_Error::FUNCTION_ERROR) - ->addVariable($func) - ->trigger(); - } - } - - /* Protected Methods - -------------------------------*/ - /* Private Methods - -------------------------------*/ -} - -/** - * 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 - -------------------------------*/ - /* Get - -------------------------------*/ - public static function get($message = NULL, $code = 0) { - $class = __CLASS__; - return new $class($message, $code); - } - - /* Magic - -------------------------------*/ - /* Public Methods - -------------------------------*/ /* Protected Methods -------------------------------*/ /* Private Methods diff --git a/library/eden/route/class.php b/library/eden/route/class.php new file mode 100644 index 0000000..b81c418 --- /dev/null +++ b/library/eden/route/class.php @@ -0,0 +1,161 @@ + +/* + * 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. + */ + +/** + * Definition for overriding classes. + * This class also provides methods to list out various routes + * + * @package Eden + * @category route + * @author Christian Blanquera + * @version $Id: route.php 1 2010-01-02 23:06:36Z blanquera $ + */ +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 + -------------------------------*/ + /** + * 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[$route] = $class; + return $this; + } + + /** + * 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(isset($this->_route[$route])) { + return $this->_route[$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[$route]); + } + + /** + * 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(); + + if($declared == $route) { + return Eden_Route_Method::i()->callStatic($class, 'i', $args); + } + } + + return $reflect->newInstanceArgs($args); + } + + /* 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..2e4df7c --- /dev/null +++ b/library/eden/route/error.php @@ -0,0 +1,34 @@ + +/** + * 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 + -------------------------------*/ + /* 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/route/function.php b/library/eden/route/function.php new file mode 100644 index 0000000..362851a --- /dev/null +++ b/library/eden/route/function.php @@ -0,0 +1,139 @@ + +/* + * 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. + */ + +/** + * Definition for overriding classes. + * This class also provides methods to list out various routes + * + * @package Eden + * @category route + * @author Christian Blanquera + * @version $Id: route.php 1 2010-01-02 23:06:36Z blanquera $ + */ +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 + -------------------------------*/ + /** + * 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[$route] = $function; + return $this; + } + + /** + * 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(isset($this->_route[$route])) { + return $this->_route[$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[$route]); + } + + /** + * 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); + } + + /* 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..1c42266 --- /dev/null +++ b/library/eden/route/method.php @@ -0,0 +1,253 @@ + +/* + * 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. + */ + +/** + * 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 + * @subpackage route + * @category framework + * @author Christian Blanquera + * @version $Id: route.php 1 2010-01-02 23:06:36Z blanquera $ + */ +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 + -------------------------------*/ + /** + * 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); + } + + if(is_string($class)) { + $class = $route->getRoute($class); + } + + $this->_route[$source][$alias] = array($class, $method); + + return $this; + } + + /** + * 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(isset($this->_route[NULL][$method])) { + return $this->_route[NULL][$method]; + } + + $class = Eden_Route_Class::i()->getRoute($class); + + if(isset($this->_route[$class][$method])) { + return $this->_route[$class][$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) { + return isset($this->_route[$class][$method]); + } + + /** + * 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(is_object($class)) { + $instance = $class; + } + + //if there is no 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 + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/session.php b/library/eden/session.php index d20d066..6285f2b 100755 --- a/library/eden/session.php +++ b/library/eden/session.php @@ -32,7 +32,7 @@ class Eden_Session extends Eden_Class implements ArrayAccess, Iterator { -------------------------------*/ /* Get -------------------------------*/ - public static function get() { + public static function i() { return self::_getSingleton(__CLASS__); } @@ -79,8 +79,8 @@ public function stop() { * @param mixed * @return this */ - public function setData($data, $value = NULL) { - $error = Eden_Session_Error::get()->argument(1, 'array', 'string'); + 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(); @@ -102,8 +102,8 @@ public function setData($data, $value = NULL) { * @param string|null * @return mixed */ - public function getData($key = NULL) { - $error = Eden_Session_Error::get()->argument(1, 'string', 'null'); + 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(); @@ -127,7 +127,7 @@ public function getData($key = NULL) { */ public function getId() { if(!self::$_session) { - Eden_Session_Error::get(Eden_Session_Error::ERROR_NOT_STARTED)->trigger(); + Eden_Session_Error::i(Eden_Session_Error::ERROR_NOT_STARTED)->trigger(); } return session_id(); @@ -140,7 +140,7 @@ public function getId() { * @return int */ public function setId($sid) { - $error = Eden_Session_Error::get()->argument(1, 'numeric'); + $error = Eden_Session_Error::i()->argument(1, 'numeric'); if(!self::$_session) { $error->setMessage(Eden_Session_Error::ERROR_ERROR_NOT_STARTED)->trigger(); @@ -156,7 +156,7 @@ public function setId($sid) { * @return this */ public function remove($name) { - Eden_Session_Error::get()->argument(1, 'string'); + Eden_Session_Error::i()->argument(1, 'string'); if(isset($_SESSION[$name])) { unset($_SESSION[$name]); @@ -172,7 +172,7 @@ public function remove($name) { */ public function clear() { if(!self::$_session) { - Eden_Session_Error::get(Eden_Session_Error::ERROR_NOT_STARTED)->trigger(); + Eden_Session_Error::i(Eden_Session_Error::ERROR_NOT_STARTED)->trigger(); } $_SESSION = array(); @@ -188,7 +188,7 @@ public function clear() { */ public function rewind() { if(!self::$_session) { - Eden_Session_Error::get(Eden_Session_Error::ERROR_NOT_STARTED)->trigger(); + Eden_Session_Error::i(Eden_Session_Error::ERROR_NOT_STARTED)->trigger(); } reset($_SESSION); @@ -202,7 +202,7 @@ public function rewind() { */ public function current() { if(!self::$_session) { - Eden_Session_Error::get(Eden_Session_Error::ERROR_NOT_STARTED)->trigger(); + Eden_Session_Error::i(Eden_Session_Error::ERROR_NOT_STARTED)->trigger(); } return current($_SESSION); @@ -216,7 +216,7 @@ public function current() { */ public function key() { if(!self::$_session) { - Eden_Session_Error::get(Eden_Session_Error::ERROR_NOT_STARTED)->trigger(); + Eden_Session_Error::i(Eden_Session_Error::ERROR_NOT_STARTED)->trigger(); } return key($_SESSION); @@ -230,7 +230,7 @@ public function key() { */ public function next() { if(!self::$_session) { - Eden_Session_Error::get(Eden_Session_Error::ERROR_NOT_STARTED)->trigger(); + Eden_Session_Error::i(Eden_Session_Error::ERROR_NOT_STARTED)->trigger(); } next($_SESSION); @@ -244,7 +244,7 @@ public function next() { */ public function valid() { if(!self::$_session) { - Eden_Session_Error::get(Eden_Session_Error::ERROR_NOT_STARTED)->trigger(); + Eden_Session_Error::i(Eden_Session_Error::ERROR_NOT_STARTED)->trigger(); } return isset($_SESSION[$this->key()]); @@ -259,7 +259,7 @@ public function valid() { */ public function offsetSet($offset, $value) { if(!self::$_session) { - Eden_Session_Error::get(Eden_Session_Error::ERROR_NOT_STARTED)->trigger(); + Eden_Session_Error::i(Eden_Session_Error::ERROR_NOT_STARTED)->trigger(); } if (is_null($offset)) { @@ -277,7 +277,7 @@ public function offsetSet($offset, $value) { */ public function offsetExists($offset) { if(!self::$_session) { - Eden_Session_Error::get(Eden_Session_Error::ERROR_NOT_STARTED)->trigger(); + Eden_Session_Error::i(Eden_Session_Error::ERROR_NOT_STARTED)->trigger(); } return isset($_SESSION[$offset]); @@ -291,7 +291,7 @@ public function offsetExists($offset) { */ public function offsetUnset($offset) { if(!self::$_session) { - Eden_Session_Error::get(Eden_Session_Error::ERROR_NOT_STARTED)->trigger(); + Eden_Session_Error::i(Eden_Session_Error::ERROR_NOT_STARTED)->trigger(); } unset($_SESSION[$offset]); @@ -305,7 +305,7 @@ public function offsetUnset($offset) { */ public function offsetGet($offset) { if(!self::$_session) { - Eden_Session_Error::get(Eden_Session_Error::ERROR_NOT_STARTED)->trigger(); + Eden_Session_Error::i(Eden_Session_Error::ERROR_NOT_STARTED)->trigger(); } return isset($_SESSION[$offset]) ? $_SESSION[$offset] : NULL; @@ -333,7 +333,7 @@ class Eden_Session_Error extends Eden_Error { -------------------------------*/ /* Get -------------------------------*/ - public static function get($message = NULL, $code = 0) { + public static function i($message = NULL, $code = 0) { $class = __CLASS__; return new $class($message, $code); } diff --git a/library/eden/sql/database.php b/library/eden/sql/database.php index bf2e958..f8f8765 100755 --- a/library/eden/sql/database.php +++ b/library/eden/sql/database.php @@ -30,7 +30,7 @@ class Eden_Sql_Database extends Eden_Event { -------------------------------*/ /* Get -------------------------------*/ - public static function get() { + public static function i() { return self::_getSingleton(__CLASS__); } @@ -45,9 +45,9 @@ public static function get() { */ public function delete($table = NULL) { //Argument 1 must be a string or null - Eden_Sql_Error::get()->argument(1, 'string', 'null'); + Eden_Sql_Error::i()->argument(1, 'string', 'null'); - return Eden_Sql_Delete::get($table); + return Eden_Sql_Delete::i($table); } /** @@ -57,9 +57,9 @@ public function delete($table = NULL) { */ public function insert($table = NULL) { //Argument 1 must be a string or null - Eden_Sql_Error::get()->argument(1, 'string', 'null'); + Eden_Sql_Error::i()->argument(1, 'string', 'null'); - return Eden_Sql_Insert::get($table); + return Eden_Sql_Insert::i($table); } /** @@ -69,9 +69,9 @@ public function insert($table = NULL) { */ public function select($select = '*') { //Argument 1 must be a string or array - Eden_Sql_Error::get()->argument(1, 'string', 'array'); + Eden_Sql_Error::i()->argument(1, 'string', 'array'); - return Eden_Sql_Select::get($select); + return Eden_Sql_Select::i($select); } /** @@ -81,9 +81,9 @@ public function select($select = '*') { */ public function update($table = NULL) { //Argument 1 must be a string or null - Eden_Sql_Error::get()->argument(1, 'string', 'null'); + Eden_Sql_Error::i()->argument(1, 'string', 'null'); - return Eden_Sql_Update::get($table); + return Eden_Sql_Update::i($table); } /* Protected Methods diff --git a/library/eden/sql/delete.php b/library/eden/sql/delete.php index 5d06d92..89a15b2 100755 --- a/library/eden/sql/delete.php +++ b/library/eden/sql/delete.php @@ -29,7 +29,7 @@ class Eden_Sql_Delete extends Eden_Sql_Query { -------------------------------*/ /* Get -------------------------------*/ - public static function get($table = NULL) { + public static function i($table = NULL) { return self::_getMultiple(__CLASS__, $table); } @@ -51,7 +51,7 @@ public function __construct($table = NULL) { */ public function setTable($table) { //Argument 1 must be a string - Eden_Sql_Error::get()->argument(1, 'string'); + Eden_Sql_Error::i()->argument(1, 'string'); $this->_table = $table; return $this; @@ -66,7 +66,7 @@ public function setTable($table) { */ public function where($where) { //Argument 1 must be a string or array - Eden_Sql_Error::get()->argument(1, 'string', 'array'); + Eden_Sql_Error::i()->argument(1, 'string', 'array'); if(is_string($where)) { $where = array($where); diff --git a/library/eden/sql/error.php b/library/eden/sql/error.php index 614f08b..7d2ab99 100755 --- a/library/eden/sql/error.php +++ b/library/eden/sql/error.php @@ -26,7 +26,7 @@ class Eden_Sql_Error extends Eden_Error { -------------------------------*/ /* Get -------------------------------*/ - public static function get($message = NULL, $code = 0) { + public static function i($message = NULL, $code = 0) { $class = __CLASS__; return new $class($message, $code); } diff --git a/library/eden/sql/insert.php b/library/eden/sql/insert.php index 68207b0..83ea9b9 100755 --- a/library/eden/sql/insert.php +++ b/library/eden/sql/insert.php @@ -29,7 +29,7 @@ class Eden_Sql_Insert extends Eden_Sql_Query { -------------------------------*/ /* Get -------------------------------*/ - public static function get($table = NULL) { + public static function i($table = NULL) { return self::_getMultiple(__CLASS__, $table); } @@ -51,7 +51,7 @@ public function __construct($table = NULL) { */ public function setTable($table) { //Argument 1 must be a string - Eden_Sql_Error::get()->argument(1, 'string'); + Eden_Sql_Error::i()->argument(1, 'string'); $this->_table = $table; return $this; @@ -68,7 +68,7 @@ public function setTable($table) { */ public function set($key, $value, $index = 0) { //argument test - Eden_Sql_Error::get() + Eden_Sql_Error::i() ->argument(1, 'string') //Argument 1 must be a string ->argument(2, 'scalar', 'null'); //Argument 2 must be scalar or null diff --git a/library/eden/sql/select.php b/library/eden/sql/select.php index 15a780d..48feb03 100755 --- a/library/eden/sql/select.php +++ b/library/eden/sql/select.php @@ -35,7 +35,7 @@ class Eden_Sql_Select extends Eden_Sql_Query { -------------------------------*/ /* Get -------------------------------*/ - public static function get($select = '*') { + public static function i($select = '*') { return self::_getMultiple(__CLASS__, $select); } @@ -56,7 +56,7 @@ public function __construct($select = '*') { */ public function select($select = '*') { //Argument 1 must be a string or array - Eden_Sql_Error::get()->argument(1, 'string', 'array'); + Eden_Sql_Error::i()->argument(1, 'string', 'array'); //if select is an array if(is_array($select)) { @@ -78,7 +78,7 @@ public function select($select = '*') { */ public function from($from) { //Argument 1 must be a string - Eden_Sql_Error::get()->argument(1, 'string'); + Eden_Sql_Error::i()->argument(1, 'string'); $this->_from = $from; return $this; @@ -97,7 +97,7 @@ public function from($from) { */ public function join($type, $table, $where, $using = true) { //argument test - Eden_Sql_Error::get() + 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 @@ -120,7 +120,7 @@ public function join($type, $table, $where, $using = true) { */ public function innerJoin($table, $where, $using = true) { //argument test - Eden_Sql_Error::get() + 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 @@ -139,7 +139,7 @@ public function innerJoin($table, $where, $using = true) { */ public function outerJoin($table, $where, $using = true) { //argument test - Eden_Sql_Error::get() + 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 @@ -158,7 +158,7 @@ public function outerJoin($table, $where, $using = true) { */ public function leftJoin($table, $where, $using = true) { //argument test - Eden_Sql_Error::get() + 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 @@ -177,7 +177,7 @@ public function leftJoin($table, $where, $using = true) { */ public function rightJoin($table, $where, $using = true) { //argument test - Eden_Sql_Error::get() + 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 @@ -194,7 +194,7 @@ public function rightJoin($table, $where, $using = true) { */ public function where($where) { //Argument 1 must be a string or array - Eden_Sql_Error::get()->argument(1, 'string', 'array'); + Eden_Sql_Error::i()->argument(1, 'string', 'array'); if(is_string($where)) { $where = array($where); @@ -215,7 +215,7 @@ public function where($where) { */ public function sortBy($field, $order = 'ASC') { //argument test - Eden_Sql_Error::get() + Eden_Sql_Error::i() ->argument(1, 'string') //Argument 1 must be a string ->argument(2, 'string'); //Argument 2 must be a string @@ -233,7 +233,7 @@ public function sortBy($field, $order = 'ASC') { */ public function groupBy($group) { //Argument 1 must be a string or array - Eden_Sql_Error::get()->argument(1, 'string', 'array'); + Eden_Sql_Error::i()->argument(1, 'string', 'array'); if(is_string($group)) { $group = array($group); @@ -253,7 +253,7 @@ public function groupBy($group) { */ public function limit($page, $length) { //argument test - Eden_Sql_Error::get() + Eden_Sql_Error::i() ->argument(1, 'numeric') //Argument 1 must be a number ->argument(2, 'numeric'); //Argument 2 must be a number diff --git a/library/eden/sql/update.php b/library/eden/sql/update.php index 56b6c02..de197a0 100755 --- a/library/eden/sql/update.php +++ b/library/eden/sql/update.php @@ -28,7 +28,7 @@ class Eden_Sql_Update extends Eden_Sql_Delete { -------------------------------*/ /* Get -------------------------------*/ - public static function get($table = NULL) { + public static function i($table = NULL) { return self::_getMultiple(__CLASS__, $table); } @@ -46,7 +46,7 @@ public static function get($table = NULL) { */ public function set($key, $value) { //argument test - Eden_Sql_Error::get() + Eden_Sql_Error::i() ->argument(1, 'string') //Argument 1 must be a string ->argument(2, 'scalar', 'null'); //Argument 2 must be scalar or null diff --git a/library/eden/template.php b/library/eden/template.php index a406d06..9905cf8 100755 --- a/library/eden/template.php +++ b/library/eden/template.php @@ -31,7 +31,7 @@ class Eden_Template extends Eden_Class { -------------------------------*/ /* Get -------------------------------*/ - public static function get() { + public static function i() { return self::_getMultiple(__CLASS__); } @@ -46,8 +46,8 @@ public static function get() { * @param mixed * @return this */ - public function setData($data, $value = NULL) { - Eden_Template_Error::get()->argument(0, 'array', 'string'); + public function set($data, $value = NULL) { + Eden_Template_Error::i()->argument(0, 'array', 'string'); if(is_array($data)) { $this->_data = $data; @@ -66,7 +66,7 @@ public function setData($data, $value = NULL) { * @return string */ public function parseString($string) { - Eden_Template_Error::get()->argument(0, 'string'); + Eden_Template_Error::i()->argument(0, 'string'); foreach($this->_data as $key => $value) { $string = str_replace($key, $value, $string); } @@ -81,7 +81,7 @@ public function parseString($string) { * @return string */ public function parsePhp($____file) { - Eden_Template_Error::get()->argument(0, $____file, 'string'); + Eden_Template_Error::i()->argument(0, $____file, 'string'); extract($this->_data, EXTR_SKIP); // Extract the values to a local namespace ob_start(); // Start output buffering @@ -98,7 +98,7 @@ public function parsePhp($____file) { * @return string */ public function parseEngine($template) { - Eden_Template_Error::get()->argument(0, 'string'); + Eden_Template_Error::i()->argument(0, 'string'); $lines = explode("\n", $template); $count = count($lines); @@ -143,8 +143,8 @@ public function parseEngine($template) { if(isset($this->_data[$key]) && is_array($this->_data[$key])) { foreach($this->_data[$key] as $value) { if(is_array($value)) { - $lines[$i][] = Eden_Template::get() - ->setData($value) + $lines[$i][] = Eden_Template::i() + ->set($value) ->parseEngine(implode("\n", $subTemplate)); } } @@ -178,7 +178,7 @@ class Eden_Template_Error extends Eden_Error { -------------------------------*/ /* Get -------------------------------*/ - public static function get($message = NULL, $code = 0) { + public static function i($message = NULL, $code = 0) { $class = __CLASS__; return new $class($message, $code); } diff --git a/library/eden/timezone.php b/library/eden/timezone.php index 97c813f..770de0f 100644 --- a/library/eden/timezone.php +++ b/library/eden/timezone.php @@ -29,7 +29,7 @@ class Eden_Timezone extends Eden_Class { -------------------------------*/ /* Get -------------------------------*/ - public static function get() { + public static function i() { return self::_getSingleton(__CLASS__); } @@ -45,7 +45,7 @@ public static function get() { */ public function getTimeZones($key = NULL) { //Argument 1 must be a string or null - Eden_Timezone_Error::get()->argument(1, 'string', 'null'); + Eden_Timezone_Error::i()->argument(1, 'string', 'null'); $zones = array(); $zonesProcessed = array(); @@ -88,7 +88,7 @@ public function getTimeZones($key = NULL) { */ public function getTimeInZone($zoneName, $systemTime = NULL) { //argument testing - Eden_Timezone_Error::get() + Eden_Timezone_Error::i() ->argument(1, 'string') //Argument 1 must be a string ->argument(2, 'int', 'null'); //Argument 2 must be a string or null @@ -120,7 +120,7 @@ class Eden_Timezone_Error extends Eden_Error { -------------------------------*/ /* Get -------------------------------*/ - public static function get($message = NULL, $code = 0) { + public static function i($message = NULL, $code = 0) { $class = __CLASS__; return new $class($message, $code); } diff --git a/library/eden/tool.php b/library/eden/tool.php index e19a199..11a8f51 100644 --- a/library/eden/tool.php +++ b/library/eden/tool.php @@ -29,7 +29,7 @@ class Eden_Tool extends Eden_Class { -------------------------------*/ /* Get -------------------------------*/ - public static function get() { + public static function i() { return self::_getSingleton(__CLASS__); } diff --git a/library/eden/tumblr/base.php b/library/eden/tumblr/base.php index 13f6146..13640f9 100644 --- a/library/eden/tumblr/base.php +++ b/library/eden/tumblr/base.php @@ -1,207 +1,207 @@ - -/* - * 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. - */ - -/** - * Twitter oauth - * - * @package Eden - * @category twitter - * @author Christian Blanquera - * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ - */ -class Eden_Tumblr_Base extends Eden_Oauth_Base { - /* 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'; - const SECRET_KEY = 'akHvmf5Fsoo7U9ztx3triIx2mczWfze3SEgIgaiGBYTlkqD0kN'; - const VERSION_HEADER = 'GData-Version'; - const GDATA_VERSION = 2; - - - /* Public Properties - -------------------------------*/ - /* Protected Properties - -------------------------------*/ - protected $_key = NULL; - protected $_secret = NULL; - - /* Private Properties - -------------------------------*/ - /* Get - -------------------------------*/ - /* Magic - -------------------------------*/ - public function __construct($key, $secret) { - //argument test - Eden_Twitter_Error::get() - ->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 - -------------------------------*/ - public function getRequestToken() { - return Eden_Oauth::get() - ->getConsumer(self::REQUEST_URL, $this->_key, $this->_secret) - ->useAuthorization() - ->setMethodToPost() - ->setSignatureToHmacSha1() - ->getQueryResponse(); - } - - /** - * Returns the URL used for login. - * - * @param array - * @param string - * @return string - */ - public function getLoginUrl($token, $redirect) { - //Argument tests - Eden_Twitter_Error::get() - ->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; - } - - /** - * Returns the access token - * - * @param string - * @param string - * @return string - */ - public function getAccessToken($token, $secret, $verifier) { - //argument test - Eden_Google_Error::get() - ->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::get() - ->getConsumer(self::ACCESS_URL, $this->_key, $this->_secret) - ->useAuthorization() - ->setMethodToPost() - ->setToken($token, $secret) - ->setVerifier($verifier) - ->setSignatureToHmacSha1() - ->getQueryResponse(); - } - - public function setAccessToken($token, $secret) { - $this->_accessToken = $token; - $this->_accessSecret = $secret; - - return $this; - } - - - /** - * Returns the meta of the last call - * - * @return array - */ - public function getMeta($key = NULL) { - Eden_Google_Error::get()->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::get() - ->getConsumer($url, $this->_key, $this->_secret) - ->setHeaders(self::VERSION_HEADER, self::GDATA_VERSION) - ->setToken($this->_accessToken, $this->_accessSecret) - ->setSignatureToHmacSha1(); - - $response = $rest->getJsonResponse($query); - - $this->_meta = $rest->getMeta(); - - return $response; - } - - /** - * Returns the token from the server - * - * @param array - * @return array - */ - protected function _post($url, $query = array()) { - $headers = array(); - $headers[] = Eden_Oauth_Consumer::POST_HEADER; - - $rest = Eden_Oauth::get() - ->getConsumer($url, $this->_key, $this->_secret) - ->setToken($this->_accessToken, $this->_accessSecret) - ->setSignatureToHmacSha1(); - - //get the authorization parameters as an array - $signature = $rest->getSignature(); - $authorization = $rest->getAuthorization($signature, false); - $authorization = $this->_buildQuery($authorization); - - if(is_array($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::get() - ->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['authorization'] = $authorization; - $this->_meta['headers'] = $headers; - $this->_meta['query'] = $query; - - return $response; - } - - /* Private Methods - -------------------------------*/ + +/* + * 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. + */ + +/** + * Twitter oauth + * + * @package Eden + * @category twitter + * @author Christian Blanquera + * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ + */ +class Eden_Tumblr_Base extends Eden_Oauth_Base { + /* 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'; + const SECRET_KEY = 'akHvmf5Fsoo7U9ztx3triIx2mczWfze3SEgIgaiGBYTlkqD0kN'; + const VERSION_HEADER = 'GData-Version'; + const GDATA_VERSION = 2; + + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_key = NULL; + protected $_secret = NULL; + + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + /* Magic + -------------------------------*/ + 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 + -------------------------------*/ + public function getRequestToken() { + return Eden_Oauth::i() + ->getConsumer(self::REQUEST_URL, $this->_key, $this->_secret) + ->useAuthorization() + ->setMethodToPost() + ->setSignatureToHmacSha1() + ->getQueryResponse(); + } + + /** + * Returns the URL used for login. + * + * @param array + * @param string + * @return string + */ + public function getLoginUrl($token, $redirect) { + //Argument tests + Eden_Twitter_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; + } + + /** + * Returns the access token + * + * @param string + * @param string + * @return string + */ + public function getAccessToken($token, $secret, $verifier) { + //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 + + return Eden_Oauth::i() + ->getConsumer(self::ACCESS_URL, $this->_key, $this->_secret) + ->useAuthorization() + ->setMethodToPost() + ->setToken($token, $secret) + ->setVerifier($verifier) + ->setSignatureToHmacSha1() + ->getQueryResponse(); + } + + public function setAccessToken($token, $secret) { + $this->_accessToken = $token; + $this->_accessSecret = $secret; + + return $this; + } + + + /** + * 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() + ->getConsumer($url, $this->_key, $this->_secret) + ->setHeaders(self::VERSION_HEADER, self::GDATA_VERSION) + ->setToken($this->_accessToken, $this->_accessSecret) + ->setSignatureToHmacSha1(); + + $response = $rest->getJsonResponse($query); + + $this->_meta = $rest->getMeta(); + + return $response; + } + + /** + * Returns the token from the server + * + * @param array + * @return array + */ + protected function _post($url, $query = array()) { + $headers = array(); + $headers[] = Eden_Oauth_Consumer::POST_HEADER; + + $rest = Eden_Oauth::i() + ->getConsumer($url, $this->_key, $this->_secret) + ->setToken($this->_accessToken, $this->_accessSecret) + ->setSignatureToHmacSha1(); + + //get the authorization parameters as an array + $signature = $rest->getSignature(); + $authorization = $rest->getAuthorization($signature, false); + $authorization = $this->_buildQuery($authorization); + + if(is_array($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->getResponse(); + + $this->_meta = $curl->getMeta(); + $this->_meta['url'] = $url; + $this->_meta['authorization'] = $authorization; + $this->_meta['headers'] = $headers; + $this->_meta['query'] = $query; + + return $response; + } + + /* Private Methods + -------------------------------*/ } \ No newline at end of file diff --git a/library/eden/tumblr/blog.php b/library/eden/tumblr/blog.php index 4952573..73e25e4 100644 --- a/library/eden/tumblr/blog.php +++ b/library/eden/tumblr/blog.php @@ -1,513 +1,513 @@ - -/* - * 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. - */ - -/** - * - * - * @package Eden - * @category tumblr - * @author Christian Blanquera - * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ - */ -class Eden_Tumblr_Blog extends Eden_Tumblr_Base { - /* Constants - -------------------------------*/ - const URL_GET_LIST = 'http://api.tumblr.com/v2/blog/kamoteche.tumblr.com/info'; - const URL_GET_AVATAR = 'http://api.tumblr.com/v2/blog/kamoteche.tumblr.com/avatar/512'; - const URL_GET_FOLLOWER = 'api.tumblr.com/v2/blog/{tumblr.poptech.org}/followers'; - const URL_GET_POST = 'http://api.tumblr.com/v2/blog/posts.json'; - const URL_GET_DRAFT = 'api.tumblr.com/v2/blog/{kamoteche.tumblr.com}/posts/draft'; - const URL_GET_SUBMISION = 'http://api.tumblr.com/v2/blog/posts/submission.json'; - const URL_ADD_BLOG = 'http://api.tumblr.com/v2/blog/posts.json'; - const URL_UPDATE = 'http://api.tumblr.com/v2/blog/edit.json'; - const URL_REBLOG = 'http://api.tumblr.com/v2/blog/reblog.json'; - const URL_REMOVE = 'http://api.tumblr.com/v2/blog/kamoteche.tumblr.com/post/delete'; - - /* Public Properties - -------------------------------*/ - /* Protected Properties - -------------------------------*/ - protected $_query = array(); - - /* Private Properties - -------------------------------*/ - /* Get - -------------------------------*/ - public static function get($user, $api) { - return self::_getMultiple(__CLASS__, $user, $api); - } - /* Magic - -------------------------------*/ - /* Public Methods - -------------------------------*/ - /** - * This method returns general information about the blog, - * such as the title, number of posts, and other high-level data. - * - * @param hostName is a string - * @param apiKey is a string - * @return $this - */ - public function getList($hostName, $apiKey) { - //Argument Test - Eden_Tumblr_Error::get() - ->argument(1, 'string') //Argument 1 must be a string - ->argument(2, 'string'); //Argument 2 must be a string - - $query = array('base-hostname' => $hostName, 'api_key' => $apiKey); - - return $this->_getResponse(self::URL_GET_LIST, $query); - } - /** - * You can get a blog's avatar in 9 different sizes. - * The default size is 64x64. - * - * @param hostName is a string - * @param size is an integer - * @return $this - */ - public function getAvatar($hostName, $size = NULL) { - //Argument Test - Eden_Tumblr_Error::get() - ->argument(1, 'string') //Argument 1 must be a string - ->argument(2, 'integer', 'null'); //Argument 2 must be a integer or null - - $query = array('base-hostname' => $hostName); - //if it is not empty - if(!is_null($size)) { - //lets put it in the query - $query['size'] = $size; - } - - return $this->_getResponse(self::URL_GET_AVATAR, $query); - } - /** - * Get followers - * - * @param hostName is a string - * @param limit is an integer - * @param offset is an integer - * @return $this - */ - public function getFollower($hostName, $limit = NULL, $offset = NULL) { - //Argument Test - Eden_Tumblr_Error::get() - ->argument(1, 'string') //Argument 1 must be a string - ->argument(2, 'integer', 'null') //Argument 2 must be a integer or null - ->argument(3, 'integer', 'null'); //Argument 2 must be a integer or null - - $query = array('base-hostname' => $hostName); - //if it is not empty - if(!is_null($limit)) { - //lets put it in the query - $query['limit'] = $limit; - } - //if it is not empty - if(!is_null($offset)) { - //lets put it in the query - $query['offset'] = $offset; - } - - return $this->_getResponse(self::URL_GET_FOLLOWER, $query); - } - /** - * Retrieve published post such as text, photo, quote, link - * Chat, Audio, Video and Answer - * - * @param hostName is a string - * @param apiKey is a string - * @param type is a string - * @param id is integer - * @param tag is a string - * @param limit is integer - * @param offset is a string - * @param reblog is a boolean - * @param notes is a boolean - * @param format is a string - * @return $this - */ - public function getPost($hostName, $apiKey, $type = NULL, $id = NULL, $tag = NULL, - $limit = NULL, $offset = NULL, $reblog = NULL, $notes = NULL, $format = NULL) { - //Argument Test - Eden_Tumblr_Error::get() - ->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 - ->argument(4, 'integer', 'null') //Argument 4 must be a integer or null - ->argument(5, 'string', 'null') //Argument 5 must be a string or null - ->argument(6, 'integer', 'null') //Argument 6 must be a integer or null - ->argument(7, 'integer', 'null') //Argument 7 must be a integer or null - ->argument(8, 'boolean', 'null') //Argument 8 must be a boolean or null - ->argument(9, 'boolean', 'null') //Argument 9 must be a boolean or null - ->argument(10, 'string', 'null'); //Argument 10 must be a string or null - - - $query = array('base-hostname' => $hostName, 'api_key' => $apiKey); - //if it is not empty - if(!is_null($type)) { - //lets put it in the query - $query['type'] = $type; - } - //if it is not empty - if(!is_null($id)) { - //lets put it in the query - $query['id'] = $id; - } - //if it is not empty - if(!is_null($tag)) { - //lets put it in the query - $query['tag'] = $tag; - } - //if it is not empty - if(!is_null($limit)) { - //lets put it in the query - $query['limit'] = $limit; - } - //if it is not empty - if(!is_null($offset)) { - //lets put it in the query - $query['offset'] = $offset; - } - //if its reblog - if($reblog) { - $query['reblog_info'] = 0; - } - //if its reblog - if($notes) { - $query['notes_info'] = 0; - } - //if it is not empty - if(!is_null($format)) { - //lets put it in the query - $query['format'] = $format; - } - - return $this->_getResponse(self::URL_GET_POST, $query); - } - /** - * Get complete set draft post - * - * @return $this - */ - public function getDraft() { - return $this->_getResponse(self::URL_GET_DRAFT); - } - /** - * Get complete set submmision post - * - * @return $this - */ - public function getSubmission() { - return $this->_getResponse(self::URL_GET_SUBMISION); - } - /** - * Add or create a blog - * - * @param type is string - * @param state is string - * @param tag is string - * @param tweets is string - * @param date is string - * @param markdown is boolean - * @param slug is string - * @return $this - */ - public function add($type, $state = NULL, $tag = NULL, $tweets = NULL, $date = NULL, $markdown = NULL, $slug = NULL) { - //Argument Test - Eden_Tumblr_Error::get() - ->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 - ->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, 'boolean', 'null') //Argument 6 must be a boolean or null - ->argument(7, 'string', 'null'); //Argument 7 must be a string or null - - $query = array('type' => $type); - //if it is not empty - if(!is_null($state)) { - //lets put it in query - $query['state'] = $state; - } - //if it is not empty - if(!is_null($tag)) { - //lets put it in query - $query['tag'] = $tag; - } - //if it is not empty - if(!is_null($tweets)) { - //lets put it in query - $query['tweets'] = $tweets; - } - //if it is not empty - if(!is_null($tweets)) { - //lets put it in query - $query['tweets'] = $tweets; - } - //if it is not empty - if(!is_null($date)) { - //lets put it in query - $query['date'] = $date; - } - //if its markdown - if($markdown) { - $query['markdown'] = 0; - } - //if it is not empty - if(!is_null($slug)) { - //lets put it in query - $query['slug'] = $slug; - } - - $url = sprintf(self::URL_ADD_BLOG, $type); - return $this->_post($url,$query); - } - /** - * Add text - * - * @param body is string - * @param title is string - * @return $this - */ - public function addText($body, $title = NULL) { - //Argument Test - Eden_Tumblr_Error::get() - ->argument(1, 'string') //Argument 1 must be a string - ->argument(2, 'string', 'null'); //Argument 2 must be a string or null - - $query = array('body' => $body); - //if it is not empty - if(!is_null($title)) { - //lets put it in query - $query['title'] = $title; - } - - $url = sprintf(self::URL_ADD_BLOG, $body); - return $this->_post($url,$query); - } - /** - * Add photo - * - * @param source is a string - * @param data is array - * @param caption is a string - * @param link is a string - * @return $this - */ - public function addPhoto($source, $data, $caption = NULL, $link = NULL) { - //Argument Test - Eden_Tumblr_Error::get() - ->argument(1, 'string') //Argument 1 must be a string - ->argument(2, 'array') //Argument 1 must be a array - ->argument(3, 'string', 'null') //Argument 1 must be a array - ->argument(4, 'string', 'null'); //Argument 2 must be a string or null - - $query = array('body' => $body,'data' =>$data); - //if it is not empty - if(!is_null($caption)) { - //lets put it in query - $query['caption'] = $caption; - } - //if it is not empty - if(!is_null($link)) { - //lets put it in query - $query['link'] = $link; - } - - $url = sprintf(self::URL_ADD_BLOG, $source); - return $this->_post($url,$query); - } - /** - * Add quote - * - * @param quote is a string - * @param source is a string - * @return $this - */ - public function addQuote($quote, $source = NULL) { - //Argument Test - Eden_Tumblr_Error::get() - ->argument(1, 'string') //Argument 1 must be a string - ->argument(2, 'string', 'null'); //Argument 1 must be a string - - $query = array('qoute' => $qoute); - //if it is not empty - if(!is_null($source)) { - //lets put it in query - $query['source'] = $source; - } - - $url = sprintf(self::URL_ADD_BLOG, $qoute); - return $this->_post($url,$query); - } - /** - * Add link - * - * @param url is a string - * @param title is a string - * @param description is string - * @return $this - */ - public function addLink($url, $title = NULL, $description = NULL) { - //Argument Test - Eden_Tumblr_Error::get() - ->argument(1, 'string') //Argument 1 must be a string - ->argument(2, 'string', 'null') //Argument 2 must be a string - ->argument(3, 'string', 'null'); //Argument 3 must be a string - - $query = array('url' => $url); - //if it is not empty - if(!is_null($title)) { - //lets put it in query - $query['title'] = $title; - } - //if it is not empty - if(!is_null($description)) { - //lets put it in query - $query['description'] = $description; - } - - $url = sprintf(self::URL_ADD_BLOG, $url); - return $this->_post($url,$query); - } - /** - * Add chat - * - * @param conversation is a string - * @param title is a string - * @return $this - */ - public function addChat($conversation, $title = NULL) { - //Argument Test - Eden_Tumblr_Error::get() - ->argument(1, 'string') //Argument 1 must be a string - ->argument(2, 'string', 'null'); //Argument 2 must be a string - - $query = array('conversation' => $conversation); - //if it is not empty - if(!is_null($title)) { - //lets put it in query - $query['title'] = $title; - } - - $url = sprintf(self::URL_ADD_BLOG, $conversation); - return $this->_post($url,$query); - } - /** - * Add audio - * - * @param data is a string - * @param externalis a string - * @param caption is a string - * @return $this - */ - public function addAudio($data, $external, $caption = NULL) { - //Argument Test - Eden_Tumblr_Error::get() - ->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 - - $query = array('data' => $data, 'external_url' => $external); - //if it is not empty - if(!is_null($caption)) { - //lets put it in query - $query['caption'] = $caption; - } - - $url = sprintf(self::URL_ADD_BLOG, $data); - return $this->_post($url,$query); - } - /** - * Add video - * - * @param data is string - * @param embed is string - * @param caption is string - * @return $this - */ - public function addVideo($data, $embed, $caption = NULL) { - //Argument Test - Eden_Tumblr_Error::get() - ->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 - - $query = array('data' => $data, 'embed' => $embed); - //if it is not empty - if(!is_null($caption)) { - //lets put it in query - $query['caption'] = $caption; - } - - $url = sprintf(self::URL_ADD_BLOG, $data); - return $this->_post($url,$query); - } - /** - * update blog post - * - * @param $id is a integer - * @return $this - */ - public function update($Id) { - //Argument Test - Eden_Tumblr_Error::get() - ->argument(1, 'integer'); //Argument 1 must be a integer - - $query = array('Id' => $Id); - - $url = sprintf(self::URL_UPDATE, $Id); - return $this->_post($url,$query); - } - /** - * reblog a post - * - * @param id is a integer - * @param reblog is a integer - * @param comment is a string - * @return $this - */ - public function reblog($Id, $reblog, $comment) { - //Argument Test - Eden_Tumblr_Error::get() - ->argument(1, 'integer') //Argument 1 must be a integer - ->argument(2, 'integer') //Argument 2 must be a integer - ->argument(3, 'string'); //Argument 3 must be a integer - - $query = array('Id' => $Id, 'reblog_key' => $reblog); - //if it is not empty - if(!is_null($comment)) { - $query['comment'] = $comment; - } - - $url = sprintf(self::URL_REBLOG, $Id); - return $this->_post($url,$query); - } - /** - * delete a post - * - * @param id is a integer - * @return $this - */ - public function remove($Id) { - //Argument Test - Eden_Tumblr_Error::get() - ->argument(1, 'integer'); //Argument 1 must be a integer - - $query = array('Id' => $Id); - - $url = sprintf(self::URL_REMOVE, $Id); - return $this->_post($url,$query); - } - - /* Protected Methods - -------------------------------*/ - /* Private Methods - -------------------------------*/ + +/* + * 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. + */ + +/** + * + * + * @package Eden + * @category tumblr + * @author Christian Blanquera + * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ + */ +class Eden_Tumblr_Blog extends Eden_Tumblr_Base { + /* Constants + -------------------------------*/ + const URL_GET_LIST = 'http://api.tumblr.com/v2/blog/kamoteche.tumblr.com/info'; + const URL_GET_AVATAR = 'http://api.tumblr.com/v2/blog/kamoteche.tumblr.com/avatar/512'; + const URL_GET_FOLLOWER = 'api.tumblr.com/v2/blog/{tumblr.poptech.org}/followers'; + const URL_GET_POST = 'http://api.tumblr.com/v2/blog/posts.json'; + const URL_GET_DRAFT = 'api.tumblr.com/v2/blog/{kamoteche.tumblr.com}/posts/draft'; + const URL_GET_SUBMISION = 'http://api.tumblr.com/v2/blog/posts/submission.json'; + const URL_ADD_BLOG = 'http://api.tumblr.com/v2/blog/posts.json'; + const URL_UPDATE = 'http://api.tumblr.com/v2/blog/edit.json'; + const URL_REBLOG = 'http://api.tumblr.com/v2/blog/reblog.json'; + const URL_REMOVE = 'http://api.tumblr.com/v2/blog/kamoteche.tumblr.com/post/delete'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_query = array(); + + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function i($user, $api) { + return self::_getMultiple(__CLASS__, $user, $api); + } + /* Magic + -------------------------------*/ + /* Public Methods + -------------------------------*/ + /** + * This method returns general information about the blog, + * such as the title, number of posts, and other high-level data. + * + * @param hostName is a string + * @param apiKey is a string + * @return $this + */ + public function getList($hostName, $apiKey) { + //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('base-hostname' => $hostName, 'api_key' => $apiKey); + + return $this->_getResponse(self::URL_GET_LIST, $query); + } + /** + * You can get a blog's avatar in 9 different sizes. + * The default size is 64x64. + * + * @param hostName is a string + * @param size is an integer + * @return $this + */ + public function getAvatar($hostName, $size = NULL) { + //Argument Test + Eden_Tumblr_Error::i() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'integer', 'null'); //Argument 2 must be a integer or null + + $query = array('base-hostname' => $hostName); + //if it is not empty + if(!is_null($size)) { + //lets put it in the query + $query['size'] = $size; + } + + return $this->_getResponse(self::URL_GET_AVATAR, $query); + } + /** + * Get followers + * + * @param hostName is a string + * @param limit is an integer + * @param offset is an integer + * @return $this + */ + public function getFollower($hostName, $limit = NULL, $offset = NULL) { + //Argument Test + Eden_Tumblr_Error::i() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'integer', 'null') //Argument 2 must be a integer or null + ->argument(3, 'integer', 'null'); //Argument 2 must be a integer or null + + $query = array('base-hostname' => $hostName); + //if it is not empty + if(!is_null($limit)) { + //lets put it in the query + $query['limit'] = $limit; + } + //if it is not empty + if(!is_null($offset)) { + //lets put it in the query + $query['offset'] = $offset; + } + + return $this->_getResponse(self::URL_GET_FOLLOWER, $query); + } + /** + * Retrieve published post such as text, photo, quote, link + * Chat, Audio, Video and Answer + * + * @param hostName is a string + * @param apiKey is a string + * @param type is a string + * @param id is integer + * @param tag is a string + * @param limit is integer + * @param offset is a string + * @param reblog is a boolean + * @param notes is a boolean + * @param format is a string + * @return $this + */ + public function getPost($hostName, $apiKey, $type = NULL, $id = NULL, $tag = NULL, + $limit = NULL, $offset = NULL, $reblog = NULL, $notes = NULL, $format = 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 + ->argument(4, 'integer', 'null') //Argument 4 must be a integer or null + ->argument(5, 'string', 'null') //Argument 5 must be a string or null + ->argument(6, 'integer', 'null') //Argument 6 must be a integer or null + ->argument(7, 'integer', 'null') //Argument 7 must be a integer or null + ->argument(8, 'boolean', 'null') //Argument 8 must be a boolean or null + ->argument(9, 'boolean', 'null') //Argument 9 must be a boolean or null + ->argument(10, 'string', 'null'); //Argument 10 must be a string or null + + + $query = array('base-hostname' => $hostName, 'api_key' => $apiKey); + //if it is not empty + if(!is_null($type)) { + //lets put it in the query + $query['type'] = $type; + } + //if it is not empty + if(!is_null($id)) { + //lets put it in the query + $query['id'] = $id; + } + //if it is not empty + if(!is_null($tag)) { + //lets put it in the query + $query['tag'] = $tag; + } + //if it is not empty + if(!is_null($limit)) { + //lets put it in the query + $query['limit'] = $limit; + } + //if it is not empty + if(!is_null($offset)) { + //lets put it in the query + $query['offset'] = $offset; + } + //if its reblog + if($reblog) { + $query['reblog_info'] = 0; + } + //if its reblog + if($notes) { + $query['notes_info'] = 0; + } + //if it is not empty + if(!is_null($format)) { + //lets put it in the query + $query['format'] = $format; + } + + return $this->_getResponse(self::URL_GET_POST, $query); + } + /** + * Get complete set draft post + * + * @return $this + */ + public function getDraft() { + return $this->_getResponse(self::URL_GET_DRAFT); + } + /** + * Get complete set submmision post + * + * @return $this + */ + public function getSubmission() { + return $this->_getResponse(self::URL_GET_SUBMISION); + } + /** + * Add or create a blog + * + * @param type is string + * @param state is string + * @param tag is string + * @param tweets is string + * @param date is string + * @param markdown is boolean + * @param slug is string + * @return $this + */ + public function add($type, $state = NULL, $tag = NULL, $tweets = NULL, $date = NULL, $markdown = NULL, $slug = 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 + ->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, 'boolean', 'null') //Argument 6 must be a boolean or null + ->argument(7, 'string', 'null'); //Argument 7 must be a string or null + + $query = array('type' => $type); + //if it is not empty + if(!is_null($state)) { + //lets put it in query + $query['state'] = $state; + } + //if it is not empty + if(!is_null($tag)) { + //lets put it in query + $query['tag'] = $tag; + } + //if it is not empty + if(!is_null($tweets)) { + //lets put it in query + $query['tweets'] = $tweets; + } + //if it is not empty + if(!is_null($tweets)) { + //lets put it in query + $query['tweets'] = $tweets; + } + //if it is not empty + if(!is_null($date)) { + //lets put it in query + $query['date'] = $date; + } + //if its markdown + if($markdown) { + $query['markdown'] = 0; + } + //if it is not empty + if(!is_null($slug)) { + //lets put it in query + $query['slug'] = $slug; + } + + $url = sprintf(self::URL_ADD_BLOG, $type); + return $this->_post($url,$query); + } + /** + * Add text + * + * @param body is string + * @param title is string + * @return $this + */ + public function addText($body, $title = 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 + + $query = array('body' => $body); + //if it is not empty + if(!is_null($title)) { + //lets put it in query + $query['title'] = $title; + } + + $url = sprintf(self::URL_ADD_BLOG, $body); + return $this->_post($url,$query); + } + /** + * Add photo + * + * @param source is a string + * @param data is array + * @param caption is a string + * @param link is a string + * @return $this + */ + public function addPhoto($source, $data, $caption = NULL, $link = NULL) { + //Argument Test + Eden_Tumblr_Error::i() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'array') //Argument 1 must be a array + ->argument(3, 'string', 'null') //Argument 1 must be a array + ->argument(4, 'string', 'null'); //Argument 2 must be a string or null + + $query = array('body' => $body,'data' =>$data); + //if it is not empty + if(!is_null($caption)) { + //lets put it in query + $query['caption'] = $caption; + } + //if it is not empty + if(!is_null($link)) { + //lets put it in query + $query['link'] = $link; + } + + $url = sprintf(self::URL_ADD_BLOG, $source); + return $this->_post($url,$query); + } + /** + * Add quote + * + * @param quote is a string + * @param source is a string + * @return $this + */ + public function addQuote($quote, $source = NULL) { + //Argument Test + Eden_Tumblr_Error::i() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'string', 'null'); //Argument 1 must be a string + + $query = array('qoute' => $qoute); + //if it is not empty + if(!is_null($source)) { + //lets put it in query + $query['source'] = $source; + } + + $url = sprintf(self::URL_ADD_BLOG, $qoute); + return $this->_post($url,$query); + } + /** + * Add link + * + * @param url is a string + * @param title is a string + * @param description is string + * @return $this + */ + public function addLink($url, $title = NULL, $description = 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 + ->argument(3, 'string', 'null'); //Argument 3 must be a string + + $query = array('url' => $url); + //if it is not empty + if(!is_null($title)) { + //lets put it in query + $query['title'] = $title; + } + //if it is not empty + if(!is_null($description)) { + //lets put it in query + $query['description'] = $description; + } + + $url = sprintf(self::URL_ADD_BLOG, $url); + return $this->_post($url,$query); + } + /** + * Add chat + * + * @param conversation is a string + * @param title is a string + * @return $this + */ + public function addChat($conversation, $title = 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 + + $query = array('conversation' => $conversation); + //if it is not empty + if(!is_null($title)) { + //lets put it in query + $query['title'] = $title; + } + + $url = sprintf(self::URL_ADD_BLOG, $conversation); + return $this->_post($url,$query); + } + /** + * Add audio + * + * @param data is a string + * @param externalis a string + * @param caption is a string + * @return $this + */ + public function addAudio($data, $external, $caption = 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 + + $query = array('data' => $data, 'external_url' => $external); + //if it is not empty + if(!is_null($caption)) { + //lets put it in query + $query['caption'] = $caption; + } + + $url = sprintf(self::URL_ADD_BLOG, $data); + return $this->_post($url,$query); + } + /** + * Add video + * + * @param data is string + * @param embed is string + * @param caption is string + * @return $this + */ + public function addVideo($data, $embed, $caption = 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 + + $query = array('data' => $data, 'embed' => $embed); + //if it is not empty + if(!is_null($caption)) { + //lets put it in query + $query['caption'] = $caption; + } + + $url = sprintf(self::URL_ADD_BLOG, $data); + return $this->_post($url,$query); + } + /** + * update blog post + * + * @param $id is a integer + * @return $this + */ + public function update($Id) { + //Argument Test + Eden_Tumblr_Error::i() + ->argument(1, 'integer'); //Argument 1 must be a integer + + $query = array('Id' => $Id); + + $url = sprintf(self::URL_UPDATE, $Id); + return $this->_post($url,$query); + } + /** + * reblog a post + * + * @param id is a integer + * @param reblog is a integer + * @param comment is a string + * @return $this + */ + public function reblog($Id, $reblog, $comment) { + //Argument Test + Eden_Tumblr_Error::i() + ->argument(1, 'integer') //Argument 1 must be a integer + ->argument(2, 'integer') //Argument 2 must be a integer + ->argument(3, 'string'); //Argument 3 must be a integer + + $query = array('Id' => $Id, 'reblog_key' => $reblog); + //if it is not empty + if(!is_null($comment)) { + $query['comment'] = $comment; + } + + $url = sprintf(self::URL_REBLOG, $Id); + return $this->_post($url,$query); + } + /** + * delete a post + * + * @param id is a integer + * @return $this + */ + public function remove($Id) { + //Argument Test + Eden_Tumblr_Error::i() + ->argument(1, 'integer'); //Argument 1 must be a integer + + $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/tumblr/error.php b/library/eden/tumblr/error.php index d69547a..6bad8fd 100644 --- a/library/eden/tumblr/error.php +++ b/library/eden/tumblr/error.php @@ -1,56 +1,56 @@ - -/* - * 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. - */ - -/** - * Eventbrite Errors - * - * @package Eden - * @category google - * @author Christian Blanquera - * @version $Id: exception.php 1 2010-01-02 23:06:36Z blanquera $ - */ -class Eden_Tumblr_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 - -------------------------------*/ - /* Get - -------------------------------*/ - public static function get($message = NULL, $code = 0) { - $class = __CLASS__; - return new $class($message, $code); - } - - /* Magic - -------------------------------*/ - /* Public Methods - -------------------------------*/ - /* Protected Methods - -------------------------------*/ - /* Private Methods - -------------------------------*/ + +/* + * 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. + */ + +/** + * Eventbrite Errors + * + * @package Eden + * @category google + * @author Christian Blanquera + * @version $Id: exception.php 1 2010-01-02 23:06:36Z blanquera $ + */ +class Eden_Tumblr_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 + -------------------------------*/ + /* 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/tumblr/oauth.php b/library/eden/tumblr/oauth.php index 806cb07..f8c6202 100644 --- a/library/eden/tumblr/oauth.php +++ b/library/eden/tumblr/oauth.php @@ -1,44 +1,44 @@ - -/* - * 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. - */ - -/** - * Twitter oauth - * - * @package Eden - * @category google - * @author Christian Blanquera - * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ - */ -class Eden_Tumblr_Oauth extends Eden_Tumblr_Base { - /* Constants - -------------------------------*/ - /* Public Properties - -------------------------------*/ - /* Protected Properties - -------------------------------*/ - protected $_key = NULL; - protected $_secret = NULL; - - /* Private Properties - -------------------------------*/ - /* Get - -------------------------------*/ - public static function get($key, $secret) { - return self::_getMultiple(__CLASS__, $key, $secret); - } - - /* Magic - -------------------------------*/ - /* Public Methods - -------------------------------*/ - /* Protected Methods - -------------------------------*/ - /* Private Methods - -------------------------------*/ + +/* + * 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. + */ + +/** + * Twitter oauth + * + * @package Eden + * @category google + * @author Christian Blanquera + * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ + */ +class Eden_Tumblr_Oauth extends Eden_Tumblr_Base { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_key = NULL; + protected $_secret = NULL; + + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function i($key, $secret) { + return self::_getMultiple(__CLASS__, $key, $secret); + } + + /* Magic + -------------------------------*/ + /* Public Methods + -------------------------------*/ + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ } \ No newline at end of file diff --git a/library/eden/tumblr/user.php b/library/eden/tumblr/user.php index 37f0b7b..a9d5494 100644 --- a/library/eden/tumblr/user.php +++ b/library/eden/tumblr/user.php @@ -1,248 +1,248 @@ - -/* - * 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. - */ - -/** - * - * - * @package Eden - * @category tumblr - * @author Christian Blanquera - * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ - */ -class Eden_Tumblr_User extends Eden_Tumblr_Base { - /* Constants - -------------------------------*/ - const URL_GET_LIST = 'http://api.tumblr.com/v2/user/info'; - const URL_GET_USER = '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 $_query = array(); - - /* Private Properties - -------------------------------*/ - /* Get - -------------------------------*/ - public static function get($user, $api) { - return self::_getMultiple(__CLASS__, $user, $api); - } - /* Magic - -------------------------------*/ - /* Public Methods - -------------------------------*/ - /** - * Use this method to retrieve the user's account information - * that matches the OAuth credentials submitted with the request. - * - * @return $this - */ - public function getList() { - $url = sprintf(self::URL_GET_LIST); - return $this->_post($url); - } - /** - * Use this method to retrieve the dashboard that matches - * the OAuth credentials submitted with the request. - * - * @param limit is integer - * @param offset is integer - * @param type is string - * @param since is integer - * @param reblog is boolean - * @param notes is boolean - * @return $this - */ - public function getUser($limit = NULL, $offset = NULL, $type = NULL, $since = NULL, $reblog = NULL, $notes = NULL) { - //Argument Test - Eden_Tumblr_Error::get() - ->argument(1, 'integer') //Argument 1 must be a integer - ->argument(2, 'integer') //Argument 2 must be a integer - ->argument(3, 'string') //Argument 3 must be a string - ->argument(4, 'integer') //Argument 4 must be a integer - ->argument(5, 'boolean') //Argument 5 must be a boolean - ->argument(6, 'boolean'); //Argument 6 must be a boolean - - $query = array(); - //if it is not empty - if(!is_null($limit)) { - //lets put it in the query - $query['limit'] = $limit; - } - //if it is not empty - if(!is_null($offset)) { - //lets put it in the query - $query['offset'] = $offset; - } - //if it is not empty - if(!is_null($type)) { - //lets put it in the query - $query['type'] = $type; - } - //if it is not empty - if(!is_null($since)) { - //lets put it in the query - $query['since_id'] = $since; - } - //if it is reblog - if($reblog) { - $query['reblog_info'] = 0; - } - //if it is notes - if($notes) { - $query['notes_info'] = 0; - } - - return $this->_getResponse(self::URL_GET_USER); - } - /** - * Use this method to retrieve the liked posts that - * match the OAuth credentials submitted with the request. - * - * @param limit is integer - * @param offset is integer - * @return $this - */ - public function getLikes($limit = NULL, $offset = NULL) { - //Argument Test - Eden_Tumblr_Error::get() - ->argument(1, 'integer') //Argument 1 must be a integer - ->argument(2, 'integer'); //Argument 2 must be a integer - - $query = array(); - //if it is not empty - if(!is_null($limit)) { - //lets put it in the query - $query['limit'] = $limit; - } - //if it is not empty - if(!is_null($offset)) { - //lets put it in the query - $query['offset'] = $offset; - } - - return $this->_getResponse(self::URL_GET_LIKES); - } - /** - * Use this method to retrieve the blogs followed by the user - * whose OAuth credentials are submitted with the request. - * - * @param limit is integer - * @param offset is integer - * @return $this - */ - public function getFollowing($limit = NULL, $offset = NULL) { - //Argument Test - Eden_Tumblr_Error::get() - ->argument(1, 'integer') //Argument 1 must be a integer - ->argument(2, 'integer'); //Argument 2 must be a integer - - $query = array(); - //if it is not empty - if(!is_null($limit)) { - //lets put it in the query - $query['limit'] = $limit; - } - //if it is not empty - if(!is_null($offset)) { - //lets put it in the query - $query['offset'] = $offset; - } - - return $this->_getResponse(self::URL_GET_FOLLOWING); - } - /** - * Follow a blog - * - * @param url is string - * @return $this - */ - public function follow($url) { - //Argument Test - Eden_Tumblr_Error::get() - ->argument(1, 'string'); //Argument 1 must be a string - - $query = array('url' => $url); - - $url = sprintf(self::URL_FOLLOW, $url); - return $this->_post($url,$query); - } - /** - * Unfollow a blog - * - * @param url is string - * @return $this - */ - public function unfollow($url) { - //Argument Test - Eden_Tumblr_Error::get() - ->argument(1, 'string'); //Argument 1 must be a string - - $query = array('url' => $url); - - $url = sprintf(self::URL_UNFOLLOW, $url); - return $this->_post($url,$query); - } - /** - * Like a post - * - * @param id is integer - * @param reblog is string - * @return $this - */ - public function like($id, $reblog) { - //Argument Test - Eden_Tumblr_Error::get() - ->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); - } - /** - * Unlike a post - * - * @param id is integer - * @param reblog is string - * @return $this - */ - public function unlike($id, $reblog) { - //Argument Test - Eden_Tumblr_Error::get() - ->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 - -------------------------------*/ + +/* + * 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. + */ + +/** + * + * + * @package Eden + * @category tumblr + * @author Christian Blanquera + * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ + */ +class Eden_Tumblr_User extends Eden_Tumblr_Base { + /* Constants + -------------------------------*/ + const URL_GET_LIST = 'http://api.tumblr.com/v2/user/info'; + const URL_GET_USER = '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 $_query = array(); + + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function i($user, $api) { + return self::_getMultiple(__CLASS__, $user, $api); + } + /* Magic + -------------------------------*/ + /* Public Methods + -------------------------------*/ + /** + * Use this method to retrieve the user's account information + * that matches the OAuth credentials submitted with the request. + * + * @return $this + */ + public function getList() { + $url = sprintf(self::URL_GET_LIST); + return $this->_post($url); + } + /** + * Use this method to retrieve the dashboard that matches + * the OAuth credentials submitted with the request. + * + * @param limit is integer + * @param offset is integer + * @param type is string + * @param since is integer + * @param reblog is boolean + * @param notes is boolean + * @return $this + */ + public function getUser($limit = NULL, $offset = NULL, $type = NULL, $since = NULL, $reblog = NULL, $notes = NULL) { + //Argument Test + Eden_Tumblr_Error::i() + ->argument(1, 'integer') //Argument 1 must be a integer + ->argument(2, 'integer') //Argument 2 must be a integer + ->argument(3, 'string') //Argument 3 must be a string + ->argument(4, 'integer') //Argument 4 must be a integer + ->argument(5, 'boolean') //Argument 5 must be a boolean + ->argument(6, 'boolean'); //Argument 6 must be a boolean + + $query = array(); + //if it is not empty + if(!is_null($limit)) { + //lets put it in the query + $query['limit'] = $limit; + } + //if it is not empty + if(!is_null($offset)) { + //lets put it in the query + $query['offset'] = $offset; + } + //if it is not empty + if(!is_null($type)) { + //lets put it in the query + $query['type'] = $type; + } + //if it is not empty + if(!is_null($since)) { + //lets put it in the query + $query['since_id'] = $since; + } + //if it is reblog + if($reblog) { + $query['reblog_info'] = 0; + } + //if it is notes + if($notes) { + $query['notes_info'] = 0; + } + + return $this->_getResponse(self::URL_GET_USER); + } + /** + * Use this method to retrieve the liked posts that + * match the OAuth credentials submitted with the request. + * + * @param limit is integer + * @param offset is integer + * @return $this + */ + public function getLikes($limit = NULL, $offset = NULL) { + //Argument Test + Eden_Tumblr_Error::i() + ->argument(1, 'integer') //Argument 1 must be a integer + ->argument(2, 'integer'); //Argument 2 must be a integer + + $query = array(); + //if it is not empty + if(!is_null($limit)) { + //lets put it in the query + $query['limit'] = $limit; + } + //if it is not empty + if(!is_null($offset)) { + //lets put it in the query + $query['offset'] = $offset; + } + + return $this->_getResponse(self::URL_GET_LIKES); + } + /** + * Use this method to retrieve the blogs followed by the user + * whose OAuth credentials are submitted with the request. + * + * @param limit is integer + * @param offset is integer + * @return $this + */ + public function getFollowing($limit = NULL, $offset = NULL) { + //Argument Test + Eden_Tumblr_Error::i() + ->argument(1, 'integer') //Argument 1 must be a integer + ->argument(2, 'integer'); //Argument 2 must be a integer + + $query = array(); + //if it is not empty + if(!is_null($limit)) { + //lets put it in the query + $query['limit'] = $limit; + } + //if it is not empty + if(!is_null($offset)) { + //lets put it in the query + $query['offset'] = $offset; + } + + return $this->_getResponse(self::URL_GET_FOLLOWING); + } + /** + * Follow a blog + * + * @param url is string + * @return $this + */ + public function follow($url) { + //Argument Test + Eden_Tumblr_Error::i() + ->argument(1, 'string'); //Argument 1 must be a string + + $query = array('url' => $url); + + $url = sprintf(self::URL_FOLLOW, $url); + return $this->_post($url,$query); + } + /** + * Unfollow a blog + * + * @param url is string + * @return $this + */ + public function unfollow($url) { + //Argument Test + Eden_Tumblr_Error::i() + ->argument(1, 'string'); //Argument 1 must be a string + + $query = array('url' => $url); + + $url = sprintf(self::URL_UNFOLLOW, $url); + return $this->_post($url,$query); + } + /** + * Like a post + * + * @param id is integer + * @param reblog is string + * @return $this + */ + 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); + } + /** + * Unlike a post + * + * @param id is integer + * @param reblog is string + * @return $this + */ + 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/accounts.php b/library/eden/twitter/accounts.php index 7b5f5a0..6436d12 100644 --- a/library/eden/twitter/accounts.php +++ b/library/eden/twitter/accounts.php @@ -1,280 +1,280 @@ - -/* - * 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. - */ - -/** - * Eventbrite new or update discount - * - * @package Eden - * @category eventbrite - * @author Christian Blanquera - * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ - */ -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 $_query = array(); - - /* Private Properties - -------------------------------*/ - /* Get - -------------------------------*/ - public static function get($key, $secret) { - return self::_getMultiple(__CLASS__, $key, $secret); - } - - /* Magic - -------------------------------*/ - /* Public Methods - -------------------------------*/ - /** - * Returns the remaining number of API requests available to the - * requesting user before the API limit is reached for the current hour. - * - * @return $this - */ - public function getLimit() { - - return $this->_getResponse(self::URL_LIMIT_STATUS); - } - /** - * Returns an HTTP 200 OK response code and a representation of the requesting user - * if authentication was successful; returns a 401 status code and an error message if not. - * - * @param name is string - * @param size is integer - * @return $this - */ - public function getCredentials($entities = false, $status = false) { - //Argument Test - Eden_Twitter_Error::get() - ->argument(1, 'boolean') //Argument 1 must be a string or integer - ->argument(2, 'boolean'); //Argument 2 must be a string or integer - - $query = array(); - //if entities - if($entities) { - $query['include_entities'] = 1; - } - //if status - if($status) { - $query['skip_status'] = 1; - } - - return $this->_getResponse(self::URL_VERIFY_CREDENTIALS, $query); - } - /** - * 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 $this - */ - public function logOut() { - - return $this->_post(self::URL_END_SESSION); - } - /** - * Sets values that users are able to set under the "Account" tab - * of their settings page. Only the parameters specified will be updated. - * - * @param name is string - * @param size is integer - * @return $this - */ - public function updateProfile($name = NULL, $url = NULL, $location = NULL, $description = NULL, $entities = NULL, $status = NULL) { - //Argument Test - Eden_Twitter_Error::get() - ->argument(1, 'string') //Argument 1 must be a string or integer - ->argument(2, 'string') //Argument 1 must be a string or integer - ->argument(3, 'string') //Argument 1 must be a string or integer - ->argument(4, 'string') //Argument 1 must be a string or integer - ->argument(5, 'boolean') //Argument 1 must be a string or integer - ->argument(8, 'boolean'); //Argument 2 must be a string or integer - - $query = array(); - //if it is not empty - if(!is_null($name) && $name <= 20) { - //lets put it in query - $query['name'] = $name; - } - //if it is not empty - if(!is_null($url) && $url <= 100) { - //lets put it in query - $query['url'] = $url; - } - //if it is not empty - if(!is_null($location) && $location <= 30) { - //lets put it in query - $query['location'] = $location; - } - //if it is not empty - if(!is_null($description) && $description <= 160) { - //lets put it in query - $query['description'] = $description; - } - //if entities - if($entities) { - $query['include_entities'] = 1; - } - //if status - if($status) { - $query['skip_status'] = 1; - } - - return $this->_post(self::URL_UPDATE_PROFILE, $query); - } - /** - * Sets values that users are able to set under the "Account" tab - * of their settings page. Only the parameters specified will be updated. - * - * @param name is string - * @param size is integer - * @return $this - */ - public function updateBackground($image = NULL, $tile = NULL, $entities = NULL, $status = NULL, $use = false) { - //Argument Test - Eden_Twitter_Error::get() - ->argument(1, 'string') //Argument 1 must be a string - ->argument(2, 'string') //Argument 1 must be a string - ->argument(3, 'boolean') //Argument 1 must be a boolean - ->argument(4, 'boolean') //Argument 1 must be a boolean - ->argument(5, 'boolean'); //Argument 1 must be a boolean - - $query = array(); - //if it is not empty - if(!is_null($image)) { - //lets put it in query - $query['image'] = $image; - } - //if it is not empty - if(!is_null($tile)) { - //lets put it in query - $query['tile'] = $tile; - } - //if entities - if($entities) { - $query['include_entities'] = 1; - } - //if status - if($status) { - $query['skip_status'] = 1; - } - //if status - if($use) { - $query['use'] = 1; - } - - 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. - * - * @param name is string - * @param size is integer - * @return $this - */ - public function updateColor($background = NULL, $link = NULL, $border = NULL, $fill = NULL, $text = NULL, $entities = false, $status = false) { - //Argument Test - Eden_Twitter_Error::get() - ->argument(1, 'string') //Argument 1 must be a string - ->argument(2, 'string') //Argument 1 must be a string - ->argument(3, 'string') //Argument 1 must be a string - ->argument(4, 'string') //Argument 1 must be a string - ->argument(5, 'string') //Argument 1 must be a string - ->argument(6, 'boolean') //Argument 1 must be a boolean - ->argument(7, 'boolean'); //Argument 1 must be a boolean - - $query = array(); - //if it is not empty - if(!is_null($background)) { - //lets put it in query - $query['profile_background_color'] = $background; - } - //if it is not empty - if(!is_null($link)) { - //lets put it in query - $query['profile_link_color'] = $link; - } - //if it is not empty - if(!is_null($border)) { - //lets put it in query - $query['profile_sidebar_border_color'] = $border; - } - //if it is not empty - if(!is_null($fill)) { - //lets put it in query - $query['profile_sidebar_fill_color'] = $fill; - } - //if it is not empty - if(!is_null($text)) { - //lets put it in query - $query['profile_text_color '] = $text; - } - //if entities - if($entities) { - $query['include_entities'] = 1; - } - //if status - if($status) { - $query['skip_status'] = 1; - } - - return $this->_post(self::URL_UPDATE_PROFILE_COLOR, $query); - } - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - /* Protected Methods - -------------------------------*/ - /* Private Methods - -------------------------------*/ - - + +/* + * 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. + */ + +/** + * Eventbrite new or update discount + * + * @package Eden + * @category eventbrite + * @author Christian Blanquera + * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ + */ +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 $_query = array(); + + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function i($key, $secret) { + return self::_getMultiple(__CLASS__, $key, $secret); + } + + /* Magic + -------------------------------*/ + /* Public Methods + -------------------------------*/ + /** + * Returns the remaining number of API requests available to the + * requesting user before the API limit is reached for the current hour. + * + * @return $this + */ + public function getLimit() { + + return $this->_getResponse(self::URL_LIMIT_STATUS); + } + /** + * Returns an HTTP 200 OK response code and a representation of the requesting user + * if authentication was successful; returns a 401 status code and an error message if not. + * + * @param name is string + * @param size is integer + * @return $this + */ + public function getCredentials($entities = false, $status = false) { + //Argument Test + Eden_Twitter_Error::i() + ->argument(1, 'boolean') //Argument 1 must be a string or integer + ->argument(2, 'boolean'); //Argument 2 must be a string or integer + + $query = array(); + //if entities + if($entities) { + $query['include_entities'] = 1; + } + //if status + if($status) { + $query['skip_status'] = 1; + } + + return $this->_getResponse(self::URL_VERIFY_CREDENTIALS, $query); + } + /** + * 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 $this + */ + public function logOut() { + + return $this->_post(self::URL_END_SESSION); + } + /** + * Sets values that users are able to set under the "Account" tab + * of their settings page. Only the parameters specified will be updated. + * + * @param name is string + * @param size is integer + * @return $this + */ + public function updateProfile($name = NULL, $url = NULL, $location = NULL, $description = NULL, $entities = NULL, $status = NULL) { + //Argument Test + Eden_Twitter_Error::i() + ->argument(1, 'string') //Argument 1 must be a string or integer + ->argument(2, 'string') //Argument 1 must be a string or integer + ->argument(3, 'string') //Argument 1 must be a string or integer + ->argument(4, 'string') //Argument 1 must be a string or integer + ->argument(5, 'boolean') //Argument 1 must be a string or integer + ->argument(8, 'boolean'); //Argument 2 must be a string or integer + + $query = array(); + //if it is not empty + if(!is_null($name) && $name <= 20) { + //lets put it in query + $query['name'] = $name; + } + //if it is not empty + if(!is_null($url) && $url <= 100) { + //lets put it in query + $query['url'] = $url; + } + //if it is not empty + if(!is_null($location) && $location <= 30) { + //lets put it in query + $query['location'] = $location; + } + //if it is not empty + if(!is_null($description) && $description <= 160) { + //lets put it in query + $query['description'] = $description; + } + //if entities + if($entities) { + $query['include_entities'] = 1; + } + //if status + if($status) { + $query['skip_status'] = 1; + } + + return $this->_post(self::URL_UPDATE_PROFILE, $query); + } + /** + * Sets values that users are able to set under the "Account" tab + * of their settings page. Only the parameters specified will be updated. + * + * @param name is string + * @param size is integer + * @return $this + */ + public function updateBackground($image = NULL, $tile = NULL, $entities = NULL, $status = NULL, $use = false) { + //Argument Test + Eden_Twitter_Error::i() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'string') //Argument 1 must be a string + ->argument(3, 'boolean') //Argument 1 must be a boolean + ->argument(4, 'boolean') //Argument 1 must be a boolean + ->argument(5, 'boolean'); //Argument 1 must be a boolean + + $query = array(); + //if it is not empty + if(!is_null($image)) { + //lets put it in query + $query['image'] = $image; + } + //if it is not empty + if(!is_null($tile)) { + //lets put it in query + $query['tile'] = $tile; + } + //if entities + if($entities) { + $query['include_entities'] = 1; + } + //if status + if($status) { + $query['skip_status'] = 1; + } + //if status + if($use) { + $query['use'] = 1; + } + + 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. + * + * @param name is string + * @param size is integer + * @return $this + */ + public function updateColor($background = NULL, $link = NULL, $border = NULL, $fill = NULL, $text = NULL, $entities = false, $status = false) { + //Argument Test + Eden_Twitter_Error::i() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'string') //Argument 1 must be a string + ->argument(3, 'string') //Argument 1 must be a string + ->argument(4, 'string') //Argument 1 must be a string + ->argument(5, 'string') //Argument 1 must be a string + ->argument(6, 'boolean') //Argument 1 must be a boolean + ->argument(7, 'boolean'); //Argument 1 must be a boolean + + $query = array(); + //if it is not empty + if(!is_null($background)) { + //lets put it in query + $query['profile_background_color'] = $background; + } + //if it is not empty + if(!is_null($link)) { + //lets put it in query + $query['profile_link_color'] = $link; + } + //if it is not empty + if(!is_null($border)) { + //lets put it in query + $query['profile_sidebar_border_color'] = $border; + } + //if it is not empty + if(!is_null($fill)) { + //lets put it in query + $query['profile_sidebar_fill_color'] = $fill; + } + //if it is not empty + if(!is_null($text)) { + //lets put it in query + $query['profile_text_color '] = $text; + } + //if entities + if($entities) { + $query['include_entities'] = 1; + } + //if status + if($status) { + $query['skip_status'] = 1; + } + + return $this->_post(self::URL_UPDATE_PROFILE_COLOR, $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 index 4d0411d..ebe19b1 100644 --- a/library/eden/twitter/base.php +++ b/library/eden/twitter/base.php @@ -38,7 +38,7 @@ class Eden_Twitter_Base extends Eden_Oauth_Base { -------------------------------*/ public function __construct($key, $secret) { //argument test - Eden_Twitter_Error::get() + Eden_Twitter_Error::i() ->argument(1, 'string') //Argument 1 must be a string ->argument(2, 'string'); //Argument 2 must be a string @@ -49,7 +49,7 @@ public function __construct($key, $secret) { /* Public Methods -------------------------------*/ public function getRequestToken() { - return Eden_Oauth::get() + return Eden_Oauth::i() ->getConsumer(self::REQUEST_URL, $this->_key, $this->_secret) ->useAuthorization() ->setMethodToPost() @@ -66,7 +66,7 @@ public function getRequestToken() { */ public function getLoginUrl($token, $redirect) { //Argument tests - Eden_Twitter_Error::get() + Eden_Twitter_Error::i() ->argument(1, 'string') //Argument 1 must be a string ->argument(2, 'string'); //Argument 2 must be a string @@ -86,11 +86,11 @@ public function getLoginUrl($token, $redirect) { */ public function getAccessToken($token, $secret) { //argument test - Eden_Google_Error::get() + Eden_Google_Error::i() ->argument(1, 'string') //Argument 1 must be a string ->argument(2, 'string'); //Argument 2 must be a string - return Eden_Oauth::get() + return Eden_Oauth::i() ->getConsumer(self::ACCESS_URL, $this->_key, $this->_secret) ->useAuthorization() ->setMethodToPost() @@ -113,7 +113,7 @@ public function setAccessToken($token, $secret) { * @return array */ public function getMeta($key = NULL) { - Eden_Google_Error::get()->argument(1, 'string', 'null'); + Eden_Google_Error::i()->argument(1, 'string', 'null'); if(isset($this->_meta[$key])) { return $this->_meta[$key]; @@ -125,7 +125,7 @@ public function getMeta($key = NULL) { /* Protected Methods -------------------------------*/ protected function _getResponse($url, array $query = array()) { - $rest = Eden_Oauth::get() + $rest = Eden_Oauth::i() ->getConsumer($url, $this->_key, $this->_secret) ->setToken($this->_accessToken, $this->_accessSecret) ->setSignatureToHmacSha1(); @@ -138,7 +138,7 @@ protected function _getResponse($url, array $query = array()) { } protected function _post($url, $query = array()) { - $rest = Eden_Oauth::get() + $rest = Eden_Oauth::i() ->getConsumer($url, $this->_key, $this->_secret) ->setToken($this->_accessToken, $this->_accessSecret) ->setMethodToPost() diff --git a/library/eden/twitter/directmessage.php b/library/eden/twitter/directmessage.php index b7ee6f4..25d0c3e 100644 --- a/library/eden/twitter/directmessage.php +++ b/library/eden/twitter/directmessage.php @@ -1,221 +1,221 @@ - -/* - * 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. - */ - -/** - * Eventbrite new or update discount - * - * @package Eden - * @category eventbrite - * @author Christian Blanquera - * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ - */ -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 $_query = array(); - - /* Private Properties - -------------------------------*/ - /* Get - -------------------------------*/ - public static function get($user, $api) { - return self::_getMultiple(__CLASS__, $user, $api); - } - /* Magic - -------------------------------*/ - /* Public Methods - -------------------------------*/ - /** - * Returns the 20 most recent direct messages - * sent to the authenticating user. - * - * @param since is integer - * @param max is integer - * @param count is integer - * @param page is integer - * @param entities is boolean - * @param skip is boolean - * @return $this - */ - public function getList($since = NULL, $max = NULL, $count = NULL, $page = NULL, $entities = false, $skip = false) { - //Argument Test - Eden_Twitter_Error::get() - ->argument(1, 'int', 'null') //Argument 1 must be an integer - ->argument(2, 'int', 'null') //Argument 2 must be an integer - ->argument(3, 'int', 'null') //Argument 3 must be an integer - ->argument(4, 'int', 'null') //Argument 4 must be an integer - ->argument(5, 'bool') //Argument 5 must be an boolean - ->argument(6, 'bool'); //Argument 6 must be a boolean - - $query = array(); - - //if it is not empty a - if(!is_null($since)) { - //lets put it in query - $query['since_id'] = $since; - } - //if it is not empty and max is not less than count - if(!is_null($max) && $max <= $count) { - //lets put it in query - $query['max_id'] = $max; - } - //if it is not empty and its less than equal to 100 - if(!is_null($count) && $count <= 200) { - //lets put it in query - $query['count'] = $count; - } - //if it is not empty - if(!is_null($page)) { - //lets put it in query - $query['page'] = $page; - } - //if entities - if($entities) { - $query['include_entities'] = 1; - } - //if replies - if($skip) { - $query['skip_status'] = 1; - } - return $this->_getResponse(self::URL_DIRECT_MESSAGE, $query); - } - /** - * Returns the 20 most recent direct messages - * sent by the authenticating user. - * - * @param since is integer - * @param max is integer - * @param count is integer - * @param page is integer - * @param entities is boolean - * @return $this - */ - public function getSent($since = NULL, $max = NULL, $count = NULL, $page = NULL, $entities = false) { - //Argument Test - Eden_Twitter_Error::get() - ->argument(1, 'int', 'null') //Argument 1 must be an integer - ->argument(2, 'int', 'null') //Argument 2 must be an integer - ->argument(3, 'int', 'null') //Argument 3 must be an integer - ->argument(4, 'int', 'null') //Argument 4 must be an integer - ->argument(5, 'bool'); //Argument 5 must be an boolean - - $query = array(); - - //if it is not empty a - if(!is_null($since)) { - //lets put it in query - $query['since_id'] = $since; - } - //if it is not empty and max is not less than count - if(!is_null($max) && $max <= $count) { - //lets put it in query - $query['max_id'] = $max; - } - //if it is not empty and its less than equal to 100 - if(!is_null($count) && $count <= 200) { - //lets put it in query - $query['count'] = $count; - } - //if it is not empty - if(!is_null($page)) { - //lets put it in query - $query['page'] = $page; - } - //if entities - if($entities) { - $query['include_entities'] = 1; - } - - return $this->_getResponse(self::URL_SENT_MESSAGE, $query); - } - /** - * Destroys the direct message specified in the required - * ID parameter. The authenticating user must be the - * recipient of the specified direct message. - * - * @param id is integer - * @param entities is boolean - * @return $this - */ - public function remove($id, $entities = false) { - //Argument Test - Eden_Twitter_Error::get() - ->argument(1, 'int') //Argument 1 must be an integer - ->argument(2, 'bool'); //Argument 2 must be a boolean - - $query = array(); - //if entities - if($entities) { - $query['include_entities'] = 1; - } - $url = sprintf(self::URL_REMOVE_MESSAGE, $id); - return $this->_post($url,$query); - } - /** - * Sends a new direct message to the specified - * user from the authenticating user. - * - * @param text is string - * @param user is integer - * @param wrap is boolean - * @return $this - */ - public function add($text, $user = NULL, $wrap = false) { - //Argument Test - Eden_Twitter_Error::get() - ->argument(1, 'string') //Argument 1 must be a string - ->argument(2, 'int','string','null') //Argument 2 must be an integer or string - ->argument(3, 'bool'); //Argument 2 must be a boolean - - $query = array('text' => $text); - //if it is not empty - if(!is_null($user)) { - //if it is integer - if(is_int($user)) { - $query['user_id'] = $user; - } else { - $query['screen_name'] = $user; - } - } - //if wrap - if($wrap) { - $query['wrap_links'] = 1; - } - return $this->_post(self::URL_NEW_MESSAGE, $query); - } - /** - * Returns a single direct message, - * specified by an id parameter. - * - * @param id is integer - * @return $this - */ - public function getDetail($id) { - //Argument Test - Eden_Twitter_Error::get() - ->argument(1, 'int'); //Argument 1 must be an integer - $url = sprintf(self::URL_SHOW_MESSAGE,$id); - return $this->_getResponse($url); - } - - /* Protected Methods - -------------------------------*/ - /* Private Methods - -------------------------------*/ + +/* + * 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. + */ + +/** + * Eventbrite new or update discount + * + * @package Eden + * @category eventbrite + * @author Christian Blanquera + * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ + */ +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 $_query = array(); + + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function i($user, $api) { + return self::_getMultiple(__CLASS__, $user, $api); + } + /* Magic + -------------------------------*/ + /* Public Methods + -------------------------------*/ + /** + * Returns the 20 most recent direct messages + * sent to the authenticating user. + * + * @param since is integer + * @param max is integer + * @param count is integer + * @param page is integer + * @param entities is boolean + * @param skip is boolean + * @return $this + */ + public function getList($since = NULL, $max = NULL, $count = NULL, $page = NULL, $entities = false, $skip = false) { + //Argument Test + Eden_Twitter_Error::i() + ->argument(1, 'int', 'null') //Argument 1 must be an integer + ->argument(2, 'int', 'null') //Argument 2 must be an integer + ->argument(3, 'int', 'null') //Argument 3 must be an integer + ->argument(4, 'int', 'null') //Argument 4 must be an integer + ->argument(5, 'bool') //Argument 5 must be an boolean + ->argument(6, 'bool'); //Argument 6 must be a boolean + + $query = array(); + + //if it is not empty a + if(!is_null($since)) { + //lets put it in query + $query['since_id'] = $since; + } + //if it is not empty and max is not less than count + if(!is_null($max) && $max <= $count) { + //lets put it in query + $query['max_id'] = $max; + } + //if it is not empty and its less than equal to 100 + if(!is_null($count) && $count <= 200) { + //lets put it in query + $query['count'] = $count; + } + //if it is not empty + if(!is_null($page)) { + //lets put it in query + $query['page'] = $page; + } + //if entities + if($entities) { + $query['include_entities'] = 1; + } + //if replies + if($skip) { + $query['skip_status'] = 1; + } + return $this->_getResponse(self::URL_DIRECT_MESSAGE, $query); + } + /** + * Returns the 20 most recent direct messages + * sent by the authenticating user. + * + * @param since is integer + * @param max is integer + * @param count is integer + * @param page is integer + * @param entities is boolean + * @return $this + */ + public function getSent($since = NULL, $max = NULL, $count = NULL, $page = NULL, $entities = false) { + //Argument Test + Eden_Twitter_Error::i() + ->argument(1, 'int', 'null') //Argument 1 must be an integer + ->argument(2, 'int', 'null') //Argument 2 must be an integer + ->argument(3, 'int', 'null') //Argument 3 must be an integer + ->argument(4, 'int', 'null') //Argument 4 must be an integer + ->argument(5, 'bool'); //Argument 5 must be an boolean + + $query = array(); + + //if it is not empty a + if(!is_null($since)) { + //lets put it in query + $query['since_id'] = $since; + } + //if it is not empty and max is not less than count + if(!is_null($max) && $max <= $count) { + //lets put it in query + $query['max_id'] = $max; + } + //if it is not empty and its less than equal to 100 + if(!is_null($count) && $count <= 200) { + //lets put it in query + $query['count'] = $count; + } + //if it is not empty + if(!is_null($page)) { + //lets put it in query + $query['page'] = $page; + } + //if entities + if($entities) { + $query['include_entities'] = 1; + } + + return $this->_getResponse(self::URL_SENT_MESSAGE, $query); + } + /** + * Destroys the direct message specified in the required + * ID parameter. The authenticating user must be the + * recipient of the specified direct message. + * + * @param id is integer + * @param entities is boolean + * @return $this + */ + public function remove($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(); + //if entities + if($entities) { + $query['include_entities'] = 1; + } + $url = sprintf(self::URL_REMOVE_MESSAGE, $id); + return $this->_post($url,$query); + } + /** + * Sends a new direct message to the specified + * user from the authenticating user. + * + * @param text is string + * @param user is integer + * @param wrap is boolean + * @return $this + */ + public function add($text, $user = NULL, $wrap = false) { + //Argument Test + Eden_Twitter_Error::i() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'int','string','null') //Argument 2 must be an integer or string + ->argument(3, 'bool'); //Argument 2 must be a boolean + + $query = array('text' => $text); + //if it is not empty + if(!is_null($user)) { + //if it is integer + if(is_int($user)) { + $query['user_id'] = $user; + } else { + $query['screen_name'] = $user; + } + } + //if wrap + if($wrap) { + $query['wrap_links'] = 1; + } + return $this->_post(self::URL_NEW_MESSAGE, $query); + } + /** + * Returns a single direct message, + * specified by an id parameter. + * + * @param id is integer + * @return $this + */ + public function getDetail($id) { + //Argument Test + Eden_Twitter_Error::i() + ->argument(1, 'int'); //Argument 1 must be an integer + $url = sprintf(self::URL_SHOW_MESSAGE,$id); + return $this->_getResponse($url); + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ } \ No newline at end of file diff --git a/library/eden/twitter/favorites.php b/library/eden/twitter/favorites.php index 7888bcf..86719fe 100644 --- a/library/eden/twitter/favorites.php +++ b/library/eden/twitter/favorites.php @@ -1,130 +1,130 @@ - -/* - * 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. - */ - -/** - * Eventbrite new or update discount - * - * @package Eden - * @category eventbrite - * @author Christian Blanquera - * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ - */ -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 - -------------------------------*/ - protected $_query = array(); - - /* Private Properties - -------------------------------*/ - /* Get - -------------------------------*/ - public static function get($key, $secret) { - return self::_getMultiple(__CLASS__, $key, $secret); - } - - /* Magic - -------------------------------*/ - /* Public Methods - -------------------------------*/ - /** - * Returns the 20 most recent favorite statuses for the authenticating - * user or user specified by the ID parameter in the requested format. - * - * @param id is string or integer - * @param since is integer - * @param page is integer - * @param entities is boolean - * @return $this - */ - public function getList($id = NULL, $since = NULL, $page = NULL, $entities = false) { - //Argument Test - Eden_Twitter_Error::get() - ->argument(1, 'int', 'string', 'null') //Argument 1 must be a string or integer - ->argument(2, 'int', 'null') //Argument 1 must be an integer - ->argument(3, 'int', 'null') //Argument 4 must be an integer - ->argument(4, 'boolean'); //Argument 4 must be a boolean - - $query = array(); - //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; - } - //if entities - if($entities) { - $query['include_entities'] = 1; - } - - return $this->_getResponse(self::URL_GET_FAVORITES, $query); - } - /** - * Favorites the status specified in the ID parameter as the authenticating - * user. Returns the favorite status when successful. - * - * @param id is integer - * @param entities is boolean - * @return $this - */ - public function addFavorite($id, $entities = false) { - //Argument Test - Eden_Twitter_Error::get() - ->argument(1, 'int') //Argument 1 must be an integer - ->argument(2, 'boolean'); //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); - } - /** - * n-favorites the status specified in the ID parameter as the authenticating user. - * - * @param id is integer - * @return $this - */ - public function removeFavorite($id) { - //Argument Test - Eden_Twitter_Error::get() - ->argument(1, 'int'); //Argument 1 must be na integer - - $query = array('id' => $id); - - $url = sprintf(self::URL_UNFAVORITE_STATUS, $id); - return $this->_post($url, $query); - } - - /* Protected Methods - -------------------------------*/ - /* Private Methods - -------------------------------*/ - - + +/* + * 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. + */ + +/** + * Eventbrite new or update discount + * + * @package Eden + * @category eventbrite + * @author Christian Blanquera + * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ + */ +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 + -------------------------------*/ + protected $_query = array(); + + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function i($key, $secret) { + return self::_getMultiple(__CLASS__, $key, $secret); + } + + /* Magic + -------------------------------*/ + /* Public Methods + -------------------------------*/ + /** + * Returns the 20 most recent favorite statuses for the authenticating + * user or user specified by the ID parameter in the requested format. + * + * @param id is string or integer + * @param since is integer + * @param page is integer + * @param entities is boolean + * @return $this + */ + public function getList($id = NULL, $since = NULL, $page = NULL, $entities = false) { + //Argument Test + Eden_Twitter_Error::i() + ->argument(1, 'int', 'string', 'null') //Argument 1 must be a string or integer + ->argument(2, 'int', 'null') //Argument 1 must be an integer + ->argument(3, 'int', 'null') //Argument 4 must be an integer + ->argument(4, 'boolean'); //Argument 4 must be a boolean + + $query = array(); + //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; + } + //if entities + if($entities) { + $query['include_entities'] = 1; + } + + return $this->_getResponse(self::URL_GET_FAVORITES, $query); + } + /** + * Favorites the status specified in the ID parameter as the authenticating + * user. Returns the favorite status when successful. + * + * @param id is integer + * @param entities is boolean + * @return $this + */ + public function addFavorite($id, $entities = false) { + //Argument Test + Eden_Twitter_Error::i() + ->argument(1, 'int') //Argument 1 must be an integer + ->argument(2, 'boolean'); //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); + } + /** + * n-favorites the status specified in the ID parameter as the authenticating user. + * + * @param id is integer + * @return $this + */ + public function removeFavorite($id) { + //Argument Test + Eden_Twitter_Error::i() + ->argument(1, 'int'); //Argument 1 must be na integer + + $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 index 9b12ffd..984961a 100644 --- a/library/eden/twitter/friends.php +++ b/library/eden/twitter/friends.php @@ -1,481 +1,481 @@ - - -/* - * 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. - */ - -/** - * Eventbrite new or update discount - * - * @package Eden - * @category eventbrite - * @author Christian Blanquera - * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ - */ -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 = 'http://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 - -------------------------------*/ - protected $_query = array(); - - protected static $_validName = array('twitterapi','twitter'); - - /* Private Properties - -------------------------------*/ - /* Get - -------------------------------*/ - public static function get($user, $api) { - return self::_getMultiple(__CLASS__, $user, $api); - } - /* Magic - -------------------------------*/ - /* Public Methods - -------------------------------*/ - /** - * Returns an array of numeric IDs for every - * user following the specified user. - * - * @param id is integer - * @param name is string - * @param cursor is integer - * @param stringify is boolean - * @return $this - */ - public function getFollowers($id = NULL, $cursor = NULL, $stringify = false) { - //Argument Test - Eden_Twitter_Error::get() - ->argument(1, 'int', 'string') //Argument 1 must be an integer - ->argument(2, 'int') //Argument 2 must be an integer - ->argument(3, 'bool'); //Argument 3 must be an boolean - - $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 id is integer - * @param name is string - * @param cursor is integer - * @param stringify is boolean - * @return $this - */ - public function getFriends($id = NULL, $cursor = NULL, $stringify = false) { - //Argument Test - Eden_Twitter_Error::get() - ->argument(1, 'int','string') //Argument 1 must be an integer - ->argument(2, 'int') //Argument 3 must be an integer - ->argument(3, 'bool'); //Argument 4 must be an boolean - - $query = array(); - //if it is not empty - if(!is_null($id)) { - if(is_int($id)) { - $query['user_id'] = $id; - } else { - //lets put it in query - $query['screen_name'] = $id; - } - } - 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_FRIENDS, $query); - } - /** - * Test for the existence of friendship between two users. - * - * @param userA is integer - * @param userB is string - * @param nameA is integer - * @param nameB is boolean - * @return $this - */ - public function friendsExist($userA = NULL, $userB = NULL) { - //Argument Test - Eden_Twitter_Error::get() - ->argument(1, 'string','int') //Argument 1 must be an integer - ->argument(2, 'string','int'); //Argument 2 must be an integer - - $query = array(); - //if it is not empty - if(!is_null($userA)) { - - if(is_int($userA)) { - //lets put it in query - $query['user_id_a'] = $userA; - } else { - $query['screen_name_a'] = $userA; - } - } - //if it is not empty - if(!is_null($userB)) { - - if(is_int($userB)) { - //lets put it in query - $query['user_id_b'] = $userB; - } else { - $query['screen_name_b'] = $userB; - } - } - return $this->_getResponse(self::URL_FRIENDS_EXIST, $query); - } - /** - * Returns an array of numeric IDs for every user - * who has a pending request to follow the authenticating user. - * - * @param cursor is integer - * @param stringify is boolean - * @return $this - */ - public function incomingFriends($cursor = NULL, $stringify = false) { - //Argument Test - Eden_Twitter_Error::get() - ->argument(1, 'int') //Argument 1 must be an integer - ->argument(2, 'boolean'); //Argument 2 must be an integer - - $query = array(); - //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_INCOMING_FRIENDS, $query); - } - /** - * Returns an array of numeric IDs for every protected user - * for whom the authenticating user has a pending follow request. - * - * @param cursor is integer - * @param stringify is boolean - * @return $this - */ - public function outgoingFriends($cursor = NULL, $stringify = false) { - //Argument Test - Eden_Twitter_Error::get() - ->argument(1, 'int') //Argument 1 must be an integer - ->argument(2, 'boolean'); //Argument 2 must be an integer - - $query = array(); - //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_OUTGOING_FRIENDS, $query); - } - /** - * Returns detailed information about the relationship between two users. - * - * @param cursor is integer - * @param stringify is boolean - * @return $this - */ - public function getDetails($id = NULL, $target = NULL) { - //Argument Test - Eden_Twitter_Error::get() - ->argument(1, 'string','int') //Argument 1 must be an string - ->argument(2, 'string','int'); //Argument 2 must be an string - - $query = array(); - //if it is not empty - if(!is_null($id)) { - - if(is_int($id)) { - //lets put it in query - $query['source_id'] = $id; - } - - if(is_string($id)) { - //lets put it in query - $query['source_screen_name'] = $id; - } - } - //if it is not empty - if(!is_null($target)) { - //if it is integer - if(is_int($target)) { - //lets put it in query - $query['target_id'] = $target; - } - //if it is string - if(is_string($target)) { - //lets put it in query - $query['target_screen_name'] = $target; - } - } - - - - return $this->_getResponse(self::URL_SHOW_FRIENDS, $query); - } - /** - * Allows the authenticating users to follow the user specified in the ID parameter.. - * - * @param name is string - * @param id is integer - * @param follow is boolean - * @return $this - */ - public function followFriends($name = NULL, $id = NULL, $follow = false) { - //Argument Test - Eden_Twitter_Error::get() - ->argument(1, 'string') //Argument 1 must be an string - ->argument(2, 'int') //Argument 2 must be an integer - ->argument(3, 'boolean'); //Argument 3 must be an boolean - - - - $query = array(); - - //if it is not empty - if(!is_null($name)) { - //lets put it in query - $query['screen_name'] = $name; - } - //if it is not empty - if(!is_null($id)) { - //lets put it in query - $query['user_id'] = $id; - } - //if follow - if($follow) { - $query['follow'] = $follow; - } - - return $this->_post(self::URL_FOLLOW_FRIENDS, $query); - } - /** - * Allows the authenticating users to unfollow the user specified in the ID parameter. - * - * @param id is integer - * @param name is string - * @param entities is boolean - * @return $this - */ - public function unfollowFriends($name = NULL, $id = NULL, $entities = false) { - //Argument Test - Eden_Twitter_Error::get() - ->argument(1, 'string') //Argument 1 must be an string - ->argument(2, 'int') //Argument 2 must be an integer - ->argument(3, 'boolean'); //Argument 3 must be an boolean - - - - $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; - } - //if entities - if($entities) { - $query['include_entities'] = $entities; - } - - return $this->_post(self::URL_UNFOLLOW_FRIENDS, $query); - } - /** - * Returns the relationship of the authenticating user to - * the comma separated list of up to 100 screen_names or user_ids provided. - * - * @param name is string - * @param id is integer - * @return $this - */ - public function lookupFriends($id = NULL) { - //Argument Test - Eden_Twitter_Error::get() - ->argument(1, 'int', 'string'); //Argument 1 must be an string - - $query = array(); - //if it is not empty - if(!is_null($id)) { - //if id is integer - if(is_int($id)) { - $id = explode(',', $id); - //lets put it in query - $query['user_id'] = $id; - } - //if id is string - if(is_string($id)) { - $id = explode(',', $id); - //at this poit id will be an array - $id = array(); - $query['screen_name'] = $id; - - - //lets put it in query - //$query['screen_name'] = $id; - } - } - - return $this->_getResponse(self::URL_LOOKUP_FRIENDS, $query); - } - /** - * Allows one to enable or disable retweets and device notifications from the specified user. - * - * @param id is string or integer - * @param device is boolean - * @param retweets is boolean - * @return $this - */ - public function update($id = NULL, $device = NULL, $retweets = NULL) { - //Argument Test - Eden_Twitter_Error::get() - ->argument(1, 'string','int') //Argument 1 must be a string or integer - ->argument(2, 'boolean') //Argument 2 must be a boolean - ->argument(3, 'boolean'); //Argument 3 must be a boolean - - $query = array(); - - //if it is not empty - if(!is_null($id)) { - //if id is string - if(is_string($id)) { - //lets put it in query - $query['screen_name'] = $id; - } - //if id is integer - if(is_int($id)) { - //lets put it in query - $query['user_id'] = $id; - } - } - - if(!is_null($device)) { - //lets put it in query - $query['device'] = $device; - } - - if(!is_null($retweets)) { - //lets put it in query - $query['retweets'] = $dretweets; - } - - return $this->_post(self::URL_UPDATE, $query); - } - /** - * Returns an array of user_ids that the currently authenticated user does not want to see retweets from. - * - * @param stringify is string - * @return $this - */ - public function getNoRetweets($stringify = NULL) { - //Argument Test - Eden_Twitter_Error::get() - ->argument(1, 'boolean'); //Argument 1 must be an boolean - - $query = array(); - - if(!is_null($stringify)) { - //lets put it in query - $query['stringify_ids'] = $stringify; - } - - return $this->_getResponse(self::URL_NO_RETWEETS_IDS, $query); - } - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - /* Protected Methods - -------------------------------*/ - /* Private Methods - -------------------------------*/ -} - + + +/* + * 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. + */ + +/** + * Eventbrite new or update discount + * + * @package Eden + * @category eventbrite + * @author Christian Blanquera + * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ + */ +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 = 'http://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 + -------------------------------*/ + protected $_query = array(); + + protected static $_validName = array('twitterapi','twitter'); + + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function i($user, $api) { + return self::_getMultiple(__CLASS__, $user, $api); + } + /* Magic + -------------------------------*/ + /* Public Methods + -------------------------------*/ + /** + * Returns an array of numeric IDs for every + * user following the specified user. + * + * @param id is integer + * @param name is string + * @param cursor is integer + * @param stringify is boolean + * @return $this + */ + public function getFollowers($id = NULL, $cursor = NULL, $stringify = false) { + //Argument Test + Eden_Twitter_Error::i() + ->argument(1, 'int', 'string') //Argument 1 must be an integer + ->argument(2, 'int') //Argument 2 must be an integer + ->argument(3, 'bool'); //Argument 3 must be an boolean + + $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 id is integer + * @param name is string + * @param cursor is integer + * @param stringify is boolean + * @return $this + */ + public function getFriends($id = NULL, $cursor = NULL, $stringify = false) { + //Argument Test + Eden_Twitter_Error::i() + ->argument(1, 'int','string') //Argument 1 must be an integer + ->argument(2, 'int') //Argument 3 must be an integer + ->argument(3, 'bool'); //Argument 4 must be an boolean + + $query = array(); + //if it is not empty + if(!is_null($id)) { + if(is_int($id)) { + $query['user_id'] = $id; + } else { + //lets put it in query + $query['screen_name'] = $id; + } + } + 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_FRIENDS, $query); + } + /** + * Test for the existence of friendship between two users. + * + * @param userA is integer + * @param userB is string + * @param nameA is integer + * @param nameB is boolean + * @return $this + */ + public function friendsExist($userA = NULL, $userB = NULL) { + //Argument Test + Eden_Twitter_Error::i() + ->argument(1, 'string','int') //Argument 1 must be an integer + ->argument(2, 'string','int'); //Argument 2 must be an integer + + $query = array(); + //if it is not empty + if(!is_null($userA)) { + + if(is_int($userA)) { + //lets put it in query + $query['user_id_a'] = $userA; + } else { + $query['screen_name_a'] = $userA; + } + } + //if it is not empty + if(!is_null($userB)) { + + if(is_int($userB)) { + //lets put it in query + $query['user_id_b'] = $userB; + } else { + $query['screen_name_b'] = $userB; + } + } + return $this->_getResponse(self::URL_FRIENDS_EXIST, $query); + } + /** + * Returns an array of numeric IDs for every user + * who has a pending request to follow the authenticating user. + * + * @param cursor is integer + * @param stringify is boolean + * @return $this + */ + public function incomingFriends($cursor = NULL, $stringify = false) { + //Argument Test + Eden_Twitter_Error::i() + ->argument(1, 'int') //Argument 1 must be an integer + ->argument(2, 'boolean'); //Argument 2 must be an integer + + $query = array(); + //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_INCOMING_FRIENDS, $query); + } + /** + * Returns an array of numeric IDs for every protected user + * for whom the authenticating user has a pending follow request. + * + * @param cursor is integer + * @param stringify is boolean + * @return $this + */ + public function outgoingFriends($cursor = NULL, $stringify = false) { + //Argument Test + Eden_Twitter_Error::i() + ->argument(1, 'int') //Argument 1 must be an integer + ->argument(2, 'boolean'); //Argument 2 must be an integer + + $query = array(); + //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_OUTGOING_FRIENDS, $query); + } + /** + * Returns detailed information about the relationship between two users. + * + * @param cursor is integer + * @param stringify is boolean + * @return $this + */ + public function getDetails($id = NULL, $target = NULL) { + //Argument Test + Eden_Twitter_Error::i() + ->argument(1, 'string','int') //Argument 1 must be an string + ->argument(2, 'string','int'); //Argument 2 must be an string + + $query = array(); + //if it is not empty + if(!is_null($id)) { + + if(is_int($id)) { + //lets put it in query + $query['source_id'] = $id; + } + + if(is_string($id)) { + //lets put it in query + $query['source_screen_name'] = $id; + } + } + //if it is not empty + if(!is_null($target)) { + //if it is integer + if(is_int($target)) { + //lets put it in query + $query['target_id'] = $target; + } + //if it is string + if(is_string($target)) { + //lets put it in query + $query['target_screen_name'] = $target; + } + } + + + + return $this->_getResponse(self::URL_SHOW_FRIENDS, $query); + } + /** + * Allows the authenticating users to follow the user specified in the ID parameter.. + * + * @param name is string + * @param id is integer + * @param follow is boolean + * @return $this + */ + public function followFriends($name = NULL, $id = NULL, $follow = false) { + //Argument Test + Eden_Twitter_Error::i() + ->argument(1, 'string') //Argument 1 must be an string + ->argument(2, 'int') //Argument 2 must be an integer + ->argument(3, 'boolean'); //Argument 3 must be an boolean + + + + $query = array(); + + //if it is not empty + if(!is_null($name)) { + //lets put it in query + $query['screen_name'] = $name; + } + //if it is not empty + if(!is_null($id)) { + //lets put it in query + $query['user_id'] = $id; + } + //if follow + if($follow) { + $query['follow'] = $follow; + } + + return $this->_post(self::URL_FOLLOW_FRIENDS, $query); + } + /** + * Allows the authenticating users to unfollow the user specified in the ID parameter. + * + * @param id is integer + * @param name is string + * @param entities is boolean + * @return $this + */ + public function unfollowFriends($name = NULL, $id = NULL, $entities = false) { + //Argument Test + Eden_Twitter_Error::i() + ->argument(1, 'string') //Argument 1 must be an string + ->argument(2, 'int') //Argument 2 must be an integer + ->argument(3, 'boolean'); //Argument 3 must be an boolean + + + + $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; + } + //if entities + if($entities) { + $query['include_entities'] = $entities; + } + + return $this->_post(self::URL_UNFOLLOW_FRIENDS, $query); + } + /** + * Returns the relationship of the authenticating user to + * the comma separated list of up to 100 screen_names or user_ids provided. + * + * @param name is string + * @param id is integer + * @return $this + */ + public function lookupFriends($id = NULL) { + //Argument Test + Eden_Twitter_Error::i() + ->argument(1, 'int', 'string'); //Argument 1 must be an string + + $query = array(); + //if it is not empty + if(!is_null($id)) { + //if id is integer + if(is_int($id)) { + $id = explode(',', $id); + //lets put it in query + $query['user_id'] = $id; + } + //if id is string + if(is_string($id)) { + $id = explode(',', $id); + //at this poit id will be an array + $id = array(); + $query['screen_name'] = $id; + + + //lets put it in query + //$query['screen_name'] = $id; + } + } + + return $this->_getResponse(self::URL_LOOKUP_FRIENDS, $query); + } + /** + * Allows one to enable or disable retweets and device notifications from the specified user. + * + * @param id is string or integer + * @param device is boolean + * @param retweets is boolean + * @return $this + */ + public function update($id = NULL, $device = NULL, $retweets = NULL) { + //Argument Test + Eden_Twitter_Error::i() + ->argument(1, 'string','int') //Argument 1 must be a string or integer + ->argument(2, 'boolean') //Argument 2 must be a boolean + ->argument(3, 'boolean'); //Argument 3 must be a boolean + + $query = array(); + + //if it is not empty + if(!is_null($id)) { + //if id is string + if(is_string($id)) { + //lets put it in query + $query['screen_name'] = $id; + } + //if id is integer + if(is_int($id)) { + //lets put it in query + $query['user_id'] = $id; + } + } + + if(!is_null($device)) { + //lets put it in query + $query['device'] = $device; + } + + if(!is_null($retweets)) { + //lets put it in query + $query['retweets'] = $dretweets; + } + + return $this->_post(self::URL_UPDATE, $query); + } + /** + * Returns an array of user_ids that the currently authenticated user does not want to see retweets from. + * + * @param stringify is string + * @return $this + */ + public function getNoRetweets($stringify = NULL) { + //Argument Test + Eden_Twitter_Error::i() + ->argument(1, 'boolean'); //Argument 1 must be an boolean + + $query = array(); + + if(!is_null($stringify)) { + //lets put it in query + $query['stringify_ids'] = $stringify; + } + + return $this->_getResponse(self::URL_NO_RETWEETS_IDS, $query); + } + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} + ?> \ No newline at end of file diff --git a/library/eden/twitter/list.php b/library/eden/twitter/list.php index e5d7a9b..a8e5c3d 100644 --- a/library/eden/twitter/list.php +++ b/library/eden/twitter/list.php @@ -1,163 +1,163 @@ - -/* - * 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. - */ - -/** - * Eventbrite new or update discount - * - * @package Eden - * @category eventbrite - * @author Christian Blanquera - * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ - */ -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'; - - - - - /* Public Properties - -------------------------------*/ - /* Protected Properties - -------------------------------*/ - protected $_query = array(); - - /* Private Properties - -------------------------------*/ - /* Get - -------------------------------*/ - public static function get($key, $secret) { - return self::_getMultiple(__CLASS__, $key, $secret); - } - - /* Magic - -------------------------------*/ - /* Public Methods - -------------------------------*/ - /** - * Returns all lists the authenticating or specified user - * subscribes to, including their own. - * - * @param name is string - * @param size is integer - * @return $this - */ - public function getList($id = NULL, $name = NULL) { - //Argument Test - Eden_Twitter_Error::get() - ->argument(1, 'int','string','null') //Argument 1 must be a string or integer - ->argument(2, 'int','string','null'); //Argument 2 must be a string or integer - - $query = array(); - - //if it is not empty - if(!is_null($id)) { - //if it is integer - if(is_int($id)) { - //lets put it in our query - $query['user_id'] = $id; - } - //if it is string - if(is_string($id)) { - //lets put it in our query - $query['screen_name'] = $id; - } - } - //if it is not empty - if(!is_null($name)) { - //if it is string - if(is_string($name)) { - //lets put it in our query - $query['screen_name'] = $name; - } - //if it is integer - if(is_int($name)) { - //lets put it in our query - $query['user_name'] = $name; - } - } - - return $this->_getResponse(self::URL_ALL_LIST, $query); - } - /** - * Returns tweet timeline for members of the specified list. - * - * @param name is string - * @param size is integer - * @return $this - - public function getStatus($id, $slug, $ownerName = NULL, $ownerId = NULL, $since = NULL, $max = NULL, $perpage = NULL, $entities = NULL, $rts = NULL) { - //Argument Test - Eden_Twitter_Error::get() - ->argument(1, 'int') //Argument 1 must be a string or integer - ->argument(2, 'string') //Argument 2 must be a string or integer - ->argument(3, 'int','string','null') //Argument 2 must be a string or integer - ->argument(4, 'int','null') //Argument 2 must be a string or integer - ->argument(5, 'int','null') //Argument 2 must be a string or integer - ->argument(6, 'int','null') //Argument 2 must be a string or integer - ->argument(7, 'int','null') //Argument 2 must be a string or integer - ->argument(8, 'boolean','null') //Argument 2 must be a string or integer - ->argument(9, 'boolean','null'); //Argument 2 must be a string or integer - - $query = array('list_id' => $id, - 'slug' => $slug); - //if it is not empty - if(!is_null($ownerName)) { - //lets put it in our query - $query['owner_name'] = $ownerName; - } - //if it is not empty - if(!is_null($ownerId)) { - //lets put it in our query - $query['owner_id'] = $ownerId; - } - //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($max)) { - //lets put it in our query - $query['max_id'] = $max; - } - //if it is not empty - if(!is_null($perpage)) { - //lets put it in our query - $query['per_page'] = $perpage; - } - //if entities - if($entities) { - $query['include_entities'] = 1; - } - //if rts - if($rts) { - $query['rts'] = 1; - } - - return $this->_getResponse(self::URL_GET_STATUS, $query); - } - */ - - - - - - - - - /* Protected Methods - -------------------------------*/ - /* Private Methods - -------------------------------*/ - - + +/* + * 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. + */ + +/** + * Eventbrite new or update discount + * + * @package Eden + * @category eventbrite + * @author Christian Blanquera + * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ + */ +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'; + + + + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_query = array(); + + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function i($key, $secret) { + return self::_getMultiple(__CLASS__, $key, $secret); + } + + /* Magic + -------------------------------*/ + /* Public Methods + -------------------------------*/ + /** + * Returns all lists the authenticating or specified user + * subscribes to, including their own. + * + * @param name is string + * @param size is integer + * @return $this + */ + public function getList($id = NULL, $name = NULL) { + //Argument Test + Eden_Twitter_Error::i() + ->argument(1, 'int','string','null') //Argument 1 must be a string or integer + ->argument(2, 'int','string','null'); //Argument 2 must be a string or integer + + $query = array(); + + //if it is not empty + if(!is_null($id)) { + //if it is integer + if(is_int($id)) { + //lets put it in our query + $query['user_id'] = $id; + } + //if it is string + if(is_string($id)) { + //lets put it in our query + $query['screen_name'] = $id; + } + } + //if it is not empty + if(!is_null($name)) { + //if it is string + if(is_string($name)) { + //lets put it in our query + $query['screen_name'] = $name; + } + //if it is integer + if(is_int($name)) { + //lets put it in our query + $query['user_name'] = $name; + } + } + + return $this->_getResponse(self::URL_ALL_LIST, $query); + } + /** + * Returns tweet timeline for members of the specified list. + * + * @param name is string + * @param size is integer + * @return $this + + public function getStatus($id, $slug, $ownerName = NULL, $ownerId = NULL, $since = NULL, $max = NULL, $perpage = NULL, $entities = NULL, $rts = NULL) { + //Argument Test + Eden_Twitter_Error::i() + ->argument(1, 'int') //Argument 1 must be a string or integer + ->argument(2, 'string') //Argument 2 must be a string or integer + ->argument(3, 'int','string','null') //Argument 2 must be a string or integer + ->argument(4, 'int','null') //Argument 2 must be a string or integer + ->argument(5, 'int','null') //Argument 2 must be a string or integer + ->argument(6, 'int','null') //Argument 2 must be a string or integer + ->argument(7, 'int','null') //Argument 2 must be a string or integer + ->argument(8, 'boolean','null') //Argument 2 must be a string or integer + ->argument(9, 'boolean','null'); //Argument 2 must be a string or integer + + $query = array('list_id' => $id, + 'slug' => $slug); + //if it is not empty + if(!is_null($ownerName)) { + //lets put it in our query + $query['owner_name'] = $ownerName; + } + //if it is not empty + if(!is_null($ownerId)) { + //lets put it in our query + $query['owner_id'] = $ownerId; + } + //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($max)) { + //lets put it in our query + $query['max_id'] = $max; + } + //if it is not empty + if(!is_null($perpage)) { + //lets put it in our query + $query['per_page'] = $perpage; + } + //if entities + if($entities) { + $query['include_entities'] = 1; + } + //if rts + if($rts) { + $query['rts'] = 1; + } + + return $this->_getResponse(self::URL_GET_STATUS, $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 index 5dc401b..5167dd0 100644 --- a/library/eden/twitter/oauth.php +++ b/library/eden/twitter/oauth.php @@ -29,7 +29,7 @@ class Eden_Twitter_Oauth extends Eden_Twitter_Base { -------------------------------*/ /* Get -------------------------------*/ - public static function get($key, $secret) { + public static function i($key, $secret) { return self::_getMultiple(__CLASS__, $key, $secret); } diff --git a/library/eden/twitter/search.php b/library/eden/twitter/search.php index 56a5ad1..99982fe 100644 --- a/library/eden/twitter/search.php +++ b/library/eden/twitter/search.php @@ -1,157 +1,157 @@ - -/* - * 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. - */ - -/** - * Eventbrite new or update discount - * - * @package Eden - * @category eventbrite - * @author Christian Blanquera - * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ - */ -class Eden_Twitter_Search extends Eden_Twitter_Base { - /* Constants - -------------------------------*/ - const URL_SEARCH = 'http://search.twitter.com/search.json'; - - /* Public Properties - -------------------------------*/ - /* Protected Properties - -------------------------------*/ - protected $_query = array(); - - protected static $_validResult = array('mixed', 'recent', 'popular'); - - /* Private Properties - -------------------------------*/ - /* Get - -------------------------------*/ - public static function get($user, $api) { - return self::_getMultiple(__CLASS__, $user, $api); - } - /* Magic - -------------------------------*/ - /* Public Methods - -------------------------------*/ - /** - * Returns tweets that match a specified query - * - * @param q is integer or string. - * @param callback is string. - * @param geocode is float. - * @param lang is string. - * @param locale is string. - * @param page is integer - * @param result is string. - * @param rpp is string. - * @param show is boolean - * @param until is string - * @param since is string - * @param entities is boolean - * @return $this - */ - public function search($q, $callback = NULL, $geocode = NULL, $lang = NULL, $locale = NULL, $page = NULL, $result = NULL, $rpp = NULL, $show = false, $until = NULL, $since = NULL, $entities = NULL) { - //Argument Test - Eden_Twitter_Error::get() - ->argument(1, 'string','int') //Argument 1 must be a string or int - ->argument(2, 'string', 'null') //Argument 2 must be a string - ->argument(3, 'float', 'null') //Argument 3 must be a flaot - ->argument(4, 'string', 'null') //Argument 4 must be a string - ->argument(5, 'string', 'null') //Argument 5 must be a string - ->argument(6, 'int', 'null') //Argument 6 must be an integer - ->argument(7, 'string', 'null') //Argument 7 must be a string - ->argument(8, 'string', 'null') //Argument 8 must be an integer - ->argument(9, 'boolean') //Argument 9 must be a boolean - ->argument(10, 'string', 'null') //Argument 10 must be a string - ->argument(11, 'string', 'null') //Argument 11 must be a string - ->argument(12, 'boolean'); //Argument 12 must be a boolean - - $query = array('q' => $q); - //if it is not empty - if(!is_null($callback)) { - //lets put it in query - $query['callback'] = $callback; - } - //if it is not empty - if(!is_null($geocode)) { - //lets put it in query - $query['geocode'] = $geocode; - } - //if it is not empty - if(!is_null($lang)) { - //lets put it in query - $query['lang'] = $lang; - } - //if it is not empty - if(!is_null($locale)) { - //lets put it in query - $query['locale'] = $locale; - } - //if it is not empty - if(!is_null($page)) { - //lets put it in query - $query['page'] = $count; - } - //if there is a result - if(!is_null($result)) { - //if result is a string - if(is_string($result)) { - //lets make it an array - $result = explode(',', $result); - } - //at this point result will be an array - $results = array(); - //for each result - foreach($result as $event) { - //if this result is a valid result - if(in_array($result, $this->_validResult)) { - //lets add this to our valid resulr list - $results[] = $event; - } - } - //if we have at least one valid result - if(!empty($results)) { - //lets make results into a string - $result = implode(',', $result); - //and add to query - $query['result_type'] = $result; - } - } - //if rpp is not empty and less than equal to 100 - if(!is_null($rpp) && $rpp <= 100) { - //lets put in in query - $query['rpp'] = $rpp; - } - //if show - if($show) { - $query['show_user'] = 1; - } - //if it is not empty - if(!is_null($until)) { - $until = date('Y-m-d', $until); - //add it to our query - $query['until'] = $until; - } - //if it is not empty and - if(!is_null($since)) { - //lets put it in query - $query['since_id'] = $since; - } - //if entities - if($entities) { - $query['include_entities'] = 1; - } - - return $this->_getResponse(self::URL_SEARCH, $query); - } - /* Protected Methods - -------------------------------*/ - /* Private Methods - -------------------------------*/ + +/* + * 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. + */ + +/** + * Eventbrite new or update discount + * + * @package Eden + * @category eventbrite + * @author Christian Blanquera + * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ + */ +class Eden_Twitter_Search extends Eden_Twitter_Base { + /* Constants + -------------------------------*/ + const URL_SEARCH = 'http://search.twitter.com/search.json'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_query = array(); + + protected static $_validResult = array('mixed', 'recent', 'popular'); + + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function i($user, $api) { + return self::_getMultiple(__CLASS__, $user, $api); + } + /* Magic + -------------------------------*/ + /* Public Methods + -------------------------------*/ + /** + * Returns tweets that match a specified query + * + * @param q is integer or string. + * @param callback is string. + * @param geocode is float. + * @param lang is string. + * @param locale is string. + * @param page is integer + * @param result is string. + * @param rpp is string. + * @param show is boolean + * @param until is string + * @param since is string + * @param entities is boolean + * @return $this + */ + public function search($q, $callback = NULL, $geocode = NULL, $lang = NULL, $locale = NULL, $page = NULL, $result = NULL, $rpp = NULL, $show = false, $until = NULL, $since = NULL, $entities = NULL) { + //Argument Test + Eden_Twitter_Error::i() + ->argument(1, 'string','int') //Argument 1 must be a string or int + ->argument(2, 'string', 'null') //Argument 2 must be a string + ->argument(3, 'float', 'null') //Argument 3 must be a flaot + ->argument(4, 'string', 'null') //Argument 4 must be a string + ->argument(5, 'string', 'null') //Argument 5 must be a string + ->argument(6, 'int', 'null') //Argument 6 must be an integer + ->argument(7, 'string', 'null') //Argument 7 must be a string + ->argument(8, 'string', 'null') //Argument 8 must be an integer + ->argument(9, 'boolean') //Argument 9 must be a boolean + ->argument(10, 'string', 'null') //Argument 10 must be a string + ->argument(11, 'string', 'null') //Argument 11 must be a string + ->argument(12, 'boolean'); //Argument 12 must be a boolean + + $query = array('q' => $q); + //if it is not empty + if(!is_null($callback)) { + //lets put it in query + $query['callback'] = $callback; + } + //if it is not empty + if(!is_null($geocode)) { + //lets put it in query + $query['geocode'] = $geocode; + } + //if it is not empty + if(!is_null($lang)) { + //lets put it in query + $query['lang'] = $lang; + } + //if it is not empty + if(!is_null($locale)) { + //lets put it in query + $query['locale'] = $locale; + } + //if it is not empty + if(!is_null($page)) { + //lets put it in query + $query['page'] = $count; + } + //if there is a result + if(!is_null($result)) { + //if result is a string + if(is_string($result)) { + //lets make it an array + $result = explode(',', $result); + } + //at this point result will be an array + $results = array(); + //for each result + foreach($result as $event) { + //if this result is a valid result + if(in_array($result, $this->_validResult)) { + //lets add this to our valid resulr list + $results[] = $event; + } + } + //if we have at least one valid result + if(!empty($results)) { + //lets make results into a string + $result = implode(',', $result); + //and add to query + $query['result_type'] = $result; + } + } + //if rpp is not empty and less than equal to 100 + if(!is_null($rpp) && $rpp <= 100) { + //lets put in in query + $query['rpp'] = $rpp; + } + //if show + if($show) { + $query['show_user'] = 1; + } + //if it is not empty + if(!is_null($until)) { + $until = date('Y-m-d', $until); + //add it to our query + $query['until'] = $until; + } + //if it is not empty and + if(!is_null($since)) { + //lets put it in query + $query['since_id'] = $since; + } + //if entities + if($entities) { + $query['include_entities'] = 1; + } + + return $this->_getResponse(self::URL_SEARCH, $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 index 73b180b..679849e 100644 --- a/library/eden/twitter/suggestions.php +++ b/library/eden/twitter/suggestions.php @@ -1,110 +1,110 @@ - -/* - * 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. - */ - -/** - * Eventbrite new or update discount - * - * @package Eden - * @category eventbrite - * @author Christian Blanquera - * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ - */ -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 - -------------------------------*/ - protected $_query = array(); - - /* Private Properties - -------------------------------*/ - /* Get - -------------------------------*/ - public static function get($key, $secret) { - return self::_getMultiple(__CLASS__, $key, $secret); - } - - /* Magic - -------------------------------*/ - /* Public Methods - -------------------------------*/ - /** - * Access to Twitter's suggested user list. - * - * @param lang is string - * @return $this - */ - public function getSuggestion($lang = NULL) { - //Argument Test - Eden_Twitter_Error::get() - ->argument(1, 'string', 'null'); //Argument 1 must be a string or integer - - $query = array(); - //if it is not empty - if(!is_null($lang)) { - //lets put it in our query - $query['lang'] = $lang; - } - - return $this->_getResponse(self::URL_SUGGESTION, $query); - } - /** - * Access the users in a given category of the - * Twitter suggested user list.. - * - * @param slug is string - * @param lang is integer - * @return $this - */ - public function getCategory($slug, $lang = NULL) { - //Argument Test - Eden_Twitter_Error::get() - ->argument(1, 'string', 'null') //Argument 1 must be a string - ->argument(2, 'string', 'null'); //Argument 1 must be a string - - $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 slug is string - * @return $this - */ - public function getRecentStatus($slug) { - //Argument Test - Eden_Twitter_Error::get() - ->argument(1, 'string', 'null'); //Argument 1 must be a string - - $query = array('slug' => $slug); - - return $this->_getResponse(self::URL_GET_RECENT_STATUS, $query); - } - - /* Protected Methods - -------------------------------*/ - /* Private Methods - -------------------------------*/ - - + +/* + * 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. + */ + +/** + * Eventbrite new or update discount + * + * @package Eden + * @category eventbrite + * @author Christian Blanquera + * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ + */ +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 + -------------------------------*/ + protected $_query = array(); + + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function i($key, $secret) { + return self::_getMultiple(__CLASS__, $key, $secret); + } + + /* Magic + -------------------------------*/ + /* Public Methods + -------------------------------*/ + /** + * Access to Twitter's suggested user list. + * + * @param lang is string + * @return $this + */ + public function getSuggestion($lang = NULL) { + //Argument Test + Eden_Twitter_Error::i() + ->argument(1, 'string', 'null'); //Argument 1 must be a string or integer + + $query = array(); + //if it is not empty + if(!is_null($lang)) { + //lets put it in our query + $query['lang'] = $lang; + } + + return $this->_getResponse(self::URL_SUGGESTION, $query); + } + /** + * Access the users in a given category of the + * Twitter suggested user list.. + * + * @param slug is string + * @param lang is integer + * @return $this + */ + public function getCategory($slug, $lang = NULL) { + //Argument Test + Eden_Twitter_Error::i() + ->argument(1, 'string', 'null') //Argument 1 must be a string + ->argument(2, 'string', 'null'); //Argument 1 must be a string + + $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 slug is string + * @return $this + */ + public function getRecentStatus($slug) { + //Argument Test + Eden_Twitter_Error::i() + ->argument(1, 'string', 'null'); //Argument 1 must be a string + + $query = array('slug' => $slug); + + return $this->_getResponse(self::URL_GET_RECENT_STATUS, $query); + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ + + } \ No newline at end of file diff --git a/library/eden/twitter/timelines.php b/library/eden/twitter/timelines.php index cb37cd3..700a134 100644 --- a/library/eden/twitter/timelines.php +++ b/library/eden/twitter/timelines.php @@ -1,615 +1,615 @@ - -/* - * 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. - */ - -/** - * Eventbrite new or update discount - * - * @package Eden - * @category eventbrite - * @author Christian Blanquera - * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ - */ -class Eden_Twitter_Timelines 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 $_query = array(); - - /* Private Properties - -------------------------------*/ - /* Get - -------------------------------*/ - public static function get($user, $api) { - return self::_getMultiple(__CLASS__, $user, $api); - } - /* Magic - -------------------------------*/ - /* Public Methods - -------------------------------*/ - /** - * 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. - * - * @param count is integer - * @param since is integer - * @param max is integer - * @param page is integer - * @param trim is boolean - * @param include is boolean - * @param entities is boolean - * @param replies is boolean - * @param detail is boolean - * @return $this - */ - public function getTimeline($count = NULL, $since = NULL, $max = NULL, $page = NULL, $trim = false, $include = false, $entities = false, $replies = false, $detail =false) { - //Argument Test - Eden_Twitter_Error::get() - ->argument(1, 'int', 'null') //Argument 1 must be an integer - ->argument(2, 'int', 'null') //Argument 2 must be an integer - ->argument(3, 'int', 'null') //Argument 3 must be an integer - ->argument(4, 'int', 'null') //Argument 4 must be an integer - ->argument(5, 'bool') //Argument 5 must be a boolean - ->argument(6, 'bool') //Argument 6 must be a boolean - ->argument(7, 'bool') //Argument 7 must be a boolean - ->argument(8, 'bool') //Argument 8 must be a boolean - ->argument(9, 'bool'); //Argument 9 must be a boolean - - $query = array(); - //if it is not empty and its less than equal to 100 - if(!is_null($count) && $count <= 200) { - //lets put it in query - $query['count'] = $count; - } - //if it is not empty - if(!is_null($since)) { - //lets put it in query - $query['since_id'] = $since; - } - //if it is not empty and max is not less than count - if(!is_null($max) && $$max <= $count) { - //lets put it in query - $query['$max_id'] = $$max; - } - //if it is not empty - if(!is_null($page)) { - //lets put it in query - $query['page'] = $page; - } - //if trim - if($trim) { - $query['trim_user'] = 1; - } - //if include - if($include) { - $query['include_rts'] = 1; - } - //if entities - if($entities) { - $query['include_entities'] = 1; - } - //if replies - if($replies) { - $query['exclude_replies'] = 1; - } - //if datails - if($detail) { - $query['contributor_details'] = 1; - } - - return $this->_getResponse(self::URL_TIMELINE, $query); - } - /** - * Returns the 20 most recent mentions (status containing @username) for the authenticating user - * - * @param count is integer - * @param since is integer - * @param max is integer - * @param page is integer - * @param trim is boolean - * @param include is boolean - * @param entities is boolean - * @param detail is boolean - * @return $this - */ - public function getMention($count = NULL, $since = NULL, $max = NULL, $page = NULL, $trim = false, $include = false, $entities = false, $detail =false) { - //Argument Test - Eden_Twitter_Error::get() - ->argument(1, 'int', 'null') //Argument 1 must be an integer - ->argument(2, 'int', 'null') //Argument 2 must be an integer - ->argument(3, 'int', 'null') //Argument 3 must be an integer - ->argument(4, 'int', 'null') //Argument 4 must be an integer - ->argument(5, 'bool') //Argument 5 must be an boolean - ->argument(6, 'bool') //Argument 6 must be a boolean - ->argument(7, 'bool') //Argument 7 must be a boolean - ->argument(8, 'bool'); //Argument 8 must be a boolean - - $query = array(); - - //if it is not empty and - if(!is_null($count) && $count <= 200) { - //lets put it in query - $query['count'] = $count; - } - //if it is not empty and - if(!is_null($since)) { - //lets put it in query - $query['since_id'] = $since; - } - //if it is not empty and $max is not less than count - if(!is_null($max) && $$max <= $count) { - //lets put it in query - $query['$max_id'] = $$max; - } - //if it is not empty and - if(!is_null($page)) { - //lets put it in query - $query['page'] = $page; - } - //if trim - if($trim) { - $query['trim_user'] = 1; - } - //if include - if($include) { - $query['include_rts'] = 1; - } - //if entities - if($entities) { - $query['include_entities'] = 1; - } - //if datails - if($detail) { - $query['contributor_details'] = 1; - } - - return $this->_getResponse(self::URL_MENTION, $query); - } - /** - * Returns the 20 most recent statuses, including - * retweets if they exist, from non-protected users. - * - * @param trim is boolean - * @param entities is boolean - * @return $this - */ - public function getPublic($trim = false, $entities = false) { - //Argument Test - Eden_Twitter_Error::get() - ->argument(1, 'bool') //Argument 1 must be a boolean - ->argument(2, 'bool'); //Argument 2 must be a boolean - - $query = array(); - //if trim - if($trim) { - $query['trim_user'] = 1; - } - //if entities - if($entities) { - $query['include_entities'] = 1; - } - - return $this->_getResponse(self::URL_PUBLIC, $query); - } - /** - * Returns the 20 most recent retweets posted by the authenticating user. - * - * @param count is integer - * @param since is integer - * @param $max is integer - * @param page is integer - * @param trim is boolean - * @param entities is boolean - * @return $this - */ - public function getBy($count = NULL, $since = NULL, $max = NULL, $page = NULL, $trim = false, $entities = false) { - //Argument Test - Eden_Twitter_Error::get() - ->argument(1, 'int', 'null') //Argument 1 must be an integer - ->argument(2, 'int', 'null') //Argument 2 must be an integer - ->argument(3, 'int', 'null') //Argument 3 must be an integer - ->argument(4, 'int', 'null') //Argument 4 must be an integer - ->argument(5, 'bool') //Argument 5 must be an boolean - ->argument(6, 'bool'); //Argument 6 must be an boolean - - $query = array(); - - //if it is not empty and - if(!is_null($count) && $count <= 200) { - //lets put it in query - $query['count'] = $count; - } - //if it is not empty and - if(!is_null($since)) { - //lets put it in query - $query['since_id'] = $since; - } - //if it is not empty and $max is not less than count - if(!is_null($max) && $$max <= $count) { - //lets put it in query - $query['$max_id'] = $$max; - } - //if it is not empty and - if(!is_null($page)) { - //lets put it in query - $query['page'] = $page; - } - //if trim - if($trim) { - $query['trim_user'] = 1; - } - //if entities - if($entities) { - $query['include_entities'] = 1; - } - - return $this->_getResponse(self::URL_BY_ME, $query); - } - /** - * Returns the 20 most recent retweets posted by users the authenticating user follow - * - * @param count is integer - * @param since is integer - * @param $max is integer - * @param page is integer - * @param trim is boolean - * @param entities is boolean - * @return $this - */ - public function getTo($count = NULL, $since = NULL, $max = NULL, $page = NULL, $trim = false, $entities = false) { - //Argument Test - Eden_Twitter_Error::get() - ->argument(1, 'int', 'null') //Argument 1 must be an integer - ->argument(2, 'int', 'null') //Argument 2 must be an integer - ->argument(3, 'int', 'null') //Argument 3 must be an integer - ->argument(4, 'int', 'null') //Argument 4 must be an integer - ->argument(5, 'bool') //Argument 5 must be a boolean - ->argument(6, 'bool'); //Argument 6 must be a boolean - - $query = array(); - - //if it is not empty and - if(!is_null($count) && $count <= 200) { - //lets put it in query - $query['count'] = $count; - } - //if it is not empty and - if(!is_null($since)) { - //lets put it in query - $query['since_id'] = $since; - } - //if it is not empty and $max is not less than count - if(!is_null($max) && $$max <= $count) { - //lets put it in query - $query['$max_id'] = $$max; - } - //if it is not empty and - if(!is_null($page)) { - //lets put it in query - $query['page'] = $page; - } - //if trim - if($trim) { - $query['trim_user'] = 1; - } - //if entities - if($entities) { - $query['include_entities'] = 1; - } - - return $this->_getResponse(self::URL_TO_ME, $query); - } - /** - * Returns the 20 most recent tweets of the authenticated user that have been retweeted by others. - * - * @param count is integer - * @param since is integer - * @param $max is integer - * @param page is integer - * @param trim is boolean - * @param entities is boolean - * @return $this - */ - public function getOf($count = NULL, $since = NULL, $max = NULL, $page = NULL, $trim = false, $entities = false) { - //Argument Test - Eden_Twitter_Error::get() - ->argument(1, 'int', 'null') //Argument 1 must be an integer - ->argument(2, 'int', 'null') //Argument 2 must be an integer - ->argument(3, 'int', 'null') //Argument 3 must be an integer - ->argument(4, 'int', 'null') //Argument 4 must be an integer - ->argument(5, 'bool') //Argument 5 must be a boolean - ->argument(6, 'bool'); //Argument 6 must be a boolean - - $query = array(); - - //if it is not empty and - if(!is_null($count) && $count <= 200) { - //lets put it in query - $query['count'] = $count; - } - //if it is not empty - if(!is_null($since)) { - //lets put it in query - $query['since_id'] = $since; - } - //if it is not empty and $max is not less than count - if(!is_null($max) && $$max <= $count) { - //lets put it in query - $query['$max_id'] = $$max; - } - //if it is not empty and - if(!is_null($page)) { - //lets put it in query - $query['page'] = $page; - } - //if trim - if($trim) { - $query['trim_user'] = 1; - } - //if entities - if($entities) { - $query['include_entities'] = 1; - } - - return $this->_getResponse(self::URL_OF_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 id is a integer - * @param name is a string - * @param since is integer - * @param count is integer - * @param $max is integer - * @param page is integer - * @param trim is boolean - * @param include is boolean - * @param entities is boolean - * @param replies is boolean - * @param detail is boolean - * @return $this - */ - public function getList($id = NULL, $since = NULL, $count = NULL, $max = NULL, $page = NULL, $trim = false, $include = false, $entities = false, $replies = false, $detail =false) { - //Argument Test - Eden_Twitter_Error::get() - ->argument(1, 'int','string', 'null') //Argument 1 must be an integer - ->argument(2, 'int', 'null') //Argument 2 must be an integer - ->argument(3, 'int', 'null') //Argument 3 must be an integer - ->argument(4, 'int', 'null') //Argument 4 must be a boolean - ->argument(5, 'int', 'null') //Argument 5 must be a boolean - ->argument(6, 'bool') //Argument 6 must be a boolean - ->argument(7, 'bool') //Argument 7 must be a boolean - ->argument(8, 'bool') //Argument 8 must be a boolean - ->argument(9, 'bool') //Argument 9 must be a boolean - ->argument(10, 'bool'); //Argument 10 must be a boolean - - $query = array(); - //If it is not empty - if(!is_null($id)) { - - if(is_int($id)) { - //Lets put it in query - $query['user_id'] = $id; - } - - if(is_string($id)) { - //Lets put it in query - $query['screen_name'] = $id; - } - } - //if it is not empty - if(!is_null($since)) { - //lets put it in query - $query['since_id'] = $since; - //if it is not empty and - if(!is_null($count) && $count <= 200) { - //lets put it in query - $query['count'] = $count; - } - } - //if it is not empty and $max is not less than count - if(!is_null($max) && $$max <= $count) { - //lets put it in query - $query['$max_id'] = $$max; - } - //if it is not empty and - if(!is_null($page)) { - //lets put it in query - $query['page'] = $page; - } - //if trim - if($trim) { - $query['trim_user'] = 1; - } - //if include - if($include) { - $query['include_rts'] = 1; - } - //if entities - if($entities) { - $query['include_entities'] = 1; - } - //if replies - if($replies) { - $query['exclude_replies'] = 1; - } - //if datails - if($detail) { - $query['contributor_details'] = 1; - } - - return $this->_getResponse(self::URL_USER, $query); - } - /** - * Returns the 20 most recent retweets posted - * by users the specified user follows. - * - * @param name is a string - * @param id is a integer or string - * @param since is integer - * @param count is integer - * @param $max is integer - * @param page is integer - * @param trim is boolean - * @param include is boolean - * @param entities is boolean - * @param replies is boolean - * @param detail is boolean - * @return $this - */ - public function getToUser($name = NULL, $id = NULL, $since = NULL, $count = NULL, $max = NULL, $page = NULL, $trim = false, $entities = false) { - //Argument Test - Eden_Twitter_Error::get() - ->argument(1, 'string', 'null') //Argument 1 must be a string - ->argument(2, 'string', 'int', 'null') //Argument 2 must be a string or integer - ->argument(3, 'int', 'null') //Argument 3 must be an integer - ->argument(4, 'int', 'null') //Argument 4 must be an integer - ->argument(5, 'int', 'null') //Argument 5 must be a boolean - ->argument(6, 'int', 'null') //Argument 6 must be a boolean - ->argument(7, 'bool') //Argument 7 must be a boolean - ->argument(8, 'bool') //Argument 8 must be a boolean - ->argument(9, 'bool') //Argument 9 must be a boolean - ->argument(10, 'bool') //Argument 10 must be a boolean - ->argument(11, 'bool'); //Argument 11 must be a boolean - - $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; - } - //if it is not empty - if(!is_null($since)) { - //lets put it in query - $query['since_id'] = $since; - } - //if it is not empty and - if(!is_null($count) && $count <= 200) { - //lets put it in query - $query['count'] = $count; - } - //if it is not empty and $max is not less than count - if(!is_null($max) && $$max <= $count) { - //lets put it in query - $query['$max_id'] = $$max; - } - //if it is not empty and - if(!is_null($page)) { - //lets put it in query - $query['page'] = $page; - } - //if trim - if($trim) { - $query['trim_user'] = 1; - } - //if entities - if($entities) { - $query['include_entities'] = 1; - } - return $this->_getResponse(self::URL_TO_USER, $query); - } - /** - * Returns the 20 most recent retweets posted by - * the specified user. The user is specified using - * the user_id or screen_name parameters - * - * @param name is a string - * @param id is a integer or string - * @param since is integer - * @param count is integer - * @param $max is integer - * @param page is integer - * @param trim is boolean - * @param include is boolean - * @param entities is boolean - * @param replies is boolean - * @param detail is boolean - * @return $this - */ - public function getByUser($name = NULL, $id = NULL, $since = NULL, $count = NULL, $max = NULL, $page = NULL, $trim = false, $entities = false) { - //Argument Test - Eden_Twitter_Error::get() - ->argument(1, 'string', 'null') //Argument 1 must be a string - ->argument(2, 'string', 'int', 'null') //Argument 2 must be a string or integer - ->argument(3, 'int', 'null') //Argument 3 must be a integer - ->argument(4, 'int', 'null') //Argument 4 must be a integer - ->argument(5, 'int', 'null') //Argument 5 must be a boolean - ->argument(6, 'int', 'null') //Argument 6 must be a boolean - ->argument(7, 'bool') //Argument 7 must be a boolean - ->argument(8, 'bool'); //Argument 8 must be a boolean - - $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; - } - //if it is not empty - if(!is_null($since)) { - //lets put it in query - $query['since_id'] = $since; - } - //if it is not empty and - if(!is_null($count) && $count <= 200) { - //lets put it in query - $query['count'] = $count; - } - //if it is not empty and $max is not less than count - if(!is_null($max) && $$max <= $count) { - //lets put it in query - $query['$max_id'] = $$max; - } - //if it is not empty and - if(!is_null($page)) { - //lets put it in query - $query['page'] = $page; - } - //if trim - if($trim) { - $query['trim_user'] = 1; - } - //if entities - if($entities) { - $query['include_entities'] = 1; - } - return $this->_getResponse(self::URL_BY_USER, $query); - } - /* Protected Methods - -------------------------------*/ - /* Private Methods - -------------------------------*/ - - + +/* + * 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. + */ + +/** + * Eventbrite new or update discount + * + * @package Eden + * @category eventbrite + * @author Christian Blanquera + * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ + */ +class Eden_Twitter_Timelines 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 $_query = array(); + + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function i($user, $api) { + return self::_getMultiple(__CLASS__, $user, $api); + } + /* Magic + -------------------------------*/ + /* Public Methods + -------------------------------*/ + /** + * 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. + * + * @param count is integer + * @param since is integer + * @param max is integer + * @param page is integer + * @param trim is boolean + * @param include is boolean + * @param entities is boolean + * @param replies is boolean + * @param detail is boolean + * @return $this + */ + public function getTimeline($count = NULL, $since = NULL, $max = NULL, $page = NULL, $trim = false, $include = false, $entities = false, $replies = false, $detail =false) { + //Argument Test + Eden_Twitter_Error::i() + ->argument(1, 'int', 'null') //Argument 1 must be an integer + ->argument(2, 'int', 'null') //Argument 2 must be an integer + ->argument(3, 'int', 'null') //Argument 3 must be an integer + ->argument(4, 'int', 'null') //Argument 4 must be an integer + ->argument(5, 'bool') //Argument 5 must be a boolean + ->argument(6, 'bool') //Argument 6 must be a boolean + ->argument(7, 'bool') //Argument 7 must be a boolean + ->argument(8, 'bool') //Argument 8 must be a boolean + ->argument(9, 'bool'); //Argument 9 must be a boolean + + $query = array(); + //if it is not empty and its less than equal to 100 + if(!is_null($count) && $count <= 200) { + //lets put it in query + $query['count'] = $count; + } + //if it is not empty + if(!is_null($since)) { + //lets put it in query + $query['since_id'] = $since; + } + //if it is not empty and max is not less than count + if(!is_null($max) && $$max <= $count) { + //lets put it in query + $query['$max_id'] = $$max; + } + //if it is not empty + if(!is_null($page)) { + //lets put it in query + $query['page'] = $page; + } + //if trim + if($trim) { + $query['trim_user'] = 1; + } + //if include + if($include) { + $query['include_rts'] = 1; + } + //if entities + if($entities) { + $query['include_entities'] = 1; + } + //if replies + if($replies) { + $query['exclude_replies'] = 1; + } + //if datails + if($detail) { + $query['contributor_details'] = 1; + } + + return $this->_getResponse(self::URL_TIMELINE, $query); + } + /** + * Returns the 20 most recent mentions (status containing @username) for the authenticating user + * + * @param count is integer + * @param since is integer + * @param max is integer + * @param page is integer + * @param trim is boolean + * @param include is boolean + * @param entities is boolean + * @param detail is boolean + * @return $this + */ + public function getMention($count = NULL, $since = NULL, $max = NULL, $page = NULL, $trim = false, $include = false, $entities = false, $detail =false) { + //Argument Test + Eden_Twitter_Error::i() + ->argument(1, 'int', 'null') //Argument 1 must be an integer + ->argument(2, 'int', 'null') //Argument 2 must be an integer + ->argument(3, 'int', 'null') //Argument 3 must be an integer + ->argument(4, 'int', 'null') //Argument 4 must be an integer + ->argument(5, 'bool') //Argument 5 must be an boolean + ->argument(6, 'bool') //Argument 6 must be a boolean + ->argument(7, 'bool') //Argument 7 must be a boolean + ->argument(8, 'bool'); //Argument 8 must be a boolean + + $query = array(); + + //if it is not empty and + if(!is_null($count) && $count <= 200) { + //lets put it in query + $query['count'] = $count; + } + //if it is not empty and + if(!is_null($since)) { + //lets put it in query + $query['since_id'] = $since; + } + //if it is not empty and $max is not less than count + if(!is_null($max) && $$max <= $count) { + //lets put it in query + $query['$max_id'] = $$max; + } + //if it is not empty and + if(!is_null($page)) { + //lets put it in query + $query['page'] = $page; + } + //if trim + if($trim) { + $query['trim_user'] = 1; + } + //if include + if($include) { + $query['include_rts'] = 1; + } + //if entities + if($entities) { + $query['include_entities'] = 1; + } + //if datails + if($detail) { + $query['contributor_details'] = 1; + } + + return $this->_getResponse(self::URL_MENTION, $query); + } + /** + * Returns the 20 most recent statuses, including + * retweets if they exist, from non-protected users. + * + * @param trim is boolean + * @param entities is boolean + * @return $this + */ + public function getPublic($trim = false, $entities = false) { + //Argument Test + Eden_Twitter_Error::i() + ->argument(1, 'bool') //Argument 1 must be a boolean + ->argument(2, 'bool'); //Argument 2 must be a boolean + + $query = array(); + //if trim + if($trim) { + $query['trim_user'] = 1; + } + //if entities + if($entities) { + $query['include_entities'] = 1; + } + + return $this->_getResponse(self::URL_PUBLIC, $query); + } + /** + * Returns the 20 most recent retweets posted by the authenticating user. + * + * @param count is integer + * @param since is integer + * @param $max is integer + * @param page is integer + * @param trim is boolean + * @param entities is boolean + * @return $this + */ + public function getBy($count = NULL, $since = NULL, $max = NULL, $page = NULL, $trim = false, $entities = false) { + //Argument Test + Eden_Twitter_Error::i() + ->argument(1, 'int', 'null') //Argument 1 must be an integer + ->argument(2, 'int', 'null') //Argument 2 must be an integer + ->argument(3, 'int', 'null') //Argument 3 must be an integer + ->argument(4, 'int', 'null') //Argument 4 must be an integer + ->argument(5, 'bool') //Argument 5 must be an boolean + ->argument(6, 'bool'); //Argument 6 must be an boolean + + $query = array(); + + //if it is not empty and + if(!is_null($count) && $count <= 200) { + //lets put it in query + $query['count'] = $count; + } + //if it is not empty and + if(!is_null($since)) { + //lets put it in query + $query['since_id'] = $since; + } + //if it is not empty and $max is not less than count + if(!is_null($max) && $$max <= $count) { + //lets put it in query + $query['$max_id'] = $$max; + } + //if it is not empty and + if(!is_null($page)) { + //lets put it in query + $query['page'] = $page; + } + //if trim + if($trim) { + $query['trim_user'] = 1; + } + //if entities + if($entities) { + $query['include_entities'] = 1; + } + + return $this->_getResponse(self::URL_BY_ME, $query); + } + /** + * Returns the 20 most recent retweets posted by users the authenticating user follow + * + * @param count is integer + * @param since is integer + * @param $max is integer + * @param page is integer + * @param trim is boolean + * @param entities is boolean + * @return $this + */ + public function getTo($count = NULL, $since = NULL, $max = NULL, $page = NULL, $trim = false, $entities = false) { + //Argument Test + Eden_Twitter_Error::i() + ->argument(1, 'int', 'null') //Argument 1 must be an integer + ->argument(2, 'int', 'null') //Argument 2 must be an integer + ->argument(3, 'int', 'null') //Argument 3 must be an integer + ->argument(4, 'int', 'null') //Argument 4 must be an integer + ->argument(5, 'bool') //Argument 5 must be a boolean + ->argument(6, 'bool'); //Argument 6 must be a boolean + + $query = array(); + + //if it is not empty and + if(!is_null($count) && $count <= 200) { + //lets put it in query + $query['count'] = $count; + } + //if it is not empty and + if(!is_null($since)) { + //lets put it in query + $query['since_id'] = $since; + } + //if it is not empty and $max is not less than count + if(!is_null($max) && $$max <= $count) { + //lets put it in query + $query['$max_id'] = $$max; + } + //if it is not empty and + if(!is_null($page)) { + //lets put it in query + $query['page'] = $page; + } + //if trim + if($trim) { + $query['trim_user'] = 1; + } + //if entities + if($entities) { + $query['include_entities'] = 1; + } + + return $this->_getResponse(self::URL_TO_ME, $query); + } + /** + * Returns the 20 most recent tweets of the authenticated user that have been retweeted by others. + * + * @param count is integer + * @param since is integer + * @param $max is integer + * @param page is integer + * @param trim is boolean + * @param entities is boolean + * @return $this + */ + public function getOf($count = NULL, $since = NULL, $max = NULL, $page = NULL, $trim = false, $entities = false) { + //Argument Test + Eden_Twitter_Error::i() + ->argument(1, 'int', 'null') //Argument 1 must be an integer + ->argument(2, 'int', 'null') //Argument 2 must be an integer + ->argument(3, 'int', 'null') //Argument 3 must be an integer + ->argument(4, 'int', 'null') //Argument 4 must be an integer + ->argument(5, 'bool') //Argument 5 must be a boolean + ->argument(6, 'bool'); //Argument 6 must be a boolean + + $query = array(); + + //if it is not empty and + if(!is_null($count) && $count <= 200) { + //lets put it in query + $query['count'] = $count; + } + //if it is not empty + if(!is_null($since)) { + //lets put it in query + $query['since_id'] = $since; + } + //if it is not empty and $max is not less than count + if(!is_null($max) && $$max <= $count) { + //lets put it in query + $query['$max_id'] = $$max; + } + //if it is not empty and + if(!is_null($page)) { + //lets put it in query + $query['page'] = $page; + } + //if trim + if($trim) { + $query['trim_user'] = 1; + } + //if entities + if($entities) { + $query['include_entities'] = 1; + } + + return $this->_getResponse(self::URL_OF_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 id is a integer + * @param name is a string + * @param since is integer + * @param count is integer + * @param $max is integer + * @param page is integer + * @param trim is boolean + * @param include is boolean + * @param entities is boolean + * @param replies is boolean + * @param detail is boolean + * @return $this + */ + public function getList($id = NULL, $since = NULL, $count = NULL, $max = NULL, $page = NULL, $trim = false, $include = false, $entities = false, $replies = false, $detail =false) { + //Argument Test + Eden_Twitter_Error::i() + ->argument(1, 'int','string', 'null') //Argument 1 must be an integer + ->argument(2, 'int', 'null') //Argument 2 must be an integer + ->argument(3, 'int', 'null') //Argument 3 must be an integer + ->argument(4, 'int', 'null') //Argument 4 must be a boolean + ->argument(5, 'int', 'null') //Argument 5 must be a boolean + ->argument(6, 'bool') //Argument 6 must be a boolean + ->argument(7, 'bool') //Argument 7 must be a boolean + ->argument(8, 'bool') //Argument 8 must be a boolean + ->argument(9, 'bool') //Argument 9 must be a boolean + ->argument(10, 'bool'); //Argument 10 must be a boolean + + $query = array(); + //If it is not empty + if(!is_null($id)) { + + if(is_int($id)) { + //Lets put it in query + $query['user_id'] = $id; + } + + if(is_string($id)) { + //Lets put it in query + $query['screen_name'] = $id; + } + } + //if it is not empty + if(!is_null($since)) { + //lets put it in query + $query['since_id'] = $since; + //if it is not empty and + if(!is_null($count) && $count <= 200) { + //lets put it in query + $query['count'] = $count; + } + } + //if it is not empty and $max is not less than count + if(!is_null($max) && $$max <= $count) { + //lets put it in query + $query['$max_id'] = $$max; + } + //if it is not empty and + if(!is_null($page)) { + //lets put it in query + $query['page'] = $page; + } + //if trim + if($trim) { + $query['trim_user'] = 1; + } + //if include + if($include) { + $query['include_rts'] = 1; + } + //if entities + if($entities) { + $query['include_entities'] = 1; + } + //if replies + if($replies) { + $query['exclude_replies'] = 1; + } + //if datails + if($detail) { + $query['contributor_details'] = 1; + } + + return $this->_getResponse(self::URL_USER, $query); + } + /** + * Returns the 20 most recent retweets posted + * by users the specified user follows. + * + * @param name is a string + * @param id is a integer or string + * @param since is integer + * @param count is integer + * @param $max is integer + * @param page is integer + * @param trim is boolean + * @param include is boolean + * @param entities is boolean + * @param replies is boolean + * @param detail is boolean + * @return $this + */ + public function getToUser($name = NULL, $id = NULL, $since = NULL, $count = NULL, $max = NULL, $page = NULL, $trim = false, $entities = false) { + //Argument Test + Eden_Twitter_Error::i() + ->argument(1, 'string', 'null') //Argument 1 must be a string + ->argument(2, 'string', 'int', 'null') //Argument 2 must be a string or integer + ->argument(3, 'int', 'null') //Argument 3 must be an integer + ->argument(4, 'int', 'null') //Argument 4 must be an integer + ->argument(5, 'int', 'null') //Argument 5 must be a boolean + ->argument(6, 'int', 'null') //Argument 6 must be a boolean + ->argument(7, 'bool') //Argument 7 must be a boolean + ->argument(8, 'bool') //Argument 8 must be a boolean + ->argument(9, 'bool') //Argument 9 must be a boolean + ->argument(10, 'bool') //Argument 10 must be a boolean + ->argument(11, 'bool'); //Argument 11 must be a boolean + + $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; + } + //if it is not empty + if(!is_null($since)) { + //lets put it in query + $query['since_id'] = $since; + } + //if it is not empty and + if(!is_null($count) && $count <= 200) { + //lets put it in query + $query['count'] = $count; + } + //if it is not empty and $max is not less than count + if(!is_null($max) && $$max <= $count) { + //lets put it in query + $query['$max_id'] = $$max; + } + //if it is not empty and + if(!is_null($page)) { + //lets put it in query + $query['page'] = $page; + } + //if trim + if($trim) { + $query['trim_user'] = 1; + } + //if entities + if($entities) { + $query['include_entities'] = 1; + } + return $this->_getResponse(self::URL_TO_USER, $query); + } + /** + * Returns the 20 most recent retweets posted by + * the specified user. The user is specified using + * the user_id or screen_name parameters + * + * @param name is a string + * @param id is a integer or string + * @param since is integer + * @param count is integer + * @param $max is integer + * @param page is integer + * @param trim is boolean + * @param include is boolean + * @param entities is boolean + * @param replies is boolean + * @param detail is boolean + * @return $this + */ + public function getByUser($name = NULL, $id = NULL, $since = NULL, $count = NULL, $max = NULL, $page = NULL, $trim = false, $entities = false) { + //Argument Test + Eden_Twitter_Error::i() + ->argument(1, 'string', 'null') //Argument 1 must be a string + ->argument(2, 'string', 'int', 'null') //Argument 2 must be a string or integer + ->argument(3, 'int', 'null') //Argument 3 must be a integer + ->argument(4, 'int', 'null') //Argument 4 must be a integer + ->argument(5, 'int', 'null') //Argument 5 must be a boolean + ->argument(6, 'int', 'null') //Argument 6 must be a boolean + ->argument(7, 'bool') //Argument 7 must be a boolean + ->argument(8, 'bool'); //Argument 8 must be a boolean + + $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; + } + //if it is not empty + if(!is_null($since)) { + //lets put it in query + $query['since_id'] = $since; + } + //if it is not empty and + if(!is_null($count) && $count <= 200) { + //lets put it in query + $query['count'] = $count; + } + //if it is not empty and $max is not less than count + if(!is_null($max) && $$max <= $count) { + //lets put it in query + $query['$max_id'] = $$max; + } + //if it is not empty and + if(!is_null($page)) { + //lets put it in query + $query['page'] = $page; + } + //if trim + if($trim) { + $query['trim_user'] = 1; + } + //if entities + if($entities) { + $query['include_entities'] = 1; + } + return $this->_getResponse(self::URL_BY_USER, $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 index 9b14a06..b220635 100644 --- a/library/eden/twitter/tweets.php +++ b/library/eden/twitter/tweets.php @@ -1,369 +1,369 @@ - -/* - * 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. - */ - -/** - * Eventbrite new or update discount - * - * @package Eden - * @category eventbrite - * @author Christian Blanquera - * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ - */ -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 $_query = array(); - - /* Private Properties - -------------------------------*/ - /* Get - -------------------------------*/ - public static function get($key, $secret) { - return self::_getMultiple(__CLASS__, $key, $secret); - } - - /* Magic - -------------------------------*/ - /* Public Methods - -------------------------------*/ - /** - * Show user objects of up to 100 members - * who retweeted the status. - * - * @param id is integer. - * @param count is integer. - * @param page is integer - * @return $this - */ - public function getWhoRetweeted($id, $count = NULL, $page = NULL) { - //Argument Test - Eden_Twitter_Error::get() - ->argument(1, 'int') //Argument 1 must be an integer - ->argument(2, 'int') //Argument 2 must be an integer - ->argument(3, 'int'); //Argument 3 must be an integer - - $query = array(); - //if it is not empty and not up to a maximum of 100 - if(!is_null($count) && $count <= 100) { - //lets put it in query - $query['count'] = $count; - } - //if it is not empty - if(!is_null($page)) { - //lets put it in query - $query['page'] = $count; - } - $url = sprintf(self::URL_WHO_RETWEETED, $id); - return $this->_post($url, $query); - } - /** - * Show user ids of up to 100 users who retweeted the status. - * - * @param id is integer. - * @param count is integer. - * @param page is integer - * @param stringify is boolean - * @return $this - */ - public function getWhoRetweetedIds($id, $count = NULL, $page = NULL, $stringify = false) { - //Argument Test - Eden_Twitter_Error::get() - ->argument(1, 'int') //Argument 1 must be an integer - ->argument(2, 'int') //Argument 2 must be an integer - ->argument(3, 'int') //Argument 3 must be an integer - ->argument(4, 'bool'); //Argument 4 must be a boolean - - $query = array(); - //if it is not empty and not up to a maximum of 100 - if(!is_null($count) && $count <= 100) { - //lets put it in query - $query['count'] = $count; - } - //if it is not empty - if(!is_null($page)) { - //lets put it in query - $query['page'] = $count; - } - //if stringify - if($stringify) { - - $query['stringify_ids'] = 1; - } - - $url = sprintf(self::URL_GET_WHO_RETWEETED_IDS, $id); - return $this->_post($url, $query); - } - /** - * Returns up to 100 of the first retweets of a given tweet. - * - * @param id is integer - * @param count is integer - * @param trim is boolean - * @param entities is boolean - * @return $this - */ - public function getRetweets($id, $count = NULL, $trim = false, $entities = false) { - //Argument Test - Eden_Twitter_Error::get() - ->argument(1, 'int') //Argument 1 must be an integer - ->argument(2, 'int') //Argument 2 must be an integer - ->argument(3, 'bool') //Argument 3 must be an boolean - ->argument(4, 'bool'); //Argument 4 must be an boolean - - $query = array('id' => $id); - //if count is not empty and less than equal to 100 - if(!is_null($count) && $count <= 100) { - //Lets put it in query - $query['count'] = $count; - } - //if trim - if($trim) { - $query['trim_user'] = 1; - } - //if entities - if($entities) { - $query['include_entities'] = 1; - } - $url = sprintf(self::URL_GET_RETWEETS, $id); - return $this->_post($url, $query); - } - /** - * Returns a single status, specified by the id parameter below. - * The status's author will be returned inline. - * - * @param id is integer - * @param trim is boolean - * @param entities is boolean - * @return $this - */ - public function getDetail($id, $trim = false, $entities = false) { - //Argument Test - Eden_Twitter_Error::get() - ->argument(1, 'int') //Argument 1 must be an integer - ->argument(2, 'bool') //Argument 2 must be an boolean - ->argument(3, 'bool'); //Argument 3 must be an boolean - - $query = array('id' => $id); - //if trim - if($trim) { - $query['trim_user'] = 1; - } - //if entities - if($entities) { - $query['include_entities'] = 1; - } - - return $this->_getResponse(self::URL_GET_LIST, $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 id is integer - * @param trim is boolean - * @param entities is boolean - * @return $this - */ - public function remove($id, $entities = false, $trim = false) { - //Argument Test - Eden_Twitter_Error::get() - ->argument(1, 'int') //Argument 1 must be an integer - ->argument(2, 'bool') //Argument 2 must be an boolean - ->argument(3, 'bool'); //Argument 3 must be an boolean - - $query = array(); - //if entities - if($entities) { - $query['include_entities'] = 1; - } - //if trim - if($trim) { - $query['trim_user'] = 1; - } - - $url = sprintf(self::URL_REMOVE, $id); - return $this->_post($url,$query); - } - /** - * Retweets a tweet. Returns the original tweet - * with retweet details embedded - * - * @param id is integer - * @param trim is boolean - * @param entities is boolean - * @return $this - */ - public function retweet($id, $entities = false, $trim = false) { - //Argument Test - Eden_Twitter_Error::get() - ->argument(1, 'int') //Argument 1 must be an integer - ->argument(2, 'bool') //Argument 2 must be an boolean - ->argument(3, 'bool'); //Argument 3 must be an boolean - - $query = array(); - //if entities - if($entities) { - $query['include_entities'] = 1; - } - //if trim - if($trim) { - $query['trim_user'] = 1; - } - $url = sprintf(self::URL_RETWEET, $id); - return $this->_post($url, $query); - } - /** - * Updates the authenticating user's status, - * also known as tweeting. - * - * @param status is integer - * @param reply is string - * @param lat is float - * @param long is float - * @param place is string or integer - * @param display is boolean - * @param trim is boolean - * @param entities is boolean - * @param wrap is boolean - * @return $this - */ - public function update($status, $reply = NULL, $lat = NULL, $long = NULL, $place = NULL, $display = NULL, $trim = FALSE, $entities = FALSE, $wrap = FALSE) { - //Argument Test - Eden_Twitter_Error::get() - ->argument(1, 'string') //Argument 1 must be a string - ->argument(2, 'string') //Argument 2 must be a string - ->argument(3, 'float') //Argument 3 must be a float - ->argument(4, 'float') //Argument 4 must be a float - ->argument(5, 'string', 'int') //Argument 5 must be an string or integer - ->argument(6, 'boolean') //Argument 6 must be an boolean - ->argument(7, 'boolean') //Argument 7 must be an boolean - ->argument(8, 'boolean'); //Argument 8 must be an boolean - - - $query = array('status' => $status); - //if reply is not empty - if(!is_null($reply)) { - //lets put it in query - $query['in_reply_to_status_id '] = $reply; - } - //if reply is not empty - if(!is_null($lat) && $lat >= -90.0 && $lat <= +90.0) { - //lets put it in query - $query ['lat'] = $lat; - } - //if reply is not empty - if(!is_null($long) && $long >= -180.0 && $lat <= +180.0) { - //lets put it in query - $query ['long'] = $long; - } - //if reply is not empty - if(!is_null($place)) { - //lets put it in query - $query['place_id '] = $place; - } - //if entities - if($display) { - $query['display_coordinates'] = 1; - } - //if trim - if($trim) { - $query['trim_user'] = 1; - } - //if entities - if($entities) { - $query['include_entities'] = 1; - } - //if wrap - if($wrap) { - $query['wrap_links'] = 1; - } - - return $this->_post(self::URL_UPDATE, $query); - } - /** - * Updates the authenticating user's status, - * also known as tweeting. - * - * @param status is integer - * @param reply is string - * @param lat is float - * @param long is float - * @param place is string or integer - * @param display is boolean - * @param trim is boolean - * @param entities is boolean - * @param wrap is boolean - * @return $this - */ - public function updateMedia($status, $media, $sensitive = NULL, $id = NULL, $lat = NULL, $long = NULL, $place = NULL, $display = NULL) { - //Argument Test - Eden_Twitter_Error::get() - ->argument(1, 'string') //Argument 1 must be a string - ->argument(2, 'string') //Argument 2 must be a string - ->argument(3, 'boolean') //Argument 3 must be a boolean - ->argument(4, 'string') //Argument 4 must be an string - ->argument(5, 'boolean') //Argument 5 must be an boolena - ->argument(6, 'boolean') //Argument 6 must be an boolean - ->argument(7, 'boolean') //Argument 7 must be an boolean - ->argument(8, 'boolean'); //Argument 8 must be an boolean - - - $query = array('status' => $status, 'media[]' => $media); - //if sensitive - if($sensitive) { - $query['possibly_sensitive'] = 1; - } - //if reply is not empty - if(!is_null($id)) { - //lets put it in query - $query['in_reply_to_status_id'] = $id; - } - //if reply is not empty - if(!is_null($lat) && $lat >= -90.0 && $lat <= +90.0) { - //lets put it in query - $query ['lat'] = $lat; - } - //if reply is not empty - if(!is_null($long) && $long >= -180.0 && $lat <= +180.0) { - //lets put it in query - $query ['long'] = $long; - } - //if reply is not empty - if(!is_null($place)) { - //lets put it in query - $query['place_id '] = $place; - } - //if entities - if($display) { - $query['display_coordinates'] = 1; - } - - return $this->_getResponse(self::URL_UPDATE_MEDIA, $query); - } - /* Protected Methods - -------------------------------*/ - /* Private Methods - -------------------------------*/ - - + +/* + * 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. + */ + +/** + * Eventbrite new or update discount + * + * @package Eden + * @category eventbrite + * @author Christian Blanquera + * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ + */ +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 $_query = array(); + + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function i($key, $secret) { + return self::_getMultiple(__CLASS__, $key, $secret); + } + + /* Magic + -------------------------------*/ + /* Public Methods + -------------------------------*/ + /** + * Show user objects of up to 100 members + * who retweeted the status. + * + * @param id is integer. + * @param count is integer. + * @param page is integer + * @return $this + */ + public function getWhoRetweeted($id, $count = NULL, $page = NULL) { + //Argument Test + Eden_Twitter_Error::i() + ->argument(1, 'int') //Argument 1 must be an integer + ->argument(2, 'int') //Argument 2 must be an integer + ->argument(3, 'int'); //Argument 3 must be an integer + + $query = array(); + //if it is not empty and not up to a maximum of 100 + if(!is_null($count) && $count <= 100) { + //lets put it in query + $query['count'] = $count; + } + //if it is not empty + if(!is_null($page)) { + //lets put it in query + $query['page'] = $count; + } + $url = sprintf(self::URL_WHO_RETWEETED, $id); + return $this->_post($url, $query); + } + /** + * Show user ids of up to 100 users who retweeted the status. + * + * @param id is integer. + * @param count is integer. + * @param page is integer + * @param stringify is boolean + * @return $this + */ + public function getWhoRetweetedIds($id, $count = NULL, $page = NULL, $stringify = false) { + //Argument Test + Eden_Twitter_Error::i() + ->argument(1, 'int') //Argument 1 must be an integer + ->argument(2, 'int') //Argument 2 must be an integer + ->argument(3, 'int') //Argument 3 must be an integer + ->argument(4, 'bool'); //Argument 4 must be a boolean + + $query = array(); + //if it is not empty and not up to a maximum of 100 + if(!is_null($count) && $count <= 100) { + //lets put it in query + $query['count'] = $count; + } + //if it is not empty + if(!is_null($page)) { + //lets put it in query + $query['page'] = $count; + } + //if stringify + if($stringify) { + + $query['stringify_ids'] = 1; + } + + $url = sprintf(self::URL_GET_WHO_RETWEETED_IDS, $id); + return $this->_post($url, $query); + } + /** + * Returns up to 100 of the first retweets of a given tweet. + * + * @param id is integer + * @param count is integer + * @param trim is boolean + * @param entities is boolean + * @return $this + */ + public function getRetweets($id, $count = NULL, $trim = false, $entities = false) { + //Argument Test + Eden_Twitter_Error::i() + ->argument(1, 'int') //Argument 1 must be an integer + ->argument(2, 'int') //Argument 2 must be an integer + ->argument(3, 'bool') //Argument 3 must be an boolean + ->argument(4, 'bool'); //Argument 4 must be an boolean + + $query = array('id' => $id); + //if count is not empty and less than equal to 100 + if(!is_null($count) && $count <= 100) { + //Lets put it in query + $query['count'] = $count; + } + //if trim + if($trim) { + $query['trim_user'] = 1; + } + //if entities + if($entities) { + $query['include_entities'] = 1; + } + $url = sprintf(self::URL_GET_RETWEETS, $id); + return $this->_post($url, $query); + } + /** + * Returns a single status, specified by the id parameter below. + * The status's author will be returned inline. + * + * @param id is integer + * @param trim is boolean + * @param entities is boolean + * @return $this + */ + public function getDetail($id, $trim = false, $entities = false) { + //Argument Test + Eden_Twitter_Error::i() + ->argument(1, 'int') //Argument 1 must be an integer + ->argument(2, 'bool') //Argument 2 must be an boolean + ->argument(3, 'bool'); //Argument 3 must be an boolean + + $query = array('id' => $id); + //if trim + if($trim) { + $query['trim_user'] = 1; + } + //if entities + if($entities) { + $query['include_entities'] = 1; + } + + return $this->_getResponse(self::URL_GET_LIST, $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 id is integer + * @param trim is boolean + * @param entities is boolean + * @return $this + */ + public function remove($id, $entities = false, $trim = false) { + //Argument Test + Eden_Twitter_Error::i() + ->argument(1, 'int') //Argument 1 must be an integer + ->argument(2, 'bool') //Argument 2 must be an boolean + ->argument(3, 'bool'); //Argument 3 must be an boolean + + $query = array(); + //if entities + if($entities) { + $query['include_entities'] = 1; + } + //if trim + if($trim) { + $query['trim_user'] = 1; + } + + $url = sprintf(self::URL_REMOVE, $id); + return $this->_post($url,$query); + } + /** + * Retweets a tweet. Returns the original tweet + * with retweet details embedded + * + * @param id is integer + * @param trim is boolean + * @param entities is boolean + * @return $this + */ + public function retweet($id, $entities = false, $trim = false) { + //Argument Test + Eden_Twitter_Error::i() + ->argument(1, 'int') //Argument 1 must be an integer + ->argument(2, 'bool') //Argument 2 must be an boolean + ->argument(3, 'bool'); //Argument 3 must be an boolean + + $query = array(); + //if entities + if($entities) { + $query['include_entities'] = 1; + } + //if trim + if($trim) { + $query['trim_user'] = 1; + } + $url = sprintf(self::URL_RETWEET, $id); + return $this->_post($url, $query); + } + /** + * Updates the authenticating user's status, + * also known as tweeting. + * + * @param status is integer + * @param reply is string + * @param lat is float + * @param long is float + * @param place is string or integer + * @param display is boolean + * @param trim is boolean + * @param entities is boolean + * @param wrap is boolean + * @return $this + */ + public function update($status, $reply = NULL, $lat = NULL, $long = NULL, $place = NULL, $display = NULL, $trim = FALSE, $entities = FALSE, $wrap = FALSE) { + //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, 'float') //Argument 3 must be a float + ->argument(4, 'float') //Argument 4 must be a float + ->argument(5, 'string', 'int') //Argument 5 must be an string or integer + ->argument(6, 'boolean') //Argument 6 must be an boolean + ->argument(7, 'boolean') //Argument 7 must be an boolean + ->argument(8, 'boolean'); //Argument 8 must be an boolean + + + $query = array('status' => $status); + //if reply is not empty + if(!is_null($reply)) { + //lets put it in query + $query['in_reply_to_status_id '] = $reply; + } + //if reply is not empty + if(!is_null($lat) && $lat >= -90.0 && $lat <= +90.0) { + //lets put it in query + $query ['lat'] = $lat; + } + //if reply is not empty + if(!is_null($long) && $long >= -180.0 && $lat <= +180.0) { + //lets put it in query + $query ['long'] = $long; + } + //if reply is not empty + if(!is_null($place)) { + //lets put it in query + $query['place_id '] = $place; + } + //if entities + if($display) { + $query['display_coordinates'] = 1; + } + //if trim + if($trim) { + $query['trim_user'] = 1; + } + //if entities + if($entities) { + $query['include_entities'] = 1; + } + //if wrap + if($wrap) { + $query['wrap_links'] = 1; + } + + return $this->_post(self::URL_UPDATE, $query); + } + /** + * Updates the authenticating user's status, + * also known as tweeting. + * + * @param status is integer + * @param reply is string + * @param lat is float + * @param long is float + * @param place is string or integer + * @param display is boolean + * @param trim is boolean + * @param entities is boolean + * @param wrap is boolean + * @return $this + */ + public function updateMedia($status, $media, $sensitive = NULL, $id = NULL, $lat = NULL, $long = NULL, $place = NULL, $display = NULL) { + //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, 'boolean') //Argument 3 must be a boolean + ->argument(4, 'string') //Argument 4 must be an string + ->argument(5, 'boolean') //Argument 5 must be an boolena + ->argument(6, 'boolean') //Argument 6 must be an boolean + ->argument(7, 'boolean') //Argument 7 must be an boolean + ->argument(8, 'boolean'); //Argument 8 must be an boolean + + + $query = array('status' => $status, 'media[]' => $media); + //if sensitive + if($sensitive) { + $query['possibly_sensitive'] = 1; + } + //if reply is not empty + if(!is_null($id)) { + //lets put it in query + $query['in_reply_to_status_id'] = $id; + } + //if reply is not empty + if(!is_null($lat) && $lat >= -90.0 && $lat <= +90.0) { + //lets put it in query + $query ['lat'] = $lat; + } + //if reply is not empty + if(!is_null($long) && $long >= -180.0 && $lat <= +180.0) { + //lets put it in query + $query ['long'] = $long; + } + //if reply is not empty + if(!is_null($place)) { + //lets put it in query + $query['place_id '] = $place; + } + //if entities + if($display) { + $query['display_coordinates'] = 1; + } + + return $this->_getResponse(self::URL_UPDATE_MEDIA, $query); + } + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ + + } \ No newline at end of file diff --git a/library/eden/twitter/users.php b/library/eden/twitter/users.php index 5b54cf6..23e3512 100644 --- a/library/eden/twitter/users.php +++ b/library/eden/twitter/users.php @@ -1,277 +1,277 @@ - -/* - * 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. - */ - -/** - * Eventbrite new or update discount - * - * @package Eden - * @category eventbrite - * @author Christian Blanquera - * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ - */ -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 $_query = array(); - - /* Private Properties - -------------------------------*/ - /* Get - -------------------------------*/ - public static function get($key, $secret) { - return self::_getMultiple(__CLASS__, $key, $secret); - } - - /* Magic - -------------------------------*/ - /* Public Methods - -------------------------------*/ - /** - * Return up to 100 users worth of extended information, - * specified by either ID, screen name, or combination of the two. - * - * @param id is string or integer - * @param netities is boolean - * @return $this - */ - public function lookupFriends($id = NULL, $entities = false) { - //Argument Test - Eden_Twitter_Error::get() - ->argument(1, 'int', 'string') //Argument 1 must be a string or integer - ->argument(2, 'boolean'); //Argument 1 must be a boolean - - $query = array(); - //if it is not empty - if(!is_null($id)) { - //if id is integer - if(is_int($id)) { - $id = explode(',', $id); - //lets put it in query - $query['user_id'] = $id; - } - //if id is string - if(is_string($id)) { - $id = explode(',', $id); - //at this poit id will be an array - $id = array(); - $query['screen_name'] = $id; - - - //lets put it in query - //$query['screen_name'] = $id; - } - } - - return $this->_getResponse(self::URL_LOOK_UP, $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. - * - * @param name is string - * @param size is integer - * @return $this - */ - public function getProfileImage($name = NULL, $size = NULL) { - //Argument Test - Eden_Twitter_Error::get() - ->argument(1, 'string', 'null') //Argument 1 must be a string - ->argument(2, 'string', 'null'); //Argument 2 must be a string - - $query = array(); - //if it is not empty - if(!is_null($name)) { - //lets put it in query - $query['screen_name'] = $name; - } - //if it is not empty - if(!is_null($size)) { - //lets put it in query - $query['size'] = $size; - } - - - return $this->_getResponse(self::URL_PROFILE_IMAGE, $query); - } - /** - * Runs a search for users similar to Find People button on Twitter.com. - * - * @param name is string - * @param size is integer - * @return $this - */ - public function search($q, $page = NULL, $perpage = NULL, $entities = false) { - //Argument Test - Eden_Twitter_Error::get() - ->argument(1, 'string','int','null') //Argument 1 must be a string or integer - ->argument(2, 'int', 'null') //Argument 2 must be an integer - ->argument(3, 'int', 'null') //Argument 3 must be an integer - ->argument(4, 'boolean'); //Argument 4 must be a boolean - - $query = array('q' => $q); - //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) && $perpage <= 20) { - //lets put it in query - $query['per_page'] = $perpage; - } - //if entities - if($entities) { - $query['include_entities'] = 1; - } - - - return $this->_getResponse(self::URL_SEARCH, $query); - } - /** - * Returns extended information of a given user, specified - * by ID or screen name as per the required id parameter. - * - * @param id is string or integer - * @param entities is boolean - * @return $this - */ - public function getDetail($id, $entities = false) { - //Argument Test - Eden_Twitter_Error::get() - ->argument(1, 'string','int') //Argument 1 must be a string or integer - ->argument(2, 'boolean'); //Argument 4 must be a boolean - - $query = array('user_id', 'screen_name' => $id); - //if entities - if($entities) { - $query['include_entities'] = 1; - } - - - return $this->_getResponse(self::URL_SHOW, $query); - } - /** - * Returns an array of users that the specified user can contribute to. - * - * @param name is string - * @param size is integer - * @return $this - */ - public function getContributees($id = NULL, $name = NULL, $entities = false, $status = false) { - //Argument Test - Eden_Twitter_Error::get() - ->argument(1, 'int', 'null') //Argument 1 must be a string or integer - ->argument(2, 'int','string', 'null') //Argument 1 must be a string or integer - ->argument(3, 'boolean') //Argument 4 must be a boolean - ->argument(4, 'boolean'); //Argument 4 must be a boolean - - $query = array(); - //if it is not empty - if(!is_null($id)) { - //lets put it in our query - $query['user_id'] = $id; - } - //if it is not empty - if(!is_null($name)) { - //lets put it in our query - $query['screen_name'] = $name; - } - //if entities - if($entities) { - $query['include_entities'] = 1; - } - //if entities - if($status) { - $query['skip_status'] = 1; - } - - return $this->_getResponse(self::URL_CONTRIBUTEES, $query); - } - /** - * Returns an array of users that the specified user can contribute to. - * - * @param name is string - * @param size is integer - * @return $this - */ - public function getContributors($id = NULL, $name = NULL, $entities = false, $status = false) { - //Argument Test - Eden_Twitter_Error::get() - ->argument(1, 'int', 'null') //Argument 1 must be a string or integer - ->argument(2, 'int','string', 'null') //Argument 1 must be a string or integer - ->argument(3, 'boolean') //Argument 4 must be a boolean - ->argument(4, 'boolean'); //Argument 4 must be a boolean - - $query = array(); - //if it is not empty - if(!is_null($id)) { - //lets put it in our query - $query['user_id'] = $id; - } - //if it is not empty - if(!is_null($name)) { - //lets put it in our query - $query['screen_name'] = $name; - } - //if entities - if($entities) { - $query['include_entities'] = 1; - } - //if entities - if($status) { - $query['skip_status'] = 1; - } - - return $this->_getResponse(self::URL_CONTRIBUTORS, $query); - } - - - - - - - - - - - - - - - - - - - - - - - - - - /* Protected Methods - -------------------------------*/ - /* Private Methods - -------------------------------*/ - - -} + +/* + * 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. + */ + +/** + * Eventbrite new or update discount + * + * @package Eden + * @category eventbrite + * @author Christian Blanquera + * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ + */ +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 $_query = array(); + + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function i($key, $secret) { + return self::_getMultiple(__CLASS__, $key, $secret); + } + + /* Magic + -------------------------------*/ + /* Public Methods + -------------------------------*/ + /** + * Return up to 100 users worth of extended information, + * specified by either ID, screen name, or combination of the two. + * + * @param id is string or integer + * @param netities is boolean + * @return $this + */ + public function lookupFriends($id = NULL, $entities = false) { + //Argument Test + Eden_Twitter_Error::i() + ->argument(1, 'int', 'string') //Argument 1 must be a string or integer + ->argument(2, 'boolean'); //Argument 1 must be a boolean + + $query = array(); + //if it is not empty + if(!is_null($id)) { + //if id is integer + if(is_int($id)) { + $id = explode(',', $id); + //lets put it in query + $query['user_id'] = $id; + } + //if id is string + if(is_string($id)) { + $id = explode(',', $id); + //at this poit id will be an array + $id = array(); + $query['screen_name'] = $id; + + + //lets put it in query + //$query['screen_name'] = $id; + } + } + + return $this->_getResponse(self::URL_LOOK_UP, $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. + * + * @param name is string + * @param size is integer + * @return $this + */ + public function getProfileImage($name = NULL, $size = NULL) { + //Argument Test + Eden_Twitter_Error::i() + ->argument(1, 'string', 'null') //Argument 1 must be a string + ->argument(2, 'string', 'null'); //Argument 2 must be a string + + $query = array(); + //if it is not empty + if(!is_null($name)) { + //lets put it in query + $query['screen_name'] = $name; + } + //if it is not empty + if(!is_null($size)) { + //lets put it in query + $query['size'] = $size; + } + + + return $this->_getResponse(self::URL_PROFILE_IMAGE, $query); + } + /** + * Runs a search for users similar to Find People button on Twitter.com. + * + * @param name is string + * @param size is integer + * @return $this + */ + public function search($q, $page = NULL, $perpage = NULL, $entities = false) { + //Argument Test + Eden_Twitter_Error::i() + ->argument(1, 'string','int','null') //Argument 1 must be a string or integer + ->argument(2, 'int', 'null') //Argument 2 must be an integer + ->argument(3, 'int', 'null') //Argument 3 must be an integer + ->argument(4, 'boolean'); //Argument 4 must be a boolean + + $query = array('q' => $q); + //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) && $perpage <= 20) { + //lets put it in query + $query['per_page'] = $perpage; + } + //if entities + if($entities) { + $query['include_entities'] = 1; + } + + + return $this->_getResponse(self::URL_SEARCH, $query); + } + /** + * Returns extended information of a given user, specified + * by ID or screen name as per the required id parameter. + * + * @param id is string or integer + * @param entities is boolean + * @return $this + */ + public function getDetail($id, $entities = false) { + //Argument Test + Eden_Twitter_Error::i() + ->argument(1, 'string','int') //Argument 1 must be a string or integer + ->argument(2, 'boolean'); //Argument 4 must be a boolean + + $query = array('user_id', 'screen_name' => $id); + //if entities + if($entities) { + $query['include_entities'] = 1; + } + + + return $this->_getResponse(self::URL_SHOW, $query); + } + /** + * Returns an array of users that the specified user can contribute to. + * + * @param name is string + * @param size is integer + * @return $this + */ + public function getContributees($id = NULL, $name = NULL, $entities = false, $status = false) { + //Argument Test + Eden_Twitter_Error::i() + ->argument(1, 'int', 'null') //Argument 1 must be a string or integer + ->argument(2, 'int','string', 'null') //Argument 1 must be a string or integer + ->argument(3, 'boolean') //Argument 4 must be a boolean + ->argument(4, 'boolean'); //Argument 4 must be a boolean + + $query = array(); + //if it is not empty + if(!is_null($id)) { + //lets put it in our query + $query['user_id'] = $id; + } + //if it is not empty + if(!is_null($name)) { + //lets put it in our query + $query['screen_name'] = $name; + } + //if entities + if($entities) { + $query['include_entities'] = 1; + } + //if entities + if($status) { + $query['skip_status'] = 1; + } + + return $this->_getResponse(self::URL_CONTRIBUTEES, $query); + } + /** + * Returns an array of users that the specified user can contribute to. + * + * @param name is string + * @param size is integer + * @return $this + */ + public function getContributors($id = NULL, $name = NULL, $entities = false, $status = false) { + //Argument Test + Eden_Twitter_Error::i() + ->argument(1, 'int', 'null') //Argument 1 must be a string or integer + ->argument(2, 'int','string', 'null') //Argument 1 must be a string or integer + ->argument(3, 'boolean') //Argument 4 must be a boolean + ->argument(4, 'boolean'); //Argument 4 must be a boolean + + $query = array(); + //if it is not empty + if(!is_null($id)) { + //lets put it in our query + $query['user_id'] = $id; + } + //if it is not empty + if(!is_null($name)) { + //lets put it in our query + $query['screen_name'] = $name; + } + //if entities + if($entities) { + $query['include_entities'] = 1; + } + //if entities + if($status) { + $query['skip_status'] = 1; + } + + return $this->_getResponse(self::URL_CONTRIBUTORS, $query); + } + + + + + + + + + + + + + + + + + + + + + + + + + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ + + +} diff --git a/library/eden/type.php b/library/eden/type.php index fda4e6e..49a6b3e 100644 --- a/library/eden/type.php +++ b/library/eden/type.php @@ -32,21 +32,21 @@ class Eden_Type extends Eden_Class { -------------------------------*/ /* Get -------------------------------*/ - public static function get($type = NULL) { + public static function i($type = NULL) { if(func_num_args() > 1) { $type = func_get_args(); } if(is_array($type)) { - return Eden_Type_Array::get($type); + return Eden_Type_Array::i($type); } if(is_string($type)) { - return Eden_Type_String::get($type); + return Eden_Type_String::i($type); } if(is_object($type)) { - return Eden_Type_Object::get($type); + return Eden_Type_Object::i($type); } return self::_getSingleton(__CLASS__); @@ -68,7 +68,7 @@ public function getArray($array) { $array = $args; } - return Eden_Type_Array::get($array); + return Eden_Type_Array::i($array); } /** @@ -78,17 +78,7 @@ public function getArray($array) { * @return Eden_Type_String */ public function getString($string) { - return Eden_Type_String::get($string); - } - - /** - * Returns the object class - * - * @param object - * @return Eden_Type_Object - */ - public function getObject($object) { - return Eden_Type_Object::get($object); + return Eden_Type_String::i($string); } /* Protected Methods diff --git a/library/eden/type/abstract.php b/library/eden/type/abstract.php index 5dd877a..2c0fd52 100755 --- a/library/eden/type/abstract.php +++ b/library/eden/type/abstract.php @@ -48,7 +48,7 @@ public function __call($name, $args) { //call the parent return parent::__call($name, $args); } catch(Eden_Error $e) { - Eden_Type_Error::get($e->getMessage())->trigger(); + Eden_Type_Error::i($e->getMessage())->trigger(); } } @@ -82,7 +82,7 @@ public function __call($name, $args) { } //return string class - return Eden_Type_String::get($result); + return Eden_Type_String::i($result); } //if the result is an array @@ -95,7 +95,7 @@ public function __call($name, $args) { } //return array class - return Eden_Type_Array::get($result); + return Eden_Type_Array::i($result); } return $result; @@ -119,9 +119,9 @@ public function revert() { * @param bool whether to get the modified or original version * @return string */ - public function getData($modified = true) { + public function get($modified = true) { //argument 1 must be a bool - Eden_Type_Error::get()->argument(1, 'bool'); + Eden_Type_Error::i()->argument(1, 'bool'); return $modified ? $this->_data : $this->_original; } diff --git a/library/eden/type/array.php b/library/eden/type/array.php index be4f6fe..dfe1838 100644 --- a/library/eden/type/array.php +++ b/library/eden/type/array.php @@ -45,13 +45,12 @@ class Eden_Type_Array extends Eden_Type_Abstract implements ArrayAccess, Iterato 'array_datas' => self::PRE, 'count' => self::PRE, 'current' => self::PRE, 'each' => self::PRE, 'end' => self::PRE, 'extract' => self::PRE, - 'in_array' => self::PRE, 'key' => self::PRE, - 'next' => self::PRE, 'prev' => self::PRE, - 'sizeof' => 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, + 'implode' => self::POST, 'in_array' => self::POST, 'array_unshift' => self::REFERENCE, 'array_walk_recursive' => self::REFERENCE, 'array_walk' => self::REFERENCE, 'arsort' => self::REFERENCE, @@ -67,7 +66,7 @@ class Eden_Type_Array extends Eden_Type_Abstract implements ArrayAccess, Iterato -------------------------------*/ /* Get -------------------------------*/ - public static function get() { + public static function i() { $data = self::_getStart(func_get_args()); return self::_getMultiple(__CLASS__, $data); } @@ -85,7 +84,7 @@ public function __construct($data = array()) { } public function __toString() { - return json_encode($this->getData()); + return json_encode($this->get()); } public function __get($name) { @@ -135,12 +134,21 @@ public function __call($name, $args) { try { return parent::__call($name, $args); } catch(Eden_Error $e) { - Eden_Type_Error::get($e->getMessage())->trigger(); + Eden_Type_Error::i($e->getMessage())->trigger(); } } /* Public Methods -------------------------------*/ + /** + * Returns if the data is empty + * + * @return bool + */ + public function isEmpty() { + return empty($this->_data); + } + /** * Copies the value of source key into destination key * @@ -160,7 +168,7 @@ public function copy($source, $destination) { */ public function cut($key) { //argument 1 must be scalar - Eden_Type_Error::get()->argument(1, 'scalar'); + Eden_Type_Error::i()->argument(1, 'scalar'); //if nothing to cut if(!isset($this->_data[$key])) { @@ -185,7 +193,7 @@ public function cut($key) { */ public function paste($after, $value, $key = NULL) { //Argument test - Eden_Type_Error::get() + 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 @@ -359,7 +367,7 @@ protected static function _getStart(array $args) { $data = $args[0]; if($data instanceof Eden_Type_Array) { - $data = $data->getData(); + $data = $data->get(); } if(!is_array($data)) { diff --git a/library/eden/type/error.php b/library/eden/type/error.php index d0fe7f1..a7a4ae9 100755 --- a/library/eden/type/error.php +++ b/library/eden/type/error.php @@ -26,7 +26,7 @@ class Eden_Type_Error extends Eden_Error { -------------------------------*/ /* Get -------------------------------*/ - public static function get($message = NULL, $code = 0) { + public static function i($message = NULL, $code = 0) { $class = __CLASS__; return new $class($message, $code); } diff --git a/library/eden/type/string.php b/library/eden/type/string.php index 5db2ada..b029101 100644 --- a/library/eden/type/string.php +++ b/library/eden/type/string.php @@ -55,13 +55,13 @@ class Eden_Type_String extends Eden_Type_Abstract { -------------------------------*/ /* Get -------------------------------*/ - public static function get($data) { + public static function i($data) { if($data instanceof Eden_Type_String) { return $data; } //argument 1 must be scalar - Eden_Type_Error::get()->argument(1, 'scalar'); + Eden_Type_Error::i()->argument(1, 'scalar'); $data = (string) $data; @@ -84,7 +84,7 @@ public function __toString() { */ public function camelize($prefix = '-') { //argument 1 must be a string - Eden_Type_Error::get()->argument(1, 'string'); + Eden_Type_Error::i()->argument(1, 'string'); $this->_data = str_replace($prefix, ' ', $this->_data); $this->_data = str_replace(' ', '', ucwords($this->_data)); @@ -102,7 +102,7 @@ public function camelize($prefix = '-') { */ public function uncamelize($prefix = '-') { //argument 1 must be a string - Eden_Type_Error::get()->argument(1, 'string'); + Eden_Type_Error::i()->argument(1, 'string'); $this->_data = strtolower(preg_replace("/([A-Z])/", $prefix."$1", $this->_data)); @@ -132,7 +132,7 @@ public function dasherize() { */ public function titlize($prefix = '-') { //argument 1 must be a string - Eden_Type_Error::get()->argument(1, 'string'); + Eden_Type_Error::i()->argument(1, 'string'); $this->_data = ucwords(str_replace($prefix, ' ', $this->_data)); diff --git a/library/eden/unit.php b/library/eden/unit.php index 0c65b2d..2d770df 100755 --- a/library/eden/unit.php +++ b/library/eden/unit.php @@ -32,7 +32,7 @@ class Eden_Unit { -------------------------------*/ /* Get -------------------------------*/ - public static function get() { + public static function i() { return self::_getMultiple(__CLASS__); } @@ -75,7 +75,7 @@ public function __call($name, $args) { -------------------------------*/ public function setPackage($name) { //Argument 1 must be a string - Eden_Unit_Error::get()->argument(1, 'string'); + Eden_Unit_Error::i()->argument(1, 'string'); $this->_package = $name; return $this; @@ -83,7 +83,7 @@ public function setPackage($name) { public function getTotalTests($package = NULL) { //Argument 1 must be a string or null - Eden_Unit_Error::get()->argument(1, 'string', 'null'); + Eden_Unit_Error::i()->argument(1, 'string', 'null'); if(isset($this->_report[$package])) { return count($this->_report[$package]); @@ -99,7 +99,7 @@ public function getTotalTests($package = NULL) { public function getPassFail($package = NULL) { //Argument 1 must be a string or null - Eden_Unit_Error::get()->argument(1, 'string', 'null'); + Eden_Unit_Error::i()->argument(1, 'string', 'null'); $passFail = array(0, 0); if(isset($this->_report[$package])) { foreach($this->_report[$package] as $test) { @@ -131,7 +131,7 @@ public function getReport() { -------------------------------*/ protected function _assertArrayHasKey($needle, $haystack) { try { - Eden_Unit_Error::get() + 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) { @@ -143,7 +143,7 @@ protected function _assertArrayHasKey($needle, $haystack) { protected function _assertClassHasAttribute($needle, $haystack) { try { //try to validate arguments - Eden_Unit_Error::get() + 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) { @@ -155,7 +155,7 @@ protected function _assertClassHasAttribute($needle, $haystack) { protected function _assertContains($needle, $haystack) { try { //try to validate arguments - Eden_Unit_Error::get() + Eden_Unit_Error::i() ->argument(1, 'string') ->argument(2, 'array', 'string'); } catch(Eden_Unit_Error $e) { @@ -171,7 +171,7 @@ protected function _assertContains($needle, $haystack) { protected function _assertContainsOnly($type, $haystack) { try { //try to validate arguments - Eden_Unit_Error::get() + 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) { @@ -205,7 +205,7 @@ protected function _assertContainsOnly($type, $haystack) { protected function _assertCount($number, $haystack) { try { //try to validate arguments - Eden_Unit_Error::get() + 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) { @@ -233,7 +233,7 @@ protected function _assertFalse($condition) { protected function _assertGreaterThan($number, $actual) { try { //try to validate arguments - Eden_Unit_Error::get() + 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) { @@ -245,7 +245,7 @@ protected function _assertGreaterThan($number, $actual) { protected function _assertGreaterThanOrEqual($number, $actual) { try { //try to validate arguments - Eden_Unit_Error::get() + 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) { @@ -257,7 +257,7 @@ protected function _assertGreaterThanOrEqual($number, $actual) { protected function _assertInstanceOf($expected, $actual) { try { //try to validate arguments - Eden_Unit_Error::get() + 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) { @@ -269,7 +269,7 @@ protected function _assertInstanceOf($expected, $actual) { protected function _assertInternalType($type, $actual) { try { //try to validate arguments - Eden_Unit_Error::get()->argument(1, 'string'); //Argument 1 must be a string + Eden_Unit_Error::i()->argument(1, 'string'); //Argument 1 must be a string } catch(Eden_Unit_Error $e) { return false; } @@ -289,7 +289,7 @@ protected function _assertInternalType($type, $actual) { protected function _assertLessThan($number, $actual) { try { //try to validate arguments - Eden_Unit_Error::get() + 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) { @@ -301,7 +301,7 @@ protected function _assertLessThan($number, $actual) { protected function _assertLessThanOrEqual($number, $actual) { try { //try to validate arguments - Eden_Unit_Error::get() + 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) { @@ -317,7 +317,7 @@ protected function _assertNull($mixed) { protected function _assertRegExp($pattern, $string) { try { //try to validate arguments - Eden_Unit_Error::get() + 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) { @@ -333,7 +333,7 @@ protected function _assertSame($expected, $actual) { protected function _assertStringEndsWith($suffix, $string) { try { //try to validate arguments - Eden_Unit_Error::get() + 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) { @@ -345,7 +345,7 @@ protected function _assertStringEndsWith($suffix, $string) { protected function _assertStringStartsWith($prefix, $string) { try { //try to validate arguments - Eden_Unit_Error::get() + 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) { @@ -377,7 +377,7 @@ class Eden_Unit_Error extends Eden_Error { -------------------------------*/ /* Get -------------------------------*/ - public static function get($message = NULL, $code = 0) { + public static function i($message = NULL, $code = 0) { $class = __CLASS__; return new $class($message, $code); } diff --git a/library/eden/validation.php b/library/eden/validation.php index b1e3b63..feee5fe 100644 --- a/library/eden/validation.php +++ b/library/eden/validation.php @@ -28,7 +28,7 @@ class Eden_Validation extends Eden_Class { -------------------------------*/ /* Get -------------------------------*/ - public static function get($value) { + public static function i($value) { return self::_getMultiple(__CLASS__, $value); } @@ -154,7 +154,7 @@ public function startsWithLetter() { * @return bool */ public function lengthGreaterThan($number) { - Eden_Validation_Error::get()->argument('int'); + Eden_Validation_Error::i()->argument('int'); return strlen((string)$this->_value) > $number; } @@ -165,7 +165,7 @@ public function lengthGreaterThan($number) { * @return bool */ public function lengthLessThan($number) { - Eden_Validation_Error::get()->argument('int'); + Eden_Validation_Error::i()->argument('int'); return strlen((string)$this->_value) < $number; } @@ -176,7 +176,7 @@ public function lengthLessThan($number) { * @return bool */ public function lengthGreaterThanEqualTo($number) { - Eden_Validation_Error::get()->argument('int'); + Eden_Validation_Error::i()->argument('int'); return strlen((string)$this->_value) >= $number; } @@ -187,7 +187,7 @@ public function lengthGreaterThanEqualTo($number) { * @return bool */ public function lengthLessThanEqualTo($number) { - Eden_Validation_Error::get()->argument('int'); + Eden_Validation_Error::i()->argument('int'); return strlen((string)$this->_value) <= $number; } @@ -198,7 +198,7 @@ public function lengthLessThanEqualTo($number) { * @return bool */ public function wordCountEquals($number) { - Eden_Validation_Error::get()->argument('int'); + Eden_Validation_Error::i()->argument('int'); $words = explode(' ', $this->_value); return count($words) === $number; } @@ -210,7 +210,7 @@ public function wordCountEquals($number) { * @return bool */ public function wordCountGreaterThan($number) { - Eden_Validation_Error::get()->argument('int'); + Eden_Validation_Error::i()->argument('int'); $words = explode(' ', $this->_value); return count($words) > $number; } @@ -222,7 +222,7 @@ public function wordCountGreaterThan($number) { * @return bool */ public function wordCountLessThan($number) { - Eden_Validation_Error::get()->argument('int'); + Eden_Validation_Error::i()->argument('int'); $words = explode(' ', $this->_value); return count($words) < $number; } @@ -234,7 +234,7 @@ public function wordCountLessThan($number) { * @return bool */ public function wordCountGreaterThanEqualTo($number) { - Eden_Validation_Error::get()->argument('int'); + Eden_Validation_Error::i()->argument('int'); $words = explode(' ', $this->_value); return count($words) >= $number; } @@ -246,7 +246,7 @@ public function wordCountGreaterThanEqualTo($number) { * @return bool */ public function wordCountLessThanEqualTo($number) { - Eden_Validation_Error::get()->argument('int'); + Eden_Validation_Error::i()->argument('int'); $words = explode(' ', $this->_value); return count($words) <= $number; } @@ -260,7 +260,7 @@ public function wordCountLessThanEqualTo($number) { * @return bool */ public function greaterThan($number) { - Eden_Validation_Error::get()->argument('numeric'); + Eden_Validation_Error::i()->argument('numeric'); return $this->_value > (float)$number; } @@ -271,7 +271,7 @@ public function greaterThan($number) { * @return bool */ public function lessThan($number) { - Eden_Validation_Error::get()->argument('numeric'); + Eden_Validation_Error::i()->argument('numeric'); return $this->_value < (float)$number; } @@ -282,7 +282,7 @@ public function lessThan($number) { * @return bool */ public function greaterThanEqualTo($number) { - Eden_Validation_Error::get()->argument('numeric'); + Eden_Validation_Error::i()->argument('numeric'); return $this->_value >= (float)$number; } @@ -293,7 +293,7 @@ public function greaterThanEqualTo($number) { * @return bool */ public function lessThanEqualTo($number) { - Eden_Validation_Error::get()->argument('numeric'); + Eden_Validation_Error::i()->argument('numeric'); return $this->_value <= (float)$number; } @@ -317,7 +317,7 @@ class Eden_Validation_Error extends Eden_Error { -------------------------------*/ /* Get -------------------------------*/ - public static function get($message = NULL, $code = 0) { + public static function i($message = NULL, $code = 0) { $class = __CLASS__; return new $class($message, $code); } diff --git a/library/eden/webcharge.php b/library/eden/webcharge.php index dd8a179..b27af0a 100644 --- a/library/eden/webcharge.php +++ b/library/eden/webcharge.php @@ -79,7 +79,7 @@ class Eden_Webcharge_Model extends Eden_Class -------------------------------*/ /* Get -------------------------------*/ - public static function get($user, $password, array $options = array()) { + public static function i($user, $password, array $options = array()) { return self::_getMultiple(__CLASS__, $user, $password, $options); } @@ -102,7 +102,7 @@ public function __construct($user = NULL, $password = NULL, array $options = arr * @return this */ public function setUser($user) { - Eden_Webcharge_Error::get() + Eden_Webcharge_Error::i() ->setMessage()->argument(1, 'string'); $this->_transaction['username'] = $user; return $this; @@ -115,7 +115,7 @@ public function setUser($user) { * @return this */ public function setPassword($password) { - Eden_Webcharge_Error::get() + Eden_Webcharge_Error::i() ->setMessage()->argument(1, 'string'); $this->_transaction['pw'] = $password; return $this; @@ -157,7 +157,7 @@ public function send() { //test for valid amount if(!$this->_transaction['fulltotal'] || !is_numeric($this->_transaction['fulltotal'])) { //throw exception - Eden_Webcharge_Error::get() + Eden_Webcharge_Error::i() ->setMessage(Eden_Webcharge_Error::INVALID_AMOUNT) ->addVariable((string) $this->_transaction['fulltotal']); } @@ -165,7 +165,7 @@ public function send() { //test for valid transaction type if(!$this->_transaction['trantype'] || !in_array($this->_transaction['trantype'], $this->_transactionTypes)) { //throw exception - Eden_Webcharge_Error::get() + Eden_Webcharge_Error::i() ->setMessage(Eden_Webcharge_Error::INVALID_TRANSACTION_TYPE) ->addVariable((string) $this->_transaction['trantype']) ->trigger(); @@ -174,7 +174,7 @@ public function send() { //test for valid card type if(!$this->_transaction['cardtype'] || !in_array($this->_transaction['cardtype'], $this->creditCards)) { //throw exception - Eden_Webcharge_Error::get() + Eden_Webcharge_Error::i() ->setMessage(Eden_Webcharge_Error::INVALID_CARD_TYPE) ->addVariable((string) $this->_transaction['cardtype']) ->trigger(); @@ -183,7 +183,7 @@ public function send() { //test for valid month if(!$this->_transaction['month'] || !is_numeric($this->_transaction['month']) || strlen((string) $this->_transaction['month']) != 2) { //throw exception - Eden_Webcharge_Error::get() + Eden_Webcharge_Error::i() ->setMessage(Eden_Webcharge_Error::INVALID_CREDIT_CARD_MONTH) ->addVariable((string) $this->_transaction['month']) ->trigger(); @@ -192,7 +192,7 @@ public function send() { //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::get() + Eden_Webcharge_Error::i() ->setMessage(Eden_Webcharge_Error::INVALID_CREDIT_CARD_YEAR) ->addVariable((string) $this->_transaction['year']) ->trigger(); @@ -201,11 +201,11 @@ public function send() { //test for valid creditcard name if(!$this->_transaction['ccname']) { //throw exception - Eden_Webcharge_Error::get(Eden_Webcharge_Error::INVALID_CREDIT_CARD_NAME)->trigger(); + Eden_Webcharge_Error::i(Eden_Webcharge_Error::INVALID_CREDIT_CARD_NAME)->trigger(); } // Create the connection through the cURL extension - return Eden_Curl::get() + return Eden_Curl::i() ->setUrl(self::PAYMENT_URL) ->when($this->_proxy != NULL) ->setProxy($this->_proxy) diff --git a/library/eden/when.php b/library/eden/when.php index 280792e..602fe56 100755 --- a/library/eden/when.php +++ b/library/eden/when.php @@ -32,7 +32,7 @@ class Eden_When extends Eden_Class implements ArrayAccess, Iterator { -------------------------------*/ /* Get -------------------------------*/ - public static function get($scope, $lines = 0) { + public static function i($scope, $lines = 0) { return self::_getMultiple(__CLASS__, $scope, $lines); } From ca8e3f7de7f987d3a5ad85b7158ed315da9a18a3 Mon Sep 17 00:00:00 2001 From: cblanquera Date: Mon, 9 Jan 2012 02:35:50 +0000 Subject: [PATCH 045/330] big changes. made all static get methods to i. Added facebook controller. path now extends string. renamed things with set data and get data to just set and get. git-svn-id: http://svn.openovate.com/edenv2/trunk@45 38ede93f-50f4-44af-b0b3-68ccca78c181 --- library/eden/mysql/collection.php | 2 +- library/eden/mysql/search.php | 2 ++ library/eden/path.php | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/library/eden/mysql/collection.php b/library/eden/mysql/collection.php index 6df2825..e3e671a 100644 --- a/library/eden/mysql/collection.php +++ b/library/eden/mysql/collection.php @@ -76,7 +76,7 @@ public function setTable($table) { * @param string * @return this */ - public function formatTime($column, $format = self::DATETIME) { + public function formatTime($column, $format = Eden_Mysql_Model::DATETIME) { //for each row foreach($this->_list as $row) { //let the row handle this diff --git a/library/eden/mysql/search.php b/library/eden/mysql/search.php index 095b4be..8142ec5 100644 --- a/library/eden/mysql/search.php +++ b/library/eden/mysql/search.php @@ -71,6 +71,8 @@ public function __call($name, $args) { if(!isset($args[0])) { $args[0] = NULL; } + + $key = $key.'=%s'; $this->addFilter($key, $args[0]); diff --git a/library/eden/path.php b/library/eden/path.php index 4f347f8..b45a470 100644 --- a/library/eden/path.php +++ b/library/eden/path.php @@ -129,7 +129,7 @@ public function prepend($path) { //check for type errors $error->argument($i + 1, $path, 'string'); //add to path - $this->_data = $this->_format($path).$this-_path; + $this->_data = $this->_format($path).$this->_data; } return $this; From 02ee6d13fae9ec32f8b2193cacea814c8dcb207f Mon Sep 17 00:00:00 2001 From: cblanquera Date: Mon, 9 Jan 2012 03:02:35 +0000 Subject: [PATCH 046/330] collection is now iterable git-svn-id: http://svn.openovate.com/edenv2/trunk@46 38ede93f-50f4-44af-b0b3-68ccca78c181 --- library/eden/collection.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/library/eden/collection.php b/library/eden/collection.php index 767bbd5..b87b41d 100644 --- a/library/eden/collection.php +++ b/library/eden/collection.php @@ -211,7 +211,7 @@ public function get($modified = true) { * @return void */ public function rewind() { - reset($this->_data); + reset($this->_list); } /** @@ -221,7 +221,7 @@ public function rewind() { * @return void */ public function current() { - return current($this->_data); + return current($this->_list); } /** @@ -231,7 +231,7 @@ public function current() { * @return void */ public function key() { - return key($this->_data); + return key($this->_list); } /** @@ -241,7 +241,7 @@ public function key() { * @return void */ public function next() { - next($this->_data); + next($this->_list); } /** From 12521c2b30ec0c94a187684a6eb5ab1b2530875e Mon Sep 17 00:00:00 2001 From: cblanquera Date: Mon, 9 Jan 2012 03:06:28 +0000 Subject: [PATCH 047/330] cookie has 2 methods called set git-svn-id: http://svn.openovate.com/edenv2/trunk@47 38ede93f-50f4-44af-b0b3-68ccca78c181 --- library/eden/cookie.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/eden/cookie.php b/library/eden/cookie.php index 8876db7..61e2d4a 100755 --- a/library/eden/cookie.php +++ b/library/eden/cookie.php @@ -87,7 +87,7 @@ public function setSecure($key, $data = NULL, $expires = 0, $path = NULL, $domai * @param string|null the domain * @return this */ - public function set(array $data, $expires = 0, $path = NULL, $domain = NULL, $secure = false, $httponly = false) { + 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); } From 0696935cb7e872218d339500caea983dac26a7e1 Mon Sep 17 00:00:00 2001 From: sy Date: Mon, 9 Jan 2012 03:27:31 +0000 Subject: [PATCH 048/330] tested for non methods in the collection git-svn-id: http://svn.openovate.com/edenv2/trunk@48 38ede93f-50f4-44af-b0b3-68ccca78c181 --- library/eden/mysql/collection.php | 270 ++++++++++++++++-------------- 1 file changed, 145 insertions(+), 125 deletions(-) diff --git a/library/eden/mysql/collection.php b/library/eden/mysql/collection.php index e3e671a..fcbb17d 100644 --- a/library/eden/mysql/collection.php +++ b/library/eden/mysql/collection.php @@ -1,126 +1,146 @@ - -/* - * 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. - */ - -/** - * Mysql Collection handler - * - * @package Eden - * @category mysql - * @author Christian Blanquera - * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ - */ -class Eden_Mysql_Collection extends Eden_Collection { - /* Constants - -------------------------------*/ - /* Public Properties - -------------------------------*/ - /* Protected Properties - -------------------------------*/ - protected $_model = 'Eden_Mysql_Model'; - - /* Private Properties - -------------------------------*/ - /* Get - -------------------------------*/ - public static function i(array $data = array()) { - return self::_getMultiple(__CLASS__,$data); - } - - /* Magic - -------------------------------*/ - /* Public Methods - -------------------------------*/ - /** - * Sets the default database - * - * @param Eden_Mysql - */ - public function setDatabase(Eden_Mysql $database) { - //for each row - foreach($this->_list as $row) { - //let the row handle this - $row->setDatabase($database); - } - - return $this; - } - - /** - * Sets the default database - * - * @param string - */ - public function setTable($table) { - //Argument 1 must be a string - Eden_Mysql_Error::i()->argument(1, 'string'); - - //for each row - foreach($this->_list as $row) { - //let the row handle this - $row->setTable($table); - } - - return $this; - } - - /** - * Useful method for formating a time column. - * - * @param string - * @param string - * @return this - */ - public function formatTime($column, $format = Eden_Mysql_Model::DATETIME) { - //for each row - foreach($this->_list as $row) { - //let the row handle this - $row->formatTime($column, $format); - } - - return $this; - } - - /** - * Inserts or updates collection to database - * - * @param string - * @param Eden_Mysql - * @return this - */ - public function save($table = NULL, Eden_Mysql $database = NULL) { - //for each row - foreach($this->_list as $i => $row) { - $row->save($table, $database); - } - - return $this; - } - - /** - * Removes collection from database - * - * @param string - * @param Eden_Mysql - * @return this - */ - public function remove($table = NULL, Eden_Mysql $database = NULL) { - //for each row - foreach($this->_list as $i => $row) { - //let the row handle this - $row->remove($table, $database); - } - - return $this; - } - - /* Protected Methods - -------------------------------*/ - /* Private Methods - -------------------------------*/ + +/* + * 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. + */ + +/** + * Mysql Collection handler + * + * @package Eden + * @category mysql + * @author Christian Blanquera + * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ + */ +class Eden_Mysql_Collection extends Eden_Collection { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_model = 'Eden_Mysql_Model'; + + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function i(array $data = array()) { + return self::_getMultiple(__CLASS__,$data); + } + + /* Magic + -------------------------------*/ + /* Public Methods + -------------------------------*/ + /** + * Sets the default database + * + * @param Eden_Mysql + */ + public function setDatabase(Eden_Mysql $database) { + //for each row + foreach($this->_list as $row) { + if(!is_object($row) || !method_exists($row, 'setDatabase')) { + continue; + } + + //let the row handle this + $row->setDatabase($database); + } + + return $this; + } + + /** + * Sets the default database + * + * @param string + */ + public function setTable($table) { + //Argument 1 must be a string + Eden_Mysql_Error::i()->argument(1, 'string'); + + //for each row + foreach($this->_list as $row) { + if(!is_object($row) || !method_exists($row, 'setTable')) { + continue; + } + + //let the row handle this + $row->setTable($table); + } + + return $this; + } + + /** + * Useful method for formating a time column. + * + * @param string + * @param string + * @return this + */ + public function formatTime($column, $format = Eden_Mysql_Model::DATETIME) { + //for each row + foreach($this->_list as $row) { + if(!is_object($row) || !method_exists($row, 'formatTime')) { + continue; + } + + //let the row handle this + $row->formatTime($column, $format); + } + + return $this; + } + + /** + * Inserts or updates collection to database + * + * @param string + * @param Eden_Mysql + * @return this + */ + public function save($table = NULL, Eden_Mysql $database = NULL) { + //for each row + foreach($this->_list as $i => $row) { + if(!is_object($row) || !method_exists($row, 'save')) { + continue; + } + + $row->save($table, $database); + } + + return $this; + } + + /** + * Removes collection from database + * + * @param string + * @param Eden_Mysql + * @return this + */ + public function remove($table = NULL, Eden_Mysql $database = NULL) { + //for each row + foreach($this->_list as $i => $row) { + if(!is_object($row) || !method_exists($row, 'remove')) { + continue; + } + + //let the row handle this + $row->remove($table, $database); + } + + return $this; + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ } \ No newline at end of file From 5245474f2c0ca1e11814464dbe1613a671578748 Mon Sep 17 00:00:00 2001 From: sy Date: Mon, 9 Jan 2012 03:32:32 +0000 Subject: [PATCH 049/330] getModel and getCollection return empty collection or model instead of null git-svn-id: http://svn.openovate.com/edenv2/trunk@49 38ede93f-50f4-44af-b0b3-68ccca78c181 --- library/eden/mysql.php | 1730 ++++++++++++++++++++-------------------- 1 file changed, 865 insertions(+), 865 deletions(-) diff --git a/library/eden/mysql.php b/library/eden/mysql.php index ca61485..49a2ce8 100755 --- a/library/eden/mysql.php +++ b/library/eden/mysql.php @@ -1,865 +1,865 @@ - -/* - * 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__).'/event.php'; -require_once dirname(__FILE__).'/sql/error.php'; -require_once dirname(__FILE__).'/mysql/error.php'; -require_once dirname(__FILE__).'/sql/database.php'; -require_once dirname(__FILE__).'/sql/query.php'; -require_once dirname(__FILE__).'/sql/delete.php'; -require_once dirname(__FILE__).'/sql/select.php'; -require_once dirname(__FILE__).'/sql/update.php'; -require_once dirname(__FILE__).'/sql/insert.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'; -require_once dirname(__FILE__).'/mysql/collection.php'; -require_once dirname(__FILE__).'/mysql/model.php'; -require_once dirname(__FILE__).'/mysql/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 - * @version $Id: abstract.php 1 2010-01-02 23:06:36Z blanquera $ - */ -class Eden_Mysql extends Eden_Sql_Database { - /* Constants - -------------------------------*/ - const FIRST = 'first'; - const LAST = 'last'; - - /* Public Properties - -------------------------------*/ - /* Protected Properties - -------------------------------*/ - protected $_type = NULL; - protected $_host = 'localhost'; - protected $_name = NULL; - protected $_user = NULL; - protected $_pass = NULL; - protected $_queries = array(); - - protected $_connection = NULL; - protected $_binds = array(); - - /* Private Properties - -------------------------------*/ - /* Get - -------------------------------*/ - public static function i($host = NULL, $name = NULL, $user = NULL, $pass = NULL) { - return self::_getMultiple(__CLASS__, $host, $name, $user, $pass); - } - - /* Magic - -------------------------------*/ - public function __construct($host, $name, $user, $pass = NULL) { - //argument test - Eden_Mysql_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 number or null - - $this->_host = $host; - $this->_name = $name; - $this->_user = $user; - $this->_pass = $pass; - } - - /* Public Methods - -------------------------------*/ - /** - * Connects to the database - * - * @param array the connection options - * @return this - */ - public function connect(array $options = array()) { - $connection = 'mysql:host='.$this->_host.';dbname='.$this->_name; - - $this->_connection = new PDO($connection, $this->_user, $this->_pass, $options); - - $this->trigger(); - - return $this; - } - - /** - * 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 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 the last inserted id - * - * @return int the id - */ - public function getLastInsertedId() { - return $this->getConnection()->lastInsertId(); - } - - /** - * Returns search - * - * @return Eden_Mysql_Search - */ - public function search() { - return Eden_Mysql_Search::i($this); - } - - /** - * Returns model - * - * @return Eden_Mysql_Model - */ - public function model(array $data = array()) { - return Eden_Mysql_Model::i($data)->setDatabase($this); - } - - /** - * Returns collection - * - * @return Eden_Mysql_Collection - */ - public function collection(array $data = array()) { - return Eden_Mysql_Collection::i($data)->setDatabase($this); - } - - /** - * 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); - } - - /** - * 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 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_Mysql_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_Mysql_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); - $filter = $this->bind($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, $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 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_Mysql_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); - - if(is_null($result)) { - return NULL; - } - - return Eden_Mysql_Model::i($result)->setDatabase($this)->setTable($table); - } - - /** - * 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_Mysql_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); - - if(is_null($results)) { - return NULL; - } - - if(!is_null($index)) { - return Eden_Mysql_Model::i($results); - } - - return Eden_Mysql_Collection::i($results)->setDatabase($this)->setTable($table); - } - - /** - * 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_Mysql_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; - } - - /** - * 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_Mysql_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_Mysql_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; - } - - /** - * 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_Mysql_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); - $filter = $this->bind($filter); - $filters[$i] = vsprintf($format, $filter); - } - } - - $query->where($filters); - - //run the query - $this->query($query, $this->getBinds()); - - $this->trigger($table, $setting, $filters); - - 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_Mysql_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, 'eq', $value))); - } - } - - /** - * 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_Mysql_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); - $filter = $this->bind($filter); - $filters[$i] = vsprintf($format, $filter); - } - } - - $query->where($filters); - - //run the query - $this->query($query, $this->getBinds()); - - $this->trigger($table, $filters); - - return $this; - } - - /** - * 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 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()); - } - - /** - * 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); - } - - /** - * 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 databse - * - * @return string - */ - public function getSchema() { - $backup = array(); - $tables = $this->getTables(); - foreach($tables as $table) { - $backup[] = $this->getBackup(); - } - - return implode("\n\n", $backup); - } - - /** - * 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_Mysql_Error::i()->argument(1, 'string', 'Eden_Sql_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_Mysql_Error::i() - ->setMessage(Eden_Mysql_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; - } - - /** - * 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_Mysql_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 all the bound values of this query - * - * @param void - * @return array - * @notes returns all the binds stored in registry - */ - public function getBinds() { - return $this->_binds; - } - - /* Protected Methods - -------------------------------*/ - /* Private Methods - -------------------------------*/ -} - + +/* + * 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__).'/event.php'; +require_once dirname(__FILE__).'/sql/error.php'; +require_once dirname(__FILE__).'/mysql/error.php'; +require_once dirname(__FILE__).'/sql/database.php'; +require_once dirname(__FILE__).'/sql/query.php'; +require_once dirname(__FILE__).'/sql/delete.php'; +require_once dirname(__FILE__).'/sql/select.php'; +require_once dirname(__FILE__).'/sql/update.php'; +require_once dirname(__FILE__).'/sql/insert.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'; +require_once dirname(__FILE__).'/mysql/collection.php'; +require_once dirname(__FILE__).'/mysql/model.php'; +require_once dirname(__FILE__).'/mysql/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 + * @version $Id: abstract.php 1 2010-01-02 23:06:36Z blanquera $ + */ +class Eden_Mysql extends Eden_Sql_Database { + /* Constants + -------------------------------*/ + const FIRST = 'first'; + const LAST = 'last'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_type = NULL; + protected $_host = 'localhost'; + protected $_name = NULL; + protected $_user = NULL; + protected $_pass = NULL; + protected $_queries = array(); + + protected $_connection = NULL; + protected $_binds = array(); + + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function i($host = NULL, $name = NULL, $user = NULL, $pass = NULL) { + return self::_getMultiple(__CLASS__, $host, $name, $user, $pass); + } + + /* Magic + -------------------------------*/ + public function __construct($host, $name, $user, $pass = NULL) { + //argument test + Eden_Mysql_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 number or null + + $this->_host = $host; + $this->_name = $name; + $this->_user = $user; + $this->_pass = $pass; + } + + /* Public Methods + -------------------------------*/ + /** + * Connects to the database + * + * @param array the connection options + * @return this + */ + public function connect(array $options = array()) { + $connection = 'mysql:host='.$this->_host.';dbname='.$this->_name; + + $this->_connection = new PDO($connection, $this->_user, $this->_pass, $options); + + $this->trigger(); + + return $this; + } + + /** + * 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 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 the last inserted id + * + * @return int the id + */ + public function getLastInsertedId() { + return $this->getConnection()->lastInsertId(); + } + + /** + * Returns search + * + * @return Eden_Mysql_Search + */ + public function search() { + return Eden_Mysql_Search::i($this); + } + + /** + * Returns model + * + * @return Eden_Mysql_Model + */ + public function model(array $data = array()) { + return Eden_Mysql_Model::i($data)->setDatabase($this); + } + + /** + * Returns collection + * + * @return Eden_Mysql_Collection + */ + public function collection(array $data = array()) { + return Eden_Mysql_Collection::i($data)->setDatabase($this); + } + + /** + * 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); + } + + /** + * 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 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_Mysql_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_Mysql_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); + $filter = $this->bind($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, $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 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_Mysql_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); + + if(is_null($result)) { + return Eden_Mysql_Model::i()->setDatabase($this)->setTable($table); + } + + return Eden_Mysql_Model::i($result)->setDatabase($this)->setTable($table); + } + + /** + * 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_Mysql_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); + + if(is_null($results)) { + return Eden_Mysql_Collection::i()->setDatabase($this)->setTable($table); + } + + if(!is_null($index)) { + return Eden_Mysql_Model::i($results); + } + + return Eden_Mysql_Collection::i($results)->setDatabase($this)->setTable($table); + } + + /** + * 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_Mysql_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; + } + + /** + * 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_Mysql_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_Mysql_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; + } + + /** + * 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_Mysql_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); + $filter = $this->bind($filter); + $filters[$i] = vsprintf($format, $filter); + } + } + + $query->where($filters); + + //run the query + $this->query($query, $this->getBinds()); + + $this->trigger($table, $setting, $filters); + + 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_Mysql_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, 'eq', $value))); + } + } + + /** + * 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_Mysql_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); + $filter = $this->bind($filter); + $filters[$i] = vsprintf($format, $filter); + } + } + + $query->where($filters); + + //run the query + $this->query($query, $this->getBinds()); + + $this->trigger($table, $filters); + + return $this; + } + + /** + * 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 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()); + } + + /** + * 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); + } + + /** + * 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 databse + * + * @return string + */ + public function getSchema() { + $backup = array(); + $tables = $this->getTables(); + foreach($tables as $table) { + $backup[] = $this->getBackup(); + } + + return implode("\n\n", $backup); + } + + /** + * 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_Mysql_Error::i()->argument(1, 'string', 'Eden_Sql_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_Mysql_Error::i() + ->setMessage(Eden_Mysql_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; + } + + /** + * 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_Mysql_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 all the bound values of this query + * + * @param void + * @return array + * @notes returns all the binds stored in registry + */ + public function getBinds() { + return $this->_binds; + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} + From 5b78c80a5eadf780e6821dc422610c5e75afb310 Mon Sep 17 00:00:00 2001 From: dmolina Date: Mon, 9 Jan 2012 04:00:31 +0000 Subject: [PATCH 050/330] added insert and update methods git-svn-id: http://svn.openovate.com/edenv2/trunk@50 38ede93f-50f4-44af-b0b3-68ccca78c181 --- library/eden/mysql/collection.php | 40 ++ library/eden/mysql/model.php | 715 +++++++++++++++++------------- 2 files changed, 439 insertions(+), 316 deletions(-) diff --git a/library/eden/mysql/collection.php b/library/eden/mysql/collection.php index fcbb17d..ab1bf01 100644 --- a/library/eden/mysql/collection.php +++ b/library/eden/mysql/collection.php @@ -98,6 +98,46 @@ public function formatTime($column, $format = Eden_Mysql_Model::DATETIME) { return $this; } + /** + * Insert collection to database + * + * @param string + * @param Eden_Mysql + * @return this + */ + public function insert($table = NULL, Eden_Mysql $database = NULL) { + //for each row + foreach($this->_list as $i => $row) { + if(!is_object($row) || !method_exists($row, 'insert')) { + continue; + } + + $row->insert($table, $database); + } + + return $this; + } + + /** + * Updates collection to database + * + * @param string + * @param Eden_Mysql + * @return this + */ + public function update($table = NULL, Eden_Mysql $database = NULL) { + //for each row + foreach($this->_list as $i => $row) { + if(!is_object($row) || !method_exists($row, 'update')) { + continue; + } + + $row->update($table, $database); + } + + return $this; + } + /** * Inserts or updates collection to database * diff --git a/library/eden/mysql/model.php b/library/eden/mysql/model.php index 84534ac..5a847d3 100644 --- a/library/eden/mysql/model.php +++ b/library/eden/mysql/model.php @@ -1,316 +1,399 @@ - -/* - * 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. - */ - -/** - * Mysql Model - * - * @package Eden - * @category mysql - * @author Christian Blanquera - * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ - */ -class Eden_Mysql_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 - -------------------------------*/ - /* Get - -------------------------------*/ - public static function i() { - $data = self::_getStart(func_get_args()); - return self::_getMultiple(__CLASS__, $data); - } - - /* Magic - -------------------------------*/ - /* Public Methods - -------------------------------*/ - /** - * Sets the default database - * - * @param Eden_Mysql - */ - public function setDatabase(Eden_Mysql $database) { - $this->_database = $database; - return $this; - } - - /** - * Sets the default database - * - * @param string - */ - public function setTable($table) { - //Argument 1 must be a string - Eden_Mysql_Error::i()->argument(1, 'string'); - - $this->_table = $table; - return $this; - } - - /** - * Useful method for formating a time column. - * - * @param string - * @param string - * @return this - */ - public function formatTime($column, $format = self::DATETIME) { - //Argument Test - Eden_Mysql_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 or updates model to database - * - * @param string - * @param Eden_Mysql - * @return this - */ - public function save($table = NULL, Eden_Mysql $database = NULL) { - //Argument 1 must be a string - $error = Eden_Mysql_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_Mysql_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_Mysql_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])); - $primarySet = $this->_isPrimarySet($meta[self::PRIMARY]); - - //update original data - $this->_original = $this->_data; - - //if no primary meta or primary values are not set - if(empty($meta[self::PRIMARY]) || !$primarySet) { - //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; - } - - //from here it means that this table has primary - //columns and all primary values are set - - $filter = array(); - //for each primary key - foreach($meta[self::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; - } - - /** - * Removes model from database - * - * @param string - * @param Eden_Mysql - * @return this - */ - public function remove($table = NULL, Eden_Mysql $database = NULL) { - //Argument 1 must be a string - $error = Eden_Mysql_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_Mysql_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_Mysql_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])); - - $filter = array(); - //for each primary key - foreach($meta[self::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; - } - - /* Protected Methods - -------------------------------*/ - protected function _isPrimarySet(array $primary) { - foreach($primary as $column) { - if(is_null($this[$column])) { - return false; - } - } - - return true; - } - - protected function _getValidColumns($columns) { - $valid = array(); - foreach($columns as $column) { - if(!isset($this->_data[$column])) { - continue; - } - - $valid[$column] = $this->_data[$column]; - } - - return $valid; - } - - 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 _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]); - } - - /* Private Methods - -------------------------------*/ -} - + +/* + * 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. + */ + +/** + * Mysql Model + * + * @package Eden + * @category mysql + * @author Christian Blanquera + * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ + */ +class Eden_Mysql_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 + -------------------------------*/ + /* Get + -------------------------------*/ + public static function i() { + $data = self::_getStart(func_get_args()); + return self::_getMultiple(__CLASS__, $data); + } + + /* Magic + -------------------------------*/ + /* Public Methods + -------------------------------*/ + /** + * Sets the default database + * + * @param Eden_Mysql + */ + public function setDatabase(Eden_Mysql $database) { + $this->_database = $database; + return $this; + } + + /** + * Sets the default database + * + * @param string + */ + public function setTable($table) { + //Argument 1 must be a string + Eden_Mysql_Error::i()->argument(1, 'string'); + + $this->_table = $table; + return $this; + } + + /** + * Useful method for formating a time column. + * + * @param string + * @param string + * @return this + */ + public function formatTime($column, $format = self::DATETIME) { + //Argument Test + Eden_Mysql_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_Mysql + * @return this + */ + public function insert($table = NULL, Eden_Mysql $database = NULL) { + //Argument 1 must be a string + $error = Eden_Mysql_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_Mysql_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_Mysql_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; + } + + /** + * Updates model to database + * + * @param string + * @param Eden_Mysql + * @return this + */ + public function update($table = NULL, Eden_Mysql $database = NULL) { + //Argument 1 must be a string + $error = Eden_Mysql_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_Mysql_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_Mysql_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 + + $filter = array(); + //for each primary key + foreach($meta[self::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; + } + + /** + * Inserts or updates model to database + * + * @param string + * @param Eden_Mysql + * @return this + */ + public function save($table = NULL, Eden_Mysql $database = NULL) { + //Argument 1 must be a string + $error = Eden_Mysql_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_Mysql_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_Mysql_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); + $primarySet = $this->_isPrimarySet($meta[self::PRIMARY]); + + //update original data + $this->_original = $this->_data; + + //if no primary meta or primary values are not set + if(empty($meta[self::PRIMARY]) || !$primarySet) { + return $this->insert($table, $database); + } + + return $this->update($table, $database); + } + + /** + * Removes model from database + * + * @param string + * @param Eden_Mysql + * @return this + */ + public function remove($table = NULL, Eden_Mysql $database = NULL) { + //Argument 1 must be a string + $error = Eden_Mysql_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_Mysql_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_Mysql_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])); + + $filter = array(); + //for each primary key + foreach($meta[self::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; + } + + /* Protected Methods + -------------------------------*/ + protected function _isPrimarySet(array $primary) { + foreach($primary as $column) { + if(is_null($this[$column])) { + return false; + } + } + + return true; + } + + protected function _getValidColumns($columns) { + $valid = array(); + foreach($columns as $column) { + if(!isset($this->_data[$column])) { + continue; + } + + $valid[$column] = $this->_data[$column]; + } + + return $valid; + } + + 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 _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]); + } + + /* Private Methods + -------------------------------*/ +} + From a83cb47e265ef95294c23bdc146fa06f13cbd5f1 Mon Sep 17 00:00:00 2001 From: dmolina Date: Mon, 9 Jan 2012 04:03:06 +0000 Subject: [PATCH 051/330] git-svn-id: http://svn.openovate.com/edenv2/trunk@51 38ede93f-50f4-44af-b0b3-68ccca78c181 --- library/eden/class.php | 381 ++++++++++++++++++++--------------------- 1 file changed, 190 insertions(+), 191 deletions(-) diff --git a/library/eden/class.php b/library/eden/class.php index b2ce2a9..3f4cc1b 100755 --- a/library/eden/class.php +++ b/library/eden/class.php @@ -1,191 +1,190 @@ - -/* - * 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__).'/error.php'; - -/** - * The base class for all classes wishing to integrate with Eve. - * 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 framework - * @author Christian Blanquera - * @version $Id: class.php 1 2010-01-02 23:06:36Z blanquera $ - */ -class Eden_Class { - /* Constants - -------------------------------*/ - /* Public Properties - -------------------------------*/ - /* Protected Properties - -------------------------------*/ - protected $_event = NULL; - protected $_observers = array(); - - /* Private Properties - -------------------------------*/ - private static $_instances = array(); - - /* Get - -------------------------------*/ - /* Magic - -------------------------------*/ - public function __toString() { - return get_class($this); - } - - 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 Methods - -------------------------------*/ - /** - * 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; - } - - /** - * 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); - } - - /** - * Invokes When if conditional is false - * - * @param bool - * @return this|Eden_Noop - */ - public function when($isTrue, $lines) { - if($isTrue) { - return $this; - } - - return Eden_When::i($this, $lines); - } - - /** - * Invokes Chain map - * - * @param bool - * @return this|Eden_Noop - */ - public function loop(array &$list, $lines = 0) { - return Eden_Map::i($this, $list, $lines); - } - - /* Protected Methods - -------------------------------*/ - protected static function _getSingleton($class) { - $class = Eden_Route::i()->getClass()->getRoute($class); - - if(!isset(self::$_instances[$class])) { - $args = func_get_args(); - array_shift($args); - - self::$_instances[$class] = self::_getInstance($class, $args); - } - - return self::$_instances[$class]; - } - - protected static function _getMultiple($class) { - $args = func_get_args(); - $class = array_shift($args); - - $class = Eden_Route::i()->getClass()->getRoute($class); - - return self::_getInstance($class, $args); - } - - /* Private Methods - -------------------------------*/ - private static function _getInstance($class, $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(); - } - } -} - -require_once dirname(__FILE__).'/route.php'; -require_once dirname(__FILE__).'/when.php'; -require_once dirname(__FILE__).'/map.php'; \ No newline at end of file + +/* + * 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__).'/error.php'; +require_once dirname(__FILE__).'/route.php'; +require_once dirname(__FILE__).'/when.php'; +require_once dirname(__FILE__).'/map.php'; + +/** + * The base class for all classes wishing to integrate with Eve. + * 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 framework + * @author Christian Blanquera + * @version $Id: class.php 1 2010-01-02 23:06:36Z blanquera $ + */ +class Eden_Class { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_event = NULL; + protected $_observers = array(); + + /* Private Properties + -------------------------------*/ + private static $_instances = array(); + + /* Get + -------------------------------*/ + /* Magic + -------------------------------*/ + public function __toString() { + return get_class($this); + } + + 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 Methods + -------------------------------*/ + /** + * 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; + } + + /** + * 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); + } + + /** + * Invokes When if conditional is false + * + * @param bool + * @return this|Eden_Noop + */ + public function when($isTrue, $lines) { + if($isTrue) { + return $this; + } + + return Eden_When::i($this, $lines); + } + + /** + * Invokes Chain map + * + * @param bool + * @return this|Eden_Noop + */ + public function loop(array &$list, $lines = 0) { + return Eden_Map::i($this, $list, $lines); + } + + /* Protected Methods + -------------------------------*/ + protected static function _getSingleton($class) { + $class = Eden_Route::i()->getClass()->getRoute($class); + + if(!isset(self::$_instances[$class])) { + $args = func_get_args(); + array_shift($args); + + self::$_instances[$class] = self::_getInstance($class, $args); + } + + return self::$_instances[$class]; + } + + protected static function _getMultiple($class) { + $args = func_get_args(); + $class = array_shift($args); + + $class = Eden_Route::i()->getClass()->getRoute($class); + + return self::_getInstance($class, $args); + } + + /* Private Methods + -------------------------------*/ + private static function _getInstance($class, $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 From 663fa76fd33ca19b2f49cffcaf314afc98723e75 Mon Sep 17 00:00:00 2001 From: dmolina Date: Tue, 10 Jan 2012 01:25:18 +0000 Subject: [PATCH 052/330] updates on mysql queries git-svn-id: http://svn.openovate.com/edenv2/trunk@52 38ede93f-50f4-44af-b0b3-68ccca78c181 --- library/eden/class.php | 2 +- library/eden/mysql.php | 12 +- library/eden/mysql/search.php | 1012 +++++++++++++++++---------------- 3 files changed, 520 insertions(+), 506 deletions(-) diff --git a/library/eden/class.php b/library/eden/class.php index 3f4cc1b..fd59706 100755 --- a/library/eden/class.php +++ b/library/eden/class.php @@ -126,7 +126,7 @@ public function callThis($method, array $args = array()) { * @param bool * @return this|Eden_Noop */ - public function when($isTrue, $lines) { + public function when($isTrue, $lines = 0) { if($isTrue) { return $this; } diff --git a/library/eden/mysql.php b/library/eden/mysql.php index 49a2ce8..0bc048e 100755 --- a/library/eden/mysql.php +++ b/library/eden/mysql.php @@ -851,12 +851,22 @@ public function bind($value) { * * @param void * @return array - * @notes returns all the binds stored in registry */ public function getBinds() { return $this->_binds; } + /** + * Sets all the bound values of this query + * + * @param array + * @return this + */ + public function setBinds(array $binds) { + $this->_binds = $binds; + return $this; + } + /* Protected Methods -------------------------------*/ /* Private Methods diff --git a/library/eden/mysql/search.php b/library/eden/mysql/search.php index 8142ec5..851e629 100644 --- a/library/eden/mysql/search.php +++ b/library/eden/mysql/search.php @@ -1,505 +1,509 @@ - -/* - * 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. - */ - -/** - * Mysql Collection handler - * - * @package Eden - * @category mysql - * @author Christian Blanquera - * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ - */ -class Eden_Mysql_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 $_join = array(); - protected $_filter = array(); - protected $_sort = array(); - protected $_group = array(); - protected $_start = 0; - protected $_range = 0; - - protected $_collection = 'Eden_Mysql_Collection'; - - /* Private Properties - -------------------------------*/ - /* Get - -------------------------------*/ - public static function i(Eden_Mysql $database) { - return self::_getMultiple(__CLASS__,$database); - } - - /* Magic - -------------------------------*/ - public function __construct(Eden_Mysql $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-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_Mysql_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_Mysql_Error::i()->argument(1, 'string'); - $this->_table = $table; - return $this; - } - - /** - * Adds Inner Join On - * - * @param string - * @param string[,string..] - * @return this - */ - public function addInnerJoinOn($table, $where) { - Eden_Mysql_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_Mysql_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_Mysql_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_Mysql_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 Right Join On - * - * @param string - * @param string[,string..] - * @return this - */ - public function addRightJoinOn($table, $where) { - Eden_Mysql_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_Mysql_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 Outer Join On - * - * @param string - * @param string[,string..] - * @return this - */ - public function addOuterJoinOn($table, $where) { - Eden_Mysql_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_Mysql_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 filter - * - * @param string - * @param string[,string..] - * @return this - */ - public function addFilter() { - Eden_Mysql_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_Mysql_Error::i() - ->argument(1, 'string') - ->argument(2, 'string'); - - if($order != self::DESC) { - $order = self::ASC; - } - - $this->_sort[$column] = $order; - - 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_Mysql_Error::i()->argument(1, 'string', 'array'); - - if(is_string($group)) { - $group = array($group); - } - - $this->_group = $group; - return $this; - } - - /** - * Sets the pagination start - * - * @param int - * @return this - */ - public function setStart($start) { - Eden_Mysql_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_Mysql_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_Mysql_Error::i()->argument(1, 'int'); - - if($page < 1) { - $page = 1; - } - - $this->_start = ($page - 1) * $this->_range; - - return $this; - } - - /** - * Returns the results in a collection - * - * @return Eden_Mysql_Collection - */ - public function getCollection() { - $collection = $this->_collection; - return $this->$collection($this->getRows()) - ->setDatabase($this->_database) - ->setTable($this->_table); - } - - /** - * Returns the array rows - * - * @return array - */ - public function getRows() { - $database = $this->_database; - - $query = $this->_getQuery($database); - - 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 $database->query($query, $database->getBinds()); - } - - /** - * Returns the total results - * - * @return int - */ - public function getTotal() { - $database = $this->_database; - $query = $this->_getQuery($database)->select('COUNT(*) as total'); - - $rows = $database->query($query, $database->getBinds()); - - return $rows[0]['total']; - } - - /* Protected Methods - -------------------------------*/ - protected function _getQuery($database) { - $query = $database->select()->from($this->_table); - - foreach($this->_join as $join) { - - $where = array_shift($join[2]); - if(!empty($join[2])) { - foreach($join[2] as $i => $value) { - $join[2][$i] = $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] = $database->bind($value); - } - - $where = vsprintf($where, $filter); - } - - $query->where($where); - } - - return $query; - } - - /* Private Methods - -------------------------------*/ + +/* + * 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. + */ + +/** + * Mysql Collection handler + * + * @package Eden + * @category mysql + * @author Christian Blanquera + * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ + */ +class Eden_Mysql_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 $_join = array(); + protected $_filter = array(); + protected $_sort = array(); + protected $_group = array(); + protected $_start = 0; + protected $_range = 0; + + protected $_collection = 'Eden_Mysql_Collection'; + + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function i(Eden_Mysql $database) { + return self::_getMultiple(__CLASS__,$database); + } + + /* Magic + -------------------------------*/ + public function __construct(Eden_Mysql $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-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_Mysql_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_Mysql_Error::i()->argument(1, 'string'); + $this->_table = $table; + return $this; + } + + /** + * Adds Inner Join On + * + * @param string + * @param string[,string..] + * @return this + */ + public function addInnerJoinOn($table, $where) { + Eden_Mysql_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_Mysql_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_Mysql_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_Mysql_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 Right Join On + * + * @param string + * @param string[,string..] + * @return this + */ + public function addRightJoinOn($table, $where) { + Eden_Mysql_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_Mysql_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 Outer Join On + * + * @param string + * @param string[,string..] + * @return this + */ + public function addOuterJoinOn($table, $where) { + Eden_Mysql_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_Mysql_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 filter + * + * @param string + * @param string[,string..] + * @return this + */ + public function addFilter() { + Eden_Mysql_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_Mysql_Error::i() + ->argument(1, 'string') + ->argument(2, 'string'); + + if($order != self::DESC) { + $order = self::ASC; + } + + $this->_sort[$column] = $order; + + 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_Mysql_Error::i()->argument(1, 'string', 'array'); + + if(is_string($group)) { + $group = array($group); + } + + $this->_group = $group; + return $this; + } + + /** + * Sets the pagination start + * + * @param int + * @return this + */ + public function setStart($start) { + Eden_Mysql_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_Mysql_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_Mysql_Error::i()->argument(1, 'int'); + + if($page < 1) { + $page = 1; + } + + $this->_start = ($page - 1) * $this->_range; + + return $this; + } + + /** + * Returns the results in a collection + * + * @return Eden_Mysql_Collection + */ + public function getCollection() { + $collection = $this->_collection; + return $this->$collection($this->getRows()) + ->setDatabase($this->_database) + ->setTable($this->_table); + } + + /** + * 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']; + } + + /* 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 From 4e3f83c3835c1758047d222d57193bc1916681e1 Mon Sep 17 00:00:00 2001 From: cblanquera Date: Tue, 10 Jan 2012 06:25:28 +0000 Subject: [PATCH 053/330] global change to how i works. You no longer need to care about the arguments being passed git-svn-id: http://svn.openovate.com/edenv2/trunk@53 38ede93f-50f4-44af-b0b3-68ccca78c181 --- library/eden/amazon/s3.php | 4 +- library/eden/block/pagination.php | 4 +- library/eden/cache.php | 4 +- library/eden/class.php | 382 ++--- library/eden/collection.php | 46 +- library/eden/eventbrite/base.php | 4 +- library/eden/eventbrite/discount.php | 4 +- library/eden/eventbrite/event.php | 4 +- library/eden/eventbrite/event/search.php | 4 +- library/eden/eventbrite/event/set.php | 4 +- library/eden/eventbrite/organizer.php | 4 +- library/eden/eventbrite/payment.php | 4 +- library/eden/eventbrite/ticket.php | 4 +- library/eden/eventbrite/user.php | 4 +- library/eden/eventbrite/venue.php | 4 +- library/eden/facebook/auth.php | 4 +- library/eden/facebook/graph.php | 4 +- library/eden/facebook/post.php | 4 +- library/eden/file.php | 4 +- library/eden/folder.php | 4 +- library/eden/getsatisfaction/company.php | 4 +- library/eden/getsatisfaction/detail.php | 4 +- library/eden/getsatisfaction/oauth.php | 4 +- library/eden/getsatisfaction/people.php | 4 +- library/eden/getsatisfaction/post.php | 4 +- library/eden/getsatisfaction/product.php | 4 +- library/eden/getsatisfaction/replies.php | 4 +- library/eden/getsatisfaction/tag.php | 4 +- library/eden/getsatisfaction/topic.php | 4 +- library/eden/google/calendar.php | 4 +- library/eden/google/contacts.php | 4 +- library/eden/google/docs.php | 4 +- library/eden/google/gmail.php | 4 +- library/eden/google/oauth.php | 4 +- library/eden/google/shortener.php | 4 +- library/eden/image.php | 4 +- library/eden/map.php | 8 +- library/eden/memcache.php | 4 +- library/eden/mysql.php | 1800 +++++++++++----------- library/eden/mysql/alter.php | 4 +- library/eden/mysql/collection.php | 370 ++--- library/eden/mysql/create.php | 4 +- library/eden/mysql/error.php | 3 + library/eden/mysql/model.php | 797 +++++----- library/eden/mysql/search.php | 1035 +++++++------ library/eden/mysql/subselect.php | 4 +- library/eden/oauth/consumer.php | 4 +- library/eden/path.php | 4 +- library/eden/registry.php | 28 +- library/eden/sql/delete.php | 4 +- library/eden/sql/insert.php | 4 +- library/eden/sql/select.php | 4 +- library/eden/sql/update.php | 4 +- library/eden/tumblr/blog.php | 5 +- library/eden/tumblr/oauth.php | 4 +- library/eden/tumblr/user.php | 5 +- library/eden/twitter/accounts.php | 4 +- library/eden/twitter/directmessage.php | 5 +- library/eden/twitter/favorites.php | 4 +- library/eden/twitter/friends.php | 5 +- library/eden/twitter/list.php | 4 +- library/eden/twitter/oauth.php | 4 +- library/eden/twitter/search.php | 5 +- library/eden/twitter/suggestions.php | 4 +- library/eden/twitter/timelines.php | 5 +- library/eden/twitter/tweets.php | 4 +- library/eden/twitter/users.php | 4 +- library/eden/type.php | 4 - library/eden/type/abstract.php | 10 + library/eden/type/array.php | 34 +- library/eden/type/string.php | 17 +- library/eden/validation.php | 4 +- library/eden/webcharge.php | 4 +- library/eden/when.php | 4 +- 74 files changed, 2453 insertions(+), 2331 deletions(-) diff --git a/library/eden/amazon/s3.php b/library/eden/amazon/s3.php index 502c2fa..743a88f 100644 --- a/library/eden/amazon/s3.php +++ b/library/eden/amazon/s3.php @@ -39,8 +39,8 @@ class Eden_Amazon_S3 extends Eden_Class { -------------------------------*/ /* Get -------------------------------*/ - public static function i($user, $pass, $host = 's3.amazonaws.com', $ssl = false) { - return self::_getMultiple(__CLASS__, $user, $pass, $host, $ssl); + public static function i() { + return self::_getMultiple(__CLASS__); } /* Magic diff --git a/library/eden/block/pagination.php b/library/eden/block/pagination.php index 68a2793..829588f 100644 --- a/library/eden/block/pagination.php +++ b/library/eden/block/pagination.php @@ -35,8 +35,8 @@ class Eden_Block_Pagination extends Eden_Block { -------------------------------*/ /* Get -------------------------------*/ - public static function i($total) { - return self::_getMultiple(__CLASS__, $total); + public static function i() { + return self::_getMultiple(__CLASS__); } /* Magic diff --git a/library/eden/cache.php b/library/eden/cache.php index b3ba6e5..8af1beb 100755 --- a/library/eden/cache.php +++ b/library/eden/cache.php @@ -39,8 +39,8 @@ class Eden_Cache extends Eden_Class { -------------------------------*/ /* Get -------------------------------*/ - public static function i($root, $key = 'key.php') { - return self::_getMultiple(__CLASS__, $root, $key); + public static function i() { + return self::_getMultiple(__CLASS__); } /* Magic diff --git a/library/eden/class.php b/library/eden/class.php index fd59706..9e26741 100755 --- a/library/eden/class.php +++ b/library/eden/class.php @@ -1,190 +1,194 @@ - -/* - * 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__).'/error.php'; -require_once dirname(__FILE__).'/route.php'; -require_once dirname(__FILE__).'/when.php'; -require_once dirname(__FILE__).'/map.php'; - -/** - * The base class for all classes wishing to integrate with Eve. - * 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 framework - * @author Christian Blanquera - * @version $Id: class.php 1 2010-01-02 23:06:36Z blanquera $ - */ -class Eden_Class { - /* Constants - -------------------------------*/ - /* Public Properties - -------------------------------*/ - /* Protected Properties - -------------------------------*/ - protected $_event = NULL; - protected $_observers = array(); - - /* Private Properties - -------------------------------*/ - private static $_instances = array(); - - /* Get - -------------------------------*/ - /* Magic - -------------------------------*/ - public function __toString() { - return get_class($this); - } - - 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 Methods - -------------------------------*/ - /** - * 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; - } - - /** - * 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); - } - - /** - * 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); - } - - /** - * Invokes Chain map - * - * @param bool - * @return this|Eden_Noop - */ - public function loop(array &$list, $lines = 0) { - return Eden_Map::i($this, $list, $lines); - } - - /* Protected Methods - -------------------------------*/ - protected static function _getSingleton($class) { - $class = Eden_Route::i()->getClass()->getRoute($class); - - if(!isset(self::$_instances[$class])) { - $args = func_get_args(); - array_shift($args); - - self::$_instances[$class] = self::_getInstance($class, $args); - } - - return self::$_instances[$class]; - } - - protected static function _getMultiple($class) { - $args = func_get_args(); - $class = array_shift($args); - - $class = Eden_Route::i()->getClass()->getRoute($class); - - return self::_getInstance($class, $args); - } - - /* Private Methods - -------------------------------*/ - private static function _getInstance($class, $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(); - } - } + +/* + * 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__).'/error.php'; +require_once dirname(__FILE__).'/route.php'; +require_once dirname(__FILE__).'/when.php'; +require_once dirname(__FILE__).'/map.php'; + +/** + * The base class for all classes wishing to integrate with Eve. + * 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 framework + * @author Christian Blanquera + * @version $Id: class.php 1 2010-01-02 23:06:36Z blanquera $ + */ +class Eden_Class { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_event = NULL; + protected $_observers = array(); + + /* Private Properties + -------------------------------*/ + private static $_instances = array(); + + /* Get + -------------------------------*/ + /* Magic + -------------------------------*/ + public function __toString() { + return get_class($this); + } + + 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 Methods + -------------------------------*/ + /** + * 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; + } + + /** + * 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); + } + + /** + * 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); + } + + /** + * Invokes Chain map + * + * @param bool + * @return this|Eden_Noop + */ + public function loop(array &$list, $lines = 0) { + return Eden_Map::i($this, $list, $lines); + } + + /* Protected Methods + -------------------------------*/ + protected static function _getSingleton($class) { + $class = Eden_Route::i()->getClass()->getRoute($class); + + if(!isset(self::$_instances[$class])) { + self::$_instances[$class] = self::_getInstance($class); + } + + return self::$_instances[$class]; + } + + protected static function _getMultiple($class) { + $class = Eden_Route::i()->getClass()->getRoute($class); + return self::_getInstance($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 index b87b41d..7b7ca5f 100644 --- a/library/eden/collection.php +++ b/library/eden/collection.php @@ -20,28 +20,27 @@ class Eden_Collection extends Eden_Class implements ArrayAccess, Iterator, Seria -------------------------------*/ const FIRST = 'first'; const LAST = 'last'; + const MODEL = 'Eden_Model'; /* Public Properties -------------------------------*/ /* Protected Properties -------------------------------*/ protected $_list = array(); - protected $_model = 'Eden_Model'; + protected $_model = self::MODEL; /* Private Properties -------------------------------*/ /* Get -------------------------------*/ - public static function i(array $data = array()) { - return self::_getMultiple(__CLASS__,$data); + public static function i() { + return self::_getMultiple(__CLASS__); } /* Magic -------------------------------*/ public function __construct(array $data = array()) { - foreach($data as $row) { - $this->add($row); - } + $this->set($data); } public function __call($name, $args) { @@ -113,6 +112,38 @@ public function __toString() { /* Public Methods -------------------------------*/ + /** + * Sets default model + * + * @param string + * @return this + */ + public function setModel($model) { + $error = Eden_Collection_Error::get()->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 + * + * @return this + */ + public function set(array $data = array()) { + foreach($data as $row) { + $this->add($row); + } + + return $this; + } + /** * Adds a row to the collection * @@ -351,7 +382,8 @@ public function count() { class Eden_Collection_Error extends Eden_Error { /* Constants -------------------------------*/ - const NOT_COLLECTION = 'The data passed into __construct is not a collection.'; + 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 -------------------------------*/ diff --git a/library/eden/eventbrite/base.php b/library/eden/eventbrite/base.php index ec6f45d..6ca7aaa 100644 --- a/library/eden/eventbrite/base.php +++ b/library/eden/eventbrite/base.php @@ -30,8 +30,8 @@ class Eden_Eventbrite_Base extends Eden_Class { -------------------------------*/ /* Get -------------------------------*/ - public static function i($user, $api) { - return self::_getMultiple(__CLASS__, $user, $api); + public static function i() { + return self::_getMultiple(__CLASS__); } /* Magic diff --git a/library/eden/eventbrite/discount.php b/library/eden/eventbrite/discount.php index eff8122..d389fa6 100644 --- a/library/eden/eventbrite/discount.php +++ b/library/eden/eventbrite/discount.php @@ -31,8 +31,8 @@ class Eden_Eventbrite_Discount extends Eden_Eventbrite_Base { -------------------------------*/ /* Get -------------------------------*/ - public static function i($user, $api) { - return self::_getMultiple(__CLASS__, $user, $api); + public static function i() { + return self::_getMultiple(__CLASS__); } /* Magic diff --git a/library/eden/eventbrite/event.php b/library/eden/eventbrite/event.php index f48a2e3..6f5228b 100644 --- a/library/eden/eventbrite/event.php +++ b/library/eden/eventbrite/event.php @@ -33,8 +33,8 @@ class Eden_Eventbrite_Event extends Eden_Eventbrite_Base { -------------------------------*/ /* Get -------------------------------*/ - public static function i($user, $api) { - return self::_getMultiple(__CLASS__, $user, $api); + public static function i() { + return self::_getMultiple(__CLASS__); } /* Magic diff --git a/library/eden/eventbrite/event/search.php b/library/eden/eventbrite/event/search.php index 578287a..85b60a3 100644 --- a/library/eden/eventbrite/event/search.php +++ b/library/eden/eventbrite/event/search.php @@ -30,8 +30,8 @@ class Eden_Eventbrite_Event_Search extends Eden_Eventbrite_Base { -------------------------------*/ /* Get -------------------------------*/ - public static function i($user, $api) { - return self::_getMultiple(__CLASS__, $user, $api); + public static function i() { + return self::_getMultiple(__CLASS__); } /* Magic diff --git a/library/eden/eventbrite/event/set.php b/library/eden/eventbrite/event/set.php index 5508d11..81700b4 100644 --- a/library/eden/eventbrite/event/set.php +++ b/library/eden/eventbrite/event/set.php @@ -31,8 +31,8 @@ class Eden_Eventbrite_Event_Set extends Eden_Eventbrite_Base { -------------------------------*/ /* Get -------------------------------*/ - public static function i($user, $api) { - return self::_getMultiple(__CLASS__, $user, $api); + public static function i() { + return self::_getMultiple(__CLASS__); } /* Magic diff --git a/library/eden/eventbrite/organizer.php b/library/eden/eventbrite/organizer.php index 7f0843b..261b263 100644 --- a/library/eden/eventbrite/organizer.php +++ b/library/eden/eventbrite/organizer.php @@ -30,8 +30,8 @@ class Eden_Eventbrite_Event_Organizer extends Eden_Eventbrite_Base { -------------------------------*/ /* Get -------------------------------*/ - public static function i($user, $api) { - return self::_getMultiple(__CLASS__, $user, $api); + public static function i() { + return self::_getMultiple(__CLASS__); } /* Magic diff --git a/library/eden/eventbrite/payment.php b/library/eden/eventbrite/payment.php index 3de6816..085a445 100644 --- a/library/eden/eventbrite/payment.php +++ b/library/eden/eventbrite/payment.php @@ -30,8 +30,8 @@ class Eden_Eventbrite_Payment extends Eden_Eventbrite_Base { -------------------------------*/ /* Get -------------------------------*/ - public static function i($user, $api) { - return self::_getMultiple(__CLASS__, $user, $api); + public static function i() { + return self::_getMultiple(__CLASS__); } /* Magic diff --git a/library/eden/eventbrite/ticket.php b/library/eden/eventbrite/ticket.php index 7f717a8..9d6b9d2 100644 --- a/library/eden/eventbrite/ticket.php +++ b/library/eden/eventbrite/ticket.php @@ -31,8 +31,8 @@ class Eden_Eventbrite_Ticket extends Eden_Eventbrite_Base { -------------------------------*/ /* Get -------------------------------*/ - public static function i($user, $api) { - return self::_getMultiple(__CLASS__, $user, $api); + public static function i() { + return self::_getMultiple(__CLASS__); } /* Magic diff --git a/library/eden/eventbrite/user.php b/library/eden/eventbrite/user.php index 3e8674a..d1ac5b8 100644 --- a/library/eden/eventbrite/user.php +++ b/library/eden/eventbrite/user.php @@ -39,8 +39,8 @@ class Eden_Eventbrite_User extends Eden_Eventbrite_Base { -------------------------------*/ /* Get -------------------------------*/ - public static function i($user, $api) { - return self::_getMultiple(__CLASS__, $user, $api); + public static function i() { + return self::_getMultiple(__CLASS__); } /* Magic diff --git a/library/eden/eventbrite/venue.php b/library/eden/eventbrite/venue.php index 6abe055..f211f69 100644 --- a/library/eden/eventbrite/venue.php +++ b/library/eden/eventbrite/venue.php @@ -31,8 +31,8 @@ class Eden_Eventbrite_Venue extends Eden_Eventbrite_Base { -------------------------------*/ /* Get -------------------------------*/ - public static function i($user, $api) { - return self::_getMultiple(__CLASS__, $user, $api); + public static function i() { + return self::_getMultiple(__CLASS__); } /* Magic -------------------------------*/ diff --git a/library/eden/facebook/auth.php b/library/eden/facebook/auth.php index 0ad559c..7ed353d 100644 --- a/library/eden/facebook/auth.php +++ b/library/eden/facebook/auth.php @@ -34,8 +34,8 @@ class Eden_Facebook_Auth extends Eden_Class { -------------------------------*/ /* Get -------------------------------*/ - public static function i($key, $secret) { - return self::_getMultiple(__CLASS__, $key, $secret); + public static function i() { + return self::_getMultiple(__CLASS__); } /* Magic diff --git a/library/eden/facebook/graph.php b/library/eden/facebook/graph.php index 9c484b4..47204f6 100644 --- a/library/eden/facebook/graph.php +++ b/library/eden/facebook/graph.php @@ -32,8 +32,8 @@ class Eden_Facebook_Graph extends Eden_Class { -------------------------------*/ /* Get -------------------------------*/ - public static function i($token) { - return self::_getMultiple(__CLASS__, $token); + public static function i() { + return self::_getMultiple(__CLASS__); } /* Magic diff --git a/library/eden/facebook/post.php b/library/eden/facebook/post.php index 5c5e7c8..331a910 100644 --- a/library/eden/facebook/post.php +++ b/library/eden/facebook/post.php @@ -35,8 +35,8 @@ class Eden_Facebook_Post extends Eden_Class { -------------------------------*/ /* Get -------------------------------*/ - public static function i($token) { - return self::_getMultiple(__CLASS__, $token); + public static function i() { + return self::_getMultiple(__CLASS__); } /* Magic diff --git a/library/eden/file.php b/library/eden/file.php index 13d86df..d23390b 100644 --- a/library/eden/file.php +++ b/library/eden/file.php @@ -32,8 +32,8 @@ class Eden_File extends Eden_Path { -------------------------------*/ /* Get -------------------------------*/ - public static function i($path) { - return self::_getMultiple(__CLASS__, $path); + public static function i() { + return self::_getMultiple(__CLASS__); } /* Magic diff --git a/library/eden/folder.php b/library/eden/folder.php index 558c832..025b096 100644 --- a/library/eden/folder.php +++ b/library/eden/folder.php @@ -30,8 +30,8 @@ class Eden_Folder extends Eden_Path { -------------------------------*/ /* Get -------------------------------*/ - public static function i($path) { - return self::_getMultiple(__CLASS__, $path); + public static function i() { + return self::_getMultiple(__CLASS__); } /* Magic diff --git a/library/eden/getsatisfaction/company.php b/library/eden/getsatisfaction/company.php index 0763922..7b83746 100644 --- a/library/eden/getsatisfaction/company.php +++ b/library/eden/getsatisfaction/company.php @@ -34,8 +34,8 @@ class Eden_GetSatisfaction_Company extends Eden_Getsatisfaction_Base { -------------------------------*/ /* Get -------------------------------*/ - public static function i($key, $secret) { - return self::_getMultiple(__CLASS__, $key, $secret); + public static function i() { + return self::_getMultiple(__CLASS__); } /* Magic diff --git a/library/eden/getsatisfaction/detail.php b/library/eden/getsatisfaction/detail.php index bd8baad..7eb3ccf 100644 --- a/library/eden/getsatisfaction/detail.php +++ b/library/eden/getsatisfaction/detail.php @@ -28,8 +28,8 @@ class Eden_GetSatisfaction_Detail extends Eden_GetSatisfaction_Base { -------------------------------*/ /* Get -------------------------------*/ - public static function i($key, $secret) { - return self::_getMultiple(__CLASS__, $key, $secret); + public static function i() { + return self::_getMultiple(__CLASS__); } /* Magic diff --git a/library/eden/getsatisfaction/oauth.php b/library/eden/getsatisfaction/oauth.php index 69ff42a..f530033 100644 --- a/library/eden/getsatisfaction/oauth.php +++ b/library/eden/getsatisfaction/oauth.php @@ -29,8 +29,8 @@ class Eden_Getsatisfaction_Oauth extends Eden_Getsatisfaction_Base { -------------------------------*/ /* Get -------------------------------*/ - public static function i($key, $secret) { - return self::_getMultiple(__CLASS__, $key, $secret); + public static function i() { + return self::_getMultiple(__CLASS__); } /* Magic diff --git a/library/eden/getsatisfaction/people.php b/library/eden/getsatisfaction/people.php index 39b4fc9..95161ca 100644 --- a/library/eden/getsatisfaction/people.php +++ b/library/eden/getsatisfaction/people.php @@ -34,8 +34,8 @@ class Eden_GetSatisfaction_People extends Eden_GetSatisfaction_Base { -------------------------------*/ /* Get -------------------------------*/ - public static function i($key, $secret) { - return self::_getMultiple(__CLASS__, $key, $secret); + public static function i() { + return self::_getMultiple(__CLASS__); } /* Magic diff --git a/library/eden/getsatisfaction/post.php b/library/eden/getsatisfaction/post.php index b318af2..c5b5c48 100644 --- a/library/eden/getsatisfaction/post.php +++ b/library/eden/getsatisfaction/post.php @@ -28,8 +28,8 @@ class Eden_Getsatisfaction_Post extends Eden_Getsatisfaction_Base { -------------------------------*/ /* Get -------------------------------*/ - public static function i($key, $secret) { - return self::_getMultiple(__CLASS__, $key, $secret); + public static function i() { + return self::_getMultiple(__CLASS__); } /* Magic diff --git a/library/eden/getsatisfaction/product.php b/library/eden/getsatisfaction/product.php index e2cff6e..d98dcbf 100644 --- a/library/eden/getsatisfaction/product.php +++ b/library/eden/getsatisfaction/product.php @@ -43,8 +43,8 @@ class Eden_GetSatisfaction_Product extends Eden_GetSatisfaction_Base { -------------------------------*/ /* Get -------------------------------*/ - public static function i($key, $secret) { - return self::_getMultiple(__CLASS__, $key, $secret); + public static function i() { + return self::_getMultiple(__CLASS__); } /* Magic diff --git a/library/eden/getsatisfaction/replies.php b/library/eden/getsatisfaction/replies.php index 61b81b4..6ed9a27 100644 --- a/library/eden/getsatisfaction/replies.php +++ b/library/eden/getsatisfaction/replies.php @@ -34,8 +34,8 @@ class Eden_Getsatisfaction_Replies extends Eden_Getsatisfaction_Base { -------------------------------*/ /* Get -------------------------------*/ - public static function i($key, $secret) { - return self::_getMultiple(__CLASS__, $key, $secret); + public static function i() { + return self::_getMultiple(__CLASS__); } /* Magic diff --git a/library/eden/getsatisfaction/tag.php b/library/eden/getsatisfaction/tag.php index 7907e5c..cf4e4b1 100644 --- a/library/eden/getsatisfaction/tag.php +++ b/library/eden/getsatisfaction/tag.php @@ -33,8 +33,8 @@ class Eden_GetSatisfaction_Tag extends Eden_GetSatisfaction_Base { -------------------------------*/ /* Get -------------------------------*/ - public static function i($key, $secret) { - return self::_getMultiple(__CLASS__, $key, $secret); + public static function i() { + return self::_getMultiple(__CLASS__); } /* Magic diff --git a/library/eden/getsatisfaction/topic.php b/library/eden/getsatisfaction/topic.php index a03b682..c7880c1 100644 --- a/library/eden/getsatisfaction/topic.php +++ b/library/eden/getsatisfaction/topic.php @@ -37,8 +37,8 @@ class Eden_GetSatisfaction_Topic extends Eden_GetSatisfaction_Base { -------------------------------*/ /* Get -------------------------------*/ - public static function i($key, $secret) { - return self::_getMultiple(__CLASS__, $key, $secret); + public static function i() { + return self::_getMultiple(__CLASS__); } /* Magic diff --git a/library/eden/google/calendar.php b/library/eden/google/calendar.php index 981198e..9b57e07 100644 --- a/library/eden/google/calendar.php +++ b/library/eden/google/calendar.php @@ -29,8 +29,8 @@ class Eden_Google_Calendar extends Eden_Google_Base { -------------------------------*/ /* Get -------------------------------*/ - public static function i($key, $secret) { - return self::_getMultiple(__CLASS__, $key, $secret); + public static function i() { + return self::_getMultiple(__CLASS__); } /* Magic diff --git a/library/eden/google/contacts.php b/library/eden/google/contacts.php index c9278e5..b4493bb 100644 --- a/library/eden/google/contacts.php +++ b/library/eden/google/contacts.php @@ -28,8 +28,8 @@ class Eden_Google_Contacts extends Eden_Google_Base { -------------------------------*/ /* Get -------------------------------*/ - public static function i($key, $secret) { - return self::_getMultiple(__CLASS__, $key, $secret); + public static function i() { + return self::_getMultiple(__CLASS__); } /* Magic diff --git a/library/eden/google/docs.php b/library/eden/google/docs.php index 5a0dae3..f3938b4 100644 --- a/library/eden/google/docs.php +++ b/library/eden/google/docs.php @@ -28,8 +28,8 @@ class Eden_Google_Docs extends Eden_Google_Base { -------------------------------*/ /* Get -------------------------------*/ - public static function i($key, $secret) { - return self::_getMultiple(__CLASS__, $key, $secret); + public static function i() { + return self::_getMultiple(__CLASS__); } /* Magic diff --git a/library/eden/google/gmail.php b/library/eden/google/gmail.php index 011d07d..dee1149 100644 --- a/library/eden/google/gmail.php +++ b/library/eden/google/gmail.php @@ -28,8 +28,8 @@ class Eden_Google_Gmail extends Eden_Google_Base { -------------------------------*/ /* Get -------------------------------*/ - public static function i($key, $secret) { - return self::_getMultiple(__CLASS__, $key, $secret); + public static function i() { + return self::_getMultiple(__CLASS__); } /* Magic diff --git a/library/eden/google/oauth.php b/library/eden/google/oauth.php index f7588d3..5fb2a11 100644 --- a/library/eden/google/oauth.php +++ b/library/eden/google/oauth.php @@ -30,8 +30,8 @@ class Eden_Google_Oauth extends Eden_Google_Base { -------------------------------*/ /* Get -------------------------------*/ - public static function i($key, $secret, $scope) { - return self::_getMultiple(__CLASS__, $key, $secret, $scope); + public static function i() { + return self::_getMultiple(__CLASS__); } /* Magic diff --git a/library/eden/google/shortener.php b/library/eden/google/shortener.php index ace62a9..fea5fa3 100644 --- a/library/eden/google/shortener.php +++ b/library/eden/google/shortener.php @@ -32,8 +32,8 @@ class Eden_Google_Shortener extends Eden_Class { -------------------------------*/ /* Get -------------------------------*/ - public static function i($key) { - return self::_getMultiple(__CLASS__, $key); + public static function i() { + return self::_getMultiple(__CLASS__); } /* Magic diff --git a/library/eden/image.php b/library/eden/image.php index 31c3802..8091826 100644 --- a/library/eden/image.php +++ b/library/eden/image.php @@ -39,8 +39,8 @@ class Eden_Image extends Eden_Class { -------------------------------*/ /* Get -------------------------------*/ - public static function i($data, $type = NULL, $path = true, $quality = 75) { - return self::_getMultiple(__CLASS__, $data, $type, $path, $quality); + public static function i() { + return self::_getMultiple(__CLASS__); } /* Magic diff --git a/library/eden/map.php b/library/eden/map.php index a5af27e..05b8cf4 100644 --- a/library/eden/map.php +++ b/library/eden/map.php @@ -34,15 +34,15 @@ class Eden_Map extends Eden_Class { -------------------------------*/ /* Get -------------------------------*/ - public static function i($scope, array &$list, $lines = 0) { - return self::_getMultiple(__CLASS__, $scope, $list, $lines); + public static function i() { + return self::_getMultiple(__CLASS__); } /* Magic -------------------------------*/ - public function __construct($scope, array &$list, $lines = 0) { + public function __construct($scope, array $list, $lines = 0) { $this->_scope = $scope; - $this->_list = &$list; + $this->_list = $list; $this->_lines = $lines; } diff --git a/library/eden/memcache.php b/library/eden/memcache.php index cd88227..5c32378 100755 --- a/library/eden/memcache.php +++ b/library/eden/memcache.php @@ -38,8 +38,8 @@ class Eden_Memcache extends Eden_Class { -------------------------------*/ /* Get -------------------------------*/ - public static function i($host = 'localhost', $port = 11211, $timeout = 1) { - return self::_getMultiple(__CLASS__, $host, $port, $timeout); + public static function i() { + return self::_getMultiple(__CLASS__); } /* Magic diff --git a/library/eden/mysql.php b/library/eden/mysql.php index 0bc048e..f1b5afa 100755 --- a/library/eden/mysql.php +++ b/library/eden/mysql.php @@ -1,875 +1,925 @@ - -/* - * 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__).'/event.php'; -require_once dirname(__FILE__).'/sql/error.php'; -require_once dirname(__FILE__).'/mysql/error.php'; -require_once dirname(__FILE__).'/sql/database.php'; -require_once dirname(__FILE__).'/sql/query.php'; -require_once dirname(__FILE__).'/sql/delete.php'; -require_once dirname(__FILE__).'/sql/select.php'; -require_once dirname(__FILE__).'/sql/update.php'; -require_once dirname(__FILE__).'/sql/insert.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'; -require_once dirname(__FILE__).'/mysql/collection.php'; -require_once dirname(__FILE__).'/mysql/model.php'; -require_once dirname(__FILE__).'/mysql/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 - * @version $Id: abstract.php 1 2010-01-02 23:06:36Z blanquera $ - */ -class Eden_Mysql extends Eden_Sql_Database { - /* Constants - -------------------------------*/ - const FIRST = 'first'; - const LAST = 'last'; - - /* Public Properties - -------------------------------*/ - /* Protected Properties - -------------------------------*/ - protected $_type = NULL; - protected $_host = 'localhost'; - protected $_name = NULL; - protected $_user = NULL; - protected $_pass = NULL; - protected $_queries = array(); - - protected $_connection = NULL; - protected $_binds = array(); - - /* Private Properties - -------------------------------*/ - /* Get - -------------------------------*/ - public static function i($host = NULL, $name = NULL, $user = NULL, $pass = NULL) { - return self::_getMultiple(__CLASS__, $host, $name, $user, $pass); - } - - /* Magic - -------------------------------*/ - public function __construct($host, $name, $user, $pass = NULL) { - //argument test - Eden_Mysql_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 number or null - - $this->_host = $host; - $this->_name = $name; - $this->_user = $user; - $this->_pass = $pass; - } - - /* Public Methods - -------------------------------*/ - /** - * Connects to the database - * - * @param array the connection options - * @return this - */ - public function connect(array $options = array()) { - $connection = 'mysql:host='.$this->_host.';dbname='.$this->_name; - - $this->_connection = new PDO($connection, $this->_user, $this->_pass, $options); - - $this->trigger(); - - return $this; - } - - /** - * 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 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 the last inserted id - * - * @return int the id - */ - public function getLastInsertedId() { - return $this->getConnection()->lastInsertId(); - } - - /** - * Returns search - * - * @return Eden_Mysql_Search - */ - public function search() { - return Eden_Mysql_Search::i($this); - } - - /** - * Returns model - * - * @return Eden_Mysql_Model - */ - public function model(array $data = array()) { - return Eden_Mysql_Model::i($data)->setDatabase($this); - } - - /** - * Returns collection - * - * @return Eden_Mysql_Collection - */ - public function collection(array $data = array()) { - return Eden_Mysql_Collection::i($data)->setDatabase($this); - } - - /** - * 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); - } - - /** - * 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 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_Mysql_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_Mysql_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); - $filter = $this->bind($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, $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 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_Mysql_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); - - if(is_null($result)) { - return Eden_Mysql_Model::i()->setDatabase($this)->setTable($table); - } - - return Eden_Mysql_Model::i($result)->setDatabase($this)->setTable($table); - } - - /** - * 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_Mysql_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); - - if(is_null($results)) { - return Eden_Mysql_Collection::i()->setDatabase($this)->setTable($table); - } - - if(!is_null($index)) { - return Eden_Mysql_Model::i($results); - } - - return Eden_Mysql_Collection::i($results)->setDatabase($this)->setTable($table); - } - - /** - * 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_Mysql_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; - } - - /** - * 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_Mysql_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_Mysql_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; - } - - /** - * 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_Mysql_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); - $filter = $this->bind($filter); - $filters[$i] = vsprintf($format, $filter); - } - } - - $query->where($filters); - - //run the query - $this->query($query, $this->getBinds()); - - $this->trigger($table, $setting, $filters); - - 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_Mysql_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, 'eq', $value))); - } - } - - /** - * 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_Mysql_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); - $filter = $this->bind($filter); - $filters[$i] = vsprintf($format, $filter); - } - } - - $query->where($filters); - - //run the query - $this->query($query, $this->getBinds()); - - $this->trigger($table, $filters); - - return $this; - } - - /** - * 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 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()); - } - - /** - * 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); - } - - /** - * 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 databse - * - * @return string - */ - public function getSchema() { - $backup = array(); - $tables = $this->getTables(); - foreach($tables as $table) { - $backup[] = $this->getBackup(); - } - - return implode("\n\n", $backup); - } - - /** - * 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_Mysql_Error::i()->argument(1, 'string', 'Eden_Sql_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_Mysql_Error::i() - ->setMessage(Eden_Mysql_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; - } - - /** - * 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_Mysql_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 all the bound values of this query - * - * @param void - * @return array - */ - public function getBinds() { - return $this->_binds; - } - - /** - * Sets all the bound values of this query - * - * @param array - * @return this - */ - public function setBinds(array $binds) { - $this->_binds = $binds; - return $this; - } - - /* Protected Methods - -------------------------------*/ - /* Private Methods - -------------------------------*/ -} - + +/* + * 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__).'/event.php'; +require_once dirname(__FILE__).'/sql/error.php'; +require_once dirname(__FILE__).'/mysql/error.php'; +require_once dirname(__FILE__).'/sql/database.php'; +require_once dirname(__FILE__).'/sql/query.php'; +require_once dirname(__FILE__).'/sql/delete.php'; +require_once dirname(__FILE__).'/sql/select.php'; +require_once dirname(__FILE__).'/sql/update.php'; +require_once dirname(__FILE__).'/sql/insert.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'; +require_once dirname(__FILE__).'/mysql/collection.php'; +require_once dirname(__FILE__).'/mysql/model.php'; +require_once dirname(__FILE__).'/mysql/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 + * @version $Id: abstract.php 1 2010-01-02 23:06:36Z blanquera $ + */ +class Eden_Mysql extends Eden_Sql_Database { + /* Constants + -------------------------------*/ + const FIRST = 'first'; + const LAST = 'last'; + + const MODEL = 'Eden_Mysql_Model'; + const COLLECTION = 'Eden_Mysql_Collection'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_type = NULL; + protected $_host = 'localhost'; + protected $_name = NULL; + protected $_user = NULL; + protected $_pass = NULL; + protected $_queries = array(); + + protected $_connection = NULL; + protected $_binds = array(); + + protected $_model = self::MODEL; + protected $_collection = self::COLLECTION; + + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + /* Magic + -------------------------------*/ + public function __construct($host, $name, $user, $pass = NULL) { + //argument test + Eden_Mysql_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 number or null + + $this->_host = $host; + $this->_name = $name; + $this->_user = $user; + $this->_pass = $pass; + } + + /* Public Methods + -------------------------------*/ + /** + * Connects to the database + * + * @param array the connection options + * @return this + */ + public function connect(array $options = array()) { + $connection = 'mysql:host='.$this->_host.';dbname='.$this->_name; + + $this->_connection = new PDO($connection, $this->_user, $this->_pass, $options); + + $this->trigger(); + + return $this; + } + + /** + * 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 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; + } + + /** + * Sets the default model + * + * @param string + * @return this + */ + public function setModel($model) { + $error = Eden_Mysql_Error::get()->argument(1, 'string'); + + if(!is_subclass_of($model, 'Eden_Model')) { + $error->setMessage(Eden_Mysql_Error::NOT_SUB_MODEL) + ->addVariable($model) + ->trigger(); + } + + $this->_model = $model; + return $this; + } + + /** + * Sets default collection + * + * @param string + * @return this + */ + public function setCollection($collection) { + $error = Eden_Mysql_Error::get()->argument(1, 'string'); + + if(!is_subclass_of($collection, 'Eden_Collection')) { + $error->setMessage(Eden_Mysql_Error::NOT_SUB_COLLECTION) + ->addVariable($collection) + ->trigger(); + } + + $this->_collection = $collection; + return $this; + } + + /** + * Returns the last inserted id + * + * @return int the id + */ + public function getLastInsertedId() { + return $this->getConnection()->lastInsertId(); + } + + /** + * Returns search + * + * @return Eden_Mysql_Search + */ + public function search() { + return Eden_Mysql_Search::i($this); + } + + /** + * Returns model + * + * @return Eden_Mysql_Model + */ + public function model(array $data = array()) { + $model = $this->_model; + return $this->$model($data)->setDatabase($this); + } + + /** + * Returns collection + * + * @return Eden_Mysql_Collection + */ + public function collection(array $data = array()) { + $collection = $this->_collection; + return $this->$collection($data)->setDatabase($this); + } + + /** + * 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); + } + + /** + * 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 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_Mysql_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_Mysql_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); + $filter = $this->bind($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, $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 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_Mysql_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 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_Mysql_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); + + if(is_null($results)) { + return $collection; + } + + if(!is_null($index)) { + return $this->model($results)->setTable($table); + } + + return $collection->set($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_Mysql_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; + } + + /** + * 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_Mysql_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_Mysql_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; + } + + /** + * 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_Mysql_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); + $filter = $this->bind($filter); + $filters[$i] = vsprintf($format, $filter); + } + } + + $query->where($filters); + + //run the query + $this->query($query, $this->getBinds()); + + $this->trigger($table, $setting, $filters); + + 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_Mysql_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, 'eq', $value))); + } + } + + /** + * 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_Mysql_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); + $filter = $this->bind($filter); + $filters[$i] = vsprintf($format, $filter); + } + } + + $query->where($filters); + + //run the query + $this->query($query, $this->getBinds()); + + $this->trigger($table, $filters); + + return $this; + } + + /** + * 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 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()); + } + + /** + * 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); + } + + /** + * 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 databse + * + * @return string + */ + public function getSchema() { + $backup = array(); + $tables = $this->getTables(); + foreach($tables as $table) { + $backup[] = $this->getBackup(); + } + + return implode("\n\n", $backup); + } + + /** + * 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_Mysql_Error::i()->argument(1, 'string', 'Eden_Sql_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_Mysql_Error::i() + ->setMessage(Eden_Mysql_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; + } + + /** + * 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_Mysql_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 all the bound values of this query + * + * @param void + * @return array + */ + public function getBinds() { + return $this->_binds; + } + + /** + * Sets all the bound values of this query + * + * @param array + * @return this + */ + public function setBinds(array $binds) { + $this->_binds = $binds; + return $this; + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} + diff --git a/library/eden/mysql/alter.php b/library/eden/mysql/alter.php index ac015b4..81e3ce3 100755 --- a/library/eden/mysql/alter.php +++ b/library/eden/mysql/alter.php @@ -37,8 +37,8 @@ class Eden_Mysql_Alter extends Eden_Sql_Query { -------------------------------*/ /* Get -------------------------------*/ - public static function i($name = NULL) { - return self::_getMultiple(__CLASS__, $name); + public static function i() { + return self::_getMultiple(__CLASS__); } /* Magic diff --git a/library/eden/mysql/collection.php b/library/eden/mysql/collection.php index ab1bf01..cd47f1a 100644 --- a/library/eden/mysql/collection.php +++ b/library/eden/mysql/collection.php @@ -1,186 +1,186 @@ - -/* - * 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. - */ - -/** - * Mysql Collection handler - * - * @package Eden - * @category mysql - * @author Christian Blanquera - * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ - */ -class Eden_Mysql_Collection extends Eden_Collection { - /* Constants - -------------------------------*/ - /* Public Properties - -------------------------------*/ - /* Protected Properties - -------------------------------*/ - protected $_model = 'Eden_Mysql_Model'; - - /* Private Properties - -------------------------------*/ - /* Get - -------------------------------*/ - public static function i(array $data = array()) { - return self::_getMultiple(__CLASS__,$data); - } - - /* Magic - -------------------------------*/ - /* Public Methods - -------------------------------*/ - /** - * Sets the default database - * - * @param Eden_Mysql - */ - public function setDatabase(Eden_Mysql $database) { - //for each row - foreach($this->_list as $row) { - if(!is_object($row) || !method_exists($row, 'setDatabase')) { - continue; - } - - //let the row handle this - $row->setDatabase($database); - } - - return $this; - } - - /** - * Sets the default database - * - * @param string - */ - public function setTable($table) { - //Argument 1 must be a string - Eden_Mysql_Error::i()->argument(1, 'string'); - - //for each row - foreach($this->_list as $row) { - if(!is_object($row) || !method_exists($row, 'setTable')) { - continue; - } - - //let the row handle this - $row->setTable($table); - } - - return $this; - } - - /** - * Useful method for formating a time column. - * - * @param string - * @param string - * @return this - */ - public function formatTime($column, $format = Eden_Mysql_Model::DATETIME) { - //for each row - foreach($this->_list as $row) { - if(!is_object($row) || !method_exists($row, 'formatTime')) { - continue; - } - - //let the row handle this - $row->formatTime($column, $format); - } - - return $this; - } - - /** - * Insert collection to database - * - * @param string - * @param Eden_Mysql - * @return this - */ - public function insert($table = NULL, Eden_Mysql $database = NULL) { - //for each row - foreach($this->_list as $i => $row) { - if(!is_object($row) || !method_exists($row, 'insert')) { - continue; - } - - $row->insert($table, $database); - } - - return $this; - } - - /** - * Updates collection to database - * - * @param string - * @param Eden_Mysql - * @return this - */ - public function update($table = NULL, Eden_Mysql $database = NULL) { - //for each row - foreach($this->_list as $i => $row) { - if(!is_object($row) || !method_exists($row, 'update')) { - continue; - } - - $row->update($table, $database); - } - - return $this; - } - - /** - * Inserts or updates collection to database - * - * @param string - * @param Eden_Mysql - * @return this - */ - public function save($table = NULL, Eden_Mysql $database = NULL) { - //for each row - foreach($this->_list as $i => $row) { - if(!is_object($row) || !method_exists($row, 'save')) { - continue; - } - - $row->save($table, $database); - } - - return $this; - } - - /** - * Removes collection from database - * - * @param string - * @param Eden_Mysql - * @return this - */ - public function remove($table = NULL, Eden_Mysql $database = NULL) { - //for each row - foreach($this->_list as $i => $row) { - if(!is_object($row) || !method_exists($row, 'remove')) { - continue; - } - - //let the row handle this - $row->remove($table, $database); - } - - return $this; - } - - /* Protected Methods - -------------------------------*/ - /* Private Methods - -------------------------------*/ + +/* + * 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. + */ + +/** + * Mysql Collection handler + * + * @package Eden + * @category mysql + * @author Christian Blanquera + * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ + */ +class Eden_Mysql_Collection extends Eden_Collection { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_model = 'Eden_Mysql_Model'; + + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + /* Magic + -------------------------------*/ + /* Public Methods + -------------------------------*/ + /** + * Sets the default database + * + * @param Eden_Mysql + */ + public function setDatabase(Eden_Mysql $database) { + //for each row + foreach($this->_list as $row) { + if(!is_object($row) || !method_exists($row, 'setDatabase')) { + continue; + } + + //let the row handle this + $row->setDatabase($database); + } + + return $this; + } + + /** + * Sets the default database + * + * @param string + */ + public function setTable($table) { + //Argument 1 must be a string + Eden_Mysql_Error::i()->argument(1, 'string'); + + //for each row + foreach($this->_list as $row) { + if(!is_object($row) || !method_exists($row, 'setTable')) { + continue; + } + + //let the row handle this + $row->setTable($table); + } + + return $this; + } + + /** + * Useful method for formating a time column. + * + * @param string + * @param string + * @return this + */ + public function formatTime($column, $format = Eden_Mysql_Model::DATETIME) { + //for each row + foreach($this->_list as $row) { + if(!is_object($row) || !method_exists($row, 'formatTime')) { + continue; + } + + //let the row handle this + $row->formatTime($column, $format); + } + + return $this; + } + + /** + * Insert collection to database + * + * @param string + * @param Eden_Mysql + * @return this + */ + public function insert($table = NULL, Eden_Mysql $database = NULL) { + //for each row + foreach($this->_list as $i => $row) { + if(!is_object($row) || !method_exists($row, 'insert')) { + continue; + } + + $row->insert($table, $database); + } + + return $this; + } + + /** + * Updates collection to database + * + * @param string + * @param Eden_Mysql + * @return this + */ + public function update($table = NULL, Eden_Mysql $database = NULL) { + //for each row + foreach($this->_list as $i => $row) { + if(!is_object($row) || !method_exists($row, 'update')) { + continue; + } + + $row->update($table, $database); + } + + return $this; + } + + /** + * Inserts or updates collection to database + * + * @param string + * @param Eden_Mysql + * @return this + */ + public function save($table = NULL, Eden_Mysql $database = NULL) { + //for each row + foreach($this->_list as $i => $row) { + if(!is_object($row) || !method_exists($row, 'save')) { + continue; + } + + $row->save($table, $database); + } + + return $this; + } + + /** + * Removes collection from database + * + * @param string + * @param Eden_Mysql + * @return this + */ + public function remove($table = NULL, Eden_Mysql $database = NULL) { + //for each row + foreach($this->_list as $i => $row) { + if(!is_object($row) || !method_exists($row, 'remove')) { + continue; + } + + //let the row handle this + $row->remove($table, $database); + } + + 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 index cbd99d0..a8319e4 100755 --- a/library/eden/mysql/create.php +++ b/library/eden/mysql/create.php @@ -33,8 +33,8 @@ class Eden_Mysql_Create extends Eden_Sql_Query { -------------------------------*/ /* Get -------------------------------*/ - public static function i($name = NULL) { - return self::_getMultiple(__CLASS__, $name); + public static function i() { + return self::_getMultiple(__CLASS__); } /* Magic diff --git a/library/eden/mysql/error.php b/library/eden/mysql/error.php index 5e2ca3f..f776993 100755 --- a/library/eden/mysql/error.php +++ b/library/eden/mysql/error.php @@ -23,6 +23,9 @@ class Eden_Mysql_Error extends Eden_Error { 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 diff --git a/library/eden/mysql/model.php b/library/eden/mysql/model.php index 5a847d3..b31d2a9 100644 --- a/library/eden/mysql/model.php +++ b/library/eden/mysql/model.php @@ -1,399 +1,398 @@ - -/* - * 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. - */ - -/** - * Mysql Model - * - * @package Eden - * @category mysql - * @author Christian Blanquera - * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ - */ -class Eden_Mysql_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 - -------------------------------*/ - /* Get - -------------------------------*/ - public static function i() { - $data = self::_getStart(func_get_args()); - return self::_getMultiple(__CLASS__, $data); - } - - /* Magic - -------------------------------*/ - /* Public Methods - -------------------------------*/ - /** - * Sets the default database - * - * @param Eden_Mysql - */ - public function setDatabase(Eden_Mysql $database) { - $this->_database = $database; - return $this; - } - - /** - * Sets the default database - * - * @param string - */ - public function setTable($table) { - //Argument 1 must be a string - Eden_Mysql_Error::i()->argument(1, 'string'); - - $this->_table = $table; - return $this; - } - - /** - * Useful method for formating a time column. - * - * @param string - * @param string - * @return this - */ - public function formatTime($column, $format = self::DATETIME) { - //Argument Test - Eden_Mysql_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_Mysql - * @return this - */ - public function insert($table = NULL, Eden_Mysql $database = NULL) { - //Argument 1 must be a string - $error = Eden_Mysql_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_Mysql_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_Mysql_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; - } - - /** - * Updates model to database - * - * @param string - * @param Eden_Mysql - * @return this - */ - public function update($table = NULL, Eden_Mysql $database = NULL) { - //Argument 1 must be a string - $error = Eden_Mysql_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_Mysql_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_Mysql_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 - - $filter = array(); - //for each primary key - foreach($meta[self::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; - } - - /** - * Inserts or updates model to database - * - * @param string - * @param Eden_Mysql - * @return this - */ - public function save($table = NULL, Eden_Mysql $database = NULL) { - //Argument 1 must be a string - $error = Eden_Mysql_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_Mysql_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_Mysql_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); - $primarySet = $this->_isPrimarySet($meta[self::PRIMARY]); - - //update original data - $this->_original = $this->_data; - - //if no primary meta or primary values are not set - if(empty($meta[self::PRIMARY]) || !$primarySet) { - return $this->insert($table, $database); - } - - return $this->update($table, $database); - } - - /** - * Removes model from database - * - * @param string - * @param Eden_Mysql - * @return this - */ - public function remove($table = NULL, Eden_Mysql $database = NULL) { - //Argument 1 must be a string - $error = Eden_Mysql_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_Mysql_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_Mysql_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])); - - $filter = array(); - //for each primary key - foreach($meta[self::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; - } - - /* Protected Methods - -------------------------------*/ - protected function _isPrimarySet(array $primary) { - foreach($primary as $column) { - if(is_null($this[$column])) { - return false; - } - } - - return true; - } - - protected function _getValidColumns($columns) { - $valid = array(); - foreach($columns as $column) { - if(!isset($this->_data[$column])) { - continue; - } - - $valid[$column] = $this->_data[$column]; - } - - return $valid; - } - - 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 _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]); - } - - /* Private Methods - -------------------------------*/ -} - + +/* + * 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. + */ + +/** + * Mysql Model + * + * @package Eden + * @category mysql + * @author Christian Blanquera + * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ + */ +class Eden_Mysql_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 + -------------------------------*/ + /* Get + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + /* Magic + -------------------------------*/ + /* Public Methods + -------------------------------*/ + /** + * Sets the default database + * + * @param Eden_Mysql + */ + public function setDatabase(Eden_Mysql $database) { + $this->_database = $database; + return $this; + } + + /** + * Sets the default database + * + * @param string + */ + public function setTable($table) { + //Argument 1 must be a string + Eden_Mysql_Error::i()->argument(1, 'string'); + + $this->_table = $table; + return $this; + } + + /** + * Useful method for formating a time column. + * + * @param string + * @param string + * @return this + */ + public function formatTime($column, $format = self::DATETIME) { + //Argument Test + Eden_Mysql_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_Mysql + * @return this + */ + public function insert($table = NULL, Eden_Mysql $database = NULL) { + //Argument 1 must be a string + $error = Eden_Mysql_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_Mysql_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_Mysql_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; + } + + /** + * Updates model to database + * + * @param string + * @param Eden_Mysql + * @return this + */ + public function update($table = NULL, Eden_Mysql $database = NULL) { + //Argument 1 must be a string + $error = Eden_Mysql_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_Mysql_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_Mysql_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 + + $filter = array(); + //for each primary key + foreach($meta[self::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; + } + + /** + * Inserts or updates model to database + * + * @param string + * @param Eden_Mysql + * @return this + */ + public function save($table = NULL, Eden_Mysql $database = NULL) { + //Argument 1 must be a string + $error = Eden_Mysql_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_Mysql_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_Mysql_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); + $primarySet = $this->_isPrimarySet($meta[self::PRIMARY]); + + //update original data + $this->_original = $this->_data; + + //if no primary meta or primary values are not set + if(empty($meta[self::PRIMARY]) || !$primarySet) { + return $this->insert($table, $database); + } + + return $this->update($table, $database); + } + + /** + * Removes model from database + * + * @param string + * @param Eden_Mysql + * @return this + */ + public function remove($table = NULL, Eden_Mysql $database = NULL) { + //Argument 1 must be a string + $error = Eden_Mysql_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_Mysql_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_Mysql_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])); + + $filter = array(); + //for each primary key + foreach($meta[self::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; + } + + /* Protected Methods + -------------------------------*/ + protected function _isPrimarySet(array $primary) { + foreach($primary as $column) { + if(is_null($this[$column])) { + return false; + } + } + + return true; + } + + protected function _getValidColumns($columns) { + $valid = array(); + foreach($columns as $column) { + if(!isset($this->_data[$column])) { + continue; + } + + $valid[$column] = $this->_data[$column]; + } + + return $valid; + } + + 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 _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]); + } + + /* Private Methods + -------------------------------*/ +} + diff --git a/library/eden/mysql/search.php b/library/eden/mysql/search.php index 851e629..c814422 100644 --- a/library/eden/mysql/search.php +++ b/library/eden/mysql/search.php @@ -1,509 +1,528 @@ - -/* - * 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. - */ - -/** - * Mysql Collection handler - * - * @package Eden - * @category mysql - * @author Christian Blanquera - * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ - */ -class Eden_Mysql_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 $_join = array(); - protected $_filter = array(); - protected $_sort = array(); - protected $_group = array(); - protected $_start = 0; - protected $_range = 0; - - protected $_collection = 'Eden_Mysql_Collection'; - - /* Private Properties - -------------------------------*/ - /* Get - -------------------------------*/ - public static function i(Eden_Mysql $database) { - return self::_getMultiple(__CLASS__,$database); - } - - /* Magic - -------------------------------*/ - public function __construct(Eden_Mysql $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-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_Mysql_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_Mysql_Error::i()->argument(1, 'string'); - $this->_table = $table; - return $this; - } - - /** - * Adds Inner Join On - * - * @param string - * @param string[,string..] - * @return this - */ - public function addInnerJoinOn($table, $where) { - Eden_Mysql_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_Mysql_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_Mysql_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_Mysql_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 Right Join On - * - * @param string - * @param string[,string..] - * @return this - */ - public function addRightJoinOn($table, $where) { - Eden_Mysql_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_Mysql_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 Outer Join On - * - * @param string - * @param string[,string..] - * @return this - */ - public function addOuterJoinOn($table, $where) { - Eden_Mysql_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_Mysql_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 filter - * - * @param string - * @param string[,string..] - * @return this - */ - public function addFilter() { - Eden_Mysql_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_Mysql_Error::i() - ->argument(1, 'string') - ->argument(2, 'string'); - - if($order != self::DESC) { - $order = self::ASC; - } - - $this->_sort[$column] = $order; - - 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_Mysql_Error::i()->argument(1, 'string', 'array'); - - if(is_string($group)) { - $group = array($group); - } - - $this->_group = $group; - return $this; - } - - /** - * Sets the pagination start - * - * @param int - * @return this - */ - public function setStart($start) { - Eden_Mysql_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_Mysql_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_Mysql_Error::i()->argument(1, 'int'); - - if($page < 1) { - $page = 1; - } - - $this->_start = ($page - 1) * $this->_range; - - return $this; - } - - /** - * Returns the results in a collection - * - * @return Eden_Mysql_Collection - */ - public function getCollection() { - $collection = $this->_collection; - return $this->$collection($this->getRows()) - ->setDatabase($this->_database) - ->setTable($this->_table); - } - - /** - * 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']; - } - - /* 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 - -------------------------------*/ + +/* + * 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. + */ + +/** + * Mysql Collection handler + * + * @package Eden + * @category mysql + * @author Christian Blanquera + * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ + */ +class Eden_Mysql_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 $_join = array(); + protected $_filter = array(); + protected $_sort = array(); + protected $_group = array(); + protected $_start = 0; + protected $_range = 0; + + protected $_collection = 'Eden_Mysql_Collection'; + + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + /* Magic + -------------------------------*/ + public function __construct(Eden_Mysql $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-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_Mysql_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_Mysql_Error::i()->argument(1, 'string'); + $this->_table = $table; + return $this; + } + + /** + * Adds Inner Join On + * + * @param string + * @param string[,string..] + * @return this + */ + public function addInnerJoinOn($table, $where) { + Eden_Mysql_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_Mysql_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_Mysql_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_Mysql_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 Right Join On + * + * @param string + * @param string[,string..] + * @return this + */ + public function addRightJoinOn($table, $where) { + Eden_Mysql_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_Mysql_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 Outer Join On + * + * @param string + * @param string[,string..] + * @return this + */ + public function addOuterJoinOn($table, $where) { + Eden_Mysql_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_Mysql_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 filter + * + * @param string + * @param string[,string..] + * @return this + */ + public function addFilter() { + Eden_Mysql_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_Mysql_Error::i() + ->argument(1, 'string') + ->argument(2, 'string'); + + if($order != self::DESC) { + $order = self::ASC; + } + + $this->_sort[$column] = $order; + + 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_Mysql_Error::i()->argument(1, 'string', 'array'); + + if(is_string($group)) { + $group = array($group); + } + + $this->_group = $group; + return $this; + } + + /** + * Sets the pagination start + * + * @param int + * @return this + */ + public function setStart($start) { + Eden_Mysql_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_Mysql_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_Mysql_Error::i()->argument(1, 'int'); + + if($page < 1) { + $page = 1; + } + + $this->_start = ($page - 1) * $this->_range; + + return $this; + } + + /** + * Sets default collection + * + * @param string + * @return this + */ + public function setCollection($collection) { + $error = Eden_Mysql_Error::get()->argument(1, 'string'); + + if(!is_subclass_of($collection, 'Eden_Collection')) { + $error->setMessage(Eden_Mysql_Error::NOT_SUB_COLLECTION) + ->addVariable($collection) + ->trigger(); + } + + $this->_collection = $collection; + return $this; + } + + /** + * Returns the results in a collection + * + * @return Eden_Mysql_Collection + */ + public function getCollection() { + $collection = $this->_collection; + return $this->$collection($this->getRows()) + ->setDatabase($this->_database) + ->setTable($this->_table); + } + + /** + * 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']; + } + + /* 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/mysql/subselect.php b/library/eden/mysql/subselect.php index 7eb8fc8..6160b40 100755 --- a/library/eden/mysql/subselect.php +++ b/library/eden/mysql/subselect.php @@ -29,8 +29,8 @@ class Eden_Mysql_Subselect extends Eden_Class { -------------------------------*/ /* Get -------------------------------*/ - public static function i(Eden_Sql_Select $parentQuery, $select = '*') { - return self::_getMultiple(__CLASS__, $parentQuery, $select); + public static function i() { + return self::_getMultiple(__CLASS__); } /* Magic diff --git a/library/eden/oauth/consumer.php b/library/eden/oauth/consumer.php index e8d6376..04625c2 100644 --- a/library/eden/oauth/consumer.php +++ b/library/eden/oauth/consumer.php @@ -47,8 +47,8 @@ class Eden_Oauth_Consumer extends Eden_Oauth_Base { -------------------------------*/ /* Get -------------------------------*/ - public static function i($url, $key, $secret) { - return self::_getMultiple(__CLASS__, $url, $key, $secret); + public static function i() { + return self::_getMultiple(__CLASS__); } /* Magic diff --git a/library/eden/path.php b/library/eden/path.php index b45a470..429b4f1 100644 --- a/library/eden/path.php +++ b/library/eden/path.php @@ -29,8 +29,8 @@ class Eden_Path extends Eden_Type_String implements ArrayAccess { -------------------------------*/ /* Get -------------------------------*/ - public static function i($path) { - return self::_getMultiple(__CLASS__, $path); + public static function i() { + return self::_getMultiple(__CLASS__); } /* Magic diff --git a/library/eden/registry.php b/library/eden/registry.php index 752982e..025fcbe 100755 --- a/library/eden/registry.php +++ b/library/eden/registry.php @@ -34,19 +34,31 @@ class Eden_Registry extends Eden_Type_Array { /* Get -------------------------------*/ public static function i() { - $data = self::_getStart(func_get_args()); + return self::_getMultiple(__CLASS__); + } + + /* Magic + -------------------------------*/ + 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)) { - $data[$key] = self::i($value); + if(!is_array($value)) { + continue; } - } + + $class = get_class($this); + + $data[$key] = $this->$class($value); + } - return self::_getMultiple(__CLASS__, $data); + parent::__construct($data); } - /* Magic - -------------------------------*/ public function __toString() { return json_encode($this->getArray()); } @@ -98,7 +110,7 @@ public function get($modified = true) { * * @return Eden_Registry */ - public function set() { + public function set($value) { $args = func_get_args(); if(count($args) < 2) { diff --git a/library/eden/sql/delete.php b/library/eden/sql/delete.php index 89a15b2..69afb5e 100755 --- a/library/eden/sql/delete.php +++ b/library/eden/sql/delete.php @@ -29,8 +29,8 @@ class Eden_Sql_Delete extends Eden_Sql_Query { -------------------------------*/ /* Get -------------------------------*/ - public static function i($table = NULL) { - return self::_getMultiple(__CLASS__, $table); + public static function i() { + return self::_getMultiple(__CLASS__); } /* Magic diff --git a/library/eden/sql/insert.php b/library/eden/sql/insert.php index 83ea9b9..60a75b6 100755 --- a/library/eden/sql/insert.php +++ b/library/eden/sql/insert.php @@ -29,8 +29,8 @@ class Eden_Sql_Insert extends Eden_Sql_Query { -------------------------------*/ /* Get -------------------------------*/ - public static function i($table = NULL) { - return self::_getMultiple(__CLASS__, $table); + public static function i() { + return self::_getMultiple(__CLASS__); } /* Magic diff --git a/library/eden/sql/select.php b/library/eden/sql/select.php index 48feb03..d518d34 100755 --- a/library/eden/sql/select.php +++ b/library/eden/sql/select.php @@ -35,8 +35,8 @@ class Eden_Sql_Select extends Eden_Sql_Query { -------------------------------*/ /* Get -------------------------------*/ - public static function i($select = '*') { - return self::_getMultiple(__CLASS__, $select); + public static function i() { + return self::_getMultiple(__CLASS__); } /* Magic diff --git a/library/eden/sql/update.php b/library/eden/sql/update.php index de197a0..f24b02d 100755 --- a/library/eden/sql/update.php +++ b/library/eden/sql/update.php @@ -28,8 +28,8 @@ class Eden_Sql_Update extends Eden_Sql_Delete { -------------------------------*/ /* Get -------------------------------*/ - public static function i($table = NULL) { - return self::_getMultiple(__CLASS__, $table); + public static function i() { + return self::_getMultiple(__CLASS__); } /* Magic diff --git a/library/eden/tumblr/blog.php b/library/eden/tumblr/blog.php index 73e25e4..fc85752 100644 --- a/library/eden/tumblr/blog.php +++ b/library/eden/tumblr/blog.php @@ -39,9 +39,10 @@ class Eden_Tumblr_Blog extends Eden_Tumblr_Base { -------------------------------*/ /* Get -------------------------------*/ - public static function i($user, $api) { - return self::_getMultiple(__CLASS__, $user, $api); + public static function i() { + return self::_getMultiple(__CLASS__); } + /* Magic -------------------------------*/ /* Public Methods diff --git a/library/eden/tumblr/oauth.php b/library/eden/tumblr/oauth.php index f8c6202..e6c3100 100644 --- a/library/eden/tumblr/oauth.php +++ b/library/eden/tumblr/oauth.php @@ -29,8 +29,8 @@ class Eden_Tumblr_Oauth extends Eden_Tumblr_Base { -------------------------------*/ /* Get -------------------------------*/ - public static function i($key, $secret) { - return self::_getMultiple(__CLASS__, $key, $secret); + public static function i() { + return self::_getMultiple(__CLASS__); } /* Magic diff --git a/library/eden/tumblr/user.php b/library/eden/tumblr/user.php index a9d5494..5ef1aff 100644 --- a/library/eden/tumblr/user.php +++ b/library/eden/tumblr/user.php @@ -38,9 +38,10 @@ class Eden_Tumblr_User extends Eden_Tumblr_Base { -------------------------------*/ /* Get -------------------------------*/ - public static function i($user, $api) { - return self::_getMultiple(__CLASS__, $user, $api); + public static function i() { + return self::_getMultiple(__CLASS__); } + /* Magic -------------------------------*/ /* Public Methods diff --git a/library/eden/twitter/accounts.php b/library/eden/twitter/accounts.php index 6436d12..d7acab8 100644 --- a/library/eden/twitter/accounts.php +++ b/library/eden/twitter/accounts.php @@ -37,8 +37,8 @@ class Eden_Twitter_Accounts extends Eden_Twitter_Base { -------------------------------*/ /* Get -------------------------------*/ - public static function i($key, $secret) { - return self::_getMultiple(__CLASS__, $key, $secret); + public static function i() { + return self::_getMultiple(__CLASS__); } /* Magic diff --git a/library/eden/twitter/directmessage.php b/library/eden/twitter/directmessage.php index 25d0c3e..eb10154 100644 --- a/library/eden/twitter/directmessage.php +++ b/library/eden/twitter/directmessage.php @@ -34,9 +34,10 @@ class Eden_Twitter_Directmessage extends Eden_Twitter_Base { -------------------------------*/ /* Get -------------------------------*/ - public static function i($user, $api) { - return self::_getMultiple(__CLASS__, $user, $api); + public static function i() { + return self::_getMultiple(__CLASS__); } + /* Magic -------------------------------*/ /* Public Methods diff --git a/library/eden/twitter/favorites.php b/library/eden/twitter/favorites.php index 86719fe..6187efe 100644 --- a/library/eden/twitter/favorites.php +++ b/library/eden/twitter/favorites.php @@ -32,8 +32,8 @@ class Eden_Twitter_Favorites extends Eden_Twitter_Base { -------------------------------*/ /* Get -------------------------------*/ - public static function i($key, $secret) { - return self::_getMultiple(__CLASS__, $key, $secret); + public static function i() { + return self::_getMultiple(__CLASS__); } /* Magic diff --git a/library/eden/twitter/friends.php b/library/eden/twitter/friends.php index 984961a..22e58ef 100644 --- a/library/eden/twitter/friends.php +++ b/library/eden/twitter/friends.php @@ -44,9 +44,10 @@ class Eden_Twitter_Friends extends Eden_Twitter_Base { -------------------------------*/ /* Get -------------------------------*/ - public static function i($user, $api) { - return self::_getMultiple(__CLASS__, $user, $api); + public static function i() { + return self::_getMultiple(__CLASS__); } + /* Magic -------------------------------*/ /* Public Methods diff --git a/library/eden/twitter/list.php b/library/eden/twitter/list.php index a8e5c3d..f24951c 100644 --- a/library/eden/twitter/list.php +++ b/library/eden/twitter/list.php @@ -34,8 +34,8 @@ class Eden_Twitter_List extends Eden_Twitter_Base { -------------------------------*/ /* Get -------------------------------*/ - public static function i($key, $secret) { - return self::_getMultiple(__CLASS__, $key, $secret); + public static function i() { + return self::_getMultiple(__CLASS__); } /* Magic diff --git a/library/eden/twitter/oauth.php b/library/eden/twitter/oauth.php index 5167dd0..6cebf92 100644 --- a/library/eden/twitter/oauth.php +++ b/library/eden/twitter/oauth.php @@ -29,8 +29,8 @@ class Eden_Twitter_Oauth extends Eden_Twitter_Base { -------------------------------*/ /* Get -------------------------------*/ - public static function i($key, $secret) { - return self::_getMultiple(__CLASS__, $key, $secret); + public static function i() { + return self::_getMultiple(__CLASS__); } /* Magic diff --git a/library/eden/twitter/search.php b/library/eden/twitter/search.php index 99982fe..57dd550 100644 --- a/library/eden/twitter/search.php +++ b/library/eden/twitter/search.php @@ -32,9 +32,10 @@ class Eden_Twitter_Search extends Eden_Twitter_Base { -------------------------------*/ /* Get -------------------------------*/ - public static function i($user, $api) { - return self::_getMultiple(__CLASS__, $user, $api); + public static function i() { + return self::_getMultiple(__CLASS__); } + /* Magic -------------------------------*/ /* Public Methods diff --git a/library/eden/twitter/suggestions.php b/library/eden/twitter/suggestions.php index 679849e..8093cf1 100644 --- a/library/eden/twitter/suggestions.php +++ b/library/eden/twitter/suggestions.php @@ -32,8 +32,8 @@ class Eden_Twitter_Suggestions extends Eden_Twitter_Base { -------------------------------*/ /* Get -------------------------------*/ - public static function i($key, $secret) { - return self::_getMultiple(__CLASS__, $key, $secret); + public static function i() { + return self::_getMultiple(__CLASS__); } /* Magic diff --git a/library/eden/twitter/timelines.php b/library/eden/twitter/timelines.php index 700a134..26b873d 100644 --- a/library/eden/twitter/timelines.php +++ b/library/eden/twitter/timelines.php @@ -37,9 +37,10 @@ class Eden_Twitter_Timelines extends Eden_Twitter_Base { -------------------------------*/ /* Get -------------------------------*/ - public static function i($user, $api) { - return self::_getMultiple(__CLASS__, $user, $api); + public static function i() { + return self::_getMultiple(__CLASS__); } + /* Magic -------------------------------*/ /* Public Methods diff --git a/library/eden/twitter/tweets.php b/library/eden/twitter/tweets.php index b220635..bc5fa9e 100644 --- a/library/eden/twitter/tweets.php +++ b/library/eden/twitter/tweets.php @@ -37,8 +37,8 @@ class Eden_Twitter_Tweets extends Eden_Twitter_Base { -------------------------------*/ /* Get -------------------------------*/ - public static function i($key, $secret) { - return self::_getMultiple(__CLASS__, $key, $secret); + public static function i() { + return self::_getMultiple(__CLASS__); } /* Magic diff --git a/library/eden/twitter/users.php b/library/eden/twitter/users.php index 23e3512..5cab81d 100644 --- a/library/eden/twitter/users.php +++ b/library/eden/twitter/users.php @@ -36,8 +36,8 @@ class Eden_Twitter_Users extends Eden_Twitter_Base { -------------------------------*/ /* Get -------------------------------*/ - public static function i($key, $secret) { - return self::_getMultiple(__CLASS__, $key, $secret); + public static function i() { + return self::_getMultiple(__CLASS__); } /* Magic diff --git a/library/eden/type.php b/library/eden/type.php index 49a6b3e..ce6bd13 100644 --- a/library/eden/type.php +++ b/library/eden/type.php @@ -45,10 +45,6 @@ public static function i($type = NULL) { return Eden_Type_String::i($type); } - if(is_object($type)) { - return Eden_Type_Object::i($type); - } - return self::_getSingleton(__CLASS__); } diff --git a/library/eden/type/abstract.php b/library/eden/type/abstract.php index 2c0fd52..b9e5fe2 100755 --- a/library/eden/type/abstract.php +++ b/library/eden/type/abstract.php @@ -103,6 +103,16 @@ public function __call($name, $args) { /* Public Methods -------------------------------*/ + /** + * Sets data + * + * @return this + */ + public function set($value) { + $this->_data = $value; + return $this; + } + /** * Reverts changes back to the original * diff --git a/library/eden/type/array.php b/library/eden/type/array.php index dfe1838..38202f3 100644 --- a/library/eden/type/array.php +++ b/library/eden/type/array.php @@ -67,13 +67,12 @@ class Eden_Type_Array extends Eden_Type_Abstract implements ArrayAccess, Iterato /* Get -------------------------------*/ public static function i() { - $data = self::_getStart(func_get_args()); - return self::_getMultiple(__CLASS__, $data); + return self::_getMultiple(__CLASS__); } /* Magic -------------------------------*/ - public function __construct($data = array()) { + public function __construct($data) { //if there is more arguments or data is not an array if(func_num_args() > 1 || !is_array($data)) { //just get the args @@ -140,6 +139,17 @@ public function __call($name, $args) { /* Public Methods -------------------------------*/ + /** + * Sets data + * + * @return this + */ + public function set($value) { + Eden_Type_Error::get()->argument(1, 'array'); + $this->_data = $value; + return $this; + } + /** * Returns if the data is empty * @@ -359,24 +369,6 @@ public function count() { /* Protected Methods -------------------------------*/ - protected static function _getStart(array $args) { - if(count($args) != 1) { - return $args; - } - - $data = $args[0]; - - if($data instanceof Eden_Type_Array) { - $data = $data->get(); - } - - if(!is_array($data)) { - $data = array($data); - } - - return $data; - } - protected function _getMethodType(&$name) { if(isset(self::$_methods[$name])) { diff --git a/library/eden/type/string.php b/library/eden/type/string.php index b029101..159bcb7 100644 --- a/library/eden/type/string.php +++ b/library/eden/type/string.php @@ -55,21 +55,20 @@ class Eden_Type_String extends Eden_Type_Abstract { -------------------------------*/ /* Get -------------------------------*/ - public static function i($data) { - if($data instanceof Eden_Type_String) { - return $data; - } - + public static function i() { + return self::_getMultiple(__CLASS__); + } + + /* Magic + -------------------------------*/ + public function __construct($data) { //argument 1 must be scalar Eden_Type_Error::i()->argument(1, 'scalar'); - $data = (string) $data; - return self::_getMultiple(__CLASS__, $data); + parent::__construct($data); } - /* Magic - -------------------------------*/ public function __toString() { return $this->_data; } diff --git a/library/eden/validation.php b/library/eden/validation.php index feee5fe..7361170 100644 --- a/library/eden/validation.php +++ b/library/eden/validation.php @@ -28,8 +28,8 @@ class Eden_Validation extends Eden_Class { -------------------------------*/ /* Get -------------------------------*/ - public static function i($value) { - return self::_getMultiple(__CLASS__, $value); + public static function i() { + return self::_getMultiple(__CLASS__); } /* Magic diff --git a/library/eden/webcharge.php b/library/eden/webcharge.php index b27af0a..4f01cf5 100644 --- a/library/eden/webcharge.php +++ b/library/eden/webcharge.php @@ -79,8 +79,8 @@ class Eden_Webcharge_Model extends Eden_Class -------------------------------*/ /* Get -------------------------------*/ - public static function i($user, $password, array $options = array()) { - return self::_getMultiple(__CLASS__, $user, $password, $options); + public static function i() { + return self::_getMultiple(__CLASS__); } /* Magic diff --git a/library/eden/when.php b/library/eden/when.php index 602fe56..cc31e5f 100755 --- a/library/eden/when.php +++ b/library/eden/when.php @@ -32,8 +32,8 @@ class Eden_When extends Eden_Class implements ArrayAccess, Iterator { -------------------------------*/ /* Get -------------------------------*/ - public static function i($scope, $lines = 0) { - return self::_getMultiple(__CLASS__, $scope, $lines); + public static function i() { + return self::_getMultiple(__CLASS__); } /* Magic From d7ce261fe342a323cb17696f1446b637f8fa9665 Mon Sep 17 00:00:00 2001 From: cblanquera Date: Tue, 10 Jan 2012 07:24:47 +0000 Subject: [PATCH 054/330] added 5.3 __invoke, works with PHP 5.3 only, but it doesn't hurt having it git-svn-id: http://svn.openovate.com/edenv2/trunk@54 38ede93f-50f4-44af-b0b3-68ccca78c181 --- library/eden/class.php | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/library/eden/class.php b/library/eden/class.php index 9e26741..c73c84a 100755 --- a/library/eden/class.php +++ b/library/eden/class.php @@ -26,6 +26,8 @@ class Eden_Class { /* Constants -------------------------------*/ + const INSTANCE = 'multiple'; + /* Public Properties -------------------------------*/ /* Protected Properties @@ -69,6 +71,41 @@ public function __call($name, $args) { } } + 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 Methods -------------------------------*/ /** From d9f3004fa1b36cad9839f7a8279e4c08237bce71 Mon Sep 17 00:00:00 2001 From: cblanquera Date: Tue, 10 Jan 2012 07:53:08 +0000 Subject: [PATCH 055/330] added property debugger git-svn-id: http://svn.openovate.com/edenv2/trunk@55 38ede93f-50f4-44af-b0b3-68ccca78c181 --- library/eden/class.php | 47 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/library/eden/class.php b/library/eden/class.php index c73c84a..8c504d3 100755 --- a/library/eden/class.php +++ b/library/eden/class.php @@ -9,6 +9,8 @@ require_once dirname(__FILE__).'/error.php'; require_once dirname(__FILE__).'/route.php'; + +require_once dirname(__FILE__).'/tool.php'; require_once dirname(__FILE__).'/when.php'; require_once dirname(__FILE__).'/map.php'; @@ -181,6 +183,51 @@ public function loop(array &$list, $lines = 0) { return Eden_Map::i($this, $list, $lines); } + /** + * Force outputs any class property + * + * @param string + * @return this + */ + public function debug($variable) { + //we are using tool in all cases + $tool = Eden_Tool::i(); + //if variable is not a string + if(!is_string($variable)) { + //soft output error + $tool->output(Eden_Error::DEBUG_NOT_STRING); + return $this; + } + + //if variable is set + if(isset($this->$variable)) { + //output it + $tool + ->output('DEBUG $this->'.$variable.':') + ->output($this->$variable); + + return $this; + } + + //could be private + $private = '_'.$variable; + //if private variable is set + if(isset($this->$private)) { + //output it + $tool + ->output('DEBUG $this->'.$private.':') + ->output($this->$private); + + return $this; + } + + //soft output error + $tool->output(sprintf(Eden_Error::DEBUG_NOT_PROPERTY, + $variable, get_class($this))); + + return $this; + } + /* Protected Methods -------------------------------*/ protected static function _getSingleton($class) { From 24aed7a2ba0ec0caaa6480489976322bddfacab1 Mon Sep 17 00:00:00 2001 From: cblanquera Date: Tue, 10 Jan 2012 07:53:23 +0000 Subject: [PATCH 056/330] added property debugger git-svn-id: http://svn.openovate.com/edenv2/trunk@56 38ede93f-50f4-44af-b0b3-68ccca78c181 --- library/eden/error.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/library/eden/error.php b/library/eden/error.php index 7595ea2..36e05ff 100755 --- a/library/eden/error.php +++ b/library/eden/error.php @@ -46,6 +46,8 @@ class Eden_Error extends Exception { 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 -------------------------------*/ From 716e571b11a9b2902f4c6591915c65e3af44819e Mon Sep 17 00:00:00 2001 From: cblanquera Date: Tue, 10 Jan 2012 08:11:22 +0000 Subject: [PATCH 057/330] added property debugger git-svn-id: http://svn.openovate.com/edenv2/trunk@57 38ede93f-50f4-44af-b0b3-68ccca78c181 --- library/eden/class.php | 22 +++++++++++++++++----- library/eden/route/class.php | 12 ++++++------ library/eden/route/method.php | 17 +++++++++++------ 3 files changed, 34 insertions(+), 17 deletions(-) diff --git a/library/eden/class.php b/library/eden/class.php index 8c504d3..d8d65ea 100755 --- a/library/eden/class.php +++ b/library/eden/class.php @@ -189,9 +189,21 @@ public function loop(array &$list, $lines = 0) { * @param string * @return this */ - public function debug($variable) { + public function debug($variable = NULL) { //we are using tool in all cases - $tool = Eden_Tool::i(); + $tool = Eden_Tool::i(); + $class = get_class($this); + + //if variale is null + if(is_null($variable)) { + //output the class + $tool + ->output('DEBUG '.$class.':') + ->output($this); + + return $this; + } + //if variable is not a string if(!is_string($variable)) { //soft output error @@ -203,7 +215,7 @@ public function debug($variable) { if(isset($this->$variable)) { //output it $tool - ->output('DEBUG $this->'.$variable.':') + ->output('DEBUG '.$class.'->'.$variable.':') ->output($this->$variable); return $this; @@ -215,7 +227,7 @@ public function debug($variable) { if(isset($this->$private)) { //output it $tool - ->output('DEBUG $this->'.$private.':') + ->output('DEBUG '.$class.'->'.$private.':') ->output($this->$private); return $this; @@ -223,7 +235,7 @@ public function debug($variable) { //soft output error $tool->output(sprintf(Eden_Error::DEBUG_NOT_PROPERTY, - $variable, get_class($this))); + $variable, $clas)); return $this; } diff --git a/library/eden/route/class.php b/library/eden/route/class.php index b81c418..be18a74 100644 --- a/library/eden/route/class.php +++ b/library/eden/route/class.php @@ -63,7 +63,7 @@ public function route($route, $class) { $class = $this->getRoute($class); } - $this->_route[$route] = $class; + $this->_route[strtolower($route)] = $class; return $this; } @@ -78,8 +78,8 @@ public function getRoute($route) { //argument 1 must be a string Eden_Route_Error::i()->argument(1, 'string'); - if(isset($this->_route[$route])) { - return $this->_route[$route]; + if($this->isRoute($route)) { + return $this->_route[strtolower($route)]; } return $route; @@ -101,7 +101,7 @@ public function getRoutes() { * @return bool */ public function isRoute($route) { - return isset($this->_route[$route]); + return isset($this->_route[strtolower($route)]); } /** @@ -145,8 +145,8 @@ public function callArray($class, array $args = array()) { ->getMethod('i') ->getDeclaringClass() ->getName(); - - if($declared == $route) { + + if(strtolower($declared) == strtolower($route)) { return Eden_Route_Method::i()->callStatic($class, 'i', $args); } } diff --git a/library/eden/route/method.php b/library/eden/route/method.php index 1c42266..ce3511d 100644 --- a/library/eden/route/method.php +++ b/library/eden/route/method.php @@ -75,13 +75,14 @@ public function route($source, $alias, $class, $method = NULL) { $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][$alias] = array($class, $method); + $this->_route[$source][strtolower($alias)] = array($class, $method); return $this; } @@ -99,14 +100,14 @@ public function getRoute($class, $method) { ->argument(1, 'string') //argument 1 must be a string ->argument(2, 'string'); //argument 2 must be a string - if(isset($this->_route[NULL][$method])) { - return $this->_route[NULL][$method]; + if($this->isRoute(NULL, $method)) { + return $this->_route[NULL][strtolower($method)]; } $class = Eden_Route_Class::i()->getRoute($class); - if(isset($this->_route[$class][$method])) { - return $this->_route[$class][$method]; + if($this->isRoute($class, $method)) { + return $this->_route[strtolower($class)][strtolower($method)]; } return array($class, $method); @@ -129,7 +130,11 @@ public function getRoutes() { * @return bool */ public function isRoute($class, $method) { - return isset($this->_route[$class][$method]); + if(is_string($class)) { + strtolower($class); + } + + return isset($this->_route[$class][strtolower($method)]); } /** From f41c1d1c7c3433ef4207dda744d6a2686b3b1a9c Mon Sep 17 00:00:00 2001 From: cblanquera Date: Tue, 10 Jan 2012 08:12:51 +0000 Subject: [PATCH 058/330] added property debugger git-svn-id: http://svn.openovate.com/edenv2/trunk@58 38ede93f-50f4-44af-b0b3-68ccca78c181 --- library/eden/route/function.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/library/eden/route/function.php b/library/eden/route/function.php index 362851a..08f8be1 100644 --- a/library/eden/route/function.php +++ b/library/eden/route/function.php @@ -57,7 +57,7 @@ public function route($route, $function) { $function = $this->getRoute($function); - $this->_route[$route] = $function; + $this->_route[strtolower($route)] = $function; return $this; } @@ -72,8 +72,8 @@ public function getRoute($route) { //argument 1 must be a string Eden_Route_Error::i()->argument(1, 'string'); - if(isset($this->_route[$route])) { - return $this->_route[$route]; + if($this->isRoute($route)) { + return $this->_route[strtolower($route)]; } return $route; @@ -95,7 +95,7 @@ public function getRoutes() { * @return bool */ public function isRoute($route) { - return isset($this->_route[$route]); + return isset($this->_route[strtolower($route)]); } /** From 05f3351185c183ebc9c5b2f6ddfd4141f095d4f6 Mon Sep 17 00:00:00 2001 From: cblanquera Date: Tue, 10 Jan 2012 08:30:35 +0000 Subject: [PATCH 059/330] collection and models git-svn-id: http://svn.openovate.com/edenv2/trunk@59 38ede93f-50f4-44af-b0b3-68ccca78c181 --- library/eden/collection.php | 2 +- library/eden/mysql.php | 16 +++++++++++----- library/eden/mysql/search.php | 25 +++++++++++++++++++++++-- 3 files changed, 35 insertions(+), 8 deletions(-) diff --git a/library/eden/collection.php b/library/eden/collection.php index 7b7ca5f..17d3c89 100644 --- a/library/eden/collection.php +++ b/library/eden/collection.php @@ -119,7 +119,7 @@ public function __toString() { * @return this */ public function setModel($model) { - $error = Eden_Collection_Error::get()->argument(1, 'string'); + $error = Eden_Collection_Error::i()->argument(1, 'string'); if(!is_subclass_of($model, 'Eden_Model')) { $error->setMessage(Eden_Collection_Error::NOT_SUB_MODEL) diff --git a/library/eden/mysql.php b/library/eden/mysql.php index f1b5afa..92936d3 100755 --- a/library/eden/mysql.php +++ b/library/eden/mysql.php @@ -152,7 +152,7 @@ public function getQueries($index = NULL) { * @return this */ public function setModel($model) { - $error = Eden_Mysql_Error::get()->argument(1, 'string'); + $error = Eden_Mysql_Error::i()->argument(1, 'string'); if(!is_subclass_of($model, 'Eden_Model')) { $error->setMessage(Eden_Mysql_Error::NOT_SUB_MODEL) @@ -171,7 +171,7 @@ public function setModel($model) { * @return this */ public function setCollection($collection) { - $error = Eden_Mysql_Error::get()->argument(1, 'string'); + $error = Eden_Mysql_Error::i()->argument(1, 'string'); if(!is_subclass_of($collection, 'Eden_Collection')) { $error->setMessage(Eden_Mysql_Error::NOT_SUB_COLLECTION) @@ -198,7 +198,9 @@ public function getLastInsertedId() { * @return Eden_Mysql_Search */ public function search() { - return Eden_Mysql_Search::i($this); + return Eden_Mysql_Search::i($this) + ->setCollection($this->_collection) + ->setModel($this->_model); } /** @@ -218,7 +220,9 @@ public function model(array $data = array()) { */ public function collection(array $data = array()) { $collection = $this->_collection; - return $this->$collection($data)->setDatabase($this); + return $this->$collection($data) + ->setDatabase($this) + ->setModel($this->_model); } /** @@ -429,7 +433,9 @@ public function getCollection($table, array $joins = array(), $filters = NULL, $results = $this->getRows($table, $joins, $filters, $sort, $start, $range, $index); - $collection = $this->collection()->setTable($table); + $collection = $this->collection() + ->setTable($table) + ->setModel($this->_model); if(is_null($results)) { return $collection; diff --git a/library/eden/mysql/search.php b/library/eden/mysql/search.php index c814422..0673602 100644 --- a/library/eden/mysql/search.php +++ b/library/eden/mysql/search.php @@ -37,6 +37,7 @@ class Eden_Mysql_Search extends Eden_Class { protected $_start = 0; protected $_range = 0; + protected $_model = 'Eden_Mysql_Model'; protected $_collection = 'Eden_Mysql_Collection'; /* Private Properties @@ -415,7 +416,7 @@ public function setPage($page) { * @return this */ public function setCollection($collection) { - $error = Eden_Mysql_Error::get()->argument(1, 'string'); + $error = Eden_Mysql_Error::i()->argument(1, 'string'); if(!is_subclass_of($collection, 'Eden_Collection')) { $error->setMessage(Eden_Mysql_Error::NOT_SUB_COLLECTION) @@ -427,6 +428,25 @@ public function setCollection($collection) { return $this; } + /** + * Sets default model + * + * @param string + * @return this + */ + public function setModel($model) { + $error = Eden_Mysql_Error::i()->argument(1, 'string'); + + if(!is_subclass_of($model, 'Eden_Model')) { + $error->setMessage(Eden_Mysql_Error::NOT_SUB_MODEL) + ->addVariable($model) + ->trigger(); + } + + $this->_model = $model; + return $this; + } + /** * Returns the results in a collection * @@ -436,7 +456,8 @@ public function getCollection() { $collection = $this->_collection; return $this->$collection($this->getRows()) ->setDatabase($this->_database) - ->setTable($this->_table); + ->setTable($this->_table) + ->setModel($this->_model); } /** From 2dc0303a4070e6179bbc57dadceb051c089410ae Mon Sep 17 00:00:00 2001 From: dmolina Date: Tue, 10 Jan 2012 08:43:52 +0000 Subject: [PATCH 060/330] set collection order git-svn-id: http://svn.openovate.com/edenv2/trunk@60 38ede93f-50f4-44af-b0b3-68ccca78c181 --- library/eden/collection.php | 817 +++++++-------- library/eden/mysql.php | 1863 +++++++++++++++++---------------- library/eden/mysql/search.php | 1097 +++++++++---------- 3 files changed, 1890 insertions(+), 1887 deletions(-) diff --git a/library/eden/collection.php b/library/eden/collection.php index 17d3c89..4923bde 100644 --- a/library/eden/collection.php +++ b/library/eden/collection.php @@ -1,409 +1,410 @@ - -/* - * 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. - */ - -/** - * Collection handler complements models for mass updating and handling - * - * @package Eden - * @category collection - * @author Christian Blanquera - * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ - */ -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 - -------------------------------*/ - /* Get - -------------------------------*/ - public static function i() { - return self::_getMultiple(__CLASS__); - } - - /* Magic - -------------------------------*/ - public function __construct(array $data = array()) { - $this->set($data); - } - - 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; - } - - //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 __get($name) { - //get all rows column values - $list = Eden_Model::i(); - - //for each row - foreach($this->_list as $i => $row) { - //ad just the name - $list[] = $row[$name]; - } - - return $list; - } - - 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 - -------------------------------*/ - /** - * 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 - * - * @return this - */ - public function set(array $data = array()) { - foreach($data as $row) { - $this->add($row); - } - - return $this; - } - - /** - * 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; - } - - /** - * Adds a row to the collection - * - * @param string - * @param string - * @return this - */ - public function copy($source, $destination) { - //Argument Test - Eden_Collection_Error::i() - ->argument(1, 'string') //Argument 1 must be a string - ->argument(2, 'string'); //Argument 2 must be a string - - //for each row - foreach($this->_list as $row) { - //let the model handle the copying - $row->copy($source, $destination); - } - - return $this; - } - - 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; - } - - /** - * 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; - } - - /** - * Rewinds the position - * For Iterator interface - * - * @return void - */ - public function rewind() { - reset($this->_list); - } - - /** - * Returns the current item - * For Iterator interface - * - * @return void - */ - public function current() { - return current($this->_list); - } - - /** - * 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); - } - - /** - * Validates whether if the index is set - * For Iterator interface - * - * @return void - */ - public function valid() { - return isset($this->_list[key($this->_list)]); - } - - /** - * 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; - } - } - - /** - * isset using the ArrayAccess interface - * - * @param number - * @return bool - */ - public function offsetExists($offset) { - return isset($this->_list[$offset]); - } - - /** - * unsets using the ArrayAccess interface - * - * @param number - * @return bool - */ - public function offsetUnset($offset) { - $this->_list = Eden_Model::i($this->_list) - ->cut($offset) - ->get(); - } - - /** - * returns data using the ArrayAccess interface - * - * @param number - * @return bool - */ - public function offsetGet($offset) { - return isset($this->_list[$offset]) ? $this->_list[$offset] : NULL; - } - - /** - * returns serialized data using the Serializable interface - * - * @return string - */ - public function serialize() { - return $this->__toString(); - } - - /** - * sets data using the Serializable interface - * - * @param string - * @return void - */ - public function unserialize($data) { - $this->_list = json_decode($data, true); - return $this; - } - - /** - * returns size using the Countable interface - * - * @return string - */ - public function count() { - return count($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 - -------------------------------*/ - /* Get - -------------------------------*/ - public static function i($message = NULL, $code = 0) { - $class = __CLASS__; - return new $class($message, $code); - } - - /* Magic - -------------------------------*/ - /* Public Methods - -------------------------------*/ - /* Protected Methods - -------------------------------*/ - /* Private Methods - -------------------------------*/ + +/* + * 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. + */ + +/** + * Collection handler complements models for mass updating and handling + * + * @package Eden + * @category collection + * @author Christian Blanquera + * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ + */ +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 + -------------------------------*/ + /* Get + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + /* Magic + -------------------------------*/ + public function __construct(array $data = array()) { + $this->set($data); + } + + 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; + } + + //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 __get($name) { + //get all rows column values + $list = Eden_Model::i(); + + //for each row + foreach($this->_list as $i => $row) { + //ad just the name + $list[] = $row[$name]; + } + + return $list; + } + + 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 + -------------------------------*/ + /** + * 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 + * + * @return this + */ + public function set(array $data = array()) { + foreach($data as $row) { + $this->add($row); + } + + return $this; + } + + /** + * 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; + } + + /** + * Adds a row to the collection + * + * @param string + * @param string + * @return this + */ + public function copy($source, $destination) { + //Argument Test + Eden_Collection_Error::i() + ->argument(1, 'string') //Argument 1 must be a string + ->argument(2, 'string'); //Argument 2 must be a string + + //for each row + foreach($this->_list as $row) { + //let the model handle the copying + $row->copy($source, $destination); + } + + return $this; + } + + 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; + } + + /** + * 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; + } + + /** + * Rewinds the position + * For Iterator interface + * + * @return void + */ + public function rewind() { + reset($this->_list); + } + + /** + * Returns the current item + * For Iterator interface + * + * @return void + */ + public function current() { + return current($this->_list); + } + + /** + * 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); + } + + /** + * Validates whether if the index is set + * For Iterator interface + * + * @return void + */ + public function valid() { + return isset($this->_list[key($this->_list)]); + } + + /** + * 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; + } + } + + /** + * isset using the ArrayAccess interface + * + * @param number + * @return bool + */ + public function offsetExists($offset) { + return isset($this->_list[$offset]); + } + + /** + * unsets using the ArrayAccess interface + * + * @param number + * @return bool + */ + public function offsetUnset($offset) { + $this->_list = Eden_Model::i($this->_list) + ->cut($offset) + ->get(); + } + + /** + * returns data using the ArrayAccess interface + * + * @param number + * @return bool + */ + public function offsetGet($offset) { + return isset($this->_list[$offset]) ? $this->_list[$offset] : NULL; + } + + /** + * returns serialized data using the Serializable interface + * + * @return string + */ + public function serialize() { + return $this->__toString(); + } + + /** + * sets data using the Serializable interface + * + * @param string + * @return void + */ + public function unserialize($data) { + $this->_list = json_decode($data, true); + return $this; + } + + /** + * returns size using the Countable interface + * + * @return string + */ + public function count() { + return count($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 + -------------------------------*/ + /* 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/mysql.php b/library/eden/mysql.php index 92936d3..6d61119 100755 --- a/library/eden/mysql.php +++ b/library/eden/mysql.php @@ -1,931 +1,932 @@ - -/* - * 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__).'/event.php'; -require_once dirname(__FILE__).'/sql/error.php'; -require_once dirname(__FILE__).'/mysql/error.php'; -require_once dirname(__FILE__).'/sql/database.php'; -require_once dirname(__FILE__).'/sql/query.php'; -require_once dirname(__FILE__).'/sql/delete.php'; -require_once dirname(__FILE__).'/sql/select.php'; -require_once dirname(__FILE__).'/sql/update.php'; -require_once dirname(__FILE__).'/sql/insert.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'; -require_once dirname(__FILE__).'/mysql/collection.php'; -require_once dirname(__FILE__).'/mysql/model.php'; -require_once dirname(__FILE__).'/mysql/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 - * @version $Id: abstract.php 1 2010-01-02 23:06:36Z blanquera $ - */ -class Eden_Mysql extends Eden_Sql_Database { - /* Constants - -------------------------------*/ - const FIRST = 'first'; - const LAST = 'last'; - - const MODEL = 'Eden_Mysql_Model'; - const COLLECTION = 'Eden_Mysql_Collection'; - - /* Public Properties - -------------------------------*/ - /* Protected Properties - -------------------------------*/ - protected $_type = NULL; - protected $_host = 'localhost'; - protected $_name = NULL; - protected $_user = NULL; - protected $_pass = NULL; - protected $_queries = array(); - - protected $_connection = NULL; - protected $_binds = array(); - - protected $_model = self::MODEL; - protected $_collection = self::COLLECTION; - - /* Private Properties - -------------------------------*/ - /* Get - -------------------------------*/ - public static function i() { - return self::_getMultiple(__CLASS__); - } - - /* Magic - -------------------------------*/ - public function __construct($host, $name, $user, $pass = NULL) { - //argument test - Eden_Mysql_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 number or null - - $this->_host = $host; - $this->_name = $name; - $this->_user = $user; - $this->_pass = $pass; - } - - /* Public Methods - -------------------------------*/ - /** - * Connects to the database - * - * @param array the connection options - * @return this - */ - public function connect(array $options = array()) { - $connection = 'mysql:host='.$this->_host.';dbname='.$this->_name; - - $this->_connection = new PDO($connection, $this->_user, $this->_pass, $options); - - $this->trigger(); - - return $this; - } - - /** - * 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 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; - } - - /** - * Sets the default model - * - * @param string - * @return this - */ - public function setModel($model) { - $error = Eden_Mysql_Error::i()->argument(1, 'string'); - - if(!is_subclass_of($model, 'Eden_Model')) { - $error->setMessage(Eden_Mysql_Error::NOT_SUB_MODEL) - ->addVariable($model) - ->trigger(); - } - - $this->_model = $model; - return $this; - } - - /** - * Sets default collection - * - * @param string - * @return this - */ - public function setCollection($collection) { - $error = Eden_Mysql_Error::i()->argument(1, 'string'); - - if(!is_subclass_of($collection, 'Eden_Collection')) { - $error->setMessage(Eden_Mysql_Error::NOT_SUB_COLLECTION) - ->addVariable($collection) - ->trigger(); - } - - $this->_collection = $collection; - return $this; - } - - /** - * Returns the last inserted id - * - * @return int the id - */ - public function getLastInsertedId() { - return $this->getConnection()->lastInsertId(); - } - - /** - * Returns search - * - * @return Eden_Mysql_Search - */ - public function search() { - return Eden_Mysql_Search::i($this) - ->setCollection($this->_collection) - ->setModel($this->_model); - } - - /** - * Returns model - * - * @return Eden_Mysql_Model - */ - public function model(array $data = array()) { - $model = $this->_model; - return $this->$model($data)->setDatabase($this); - } - - /** - * Returns collection - * - * @return Eden_Mysql_Collection - */ - public function collection(array $data = array()) { - $collection = $this->_collection; - return $this->$collection($data) - ->setDatabase($this) - ->setModel($this->_model); - } - - /** - * 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); - } - - /** - * 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 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_Mysql_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_Mysql_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); - $filter = $this->bind($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, $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 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_Mysql_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 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_Mysql_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 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_Mysql_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; - } - - /** - * 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_Mysql_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_Mysql_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; - } - - /** - * 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_Mysql_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); - $filter = $this->bind($filter); - $filters[$i] = vsprintf($format, $filter); - } - } - - $query->where($filters); - - //run the query - $this->query($query, $this->getBinds()); - - $this->trigger($table, $setting, $filters); - - 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_Mysql_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, 'eq', $value))); - } - } - - /** - * 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_Mysql_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); - $filter = $this->bind($filter); - $filters[$i] = vsprintf($format, $filter); - } - } - - $query->where($filters); - - //run the query - $this->query($query, $this->getBinds()); - - $this->trigger($table, $filters); - - return $this; - } - - /** - * 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 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()); - } - - /** - * 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); - } - - /** - * 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 databse - * - * @return string - */ - public function getSchema() { - $backup = array(); - $tables = $this->getTables(); - foreach($tables as $table) { - $backup[] = $this->getBackup(); - } - - return implode("\n\n", $backup); - } - - /** - * 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_Mysql_Error::i()->argument(1, 'string', 'Eden_Sql_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_Mysql_Error::i() - ->setMessage(Eden_Mysql_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; - } - - /** - * 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_Mysql_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 all the bound values of this query - * - * @param void - * @return array - */ - public function getBinds() { - return $this->_binds; - } - - /** - * Sets all the bound values of this query - * - * @param array - * @return this - */ - public function setBinds(array $binds) { - $this->_binds = $binds; - return $this; - } - - /* Protected Methods - -------------------------------*/ - /* Private Methods - -------------------------------*/ -} - + +/* + * 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__).'/event.php'; +require_once dirname(__FILE__).'/sql/error.php'; +require_once dirname(__FILE__).'/mysql/error.php'; +require_once dirname(__FILE__).'/sql/database.php'; +require_once dirname(__FILE__).'/sql/query.php'; +require_once dirname(__FILE__).'/sql/delete.php'; +require_once dirname(__FILE__).'/sql/select.php'; +require_once dirname(__FILE__).'/sql/update.php'; +require_once dirname(__FILE__).'/sql/insert.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'; +require_once dirname(__FILE__).'/mysql/collection.php'; +require_once dirname(__FILE__).'/mysql/model.php'; +require_once dirname(__FILE__).'/mysql/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 + * @version $Id: abstract.php 1 2010-01-02 23:06:36Z blanquera $ + */ +class Eden_Mysql extends Eden_Sql_Database { + /* Constants + -------------------------------*/ + const FIRST = 'first'; + const LAST = 'last'; + + const MODEL = 'Eden_Mysql_Model'; + const COLLECTION = 'Eden_Mysql_Collection'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_type = NULL; + protected $_host = 'localhost'; + protected $_name = NULL; + protected $_user = NULL; + protected $_pass = NULL; + protected $_queries = array(); + + protected $_connection = NULL; + protected $_binds = array(); + + protected $_model = self::MODEL; + protected $_collection = self::COLLECTION; + + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + /* Magic + -------------------------------*/ + public function __construct($host, $name, $user, $pass = NULL) { + //argument test + Eden_Mysql_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 number or null + + $this->_host = $host; + $this->_name = $name; + $this->_user = $user; + $this->_pass = $pass; + } + + /* Public Methods + -------------------------------*/ + /** + * Connects to the database + * + * @param array the connection options + * @return this + */ + public function connect(array $options = array()) { + $connection = 'mysql:host='.$this->_host.';dbname='.$this->_name; + + $this->_connection = new PDO($connection, $this->_user, $this->_pass, $options); + + $this->trigger(); + + return $this; + } + + /** + * 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 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; + } + + /** + * Sets the default model + * + * @param string + * @return this + */ + public function setModel($model) { + $error = Eden_Mysql_Error::i()->argument(1, 'string'); + + if(!is_subclass_of($model, 'Eden_Model')) { + $error->setMessage(Eden_Mysql_Error::NOT_SUB_MODEL) + ->addVariable($model) + ->trigger(); + } + + $this->_model = $model; + return $this; + } + + /** + * Sets default collection + * + * @param string + * @return this + */ + public function setCollection($collection) { + $error = Eden_Mysql_Error::i()->argument(1, 'string'); + + if(!is_subclass_of($collection, 'Eden_Collection')) { + $error->setMessage(Eden_Mysql_Error::NOT_SUB_COLLECTION) + ->addVariable($collection) + ->trigger(); + } + + $this->_collection = $collection; + return $this; + } + + /** + * Returns the last inserted id + * + * @return int the id + */ + public function getLastInsertedId() { + return $this->getConnection()->lastInsertId(); + } + + /** + * Returns search + * + * @return Eden_Mysql_Search + */ + public function search() { + return Eden_Mysql_Search::i($this) + ->setCollection($this->_collection) + ->setModel($this->_model); + } + + /** + * Returns model + * + * @return Eden_Mysql_Model + */ + public function model(array $data = array()) { + $model = $this->_model; + return $this->$model($data)->setDatabase($this); + } + + /** + * Returns collection + * + * @return Eden_Mysql_Collection + */ + public function collection(array $data = array()) { + $collection = $this->_collection; + return $this->$collection() + ->setDatabase($this) + ->setModel($this->_model) + ->set($data); + } + + /** + * 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); + } + + /** + * 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 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_Mysql_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_Mysql_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); + $filter = $this->bind($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, $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 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_Mysql_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 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_Mysql_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 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_Mysql_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; + } + + /** + * 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_Mysql_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_Mysql_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; + } + + /** + * 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_Mysql_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); + $filter = $this->bind($filter); + $filters[$i] = vsprintf($format, $filter); + } + } + + $query->where($filters); + + //run the query + $this->query($query, $this->getBinds()); + + $this->trigger($table, $setting, $filters); + + 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_Mysql_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, 'eq', $value))); + } + } + + /** + * 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_Mysql_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); + $filter = $this->bind($filter); + $filters[$i] = vsprintf($format, $filter); + } + } + + $query->where($filters); + + //run the query + $this->query($query, $this->getBinds()); + + $this->trigger($table, $filters); + + return $this; + } + + /** + * 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 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()); + } + + /** + * 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); + } + + /** + * 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 databse + * + * @return string + */ + public function getSchema() { + $backup = array(); + $tables = $this->getTables(); + foreach($tables as $table) { + $backup[] = $this->getBackup(); + } + + return implode("\n\n", $backup); + } + + /** + * 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_Mysql_Error::i()->argument(1, 'string', 'Eden_Sql_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_Mysql_Error::i() + ->setMessage(Eden_Mysql_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; + } + + /** + * 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_Mysql_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 all the bound values of this query + * + * @param void + * @return array + */ + public function getBinds() { + return $this->_binds; + } + + /** + * Sets all the bound values of this query + * + * @param array + * @return this + */ + public function setBinds(array $binds) { + $this->_binds = $binds; + return $this; + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} + diff --git a/library/eden/mysql/search.php b/library/eden/mysql/search.php index 0673602..a36a500 100644 --- a/library/eden/mysql/search.php +++ b/library/eden/mysql/search.php @@ -1,549 +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. - */ - -/** - * Mysql Collection handler - * - * @package Eden - * @category mysql - * @author Christian Blanquera - * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ - */ -class Eden_Mysql_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 $_join = array(); - protected $_filter = array(); - protected $_sort = array(); - protected $_group = array(); - protected $_start = 0; - protected $_range = 0; - - protected $_model = 'Eden_Mysql_Model'; - protected $_collection = 'Eden_Mysql_Collection'; - - /* Private Properties - -------------------------------*/ - /* Get - -------------------------------*/ - public static function i() { - return self::_getMultiple(__CLASS__); - } - - /* Magic - -------------------------------*/ - public function __construct(Eden_Mysql $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-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_Mysql_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_Mysql_Error::i()->argument(1, 'string'); - $this->_table = $table; - return $this; - } - - /** - * Adds Inner Join On - * - * @param string - * @param string[,string..] - * @return this - */ - public function addInnerJoinOn($table, $where) { - Eden_Mysql_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_Mysql_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_Mysql_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_Mysql_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 Right Join On - * - * @param string - * @param string[,string..] - * @return this - */ - public function addRightJoinOn($table, $where) { - Eden_Mysql_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_Mysql_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 Outer Join On - * - * @param string - * @param string[,string..] - * @return this - */ - public function addOuterJoinOn($table, $where) { - Eden_Mysql_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_Mysql_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 filter - * - * @param string - * @param string[,string..] - * @return this - */ - public function addFilter() { - Eden_Mysql_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_Mysql_Error::i() - ->argument(1, 'string') - ->argument(2, 'string'); - - if($order != self::DESC) { - $order = self::ASC; - } - - $this->_sort[$column] = $order; - - 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_Mysql_Error::i()->argument(1, 'string', 'array'); - - if(is_string($group)) { - $group = array($group); - } - - $this->_group = $group; - return $this; - } - - /** - * Sets the pagination start - * - * @param int - * @return this - */ - public function setStart($start) { - Eden_Mysql_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_Mysql_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_Mysql_Error::i()->argument(1, 'int'); - - if($page < 1) { - $page = 1; - } - - $this->_start = ($page - 1) * $this->_range; - - return $this; - } - - /** - * Sets default collection - * - * @param string - * @return this - */ - public function setCollection($collection) { - $error = Eden_Mysql_Error::i()->argument(1, 'string'); - - if(!is_subclass_of($collection, 'Eden_Collection')) { - $error->setMessage(Eden_Mysql_Error::NOT_SUB_COLLECTION) - ->addVariable($collection) - ->trigger(); - } - - $this->_collection = $collection; - return $this; - } - - /** - * Sets default model - * - * @param string - * @return this - */ - public function setModel($model) { - $error = Eden_Mysql_Error::i()->argument(1, 'string'); - - if(!is_subclass_of($model, 'Eden_Model')) { - $error->setMessage(Eden_Mysql_Error::NOT_SUB_MODEL) - ->addVariable($model) - ->trigger(); - } - - $this->_model = $model; - return $this; - } - - /** - * Returns the results in a collection - * - * @return Eden_Mysql_Collection - */ - public function getCollection() { - $collection = $this->_collection; - return $this->$collection($this->getRows()) - ->setDatabase($this->_database) - ->setTable($this->_table) - ->setModel($this->_model); - } - - /** - * 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']; - } - - /* 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 - -------------------------------*/ + +/* + * 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. + */ + +/** + * Mysql Collection handler + * + * @package Eden + * @category mysql + * @author Christian Blanquera + * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ + */ +class Eden_Mysql_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 $_join = array(); + protected $_filter = array(); + protected $_sort = array(); + protected $_group = array(); + protected $_start = 0; + protected $_range = 0; + + protected $_model = 'Eden_Mysql_Model'; + protected $_collection = 'Eden_Mysql_Collection'; + + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + /* Magic + -------------------------------*/ + public function __construct(Eden_Mysql $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-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_Mysql_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_Mysql_Error::i()->argument(1, 'string'); + $this->_table = $table; + return $this; + } + + /** + * Adds Inner Join On + * + * @param string + * @param string[,string..] + * @return this + */ + public function addInnerJoinOn($table, $where) { + Eden_Mysql_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_Mysql_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_Mysql_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_Mysql_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 Right Join On + * + * @param string + * @param string[,string..] + * @return this + */ + public function addRightJoinOn($table, $where) { + Eden_Mysql_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_Mysql_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 Outer Join On + * + * @param string + * @param string[,string..] + * @return this + */ + public function addOuterJoinOn($table, $where) { + Eden_Mysql_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_Mysql_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 filter + * + * @param string + * @param string[,string..] + * @return this + */ + public function addFilter() { + Eden_Mysql_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_Mysql_Error::i() + ->argument(1, 'string') + ->argument(2, 'string'); + + if($order != self::DESC) { + $order = self::ASC; + } + + $this->_sort[$column] = $order; + + 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_Mysql_Error::i()->argument(1, 'string', 'array'); + + if(is_string($group)) { + $group = array($group); + } + + $this->_group = $group; + return $this; + } + + /** + * Sets the pagination start + * + * @param int + * @return this + */ + public function setStart($start) { + Eden_Mysql_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_Mysql_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_Mysql_Error::i()->argument(1, 'int'); + + if($page < 1) { + $page = 1; + } + + $this->_start = ($page - 1) * $this->_range; + + return $this; + } + + /** + * Sets default collection + * + * @param string + * @return this + */ + public function setCollection($collection) { + $error = Eden_Mysql_Error::i()->argument(1, 'string'); + + if(!is_subclass_of($collection, 'Eden_Collection')) { + $error->setMessage(Eden_Mysql_Error::NOT_SUB_COLLECTION) + ->addVariable($collection) + ->trigger(); + } + + $this->_collection = $collection; + return $this; + } + + /** + * Sets default model + * + * @param string + * @return this + */ + public function setModel($model) { + $error = Eden_Mysql_Error::i()->argument(1, 'string'); + + if(!is_subclass_of($model, 'Eden_Model')) { + $error->setMessage(Eden_Mysql_Error::NOT_SUB_MODEL) + ->addVariable($model) + ->trigger(); + } + + $this->_model = $model; + return $this; + } + + /** + * Returns the results in a collection + * + * @return Eden_Mysql_Collection + */ + public function getCollection() { + $collection = $this->_collection; + return $this->$collection() + ->setDatabase($this->_database) + ->setTable($this->_table) + ->setModel($this->_model) + ->set($this->getRows()); + } + + /** + * 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']; + } + + /* 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 From 611db12295b862c18703425ccd897a26776aff11 Mon Sep 17 00:00:00 2001 From: dmolina Date: Tue, 10 Jan 2012 12:28:26 +0000 Subject: [PATCH 061/330] update library git-svn-id: http://svn.openovate.com/edenv2/trunk@61 38ede93f-50f4-44af-b0b3-68ccca78c181 --- library/eden/curl.php | 1040 ++++++++++++++--------------- library/eden/mysql/collection.php | 407 ++++++----- library/eden/type/array.php | 798 +++++++++++----------- 3 files changed, 1141 insertions(+), 1104 deletions(-) diff --git a/library/eden/curl.php b/library/eden/curl.php index 526204b..1df6d49 100644 --- a/library/eden/curl.php +++ b/library/eden/curl.php @@ -1,521 +1,521 @@ - -/* - * 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__).'/class.php'; - -/** - * cURL wrapper - * - * @package Eden - * @category curl - * @author Christian Blanquera - * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ - */ -class Eden_Curl extends Eden_Class implements ArrayAccess { - /* Constants - -------------------------------*/ - /* 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 - -------------------------------*/ - /* Get - -------------------------------*/ - public static function i() { - return self::_getMultiple(__CLASS__); - } - - /* Magic - -------------------------------*/ - public function __call($name, $args) { - if(strpos($name, 'set') === 0) { - $method = substr($name, 3); - - if(isset(self::$_setBoolKeys[$method])) { - Eden_Curl_Error::get()->vargument($name, $args, 1, 'bool'); - $key = self::$_setBoolKeys[$method]; - $this->_options[$key] = $args[0]; - - return $this; - } - - if(isset(self::$_setIntegerKeys[$method])) { - Eden_Curl_Error::get()->vargument($name, $args, 1, 'int'); - $key = self::$_setIntegerKeys[$method]; - $this->_options[$key] = $args[0]; - - return $this; - } - - if(isset(self::$_setStringKeys[$method])) { - Eden_Curl_Error::get()->vargument($name, $args, 1, 'string'); - $key = self::$_setStringKeys[$method]; - $this->_options[$key] = $args[0]; - - return $this; - } - - if(isset(self::$_setArrayKeys[$method])) { - Eden_Curl_Error::get()->vargument($name, $args, 1, 'array'); - $key = self::$_setArrayKeys[$method]; - $this->_options[$key] = $args[0]; - - return $this; - } - - if(isset(self::$_setFileKeys[$method])) { - $key = $this->_setFileKeys[$method]; - $this->_options[$key] = $args[0]; - - return $this; - } - - if(isset(self::$_setCallbackKeys[$method])) { - Eden_Curl_Error::get()->vargument($name, $args, 1, 'array', 'string'); - $key = self::$_setCallbackKeys[$method]; - $this->_options[$key] = $args[0]; - - return $this; - } - } - - parent::__call($name, $args); - } - - /* Public Methods - -------------------------------*/ - /** - * Sets CURLOPT_SSL_VERIFYHOST - * - * @param bool - * @return this - */ - public function verifyHost($on = true) { - Eden_Curl_Error::get()->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::get()->argument(1, 'bool'); - $this->options[CURLOPT_SSL_VERIFYPEER] = $on; - return $this; - } - - /** - * Sets url parameter - * - * @param array|string - * @return this - */ - public function setUrlParameter($key, $value = NULL) { - Eden_Curl_Error::get() - ->argument(1, 'array', 'string') - ->argument(2, 'scalar'); - - if(is_array($key)) { - $this->_param = $key; - return $this; - } - - $this->_param[$key] = $value; - } - - /** - * Sets request headers - * - * @param array|string - * @return this - */ - public function setHeaders($key, $value = NULL) { - Eden_Curl_Error::get() - ->argument(1, 'array', 'string') - ->argument(2, 'scalar','null'); - - if(is_array($key)) { - $this->_headers = $key; - return $this; - } - - $this->_headers[] = $key.': '.$value; - return $this; - } - - /** - * 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; - } - - /** - * 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 JSON - * - * @return array - */ - public function getJsonResponse($assoc = true) { - $this->_meta['response'] = $this->getResponse(); - Eden_Curl_Error::get()->argument(1, 'bool'); - return json_decode($this->_meta['response'], $assoc); - } - - /** - * 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 - * parsed as SimpleXml - * - * @return SimpleXmlElement - */ - public function getSimpleXmlResponse() { - $this->_meta['response'] = $this->getResponse(); - return simplexml_load_string($this->_meta['response']); - } - - /** - * 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; - } - - /** - * Returns the meta of the last call - * - * @return array - */ - public function getMeta($key = NULL) { - Eden_Curl_Error::get()->argument(1, 'string', 'null'); - - if(isset($this->_meta[$key])) { - return $this->_meta[$key]; - } - - return $this->_meta; - } - - /** - * 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)); - } - } - } - - /** - * isset using the ArrayAccess interface - * - * @param number - * @return bool - */ - public function offsetExists($offset) { - return isset($this->_option[$offset]); - } - - /** - * unsets using the ArrayAccess interface - * - * @param number - * @return bool - */ - public function offsetUnset($offset) { - unset($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; - } - - /* Protected Methods - -------------------------------*/ - 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; - } - - protected function _addHeaders() { - if(empty($this->_headers)) { - return $this; - } - - $this->_options[CURLOPT_HTTPHEADER] = $this->_headers; - return $this; - } - - /* Private Methods - -------------------------------*/ -} - -/** - * cUrl Errors - */ -class Eden_Curl_Error extends Eden_Error { - /* Constants - -------------------------------*/ - /* Public Properties - -------------------------------*/ - /* Protected Properties - -------------------------------*/ - /* Private Properties - -------------------------------*/ - /* Get - -------------------------------*/ - public static function get($message = NULL, $code = 0) { - $class = __CLASS__; - return new $class($message, $code); - } - - /* Magic - -------------------------------*/ - /* Public Methods - -------------------------------*/ - /* Protected Methods - -------------------------------*/ - /* Private Methods - -------------------------------*/ + +/* + * 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__).'/class.php'; + +/** + * cURL wrapper + * + * @package Eden + * @category curl + * @author Christian Blanquera + * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ + */ +class Eden_Curl extends Eden_Class implements ArrayAccess { + /* Constants + -------------------------------*/ + /* 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 + -------------------------------*/ + /* Get + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + /* Magic + -------------------------------*/ + 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 = $this->_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 + -------------------------------*/ + /** + * 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; + } + + /** + * 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 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; + } + + /** + * 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; + } + + /** + * 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 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); + } + + /** + * 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 + * parsed as SimpleXml + * + * @return SimpleXmlElement + */ + public function getSimpleXmlResponse() { + $this->_meta['response'] = $this->getResponse(); + return simplexml_load_string($this->_meta['response']); + } + + /** + * 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; + } + + /** + * 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; + } + + /** + * 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)); + } + } + } + + /** + * isset using the ArrayAccess interface + * + * @param number + * @return bool + */ + public function offsetExists($offset) { + return isset($this->_option[$offset]); + } + + /** + * unsets using the ArrayAccess interface + * + * @param number + * @return bool + */ + public function offsetUnset($offset) { + unset($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; + } + + /* Protected Methods + -------------------------------*/ + 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; + } + + protected function _addHeaders() { + if(empty($this->_headers)) { + return $this; + } + + $this->_options[CURLOPT_HTTPHEADER] = $this->_headers; + return $this; + } + + /* Private Methods + -------------------------------*/ +} + +/** + * cUrl Errors + */ +class Eden_Curl_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/mysql/collection.php b/library/eden/mysql/collection.php index cd47f1a..60f72f6 100644 --- a/library/eden/mysql/collection.php +++ b/library/eden/mysql/collection.php @@ -1,186 +1,223 @@ - -/* - * 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. - */ - -/** - * Mysql Collection handler - * - * @package Eden - * @category mysql - * @author Christian Blanquera - * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ - */ -class Eden_Mysql_Collection extends Eden_Collection { - /* Constants - -------------------------------*/ - /* Public Properties - -------------------------------*/ - /* Protected Properties - -------------------------------*/ - protected $_model = 'Eden_Mysql_Model'; - - /* Private Properties - -------------------------------*/ - /* Get - -------------------------------*/ - public static function i() { - return self::_getMultiple(__CLASS__); - } - - /* Magic - -------------------------------*/ - /* Public Methods - -------------------------------*/ - /** - * Sets the default database - * - * @param Eden_Mysql - */ - public function setDatabase(Eden_Mysql $database) { - //for each row - foreach($this->_list as $row) { - if(!is_object($row) || !method_exists($row, 'setDatabase')) { - continue; - } - - //let the row handle this - $row->setDatabase($database); - } - - return $this; - } - - /** - * Sets the default database - * - * @param string - */ - public function setTable($table) { - //Argument 1 must be a string - Eden_Mysql_Error::i()->argument(1, 'string'); - - //for each row - foreach($this->_list as $row) { - if(!is_object($row) || !method_exists($row, 'setTable')) { - continue; - } - - //let the row handle this - $row->setTable($table); - } - - return $this; - } - - /** - * Useful method for formating a time column. - * - * @param string - * @param string - * @return this - */ - public function formatTime($column, $format = Eden_Mysql_Model::DATETIME) { - //for each row - foreach($this->_list as $row) { - if(!is_object($row) || !method_exists($row, 'formatTime')) { - continue; - } - - //let the row handle this - $row->formatTime($column, $format); - } - - return $this; - } - - /** - * Insert collection to database - * - * @param string - * @param Eden_Mysql - * @return this - */ - public function insert($table = NULL, Eden_Mysql $database = NULL) { - //for each row - foreach($this->_list as $i => $row) { - if(!is_object($row) || !method_exists($row, 'insert')) { - continue; - } - - $row->insert($table, $database); - } - - return $this; - } - - /** - * Updates collection to database - * - * @param string - * @param Eden_Mysql - * @return this - */ - public function update($table = NULL, Eden_Mysql $database = NULL) { - //for each row - foreach($this->_list as $i => $row) { - if(!is_object($row) || !method_exists($row, 'update')) { - continue; - } - - $row->update($table, $database); - } - - return $this; - } - - /** - * Inserts or updates collection to database - * - * @param string - * @param Eden_Mysql - * @return this - */ - public function save($table = NULL, Eden_Mysql $database = NULL) { - //for each row - foreach($this->_list as $i => $row) { - if(!is_object($row) || !method_exists($row, 'save')) { - continue; - } - - $row->save($table, $database); - } - - return $this; - } - - /** - * Removes collection from database - * - * @param string - * @param Eden_Mysql - * @return this - */ - public function remove($table = NULL, Eden_Mysql $database = NULL) { - //for each row - foreach($this->_list as $i => $row) { - if(!is_object($row) || !method_exists($row, 'remove')) { - continue; - } - - //let the row handle this - $row->remove($table, $database); - } - - return $this; - } - - /* Protected Methods - -------------------------------*/ - /* Private Methods - -------------------------------*/ + +/* + * 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. + */ + +/** + * Mysql Collection handler + * + * @package Eden + * @category mysql + * @author Christian Blanquera + * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ + */ +class Eden_Mysql_Collection extends Eden_Collection { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_model = 'Eden_Mysql_Model'; + protected $_database = NULL; + protected $_table = NULL; + + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + /* Magic + -------------------------------*/ + /* Public Methods + -------------------------------*/ + /** + * Sets the default database + * + * @param Eden_Mysql + */ + public function setDatabase(Eden_Mysql $database) { + $this->_database = $database; + + //for each row + foreach($this->_list as $row) { + if(!is_object($row) || !method_exists($row, 'setDatabase')) { + continue; + } + + //let the row handle this + $row->setDatabase($database); + } + + return $this; + } + + /** + * Sets the default database + * + * @param string + */ + public function setTable($table) { + //Argument 1 must be a string + Eden_Mysql_Error::i()->argument(1, 'string'); + + $this->_table = $table; + + //for each row + foreach($this->_list as $row) { + if(!is_object($row) || !method_exists($row, 'setTable')) { + continue; + } + + //let the row handle this + $row->setTable($table); + } + + return $this; + } + + /** + * Useful method for formating a time column. + * + * @param string + * @param string + * @return this + */ + public function formatTime($column, $format = Eden_Mysql_Model::DATETIME) { + //for each row + foreach($this->_list as $row) { + if(!is_object($row) || !method_exists($row, 'formatTime')) { + continue; + } + + //let the row handle this + $row->formatTime($column, $format); + } + + return $this; + } + + /** + * 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_Mysql_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; + } + + /** + * Insert collection to database + * + * @param string + * @param Eden_Mysql + * @return this + */ + public function insert($table = NULL, Eden_Mysql $database = NULL) { + //for each row + foreach($this->_list as $i => $row) { + if(!is_object($row) || !method_exists($row, 'insert')) { + continue; + } + + $row->insert($table, $database); + } + + return $this; + } + + /** + * Updates collection to database + * + * @param string + * @param Eden_Mysql + * @return this + */ + public function update($table = NULL, Eden_Mysql $database = NULL) { + //for each row + foreach($this->_list as $i => $row) { + if(!is_object($row) || !method_exists($row, 'update')) { + continue; + } + + $row->update($table, $database); + } + + return $this; + } + + /** + * Inserts or updates collection to database + * + * @param string + * @param Eden_Mysql + * @return this + */ + public function save($table = NULL, Eden_Mysql $database = NULL) { + //for each row + foreach($this->_list as $i => $row) { + if(!is_object($row) || !method_exists($row, 'save')) { + continue; + } + + $row->save($table, $database); + } + + return $this; + } + + /** + * Removes collection from database + * + * @param string + * @param Eden_Mysql + * @return this + */ + public function remove($table = NULL, Eden_Mysql $database = NULL) { + //for each row + foreach($this->_list as $i => $row) { + if(!is_object($row) || !method_exists($row, 'remove')) { + continue; + } + + //let the row handle this + $row->remove($table, $database); + } + + return $this; + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ } \ No newline at end of file diff --git a/library/eden/type/array.php b/library/eden/type/array.php index 38202f3..fee1d15 100644 --- a/library/eden/type/array.php +++ b/library/eden/type/array.php @@ -1,400 +1,400 @@ - -/* - * 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. - */ - -/** - * - * @package Eden - * @category registry - * @author Christian Blanquera - * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ - */ -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 - -------------------------------*/ - /* Get - -------------------------------*/ - public static function i() { - return self::_getMultiple(__CLASS__); - } - - /* Magic - -------------------------------*/ - public function __construct($data) { - //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 __toString() { - return json_encode($this->get()); - } - - public function __get($name) { - if(isset($this->_data[$name])) { - return $this->_data[$name]; - } - - return NULL; - } - - public function __set($name, $value) { - $this->_data[$name] = $value; - } - - 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))); - - return $this->__get($key); - - } 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 Methods - -------------------------------*/ - /** - * Sets data - * - * @return this - */ - public function set($value) { - Eden_Type_Error::get()->argument(1, 'array'); - $this->_data = $value; - return $this; - } - - /** - * Returns if the data is empty - * - * @return bool - */ - public function isEmpty() { - return empty($this->_data); - } - - /** - * 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; - } - - /** - * 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; - } - - /** - * 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 the current item - * For Iterator interface - * - * @return void - */ - public function current() { - return current($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); - } - - /** - * Validates whether if the index is set - * For Iterator interface - * - * @return void - */ - public function valid() { - return isset($this->_data[$this->key()]); - } - - /** - * 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; - } - } - - /** - * isset using the ArrayAccess interface - * - * @param number - * @return bool - */ - public function offsetExists($offset) { - return isset($this->_data[$offset]); - } - - /** - * unsets using the ArrayAccess interface - * - * @param number - * @return bool - */ - public function offsetUnset($offset) { - unset($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; - } - - /** - * returns serialized data using the Serializable interface - * - * @return string - */ - public function serialize() { - return json_encode($this->_data); - } - - /** - * sets data using the Serializable interface - * - * @param string - * @return void - */ - public function unserialize($data) { - $this->_data = json_decode($data, true); - return $this; - } - - /** - * returns size using the Countable interface - * - * @return string - */ - public function count() { - return count($this->_data); - } - - /* 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 - -------------------------------*/ + +/* + * 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. + */ + +/** + * + * @package Eden + * @category registry + * @author Christian Blanquera + * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ + */ +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 + -------------------------------*/ + /* Get + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + /* Magic + -------------------------------*/ + 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 __toString() { + return json_encode($this->get()); + } + + public function __get($name) { + if(isset($this->_data[$name])) { + return $this->_data[$name]; + } + + return NULL; + } + + public function __set($name, $value) { + $this->_data[$name] = $value; + } + + 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))); + + return $this->__get($key); + + } 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 Methods + -------------------------------*/ + /** + * Sets data + * + * @return this + */ + public function set($value) { + Eden_Type_Error::i()->argument(1, 'array'); + $this->_data = $value; + return $this; + } + + /** + * Returns if the data is empty + * + * @return bool + */ + public function isEmpty() { + return empty($this->_data); + } + + /** + * 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; + } + + /** + * 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; + } + + /** + * 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 the current item + * For Iterator interface + * + * @return void + */ + public function current() { + return current($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); + } + + /** + * Validates whether if the index is set + * For Iterator interface + * + * @return void + */ + public function valid() { + return isset($this->_data[$this->key()]); + } + + /** + * 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; + } + } + + /** + * isset using the ArrayAccess interface + * + * @param number + * @return bool + */ + public function offsetExists($offset) { + return isset($this->_data[$offset]); + } + + /** + * unsets using the ArrayAccess interface + * + * @param number + * @return bool + */ + public function offsetUnset($offset) { + unset($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; + } + + /** + * returns serialized data using the Serializable interface + * + * @return string + */ + public function serialize() { + return json_encode($this->_data); + } + + /** + * sets data using the Serializable interface + * + * @param string + * @return void + */ + public function unserialize($data) { + $this->_data = json_decode($data, true); + return $this; + } + + /** + * returns size using the Countable interface + * + * @return string + */ + public function count() { + return count($this->_data); + } + + /* 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 From 4c05dd53858965bbea97a5b4e32f2fd895726a73 Mon Sep 17 00:00:00 2001 From: cblanquera Date: Tue, 10 Jan 2012 15:27:34 +0000 Subject: [PATCH 062/330] moving collection, model, search to sql library because it can apply to all sql database git-svn-id: http://svn.openovate.com/edenv2/trunk@62 38ede93f-50f4-44af-b0b3-68ccca78c181 --- library/eden.php | 14 +- library/eden/mysql.php | 1229 +++++--------------- library/eden/mysql/error.php | 8 - library/eden/{mysql => sql}/collection.php | 463 ++++---- library/eden/sql/database.php | 662 ++++++++++- library/eden/sql/error.php | 7 + library/eden/{mysql => sql}/model.php | 54 +- library/eden/sql/query.php | 1 - library/eden/{mysql => sql}/search.php | 1100 +++++++++--------- 9 files changed, 1788 insertions(+), 1750 deletions(-) rename library/eden/{mysql => sql}/collection.php (67%) rename library/eden/{mysql => sql}/model.php (84%) rename library/eden/{mysql => sql}/search.php (84%) diff --git a/library/eden.php b/library/eden.php index a79a9c3..ccc53e4 100644 --- a/library/eden.php +++ b/library/eden.php @@ -16,8 +16,13 @@ * @version $Id: framework.php 9 2010-01-12 15:42:40Z blanquera $ */ function eden() { - //return the results - return Eden::i(); + $class = Eden::i(); + if(func_num_args() == 0) { + return $class; + } + + $args = func_get_args(); + return $class->__invoke($args); } /** @@ -179,8 +184,6 @@ public function routeClasses($routes) { if($routes === true) { $route->route('Cache', 'Eden_Cache') - ->route('String', 'Eden_Type_String') - ->route('Array', 'Eden_Type_Array') ->route('Registry', 'Eden_Registry') ->route('Model', 'Eden_Model') ->route('Collection', 'Eden_Collection') @@ -194,8 +197,7 @@ public function routeClasses($routes) { ->route('Folder', 'Eden_Folder') ->route('Image', 'Eden_Image') ->route('Mysql', 'Eden_Mysql') - ->route('Array', 'Eden_Type_Array') - ->route('String', 'Eden_Type_String') + ->route('Type', 'Eden_Type') ->route('Validation', 'Eden_Validation'); return $this; diff --git a/library/eden/mysql.php b/library/eden/mysql.php index 6d61119..19e7a53 100755 --- a/library/eden/mysql.php +++ b/library/eden/mysql.php @@ -1,932 +1,297 @@ - -/* - * 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__).'/event.php'; -require_once dirname(__FILE__).'/sql/error.php'; -require_once dirname(__FILE__).'/mysql/error.php'; -require_once dirname(__FILE__).'/sql/database.php'; -require_once dirname(__FILE__).'/sql/query.php'; -require_once dirname(__FILE__).'/sql/delete.php'; -require_once dirname(__FILE__).'/sql/select.php'; -require_once dirname(__FILE__).'/sql/update.php'; -require_once dirname(__FILE__).'/sql/insert.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'; -require_once dirname(__FILE__).'/mysql/collection.php'; -require_once dirname(__FILE__).'/mysql/model.php'; -require_once dirname(__FILE__).'/mysql/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 - * @version $Id: abstract.php 1 2010-01-02 23:06:36Z blanquera $ - */ -class Eden_Mysql extends Eden_Sql_Database { - /* Constants - -------------------------------*/ - const FIRST = 'first'; - const LAST = 'last'; - - const MODEL = 'Eden_Mysql_Model'; - const COLLECTION = 'Eden_Mysql_Collection'; - - /* Public Properties - -------------------------------*/ - /* Protected Properties - -------------------------------*/ - protected $_type = NULL; - protected $_host = 'localhost'; - protected $_name = NULL; - protected $_user = NULL; - protected $_pass = NULL; - protected $_queries = array(); - - protected $_connection = NULL; - protected $_binds = array(); - - protected $_model = self::MODEL; - protected $_collection = self::COLLECTION; - - /* Private Properties - -------------------------------*/ - /* Get - -------------------------------*/ - public static function i() { - return self::_getMultiple(__CLASS__); - } - - /* Magic - -------------------------------*/ - public function __construct($host, $name, $user, $pass = NULL) { - //argument test - Eden_Mysql_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 number or null - - $this->_host = $host; - $this->_name = $name; - $this->_user = $user; - $this->_pass = $pass; - } - - /* Public Methods - -------------------------------*/ - /** - * Connects to the database - * - * @param array the connection options - * @return this - */ - public function connect(array $options = array()) { - $connection = 'mysql:host='.$this->_host.';dbname='.$this->_name; - - $this->_connection = new PDO($connection, $this->_user, $this->_pass, $options); - - $this->trigger(); - - return $this; - } - - /** - * 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 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; - } - - /** - * Sets the default model - * - * @param string - * @return this - */ - public function setModel($model) { - $error = Eden_Mysql_Error::i()->argument(1, 'string'); - - if(!is_subclass_of($model, 'Eden_Model')) { - $error->setMessage(Eden_Mysql_Error::NOT_SUB_MODEL) - ->addVariable($model) - ->trigger(); - } - - $this->_model = $model; - return $this; - } - - /** - * Sets default collection - * - * @param string - * @return this - */ - public function setCollection($collection) { - $error = Eden_Mysql_Error::i()->argument(1, 'string'); - - if(!is_subclass_of($collection, 'Eden_Collection')) { - $error->setMessage(Eden_Mysql_Error::NOT_SUB_COLLECTION) - ->addVariable($collection) - ->trigger(); - } - - $this->_collection = $collection; - return $this; - } - - /** - * Returns the last inserted id - * - * @return int the id - */ - public function getLastInsertedId() { - return $this->getConnection()->lastInsertId(); - } - - /** - * Returns search - * - * @return Eden_Mysql_Search - */ - public function search() { - return Eden_Mysql_Search::i($this) - ->setCollection($this->_collection) - ->setModel($this->_model); - } - - /** - * Returns model - * - * @return Eden_Mysql_Model - */ - public function model(array $data = array()) { - $model = $this->_model; - return $this->$model($data)->setDatabase($this); - } - - /** - * Returns collection - * - * @return Eden_Mysql_Collection - */ - public function collection(array $data = array()) { - $collection = $this->_collection; - return $this->$collection() - ->setDatabase($this) - ->setModel($this->_model) - ->set($data); - } - - /** - * 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); - } - - /** - * 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 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_Mysql_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_Mysql_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); - $filter = $this->bind($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, $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 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_Mysql_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 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_Mysql_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 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_Mysql_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; - } - - /** - * 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_Mysql_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_Mysql_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; - } - - /** - * 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_Mysql_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); - $filter = $this->bind($filter); - $filters[$i] = vsprintf($format, $filter); - } - } - - $query->where($filters); - - //run the query - $this->query($query, $this->getBinds()); - - $this->trigger($table, $setting, $filters); - - 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_Mysql_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, 'eq', $value))); - } - } - - /** - * 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_Mysql_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); - $filter = $this->bind($filter); - $filters[$i] = vsprintf($format, $filter); - } - } - - $query->where($filters); - - //run the query - $this->query($query, $this->getBinds()); - - $this->trigger($table, $filters); - - return $this; - } - - /** - * 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 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()); - } - - /** - * 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); - } - - /** - * 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 databse - * - * @return string - */ - public function getSchema() { - $backup = array(); - $tables = $this->getTables(); - foreach($tables as $table) { - $backup[] = $this->getBackup(); - } - - return implode("\n\n", $backup); - } - - /** - * 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_Mysql_Error::i()->argument(1, 'string', 'Eden_Sql_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_Mysql_Error::i() - ->setMessage(Eden_Mysql_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; - } - - /** - * 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_Mysql_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 all the bound values of this query - * - * @param void - * @return array - */ - public function getBinds() { - return $this->_binds; - } - - /** - * Sets all the bound values of this query - * - * @param array - * @return this - */ - public function setBinds(array $binds) { - $this->_binds = $binds; - return $this; - } - - /* Protected Methods - -------------------------------*/ - /* Private Methods - -------------------------------*/ -} - + +/* + * 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__).'/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 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 + * @version $Id: abstract.php 1 2010-01-02 23:06:36Z blanquera $ + */ +class Eden_Mysql extends Eden_Sql_Database { + /* Constants + -------------------------------*/ + const FIRST = 'first'; + const LAST = 'last'; + + const MODEL = 'Eden_Mysql_Model'; + const COLLECTION = 'Eden_Mysql_Collection'; + + /* 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 + -------------------------------*/ + /* Get + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + /* Magic + -------------------------------*/ + public function __construct($host, $name, $user, $pass = NULL) { + //argument test + Eden_Mysql_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 number or null + + $this->_host = $host; + $this->_name = $name; + $this->_user = $user; + $this->_pass = $pass; + } + + /* Public Methods + -------------------------------*/ + /** + * Connects to the database + * + * @param array the connection options + * @return this + */ + public function connect(array $options = array()) { + $connection = 'mysql:host='.$this->_host.';dbname='.$this->_name; + + $this->_connection = new PDO($connection, $this->_user, $this->_pass, $options); + + $this->trigger(); + + return $this; + } + + /** + * 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); + } + + /** + * 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(); + } + + /** + * 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 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()); + } + + /** + * 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); + } + + /** + * 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 databse + * + * @return string + */ + public function getSchema() { + $backup = array(); + $tables = $this->getTables(); + foreach($tables as $table) { + $backup[] = $this->getBackup(); + } + + return implode("\n\n", $backup); + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} + diff --git a/library/eden/mysql/error.php b/library/eden/mysql/error.php index f776993..e9c3a11 100755 --- a/library/eden/mysql/error.php +++ b/library/eden/mysql/error.php @@ -18,14 +18,6 @@ class Eden_Mysql_Error extends Eden_Error { /* Constants -------------------------------*/ - const QUERY_ERROR = '%s Query: %s'; - const SET_INVALID = 'No column %s exists in table %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 diff --git a/library/eden/mysql/collection.php b/library/eden/sql/collection.php similarity index 67% rename from library/eden/mysql/collection.php rename to library/eden/sql/collection.php index 60f72f6..bc86e1d 100644 --- a/library/eden/mysql/collection.php +++ b/library/eden/sql/collection.php @@ -1,223 +1,242 @@ - -/* - * 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. - */ - -/** - * Mysql Collection handler - * - * @package Eden - * @category mysql - * @author Christian Blanquera - * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ - */ -class Eden_Mysql_Collection extends Eden_Collection { - /* Constants - -------------------------------*/ - /* Public Properties - -------------------------------*/ - /* Protected Properties - -------------------------------*/ - protected $_model = 'Eden_Mysql_Model'; - protected $_database = NULL; - protected $_table = NULL; - - /* Private Properties - -------------------------------*/ - /* Get - -------------------------------*/ - public static function i() { - return self::_getMultiple(__CLASS__); - } - - /* Magic - -------------------------------*/ - /* Public Methods - -------------------------------*/ - /** - * Sets the default database - * - * @param Eden_Mysql - */ - public function setDatabase(Eden_Mysql $database) { - $this->_database = $database; - - //for each row - foreach($this->_list as $row) { - if(!is_object($row) || !method_exists($row, 'setDatabase')) { - continue; - } - - //let the row handle this - $row->setDatabase($database); - } - - return $this; - } - - /** - * Sets the default database - * - * @param string - */ - public function setTable($table) { - //Argument 1 must be a string - Eden_Mysql_Error::i()->argument(1, 'string'); - - $this->_table = $table; - - //for each row - foreach($this->_list as $row) { - if(!is_object($row) || !method_exists($row, 'setTable')) { - continue; - } - - //let the row handle this - $row->setTable($table); - } - - return $this; - } - - /** - * Useful method for formating a time column. - * - * @param string - * @param string - * @return this - */ - public function formatTime($column, $format = Eden_Mysql_Model::DATETIME) { - //for each row - foreach($this->_list as $row) { - if(!is_object($row) || !method_exists($row, 'formatTime')) { - continue; - } - - //let the row handle this - $row->formatTime($column, $format); - } - - return $this; - } - - /** - * 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_Mysql_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; - } - - /** - * Insert collection to database - * - * @param string - * @param Eden_Mysql - * @return this - */ - public function insert($table = NULL, Eden_Mysql $database = NULL) { - //for each row - foreach($this->_list as $i => $row) { - if(!is_object($row) || !method_exists($row, 'insert')) { - continue; - } - - $row->insert($table, $database); - } - - return $this; - } - - /** - * Updates collection to database - * - * @param string - * @param Eden_Mysql - * @return this - */ - public function update($table = NULL, Eden_Mysql $database = NULL) { - //for each row - foreach($this->_list as $i => $row) { - if(!is_object($row) || !method_exists($row, 'update')) { - continue; - } - - $row->update($table, $database); - } - - return $this; - } - - /** - * Inserts or updates collection to database - * - * @param string - * @param Eden_Mysql - * @return this - */ - public function save($table = NULL, Eden_Mysql $database = NULL) { - //for each row - foreach($this->_list as $i => $row) { - if(!is_object($row) || !method_exists($row, 'save')) { - continue; - } - - $row->save($table, $database); - } - - return $this; - } - - /** - * Removes collection from database - * - * @param string - * @param Eden_Mysql - * @return this - */ - public function remove($table = NULL, Eden_Mysql $database = NULL) { - //for each row - foreach($this->_list as $i => $row) { - if(!is_object($row) || !method_exists($row, 'remove')) { - continue; - } - - //let the row handle this - $row->remove($table, $database); - } - - return $this; - } - - /* Protected Methods - -------------------------------*/ - /* Private Methods - -------------------------------*/ + +/* + * 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. + */ + +/** + * Sql Collection handler + * + * @package Eden + * @category sql + * @author Christian Blanquera + * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ + */ +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 + -------------------------------*/ + /* Get + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + /* Magic + -------------------------------*/ + /* Public Methods + -------------------------------*/ + /** + * Sets the default database + * + * @param Eden_Sql + */ + public function setDatabase(Eden_Sql $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 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; + } + + /** + * 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_Sql_Database::MODEL)) { + $error->setMessage(Eden_Sql_Error::NOT_SUB_MODEL) + ->addVariable($model) + ->trigger(); + } + + $this->_model = $model; + return $this; + } + + /** + * Useful method for formating a time column. + * + * @param string + * @param string + * @return this + */ + public function formatTime($column, $format = Eden_Sql_Model::DATETIME) { + //for each row + foreach($this->_list as $row) { + if(!is_object($row) || !method_exists($row, __FUNCTION__)) { + continue; + } + + //let the row handle this + $row->formatTime($column, $format); + } + + return $this; + } + + /** + * 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; + } + + /** + * Insert collection to database + * + * @param string + * @param Eden_Sql + * @return this + */ + public function insert($table = NULL, Eden_Sql $database = NULL) { + //for each row + foreach($this->_list as $i => $row) { + if(!is_object($row) || !method_exists($row, __FUNCTION__)) { + continue; + } + + $row->insert($table, $database); + } + + return $this; + } + + /** + * Updates collection to database + * + * @param string + * @param Eden_Sql + * @return this + */ + public function update($table = NULL, Eden_Sql $database = NULL) { + //for each row + foreach($this->_list as $i => $row) { + if(!is_object($row) || !method_exists($row, __FUNCTION__)) { + continue; + } + + $row->update($table, $database); + } + + return $this; + } + + /** + * Inserts or updates collection to database + * + * @param string + * @param Eden_Sql + * @return this + */ + public function save($table = NULL, Eden_Sql $database = NULL) { + //for each row + foreach($this->_list as $i => $row) { + if(!is_object($row) || !method_exists($row, __FUNCTION__)) { + continue; + } + + $row->save($table, $database); + } + + return $this; + } + + /** + * Removes collection from database + * + * @param string + * @param Eden_Sql + * @return this + */ + public function remove($table = NULL, Eden_Sql $database = NULL) { + //for each row + foreach($this->_list as $i => $row) { + if(!is_object($row) || !method_exists($row, __FUNCTION__)) { + continue; + } + + //let the row handle this + $row->remove($table, $database); + } + + 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 index f8f8765..738ff9b 100755 --- a/library/eden/sql/database.php +++ b/library/eden/sql/database.php @@ -7,6 +7,17 @@ * distributed with this package. */ +require_once dirname(__FILE__).'/event.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 @@ -19,25 +30,61 @@ * @author Christian Blanquera * @version $Id: abstract.php 1 2010-01-02 23:06:36Z blanquera $ */ -class Eden_Sql_Database extends Eden_Event { +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 -------------------------------*/ - public static function i() { - return self::_getSingleton(__CLASS__); - } - /* Magic -------------------------------*/ /* Public Methods -------------------------------*/ + /** + * Connects to the database + * + * @param array the connection options + * @return this + */ + abstract public function connect(array $options = array()); + + /** + * 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 delete query builder * @@ -86,6 +133,611 @@ public function update($table = NULL) { return Eden_Sql_Update::i($table); } + /** + * 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 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; + } + + /** + * Returns the last inserted id + * + * @return int the id + */ + public function getLastInsertedId() { + return $this->getConnection()->lastInsertId(); + } + + /** + * Returns search + * + * @return Eden_Sql_Search + */ + public function search() { + return Eden_Sql_Search::i($this) + ->setCollection($this->_collection) + ->setModel($this->_model); + } + + /** + * Returns model + * + * @return Eden_Sql_Model + */ + public function model(array $data = array()) { + $model = $this->_model; + return $this->$model($data)->setDatabase($this); + } + + /** + * 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 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); + $filter = $this->bind($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, $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 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 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); + } + + /** + * 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; + } + + /** + * 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); + $filter = $this->bind($filter); + $filters[$i] = vsprintf($format, $filter); + } + } + + $query->where($filters); + + //run the query + $this->query($query, $this->getBinds()); + + $this->trigger($table, $setting, $filters); + + 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))); + } + } + + /** + * 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); + $filter = $this->bind($filter); + $filters[$i] = vsprintf($format, $filter); + } + } + + $query->where($filters); + + //run the query + $this->query($query, $this->getBinds()); + + $this->trigger($table, $filters); + + return $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 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; + } + + /** + * 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 all the bound values of this query + * + * @param void + * @return array + */ + public function getBinds() { + return $this->_binds; + } + + /** + * Sets all the bound values of this query + * + * @param array + * @return this + */ + public function setBinds(array $binds) { + $this->_binds = $binds; + return $this; + } + /* Protected Methods -------------------------------*/ /* Private Methods diff --git a/library/eden/sql/error.php b/library/eden/sql/error.php index 7d2ab99..684c98a 100755 --- a/library/eden/sql/error.php +++ b/library/eden/sql/error.php @@ -18,6 +18,13 @@ 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 diff --git a/library/eden/mysql/model.php b/library/eden/sql/model.php similarity index 84% rename from library/eden/mysql/model.php rename to library/eden/sql/model.php index b31d2a9..4ecdda9 100644 --- a/library/eden/mysql/model.php +++ b/library/eden/sql/model.php @@ -8,14 +8,14 @@ */ /** - * Mysql Model + * Sql Model * * @package Eden - * @category mysql + * @category sql * @author Christian Blanquera * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ */ -class Eden_Mysql_Model extends Eden_Model { +class Eden_Sql_Model extends Eden_Model { /* Constants -------------------------------*/ const COLUMNS = 'columns'; @@ -49,9 +49,9 @@ public static function i() { /** * Sets the default database * - * @param Eden_Mysql + * @param Eden_Sql */ - public function setDatabase(Eden_Mysql $database) { + public function setDatabase(Eden_Sql $database) { $this->_database = $database; return $this; } @@ -63,7 +63,7 @@ public function setDatabase(Eden_Mysql $database) { */ public function setTable($table) { //Argument 1 must be a string - Eden_Mysql_Error::i()->argument(1, 'string'); + Eden_Sql_Error::i()->argument(1, 'string'); $this->_table = $table; return $this; @@ -78,7 +78,7 @@ public function setTable($table) { */ public function formatTime($column, $format = self::DATETIME) { //Argument Test - Eden_Mysql_Error::i() + Eden_Sql_Error::i() ->argument(1, 'string') //Argument 1 must be a string ->argument(2, 'string'); //Argument 1 must be a string @@ -110,19 +110,19 @@ public function formatTime($column, $format = self::DATETIME) { * Inserts model to database * * @param string - * @param Eden_Mysql + * @param Eden_Sql * @return this */ - public function insert($table = NULL, Eden_Mysql $database = NULL) { + public function insert($table = NULL, Eden_Sql $database = NULL) { //Argument 1 must be a string - $error = Eden_Mysql_Error::i()->argument(1, 'string', 'null'); + $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_Mysql_Error::TABLE_NOT_SET)->trigger(); + $error->setMessage(Eden_Sql_Error::TABLE_NOT_SET)->trigger(); } $table = $this->_table; @@ -132,7 +132,7 @@ public function insert($table = NULL, Eden_Mysql $database = NULL) { if(is_null($database)) { //and no default database if(!$this->_database) { - $error->setMessage(Eden_Mysql_Error::DATABASE_NOT_SET)->trigger(); + $error->setMessage(Eden_Sql_Error::DATABASE_NOT_SET)->trigger(); } $database = $this->_database; @@ -161,19 +161,19 @@ public function insert($table = NULL, Eden_Mysql $database = NULL) { * Updates model to database * * @param string - * @param Eden_Mysql + * @param Eden_Sql * @return this */ - public function update($table = NULL, Eden_Mysql $database = NULL) { + public function update($table = NULL, Eden_Sql $database = NULL) { //Argument 1 must be a string - $error = Eden_Mysql_Error::i()->argument(1, 'string', 'null'); + $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_Mysql_Error::TABLE_NOT_SET)->trigger(); + $error->setMessage(Eden_Sql_Error::TABLE_NOT_SET)->trigger(); } $table = $this->_table; @@ -183,7 +183,7 @@ public function update($table = NULL, Eden_Mysql $database = NULL) { if(is_null($database)) { //and no default database if(!$this->_database) { - $error->setMessage(Eden_Mysql_Error::DATABASE_NOT_SET)->trigger(); + $error->setMessage(Eden_Sql_Error::DATABASE_NOT_SET)->trigger(); } $database = $this->_database; @@ -216,19 +216,19 @@ public function update($table = NULL, Eden_Mysql $database = NULL) { * Inserts or updates model to database * * @param string - * @param Eden_Mysql + * @param Eden_Sql * @return this */ - public function save($table = NULL, Eden_Mysql $database = NULL) { + public function save($table = NULL, Eden_Sql $database = NULL) { //Argument 1 must be a string - $error = Eden_Mysql_Error::i()->argument(1, 'string', 'null'); + $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_Mysql_Error::TABLE_NOT_SET)->trigger(); + $error->setMessage(Eden_Sql_Error::TABLE_NOT_SET)->trigger(); } $table = $this->_table; @@ -238,7 +238,7 @@ public function save($table = NULL, Eden_Mysql $database = NULL) { if(is_null($database)) { //and no default database if(!$this->_database) { - $error->setMessage(Eden_Mysql_Error::DATABASE_NOT_SET)->trigger(); + $error->setMessage(Eden_Sql_Error::DATABASE_NOT_SET)->trigger(); } $database = $this->_database; @@ -263,19 +263,19 @@ public function save($table = NULL, Eden_Mysql $database = NULL) { * Removes model from database * * @param string - * @param Eden_Mysql + * @param Eden_Sql * @return this */ - public function remove($table = NULL, Eden_Mysql $database = NULL) { + public function remove($table = NULL, Eden_Sql $database = NULL) { //Argument 1 must be a string - $error = Eden_Mysql_Error::i()->argument(1, 'string', 'null'); + $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_Mysql_Error::TABLE_NOT_SET)->trigger(); + $error->setMessage(Eden_Sql_Error::TABLE_NOT_SET)->trigger(); } $table = $this->_table; @@ -285,7 +285,7 @@ public function remove($table = NULL, Eden_Mysql $database = NULL) { if(is_null($database)) { //and no default database if(!$this->_database) { - $error->setMessage(Eden_Mysql_Error::DATABASE_NOT_SET)->trigger(); + $error->setMessage(Eden_Sql_Error::DATABASE_NOT_SET)->trigger(); } $database = $this->_database; diff --git a/library/eden/sql/query.php b/library/eden/sql/query.php index 968d790..c112b67 100755 --- a/library/eden/sql/query.php +++ b/library/eden/sql/query.php @@ -26,7 +26,6 @@ abstract class Eden_Sql_Query extends Eden_Class { -------------------------------*/ /* Get -------------------------------*/ - /* Magic -------------------------------*/ public function __toString() { diff --git a/library/eden/mysql/search.php b/library/eden/sql/search.php similarity index 84% rename from library/eden/mysql/search.php rename to library/eden/sql/search.php index a36a500..dd24577 100644 --- a/library/eden/mysql/search.php +++ b/library/eden/sql/search.php @@ -1,550 +1,552 @@ - -/* - * 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. - */ - -/** - * Mysql Collection handler - * - * @package Eden - * @category mysql - * @author Christian Blanquera - * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ - */ -class Eden_Mysql_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 $_join = array(); - protected $_filter = array(); - protected $_sort = array(); - protected $_group = array(); - protected $_start = 0; - protected $_range = 0; - - protected $_model = 'Eden_Mysql_Model'; - protected $_collection = 'Eden_Mysql_Collection'; - - /* Private Properties - -------------------------------*/ - /* Get - -------------------------------*/ - public static function i() { - return self::_getMultiple(__CLASS__); - } - - /* Magic - -------------------------------*/ - public function __construct(Eden_Mysql $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-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_Mysql_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_Mysql_Error::i()->argument(1, 'string'); - $this->_table = $table; - return $this; - } - - /** - * Adds Inner Join On - * - * @param string - * @param string[,string..] - * @return this - */ - public function addInnerJoinOn($table, $where) { - Eden_Mysql_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_Mysql_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_Mysql_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_Mysql_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 Right Join On - * - * @param string - * @param string[,string..] - * @return this - */ - public function addRightJoinOn($table, $where) { - Eden_Mysql_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_Mysql_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 Outer Join On - * - * @param string - * @param string[,string..] - * @return this - */ - public function addOuterJoinOn($table, $where) { - Eden_Mysql_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_Mysql_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 filter - * - * @param string - * @param string[,string..] - * @return this - */ - public function addFilter() { - Eden_Mysql_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_Mysql_Error::i() - ->argument(1, 'string') - ->argument(2, 'string'); - - if($order != self::DESC) { - $order = self::ASC; - } - - $this->_sort[$column] = $order; - - 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_Mysql_Error::i()->argument(1, 'string', 'array'); - - if(is_string($group)) { - $group = array($group); - } - - $this->_group = $group; - return $this; - } - - /** - * Sets the pagination start - * - * @param int - * @return this - */ - public function setStart($start) { - Eden_Mysql_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_Mysql_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_Mysql_Error::i()->argument(1, 'int'); - - if($page < 1) { - $page = 1; - } - - $this->_start = ($page - 1) * $this->_range; - - return $this; - } - - /** - * Sets default collection - * - * @param string - * @return this - */ - public function setCollection($collection) { - $error = Eden_Mysql_Error::i()->argument(1, 'string'); - - if(!is_subclass_of($collection, 'Eden_Collection')) { - $error->setMessage(Eden_Mysql_Error::NOT_SUB_COLLECTION) - ->addVariable($collection) - ->trigger(); - } - - $this->_collection = $collection; - return $this; - } - - /** - * Sets default model - * - * @param string - * @return this - */ - public function setModel($model) { - $error = Eden_Mysql_Error::i()->argument(1, 'string'); - - if(!is_subclass_of($model, 'Eden_Model')) { - $error->setMessage(Eden_Mysql_Error::NOT_SUB_MODEL) - ->addVariable($model) - ->trigger(); - } - - $this->_model = $model; - return $this; - } - - /** - * Returns the results in a collection - * - * @return Eden_Mysql_Collection - */ - public function getCollection() { - $collection = $this->_collection; - return $this->$collection() - ->setDatabase($this->_database) - ->setTable($this->_table) - ->setModel($this->_model) - ->set($this->getRows()); - } - - /** - * 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']; - } - - /* 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 - -------------------------------*/ + +/* + * 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. + */ + +/** + * Sql Search + * + * @package Eden + * @category sql + * @author Christian Blanquera + * @version $Id: registry.php 1 2010-01-02 23:06:36Z blanquera $ + */ +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 + -------------------------------*/ + /* Get + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + /* Magic + -------------------------------*/ + public function __construct(Eden_Sql $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-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 Methods + -------------------------------*/ + /** + * 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_Sql_Database::COLLECTION)) { + $error->setMessage(Eden_Sql_Error::NOT_SUB_COLLECTION) + ->addVariable($collection) + ->trigger(); + } + + $this->_collection = $collection; + 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_Sql_Database::MODEL)) { + $error->setMessage(Eden_Sql_Error::NOT_SUB_MODEL) + ->addVariable($model) + ->trigger(); + } + + $this->_model = $model; + 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 Table + * + * @param string + * @return this + */ + public function setTable($table) { + Eden_Sql_Error::i()->argument(1, 'string'); + $this->_table = $table; + 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 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 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 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 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; + } + + /** + * 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 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 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 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; + } + + /** + * 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 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']; + } + + /* 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 From f596d8908b416cb8482cf32b626332fcd4139583 Mon Sep 17 00:00:00 2001 From: cblanquera Date: Wed, 11 Jan 2012 07:25:44 +0000 Subject: [PATCH 063/330] abstracted mysql files to sql and branched pgsql. pgsql semi works git-svn-id: http://svn.openovate.com/edenv2/trunk@63 38ede93f-50f4-44af-b0b3-68ccca78c181 --- library/eden/mysql.php | 25 ++- library/eden/postgre.php | 361 +++++++++++++++++++++++++++++++ library/eden/postgre/alter.php | 250 +++++++++++++++++++++ library/eden/postgre/create.php | 170 +++++++++++++++ library/eden/postgre/delete.php | 60 +++++ library/eden/postgre/error.php | 42 ++++ library/eden/postgre/insert.php | 86 ++++++++ library/eden/postgre/select.php | 63 ++++++ library/eden/postgre/update.php | 85 ++++++++ library/eden/postgre/utility.php | 102 +++++++++ library/eden/sql/collection.php | 12 +- library/eden/sql/database.php | 2 +- library/eden/sql/model.php | 10 +- library/eden/sql/search.php | 6 +- 14 files changed, 1249 insertions(+), 25 deletions(-) create mode 100644 library/eden/postgre.php create mode 100644 library/eden/postgre/alter.php create mode 100644 library/eden/postgre/create.php create mode 100644 library/eden/postgre/delete.php create mode 100644 library/eden/postgre/error.php create mode 100644 library/eden/postgre/insert.php create mode 100644 library/eden/postgre/select.php create mode 100644 library/eden/postgre/update.php create mode 100644 library/eden/postgre/utility.php diff --git a/library/eden/mysql.php b/library/eden/mysql.php index 19e7a53..da0e723 100755 --- a/library/eden/mysql.php +++ b/library/eden/mysql.php @@ -29,12 +29,6 @@ class Eden_Mysql extends Eden_Sql_Database { /* Constants -------------------------------*/ - const FIRST = 'first'; - const LAST = 'last'; - - const MODEL = 'Eden_Mysql_Model'; - const COLLECTION = 'Eden_Mysql_Collection'; - /* Public Properties -------------------------------*/ /* Protected Properties @@ -57,18 +51,20 @@ public static function i() { /* Magic -------------------------------*/ - public function __construct($host, $name, $user, $pass = NULL) { + public function __construct($host, $name, $user, $pass = NULL, $port = NULL) { //argument test Eden_Mysql_Error::i() - ->argument(1, 'string') //Argument 1 must be a string + ->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(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 @@ -80,7 +76,16 @@ public function __construct($host, $name, $user, $pass = NULL) { * @return this */ public function connect(array $options = array()) { - $connection = 'mysql:host='.$this->_host.';dbname='.$this->_name; + $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); diff --git a/library/eden/postgre.php b/library/eden/postgre.php new file mode 100644 index 0000000..52c81c1 --- /dev/null +++ b/library/eden/postgre.php @@ -0,0 +1,361 @@ + +/* + * 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__).'/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 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 + * @version $Id: abstract.php 1 2010-01-02 23:06:36Z blanquera $ + */ +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 + -------------------------------*/ + /* Get + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + /* Magic + -------------------------------*/ + 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 + -------------------------------*/ + /** + * 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 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); + } + + /** + * 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); + } + + /** + * 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_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); + } + + /** + * 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 alter query builder + * + * @return Eden_Sql_Utility + */ + public function utility() { + return Eden_Postgre_Utility::i(); + } + + /** + * 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; + } + + + + /** + * 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); + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} + diff --git a/library/eden/postgre/alter.php b/library/eden/postgre/alter.php new file mode 100644 index 0000000..e0a7760 --- /dev/null +++ b/library/eden/postgre/alter.php @@ -0,0 +1,250 @@ + +/* + * 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. + */ + +/** + * Generates alter query string syntax + * + * @package Eden + * @category sql + * @author Christian Blanquera + * @version $Id: alter.php 1 2010-01-02 23:06:36Z blanquera $ + */ +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 + -------------------------------*/ + /* Get + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + /* Magic + -------------------------------*/ + public function __construct($name = NULL) { + if(is_string($name)) { + $this->setName($name); + } + } + + /* Public Methods + -------------------------------*/ + /** + * 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; + } + + /** + * 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; + } + + /** + * 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; + } + + /** + * 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; + } + + /** + * 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; + } + + /** + * 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; + } + + /** + * 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); + } + + /* 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..1c2b276 --- /dev/null +++ b/library/eden/postgre/create.php @@ -0,0 +1,170 @@ + +/* + * 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. + */ + +/** + * Generates create table query string syntax + * + * @package Eden + * @category sql + * @author Christian Blanquera + * @version $Id: create.php 1 2010-01-02 23:06:36Z blanquera $ + */ +class Eden_PostGre_Create extends Eden_Sql_Query { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_name = NULL; + protected $_fields = array(); + protected $_primaryKeys = array(); + + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + /* Magic + -------------------------------*/ + public function __construct($name = NULL) { + if(is_string($name)) { + $this->setName($name); + } + } + + /* Public Methods + -------------------------------*/ + /** + * 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 fields to the table + * + * @param array fields + * @return this + */ + public function setFields(array $fields) { + $this->_fields = $fields; + 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; + } + + /** + * 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); + } + + $fields = !empty($fields) ? implode(', ', $fields) : ''; + $primary = !empty($this->_primaryKeys) ? ', PRIMARY KEY ("'.implode('", ""', $this->_primaryKeys).'")' : ''; + return sprintf('CREATE TABLE %s (%s%s)', $table, $fields, $primary); + } + + /* 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..884f9a3 --- /dev/null +++ b/library/eden/postgre/delete.php @@ -0,0 +1,60 @@ + +/* + * 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. + */ + +/** + * Generates delete query string syntax + * + * @package Eden + * @category sql + * @author Christian Blanquera + * @version $Id: delete.php 1 2010-01-02 23:06:36Z blanquera $ + */ +class Eden_Postgre_Delete extends Eden_Sql_Delete { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_table = NULL; + protected $_where = array(); + + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + /* Magic + -------------------------------*/ + 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..34f5be7 --- /dev/null +++ b/library/eden/postgre/error.php @@ -0,0 +1,42 @@ + +/* + * 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 + * @version $Id: exception.php 1 2010-01-02 23:06:36Z blanquera $ + */ +class Eden_Postgre_Error extends Eden_Sql_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/postgre/insert.php b/library/eden/postgre/insert.php new file mode 100644 index 0000000..ed8461b --- /dev/null +++ b/library/eden/postgre/insert.php @@ -0,0 +1,86 @@ + +/* + * 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. + */ + +/** + * Generates insert query string syntax + * + * @package Eden + * @category sql + * @author Christian Blanquera + * @version $Id: insert.php 1 2010-01-02 23:06:36Z blanquera $ + */ +class Eden_Postgre_Insert extends Eden_Sql_Insert { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + /* Magic + -------------------------------*/ + /* Public Methods + -------------------------------*/ + /** + * 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; + } + + /** + * 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).';'; + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} diff --git a/library/eden/postgre/select.php b/library/eden/postgre/select.php new file mode 100644 index 0000000..b4299bc --- /dev/null +++ b/library/eden/postgre/select.php @@ -0,0 +1,63 @@ + +/* + * 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. + */ + +/** + * Generates select query string syntax + * + * @package Eden + * @category sql + * @author Christian Blanquera + * @version $Id: select.php 1 2010-01-02 23:06:36Z blanquera $ + */ +class Eden_Postgre_Select extends Eden_Sql_Select { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + /* Magic + -------------------------------*/ + /* 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..7eb9864 --- /dev/null +++ b/library/eden/postgre/update.php @@ -0,0 +1,85 @@ + +/* + * 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. + */ + +/** + * Generates update query string syntax + * + * @package Eden + * @category sql + * @author Christian Blanquera + * @version $Id: update.php 1 2010-01-02 23:06:36Z blanquera $ + */ +class Eden_Postgre_Update extends Eden_Postgre_Delete { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_set = array(); + + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + /* Magic + -------------------------------*/ + /* Public Methods + -------------------------------*/ + /** + * 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; + } + + /** + * 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).';'; + } + + /* 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..361db2f --- /dev/null +++ b/library/eden/postgre/utility.php @@ -0,0 +1,102 @@ + +/* + * 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. + */ + +/** + * Generates utility query strings + * + * @package Eden + * @subpackage database + * @category database + * @author Christian Blanquera + * @version $Id: utility.php 1 2010-01-02 23:06:36Z blanquera $ + */ +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 + -------------------------------*/ + 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; + } + + /** + * 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; + } + + /** + * 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; + } + + /** + * Returns the string version of the query + * + * @return string + */ + public function getQuery() { + return $this->_query.';'; + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} \ No newline at end of file diff --git a/library/eden/sql/collection.php b/library/eden/sql/collection.php index bc86e1d..95f0304 100644 --- a/library/eden/sql/collection.php +++ b/library/eden/sql/collection.php @@ -43,7 +43,7 @@ public static function i() { * * @param Eden_Sql */ - public function setDatabase(Eden_Sql $database) { + public function setDatabase(Eden_Sql_Database $database) { $this->_database = $database; //for each row @@ -92,7 +92,7 @@ public function setTable($table) { public function setModel($model) { $error = Eden_Sql_Error::i()->argument(1, 'string'); - if(!is_subclass_of($model, Eden_Sql_Database::MODEL)) { + if(!is_subclass_of($model, 'Eden_Model')) { $error->setMessage(Eden_Sql_Error::NOT_SUB_MODEL) ->addVariable($model) ->trigger(); @@ -161,7 +161,7 @@ public function add($row = array()) { * @param Eden_Sql * @return this */ - public function insert($table = NULL, Eden_Sql $database = NULL) { + public function insert($table = NULL, Eden_Sql_Database $database = NULL) { //for each row foreach($this->_list as $i => $row) { if(!is_object($row) || !method_exists($row, __FUNCTION__)) { @@ -181,7 +181,7 @@ public function insert($table = NULL, Eden_Sql $database = NULL) { * @param Eden_Sql * @return this */ - public function update($table = NULL, Eden_Sql $database = NULL) { + public function update($table = NULL, Eden_Sql_Database $database = NULL) { //for each row foreach($this->_list as $i => $row) { if(!is_object($row) || !method_exists($row, __FUNCTION__)) { @@ -201,7 +201,7 @@ public function update($table = NULL, Eden_Sql $database = NULL) { * @param Eden_Sql * @return this */ - public function save($table = NULL, Eden_Sql $database = NULL) { + public function save($table = NULL, Eden_Sql_Database $database = NULL) { //for each row foreach($this->_list as $i => $row) { if(!is_object($row) || !method_exists($row, __FUNCTION__)) { @@ -221,7 +221,7 @@ public function save($table = NULL, Eden_Sql $database = NULL) { * @param Eden_Sql * @return this */ - public function remove($table = NULL, Eden_Sql $database = NULL) { + public function remove($table = NULL, Eden_Sql_Database $database = NULL) { //for each row foreach($this->_list as $i => $row) { if(!is_object($row) || !method_exists($row, __FUNCTION__)) { diff --git a/library/eden/sql/database.php b/library/eden/sql/database.php index 738ff9b..5149f09 100755 --- a/library/eden/sql/database.php +++ b/library/eden/sql/database.php @@ -7,7 +7,7 @@ * distributed with this package. */ -require_once dirname(__FILE__).'/event.php'; +require_once dirname(__FILE__).'/../event.php'; require_once dirname(__FILE__).'/error.php'; require_once dirname(__FILE__).'/query.php'; require_once dirname(__FILE__).'/delete.php'; diff --git a/library/eden/sql/model.php b/library/eden/sql/model.php index 4ecdda9..28873d6 100644 --- a/library/eden/sql/model.php +++ b/library/eden/sql/model.php @@ -51,7 +51,7 @@ public static function i() { * * @param Eden_Sql */ - public function setDatabase(Eden_Sql $database) { + public function setDatabase(Eden_Sql_Database $database) { $this->_database = $database; return $this; } @@ -113,7 +113,7 @@ public function formatTime($column, $format = self::DATETIME) { * @param Eden_Sql * @return this */ - public function insert($table = NULL, Eden_Sql $database = NULL) { + 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'); @@ -164,7 +164,7 @@ public function insert($table = NULL, Eden_Sql $database = NULL) { * @param Eden_Sql * @return this */ - public function update($table = NULL, Eden_Sql $database = NULL) { + public function update($table = NULL, Eden_Sql_Database $database = NULL) { //Argument 1 must be a string $error = Eden_Sql_Error::i()->argument(1, 'string', 'null'); @@ -219,7 +219,7 @@ public function update($table = NULL, Eden_Sql $database = NULL) { * @param Eden_Sql * @return this */ - public function save($table = NULL, Eden_Sql $database = NULL) { + public function save($table = NULL, Eden_Sql_Database $database = NULL) { //Argument 1 must be a string $error = Eden_Sql_Error::i()->argument(1, 'string', 'null'); @@ -266,7 +266,7 @@ public function save($table = NULL, Eden_Sql $database = NULL) { * @param Eden_Sql * @return this */ - public function remove($table = NULL, Eden_Sql $database = NULL) { + public function remove($table = NULL, Eden_Sql_Database $database = NULL) { //Argument 1 must be a string $error = Eden_Sql_Error::i()->argument(1, 'string', 'null'); diff --git a/library/eden/sql/search.php b/library/eden/sql/search.php index dd24577..b349593 100644 --- a/library/eden/sql/search.php +++ b/library/eden/sql/search.php @@ -52,7 +52,7 @@ public static function i() { /* Magic -------------------------------*/ - public function __construct(Eden_Sql $database) { + public function __construct(Eden_Sql_Database $database) { $this->_database = $database; } @@ -123,7 +123,7 @@ public function __call($name, $args) { public function setCollection($collection) { $error = Eden_Sql_Error::i()->argument(1, 'string'); - if(!is_subclass_of($collection, Eden_Sql_Database::COLLECTION)) { + if(!is_subclass_of($collection, 'Eden_Collection')) { $error->setMessage(Eden_Sql_Error::NOT_SUB_COLLECTION) ->addVariable($collection) ->trigger(); @@ -142,7 +142,7 @@ public function setCollection($collection) { public function setModel($model) { $error = Eden_Sql_Error::i()->argument(1, 'string'); - if(!is_subclass_of($model, Eden_Sql_Database::MODEL)) { + if(!is_subclass_of($model, 'Eden_Model')) { $error->setMessage(Eden_Sql_Error::NOT_SUB_MODEL) ->addVariable($model) ->trigger(); From d274bac0dc527609471798e5821d7ea58a19164b Mon Sep 17 00:00:00 2001 From: cblanquera Date: Wed, 11 Jan 2012 11:04:04 +0000 Subject: [PATCH 064/330] front site git-svn-id: http://svn.openovate.com/edenv2/trunk@64 38ede93f-50f4-44af-b0b3-68ccca78c181 --- site/front.php | 154 ++++---- site/front/block/crumbs.php | 80 ++++ site/front/block/log.php | 87 +++++ site/front/block/menu.php | 110 ++++++ site/front/block/template/crumbs.php | 9 + site/front/block/template/log.php | 10 + site/front/block/template/menu.php | 21 ++ site/front/error.php | 2 +- site/front/handler.php | 2 +- site/front/page.php | 11 +- site/front/page/api.php | 294 +++++++++++++++ site/front/page/documentation.php | 52 +++ site/front/page/download.php | 209 +++++++++++ site/front/page/index.php | 4 - site/front/template/_foot.php | 2 +- site/front/template/_head.php | 7 +- site/front/template/_menu.php | 121 ++++++ site/front/template/_page.php | 2 +- site/front/template/api.php | 103 ++++++ site/front/template/documentation.php | 82 +++++ site/front/template/documentation/library.php | 58 +++ .../documentation/library/autoloading.php | 35 ++ .../documentation/library/classes.php | 142 +++++++ .../template/documentation/library/errors.php | 297 +++++++++++++++ .../documentation/library/features.php | 188 ++++++++++ site/front/template/documentation/start.php | 17 + site/front/template/download.php | 10 + site/front/template/error.php | 17 +- site/web/.htaccess | 6 + site/web/assets/brushes/shAutoloader.js | 17 + site/web/assets/brushes/shBrushAS3.js | 59 +++ site/web/assets/brushes/shBrushAppleScript.js | 75 ++++ site/web/assets/brushes/shBrushBash.js | 59 +++ site/web/assets/brushes/shBrushCSharp.js | 65 ++++ site/web/assets/brushes/shBrushColdFusion.js | 100 +++++ site/web/assets/brushes/shBrushCpp.js | 97 +++++ site/web/assets/brushes/shBrushCss.js | 91 +++++ site/web/assets/brushes/shBrushDelphi.js | 55 +++ site/web/assets/brushes/shBrushDiff.js | 41 +++ site/web/assets/brushes/shBrushErlang.js | 52 +++ site/web/assets/brushes/shBrushGroovy.js | 67 ++++ site/web/assets/brushes/shBrushJScript.js | 52 +++ site/web/assets/brushes/shBrushJava.js | 57 +++ site/web/assets/brushes/shBrushJavaFX.js | 58 +++ site/web/assets/brushes/shBrushPerl.js | 72 ++++ site/web/assets/brushes/shBrushPhp.js | 88 +++++ site/web/assets/brushes/shBrushPlain.js | 33 ++ site/web/assets/brushes/shBrushPowerShell.js | 74 ++++ site/web/assets/brushes/shBrushPython.js | 64 ++++ site/web/assets/brushes/shBrushRuby.js | 55 +++ site/web/assets/brushes/shBrushSass.js | 94 +++++ site/web/assets/brushes/shBrushScala.js | 51 +++ site/web/assets/brushes/shBrushSql.js | 66 ++++ site/web/assets/brushes/shBrushVb.js | 56 +++ site/web/assets/brushes/shBrushXml.js | 69 ++++ site/web/assets/brushes/shCore.css | 226 ++++++++++++ site/web/assets/brushes/shCore.js | 17 + site/web/assets/brushes/shCoreDefault.css | 328 +++++++++++++++++ site/web/assets/brushes/shCoreDjango.css | 331 +++++++++++++++++ site/web/assets/brushes/shCoreEclipse.css | 339 +++++++++++++++++ site/web/assets/brushes/shCoreEmacs.css | 324 ++++++++++++++++ site/web/assets/brushes/shCoreFadeToGrey.css | 328 +++++++++++++++++ site/web/assets/brushes/shCoreMDUltra.css | 324 ++++++++++++++++ site/web/assets/brushes/shCoreMidnight.css | 324 ++++++++++++++++ site/web/assets/brushes/shCoreRDark.css | 324 ++++++++++++++++ site/web/assets/brushes/shLegacy.js | 17 + site/web/assets/brushes/shThemeDefault.css | 117 ++++++ site/web/assets/brushes/shThemeDjango.css | 120 ++++++ site/web/assets/brushes/shThemeEclipse.css | 128 +++++++ site/web/assets/brushes/shThemeEmacs.css | 113 ++++++ site/web/assets/brushes/shThemeFadeToGrey.css | 117 ++++++ site/web/assets/brushes/shThemeMDUltra.css | 113 ++++++ site/web/assets/brushes/shThemeMidnight.css | 113 ++++++ site/web/assets/brushes/shThemeRDark.css | 113 ++++++ site/web/assets/images/book-sprite.jpg | Bin 0 -> 77360 bytes site/web/assets/images/book-sprite.png | Bin 0 -> 4691 bytes site/web/assets/main.css | 346 ++++++++++++++++++ site/web/assets/reset.css | 2 + site/web/index.php | 3 +- 79 files changed, 7861 insertions(+), 105 deletions(-) create mode 100644 site/front/block/crumbs.php create mode 100644 site/front/block/log.php create mode 100644 site/front/block/menu.php create mode 100644 site/front/block/template/crumbs.php create mode 100644 site/front/block/template/log.php create mode 100644 site/front/block/template/menu.php create mode 100644 site/front/page/api.php create mode 100644 site/front/page/documentation.php create mode 100644 site/front/page/download.php create mode 100644 site/front/template/_menu.php create mode 100644 site/front/template/api.php create mode 100644 site/front/template/documentation.php create mode 100644 site/front/template/documentation/library.php create mode 100644 site/front/template/documentation/library/autoloading.php create mode 100644 site/front/template/documentation/library/classes.php create mode 100644 site/front/template/documentation/library/errors.php create mode 100644 site/front/template/documentation/library/features.php create mode 100644 site/front/template/documentation/start.php create mode 100644 site/front/template/download.php create mode 100644 site/web/.htaccess create mode 100644 site/web/assets/brushes/shAutoloader.js create mode 100644 site/web/assets/brushes/shBrushAS3.js create mode 100644 site/web/assets/brushes/shBrushAppleScript.js create mode 100644 site/web/assets/brushes/shBrushBash.js create mode 100644 site/web/assets/brushes/shBrushCSharp.js create mode 100644 site/web/assets/brushes/shBrushColdFusion.js create mode 100644 site/web/assets/brushes/shBrushCpp.js create mode 100644 site/web/assets/brushes/shBrushCss.js create mode 100644 site/web/assets/brushes/shBrushDelphi.js create mode 100644 site/web/assets/brushes/shBrushDiff.js create mode 100644 site/web/assets/brushes/shBrushErlang.js create mode 100644 site/web/assets/brushes/shBrushGroovy.js create mode 100644 site/web/assets/brushes/shBrushJScript.js create mode 100644 site/web/assets/brushes/shBrushJava.js create mode 100644 site/web/assets/brushes/shBrushJavaFX.js create mode 100644 site/web/assets/brushes/shBrushPerl.js create mode 100644 site/web/assets/brushes/shBrushPhp.js create mode 100644 site/web/assets/brushes/shBrushPlain.js create mode 100644 site/web/assets/brushes/shBrushPowerShell.js create mode 100644 site/web/assets/brushes/shBrushPython.js create mode 100644 site/web/assets/brushes/shBrushRuby.js create mode 100644 site/web/assets/brushes/shBrushSass.js create mode 100644 site/web/assets/brushes/shBrushScala.js create mode 100644 site/web/assets/brushes/shBrushSql.js create mode 100644 site/web/assets/brushes/shBrushVb.js create mode 100644 site/web/assets/brushes/shBrushXml.js create mode 100644 site/web/assets/brushes/shCore.css create mode 100644 site/web/assets/brushes/shCore.js create mode 100644 site/web/assets/brushes/shCoreDefault.css create mode 100644 site/web/assets/brushes/shCoreDjango.css create mode 100644 site/web/assets/brushes/shCoreEclipse.css create mode 100644 site/web/assets/brushes/shCoreEmacs.css create mode 100644 site/web/assets/brushes/shCoreFadeToGrey.css create mode 100644 site/web/assets/brushes/shCoreMDUltra.css create mode 100644 site/web/assets/brushes/shCoreMidnight.css create mode 100644 site/web/assets/brushes/shCoreRDark.css create mode 100644 site/web/assets/brushes/shLegacy.js create mode 100644 site/web/assets/brushes/shThemeDefault.css create mode 100644 site/web/assets/brushes/shThemeDjango.css create mode 100644 site/web/assets/brushes/shThemeEclipse.css create mode 100644 site/web/assets/brushes/shThemeEmacs.css create mode 100644 site/web/assets/brushes/shThemeFadeToGrey.css create mode 100755 site/web/assets/brushes/shThemeMDUltra.css create mode 100644 site/web/assets/brushes/shThemeMidnight.css create mode 100644 site/web/assets/brushes/shThemeRDark.css create mode 100644 site/web/assets/images/book-sprite.jpg create mode 100644 site/web/assets/images/book-sprite.png create mode 100644 site/web/assets/main.css create mode 100644 site/web/assets/reset.css diff --git a/site/front.php b/site/front.php index f6e86ac..b287843 100644 --- a/site/front.php +++ b/site/front.php @@ -18,7 +18,13 @@ * @version $Id: application.php 21 2010-01-06 01:19:17Z blanquera $ */ function front() { - return Front::get(); + $class = Front::i(); + if(func_num_args() == 0) { + return $class; + } + + $args = func_get_args(); + return $class->__invoke($args); } /** @@ -46,19 +52,23 @@ class Front extends Eden { -------------------------------*/ /* Get -------------------------------*/ - public static function get() { + public static function i() { return self::_getSingleton(__CLASS__); } /* Magic -------------------------------*/ public function __construct() { + if(!self::$_active) { + self::$_active = $this; + } + $this->_root = dirname(__FILE__); $this->setLoader(); //require registry - $this->_registry = Eden_Loader::get() + $this->_registry = Eden_Loader::i() ->load('Eden_Registry') ->Eden_Registry(); } @@ -76,26 +86,23 @@ public function __construct() { * @return this */ public function setDebug($reporting = NULL, $default = NULL) { - Eden_Error::get()->argument(1, 'int', 'null')->argument(2, 'bool', 'null'); + Eden_Error::i()->argument(1, 'int', 'null')->argument(2, 'bool', 'null'); - Eden_Loader::get() + Eden_Loader::i() ->load('Eden_Template') ->Eden_Error_Event() - ->when(!is_null($reporting)) + ->when(!is_null($reporting), 1) ->setReporting($reporting) - ->endWhen() - ->when($default === true) + ->when($default === true, 4) ->setErrorHandler() ->setExceptionHandler() ->listen('error', $this, 'error') ->listen('exception', $this, 'error') - ->endWhen() - ->when($default === false) + ->when($default === false, 4) ->releaseErrorHandler() ->releaseExceptionHandler() ->unlisten('error', $this, 'error') - ->unlisten('exception', $this, 'error') - ->endWhen(); + ->unlisten('exception', $this, 'error'); return $this; } @@ -118,15 +125,15 @@ public function setPaths(array $paths = array()) { //foreach default path foreach($default as $key => $path) { - $this->_registry->setData('path', $key, $path); + $this->_registry->set('path', $key, $path); } //for each path foreach($paths as $key => $path) { //make them absolute - $path = (string) Eden_Path::get($path)->absolute(); + $path = (string) Eden_Path::i($path)->absolute(); //set it - $this->_registry->setData('path', $key, $path); + $this->_registry->set('path', $key, $path); } return $this; @@ -138,13 +145,13 @@ public function setPaths(array $paths = array()) { * @return this */ public function setPages($pages, $absolute = false) { - Front_Error::get() + Front_Error::i() ->argument(1, 'string', 'array') ->argument(2, 'bool'); if(is_string($pages)) { if(!$absolute) { - $pages = $this->_registry->getData('path', 'config').'/'.$pages; + $pages = $this->_registry->get('path', 'config').'/'.$pages; } $pages = include($pages); @@ -177,7 +184,7 @@ public function setRequest(Eden_Registry $request = NULL) { $path = str_replace('favicon.ico', '/', $path); //fix the request path - $path = (string) Eden_Path::get($path); + $path = (string) Eden_Path::i($path); //get the path array $pathArray = explode('/', $path); @@ -246,14 +253,13 @@ public function setRequest(Eden_Registry $request = NULL) { 'variables' => $variables); //set the request - $request->setData('server', $_SERVER) - ->setData('cookie', $_COOKIE) - ->setData('request', $_REQUEST) - ->setData('get', $_GET) - ->setData('post', $_POST) - ->setData('files', $_FILES) - ->setData('request', $path) - ->setData('page', $page); + $request->set('server', $_SERVER) + ->set('cookie', $_COOKIE) + ->set('get', $_GET) + ->set('post', $_POST) + ->set('files', $_FILES) + ->set('request', $path) + ->set('page', $page); return $this; } @@ -271,7 +277,7 @@ public function setResponse($default, Eden_Registry $request = NULL) { $request = $this->_registry; } - $page = $request->getData('page'); + $page = $request->get('page'); if(!$page || !class_exists($page)) { $page = $default; @@ -285,7 +291,7 @@ public function setResponse($default, Eden_Registry $request = NULL) { exit; } - $request->setData('response', $response); + $request->set('response', $response); return $this; } @@ -303,7 +309,7 @@ public function getResponse(Eden_Registry $request = NULL) { $request = $this->_registry; } - return $request->getData('response'); + return $request->get('response'); } /* Public Database Methods @@ -317,7 +323,7 @@ public function addDatabase($key, $type = NULL, $host = NULL, $name = NULL, $user = NULL, $pass = NULL, $default = true) { - Front_Error::get() + Front_Error::i() ->argument(1, 'string', 'array', 'null') ->argument(2, 'string', 'null') ->argument(3, 'string', 'null') @@ -339,14 +345,14 @@ public function addDatabase($key, $type = NULL, //connect to the data as described in the config switch($type) { case 'postgre': - $database = Eden_Pgsql::get($host, $name, $user, $pass); + $database = Eden_Postgre::i($host, $name, $user, $pass); break; case 'mysql': - $database = Eden_Mysql::get($host, $name, $user, $pass); + $database = Eden_Mysql::i($host, $name, $user, $pass); break; } - $this->_registry->setData('database', $key, $database); + $this->_registry->set('database', $key, $database); if($default) { $this->_database = $database; @@ -366,7 +372,7 @@ public function getDatabase($key = NULL) { return $this->_database; } - return $this->_registry->getData('database', $key); + return $this->_registry->get('database', $key); } /** @@ -376,7 +382,7 @@ public function getDatabase($key = NULL) { * @return this */ public function setDefaultDatabase($key) { - Front_Error::get()->argument(1, 'string'); + Front_Error::i()->argument(1, 'string'); $args = func_get_args(); //if the args are greater than 5 @@ -386,7 +392,7 @@ public function setDefaultDatabase($key) { } //now set it - $this->_database = $this->_registry->getData('database', $key); + $this->_database = $this->_registry->getValue('database', $key); return $this; } @@ -400,7 +406,7 @@ public function setDefaultDatabase($key) { * @return Eden_Application */ public function setFilters($filters) { - Front_Error::get()->argument(1, 'string', 'array'); + Front_Error::i()->argument(1, 'string', 'array'); if(is_string($filters)) { $filters = include($filters); @@ -429,14 +435,14 @@ public function setFilters($filters) { public function setCache($root) { //we need Eden_Path to fix the path formatting if(!class_exists('Eden_Path')) { - Eden_Loader::get()->load('Eden_Path'); + Eden_Loader::i()->load('Eden_Path'); } //format the path - $root = (string) Eden_Path::get($root); + $root = (string) Eden_Path::i($root); // Start the Global Cache - Eden_Cache::get($root); + Eden_Cache::i($root); return $this; } @@ -457,8 +463,8 @@ public function getRegistry() { * @return Eden_Template */ public function template($file, array $data = array()) { - Front_Error::get()->argument(1, 'string'); - return Eden_Template::get()->setData($data)->parsePhp($file); + Front_Error::i()->argument(1, 'string'); + return Eden_Template::i()->set($data)->parsePhp($file); } /** @@ -466,48 +472,32 @@ public function template($file, array $data = array()) { * * @return void */ - public function error($event, $trace, $offset, $type, $level, $class, $file, $line, $message) { - //if there is a trace template and there's at least 2 leads - if(count($trace) > $offset) { - //for each trace - foreach($trace as $i => $call) { - //if we are at the first one - if($i < $offset) { - //ignore it because it will be the actual - //call to the error or exception - unset($trace[$i]); - continue; - } - - //either way make this array to a comma separated string - $argments = NULL; - if(isset($call['args'])) { - $argments = implode(', ', $this->_getArguments($call['args'])); - } - //lets formulate the method - $method = $call['function'].'('.$argments.')'; - if(isset($call['class'])) { - $method = $call['class'].'->'.$method; - } - - $tline = isset($call['line']) ? $call['line'] : 'N/A'; - $tfile = isset($call['file']) ? $call['file'] : 'Virtual Call'; - - //convert trace from array to string - $trace[$i] = array($method, $tfile, $tline); + public function error($event, $type, $level, $class, $file, $line, $message, $trace, $offset) { + $history = array(); + for(; isset($trace[$offset]); $offset++) { + $row = $trace[$offset]; + + //lets formulate the method + $method = $row['function'].'()'; + if(isset($row['class'])) { + $method = $row['class'].'->'.$method; } - } else { - $trace = array(); + + $rowLine = isset($row['line']) ? $row['line'] : 'N/A'; + $rowFile = isset($row['file']) ? $row['file'] : 'Virtual Call'; + + //add to history + $history[] = array($method, $rowFile, $rowLine); } - - echo $this->Eden_Template() - ->setData('trace', $trace) - ->setData('type', $type) - ->setData('level', $level) - ->setData('class', $class) - ->setData('file', $file) - ->setData('line', $line) - ->setData('message', $message) + + echo Eden_Template::i() + ->set('history', $history) + ->set('type', $type) + ->set('level', $level) + ->set('class', $class) + ->set('file', $file) + ->set('line', $line) + ->set('message', $message) ->parsePhp(dirname(__FILE__).'/front/template/error.php'); } diff --git a/site/front/block/crumbs.php b/site/front/block/crumbs.php new file mode 100644 index 0000000..3b09f2e --- /dev/null +++ b/site/front/block/crumbs.php @@ -0,0 +1,80 @@ + +/* + * 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. + */ + +/** + * Pagination block + * + * @package Eden + * @category site + * @author Christian Blanquera + * @version $Id: form.php 1 2010-01-02 23:06:36Z blanquera $ + */ +class Front_Block_Crumbs extends Eden_Block { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_path = NULL; + + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + /* Magic + -------------------------------*/ + /* Public Methods + -------------------------------*/ + /** + * This Block has pagination we need to pass in the url + * + * @param array + * @return this + */ + public function setPath($path) { + $this->_path = $path; + return $this; + } + + /** + * Returns the template variables in key value format + * + * @param array data + * @return array + */ + public function getVariables() { + $crumbs = array(array('link' => '/', 'name' => 'API')); + if(trim($this->_path)) { + $pathArray = explode('/', $this->_path); + array_shift($pathArray); + $current = NULL; + foreach($pathArray as $path) { + $current .= '/'.$path; + $crumbs[] = array('link' => $current, 'name' => $path); + } + } + + return array('crumbs' => $crumbs); + } + + /** + * Returns a template file + * + * @param array data + * @return string + */ + public function getTemplate() { + return realpath(dirname(__FILE__).'/template/crumbs.php'); + } +} \ No newline at end of file diff --git a/site/front/block/log.php b/site/front/block/log.php new file mode 100644 index 0000000..e940f1c --- /dev/null +++ b/site/front/block/log.php @@ -0,0 +1,87 @@ + +/* + * 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. + */ + +/** + * Pagination block + * + * @package Eden + * @category site + * @author Christian Blanquera + * @version $Id: form.php 1 2010-01-02 23:06:36Z blanquera $ + */ +class Front_Block_Log extends Eden_Block { + /* Constants + -------------------------------*/ + const REPO_URL = 'http://svn.openovate.com/edenv2/trunk/library'; + const REPO_USER = 'cblanquera'; + const REPO_PASS = 'gphead'; + const REPO_LOG = 'svn log --username %s --password %s --xml --non-interactive --verbose %s 2>&1'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_path = NULL; + + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + /* Magic + -------------------------------*/ + /* Public Methods + -------------------------------*/ + /** + * This Block has pagination we need to pass in the url + * + * @param array + * @return this + */ + public function setPath($path) { + $this->_path = $path; + return $this; + } + + /** + * Returns the template variables in key value format + * + * @param array data + * @return array + */ + public function getVariables() { + exec(sprintf(self::REPO_LOG, self::REPO_USER, self::REPO_PASS, self::REPO_URL), $log); + $log = implode("\n", $log); + $log = simplexml_load_string($log); + $history = array(); + foreach($log->logentry as $entry) { + $history[] = array( + 'revision' => $entry->attributes()->revision, + 'author' => $entry->author, + 'date' => date('F d, Y g:iA', strtotime($entry->date)), + 'message' => $entry->msg + ); + } + + return array('history' => $history); + } + + /** + * Returns a template file + * + * @param array data + * @return string + */ + public function getTemplate() { + return realpath(dirname(__FILE__).'/template/log.php'); + } +} \ No newline at end of file diff --git a/site/front/block/menu.php b/site/front/block/menu.php new file mode 100644 index 0000000..f43f635 --- /dev/null +++ b/site/front/block/menu.php @@ -0,0 +1,110 @@ + +/* + * 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. + */ + +/** + * Pagination block + * + * @package Eden + * @category site + * @author Christian Blanquera + * @version $Id: form.php 1 2010-01-02 23:06:36Z blanquera $ + */ +class Front_Block_Menu extends Eden_Block { + /* Constants + -------------------------------*/ + const REPO_URL = 'http://svn.openovate.com/edenv2/trunk/library'; + const REPO_USER = 'cblanquera'; + const REPO_PASS = 'gphead'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_path = NULL; + protected $_root = NULL; + + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function i() { + return self::_getMultiple(__CLASS__); + } + + /* Magic + -------------------------------*/ + /* Public Methods + -------------------------------*/ + /** + * This Block has pagination we need to pass in the url + * + * @param array + * @return this + */ + public function setPath($path) { + $this->_path = $path; + return $this; + } + + /** + * This Block has pagination we need to pass in the url + * + * @param array + * @return this + */ + public function setRoot($root) { + $this->_root = $root; + return $this; + } + + /** + * Returns the template variables in key value format + * + * @param array data + * @return array + */ + public function getVariables() { + $contents = $this->_getContents($this->_root); + return array('contents' => $contents, 'current' => $this->_path, 'root' => $this->_root); + } + + /** + * Returns a template file + * + * @param array data + * @return string + */ + public function getTemplate() { + return realpath(dirname(__FILE__).'/template/menu.php'); + } + + protected function _getContents($path) { + $response = $this->Eden_Curl() + ->setUrl(self::REPO_URL.$path) + ->setUserPwd(self::REPO_USER.':'.self::REPO_PASS) + ->setHttpAuth(CURLAUTH_BASIC) + ->setFollowLocation(true) + ->getResponse(); + + $lines = explode("\n", $response); + $folders = $files = array(); + foreach($lines as $line) { + if(preg_match("/
  • $folders, 'files' => $files); + } +} \ No newline at end of file diff --git a/site/front/block/template/crumbs.php b/site/front/block/template/crumbs.php new file mode 100644 index 0000000..27d91e7 --- /dev/null +++ b/site/front/block/template/crumbs.php @@ -0,0 +1,9 @@ + 1): ?> + $crumb): ?> + + + + > + + + \ No newline at end of file diff --git a/site/front/block/template/log.php b/site/front/block/template/log.php new file mode 100644 index 0000000..f5e5978 --- /dev/null +++ b/site/front/block/template/log.php @@ -0,0 +1,10 @@ + $log): ?> +
    +
    + Revision: + | By: + | On: +
    +

    +
    + \ No newline at end of file diff --git a/site/front/block/template/menu.php b/site/front/block/template/menu.php new file mode 100644 index 0000000..946504a --- /dev/null +++ b/site/front/block/template/menu.php @@ -0,0 +1,21 @@ +
      + +
    • + + + Front_Block_Menu()->setPath($current)->setRoot($root.'/'.$folder); ?> + + + +
    • + + +
    • + + + + + +
    • + +
    \ No newline at end of file diff --git a/site/front/error.php b/site/front/error.php index 547d5e2..adb3c9b 100644 --- a/site/front/error.php +++ b/site/front/error.php @@ -26,7 +26,7 @@ class Front_Error extends Eden_Error { -------------------------------*/ /* Get -------------------------------*/ - public static function get($message = NULL, $code = 0) { + public static function i($message = NULL, $code = 0) { $class = __CLASS__; return new $class($message, $code); } diff --git a/site/front/handler.php b/site/front/handler.php index a17e154..5e38a03 100644 --- a/site/front/handler.php +++ b/site/front/handler.php @@ -23,7 +23,7 @@ class Front_Handler extends Eden_Class { -------------------------------*/ /* Get -------------------------------*/ - public static function get(Eden $app) { + public static function i(Eden $app) { return self::_getSingleton(__CLASS__, $app); } diff --git a/site/front/page.php b/site/front/page.php index 58b0cbc..835357b 100644 --- a/site/front/page.php +++ b/site/front/page.php @@ -23,8 +23,9 @@ abstract class Front_Page extends Eden_Class { -------------------------------*/ /* Protected Properties -------------------------------*/ - protected $_request = NULL; - protected $_messages = array(); + protected $_meta = array(); + protected $_request = NULL; + protected $_messages = array(); /* Private Properties -------------------------------*/ @@ -40,7 +41,7 @@ public function __toString() { try { $output = $this->render(); } catch(Exception $e) { - Eden_Error_Event::get()->exceptionHandler($e); + Eden_Error_Event::i()->exceptionHandler($e); return ''; } @@ -70,9 +71,9 @@ protected function _setMessage($message, $type = NULL) { } protected function _renderPage() { - $tpl = $this->_request->getData('path', 'template'); + $tpl = $this->_request['path']['template']; - $messages = $this->_request->getData('message'); + $messages = $this->_request['message']; if(is_array($messages)) { foreach($messages as $message) { diff --git a/site/front/page/api.php b/site/front/page/api.php new file mode 100644 index 0000000..90ab6cf --- /dev/null +++ b/site/front/page/api.php @@ -0,0 +1,294 @@ + +/* + * This file is part a custom application package. + * (c) 2009-2011 Christian Blanquera + */ + +/** + * Default logic to output a page + * + * @author Christian Blanquera + * @version $Id: index.php 14 2010-01-13 03:39:03Z blanquera $ + */ +class Front_Page_Api extends Front_Page { + /* Constants + -------------------------------*/ + const REPO_URL = 'http://svn.openovate.com/edenv2/trunk/library'; + const REPO_USER = 'cblanquera'; + const REPO_PASS = 'gphead'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_title = 'Eden - API'; + protected $_class = 'api'; + protected $_template = '/api.php'; + + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function i(Eden_Registry $request = NULL) { + return self::_getMultiple(__CLASS__, $request); + } + + /* Magic + -------------------------------*/ + /* Public Methods + -------------------------------*/ + public function render() { + $source = $this->_request['get']['source']; + $pathArray = $this->_request['request']['variables']->get(false); + $path = '/'.implode('/', $pathArray); + $code = $minify =NULL; + $notes = array(); + + if($path == '/') { + $path = NULL; + } + + if(strpos($path, '.') !== false) { + $code = $this->Eden_Curl() + ->setUrl(self::REPO_URL.$path) + ->setUserPwd(self::REPO_USER.':'.self::REPO_PASS) + ->setHttpAuth(CURLAUTH_BASIC) + ->getResponse(); + + $minify = $this->_getMinify($code); + + $notes = strpos($path, '.php') ? $this->_getNotes($code) : array(); + } + + $this->_body = array( + 'minify' => $minify, + 'source' => $source, + 'path' => $path, + 'code' => $code, + 'notes' => $notes); + + return $this->_renderPage(); + } + + /* Protected Methods + -------------------------------*/ + protected function _getNotes($code) { + $lines = explode("\n", $code); + $notes = array(); + $section = 'unknown'; + $class = 'unknown'; + foreach($lines as $i => $line) { + if(preg_match("#-+\*/#", $line)) { + $section = trim(str_replace('/*', '', $lines[$i-1])); + $notes[$class][$section] = array(); + continue; + } + + if(strpos(trim($line), '/**') === 0) { + $doc = $this->_getJavaDoc($lines, $i); + if($doc['meta']['type'] == 'class') { + $class = $doc['meta']['name']; + $notes[$class] = $doc; + continue; + } + + $notes[$class][$section][] = $doc; + continue; + } + + if(strpos(trim($line), 'const') === 0) { + list($key, $value) = explode('=', str_replace(array('const', ';', '\'', '"'), '', $line)); + if($value === true) { + $value = 'true'; + } else if($value === false) { + $value = 'false'; + } else if(is_null($value)) { + $value = 'null'; + } + $notes[$class]['Constants'][trim($key)] = trim($value); + continue; + } + + if(strpos(trim($line), 'public $') === 0) { + list($key, $value) = explode('=', str_replace('public', '', $line)); + $notes[$class]['Public Properties'][] = trim($key); + continue; + } + + if(strpos(trim($line), 'protected $') === 0) { + list($key, $value) = explode('=', str_replace('protected', '', $line)); + $notes[$class]['Public Properties'][] = trim($key); + continue; + } + + if(strpos(trim($line), 'private $') === 0) { + list($key, $value) = explode('=', str_replace('private', '', $line)); + $notes[$class]['Public Properties'][] = trim($key); + continue; + } + } + + return $notes; + } + + protected function _getJavaDoc($lines, &$i) { + $description = $code = NULL; + $attributes = $meta = array(); + $meta['type'] = 'unknown'; + $mode = true; + for($i++; $i < count($lines); $i++) { + $line = trim(preg_replace("/^\s+\*\s*/", '', $lines[$i])); + + if($line == '/') { + $i++; + break; + } + + if(strpos($line, '@') === 0) { + $mode = false; + list($key, $value) = explode(' ', substr($line, 1), 2); + if(isset($attributes[$key])) { + if(!is_array($attributes[$key])) { + $attributes[$key] = array($attributes[$key]); + } + + $attributes[$key][] = trim($value); + continue; + } + + $attributes[$key] = trim($value); + continue; + } + + if(!$mode) { + if(is_array($attributes[$key])) { + $attributes[$key][count($attributes[$key])-1] .= ' '.$line; + continue; + } + + $attributes[$key] .= ' '.$line; + continue; + } + + $description[] = $line; + } + + if(isset($lines[$i]) && strpos($lines[$i], 'class') !== false) { + $meta = array( + 'name' => NULL, + 'type' => 'class', + 'abstract' => false, + 'extends' => NULL, + 'implements' => array()); + + preg_match("/class\s([a-zA-Z0-9-_]+)/", $lines[$i], $matches); + if(isset($matches[1])) { + $meta['name'] = $matches[1]; + } + + preg_match("/extends\s([a-zA-Z0-9-_]+)/", $lines[$i], $matches); + if(isset($matches[1])) { + $meta['extends'] = $matches[1]; + } + + preg_match("/implements\s([a-zA-Z0-9-_\,\s]+)/", $lines[$i], $matches); + if(isset($matches[1])) { + $meta['implements'] = explode(',', $matches[1]); + } + } + + if(isset($lines[$i]) && strpos($lines[$i], 'function') !== false) { + $meta = array( + 'name' => NULL, + 'type' => 'function', + 'abstract' => false, + 'static' => false, + 'access' => NULL); + + preg_match("/function\s([a-zA-Z0-9-_]+)/", $lines[$i], $matches); + $meta['name'] = $matches[1]; + + if(strpos($lines[$i], 'static') !== false) { + $meta['static'] = true; + } + + if(strpos($lines[$i], 'public') !== false) { + $meta['access'] = 'public'; + } + + if(strpos($lines[$i], 'protected') !== false) { + $meta['access'] = 'protected'; + } + + if(strpos($lines[$i], 'private') !== false) { + $meta['access'] = 'private'; + } + } + + if(isset($lines[$i]) && strpos($lines[$i], 'abstract') !== false) { + $meta['abstract'] = true; + } + + if(isset($lines[$i])) { + $code = trim(preg_replace("/\s*\{/", '', $lines[$i])); + } + + return array( + 'code' => $code, + 'meta' => $meta, + 'description' => $description, + 'attributes' => $attributes); + } + + protected function _getMinify($code) { + if (!defined('T_ML_COMMENT')) { + define('T_ML_COMMENT', T_COMMENT); + } else { + define('T_DOC_COMMENT', T_ML_COMMENT); + } + + $tokens = token_get_all($code); + + $minify = NULL; + + foreach ($tokens as $token) { + if (is_string($token)) { + // simple 1-character token + $minify .= $token; + continue; + } + + // token array + list($id, $text) = $token; + + switch ($id) { + case T_COMMENT: + case T_ML_COMMENT: // we've defined this + case T_DOC_COMMENT: // and this + // no action on comments + break; + default: + // anything else -> output "as is" + $minify .= $text; + break; + } + } + + $minify = str_replace('\s*/is", '->', $minify); + $minify = preg_replace("/\s*\=\>\s*/is", '=>', $minify); + $minify = preg_replace("/\s*\=\s*/is", '=', $minify); + $minify = preg_replace("/\s*\,\s*/is", ',', $minify); + $minify = preg_replace("/\s*\{\s*/is", '{', $minify); + $minify = preg_replace("/\s*\}\s*/is", '}', $minify); + $minify = preg_replace("/\s*\;\s*/is", ';', $minify); + $minify = preg_replace("/\s*\.\s*/is", '.', $minify); + + return $minify; + } + + /* Private Methods + -------------------------------*/ +} diff --git a/site/front/page/documentation.php b/site/front/page/documentation.php new file mode 100644 index 0000000..9e211cd --- /dev/null +++ b/site/front/page/documentation.php @@ -0,0 +1,52 @@ + +/* + * This file is part a custom application package. + * (c) 2009-2011 Christian Blanquera + */ + +/** + * Default logic to output a page + * + * @author Christian Blanquera + * @version $Id: index.php 14 2010-01-13 03:39:03Z blanquera $ + */ +class Front_Page_Documentation extends Front_Page { + /* Constants + -------------------------------*/ + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_title = 'Eden - Documentation'; + protected $_class = 'documentation'; + protected $_template = '/documentation.php'; + + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function i(Eden_Registry $request = NULL) { + return self::_getMultiple(__CLASS__, $request); + } + + /* Magic + -------------------------------*/ + /* Public Methods + -------------------------------*/ + public function render() { + + $content = NULL; + $file = $this->_request['request']['string'].'.php'; + if($file != '/documentation.php') { + $template = $this->_request['path']['template']; + $content = front()->template($template.$file); + } + $this->_body = array('content' => $content); + return $this->_renderPage(); + } + + /* Protected Methods + -------------------------------*/ + /* Private Methods + -------------------------------*/ +} diff --git a/site/front/page/download.php b/site/front/page/download.php new file mode 100644 index 0000000..2a239e1 --- /dev/null +++ b/site/front/page/download.php @@ -0,0 +1,209 @@ + +/* + * This file is part a custom application package. + * (c) 2009-2011 Christian Blanquera + */ + +/** + * Default logic to output a page + * + * @author Christian Blanquera + * @version $Id: index.php 14 2010-01-13 03:39:03Z blanquera $ + */ +class Front_Page_Download extends Front_Page { + /* Constants + -------------------------------*/ + const REPO_URL = 'http://svn.openovate.com/edenv2/trunk/library'; + const REPO_USER = 'cblanquera'; + const REPO_PASS = 'gphead'; + + /* Public Properties + -------------------------------*/ + /* Protected Properties + -------------------------------*/ + protected $_title = 'Eden - Downloads'; + protected $_class = 'download'; + protected $_template = '/download.php'; + + protected $_core = array( + 'Eden_Class', + 'Eden_Error', + 'Eden_Event', + 'Eden_Error_Event', + 'Eden_Route_Error', + 'Eden_Route_Class', + 'Eden_Route_Method', + 'Eden_Route_Function', + 'Eden_Route', + 'Eden_When', + 'Eden_Map', + 'Eden_Loader', + 'Eden_Type', + 'Eden_Type_Abstract', + 'Eden_Type_Error', + 'Eden_Type_Array', + 'Eden_Type_String', + 'Eden_Collection', + 'Eden_Block', + 'Eden_Model', + 'Eden'); + + protected $_utilities = array( + 'Eden_Tool', + 'Eden_Template', + 'Eden_Session', + 'Eden_Cookie', + 'Eden_Registry', + 'Eden_Curl', + 'Eden_Path', + 'Eden_File', + 'Eden_Folder', + 'Eden_Image', + 'Eden_Unit', + 'Eden_Validation', + 'Eden_Oauth_Error', + 'Eden_Oauth_Base', + 'Eden_Oauth_Consumer'); + + protected $_database = array( + 'Eden_Sql_Error', + 'Eden_Mysql_Error', + 'Eden_Sql_Database', + 'Eden_Sql_Query', + 'Eden_Sql_Delete', + 'Eden_Sql_Select', + 'Eden_Sql_Update', + 'Eden_Sql_Insert', + 'Eden_Mysql_Alter', + 'Eden_Mysql_Create', + 'Eden_Mysql_Subselect', + 'Eden_Mysql_Utility', + 'Eden_Mysql_Collection', + 'Eden_Mysql_Model', + 'Eden_Mysql_Search', + 'Eden_Mysql'); + + protected $_cache = array( + 'Eden_Cache', + 'Eden_Apc', + 'Eden_Memcache'); + + /* Private Properties + -------------------------------*/ + /* Get + -------------------------------*/ + public static function i(Eden_Registry $request = NULL) { + return self::_getMultiple(__CLASS__, $request); + } + + /* Magic + -------------------------------*/ + /* Public Methods + -------------------------------*/ + public function render() { + if (!defined('T_ML_COMMENT')) { + define('T_ML_COMMENT', T_COMMENT); + } else { + define('T_DOC_COMMENT', T_ML_COMMENT); + } + + $package = $this->_request['post']['package']; + + if(!empty($package)) { + $classes = $this->_core; + + if($package->inArray('utilities')) { + $classes = array_merge($classes, $this->_utilities); + } + + if($package->inArray('database')) { + $classes = array_merge($classes, $this->_database); + } + + if($package->inArray('cache')) { + $classes = array_merge($classes, $this->_cache); + } + + $bundle = '_getClass($class)."\n"; + } + + header('Content-Type: text/plain'); + header('Content-Length: '.strlen($bundle)); + header('Content-Disposition: attachment; filename="eden.php"'); + return $bundle; + } + + return $this->_renderPage(); + } + + /* Protected Methods + -------------------------------*/ + protected function _getClass($class) { + $path = strtolower('/'.str_replace('_', '/', $class)).'.php'; + $code = $this->Eden_Curl() + ->setUrl(self::REPO_URL.$path) + ->setUserPwd(self::REPO_USER.':'.self::REPO_PASS) + ->setHttpAuth(CURLAUTH_BASIC) + ->getResponse(); + + return $this->_getMinify($code); + } + + protected function _getMinify($code) { + $tokens = token_get_all($code); + + $minify = NULL; + + foreach ($tokens as $token) { + if (is_string($token)) { + // simple 1-character token + $minify .= $token; + continue; + } + + // token array + list($id, $text) = $token; + + switch ($id) { + case T_COMMENT: + case T_ML_COMMENT: // we've defined this + case T_DOC_COMMENT: // and this + // no action on comments + break; + default: + // anything else -> output "as is" + $minify .= $text; + break; + } + } + + $minify = str_replace('\s*/is", '->', $minify); + $minify = preg_replace("/\s*\=\>\s*/is", '=>', $minify); + $minify = preg_replace("/\s*\=\s*/is", '=', $minify); + $minify = preg_replace("/\s*\,\s*/is", ',', $minify); + $minify = preg_replace("/\s*\{\s*/is", '{', $minify); + $minify = preg_replace("/\s*\}\s*/is", '}', $minify); + $minify = preg_replace("/\s*\;\s*/is", ';', $minify); + $minify = preg_replace("/\s*\.\s*/is", '.', $minify); + + if(strpos($minify, 'function ') !== false + && (strpos($minify, 'class ') === false + || strpos($minify, 'function ') < strpos($minify, 'class '))) { + $minify = substr($minify, strpos($minify, 'function ')); + } else if(strpos($minify, 'abstract ') !== false) { + $minify = substr($minify, strpos($minify, 'abstract ')); + } else if(strpos($minify, 'class ') !== false) { + $minify = substr($minify, strpos($minify, 'class ')); + } + + return $minify; + } + + /* Private Methods + -------------------------------*/ +} diff --git a/site/front/page/index.php b/site/front/page/index.php index 3faf888..8b56bd1 100644 --- a/site/front/page/index.php +++ b/site/front/page/index.php @@ -28,10 +28,6 @@ class Front_Page_Index extends Front_Page { -------------------------------*/ /* Get -------------------------------*/ - public static function get(Eden_Registry $request = NULL) { - return self::_getMultiple(__CLASS__, $request); - } - /* Magic -------------------------------*/ /* Public Methods diff --git a/site/front/template/_foot.php b/site/front/template/_foot.php index eab7a9a..63d65f3 100644 --- a/site/front/template/_foot.php +++ b/site/front/template/_foot.php @@ -1 +1 @@ -FOOT \ No newline at end of file + \ No newline at end of file diff --git a/site/front/template/_head.php b/site/front/template/_head.php index e5517e4..e3c5e86 100644 --- a/site/front/template/_head.php +++ b/site/front/template/_head.php @@ -1 +1,6 @@ -HEAD \ No newline at end of file +

    Eden PHP Library

    + \ No newline at end of file diff --git a/site/front/template/_menu.php b/site/front/template/_menu.php new file mode 100644 index 0000000..ef4dc5a --- /dev/null +++ b/site/front/template/_menu.php @@ -0,0 +1,121 @@ +