diff options
author | robocoder <anthon.pang@gmail.com> | 2011-01-10 21:50:50 +0300 |
---|---|---|
committer | robocoder <anthon.pang@gmail.com> | 2011-01-10 21:50:50 +0300 |
commit | 7191afd6d6bb443708886bb013a4155271ce40d3 (patch) | |
tree | 3d1228f9d062d31354836f629c825ec7bedb88d3 /libs/Zend | |
parent | bae316c9500f56f78aa7b1c596d9ef38b8b50231 (diff) |
fixes #1765 - updating to Zend Framework 1.11.2 with some modifications:
ZF-10888: loadClass() inconsistencies
* Zend/Http/Client.php
* Zend/Uri.php
* Zend/Validate.php
ZF-10890: include_path dependency and inconsistencies
* Zend/Validate/Hostname.php
refs #160 - added Zend_OpenId
git-svn-id: http://dev.piwik.org/svn/trunk@3694 59fd770c-687e-43c8-a1e3-f5a4ff64c105
Diffstat (limited to 'libs/Zend')
257 files changed, 12440 insertions, 1516 deletions
diff --git a/libs/Zend/Auth/Adapter/DbTable.php b/libs/Zend/Auth/Adapter/DbTable.php index c0c06b82c6..3ea1a3bc1e 100644 --- a/libs/Zend/Auth/Adapter/DbTable.php +++ b/libs/Zend/Auth/Adapter/DbTable.php @@ -17,7 +17,7 @@ * @subpackage Adapter * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: DbTable.php 22614 2010-07-17 13:46:07Z dragonbe $ + * @version $Id: DbTable.php 23484 2010-12-10 03:57:59Z mjh_ca $ */ @@ -114,12 +114,12 @@ class Zend_Auth_Adapter_DbTable implements Zend_Auth_Adapter_Interface * @var array */ protected $_resultRow = null; - + /** - * $_ambiguityIdentity - Flag to indicate same Identity can be used with + * $_ambiguityIdentity - Flag to indicate same Identity can be used with * different credentials. Default is FALSE and need to be set to true to * allow ambiguity usage. - * + * * @var boolean */ protected $_ambiguityIdentity = false; @@ -159,7 +159,7 @@ class Zend_Auth_Adapter_DbTable implements Zend_Auth_Adapter_Interface /** * _setDbAdapter() - set the database adapter to be used for quering * - * @param Zend_Db_Adapter_Abstract + * @param Zend_Db_Adapter_Abstract * @throws Zend_Auth_Adapter_Exception * @return Zend_Auth_Adapter_DbTable */ @@ -178,7 +178,7 @@ class Zend_Auth_Adapter_DbTable implements Zend_Auth_Adapter_Interface throw new Zend_Auth_Adapter_Exception('No database adapter present'); } } - + return $this; } @@ -265,12 +265,12 @@ class Zend_Auth_Adapter_DbTable implements Zend_Auth_Adapter_Interface $this->_credential = $credential; return $this; } - + /** * setAmbiguityIdentity() - sets a flag for usage of identical identities * with unique credentials. It accepts integers (0, 1) or boolean (true, * false) parameters. Default is false. - * + * * @param int|bool $flag * @return Zend_Auth_Adapter_DbTable */ @@ -284,9 +284,9 @@ class Zend_Auth_Adapter_DbTable implements Zend_Auth_Adapter_Interface return $this; } /** - * getAmbiguityIdentity() - returns TRUE for usage of multiple identical + * getAmbiguityIdentity() - returns TRUE for usage of multiple identical * identies with different credentials, FALSE if not used. - * + * * @return bool */ public function getAmbiguityIdentity() @@ -367,7 +367,7 @@ class Zend_Auth_Adapter_DbTable implements Zend_Auth_Adapter_Interface $this->_authenticateSetup(); $dbSelect = $this->_authenticateCreateSelect(); $resultIdentities = $this->_authenticateQuerySelect($dbSelect); - + if ( ($authResult = $this->_authenticateValidateResultSet($resultIdentities)) instanceof Zend_Auth_Result) { return $authResult; } @@ -382,7 +382,7 @@ class Zend_Auth_Adapter_DbTable implements Zend_Auth_Adapter_Interface } $resultIdentities = $validIdentities; } - + $authResult = $this->_authenticateValidateResult(array_shift($resultIdentities)); return $authResult; } diff --git a/libs/Zend/Auth/Adapter/Digest.php b/libs/Zend/Auth/Adapter/Digest.php index a099bef358..7e1e8bd82d 100644 --- a/libs/Zend/Auth/Adapter/Digest.php +++ b/libs/Zend/Auth/Adapter/Digest.php @@ -17,7 +17,7 @@ * @subpackage Adapter * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Digest.php 20096 2010-01-06 02:05:09Z bkarwin $ + * @version $Id: Digest.php 23484 2010-12-10 03:57:59Z mjh_ca $ */ @@ -213,7 +213,7 @@ class Zend_Auth_Adapter_Digest implements Zend_Auth_Adapter_Interface while ($line = trim(fgets($fileHandle))) { if (substr($line, 0, $idLength) === $id) { - if (substr($line, -32) === md5("$this->_username:$this->_realm:$this->_password")) { + if ($this->_secureStringCompare(substr($line, -32), md5("$this->_username:$this->_realm:$this->_password"))) { $result['code'] = Zend_Auth_Result::SUCCESS; } else { $result['code'] = Zend_Auth_Result::FAILURE_CREDENTIAL_INVALID; @@ -227,4 +227,26 @@ class Zend_Auth_Adapter_Digest implements Zend_Auth_Adapter_Interface $result['messages'][] = "Username '$this->_username' and realm '$this->_realm' combination not found"; return new Zend_Auth_Result($result['code'], $result['identity'], $result['messages']); } + + /** + * Securely compare two strings for equality while avoided C level memcmp() + * optimisations capable of leaking timing information useful to an attacker + * attempting to iteratively guess the unknown string (e.g. password) being + * compared against. + * + * @param string $a + * @param string $b + * @return bool + */ + protected function _secureStringCompare($a, $b) + { + if (strlen($a) !== strlen($b)) { + return false; + } + $result = 0; + for ($i = 0; $i < strlen($a); $i++) { + $result |= ord($a[$i]) ^ ord($b[$i]); + } + return $result == 0; + } } diff --git a/libs/Zend/Auth/Adapter/Http.php b/libs/Zend/Auth/Adapter/Http.php index d645d8db93..595a30cb23 100644 --- a/libs/Zend/Auth/Adapter/Http.php +++ b/libs/Zend/Auth/Adapter/Http.php @@ -17,7 +17,7 @@ * @subpackage Zend_Auth_Adapter_Http * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Http.php 20096 2010-01-06 02:05:09Z bkarwin $ + * @version $Id: Http.php 23484 2010-12-10 03:57:59Z mjh_ca $ */ @@ -538,7 +538,7 @@ class Zend_Auth_Adapter_Http implements Zend_Auth_Adapter_Interface } $password = $this->_basicResolver->resolve($creds[0], $this->_realm); - if ($password && $password == $creds[1]) { + if ($password && $this->_secureStringCompare($password, $creds[1])) { $identity = array('username'=>$creds[0], 'realm'=>$this->_realm); return new Zend_Auth_Result(Zend_Auth_Result::SUCCESS, $identity); } else { @@ -640,7 +640,7 @@ class Zend_Auth_Adapter_Http implements Zend_Auth_Adapter_Interface // If our digest matches the client's let them in, otherwise return // a 401 code and exit to prevent access to the protected resource. - if ($digest == $data['response']) { + if ($this->_secureStringCompare($digest, $data['response'])) { $identity = array('username'=>$data['username'], 'realm'=>$data['realm']); return new Zend_Auth_Result(Zend_Auth_Result::SUCCESS, $identity); } else { @@ -844,4 +844,26 @@ class Zend_Auth_Adapter_Http implements Zend_Auth_Adapter_Interface return $data; } + + /** + * Securely compare two strings for equality while avoided C level memcmp() + * optimisations capable of leaking timing information useful to an attacker + * attempting to iteratively guess the unknown string (e.g. password) being + * compared against. + * + * @param string $a + * @param string $b + * @return bool + */ + protected function _secureStringCompare($a, $b) + { + if (strlen($a) !== strlen($b)) { + return false; + } + $result = 0; + for ($i = 0; $i < strlen($a); $i++) { + $result |= ord($a[$i]) ^ ord($b[$i]); + } + return $result == 0; + } } diff --git a/libs/Zend/Auth/Adapter/Ldap.php b/libs/Zend/Auth/Adapter/Ldap.php index 20f31c1fe0..05f5d2168e 100644 --- a/libs/Zend/Auth/Adapter/Ldap.php +++ b/libs/Zend/Auth/Adapter/Ldap.php @@ -17,7 +17,7 @@ * @subpackage Zend_Auth_Adapter * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Ldap.php 21320 2010-03-04 16:05:09Z sgehrig $ + * @version $Id: Ldap.php 23486 2010-12-10 04:05:30Z mjh_ca $ */ /** @@ -335,8 +335,8 @@ class Zend_Auth_Adapter_Ldap implements Zend_Auth_Adapter_Interface $messages[1] = ''; $messages[] = "$canonicalName authentication successful"; if ($requireRebind === true) { - // rebinding with authenticated user - $ldap->bind($dn, $password); + // rebinding with authenticated user + $ldap->bind($dn, $password); } return new Zend_Auth_Result(Zend_Auth_Result::SUCCESS, $canonicalName, $messages); } else { diff --git a/libs/Zend/Cache.php b/libs/Zend/Cache.php index 761be75e17..6b66fa14cd 100644 --- a/libs/Zend/Cache.php +++ b/libs/Zend/Cache.php @@ -16,7 +16,7 @@ * @package Zend_Cache * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Cache.php 21974 2010-04-23 17:10:17Z alexander $ + * @version $Id: Cache.php 23154 2010-10-18 17:41:06Z mabe $ */ @@ -40,7 +40,7 @@ abstract class Zend_Cache * * @var array */ - public static $standardBackends = array('File', 'Sqlite', 'Memcached', 'Apc', 'ZendPlatform', + public static $standardBackends = array('File', 'Sqlite', 'Memcached', 'Libmemcached', 'Apc', 'ZendPlatform', 'Xcache', 'TwoLevels', 'ZendServer_Disk', 'ZendServer_ShMem'); /** @@ -48,10 +48,10 @@ abstract class Zend_Cache * * @var array */ - public static $standardExtendedBackends = array('File', 'Apc', 'TwoLevels', 'Memcached', 'Sqlite'); + public static $standardExtendedBackends = array('File', 'Apc', 'TwoLevels', 'Memcached', 'Libmemcached', 'Sqlite'); /** - * Only for backward compatibily (may be removed in next major release) + * Only for backward compatibility (may be removed in next major release) * * @var array * @deprecated @@ -59,12 +59,12 @@ abstract class Zend_Cache public static $availableFrontends = array('Core', 'Output', 'Class', 'File', 'Function', 'Page'); /** - * Only for backward compatibily (may be removed in next major release) + * Only for backward compatibility (may be removed in next major release) * * @var array * @deprecated */ - public static $availableBackends = array('File', 'Sqlite', 'Memcached', 'Apc', 'ZendPlatform', 'Xcache', 'TwoLevels'); + public static $availableBackends = array('File', 'Sqlite', 'Memcached', 'Libmemcached', 'Apc', 'ZendPlatform', 'Xcache', 'TwoLevels'); /** * Consts for clean() method @@ -84,7 +84,7 @@ abstract class Zend_Cache * @param array $backendOptions associative array of options for the corresponding backend constructor * @param boolean $customFrontendNaming if true, the frontend argument is used as a complete class name ; if false, the frontend argument is used as the end of "Zend_Cache_Frontend_[...]" class name * @param boolean $customBackendNaming if true, the backend argument is used as a complete class name ; if false, the backend argument is used as the end of "Zend_Cache_Backend_[...]" class name - * @param boolean $autoload if true, there will no // require_once for backend and frontend (usefull only for custom backends/frontends) + * @param boolean $autoload if true, there will no // require_once for backend and frontend (useful only for custom backends/frontends) * @throws Zend_Cache_Exception * @return Zend_Cache_Core|Zend_Cache_Frontend */ @@ -113,7 +113,7 @@ abstract class Zend_Cache } /** - * Frontend Constructor + * Backend Constructor * * @param string $backend * @param array $backendOptions @@ -154,7 +154,7 @@ abstract class Zend_Cache } /** - * Backend Constructor + * Frontend Constructor * * @param string $frontend * @param array $frontendOptions diff --git a/libs/Zend/Cache/Backend.php b/libs/Zend/Cache/Backend.php index f71dae135a..3e94ab3d8c 100644 --- a/libs/Zend/Cache/Backend.php +++ b/libs/Zend/Cache/Backend.php @@ -17,7 +17,7 @@ * @subpackage Zend_Cache_Backend * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Backend.php 20882 2010-02-03 18:19:44Z matthew $ + * @version $Id: Backend.php 20880 2010-02-03 18:18:32Z matthew $ */ diff --git a/libs/Zend/Cache/Backend/BlackHole.php b/libs/Zend/Cache/Backend/BlackHole.php index 3eb382eca2..8951ce63c9 100644 --- a/libs/Zend/Cache/Backend/BlackHole.php +++ b/libs/Zend/Cache/Backend/BlackHole.php @@ -17,7 +17,7 @@ * @subpackage Zend_Cache_Backend * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: BlackHole.php 17867 2009-08-28 09:42:11Z yoshida@zend.co.jp $ + * @version $Id: BlackHole.php 23484 2010-12-10 03:57:59Z mjh_ca $ */ /** @@ -36,8 +36,8 @@ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ -class Zend_Cache_Backend_BlackHole - extends Zend_Cache_Backend +class Zend_Cache_Backend_BlackHole + extends Zend_Cache_Backend implements Zend_Cache_Backend_ExtendedInterface { /** diff --git a/libs/Zend/Cache/Backend/File.php b/libs/Zend/Cache/Backend/File.php index eeddfa5b80..44473a6f73 100644 --- a/libs/Zend/Cache/Backend/File.php +++ b/libs/Zend/Cache/Backend/File.php @@ -17,7 +17,7 @@ * @subpackage Zend_Cache_Backend * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: File.php 21642 2010-03-25 17:07:02Z mabe $ + * @version $Id: File.php 21636 2010-03-24 17:10:23Z mabe $ */ /** diff --git a/libs/Zend/Cache/Backend/Libmemcached.php b/libs/Zend/Cache/Backend/Libmemcached.php new file mode 100644 index 0000000000..45b390f9b2 --- /dev/null +++ b/libs/Zend/Cache/Backend/Libmemcached.php @@ -0,0 +1,484 @@ +<?php +/** + * Zend Framework + * + * LICENSE + * + * This source file is subject to the new BSD license that is bundled + * with this package in the file LICENSE.txt. + * It is also available through the world-wide-web at this URL: + * http://framework.zend.com/license/new-bsd + * If you did not receive a copy of the license and are unable to + * obtain it through the world-wide-web, please send an email + * to license@zend.com so we can send you a copy immediately. + * + * @category Zend + * @package Zend_Cache + * @subpackage Zend_Cache_Backend + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + * @version $Id: Libmemcached.php 23220 2010-10-22 10:24:14Z mabe $ + */ + + +/** + * @see Zend_Cache_Backend_Interface + */ +// require_once 'Zend/Cache/Backend/ExtendedInterface.php'; + +/** + * @see Zend_Cache_Backend + */ +// require_once 'Zend/Cache/Backend.php'; + + +/** + * @package Zend_Cache + * @subpackage Zend_Cache_Backend + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ +class Zend_Cache_Backend_Libmemcached extends Zend_Cache_Backend implements Zend_Cache_Backend_ExtendedInterface +{ + /** + * Default Server Values + */ + const DEFAULT_HOST = '127.0.0.1'; + const DEFAULT_PORT = 11211; + const DEFAULT_WEIGHT = 1; + + /** + * Log message + */ + const TAGS_UNSUPPORTED_BY_CLEAN_OF_LIBMEMCACHED_BACKEND = 'Zend_Cache_Backend_Libmemcached::clean() : tags are unsupported by the Libmemcached backend'; + const TAGS_UNSUPPORTED_BY_SAVE_OF_LIBMEMCACHED_BACKEND = 'Zend_Cache_Backend_Libmemcached::save() : tags are unsupported by the Libmemcached backend'; + + /** + * Available options + * + * =====> (array) servers : + * an array of memcached server ; each memcached server is described by an associative array : + * 'host' => (string) : the name of the memcached server + * 'port' => (int) : the port of the memcached server + * 'weight' => (int) : number of buckets to create for this server which in turn control its + * probability of it being selected. The probability is relative to the total + * weight of all servers. + * =====> (array) client : + * an array of memcached client options ; the memcached client is described by an associative array : + * @see http://php.net/manual/memcached.constants.php + * - The option name can be the name of the constant without the prefix 'OPT_' + * or the integer value of this option constant + * + * @var array available options + */ + protected $_options = array( + 'servers' => array(array( + 'host' => self::DEFAULT_HOST, + 'port' => self::DEFAULT_PORT, + 'weight' => self::DEFAULT_WEIGHT, + )), + 'client' => array() + ); + + /** + * Memcached object + * + * @var mixed memcached object + */ + protected $_memcache = null; + + /** + * Constructor + * + * @param array $options associative array of options + * @throws Zend_Cache_Exception + * @return void + */ + public function __construct(array $options = array()) + { + if (!extension_loaded('memcached')) { + Zend_Cache::throwException('The memcached extension must be loaded for using this backend !'); + } + + // override default client options + $this->_options['client'] = array( + Memcached::OPT_DISTRIBUTION => Memcached::DISTRIBUTION_CONSISTENT, + Memcached::OPT_HASH => Memcached::HASH_MD5, + Memcached::OPT_LIBKETAMA_COMPATIBLE => true, + ); + + parent::__construct($options); + + if (isset($this->_options['servers'])) { + $value = $this->_options['servers']; + if (isset($value['host'])) { + // in this case, $value seems to be a simple associative array (one server only) + $value = array(0 => $value); // let's transform it into a classical array of associative arrays + } + $this->setOption('servers', $value); + } + $this->_memcache = new Memcached; + + // setup memcached client options + foreach ($this->_options['client'] as $name => $value) { + $optId = null; + if (is_int($name)) { + $optId = $name; + } else { + $optConst = 'Memcached::OPT_' . strtoupper($name); + if (defined($optConst)) { + $optId = constant($optConst); + } else { + $this->_log("Unknown memcached client option '{$name}' ({$optConst})"); + } + } + if ($optId) { + if (!$this->_memcache->setOption($optId, $value)) { + $this->_log("Setting memcached client option '{$optId}' failed"); + } + } + } + + // setup memcached servers + $servers = array(); + foreach ($this->_options['servers'] as $server) { + if (!array_key_exists('port', $server)) { + $server['port'] = self::DEFAULT_PORT; + } + if (!array_key_exists('weight', $server)) { + $server['weight'] = self::DEFAULT_WEIGHT; + } + + $servers[] = array($server['host'], $server['port'], $server['weight']); + } + $this->_memcache->addServers($servers); + } + + /** + * Test if a cache is available for the given id and (if yes) return it (false else) + * + * @param string $id Cache id + * @param boolean $doNotTestCacheValidity If set to true, the cache validity won't be tested + * @return string|false cached datas + */ + public function load($id, $doNotTestCacheValidity = false) + { + $tmp = $this->_memcache->get($id); + if (isset($tmp[0])) { + return $tmp[0]; + } + return false; + } + + /** + * Test if a cache is available or not (for the given id) + * + * @param string $id Cache id + * @return int|false (a cache is not available) or "last modified" timestamp (int) of the available cache record + */ + public function test($id) + { + $tmp = $this->_memcache->get($id); + if (isset($tmp[0], $tmp[1])) { + return (int)$tmp[1]; + } + return false; + } + + /** + * Save some string datas into a cache record + * + * Note : $data is always "string" (serialization is done by the + * core not by the backend) + * + * @param string $data Datas to cache + * @param string $id Cache id + * @param array $tags Array of strings, the cache record will be tagged by each string entry + * @param int $specificLifetime If != false, set a specific lifetime for this cache record (null => infinite lifetime) + * @return boolean True if no problem + */ + public function save($data, $id, $tags = array(), $specificLifetime = false) + { + $lifetime = $this->getLifetime($specificLifetime); + + // ZF-8856: using set because add needs a second request if item already exists + $result = @$this->_memcache->set($id, array($data, time(), $lifetime), $lifetime); + if ($result === false) { + $rsCode = $this->_memcache->getResultCode(); + $rsMsg = $this->_memcache->getResultMessage(); + $this->_log("Memcached::set() failed: [{$rsCode}] {$rsMsg}"); + } + + if (count($tags) > 0) { + $this->_log(self::TAGS_UNSUPPORTED_BY_SAVE_OF_LIBMEMCACHED_BACKEND); + } + + return $result; + } + + /** + * Remove a cache record + * + * @param string $id Cache id + * @return boolean True if no problem + */ + public function remove($id) + { + return $this->_memcache->delete($id); + } + + /** + * Clean some cache records + * + * Available modes are : + * 'all' (default) => remove all cache entries ($tags is not used) + * 'old' => unsupported + * 'matchingTag' => unsupported + * 'notMatchingTag' => unsupported + * 'matchingAnyTag' => unsupported + * + * @param string $mode Clean mode + * @param array $tags Array of tags + * @throws Zend_Cache_Exception + * @return boolean True if no problem + */ + public function clean($mode = Zend_Cache::CLEANING_MODE_ALL, $tags = array()) + { + switch ($mode) { + case Zend_Cache::CLEANING_MODE_ALL: + return $this->_memcache->flush(); + break; + case Zend_Cache::CLEANING_MODE_OLD: + $this->_log("Zend_Cache_Backend_Libmemcached::clean() : CLEANING_MODE_OLD is unsupported by the Libmemcached backend"); + break; + case Zend_Cache::CLEANING_MODE_MATCHING_TAG: + case Zend_Cache::CLEANING_MODE_NOT_MATCHING_TAG: + case Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG: + $this->_log(self::TAGS_UNSUPPORTED_BY_CLEAN_OF_LIBMEMCACHED_BACKEND); + break; + default: + Zend_Cache::throwException('Invalid mode for clean() method'); + break; + } + } + + /** + * Return true if the automatic cleaning is available for the backend + * + * @return boolean + */ + public function isAutomaticCleaningAvailable() + { + return false; + } + + /** + * Set the frontend directives + * + * @param array $directives Assoc of directives + * @throws Zend_Cache_Exception + * @return void + */ + public function setDirectives($directives) + { + parent::setDirectives($directives); + $lifetime = $this->getLifetime(false); + if ($lifetime > 2592000) { + // #ZF-3490 : For the memcached backend, there is a lifetime limit of 30 days (2592000 seconds) + $this->_log('memcached backend has a limit of 30 days (2592000 seconds) for the lifetime'); + } + if ($lifetime === null) { + // #ZF-4614 : we tranform null to zero to get the maximal lifetime + parent::setDirectives(array('lifetime' => 0)); + } + } + + /** + * Return an array of stored cache ids + * + * @return array array of stored cache ids (string) + */ + public function getIds() + { + $this->_log("Zend_Cache_Backend_Libmemcached::save() : getting the list of cache ids is unsupported by the Libmemcached backend"); + return array(); + } + + /** + * Return an array of stored tags + * + * @return array array of stored tags (string) + */ + public function getTags() + { + $this->_log(self::TAGS_UNSUPPORTED_BY_SAVE_OF_LIBMEMCACHED_BACKEND); + return array(); + } + + /** + * Return an array of stored cache ids which match given tags + * + * In case of multiple tags, a logical AND is made between tags + * + * @param array $tags array of tags + * @return array array of matching cache ids (string) + */ + public function getIdsMatchingTags($tags = array()) + { + $this->_log(self::TAGS_UNSUPPORTED_BY_SAVE_OF_LIBMEMCACHED_BACKEND); + return array(); + } + + /** + * Return an array of stored cache ids which don't match given tags + * + * In case of multiple tags, a logical OR is made between tags + * + * @param array $tags array of tags + * @return array array of not matching cache ids (string) + */ + public function getIdsNotMatchingTags($tags = array()) + { + $this->_log(self::TAGS_UNSUPPORTED_BY_SAVE_OF_LIBMEMCACHED_BACKEND); + return array(); + } + + /** + * Return an array of stored cache ids which match any given tags + * + * In case of multiple tags, a logical AND is made between tags + * + * @param array $tags array of tags + * @return array array of any matching cache ids (string) + */ + public function getIdsMatchingAnyTags($tags = array()) + { + $this->_log(self::TAGS_UNSUPPORTED_BY_SAVE_OF_LIBMEMCACHED_BACKEND); + return array(); + } + + /** + * Return the filling percentage of the backend storage + * + * @throws Zend_Cache_Exception + * @return int integer between 0 and 100 + */ + public function getFillingPercentage() + { + $mems = $this->_memcache->getStats(); + if ($mems === false) { + return 0; + } + + $memSize = null; + $memUsed = null; + foreach ($mems as $key => $mem) { + if ($mem === false) { + $this->_log('can\'t get stat from ' . $key); + continue; + } + + $eachSize = $mem['limit_maxbytes']; + $eachUsed = $mem['bytes']; + if ($eachUsed > $eachSize) { + $eachUsed = $eachSize; + } + + $memSize += $eachSize; + $memUsed += $eachUsed; + } + + if ($memSize === null || $memUsed === null) { + Zend_Cache::throwException('Can\'t get filling percentage'); + } + + return ((int) (100. * ($memUsed / $memSize))); + } + + /** + * Return an array of metadatas for the given cache id + * + * The array must include these keys : + * - expire : the expire timestamp + * - tags : a string array of tags + * - mtime : timestamp of last modification time + * + * @param string $id cache id + * @return array array of metadatas (false if the cache id is not found) + */ + public function getMetadatas($id) + { + $tmp = $this->_memcache->get($id); + if (isset($tmp[0], $tmp[1], $tmp[2])) { + $data = $tmp[0]; + $mtime = $tmp[1]; + $lifetime = $tmp[2]; + return array( + 'expire' => $mtime + $lifetime, + 'tags' => array(), + 'mtime' => $mtime + ); + } + + return false; + } + + /** + * Give (if possible) an extra lifetime to the given cache id + * + * @param string $id cache id + * @param int $extraLifetime + * @return boolean true if ok + */ + public function touch($id, $extraLifetime) + { + $tmp = $this->_memcache->get($id); + if (isset($tmp[0], $tmp[1], $tmp[2])) { + $data = $tmp[0]; + $mtime = $tmp[1]; + $lifetime = $tmp[2]; + $newLifetime = $lifetime - (time() - $mtime) + $extraLifetime; + if ($newLifetime <=0) { + return false; + } + // #ZF-5702 : we try replace() first becase set() seems to be slower + if (!($result = $this->_memcache->replace($id, array($data, time(), $newLifetime), $newLifetime))) { + $result = $this->_memcache->set($id, array($data, time(), $newLifetime), $newLifetime); + if ($result === false) { + $rsCode = $this->_memcache->getResultCode(); + $rsMsg = $this->_memcache->getResultMessage(); + $this->_log("Memcached::set() failed: [{$rsCode}] {$rsMsg}"); + } + } + return $result; + } + return false; + } + + /** + * Return an associative array of capabilities (booleans) of the backend + * + * The array must include these keys : + * - automatic_cleaning (is automating cleaning necessary) + * - tags (are tags supported) + * - expired_read (is it possible to read expired cache records + * (for doNotTestCacheValidity option for example)) + * - priority does the backend deal with priority when saving + * - infinite_lifetime (is infinite lifetime can work with this backend) + * - get_list (is it possible to get the list of cache ids and the complete list of tags) + * + * @return array associative of with capabilities + */ + public function getCapabilities() + { + return array( + 'automatic_cleaning' => false, + 'tags' => false, + 'expired_read' => false, + 'priority' => false, + 'infinite_lifetime' => false, + 'get_list' => false + ); + } + +} diff --git a/libs/Zend/Cache/Backend/Memcached.php b/libs/Zend/Cache/Backend/Memcached.php index 3c29bcce67..fb178bf0ae 100644 --- a/libs/Zend/Cache/Backend/Memcached.php +++ b/libs/Zend/Cache/Backend/Memcached.php @@ -17,7 +17,7 @@ * @subpackage Zend_Cache_Backend * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Memcached.php 22208 2010-05-20 16:59:02Z mabe $ + * @version $Id: Memcached.php 22207 2010-05-20 16:47:16Z mabe $ */ diff --git a/libs/Zend/Cache/Backend/Static.php b/libs/Zend/Cache/Backend/Static.php index 6872902a18..0c6f02fc9c 100644 --- a/libs/Zend/Cache/Backend/Static.php +++ b/libs/Zend/Cache/Backend/Static.php @@ -17,7 +17,7 @@ * @subpackage Zend_Cache_Backend * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: BlackHole.php 17867 2009-08-28 09:42:11Z yoshida@zend.co.jp $ + * @version $Id: Static.php 22950 2010-09-16 19:33:00Z mabe $ */ /** @@ -166,7 +166,7 @@ class Zend_Cache_Backend_Static if (empty($fileName)) { $fileName = $this->_options['index_filename']; } - if (is_null($this->_tagged) && $tagged = $this->getInnerCache()->load(self::INNER_CACHE_NAME)) { + if ($this->_tagged === null && $tagged = $this->getInnerCache()->load(self::INNER_CACHE_NAME)) { $this->_tagged = $tagged; } elseif (!$this->_tagged) { return false; @@ -211,7 +211,7 @@ class Zend_Cache_Backend_Static } clearstatcache(); - if (is_null($id) || strlen($id) == 0) { + if ($id === null || strlen($id) == 0) { $id = $this->_detectId(); } else { $id = $this->_decodeId($id); @@ -225,7 +225,7 @@ class Zend_Cache_Backend_Static $pathName = realpath($this->_options['public_dir']) . dirname($id); $this->_createDirectoriesFor($pathName); - if (is_null($id) || strlen($id) == 0) { + if ($id === null || strlen($id) == 0) { $dataUnserialized = unserialize($data); $data = $dataUnserialized['data']; } @@ -239,9 +239,9 @@ class Zend_Cache_Backend_Static } @chmod($file, $this->_octdec($this->_options['cache_file_umask'])); - if (is_null($this->_tagged) && $tagged = $this->getInnerCache()->load(self::INNER_CACHE_NAME)) { + if ($this->_tagged === null && $tagged = $this->getInnerCache()->load(self::INNER_CACHE_NAME)) { $this->_tagged = $tagged; - } elseif (is_null($this->_tagged)) { + } elseif ($this->_tagged === null) { $this->_tagged = array(); } if (!isset($this->_tagged[$id])) { @@ -261,22 +261,15 @@ class Zend_Cache_Backend_Static */ protected function _createDirectoriesFor($path) { - if ( !is_dir($path) - && !@mkdir($path, $this->_options['cache_directory_umask'], true)) { - $lastErr = error_get_last(); - Zend_Cache::throwException("Can't create directory: {$lastErr['message']}"); - } - - /* - $parts = explode('/', $path); - $directory = ''; - foreach ($parts as $part) { - $directory = rtrim($directory, '/') . '/' . $part; - if (!is_dir($directory)) { - mkdir($directory, $this->_octdec($this->_options['cache_directory_umask'])); + if (!is_dir($path)) { + $oldUmask = umask(0); + if ( !@mkdir($path, $this->_octdec($this->_options['cache_directory_umask']), true)) { + $lastErr = error_get_last(); + umask($oldUmask); + Zend_Cache::throwException("Can't create directory: {$lastErr['message']}"); } + umask($oldUmask); } - */ } /** @@ -305,7 +298,7 @@ class Zend_Cache_Backend_Static Zend_Cache::throwException('Invalid cache id: does not match expected public_dir path'); } $fileName = basename($id); - if (is_null($this->_tagged) && $tagged = $this->getInnerCache()->load(self::INNER_CACHE_NAME)) { + if ($this->_tagged === null && $tagged = $this->getInnerCache()->load(self::INNER_CACHE_NAME)) { $this->_tagged = $tagged; } elseif (!$this->_tagged) { return false; @@ -394,7 +387,7 @@ class Zend_Cache_Backend_Static if (empty($tags)) { throw new Zend_Exception('Cannot use tag matching modes as no tags were defined'); } - if (is_null($this->_tagged) && $tagged = $this->getInnerCache()->load(self::INNER_CACHE_NAME)) { + if ($this->_tagged === null && $tagged = $this->getInnerCache()->load(self::INNER_CACHE_NAME)) { $this->_tagged = $tagged; } elseif (!$this->_tagged) { return true; @@ -412,11 +405,11 @@ class Zend_Cache_Backend_Static $result = true; break; case Zend_Cache::CLEANING_MODE_ALL: - if (is_null($this->_tagged)) { + if ($this->_tagged === null) { $tagged = $this->getInnerCache()->load(self::INNER_CACHE_NAME); $this->_tagged = $tagged; } - if (is_null($this->_tagged) || empty($this->_tagged)) { + if ($this->_tagged === null || empty($this->_tagged)) { return true; } $urls = array_keys($this->_tagged); @@ -434,11 +427,11 @@ class Zend_Cache_Backend_Static if (empty($tags)) { throw new Zend_Exception('Cannot use tag matching modes as no tags were defined'); } - if (is_null($this->_tagged)) { + if ($this->_tagged === null) { $tagged = $this->getInnerCache()->load(self::INNER_CACHE_NAME); $this->_tagged = $tagged; } - if (is_null($this->_tagged) || empty($this->_tagged)) { + if ($this->_tagged === null || empty($this->_tagged)) { return true; } $urls = array_keys($this->_tagged); @@ -481,7 +474,7 @@ class Zend_Cache_Backend_Static */ public function getInnerCache() { - if (is_null($this->_tagCache)) { + if ($this->_tagCache === null) { Zend_Cache::throwException('An Inner Cache has not been set; use setInnerCache()'); } return $this->_tagCache; @@ -550,7 +543,7 @@ class Zend_Cache_Backend_Static */ protected function _octdec($val) { - if (decoct(octdec($val)) == $val && is_string($val)) { + if (is_string($val) && decoct(octdec($val)) == $val) { return octdec($val); } return $val; diff --git a/libs/Zend/Cache/Backend/Test.php b/libs/Zend/Cache/Backend/Test.php index 2061ab84bb..19bf93b080 100644 --- a/libs/Zend/Cache/Backend/Test.php +++ b/libs/Zend/Cache/Backend/Test.php @@ -17,7 +17,7 @@ * @subpackage Zend_Cache_Backend * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Test.php 22504 2010-06-30 17:05:07Z mabe $ + * @version $Id: Test.php 23051 2010-10-07 17:01:21Z mabe $ */ @@ -109,7 +109,8 @@ class Zend_Cache_Backend_Test extends Zend_Cache_Backend implements Zend_Cache_B || $id == 'e83249ea22178277d5befc2c5e2e9ace' || $id == '40f649b94977c0a6e76902e2a0b43587' || $id == '88161989b73a4cbfd0b701c446115a99' - || $id == '205fc79cba24f0f0018eb92c7c8b3ba4') + || $id == '205fc79cba24f0f0018eb92c7c8b3ba4' + || $id == '170720e35f38150b811f68a937fb042d') { return false; } diff --git a/libs/Zend/Cache/Backend/TwoLevels.php b/libs/Zend/Cache/Backend/TwoLevels.php index 92330cb268..f9b43d974d 100644 --- a/libs/Zend/Cache/Backend/TwoLevels.php +++ b/libs/Zend/Cache/Backend/TwoLevels.php @@ -17,7 +17,7 @@ * @subpackage Zend_Cache_Backend * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: TwoLevels.php 22506 2010-06-30 17:23:21Z mabe $ + * @version $Id: TwoLevels.php 22736 2010-07-30 16:25:54Z andyfowler $ */ @@ -201,6 +201,11 @@ class Zend_Cache_Backend_TwoLevels extends Zend_Cache_Backend implements Zend_Ca $boolSlow = $this->_slowBackend->save($preparedData, $id, $tags, $lifetime); if ($boolSlow === true) { $boolFast = $this->_fastBackend->remove($id); + if (!$boolFast && !$this->_fastBackend->test($id)) { + // some backends return false on remove() even if the key never existed. (and it won't if fast is full) + // all we care about is that the key doesn't exist now + $boolFast = true; + } } } diff --git a/libs/Zend/Cache/Backend/Xcache.php b/libs/Zend/Cache/Backend/Xcache.php index ccd9672ca6..922f214b0b 100644 --- a/libs/Zend/Cache/Backend/Xcache.php +++ b/libs/Zend/Cache/Backend/Xcache.php @@ -17,7 +17,7 @@ * @subpackage Zend_Cache_Backend * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Xcache.php 20096 2010-01-06 02:05:09Z bkarwin $ + * @version $Id: Xcache.php 23345 2010-11-15 16:31:14Z mabe $ */ @@ -182,7 +182,12 @@ class Zend_Cache_Backend_Xcache extends Zend_Cache_Backend implements Zend_Cache if ($this->_options['password']) { $_SERVER['PHP_AUTH_PW'] = $this->_options['password']; } - xcache_clear_cache(XC_TYPE_VAR, 0); + + $cnt = xcache_count(XC_TYPE_VAR); + for ($i=0; $i < $cnt; $i++) { + xcache_clear_cache(XC_TYPE_VAR, $i); + } + if (isset($backup['PHP_AUTH_USER'])) { $_SERVER['PHP_AUTH_USER'] = $backup['PHP_AUTH_USER']; $_SERVER['PHP_AUTH_PW'] = $backup['PHP_AUTH_PW']; diff --git a/libs/Zend/Cache/Core.php b/libs/Zend/Cache/Core.php index 6906907d66..5c2b905622 100644 --- a/libs/Zend/Cache/Core.php +++ b/libs/Zend/Cache/Core.php @@ -16,7 +16,7 @@ * @package Zend_Cache * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Core.php 22652 2010-07-21 04:30:24Z ramon $ + * @version $Id: Core.php 22651 2010-07-21 04:19:44Z ramon $ */ diff --git a/libs/Zend/Cache/Frontend/Capture.php b/libs/Zend/Cache/Frontend/Capture.php index 8536c5ffb5..ee20a294e8 100644 --- a/libs/Zend/Cache/Frontend/Capture.php +++ b/libs/Zend/Cache/Frontend/Capture.php @@ -17,6 +17,7 @@ * @subpackage Zend_Cache_Frontend * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License + * @version $Id: Capture.php 23484 2010-12-10 03:57:59Z mjh_ca $ */ @@ -45,7 +46,7 @@ class Zend_Cache_Frontend_Capture extends Zend_Cache_Core * @var array */ protected $_tags = array(); - + protected $_extension = null; /** @@ -74,7 +75,7 @@ class Zend_Cache_Frontend_Capture extends Zend_Cache_Core public function _flush($data) { $id = array_pop($this->_idStack); - if (is_null($id)) { + if ($id === null) { Zend_Cache::throwException('use of _flush() without a start()'); } if ($this->_extension) { diff --git a/libs/Zend/Cache/Frontend/Class.php b/libs/Zend/Cache/Frontend/Class.php index cfeffc4e23..d496087ee2 100644 --- a/libs/Zend/Cache/Frontend/Class.php +++ b/libs/Zend/Cache/Frontend/Class.php @@ -17,7 +17,7 @@ * @subpackage Zend_Cache_Frontend * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Class.php 22654 2010-07-22 18:44:13Z mabe $ + * @version $Id: Class.php 23051 2010-10-07 17:01:21Z mabe $ */ /** @@ -218,11 +218,16 @@ class Zend_Cache_Frontend_Class extends Zend_Cache_Core // A cache is not available (or not valid for this frontend) ob_start(); ob_implicit_flush(false); - $return = call_user_func_array(array($this->_cachedEntity, $name), $parameters); - $output = ob_get_contents(); - ob_end_clean(); - $data = array($output, $return); - $this->save($data, $id, $this->_tags, $this->_specificLifetime, $this->_priority); + + try { + $return = call_user_func_array(array($this->_cachedEntity, $name), $parameters); + $output = ob_get_clean(); + $data = array($output, $return); + $this->save($data, $id, $this->_tags, $this->_specificLifetime, $this->_priority); + } catch (Exception $e) { + ob_end_clean(); + throw $e; + } } echo $output; diff --git a/libs/Zend/Cache/Frontend/File.php b/libs/Zend/Cache/Frontend/File.php index 2cbfe74d0c..4113b5f7fb 100644 --- a/libs/Zend/Cache/Frontend/File.php +++ b/libs/Zend/Cache/Frontend/File.php @@ -17,7 +17,7 @@ * @subpackage Zend_Cache_Frontend * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: File.php 20096 2010-01-06 02:05:09Z bkarwin $ + * @version $Id: File.php 23330 2010-11-14 20:08:09Z mabe $ */ @@ -97,22 +97,31 @@ class Zend_Cache_Frontend_File extends Zend_Cache_Core } /** - * Change the master_file option + * Change the master_files option * - * @param string $masterFile the complete path and name of the master file + * @param array $masterFiles the complete paths and name of the master files */ - public function setMasterFiles($masterFiles) + public function setMasterFiles(array $masterFiles) { - clearstatcache(); - $this->_specificOptions['master_file'] = $masterFiles[0]; // to keep a compatibility - $this->_specificOptions['master_files'] = $masterFiles; + $this->_specificOptions['master_file'] = null; // to keep a compatibility + $this->_specificOptions['master_files'] = null; $this->_masterFile_mtimes = array(); + + clearstatcache(); $i = 0; foreach ($masterFiles as $masterFile) { - $this->_masterFile_mtimes[$i] = @filemtime($masterFile); - if ((!($this->_specificOptions['ignore_missing_master_files'])) && (!($this->_masterFile_mtimes[$i]))) { - Zend_Cache::throwException('Unable to read master_file : '.$masterFile); + $mtime = @filemtime($masterFile); + + if (!$this->_specificOptions['ignore_missing_master_files'] && !$mtime) { + Zend_Cache::throwException('Unable to read master_file : ' . $masterFile); + } + + $this->_masterFile_mtimes[$i] = $mtime; + $this->_specificOptions['master_files'][$i] = $masterFile; + if ($i === 0) { // to keep a compatibility + $this->_specificOptions['master_files'] = $masterFile; } + $i++; } } @@ -127,7 +136,7 @@ class Zend_Cache_Frontend_File extends Zend_Cache_Core */ public function setMasterFile($masterFile) { - $this->setMasterFiles(array(0 => $masterFile)); + $this->setMasterFiles(array($masterFile)); } /** diff --git a/libs/Zend/Cache/Frontend/Function.php b/libs/Zend/Cache/Frontend/Function.php index a5a884c2ce..88617748cb 100644 --- a/libs/Zend/Cache/Frontend/Function.php +++ b/libs/Zend/Cache/Frontend/Function.php @@ -17,7 +17,7 @@ * @subpackage Zend_Cache_Frontend * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Function.php 22654 2010-07-22 18:44:13Z mabe $ + * @version $Id: Function.php 22648 2010-07-20 14:43:27Z mabe $ */ diff --git a/libs/Zend/Cache/Manager.php b/libs/Zend/Cache/Manager.php index 504cced8b8..d1b53e284e 100644 --- a/libs/Zend/Cache/Manager.php +++ b/libs/Zend/Cache/Manager.php @@ -16,7 +16,7 @@ * @package Zend_Cache * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id$ + * @version $Id: Manager.php 22727 2010-07-30 12:36:00Z mabe $ */ /** @see Zend_Cache_Exception */ diff --git a/libs/Zend/Config/Ini.php b/libs/Zend/Config/Ini.php index 63cab0f9a4..d3938be8fa 100644 --- a/libs/Zend/Config/Ini.php +++ b/libs/Zend/Config/Ini.php @@ -16,7 +16,7 @@ * @package Zend_Config * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Ini.php 20096 2010-01-06 02:05:09Z bkarwin $ + * @version $Id: Ini.php 23484 2010-12-10 03:57:59Z mjh_ca $ */ @@ -157,11 +157,11 @@ class Zend_Config_Ini extends Zend_Config $this->_loadedSection = $section; } - + /** * Load the INI file from disk using parse_ini_file(). Use a private error * handler to convert any loading errors into a Zend_Config_Exception - * + * * @param string $filename * @throws Zend_Config_Exception * @return array @@ -171,7 +171,7 @@ class Zend_Config_Ini extends Zend_Config set_error_handler(array($this, '_loadFileErrorHandler')); $iniArray = parse_ini_file($filename, true); // Warnings and errors are suppressed restore_error_handler(); - + // Check if there was a error while loading file if ($this->_loadFileErrorStr !== null) { /** @@ -180,7 +180,7 @@ class Zend_Config_Ini extends Zend_Config // require_once 'Zend/Config/Exception.php'; throw new Zend_Config_Exception($this->_loadFileErrorStr); } - + return $iniArray; } diff --git a/libs/Zend/Config/Json.php b/libs/Zend/Config/Json.php new file mode 100755 index 0000000000..b80a95becd --- /dev/null +++ b/libs/Zend/Config/Json.php @@ -0,0 +1,240 @@ +<?php +/** + * Zend Framework + * + * LICENSE + * + * This source file is subject to the new BSD license that is bundled + * with this package in the file LICENSE.txt. + * It is also available through the world-wide-web at this URL: + * http://framework.zend.com/license/new-bsd + * If you did not receive a copy of the license and are unable to + * obtain it through the world-wide-web, please send an email + * to license@zend.com so we can send you a copy immediately. + * + * @category Zend + * @package Zend_Config + * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + * @version $Id: Json.php 23294 2010-11-05 00:27:34Z ramon $ + */ + +/** + * @see Zend_Config + */ +// require_once 'Zend/Config.php'; + +/** + * @see Zend_Json + */ +// require_once 'Zend/Json.php'; + +/** + * JSON Adapter for Zend_Config + * + * @category Zend + * @package Zend_Config + * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ +class Zend_Config_Json extends Zend_Config +{ + /** + * Name of object key indicating section current section extends + */ + const EXTENDS_NAME = "_extends"; + + /** + * Whether or not to ignore constants in the JSON string + * + * Note: if you do not have constant names in quotations in your JSON + * string, they may lead to syntax errors when parsing. + * + * @var bool + */ + protected $_ignoreConstants = false; + + /** + * Whether to skip extends or not + * + * @var boolean + */ + protected $_skipExtends = false; + + /** + * Loads the section $section from the config file encoded as JSON + * + * Sections are defined as properties of the main object + * + * In order to extend another section, a section defines the "_extends" + * property having a value of the section name from which the extending + * section inherits values. + * + * Note that the keys in $section will override any keys of the same + * name in the sections that have been included via "_extends". + * + * @param string $json JSON file or string to process + * @param mixed $section Section to process + * @param boolean $options Whether modifiacations are allowed at runtime + * @throws Zend_Config_Exception When JSON text is not set or cannot be loaded + * @throws Zend_Config_Exception When section $sectionName cannot be found in $json + */ + public function __construct($json, $section = null, $options = false) + { + if (empty($json)) { + // require_once 'Zend/Config/Exception.php'; + throw new Zend_Config_Exception('Filename is not set'); + } + + $allowModifications = false; + if (is_bool($options)) { + $allowModifications = $options; + } elseif (is_array($options)) { + foreach ($options as $key => $value) { + switch (strtolower($key)) { + case 'allow_modifications': + case 'allowmodifications': + $allowModifications = (bool) $value; + break; + case 'skip_extends': + case 'skipextends': + $this->_skipExtends = (bool) $value; + break; + case 'ignore_constants': + case 'ignoreconstants': + $this->_ignoreConstants = (bool) $value; + break; + default: + break; + } + } + } + + set_error_handler(array($this, '_loadFileErrorHandler')); // Warnings and errors are suppressed + if ($json[0] != '{') { + $json = file_get_contents($json); + } + restore_error_handler(); + + // Check if there was a error while loading file + if ($this->_loadFileErrorStr !== null) { + // require_once 'Zend/Config/Exception.php'; + throw new Zend_Config_Exception($this->_loadFileErrorStr); + } + + // Replace constants + if (!$this->_ignoreConstants) { + $json = $this->_replaceConstants($json); + } + + // Parse/decode + $config = Zend_Json::decode($json); + + if (null === $config) { + // decode failed + // require_once 'Zend/Config/Exception.php'; + throw new Zend_Config_Exception("Error parsing JSON data"); + } + + if ($section === null) { + $dataArray = array(); + foreach ($config as $sectionName => $sectionData) { + $dataArray[$sectionName] = $this->_processExtends($config, $sectionName); + } + + parent::__construct($dataArray, $allowModifications); + } elseif (is_array($section)) { + $dataArray = array(); + foreach ($section as $sectionName) { + if (!isset($config[$sectionName])) { + // require_once 'Zend/Config/Exception.php'; + throw new Zend_Config_Exception(sprintf('Section "%s" cannot be found', $sectionName)); + } + + $dataArray = array_merge($this->_processExtends($config, $sectionName), $dataArray); + } + + parent::__construct($dataArray, $allowModifications); + } else { + if (!isset($config[$section])) { + // require_once 'Zend/Config/Exception.php'; + throw new Zend_Config_Exception(sprintf('Section "%s" cannot be found', $section)); + } + + $dataArray = $this->_processExtends($config, $section); + if (!is_array($dataArray)) { + // Section in the JSON data contains just one top level string + $dataArray = array($section => $dataArray); + } + + parent::__construct($dataArray, $allowModifications); + } + + $this->_loadedSection = $section; + } + + /** + * Helper function to process each element in the section and handle + * the "_extends" inheritance attribute. + * + * @param array $data Data array to process + * @param string $section Section to process + * @param array $config Configuration which was parsed yet + * @throws Zend_Config_Exception When $section cannot be found + * @return array + */ + protected function _processExtends(array $data, $section, array $config = array()) + { + if (!isset($data[$section])) { + // require_once 'Zend/Config/Exception.php'; + throw new Zend_Config_Exception(sprintf('Section "%s" cannot be found', $section)); + } + + $thisSection = $data[$section]; + + if (is_array($thisSection) && isset($thisSection[self::EXTENDS_NAME])) { + if (is_array($thisSection[self::EXTENDS_NAME])) { + // require_once 'Zend/Config/Exception.php'; + throw new Zend_Config_Exception('Invalid extends clause: must be a string; array received'); + } + $this->_assertValidExtend($section, $thisSection[self::EXTENDS_NAME]); + + if (!$this->_skipExtends) { + $config = $this->_processExtends($data, $thisSection[self::EXTENDS_NAME], $config); + } + unset($thisSection[self::EXTENDS_NAME]); + } + + $config = $this->_arrayMergeRecursive($config, $thisSection); + + return $config; + } + + /** + * Replace any constants referenced in a string with their values + * + * @param string $value + * @return string + */ + protected function _replaceConstants($value) + { + foreach ($this->_getConstants() as $constant) { + if (strstr($value, $constant)) { + $value = str_replace($constant, constant($constant), $value); + } + } + return $value; + } + + /** + * Get (reverse) sorted list of defined constant names + * + * @return array + */ + protected function _getConstants() + { + $constants = array_keys(get_defined_constants()); + rsort($constants, SORT_STRING); + return $constants; + } +} diff --git a/libs/Zend/Config/Writer/Ini.php b/libs/Zend/Config/Writer/Ini.php index 163c95e216..28a7ce8ab4 100644 --- a/libs/Zend/Config/Writer/Ini.php +++ b/libs/Zend/Config/Writer/Ini.php @@ -16,7 +16,7 @@ * @package Zend_Config * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Ini.php 20096 2010-01-06 02:05:09Z bkarwin $ + * @version $Id: Ini.php 23484 2010-12-10 03:57:59Z mjh_ca $ */ /** @@ -93,7 +93,8 @@ class Zend_Config_Writer_Ini extends Zend_Config_Writer_FileAbstract . $this->_addBranch($this->_config) . "\n"; } else { - foreach ($this->_config as $sectionName => $data) { + $config = $this->_sortRootElements($this->_config); + foreach ($config as $sectionName => $data) { if (!($data instanceof Zend_Config)) { $iniString .= $sectionName . ' = ' @@ -160,4 +161,33 @@ class Zend_Config_Writer_Ini extends Zend_Config_Writer_FileAbstract throw new Zend_Config_Exception('Value can not contain double quotes "'); } } + + /** + * Root elements that are not assigned to any section needs to be + * on the top of config. + * + * @see http://framework.zend.com/issues/browse/ZF-6289 + * @param Zend_Config + * @return Zend_Config + */ + protected function _sortRootElements(Zend_Config $config) + { + $configArray = $config->toArray(); + $sections = array(); + + // remove sections from config array + foreach ($configArray as $key => $value) { + if (is_array($value)) { + $sections[$key] = $value; + unset($configArray[$key]); + } + } + + // readd sections to the end + foreach ($sections as $key => $value) { + $configArray[$key] = $value; + } + + return new Zend_Config($configArray); + } } diff --git a/libs/Zend/Config/Writer/Json.php b/libs/Zend/Config/Writer/Json.php new file mode 100755 index 0000000000..5140749f8d --- /dev/null +++ b/libs/Zend/Config/Writer/Json.php @@ -0,0 +1,106 @@ +<?php +/** + * Zend Framework + * + * LICENSE + * + * This source file is subject to the new BSD license that is bundled + * with this package in the file LICENSE.txt. + * It is also available through the world-wide-web at this URL: + * http://framework.zend.com/license/new-bsd + * If you did not receive a copy of the license and are unable to + * obtain it through the world-wide-web, please send an email + * to license@zend.com so we can send you a copy immediately. + * + * @category Zend + * @package Zend_Config + * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + * @version $Id: Json.php 23294 2010-11-05 00:27:34Z ramon $ + */ + +/** + * @see Zend_Config_Writer + */ +// require_once 'Zend/Config/Writer/FileAbstract.php'; + +/** + * @see Zend_Config_Json + */ +// require_once 'Zend/Config/Json.php'; + +/** + * @category Zend + * @package Zend_Config + * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ +class Zend_Config_Writer_Json extends Zend_Config_Writer_FileAbstract +{ + /** + * If we need to pretty-print JSON data + * + * @var boolean + */ + protected $_prettyPrint = false; + + /** + * Get prettyPrint flag + * + * @return the prettyPrint flag + */ + public function prettyPrint() + { + return $this->_prettyPrint; + } + + /** + * Set prettyPrint flag + * + * @param bool $prettyPrint PrettyPrint flag + * @return Zend_Config_Writer_Json + */ + public function setPrettyPrint($flag) + { + $this->_prettyPrint = (bool) $flag; + return $this; + } + + /** + * Render a Zend_Config into a JSON config string. + * + * @since 1.10 + * @return string + */ + public function render() + { + $data = $this->_config->toArray(); + $sectionName = $this->_config->getSectionName(); + $extends = $this->_config->getExtends(); + + if (is_string($sectionName)) { + $data = array($sectionName => $data); + } + + foreach ($extends as $section => $parentSection) { + $data[$section][Zend_Config_Json::EXTENDS_NAME] = $parentSection; + } + + // Ensure that each "extends" section actually exists + foreach ($data as $section => $sectionData) { + if (is_array($sectionData) && isset($sectionData[Zend_Config_Json::EXTENDS_NAME])) { + $sectionExtends = $sectionData[Zend_Config_Json::EXTENDS_NAME]; + if (!isset($data[$sectionExtends])) { + // Remove "extends" declaration if section does not exist + unset($data[$section][Zend_Config_Json::EXTENDS_NAME]); + } + } + } + + $out = Zend_Json::encode($data); + if ($this->prettyPrint()) { + $out = Zend_Json::prettyPrint($out); + } + return $out; + } +} diff --git a/libs/Zend/Config/Writer/Yaml.php b/libs/Zend/Config/Writer/Yaml.php new file mode 100755 index 0000000000..2cacd35100 --- /dev/null +++ b/libs/Zend/Config/Writer/Yaml.php @@ -0,0 +1,144 @@ +<?php +/** + * Zend Framework + * + * LICENSE + * + * This source file is subject to the new BSD license that is bundled + * with this package in the file LICENSE.txt. + * It is also available through the world-wide-web at this URL: + * http://framework.zend.com/license/new-bsd + * If you did not receive a copy of the license and are unable to + * obtain it through the world-wide-web, please send an email + * to license@zend.com so we can send you a copy immediately. + * + * @category Zend + * @package Zend_Config + * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + * @version $Id: Yaml.php 23294 2010-11-05 00:27:34Z ramon $ + */ + +/** + * @see Zend_Config_Writer + */ +// require_once 'Zend/Config/Writer/FileAbstract.php'; + +/** + * @see Zend_Config_Yaml + */ +// require_once 'Zend/Config/Yaml.php'; + +/** + * @category Zend + * @package Zend_Config + * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ +class Zend_Config_Writer_Yaml extends Zend_Config_Writer_FileAbstract +{ + /** + * What to call when we need to decode some YAML? + * + * @var callable + */ + protected $_yamlEncoder = array('Zend_Config_Writer_Yaml', 'encode'); + + /** + * Get callback for decoding YAML + * + * @return callable + */ + public function getYamlEncoder() + { + return $this->_yamlEncoder; + } + + /** + * Set callback for decoding YAML + * + * @param $yamlEncoder the decoder to set + * @return Zend_Config_Yaml + */ + public function setYamlEncoder($yamlEncoder) + { + if (!is_callable($yamlEncoder)) { + // require_once 'Zend/Config/Exception.php'; + throw new Zend_Config_Exception('Invalid parameter to setYamlEncoder - must be callable'); + } + + $this->_yamlEncoder = $yamlEncoder; + return $this; + } + + /** + * Render a Zend_Config into a YAML config string. + * + * @since 1.10 + * @return string + */ + public function render() + { + $data = $this->_config->toArray(); + $sectionName = $this->_config->getSectionName(); + $extends = $this->_config->getExtends(); + + if (is_string($sectionName)) { + $data = array($sectionName => $data); + } + + foreach ($extends as $section => $parentSection) { + $data[$section][Zend_Config_Yaml::EXTENDS_NAME] = $parentSection; + } + + // Ensure that each "extends" section actually exists + foreach ($data as $section => $sectionData) { + if (is_array($sectionData) && isset($sectionData[Zend_Config_Yaml::EXTENDS_NAME])) { + $sectionExtends = $sectionData[Zend_Config_Yaml::EXTENDS_NAME]; + if (!isset($data[$sectionExtends])) { + // Remove "extends" declaration if section does not exist + unset($data[$section][Zend_Config_Yaml::EXTENDS_NAME]); + } + } + } + + return call_user_func($this->getYamlEncoder(), $data); + } + + /** + * Very dumb YAML encoder + * + * Until we have Zend_Yaml... + * + * @param array $data YAML data + * @return string + */ + public static function encode($data) + { + return self::_encodeYaml(0, $data); + } + + /** + * Service function for encoding YAML + * + * @param int $indent Current indent level + * @param array $data Data to encode + * @return string + */ + protected static function _encodeYaml($indent, $data) + { + reset($data); + $result = ""; + $numeric = is_numeric(key($data)); + + foreach($data as $key => $value) { + if(is_array($value)) { + $encoded = "\n".self::_encodeYaml($indent+1, $value); + } else { + $encoded = (string)$value."\n"; + } + $result .= str_repeat(" ", $indent).($numeric?"- ":"$key: ").$encoded; + } + return $result; + } +} diff --git a/libs/Zend/Config/Yaml.php b/libs/Zend/Config/Yaml.php new file mode 100755 index 0000000000..7e930564b2 --- /dev/null +++ b/libs/Zend/Config/Yaml.php @@ -0,0 +1,382 @@ +<?php +/** + * Zend Framework + * + * LICENSE + * + * This source file is subject to the new BSD license that is bundled + * with this package in the file LICENSE.txt. + * It is also available through the world-wide-web at this URL: + * http://framework.zend.com/license/new-bsd + * If you did not receive a copy of the license and are unable to + * obtain it through the world-wide-web, please send an email + * to license@zend.com so we can send you a copy immediately. + * + * @category Zend + * @package Zend_Config + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + * @version $Id: Yaml.php 23294 2010-11-05 00:27:34Z ramon $ + */ + +/** + * @see Zend_Config + */ +// require_once 'Zend/Config.php'; + +/** + * YAML Adapter for Zend_Config + * + * @category Zend + * @package Zend_Config + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ +class Zend_Config_Yaml extends Zend_Config +{ + /** + * Attribute name that indicates what section a config extends from + */ + const EXTENDS_NAME = "_extends"; + + /** + * Whether to skip extends or not + * + * @var boolean + */ + protected $_skipExtends = false; + + /** + * What to call when we need to decode some YAML? + * + * @var callable + */ + protected $_yamlDecoder = array(__CLASS__, 'decode'); + + /** + * Whether or not to ignore constants in parsed YAML + * @var bool + */ + protected static $_ignoreConstants = false; + + /** + * Indicate whether parser should ignore constants or not + * + * @param bool $flag + * @return void + */ + public static function setIgnoreConstants($flag) + { + self::$_ignoreConstants = (bool) $flag; + } + + /** + * Whether parser should ignore constants or not + * + * @return bool + */ + public static function ignoreConstants() + { + return self::$_ignoreConstants; + } + + /** + * Get callback for decoding YAML + * + * @return callable + */ + public function getYamlDecoder() + { + return $this->_yamlDecoder; + } + + /** + * Set callback for decoding YAML + * + * @param $yamlDecoder the decoder to set + * @return Zend_Config_Yaml + */ + public function setYamlDecoder($yamlDecoder) + { + if (!is_callable($yamlDecoder)) { + // require_once 'Zend/Config/Exception.php'; + throw new Zend_Config_Exception('Invalid parameter to setYamlDecoder() - must be callable'); + } + + $this->_yamlDecoder = $yamlDecoder; + return $this; + } + + /** + * Loads the section $section from the config file encoded as YAML + * + * Sections are defined as properties of the main object + * + * In order to extend another section, a section defines the "_extends" + * property having a value of the section name from which the extending + * section inherits values. + * + * Note that the keys in $section will override any keys of the same + * name in the sections that have been included via "_extends". + * + * Options may include: + * - allow_modifications: whether or not the config object is mutable + * - skip_extends: whether or not to skip processing of parent configuration + * - yaml_decoder: a callback to use to decode the Yaml source + * + * @param string $yaml YAML file to process + * @param mixed $section Section to process + * @param boolean $options Whether modifiacations are allowed at runtime + */ + public function __construct($yaml, $section = null, $options = false) + { + if (empty($yaml)) { + // require_once 'Zend/Config/Exception.php'; + throw new Zend_Config_Exception('Filename is not set'); + } + + $ignoreConstants = $staticIgnoreConstants = self::ignoreConstants(); + $allowModifications = false; + if (is_bool($options)) { + $allowModifications = $options; + } elseif (is_array($options)) { + foreach ($options as $key => $value) { + switch (strtolower($key)) { + case 'allow_modifications': + case 'allowmodifications': + $allowModifications = (bool) $value; + break; + case 'skip_extends': + case 'skipextends': + $this->_skipExtends = (bool) $value; + break; + case 'ignore_constants': + case 'ignoreconstants': + $ignoreConstants = (bool) $value; + break; + case 'yaml_decoder': + case 'yamldecoder': + $this->setYamlDecoder($value); + break; + default: + break; + } + } + } + + // Suppress warnings and errors while loading file + set_error_handler(array($this, '_loadFileErrorHandler')); + $yaml = file_get_contents($yaml); + restore_error_handler(); + + // Check if there was a error while loading file + if ($this->_loadFileErrorStr !== null) { + // require_once 'Zend/Config/Exception.php'; + throw new Zend_Config_Exception($this->_loadFileErrorStr); + } + + // Override static value for ignore_constants if provided in $options + self::setIgnoreConstants($ignoreConstants); + + // Parse YAML + $config = call_user_func($this->getYamlDecoder(), $yaml); + + // Reset original static state of ignore_constants + self::setIgnoreConstants($staticIgnoreConstants); + + if (null === $config) { + // decode failed + // require_once 'Zend/Config/Exception.php'; + throw new Zend_Config_Exception("Error parsing YAML data"); + } + + if (null === $section) { + $dataArray = array(); + foreach ($config as $sectionName => $sectionData) { + $dataArray[$sectionName] = $this->_processExtends($config, $sectionName); + } + parent::__construct($dataArray, $allowModifications); + } elseif (is_array($section)) { + $dataArray = array(); + foreach ($section as $sectionName) { + if (!isset($config[$sectionName])) { + // require_once 'Zend/Config/Exception.php'; + throw new Zend_Config_Exception(sprintf('Section "%s" cannot be found', $section)); + } + + $dataArray = array_merge($this->_processExtends($config, $sectionName), $dataArray); + } + parent::__construct($dataArray, $allowModifications); + } else { + if (!isset($config[$section])) { + // require_once 'Zend/Config/Exception.php'; + throw new Zend_Config_Exception(sprintf('Section "%s" cannot be found', $section)); + } + + $dataArray = $this->_processExtends($config, $section); + if (!is_array($dataArray)) { + // Section in the yaml data contains just one top level string + $dataArray = array($section => $dataArray); + } + parent::__construct($dataArray, $allowModifications); + } + + $this->_loadedSection = $section; + } + + /** + * Helper function to process each element in the section and handle + * the "_extends" inheritance attribute. + * + * @param array $data Data array to process + * @param string $section Section to process + * @param array $config Configuration which was parsed yet + * @return array + * @throws Zend_Config_Exception When $section cannot be found + */ + protected function _processExtends(array $data, $section, array $config = array()) + { + if (!isset($data[$section])) { + // require_once 'Zend/Config/Exception.php'; + throw new Zend_Config_Exception(sprintf('Section "%s" cannot be found', $section)); + } + + $thisSection = $data[$section]; + + if (is_array($thisSection) && isset($thisSection[self::EXTENDS_NAME])) { + $this->_assertValidExtend($section, $thisSection[self::EXTENDS_NAME]); + + if (!$this->_skipExtends) { + $config = $this->_processExtends($data, $thisSection[self::EXTENDS_NAME], $config); + } + unset($thisSection[self::EXTENDS_NAME]); + } + + $config = $this->_arrayMergeRecursive($config, $thisSection); + + return $config; + } + + /** + * Very dumb YAML parser + * + * Until we have Zend_Yaml... + * + * @param string $yaml YAML source + * @return array Decoded data + */ + public static function decode($yaml) + { + $lines = explode("\n", $yaml); + reset($lines); + return self::_decodeYaml(0, $lines); + } + + /** + * Service function to decode YAML + * + * @param int $currentIndent Current indent level + * @param array $lines YAML lines + * @return array|string + */ + protected static function _decodeYaml($currentIndent, &$lines) + { + $config = array(); + $inIndent = false; + while (list($n, $line) = each($lines)) { + $lineno = $n+1; + if (strlen($line) == 0) { + continue; + } + if ($line[0] == '#') { + // comment + continue; + } + $indent = strspn($line, " "); + + // line without the spaces + $line = trim($line); + if (strlen($line) == 0) { + continue; + } + + if ($indent < $currentIndent) { + // this level is done + prev($lines); + return $config; + } + + if (!$inIndent) { + $currentIndent = $indent; + $inIndent = true; + } + + if (preg_match("/(\w+):\s*(.*)/", $line, $m)) { + // key: value + if ($m[2]) { + // simple key: value + $value = $m[2]; + // Check for booleans and constants + if (preg_match('/^(t(rue)?|on|y(es)?)$/i', $value)) { + $value = true; + } elseif (preg_match('/^(f(alse)?|off|n(o)?)$/i', $value)) { + $value = false; + } elseif (!self::$_ignoreConstants) { + // test for constants + $value = self::_replaceConstants($value); + } + } else { + // key: and then values on new lines + $value = self::_decodeYaml($currentIndent + 1, $lines); + if (is_array($value) && !count($value)) { + $value = ""; + } + } + $config[$m[1]] = $value; + } elseif ($line[0] == "-") { + // item in the list: + // - FOO + if (strlen($line) > 2) { + $config[] = substr($line, 2); + } else { + $config[] = self::_decodeYaml($currentIndent + 1, $lines); + } + } else { + // require_once 'Zend/Config/Exception.php'; + throw new Zend_Config_Exception(sprintf( + 'Error parsing YAML at line %d - unsupported syntax: "%s"', + $lineno, $line + )); + } + } + return $config; + } + + /** + * Replace any constants referenced in a string with their values + * + * @param string $value + * @return string + */ + protected static function _replaceConstants($value) + { + foreach (self::_getConstants() as $constant) { + if (strstr($value, $constant)) { + $value = str_replace($constant, constant($constant), $value); + } + } + return $value; + } + + /** + * Get (reverse) sorted list of defined constant names + * + * @return array + */ + protected static function _getConstants() + { + $constants = array_keys(get_defined_constants()); + rsort($constants, SORT_STRING); + return $constants; + } +} diff --git a/libs/Zend/Db.php b/libs/Zend/Db.php index d235a5461d..388c8012b8 100644 --- a/libs/Zend/Db.php +++ b/libs/Zend/Db.php @@ -17,7 +17,7 @@ * @package Zend_Db * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Db.php 20096 2010-01-06 02:05:09Z bkarwin $ + * @version $Id: Db.php 23405 2010-11-19 19:46:10Z bittarman $ */ @@ -43,6 +43,11 @@ class Zend_Db const CASE_FOLDING = 'caseFolding'; /** + * Use the FETCH_MODE constant in the config of a Zend_Db_Adapter. + */ + const FETCH_MODE = 'fetchMode'; + + /** * Use the AUTO_QUOTE_IDENTIFIERS constant in the config of a Zend_Db_Adapter. */ const AUTO_QUOTE_IDENTIFIERS = 'autoQuoteIdentifiers'; @@ -85,9 +90,6 @@ class Zend_Db * 'NULL_TO_STRING', 'ERR_NONE', 'FETCH_ORI_NEXT', * 'FETCH_ORI_PRIOR', 'FETCH_ORI_FIRST', 'FETCH_ORI_LAST', * 'FETCH_ORI_ABS', 'FETCH_ORI_REL', 'CURSOR_FWDONLY', 'CURSOR_SCROLL', - * 'ERR_CANT_MAP', 'ERR_SYNTAX', 'ERR_CONSTRAINT', 'ERR_NOT_FOUND', - * 'ERR_ALREADY_EXISTS', 'ERR_NOT_IMPLEMENTED', 'ERR_MISMATCH', - * 'ERR_TRUNCATED', 'ERR_DISCONNECTED', 'ERR_NO_PERM', * ); * * $const = array(); @@ -120,17 +122,7 @@ class Zend_Db const CASE_UPPER = 1; const CURSOR_FWDONLY = 0; const CURSOR_SCROLL = 1; - const ERR_ALREADY_EXISTS = NULL; - const ERR_CANT_MAP = NULL; - const ERR_CONSTRAINT = NULL; - const ERR_DISCONNECTED = NULL; - const ERR_MISMATCH = NULL; - const ERR_NO_PERM = NULL; const ERR_NONE = '00000'; - const ERR_NOT_FOUND = NULL; - const ERR_NOT_IMPLEMENTED = NULL; - const ERR_SYNTAX = NULL; - const ERR_TRUNCATED = NULL; const ERRMODE_EXCEPTION = 2; const ERRMODE_SILENT = 0; const ERRMODE_WARNING = 1; diff --git a/libs/Zend/Db/Adapter/Abstract.php b/libs/Zend/Db/Adapter/Abstract.php index 55b77a60e1..a9f8f5c590 100644 --- a/libs/Zend/Db/Adapter/Abstract.php +++ b/libs/Zend/Db/Adapter/Abstract.php @@ -17,7 +17,7 @@ * @subpackage Adapter * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Abstract.php 20096 2010-01-06 02:05:09Z bkarwin $ + * @version $Id: Abstract.php 23252 2010-10-26 12:48:32Z matthew $ */ @@ -184,7 +184,8 @@ abstract class Zend_Db_Adapter_Abstract $options = array( Zend_Db::CASE_FOLDING => $this->_caseFolding, - Zend_Db::AUTO_QUOTE_IDENTIFIERS => $this->_autoQuoteIdentifiers + Zend_Db::AUTO_QUOTE_IDENTIFIERS => $this->_autoQuoteIdentifiers, + Zend_Db::FETCH_MODE => $this->_fetchMode, ); $driverOptions = array(); @@ -236,6 +237,16 @@ abstract class Zend_Db_Adapter_Abstract } } + if (array_key_exists(Zend_Db::FETCH_MODE, $options)) { + if (is_string($options[Zend_Db::FETCH_MODE])) { + $constant = 'Zend_Db::FETCH_' . strtoupper($options[Zend_Db::FETCH_MODE]); + if(defined($constant)) { + $options[Zend_Db::FETCH_MODE] = constant($constant); + } + } + $this->setFetchMode((int) $options[Zend_Db::FETCH_MODE]); + } + // obtain quoting property if there is one if (array_key_exists(Zend_Db::AUTO_QUOTE_IDENTIFIERS, $options)) { $this->_autoQuoteIdentifiers = (bool) $options[Zend_Db::AUTO_QUOTE_IDENTIFIERS]; @@ -526,13 +537,27 @@ abstract class Zend_Db_Adapter_Abstract // extract and quote col names from the array keys $cols = array(); $vals = array(); + $i = 0; foreach ($bind as $col => $val) { $cols[] = $this->quoteIdentifier($col, true); if ($val instanceof Zend_Db_Expr) { $vals[] = $val->__toString(); unset($bind[$col]); } else { - $vals[] = '?'; + if ($this->supportsParameters('positional')) { + $vals[] = '?'; + } else { + if ($this->supportsParameters('named')) { + unset($bind[$col]); + $bind[':col'.$i] = $val; + $vals[] = ':col'.$i; + $i++; + } else { + /** @see Zend_Db_Adapter_Exception */ + // require_once 'Zend/Db/Adapter/Exception.php'; + throw new Zend_Db_Adapter_Exception(get_class($this) ." doesn't support positional or named binding"); + } + } } } @@ -543,7 +568,10 @@ abstract class Zend_Db_Adapter_Abstract . 'VALUES (' . implode(', ', $vals) . ')'; // execute the statement and return the number of affected rows - $stmt = $this->query($sql, array_values($bind)); + if ($this->supportsParameters('positional')) { + $bind = array_values($bind); + } + $stmt = $this->query($sql, $bind); $result = $stmt->rowCount(); return $result; } @@ -574,8 +602,8 @@ abstract class Zend_Db_Adapter_Abstract } else { if ($this->supportsParameters('named')) { unset($bind[$col]); - $bind[':'.$col.$i] = $val; - $val = ':'.$col.$i; + $bind[':col'.$i] = $val; + $val = ':col'.$i; $i++; } else { /** @see Zend_Db_Adapter_Exception */ @@ -754,8 +782,6 @@ abstract class Zend_Db_Adapter_Abstract /** * Fetches the first column of all SQL result rows as an array. * - * The first column in each row is used as the array key. - * * @param string|Zend_Db_Select $sql An SQL SELECT statement. * @param mixed $bind Data to bind into SELECT placeholders. * @return array diff --git a/libs/Zend/Db/Adapter/Db2.php b/libs/Zend/Db/Adapter/Db2.php index 3fa4b4c618..801a34acaf 100644 --- a/libs/Zend/Db/Adapter/Db2.php +++ b/libs/Zend/Db/Adapter/Db2.php @@ -17,7 +17,7 @@ * @subpackage Adapter * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Db2.php 20096 2010-01-06 02:05:09Z bkarwin $ + * @version $Id: Db2.php 23484 2010-12-10 03:57:59Z mjh_ca $ * */ @@ -154,6 +154,14 @@ class Zend_Db_Adapter_Db2 extends Zend_Db_Adapter_Abstract $this->_config['driver_options']['DB2_ATTR_CASE'] = $caseAttrMap[$this->_config['options'][Zend_Db::CASE_FOLDING]]; } + if ($this->_isI5 && isset($this->_config['driver_options']['i5_naming'])) { + if ($this->_config['driver_options']['i5_naming']) { + $this->_config['driver_options']['i5_naming'] = DB2_I5_NAMING_ON; + } else { + $this->_config['driver_options']['i5_naming'] = DB2_I5_NAMING_OFF; + } + } + if ($this->_config['host'] !== 'localhost' && !$this->_isI5) { // if the host isn't localhost, use extended connection params $dbname = 'DRIVER={IBM DB2 ODBC DRIVER}' . @@ -411,7 +419,7 @@ class Zend_Db_Adapter_Db2 extends Zend_Db_Adapter_Abstract AND C.TABLE_NAME = k.TABLE_NAME AND C.COLUMN_NAME = k.COLUMN_NAME) WHERE " - . $this->quoteInto('UPPER(C.TABLE_NAME) = UPPER(?)', $tableName); + . $this->quoteInto('UPPER(C.TABLE_NAME) = UPPER(?)', $tableName); if ($schemaName) { $sql .= $this->quoteInto(' AND UPPER(C.TABLE_SCHEMA) = UPPER(?)', $schemaName); diff --git a/libs/Zend/Db/Adapter/Db2/Exception.php b/libs/Zend/Db/Adapter/Db2/Exception.php index 8104606d59..666761e6d7 100644 --- a/libs/Zend/Db/Adapter/Db2/Exception.php +++ b/libs/Zend/Db/Adapter/Db2/Exception.php @@ -17,7 +17,7 @@ * @subpackage Adapter * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Exception.php 20096 2010-01-06 02:05:09Z bkarwin $ + * @version $Id: Exception.php 23484 2010-12-10 03:57:59Z mjh_ca $ */ /** @@ -38,7 +38,7 @@ class Zend_Db_Adapter_Db2_Exception extends Zend_Db_Adapter_Exception protected $code = '00000'; protected $message = 'unknown exception'; - function __construct($message = 'unknown exception', $code = '00000', Exception $e = null) + function __construct($message = 'unknown exception', $code = '00000', Exception $e = null) { parent::__construct($message, $code, $e); } diff --git a/libs/Zend/Db/Adapter/Oracle.php b/libs/Zend/Db/Adapter/Oracle.php index b803878a64..2e0cc68080 100644 --- a/libs/Zend/Db/Adapter/Oracle.php +++ b/libs/Zend/Db/Adapter/Oracle.php @@ -17,7 +17,7 @@ * @subpackage Adapter * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Oracle.php 20096 2010-01-06 02:05:09Z bkarwin $ + * @version $Id: Oracle.php 23573 2010-12-23 18:20:00Z mikaelkael $ */ /** @@ -147,7 +147,8 @@ class Zend_Db_Adapter_Oracle extends Zend_Db_Adapter_Abstract public function isConnected() { return ((bool) (is_resource($this->_connection) - && get_resource_type($this->_connection) == 'oci8 connection')); + && (get_resource_type($this->_connection) == 'oci8 connection' + || get_resource_type($this->_connection) == 'oci8 persistent connection'))); } /** @@ -603,46 +604,6 @@ class Zend_Db_Adapter_Oracle extends Zend_Db_Adapter_Abstract } /** - * Inserts a table row with specified data. - * - * Oracle does not support anonymous ('?') binds. - * - * @param mixed $table The table to insert data into. - * @param array $bind Column-value pairs. - * @return int The number of affected rows. - */ - public function insert($table, array $bind) - { - $i = 0; - // extract and quote col names from the array keys - $cols = array(); - $vals = array(); - foreach ($bind as $col => $val) { - $cols[] = $this->quoteIdentifier($col, true); - if ($val instanceof Zend_Db_Expr) { - $vals[] = $val->__toString(); - unset($bind[$col]); - } else { - $vals[] = ':'.$col.$i; - unset($bind[$col]); - $bind[':'.$col.$i] = $val; - } - $i++; - } - - // build the statement - $sql = "INSERT INTO " - . $this->quoteIdentifier($table, true) - . ' (' . implode(', ', $cols) . ') ' - . 'VALUES (' . implode(', ', $vals) . ')'; - - // execute the statement and return the number of affected rows - $stmt = $this->query($sql, $bind); - $result = $stmt->rowCount(); - return $result; - } - - /** * Check if the adapter supports real SQL parameters. * * @param string $type 'positional' or 'named' diff --git a/libs/Zend/Db/Adapter/Pdo/Pgsql.php b/libs/Zend/Db/Adapter/Pdo/Pgsql.php index 3b48d5921a..b91dca47e4 100644 --- a/libs/Zend/Db/Adapter/Pdo/Pgsql.php +++ b/libs/Zend/Db/Adapter/Pdo/Pgsql.php @@ -17,7 +17,7 @@ * @subpackage Adapter * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Pgsql.php 22566 2010-07-16 02:07:36Z ramon $ + * @version $Id: Pgsql.php 22788 2010-08-03 18:29:55Z ramon $ */ @@ -281,7 +281,7 @@ class Zend_Db_Adapter_Pdo_Pgsql extends Zend_Db_Adapter_Pdo_Abstract public function lastSequenceId($sequenceName) { $this->_connect(); - $sequenceName = trim((string) $sequenceName, $this->getQuoteIdentifierSymbol()); + $sequenceName = str_replace($this->getQuoteIdentifierSymbol(), '', (string) $sequenceName); $value = $this->fetchOne("SELECT CURRVAL(" . $this->quote($this->quoteIdentifier($sequenceName, true)) . ")"); @@ -299,7 +299,7 @@ class Zend_Db_Adapter_Pdo_Pgsql extends Zend_Db_Adapter_Pdo_Abstract public function nextSequenceId($sequenceName) { $this->_connect(); - $sequenceName = trim((string) $sequenceName, $this->getQuoteIdentifierSymbol()); + $sequenceName = str_replace($this->getQuoteIdentifierSymbol(), '', (string) $sequenceName); $value = $this->fetchOne("SELECT NEXTVAL(" . $this->quote($this->quoteIdentifier($sequenceName, true)) . ")"); diff --git a/libs/Zend/Db/Adapter/Sqlsrv.php b/libs/Zend/Db/Adapter/Sqlsrv.php index 7e56025eab..b86bf54640 100644 --- a/libs/Zend/Db/Adapter/Sqlsrv.php +++ b/libs/Zend/Db/Adapter/Sqlsrv.php @@ -17,7 +17,7 @@ * @subpackage Adapter * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Sqlsrv.php 21197 2010-02-24 16:12:53Z rob $ + * @version $Id: Sqlsrv.php 23584 2010-12-28 19:51:49Z matthew $ */ /** @@ -437,6 +437,13 @@ class Zend_Db_Adapter_Sqlsrv extends Zend_Db_Adapter_Abstract $sql = "exec sp_columns @table_name = " . $this->quoteIdentifier($tableName, true); $stmt = $this->query($sql); $result = $stmt->fetchAll(Zend_Db::FETCH_NUM); + + // ZF-7698 + $stmt->closeCursor(); + + if (count($result) == 0) { + return array(); + } $owner = 1; $table_name = 2; @@ -609,25 +616,23 @@ class Zend_Db_Adapter_Sqlsrv extends Zend_Db_Adapter_Abstract $sql = preg_replace('/^SELECT\s/i', 'SELECT TOP ' . $count . ' ', $sql); } else { $orderby = stristr($sql, 'ORDER BY'); - if ($orderby !== false) { - $sort = (stripos($orderby, ' desc') !== false) ? 'desc' : 'asc'; - $order = str_ireplace('ORDER BY', '', $orderby); - $order = trim(preg_replace('/\bASC\b|\bDESC\b/i', '', $order)); - } - - $sql = preg_replace('/^SELECT\s/i', 'SELECT TOP ' . ($count+$offset) . ' ', $sql); - - $sql = 'SELECT * FROM (SELECT TOP ' . $count . ' * FROM (' . $sql . ') AS inner_tbl'; - if ($orderby !== false) { - $innerOrder = preg_replace('/\".*\".\"(.*)\"/i', '"inner_tbl"."$1"', $order); - $sql .= ' ORDER BY ' . $innerOrder . ' '; - $sql .= (stripos($sort, 'asc') !== false) ? 'DESC' : 'ASC'; - } - $sql .= ') AS outer_tbl'; - if ($orderby !== false) { - $outerOrder = preg_replace('/\".*\".\"(.*)\"/i', '"outer_tbl"."$1"', $order); - $sql .= ' ORDER BY ' . $outerOrder . ' ' . $sort; + + if (!$orderby) { + $over = 'ORDER BY (SELECT 0)'; + } else { + $over = preg_replace('/\"[^,]*\".\"([^,]*)\"/i', '"inner_tbl"."$1"', $orderby); } + + // Remove ORDER BY clause from $sql + $sql = preg_replace('/\s+ORDER BY(.*)/', '', $sql); + + // Add ORDER BY clause as an argument for ROW_NUMBER() + $sql = "SELECT ROW_NUMBER() OVER ($over) AS \"ZEND_DB_ROWNUM\", * FROM ($sql) AS inner_tbl"; + + $start = $offset + 1; + $end = $offset + $count; + + $sql = "WITH outer_tbl AS ($sql) SELECT * FROM outer_tbl WHERE \"ZEND_DB_ROWNUM\" BETWEEN $start AND $end"; } return $sql; @@ -657,10 +662,10 @@ class Zend_Db_Adapter_Sqlsrv extends Zend_Db_Adapter_Abstract public function getServerVersion() { $this->_connect(); - $version = sqlsrv_client_info($this->_connection); + $serverInfo = sqlsrv_server_info($this->_connection); - if ($version !== false) { - return $version['DriverVer']; + if ($serverInfo !== false) { + return $serverInfo['SQLServerVersion']; } return null; diff --git a/libs/Zend/Db/Adapter/Sqlsrv/Exception.php b/libs/Zend/Db/Adapter/Sqlsrv/Exception.php index 1f68aa9c56..d82da51c4f 100644 --- a/libs/Zend/Db/Adapter/Sqlsrv/Exception.php +++ b/libs/Zend/Db/Adapter/Sqlsrv/Exception.php @@ -17,7 +17,7 @@ * @subpackage Adapter * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Exception.php 20629 2010-01-25 21:17:23Z ralph $ + * @version $Id: Exception.php 20625 2010-01-25 21:03:53Z ralph $ */ /** diff --git a/libs/Zend/Db/Profiler/Query.php b/libs/Zend/Db/Profiler/Query.php index aacc16fbb9..a634ea966e 100644 --- a/libs/Zend/Db/Profiler/Query.php +++ b/libs/Zend/Db/Profiler/Query.php @@ -17,7 +17,7 @@ * @subpackage Profiler * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Query.php 20096 2010-01-06 02:05:09Z bkarwin $ + * @version $Id: Query.php 23382 2010-11-18 22:50:50Z bittarman $ */ @@ -195,5 +195,19 @@ class Zend_Db_Profiler_Query return $this->_endedMicrotime - $this->_startedMicrotime; } + + /** + * Get the time (in seconds) when the profiler started running. + * + * @return bool|float + */ + public function getStartedMicrotime() + { + if(null === $this->_startedMicrotime) { + return false; + } + + return $this->_startedMicrotime; + } } diff --git a/libs/Zend/Db/Select.php b/libs/Zend/Db/Select.php index 721f3ec859..ac4419bbd7 100644 --- a/libs/Zend/Db/Select.php +++ b/libs/Zend/Db/Select.php @@ -17,7 +17,7 @@ * @subpackage Select * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Select.php 20096 2010-01-06 02:05:09Z bkarwin $ + * @version $Id: Select.php 23516 2010-12-16 13:26:11Z bittarman $ */ @@ -207,8 +207,8 @@ class Zend_Db_Select * The first parameter $name can be a simple string, in which case the * correlation name is generated automatically. If you want to specify * the correlation name, the first parameter must be an associative - * array in which the key is the physical table name, and the value is - * the correlation name. For example, array('table' => 'alias'). + * array in which the key is the correlation name, and the value is + * the physical table name. For example, array('alias' => 'table'). * The correlation name is prepended to all columns fetched for this * table. * @@ -219,8 +219,8 @@ class Zend_Db_Select * no correlation name is generated or prepended to the columns named * in the second parameter. * - * @param array|string|Zend_Db_Expr $name The table name or an associative array relating table name to - * correlation name. + * @param array|string|Zend_Db_Expr $name The table name or an associative array + * relating correlation name to table name. * @param array|string|Zend_Db_Expr $cols The columns to select from this table. * @param string $schema The schema name to specify, if any. * @return Zend_Db_Select This Zend_Db_Select object. @@ -467,7 +467,7 @@ class Zend_Db_Select * * @param string $cond The WHERE condition. * @param mixed $value OPTIONAL The value to quote into the condition. - * @param constant $type OPTIONAL The type of the given value + * @param int $type OPTIONAL The type of the given value * @return Zend_Db_Select This Zend_Db_Select object. */ public function where($cond, $value = null, $type = null) @@ -484,7 +484,7 @@ class Zend_Db_Select * * @param string $cond The WHERE condition. * @param mixed $value OPTIONAL The value to quote into the condition. - * @param constant $type OPTIONAL The type of the given value + * @param int $type OPTIONAL The type of the given value * @return Zend_Db_Select This Zend_Db_Select object. * * @see where() @@ -526,14 +526,14 @@ class Zend_Db_Select * appears. See {@link where()} for an example * * @param string $cond The HAVING condition. - * @param string|Zend_Db_Expr $val The value to quote into the condition. + * @param mixed $value OPTIONAL The value to quote into the condition. + * @param int $type OPTIONAL The type of the given value * @return Zend_Db_Select This Zend_Db_Select object. */ - public function having($cond) + public function having($cond, $value = null, $type = null) { - if (func_num_args() > 1) { - $val = func_get_arg(1); - $cond = $this->_adapter->quoteInto($cond, $val); + if ($value !== null) { + $cond = $this->_adapter->quoteInto($cond, $value, $type); } if ($this->_parts[self::HAVING]) { @@ -551,16 +551,16 @@ class Zend_Db_Select * Otherwise identical to orHaving(). * * @param string $cond The HAVING condition. - * @param mixed $val The value to quote into the condition. + * @param mixed $value OPTIONAL The value to quote into the condition. + * @param int $type OPTIONAL The type of the given value * @return Zend_Db_Select This Zend_Db_Select object. * * @see having() */ - public function orHaving($cond) + public function orHaving($cond, $value = null, $type = null) { - if (func_num_args() > 1) { - $val = func_get_arg(1); - $cond = $this->_adapter->quoteInto($cond, $val); + if ($value !== null) { + $cond = $this->_adapter->quoteInto($cond, $value, $type); } if ($this->_parts[self::HAVING]) { diff --git a/libs/Zend/Db/Statement/Exception.php b/libs/Zend/Db/Statement/Exception.php index 511888a5e3..23e36c3eff 100644 --- a/libs/Zend/Db/Statement/Exception.php +++ b/libs/Zend/Db/Statement/Exception.php @@ -17,7 +17,7 @@ * @subpackage Statement * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Exception.php 20514 2010-01-22 07:57:10Z ralph $ + * @version $Id: Exception.php 20513 2010-01-22 07:55:48Z ralph $ */ /** diff --git a/libs/Zend/Db/Statement/Pdo/Oci.php b/libs/Zend/Db/Statement/Pdo/Oci.php index 2306228187..bc0bbde185 100644 --- a/libs/Zend/Db/Statement/Pdo/Oci.php +++ b/libs/Zend/Db/Statement/Pdo/Oci.php @@ -17,7 +17,7 @@ * @subpackage Statement * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Oci.php 21105 2010-02-19 21:27:09Z mikaelkael $ + * @version $Id: Oci.php 21104 2010-02-19 21:26:36Z mikaelkael $ */ /** diff --git a/libs/Zend/Db/Statement/Sqlsrv.php b/libs/Zend/Db/Statement/Sqlsrv.php index 9663c83ccf..121e416c33 100644 --- a/libs/Zend/Db/Statement/Sqlsrv.php +++ b/libs/Zend/Db/Statement/Sqlsrv.php @@ -17,7 +17,7 @@ * @subpackage Statement * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Sqlsrv.php 20096 2010-01-06 02:05:09Z bkarwin $ + * @version $Id: Sqlsrv.php 23486 2010-12-10 04:05:30Z mjh_ca $ */ /** @@ -376,8 +376,11 @@ class Zend_Db_Statement_Sqlsrv extends Zend_Db_Statement // require_once 'Zend/Db/Statement/Sqlsrv/Exception.php'; throw new Zend_Db_Statement_Sqlsrv_Exception(sqlsrv_errors()); } + + // reset column keys + $this->_keys = null; - //else - moved to next (or there are no more rows) + return true; } /** @@ -408,4 +411,30 @@ class Zend_Db_Statement_Sqlsrv extends Zend_Db_Statement return $num_rows; } + + /** + * Returns an array containing all of the result set rows. + * + * @param int $style OPTIONAL Fetch mode. + * @param int $col OPTIONAL Column number, if fetch mode is by column. + * @return array Collection of rows, each in a format by the fetch mode. + * + * Behaves like parent, but if limit() + * is used, the final result removes the extra column + * 'zend_db_rownum' + */ + public function fetchAll($style = null, $col = null) + { + $data = parent::fetchAll($style, $col); + $results = array(); + $remove = $this->_adapter->foldCase('ZEND_DB_ROWNUM'); + + foreach ($data as $row) { + if (is_array($row) && array_key_exists($remove, $row)) { + unset($row[$remove]); + } + $results[] = $row; + } + return $results; + } } diff --git a/libs/Zend/Db/Table/Abstract.php b/libs/Zend/Db/Table/Abstract.php index b1ab26f1f4..435d198ecc 100644 --- a/libs/Zend/Db/Table/Abstract.php +++ b/libs/Zend/Db/Table/Abstract.php @@ -17,7 +17,7 @@ * @subpackage Table * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Abstract.php 21079 2010-02-18 18:15:49Z tech13 $ + * @version $Id: Abstract.php 23578 2010-12-24 16:31:45Z ramon $ */ /** @@ -807,12 +807,23 @@ abstract class Zend_Db_Table_Abstract //get db configuration $dbConfig = $this->_db->getConfig(); + $port = isset($dbConfig['options']['port']) + ? ':'.$dbConfig['options']['port'] + : (isset($dbConfig['port']) + ? ':'.$dbConfig['port'] + : null); + + $host = isset($dbConfig['options']['host']) + ? ':'.$dbConfig['options']['host'] + : (isset($dbConfig['host']) + ? ':'.$dbConfig['host'] + : null); + // Define the cache identifier where the metadata are saved $cacheId = md5( // port:host/dbname:schema.table (based on availabilty) - (isset($dbConfig['options']['port']) ? ':'.$dbConfig['options']['port'] : null) - . (isset($dbConfig['options']['host']) ? ':'.$dbConfig['options']['host'] : null) - . '/'.$dbConfig['dbname'].':'.$this->_schema.'.'.$this->_name - ); + $port . $host . '/'. $dbConfig['dbname'] . ':' + . $this->_schema. '.' . $this->_name + ); } // If $this has no metadata cache or metadata cache misses @@ -961,7 +972,7 @@ abstract class Zend_Db_Table_Abstract * You can elect to return only a part of this information by supplying its key name, * otherwise all information is returned as an array. * - * @param $key The specific info part to return OPTIONAL + * @param string $key The specific info part to return OPTIONAL * @return mixed */ public function info($key = null) diff --git a/libs/Zend/Db/Table/Row/Abstract.php b/libs/Zend/Db/Table/Row/Abstract.php index bc7e5b5274..8a864fef94 100644 --- a/libs/Zend/Db/Table/Row/Abstract.php +++ b/libs/Zend/Db/Table/Row/Abstract.php @@ -17,7 +17,7 @@ * @subpackage Table * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Abstract.php 22230 2010-05-21 20:59:18Z ralph $ + * @version $Id: Abstract.php 23484 2010-12-10 03:57:59Z mjh_ca $ */ /** @@ -646,7 +646,7 @@ abstract class Zend_Db_Table_Row_Abstract implements ArrayAccess, IteratorAggreg { return new ArrayIterator((array) $this->_data); } - + /** * Returns the column/value data as an array. * diff --git a/libs/Zend/Db/Table/Rowset/Abstract.php b/libs/Zend/Db/Table/Rowset/Abstract.php index ec24b7c620..456060a029 100644 --- a/libs/Zend/Db/Table/Rowset/Abstract.php +++ b/libs/Zend/Db/Table/Rowset/Abstract.php @@ -17,7 +17,7 @@ * @subpackage Table * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Abstract.php 22616 2010-07-17 15:53:16Z ramon $ + * @version $Id: Abstract.php 23484 2010-12-10 03:57:59Z mjh_ca $ */ /** @@ -245,20 +245,8 @@ abstract class Zend_Db_Table_Rowset_Abstract implements SeekableIterator, Counta return null; } - // do we already have a row object for this position? - if (empty($this->_rows[$this->_pointer])) { - $this->_rows[$this->_pointer] = new $this->_rowClass( - array( - 'table' => $this->_table, - 'data' => $this->_data[$this->_pointer], - 'stored' => $this->_stored, - 'readOnly' => $this->_readOnly - ) - ); - } - // return the row object - return $this->_rows[$this->_pointer]; + return $this->_loadAndReturnRow($this->_pointer); } /** @@ -390,17 +378,17 @@ abstract class Zend_Db_Table_Rowset_Abstract implements SeekableIterator, Counta */ public function getRow($position, $seek = false) { - $key = $this->key(); try { - $this->seek($position); - $row = $this->current(); + $row = $this->_loadAndReturnRow($position); } catch (Zend_Db_Table_Rowset_Exception $e) { // require_once 'Zend/Db/Table/Rowset/Exception.php'; throw new Zend_Db_Table_Rowset_Exception('No row could be found at position ' . (int) $position, 0, $e); } - if ($seek == false) { - $this->seek($key); + + if ($seek == true) { + $this->seek($position); } + return $row; } @@ -421,4 +409,27 @@ abstract class Zend_Db_Table_Rowset_Abstract implements SeekableIterator, Counta return $this->_data; } + protected function _loadAndReturnRow($position) + { + if (!isset($this->_data[$position])) { + // require_once 'Zend/Db/Table/Rowset/Exception.php'; + throw new Zend_Db_Table_Rowset_Exception("Data for provided position does not exist"); + } + + // do we already have a row object for this position? + if (empty($this->_rows[$position])) { + $this->_rows[$position] = new $this->_rowClass( + array( + 'table' => $this->_table, + 'data' => $this->_data[$position], + 'stored' => $this->_stored, + 'readOnly' => $this->_readOnly + ) + ); + } + + // return the row object + return $this->_rows[$position]; + } + } diff --git a/libs/Zend/Exception.php b/libs/Zend/Exception.php index bbfb792e93..7d186304e2 100644 --- a/libs/Zend/Exception.php +++ b/libs/Zend/Exception.php @@ -16,6 +16,7 @@ * @package Zend * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License + * @version $Id: Exception.php 23484 2010-12-10 03:57:59Z mjh_ca $ */ /** @@ -53,9 +54,9 @@ class Zend_Exception extends Exception * Overloading * * For PHP < 5.3.0, provides access to the getPrevious() method. - * - * @param string $method - * @param array $args + * + * @param string $method + * @param array $args * @return mixed */ public function __call($method, array $args) @@ -75,8 +76,8 @@ class Zend_Exception extends Exception { if (version_compare(PHP_VERSION, '5.3.0', '<')) { if (null !== ($e = $this->getPrevious())) { - return $e->__toString() - . "\n\nNext " + return $e->__toString() + . "\n\nNext " . parent::__toString(); } } diff --git a/libs/Zend/Feed/Pubsubhubbub.php b/libs/Zend/Feed/Pubsubhubbub.php index eeffd74218..26688b7d6f 100644 --- a/libs/Zend/Feed/Pubsubhubbub.php +++ b/libs/Zend/Feed/Pubsubhubbub.php @@ -16,6 +16,7 @@ * @package Zend_Feed_Pubsubhubbub * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License + * @version $Id: Pubsubhubbub.php 23484 2010-12-10 03:57:59Z mjh_ca $ */ /** @@ -56,7 +57,7 @@ class Zend_Feed_Pubsubhubbub */ const VERIFICATION_MODE_SYNC = 'sync'; const VERIFICATION_MODE_ASYNC = 'async'; - + /** * Subscription States */ diff --git a/libs/Zend/Feed/Pubsubhubbub/CallbackAbstract.php b/libs/Zend/Feed/Pubsubhubbub/CallbackAbstract.php index 2fae31b831..0087224d52 100644 --- a/libs/Zend/Feed/Pubsubhubbub/CallbackAbstract.php +++ b/libs/Zend/Feed/Pubsubhubbub/CallbackAbstract.php @@ -17,6 +17,7 @@ * @subpackage Callback * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License + * @version $Id: CallbackAbstract.php 23484 2010-12-10 03:57:59Z mjh_ca $ */ /** @@ -40,7 +41,7 @@ abstract class Zend_Feed_Pubsubhubbub_CallbackAbstract implements Zend_Feed_Pubsubhubbub_CallbackInterface { /** - * An instance of Zend_Feed_Pubsubhubbub_Model_SubscriptionInterface used + * An instance of Zend_Feed_Pubsubhubbub_Model_SubscriptionInterface used * to background save any verification tokens associated with a subscription * or other. * @@ -73,7 +74,7 @@ abstract class Zend_Feed_Pubsubhubbub_CallbackAbstract */ public function __construct($config = null) { - if (!is_null($config)) { + if ($config !== null) { $this->setConfig($config); } } diff --git a/libs/Zend/Feed/Pubsubhubbub/CallbackInterface.php b/libs/Zend/Feed/Pubsubhubbub/CallbackInterface.php index ce30a6bb23..15e89f5b67 100644 --- a/libs/Zend/Feed/Pubsubhubbub/CallbackInterface.php +++ b/libs/Zend/Feed/Pubsubhubbub/CallbackInterface.php @@ -17,6 +17,7 @@ * @subpackage Callback * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License + * @version $Id: CallbackInterface.php 20785 2010-01-31 09:43:03Z mikaelkael $ */ /** diff --git a/libs/Zend/Feed/Pubsubhubbub/Exception.php b/libs/Zend/Feed/Pubsubhubbub/Exception.php index 5bc562c94e..27e4b7bf1d 100644 --- a/libs/Zend/Feed/Pubsubhubbub/Exception.php +++ b/libs/Zend/Feed/Pubsubhubbub/Exception.php @@ -16,6 +16,7 @@ * @package Zend_Feed_Pubsubhubbub * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License + * @version $Id: Exception.php 20785 2010-01-31 09:43:03Z mikaelkael $ */ /** diff --git a/libs/Zend/Feed/Pubsubhubbub/HttpResponse.php b/libs/Zend/Feed/Pubsubhubbub/HttpResponse.php index e44f0eb86a..1914dc7ee9 100644 --- a/libs/Zend/Feed/Pubsubhubbub/HttpResponse.php +++ b/libs/Zend/Feed/Pubsubhubbub/HttpResponse.php @@ -16,6 +16,7 @@ * @package Zend_Feed_Pubsubhubbub * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License + * @version $Id: HttpResponse.php 20785 2010-01-31 09:43:03Z mikaelkael $ */ /** diff --git a/libs/Zend/Feed/Pubsubhubbub/Model/ModelAbstract.php b/libs/Zend/Feed/Pubsubhubbub/Model/ModelAbstract.php index eab4b56322..f88ce620a2 100644 --- a/libs/Zend/Feed/Pubsubhubbub/Model/ModelAbstract.php +++ b/libs/Zend/Feed/Pubsubhubbub/Model/ModelAbstract.php @@ -16,13 +16,14 @@ * @package Zend_Feed_Pubsubhubbub * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License + * @version $Id: ModelAbstract.php 23484 2010-12-10 03:57:59Z mjh_ca $ */ /** @see Zend_Db_Table */ // require_once 'Zend/Db/Table.php'; -/** +/** * @see Zend_Registry * Seems to fix the file not being included by Zend_Db_Table... */ @@ -42,17 +43,17 @@ class Zend_Feed_Pubsubhubbub_Model_ModelAbstract * @var Zend_Db_Table */ protected $_db = null; - + /** * Constructor - * - * @param array $data - * @param Zend_Db_Table_Abstract $tableGateway + * + * @param array $data + * @param Zend_Db_Table_Abstract $tableGateway * @return void */ public function __construct(Zend_Db_Table_Abstract $tableGateway = null) { - if (is_null($tableGateway)) { + if ($tableGateway === null) { $parts = explode('_', get_class($this)); $table = strtolower(array_pop($parts)); $this->_db = new Zend_Db_Table($table); diff --git a/libs/Zend/Feed/Pubsubhubbub/Model/Subscription.php b/libs/Zend/Feed/Pubsubhubbub/Model/Subscription.php index 5858b19d1a..9964e9148b 100644 --- a/libs/Zend/Feed/Pubsubhubbub/Model/Subscription.php +++ b/libs/Zend/Feed/Pubsubhubbub/Model/Subscription.php @@ -17,6 +17,7 @@ * @subpackage Entity * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License + * @version $Id: Subscription.php 22507 2010-06-30 19:11:27Z ramon $ */ /** @see Zend_Feed_Pubsubhubbub_Model_ModelAbstract */ diff --git a/libs/Zend/Feed/Pubsubhubbub/Model/SubscriptionInterface.php b/libs/Zend/Feed/Pubsubhubbub/Model/SubscriptionInterface.php index f8a6e6a3e3..8acd669a77 100644 --- a/libs/Zend/Feed/Pubsubhubbub/Model/SubscriptionInterface.php +++ b/libs/Zend/Feed/Pubsubhubbub/Model/SubscriptionInterface.php @@ -17,6 +17,7 @@ * @subpackage Entity * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License + * @version $Id: SubscriptionInterface.php 23484 2010-12-10 03:57:59Z mjh_ca $ */ /** @@ -28,7 +29,7 @@ */ interface Zend_Feed_Pubsubhubbub_Model_SubscriptionInterface { - + /** * Save subscription to RDMBS * @@ -36,23 +37,23 @@ interface Zend_Feed_Pubsubhubbub_Model_SubscriptionInterface * @return bool */ public function setSubscription(array $data); - + /** * Get subscription by ID/key - * - * @param string $key + * + * @param string $key * @return array */ public function getSubscription($key); /** * Determine if a subscription matching the key exists - * - * @param string $key + * + * @param string $key * @return bool */ public function hasSubscription($key); - + /** * Delete a subscription * @@ -60,5 +61,5 @@ interface Zend_Feed_Pubsubhubbub_Model_SubscriptionInterface * @return bool */ public function deleteSubscription($key); - + } diff --git a/libs/Zend/Feed/Pubsubhubbub/Publisher.php b/libs/Zend/Feed/Pubsubhubbub/Publisher.php index dfc388beca..67573262a4 100644 --- a/libs/Zend/Feed/Pubsubhubbub/Publisher.php +++ b/libs/Zend/Feed/Pubsubhubbub/Publisher.php @@ -16,6 +16,7 @@ * @package Zend_Feed_Pubsubhubbub * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License + * @version $Id: Publisher.php 23075 2010-10-10 21:31:30Z padraic $ */ /** @@ -73,7 +74,7 @@ class Zend_Feed_Pubsubhubbub_Publisher */ public function __construct($config = null) { - if (!is_null($config)) { + if ($config !== null) { $this->setConfig($config); } } @@ -305,7 +306,7 @@ class Zend_Feed_Pubsubhubbub_Publisher $this->removeParameter($name); return $this; } - if (empty($value) || (!is_string($value) && !is_null($value))) { + if (empty($value) || (!is_string($value) && $value !== null)) { // require_once 'Zend/Feed/Pubsubhubbub/Exception.php'; throw new Zend_Feed_Pubsubhubbub_Exception('Invalid parameter "value"' .' of "' . $value . '" must be a non-empty string'); @@ -411,7 +412,7 @@ class Zend_Feed_Pubsubhubbub_Publisher $params[] = urlencode($name) . '=' . urlencode($value); } $paramString = implode('&', $params); - $client->setRawData($paramString); + $client->setRawData($paramString, 'application/x-www-form-urlencoded'); return $client; } } diff --git a/libs/Zend/Feed/Pubsubhubbub/Subscriber.php b/libs/Zend/Feed/Pubsubhubbub/Subscriber.php index 9921bce594..e5a84e5388 100644 --- a/libs/Zend/Feed/Pubsubhubbub/Subscriber.php +++ b/libs/Zend/Feed/Pubsubhubbub/Subscriber.php @@ -16,6 +16,7 @@ * @package Zend_Feed_Pubsubhubbub * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License + * @version $Id: Subscriber.php 23484 2010-12-10 03:57:59Z mjh_ca $ */ /** @@ -121,7 +122,7 @@ class Zend_Feed_Pubsubhubbub_Subscriber * @var array */ protected $_authentications = array(); - + /** * Tells the Subscriber to append any subscription identifier to the path * of the base Callback URL. E.g. an identifier "subkey1" would be added @@ -149,7 +150,7 @@ class Zend_Feed_Pubsubhubbub_Subscriber */ public function __construct($config = null) { - if (!is_null($config)) { + if ($config !== null) { $this->setConfig($config); } } @@ -392,12 +393,12 @@ class Zend_Feed_Pubsubhubbub_Subscriber $this->_hubUrls = array_unique($this->_hubUrls); return $this->_hubUrls; } - + /** * Add authentication credentials for a given URL - * - * @param string $url - * @param array $authentication + * + * @param string $url + * @param array $authentication * @return Zend_Feed_Pubsubhubbub_Subscriber */ public function addAuthentication($url, array $authentication) @@ -411,11 +412,11 @@ class Zend_Feed_Pubsubhubbub_Subscriber $this->_authentications[$url] = $authentication; return $this; } - + /** * Add authentication credentials for hub URLs - * - * @param array $authentications + * + * @param array $authentications * @return Zend_Feed_Pubsubhubbub_Subscriber */ public function addAuthentications(array $authentications) @@ -425,21 +426,21 @@ class Zend_Feed_Pubsubhubbub_Subscriber } return $this; } - + /** * Get all hub URL authentication credentials - * + * * @return array */ public function getAuthentications() { return $this->_authentications; } - + /** * Set flag indicating whether or not to use a path parameter - * - * @param bool $bool + * + * @param bool $bool * @return Zend_Feed_Pubsubhubbub_Subscriber */ public function usePathParameter($bool = true) @@ -470,7 +471,7 @@ class Zend_Feed_Pubsubhubbub_Subscriber $this->removeParameter($name); return $this; } - if (empty($value) || (!is_string($value) && !is_null($value))) { + if (empty($value) || (!is_string($value) && $value !== null)) { // require_once 'Zend/Feed/Pubsubhubbub/Exception.php'; throw new Zend_Feed_Pubsubhubbub_Exception('Invalid parameter "value"' . ' of "' . $value . '" must be a non-empty string'); @@ -537,7 +538,7 @@ class Zend_Feed_Pubsubhubbub_Subscriber } /** - * Gets an instance of Zend_Feed_Pubsubhubbub_Storage_StorageInterface used + * Gets an instance of Zend_Feed_Pubsubhubbub_Storage_StorageInterface used * to background save any verification tokens associated with a subscription * or other. * @@ -637,7 +638,10 @@ class Zend_Feed_Pubsubhubbub_Subscriber $client->setAuth($auth[0], $auth[1]); } $client->setUri($url); - $client->setRawData($this->_getRequestParameters($url, $mode)); + $client->setRawData( + $this->_getRequestParameters($url, $mode), + 'application/x-www-form-urlencoded' + ); $response = $client->request(); if ($response->getStatus() !== 204 && $response->getStatus() !== 202 @@ -732,7 +736,7 @@ class Zend_Feed_Pubsubhubbub_Subscriber $params['hub.callback'] = rtrim($this->getCallbackUrl(), '/') . '/' . Zend_Feed_Pubsubhubbub::urlencode($key); } - if ($mode == 'subscribe' && !is_null($this->getLeaseSeconds())) { + if ($mode == 'subscribe' && $this->getLeaseSeconds() !== null) { $params['hub.lease_seconds'] = $this->getLeaseSeconds(); } @@ -741,7 +745,7 @@ class Zend_Feed_Pubsubhubbub_Subscriber foreach ($optParams as $name => $value) { $params[$name] = $value; } - + // store subscription to storage $now = new Zend_Date; $expires = null; diff --git a/libs/Zend/Feed/Pubsubhubbub/Subscriber/Callback.php b/libs/Zend/Feed/Pubsubhubbub/Subscriber/Callback.php index 1f42375839..03d96fa549 100644 --- a/libs/Zend/Feed/Pubsubhubbub/Subscriber/Callback.php +++ b/libs/Zend/Feed/Pubsubhubbub/Subscriber/Callback.php @@ -16,6 +16,7 @@ * @package Zend_Feed_Pubsubhubbub * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License + * @version $Id: Callback.php 23484 2010-12-10 03:57:59Z mjh_ca $ */ /** @@ -48,7 +49,7 @@ class Zend_Feed_Pubsubhubbub_Subscriber_Callback * @var string */ protected $_feedUpdate = null; - + /** * Holds a manually set subscription key (i.e. identifies a unique * subscription) which is typical when it is not passed in the query string @@ -58,14 +59,14 @@ class Zend_Feed_Pubsubhubbub_Subscriber_Callback * @var string */ protected $_subscriptionKey = null; - + /** * After verification, this is set to the verified subscription's data. * * @var array */ protected $_currentSubscriptionData = null; - + /** * Set a subscription key to use for the current callback request manually. * Required if usePathParameter is enabled for the Subscriber. @@ -101,13 +102,14 @@ class Zend_Feed_Pubsubhubbub_Subscriber_Callback * SHOULD be validated/processed by an asynchronous process so as * to avoid holding up responses to the Hub. */ + $contentType = $this->_getHeader('Content-Type'); if (strtolower($_SERVER['REQUEST_METHOD']) == 'post' && $this->_hasValidVerifyToken(null, false) - && ($this->_getHeader('Content-Type') == 'application/atom+xml' - || $this->_getHeader('Content-Type') == 'application/rss+xml' - || $this->_getHeader('Content-Type') == 'application/xml' - || $this->_getHeader('Content-Type') == 'text/xml' - || $this->_getHeader('Content-Type') == 'application/rdf+xml') + && (stripos($contentType, 'application/atom+xml') === 0 + || stripos($contentType, 'application/rss+xml') === 0 + || stripos($contentType, 'application/xml') === 0 + || stripos($contentType, 'text/xml') === 0 + || stripos($contentType, 'application/rdf+xml') === 0) ) { $this->setFeedUpdate($this->_getRawBody()); $this->getHttpResponse() @@ -153,9 +155,9 @@ class Zend_Feed_Pubsubhubbub_Subscriber_Callback return false; } $required = array( - 'hub_mode', + 'hub_mode', 'hub_topic', - 'hub_challenge', + 'hub_challenge', 'hub_verify_token', ); foreach ($required as $key) { @@ -207,7 +209,7 @@ class Zend_Feed_Pubsubhubbub_Subscriber_Callback */ public function hasFeedUpdate() { - if (is_null($this->_feedUpdate)) { + if ($this->_feedUpdate === null) { return false; } return true; diff --git a/libs/Zend/Feed/Reader.php b/libs/Zend/Feed/Reader.php index 26bf661cdf..cfec342577 100644 --- a/libs/Zend/Feed/Reader.php +++ b/libs/Zend/Feed/Reader.php @@ -16,7 +16,7 @@ * @package Zend_Feed_Reader * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Reader.php 22093 2010-05-04 12:55:06Z padraic $ + * @version $Id: Reader.php 23484 2010-12-10 03:57:59Z mjh_ca $ */ /** @@ -236,10 +236,10 @@ class Zend_Feed_Reader if (self::$_httpConditionalGet && $cache) { $data = $cache->load($cacheId); if ($data) { - if (is_null($etag)) { + if ($etag === null) { $etag = $cache->load($cacheId.'_etag'); } - if (is_null($lastModified)) { + if ($lastModified === null) { $lastModified = $cache->load($cacheId.'_lastmodified');; } if ($etag) { @@ -510,7 +510,7 @@ class Zend_Feed_Reader if ($xpath->query('//atom:feed')->length) { return self::TYPE_ATOM_10; } - + if ($xpath->query('//atom:entry')->length) { if ($specOnly == true) { return self::TYPE_ATOM_10; @@ -698,7 +698,7 @@ class Zend_Feed_Reader self::registerExtension('Thread'); self::registerExtension('Podcast'); } - + /** * Utility method to apply array_unique operation to a multidimensional * array. @@ -717,5 +717,5 @@ class Zend_Feed_Reader } return $array; } - + } diff --git a/libs/Zend/Feed/Reader/Collection.php b/libs/Zend/Feed/Reader/Collection.php index fba2b52b52..693bf3e57f 100644 --- a/libs/Zend/Feed/Reader/Collection.php +++ b/libs/Zend/Feed/Reader/Collection.php @@ -16,7 +16,7 @@ * @package Zend_Feed_Reader * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id$ + * @version $Id: Collection.php 23484 2010-12-10 03:57:59Z mjh_ca $ */ /** @@ -28,6 +28,6 @@ class Zend_Feed_Reader_Collection extends ArrayObject { - + } diff --git a/libs/Zend/Feed/Reader/Collection/Author.php b/libs/Zend/Feed/Reader/Collection/Author.php index 6a039974b6..7b860af16c 100644 --- a/libs/Zend/Feed/Reader/Collection/Author.php +++ b/libs/Zend/Feed/Reader/Collection/Author.php @@ -16,9 +16,9 @@ * @package Zend_Feed_Reader * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Author.php 20096 2010-01-06 02:05:09Z bkarwin $ + * @version $Id: Author.php 23484 2010-12-10 03:57:59Z mjh_ca $ */ - + /** * @see Zend_Feed_Reader_Collection_CollectionAbstract */ diff --git a/libs/Zend/Feed/Reader/Collection/Category.php b/libs/Zend/Feed/Reader/Collection/Category.php index 2587c13268..0cc82eacaa 100644 --- a/libs/Zend/Feed/Reader/Collection/Category.php +++ b/libs/Zend/Feed/Reader/Collection/Category.php @@ -16,9 +16,9 @@ * @package Zend_Feed_Reader * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Category.php 20954 2010-02-06 17:56:27Z padraic $ + * @version $Id: Category.php 23484 2010-12-10 03:57:59Z mjh_ca $ */ - + /** * @see Zend_Feed_Reader_Collection_CollectionAbstract */ diff --git a/libs/Zend/Feed/Reader/Entry/Atom.php b/libs/Zend/Feed/Reader/Entry/Atom.php index 77289b411b..affcd5b3ea 100644 --- a/libs/Zend/Feed/Reader/Entry/Atom.php +++ b/libs/Zend/Feed/Reader/Entry/Atom.php @@ -16,7 +16,7 @@ * @package Zend_Feed_Reader * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Atom.php 20096 2010-01-06 02:05:09Z bkarwin $ + * @version $Id: Atom.php 23484 2010-12-10 03:57:59Z mjh_ca $ */ /** @@ -74,7 +74,7 @@ class Zend_Feed_Reader_Entry_Atom extends Zend_Feed_Reader_EntryAbstract impleme $threadClass = Zend_Feed_Reader::getPluginLoader()->getClassName('Thread_Entry'); $this->_extensions['Thread_Entry'] = new $threadClass($entry, $entryKey, $type); - + $threadClass = Zend_Feed_Reader::getPluginLoader()->getClassName('DublinCore_Entry'); $this->_extensions['DublinCore_Entry'] = new $threadClass($entry, $entryKey, $type); } @@ -344,7 +344,7 @@ class Zend_Feed_Reader_Entry_Atom extends Zend_Feed_Reader_EntryAbstract impleme return $this->_data['commentfeedlink']; } - + /** * Get category data as a Zend_Feed_Reader_Collection_Category object * @@ -357,7 +357,7 @@ class Zend_Feed_Reader_Entry_Atom extends Zend_Feed_Reader_EntryAbstract impleme } $categoryCollection = $this->getExtension('Atom')->getCategories(); - + if (count($categoryCollection) == 0) { $categoryCollection = $this->getExtension('DublinCore')->getCategories(); } @@ -366,7 +366,7 @@ class Zend_Feed_Reader_Entry_Atom extends Zend_Feed_Reader_EntryAbstract impleme return $this->_data['categories']; } - + /** * Get source feed metadata from the entry * @@ -382,7 +382,7 @@ class Zend_Feed_Reader_Entry_Atom extends Zend_Feed_Reader_EntryAbstract impleme $this->_data['source'] = $source; - return $this->_data['source']; + return $this->_data['source']; } /** diff --git a/libs/Zend/Feed/Reader/Entry/Rss.php b/libs/Zend/Feed/Reader/Entry/Rss.php index 21a30a98fc..9f02d3869e 100644 --- a/libs/Zend/Feed/Reader/Entry/Rss.php +++ b/libs/Zend/Feed/Reader/Entry/Rss.php @@ -16,7 +16,7 @@ * @package Zend_Feed_Reader * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Rss.php 22301 2010-05-26 10:15:13Z padraic $ + * @version $Id: Rss.php 23484 2010-12-10 03:57:59Z mjh_ca $ */ /** @@ -159,7 +159,7 @@ class Zend_Feed_Reader_Entry_Rss extends Zend_Feed_Reader_EntryAbstract implemen if (array_key_exists('authors', $this->_data)) { return $this->_data['authors']; } - + $authors = array(); $authors_dc = $this->getExtension('DublinCore')->getAuthors(); if (!empty($authors_dc)) { @@ -169,7 +169,7 @@ class Zend_Feed_Reader_Entry_Rss extends Zend_Feed_Reader_EntryAbstract implemen ); } } - + if ($this->getType() !== Zend_Feed_Reader::TYPE_RSS_10 && $this->getType() !== Zend_Feed_Reader::TYPE_RSS_090) { $list = $this->_xpath->query($this->_xpathQueryRss . '//author'); @@ -189,7 +189,7 @@ class Zend_Feed_Reader_Entry_Rss extends Zend_Feed_Reader_EntryAbstract implemen $data['name'] = $matches[1]; } $authors[] = $data; - } + } } } @@ -472,7 +472,7 @@ class Zend_Feed_Reader_Entry_Rss extends Zend_Feed_Reader_EntryAbstract implemen return $this->_data['links']; } - + /** * Get all categories * @@ -503,7 +503,7 @@ class Zend_Feed_Reader_Entry_Rss extends Zend_Feed_Reader_EntryAbstract implemen } else { $categoryCollection = $this->getExtension('DublinCore')->getCategories(); } - + if (count($categoryCollection) == 0) { $categoryCollection = $this->getExtension('Atom')->getCategories(); } diff --git a/libs/Zend/Feed/Reader/EntryInterface.php b/libs/Zend/Feed/Reader/EntryInterface.php index 392a533a30..72796151fc 100644 --- a/libs/Zend/Feed/Reader/EntryInterface.php +++ b/libs/Zend/Feed/Reader/EntryInterface.php @@ -16,7 +16,7 @@ * @package Zend_Feed_Reader * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: EntryInterface.php 20096 2010-01-06 02:05:09Z bkarwin $ + * @version $Id: EntryInterface.php 23484 2010-12-10 03:57:59Z mjh_ca $ */ /** @@ -133,7 +133,7 @@ interface Zend_Feed_Reader_EntryInterface * @return string */ public function getCommentFeedLink(); - + /** * Get all categories * diff --git a/libs/Zend/Feed/Reader/Extension/Atom/Entry.php b/libs/Zend/Feed/Reader/Extension/Atom/Entry.php index 1efa197787..f17a9a0d1d 100644 --- a/libs/Zend/Feed/Reader/Extension/Atom/Entry.php +++ b/libs/Zend/Feed/Reader/Extension/Atom/Entry.php @@ -16,7 +16,7 @@ * @package Zend_Feed_Reader * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Entry.php 22301 2010-05-26 10:15:13Z padraic $ + * @version $Id: Entry.php 23484 2010-12-10 03:57:59Z mjh_ca $ */ /** @@ -127,9 +127,9 @@ class Zend_Feed_Reader_Extension_Atom_Entry if (array_key_exists('content', $this->_data)) { return $this->_data['content']; } - + $content = null; - + $el = $this->getXpath()->query($this->getXpathPrefix() . '/atom:content'); if($el->length > 0) { $el = $el->item(0); @@ -158,7 +158,7 @@ class Zend_Feed_Reader_Extension_Atom_Entry break; } } - + //var_dump($content); exit; if (!$content) { @@ -169,7 +169,7 @@ class Zend_Feed_Reader_Extension_Atom_Entry return $this->_data['content']; } - + /** * Parse out XHTML to remove the namespacing */ @@ -510,7 +510,7 @@ class Zend_Feed_Reader_Extension_Atom_Entry return $this->_data['commentfeedlink']; } - + /** * Get all categories * @@ -551,7 +551,7 @@ class Zend_Feed_Reader_Extension_Atom_Entry return $this->_data['categories']; } - + /** * Get source feed metadata from the entry * @@ -562,7 +562,7 @@ class Zend_Feed_Reader_Extension_Atom_Entry if (array_key_exists('source', $this->_data)) { return $this->_data['source']; } - + $source = null; // TODO: Investigate why _getAtomType() fails here. Is it even needed? if ($this->getType() == Zend_Feed_Reader::TYPE_ATOM_10) { @@ -572,9 +572,9 @@ class Zend_Feed_Reader_Extension_Atom_Entry $source = new Zend_Feed_Reader_Feed_Atom_Source($element, $this->getXpathPrefix()); } } - + $this->_data['source'] = $source; - return $this->_data['source']; + return $this->_data['source']; } /** @@ -584,7 +584,7 @@ class Zend_Feed_Reader_Extension_Atom_Entry protected function _absolutiseUri($link) { if (!Zend_Uri::check($link)) { - if (!is_null($this->getBaseUrl())) { + if ($this->getBaseUrl() !== null) { $link = $this->getBaseUrl() . $link; if (!Zend_Uri::check($link)) { $link = null; @@ -607,7 +607,7 @@ class Zend_Feed_Reader_Extension_Atom_Entry $emailNode = $element->getElementsByTagName('email'); $nameNode = $element->getElementsByTagName('name'); $uriNode = $element->getElementsByTagName('uri'); - + if ($emailNode->length && strlen($emailNode->item(0)->nodeValue) > 0) { $author['email'] = $emailNode->item(0)->nodeValue; } diff --git a/libs/Zend/Feed/Reader/Extension/Atom/Feed.php b/libs/Zend/Feed/Reader/Extension/Atom/Feed.php index 3e0e2079c5..50e9cd0554 100644 --- a/libs/Zend/Feed/Reader/Extension/Atom/Feed.php +++ b/libs/Zend/Feed/Reader/Extension/Atom/Feed.php @@ -16,7 +16,7 @@ * @package Zend_Feed_Reader * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Feed.php 22301 2010-05-26 10:15:13Z padraic $ + * @version $Id: Feed.php 23484 2010-12-10 03:57:59Z mjh_ca $ */ /** @@ -317,6 +317,30 @@ class Zend_Feed_Reader_Extension_Atom_Feed } /** + * Get the feed image + * + * @return array|null + */ + public function getIcon() + { + if (array_key_exists('icon', $this->_data)) { + return $this->_data['icon']; + } + + $imageUrl = $this->_xpath->evaluate('string(' . $this->getXpathPrefix() . '/atom:icon)'); + + if (!$imageUrl) { + $image = null; + } else { + $image = array('uri'=>$imageUrl); + } + + $this->_data['icon'] = $image; + + return $this->_data['icon']; + } + + /** * Get the base URI of the feed (if set). * * @return string|null @@ -396,7 +420,7 @@ class Zend_Feed_Reader_Extension_Atom_Feed return $this->_data['hubs']; } $hubs = array(); - + $list = $this->_xpath->query($this->getXpathPrefix() . '//atom:link[@rel="hub"]/@href'); @@ -434,7 +458,7 @@ class Zend_Feed_Reader_Extension_Atom_Feed return $this->_data['title']; } - + /** * Get all categories * @@ -489,7 +513,7 @@ class Zend_Feed_Reader_Extension_Atom_Feed $emailNode = $element->getElementsByTagName('email'); $nameNode = $element->getElementsByTagName('name'); $uriNode = $element->getElementsByTagName('uri'); - + if ($emailNode->length && strlen($emailNode->item(0)->nodeValue) > 0) { $author['email'] = $emailNode->item(0)->nodeValue; } @@ -515,7 +539,7 @@ class Zend_Feed_Reader_Extension_Atom_Feed protected function _absolutiseUri($link) { if (!Zend_Uri::check($link)) { - if (!is_null($this->getBaseUrl())) { + if ($this->getBaseUrl() !== null) { $link = $this->getBaseUrl() . $link; if (!Zend_Uri::check($link)) { $link = null; diff --git a/libs/Zend/Feed/Reader/Extension/Content/Entry.php b/libs/Zend/Feed/Reader/Extension/Content/Entry.php index ca10f24a3b..c3da556fc6 100644 --- a/libs/Zend/Feed/Reader/Extension/Content/Entry.php +++ b/libs/Zend/Feed/Reader/Extension/Content/Entry.php @@ -16,7 +16,7 @@ * @package Zend_Feed_Reader * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Entry.php 22301 2010-05-26 10:15:13Z padraic $ + * @version $Id: Entry.php 22300 2010-05-26 10:13:34Z padraic $ */ /** diff --git a/libs/Zend/Feed/Reader/Extension/DublinCore/Entry.php b/libs/Zend/Feed/Reader/Extension/DublinCore/Entry.php index 4ad104b6ff..7ed87de7a8 100644 --- a/libs/Zend/Feed/Reader/Extension/DublinCore/Entry.php +++ b/libs/Zend/Feed/Reader/Extension/DublinCore/Entry.php @@ -16,7 +16,7 @@ * @package Zend_Feed_Reader * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Entry.php 20096 2010-01-06 02:05:09Z bkarwin $ + * @version $Id: Entry.php 23484 2010-12-10 03:57:59Z mjh_ca $ */ /** @@ -102,7 +102,7 @@ class Zend_Feed_Reader_Extension_DublinCore_Entry return $this->_data['authors']; } - + /** * Get categories (subjects under DC) * @@ -113,13 +113,13 @@ class Zend_Feed_Reader_Extension_DublinCore_Entry if (array_key_exists('categories', $this->_data)) { return $this->_data['categories']; } - + $list = $this->_xpath->evaluate($this->getXpathPrefix() . '//dc11:subject'); if (!$list->length) { $list = $this->_xpath->evaluate($this->getXpathPrefix() . '//dc10:subject'); } - + if ($list->length) { $categoryCollection = new Zend_Feed_Reader_Collection_Category; foreach ($list as $category) { @@ -132,11 +132,11 @@ class Zend_Feed_Reader_Extension_DublinCore_Entry } else { $categoryCollection = new Zend_Feed_Reader_Collection_Category; } - + $this->_data['categories'] = $categoryCollection; - return $this->_data['categories']; + return $this->_data['categories']; } - + /** * Get the entry content diff --git a/libs/Zend/Feed/Reader/Extension/DublinCore/Feed.php b/libs/Zend/Feed/Reader/Extension/DublinCore/Feed.php index 4e4bcf4888..775346698a 100644 --- a/libs/Zend/Feed/Reader/Extension/DublinCore/Feed.php +++ b/libs/Zend/Feed/Reader/Extension/DublinCore/Feed.php @@ -16,7 +16,7 @@ * @package Zend_Feed_Reader * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Feed.php 20096 2010-01-06 02:05:09Z bkarwin $ + * @version $Id: Feed.php 23484 2010-12-10 03:57:59Z mjh_ca $ */ /** @@ -84,7 +84,7 @@ class Zend_Feed_Reader_Extension_DublinCore_Feed $list = $this->_xpath->query('//dc10:publisher'); } } - + if ($list->length) { foreach ($list as $author) { $authors[] = array( @@ -261,7 +261,7 @@ class Zend_Feed_Reader_Extension_DublinCore_Feed return $this->_data['date']; } - + /** * Get categories (subjects under DC) * @@ -272,13 +272,13 @@ class Zend_Feed_Reader_Extension_DublinCore_Feed if (array_key_exists('categories', $this->_data)) { return $this->_data['categories']; } - + $list = $this->_xpath->evaluate($this->getXpathPrefix() . '//dc11:subject'); if (!$list->length) { $list = $this->_xpath->evaluate($this->getXpathPrefix() . '//dc10:subject'); } - + if ($list->length) { $categoryCollection = new Zend_Feed_Reader_Collection_Category; foreach ($list as $category) { @@ -291,9 +291,9 @@ class Zend_Feed_Reader_Extension_DublinCore_Feed } else { $categoryCollection = new Zend_Feed_Reader_Collection_Category; } - + $this->_data['categories'] = $categoryCollection; - return $this->_data['categories']; + return $this->_data['categories']; } /** diff --git a/libs/Zend/Feed/Reader/Extension/EntryAbstract.php b/libs/Zend/Feed/Reader/Extension/EntryAbstract.php index 299c1bfbaf..7550453875 100644 --- a/libs/Zend/Feed/Reader/Extension/EntryAbstract.php +++ b/libs/Zend/Feed/Reader/Extension/EntryAbstract.php @@ -16,7 +16,7 @@ * @package Zend_Feed_Reader * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: EntryAbstract.php 20096 2010-01-06 02:05:09Z bkarwin $ + * @version $Id: EntryAbstract.php 22662 2010-07-24 17:37:36Z mabe $ */ /** @@ -83,7 +83,7 @@ abstract class Zend_Feed_Reader_Extension_EntryAbstract $this->_entryKey = $entryKey; $this->_domDocument = $entry->ownerDocument; - if (!is_null($type)) { + if ($type !== null) { $this->_data['type'] = $type; } else { $this->_data['type'] = Zend_Feed_Reader::detectType($entry->ownerDocument, true); diff --git a/libs/Zend/Feed/Reader/Feed/Atom.php b/libs/Zend/Feed/Reader/Feed/Atom.php index 8199355995..2243eefa94 100644 --- a/libs/Zend/Feed/Reader/Feed/Atom.php +++ b/libs/Zend/Feed/Reader/Feed/Atom.php @@ -16,7 +16,7 @@ * @package Zend_Feed_Reader * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Atom.php 22108 2010-05-05 13:44:11Z padraic $ + * @version $Id: Atom.php 23484 2010-12-10 03:57:59Z mjh_ca $ */ /** @@ -318,7 +318,7 @@ class Zend_Feed_Reader_Feed_Atom extends Zend_Feed_Reader_FeedAbstract $link = $this->getExtension('Atom')->getFeedLink(); - if (is_null($link) || empty($link)) { + if ($link === null || empty($link)) { $link = $this->getOriginalSourceUri(); } @@ -362,7 +362,7 @@ class Zend_Feed_Reader_Feed_Atom extends Zend_Feed_Reader_FeedAbstract return $this->_data['hubs']; } - + /** * Get all categories * @@ -375,7 +375,7 @@ class Zend_Feed_Reader_Feed_Atom extends Zend_Feed_Reader_FeedAbstract } $categoryCollection = $this->getExtension('Atom')->getCategories(); - + if (count($categoryCollection) == 0) { $categoryCollection = $this->getExtension('DublinCore')->getCategories(); } diff --git a/libs/Zend/Feed/Reader/Feed/Atom/Source.php b/libs/Zend/Feed/Reader/Feed/Atom/Source.php index bdd972f93e..83b1b34796 100644 --- a/libs/Zend/Feed/Reader/Feed/Atom/Source.php +++ b/libs/Zend/Feed/Reader/Feed/Atom/Source.php @@ -16,7 +16,7 @@ * @package Zend_Feed_Reader * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Atom.php 19165 2009-11-21 16:46:40Z padraic $ + * @version $Id: Source.php 23484 2010-12-10 03:57:59Z mjh_ca $ */ /** @@ -49,7 +49,7 @@ class Zend_Feed_Reader_Feed_Atom_Source extends Zend_Feed_Reader_Feed_Atom $this->_data['type'] = $type; $this->_registerNamespaces(); $this->_loadExtensions(); - + $atomClass = Zend_Feed_Reader::getPluginLoader()->getClassName('Atom_Feed'); $this->_extensions['Atom_Feed'] = new $atomClass($this->_domDocument, $this->_data['type'], $this->_xpath); $atomClass = Zend_Feed_Reader::getPluginLoader()->getClassName('DublinCore_Feed'); @@ -58,12 +58,12 @@ class Zend_Feed_Reader_Feed_Atom_Source extends Zend_Feed_Reader_Feed_Atom $extension->setXpathPrefix(rtrim($xpathPrefix, '/') . '/atom:source'); } } - + /** * Since this is not an Entry carrier but a vehicle for Feed metadata, any * applicable Entry methods are stubbed out and do nothing. */ - + /** * @return void */ @@ -73,7 +73,7 @@ class Zend_Feed_Reader_Feed_Atom_Source extends Zend_Feed_Reader_Feed_Atom * @return void */ public function current() {} - + /** * @return void */ @@ -88,12 +88,12 @@ class Zend_Feed_Reader_Feed_Atom_Source extends Zend_Feed_Reader_Feed_Atom * @return void */ public function rewind() {} - + /** * @return void */ public function valid() {} - + /** * @return void */ diff --git a/libs/Zend/Feed/Reader/Feed/Rss.php b/libs/Zend/Feed/Reader/Feed/Rss.php index bff78c3455..e4cbd105f1 100644 --- a/libs/Zend/Feed/Reader/Feed/Rss.php +++ b/libs/Zend/Feed/Reader/Feed/Rss.php @@ -16,7 +16,7 @@ * @package Zend_Feed_Reader * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Rss.php 22301 2010-05-26 10:15:13Z padraic $ + * @version $Id: Rss.php 23484 2010-12-10 03:57:59Z mjh_ca $ */ /** @@ -105,7 +105,7 @@ class Zend_Feed_Reader_Feed_Rss extends Zend_Feed_Reader_FeedAbstract if (array_key_exists('authors', $this->_data)) { return $this->_data['authors']; } - + $authors = array(); $authors_dc = $this->getExtension('DublinCore')->getAuthors(); if (!empty($authors_dc)) { @@ -139,7 +139,7 @@ class Zend_Feed_Reader_Feed_Rss extends Zend_Feed_Reader_FeedAbstract $data['name'] = $matches[1]; } $authors[] = $data; - } + } } } @@ -178,7 +178,7 @@ class Zend_Feed_Reader_Feed_Rss extends Zend_Feed_Reader_FeedAbstract $copyright = $this->_xpath->evaluate('string(/rss/channel/copyright)'); } - if (!$copyright && !is_null($this->getExtension('DublinCore'))) { + if (!$copyright && $this->getExtension('DublinCore') !== null) { $copyright = $this->getExtension('DublinCore')->getCopyright(); } @@ -344,7 +344,7 @@ class Zend_Feed_Reader_Feed_Rss extends Zend_Feed_Reader_FeedAbstract $description = $this->_xpath->evaluate('string(/rdf:RDF/rss:channel/rss:description)'); } - if (!$description && !is_null($this->getExtension('DublinCore'))) { + if (!$description && $this->getExtension('DublinCore') !== null) { $description = $this->getExtension('DublinCore')->getDescription(); } @@ -379,7 +379,7 @@ class Zend_Feed_Reader_Feed_Rss extends Zend_Feed_Reader_FeedAbstract $id = $this->_xpath->evaluate('string(/rss/channel/guid)'); } - if (!$id && !is_null($this->getExtension('DublinCore'))) { + if (!$id && $this->getExtension('DublinCore') !== null) { $id = $this->getExtension('DublinCore')->getId(); } @@ -474,7 +474,7 @@ class Zend_Feed_Reader_Feed_Rss extends Zend_Feed_Reader_FeedAbstract $language = $this->_xpath->evaluate('string(/rss/channel/language)'); } - if (!$language && !is_null($this->getExtension('DublinCore'))) { + if (!$language && $this->getExtension('DublinCore') !== null) { $language = $this->getExtension('DublinCore')->getLanguage(); } @@ -543,7 +543,7 @@ class Zend_Feed_Reader_Feed_Rss extends Zend_Feed_Reader_FeedAbstract $link = $this->getExtension('Atom')->getFeedLink(); - if (is_null($link) || empty($link)) { + if ($link === null || empty($link)) { $link = $this->getOriginalSourceUri(); } @@ -612,7 +612,7 @@ class Zend_Feed_Reader_Feed_Rss extends Zend_Feed_Reader_FeedAbstract $title = $this->_xpath->evaluate('string(/rdf:RDF/rss:channel/rss:title)'); } - if (!$title && !is_null($this->getExtension('DublinCore'))) { + if (!$title && $this->getExtension('DublinCore') !== null) { $title = $this->getExtension('DublinCore')->getTitle(); } @@ -652,7 +652,7 @@ class Zend_Feed_Reader_Feed_Rss extends Zend_Feed_Reader_FeedAbstract return $this->_data['hubs']; } - + /** * Get all categories * @@ -683,7 +683,7 @@ class Zend_Feed_Reader_Feed_Rss extends Zend_Feed_Reader_FeedAbstract } else { $categoryCollection = $this->getExtension('DublinCore')->getCategories(); } - + if (count($categoryCollection) == 0) { $categoryCollection = $this->getExtension('Atom')->getCategories(); } diff --git a/libs/Zend/Feed/Reader/FeedAbstract.php b/libs/Zend/Feed/Reader/FeedAbstract.php index bda9f23b46..872bb6cfce 100644 --- a/libs/Zend/Feed/Reader/FeedAbstract.php +++ b/libs/Zend/Feed/Reader/FeedAbstract.php @@ -16,7 +16,7 @@ * @package Zend_Feed_Reader * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: FeedAbstract.php 22093 2010-05-04 12:55:06Z padraic $ + * @version $Id: FeedAbstract.php 22092 2010-05-04 12:50:51Z padraic $ */ /** diff --git a/libs/Zend/Feed/Reader/FeedInterface.php b/libs/Zend/Feed/Reader/FeedInterface.php index 35060bafce..df47ea15e2 100644 --- a/libs/Zend/Feed/Reader/FeedInterface.php +++ b/libs/Zend/Feed/Reader/FeedInterface.php @@ -16,7 +16,7 @@ * @package Zend_Feed_Reader * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: FeedInterface.php 20096 2010-01-06 02:05:09Z bkarwin $ + * @version $Id: FeedInterface.php 23484 2010-12-10 03:57:59Z mjh_ca $ */ /** @@ -111,7 +111,7 @@ interface Zend_Feed_Reader_FeedInterface extends Iterator, Countable * @return string|null */ public function getTitle(); - + /** * Get all categories * diff --git a/libs/Zend/Feed/Reader/FeedSet.php b/libs/Zend/Feed/Reader/FeedSet.php index 57ccbf6056..a529386591 100644 --- a/libs/Zend/Feed/Reader/FeedSet.php +++ b/libs/Zend/Feed/Reader/FeedSet.php @@ -16,7 +16,7 @@ * @package Zend_Feed_Reader * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: FeedSet.php 20096 2010-01-06 02:05:09Z bkarwin $ + * @version $Id: FeedSet.php 23484 2010-12-10 03:57:59Z mjh_ca $ */ /** @@ -81,14 +81,14 @@ class Zend_Feed_Reader_FeedSet extends ArrayObject )); } } - + /** * Attempt to turn a relative URI into an absolute URI */ protected function _absolutiseUri($link, $uri = null) { if (!Zend_Uri::check($link)) { - if (!is_null($uri)) { + if ($uri !== null) { $uri = Zend_Uri::factory($uri); if ($link[0] !== '/') { @@ -103,7 +103,7 @@ class Zend_Feed_Reader_FeedSet extends ArrayObject } return $link; } - + /** * Canonicalize relative path */ diff --git a/libs/Zend/Feed/Writer.php b/libs/Zend/Feed/Writer.php index 1a40f63cd9..aa7b9e1df0 100644 --- a/libs/Zend/Feed/Writer.php +++ b/libs/Zend/Feed/Writer.php @@ -16,7 +16,7 @@ * @package Zend_Feed_Writer * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Writer.php 20096 2010-01-06 02:05:09Z bkarwin $ + * @version $Id: Writer.php 23486 2010-12-10 04:05:30Z mjh_ca $ */ /** @@ -27,20 +27,20 @@ */ class Zend_Feed_Writer { - /** - * Namespace constants - */ - const NAMESPACE_ATOM_03 = 'http://purl.org/atom/ns#'; + /** + * Namespace constants + */ + const NAMESPACE_ATOM_03 = 'http://purl.org/atom/ns#'; const NAMESPACE_ATOM_10 = 'http://www.w3.org/2005/Atom'; const NAMESPACE_RDF = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#'; const NAMESPACE_RSS_090 = 'http://my.netscape.com/rdf/simple/0.9/'; const NAMESPACE_RSS_10 = 'http://purl.org/rss/1.0/'; /** - * Feed type constants - */ - const TYPE_ANY = 'any'; - const TYPE_ATOM_03 = 'atom-03'; + * Feed type constants + */ + const TYPE_ANY = 'any'; + const TYPE_ATOM_03 = 'atom-03'; const TYPE_ATOM_10 = 'atom-10'; const TYPE_ATOM_ANY = 'atom'; const TYPE_RSS_090 = 'rss-090'; @@ -53,7 +53,7 @@ class Zend_Feed_Writer const TYPE_RSS_10 = 'rss-10'; const TYPE_RSS_20 = 'rss-20'; const TYPE_RSS_ANY = 'rss'; - + /** * PluginLoader instance used by component * @@ -81,7 +81,7 @@ class Zend_Feed_Writer 'entryRenderer' => array(), 'feedRenderer' => array(), ); - + /** * Set plugin loader for use with Extensions * @@ -257,7 +257,7 @@ class Zend_Feed_Writer self::registerExtension('Threading'); self::registerExtension('ITunes'); } - + public static function lcfirst($str) { $str[0] = strtolower($str[0]); diff --git a/libs/Zend/Feed/Writer/Deleted.php b/libs/Zend/Feed/Writer/Deleted.php index 19bb56b49e..9079366a21 100644 --- a/libs/Zend/Feed/Writer/Deleted.php +++ b/libs/Zend/Feed/Writer/Deleted.php @@ -16,11 +16,11 @@ * @package Zend_Feed_Writer * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Feed.php 20096 2010-01-06 02:05:09Z bkarwin $ + * @version $Id: Deleted.php 23484 2010-12-10 03:57:59Z mjh_ca $ */ // require_once 'Zend/Feed/Writer/Feed/FeedAbstract.php'; - + /** * @category Zend * @package Zend_Feed_Writer @@ -36,7 +36,7 @@ class Zend_Feed_Writer_Deleted * @var array */ protected $_data = array(); - + /** * Holds the value "atom" or "rss" depending on the feed type set when * when last exported. @@ -44,7 +44,7 @@ class Zend_Feed_Writer_Deleted * @var string */ protected $_type = null; - + /** * Set the feed character encoding * @@ -71,7 +71,7 @@ class Zend_Feed_Writer_Deleted } return $this->_data['encoding']; } - + /** * Unset a specific data point * @@ -83,7 +83,7 @@ class Zend_Feed_Writer_Deleted unset($this->_data[$name]); } } - + /** * Set the current feed type being exported to "rss" or "atom". This allows * other objects to gracefully choose whether to execute or not, depending @@ -95,7 +95,7 @@ class Zend_Feed_Writer_Deleted { $this->_type = $type; } - + /** * Retrieve the current or last feed type exported. * @@ -105,7 +105,7 @@ class Zend_Feed_Writer_Deleted { return $this->_type; } - + public function setReference($reference) { if (empty($reference) || !is_string($reference)) { @@ -114,7 +114,7 @@ class Zend_Feed_Writer_Deleted } $this->_data['reference'] = $reference; } - + public function getReference() { if (!array_key_exists('reference', $this->_data)) { @@ -122,11 +122,11 @@ class Zend_Feed_Writer_Deleted } return $this->_data['reference']; } - + public function setWhen($date = null) { $zdate = null; - if (is_null($date)) { + if ($date === null) { $zdate = new Zend_Date; } elseif (ctype_digit($date) && strlen($date) == 10) { $zdate = new Zend_Date($date, Zend_Date::TIMESTAMP); @@ -138,7 +138,7 @@ class Zend_Feed_Writer_Deleted } $this->_data['when'] = $zdate; } - + public function getWhen() { if (!array_key_exists('when', $this->_data)) { @@ -146,12 +146,12 @@ class Zend_Feed_Writer_Deleted } return $this->_data['when']; } - + public function setBy(array $by) { $author = array(); - if (!array_key_exists('name', $by) - || empty($by['name']) + if (!array_key_exists('name', $by) + || empty($by['name']) || !is_string($by['name']) ) { // require_once 'Zend/Feed/Exception.php'; @@ -166,8 +166,8 @@ class Zend_Feed_Writer_Deleted $author['email'] = $by['email']; } if (isset($by['uri'])) { - if (empty($by['uri']) - || !is_string($by['uri']) + if (empty($by['uri']) + || !is_string($by['uri']) || !Zend_Uri::check($by['uri']) ) { // require_once 'Zend/Feed/Exception.php'; @@ -177,7 +177,7 @@ class Zend_Feed_Writer_Deleted } $this->_data['by'] = $author; } - + public function getBy() { if (!array_key_exists('by', $this->_data)) { @@ -185,12 +185,12 @@ class Zend_Feed_Writer_Deleted } return $this->_data['by']; } - + public function setComment($comment) { $this->_data['comment'] = $comment; } - + public function getComment() { if (!array_key_exists('comment', $this->_data)) { diff --git a/libs/Zend/Feed/Writer/Entry.php b/libs/Zend/Feed/Writer/Entry.php index 01d290e6fb..cd667dbed2 100644 --- a/libs/Zend/Feed/Writer/Entry.php +++ b/libs/Zend/Feed/Writer/Entry.php @@ -16,7 +16,7 @@ * @package Zend_Feed_Writer * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Entry.php 22065 2010-04-30 14:04:57Z padraic $ + * @version $Id: Entry.php 23484 2010-12-10 03:57:59Z mjh_ca $ */ /** @@ -46,14 +46,14 @@ class Zend_Feed_Writer_Entry * @var array */ protected $_data = array(); - + /** * Registered extensions * * @var array */ protected $_extensions = array(); - + /** * Holds the value "atom" or "rss" depending on the feed type set when * when last exported. @@ -61,7 +61,7 @@ class Zend_Feed_Writer_Entry * @var string */ protected $_type = null; - + /** * Constructor: Primarily triggers the registration of core extensions and * loads those appropriate to this data container. @@ -84,8 +84,8 @@ class Zend_Feed_Writer_Entry { $author = array(); if (is_array($name)) { - if (!array_key_exists('name', $name) - || empty($name['name']) + if (!array_key_exists('name', $name) + || empty($name['name']) || !is_string($name['name']) ) { // require_once 'Zend/Feed/Exception.php'; @@ -100,8 +100,8 @@ class Zend_Feed_Writer_Entry $author['email'] = $name['email']; } if (isset($name['uri'])) { - if (empty($name['uri']) - || !is_string($name['uri']) + if (empty($name['uri']) + || !is_string($name['uri']) || !Zend_Uri::check($name['uri']) ) { // require_once 'Zend/Feed/Exception.php'; @@ -148,7 +148,7 @@ class Zend_Feed_Writer_Entry $this->addAuthor($author); } } - + /** * Set the feed character encoding * @@ -212,7 +212,7 @@ class Zend_Feed_Writer_Entry public function setDateCreated($date = null) { $zdate = null; - if (is_null($date)) { + if ($date === null) { $zdate = new Zend_Date; } elseif (ctype_digit($date) && strlen($date) == 10) { $zdate = new Zend_Date($date, Zend_Date::TIMESTAMP); @@ -233,7 +233,7 @@ class Zend_Feed_Writer_Entry public function setDateModified($date = null) { $zdate = null; - if (is_null($date)) { + if ($date === null) { $zdate = new Zend_Date; } elseif (ctype_digit($date) && strlen($date) == 10) { $zdate = new Zend_Date($date, Zend_Date::TIMESTAMP); @@ -337,7 +337,7 @@ class Zend_Feed_Writer_Entry } $this->_data['commentFeedLinks'][] = $link; } - + /** * Set a links to an XML feed for any comments associated with this entry. * Each link is an array with keys "uri" and "type", where type is one of: @@ -456,7 +456,7 @@ class Zend_Feed_Writer_Entry } return $this->_data['id']; } - + /** * Get a link to the HTML source * @@ -536,12 +536,12 @@ class Zend_Feed_Writer_Entry } return $this->_data['commentFeedLinks']; } - + /** * Add a entry category * * @param string $category - */ + */ public function addCategory(array $category) { if (!isset($category['term'])) { @@ -551,7 +551,7 @@ class Zend_Feed_Writer_Entry . ' readable category name'); } if (isset($category['scheme'])) { - if (empty($category['scheme']) + if (empty($category['scheme']) || !is_string($category['scheme']) || !Zend_Uri::check($category['scheme']) ) { @@ -565,7 +565,7 @@ class Zend_Feed_Writer_Entry } $this->_data['categories'][] = $category; } - + /** * Set an array of entry categories * @@ -577,7 +577,7 @@ class Zend_Feed_Writer_Entry $this->addCategory($category); } } - + /** * Get the entry categories * @@ -590,7 +590,7 @@ class Zend_Feed_Writer_Entry } return $this->_data['categories']; } - + /** * Adds an enclosure to the entry. The array parameter may contain the * keys 'uri', 'type' and 'length'. Only 'uri' is required for Atom, though the @@ -611,7 +611,7 @@ class Zend_Feed_Writer_Entry } $this->_data['enclosure'] = $enclosure; } - + /** * Retrieve an array of all enclosures to be added to entry. * @@ -624,7 +624,7 @@ class Zend_Feed_Writer_Entry } return $this->_data['enclosure']; } - + /** * Unset a specific data point * @@ -636,7 +636,7 @@ class Zend_Feed_Writer_Entry unset($this->_data[$name]); } } - + /** * Get registered extensions * @@ -660,7 +660,7 @@ class Zend_Feed_Writer_Entry } return null; } - + /** * Set the current feed type being exported to "rss" or "atom". This allows * other objects to gracefully choose whether to execute or not, depending @@ -672,7 +672,7 @@ class Zend_Feed_Writer_Entry { $this->_type = $type; } - + /** * Retrieve the current or last feed type exported. * @@ -703,7 +703,7 @@ class Zend_Feed_Writer_Entry throw new Zend_Feed_Exception('Method: ' . $method . ' does not exist and could not be located on a registered Extension'); } - + /** * Creates a new Zend_Feed_Writer_Source data container for use. This is NOT * added to the current feed automatically, but is necessary to create a @@ -731,7 +731,7 @@ class Zend_Feed_Writer_Entry { $this->_data['source'] = $source; } - + /** * @return Zend_Feed_Writer_Source */ diff --git a/libs/Zend/Feed/Writer/Extension/Atom/Renderer/Feed.php b/libs/Zend/Feed/Writer/Extension/Atom/Renderer/Feed.php index 588a57af66..285c8ec2e1 100644 --- a/libs/Zend/Feed/Writer/Extension/Atom/Renderer/Feed.php +++ b/libs/Zend/Feed/Writer/Extension/Atom/Renderer/Feed.php @@ -16,14 +16,14 @@ * @package Zend_Feed_Writer * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Feed.php 20326 2010-01-16 00:20:43Z padraic $ + * @version $Id: Feed.php 23484 2010-12-10 03:57:59Z mjh_ca $ */ - + /** * @see Zend_Feed_Writer_Extension_RendererAbstract */ // require_once 'Zend/Feed/Writer/Extension/RendererAbstract.php'; - + /** * @category Zend * @package Zend_Feed_Writer @@ -42,10 +42,10 @@ class Zend_Feed_Writer_Extension_Atom_Renderer_Feed * @var bool */ protected $_called = false; - + /** * Render feed - * + * * @return void */ public function render() @@ -63,23 +63,23 @@ class Zend_Feed_Writer_Extension_Atom_Renderer_Feed $this->_appendNamespaces(); } } - + /** * Append namespaces to root element of feed - * + * * @return void */ protected function _appendNamespaces() { $this->getRootElement()->setAttribute('xmlns:atom', - 'http://www.w3.org/2005/Atom'); + 'http://www.w3.org/2005/Atom'); } /** * Set feed link elements - * - * @param DOMDocument $dom - * @param DOMElement $root + * + * @param DOMDocument $dom + * @param DOMElement $root * @return void */ protected function _setFeedLinks(DOMDocument $dom, DOMElement $root) @@ -98,12 +98,12 @@ class Zend_Feed_Writer_Extension_Atom_Renderer_Feed } $this->_called = true; } - + /** * Set PuSH hubs - * - * @param DOMDocument $dom - * @param DOMElement $root + * + * @param DOMDocument $dom + * @param DOMElement $root * @return void */ protected function _setHubs(DOMDocument $dom, DOMElement $root) diff --git a/libs/Zend/Feed/Writer/Extension/Content/Renderer/Entry.php b/libs/Zend/Feed/Writer/Extension/Content/Renderer/Entry.php index 0036c6325e..f19018f600 100644 --- a/libs/Zend/Feed/Writer/Extension/Content/Renderer/Entry.php +++ b/libs/Zend/Feed/Writer/Extension/Content/Renderer/Entry.php @@ -16,14 +16,14 @@ * @package Zend_Feed_Writer * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Entry.php 20326 2010-01-16 00:20:43Z padraic $ + * @version $Id: Entry.php 23484 2010-12-10 03:57:59Z mjh_ca $ */ - + /** * @see Zend_Feed_Writer_Extension_RendererAbstract */ // require_once 'Zend/Feed/Writer/Extension/RendererAbstract.php'; - + /** * @category Zend * @package Zend_Feed_Writer @@ -42,10 +42,10 @@ class Zend_Feed_Writer_Extension_Content_Renderer_Entry * @var bool */ protected $_called = false; - + /** * Render entry - * + * * @return void */ public function render() @@ -58,23 +58,23 @@ class Zend_Feed_Writer_Extension_Content_Renderer_Entry $this->_appendNamespaces(); } } - + /** * Append namespaces to root element - * + * * @return void */ protected function _appendNamespaces() { $this->getRootElement()->setAttribute('xmlns:content', - 'http://purl.org/rss/1.0/modules/content/'); + 'http://purl.org/rss/1.0/modules/content/'); } /** * Set entry content - * - * @param DOMDocument $dom - * @param DOMElement $root + * + * @param DOMDocument $dom + * @param DOMElement $root * @return void */ protected function _setContent(DOMDocument $dom, DOMElement $root) diff --git a/libs/Zend/Feed/Writer/Extension/DublinCore/Renderer/Entry.php b/libs/Zend/Feed/Writer/Extension/DublinCore/Renderer/Entry.php index c433ea3a6c..8dd6660ff3 100644 --- a/libs/Zend/Feed/Writer/Extension/DublinCore/Renderer/Entry.php +++ b/libs/Zend/Feed/Writer/Extension/DublinCore/Renderer/Entry.php @@ -16,14 +16,14 @@ * @package Zend_Feed_Writer * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Entry.php 20326 2010-01-16 00:20:43Z padraic $ + * @version $Id: Entry.php 23484 2010-12-10 03:57:59Z mjh_ca $ */ - + /** * @see Zend_Feed_Writer_Extension_RendererAbstract */ // require_once 'Zend/Feed/Writer/Extension/RendererAbstract.php'; - + /** * @category Zend * @package Zend_Feed_Writer @@ -42,10 +42,10 @@ class Zend_Feed_Writer_Extension_DublinCore_Renderer_Entry * @var bool */ protected $_called = false; - + /** * Render entry - * + * * @return void */ public function render() @@ -58,23 +58,23 @@ class Zend_Feed_Writer_Extension_DublinCore_Renderer_Entry $this->_appendNamespaces(); } } - + /** * Append namespaces to entry - * + * * @return void */ protected function _appendNamespaces() { $this->getRootElement()->setAttribute('xmlns:dc', - 'http://purl.org/dc/elements/1.1/'); + 'http://purl.org/dc/elements/1.1/'); } /** * Set entry author elements - * - * @param DOMDocument $dom - * @param DOMElement $root + * + * @param DOMDocument $dom + * @param DOMElement $root * @return void */ protected function _setAuthors(DOMDocument $dom, DOMElement $root) @@ -88,7 +88,7 @@ class Zend_Feed_Writer_Extension_DublinCore_Renderer_Entry if (array_key_exists('name', $data)) { $text = $dom->createTextNode($data['name']); $author->appendChild($text); - $root->appendChild($author); + $root->appendChild($author); } } $this->_called = true; diff --git a/libs/Zend/Feed/Writer/Extension/DublinCore/Renderer/Feed.php b/libs/Zend/Feed/Writer/Extension/DublinCore/Renderer/Feed.php index e1a0105019..9b9db5321d 100644 --- a/libs/Zend/Feed/Writer/Extension/DublinCore/Renderer/Feed.php +++ b/libs/Zend/Feed/Writer/Extension/DublinCore/Renderer/Feed.php @@ -16,14 +16,14 @@ * @package Zend_Feed_Writer * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Feed.php 20326 2010-01-16 00:20:43Z padraic $ + * @version $Id: Feed.php 23484 2010-12-10 03:57:59Z mjh_ca $ */ - + /** * @see Zend_Feed_Writer_Extension_RendererAbstract */ // require_once 'Zend/Feed/Writer/Extension/RendererAbstract.php'; - + /** * @category Zend * @package Zend_Feed_Writer @@ -42,10 +42,10 @@ class Zend_Feed_Writer_Extension_DublinCore_Renderer_Feed * @var bool */ protected $_called = false; - + /** * Render feed - * + * * @return void */ public function render() @@ -58,23 +58,23 @@ class Zend_Feed_Writer_Extension_DublinCore_Renderer_Feed $this->_appendNamespaces(); } } - + /** * Append namespaces to feed element - * + * * @return void */ protected function _appendNamespaces() { $this->getRootElement()->setAttribute('xmlns:dc', - 'http://purl.org/dc/elements/1.1/'); + 'http://purl.org/dc/elements/1.1/'); } /** * Set feed authors - * - * @param DOMDocument $dom - * @param DOMElement $root + * + * @param DOMDocument $dom + * @param DOMElement $root * @return void */ protected function _setAuthors(DOMDocument $dom, DOMElement $root) @@ -88,7 +88,7 @@ class Zend_Feed_Writer_Extension_DublinCore_Renderer_Feed if (array_key_exists('name', $data)) { $text = $dom->createTextNode($data['name']); $author->appendChild($text); - $root->appendChild($author); + $root->appendChild($author); } } $this->_called = true; diff --git a/libs/Zend/Feed/Writer/Extension/ITunes/Entry.php b/libs/Zend/Feed/Writer/Extension/ITunes/Entry.php index 1d7fbc5070..be4963150f 100644 --- a/libs/Zend/Feed/Writer/Extension/ITunes/Entry.php +++ b/libs/Zend/Feed/Writer/Extension/ITunes/Entry.php @@ -16,9 +16,9 @@ * @package Zend_Feed_Writer * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Entry.php 20096 2010-01-06 02:05:09Z bkarwin $ + * @version $Id: Entry.php 23484 2010-12-10 03:57:59Z mjh_ca $ */ - + /** * @category Zend * @package Zend_Feed_Writer @@ -33,18 +33,18 @@ class Zend_Feed_Writer_Extension_ITunes_Entry * @var array */ protected $_data = array(); - + /** * Encoding of all text values * * @var string */ protected $_encoding = 'UTF-8'; - + /** * Set feed encoding - * - * @param string $enc + * + * @param string $enc * @return Zend_Feed_Writer_Extension_ITunes_Entry */ public function setEncoding($enc) @@ -52,17 +52,17 @@ class Zend_Feed_Writer_Extension_ITunes_Entry $this->_encoding = $enc; return $this; } - + /** * Get feed encoding - * + * * @return string */ public function getEncoding() { return $this->_encoding; } - + /** * Set a block value of "yes" or "no". You may also set an empty string. * @@ -83,11 +83,11 @@ class Zend_Feed_Writer_Extension_ITunes_Entry } $this->_data['block'] = $value; } - + /** * Add authors to itunes entry - * - * @param array $values + * + * @param array $values * @return Zend_Feed_Writer_Extension_ITunes_Entry */ public function addItunesAuthors(array $values) @@ -97,11 +97,11 @@ class Zend_Feed_Writer_Extension_ITunes_Entry } return $this; } - + /** * Add author to itunes entry - * - * @param string $value + * + * @param string $value * @return Zend_Feed_Writer_Extension_ITunes_Entry */ public function addItunesAuthor($value) @@ -114,14 +114,14 @@ class Zend_Feed_Writer_Extension_ITunes_Entry if (!isset($this->_data['authors'])) { $this->_data['authors'] = array(); } - $this->_data['authors'][] = $value; + $this->_data['authors'][] = $value; return $this; } - + /** * Set duration - * - * @param int $value + * + * @param int $value * @return Zend_Feed_Writer_Extension_ITunes_Entry */ public function setItunesDuration($value) @@ -138,11 +138,11 @@ class Zend_Feed_Writer_Extension_ITunes_Entry $this->_data['duration'] = $value; return $this; } - + /** * Set "explicit" flag - * - * @param bool $value + * + * @param bool $value * @return Zend_Feed_Writer_Extension_ITunes_Entry */ public function setItunesExplicit($value) @@ -155,11 +155,11 @@ class Zend_Feed_Writer_Extension_ITunes_Entry $this->_data['explicit'] = $value; return $this; } - + /** * Set keywords - * - * @param array $value + * + * @param array $value * @return Zend_Feed_Writer_Extension_ITunes_Entry */ public function setItunesKeywords(array $value) @@ -179,11 +179,11 @@ class Zend_Feed_Writer_Extension_ITunes_Entry $this->_data['keywords'] = $value; return $this; } - + /** * Set subtitle - * - * @param string $value + * + * @param string $value * @return Zend_Feed_Writer_Extension_ITunes_Entry */ public function setItunesSubtitle($value) @@ -196,11 +196,11 @@ class Zend_Feed_Writer_Extension_ITunes_Entry $this->_data['subtitle'] = $value; return $this; } - + /** * Set summary - * - * @param string $value + * + * @param string $value * @return Zend_Feed_Writer_Extension_ITunes_Entry */ public function setItunesSummary($value) @@ -213,12 +213,12 @@ class Zend_Feed_Writer_Extension_ITunes_Entry $this->_data['summary'] = $value; return $this; } - + /** * Overloading to itunes specific setters - * - * @param string $method - * @param array $params + * + * @param string $method + * @param array $params * @return mixed */ public function __call($method, array $params) @@ -232,7 +232,7 @@ class Zend_Feed_Writer_Extension_ITunes_Entry 'invalid method: ' . $method ); } - if (!array_key_exists($point, $this->_data) + if (!array_key_exists($point, $this->_data) || empty($this->_data[$point]) ) { return null; diff --git a/libs/Zend/Feed/Writer/Extension/ITunes/Feed.php b/libs/Zend/Feed/Writer/Extension/ITunes/Feed.php index caf0440a03..5969fd68f7 100644 --- a/libs/Zend/Feed/Writer/Extension/ITunes/Feed.php +++ b/libs/Zend/Feed/Writer/Extension/ITunes/Feed.php @@ -16,9 +16,9 @@ * @package Zend_Feed_Writer * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Feed.php 20096 2010-01-06 02:05:09Z bkarwin $ + * @version $Id: Feed.php 23484 2010-12-10 03:57:59Z mjh_ca $ */ - + /** * @category Zend * @package Zend_Feed_Writer @@ -33,18 +33,18 @@ class Zend_Feed_Writer_Extension_ITunes_Feed * @var array */ protected $_data = array(); - + /** * Encoding of all text values * * @var string */ protected $_encoding = 'UTF-8'; - + /** * Set feed encoding - * - * @param string $enc + * + * @param string $enc * @return Zend_Feed_Writer_Extension_ITunes_Feed */ public function setEncoding($enc) @@ -52,17 +52,17 @@ class Zend_Feed_Writer_Extension_ITunes_Feed $this->_encoding = $enc; return $this; } - + /** * Get feed encoding - * + * * @return string */ public function getEncoding() { return $this->_encoding; } - + /** * Set a block value of "yes" or "no". You may also set an empty string. * @@ -84,11 +84,11 @@ class Zend_Feed_Writer_Extension_ITunes_Feed $this->_data['block'] = $value; return $this; } - + /** * Add feed authors - * - * @param array $values + * + * @param array $values * @return Zend_Feed_Writer_Extension_ITunes_Feed */ public function addItunesAuthors(array $values) @@ -98,11 +98,11 @@ class Zend_Feed_Writer_Extension_ITunes_Feed } return $this; } - + /** * Add feed author - * - * @param string $value + * + * @param string $value * @return Zend_Feed_Writer_Extension_ITunes_Feed */ public function addItunesAuthor($value) @@ -115,14 +115,14 @@ class Zend_Feed_Writer_Extension_ITunes_Feed if (!isset($this->_data['authors'])) { $this->_data['authors'] = array(); } - $this->_data['authors'][] = $value; + $this->_data['authors'][] = $value; return $this; } - + /** * Set feed categories - * - * @param array $values + * + * @param array $values * @return Zend_Feed_Writer_Extension_ITunes_Feed */ public function setItunesCategories(array $values) @@ -152,16 +152,16 @@ class Zend_Feed_Writer_Extension_ITunes_Feed . ' contain a maximum of 255 characters each'); } $this->_data['categories'][$key][] = $val; - } + } } } return $this; } - + /** * Set feed image (icon) - * - * @param string $value + * + * @param string $value * @return Zend_Feed_Writer_Extension_ITunes_Feed */ public function setItunesImage($value) @@ -180,11 +180,11 @@ class Zend_Feed_Writer_Extension_ITunes_Feed $this->_data['image'] = $value; return $this; } - + /** * Set feed cumulative duration - * - * @param string $value + * + * @param string $value * @return Zend_Feed_Writer_Extension_ITunes_Feed */ public function setItunesDuration($value) @@ -201,11 +201,11 @@ class Zend_Feed_Writer_Extension_ITunes_Feed $this->_data['duration'] = $value; return $this; } - + /** * Set "explicit" flag - * - * @param bool $value + * + * @param bool $value * @return Zend_Feed_Writer_Extension_ITunes_Feed */ public function setItunesExplicit($value) @@ -218,11 +218,11 @@ class Zend_Feed_Writer_Extension_ITunes_Feed $this->_data['explicit'] = $value; return $this; } - + /** * Set feed keywords - * - * @param array $value + * + * @param array $value * @return Zend_Feed_Writer_Extension_ITunes_Feed */ public function setItunesKeywords(array $value) @@ -242,11 +242,11 @@ class Zend_Feed_Writer_Extension_ITunes_Feed $this->_data['keywords'] = $value; return $this; } - + /** * Set new feed URL - * - * @param string $value + * + * @param string $value * @return Zend_Feed_Writer_Extension_ITunes_Feed */ public function setItunesNewFeedUrl($value) @@ -259,25 +259,25 @@ class Zend_Feed_Writer_Extension_ITunes_Feed $this->_data['newFeedUrl'] = $value; return $this; } - + /** * Add feed owners - * - * @param array $values + * + * @param array $values * @return Zend_Feed_Writer_Extension_ITunes_Feed */ public function addItunesOwners(array $values) { foreach ($values as $value) { - $this->addItunesOwner($value); + $this->addItunesOwner($value); } return $this; } - + /** * Add feed owner - * - * @param string $value + * + * @param string $value * @return Zend_Feed_Writer_Extension_ITunes_Feed */ public function addItunesOwner(array $value) @@ -300,11 +300,11 @@ class Zend_Feed_Writer_Extension_ITunes_Feed $this->_data['owners'][] = $value; return $this; } - + /** * Set feed subtitle - * - * @param string $value + * + * @param string $value * @return Zend_Feed_Writer_Extension_ITunes_Feed */ public function setItunesSubtitle($value) @@ -317,11 +317,11 @@ class Zend_Feed_Writer_Extension_ITunes_Feed $this->_data['subtitle'] = $value; return $this; } - + /** * Set feed summary - * - * @param string $value + * + * @param string $value * @return Zend_Feed_Writer_Extension_ITunes_Feed */ public function setItunesSummary($value) @@ -334,12 +334,12 @@ class Zend_Feed_Writer_Extension_ITunes_Feed $this->_data['summary'] = $value; return $this; } - + /** * Overloading: proxy to internal setters - * - * @param string $method - * @param array $params + * + * @param string $method + * @param array $params * @return mixed */ public function __call($method, array $params) diff --git a/libs/Zend/Feed/Writer/Extension/ITunes/Renderer/Entry.php b/libs/Zend/Feed/Writer/Extension/ITunes/Renderer/Entry.php index 046cb546fb..7783e3972f 100644 --- a/libs/Zend/Feed/Writer/Extension/ITunes/Renderer/Entry.php +++ b/libs/Zend/Feed/Writer/Extension/ITunes/Renderer/Entry.php @@ -16,14 +16,14 @@ * @package Zend_Feed_Writer * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Entry.php 20326 2010-01-16 00:20:43Z padraic $ + * @version $Id: Entry.php 23484 2010-12-10 03:57:59Z mjh_ca $ */ - + /** * @see Zend_Feed_Writer_Extension_RendererAbstract */ // require_once 'Zend/Feed/Writer/Extension/RendererAbstract.php'; - + /** * @category Zend * @package Zend_Feed_Writer @@ -41,10 +41,10 @@ class Zend_Feed_Writer_Extension_ITunes_Renderer_Entry * @var bool */ protected $_called = false; - + /** * Render entry - * + * * @return void */ public function render() @@ -60,23 +60,23 @@ class Zend_Feed_Writer_Extension_ITunes_Renderer_Entry $this->_appendNamespaces(); } } - + /** * Append namespaces to entry root - * + * * @return void */ protected function _appendNamespaces() { $this->getRootElement()->setAttribute('xmlns:itunes', - 'http://www.itunes.com/dtds/podcast-1.0.dtd'); + 'http://www.itunes.com/dtds/podcast-1.0.dtd'); } /** * Set entry authors - * - * @param DOMDocument $dom - * @param DOMElement $root + * + * @param DOMDocument $dom + * @param DOMElement $root * @return void */ protected function _setAuthors(DOMDocument $dom, DOMElement $root) @@ -93,18 +93,18 @@ class Zend_Feed_Writer_Extension_ITunes_Renderer_Entry $this->_called = true; } } - + /** * Set itunes block - * - * @param DOMDocument $dom - * @param DOMElement $root + * + * @param DOMDocument $dom + * @param DOMElement $root * @return void */ protected function _setBlock(DOMDocument $dom, DOMElement $root) { $block = $this->getDataContainer()->getItunesBlock(); - if (is_null($block)) { + if ($block === null) { return; } $el = $dom->createElement('itunes:block'); @@ -113,12 +113,12 @@ class Zend_Feed_Writer_Extension_ITunes_Renderer_Entry $root->appendChild($el); $this->_called = true; } - + /** * Set entry duration - * - * @param DOMDocument $dom - * @param DOMElement $root + * + * @param DOMDocument $dom + * @param DOMElement $root * @return void */ protected function _setDuration(DOMDocument $dom, DOMElement $root) @@ -133,18 +133,18 @@ class Zend_Feed_Writer_Extension_ITunes_Renderer_Entry $root->appendChild($el); $this->_called = true; } - + /** * Set explicit flag - * - * @param DOMDocument $dom - * @param DOMElement $root + * + * @param DOMDocument $dom + * @param DOMElement $root * @return void */ protected function _setExplicit(DOMDocument $dom, DOMElement $root) { $explicit = $this->getDataContainer()->getItunesExplicit(); - if (is_null($explicit)) { + if ($explicit === null) { return; } $el = $dom->createElement('itunes:explicit'); @@ -153,12 +153,12 @@ class Zend_Feed_Writer_Extension_ITunes_Renderer_Entry $root->appendChild($el); $this->_called = true; } - + /** * Set entry keywords - * - * @param DOMDocument $dom - * @param DOMElement $root + * + * @param DOMDocument $dom + * @param DOMElement $root * @return void */ protected function _setKeywords(DOMDocument $dom, DOMElement $root) @@ -173,12 +173,12 @@ class Zend_Feed_Writer_Extension_ITunes_Renderer_Entry $root->appendChild($el); $this->_called = true; } - + /** * Set entry subtitle - * - * @param DOMDocument $dom - * @param DOMElement $root + * + * @param DOMDocument $dom + * @param DOMElement $root * @return void */ protected function _setSubtitle(DOMDocument $dom, DOMElement $root) @@ -193,12 +193,12 @@ class Zend_Feed_Writer_Extension_ITunes_Renderer_Entry $root->appendChild($el); $this->_called = true; } - + /** * Set entry summary - * - * @param DOMDocument $dom - * @param DOMElement $root + * + * @param DOMDocument $dom + * @param DOMElement $root * @return void */ protected function _setSummary(DOMDocument $dom, DOMElement $root) diff --git a/libs/Zend/Feed/Writer/Extension/ITunes/Renderer/Feed.php b/libs/Zend/Feed/Writer/Extension/ITunes/Renderer/Feed.php index 192d19ec42..6fc8c0bf22 100644 --- a/libs/Zend/Feed/Writer/Extension/ITunes/Renderer/Feed.php +++ b/libs/Zend/Feed/Writer/Extension/ITunes/Renderer/Feed.php @@ -16,14 +16,14 @@ * @package Zend_Feed_Writer * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Feed.php 20326 2010-01-16 00:20:43Z padraic $ + * @version $Id: Feed.php 23484 2010-12-10 03:57:59Z mjh_ca $ */ - + /** * @see Zend_Feed_Writer_Extension_RendererAbstract */ // require_once 'Zend/Feed/Writer/Extension/RendererAbstract.php'; - + /** * @category Zend * @package Zend_Feed_Writer @@ -33,7 +33,7 @@ class Zend_Feed_Writer_Extension_ITunes_Renderer_Feed extends Zend_Feed_Writer_Extension_RendererAbstract { - + /** * Set to TRUE if a rendering method actually renders something. This * is used to prevent premature appending of a XML namespace declaration @@ -42,10 +42,10 @@ class Zend_Feed_Writer_Extension_ITunes_Renderer_Feed * @var bool */ protected $_called = false; - + /** * Render feed - * + * * @return void */ public function render() @@ -65,23 +65,23 @@ class Zend_Feed_Writer_Extension_ITunes_Renderer_Feed $this->_appendNamespaces(); } } - + /** * Append feed namespaces - * + * * @return void */ protected function _appendNamespaces() { $this->getRootElement()->setAttribute('xmlns:itunes', - 'http://www.itunes.com/dtds/podcast-1.0.dtd'); + 'http://www.itunes.com/dtds/podcast-1.0.dtd'); } /** * Set feed authors - * - * @param DOMDocument $dom - * @param DOMElement $root + * + * @param DOMDocument $dom + * @param DOMElement $root * @return void */ protected function _setAuthors(DOMDocument $dom, DOMElement $root) @@ -98,18 +98,18 @@ class Zend_Feed_Writer_Extension_ITunes_Renderer_Feed } $this->_called = true; } - + /** * Set feed itunes block - * - * @param DOMDocument $dom - * @param DOMElement $root + * + * @param DOMDocument $dom + * @param DOMElement $root * @return void */ protected function _setBlock(DOMDocument $dom, DOMElement $root) { $block = $this->getDataContainer()->getItunesBlock(); - if (is_null($block)) { + if ($block === null) { return; } $el = $dom->createElement('itunes:block'); @@ -118,12 +118,12 @@ class Zend_Feed_Writer_Extension_ITunes_Renderer_Feed $root->appendChild($el); $this->_called = true; } - + /** * Set feed categories - * - * @param DOMDocument $dom - * @param DOMElement $root + * + * @param DOMDocument $dom + * @param DOMElement $root * @return void */ protected function _setCategories(DOMDocument $dom, DOMElement $root) @@ -150,12 +150,12 @@ class Zend_Feed_Writer_Extension_ITunes_Renderer_Feed } $this->_called = true; } - + /** * Set feed image (icon) - * - * @param DOMDocument $dom - * @param DOMElement $root + * + * @param DOMDocument $dom + * @param DOMElement $root * @return void */ protected function _setImage(DOMDocument $dom, DOMElement $root) @@ -169,12 +169,12 @@ class Zend_Feed_Writer_Extension_ITunes_Renderer_Feed $root->appendChild($el); $this->_called = true; } - + /** * Set feed cumulative duration - * - * @param DOMDocument $dom - * @param DOMElement $root + * + * @param DOMDocument $dom + * @param DOMElement $root * @return void */ protected function _setDuration(DOMDocument $dom, DOMElement $root) @@ -189,18 +189,18 @@ class Zend_Feed_Writer_Extension_ITunes_Renderer_Feed $root->appendChild($el); $this->_called = true; } - + /** * Set explicit flag - * - * @param DOMDocument $dom - * @param DOMElement $root + * + * @param DOMDocument $dom + * @param DOMElement $root * @return void */ protected function _setExplicit(DOMDocument $dom, DOMElement $root) { $explicit = $this->getDataContainer()->getItunesExplicit(); - if (is_null($explicit)) { + if ($explicit === null) { return; } $el = $dom->createElement('itunes:explicit'); @@ -209,12 +209,12 @@ class Zend_Feed_Writer_Extension_ITunes_Renderer_Feed $root->appendChild($el); $this->_called = true; } - + /** * Set feed keywords - * - * @param DOMDocument $dom - * @param DOMElement $root + * + * @param DOMDocument $dom + * @param DOMElement $root * @return void */ protected function _setKeywords(DOMDocument $dom, DOMElement $root) @@ -229,12 +229,12 @@ class Zend_Feed_Writer_Extension_ITunes_Renderer_Feed $root->appendChild($el); $this->_called = true; } - + /** * Set feed's new URL - * - * @param DOMDocument $dom - * @param DOMElement $root + * + * @param DOMDocument $dom + * @param DOMElement $root * @return void */ protected function _setNewFeedUrl(DOMDocument $dom, DOMElement $root) @@ -249,12 +249,12 @@ class Zend_Feed_Writer_Extension_ITunes_Renderer_Feed $root->appendChild($el); $this->_called = true; } - + /** - * Set feed owners - * - * @param DOMDocument $dom - * @param DOMElement $root + * Set feed owners + * + * @param DOMDocument $dom + * @param DOMElement $root * @return void */ protected function _setOwners(DOMDocument $dom, DOMElement $root) @@ -277,12 +277,12 @@ class Zend_Feed_Writer_Extension_ITunes_Renderer_Feed } $this->_called = true; } - + /** * Set feed subtitle - * - * @param DOMDocument $dom - * @param DOMElement $root + * + * @param DOMDocument $dom + * @param DOMElement $root * @return void */ protected function _setSubtitle(DOMDocument $dom, DOMElement $root) @@ -297,12 +297,12 @@ class Zend_Feed_Writer_Extension_ITunes_Renderer_Feed $root->appendChild($el); $this->_called = true; } - + /** * Set feed summary - * - * @param DOMDocument $dom - * @param DOMElement $root + * + * @param DOMDocument $dom + * @param DOMElement $root * @return void */ protected function _setSummary(DOMDocument $dom, DOMElement $root) diff --git a/libs/Zend/Feed/Writer/Extension/RendererAbstract.php b/libs/Zend/Feed/Writer/Extension/RendererAbstract.php index b381be3657..edca065c17 100644 --- a/libs/Zend/Feed/Writer/Extension/RendererAbstract.php +++ b/libs/Zend/Feed/Writer/Extension/RendererAbstract.php @@ -16,13 +16,14 @@ * @package Zend_Feed_Writer_Entry_Rss * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License + * @version $Id: RendererAbstract.php 23484 2010-12-10 03:57:59Z mjh_ca $ */ - + /** * @see Zend_Feed_Writer_Extension_RendererInterface */ // require_once 'Zend/Feed/Writer/Extension/RendererInterface.php'; - + /** * @category Zend * @package Zend_Feed_Writer_Entry_Rss @@ -36,32 +37,32 @@ abstract class Zend_Feed_Writer_Extension_RendererAbstract * @var DOMDocument */ protected $_dom = null; - + /** * @var mixed */ protected $_entry = null; - + /** * @var DOMElement */ protected $_base = null; - + /** * @var mixed */ protected $_container = null; - + /** * @var string */ protected $_type = null; - + /** * @var DOMElement */ protected $_rootElement = null; - + /** * Encoding of all text values * @@ -71,19 +72,19 @@ abstract class Zend_Feed_Writer_Extension_RendererAbstract /** * Constructor - * - * @param mixed $container + * + * @param mixed $container * @return void */ public function __construct($container) { $this->_container = $container; } - + /** * Set feed encoding - * - * @param string $enc + * + * @param string $enc * @return Zend_Feed_Writer_Extension_RendererAbstract */ public function setEncoding($enc) @@ -91,22 +92,22 @@ abstract class Zend_Feed_Writer_Extension_RendererAbstract $this->_encoding = $enc; return $this; } - + /** * Get feed encoding - * + * * @return void */ public function getEncoding() { return $this->_encoding; } - + /** * Set DOMDocument and DOMElement on which to operate - * - * @param DOMDocument $dom - * @param DOMElement $base + * + * @param DOMDocument $dom + * @param DOMElement $base * @return Zend_Feed_Writer_Extension_RendererAbstract */ public function setDomDocument(DOMDocument $dom, DOMElement $base) @@ -115,21 +116,21 @@ abstract class Zend_Feed_Writer_Extension_RendererAbstract $this->_base = $base; return $this; } - + /** * Get data container being rendered - * + * * @return mixed */ public function getDataContainer() { return $this->_container; } - + /** * Set feed type - * - * @param string $type + * + * @param string $type * @return Zend_Feed_Writer_Extension_RendererAbstract */ public function setType($type) @@ -137,21 +138,21 @@ abstract class Zend_Feed_Writer_Extension_RendererAbstract $this->_type = $type; return $this; } - + /** * Get feedtype - * + * * @return string */ public function getType() { return $this->_type; } - + /** - * Set root element of document - * - * @param DOMElement $root + * Set root element of document + * + * @param DOMElement $root * @return Zend_Feed_Writer_Extension_RendererAbstract */ public function setRootElement(DOMElement $root) @@ -159,20 +160,20 @@ abstract class Zend_Feed_Writer_Extension_RendererAbstract $this->_rootElement = $root; return $this; } - + /** * Get root element - * + * * @return DOMElement */ public function getRootElement() { return $this->_rootElement; } - + /** * Append namespaces to feed - * + * * @return void */ abstract protected function _appendNamespaces(); diff --git a/libs/Zend/Feed/Writer/Extension/RendererInterface.php b/libs/Zend/Feed/Writer/Extension/RendererInterface.php index e9c9014176..4c5477261c 100644 --- a/libs/Zend/Feed/Writer/Extension/RendererInterface.php +++ b/libs/Zend/Feed/Writer/Extension/RendererInterface.php @@ -16,6 +16,7 @@ * @package Zend_Feed_Writer * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License + * @version $Id: RendererInterface.php 23484 2010-12-10 03:57:59Z mjh_ca $ */ /** @@ -29,30 +30,30 @@ interface Zend_Feed_Writer_Extension_RendererInterface /** * Constructor * - * @param mixed $container + * @param mixed $container * @return void */ public function __construct($container); - + /** * Set DOMDocument and DOMElement on which to operate - * - * @param DOMDocument $dom - * @param DOMElement $base + * + * @param DOMDocument $dom + * @param DOMElement $base * @return void */ public function setDomDocument(DOMDocument $dom, DOMElement $base); - + /** * Render - * + * * @return void */ public function render(); - + /** * Retrieve container - * + * * @return mixed */ public function getDataContainer(); diff --git a/libs/Zend/Feed/Writer/Extension/Slash/Renderer/Entry.php b/libs/Zend/Feed/Writer/Extension/Slash/Renderer/Entry.php index 2814775551..106a0548bc 100644 --- a/libs/Zend/Feed/Writer/Extension/Slash/Renderer/Entry.php +++ b/libs/Zend/Feed/Writer/Extension/Slash/Renderer/Entry.php @@ -16,14 +16,14 @@ * @package Zend_Feed_Writer * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Entry.php 20326 2010-01-16 00:20:43Z padraic $ + * @version $Id: Entry.php 23484 2010-12-10 03:57:59Z mjh_ca $ */ - + /** * @see Zend_Feed_Writer_Extension_RendererAbstract */ // require_once 'Zend/Feed/Writer/Extension/RendererAbstract.php'; - + /** * @category Zend * @package Zend_Feed_Writer @@ -42,10 +42,10 @@ class Zend_Feed_Writer_Extension_Slash_Renderer_Entry * @var bool */ protected $_called = false; - + /** * Render entry - * + * * @return void */ public function render() @@ -58,30 +58,30 @@ class Zend_Feed_Writer_Extension_Slash_Renderer_Entry $this->_appendNamespaces(); } } - + /** * Append entry namespaces - * + * * @return void */ protected function _appendNamespaces() { $this->getRootElement()->setAttribute('xmlns:slash', - 'http://purl.org/rss/1.0/modules/slash/'); + 'http://purl.org/rss/1.0/modules/slash/'); } /** * Set entry comment count - * - * @param DOMDocument $dom - * @param DOMElement $root + * + * @param DOMDocument $dom + * @param DOMElement $root * @return void */ protected function _setCommentCount(DOMDocument $dom, DOMElement $root) { $count = $this->getDataContainer()->getCommentCount(); if (!$count) { - $count = 0; + return; } $tcount = $this->_dom->createElement('slash:comments'); $tcount->nodeValue = $count; diff --git a/libs/Zend/Feed/Writer/Extension/Threading/Renderer/Entry.php b/libs/Zend/Feed/Writer/Extension/Threading/Renderer/Entry.php index 69e731d4ba..37127f475f 100644 --- a/libs/Zend/Feed/Writer/Extension/Threading/Renderer/Entry.php +++ b/libs/Zend/Feed/Writer/Extension/Threading/Renderer/Entry.php @@ -16,14 +16,14 @@ * @package Zend_Feed_Writer * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Entry.php 20326 2010-01-16 00:20:43Z padraic $ + * @version $Id: Entry.php 23484 2010-12-10 03:57:59Z mjh_ca $ */ - + /** * @see Zend_Feed_Writer_Extension_RendererAbstract */ // require_once 'Zend/Feed/Writer/Extension/RendererAbstract.php'; - + /** * @category Zend * @package Zend_Feed_Writer @@ -42,10 +42,10 @@ class Zend_Feed_Writer_Extension_Threading_Renderer_Entry * @var bool */ protected $_called = false; - + /** * Render entry - * + * * @return void */ public function render() @@ -60,23 +60,23 @@ class Zend_Feed_Writer_Extension_Threading_Renderer_Entry $this->_appendNamespaces(); } } - + /** * Append entry namespaces - * + * * @return void */ protected function _appendNamespaces() { $this->getRootElement()->setAttribute('xmlns:thr', - 'http://purl.org/syndication/thread/1.0'); + 'http://purl.org/syndication/thread/1.0'); } - + /** * Set comment link - * - * @param DOMDocument $dom - * @param DOMElement $root + * + * @param DOMDocument $dom + * @param DOMElement $root * @return void */ protected function _setCommentLink(DOMDocument $dom, DOMElement $root) @@ -90,18 +90,18 @@ class Zend_Feed_Writer_Extension_Threading_Renderer_Entry $clink->setAttribute('type', 'text/html'); $clink->setAttribute('href', $link); $count = $this->getDataContainer()->getCommentCount(); - if (!is_null($count)) { + if ($count !== null) { $clink->setAttribute('thr:count', $count); } $root->appendChild($clink); $this->_called = true; } - + /** * Set comment feed links - * - * @param DOMDocument $dom - * @param DOMElement $root + * + * @param DOMDocument $dom + * @param DOMElement $root * @return void */ protected function _setCommentFeedLinks(DOMDocument $dom, DOMElement $root) @@ -116,7 +116,7 @@ class Zend_Feed_Writer_Extension_Threading_Renderer_Entry $flink->setAttribute('type', 'application/'. $link['type'] .'+xml'); $flink->setAttribute('href', $link['uri']); $count = $this->getDataContainer()->getCommentCount(); - if (!is_null($count)) { + if ($count !== null) { $flink->setAttribute('thr:count', $count); } $root->appendChild($flink); @@ -126,15 +126,15 @@ class Zend_Feed_Writer_Extension_Threading_Renderer_Entry /** * Set entry comment count - * - * @param DOMDocument $dom - * @param DOMElement $root + * + * @param DOMDocument $dom + * @param DOMElement $root * @return void */ protected function _setCommentCount(DOMDocument $dom, DOMElement $root) { $count = $this->getDataContainer()->getCommentCount(); - if (is_null($count)) { + if ($count === null) { return; } $tcount = $this->_dom->createElement('thr:total'); diff --git a/libs/Zend/Feed/Writer/Extension/WellFormedWeb/Renderer/Entry.php b/libs/Zend/Feed/Writer/Extension/WellFormedWeb/Renderer/Entry.php index c57244ae4b..d8c0187136 100644 --- a/libs/Zend/Feed/Writer/Extension/WellFormedWeb/Renderer/Entry.php +++ b/libs/Zend/Feed/Writer/Extension/WellFormedWeb/Renderer/Entry.php @@ -16,14 +16,14 @@ * @package Zend_Feed_Writer * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Entry.php 20326 2010-01-16 00:20:43Z padraic $ + * @version $Id: Entry.php 23484 2010-12-10 03:57:59Z mjh_ca $ */ - + /** * @see Zend_Feed_Writer_Extension_RendererAbstract */ // require_once 'Zend/Feed/Writer/Extension/RendererAbstract.php'; - + /** * @category Zend * @package Zend_Feed_Writer @@ -42,10 +42,10 @@ class Zend_Feed_Writer_Extension_WellFormedWeb_Renderer_Entry * @var bool */ protected $_called = false; - + /** * Render entry - * + * * @return void */ public function render() @@ -58,23 +58,23 @@ class Zend_Feed_Writer_Extension_WellFormedWeb_Renderer_Entry $this->_appendNamespaces(); } } - + /** * Append entry namespaces - * + * * @return void */ protected function _appendNamespaces() { $this->getRootElement()->setAttribute('xmlns:wfw', - 'http://wellformedweb.org/CommentAPI/'); + 'http://wellformedweb.org/CommentAPI/'); } - + /** * Set entry comment feed links - * - * @param DOMDocument $dom - * @param DOMElement $root + * + * @param DOMDocument $dom + * @param DOMElement $root * @return void */ protected function _setCommentFeedLinks(DOMDocument $dom, DOMElement $root) diff --git a/libs/Zend/Feed/Writer/Feed.php b/libs/Zend/Feed/Writer/Feed.php index 724caed1a2..5e23a619a5 100644 --- a/libs/Zend/Feed/Writer/Feed.php +++ b/libs/Zend/Feed/Writer/Feed.php @@ -16,7 +16,7 @@ * @package Zend_Feed_Writer * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Feed.php 20519 2010-01-22 14:06:24Z padraic $ + * @version $Id: Feed.php 23486 2010-12-10 04:05:30Z mjh_ca $ */ /** @@ -107,7 +107,7 @@ implements Iterator, Countable { $this->_entries[] = $deleted; } - + /** * Creates a new Zend_Feed_Writer_Deleted data container for use. This is NOT * added to the current feed automatically, but is necessary to create a @@ -205,7 +205,7 @@ implements Iterator, Countable return count($this->_entries); } - /** + /** * Return the current entry * * @return Zend_Feed_Reader_Entry_Interface @@ -225,7 +225,7 @@ implements Iterator, Countable return $this->_entriesKey; } - /** + /** * Move the feed pointer forward * * @return void diff --git a/libs/Zend/Feed/Writer/Feed/FeedAbstract.php b/libs/Zend/Feed/Writer/Feed/FeedAbstract.php index bc2a0fa06f..447cca1e45 100644 --- a/libs/Zend/Feed/Writer/Feed/FeedAbstract.php +++ b/libs/Zend/Feed/Writer/Feed/FeedAbstract.php @@ -16,7 +16,7 @@ * @package Zend_Feed_Writer * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Feed.php 20096 2010-01-06 02:05:09Z bkarwin $ + * @version $Id: FeedAbstract.php 23484 2010-12-10 03:57:59Z mjh_ca $ */ /** @@ -49,6 +49,9 @@ */ // require_once 'Zend/Feed/Writer/Renderer/Feed/Rss.php'; +// require_once 'Zend/Validate/EmailAddress.php'; + + /** * @category Zend * @package Zend_Feed_Writer @@ -63,7 +66,7 @@ class Zend_Feed_Writer_Feed_FeedAbstract * @var array */ protected $_data = array(); - + /** * Holds the value "atom" or "rss" depending on the feed type set when * when last exported. @@ -71,7 +74,7 @@ class Zend_Feed_Writer_Feed_FeedAbstract * @var string */ protected $_type = null; - + /** * Constructor: Primarily triggers the registration of core extensions and * loads those appropriate to this data container. @@ -171,7 +174,7 @@ class Zend_Feed_Writer_Feed_FeedAbstract public function setDateCreated($date = null) { $zdate = null; - if (is_null($date)) { + if ($date === null) { $zdate = new Zend_Date; } elseif (ctype_digit($date) && strlen($date) == 10) { $zdate = new Zend_Date($date, Zend_Date::TIMESTAMP); @@ -192,7 +195,7 @@ class Zend_Feed_Writer_Feed_FeedAbstract public function setDateModified($date = null) { $zdate = null; - if (is_null($date)) { + if ($date === null) { $zdate = new Zend_Date; } elseif (ctype_digit($date) && strlen($date) == 10) { $zdate = new Zend_Date($date, Zend_Date::TIMESTAMP); @@ -213,7 +216,7 @@ class Zend_Feed_Writer_Feed_FeedAbstract public function setLastBuildDate($date = null) { $zdate = null; - if (is_null($date)) { + if ($date === null) { $zdate = new Zend_Date; } elseif (ctype_digit($date) && strlen($date) == 10) { $zdate = new Zend_Date($date, Zend_Date::TIMESTAMP); @@ -300,7 +303,8 @@ class Zend_Feed_Writer_Feed_FeedAbstract public function setId($id) { if ((empty($id) || !is_string($id) || !Zend_Uri::check($id)) && - !preg_match("#^urn:[a-zA-Z0-9][a-zA-Z0-9\-]{1,31}:([a-zA-Z0-9\(\)\+\,\.\:\=\@\;\$\_\!\*\-]|%[0-9a-fA-F]{2})*#", $id)) { + !preg_match("#^urn:[a-zA-Z0-9][a-zA-Z0-9\-]{1,31}:([a-zA-Z0-9\(\)\+\,\.\:\=\@\;\$\_\!\*\-]|%[0-9a-fA-F]{2})*#", $id) + && !$this->_validateTagUri($id)) { // require_once 'Zend/Feed/Exception.php'; throw new Zend_Feed_Exception('Invalid parameter: parameter must be a non-empty string and valid URI/IRI'); } @@ -308,6 +312,38 @@ class Zend_Feed_Writer_Feed_FeedAbstract } /** + * Validate a URI using the tag scheme (RFC 4151) + * + * @param string $id + * @return bool + */ + protected function _validateTagUri($id) + { + if (preg_match('/^tag:(?<name>.*),(?<date>\d{4}-?\d{0,2}-?\d{0,2}):(?<specific>.*)(.*:)*$/', $id, $matches)) { + $dvalid = false; + $nvalid = false; + $date = $matches['date']; + $d6 = strtotime($date); + if ((strlen($date) == 4) && $date <= date('Y')) { + $dvalid = true; + } elseif ((strlen($date) == 7) && ($d6 < strtotime("now"))) { + $dvalid = true; + } elseif ((strlen($date) == 10) && ($d6 < strtotime("now"))) { + $dvalid = true; + } + $validator = new Zend_Validate_EmailAddress; + if ($validator->isValid($matches['name'])) { + $nvalid = true; + } else { + $nvalid = $validator->isValid('info@' . $matches['name']); + } + return $dvalid && $nvalid; + + } + return false; + } + + /** * Set a feed image (URI at minimum). Parameter is a single array with the * required key 'uri'. When rendering as RSS, the required keys are 'uri', * 'title' and 'link'. RSS also specifies three optional parameters 'width', @@ -323,7 +359,25 @@ class Zend_Feed_Writer_Feed_FeedAbstract throw new Zend_Feed_Exception('Invalid parameter: parameter \'uri\'' . ' must be a non-empty string and valid URI/IRI'); } - $this->_data['image'] = $data; + $this->_data['image'] = $data; + } + + /** + * Set a feed icon (URI at minimum). Parameter is a single array with the + * required key 'uri'. Only 'uri' is required and used for Atom rendering. + * RSS does not support an Icon tag except via Atom 1.0 as an extension. + * + * @param array $data + */ + public function setIcon(array $data) + { + if (empty($data['uri']) || !is_string($data['uri']) + || !Zend_Uri::check($data['uri'])) { + // require_once 'Zend/Feed/Exception.php'; + throw new Zend_Feed_Exception('Invalid parameter: parameter \'uri\'' + . ' must be a non-empty string and valid URI/IRI'); + } + $this->_data['icon'] = $data; } /** @@ -399,7 +453,7 @@ class Zend_Feed_Writer_Feed_FeedAbstract } $this->_data['encoding'] = $encoding; } - + /** * Set the feed's base URL * @@ -414,7 +468,7 @@ class Zend_Feed_Writer_Feed_FeedAbstract } $this->_data['baseUrl'] = $url; } - + /** * Add a Pubsubhubbub hub endpoint URL * @@ -432,7 +486,7 @@ class Zend_Feed_Writer_Feed_FeedAbstract } $this->_data['hubs'][] = $url; } - + /** * Add Pubsubhubbub hub endpoint URLs * @@ -444,12 +498,12 @@ class Zend_Feed_Writer_Feed_FeedAbstract $this->addHub($url); } } - + /** * Add a feed category * * @param string $category - */ + */ public function addCategory(array $category) { if (!isset($category['term'])) { @@ -459,7 +513,7 @@ class Zend_Feed_Writer_Feed_FeedAbstract . ' readable category name'); } if (isset($category['scheme'])) { - if (empty($category['scheme']) + if (empty($category['scheme']) || !is_string($category['scheme']) || !Zend_Uri::check($category['scheme']) ) { @@ -473,7 +527,7 @@ class Zend_Feed_Writer_Feed_FeedAbstract } $this->_data['categories'][] = $category; } - + /** * Set an array of feed categories * @@ -619,6 +673,19 @@ class Zend_Feed_Writer_Feed_FeedAbstract } /** + * Get the feed icon URI + * + * @return array + */ + public function getIcon() + { + if (!array_key_exists('icon', $this->_data)) { + return null; + } + return $this->_data['icon']; + } + + /** * Get the feed language * * @return string|null @@ -682,7 +749,7 @@ class Zend_Feed_Writer_Feed_FeedAbstract } return $this->_data['encoding']; } - + /** * Get the feed's base url * @@ -695,7 +762,7 @@ class Zend_Feed_Writer_Feed_FeedAbstract } return $this->_data['baseUrl']; } - + /** * Get the URLs used as Pubsubhubbub hubs endpoints * @@ -708,7 +775,7 @@ class Zend_Feed_Writer_Feed_FeedAbstract } return $this->_data['hubs']; } - + /** * Get the feed categories * @@ -731,7 +798,7 @@ class Zend_Feed_Writer_Feed_FeedAbstract { $this->_data = array(); } - + /** * Set the current feed type being exported to "rss" or "atom". This allows * other objects to gracefully choose whether to execute or not, depending @@ -743,7 +810,7 @@ class Zend_Feed_Writer_Feed_FeedAbstract { $this->_type = $type; } - + /** * Retrieve the current or last feed type exported. * @@ -753,7 +820,7 @@ class Zend_Feed_Writer_Feed_FeedAbstract { return $this->_type; } - + /** * Unset a specific data point * @@ -765,7 +832,7 @@ class Zend_Feed_Writer_Feed_FeedAbstract unset($this->_data[$name]); } } - + /** * Method overloading: call given method on first extension implementing it * diff --git a/libs/Zend/Feed/Writer/Renderer/Entry/Atom.php b/libs/Zend/Feed/Writer/Renderer/Entry/Atom.php index 76095e89f0..672e070bba 100644 --- a/libs/Zend/Feed/Writer/Renderer/Entry/Atom.php +++ b/libs/Zend/Feed/Writer/Renderer/Entry/Atom.php @@ -16,7 +16,7 @@ * @package Zend_Feed_Writer * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Atom.php 22065 2010-04-30 14:04:57Z padraic $ + * @version $Id: Atom.php 23484 2010-12-10 03:57:59Z mjh_ca $ */ /** @@ -38,8 +38,8 @@ class Zend_Feed_Writer_Renderer_Entry_Atom { /** * Constructor - * - * @param Zend_Feed_Writer_Entry $container + * + * @param Zend_Feed_Writer_Entry $container * @return void */ public function __construct (Zend_Feed_Writer_Entry $container) @@ -49,7 +49,7 @@ class Zend_Feed_Writer_Renderer_Entry_Atom /** * Render atom entry - * + * * @return Zend_Feed_Writer_Renderer_Entry_Atom */ public function render() @@ -58,7 +58,7 @@ class Zend_Feed_Writer_Renderer_Entry_Atom $this->_dom->formatOutput = true; $entry = $this->_dom->createElementNS(Zend_Feed_Writer::NAMESPACE_ATOM_10, 'entry'); $this->_dom->appendChild($entry); - + $this->_setSource($this->_dom, $entry); $this->_setTitle($this->_dom, $entry); $this->_setDescription($this->_dom, $entry); @@ -77,15 +77,15 @@ class Zend_Feed_Writer_Renderer_Entry_Atom $ext->setDomDocument($this->getDomDocument(), $entry); $ext->render(); } - + return $this; } - + /** * Set entry title - * - * @param DOMDocument $dom - * @param DOMElement $root + * + * @param DOMDocument $dom + * @param DOMElement $root * @return void */ protected function _setTitle(DOMDocument $dom, DOMElement $root) @@ -108,12 +108,12 @@ class Zend_Feed_Writer_Renderer_Entry_Atom $cdata = $dom->createCDATASection($this->getDataContainer()->getTitle()); $title->appendChild($cdata); } - + /** * Set entry description - * - * @param DOMDocument $dom - * @param DOMElement $root + * + * @param DOMDocument $dom + * @param DOMElement $root * @return void */ protected function _setDescription(DOMDocument $dom, DOMElement $root) @@ -129,12 +129,12 @@ class Zend_Feed_Writer_Renderer_Entry_Atom ); $subtitle->appendChild($cdata); } - + /** * Set date entry was modified - * - * @param DOMDocument $dom - * @param DOMElement $root + * + * @param DOMDocument $dom + * @param DOMElement $root * @return void */ protected function _setDateModified(DOMDocument $dom, DOMElement $root) @@ -159,12 +159,12 @@ class Zend_Feed_Writer_Renderer_Entry_Atom ); $updated->appendChild($text); } - + /** * Set date entry was created - * - * @param DOMDocument $dom - * @param DOMElement $root + * + * @param DOMDocument $dom + * @param DOMElement $root * @return void */ protected function _setDateCreated(DOMDocument $dom, DOMElement $root) @@ -179,12 +179,12 @@ class Zend_Feed_Writer_Renderer_Entry_Atom ); $el->appendChild($text); } - + /** - * Set entry authors - * - * @param DOMDocument $dom - * @param DOMElement $root + * Set entry authors + * + * @param DOMDocument $dom + * @param DOMElement $root * @return void */ protected function _setAuthors(DOMDocument $dom, DOMElement $root) @@ -218,12 +218,12 @@ class Zend_Feed_Writer_Renderer_Entry_Atom } } } - + /** * Set entry enclosure - * - * @param DOMDocument $dom - * @param DOMElement $root + * + * @param DOMDocument $dom + * @param DOMElement $root * @return void */ protected function _setEnclosure(DOMDocument $dom, DOMElement $root) @@ -243,7 +243,7 @@ class Zend_Feed_Writer_Renderer_Entry_Atom $enclosure->setAttribute('href', $data['uri']); $root->appendChild($enclosure); } - + protected function _setLink(DOMDocument $dom, DOMElement $root) { if(!$this->getDataContainer()->getLink()) { @@ -255,12 +255,12 @@ class Zend_Feed_Writer_Renderer_Entry_Atom $link->setAttribute('type', 'text/html'); $link->setAttribute('href', $this->getDataContainer()->getLink()); } - + /** - * Set entry identifier - * - * @param DOMDocument $dom - * @param DOMElement $root + * Set entry identifier + * + * @param DOMDocument $dom + * @param DOMElement $root * @return void */ protected function _setId(DOMDocument $dom, DOMElement $root) @@ -286,7 +286,9 @@ class Zend_Feed_Writer_Renderer_Entry_Atom $this->getDataContainer()->getLink()); } if (!Zend_Uri::check($this->getDataContainer()->getId()) && - !preg_match("#^urn:[a-zA-Z0-9][a-zA-Z0-9\-]{1,31}:([a-zA-Z0-9\(\)\+\,\.\:\=\@\;\$\_\!\*\-]|%[0-9a-fA-F]{2})*#", $this->getDataContainer()->getId())) { + !preg_match("#^urn:[a-zA-Z0-9][a-zA-Z0-9\-]{1,31}:([a-zA-Z0-9\(\)\+\,\.\:\=\@\;\$\_\!\*\-]|%[0-9a-fA-F]{2})*#", + $this->getDataContainer()->getId() + ) && !$this->_validateTagUri($this->getDataContainer()->getId())) { // require_once 'Zend/Feed/Exception.php'; throw new Zend_Feed_Exception('Atom 1.0 IDs must be a valid URI/IRI'); } @@ -295,12 +297,44 @@ class Zend_Feed_Writer_Renderer_Entry_Atom $text = $dom->createTextNode($this->getDataContainer()->getId()); $id->appendChild($text); } - + + /** + * Validate a URI using the tag scheme (RFC 4151) + * + * @param string $id + * @return bool + */ + protected function _validateTagUri($id) + { + if (preg_match('/^tag:(?<name>.*),(?<date>\d{4}-?\d{0,2}-?\d{0,2}):(?<specific>.*)(.*:)*$/', $id, $matches)) { + $dvalid = false; + $nvalid = false; + $date = $matches['date']; + $d6 = strtotime($date); + if ((strlen($date) == 4) && $date <= date('Y')) { + $dvalid = true; + } elseif ((strlen($date) == 7) && ($d6 < strtotime("now"))) { + $dvalid = true; + } elseif ((strlen($date) == 10) && ($d6 < strtotime("now"))) { + $dvalid = true; + } + $validator = new Zend_Validate_EmailAddress; + if ($validator->isValid($matches['name'])) { + $nvalid = true; + } else { + $nvalid = $validator->isValid('info@' . $matches['name']); + } + return $dvalid && $nvalid; + + } + return false; + } + /** - * Set entry content - * - * @param DOMDocument $dom - * @param DOMElement $root + * Set entry content + * + * @param DOMDocument $dom + * @param DOMElement $root * @return void */ protected function _setContent(DOMDocument $dom, DOMElement $root) @@ -330,7 +364,7 @@ class Zend_Feed_Writer_Renderer_Entry_Atom $element->appendChild($xhtml); $root->appendChild($element); } - + /** * Load a HTML string and attempt to normalise to XML */ @@ -352,19 +386,19 @@ class Zend_Feed_Writer_Renderer_Entry_Atom $xhtml = $content; } $xhtml = preg_replace(array( - "/(<[\/]?)([a-zA-Z]+)/" + "/(<[\/]?)([a-zA-Z]+)/" ), '$1xhtml:$2', $xhtml); $dom = new DOMDocument('1.0', $this->getEncoding()); $dom->loadXML('<xhtml:div xmlns:xhtml="http://www.w3.org/1999/xhtml">' . $xhtml . '</xhtml:div>'); return $dom->documentElement; } - + /** - * Set entry cateories - * - * @param DOMDocument $dom - * @param DOMElement $root + * Set entry cateories + * + * @param DOMDocument $dom + * @param DOMElement $root * @return void */ protected function _setCategories(DOMDocument $dom, DOMElement $root) @@ -387,12 +421,12 @@ class Zend_Feed_Writer_Renderer_Entry_Atom $root->appendChild($category); } } - + /** * Append Source element (Atom 1.0 Feed Metadata) * - * @param DOMDocument $dom - * @param DOMElement $root + * @param DOMDocument $dom + * @param DOMElement $root * @return void */ protected function _setSource(DOMDocument $dom, DOMElement $root) @@ -405,6 +439,6 @@ class Zend_Feed_Writer_Renderer_Entry_Atom $renderer->setType($this->getType()); $element = $renderer->render()->getElement(); $imported = $dom->importNode($element, true); - $root->appendChild($imported); + $root->appendChild($imported); } } diff --git a/libs/Zend/Feed/Writer/Renderer/Entry/Atom/Deleted.php b/libs/Zend/Feed/Writer/Renderer/Entry/Atom/Deleted.php index fb75262935..48ef8c817d 100644 --- a/libs/Zend/Feed/Writer/Renderer/Entry/Atom/Deleted.php +++ b/libs/Zend/Feed/Writer/Renderer/Entry/Atom/Deleted.php @@ -16,7 +16,7 @@ * @package Zend_Feed_Writer * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Atom.php 20506 2010-01-21 22:19:05Z padraic $ + * @version $Id: Deleted.php 23484 2010-12-10 03:57:59Z mjh_ca $ */ /** @@ -36,8 +36,8 @@ class Zend_Feed_Writer_Renderer_Entry_Atom_Deleted { /** * Constructor - * - * @param Zend_Feed_Writer_Deleted $container + * + * @param Zend_Feed_Writer_Deleted $container * @return void */ public function __construct (Zend_Feed_Writer_Deleted $container) @@ -47,7 +47,7 @@ class Zend_Feed_Writer_Renderer_Entry_Atom_Deleted /** * Render atom entry - * + * * @return Zend_Feed_Writer_Renderer_Entry_Atom */ public function render() @@ -56,21 +56,21 @@ class Zend_Feed_Writer_Renderer_Entry_Atom_Deleted $this->_dom->formatOutput = true; $entry = $this->_dom->createElement('at:deleted-entry'); $this->_dom->appendChild($entry); - + $entry->setAttribute('ref', $this->_container->getReference()); $entry->setAttribute('when', $this->_container->getWhen()->get(Zend_Date::ISO_8601)); - + $this->_setBy($this->_dom, $entry); $this->_setComment($this->_dom, $entry); - + return $this; } - + /** * Set tombstone comment - * - * @param DOMDocument $dom - * @param DOMElement $root + * + * @param DOMDocument $dom + * @param DOMElement $root * @return void */ protected function _setComment(DOMDocument $dom, DOMElement $root) @@ -84,12 +84,12 @@ class Zend_Feed_Writer_Renderer_Entry_Atom_Deleted $cdata = $dom->createCDATASection($this->getDataContainer()->getComment()); $c->appendChild($cdata); } - + /** - * Set entry authors - * - * @param DOMDocument $dom - * @param DOMElement $root + * Set entry authors + * + * @param DOMDocument $dom + * @param DOMElement $root * @return void */ protected function _setBy(DOMDocument $dom, DOMElement $root) @@ -117,5 +117,5 @@ class Zend_Feed_Writer_Renderer_Entry_Atom_Deleted $uri->appendChild($text); } } - + } diff --git a/libs/Zend/Feed/Writer/Renderer/Entry/Rss.php b/libs/Zend/Feed/Writer/Renderer/Entry/Rss.php index 74e80f5707..a54db1b3b4 100644 --- a/libs/Zend/Feed/Writer/Renderer/Entry/Rss.php +++ b/libs/Zend/Feed/Writer/Renderer/Entry/Rss.php @@ -16,7 +16,7 @@ * @package Zend_Feed_Writer * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Rss.php 22065 2010-04-30 14:04:57Z padraic $ + * @version $Id: Rss.php 23484 2010-12-10 03:57:59Z mjh_ca $ */ /** @@ -36,18 +36,18 @@ class Zend_Feed_Writer_Renderer_Entry_Rss { /** * Constructor - * - * @param Zend_Feed_Writer_Entry $container + * + * @param Zend_Feed_Writer_Entry $container * @return void */ public function __construct (Zend_Feed_Writer_Entry $container) { parent::__construct($container); } - + /** * Render RSS entry - * + * * @return Zend_Feed_Writer_Renderer_Entry_Rss */ public function render() @@ -57,7 +57,7 @@ class Zend_Feed_Writer_Renderer_Entry_Rss $this->_dom->substituteEntities = false; $entry = $this->_dom->createElement('item'); $this->_dom->appendChild($entry); - + $this->_setTitle($this->_dom, $entry); $this->_setDescription($this->_dom, $entry); $this->_setDateCreated($this->_dom, $entry); @@ -77,12 +77,12 @@ class Zend_Feed_Writer_Renderer_Entry_Rss return $this; } - + /** * Set entry title - * - * @param DOMDocument $dom - * @param DOMElement $root + * + * @param DOMDocument $dom + * @param DOMElement $root * @return void */ protected function _setTitle(DOMDocument $dom, DOMElement $root) @@ -106,12 +106,12 @@ class Zend_Feed_Writer_Renderer_Entry_Rss $text = $dom->createTextNode($this->getDataContainer()->getTitle()); $title->appendChild($text); } - + /** * Set entry description - * - * @param DOMDocument $dom - * @param DOMElement $root + * + * @param DOMDocument $dom + * @param DOMElement $root * @return void */ protected function _setDescription(DOMDocument $dom, DOMElement $root) @@ -139,12 +139,12 @@ class Zend_Feed_Writer_Renderer_Entry_Rss $text = $dom->createCDATASection($this->getDataContainer()->getDescription()); $subtitle->appendChild($text); } - + /** * Set date entry was last modified - * - * @param DOMDocument $dom - * @param DOMElement $root + * + * @param DOMDocument $dom + * @param DOMElement $root * @return void */ protected function _setDateModified(DOMDocument $dom, DOMElement $root) @@ -160,12 +160,12 @@ class Zend_Feed_Writer_Renderer_Entry_Rss ); $updated->appendChild($text); } - + /** * Set date entry was created - * - * @param DOMDocument $dom - * @param DOMElement $root + * + * @param DOMDocument $dom + * @param DOMElement $root * @return void */ protected function _setDateCreated(DOMDocument $dom, DOMElement $root) @@ -179,12 +179,12 @@ class Zend_Feed_Writer_Renderer_Entry_Rss ); } } - + /** * Set entry authors - * - * @param DOMDocument $dom - * @param DOMElement $root + * + * @param DOMDocument $dom + * @param DOMElement $root * @return void */ protected function _setAuthors(DOMDocument $dom, DOMElement $root) @@ -204,12 +204,12 @@ class Zend_Feed_Writer_Renderer_Entry_Rss $root->appendChild($author); } } - + /** * Set entry enclosure - * - * @param DOMDocument $dom - * @param DOMElement $root + * + * @param DOMDocument $dom + * @param DOMElement $root * @return void */ protected function _setEnclosure(DOMDocument $dom, DOMElement $root) @@ -255,12 +255,12 @@ class Zend_Feed_Writer_Renderer_Entry_Rss $enclosure->setAttribute('url', $data['uri']); $root->appendChild($enclosure); } - + /** * Set link to entry - * - * @param DOMDocument $dom - * @param DOMElement $root + * + * @param DOMDocument $dom + * @param DOMElement $root * @return void */ protected function _setLink(DOMDocument $dom, DOMElement $root) @@ -273,12 +273,12 @@ class Zend_Feed_Writer_Renderer_Entry_Rss $text = $dom->createTextNode($this->getDataContainer()->getLink()); $link->appendChild($text); } - + /** * Set entry identifier - * - * @param DOMDocument $dom - * @param DOMElement $root + * + * @param DOMDocument $dom + * @param DOMElement $root * @return void */ protected function _setId(DOMDocument $dom, DOMElement $root) @@ -300,12 +300,12 @@ class Zend_Feed_Writer_Renderer_Entry_Rss $id->setAttribute('isPermaLink', 'false'); } } - + /** * Set link to entry comments - * - * @param DOMDocument $dom - * @param DOMElement $root + * + * @param DOMDocument $dom + * @param DOMElement $root * @return void */ protected function _setCommentLink(DOMDocument $dom, DOMElement $root) @@ -319,12 +319,12 @@ class Zend_Feed_Writer_Renderer_Entry_Rss $clink->appendChild($text); $root->appendChild($clink); } - + /** * Set entry categories - * - * @param DOMDocument $dom - * @param DOMElement $root + * + * @param DOMDocument $dom + * @param DOMElement $root * @return void */ protected function _setCategories(DOMDocument $dom, DOMElement $root) diff --git a/libs/Zend/Feed/Writer/Renderer/Feed/Atom.php b/libs/Zend/Feed/Writer/Renderer/Feed/Atom.php index 2c88dd4298..2966d0155b 100644 --- a/libs/Zend/Feed/Writer/Renderer/Feed/Atom.php +++ b/libs/Zend/Feed/Writer/Renderer/Feed/Atom.php @@ -16,7 +16,7 @@ * @package Zend_Feed_Writer * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Atom.php 22098 2010-05-04 18:03:29Z padraic $ + * @version $Id: Atom.php 23484 2010-12-10 03:57:59Z mjh_ca $ */ /** @see Zend_Feed_Writer_Feed */ @@ -51,8 +51,8 @@ class Zend_Feed_Writer_Renderer_Feed_Atom { /** * Constructor - * - * @param Zend_Feed_Writer_Feed $container + * + * @param Zend_Feed_Writer_Feed $container * @return void */ public function __construct (Zend_Feed_Writer_Feed $container) @@ -62,7 +62,7 @@ class Zend_Feed_Writer_Renderer_Feed_Atom /** * Render Atom feed - * + * * @return Zend_Feed_Writer_Renderer_Feed_Atom */ public function render() @@ -82,6 +82,7 @@ class Zend_Feed_Writer_Renderer_Feed_Atom $this->_setTitle($this->_dom, $root); $this->_setDescription($this->_dom, $root); $this->_setImage($this->_dom, $root); + $this->_setIcon($this->_dom, $root); $this->_setDateCreated($this->_dom, $root); $this->_setDateModified($this->_dom, $root); $this->_setGenerator($this->_dom, $root); @@ -92,14 +93,14 @@ class Zend_Feed_Writer_Renderer_Feed_Atom $this->_setCopyright($this->_dom, $root); $this->_setCategories($this->_dom, $root); $this->_setHubs($this->_dom, $root); - + foreach ($this->_extensions as $ext) { $ext->setType($this->getType()); $ext->setRootElement($this->getRootElement()); $ext->setDomDocument($this->getDomDocument(), $root); $ext->render(); } - + foreach ($this->_container as $entry) { if ($this->getDataContainer()->getEncoding()) { $entry->setEncoding($this->getDataContainer()->getEncoding()); diff --git a/libs/Zend/Feed/Writer/Renderer/Feed/Atom/AtomAbstract.php b/libs/Zend/Feed/Writer/Renderer/Feed/Atom/AtomAbstract.php index 254516e5b5..b0062852d5 100644 --- a/libs/Zend/Feed/Writer/Renderer/Feed/Atom/AtomAbstract.php +++ b/libs/Zend/Feed/Writer/Renderer/Feed/Atom/AtomAbstract.php @@ -16,7 +16,7 @@ * @package Zend_Feed_Writer * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Atom.php 20096 2010-01-06 02:05:09Z bkarwin $ + * @version $Id: AtomAbstract.php 23484 2010-12-10 03:57:59Z mjh_ca $ */ /** @see Zend_Feed_Writer_Feed */ @@ -45,8 +45,8 @@ class Zend_Feed_Writer_Renderer_Feed_Atom_AtomAbstract { /** * Constructor - * - * @param Zend_Feed_Writer_Feed $container + * + * @param Zend_Feed_Writer_Feed $container * @return void */ public function __construct ($container) @@ -56,9 +56,9 @@ class Zend_Feed_Writer_Renderer_Feed_Atom_AtomAbstract /** * Set feed language - * - * @param DOMDocument $dom - * @param DOMElement $root + * + * @param DOMDocument $dom + * @param DOMElement $root * @return void */ protected function _setLanguage(DOMDocument $dom, DOMElement $root) @@ -71,9 +71,9 @@ class Zend_Feed_Writer_Renderer_Feed_Atom_AtomAbstract /** * Set feed title - * - * @param DOMDocument $dom - * @param DOMElement $root + * + * @param DOMDocument $dom + * @param DOMElement $root * @return void */ protected function _setTitle(DOMDocument $dom, DOMElement $root) @@ -100,9 +100,9 @@ class Zend_Feed_Writer_Renderer_Feed_Atom_AtomAbstract /** * Set feed description - * - * @param DOMDocument $dom - * @param DOMElement $root + * + * @param DOMDocument $dom + * @param DOMElement $root * @return void */ protected function _setDescription(DOMDocument $dom, DOMElement $root) @@ -119,9 +119,9 @@ class Zend_Feed_Writer_Renderer_Feed_Atom_AtomAbstract /** * Set date feed was last modified - * - * @param DOMDocument $dom - * @param DOMElement $root + * + * @param DOMDocument $dom + * @param DOMElement $root * @return void */ protected function _setDateModified(DOMDocument $dom, DOMElement $root) @@ -149,9 +149,9 @@ class Zend_Feed_Writer_Renderer_Feed_Atom_AtomAbstract /** * Set feed generator string - * - * @param DOMDocument $dom - * @param DOMElement $root + * + * @param DOMDocument $dom + * @param DOMElement $root * @return void */ protected function _setGenerator(DOMDocument $dom, DOMElement $root) @@ -176,9 +176,9 @@ class Zend_Feed_Writer_Renderer_Feed_Atom_AtomAbstract /** * Set link to feed - * - * @param DOMDocument $dom - * @param DOMElement $root + * + * @param DOMDocument $dom + * @param DOMElement $root * @return void */ protected function _setLink(DOMDocument $dom, DOMElement $root) @@ -195,9 +195,9 @@ class Zend_Feed_Writer_Renderer_Feed_Atom_AtomAbstract /** * Set feed links - * - * @param DOMDocument $dom - * @param DOMElement $root + * + * @param DOMDocument $dom + * @param DOMElement $root * @return void */ protected function _setFeedLinks(DOMDocument $dom, DOMElement $root) @@ -227,12 +227,12 @@ class Zend_Feed_Writer_Renderer_Feed_Atom_AtomAbstract $flink->setAttribute('href', $href); } } - + /** - * Set feed authors - * - * @param DOMDocument $dom - * @param DOMElement $root + * Set feed authors + * + * @param DOMDocument $dom + * @param DOMElement $root * @return void */ protected function _setAuthors(DOMDocument $dom, DOMElement $root) @@ -270,9 +270,9 @@ class Zend_Feed_Writer_Renderer_Feed_Atom_AtomAbstract /** * Set feed identifier - * - * @param DOMDocument $dom - * @param DOMElement $root + * + * @param DOMDocument $dom + * @param DOMElement $root * @return void */ protected function _setId(DOMDocument $dom, DOMElement $root) @@ -302,12 +302,12 @@ class Zend_Feed_Writer_Renderer_Feed_Atom_AtomAbstract $text = $dom->createTextNode($this->getDataContainer()->getId()); $id->appendChild($text); } - + /** * Set feed copyright - * - * @param DOMDocument $dom - * @param DOMElement $root + * + * @param DOMDocument $dom + * @param DOMElement $root * @return void */ protected function _setCopyright(DOMDocument $dom, DOMElement $root) @@ -324,9 +324,9 @@ class Zend_Feed_Writer_Renderer_Feed_Atom_AtomAbstract /** * Set feed level logo (image) - * - * @param DOMDocument $dom - * @param DOMElement $root + * + * @param DOMDocument $dom + * @param DOMElement $root * @return void */ protected function _setImage(DOMDocument $dom, DOMElement $root) @@ -340,12 +340,31 @@ class Zend_Feed_Writer_Renderer_Feed_Atom_AtomAbstract $text = $dom->createTextNode($image['uri']); $img->appendChild($text); } - + + /** + * Set feed level icon (image) + * + * @param DOMDocument $dom + * @param DOMElement $root + * @return void + */ + protected function _setIcon(DOMDocument $dom, DOMElement $root) + { + $image = $this->getDataContainer()->getIcon(); + if (!$image) { + return; + } + $img = $dom->createElement('icon'); + $root->appendChild($img); + $text = $dom->createTextNode($image['uri']); + $img->appendChild($text); + } + /** - * Set date feed was created - * - * @param DOMDocument $dom - * @param DOMElement $root + * Set date feed was created + * + * @param DOMDocument $dom + * @param DOMElement $root * @return void */ protected function _setDateCreated(DOMDocument $dom, DOMElement $root) @@ -359,12 +378,12 @@ class Zend_Feed_Writer_Renderer_Feed_Atom_AtomAbstract ); } } - + /** * Set base URL to feed links - * - * @param DOMDocument $dom - * @param DOMElement $root + * + * @param DOMDocument $dom + * @param DOMElement $root * @return void */ protected function _setBaseUrl(DOMDocument $dom, DOMElement $root) @@ -375,12 +394,12 @@ class Zend_Feed_Writer_Renderer_Feed_Atom_AtomAbstract } $root->setAttribute('xml:base', $baseUrl); } - + /** - * Set hubs to which this feed pushes - * - * @param DOMDocument $dom - * @param DOMElement $root + * Set hubs to which this feed pushes + * + * @param DOMDocument $dom + * @param DOMElement $root * @return void */ protected function _setHubs(DOMDocument $dom, DOMElement $root) @@ -396,12 +415,12 @@ class Zend_Feed_Writer_Renderer_Feed_Atom_AtomAbstract $root->appendChild($hub); } } - + /** - * Set feed cateories - * - * @param DOMDocument $dom - * @param DOMElement $root + * Set feed cateories + * + * @param DOMDocument $dom + * @param DOMElement $root * @return void */ protected function _setCategories(DOMDocument $dom, DOMElement $root) diff --git a/libs/Zend/Feed/Writer/Renderer/Feed/Atom/Source.php b/libs/Zend/Feed/Writer/Renderer/Feed/Atom/Source.php index 125fed1eaf..80d428a4e2 100644 --- a/libs/Zend/Feed/Writer/Renderer/Feed/Atom/Source.php +++ b/libs/Zend/Feed/Writer/Renderer/Feed/Atom/Source.php @@ -16,11 +16,11 @@ * @package Zend_Feed_Writer * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Atom.php 20096 2010-01-06 02:05:09Z bkarwin $ + * @version $Id: Source.php 23484 2010-12-10 03:57:59Z mjh_ca $ */ - + // require_once 'Zend/Feed/Writer/Renderer/Feed/Atom/AtomAbstract.php'; - + /** * @category Zend * @package Zend_Feed_Writer @@ -34,18 +34,18 @@ class Zend_Feed_Writer_Renderer_Feed_Atom_Source /** * Constructor - * - * @param Zend_Feed_Writer_Feed_Source $container + * + * @param Zend_Feed_Writer_Feed_Source $container * @return void */ public function __construct (Zend_Feed_Writer_Source $container) { parent::__construct($container); } - + /** * Render Atom Feed Metadata (Source element) - * + * * @return Zend_Feed_Writer_Renderer_Feed_Atom */ public function render() @@ -71,7 +71,7 @@ class Zend_Feed_Writer_Renderer_Feed_Atom_Source $this->_setAuthors($this->_dom, $root); $this->_setCopyright($this->_dom, $root); $this->_setCategories($this->_dom, $root); - + foreach ($this->_extensions as $ext) { $ext->setType($this->getType()); $ext->setRootElement($this->getRootElement()); @@ -80,12 +80,12 @@ class Zend_Feed_Writer_Renderer_Feed_Atom_Source } return $this; } - + /** * Set feed generator string - * - * @param DOMDocument $dom - * @param DOMElement $root + * + * @param DOMDocument $dom + * @param DOMElement $root * @return void */ protected function _setGenerator(DOMDocument $dom, DOMElement $root) diff --git a/libs/Zend/Feed/Writer/Renderer/Feed/Rss.php b/libs/Zend/Feed/Writer/Renderer/Feed/Rss.php index 07b94e7b86..918a072dde 100644 --- a/libs/Zend/Feed/Writer/Renderer/Feed/Rss.php +++ b/libs/Zend/Feed/Writer/Renderer/Feed/Rss.php @@ -16,7 +16,7 @@ * @package Zend_Feed_Writer * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Rss.php 22108 2010-05-05 13:44:11Z padraic $ + * @version $Id: Rss.php 23484 2010-12-10 03:57:59Z mjh_ca $ */ /** @see Zend_Feed_Writer_Feed */ @@ -46,8 +46,8 @@ class Zend_Feed_Writer_Renderer_Feed_Rss { /** * Constructor - * - * @param Zend_Feed_Writer_Feed $container + * + * @param Zend_Feed_Writer_Feed $container * @return void */ public function __construct (Zend_Feed_Writer_Feed $container) @@ -57,7 +57,7 @@ class Zend_Feed_Writer_Renderer_Feed_Rss /** * Render RSS feed - * + * * @return Zend_Feed_Writer_Renderer_Feed_Rss */ public function render() @@ -71,7 +71,7 @@ class Zend_Feed_Writer_Renderer_Feed_Rss $rss = $this->_dom->createElement('rss'); $this->setRootElement($rss); $rss->setAttribute('version', '2.0'); - + $channel = $this->_dom->createElement('channel'); $rss->appendChild($channel); $this->_dom->appendChild($rss); @@ -88,14 +88,14 @@ class Zend_Feed_Writer_Renderer_Feed_Rss $this->_setAuthors($this->_dom, $channel); $this->_setCopyright($this->_dom, $channel); $this->_setCategories($this->_dom, $channel); - + foreach ($this->_extensions as $ext) { $ext->setType($this->getType()); $ext->setRootElement($this->getRootElement()); $ext->setDomDocument($this->getDomDocument(), $channel); $ext->render(); } - + foreach ($this->_container as $entry) { if ($this->getDataContainer()->getEncoding()) { $entry->setEncoding($this->getDataContainer()->getEncoding()); @@ -120,9 +120,9 @@ class Zend_Feed_Writer_Renderer_Feed_Rss /** * Set feed language - * - * @param DOMDocument $dom - * @param DOMElement $root + * + * @param DOMDocument $dom + * @param DOMElement $root * @return void */ protected function _setLanguage(DOMDocument $dom, DOMElement $root) @@ -138,9 +138,9 @@ class Zend_Feed_Writer_Renderer_Feed_Rss /** * Set feed title - * - * @param DOMDocument $dom - * @param DOMElement $root + * + * @param DOMDocument $dom + * @param DOMElement $root * @return void */ protected function _setTitle(DOMDocument $dom, DOMElement $root) @@ -166,9 +166,9 @@ class Zend_Feed_Writer_Renderer_Feed_Rss /** * Set feed description - * - * @param DOMDocument $dom - * @param DOMElement $root + * + * @param DOMDocument $dom + * @param DOMElement $root * @return void */ protected function _setDescription(DOMDocument $dom, DOMElement $root) @@ -193,9 +193,9 @@ class Zend_Feed_Writer_Renderer_Feed_Rss /** * Set date feed was last modified - * - * @param DOMDocument $dom - * @param DOMElement $root + * + * @param DOMDocument $dom + * @param DOMElement $root * @return void */ protected function _setDateModified(DOMDocument $dom, DOMElement $root) @@ -214,9 +214,9 @@ class Zend_Feed_Writer_Renderer_Feed_Rss /** * Set feed generator string - * - * @param DOMDocument $dom - * @param DOMElement $root + * + * @param DOMDocument $dom + * @param DOMElement $root * @return void */ protected function _setGenerator(DOMDocument $dom, DOMElement $root) @@ -242,9 +242,9 @@ class Zend_Feed_Writer_Renderer_Feed_Rss /** * Set link to feed - * - * @param DOMDocument $dom - * @param DOMElement $root + * + * @param DOMDocument $dom + * @param DOMElement $root * @return void */ protected function _setLink(DOMDocument $dom, DOMElement $root) @@ -270,12 +270,12 @@ class Zend_Feed_Writer_Renderer_Feed_Rss $link->setAttribute('isPermaLink', 'false'); } } - + /** * Set feed authors - * - * @param DOMDocument $dom - * @param DOMElement $root + * + * @param DOMDocument $dom + * @param DOMElement $root * @return void */ protected function _setAuthors(DOMDocument $dom, DOMElement $root) @@ -295,12 +295,12 @@ class Zend_Feed_Writer_Renderer_Feed_Rss $root->appendChild($author); } } - + /** * Set feed copyright - * - * @param DOMDocument $dom - * @param DOMElement $root + * + * @param DOMDocument $dom + * @param DOMElement $root * @return void */ protected function _setCopyright(DOMDocument $dom, DOMElement $root) @@ -317,9 +317,9 @@ class Zend_Feed_Writer_Renderer_Feed_Rss /** * Set feed channel image - * - * @param DOMDocument $dom - * @param DOMElement $root + * + * @param DOMDocument $dom + * @param DOMElement $root * @return void */ protected function _setImage(DOMDocument $dom, DOMElement $root) @@ -422,12 +422,12 @@ class Zend_Feed_Writer_Renderer_Feed_Rss $img->appendChild($desc); } } - + /** * Set date feed was created - * - * @param DOMDocument $dom - * @param DOMElement $root + * + * @param DOMDocument $dom + * @param DOMElement $root * @return void */ protected function _setDateCreated(DOMDocument $dom, DOMElement $root) @@ -444,9 +444,9 @@ class Zend_Feed_Writer_Renderer_Feed_Rss /** * Set date feed last build date - * - * @param DOMDocument $dom - * @param DOMElement $root + * + * @param DOMDocument $dom + * @param DOMElement $root * @return void */ protected function _setLastBuildDate(DOMDocument $dom, DOMElement $root) @@ -462,12 +462,12 @@ class Zend_Feed_Writer_Renderer_Feed_Rss ); $lastBuildDate->appendChild($text); } - + /** * Set base URL to feed links - * - * @param DOMDocument $dom - * @param DOMElement $root + * + * @param DOMDocument $dom + * @param DOMElement $root * @return void */ protected function _setBaseUrl(DOMDocument $dom, DOMElement $root) @@ -478,12 +478,12 @@ class Zend_Feed_Writer_Renderer_Feed_Rss } $root->setAttribute('xml:base', $baseUrl); } - + /** * Set feed categories - * - * @param DOMDocument $dom - * @param DOMElement $root + * + * @param DOMDocument $dom + * @param DOMElement $root * @return void */ protected function _setCategories(DOMDocument $dom, DOMElement $root) diff --git a/libs/Zend/Feed/Writer/Renderer/RendererAbstract.php b/libs/Zend/Feed/Writer/Renderer/RendererAbstract.php index b3457ed643..743f1b73dc 100644 --- a/libs/Zend/Feed/Writer/Renderer/RendererAbstract.php +++ b/libs/Zend/Feed/Writer/Renderer/RendererAbstract.php @@ -16,15 +16,15 @@ * @package Zend_Feed_Writer * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: RendererAbstract.php 20096 2010-01-06 02:05:09Z bkarwin $ + * @version $Id: RendererAbstract.php 23484 2010-12-10 03:57:59Z mjh_ca $ */ - + /** @see Zend_Feed_Writer */ // require_once 'Zend/Feed/Writer.php'; /** @see Zend_Version */ // require_once 'Zend/Version.php'; - + /** * @category Zend * @package Zend_Feed_Writer @@ -38,7 +38,7 @@ class Zend_Feed_Writer_Renderer_RendererAbstract * @var array */ protected $_extensions = array(); - + /** * @var mixed */ @@ -58,14 +58,14 @@ class Zend_Feed_Writer_Renderer_RendererAbstract * @var array */ protected $_exceptions = array(); - + /** * Encoding of all text values * * @var string */ protected $_encoding = 'UTF-8'; - + /** * Holds the value "atom" or "rss" depending on the feed type set when * when last exported. @@ -73,7 +73,7 @@ class Zend_Feed_Writer_Renderer_RendererAbstract * @var string */ protected $_type = null; - + /** * @var DOMElement */ @@ -81,8 +81,8 @@ class Zend_Feed_Writer_Renderer_RendererAbstract /** * Constructor - * - * @param mixed $container + * + * @param mixed $container * @return void */ public function __construct($container) @@ -91,10 +91,10 @@ class Zend_Feed_Writer_Renderer_RendererAbstract $this->setType($container->getType()); $this->_loadExtensions(); } - + /** * Save XML to string - * + * * @return string */ public function saveXml() @@ -104,7 +104,7 @@ class Zend_Feed_Writer_Renderer_RendererAbstract /** * Get DOM document - * + * * @return DOMDocument */ public function getDomDocument() @@ -114,7 +114,7 @@ class Zend_Feed_Writer_Renderer_RendererAbstract /** * Get document element from DOM - * + * * @return DOMElement */ public function getElement() @@ -124,18 +124,18 @@ class Zend_Feed_Writer_Renderer_RendererAbstract /** * Get data container of items being rendered - * + * * @return mixed */ public function getDataContainer() { return $this->_container; } - + /** * Set feed encoding - * - * @param string $enc + * + * @param string $enc * @return Zend_Feed_Writer_Renderer_RendererAbstract */ public function setEncoding($enc) @@ -143,10 +143,10 @@ class Zend_Feed_Writer_Renderer_RendererAbstract $this->_encoding = $enc; return $this; } - + /** * Get feed encoding - * + * * @return string */ public function getEncoding() @@ -156,8 +156,8 @@ class Zend_Feed_Writer_Renderer_RendererAbstract /** * Indicate whether or not to ignore exceptions - * - * @param bool $bool + * + * @param bool $bool * @return Zend_Feed_Writer_Renderer_RendererAbstract */ public function ignoreExceptions($bool = true) @@ -172,14 +172,14 @@ class Zend_Feed_Writer_Renderer_RendererAbstract /** * Get exception list - * + * * @return array */ public function getExceptions() { return $this->_exceptions; } - + /** * Set the current feed type being exported to "rss" or "atom". This allows * other objects to gracefully choose whether to execute or not, depending @@ -191,7 +191,7 @@ class Zend_Feed_Writer_Renderer_RendererAbstract { $this->_type = $type; } - + /** * Retrieve the current or last feed type exported. * @@ -201,7 +201,7 @@ class Zend_Feed_Writer_Renderer_RendererAbstract { return $this->_type; } - + /** * Sets the absolute root element for the XML feed being generated. This * helps simplify the appending of namespace declarations, but also ensures @@ -214,7 +214,7 @@ class Zend_Feed_Writer_Renderer_RendererAbstract { $this->_rootElement = $root; } - + /** * Retrieve the absolute root element for the XML feed being generated. * @@ -224,7 +224,7 @@ class Zend_Feed_Writer_Renderer_RendererAbstract { return $this->_rootElement; } - + /** * Load extensions from Zend_Feed_Writer * diff --git a/libs/Zend/Feed/Writer/Renderer/RendererInterface.php b/libs/Zend/Feed/Writer/Renderer/RendererInterface.php index 89b4294416..17549bb279 100644 --- a/libs/Zend/Feed/Writer/Renderer/RendererInterface.php +++ b/libs/Zend/Feed/Writer/Renderer/RendererInterface.php @@ -16,7 +16,7 @@ * @package Zend_Feed_Writer * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: RendererInterface.php 20096 2010-01-06 02:05:09Z bkarwin $ + * @version $Id: RendererInterface.php 23484 2010-12-10 03:57:59Z mjh_ca $ */ /** @@ -29,53 +29,53 @@ interface Zend_Feed_Writer_Renderer_RendererInterface { /** * Render feed/entry - * + * * @return void */ public function render(); /** * Save feed and/or entry to XML and return string - * + * * @return string */ public function saveXml(); /** * Get DOM document - * + * * @return DOMDocument */ public function getDomDocument(); /** * Get document element from DOM - * + * * @return DOMElement */ public function getElement(); /** * Get data container containing feed items - * + * * @return mixed */ public function getDataContainer(); /** * Should exceptions be ignored? - * + * * @return mixed */ public function ignoreExceptions(); - + /** * Get list of thrown exceptions - * + * * @return array */ public function getExceptions(); - + /** * Set the current feed type being exported to "rss" or "atom". This allows * other objects to gracefully choose whether to execute or not, depending @@ -84,14 +84,14 @@ interface Zend_Feed_Writer_Renderer_RendererInterface * @param string $type */ public function setType($type); - + /** * Retrieve the current or last feed type exported. * * @return string Value will be "rss" or "atom" */ public function getType(); - + /** * Sets the absolute root element for the XML feed being generated. This * helps simplify the appending of namespace declarations, but also ensures @@ -101,7 +101,7 @@ interface Zend_Feed_Writer_Renderer_RendererInterface * @param DOMElement $root */ public function setRootElement(DOMElement $root); - + /** * Retrieve the absolute root element for the XML feed being generated. * diff --git a/libs/Zend/Feed/Writer/Source.php b/libs/Zend/Feed/Writer/Source.php index 3861fc77fc..3e49f534b6 100644 --- a/libs/Zend/Feed/Writer/Source.php +++ b/libs/Zend/Feed/Writer/Source.php @@ -16,11 +16,11 @@ * @package Zend_Feed_Writer * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Feed.php 20096 2010-01-06 02:05:09Z bkarwin $ + * @version $Id: Source.php 23484 2010-12-10 03:57:59Z mjh_ca $ */ // require_once 'Zend/Feed/Writer/Feed/FeedAbstract.php'; - + /** * @category Zend * @package Zend_Feed_Writer diff --git a/libs/Zend/Http/Client.php b/libs/Zend/Http/Client.php index d59c67ff7a..b62c1e8bd2 100644 --- a/libs/Zend/Http/Client.php +++ b/libs/Zend/Http/Client.php @@ -16,7 +16,7 @@ * @category Zend * @package Zend_Http * @subpackage Client - * @version $Id: Client.php 22539 2010-07-08 12:47:44Z shahar $ + * @version $Id: Client.php 23484 2010-12-10 03:57:59Z mjh_ca $ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ @@ -50,10 +50,10 @@ // require_once 'Zend/Http/Response/Stream.php'; /** - * Zend_Http_Client is an implemetation of an HTTP client in PHP. The client + * Zend_Http_Client is an implementation of an HTTP client in PHP. The client * supports basic features like sending different HTTP requests and handling * redirections, as well as more advanced features like proxy settings, HTTP - * authentication and cookie persistance (using a Zend_Http_CookieJar object) + * authentication and cookie persistence (using a Zend_Http_CookieJar object) * * @todo Implement proxy settings * @category Zend @@ -119,10 +119,11 @@ class Zend_Http_Client 'strict' => true, 'output_stream' => false, 'encodecookies' => true, + 'rfc3986_strict' => false ); /** - * The adapter used to preform the actual connection to the server + * The adapter used to perform the actual connection to the server * * @var Zend_Http_Client_Adapter_Interface */ @@ -157,7 +158,7 @@ class Zend_Http_Client protected $paramsGet = array(); /** - * Assiciative array of POST parameters + * Associative array of POST parameters * * @var array */ @@ -232,7 +233,7 @@ class Zend_Http_Client /** * Fileinfo magic database resource * - * This varaiable is populated the first time _detectFileMimeType is called + * This variable is populated the first time _detectFileMimeType is called * and is then reused on every call to this method * * @var resource @@ -240,7 +241,7 @@ class Zend_Http_Client static protected $_fileInfoDb = null; /** - * Contructor method. Will create a new HTTP client. Accepts the target + * Constructor method. Will create a new HTTP client. Accepts the target * URL and optionally configuration array. * * @param Zend_Uri_Http|string $uri @@ -368,12 +369,12 @@ class Zend_Http_Client * * This function can be used in several ways to set the client's request * headers: - * 1. By providing two parameters: $name as the header to set (eg. 'Host') - * and $value as it's value (eg. 'www.example.com'). + * 1. By providing two parameters: $name as the header to set (e.g. 'Host') + * and $value as it's value (e.g. 'www.example.com'). * 2. By providing a single header string as the only parameter - * eg. 'Host: www.example.com' + * e.g. 'Host: www.example.com' * 3. By providing an array of headers as the first parameter - * eg. array('host' => 'www.example.com', 'x-foo: bar'). In This case + * e.g. array('host' => 'www.example.com', 'x-foo: bar'). In This case * the function will call itself recursively for each array item. * * @param string|array $name Header name, full header string ('Header: value') @@ -384,7 +385,7 @@ class Zend_Http_Client */ public function setHeaders($name, $value = null) { - // If we got an array, go recusive! + // If we got an array, go recursive! if (is_array($name)) { foreach ($name as $k => $v) { if (is_string($k)) { @@ -585,7 +586,10 @@ class Zend_Http_Client */ public function setCookieJar($cookiejar = true) { - // Zend_Loader::loadClass('Zend_Http_CookieJar'); + if (!class_exists('Zend_Http_CookieJar')) { + // require_once 'Zend/Loader.php'; + Zend_Loader::loadClass('Zend_Http_CookieJar'); + } if ($cookiejar instanceof Zend_Http_CookieJar) { $this->cookiejar = $cookiejar; @@ -623,7 +627,10 @@ class Zend_Http_Client */ public function setCookie($cookie, $value = null) { - // Zend_Loader::loadClass('Zend_Http_Cookie'); + if (!class_exists('Zend_Http_Cookie')) { + // require_once 'Zend/Loader.php'; + Zend_Loader::loadClass('Zend_Http_Cookie'); + } if (is_array($cookie)) { foreach ($cookie as $c => $v) { @@ -835,13 +842,16 @@ class Zend_Http_Client public function setAdapter($adapter) { if (is_string($adapter)) { - // try { - // Zend_Loader::loadClass($adapter); - // } catch (Zend_Exception $e) { - /** @see Zend_Http_Client_Exception */ - // require_once 'Zend/Http/Client/Exception.php'; - // throw new Zend_Http_Client_Exception("Unable to load adapter '$adapter': {$e->getMessage()}", 0, $e); - // } + if (!class_exists($adapter)) { + // require_once 'Zend/Loader.php'; + try { + Zend_Loader::loadClass($adapter); + } catch (Zend_Exception $e) { + /** @see Zend_Http_Client_Exception */ + // require_once 'Zend/Http/Client/Exception.php'; + throw new Zend_Http_Client_Exception("Unable to load adapter '$adapter': {$e->getMessage()}", 0, $e); + } + } $adapter = new $adapter; } @@ -910,10 +920,10 @@ class Zend_Http_Client // require_once 'Zend/Http/Client/Exception.php'; throw new Zend_Http_Client_Exception("Could not open temp file {$this->_stream_name}"); } - + return $fp; } - + /** * Send the HTTP request and return an HTTP response object * @@ -950,6 +960,9 @@ class Zend_Http_Client $query .= '&'; } $query .= http_build_query($this->paramsGet, null, '&'); + if ($this->config['rfc3986_strict']) { + $query = str_replace('+', '%20', $query); + } $uri->setQuery($query); } @@ -1009,7 +1022,7 @@ class Zend_Http_Client // Load cookies into cookie jar if (isset($this->cookiejar)) { - $this->cookiejar->addCookiesFromResponse($response, $uri); + $this->cookiejar->addCookiesFromResponse($response, $uri, $this->config['encodecookies']); } // If we got redirected, look for the Location header @@ -1104,7 +1117,7 @@ class Zend_Http_Client } // Set the Content-Type header - if ($this->method == self::POST && + if (($this->method == self::POST || $this->method == self::PUT) && (! isset($this->headers[strtolower(self::CONTENT_TYPE)]) && isset($this->enctype))) { $headers[] = self::CONTENT_TYPE . ': ' . $this->enctype; diff --git a/libs/Zend/Http/Client/Adapter/Curl.php b/libs/Zend/Http/Client/Adapter/Curl.php index 4747bd898c..1edec3aaeb 100644 --- a/libs/Zend/Http/Client/Adapter/Curl.php +++ b/libs/Zend/Http/Client/Adapter/Curl.php @@ -16,7 +16,7 @@ * @category Zend * @package Zend_Http * @subpackage Client_Adapter - * @version $Id: Curl.php 22221 2010-05-21 07:00:58Z dragonbe $ + * @version $Id: Curl.php 23484 2010-12-10 03:57:59Z mjh_ca $ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ @@ -334,7 +334,7 @@ class Zend_Http_Client_Adapter_Curl implements Zend_Http_Client_Adapter_Interfac $curlMethod = CURLOPT_CUSTOMREQUEST; $curlValue = "TRACE"; break; - + case Zend_Http_Client::HEAD: $curlMethod = CURLOPT_CUSTOMREQUEST; $curlValue = "HEAD"; diff --git a/libs/Zend/Http/Client/Adapter/Proxy.php b/libs/Zend/Http/Client/Adapter/Proxy.php index 084fdae121..770fb13971 100644 --- a/libs/Zend/Http/Client/Adapter/Proxy.php +++ b/libs/Zend/Http/Client/Adapter/Proxy.php @@ -16,7 +16,7 @@ * @category Zend * @package Zend_Http * @subpackage Client_Adapter - * @version $Id: Proxy.php 22445 2010-06-16 09:09:12Z bate $ + * @version $Id: Proxy.php 23486 2010-12-10 04:05:30Z mjh_ca $ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ @@ -92,10 +92,10 @@ class Zend_Http_Client_Adapter_Proxy extends Zend_Http_Client_Adapter_Socket if (! $this->config['proxy_host']) { return parent::connect($host, $port, $secure); } - + /* Url might require stream context even if proxy connection doesn't */ if ($secure) { - $this->config['sslusecontext'] = true; + $this->config['sslusecontext'] = true; } // Connect (a non-secure connection) to the proxy server @@ -174,20 +174,20 @@ class Zend_Http_Client_Adapter_Proxy extends Zend_Http_Client_Adapter_Socket // Add the request body $request .= "\r\n" . $body; } - + // Send the request if (! @fwrite($this->socket, $request)) { // require_once 'Zend/Http/Client/Adapter/Exception.php'; throw new Zend_Http_Client_Adapter_Exception("Error writing request to proxy server"); } - + if(is_resource($body)) { if(stream_copy_to_stream($body, $this->socket) == 0) { // require_once 'Zend/Http/Client/Adapter/Exception.php'; throw new Zend_Http_Client_Adapter_Exception('Error writing request to server'); } } - + return $request; } diff --git a/libs/Zend/Http/Client/Adapter/Socket.php b/libs/Zend/Http/Client/Adapter/Socket.php index 9d91ed7b85..a56048d60b 100644 --- a/libs/Zend/Http/Client/Adapter/Socket.php +++ b/libs/Zend/Http/Client/Adapter/Socket.php @@ -16,7 +16,7 @@ * @category Zend * @package Zend_Http * @subpackage Client_Adapter - * @version $Id: Socket.php 22577 2010-07-16 15:51:51Z dragonbe $ + * @version $Id: Socket.php 23486 2010-12-10 04:05:30Z mjh_ca $ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ @@ -62,11 +62,11 @@ class Zend_Http_Client_Adapter_Socket implements Zend_Http_Client_Adapter_Interf /** * Stream for storing output - * + * * @var resource */ protected $out_stream = null; - + /** * Parameters array * @@ -124,17 +124,17 @@ class Zend_Http_Client_Adapter_Socket implements Zend_Http_Client_Adapter_Interf } } - /** - * Retrieve the array of all configuration options - * - * @return array - */ - public function getConfig() - { - return $this->config; - } - - /** + /** + * Retrieve the array of all configuration options + * + * @return array + */ + public function getConfig() + { + return $this->config; + } + + /** * Set the stream context for the TCP connection to the server * * Can accept either a pre-existing stream context resource, or an array @@ -290,13 +290,13 @@ class Zend_Http_Client_Adapter_Socket implements Zend_Http_Client_Adapter_Interf // Add the request body $request .= "\r\n" . $body; } - + // Send the request if (! @fwrite($this->socket, $request)) { // require_once 'Zend/Http/Client/Adapter/Exception.php'; throw new Zend_Http_Client_Adapter_Exception('Error writing request to server'); } - + if(is_resource($body)) { if(stream_copy_to_stream($body, $this->socket) == 0) { // require_once 'Zend/Http/Client/Adapter/Exception.php'; @@ -326,7 +326,7 @@ class Zend_Http_Client_Adapter_Socket implements Zend_Http_Client_Adapter_Interf if (rtrim($line) === '') break; } } - + $this->_checkSocketReadTimeout(); $statusCode = Zend_Http_Response::extractCode($response); @@ -353,7 +353,7 @@ class Zend_Http_Client_Adapter_Socket implements Zend_Http_Client_Adapter_Interf // If we got a 'transfer-encoding: chunked' header if (isset($headers['transfer-encoding'])) { - + if (strtolower($headers['transfer-encoding']) == 'chunked') { do { @@ -384,7 +384,7 @@ class Zend_Http_Client_Adapter_Socket implements Zend_Http_Client_Adapter_Interf if($this->out_stream) { if(stream_copy_to_stream($this->socket, $this->out_stream, $read_to - $current_pos) == 0) { $this->_checkSocketReadTimeout(); - break; + break; } } else { $line = @fread($this->socket, $read_to - $current_pos); @@ -405,11 +405,11 @@ class Zend_Http_Client_Adapter_Socket implements Zend_Http_Client_Adapter_Interf } while ($chunksize > 0); } else { $this->close(); - // require_once 'Zend/Http/Client/Adapter/Exception.php'; + // require_once 'Zend/Http/Client/Adapter/Exception.php'; throw new Zend_Http_Client_Adapter_Exception('Cannot handle "' . $headers['transfer-encoding'] . '" transfer encoding'); } - + // We automatically decode chunked-messages when writing to a stream // this means we have to disallow the Zend_Http_Response to do it again if ($this->out_stream) { @@ -421,11 +421,11 @@ class Zend_Http_Client_Adapter_Socket implements Zend_Http_Client_Adapter_Interf // If we got more than one Content-Length header (see ZF-9404) use // the last value sent if (is_array($headers['content-length'])) { - $contentLength = $headers['content-length'][count($headers['content-length']) - 1]; + $contentLength = $headers['content-length'][count($headers['content-length']) - 1]; } else { $contentLength = $headers['content-length']; } - + $current_pos = ftell($this->socket); $chunk = ''; @@ -436,7 +436,7 @@ class Zend_Http_Client_Adapter_Socket implements Zend_Http_Client_Adapter_Interf if($this->out_stream) { if(@stream_copy_to_stream($this->socket, $this->out_stream, $read_to - $current_pos) == 0) { $this->_checkSocketReadTimeout(); - break; + break; } } else { $chunk = @fread($this->socket, $read_to - $current_pos); @@ -459,7 +459,7 @@ class Zend_Http_Client_Adapter_Socket implements Zend_Http_Client_Adapter_Interf if($this->out_stream) { if(@stream_copy_to_stream($this->socket, $this->out_stream) == 0) { $this->_checkSocketReadTimeout(); - break; + break; } } else { $buff = @fread($this->socket, 8192); @@ -516,19 +516,19 @@ class Zend_Http_Client_Adapter_Socket implements Zend_Http_Client_Adapter_Interf } } } - + /** * Set output stream for the response - * + * * @param resource $stream * @return Zend_Http_Client_Adapter_Socket */ - public function setOutputStream($stream) + public function setOutputStream($stream) { $this->out_stream = $stream; return $this; } - + /** * Destructor: make sure the socket is disconnected * diff --git a/libs/Zend/Http/Client/Adapter/Stream.php b/libs/Zend/Http/Client/Adapter/Stream.php index 58dd921f20..676b6f411b 100644 --- a/libs/Zend/Http/Client/Adapter/Stream.php +++ b/libs/Zend/Http/Client/Adapter/Stream.php @@ -16,7 +16,7 @@ * @category Zend * @package Zend_Http * @subpackage Client_Adapter - * @version $Id: Interface.php 16214 2009-06-21 19:34:03Z thomas $ + * @version $Id: Stream.php 23582 2010-12-28 00:17:56Z ramon $ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ @@ -36,11 +36,11 @@ interface Zend_Http_Client_Adapter_Stream { /** * Set output stream - * + * * This function sets output stream where the result will be stored. - * + * * @param resource $stream Stream to write the output to - * + * */ - function setOutputStream($stream); + public function setOutputStream($stream); } diff --git a/libs/Zend/Http/Cookie.php b/libs/Zend/Http/Cookie.php index 49d2ff6ad8..790a99c20d 100644 --- a/libs/Zend/Http/Cookie.php +++ b/libs/Zend/Http/Cookie.php @@ -17,7 +17,7 @@ * @package Zend_Http * @subpackage Cookie * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) - * @version $Id: Cookie.php 21020 2010-02-11 17:27:23Z shahar $ + * @version $Id: Cookie.php 23443 2010-11-24 11:53:13Z shahar $ * @license http://framework.zend.com/license/new-bsd New BSD License */ @@ -277,7 +277,7 @@ class Zend_Http_Cookie * * @param string $cookieStr * @param Zend_Uri_Http|string $refUri Reference URI for default values (domain, path) - * @param boolean $encodeValue Weither or not the cookie's value should be + * @param boolean $encodeValue Whether or not the cookie's value should be * passed through urlencode/urldecode * @return Zend_Http_Cookie A new Zend_Http_Cookie object or false on failure. */ @@ -395,7 +395,7 @@ class Zend_Http_Cookie // Check for either exact match or suffix match return ($cookieDomain == $host || - preg_match("/\.$cookieDomain$/", $host)); + preg_match('/\.' . preg_quote($cookieDomain) . '$/', $host)); } /** diff --git a/libs/Zend/Http/CookieJar.php b/libs/Zend/Http/CookieJar.php index 3d00a8e0af..1de99ee489 100644 --- a/libs/Zend/Http/CookieJar.php +++ b/libs/Zend/Http/CookieJar.php @@ -15,7 +15,7 @@ * @category Zend * @package Zend_Http * @subpackage CookieJar - * @version $Id: CookieJar.php 20096 2010-01-06 02:05:09Z bkarwin $ + * @version $Id: CookieJar.php 23443 2010-11-24 11:53:13Z shahar $ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ @@ -116,11 +116,12 @@ class Zend_Http_CookieJar implements Countable, IteratorAggregate * * @param Zend_Http_Cookie|string $cookie * @param Zend_Uri_Http|string $ref_uri Optional reference URI (for domain, path, secure) + * @param boolean $encodeValue */ - public function addCookie($cookie, $ref_uri = null) + public function addCookie($cookie, $ref_uri = null, $encodeValue = true) { if (is_string($cookie)) { - $cookie = Zend_Http_Cookie::fromString($cookie, $ref_uri); + $cookie = Zend_Http_Cookie::fromString($cookie, $ref_uri, $encodeValue); } if ($cookie instanceof Zend_Http_Cookie) { @@ -142,8 +143,9 @@ class Zend_Http_CookieJar implements Countable, IteratorAggregate * * @param Zend_Http_Response $response * @param Zend_Uri_Http|string $ref_uri Requested URI + * @param boolean $encodeValue */ - public function addCookiesFromResponse($response, $ref_uri) + public function addCookiesFromResponse($response, $ref_uri, $encodeValue = true) { if (! $response instanceof Zend_Http_Response) { // require_once 'Zend/Http/Exception.php'; @@ -155,10 +157,10 @@ class Zend_Http_CookieJar implements Countable, IteratorAggregate if (is_array($cookie_hdrs)) { foreach ($cookie_hdrs as $cookie) { - $this->addCookie($cookie, $ref_uri); + $this->addCookie($cookie, $ref_uri, $encodeValue); } } elseif (is_string($cookie_hdrs)) { - $this->addCookie($cookie_hdrs, $ref_uri); + $this->addCookie($cookie_hdrs, $ref_uri, $encodeValue); } } diff --git a/libs/Zend/Http/Response.php b/libs/Zend/Http/Response.php index e460018977..4dbdecd3d5 100644 --- a/libs/Zend/Http/Response.php +++ b/libs/Zend/Http/Response.php @@ -16,7 +16,7 @@ * @category Zend * @package Zend_Http * @subpackage Response - * @version $Id: Response.php 22555 2010-07-13 16:06:29Z shahar $ + * @version $Id: Response.php 23484 2010-12-10 03:57:59Z mjh_ca $ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ @@ -141,14 +141,14 @@ class Zend_Http_Response * * If no message is passed, the message will be guessed according to the response code. * - * @param int $code Response code (200, 404, ...) - * @param array $headers Headers array + * @param int $code Response code (200, 404, ...) + * @param array $headers Headers array * @param string $body Response body * @param string $version HTTP version * @param string $message Response code as text * @throws Zend_Http_Exception */ - public function __construct($code, $headers, $body = null, $version = '1.1', $message = null) + public function __construct($code, array $headers, $body = null, $version = '1.1', $message = null) { // Make sure the response code is valid and set it if (self::responseCodeAsText($code) === null) { @@ -158,15 +158,17 @@ class Zend_Http_Response $this->code = $code; - // Make sure we got valid headers and set them - if (! is_array($headers)) { - // require_once 'Zend/Http/Exception.php'; - throw new Zend_Http_Exception('No valid headers were passed'); - } - foreach ($headers as $name => $value) { - if (is_int($name)) - list($name, $value) = explode(": ", $value, 1); + if (is_int($name)) { + $header = explode(":", $value, 2); + if (count($header) != 2) { + // require_once 'Zend/Http/Exception.php'; + throw new Zend_Http_Exception("'{$value}' is not a valid HTTP header"); + } + + $name = trim($header[0]); + $value = trim($header[1]); + } $this->headers[ucwords(strtolower($name))] = $value; } diff --git a/libs/Zend/Http/Response/Stream.php b/libs/Zend/Http/Response/Stream.php index 667ca321ab..288b65752f 100644 --- a/libs/Zend/Http/Response/Stream.php +++ b/libs/Zend/Http/Response/Stream.php @@ -16,7 +16,7 @@ * @category Zend * @package Zend_Http * @subpackage Response - * @version $Id: Response.php 17131 2009-07-26 10:03:39Z shahar $ + * @version $Id: Stream.php 20785 2010-01-31 09:43:03Z mikaelkael $ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ diff --git a/libs/Zend/Http/UserAgent.php b/libs/Zend/Http/UserAgent.php new file mode 100644 index 0000000000..6588d75d90 --- /dev/null +++ b/libs/Zend/Http/UserAgent.php @@ -0,0 +1,847 @@ +<?php +/** + * Zend Framework + * + * LICENSE + * + * This source file is subject to the new BSD license that is bundled + * with this package in the file LICENSE.txt. + * It is also available through the world-wide-web at this URL: + * http://framework.zend.com/license/new-bsd + * If you did not receive a copy of the license and are unable to + * obtain it through the world-wide-web, please send an email + * to license@zend.com so we can send you a copy immediately. + * + * @category Zend + * @package Zend_Http_UserAgent + * @subpackage UserAgent + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +/** + * Lists of User Agent chains for testing : + * + * - http://www.useragentstring.com/layout/useragentstring.php + * - http://user-agent-string.info/list-of-ua + * - http://www.user-agents.org/allagents.xml + * - http://en.wikipedia.org/wiki/List_of_user_agents_for_mobile_phones + * - http://www.mobilemultimedia.be/fr/ + * + * @category Zend + * @package Zend_Http_UserAgent + * @subpackage UserAgent + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ +class Zend_Http_UserAgent implements Serializable +{ + /** + * 'desktop' by default if the sequence return false for each item or is empty + */ + const DEFAULT_IDENTIFICATION_SEQUENCE = 'mobile,desktop'; + + /** + * Default persitent storage adapter : Session or NonPersitent + */ + const DEFAULT_PERSISTENT_STORAGE_ADAPTER = 'Session'; + + /** + * 'desktop' by default if the sequence return false for each item + */ + const DEFAULT_BROWSER_TYPE = 'desktop'; + + /** + * Default User Agent chain to prevent empty value + */ + const DEFAULT_HTTP_USER_AGENT = 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)'; + + /** + * Default Http Accept param to prevent empty value + */ + const DEFAULT_HTTP_ACCEPT = "application/xhtml+xml"; + + /** + * Default markup language + */ + const DEFAULT_MARKUP_LANGUAGE = "xhtml"; + + /** + * Browser type + * + * @var string + */ + protected $_browserType; + + /** + * Browser type class + * + * Map of browser types to classes. + * + * @var array + */ + protected $_browserTypeClass = array(); + + /** + * Array to store config + * + * Default values are provided to ensure specific keys are present at + * instantiation. + * + * @var array + */ + protected $_config = array( + 'identification_sequence' => self::DEFAULT_IDENTIFICATION_SEQUENCE, + 'storage' => array( + 'adapter' => self::DEFAULT_PERSISTENT_STORAGE_ADAPTER, + ), + ); + + /** + * Identified device + * + * @var Zend_Http_UserAgent_Device + */ + protected $_device; + + /** + * Whether or not this instance is immutable. + * + * If true, none of the following may be modified: + * - $_server + * - $_browserType + * - User-Agent (defined in $_server) + * - HTTP Accept value (defined in $_server) + * - $_storage + * + * @var bool + */ + protected $_immutable = false; + + /** + * Plugin loaders + * @var array + */ + protected $_loaders = array(); + + /** + * Valid plugin loader types + * @var array + */ + protected $_loaderTypes = array('storage', 'device'); + + /** + * Trace of items matched to identify the browser type + * + * @var array + */ + protected $_matchLog = array(); + + /** + * Server variable + * + * @var array + */ + protected $_server; + + /** + * Persistent storage handler + * + * @var Zend_Http_UserAgent_Storage + */ + protected $_storage; + + /** + * Constructor + * + * @param null|array|Zend_Config|ArrayAccess $options + * @return void + */ + public function __construct($options = null) + { + if (null !== $options) { + $this->setOptions($options); + } + } + + /** + * Serialized representation of the object + * + * @return string + */ + public function serialize() + { + $spec = array( + 'browser_type' => $this->_browserType, + 'config' => $this->_config, + 'device_class' => get_class($this->_device), + 'device' => $this->_device->serialize(), + 'user_agent' => $this->getServerValue('http_user_agent'), + 'http_accept' => $this->getServerValue('http_accept'), + ); + return serialize($spec); + } + + /** + * Unserialize a previous representation of the object + * + * @param string $serialized + * @return void + */ + public function unserialize($serialized) + { + $spec = unserialize($serialized); + + $this->setOptions($spec); + + // Determine device class and ensure the class is loaded + $deviceClass = $spec['device_class']; + if (!class_exists($deviceClass)) { + $this->_getUserAgentDevice($this->getBrowserType()); + } + + // Get device specification and instantiate + $deviceSpec = unserialize($spec['device']); + $deviceSpec['_config'] = $this->getConfig(); + $deviceSpec['_server'] = $this->getServer(); + $this->_device = new $deviceClass($deviceSpec); + } + + /** + * Configure instance + * + * @param array|Zend_Config|ArrayAccess $options + * @return Zend_Http_UserAgent + */ + public function setOptions($options) + { + if ($options instanceof Zend_Config) { + $options = $options->toArray(); + } + + if (!is_array($options) + && !$options instanceof ArrayAccess + && !$options instanceof Traversable + ) { + // require_once 'Zend/Http/UserAgent/Exception.php'; + throw new Zend_Http_UserAgent_Exception(sprintf( + 'Invalid argument; expected array, Zend_Config object, or object implementing ArrayAccess and Traversable; received %s', + (is_object($options) ? get_class($options) : gettype($options)) + )); + } + + // Set $_SERVER first + if (isset($options['server'])) { + $this->setServer($options['server']); + unset($options['server']); + } + + // Get plugin loaders sorted + if (isset($options['plugin_loader'])) { + $plConfig = $options['plugin_loader']; + if (is_array($plConfig) || $plConfig instanceof Traversable) { + foreach ($plConfig as $type => $class) { + $this->setPluginLoader($type, $class); + } + } + unset($plConfig, $options['plugin_loader']); + } + + // And then loop through the remaining options + $config = array(); + foreach ($options as $key => $value) { + switch (strtolower($key)) { + case 'browser_type': + $this->setBrowserType($value); + break; + case 'http_accept': + $this->setHttpAccept($value); + break; + case 'user_agent': + $this->setUserAgent($value); + break; + default: + // Cache remaining options for $_config + $config[$key] = $value; + break; + } + } + $this->setConfig($config); + + return $this; + } + + /** + * Comparison of the UserAgent chain and browser signatures. + * + * The comparison is case-insensitive : the browser signatures must be in lower + * case + * + * @param string $deviceClass Name of class against which a match will be attempted + * @return bool + */ + protected function _match($deviceClass) + { + // Validate device class + $r = new ReflectionClass($deviceClass); + if (!$r->implementsInterface('Zend_Http_UserAgent_Device')) { + throw new Zend_Http_UserAgent_Exception(sprintf( + 'Invalid device class provided ("%s"); must implement Zend_Http_UserAgent_Device', + $deviceClass + )); + } + + $userAgent = $this->getUserAgent(); + + // Call match method on device class + return call_user_func( + array($deviceClass, 'match'), + $userAgent, + $this->getServer() + ); + } + + /** + * Loads class for a user agent device + * + * @param string $browserType Browser type + * @return string + * @throws Zend_Loader_PluginLoader_Exception if unable to load UA device + */ + protected function _getUserAgentDevice($browserType) + { + $browserType = strtolower($browserType); + if (isset($this->_browserTypeClass[$browserType])) { + return $this->_browserTypeClass[$browserType]; + } + + if (isset($this->_config[$browserType]) + && isset($this->_config[$browserType]['device']) + ) { + $deviceConfig = $this->_config[$browserType]['device']; + if (is_array($deviceConfig) && isset($deviceConfig['classname'])) { + $device = (string) $deviceConfig['classname']; + if (!class_exists($device)) { + // require_once 'Zend/Http/UserAgent/Exception.php'; + throw new Zend_Http_UserAgent_Exception(sprintf( + 'Invalid classname "%s" provided in device configuration for browser type "%s"', + $device, + $browserType + )); + } + } elseif (is_array($deviceConfig) && isset($deviceConfig['path'])) { + $loader = $this->getPluginLoader('device'); + $path = $deviceConfig['path']; + $prefix = isset($deviceConfig['prefix']) ? $deviceConfig['prefix'] : 'Zend_Http_UserAgent'; + $loader->addPrefixPath($prefix, $path); + + $device = $loader->load($browserType); + } else { + $loader = $this->getPluginLoader('device'); + $device = $loader->load($browserType); + } + } else { + $loader = $this->getPluginLoader('device'); + $device = $loader->load($browserType); + } + + $this->_browserTypeClass[$browserType] = $device; + + return $device; + } + + /** + * Returns the User Agent value + * + * If $userAgent param is null, the value of $_server['HTTP_USER_AGENT'] is + * returned. + * + * @return string + */ + public function getUserAgent() + { + if (null === ($ua = $this->getServerValue('http_user_agent'))) { + $ua = self::DEFAULT_HTTP_USER_AGENT; + $this->setUserAgent($ua); + } + + return $ua; + } + + /** + * Force or replace the UA chain in $_server variable + * + * @param string $userAgent Forced UserAgent chain + * @return Zend_Http_UserAgent + */ + public function setUserAgent($userAgent) + { + $this->setServerValue('http_user_agent', $userAgent); + return $this; + } + + /** + * Returns the HTTP Accept server param + * + * @param string $httpAccept (option) forced HTTP Accept chain + * @return string + */ + public function getHttpAccept($httpAccept = null) + { + if (null === ($accept = $this->getServerValue('http_accept'))) { + $accept = self::DEFAULT_HTTP_ACCEPT; + $this->setHttpAccept($accept); + } + return $accept; + } + + /** + * Force or replace the HTTP_ACCEPT chain in self::$_server variable + * + * @param string $httpAccept Forced HTTP Accept chain + * @return Zend_Http_UserAgent + */ + public function setHttpAccept($httpAccept) + { + $this->setServerValue('http_accept', $httpAccept); + return $this; + } + + /** + * Returns the persistent storage handler + * + * Session storage is used by default unless a different storage adapter + * has been set via the "persistent_storage_adapter" key. That key should + * contain either a fully qualified class name, or a short name that + * resolves via the plugin loader. + * + * @param string $browser Browser identifier (User Agent chain) + * @return Zend_Http_UserAgent_Storage + */ + public function getStorage($browser = null) + { + if (null === $browser) { + $browser = $this->getUserAgent(); + } + if (null === $this->_storage) { + $config = $this->_config['storage']; + $adapter = $config['adapter']; + if (!class_exists($adapter)) { + $loader = $this->getPluginLoader('storage'); + $adapter = $loader->load($adapter); + $loader = $this->getPluginLoader('storage'); + } + $options = array('browser_type' => $browser); + if (isset($config['options'])) { + $options = array_merge($options, $config['options']); + } + $this->setStorage(new $adapter($options)); + } + return $this->_storage; + } + + /** + * Sets the persistent storage handler + * + * @param Zend_Http_UserAgent_Storage $storage + * @return Zend_Http_UserAgent + */ + public function setStorage(Zend_Http_UserAgent_Storage $storage) + { + if ($this->_immutable) { + // require_once 'Zend/Http/UserAgent/Exception.php'; + throw new Zend_Http_UserAgent_Exception( + 'The User-Agent device object has already been retrieved; the storage object is now immutable' + ); + } + + $this->_storage = $storage; + return $this; + } + + /** + * Clean the persistent storage + * + * @param string $browser Browser identifier (User Agent chain) + * @return void + */ + public function clearStorage($browser = null) + { + $this->getStorage($browser)->clear(); + } + + /** + * Get user configuration + * + * @return array + */ + public function getConfig() + { + return $this->_config; + } + + /** + * Config parameters is an Array or a Zend_Config object + * + * The allowed parameters are : + * - the identification sequence (can be empty) => desktop browser type is the + * default browser type returned + * $config['identification_sequence'] : ',' separated browser types + * - the persistent storage adapter + * $config['persistent_storage_adapter'] = "Session" or "NonPersistent" + * - to add or replace a browser type device + * $config[(type)]['device']['path'] + * $config[(type)]['device']['classname'] + * - to add or replace a browser type features adapter + * $config[(type)]['features']['path'] + * $config[(type)]['features']['classname'] + * + * @param mixed $config (option) Config array + * @return Zend_Http_UserAgent + */ + public function setConfig($config = array()) + { + if ($config instanceof Zend_Config) { + $config = $config->toArray(); + } + + // Verify that Config parameters are in an array. + if (!is_array($config) && !$config instanceof Traversable) { + // require_once 'Zend/Http/UserAgent/Exception.php'; + throw new Zend_Http_UserAgent_Exception(sprintf( + 'Config parameters must be in an array or a Traversable object; received "%s"', + (is_object($config) ? get_class($config) : gettype($config)) + )); + } + + if ($config instanceof Traversable) { + $tmp = array(); + foreach ($config as $key => $value) { + $tmp[$key] = $value; + } + $config = $tmp; + unset($tmp); + } + + $this->_config = array_merge($this->_config, $config); + return $this; + } + + /** + * @return the $device + */ + public function getDevice() + { + if (null !== $this->_device) { + return $this->_device; + } + + $userAgent = $this->getUserAgent(); + + // search an existing identification in the session + $storage = $this->getStorage($userAgent); + + if (!$storage->isEmpty()) { + // If the user agent and features are already existing, the + // Zend_Http_UserAgent object is serialized in the session + $object = $storage->read(); + $this->unserialize($object); + } else { + // Otherwise, the identification is made and stored in the session. + // Find the browser type: + $this->setBrowserType($this->_matchUserAgent()); + $this->_createDevice(); + + // put the result in storage: + $this->getStorage($userAgent) + ->write($this->serialize()); + } + + // Mark the object as immutable + $this->_immutable = true; + + // Return the device instance + return $this->_device; + } + + /** + * Retrieve the browser type + * + * @return string $browserType + */ + public function getBrowserType() + { + return $this->_browserType; + } + + /** + * Set the browser "type" + * + * @param string $browserType + * @return Zend_Http_UserAgent + */ + public function setBrowserType($browserType) + { + if ($this->_immutable) { + // require_once 'Zend/Http/UserAgent/Exception.php'; + throw new Zend_Http_UserAgent_Exception( + 'The User-Agent device object has already been retrieved; the browser type is now immutable' + ); + } + + $this->_browserType = $browserType; + return $this; + } + + /** + * Retrieve the "$_SERVER" array + * + * Basically, the $_SERVER array or an equivalent container storing the + * data that will be introspected. + * + * If the value has not been previously set, it sets itself from the + * $_SERVER superglobal. + * + * @return array + */ + public function getServer() + { + if (null === $this->_server) { + $this->setServer($_SERVER); + } + return $this->_server; + } + + /** + * Retrieve the "$_SERVER" array + * + * Basically, the $_SERVER array or an equivalent container storing the + * data that will be introspected. + * + * @param array|ArrayAccess $server + * @return void + * @throws Zend_Http_UserAgent_Exception on invalid parameter + */ + public function setServer($server) + { + if ($this->_immutable) { + // require_once 'Zend/Http/UserAgent/Exception.php'; + throw new Zend_Http_UserAgent_Exception( + 'The User-Agent device object has already been retrieved; the server array is now immutable' + ); + } + + if (!is_array($server) && !$server instanceof Traversable) { + // require_once 'Zend/Http/UserAgent/Exception.php'; + throw new Zend_Http_UserAgent_Exception(sprintf( + 'Expected an array or object implementing Traversable; received %s', + (is_object($server) ? get_class($server) : gettype($server)) + )); + } + + // Get an array if we don't have one + if ($server instanceof ArrayObject) { + $server = $server->getArrayCopy(); + } elseif ($server instanceof Traversable) { + $tmp = array(); + foreach ($server as $key => $value) { + $tmp[$key] = $value; + } + $server = $tmp; + unset($tmp); + } + + // Normalize key case + $server = array_change_key_case($server, CASE_LOWER); + + $this->_server = $server; + return $this; + } + + /** + * Retrieve a server value + * + * @param string $key + * @return mixed + */ + public function getServerValue($key) + { + $key = strtolower($key); + $server = $this->getServer(); + $return = null; + if (isset($server[$key])) { + $return = $server[$key]; + } + unset($server); + return $return; + } + + /** + * Set a server value + * + * @param string|int|float $key + * @param mixed $value + * @return void + */ + public function setServerValue($key, $value) + { + if ($this->_immutable) { + // require_once 'Zend/Http/UserAgent/Exception.php'; + throw new Zend_Http_UserAgent_Exception( + 'The User-Agent device object has already been retrieved; the server array is now immutable' + ); + } + + $server = $this->getServer(); // ensure it's been initialized + $key = strtolower($key); + $this->_server[$key] = $value; + return $this; + } + + /** + * Set plugin loader + * + * @param string $type Type of plugin loader; one of 'storage', (?) + * @param string|Zend_Loader_PluginLoader $loader + * @return Zend_Http_UserAgent + */ + public function setPluginLoader($type, $loader) + { + $type = $this->_validateLoaderType($type); + + if (is_string($loader)) { + if (!class_exists($loader)) { + // require_once 'Zend/Loader.php'; + Zend_Loader::loadClass($loader); + } + $loader = new $loader(); + } elseif (!is_object($loader)) { + // require_once 'Zend/Http/UserAgent/Exception.php'; + throw new Zend_Http_UserAgent_Exception(sprintf( + 'Expected a plugin loader class or object; received %s', + gettype($loader) + )); + } + if (!$loader instanceof Zend_Loader_PluginLoader) { + // require_once 'Zend/Http/UserAgent/Exception.php'; + throw new Zend_Http_UserAgent_Exception(sprintf( + 'Expected an object extending Zend_Loader_PluginLoader; received %s', + get_class($loader) + )); + } + + $basePrefix = 'Zend_Http_UserAgent_'; + $basePath = 'Zend/Http/UserAgent/'; + switch ($type) { + case 'storage': + $prefix = $basePrefix . 'Storage'; + $path = $basePath . 'Storage'; + break; + case 'device': + $prefix = $basePrefix; + $path = $basePath; + break; + } + $loader->addPrefixPath($prefix, $path); + $this->_loaders[$type] = $loader; + return $this; + } + + /** + * Get a plugin loader + * + * @param string $type A valid plugin loader type; see {@link $_loaderTypes} + * @return Zend_Loader_PluginLoader + */ + public function getPluginLoader($type) + { + $type = $this->_validateLoaderType($type); + if (!isset($this->_loaders[$type])) { + // require_once 'Zend/Loader/PluginLoader.php'; + $this->setPluginLoader($type, new Zend_Loader_PluginLoader()); + } + return $this->_loaders[$type]; + } + + /** + * Validate a plugin loader type + * + * Verifies that it is in {@link $_loaderTypes}, and returns a normalized + * version of the type. + * + * @param string $type + * @return string + * @throws Zend_Http_UserAgent_Exception on invalid type + */ + protected function _validateLoaderType($type) + { + $type = strtolower($type); + if (!in_array($type, $this->_loaderTypes)) { + $types = implode(', ', $this->_loaderTypes); + + // require_once 'Zend/Http/UserAgent/Exception.php'; + throw new Zend_Http_UserAgent_Exception(sprintf( + 'Expected one of "%s" for plugin loader type; received "%s"', + $types, + (string) $type + )); + } + return $type; + } + + /** + * Run the identification sequence to match the right browser type according to the + * user agent + * + * @return Zend_Http_UserAgent_Result + */ + protected function _matchUserAgent() + { + $type = self::DEFAULT_BROWSER_TYPE; + + // If we have no identification sequence, just return the default type + if (empty($this->_config['identification_sequence'])) { + return $type; + } + + // Get sequence against which to match + $sequence = explode(',', $this->_config['identification_sequence']); + + // If a browser type is already configured, push that to the front of the list + if (null !== ($browserType = $this->getBrowserType())) { + array_unshift($sequence, $browserType); + } + + // Append the default browser type to the list if not alread in the list + if (!in_array($type, $sequence)) { + $sequence[] = $type; + } + + // Test each type until we find a match + foreach ($sequence as $browserType) { + $browserType = trim($browserType); + $className = $this->_getUserAgentDevice($browserType); + + // Attempt to match this device class + if ($this->_match($className)) { + $type = $browserType; + $this->_browserTypeClass[$type] = $className; + break; + } + } + + return $type; + } + + /** + * Creates device object instance + * + * @return void + */ + protected function _createDevice() + { + $browserType = $this->getBrowserType(); + $classname = $this->_getUserAgentDevice($browserType); + $this->_device = new $classname($this->getUserAgent(), $this->getServer(), $this->getConfig()); + } +} diff --git a/libs/Zend/Http/UserAgent/AbstractDevice.php b/libs/Zend/Http/UserAgent/AbstractDevice.php new file mode 100644 index 0000000000..24b47b071d --- /dev/null +++ b/libs/Zend/Http/UserAgent/AbstractDevice.php @@ -0,0 +1,974 @@ +<?php +/** + * Zend Framework + * + * LICENSE + * + * This source file is subject to the new BSD license that is bundled + * with this package in the file LICENSE.txt. + * It is also available through the world-wide-web at this URL: + * http://framework.zend.com/license/new-bsd + * If you did not receive a copy of the license and are unable to + * obtain it through the world-wide-web, please send an email + * to license@zend.com so we can send you a copy immediately. + * + * @category Zend + * @package Zend_Http + * @subpackage UserAgent + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +// require_once 'Zend/Http/UserAgent/Device.php'; + +/** + * Abstract Class to define a browser device. + * + * @category Zend + * @package Zend_Http + * @subpackage UserAgent + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ +abstract class Zend_Http_UserAgent_AbstractDevice + implements Zend_Http_UserAgent_Device +{ + /** + * Browser signature + * + * @var string + */ + protected $_browser = ''; + + /** + * Browser version + * + * @var string + */ + protected $_browserVersion = ''; + + /** + * Configuration + * + * @var array + */ + protected $_config; + + /** + * User Agent chain + * + * @var string + */ + protected $_userAgent; + + /** + * Server variable + * + * @var array + */ + protected $_server; + + /** + * Image types + * + * @var array + */ + protected $_images = array( + 'jpeg', + 'gif', + 'png', + 'pjpeg', + 'x-png', + 'bmp', + ); + + /** + * Browser/Device features + * + * @var array + */ + protected $_aFeatures = array(); + + /** + * Browser/Device features groups + * + * @var array + */ + protected $_aGroup = array(); + + /** + * Constructor + * + * @param null|string|array $userAgent If array, restores from serialized version + * @param array $server + * @param array $config + * @return void + */ + public function __construct($userAgent = null, array $server = array(), array $config = array()) + { + if (is_array($userAgent)) { + // Restoring from serialized array + $this->_restoreFromArray($userAgent); + } else { + // Constructing new object + $this->setUserAgent($userAgent); + $this->_server = $server; + $this->_config = $config; + $this->_getDefaultFeatures(); + $this->_defineFeatures(); + } + } + + /** + * Serialize object + * + * @return string + */ + public function serialize() + { + $spec = array( + '_aFeatures' => $this->_aFeatures, + '_aGroup' => $this->_aGroup, + '_browser' => $this->_browser, + '_browserVersion' => $this->_browserVersion, + '_userAgent' => $this->_userAgent, + '_images' => $this->_images, + ); + return serialize($spec); + } + + /** + * Unserialize + * + * @param string $serialized + * @return void + */ + public function unserialize($serialized) + { + $spec = unserialize($serialized); + $this->_restoreFromArray($spec); + } + + /** + * Restore object state from array + * + * @param array $spec + * @return void + */ + protected function _restoreFromArray(array $spec) + { + foreach ($spec as $key => $value) { + if (property_exists($this, $key)) { + $this->{$key} = $value; + } + } + } + + /** + * Look for features + * + * @return array|null + */ + protected function _defineFeatures() + { + $features = $this->_loadFeaturesAdapter(); + + if (is_array($features)) { + $this->_aFeatures = array_merge($this->_aFeatures, $features); + } + + return $this->_aFeatures; + } + + /** + * Gets the browser type identifier + * + * @return string + */ + abstract public function getType(); + + /** + * Check a feature for the current browser/device. + * + * @param string $feature The feature to check. + * @return bool + */ + public function hasFeature($feature) + { + return (!empty($this->_aFeatures[$feature])); + } + + /** + * Gets the value of the current browser/device feature + * + * @param string $feature Feature to search + * @return string|null + */ + public function getFeature($feature) + { + if ($this->hasFeature($feature)) { + return $this->_aFeatures[$feature]; + } + } + + /** + * Set a feature for the current browser/device. + * + * @param string $feature The feature to set. + * @param string $value (option) feature value. + * @param string $group (option) Group to associate with the feature + * @return Zend_Http_UserAgent_AbstractDevice + */ + public function setFeature($feature, $value = false, $group = '') + { + $this->_aFeatures[$feature] = $value; + if (!empty($group)) { + $this->setGroup($group, $feature); + } + return $this; + } + + /** + * Affects a feature to a group + * + * @param string $group Group name + * @param string $feature Feature name + * @return Zend_Http_UserAgent_AbstractDevice + */ + public function setGroup($group, $feature) + { + if (!isset($this->_aGroup[$group])) { + $this->_aGroup[$group] = array(); + } + if (!in_array($feature, $this->_aGroup[$group])) { + $this->_aGroup[$group][] = $feature; + } + return $this; + } + + /** + * Gets an array of features associated to a group + * + * @param string $group Group param + * @return array + */ + public function getGroup($group) + { + return $this->_aGroup[$group]; + } + + /** + * Gets all the browser/device features + * + * @return array + */ + public function getAllFeatures() + { + return $this->_aFeatures; + } + + /** + * Gets all the browser/device features' groups + * + * @return array + */ + public function getAllGroups() + { + return $this->_aGroup; + } + + /** + * Sets all the standard features extracted from the User Agent chain and $this->_server + * vars + * + * @return void + */ + protected function _getDefaultFeatures() + { + $server = array(); + + // gets info from user agent chain + $uaExtract = $this->extractFromUserAgent($this->getUserAgent()); + + if (is_array($uaExtract)) { + foreach ($uaExtract as $key => $info) { + $this->setFeature($key, $info, 'product_info'); + } + } + + if (isset($uaExtract['browser_name'])) { + $this->_browser = $uaExtract['browser_name']; + } + if (isset($uaExtract['browser_version'])) { + $this->_browserVersion = $uaExtract['browser_version']; + } + if (isset($uaExtract['device_os'])) { + $this->device_os = $uaExtract['device_os_name']; + } + + /* browser & device info */ + $this->setFeature('is_wireless_device', false, 'product_info'); + $this->setFeature('is_mobile', false, 'product_info'); + $this->setFeature('is_desktop', false, 'product_info'); + $this->setFeature('is_tablet', false, 'product_info'); + $this->setFeature('is_bot', false, 'product_info'); + $this->setFeature('is_email', false, 'product_info'); + $this->setFeature('is_text', false, 'product_info'); + $this->setFeature('device_claims_web_support', false, 'product_info'); + + $this->setFeature('is_' . strtolower($this->getType()), true, 'product_info'); + + /* sets the browser name */ + if (isset($this->list) && empty($this->_browser)) { + $lowerUserAgent = strtolower($this->getUserAgent()); + foreach ($this->list as $browser_signature) { + if (strpos($lowerUserAgent, $browser_signature) !== false) { + $this->_browser = strtolower($browser_signature); + $this->setFeature('browser_name', $this->_browser, 'product_info'); + } + } + } + + /* sets the client IP */ + if (isset($this->_server['remote_addr'])) { + $this->setFeature('client_ip', $this->_server['remote_addr'], 'product_info'); + } elseif (isset($this->_server['http_x_forwarded_for'])) { + $this->setFeature('client_ip', $this->_server['http_x_forwarded_for'], 'product_info'); + } elseif (isset($this->_server['http_client_ip'])) { + $this->setFeature('client_ip', $this->_server['http_client_ip'], 'product_info'); + } + + /* sets the server infos */ + if (isset($this->_server['server_software'])) { + if (strpos($this->_server['server_software'], 'Apache') !== false || strpos($this->_server['server_software'], 'LiteSpeed') !== false) { + $server['version'] = 1; + if (strpos($this->_server['server_software'], 'Apache/2') !== false) { + $server['version'] = 2; + } + $server['server'] = 'apache'; + } + + if (strpos($this->_server['server_software'], 'Microsoft-IIS') !== false) { + $server['server'] = 'iis'; + } + + if (strpos($this->_server['server_software'], 'Unix') !== false) { + $server['os'] = 'unix'; + if (isset($_ENV['MACHTYPE'])) { + if (strpos($_ENV['MACHTYPE'], 'linux') !== false) { + $server['os'] = 'linux'; + } + } + } elseif (strpos($this->_server['server_software'], 'Win') !== false) { + $server['os'] = 'windows'; + } + + if (preg_match('/Apache\/([0-9\.]*)/', $this->_server['server_software'], $arr)) { + if ($arr[1]) { + $server['version'] = $arr[1]; + $server['server'] = 'apache'; + } + } + } + + $this->setFeature('php_version', phpversion(), 'server_info'); + if (isset($server['server'])) { + $this->setFeature('server_os', $server['server'], 'server_info'); + } + if (isset($server['version'])) { + $this->setFeature('server_os_version', $server['version'], 'server_info'); + } + if (isset($this->_server['http_accept'])) { + $this->setFeature('server_http_accept', $this->_server['http_accept'], 'server_info'); + } + if (isset($this->_server['http_accept_language'])) { + $this->setFeature('server_http_accept_language', $this->_server['http_accept_language'], 'server_info'); + } + if (isset($this->_server['server_addr'])) { + $this->setFeature('server_ip', $this->_server['server_addr'], 'server_info'); + } + if (isset($this->_server['server_name'])) { + $this->setFeature('server_name', $this->_server['server_name'], 'server_info'); + } + } + + /** + * Extract and sets informations from the User Agent chain + * + * @param string $userAgent User Agent chain + * @return array + */ + public static function extractFromUserAgent($userAgent) + { + $userAgent = trim($userAgent); + + /** + * @see http://www.texsoft.it/index.php?c=software&m=sw.php.useragent&l=it + */ + $pattern = "(([^/\s]*)(/(\S*))?)(\s*\[[a-zA-Z][a-zA-Z]\])?\s*(\\((([^()]|(\\([^()]*\\)))*)\\))?\s*"; + preg_match("#^$pattern#", $userAgent, $match); + + $comment = array(); + if (isset($match[7])) { + $comment = explode(';', $match[7]); + } + + // second part if exists + $end = substr($userAgent, strlen($match[0])); + if (!empty($end)) { + $result['others']['full'] = $end; + } + + $match2 = array(); + if (isset($result['others'])) { + preg_match_all('/(([^\/\s]*)(\/)?([^\/\(\)\s]*)?)(\s\((([^\)]*)*)\))?/i', $result['others']['full'], $match2); + } + $result['user_agent'] = trim($match[1]); + $result['product_name'] = isset($match[2]) ? trim($match[2]) : ''; + $result['browser_name'] = $result['product_name']; + if (isset($match[4]) && trim($match[4])) { + $result['product_version'] = trim($match[4]); + $result['browser_version'] = trim($match[4]); + } + if (count($comment) && !empty($comment[0])) { + $result['comment']['full'] = trim($match[7]); + $result['comment']['detail'] = $comment; + $result['compatibility_flag'] = trim($comment[0]); + if (isset($comment[1])) { + $result['browser_token'] = trim($comment[1]); + } + if (isset($comment[2])) { + $result['device_os_token'] = trim($comment[2]); + } + } + if (empty($result['device_os_token']) && !empty($result['compatibility_flag'])) { + // some browsers do not have a platform token + $result['device_os_token'] = $result['compatibility_flag']; + } + if ($match2) { + $i = 0; + $max = count($match2[0]); + for ($i = 0; $i < $max; $i ++) { + if (!empty($match2[0][$i])) { + $result['others']['detail'][] = array( + $match2[0][$i], + $match2[2][$i], + $match2[4][$i], + ); + } + } + } + + /** Security level */ + $security = array( + 'N' => 'no security', + 'U' => 'strong security', + 'I' => 'weak security', + ); + if (!empty($result['browser_token'])) { + if (isset($security[$result['browser_token']])) { + $result['security_level'] = $security[$result['browser_token']]; + unset($result['browser_token']); + } + } + + $product = strtolower($result['browser_name']); + + // Mozilla : true && false + $compatibleOrIe = false; + if (isset($result['compatibility_flag']) && isset($result['comment'])) { + $compatibleOrIe = ($result['compatibility_flag'] == 'compatible' || strpos($result['comment']['full'], "MSIE") !== false); + } + if ($product == 'mozilla' && $compatibleOrIe) { + if (!empty($result['browser_token'])) { + // Classic Mozilla chain + preg_match_all('/([^\/\s].*)(\/|\s)(.*)/i', $result['browser_token'], $real); + } else { + // MSIE specific chain with 'Windows' compatibility flag + foreach ($result['comment']['detail'] as $v) { + if (strpos($v, 'MSIE') !== false) { + $real[0][1] = trim($v); + $result['browser_engine'] = "MSIE"; + $real[1][0] = "Internet Explorer"; + $temp = explode(' ', trim($v)); + $real[3][0] = $temp[1]; + + } + if (strpos($v, 'Win') !== false) { + $result['device_os_token'] = trim($v); + } + } + } + + if (!empty($real[0])) { + $result['browser_name'] = $real[1][0]; + $result['browser_version'] = $real[3][0]; + } else { + $result['browser_name'] = $result['browser_token']; + $result['browser_version'] = '??'; + } + } elseif ($product == 'mozilla' && $result['browser_version'] < 5.0) { + // handles the real Mozilla (or old Netscape if version < 5.0) + $result['browser_name'] = 'Netscape'; + } + + /** windows */ + if ($result['browser_name'] == 'MSIE') { + $result['browser_engine'] = 'MSIE'; + $result['browser_name'] = 'Internet Explorer'; + } + if (isset($result['device_os_token'])) { + if (strpos($result['device_os_token'], 'Win') !== false) { + + $windows = array( + 'Windows NT 6.1' => 'Windows 7', + 'Windows NT 6.0' => 'Windows Vista', + 'Windows NT 5.2' => 'Windows Server 2003', + 'Windows NT 5.1' => 'Windows XP', + 'Windows NT 5.01' => 'Windows 2000 SP1', + 'Windows NT 5.0' => 'Windows 2000', + 'Windows NT 4.0' => 'Microsoft Windows NT 4.0', + 'WinNT' => 'Microsoft Windows NT 4.0', + 'Windows 98; Win 9x 4.90' => 'Windows Me', + 'Windows 98' => 'Windows 98', + 'Win98' => 'Windows 98', + 'Windows 95' => 'Windows 95', + 'Win95' => 'Windows 95', + 'Windows CE' => 'Windows CE', + ); + if (isset($windows[$result['device_os_token']])) { + $result['device_os_name'] = $windows[$result['device_os_token']]; + } else { + $result['device_os_name'] = $result['device_os_token']; + } + } + } + + // iphone + $apple_device = array( + 'iPhone', + 'iPod', + 'iPad', + ); + if (isset($result['compatibility_flag'])) { + if (in_array($result['compatibility_flag'], $apple_device)) { + $result['device'] = strtolower($result['compatibility_flag']); + $result['device_os_token'] = 'iPhone OS'; + $result['browser_language'] = trim($comment[3]); + $result['browser_version'] = $result['others']['detail'][1][2]; + if (!empty($result['others']['detail'][2])) { + $result['firmware'] = $result['others']['detail'][2][2]; + } + if (!empty($result['others']['detail'][3])) { + $result['browser_name'] = $result['others']['detail'][3][1]; + $result['browser_build'] = $result['others']['detail'][3][2]; + } + } + } + + // Safari + if (isset($result['others'])) { + if ($result['others']['detail'][0][1] == 'AppleWebKit') { + $result['browser_engine'] = 'AppleWebKit'; + if ($result['others']['detail'][1][1] == 'Version') { + $result['browser_version'] = $result['others']['detail'][1][2]; + } else { + $result['browser_version'] = $result['others']['detail'][count($result['others']['detail']) - 1][2]; + } + if (isset($comment[3])) { + $result['browser_language'] = trim($comment[3]); + } + + $last = $result['others']['detail'][count($result['others']['detail']) - 1][1]; + + if (empty($result['others']['detail'][2][1]) || $result['others']['detail'][2][1] == 'Safari') { + $result['browser_name'] = ($result['others']['detail'][1][1] && $result['others']['detail'][1][1] != 'Version' ? $result['others']['detail'][1][1] : 'Safari'); + $result['browser_version'] = ($result['others']['detail'][1][2] ? $result['others']['detail'][1][2] : $result['others']['detail'][0][2]); + } else { + $result['browser_name'] = $result['others']['detail'][2][1]; + $result['browser_version'] = $result['others']['detail'][2][2]; + + // mobile version + if ($result['browser_name'] == 'Mobile') { + $result['browser_name'] = 'Safari ' . $result['browser_name']; + if ($result['others']['detail'][1][1] == 'Version') { + $result['browser_version'] = $result['others']['detail'][1][2]; + } + } + } + + // For Safari < 2.2, AppleWebKit version gives the Safari version + if (strpos($result['browser_version'], '.') > 2 || (int) $result['browser_version'] > 20) { + $temp = explode('.', $result['browser_version']); + $build = (int) $temp[0]; + $awkVersion = array( + 48 => '0.8', + 73 => '0.9', + 85 => '1.0', + 103 => '1.1', + 124 => '1.2', + 300 => '1.3', + 400 => '2.0', + ); + foreach ($awkVersion as $k => $v) { + if ($build >= $k) { + $result['browser_version'] = $v; + } + } + } + } + + // Gecko (Firefox or compatible) + if ($result['others']['detail'][0][1] == 'Gecko') { + $searchRV = true; + if (!empty($result['others']['detail'][1][1]) && !empty($result['others']['detail'][count($result['others']['detail']) - 1][2]) || strpos(strtolower($result['others']['full']), 'opera') !== false) { + $searchRV = false; + $result['browser_engine'] = $result['others']['detail'][0][1]; + + // the name of the application is at the end indepenently + // of quantity of information in $result['others']['detail'] + $last = count($result['others']['detail']) - 1; + + // exception : if the version of the last information is + // empty we take the previous one + if (empty($result['others']['detail'][$last][2])) { + $last --; + } + + // exception : if the last one is 'Red Hat' or 'Debian' => + // use rv: to find browser_version */ + if (in_array($result['others']['detail'][$last][1], array( + 'Debian', + 'Hat', + ))) { + $searchRV = true; + } + $result['browser_name'] = $result['others']['detail'][$last][1]; + $result['browser_version'] = $result['others']['detail'][$last][2]; + if (isset($comment[4])) { + $result['browser_build'] = trim($comment[4]); + } + $result['browser_language'] = trim($comment[3]); + + // Netscape + if ($result['browser_name'] == 'Navigator' || $result['browser_name'] == 'Netscape6') { + $result['browser_name'] = 'Netscape'; + } + } + if ($searchRV) { + // Mozilla alone : the version is identified by rv: + $result['browser_name'] = 'Mozilla'; + if (isset($result['comment']['detail'])) { + foreach ($result['comment']['detail'] as $rv) { + if (strpos($rv, 'rv:') !== false) { + $result['browser_version'] = trim(str_replace('rv:', '', $rv)); + } + } + } + } + } + + // Netscape + if ($result['others']['detail'][0][1] == 'Netscape') { + $result['browser_name'] = 'Netscape'; + $result['browser_version'] = $result['others']['detail'][0][2]; + } + + // Opera + // Opera: engine Presto + if ($result['others']['detail'][0][1] == 'Presto') { + $result['browser_engine'] = 'Presto'; + if (!empty($result['others']['detail'][1][2])) { + $result['browser_version'] = $result['others']['detail'][1][2]; + } + } + + // UA ends with 'Opera X.XX' + if ($result['others']['detail'][0][1] == 'Opera') { + $result['browser_name'] = $result['others']['detail'][0][1]; + $result['browser_version'] = $result['others']['detail'][1][1]; + } + + // Opera Mini + if (isset($result["browser_token"])) { + if (strpos($result["browser_token"], 'Opera Mini') !== false) { + $result['browser_name'] = 'Opera Mini'; + } + } + + // Symbian + if ($result['others']['detail'][0][1] == 'SymbianOS') { + $result['device_os_token'] = 'SymbianOS'; + } + } + + // UA ends with 'Opera X.XX' + if (isset($result['browser_name']) && isset($result['browser_engine'])) { + if ($result['browser_name'] == 'Opera' && $result['browser_engine'] == 'Gecko' && empty($result['browser_version'])) { + $result['browser_version'] = $result['others']['detail'][count($result['others']['detail']) - 1][1]; + } + } + + // cleanup + if (isset($result['browser_version']) && isset($result['browser_build'])) { + if ($result['browser_version'] == $result['browser_build']) { + unset($result['browser_build']); + } + } + + // compatibility + $compatibility['AppleWebKit'] = 'Safari'; + $compatibility['Gecko'] = 'Firefox'; + $compatibility['MSIE'] = 'Internet Explorer'; + $compatibility['Presto'] = 'Opera'; + if (!empty($result['browser_engine'])) { + if (isset($compatibility[$result['browser_engine']])) { + $result['browser_compatibility'] = $compatibility[$result['browser_engine']]; + } + } + + ksort($result); + return $result; + } + + /** + * Loads the Features Adapter if it's defined in the $config array + * Otherwise, nothing is done + * + * @param string $browserType Browser type + * @return array + */ + protected function _loadFeaturesAdapter() + { + $config = $this->_config; + $browserType = $this->getType(); + if (!isset($config[$browserType]) || !isset($config[$browserType]['features'])) { + return array(); + } + $config = $config[$browserType]['features']; + + if (empty($config['classname'])) { + // require_once 'Zend/Http/UserAgent/Exception.php'; + throw new Zend_Http_UserAgent_Exception('The ' . $this->getType() . ' features adapter must have a "classname" config parameter defined'); + } + + $className = $config['classname']; + if (!class_exists($className)) { + if (isset($config['path'])) { + $path = $config['path']; + } else { + // require_once 'Zend/Http/UserAgent/Exception.php'; + throw new Zend_Http_UserAgent_Exception('The ' . $this->getType() . ' features adapter must have a "path" config parameter defined'); + } + + if (false === include_once ($path)) { + // require_once 'Zend/Http/UserAgent/Exception.php'; + throw new Zend_Http_UserAgent_Exception('The ' . $this->getType() . ' features adapter path that does not exist'); + } + } + + return call_user_func(array($className, 'getFromRequest'), $this->_server, $this->_config); + } + + /** + * Retrieve image format support + * + * @return array + */ + public function getImageFormatSupport() + { + return $this->_images; + } + + /** + * Get maximum image height supported by this device + * + * @return int + */ + public function getMaxImageHeight() + { + return null; + } + + /** + * Get maximum image width supported by this device + * + * @return int + */ + public function getMaxImageWidth() + { + return null; + } + + /** + * Get physical screen height of this device + * + * @return int + */ + public function getPhysicalScreenHeight() + { + return null; + } + + /** + * Get physical screen width of this device + * + * @return int + */ + public function getPhysicalScreenWidth() + { + return null; + } + + /** + * Get preferred markup type + * + * @return string + */ + public function getPreferredMarkup() + { + return 'xhtml'; + } + + /** + * Get supported X/HTML version + * + * @return int + */ + public function getXhtmlSupportLevel() + { + return 4; + } + + /** + * Does the device support Flash? + * + * @return bool + */ + public function hasFlashSupport() + { + return true; + } + + /** + * Does the device support PDF? + * + * @return bool + */ + public function hasPdfSupport() + { + return true; + } + + /** + * Does the device have a phone number associated with it? + * + * @return bool + */ + public function hasPhoneNumber() + { + return false; + } + + /** + * Does the device support HTTPS? + * + * @return bool + */ + public function httpsSupport() + { + return true; + } + + /** + * Get the browser type + * + * @return string + */ + public function getBrowser() + { + return $this->_browser; + } + + /** + * Get the browser version + * + * @return string + */ + public function getBrowserVersion() + { + return $this->_browserVersion; + } + + /** + * Get the user agent string + * + * @return string + */ + public function getUserAgent() + { + return $this->_userAgent; + } + + /** + * @return the $_images + */ + public function getImages() + { + return $this->_images; + } + + /** + * @param string $browser + */ + public function setBrowser($browser) + { + $this->_browser = $browser; + } + + /** + * @param string $browserVersion + */ + public function setBrowserVersion($browserVersion) + { + $this->_browserVersion = $browserVersion; + } + + /** + * @param string $userAgent + */ + public function setUserAgent($userAgent) + { + $this->_userAgent = $userAgent; + return $this; + } + + /** + * @param array $_images + */ + public function setImages($_images) + { + $this->_images = $_images; + } + + /** + * Match a user agent string against a list of signatures + * + * @param string $userAgent + * @param array $signatures + * @return bool + */ + protected static function _matchAgentAgainstSignatures($userAgent, $signatures) + { + $userAgent = strtolower($userAgent); + foreach ($signatures as $signature) { + if (!empty($signature)) { + if (strpos($userAgent, $signature) !== false) { + // Browser signature was found in user agent string + return true; + } + } + } + return false; + } +} diff --git a/libs/Zend/Http/UserAgent/Bot.php b/libs/Zend/Http/UserAgent/Bot.php new file mode 100644 index 0000000000..c35cefd0d5 --- /dev/null +++ b/libs/Zend/Http/UserAgent/Bot.php @@ -0,0 +1,129 @@ +<?php +/** + * Zend Framework + * + * LICENSE + * + * This source file is subject to the new BSD license that is bundled + * with this package in the file LICENSE.txt. + * It is also available through the world-wide-web at this URL: + * http://framework.zend.com/license/new-bsd + * If you did not receive a copy of the license and are unable to + * obtain it through the world-wide-web, please send an email + * to license@zend.com so we can send you a copy immediately. + * + * @category Zend + * @package Zend_Http + * @subpackage UserAgent + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ +// require_once 'Zend/Http/UserAgent/AbstractDevice.php'; + +/** + * Bot browser type matcher + * + * @category Zend + * @package Zend_Http + * @subpackage UserAgent + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +class Zend_Http_UserAgent_Bot extends Zend_Http_UserAgent_AbstractDevice +{ + + /** + * User Agent Signatures + * + * @var array + */ + protected static $_uaSignatures = array( + // The most common ones. + 'googlebot', + 'msnbot', + 'slurp', + 'yahoo', + + // The rest, alphabetically. + 'alexa', + 'appie', + 'archiver', + 'ask jeeves', + 'baiduspider', + 'bot', + 'crawl', + 'crawler', + 'curl', + 'eventbox', + 'facebookexternal', + 'fast', + 'feedfetcher-google', + 'firefly', + 'froogle', + 'gigabot', + 'girafabot', + 'google', + 'htdig', + 'infoseek', + 'inktomi', + 'java', + 'larbin', + 'looksmart', + 'mechanize', + 'mediapartners-google', + 'monitor', + 'nambu', + 'nationaldirectory', + 'novarra', + 'pear', + 'perl', + 'python', + 'rabaz', + 'radian', + 'rankivabot', + 'scooter', + 'sogou web spider', + 'spade', + 'sphere', + 'spider', + 'technoratisnoop', + 'tecnoseek', + 'teoma', + 'toolbar', + 'transcoder', + 'twitt', + 'url_spider_sql', + 'webalta crawler', + 'webbug', + 'webfindbot', + 'wordpress', + 'www.galaxy.com', + 'yahoo! searchmonkey', + 'yahoo! slurp', + 'yandex', + 'zyborg', + ); + + /** + * Comparison of the UserAgent chain and browser signatures + * + * @param string $userAgent User Agent chain + * @param array $server $_SERVER like param + * @return bool + */ + public static function match($userAgent, $server) + { + return self::_matchAgentAgainstSignatures($userAgent, self::$_uaSignatures); + } + + /** + * Gives the current browser type + * + * @return string + */ + public function getType() + { + return 'bot'; + } +} diff --git a/libs/Zend/Http/UserAgent/Checker.php b/libs/Zend/Http/UserAgent/Checker.php new file mode 100644 index 0000000000..aa4946bb4a --- /dev/null +++ b/libs/Zend/Http/UserAgent/Checker.php @@ -0,0 +1,76 @@ +<?php +/** + * Zend Framework + * + * LICENSE + * + * This source file is subject to the new BSD license that is bundled + * with this package in the file LICENSE.txt. + * It is also available through the world-wide-web at this URL: + * http://framework.zend.com/license/new-bsd + * If you did not receive a copy of the license and are unable to + * obtain it through the world-wide-web, please send an email + * to license@zend.com so we can send you a copy immediately. + * + * @category Zend + * @package Zend_Http + * @subpackage UserAgent + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ +// require_once 'Zend/Http/UserAgent/Desktop.php'; + +/** + * Checker browser type matcher + * + * @category Zend + * @package Zend_Http + * @subpackage UserAgent + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +class Zend_Http_UserAgent_Checker extends Zend_Http_UserAgent_Desktop +{ + + /** + * User Agent Signatures + * + * @var array + */ + protected static $_uaSignatures = array( + 'abilogic', + 'checklink', + 'checker', + 'linksmanager', + 'mojoo', + 'notifixious', + 'ploetz', + 'zeller', + 'sitebar', + 'xenu', + 'sleuth', + ); + + /** + * Comparison of the UserAgent chain and User Agent signatures + * + * @param string $userAgent User Agent chain + * @param array $server $_SERVER like param + * @return bool + */ + public static function match($userAgent, $server) + { + return self::_matchAgentAgainstSignatures($userAgent, self::$_uaSignatures); + } + + /** + * Gives the current browser type + * + * @return string + */ + public function getType() + { + return 'bot'; + } +} diff --git a/libs/Zend/Http/UserAgent/Console.php b/libs/Zend/Http/UserAgent/Console.php new file mode 100644 index 0000000000..b7f554b5a2 --- /dev/null +++ b/libs/Zend/Http/UserAgent/Console.php @@ -0,0 +1,67 @@ +<?php +/** + * Zend Framework + * + * LICENSE + * + * This source file is subject to the new BSD license that is bundled + * with this package in the file LICENSE.txt. + * It is also available through the world-wide-web at this URL: + * http://framework.zend.com/license/new-bsd + * If you did not receive a copy of the license and are unable to + * obtain it through the world-wide-web, please send an email + * to license@zend.com so we can send you a copy immediately. + * + * @category Zend + * @package Zend_Http + * @subpackage UserAgent + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +// require_once 'Zend/Http/UserAgent/Desktop.php'; + +/** + * Console browser type matcher + * + * @category Zend + * @package Zend_Http + * @subpackage UserAgent + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ +class Zend_Http_UserAgent_Console extends Zend_Http_UserAgent_Desktop +{ + /** + * User Agent Signatures + * + * @var array + */ + protected static $_uaSignatures = array( + 'playstation', + 'wii', + 'libnup', + ); + + /** + * Comparison of the UserAgent chain and User Agent signatures + * + * @param string $userAgent User Agent chain + * @param array $server $_SERVER like param + * @return bool + */ + public static function match($userAgent, $server) + { + return self::_matchAgentAgainstSignatures($userAgent, self::$_uaSignatures); + } + + /** + * Gives the current browser type + * + * @return string + */ + public function getType() + { + return 'console'; + } +} diff --git a/libs/Zend/Http/UserAgent/Desktop.php b/libs/Zend/Http/UserAgent/Desktop.php new file mode 100644 index 0000000000..422b1bc786 --- /dev/null +++ b/libs/Zend/Http/UserAgent/Desktop.php @@ -0,0 +1,56 @@ +<?php +/** + * Zend Framework + * + * LICENSE + * + * This source file is subject to the new BSD license that is bundled + * with this package in the file LICENSE.txt. + * It is also available through the world-wide-web at this URL: + * http://framework.zend.com/license/new-bsd + * If you did not receive a copy of the license and are unable to + * obtain it through the world-wide-web, please send an email + * to license@zend.com so we can send you a copy immediately. + * + * @category Zend + * @package Zend_Http + * @subpackage UserAgent + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +// require_once 'Zend/Http/UserAgent/AbstractDevice.php'; + +/** + * Desktop browser type matcher + * + * @category Zend + * @package Zend_Browser + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ +class Zend_Http_UserAgent_Desktop extends Zend_Http_UserAgent_AbstractDevice +{ + + /** + * Used by default : must be always true + * + * @param string $userAgent User Agent chain + * @param array $server $_SERVER like param + * @return bool + */ + public static function match($userAgent, $server) + { + return true; + } + + /** + * Gives the current browser type + * + * @return string + */ + public function getType() + { + return 'desktop'; + } +} diff --git a/libs/Zend/Http/UserAgent/Device.php b/libs/Zend/Http/UserAgent/Device.php new file mode 100644 index 0000000000..68bcd1e81a --- /dev/null +++ b/libs/Zend/Http/UserAgent/Device.php @@ -0,0 +1,200 @@ +<?php +/** + * Zend Framework + * + * LICENSE + * + * This source file is subject to the new BSD license that is bundled + * with this package in the file LICENSE.txt. + * It is also available through the world-wide-web at this URL: + * http://framework.zend.com/license/new-bsd + * If you did not receive a copy of the license and are unable to + * obtain it through the world-wide-web, please send an email + * to license@zend.com so we can send you a copy immediately. + * + * @category Zend + * @package Zend_Http + * @subpackage UserAgent + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +/** + * Interface defining a browser device type. + * + * @category Zend + * @package Zend_Http + * @subpackage UserAgent + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ +interface Zend_Http_UserAgent_Device extends Serializable +{ + /** + * Constructor + * + * Allows injecting user agent, server array, and/or config array. If an + * array is provided for the first argument, the assumption should be that + * the device object is being seeded with cached values from serialization. + * + * @param null|string|array $userAgent + * @param array $server + * @param array $config + * @return void + */ + public function __construct($userAgent = null, array $server = array(), array $config = array()); + + /** + * Attempt to match the user agent + * + * Return either an array of browser signature strings, or a boolean. + * + * @param string $userAgent + * @param array $server + * @return bool|array + */ + public static function match($userAgent, $server); + + /** + * Get all browser/device features + * + * @return array + */ + public function getAllFeatures(); + + /** + * Get all of the browser/device's features' groups + * + * @return void + */ + public function getAllGroups(); + + /** + * Whether or not the device has a given feature + * + * @param string $feature + * @return bool + */ + public function hasFeature($feature); + + /** + * Get the value of a specific device feature + * + * @param string $feature + * @return mixed + */ + public function getFeature($feature); + + /** + * Get the browser type + * + * @return string + */ + public function getBrowser(); + + /** + * Retrurn the browser version + * + * @return string + */ + public function getBrowserVersion(); + + /** + * Get an array of features associated with a group + * + * @param string $group + * @return array + */ + public function getGroup($group); + + /** + * Retrieve image format support + * + * @return array + */ + public function getImageFormatSupport(); + + /** + * Get image types + * + * @return array + */ + public function getImages(); + + /** + * Get the maximum image height supported by this device + * + * @return int + */ + public function getMaxImageHeight(); + + /** + * Get the maximum image width supported by this device + * + * @return int + */ + public function getMaxImageWidth(); + + /** + * Get the physical screen height of this device + * + * @return int + */ + public function getPhysicalScreenHeight(); + + /** + * Get the physical screen width of this device + * + * @return int + */ + public function getPhysicalScreenWidth(); + + /** + * Get the preferred markup type + * + * @return string + */ + public function getPreferredMarkup(); + + /** + * Get the user agent string + * + * @return string + */ + public function getUserAgent(); + + /** + * Get supported X/HTML version + * + * @return int + */ + public function getXhtmlSupportLevel(); + + /** + * Does the device support Flash? + * + * @return bool + */ + public function hasFlashSupport(); + + /** + * Does the device support PDF? + * + * @return bool + */ + public function hasPdfSupport(); + + /** + * Does the device have a phone number associated with it? + * + * @return bool + */ + public function hasPhoneNumber(); + + /** + * Does the device support HTTPS? + * + * @return bool + */ + public function httpsSupport(); +} diff --git a/libs/Zend/Http/UserAgent/Email.php b/libs/Zend/Http/UserAgent/Email.php new file mode 100644 index 0000000000..28ba15955a --- /dev/null +++ b/libs/Zend/Http/UserAgent/Email.php @@ -0,0 +1,65 @@ +<?php +/** + * Zend Framework + * + * LICENSE + * + * This source file is subject to the new BSD license that is bundled + * with this package in the file LICENSE.txt. + * It is also available through the world-wide-web at this URL: + * http://framework.zend.com/license/new-bsd + * If you did not receive a copy of the license and are unable to + * obtain it through the world-wide-web, please send an email + * to license@zend.com so we can send you a copy immediately. + * + * @category Zend + * @package Zend_Http + * @subpackage UserAgent + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +// require_once 'Zend/Http/UserAgent/Desktop.php'; + +/** + * Email browser type matcher + * + * @category Zend + * @package Zend_Http + * @subpackage UserAgent + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ +class Zend_Http_UserAgent_Email extends Zend_Http_UserAgent_Desktop +{ + /** + * User Agent Signatures + * + * @var array + */ + protected static $_uaSignatures = array( + 'thunderbird', + ); + + /** + * Comparison of the UserAgent chain and User Agent signatures + * + * @param string $userAgent User Agent chain + * @param array $server $_SERVER like param + * @return bool + */ + public static function match($userAgent, $server) + { + return self::_matchAgentAgainstSignatures($userAgent, self::$_uaSignatures); + } + + /** + * Gives the current browser type + * + * @return string + */ + public function getType() + { + return 'email'; + } +} diff --git a/libs/Zend/Http/UserAgent/Exception.php b/libs/Zend/Http/UserAgent/Exception.php new file mode 100644 index 0000000000..7e6b303d76 --- /dev/null +++ b/libs/Zend/Http/UserAgent/Exception.php @@ -0,0 +1,36 @@ +<?php +/** + * Zend Framework + * + * LICENSE + * + * This source file is subject to the new BSD license that is bundled + * with this package in the file LICENSE.txt. + * It is also available through the world-wide-web at this URL: + * http://framework.zend.com/license/new-bsd + * If you did not receive a copy of the license and are unable to + * obtain it through the world-wide-web, please send an email + * to license@zend.com so we can send you a copy immediately. + * + * @category Zend + * @package Zend_Http + * @subpackage UserAgent + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +/** + * Zend_Exception + */ +// require_once 'Zend/Exception.php'; + +/** + * @category Zend + * @package Zend_Http + * @subpackage UserAgent + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ +class Zend_Http_UserAgent_Exception extends Zend_Exception +{ +} diff --git a/libs/Zend/Http/UserAgent/Features/Adapter.php b/libs/Zend/Http/UserAgent/Features/Adapter.php new file mode 100644 index 0000000000..ad9b935d95 --- /dev/null +++ b/libs/Zend/Http/UserAgent/Features/Adapter.php @@ -0,0 +1,39 @@ +<?php +/** + * Zend Framework + * + * LICENSE + * + * This source file is subject to the new BSD license that is bundled + * with this package in the file LICENSE.txt. + * It is also available through the world-wide-web at this URL: + * http://framework.zend.com/license/new-bsd + * If you did not receive a copy of the license and are unable to + * obtain it through the world-wide-web, please send an email + * to license@zend.com so we can send you a copy immediately. + * + * @category Zend + * @package Zend_Http + * @subpackage UserAgent + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +/** + * The interface required by all Zend_Browser_Features Adapter classes to implement. + * + * @category Zend + * @package Zend_Http + * @subpackage UserAgent + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ +interface Zend_Http_UserAgent_Features_Adapter +{ + /** + * Retrieve the browser's features from a given request object ($_SERVER) + * + * @return array + */ + public static function getFromRequest($request, array $config); +} diff --git a/libs/Zend/Http/UserAgent/Features/Adapter/DeviceAtlas.php b/libs/Zend/Http/UserAgent/Features/Adapter/DeviceAtlas.php new file mode 100644 index 0000000000..1e2897e147 --- /dev/null +++ b/libs/Zend/Http/UserAgent/Features/Adapter/DeviceAtlas.php @@ -0,0 +1,78 @@ +<?php +/** + * Zend Framework + * + * LICENSE + * + * This source file is subject to the new BSD license that is bundled + * with this package in the file LICENSE.txt. + * It is also available through the world-wide-web at this URL: + * http://framework.zend.com/license/new-bsd + * If you did not receive a copy of the license and are unable to + * obtain it through the world-wide-web, please send an email + * to license@zend.com so we can send you a copy immediately. + * + * @category Zend + * @package Zend_Http + * @subpackage UserAgent + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +/** + * Zend_Http_UserAgent_Features_Adapter_Interface + */ +// require_once 'Zend/Http/UserAgent/Features/Adapter.php'; + +/** + * Features adapter build with the Tera Wurfl Api + * See installation instruction here : http://deviceatlas.com/licences + * Download : http://deviceatlas.com/getAPI/php + * + * @package Zend_Http + * @subpackage UserAgent + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ +class Zend_Http_UserAgent_Features_Adapter_DeviceAtlas implements Zend_Http_UserAgent_Features_Adapter +{ + /** + * Get features from request + * + * @param array $request $_SERVER variable + * @return array + */ + public static function getFromRequest($request, array $config) + { + if (!class_exists('Mobi_Mtld_DA_Api')) { + if (!isset($config['deviceatlas'])) { + // require_once 'Zend/Http/UserAgent/Features/Exception.php'; + throw new Zend_Http_UserAgent_Features_Exception('"DeviceAtlas" configuration is not defined'); + } + } + + $config = $config['deviceatlas']; + + if (!class_exists('Mobi_Mtld_DA_Api')) { + if (empty($config['deviceatlas_lib_dir'])) { + // require_once 'Zend/Http/UserAgent/Features/Exception.php'; + throw new Zend_Http_UserAgent_Features_Exception('The "deviceatlas_lib_dir" parameter is not defined'); + } + + // Include the Device Atlas file from the specified lib_dir + // require_once ($config['deviceatlas_lib_dir'] . '/Mobi/Mtld/DA/Api.php'); + } + + if (empty($config['deviceatlas_data'])) { + // require_once 'Zend/Http/UserAgent/Features/Exception.php'; + throw new Zend_Http_UserAgent_Features_Exception('The "deviceatlas_data" parameter is not defined'); + } + + //load the device data-tree : e.g. 'json/DeviceAtlas.json + $tree = Mobi_Mtld_DA_Api::getTreeFromFile($config['deviceatlas_data']); + + $properties = Mobi_Mtld_DA_Api::getProperties($tree, $request['http_user_agent']); + + return $properties; + } +} diff --git a/libs/Zend/Http/UserAgent/Features/Adapter/TeraWurfl.php b/libs/Zend/Http/UserAgent/Features/Adapter/TeraWurfl.php new file mode 100644 index 0000000000..760112193c --- /dev/null +++ b/libs/Zend/Http/UserAgent/Features/Adapter/TeraWurfl.php @@ -0,0 +1,102 @@ +<?php +/** + * Zend Framework + * + * LICENSE + * + * This source file is subject to the new BSD license that is bundled + * with this package in the file LICENSE.txt. + * It is also available through the world-wide-web at this URL: + * http://framework.zend.com/license/new-bsd + * If you did not receive a copy of the license and are unable to + * obtain it through the world-wide-web, please send an email + * to license@zend.com so we can send you a copy immediately. + * + * @category Zend + * @package Zend_Http + * @subpackage UserAgent + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +/** + * Zend_Http_UserAgent_Features_Adapter_Interface + */ +// require_once 'Zend/Http/UserAgent/Features/Adapter.php'; + +/** + * Features adapter build with the Tera Wurfl Api + * See installation instruction here : http://www.tera-wurfl.com/wiki/index.php/Installation + * Download : http://www.tera-wurfl.com/wiki/index.php/Downloads + * + * @package Zend_Http + * @subpackage UserAgent + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ +class Zend_Http_UserAgent_Features_Adapter_TeraWurfl implements Zend_Http_UserAgent_Features_Adapter +{ + /** + * Get features from request + * + * @param array $request $_SERVER variable + * @return array + */ + public static function getFromRequest($request, array $config) + { + if (!class_exists('TeraWurfl')) { + // If TeraWurfl class not found, see if we can load it from + // configuration + // + if (!isset($config['terawurfl'])) { + // No configuration + // require_once 'Zend/Http/UserAgent/Features/Exception.php'; + throw new Zend_Http_UserAgent_Features_Exception('"TeraWurfl" configuration is not defined'); + } + + $config = $config['terawurfl']; + + if (empty($config['terawurfl_lib_dir'])) { + // No lib_dir given + // require_once 'Zend/Http/UserAgent/Features/Exception.php'; + throw new Zend_Http_UserAgent_Features_Exception('The "terawurfl_lib_dir" parameter is not defined'); + } + + // Include the Tera-WURFL file + // require_once ($config['terawurfl_lib_dir'] . '/TeraWurfl.php'); + } + + + // instantiate the Tera-WURFL object + $wurflObj = new TeraWurfl(); + + // Get the capabilities of the current client. + $matched = $wurflObj->getDeviceCapabilitiesFromRequest(array_change_key_case($request, CASE_UPPER)); + + return self::getAllCapabilities($wurflObj); + } + + /*** + * Builds an array with all capabilities + * + * @param TeraWurfl $wurflObj TeraWurfl object + */ + public static function getAllCapabilities(TeraWurfl $wurflObj) + { + + foreach ($wurflObj->capabilities as $group) { + if (!is_array($group)) { + continue; + } + while (list ($key, $value) = each($group)) { + if (is_bool($value)) { + // to have the same type than the official WURFL API + $features[$key] = ($value ? 'true' : 'false'); + } else { + $features[$key] = $value; + } + } + } + return $features; + } +} diff --git a/libs/Zend/Http/UserAgent/Features/Adapter/WurflApi.php b/libs/Zend/Http/UserAgent/Features/Adapter/WurflApi.php new file mode 100644 index 0000000000..12d130dcae --- /dev/null +++ b/libs/Zend/Http/UserAgent/Features/Adapter/WurflApi.php @@ -0,0 +1,103 @@ +<?php +/** + * Zend Framework + * + * LICENSE + * + * This source file is subject to the new BSD license that is bundled + * with this package in the file LICENSE.txt. + * It is also available through the world-wide-web at this URL: + * http://framework.zend.com/license/new-bsd + * If you did not receive a copy of the license and are unable to + * obtain it through the world-wide-web, please send an email + * to license@zend.com so we can send you a copy immediately. + * + * @category Zend + * @package Zend_Http + * @subpackage UserAgent + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +/** + * Zend_Http_UserAgent_Features_Adapter_Interface + */ +// require_once 'Zend/Http/UserAgent/Features/Adapter.php'; + +/** + * Features adapter build with the official WURFL PHP API + * See installation instruction here : http://wurfl.sourceforge.net/nphp/ + * Download : http://sourceforge.net/projects/wurfl/files/WURFL PHP/1.1/wurfl-php-1.1.tar.gz/download + * + * @package Zend_Http + * @subpackage UserAgent + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ +class Zend_Http_UserAgent_Features_Adapter_WurflApi + implements Zend_Http_UserAgent_Features_Adapter +{ + const DEFAULT_API_VERSION = '1.1'; + + /** + * Get features from request + * + * @param array $request $_SERVER variable + * @return array + */ + public static function getFromRequest($request, array $config) + { + if (!isset($config['wurflapi'])) { + // require_once 'Zend/Http/UserAgent/Features/Exception.php'; + throw new Zend_Http_UserAgent_Features_Exception('"wurflapi" configuration is not defined'); + } + + $config = $config['wurflapi']; + + if (empty($config['wurfl_lib_dir'])) { + // require_once 'Zend/Http/UserAgent/Features/Exception.php'; + throw new Zend_Http_UserAgent_Features_Exception('The "wurfl_lib_dir" parameter is not defined'); + } + if (empty($config['wurfl_config_file']) && empty($config['wurfl_config_array'])) { + // require_once 'Zend/Http/UserAgent/Features/Exception.php'; + throw new Zend_Http_UserAgent_Features_Exception('The "wurfl_config_file" parameter is not defined'); + } + + if (empty($config['wurfl_api_version'])) { + $config['wurfl_api_version'] = self::DEFAULT_API_VERSION; + } + + switch ($config['wurfl_api_version']) { + case '1.0': + // Zend_Http_UserAgent::$config['wurfl_config_file'] must be an XML file + // require_once ($config['wurfl_lib_dir'] . 'WURFLManagerProvider.php'); + $wurflManager = WURFL_WURFLManagerProvider::getWURFLManager(Zend_Http_UserAgent::$config['wurfl_config_file']); + break; + case '1.1': + // require_once ($config['wurfl_lib_dir'] . 'Application.php'); + if (!empty($config['wurfl_config_file'])) { + $wurflConfig = WURFL_Configuration_ConfigFactory::create($config['wurfl_config_file']); + } elseif (!empty($config['wurfl_config_array'])) { + $c = $config['wurfl_config_array']; + $wurflConfig = new WURFL_Configuration_InMemoryConfig(); + $wurflConfig->wurflFile($c['wurfl']['main-file']) + ->wurflPatch($c['wurfl']['patches']) + ->persistence($c['persistence']['provider'], $c['persistence']['dir']); + } + + $wurflManagerFactory = new WURFL_WURFLManagerFactory($wurflConfig); + $wurflManager = $wurflManagerFactory->create(); + break; + default: + // require_once 'Zend/Http/UserAgent/Features/Exception.php'; + throw new Zend_Http_UserAgent_Features_Exception(sprintf( + 'Unknown API version "%s"', + $config['wurfl_api_version'] + )); + } + + $device = $wurflManager->getDeviceForHttpRequest(array_change_key_case($request, CASE_UPPER)); + $features = $device->getAllCapabilities(); + return $features; + } +} diff --git a/libs/Zend/Http/UserAgent/Features/Exception.php b/libs/Zend/Http/UserAgent/Features/Exception.php new file mode 100644 index 0000000000..8462eeb186 --- /dev/null +++ b/libs/Zend/Http/UserAgent/Features/Exception.php @@ -0,0 +1,36 @@ +<?php +/** + * Zend Framework + * + * LICENSE + * + * This source file is subject to the new BSD license that is bundled + * with this package in the file LICENSE.txt. + * It is also available through the world-wide-web at this URL: + * http://framework.zend.com/license/new-bsd + * If you did not receive a copy of the license and are unable to + * obtain it through the world-wide-web, please send an email + * to license@zend.com so we can send you a copy immediately. + * + * @category Zend + * @package Zend_Http + * @subpackage UserAgent + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +/** + * @see Zend_Browser_Exception + */ +// require_once 'Zend/Http/UserAgent/Exception.php'; + +/** + * @category Zend + * @package Zend_Http + * @subpackage UserAgent + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ +class Zend_Http_UserAgent_Features_Exception extends Zend_Http_UserAgent_Exception +{ +} diff --git a/libs/Zend/Http/UserAgent/Feed.php b/libs/Zend/Http/UserAgent/Feed.php new file mode 100644 index 0000000000..e249b9f26c --- /dev/null +++ b/libs/Zend/Http/UserAgent/Feed.php @@ -0,0 +1,81 @@ +<?php +/** + * Zend Framework + * + * LICENSE + * + * This source file is subject to the new BSD license that is bundled + * with this package in the file LICENSE.txt. + * It is also available through the world-wide-web at this URL: + * http://framework.zend.com/license/new-bsd + * If you did not receive a copy of the license and are unable to + * obtain it through the world-wide-web, please send an email + * to license@zend.com so we can send you a copy immediately. + * + * @category Zend + * @package Zend_Http + * @subpackage UserAgent + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +// require_once 'Zend/Http/UserAgent/AbstractDevice.php'; + +/** + * Feed browser type matcher + * + * @category Zend + * @package Zend_Http + * @subpackage UserAgent + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ +class Zend_Http_UserAgent_Feed extends Zend_Http_UserAgent_AbstractDevice +{ + /** + * User Agent Signatures + * + * @var array + */ + protected static $_uaSignatures = array( + 'bloglines', + 'everyfeed', + 'feedfetcher', + 'gregarius', + ); + + /** + * Comparison of the UserAgent chain and User Agent signatures + * + * @param string $userAgent User Agent chain + * @param array $server $_SERVER like param + * @return bool + */ + public static function match($userAgent, $server) + { + return self::_matchAgentAgainstSignatures($userAgent, self::$_uaSignatures); + } + + /** + * Gives the current browser type + * + * @return string + */ + public function getType() + { + return 'feed'; + } + + /** + * Look for features + * + * @return string + */ + protected function _defineFeatures() + { + $this->setFeature('iframes', false, 'product_capability'); + $this->setFeature('frames', false, 'product_capability'); + $this->setFeature('javascript', false, 'product_capability'); + return parent::_defineFeatures(); + } +} diff --git a/libs/Zend/Http/UserAgent/Mobile.php b/libs/Zend/Http/UserAgent/Mobile.php new file mode 100644 index 0000000000..22416ecc0c --- /dev/null +++ b/libs/Zend/Http/UserAgent/Mobile.php @@ -0,0 +1,538 @@ +<?php +/** + * Zend Framework + * + * LICENSE + * + * This source file is subject to the new BSD license that is bundled + * with this package in the file LICENSE.txt. + * It is also available through the world-wide-web at this URL: + * http://framework.zend.com/license/new-bsd + * If you did not receive a copy of the license and are unable to + * obtain it through the world-wide-web, please send an email + * to license@zend.com so we can send you a copy immediately. + * + * @category Zend + * @package Zend_Http + * @subpackage UserAgent + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +// require_once 'Zend/Http/UserAgent/AbstractDevice.php'; + +/** + * Mobile browser type matcher + * + * @category Zend + * @package Zend_Http + * @subpackage UserAgent + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ +class Zend_Http_UserAgent_Mobile extends Zend_Http_UserAgent_AbstractDevice +{ + + const DEFAULT_FEATURES_ADAPTER_CLASSNAME = 'Zend_Http_UserAgent_Features_Adapter_WurflApi'; + + const DEFAULT_FEATURES_ADAPTER_PATH = 'Zend/Http/UserAgent/Features/Adapter/WurflApi.php'; + + /** + * User Agent Signatures + * + * @var array + */ + protected static $_uaSignatures = array( + 'iphone', + 'ipod', + 'ipad', + 'android', + 'blackberry', + 'opera mini', + 'opera mobi', + 'palm', + 'palmos', + 'elaine', + 'windows ce', + 'icab', + '_mms', + 'ahong', + 'archos', + 'armv', + 'astel', + 'avantgo', + 'benq', + 'blazer', + 'brew', + 'com2', + 'compal', + 'danger', + 'pocket', + 'docomo', + 'epoc', + 'ericsson', + 'eudoraweb', + 'hiptop', + 'htc-', + 'htc_', + 'iemobile', + 'ipad', + 'iris', + 'j-phone', + 'kddi', + 'kindle', + 'lg ', + 'lg-', + 'lg/', + 'lg;lx', + 'lge vx', + 'lge', + 'lge-', + 'lge-cx', + 'lge-lx', + 'lge-mx', + 'linux armv', + 'maemo', + 'midp', + 'mini 9.5', + 'minimo', + 'mob-x', + 'mobi', + 'mobile', + 'mobilephone', + 'mot 24', + 'mot-', + 'motorola', + 'n410', + 'netfront', + 'nintendo wii', + 'nintendo', + 'nitro', + 'nokia', + 'novarra-vision', + 'nuvifone', + 'openweb', + 'oper', + 'opwv', + 'palmsource', + 'pdxgw', + 'phone', + 'playstation', + 'polaris', + 'portalmmm', + 'qt embedded', + 'reqwirelessweb', + 'sagem', + 'sam-r', + 'samsu', + 'samsung', + 'sec-', + 'sec-sgh', + 'semc-browser', + 'series60', + 'series70', + 'series80', + 'series90', + 'sharp', + 'sie-m', + 'sie-s', + 'smartphone', + 'sony cmd', + 'sonyericsson', + 'sprint', + 'spv', + 'symbian os', + 'symbian', + 'symbianos', + 'telco', + 'teleca', + 'treo', + 'up.browser', + 'up.link', + 'vodafone', + 'vodaphone', + 'webos', + 'wml', + 'windows phone os 7', + 'wireless', + 'wm5 pie', + 'wms pie', + 'xiino', + 'wap', + 'up/', + 'psion', + 'j2me', + 'klondike', + 'kbrowser' + ); + + /** + * @var array + */ + protected static $_haTerms = array( + 'midp', + 'wml', + 'vnd.rim', + 'vnd.wap', + 'j2me', + ); + + /** + * first 4 letters of mobile User Agent chains + * + * @var array + */ + protected static $_uaBegin = array( + 'w3c ', + 'acs-', + 'alav', + 'alca', + 'amoi', + 'audi', + 'avan', + 'benq', + 'bird', + 'blac', + 'blaz', + 'brew', + 'cell', + 'cldc', + 'cmd-', + 'dang', + 'doco', + 'eric', + 'hipt', + 'inno', + 'ipaq', + 'java', + 'jigs', + 'kddi', + 'keji', + 'leno', + 'lg-c', + 'lg-d', + 'lg-g', + 'lge-', + 'maui', + 'maxo', + 'midp', + 'mits', + 'mmef', + 'mobi', + 'mot-', + 'moto', + 'mwbp', + 'nec-', + 'newt', + 'noki', + 'palm', + 'pana', + 'pant', + 'phil', + 'play', + 'port', + 'prox', + 'qwap', + 'sage', + 'sams', + 'sany', + 'sch-', + 'sec-', + 'send', + 'seri', + 'sgh-', + 'shar', + 'sie-', + 'siem', + 'smal', + 'smar', + 'sony', + 'sph-', + 'symb', + 't-mo', + 'teli', + 'tim-', + 'tosh', + 'tsm-', + 'upg1', + 'upsi', + 'vk-v', + 'voda', + 'wap-', + 'wapa', + 'wapi', + 'wapp', + 'wapr', + 'webc', + 'winw', + 'winw', + 'xda', + 'xda-', + ); + + /** + * Comparison of the UserAgent chain and User Agent signatures + * + * @param string $userAgent User Agent chain + * @param array $server $_SERVER like param + * @return bool + */ + public static function match($userAgent, $server) + { + // To have a quick identification, try light-weight tests first + if (isset($server['all_http'])) { + if (strpos(strtolower(str_replace(' ', '', $server['all_http'])), 'operam') !== false) { + // Opera Mini or Opera Mobi + return true; + } + } + + if (isset($server['http_x_wap_profile']) || isset($server['http_profile'])) { + return true; + } + + if (isset($server['http_accept'])) { + if (self::_matchAgentAgainstSignatures($server['http_accept'], self::$_haTerms)) { + return true; + } + } + + if (self::userAgentStart($userAgent)) { + return true; + } + + if (self::_matchAgentAgainstSignatures($userAgent, self::$_uaSignatures)) { + return true; + } + + return false; + } + + /** + * Retrieve beginning clause of user agent + * + * @param string $userAgent + * @return string + */ + public static function userAgentStart($userAgent) + { + + $mobile_ua = strtolower(substr($userAgent, 0, 4)); + + return (in_array($mobile_ua, self::$_uaBegin)); + } + + /** + * Constructor + * + * @return void + */ + public function __construct($userAgent = null, array $server = array(), array $config = array()) + { + // For mobile detection, an adapter must be defined + if (empty($config['mobile']['features'])) { + $config['mobile']['features']['path'] = self::DEFAULT_FEATURES_ADAPTER_PATH; + $config['mobile']['features']['classname'] = self::DEFAULT_FEATURES_ADAPTER_CLASSNAME; + } + parent::__construct($userAgent, $server, $config); + } + + /** + * Gives the current browser type + * + * @return string + */ + public function getType() + { + return 'mobile'; + } + + /** + * Look for features + * + * @return string + */ + protected function _defineFeatures() + { + $this->setFeature('is_wireless_device', false, 'product_info'); + + parent::_defineFeatures(); + + if (isset($this->_aFeatures["mobile_browser"])) { + $this->setFeature("browser_name", $this->_aFeatures["mobile_browser"]); + $this->_browser = $this->_aFeatures["mobile_browser"]; + } + if (isset($this->_aFeatures["mobile_browser_version"])) { + $this->setFeature("browser_version", $this->_aFeatures["mobile_browser_version"]); + $this->_browserVersion = $this->_aFeatures["mobile_browser_version"]; + } + + // markup + if ($this->getFeature('device_os') == 'iPhone OS' + || $this->getFeature('device_os_token') == 'iPhone OS' + ) { + $this->setFeature('markup', 'iphone'); + } else { + $this->setFeature('markup', $this->getMarkupLanguage($this->getFeature('preferred_markup'))); + } + + // image format + $this->_images = array(); + + if ($this->getFeature('png')) { + $this->_images[] = 'png'; + } + if ($this->getFeature('jpg')) { + $this->_images[] = 'jpg'; + } + if ($this->getFeature('gif')) { + $this->_images[] = 'gif'; + } + if ($this->getFeature('wbmp')) { + $this->_images[] = 'wbmp'; + } + + return $this->_aFeatures; + } + + /** + * Determine markup language expected + * + * @access public + * @return __TYPE__ + */ + public function getMarkupLanguage($preferredMarkup = null) + { + $return = ''; + switch ($preferredMarkup) { + case 'wml_1_1': + case 'wml_1_2': + case 'wml_1_3': + $return = 'wml'; //text/vnd.wap.wml encoding="ISO-8859-15" + case 'html_wi_imode_compact_generic': + case 'html_wi_imode_html_1': + case 'html_wi_imode_html_2': + case 'html_wi_imode_html_3': + case 'html_wi_imode_html_4': + case 'html_wi_imode_html_5': + $return = 'chtml'; //text/html + case 'html_wi_oma_xhtmlmp_1_0': //application/vnd.wap.xhtml+xml + case 'html_wi_w3_xhtmlbasic': //application/xhtml+xml DTD XHTML Basic 1.0 + $return = 'xhtml'; + case 'html_web_3_2': //text/html DTD Html 3.2 Final + case 'html_web_4_0': //text/html DTD Html 4.01 Transitional + $return = ''; + } + return $return; + } + + /** + * Determine image format support + * + * @return array + */ + public function getImageFormatSupport() + { + return $this->_images; + } + + /** + * Determine maximum image height supported + * + * @return int + */ + public function getMaxImageHeight() + { + return $this->getFeature('max_image_height'); + } + + /** + * Determine maximum image width supported + * + * @return int + */ + public function getMaxImageWidth() + { + return $this->getFeature('max_image_width'); + } + + /** + * Determine physical screen height + * + * @return int + */ + public function getPhysicalScreenHeight() + { + return $this->getFeature('physical_screen_height'); + } + + /** + * Determine physical screen width + * + * @return int + */ + public function getPhysicalScreenWidth() + { + return $this->getFeature('physical_screen_width'); + } + + /** + * Determine preferred markup + * + * @return string + */ + public function getPreferredMarkup() + { + return $this->getFeature("markup"); + } + + /** + * Determine X/HTML support level + * + * @return int + */ + public function getXhtmlSupportLevel() + { + return $this->getFeature('xhtml_support_level'); + } + + /** + * Does the device support Flash? + * + * @return bool + */ + public function hasFlashSupport() + { + return $this->getFeature('fl_browser'); + } + + /** + * Does the device support PDF? + * + * @return bool + */ + public function hasPdfSupport() + { + return $this->getFeature('pdf_support'); + } + + /** + * Does the device have an associated phone number? + * + * @return bool + */ + public function hasPhoneNumber() + { + return $this->getFeature('can_assign_phone_number'); + } + + /** + * Does the device support HTTPS? + * + * @return bool + */ + public function httpsSupport() + { + return ($this->getFeature('https_support') == 'supported'); + } +} diff --git a/libs/Zend/Http/UserAgent/Offline.php b/libs/Zend/Http/UserAgent/Offline.php new file mode 100644 index 0000000000..50a6046437 --- /dev/null +++ b/libs/Zend/Http/UserAgent/Offline.php @@ -0,0 +1,70 @@ +<?php +/** + * Zend Framework + * + * LICENSE + * + * This source file is subject to the new BSD license that is bundled + * with this package in the file LICENSE.txt. + * It is also available through the world-wide-web at this URL: + * http://framework.zend.com/license/new-bsd + * If you did not receive a copy of the license and are unable to + * obtain it through the world-wide-web, please send an email + * to license@zend.com so we can send you a copy immediately. + * + * @category Zend + * @package Zend_Http + * @subpackage UserAgent + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +// require_once 'Zend/Http/UserAgent/Desktop.php'; + +/** + * Offline browser type matcher + * + * @category Zend + * @package Zend_Http + * @subpackage UserAgent + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ +class Zend_Http_UserAgent_Offline extends Zend_Http_UserAgent_Desktop +{ + /** + * User Agent Signatures + * + * @var array + */ + protected static $_uaSignatures = array( + 'wget', + 'webzip', + 'webcopier', + 'downloader', + 'superbot', + 'offline', + ); + + /** + * Comparison of the UserAgent chain and User Agent signatures + * + * @param string $userAgent User Agent chain + * @param array $server $_SERVER like param + * @return bool + */ + public static function match($userAgent, $server) + { + return self::_matchAgentAgainstSignatures($userAgent, self::$_uaSignatures); + } + + /** + * Gives the current browser type + * + * @return string + */ + public function getType() + { + return 'offline'; + } +} diff --git a/libs/Zend/Http/UserAgent/Probe.php b/libs/Zend/Http/UserAgent/Probe.php new file mode 100644 index 0000000000..73656f8bbb --- /dev/null +++ b/libs/Zend/Http/UserAgent/Probe.php @@ -0,0 +1,81 @@ +<?php +/** + * Zend Framework + * + * LICENSE + * + * This source file is subject to the new BSD license that is bundled + * with this package in the file LICENSE.txt. + * It is also available through the world-wide-web at this URL: + * http://framework.zend.com/license/new-bsd + * If you did not receive a copy of the license and are unable to + * obtain it through the world-wide-web, please send an email + * to license@zend.com so we can send you a copy immediately. + * + * @category Zend + * @package Zend_Http + * @subpackage UserAgent + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +// require_once 'Zend/Http/UserAgent/AbstractDevice.php'; + +/** + * Probe browser type matcher + * + * @category Zend + * @package Zend_Http + * @subpackage UserAgent + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ +class Zend_Http_UserAgent_Probe extends Zend_Http_UserAgent_AbstractDevice +{ + /** + * User Agent Signatures + * + * @var array + */ + protected static $_uaSignatures = array( + 'witbe', + 'netvigie', + ); + + /** + * Comparison of the UserAgent chain and User Agent signatures + * + * @param string $userAgent User Agent chain + * @param array $server $_SERVER like param + * @return bool + */ + public static function match($userAgent, $server) + { + return self::_matchAgentAgainstSignatures($userAgent, self::$_uaSignatures); + } + + + /** + * Gives the current browser type + * + * @return string + */ + public function getType() + { + return 'probe'; + } + + /** + * Look for features + * + * @return string + */ + protected function _defineFeatures() + { + $this->setFeature('images', false, 'product_capability'); + $this->setFeature('iframes', false, 'product_capability'); + $this->setFeature('frames', false, 'product_capability'); + $this->setFeature('javascript', false, 'product_capability'); + return parent::_defineFeatures(); + } +} diff --git a/libs/Zend/Http/UserAgent/Spam.php b/libs/Zend/Http/UserAgent/Spam.php new file mode 100644 index 0000000000..6f9ebacffb --- /dev/null +++ b/libs/Zend/Http/UserAgent/Spam.php @@ -0,0 +1,79 @@ +<?php +/** + * Zend Framework + * + * LICENSE + * + * This source file is subject to the new BSD license that is bundled + * with this package in the file LICENSE.txt. + * It is also available through the world-wide-web at this URL: + * http://framework.zend.com/license/new-bsd + * If you did not receive a copy of the license and are unable to + * obtain it through the world-wide-web, please send an email + * to license@zend.com so we can send you a copy immediately. + * + * @category Zend + * @package Zend_Http + * @subpackage UserAgent + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +// require_once 'Zend/Http/UserAgent/AbstractDevice.php'; + +/** + * Spam browser type matcher + * + * @category Zend + * @package Zend_Http + * @subpackage UserAgent + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ +class Zend_Http_UserAgent_Spam extends Zend_Http_UserAgent_AbstractDevice +{ + /** + * @todo User Agent Signatures + * + * @var array + */ + protected static $_uaSignatures = array( + '', + ); + + /** + * Comparison of the UserAgent chain and User Agent signatures + * + * @param string $userAgent User Agent chain + * @param array $server $_SERVER like param + * @return bool + */ + public static function match($userAgent, $server) + { + return self::_matchAgentAgainstSignatures($userAgent, self::$_uaSignatures); + } + + /** + * Gives the current browser type + * + * @return string + */ + public function getType() + { + return 'spam'; + } + + /** + * Look for features + * + * @return string + */ + protected function _defineFeatures() + { + $this->setFeature('images', false, 'product_capability'); + $this->setFeature('iframes', false, 'product_capability'); + $this->setFeature('frames', false, 'product_capability'); + $this->setFeature('javascript', false, 'product_capability'); + return parent::_defineFeatures(); + } +} diff --git a/libs/Zend/Http/UserAgent/Storage.php b/libs/Zend/Http/UserAgent/Storage.php new file mode 100644 index 0000000000..59daec4407 --- /dev/null +++ b/libs/Zend/Http/UserAgent/Storage.php @@ -0,0 +1,65 @@ +<?php +/** + * Zend Framework + * + * LICENSE + * + * This source file is subject to the new BSD license that is bundled + * with this package in the file LICENSE.txt. + * It is also available through the world-wide-web at this URL: + * http://framework.zend.com/license/new-bsd + * If you did not receive a copy of the license and are unable to + * obtain it through the world-wide-web, please send an email + * to license@zend.com so we can send you a copy immediately. + * + * @category Zend + * @package Zend_Http + * @subpackage UserAgent + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +/** + * @category Zend + * @package Zend_Http + * @subpackage UserAgent + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ +interface Zend_Http_UserAgent_Storage +{ + /** + * Returns true if and only if storage is empty + * + * @throws Zend_Http_UserAgent_Storage_Exception If it is impossible to determine whether storage is empty + * @return boolean + */ + public function isEmpty(); + + /** + * Returns the contents of storage associated to the key parameter + * + * Behavior is undefined when storage is empty. + * + * @throws Zend_Http_UserAgent_Storage_Exception If reading contents from storage is impossible + * @return mixed + */ + public function read(); + + /** + * Writes $contents associated to the key parameter to storage + * + * @param mixed $contents + * @throws Zend_Http_UserAgent_Storage_Exception If writing $contents to storage is impossible + * @return void + */ + public function write($contents); + + /** + * Clears contents from storage + * + * @throws Zend_Http_UserAgent_Storage_Exception If clearing contents from storage is impossible + * @return void + */ + public function clear(); +} diff --git a/libs/Zend/Http/UserAgent/Storage/Exception.php b/libs/Zend/Http/UserAgent/Storage/Exception.php new file mode 100644 index 0000000000..86f8ac9053 --- /dev/null +++ b/libs/Zend/Http/UserAgent/Storage/Exception.php @@ -0,0 +1,37 @@ +<?php +/** + * Zend Framework + * + * LICENSE + * + * This source file is subject to the new BSD license that is bundled + * with this package in the file LICENSE.txt. + * It is also available through the world-wide-web at this URL: + * http://framework.zend.com/license/new-bsd + * If you did not receive a copy of the license and are unable to + * obtain it through the world-wide-web, please send an email + * to license@zend.com so we can send you a copy immediately. + * + * @category Zend + * @package Zend_Http + * @subpackage UserAgent + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + + +/** + * @see Zend_Http_UserAgent_Exception + */ +// require_once 'Zend/Http/UserAgent/Exception.php'; + + +/** + * @package Zend_Http + * @subpackage UserAgent + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ +class Zend_Http_UserAgent_Storage_Exception extends Zend_Http_UserAgent_Exception +{ +} diff --git a/libs/Zend/Http/UserAgent/Storage/NonPersistent.php b/libs/Zend/Http/UserAgent/Storage/NonPersistent.php new file mode 100644 index 0000000000..f48806d6d2 --- /dev/null +++ b/libs/Zend/Http/UserAgent/Storage/NonPersistent.php @@ -0,0 +1,97 @@ +<?php +/** + * Zend Framework + * + * LICENSE + * + * This source file is subject to the new BSD license that is bundled + * with this package in the file LICENSE.txt. + * It is also available through the world-wide-web at this URL: + * http://framework.zend.com/license/new-bsd + * If you did not receive a copy of the license and are unable to + * obtain it through the world-wide-web, please send an email + * to license@zend.com so we can send you a copy immediately. + * + * @category Zend + * @package Zend_Http + * @subpackage UserAgent + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + * @version $Id: NonPersistent.php 20096 2010-01-06 02:05:09Z bkarwin $ + */ + + +/** + * @see Zend_Http_UserAgent_Storage_Interface + */ +// require_once 'Zend/Http/UserAgent/Storage.php'; + + +/** + * Non-Persistent Browser Storage + * + * Since HTTP Browserentication happens again on each request, this will always be + * re-populated. So there's no need to use sessions, this simple value class + * will hold the data for rest of the current request. + * + * @package Zend_Http + * @subpackage UserAgent + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ +class Zend_Http_UserAgent_Storage_NonPersistent + implements Zend_Http_UserAgent_Storage +{ + /** + * Holds the actual Browser data + * @var mixed + */ + protected $_data; + + /** + * Returns true if and only if storage is empty + * + * @throws Zend_Http_UserAgent_Storage_Exception If it is impossible to determine whether storage is empty + * @return boolean + */ + public function isEmpty() + { + return empty($this->_data); + } + + /** + * Returns the contents of storage + * + * Behavior is undefined when storage is empty. + * + * @throws Zend_Http_UserAgent_Storage_Exception If reading contents from storage is impossible + * @return mixed + */ + public function read() + { + return $this->_data; + } + + /** + * Writes $contents to storage + * + * @param mixed $contents + * @throws Zend_Http_UserAgent_Storage_Exception If writing $contents to storage is impossible + * @return void + */ + public function write($contents) + { + $this->_data = $contents; + } + + /** + * Clears contents from storage + * + * @throws Zend_Http_UserAgent_Storage_Exception If clearing contents from storage is impossible + * @return void + */ + public function clear() + { + $this->_data = null; + } +} diff --git a/libs/Zend/Http/UserAgent/Storage/Session.php b/libs/Zend/Http/UserAgent/Storage/Session.php new file mode 100644 index 0000000000..167267c058 --- /dev/null +++ b/libs/Zend/Http/UserAgent/Storage/Session.php @@ -0,0 +1,166 @@ +<?php +/** + * Zend Framework + * + * LICENSE + * + * This source file is subject to the new BSD license that is bundled + * with this package in the file LICENSE.txt. + * It is also available through the world-wide-web at this URL: + * http://framework.zend.com/license/new-bsd + * If you did not receive a copy of the license and are unable to + * obtain it through the world-wide-web, please send an email + * to license@zend.com so we can send you a copy immediately. + * + * @category Zend + * @package Zend_Http + * @subpackage UserAgent + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +/** + * @see Zend_Http_UserAgent_Storage + */ +// require_once 'Zend/Http/UserAgent/Storage.php'; + +/** + * @see Zend_Session_Namespace + */ +// require_once 'Zend/Session/Namespace.php'; + +/** + * @package Zend_Http + * @subpackage UserAgent + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ +class Zend_Http_UserAgent_Storage_Session implements Zend_Http_UserAgent_Storage +{ + /** + * Default session namespace + */ + const NAMESPACE_DEFAULT = 'Zend_Http_UserAgent'; + + /** + * Default session object member name + */ + const MEMBER_DEFAULT = 'storage'; + + /** + * Object to proxy $_SESSION storage + * + * @var Zend_Session_Namespace + */ + protected $_session; + + /** + * Session namespace + * + * @var mixed + */ + protected $_namespace; + + /** + * Session object member + * + * @var mixed + */ + protected $_member; + + /** + * Sets session storage options and initializes session namespace object + * + * Expects options to contain 0 or more of the following keys: + * - browser_type -- maps to "namespace" internally + * - member + * + * @param null|array|object $options + * @return void + * @throws Zend_Http_UserAgent_Storage_Exception on invalid $options argument + */ + public function __construct($options = null) + { + if (is_object($options) && method_exists($options, 'toArray')) { + $options = $options->toArray(); + } elseif (is_object($options)) { + $options = (array) $options; + } + if (null !== $options && !is_array($options)) { + // require_once 'Zend/Http/UserAgent/Storage/Exception.php'; + throw new Zend_Http_UserAgent_Storage_Exception(sprintf( + 'Expected array or object options; "%s" provided', + gettype($options) + )); + } + + // add '.' to prevent the message ''Session namespace must not start with a number' + $this->_namespace = '.' + . (isset($options['browser_type']) + ? $options['browser_type'] + : self::NAMESPACE_DEFAULT); + $this->_member = isset($options['member']) ? $options['member'] : self::MEMBER_DEFAULT; + $this->_session = new Zend_Session_Namespace($this->_namespace); + } + + /** + * Returns the session namespace name + * + * @return string + */ + public function getNamespace() + { + return $this->_namespace; + } + + /** + * Returns the name of the session object member + * + * @return string + */ + public function getMember() + { + return $this->_member; + } + + /** + * Defined by Zend_Http_UserAgent_Storage + * + * @return boolean + */ + public function isEmpty() + { + return empty($this->_session->{$this->_member}); + } + + /** + * Defined by Zend_Http_UserAgent_Storage + * + * @return mixed + */ + public function read() + { + return $this->_session->{$this->_member}; + } + + /** + * Defined by Zend_Http_UserAgent_Storage + * + * @param mixed $contents + * @return void + */ + public function write($content) + { + $this->_session->{$this->_member} = $content; + } + + /** + * Defined by Zend_Http_UserAgent_Storage + * + * @return void + */ + public function clear() + { + unset($this->_session->{$this->_member}); + } +} diff --git a/libs/Zend/Http/UserAgent/Text.php b/libs/Zend/Http/UserAgent/Text.php new file mode 100644 index 0000000000..b7c8523b22 --- /dev/null +++ b/libs/Zend/Http/UserAgent/Text.php @@ -0,0 +1,132 @@ +<?php +/** + * Zend Framework + * + * LICENSE + * + * This source file is subject to the new BSD license that is bundled + * with this package in the file LICENSE.txt. + * It is also available through the world-wide-web at this URL: + * http://framework.zend.com/license/new-bsd + * If you did not receive a copy of the license and are unable to + * obtain it through the world-wide-web, please send an email + * to license@zend.com so we can send you a copy immediately. + * + * @category Zend + * @package Zend_Http + * @subpackage UserAgent + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +// require_once 'Zend/Http/UserAgent/AbstractDevice.php'; + +/** + * Text browser type matcher + * + * @category Zend + * @package Zend_Http + * @subpackage UserAgent + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ +class Zend_Http_UserAgent_Text extends Zend_Http_UserAgent_AbstractDevice +{ + /** + * User Agent Signatures + * + * @var array + */ + protected static $_uaSignatures = array( + 'lynx', + 'retawq', + 'w3m', + ); + + /** + * Comparison of the UserAgent chain and User Agent signatures + * + * @param string $userAgent User Agent chain + * @param array $server $_SERVER like param + * @return bool + */ + public static function match($userAgent, $server) + { + return self::_matchAgentAgainstSignatures($userAgent, self::$_uaSignatures); + } + + /** + * Gives the current browser type + * + * @return string + */ + public function getType() + { + return 'text'; + } + + /** + * Look for features + * + * @return string + */ + protected function _defineFeatures() + { + $this->setFeature('images', false, 'product_capability'); + $this->setFeature('iframes', false, 'product_capability'); + $this->setFeature('frames', false, 'product_capability'); + $this->setFeature('javascript', false, 'product_capability'); + return parent::_defineFeatures(); + } + + /** + * Determine supported image formats + * + * @return null + */ + public function getImageFormatSupport() + { + return null; + } + + /** + * Get preferred markup format + * + * @return string + */ + public function getPreferredMarkup() + { + return 'xhtml'; + } + + /** + * Get supported X/HTML markup level + * + * @return int + */ + public function getXhtmlSupportLevel() + { + return 1; + } + + /** + * Does the device support Flash? + * + * @return bool + */ + public function hasFlashSupport() + { + + return false; + } + + /** + * Does the device support PDF? + * + * @return bool + */ + public function hasPdfSupport() + { + return false; + } +} diff --git a/libs/Zend/Http/UserAgent/Validator.php b/libs/Zend/Http/UserAgent/Validator.php new file mode 100644 index 0000000000..947cd3ebde --- /dev/null +++ b/libs/Zend/Http/UserAgent/Validator.php @@ -0,0 +1,73 @@ +<?php +/** + * Zend Framework + * + * LICENSE + * + * This source file is subject to the new BSD license that is bundled + * with this package in the file LICENSE.txt. + * It is also available through the world-wide-web at this URL: + * http://framework.zend.com/license/new-bsd + * If you did not receive a copy of the license and are unable to + * obtain it through the world-wide-web, please send an email + * to license@zend.com so we can send you a copy immediately. + * + * @category Zend + * @package Zend_Http + * @subpackage UserAgent + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +// require_once 'Zend/Http/UserAgent/Desktop.php'; + +/** + * Validator browser type matcher + * + * @category Zend + * @package Zend_Http + * @subpackage UserAgent + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ +class Zend_Http_UserAgent_Validator extends Zend_Http_UserAgent_Desktop +{ + /** + * User Agent Signatures + * + * @var array + */ + protected static $_uaSignatures = array( + 'htmlvalidator', + 'csscheck', + 'cynthia', + 'htmlparser', + 'validator', + 'jfouffa', + 'jigsaw', + 'w3c_validator', + 'wdg_validator', + ); + + /** + * Comparison of the UserAgent chain and User Agent signatures + * + * @param string $userAgent User Agent chain + * @param array $server $_SERVER like param + * @return bool + */ + public static function match($userAgent, $server) + { + return self::_matchAgentAgainstSignatures($userAgent, self::$_uaSignatures); + } + + /** + * Gives the current browser type + * + * @return string + */ + public function getType() + { + return 'validator'; + } +} diff --git a/libs/Zend/Loader.php b/libs/Zend/Loader.php index b5ae731ef0..b25847d701 100644 --- a/libs/Zend/Loader.php +++ b/libs/Zend/Loader.php @@ -16,7 +16,7 @@ * @package Zend_Loader * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Loader.php 22020 2010-04-27 16:35:56Z matthew $ + * @version $Id: Loader.php 23484 2010-12-10 03:57:59Z mjh_ca $ */ /** @@ -61,7 +61,7 @@ class Zend_Loader } // Autodiscover the path from the class name - // Implementation is PHP namespace-aware, and based on + // Implementation is PHP namespace-aware, and based on // Framework Interop Group reference implementation: // http://groups.google.com/group/php-standards/web/psr-0-final-proposal $className = ltrim($class, '\\'); @@ -174,7 +174,7 @@ class Zend_Loader public static function isReadable($filename) { if (is_readable($filename)) { - // Return early if the filename is readable without needing the + // Return early if the filename is readable without needing the // include_path return true; } @@ -182,7 +182,7 @@ class Zend_Loader if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN' && preg_match('/^[a-z]:/i', $filename) ) { - // If on windows, and path provided is clearly an absolute path, + // If on windows, and path provided is clearly an absolute path, // return false immediately return false; } @@ -207,8 +207,8 @@ class Zend_Loader * * If no path provided, uses current include_path. Works around issues that * occur when the path includes stream schemas. - * - * @param string|null $path + * + * @param string|null $path * @return array */ public static function explodeIncludePath($path = null) @@ -218,7 +218,7 @@ class Zend_Loader } if (PATH_SEPARATOR == ':') { - // On *nix systems, include_paths which include paths with a stream + // On *nix systems, include_paths which include paths with a stream // schema cannot be safely explode'd, so we have to be a bit more // intelligent in the approach. $paths = preg_split('#:(?!//)#', $path); diff --git a/libs/Zend/Loader/Autoloader.php b/libs/Zend/Loader/Autoloader.php index 67be780d1a..e9f27e79c4 100644 --- a/libs/Zend/Loader/Autoloader.php +++ b/libs/Zend/Loader/Autoloader.php @@ -16,7 +16,7 @@ * @package Zend_Loader * @subpackage Autoloader * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) - * @version $Id: Autoloader.php 22480 2010-06-21 17:37:20Z matthew $ + * @version $Id: Autoloader.php 23161 2010-10-19 16:08:36Z matthew $ * @license http://framework.zend.com/license/new-bsd New BSD License */ @@ -560,7 +560,7 @@ class Zend_Loader_Autoloader $versionLen = strlen($version); $versions = array(); $dirs = glob("$path/*", GLOB_ONLYDIR); - foreach ($dirs as $dir) { + foreach ((array) $dirs as $dir) { $dirName = substr($dir, strlen($path) + 1); if (!preg_match('/^(?:ZendFramework-)?(\d+\.\d+\.\d+((a|b|pl|pr|p|rc)\d+)?)(?:-minimal)?$/i', $dirName, $matches)) { continue; diff --git a/libs/Zend/Loader/Autoloader/Interface.php b/libs/Zend/Loader/Autoloader/Interface.php index 8bcaf14fb2..3533285988 100644 --- a/libs/Zend/Loader/Autoloader/Interface.php +++ b/libs/Zend/Loader/Autoloader/Interface.php @@ -16,7 +16,7 @@ * @package Zend_Loader * @subpackage Autoloader * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) - * @version $Id: Interface.php 20096 2010-01-06 02:05:09Z bkarwin $ + * @version $Id: Interface.php 22913 2010-08-29 00:28:02Z ramon $ * @license http://framework.zend.com/license/new-bsd New BSD License */ @@ -30,5 +30,14 @@ */ interface Zend_Loader_Autoloader_Interface { + /** + * Autoload a class + * + * @abstract + * @param string $class + * @return mixed + * False [if unable to load $class] + * get_class($class) [if $class is successfully loaded] + */ public function autoload($class); } diff --git a/libs/Zend/Loader/Autoloader/Resource.php b/libs/Zend/Loader/Autoloader/Resource.php index cd0a7fe7fc..5c9d94d384 100644 --- a/libs/Zend/Loader/Autoloader/Resource.php +++ b/libs/Zend/Loader/Autoloader/Resource.php @@ -16,7 +16,7 @@ * @package Zend_Loader * @subpackage Autoloader * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) - * @version $Id: Resource.php 20096 2010-01-06 02:05:09Z bkarwin $ + * @version $Id: Resource.php 23568 2010-12-20 08:13:20Z mjh_ca $ * @license http://framework.zend.com/license/new-bsd New BSD License */ @@ -88,6 +88,7 @@ class Zend_Loader_Autoloader_Resource implements Zend_Loader_Autoloader_Interfac if (!empty($namespace)) { $namespace .= '_'; } + // require_once 'Zend/Loader/Autoloader.php'; Zend_Loader_Autoloader::getInstance()->unshiftAutoloader($this, $namespace); } @@ -205,6 +206,12 @@ class Zend_Loader_Autoloader_Resource implements Zend_Loader_Autoloader_Interfac */ public function setOptions(array $options) { + // Set namespace first, see ZF-10836 + if (isset($options['namespace'])) { + $this->setNamespace($options['namespace']); + unset($options['namespace']); + } + $methods = get_class_methods($this); foreach ($options as $key => $value) { $method = 'set' . ucfirst($key); diff --git a/libs/Zend/Loader/PluginLoader.php b/libs/Zend/Loader/PluginLoader.php index 43e9fda963..78bc2155c5 100644 --- a/libs/Zend/Loader/PluginLoader.php +++ b/libs/Zend/Loader/PluginLoader.php @@ -17,7 +17,7 @@ * @subpackage PluginLoader * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: PluginLoader.php 22604 2010-07-17 00:14:06Z ramon $ + * @version $Id: PluginLoader.php 22603 2010-07-17 00:02:10Z ramon $ */ /** Zend_Loader_PluginLoader_Interface */ diff --git a/libs/Zend/Log.php b/libs/Zend/Log.php index ab263d3b63..b422e351a4 100644 --- a/libs/Zend/Log.php +++ b/libs/Zend/Log.php @@ -16,7 +16,7 @@ * @package Zend_Log * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Log.php 22632 2010-07-18 18:30:08Z ramon $ + * @version $Id: Log.php 23576 2010-12-23 23:25:44Z ramon $ */ /** @@ -24,7 +24,7 @@ * @package Zend_Log * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Log.php 22632 2010-07-18 18:30:08Z ramon $ + * @version $Id: Log.php 23576 2010-12-23 23:25:44Z ramon $ */ class Zend_Log { @@ -70,11 +70,35 @@ class Zend_Log */ protected $_defaultFilterNamespace = 'Zend_Log_Filter'; + /** + * + * @var callback + */ + protected $_origErrorHandler = null; + + /** + * + * @var boolean + */ + protected $_registeredErrorHandler = false; + + /** + * + * @var array|boolean + */ + protected $_errorHandlerMap = false; + + /** + * + * @var string + */ + protected $_timestampFormat = 'c'; /** * Class constructor. Create a new logger * * @param Zend_Log_Writer_Abstract|null $writer default writer + * @return void */ public function __construct(Zend_Log_Writer_Abstract $writer = null) { @@ -92,6 +116,7 @@ class Zend_Log * * @param array|Zend_Config Array or instance of Zend_Config * @return Zend_Log + * @throws Zend_Log_Exception */ static public function factory($config = array()) { @@ -105,7 +130,7 @@ class Zend_Log throw new Zend_Log_Exception('Configuration must be an array or instance of Zend_Config'); } - $log = new Zend_Log; + $log = new self; if (!is_array(current($config))) { $log->addWriter(current($config)); @@ -124,6 +149,7 @@ class Zend_Log * * @param array $spec config array with writer spec * @return Zend_Log_Writer_Abstract + * @throws Zend_Log_Exception */ protected function _constructWriterFromConfig($config) { @@ -151,6 +177,7 @@ class Zend_Log * * @param array|Zend_Config $config Zend_Config or Array * @return Zend_Log_Filter_Interface + * @throws Zend_Log_Exception */ protected function _constructFilterFromConfig($config) { @@ -175,6 +202,7 @@ class Zend_Log * @param mixed $config Zend_Config or Array * @param string $namespace * @return object + * @throws Zend_Log_Exception */ protected function _constructFromConfig($type, $config, $namespace) { @@ -214,6 +242,7 @@ class Zend_Log * @param string $type filter|writer * @param string $defaultNamespace * @return string full classname + * @throws Zend_Log_Exception */ protected function getClassName($config, $type, $defaultNamespace) { @@ -233,6 +262,25 @@ class Zend_Log } /** + * Packs message and priority into Event array + * + * @param string $message Message to log + * @param integer $priority Priority of message + * @return array Event array + */ + protected function _packEvent($message, $priority) + { + return array_merge(array( + 'timestamp' => date($this->_timestampFormat), + 'message' => $message, + 'priority' => $priority, + 'priorityName' => $this->_priorities[$priority] + ), + $this->_extras + ); + } + + /** * Class destructor. Shutdown log writers * * @return void @@ -306,11 +354,7 @@ class Zend_Log } // pack into event required by filters and writers - $event = array_merge(array('timestamp' => date('c'), - 'message' => $message, - 'priority' => $priority, - 'priorityName' => $this->_priorities[$priority]), - $this->_extras); + $event = $this->_packEvent($message, $priority); // Check to see if any extra information was passed if (!empty($extras)) { @@ -349,7 +393,7 @@ class Zend_Log * * @param string $name Name of priority * @param integer $priority Numeric priority - * @throws Zend_Log_InvalidArgumentException + * @throws Zend_Log_Exception */ public function addPriority($name, $priority) { @@ -364,6 +408,7 @@ class Zend_Log } $this->_priorities[$priority] = $name; + return $this; } /** @@ -371,12 +416,13 @@ class Zend_Log * Before a message will be received by any of the writers, it * must be accepted by all filters added with this method. * - * @param int|Zend_Log_Filter_Interface $filter - * @return void + * @param int|Zend_Config|array|Zend_Log_Filter_Interface $filter + * @return Zend_Log + * @throws Zend_Log_Exception */ public function addFilter($filter) { - if (is_integer($filter)) { + if (is_int($filter)) { /** @see Zend_Log_Filter_Priority */ // require_once 'Zend/Log/Filter/Priority.php'; $filter = new Zend_Log_Filter_Priority($filter); @@ -391,6 +437,7 @@ class Zend_Log } $this->_filters[] = $filter; + return $this; } /** @@ -398,7 +445,7 @@ class Zend_Log * message and writing it out to storage. * * @param mixed $writer Zend_Log_Writer_Abstract or Config array - * @return void + * @return Zend_Log */ public function addWriter($writer) { @@ -416,6 +463,7 @@ class Zend_Log } $this->_writers[] = $writer; + return $this; } /** @@ -423,10 +471,113 @@ class Zend_Log * * @param $name Name of the field * @param $value Value of the field - * @return void + * @return Zend_Log */ public function setEventItem($name, $value) { $this->_extras = array_merge($this->_extras, array($name => $value)); + return $this; + } + + /** + * Register Logging system as an error handler to log php errors + * Note: it still calls the original error handler if set_error_handler is able to return it. + * + * Errors will be mapped as: + * E_NOTICE, E_USER_NOTICE => NOTICE + * E_WARNING, E_CORE_WARNING, E_USER_WARNING => WARN + * E_ERROR, E_USER_ERROR, E_CORE_ERROR, E_RECOVERABLE_ERROR => ERR + * E_DEPRECATED, E_STRICT, E_USER_DEPRECATED => DEBUG + * (unknown/other) => INFO + * + * @link http://www.php.net/manual/en/function.set-error-handler.php Custom error handler + * + * @return Zend_Log + */ + public function registerErrorHandler() + { + // Only register once. Avoids loop issues if it gets registered twice. + if ($this->_registeredErrorHandler) { + return $this; + } + + $this->_origErrorHandler = set_error_handler(array($this, 'errorHandler')); + + // Contruct a default map of phpErrors to Zend_Log priorities. + // Some of the errors are uncatchable, but are included for completeness + $this->_errorHandlerMap = array( + E_NOTICE => Zend_Log::NOTICE, + E_USER_NOTICE => Zend_Log::NOTICE, + E_WARNING => Zend_Log::WARN, + E_CORE_WARNING => Zend_Log::WARN, + E_USER_WARNING => Zend_Log::WARN, + E_ERROR => Zend_Log::ERR, + E_USER_ERROR => Zend_Log::ERR, + E_CORE_ERROR => Zend_Log::ERR, + E_RECOVERABLE_ERROR => Zend_Log::ERR, + E_STRICT => Zend_Log::DEBUG, + ); + // PHP 5.3.0+ + if (defined('E_DEPRECATED')) { + $this->_errorHandlerMap['E_DEPRECATED'] = Zend_Log::DEBUG; + } + if (defined('E_USER_DEPRECATED')) { + $this->_errorHandlerMap['E_USER_DEPRECATED'] = Zend_Log::DEBUG; + } + + $this->_registeredErrorHandler = true; + return $this; + } + + /** + * Error Handler will convert error into log message, and then call the original error handler + * + * @link http://www.php.net/manual/en/function.set-error-handler.php Custom error handler + * @param int $errno + * @param string $errstr + * @param string $errfile + * @param int $errline + * @param array $errcontext + * @return boolean + */ + public function errorHandler($errno, $errstr, $errfile, $errline, $errcontext) + { + $errorLevel = error_reporting(); + + if ($errorLevel && $errno) { + if (isset($this->_errorHandlerMap[$errno])) { + $priority = $this->_errorHandlerMap[$errno]; + } else { + $priority = Zend_Log::INFO; + } + $this->log($errstr, $priority, array('errno'=>$errno, 'file'=>$errfile, 'line'=>$errline, 'context'=>$errcontext)); + } + + if ($this->_origErrorHandler !== null) { + return call_user_func($this->_origErrorHandler, $errno, $errstr, $errfile, $errline, $errcontext); + } + return false; + } + + /** + * Set timestamp format for log entries. + * + * @param string $format + * @return Zend_Log + */ + public function setTimestampFormat($format) + { + $this->_timestampFormat = $format; + return $this; + } + + /** + * Get timestamp format used for log entries. + * + * @return string + */ + public function getTimestampFormat() + { + return $this->_timestampFormat; } } diff --git a/libs/Zend/Log/FactoryInterface.php b/libs/Zend/Log/FactoryInterface.php index 20a270747f..ea988826c2 100644 --- a/libs/Zend/Log/FactoryInterface.php +++ b/libs/Zend/Log/FactoryInterface.php @@ -16,7 +16,7 @@ * @package Zend_Log * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id$ + * @version $Id: FactoryInterface.php 23484 2010-12-10 03:57:59Z mjh_ca $ */ /** @@ -24,13 +24,13 @@ * @package Zend_Log * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id$ + * @version $Id: FactoryInterface.php 23484 2010-12-10 03:57:59Z mjh_ca $ */ interface Zend_Log_FactoryInterface { /** * Construct a Zend_Log driver - * + * * @param array|Zen_Config $config * @return Zend_Log_FactoryInterface */ diff --git a/libs/Zend/Log/Filter/Abstract.php b/libs/Zend/Log/Filter/Abstract.php index e0e97b89f2..01a31f4e00 100644 --- a/libs/Zend/Log/Filter/Abstract.php +++ b/libs/Zend/Log/Filter/Abstract.php @@ -17,7 +17,7 @@ * @subpackage Writer * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id$ + * @version $Id: Abstract.php 23484 2010-12-10 03:57:59Z mjh_ca $ */ /** @see Zend_Log_Filter_Interface */ @@ -29,17 +29,17 @@ /** * @category Zend * @package Zend_Log - * @subpackage Writer + * @subpackage Filter * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id$ + * @version $Id: Abstract.php 23484 2010-12-10 03:57:59Z mjh_ca $ */ -abstract class Zend_Log_Filter_Abstract +abstract class Zend_Log_Filter_Abstract implements Zend_Log_Filter_Interface, Zend_Log_FactoryInterface { /** * Validate and optionally convert the config to array - * + * * @param array|Zend_Config $config Zend_Config or Array * @return array * @throws Zend_Log_Exception diff --git a/libs/Zend/Log/Filter/Message.php b/libs/Zend/Log/Filter/Message.php index 4510888610..877722dd3a 100644 --- a/libs/Zend/Log/Filter/Message.php +++ b/libs/Zend/Log/Filter/Message.php @@ -17,7 +17,7 @@ * @subpackage Filter * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Message.php 20982 2010-02-08 15:51:36Z matthew $ + * @version $Id: Message.php 23576 2010-12-23 23:25:44Z ramon $ */ /** Zend_Log_Filter_Abstract */ @@ -29,7 +29,7 @@ * @subpackage Filter * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Message.php 20982 2010-02-08 15:51:36Z matthew $ + * @version $Id: Message.php 23576 2010-12-23 23:25:44Z ramon $ */ class Zend_Log_Filter_Message extends Zend_Log_Filter_Abstract { @@ -42,6 +42,7 @@ class Zend_Log_Filter_Message extends Zend_Log_Filter_Abstract * Filter out any log messages not matching $regexp. * * @param string $regexp Regular expression to test the log message + * @return void * @throws Zend_Log_Exception */ public function __construct($regexp) @@ -55,12 +56,11 @@ class Zend_Log_Filter_Message extends Zend_Log_Filter_Abstract /** * Create a new instance of Zend_Log_Filter_Message - * + * * @param array|Zend_Config $config * @return Zend_Log_Filter_Message - * @throws Zend_Log_Exception */ - static public function factory($config) + static public function factory($config) { $config = self::_parseConfig($config); $config = array_merge(array( diff --git a/libs/Zend/Log/Filter/Priority.php b/libs/Zend/Log/Filter/Priority.php index 45ba7c953b..80670df1b7 100644 --- a/libs/Zend/Log/Filter/Priority.php +++ b/libs/Zend/Log/Filter/Priority.php @@ -17,7 +17,7 @@ * @subpackage Filter * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Priority.php 20260 2010-01-13 18:29:22Z ralph $ + * @version $Id: Priority.php 23576 2010-12-23 23:25:44Z ramon $ */ /** Zend_Log_Filter_Abstract */ @@ -29,7 +29,7 @@ * @subpackage Filter * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Priority.php 20260 2010-01-13 18:29:22Z ralph $ + * @version $Id: Priority.php 23576 2010-12-23 23:25:44Z ramon $ */ class Zend_Log_Filter_Priority extends Zend_Log_Filter_Abstract { @@ -49,31 +49,31 @@ class Zend_Log_Filter_Priority extends Zend_Log_Filter_Abstract * * @param integer $priority Priority * @param string $operator Comparison operator + * @return void * @throws Zend_Log_Exception */ - public function __construct($priority, $operator = NULL) + public function __construct($priority, $operator = null) { - if (! is_integer($priority)) { + if (! is_int($priority)) { // require_once 'Zend/Log/Exception.php'; throw new Zend_Log_Exception('Priority must be an integer'); } $this->_priority = $priority; - $this->_operator = is_null($operator) ? '<=' : $operator; + $this->_operator = $operator === null ? '<=' : $operator; } /** * Create a new instance of Zend_Log_Filter_Priority - * + * * @param array|Zend_Config $config * @return Zend_Log_Filter_Priority - * @throws Zend_Log_Exception */ - static public function factory($config) + static public function factory($config) { $config = self::_parseConfig($config); $config = array_merge(array( - 'priority' => null, + 'priority' => null, 'operator' => null, ), $config); @@ -83,7 +83,7 @@ class Zend_Log_Filter_Priority extends Zend_Log_Filter_Abstract } return new self( - (int) $config['priority'], + (int) $config['priority'], $config['operator'] ); } diff --git a/libs/Zend/Log/Filter/Suppress.php b/libs/Zend/Log/Filter/Suppress.php index d87d2720a2..4efbf87f8a 100644 --- a/libs/Zend/Log/Filter/Suppress.php +++ b/libs/Zend/Log/Filter/Suppress.php @@ -17,11 +17,11 @@ * @subpackage Filter * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Suppress.php 20096 2010-01-06 02:05:09Z bkarwin $ + * @version $Id: Suppress.php 22977 2010-09-19 12:44:00Z intiilapa $ */ /** Zend_Log_Filter_Interface */ -// require_once 'Zend/Log/Filter/Interface.php'; +// require_once 'Zend/Log/Filter/Abstract.php'; /** * @category Zend @@ -29,7 +29,7 @@ * @subpackage Filter * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Suppress.php 20096 2010-01-06 02:05:09Z bkarwin $ + * @version $Id: Suppress.php 22977 2010-09-19 12:44:00Z intiilapa $ */ class Zend_Log_Filter_Suppress extends Zend_Log_Filter_Abstract { @@ -65,7 +65,7 @@ class Zend_Log_Filter_Suppress extends Zend_Log_Filter_Abstract /** * Create a new instance of Zend_Log_Filter_Suppress - * + * * @param array|Zend_Config $config * @return Zend_Log_Filter_Suppress * @throws Zend_Log_Exception diff --git a/libs/Zend/Log/Formatter/Simple.php b/libs/Zend/Log/Formatter/Simple.php index 22f5a116fc..3e8aa5f208 100644 --- a/libs/Zend/Log/Formatter/Simple.php +++ b/libs/Zend/Log/Formatter/Simple.php @@ -17,7 +17,7 @@ * @subpackage Formatter * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Simple.php 20096 2010-01-06 02:05:09Z bkarwin $ + * @version $Id: Simple.php 23576 2010-12-23 23:25:44Z ramon $ */ /** Zend_Log_Formatter_Interface */ @@ -29,7 +29,7 @@ * @subpackage Formatter * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Simple.php 20096 2010-01-06 02:05:09Z bkarwin $ + * @version $Id: Simple.php 23576 2010-12-23 23:25:44Z ramon $ */ class Zend_Log_Formatter_Simple implements Zend_Log_Formatter_Interface { @@ -44,6 +44,7 @@ class Zend_Log_Formatter_Simple implements Zend_Log_Formatter_Interface * Class constructor * * @param null|string $format Format specifier for log messages + * @return void * @throws Zend_Log_Exception */ public function __construct($format = null) diff --git a/libs/Zend/Log/Formatter/Xml.php b/libs/Zend/Log/Formatter/Xml.php index ebf3c29e97..8940473f09 100644 --- a/libs/Zend/Log/Formatter/Xml.php +++ b/libs/Zend/Log/Formatter/Xml.php @@ -17,7 +17,7 @@ * @subpackage Formatter * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Xml.php 20104 2010-01-06 21:26:01Z matthew $ + * @version $Id: Xml.php 23576 2010-12-23 23:25:44Z ramon $ */ /** Zend_Log_Formatter_Interface */ @@ -29,17 +29,17 @@ * @subpackage Formatter * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Xml.php 20104 2010-01-06 21:26:01Z matthew $ + * @version $Id: Xml.php 23576 2010-12-23 23:25:44Z ramon $ */ class Zend_Log_Formatter_Xml implements Zend_Log_Formatter_Interface { /** - * @var Relates XML elements to log data field keys. + * @var string Name of root element */ protected $_rootElement; /** - * @var Relates XML elements to log data field keys. + * @var array Relates XML elements to log data field keys. */ protected $_elementMap; @@ -52,8 +52,9 @@ class Zend_Log_Formatter_Xml implements Zend_Log_Formatter_Interface * Class constructor * * @param string $rootElement Name of root element - * @param array $elementMap + * @param array $elementMap Relates XML elements to log data field keys * @param string $encoding Encoding to use (defaults to UTF-8) + * @return void */ public function __construct($rootElement = 'logEntry', $elementMap = null, $encoding = 'UTF-8') { diff --git a/libs/Zend/Log/Writer/Abstract.php b/libs/Zend/Log/Writer/Abstract.php index b3e244ba0e..11750458e5 100644 --- a/libs/Zend/Log/Writer/Abstract.php +++ b/libs/Zend/Log/Writer/Abstract.php @@ -17,7 +17,7 @@ * @subpackage Writer * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Abstract.php 22632 2010-07-18 18:30:08Z ramon $ + * @version $Id: Abstract.php 23576 2010-12-23 23:25:44Z ramon $ */ /** Zend_Log_Filter_Priority */ @@ -29,7 +29,7 @@ * @subpackage Writer * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Abstract.php 22632 2010-07-18 18:30:08Z ramon $ + * @version $Id: Abstract.php 23576 2010-12-23 23:25:44Z ramon $ */ abstract class Zend_Log_Writer_Abstract implements Zend_Log_FactoryInterface { @@ -40,6 +40,7 @@ abstract class Zend_Log_Writer_Abstract implements Zend_Log_FactoryInterface /** * Formats the log message before writing. + * * @var Zend_Log_Formatter_Interface */ protected $_formatter; @@ -48,11 +49,11 @@ abstract class Zend_Log_Writer_Abstract implements Zend_Log_FactoryInterface * Add a filter specific to this writer. * * @param Zend_Log_Filter_Interface $filter - * @return void + * @return Zend_Log_Writer_Abstract */ public function addFilter($filter) { - if (is_integer($filter)) { + if (is_int($filter)) { $filter = new Zend_Log_Filter_Priority($filter); } @@ -63,12 +64,13 @@ abstract class Zend_Log_Writer_Abstract implements Zend_Log_FactoryInterface } $this->_filters[] = $filter; + return $this; } /** * Log a message to this writer. * - * @param array $event log data event + * @param array $event log data event * @return void */ public function write($event) @@ -87,11 +89,12 @@ abstract class Zend_Log_Writer_Abstract implements Zend_Log_FactoryInterface * Set a new formatter for this writer * * @param Zend_Log_Formatter_Interface $formatter - * @return void + * @return Zend_Log_Writer_Abstract */ public function setFormatter(Zend_Log_Formatter_Interface $formatter) { $this->_formatter = $formatter; + return $this; } /** @@ -126,8 +129,8 @@ abstract class Zend_Log_Writer_Abstract implements Zend_Log_FactoryInterface if (!is_array($config)) { // require_once 'Zend/Log/Exception.php'; throw new Zend_Log_Exception( - 'Configuration must be an array or instance of Zend_Config' - ); + 'Configuration must be an array or instance of Zend_Config' + ); } return $config; diff --git a/libs/Zend/Log/Writer/Db.php b/libs/Zend/Log/Writer/Db.php index 54634040b4..47217052d6 100644 --- a/libs/Zend/Log/Writer/Db.php +++ b/libs/Zend/Log/Writer/Db.php @@ -17,7 +17,7 @@ * @subpackage Writer * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Db.php 22514 2010-07-01 14:11:18Z ramon $ + * @version $Id: Db.php 23576 2010-12-23 23:25:44Z ramon $ */ /** Zend_Log_Writer_Abstract */ @@ -29,18 +29,20 @@ * @subpackage Writer * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Db.php 22514 2010-07-01 14:11:18Z ramon $ + * @version $Id: Db.php 23576 2010-12-23 23:25:44Z ramon $ */ class Zend_Log_Writer_Db extends Zend_Log_Writer_Abstract { /** * Database adapter instance + * * @var Zend_Db_Adapter */ private $_db; /** * Name of the log table in the database + * * @var string */ private $_table; @@ -58,6 +60,7 @@ class Zend_Log_Writer_Db extends Zend_Log_Writer_Abstract * @param Zend_Db_Adapter $db Database adapter instance * @param string $table Log table in database * @param array $columnMap + * @return void */ public function __construct($db, $table, $columnMap = null) { @@ -95,6 +98,9 @@ class Zend_Log_Writer_Db extends Zend_Log_Writer_Abstract /** * Formatting is not possible on this writer + * + * @return void + * @throws Zend_Log_Exception */ public function setFormatter(Zend_Log_Formatter_Interface $formatter) { diff --git a/libs/Zend/Log/Writer/Firebug.php b/libs/Zend/Log/Writer/Firebug.php index 585f6a3dc1..94266506f1 100644 --- a/libs/Zend/Log/Writer/Firebug.php +++ b/libs/Zend/Log/Writer/Firebug.php @@ -17,7 +17,7 @@ * @subpackage Writer * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Firebug.php 20096 2010-01-06 02:05:09Z bkarwin $ + * @version $Id: Firebug.php 23576 2010-12-23 23:25:44Z ramon $ */ /** Zend_Log */ @@ -43,9 +43,9 @@ */ class Zend_Log_Writer_Firebug extends Zend_Log_Writer_Abstract { - /** * Maps logging priorities to logging display styles + * * @var array */ protected $_priorityStyles = array(Zend_Log::EMERG => Zend_Wildfire_Plugin_FirePhp::ERROR, @@ -59,18 +59,22 @@ class Zend_Log_Writer_Firebug extends Zend_Log_Writer_Abstract /** * The default logging style for un-mapped priorities + * * @var string */ protected $_defaultPriorityStyle = Zend_Wildfire_Plugin_FirePhp::LOG; /** * Flag indicating whether the log writer is enabled + * * @var boolean */ protected $_enabled = true; /** * Class constructor + * + * @return void */ public function __construct() { @@ -80,13 +84,12 @@ class Zend_Log_Writer_Firebug extends Zend_Log_Writer_Abstract $this->_formatter = new Zend_Log_Formatter_Firebug(); } - + /** * Create a new instance of Zend_Log_Writer_Firebug - * + * * @param array|Zend_Config $config * @return Zend_Log_Writer_Firebug - * @throws Zend_Log_Exception */ static public function factory($config) { @@ -195,6 +198,7 @@ class Zend_Log_Writer_Firebug extends Zend_Log_Writer_Abstract Zend_Wildfire_Plugin_FirePhp::getInstance()->send($message, $label, $type, - array('traceOffset'=>6)); + array('traceOffset'=>4, + 'fixZendLogOffsetIfApplicable'=>true)); } } diff --git a/libs/Zend/Log/Writer/Mail.php b/libs/Zend/Log/Writer/Mail.php index 70f57b8616..2807a4ed52 100644 --- a/libs/Zend/Log/Writer/Mail.php +++ b/libs/Zend/Log/Writer/Mail.php @@ -17,7 +17,7 @@ * @subpackage Writer * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Mail.php 20096 2010-01-06 02:05:09Z bkarwin $ + * @version $Id: Mail.php 23576 2010-12-23 23:25:44Z ramon $ */ /** Zend_Log_Writer_Abstract */ @@ -41,7 +41,7 @@ * @subpackage Writer * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Mail.php 20096 2010-01-06 02:05:09Z bkarwin $ + * @version $Id: Mail.php 23576 2010-12-23 23:25:44Z ramon $ */ class Zend_Log_Writer_Mail extends Zend_Log_Writer_Abstract { @@ -101,6 +101,18 @@ class Zend_Log_Writer_Mail extends Zend_Log_Writer_Abstract protected $_subjectPrependText; /** + * MethodMap for Zend_Mail's headers + * + * @var array + */ + protected static $_methodMapHeaders = array( + 'from' => 'setFrom', + 'to' => 'addTo', + 'cc' => 'addCc', + 'bcc' => 'addBcc', + ); + + /** * Class constructor. * * Constructs the mail writer; requires a Zend_Mail instance, and takes an @@ -113,21 +125,131 @@ class Zend_Log_Writer_Mail extends Zend_Log_Writer_Abstract */ public function __construct(Zend_Mail $mail, Zend_Layout $layout = null) { - $this->_mail = $mail; - $this->_layout = $layout; + $this->_mail = $mail; + if (null !== $layout) { + $this->setLayout($layout); + } $this->_formatter = new Zend_Log_Formatter_Simple(); } - + /** * Create a new instance of Zend_Log_Writer_Mail - * + * * @param array|Zend_Config $config * @return Zend_Log_Writer_Mail - * @throws Zend_Log_Exception */ static public function factory($config) { - throw new Zend_Exception('Zend_Log_Writer_Mail does not currently implement a factory'); + $config = self::_parseConfig($config); + $mail = self::_constructMailFromConfig($config); + $writer = new self($mail); + + if (isset($config['layout']) || isset($config['layoutOptions'])) { + $writer->setLayout($config); + } + if (isset($config['layoutFormatter'])) { + $layoutFormatter = new $config['layoutFormatter']; + $writer->setLayoutFormatter($layoutFormatter); + } + if (isset($config['subjectPrependText'])) { + $writer->setSubjectPrependText($config['subjectPrependText']); + } + + return $writer; + } + + /** + * Set the layout + * + * @param Zend_Layout|array $layout + * @return Zend_Log_Writer_Mail + * @throws Zend_Log_Exception + */ + public function setLayout($layout) + { + if (is_array($layout)) { + $layout = $this->_constructLayoutFromConfig($layout); + } + + if (!$layout instanceof Zend_Layout) { + // require_once 'Zend/Log/Exception.php'; + throw new Zend_Log_Exception('Mail must be an instance of Zend_Layout or an array'); + } + $this->_layout = $layout; + + return $this; + } + + /** + * Construct a Zend_Mail instance based on a configuration array + * + * @param array $config + * @return Zend_Mail + * @throws Zend_Log_Exception + */ + protected static function _constructMailFromConfig(array $config) + { + $mailClass = 'Zend_Mail'; + if (isset($config['mail'])) { + $mailClass = $config['mail']; + } + + if (!array_key_exists('charset', $config)) { + $config['charset'] = null; + } + $mail = new $mailClass($config['charset']); + if (!$mail instanceof Zend_Mail) { + throw new Zend_Log_Exception($mail . 'must extend Zend_Mail'); + } + + if (isset($config['subject'])) { + $mail->setSubject($config['subject']); + } + + $headerAddresses = array_intersect_key($config, self::$_methodMapHeaders); + if (count($headerAddresses)) { + foreach ($headerAddresses as $header => $address) { + $method = self::$_methodMapHeaders[$header]; + if (is_array($address) && isset($address['name']) + && !is_numeric($address['name']) + ) { + $params = array( + $address['email'], + $address['name'] + ); + } else if (is_array($address) && isset($address['email'])) { + $params = array($address['email']); + } else { + $params = array($address); + } + call_user_func_array(array($mail, $method), $params); + } + } + + return $mail; + } + + /** + * Construct a Zend_Layout instance based on a configuration array + * + * @param array $config + * @return Zend_Layout + * @throws Zend_Log_Exception + */ + protected function _constructLayoutFromConfig(array $config) + { + $config = array_merge(array( + 'layout' => 'Zend_Layout', + 'layoutOptions' => null + ), $config); + + $layoutClass = $config['layout']; + $layout = new $layoutClass($config['layoutOptions']); + if (!$layout instanceof Zend_Layout) { + throw new Zend_Log_Exception($layout . 'must extend Zend_Layout'); + } + + return $layout; } /** @@ -211,6 +333,7 @@ class Zend_Log_Writer_Mail extends Zend_Log_Writer_Abstract * * @param string $subject Subject prepend text. * @return Zend_Log_Writer_Mail + * @throws Zend_Log_Exception */ public function setSubjectPrependText($subject) { diff --git a/libs/Zend/Log/Writer/Mock.php b/libs/Zend/Log/Writer/Mock.php index 1e14a2f00e..29984292b6 100644 --- a/libs/Zend/Log/Writer/Mock.php +++ b/libs/Zend/Log/Writer/Mock.php @@ -17,7 +17,7 @@ * @subpackage Writer * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Mock.php 20096 2010-01-06 02:05:09Z bkarwin $ + * @version $Id: Mock.php 23576 2010-12-23 23:25:44Z ramon $ */ /** Zend_Log_Writer_Abstract */ @@ -29,17 +29,21 @@ * @subpackage Writer * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Mock.php 20096 2010-01-06 02:05:09Z bkarwin $ + * @version $Id: Mock.php 23576 2010-12-23 23:25:44Z ramon $ */ class Zend_Log_Writer_Mock extends Zend_Log_Writer_Abstract { /** * array of log events + * + * @var array */ public $events = array(); /** * shutdown called? + * + * @var boolean */ public $shutdown = false; @@ -66,12 +70,11 @@ class Zend_Log_Writer_Mock extends Zend_Log_Writer_Abstract /** * Create a new instance of Zend_Log_Writer_Mock - * + * * @param array|Zend_Config $config * @return Zend_Log_Writer_Mock - * @throws Zend_Log_Exception */ - static public function factory($config) + static public function factory($config) { return new self(); } diff --git a/libs/Zend/Log/Writer/Null.php b/libs/Zend/Log/Writer/Null.php index f281883fbb..9d80cf1552 100644 --- a/libs/Zend/Log/Writer/Null.php +++ b/libs/Zend/Log/Writer/Null.php @@ -17,7 +17,7 @@ * @subpackage Writer * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Null.php 20096 2010-01-06 02:05:09Z bkarwin $ + * @version $Id: Null.php 23576 2010-12-23 23:25:44Z ramon $ */ /** Zend_Log_Writer_Abstract */ @@ -29,7 +29,7 @@ * @subpackage Writer * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Null.php 20096 2010-01-06 02:05:09Z bkarwin $ + * @version $Id: Null.php 23576 2010-12-23 23:25:44Z ramon $ */ class Zend_Log_Writer_Null extends Zend_Log_Writer_Abstract { @@ -42,13 +42,12 @@ class Zend_Log_Writer_Null extends Zend_Log_Writer_Abstract protected function _write($event) { } - + /** * Create a new instance of Zend_Log_Writer_Null - * + * * @param array|Zend_Config $config * @return Zend_Log_Writer_Null - * @throws Zend_Log_Exception */ static public function factory($config) { diff --git a/libs/Zend/Log/Writer/Stream.php b/libs/Zend/Log/Writer/Stream.php index b722dbb4bd..25d6d75892 100644 --- a/libs/Zend/Log/Writer/Stream.php +++ b/libs/Zend/Log/Writer/Stream.php @@ -17,7 +17,7 @@ * @subpackage Writer * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Stream.php 20096 2010-01-06 02:05:09Z bkarwin $ + * @version $Id: Stream.php 23584 2010-12-28 19:51:49Z matthew $ */ /** Zend_Log_Writer_Abstract */ @@ -32,12 +32,13 @@ * @subpackage Writer * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Stream.php 20096 2010-01-06 02:05:09Z bkarwin $ + * @version $Id: Stream.php 23584 2010-12-28 19:51:49Z matthew $ */ class Zend_Log_Writer_Stream extends Zend_Log_Writer_Abstract { /** * Holds the PHP stream to log to. + * * @var null|stream */ protected $_stream = null; @@ -45,13 +46,15 @@ class Zend_Log_Writer_Stream extends Zend_Log_Writer_Abstract /** * Class Constructor * - * @param streamOrUrl Stream or URL to open as a stream - * @param mode Mode, only applicable if a URL is given + * @param array|string|resource $streamOrUrl Stream or URL to open as a stream + * @param string|null $mode Mode, only applicable if a URL is given + * @return void + * @throws Zend_Log_Exception */ - public function __construct($streamOrUrl, $mode = NULL) + public function __construct($streamOrUrl, $mode = null) { // Setting the default - if ($mode === NULL) { + if (null === $mode) { $mode = 'a'; } @@ -81,30 +84,29 @@ class Zend_Log_Writer_Stream extends Zend_Log_Writer_Abstract $this->_formatter = new Zend_Log_Formatter_Simple(); } - + /** - * Create a new instance of Zend_Log_Writer_Mock - * + * Create a new instance of Zend_Log_Writer_Stream + * * @param array|Zend_Config $config - * @return Zend_Log_Writer_Mock - * @throws Zend_Log_Exception + * @return Zend_Log_Writer_Stream */ static public function factory($config) { $config = self::_parseConfig($config); $config = array_merge(array( - 'stream' => null, + 'stream' => null, 'mode' => null, ), $config); - $streamOrUrl = isset($config['url']) ? $config['url'] : $config['stream']; - + $streamOrUrl = isset($config['url']) ? $config['url'] : $config['stream']; + return new self( - $streamOrUrl, + $streamOrUrl, $config['mode'] ); } - + /** * Close the stream resource. * @@ -122,6 +124,7 @@ class Zend_Log_Writer_Stream extends Zend_Log_Writer_Abstract * * @param array $event event data * @return void + * @throws Zend_Log_Exception */ protected function _write($event) { diff --git a/libs/Zend/Log/Writer/Syslog.php b/libs/Zend/Log/Writer/Syslog.php index 722744271b..0ac5a5690a 100644 --- a/libs/Zend/Log/Writer/Syslog.php +++ b/libs/Zend/Log/Writer/Syslog.php @@ -17,9 +17,12 @@ * @subpackage Writer * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Syslog.php 22632 2010-07-18 18:30:08Z ramon $ + * @version $Id: Syslog.php 23576 2010-12-23 23:25:44Z ramon $ */ +/** Zend_Log */ +// require_once 'Zend/Log.php'; + /** Zend_Log_Writer_Abstract */ // require_once 'Zend/Log/Writer/Abstract.php'; @@ -36,6 +39,7 @@ class Zend_Log_Writer_Syslog extends Zend_Log_Writer_Abstract { /** * Maps Zend_Log priorities to PHP's syslog priorities + * * @var array */ protected $_priorities = array( @@ -51,36 +55,41 @@ class Zend_Log_Writer_Syslog extends Zend_Log_Writer_Abstract /** * The default log priority - for unmapped custom priorities + * * @var string */ protected $_defaultPriority = LOG_NOTICE; /** * Last application name set by a syslog-writer instance + * * @var string */ protected static $_lastApplication; /** * Last facility name set by a syslog-writer instance + * * @var string */ protected static $_lastFacility; /** * Application name used by this syslog-writer instance + * * @var string */ protected $_application = 'Zend_Log'; /** * Facility used by this syslog-writer instance + * * @var int */ protected $_facility = LOG_USER; /** - * _validFacilities + * Types of program available to logging of message * * @var array */ @@ -89,7 +98,7 @@ class Zend_Log_Writer_Syslog extends Zend_Log_Writer_Abstract /** * Class constructor * - * @param array $options Array of options; may include "application" and "facility" keys + * @param array $params Array of options; may include "application" and "facility" keys * @return void */ public function __construct(array $params = array()) @@ -100,7 +109,7 @@ class Zend_Log_Writer_Syslog extends Zend_Log_Writer_Abstract $runInitializeSyslog = true; if (isset($params['facility'])) { - $this->_facility = $this->setFacility($params['facility']); + $this->setFacility($params['facility']); $runInitializeSyslog = false; } @@ -114,7 +123,6 @@ class Zend_Log_Writer_Syslog extends Zend_Log_Writer_Abstract * * @param array|Zend_Config $config * @return Zend_Log_Writer_Syslog - * @throws Zend_Log_Exception */ static public function factory($config) { @@ -173,13 +181,13 @@ class Zend_Log_Writer_Syslog extends Zend_Log_Writer_Abstract * Set syslog facility * * @param int $facility Syslog facility - * @return void + * @return Zend_Log_Writer_Syslog * @throws Zend_Log_Exception for invalid log facility */ public function setFacility($facility) { if ($this->_facility === $facility) { - return; + return $this; } if (!count($this->_validFacilities)) { @@ -200,21 +208,23 @@ class Zend_Log_Writer_Syslog extends Zend_Log_Writer_Abstract $this->_facility = $facility; $this->_initializeSyslog(); + return $this; } /** * Set application name * * @param string $application Application name - * @return void + * @return Zend_Log_Writer_Syslog */ public function setApplicationName($application) { if ($this->_application === $application) { - return; + return $this; } $this->_application = $application; $this->_initializeSyslog(); + return $this; } /** @@ -230,7 +240,7 @@ class Zend_Log_Writer_Syslog extends Zend_Log_Writer_Abstract /** * Write a message to syslog. * - * @param array $event event data + * @param array $event event data * @return void */ protected function _write($event) diff --git a/libs/Zend/Log/Writer/ZendMonitor.php b/libs/Zend/Log/Writer/ZendMonitor.php index a6c1843779..1dbf677940 100644 --- a/libs/Zend/Log/Writer/ZendMonitor.php +++ b/libs/Zend/Log/Writer/ZendMonitor.php @@ -17,7 +17,7 @@ * @subpackage Writer * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: ZendMonitor.php 22533 2010-07-07 02:38:14Z ramon $ + * @version $Id: ZendMonitor.php 23576 2010-12-23 23:25:44Z ramon $ */ /** Zend_Log_Writer_Abstract */ @@ -29,32 +29,42 @@ * @subpackage Writer * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: ZendMonitor.php 22533 2010-07-07 02:38:14Z ramon $ + * @version $Id: ZendMonitor.php 23576 2010-12-23 23:25:44Z ramon $ */ class Zend_Log_Writer_ZendMonitor extends Zend_Log_Writer_Abstract { /** * Is Zend Monitor enabled? - * @var bool + * + * @var boolean */ protected $_isEnabled = true; /** - * @throws Zend_Log_Exception if Zend Monitor extension not present + * Is this for a Zend Server intance? + * + * @var boolean + */ + protected $_isZendServer = false; + + /** + * @return void */ public function __construct() { if (!function_exists('monitor_custom_event')) { $this->_isEnabled = false; } + if (function_exists('zend_monitor_custom_event')) { + $this->_isZendServer = true; + } } /** * Create a new instance of Zend_Log_Writer_ZendMonitor * * @param array|Zend_Config $config - * @return Zend_Log_Writer_Syslog - * @throws Zend_Log_Exception + * @return Zend_Log_Writer_ZendMonitor */ static public function factory($config) { @@ -68,7 +78,7 @@ class Zend_Log_Writer_ZendMonitor extends Zend_Log_Writer_Abstract * fail silently. You can query this method to determine if the log * writer is enabled. * - * @return bool + * @return boolean */ public function isEnabled() { @@ -78,7 +88,7 @@ class Zend_Log_Writer_ZendMonitor extends Zend_Log_Writer_Abstract /** * Log a message to this writer. * - * @param array $event log data event + * @param array $event log data event * @return void */ public function write($event) @@ -93,7 +103,7 @@ class Zend_Log_Writer_ZendMonitor extends Zend_Log_Writer_Abstract /** * Write a message to the log. * - * @param array $event log data event + * @param array $event log data event * @return void */ protected function _write($event) @@ -103,7 +113,17 @@ class Zend_Log_Writer_ZendMonitor extends Zend_Log_Writer_Abstract unset($event['priority'], $event['message']); if (!empty($event)) { - monitor_custom_event($priority, $message, false, $event); + if ($this->_isZendServer) { + // On Zend Server; third argument should be the event + zend_monitor_custom_event($priority, $message, $event); + } else { + // On Zend Platform; third argument is severity -- either + // 0 or 1 -- and fourth is optional (event) + // Severity is either 0 (normal) or 1 (severe); classifying + // notice, info, and debug as "normal", and all others as + // "severe" + monitor_custom_event($priority, $message, ($priority > 4) ? 0 : 1, $event); + } } else { monitor_custom_event($priority, $message); } diff --git a/libs/Zend/Mail.php b/libs/Zend/Mail.php index 81d1b5051d..8a1fa7a401 100644 --- a/libs/Zend/Mail.php +++ b/libs/Zend/Mail.php @@ -16,7 +16,7 @@ * @package Zend_Mail * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Mail.php 20783 2010-01-31 08:06:30Z yoshida@zend.co.jp $ + * @version $Id: Mail.php 23251 2010-10-26 12:47:55Z matthew $ */ @@ -77,7 +77,7 @@ class Zend_Mail extends Zend_Mime_Message * Mail character set * @var string */ - protected $_charset = null; + protected $_charset = 'iso-8859-1'; /** * Mail headers @@ -208,11 +208,14 @@ class Zend_Mail extends Zend_Mime_Message /** * Public constructor * - * @param string $charset + * @param string $charset + * @return void */ - public function __construct($charset = 'iso-8859-1') + public function __construct($charset = null) { - $this->_charset = $charset; + if ($charset != null) { + $this->_charset = $charset; + } } /** @@ -535,12 +538,11 @@ class Zend_Mail extends Zend_Mime_Message * Clear header from the message * * @param string $headerName + * @deprecated use public method directly */ protected function _clearHeader($headerName) { - if (isset($this->_headers[$headerName])){ - unset($this->_headers[$headerName]); - } + $this->clearHeader($headerName); } /** @@ -630,6 +632,20 @@ class Zend_Mail extends Zend_Mime_Message } /** + * Clear header from the message + * + * @param string $headerName + * @return Zend_Mail Provides fluent inter + */ + public function clearHeader($headerName) + { + if (isset($this->_headers[$headerName])){ + unset($this->_headers[$headerName]); + } + return $this; + } + + /** * Clears list of recipient email addresses * * @return Zend_Mail Provides fluent interface @@ -639,9 +655,9 @@ class Zend_Mail extends Zend_Mime_Message $this->_recipients = array(); $this->_to = array(); - $this->_clearHeader('To'); - $this->_clearHeader('Cc'); - $this->_clearHeader('Bcc'); + $this->clearHeader('To'); + $this->clearHeader('Cc'); + $this->clearHeader('Bcc'); return $this; } @@ -726,7 +742,7 @@ class Zend_Mail extends Zend_Mime_Message public function clearFrom() { $this->_from = null; - $this->_clearHeader('From'); + $this->clearHeader('From'); return $this; } @@ -739,7 +755,7 @@ class Zend_Mail extends Zend_Mime_Message public function clearReplyTo() { $this->_replyTo = null; - $this->_clearHeader('Reply-To'); + $this->clearHeader('Reply-To'); return $this; } @@ -891,7 +907,7 @@ class Zend_Mail extends Zend_Mime_Message public function clearReturnPath() { $this->_returnPath = null; - $this->_clearHeader('Return-Path'); + $this->clearHeader('Return-Path'); return $this; } @@ -937,7 +953,7 @@ class Zend_Mail extends Zend_Mime_Message public function clearSubject() { $this->_subject = null; - $this->_clearHeader('Subject'); + $this->clearHeader('Subject'); return $this; } @@ -1007,7 +1023,7 @@ class Zend_Mail extends Zend_Mime_Message public function clearDate() { $this->_date = null; - $this->_clearHeader('Date'); + $this->clearHeader('Date'); return $this; } @@ -1065,7 +1081,7 @@ class Zend_Mail extends Zend_Mime_Message public function clearMessageId() { $this->_messageId = null; - $this->_clearHeader('Message-Id'); + $this->clearHeader('Message-Id'); return $this; } diff --git a/libs/Zend/Mail/Protocol/Abstract.php b/libs/Zend/Mail/Protocol/Abstract.php index cbfeaa8946..c9f57806bd 100644 --- a/libs/Zend/Mail/Protocol/Abstract.php +++ b/libs/Zend/Mail/Protocol/Abstract.php @@ -18,7 +18,7 @@ * @subpackage Protocol * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Abstract.php 21635 2010-03-24 15:25:13Z yoshida@zend.co.jp $ + * @version $Id: Abstract.php 23484 2010-12-10 03:57:59Z mjh_ca $ */ @@ -44,7 +44,7 @@ * @subpackage Protocol * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Abstract.php 21635 2010-03-24 15:25:13Z yoshida@zend.co.jp $ + * @version $Id: Abstract.php 23484 2010-12-10 03:57:59Z mjh_ca $ * @todo Implement proxy settings */ abstract class Zend_Mail_Protocol_Abstract @@ -62,8 +62,9 @@ abstract class Zend_Mail_Protocol_Abstract /** * Maximum of the transaction log + * @var integer */ - const MAXIMUM_LOG = 64; + protected $_maximumLog = 64; /** @@ -159,6 +160,28 @@ abstract class Zend_Mail_Protocol_Abstract $this->_disconnect(); } + /** + * Set the maximum log size + * + * @param integer $maximumLog Maximum log size + * @return void + */ + public function setMaximumLog($maximumLog) + { + $this->_maximumLog = (int) $maximumLog; + } + + + /** + * Get the maximum log size + * + * @return int the maximum log size + */ + public function getMaximumLog() + { + return $this->_maximumLog; + } + /** * Create a connection to the remote host @@ -219,7 +242,7 @@ abstract class Zend_Mail_Protocol_Abstract */ protected function _addLog($value) { - if (count($this->_log) >= self::MAXIMUM_LOG) { + if ($this->_maximumLog >= 0 && count($this->_log) >= $this->_maximumLog) { array_shift($this->_log); } @@ -254,7 +277,7 @@ abstract class Zend_Mail_Protocol_Abstract throw new Zend_Mail_Protocol_Exception($errorStr); } - if (($result = stream_set_timeout($this->_socket, self::TIMEOUT_CONNECTION)) === false) { + if (($result = $this->_setStreamTimeout(self::TIMEOUT_CONNECTION)) === false) { /** * @see Zend_Mail_Protocol_Exception */ @@ -334,7 +357,7 @@ abstract class Zend_Mail_Protocol_Abstract // Adapters may wish to supply per-commend timeouts according to appropriate RFC if ($timeout !== null) { - stream_set_timeout($this->_socket, $timeout); + $this->_setStreamTimeout($timeout); } // Retrieve response @@ -405,9 +428,20 @@ abstract class Zend_Mail_Protocol_Abstract * @see Zend_Mail_Protocol_Exception */ // require_once 'Zend/Mail/Protocol/Exception.php'; - throw new Zend_Mail_Protocol_Exception($errMsg); + throw new Zend_Mail_Protocol_Exception($errMsg, $cmd); } return $msg; } + + /** + * Set stream timeout + * + * @param integer $timeout + * @return boolean + */ + protected function _setStreamTimeout($timeout) + { + return stream_set_timeout($this->_socket, $timeout); + } } diff --git a/libs/Zend/Mail/Protocol/Smtp.php b/libs/Zend/Mail/Protocol/Smtp.php index a7d8153fa2..8407c1c8e1 100644 --- a/libs/Zend/Mail/Protocol/Smtp.php +++ b/libs/Zend/Mail/Protocol/Smtp.php @@ -18,7 +18,7 @@ * @subpackage Protocol * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Smtp.php 20096 2010-01-06 02:05:09Z bkarwin $ + * @version $Id: Smtp.php 23476 2010-12-06 20:10:27Z mjh_ca $ */ @@ -327,7 +327,7 @@ class Zend_Mail_Protocol_Smtp extends Zend_Mail_Protocol_Abstract /** - * Issues the RSET command end validates answer + * Issues the RSET command and validates answer * * Can be used to restore a clean smtp communication state when a transaction has been cancelled or commencing a new transaction. * @@ -346,7 +346,7 @@ class Zend_Mail_Protocol_Smtp extends Zend_Mail_Protocol_Abstract /** - * Issues the NOOP command end validates answer + * Issues the NOOP command and validates answer * * Not used by Zend_Mail, could be used to keep a connection alive or check if it is still open. * @@ -360,7 +360,7 @@ class Zend_Mail_Protocol_Smtp extends Zend_Mail_Protocol_Abstract /** - * Issues the VRFY command end validates answer + * Issues the VRFY command and validates answer * * Not used by Zend_Mail. * diff --git a/libs/Zend/Mail/Protocol/Smtp/Auth/Crammd5.php b/libs/Zend/Mail/Protocol/Smtp/Auth/Crammd5.php index 2356422129..146159eb0c 100644 --- a/libs/Zend/Mail/Protocol/Smtp/Auth/Crammd5.php +++ b/libs/Zend/Mail/Protocol/Smtp/Auth/Crammd5.php @@ -17,7 +17,7 @@ * @subpackage Protocol * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Crammd5.php 22655 2010-07-22 18:47:20Z mabe $ + * @version $Id: Crammd5.php 22653 2010-07-22 18:41:39Z mabe $ */ diff --git a/libs/Zend/Mail/Protocol/Smtp/Auth/Plain.php b/libs/Zend/Mail/Protocol/Smtp/Auth/Plain.php index ce5ba241ac..fd97fc6264 100644 --- a/libs/Zend/Mail/Protocol/Smtp/Auth/Plain.php +++ b/libs/Zend/Mail/Protocol/Smtp/Auth/Plain.php @@ -17,7 +17,7 @@ * @subpackage Protocol * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Plain.php 22655 2010-07-22 18:47:20Z mabe $ + * @version $Id: Plain.php 22653 2010-07-22 18:41:39Z mabe $ */ diff --git a/libs/Zend/Mail/Transport/File.php b/libs/Zend/Mail/Transport/File.php new file mode 100644 index 0000000000..0be3d3c8eb --- /dev/null +++ b/libs/Zend/Mail/Transport/File.php @@ -0,0 +1,134 @@ +<?php +/** + * Zend Framework + * + * LICENSE + * + * This source file is subject to the new BSD license that is bundled + * with this package in the file LICENSE.txt. + * It is also available through the world-wide-web at this URL: + * http://framework.zend.com/license/new-bsd + * If you did not receive a copy of the license and are unable to + * obtain it through the world-wide-web, please send an email + * to license@zend.com so we can send you a copy immediately. + * + * @category Zend + * @package Zend_Mail + * @subpackage Transport + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + * @version $Id$ + */ + +/** + * @see Zend_Mail_Transport_Abstract + */ +// require_once 'Zend/Mail/Transport/Abstract.php'; + + +/** + * File transport + * + * Class for saving outgoing emails in filesystem + * + * @category Zend + * @package Zend_Mail + * @subpackage Transport + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ +class Zend_Mail_Transport_File extends Zend_Mail_Transport_Abstract +{ + /** + * Target directory for saving sent email messages + * + * @var string + */ + protected $_path; + + /** + * Callback function generating a file name + * + * @var string|array + */ + protected $_callback; + + /** + * Constructor + * + * @param array|Zend_Config $options OPTIONAL (Default: null) + * @return void + */ + public function __construct($options = null) + { + if ($options instanceof Zend_Config) { + $options = $options->toArray(); + } elseif (!is_array($options)) { + $options = array(); + } + + // Making sure we have some defaults to work with + if (!isset($options['path'])) { + $options['path'] = sys_get_temp_dir(); + } + if (!isset($options['callback'])) { + $options['callback'] = array($this, 'defaultCallback'); + } + + $this->setOptions($options); + } + + /** + * Sets options + * + * @param array $options + * @return void + */ + public function setOptions(array $options) + { + if (isset($options['path'])&& is_dir($options['path'])) { + $this->_path = $options['path']; + } + if (isset($options['callback']) && is_callable($options['callback'])) { + $this->_callback = $options['callback']; + } + } + + /** + * Saves e-mail message to a file + * + * @return void + * @throws Zend_Mail_Transport_Exception on not writable target directory + * @throws Zend_Mail_Transport_Exception on file_put_contents() failure + */ + protected function _sendMail() + { + $file = $this->_path . DIRECTORY_SEPARATOR . call_user_func($this->_callback, $this); + + if (!is_writable(dirname($file))) { + // require_once 'Zend/Mail/Transport/Exception.php'; + throw new Zend_Mail_Transport_Exception(sprintf( + 'Target directory "%s" does not exist or is not writable', + dirname($file) + )); + } + + $email = $this->header . $this->EOL . $this->body; + + if (!file_put_contents($file, $email)) { + // require_once 'Zend/Mail/Transport/Exception.php'; + throw new Zend_Mail_Transport_Exception('Unable to send mail'); + } + } + + /** + * Default callback for generating filenames + * + * @param Zend_Mail_Transport_File File transport instance + * @return string + */ + public function defaultCallback($transport) + { + return 'ZendMail_' . $_SERVER['REQUEST_TIME'] . '_' . mt_rand() . '.tmp'; + } +} diff --git a/libs/Zend/Mail/Transport/Sendmail.php b/libs/Zend/Mail/Transport/Sendmail.php index c12eb46a23..d046b242e6 100644 --- a/libs/Zend/Mail/Transport/Sendmail.php +++ b/libs/Zend/Mail/Transport/Sendmail.php @@ -17,7 +17,7 @@ * @subpackage Transport * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Sendmail.php 21605 2010-03-22 15:09:03Z yoshida@zend.co.jp $ + * @version $Id: Sendmail.php 23484 2010-12-10 03:57:59Z mjh_ca $ */ @@ -74,14 +74,14 @@ class Zend_Mail_Transport_Sendmail extends Zend_Mail_Transport_Abstract */ public function __construct($parameters = null) { - if ($parameters instanceof Zend_Config) { - $parameters = $parameters->toArray(); + if ($parameters instanceof Zend_Config) { + $parameters = $parameters->toArray(); } - if (is_array($parameters)) { + if (is_array($parameters)) { $parameters = implode(' ', $parameters); } - + $this->parameters = $parameters; } @@ -109,7 +109,7 @@ class Zend_Mail_Transport_Sendmail extends Zend_Mail_Transport_Abstract if(!is_string($this->parameters)) { /** * @see Zend_Mail_Transport_Exception - * + * * Exception is thrown here because * $parameters is a public property */ diff --git a/libs/Zend/Mail/Transport/Smtp.php b/libs/Zend/Mail/Transport/Smtp.php index a89f6bcf73..fe956c4312 100644 --- a/libs/Zend/Mail/Transport/Smtp.php +++ b/libs/Zend/Mail/Transport/Smtp.php @@ -17,7 +17,7 @@ * @subpackage Transport * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Smtp.php 20096 2010-01-06 02:05:09Z bkarwin $ + * @version $Id: Smtp.php 23484 2010-12-10 03:57:59Z mjh_ca $ */ @@ -111,7 +111,7 @@ class Zend_Mail_Transport_Smtp extends Zend_Mail_Transport_Abstract * @param string $host OPTIONAL (Default: 127.0.0.1) * @param array|null $config OPTIONAL (Default: null) * @return void - * + * * @todo Someone please make this compatible * with the SendMail transport class. */ @@ -204,7 +204,7 @@ class Zend_Mail_Transport_Smtp extends Zend_Mail_Transport_Abstract } // Set sender email address - $this->_connection->mail($this->_mail->getFrom()); + $this->_connection->mail($this->_mail->getReturnPath()); // Set recipient forward paths foreach ($this->_mail->getRecipients() as $recipient) { diff --git a/libs/Zend/OpenId.php b/libs/Zend/OpenId.php new file mode 100644 index 0000000000..55aa2f966b --- /dev/null +++ b/libs/Zend/OpenId.php @@ -0,0 +1,753 @@ +<?php + +/** + * Zend Framework + * + * LICENSE + * + * This source file is subject to the new BSD license that is bundled + * with this package in the file LICENSE.txt. + * It is also available through the world-wide-web at this URL: + * http://framework.zend.com/license/new-bsd + * If you did not receive a copy of the license and are unable to + * obtain it through the world-wide-web, please send an email + * to license@zend.com so we can send you a copy immediately. + * + * @category Zend + * @package Zend_OpenId + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + * @version $Id: OpenId.php 22653 2010-07-22 18:41:39Z mabe $ + */ + +/** + * @see Zend_Controller_Response_Abstract + */ +// require_once "Zend/Controller/Response/Abstract.php"; + +/** + * Static class that contains common utility functions for + * {@link Zend_OpenId_Consumer} and {@link Zend_OpenId_Provider}. + * + * This class implements common utility functions that are used by both + * Consumer and Provider. They include functions for Diffie-Hellman keys + * generation and exchange, URL normalization, HTTP redirection and some others. + * + * @category Zend + * @package Zend_OpenId + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ +class Zend_OpenId +{ + /** + * Default Diffie-Hellman key generator (1024 bit) + */ + const DH_P = 'dcf93a0b883972ec0e19989ac5a2ce310e1d37717e8d9571bb7623731866e61ef75a2e27898b057f9891c2e27a639c3f29b60814581cd3b2ca3986d2683705577d45c2e7e52dc81c7a171876e5cea74b1448bfdfaf18828efd2519f14e45e3826634af1949e5b535cc829a483b8a76223e5d490a257f05bdff16f2fb22c583ab'; + + /** + * Default Diffie-Hellman prime number (should be 2 or 5) + */ + const DH_G = '02'; + + /** + * OpenID 2.0 namespace. All OpenID 2.0 messages MUST contain variable + * openid.ns with its value. + */ + const NS_2_0 = 'http://specs.openid.net/auth/2.0'; + + /** + * Allows enable/disable stoping execution of PHP script after redirect() + */ + static public $exitOnRedirect = true; + + /** + * Alternative request URL that can be used to override the default + * selfUrl() response + */ + static public $selfUrl = null; + + /** + * Sets alternative request URL that can be used to override the default + * selfUrl() response + * + * @param string $selfUrl the URL to be set + * @return string the old value of overriding URL + */ + static public function setSelfUrl($selfUrl = null) + { + $ret = self::$selfUrl; + self::$selfUrl = $selfUrl; + return $ret; + } + + /** + * Returns a full URL that was requested on current HTTP request. + * + * @return string + */ + static public function selfUrl() + { + if (self::$selfUrl !== null) { + return self::$selfUrl; + } if (isset($_SERVER['SCRIPT_URI'])) { + return $_SERVER['SCRIPT_URI']; + } + $url = ''; + $port = ''; + if (isset($_SERVER['HTTP_HOST'])) { + if (($pos = strpos($_SERVER['HTTP_HOST'], ':')) === false) { + if (isset($_SERVER['SERVER_PORT'])) { + $port = ':' . $_SERVER['SERVER_PORT']; + } + $url = $_SERVER['HTTP_HOST']; + } else { + $url = substr($_SERVER['HTTP_HOST'], 0, $pos); + $port = substr($_SERVER['HTTP_HOST'], $pos); + } + } else if (isset($_SERVER['SERVER_NAME'])) { + $url = $_SERVER['SERVER_NAME']; + if (isset($_SERVER['SERVER_PORT'])) { + $port = ':' . $_SERVER['SERVER_PORT']; + } + } + if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') { + $url = 'https://' . $url; + if ($port == ':443') { + $port = ''; + } + } else { + $url = 'http://' . $url; + if ($port == ':80') { + $port = ''; + } + } + + $url .= $port; + if (isset($_SERVER['HTTP_X_REWRITE_URL'])) { + $url .= $_SERVER['HTTP_X_REWRITE_URL']; + } elseif (isset($_SERVER['REQUEST_URI'])) { + $query = strpos($_SERVER['REQUEST_URI'], '?'); + if ($query === false) { + $url .= $_SERVER['REQUEST_URI']; + } else { + $url .= substr($_SERVER['REQUEST_URI'], 0, $query); + } + } else if (isset($_SERVER['SCRIPT_URL'])) { + $url .= $_SERVER['SCRIPT_URL']; + } else if (isset($_SERVER['REDIRECT_URL'])) { + $url .= $_SERVER['REDIRECT_URL']; + } else if (isset($_SERVER['PHP_SELF'])) { + $url .= $_SERVER['PHP_SELF']; + } else if (isset($_SERVER['SCRIPT_NAME'])) { + $url .= $_SERVER['SCRIPT_NAME']; + if (isset($_SERVER['PATH_INFO'])) { + $url .= $_SERVER['PATH_INFO']; + } + } + return $url; + } + + /** + * Returns an absolute URL for the given one + * + * @param string $url absilute or relative URL + * @return string + */ + static public function absoluteUrl($url) + { + if (empty($url)) { + return Zend_OpenId::selfUrl(); + } else if (!preg_match('|^([^:]+)://|', $url)) { + if (preg_match('|^([^:]+)://([^:@]*(?:[:][^@]*)?@)?([^/:@?#]*)(?:[:]([^/?#]*))?(/[^?]*)?((?:[?](?:[^#]*))?(?:#.*)?)$|', Zend_OpenId::selfUrl(), $reg)) { + $scheme = $reg[1]; + $auth = $reg[2]; + $host = $reg[3]; + $port = $reg[4]; + $path = $reg[5]; + $query = $reg[6]; + if ($url[0] == '/') { + return $scheme + . '://' + . $auth + . $host + . (empty($port) ? '' : (':' . $port)) + . $url; + } else { + $dir = dirname($path); + return $scheme + . '://' + . $auth + . $host + . (empty($port) ? '' : (':' . $port)) + . (strlen($dir) > 1 ? $dir : '') + . '/' + . $url; + } + } + } + return $url; + } + + /** + * Converts variable/value pairs into URL encoded query string + * + * @param array $params variable/value pairs + * @return string URL encoded query string + */ + static public function paramsToQuery($params) + { + foreach($params as $key => $value) { + if (isset($query)) { + $query .= '&' . $key . '=' . urlencode($value); + } else { + $query = $key . '=' . urlencode($value); + } + } + return isset($query) ? $query : ''; + } + + /** + * Normalizes URL according to RFC 3986 to use it in comparison operations. + * The function gets URL argument by reference and modifies it. + * It returns true on success and false of failure. + * + * @param string &$id url to be normalized + * @return bool + */ + static public function normalizeUrl(&$id) + { + // RFC 3986, 6.2.2. Syntax-Based Normalization + + // RFC 3986, 6.2.2.2 Percent-Encoding Normalization + $i = 0; + $n = strlen($id); + $res = ''; + while ($i < $n) { + if ($id[$i] == '%') { + if ($i + 2 >= $n) { + return false; + } + ++$i; + if ($id[$i] >= '0' && $id[$i] <= '9') { + $c = ord($id[$i]) - ord('0'); + } else if ($id[$i] >= 'A' && $id[$i] <= 'F') { + $c = ord($id[$i]) - ord('A') + 10; + } else if ($id[$i] >= 'a' && $id[$i] <= 'f') { + $c = ord($id[$i]) - ord('a') + 10; + } else { + return false; + } + ++$i; + if ($id[$i] >= '0' && $id[$i] <= '9') { + $c = ($c << 4) | (ord($id[$i]) - ord('0')); + } else if ($id[$i] >= 'A' && $id[$i] <= 'F') { + $c = ($c << 4) | (ord($id[$i]) - ord('A') + 10); + } else if ($id[$i] >= 'a' && $id[$i] <= 'f') { + $c = ($c << 4) | (ord($id[$i]) - ord('a') + 10); + } else { + return false; + } + ++$i; + $ch = chr($c); + if (($ch >= 'A' && $ch <= 'Z') || + ($ch >= 'a' && $ch <= 'z') || + $ch == '-' || + $ch == '.' || + $ch == '_' || + $ch == '~') { + $res .= $ch; + } else { + $res .= '%'; + if (($c >> 4) < 10) { + $res .= chr(($c >> 4) + ord('0')); + } else { + $res .= chr(($c >> 4) - 10 + ord('A')); + } + $c = $c & 0xf; + if ($c < 10) { + $res .= chr($c + ord('0')); + } else { + $res .= chr($c - 10 + ord('A')); + } + } + } else { + $res .= $id[$i++]; + } + } + + if (!preg_match('|^([^:]+)://([^:@]*(?:[:][^@]*)?@)?([^/:@?#]*)(?:[:]([^/?#]*))?(/[^?#]*)?((?:[?](?:[^#]*))?)((?:#.*)?)$|', $res, $reg)) { + return false; + } + $scheme = $reg[1]; + $auth = $reg[2]; + $host = $reg[3]; + $port = $reg[4]; + $path = $reg[5]; + $query = $reg[6]; + $fragment = $reg[7]; /* strip it */ + + if (empty($scheme) || empty($host)) { + return false; + } + + // RFC 3986, 6.2.2.1. Case Normalization + $scheme = strtolower($scheme); + $host = strtolower($host); + + // RFC 3986, 6.2.2.3. Path Segment Normalization + if (!empty($path)) { + $i = 0; + $n = strlen($path); + $res = ""; + while ($i < $n) { + if ($path[$i] == '/') { + ++$i; + while ($i < $n && $path[$i] == '/') { + ++$i; + } + if ($i < $n && $path[$i] == '.') { + ++$i; + if ($i < $n && $path[$i] == '.') { + ++$i; + if ($i == $n || $path[$i] == '/') { + if (($pos = strrpos($res, '/')) !== false) { + $res = substr($res, 0, $pos); + } + } else { + $res .= '/..'; + } + } else if ($i != $n && $path[$i] != '/') { + $res .= '/.'; + } + } else { + $res .= '/'; + } + } else { + $res .= $path[$i++]; + } + } + $path = $res; + } + + // RFC 3986,6.2.3. Scheme-Based Normalization + if ($scheme == 'http') { + if ($port == 80) { + $port = ''; + } + } else if ($scheme == 'https') { + if ($port == 443) { + $port = ''; + } + } + if (empty($path)) { + $path = '/'; + } + + $id = $scheme + . '://' + . $auth + . $host + . (empty($port) ? '' : (':' . $port)) + . $path + . $query; + return true; + } + + /** + * Normalizes OpenID identifier that can be URL or XRI name. + * Returns true on success and false of failure. + * + * Normalization is performed according to the following rules: + * 1. If the user's input starts with one of the "xri://", "xri://$ip*", + * or "xri://$dns*" prefixes, they MUST be stripped off, so that XRIs + * are used in the canonical form, and URI-authority XRIs are further + * considered URL identifiers. + * 2. If the first character of the resulting string is an XRI Global + * Context Symbol ("=", "@", "+", "$", "!"), then the input SHOULD be + * treated as an XRI. + * 3. Otherwise, the input SHOULD be treated as an http URL; if it does + * not include a "http" or "https" scheme, the Identifier MUST be + * prefixed with the string "http://". + * 4. URL identifiers MUST then be further normalized by both following + * redirects when retrieving their content and finally applying the + * rules in Section 6 of [RFC3986] to the final destination URL. + * @param string &$id identifier to be normalized + * @return bool + */ + static public function normalize(&$id) + { + $id = trim($id); + if (strlen($id) === 0) { + return true; + } + + // 7.2.1 + if (strpos($id, 'xri://$ip*') === 0) { + $id = substr($id, strlen('xri://$ip*')); + } else if (strpos($id, 'xri://$dns*') === 0) { + $id = substr($id, strlen('xri://$dns*')); + } else if (strpos($id, 'xri://') === 0) { + $id = substr($id, strlen('xri://')); + } + + // 7.2.2 + if ($id[0] == '=' || + $id[0] == '@' || + $id[0] == '+' || + $id[0] == '$' || + $id[0] == '!') { + return true; + } + + // 7.2.3 + if (strpos($id, "://") === false) { + $id = 'http://' . $id; + } + + // 7.2.4 + return self::normalizeURL($id); + } + + /** + * Performs a HTTP redirection to specified URL with additional data. + * It may generate redirected request using GET or POST HTTP method. + * The function never returns. + * + * @param string $url URL to redirect to + * @param array $params additional variable/value pairs to send + * @param Zend_Controller_Response_Abstract $response + * @param string $method redirection method ('GET' or 'POST') + */ + static public function redirect($url, $params = null, + Zend_Controller_Response_Abstract $response = null, $method = 'GET') + { + $url = Zend_OpenId::absoluteUrl($url); + $body = ""; + if (null === $response) { + // require_once "Zend/Controller/Response/Http.php"; + $response = new Zend_Controller_Response_Http(); + } + + if ($method == 'POST') { + $body = "<html><body onLoad=\"document.forms[0].submit();\">\n"; + $body .= "<form method=\"POST\" action=\"$url\">\n"; + if (is_array($params) && count($params) > 0) { + foreach($params as $key => $value) { + $body .= '<input type="hidden" name="' . $key . '" value="' . $value . "\">\n"; + } + } + $body .= "<input type=\"submit\" value=\"Continue OpenID transaction\">\n"; + $body .= "</form></body></html>\n"; + } else if (is_array($params) && count($params) > 0) { + if (strpos($url, '?') === false) { + $url .= '?' . self::paramsToQuery($params); + } else { + $url .= '&' . self::paramsToQuery($params); + } + } + if (!empty($body)) { + $response->setBody($body); + } else if (!$response->canSendHeaders()) { + $response->setBody("<script language=\"JavaScript\"" . + " type=\"text/javascript\">window.location='$url';" . + "</script>"); + } else { + $response->setRedirect($url); + } + $response->sendResponse(); + if (self::$exitOnRedirect) { + exit(); + } + } + + /** + * Produces string of random byte of given length. + * + * @param integer $len length of requested string + * @return string RAW random binary string + */ + static public function randomBytes($len) + { + $key = ''; + for($i=0; $i < $len; $i++) { + $key .= chr(mt_rand(0, 255)); + } + return $key; + } + + /** + * Generates a hash value (message digest) according to given algorithm. + * It returns RAW binary string. + * + * This is a wrapper function that uses one of available internal function + * dependent on given PHP configuration. It may use various functions from + * ext/openssl, ext/hash, ext/mhash or ext/standard. + * + * @param string $func digest algorithm + * @param string $data data to sign + * @return string RAW digital signature + * @throws Zend_OpenId_Exception + */ + static public function digest($func, $data) + { + if (function_exists('openssl_digest')) { + return openssl_digest($data, $func, true); + } else if (function_exists('hash')) { + return hash($func, $data, true); + } else if ($func === 'sha1') { + return sha1($data, true); + } else if ($func === 'sha256') { + if (function_exists('mhash')) { + return mhash(MHASH_SHA256 , $data); + } + } + // require_once "Zend/OpenId/Exception.php"; + throw new Zend_OpenId_Exception( + 'Unsupported digest algorithm "' . $func . '".', + Zend_OpenId_Exception::UNSUPPORTED_DIGEST); + } + + /** + * Generates a keyed hash value using the HMAC method. It uses ext/hash + * if available or user-level PHP implementation, that is not significantly + * slower. + * + * @param string $macFunc name of selected hashing algorithm (sha1, sha256) + * @param string $data data to sign + * @param string $secret shared secret key used for generating the HMAC + * variant of the message digest + * @return string RAW HMAC value + */ + static public function hashHmac($macFunc, $data, $secret) + { +// // require_once "Zend/Crypt/Hmac.php"; +// return Zend_Crypt_Hmac::compute($secret, $macFunc, $data, Zend_Crypt_Hmac::BINARY); + if (function_exists('hash_hmac')) { + return hash_hmac($macFunc, $data, $secret, 1); + } else { + if (Zend_OpenId::strlen($secret) > 64) { + $secret = self::digest($macFunc, $secret); + } + $secret = str_pad($secret, 64, chr(0x00)); + $ipad = str_repeat(chr(0x36), 64); + $opad = str_repeat(chr(0x5c), 64); + $hash1 = self::digest($macFunc, ($secret ^ $ipad) . $data); + return self::digest($macFunc, ($secret ^ $opad) . $hash1); + } + } + + /** + * Converts binary representation into ext/gmp or ext/bcmath big integer + * representation. + * + * @param string $bin binary representation of big number + * @return mixed + * @throws Zend_OpenId_Exception + */ + static protected function binToBigNum($bin) + { + if (extension_loaded('gmp')) { + return gmp_init(bin2hex($bin), 16); + } else if (extension_loaded('bcmath')) { + $bn = 0; + $len = Zend_OpenId::strlen($bin); + for ($i = 0; $i < $len; $i++) { + $bn = bcmul($bn, 256); + $bn = bcadd($bn, ord($bin[$i])); + } + return $bn; + } + // require_once "Zend/OpenId/Exception.php"; + throw new Zend_OpenId_Exception( + 'The system doesn\'t have proper big integer extension', + Zend_OpenId_Exception::UNSUPPORTED_LONG_MATH); + } + + /** + * Converts internal ext/gmp or ext/bcmath big integer representation into + * binary string. + * + * @param mixed $bn big number + * @return string + * @throws Zend_OpenId_Exception + */ + static protected function bigNumToBin($bn) + { + if (extension_loaded('gmp')) { + $s = gmp_strval($bn, 16); + if (strlen($s) % 2 != 0) { + $s = '0' . $s; + } else if ($s[0] > '7') { + $s = '00' . $s; + } + return pack("H*", $s); + } else if (extension_loaded('bcmath')) { + $cmp = bccomp($bn, 0); + if ($cmp == 0) { + return "\0"; + } else if ($cmp < 0) { + // require_once "Zend/OpenId/Exception.php"; + throw new Zend_OpenId_Exception( + 'Big integer arithmetic error', + Zend_OpenId_Exception::ERROR_LONG_MATH); + } + $bin = ""; + while (bccomp($bn, 0) > 0) { + $bin = chr(bcmod($bn, 256)) . $bin; + $bn = bcdiv($bn, 256); + } + if (ord($bin[0]) > 127) { + $bin = "\0" . $bin; + } + return $bin; + } + // require_once "Zend/OpenId/Exception.php"; + throw new Zend_OpenId_Exception( + 'The system doesn\'t have proper big integer extension', + Zend_OpenId_Exception::UNSUPPORTED_LONG_MATH); + } + + /** + * Performs the first step of a Diffie-Hellman key exchange by generating + * private and public DH values based on given prime number $p and + * generator $g. Both sides of key exchange MUST have the same prime number + * and generator. In this case they will able to create a random shared + * secret that is never send from one to the other. + * + * @param string $p prime number in binary representation + * @param string $g generator in binary representation + * @param string $priv_key private key in binary representation + * @return mixed + */ + static public function createDhKey($p, $g, $priv_key = null) + { + if (function_exists('openssl_dh_compute_key')) { + $dh_details = array( + 'p' => $p, + 'g' => $g + ); + if ($priv_key !== null) { + $dh_details['priv_key'] = $priv_key; + } + return openssl_pkey_new(array('dh'=>$dh_details)); + } else { + $bn_p = self::binToBigNum($p); + $bn_g = self::binToBigNum($g); + if ($priv_key === null) { + $priv_key = self::randomBytes(Zend_OpenId::strlen($p)); + } + $bn_priv_key = self::binToBigNum($priv_key); + if (extension_loaded('gmp')) { + $bn_pub_key = gmp_powm($bn_g, $bn_priv_key, $bn_p); + } else if (extension_loaded('bcmath')) { + $bn_pub_key = bcpowmod($bn_g, $bn_priv_key, $bn_p); + } + $pub_key = self::bigNumToBin($bn_pub_key); + + return array( + 'p' => $bn_p, + 'g' => $bn_g, + 'priv_key' => $bn_priv_key, + 'pub_key' => $bn_pub_key, + 'details' => array( + 'p' => $p, + 'g' => $g, + 'priv_key' => $priv_key, + 'pub_key' => $pub_key)); + } + } + + /** + * Returns an associative array with Diffie-Hellman key components in + * binary representation. The array includes original prime number 'p' and + * generator 'g', random private key 'priv_key' and corresponding public + * key 'pub_key'. + * + * @param mixed $dh Diffie-Hellman key + * @return array + */ + static public function getDhKeyDetails($dh) + { + if (function_exists('openssl_dh_compute_key')) { + $details = openssl_pkey_get_details($dh); + if (isset($details['dh'])) { + return $details['dh']; + } + } else { + return $dh['details']; + } + } + + /** + * Computes the shared secret from the private DH value $dh and the other + * party's public value in $pub_key + * + * @param string $pub_key other party's public value + * @param mixed $dh Diffie-Hellman key + * @return string + * @throws Zend_OpenId_Exception + */ + static public function computeDhSecret($pub_key, $dh) + { + if (function_exists('openssl_dh_compute_key')) { + $ret = openssl_dh_compute_key($pub_key, $dh); + if (ord($ret[0]) > 127) { + $ret = "\0" . $ret; + } + return $ret; + } else if (extension_loaded('gmp')) { + $bn_pub_key = self::binToBigNum($pub_key); + $bn_secret = gmp_powm($bn_pub_key, $dh['priv_key'], $dh['p']); + return self::bigNumToBin($bn_secret); + } else if (extension_loaded('bcmath')) { + $bn_pub_key = self::binToBigNum($pub_key); + $bn_secret = bcpowmod($bn_pub_key, $dh['priv_key'], $dh['p']); + return self::bigNumToBin($bn_secret); + } + // require_once "Zend/OpenId/Exception.php"; + throw new Zend_OpenId_Exception( + 'The system doesn\'t have proper big integer extension', + Zend_OpenId_Exception::UNSUPPORTED_LONG_MATH); + } + + /** + * Takes an arbitrary precision integer and returns its shortest big-endian + * two's complement representation. + * + * Arbitrary precision integers MUST be encoded as big-endian signed two's + * complement binary strings. Henceforth, "btwoc" is a function that takes + * an arbitrary precision integer and returns its shortest big-endian two's + * complement representation. All integers that are used with + * Diffie-Hellman Key Exchange are positive. This means that the left-most + * bit of the two's complement representation MUST be zero. If it is not, + * implementations MUST add a zero byte at the front of the string. + * + * @param string $str binary representation of arbitrary precision integer + * @return string big-endian signed representation + */ + static public function btwoc($str) + { + if (ord($str[0]) > 127) { + return "\0" . $str; + } + return $str; + } + + /** + * Returns lenght of binary string in bytes + * + * @param string $str + * @return int the string lenght + */ + static public function strlen($str) + { + if (extension_loaded('mbstring') && + (((int)ini_get('mbstring.func_overload')) & 2)) { + return mb_strlen($str, 'latin1'); + } else { + return strlen($str); + } + } + +} diff --git a/libs/Zend/OpenId/Consumer.php b/libs/Zend/OpenId/Consumer.php new file mode 100644 index 0000000000..ab94200d78 --- /dev/null +++ b/libs/Zend/OpenId/Consumer.php @@ -0,0 +1,958 @@ +<?php + +/** + * Zend Framework + * + * LICENSE + * + * This source file is subject to the new BSD license that is bundled + * with this package in the file LICENSE.txt. + * It is also available through the world-wide-web at this URL: + * http://framework.zend.com/license/new-bsd + * If you did not receive a copy of the license and are unable to + * obtain it through the world-wide-web, please send an email + * to license@zend.com so we can send you a copy immediately. + * + * @category Zend + * @package Zend_OpenId + * @subpackage Zend_OpenId_Consumer + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + * @version $Id: Consumer.php 20096 2010-01-06 02:05:09Z bkarwin $ + */ + +/** + * @see Zend_OpenId + */ +// require_once "Zend/OpenId.php"; + +/** + * @see Zend_OpenId_Extension + */ +// require_once "Zend/OpenId/Extension.php"; + +/** + * @see Zend_OpenId_Consumer_Storage + */ +// require_once "Zend/OpenId/Consumer/Storage.php"; + +/** + * @see Zend_Http_Client + */ +// require_once 'Zend/Http/Client.php'; + +/** + * OpenID consumer implementation + * + * @category Zend + * @package Zend_OpenId + * @subpackage Zend_OpenId_Consumer + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ +class Zend_OpenId_Consumer +{ + + /** + * Reference to an implementation of storage object + * + * @var Zend_OpenId_Consumer_Storage $_storage + */ + protected $_storage = null; + + /** + * Enables or disables consumer to use association with server based on + * Diffie-Hellman key agreement + * + * @var Zend_OpenId_Consumer_Storage $_dumbMode + */ + protected $_dumbMode = false; + + /** + * Internal cache to prevent unnecessary access to storage + * + * @var array $_cache + */ + protected $_cache = array(); + + /** + * HTTP client to make HTTP requests + * + * @var Zend_Http_Client $_httpClient + */ + private $_httpClient = null; + + /** + * HTTP session to store climed_id between requests + * + * @var Zend_Session_Namespace $_session + */ + private $_session = null; + + /** + * Last error message for logi, check or verify failure + * + * @var string $_error + */ + private $_error = ''; + + /** + * Constructs a Zend_OpenId_Consumer object with given $storage. + * Enables or disables future association with server based on + * Diffie-Hellman key agreement. + * + * @param Zend_OpenId_Consumer_Storage $storage implementation of custom + * storage object + * @param bool $dumbMode Enables or disables consumer to use association + * with server based on Diffie-Hellman key agreement + */ + public function __construct(Zend_OpenId_Consumer_Storage $storage = null, + $dumbMode = false) + { + if ($storage === null) { + // require_once "Zend/OpenId/Consumer/Storage/File.php"; + $this->_storage = new Zend_OpenId_Consumer_Storage_File(); + } else { + $this->_storage = $storage; + } + $this->_dumbMode = $dumbMode; + } + + /** + * Performs check (with possible user interaction) of OpenID identity. + * + * This is the first step of OpenID authentication process. + * On success the function does not return (it does HTTP redirection to + * server and exits). On failure it returns false. + * + * @param string $id OpenID identity + * @param string $returnTo URL to redirect response from server to + * @param string $root HTTP URL to identify consumer on server + * @param mixed $extensions extension object or array of extensions objects + * @param Zend_Controller_Response_Abstract $response an optional response + * object to perform HTTP or HTML form redirection + * @return bool + */ + public function login($id, $returnTo = null, $root = null, $extensions = null, + Zend_Controller_Response_Abstract $response = null) + { + return $this->_checkId( + false, + $id, + $returnTo, + $root, + $extensions, + $response); + } + + /** + * Performs immediate check (without user interaction) of OpenID identity. + * + * This is the first step of OpenID authentication process. + * On success the function does not return (it does HTTP redirection to + * server and exits). On failure it returns false. + * + * @param string $id OpenID identity + * @param string $returnTo HTTP URL to redirect response from server to + * @param string $root HTTP URL to identify consumer on server + * @param mixed $extensions extension object or array of extensions objects + * @param Zend_Controller_Response_Abstract $response an optional response + * object to perform HTTP or HTML form redirection + * @return bool + */ + public function check($id, $returnTo=null, $root=null, $extensions = null, + Zend_Controller_Response_Abstract $response = null) + + { + return $this->_checkId( + true, + $id, + $returnTo, + $root, + $extensions, + $response); + } + + /** + * Verifies authentication response from OpenID server. + * + * This is the second step of OpenID authentication process. + * The function returns true on successful authentication and false on + * failure. + * + * @param array $params HTTP query data from OpenID server + * @param string &$identity this argument is set to end-user's claimed + * identifier or OpenID provider local identifier. + * @param mixed $extensions extension object or array of extensions objects + * @return bool + */ + public function verify($params, &$identity = "", $extensions = null) + { + $this->_setError(''); + + $version = 1.1; + if (isset($params['openid_ns']) && + $params['openid_ns'] == Zend_OpenId::NS_2_0) { + $version = 2.0; + } + + if (isset($params["openid_claimed_id"])) { + $identity = $params["openid_claimed_id"]; + } else if (isset($params["openid_identity"])){ + $identity = $params["openid_identity"]; + } else { + $identity = ""; + } + + if ($version < 2.0 && !isset($params["openid_claimed_id"])) { + if ($this->_session !== null) { + if ($this->_session->identity === $identity) { + $identity = $this->_session->claimed_id; + } + } else if (defined('SID')) { + if (isset($_SESSION["zend_openid"]["identity"]) && + isset($_SESSION["zend_openid"]["claimed_id"]) && + $_SESSION["zend_openid"]["identity"] === $identity) { + $identity = $_SESSION["zend_openid"]["claimed_id"]; + } + } else { + // require_once "Zend/Session/Namespace.php"; + $this->_session = new Zend_Session_Namespace("zend_openid"); + if ($this->_session->identity === $identity) { + $identity = $this->_session->claimed_id; + } + } + } + + if (empty($params['openid_mode'])) { + $this->_setError("Missing openid.mode"); + return false; + } + if (empty($params['openid_return_to'])) { + $this->_setError("Missing openid.return_to"); + return false; + } + if (empty($params['openid_signed'])) { + $this->_setError("Missing openid.signed"); + return false; + } + if (empty($params['openid_sig'])) { + $this->_setError("Missing openid.sig"); + return false; + } + if ($params['openid_mode'] != 'id_res') { + $this->_setError("Wrong openid.mode '".$params['openid_mode']."' != 'id_res'"); + return false; + } + if (empty($params['openid_assoc_handle'])) { + $this->_setError("Missing openid.assoc_handle"); + return false; + } + if ($params['openid_return_to'] != Zend_OpenId::selfUrl()) { + /* Ignore query part in openid.return_to */ + $pos = strpos($params['openid_return_to'], '?'); + if ($pos === false || + SUBSTR($params['openid_return_to'], 0 , $pos) != Zend_OpenId::selfUrl()) { + + $this->_setError("Wrong openid.return_to '". + $params['openid_return_to']."' != '" . Zend_OpenId::selfUrl() ."'"); + return false; + } + } + + if ($version >= 2.0) { + if (empty($params['openid_response_nonce'])) { + $this->_setError("Missing openid.response_nonce"); + return false; + } + if (empty($params['openid_op_endpoint'])) { + $this->_setError("Missing openid.op_endpoint"); + return false; + /* OpenID 2.0 (11.3) Checking the Nonce */ + } else if (!$this->_storage->isUniqueNonce($params['openid_op_endpoint'], $params['openid_response_nonce'])) { + $this->_setError("Duplicate openid.response_nonce"); + return false; + } + } + + + if (!empty($params['openid_invalidate_handle'])) { + if ($this->_storage->getAssociationByHandle( + $params['openid_invalidate_handle'], + $url, + $macFunc, + $secret, + $expires)) { + $this->_storage->delAssociation($url); + } + } + + if ($this->_storage->getAssociationByHandle( + $params['openid_assoc_handle'], + $url, + $macFunc, + $secret, + $expires)) { + $signed = explode(',', $params['openid_signed']); + $data = ''; + foreach ($signed as $key) { + $data .= $key . ':' . $params['openid_' . strtr($key,'.','_')] . "\n"; + } + if (base64_decode($params['openid_sig']) == + Zend_OpenId::hashHmac($macFunc, $data, $secret)) { + if (!Zend_OpenId_Extension::forAll($extensions, 'parseResponse', $params)) { + $this->_setError("Extension::parseResponse failure"); + return false; + } + /* OpenID 2.0 (11.2) Verifying Discovered Information */ + if (isset($params['openid_claimed_id'])) { + $id = $params['openid_claimed_id']; + if (!Zend_OpenId::normalize($id)) { + $this->_setError("Normalization failed"); + return false; + } else if (!$this->_discovery($id, $discovered_server, $discovered_version)) { + $this->_setError("Discovery failed: " . $this->getError()); + return false; + } else if ((!empty($params['openid_identity']) && + $params["openid_identity"] != $id) || + (!empty($params['openid_op_endpoint']) && + $params['openid_op_endpoint'] != $discovered_server) || + $discovered_version != $version) { + $this->_setError("Discovery information verification failed"); + return false; + } + } + return true; + } + $this->_storage->delAssociation($url); + $this->_setError("Signature check failed"); + return false; + } + else + { + /* Use dumb mode */ + if (isset($params['openid_claimed_id'])) { + $id = $params['openid_claimed_id']; + } else if (isset($params['openid_identity'])) { + $id = $params['openid_identity']; + } else { + $this->_setError("Missing openid.claimed_id and openid.identity"); + return false; + } + + if (!Zend_OpenId::normalize($id)) { + $this->_setError("Normalization failed"); + return false; + } else if (!$this->_discovery($id, $server, $discovered_version)) { + $this->_setError("Discovery failed: " . $this->getError()); + return false; + } + + /* OpenID 2.0 (11.2) Verifying Discovered Information */ + if ((isset($params['openid_identity']) && + $params["openid_identity"] != $id) || + (isset($params['openid_op_endpoint']) && + $params['openid_op_endpoint'] != $server) || + $discovered_version != $version) { + $this->_setError("Discovery information verification failed"); + return false; + } + + $params2 = array(); + foreach ($params as $key => $val) { + if (strpos($key, 'openid_ns_') === 0) { + $key = 'openid.ns.' . substr($key, strlen('openid_ns_')); + } else if (strpos($key, 'openid_sreg_') === 0) { + $key = 'openid.sreg.' . substr($key, strlen('openid_sreg_')); + } else if (strpos($key, 'openid_') === 0) { + $key = 'openid.' . substr($key, strlen('openid_')); + } + $params2[$key] = $val; + } + $params2['openid.mode'] = 'check_authentication'; + $ret = $this->_httpRequest($server, 'POST', $params2, $status); + if ($status != 200) { + $this->_setError("'Dumb' signature verification HTTP request failed"); + return false; + } + $r = array(); + if (is_string($ret)) { + foreach(explode("\n", $ret) as $line) { + $line = trim($line); + if (!empty($line)) { + $x = explode(':', $line, 2); + if (is_array($x) && count($x) == 2) { + list($key, $value) = $x; + $r[trim($key)] = trim($value); + } + } + } + } + $ret = $r; + if (!empty($ret['invalidate_handle'])) { + if ($this->_storage->getAssociationByHandle( + $ret['invalidate_handle'], + $url, + $macFunc, + $secret, + $expires)) { + $this->_storage->delAssociation($url); + } + } + if (isset($ret['is_valid']) && $ret['is_valid'] == 'true') { + if (!Zend_OpenId_Extension::forAll($extensions, 'parseResponse', $params)) { + $this->_setError("Extension::parseResponse failure"); + return false; + } + return true; + } + $this->_setError("'Dumb' signature verification failed"); + return false; + } + } + + /** + * Store assiciation in internal chace and external storage + * + * @param string $url OpenID server url + * @param string $handle association handle + * @param string $macFunc HMAC function (sha1 or sha256) + * @param string $secret shared secret + * @param integer $expires expiration UNIX time + * @return void + */ + protected function _addAssociation($url, $handle, $macFunc, $secret, $expires) + { + $this->_cache[$url] = array($handle, $macFunc, $secret, $expires); + return $this->_storage->addAssociation( + $url, + $handle, + $macFunc, + $secret, + $expires); + } + + /** + * Retrive assiciation information for given $url from internal cahce or + * external storage + * + * @param string $url OpenID server url + * @param string &$handle association handle + * @param string &$macFunc HMAC function (sha1 or sha256) + * @param string &$secret shared secret + * @param integer &$expires expiration UNIX time + * @return void + */ + protected function _getAssociation($url, &$handle, &$macFunc, &$secret, &$expires) + { + if (isset($this->_cache[$url])) { + $handle = $this->_cache[$url][0]; + $macFunc = $this->_cache[$url][1]; + $secret = $this->_cache[$url][2]; + $expires = $this->_cache[$url][3]; + return true; + } + if ($this->_storage->getAssociation( + $url, + $handle, + $macFunc, + $secret, + $expires)) { + $this->_cache[$url] = array($handle, $macFunc, $secret, $expires); + return true; + } + return false; + } + + /** + * Performs HTTP request to given $url using given HTTP $method. + * Send additinal query specified by variable/value array, + * On success returns HTTP response without headers, false on failure. + * + * @param string $url OpenID server url + * @param string $method HTTP request method 'GET' or 'POST' + * @param array $params additional qwery parameters to be passed with + * @param int &$staus HTTP status code + * request + * @return mixed + */ + protected function _httpRequest($url, $method = 'GET', array $params = array(), &$status = null) + { + $client = $this->_httpClient; + if ($client === null) { + $client = new Zend_Http_Client( + $url, + array( + 'maxredirects' => 4, + 'timeout' => 15, + 'useragent' => 'Zend_OpenId' + ) + ); + } else { + $client->setUri($url); + } + + $client->resetParameters(); + if ($method == 'POST') { + $client->setMethod(Zend_Http_Client::POST); + $client->setParameterPost($params); + } else { + $client->setMethod(Zend_Http_Client::GET); + $client->setParameterGet($params); + } + + try { + $response = $client->request(); + } catch (Exception $e) { + $this->_setError('HTTP Request failed: ' . $e->getMessage()); + return false; + } + $status = $response->getStatus(); + $body = $response->getBody(); + if ($status == 200 || ($status == 400 && !empty($body))) { + return $body; + }else{ + $this->_setError('Bad HTTP response'); + return false; + } + } + + /** + * Create (or reuse existing) association between OpenID consumer and + * OpenID server based on Diffie-Hellman key agreement. Returns true + * on success and false on failure. + * + * @param string $url OpenID server url + * @param float $version OpenID protocol version + * @param string $priv_key for testing only + * @return bool + */ + protected function _associate($url, $version, $priv_key=null) + { + + /* Check if we already have association in chace or storage */ + if ($this->_getAssociation( + $url, + $handle, + $macFunc, + $secret, + $expires)) { + return true; + } + + if ($this->_dumbMode) { + /* Use dumb mode */ + return true; + } + + $params = array(); + + if ($version >= 2.0) { + $params = array( + 'openid.ns' => Zend_OpenId::NS_2_0, + 'openid.mode' => 'associate', + 'openid.assoc_type' => 'HMAC-SHA256', + 'openid.session_type' => 'DH-SHA256', + ); + } else { + $params = array( + 'openid.mode' => 'associate', + 'openid.assoc_type' => 'HMAC-SHA1', + 'openid.session_type' => 'DH-SHA1', + ); + } + + $dh = Zend_OpenId::createDhKey(pack('H*', Zend_OpenId::DH_P), + pack('H*', Zend_OpenId::DH_G), + $priv_key); + $dh_details = Zend_OpenId::getDhKeyDetails($dh); + + $params['openid.dh_modulus'] = base64_encode( + Zend_OpenId::btwoc($dh_details['p'])); + $params['openid.dh_gen'] = base64_encode( + Zend_OpenId::btwoc($dh_details['g'])); + $params['openid.dh_consumer_public'] = base64_encode( + Zend_OpenId::btwoc($dh_details['pub_key'])); + + while(1) { + $ret = $this->_httpRequest($url, 'POST', $params, $status); + if ($ret === false) { + $this->_setError("HTTP request failed"); + return false; + } + + $r = array(); + $bad_response = false; + foreach(explode("\n", $ret) as $line) { + $line = trim($line); + if (!empty($line)) { + $x = explode(':', $line, 2); + if (is_array($x) && count($x) == 2) { + list($key, $value) = $x; + $r[trim($key)] = trim($value); + } else { + $bad_response = true; + } + } + } + if ($bad_response && strpos($ret, 'Unknown session type') !== false) { + $r['error_code'] = 'unsupported-type'; + } + $ret = $r; + + if (isset($ret['error_code']) && + $ret['error_code'] == 'unsupported-type') { + if ($params['openid.session_type'] == 'DH-SHA256') { + $params['openid.session_type'] = 'DH-SHA1'; + $params['openid.assoc_type'] = 'HMAC-SHA1'; + } else if ($params['openid.session_type'] == 'DH-SHA1') { + $params['openid.session_type'] = 'no-encryption'; + } else { + $this->_setError("The OpenID service responded with: " . $ret['error_code']); + return false; + } + } else { + break; + } + } + + if ($status != 200) { + $this->_setError("The server responded with status code: " . $status); + return false; + } + + if ($version >= 2.0 && + isset($ret['ns']) && + $ret['ns'] != Zend_OpenId::NS_2_0) { + $this->_setError("Wrong namespace definition in the server response"); + return false; + } + + if (!isset($ret['assoc_handle']) || + !isset($ret['expires_in']) || + !isset($ret['assoc_type']) || + $params['openid.assoc_type'] != $ret['assoc_type']) { + if ($params['openid.assoc_type'] != $ret['assoc_type']) { + $this->_setError("The returned assoc_type differed from the supplied openid.assoc_type"); + } else { + $this->_setError("Missing required data from provider (assoc_handle, expires_in, assoc_type are required)"); + } + return false; + } + + $handle = $ret['assoc_handle']; + $expiresIn = $ret['expires_in']; + + if ($ret['assoc_type'] == 'HMAC-SHA1') { + $macFunc = 'sha1'; + } else if ($ret['assoc_type'] == 'HMAC-SHA256' && + $version >= 2.0) { + $macFunc = 'sha256'; + } else { + $this->_setError("Unsupported assoc_type"); + return false; + } + + if ((empty($ret['session_type']) || + ($version >= 2.0 && $ret['session_type'] == 'no-encryption')) && + isset($ret['mac_key'])) { + $secret = base64_decode($ret['mac_key']); + } else if (isset($ret['session_type']) && + $ret['session_type'] == 'DH-SHA1' && + !empty($ret['dh_server_public']) && + !empty($ret['enc_mac_key'])) { + $dhFunc = 'sha1'; + } else if (isset($ret['session_type']) && + $ret['session_type'] == 'DH-SHA256' && + $version >= 2.0 && + !empty($ret['dh_server_public']) && + !empty($ret['enc_mac_key'])) { + $dhFunc = 'sha256'; + } else { + $this->_setError("Unsupported session_type"); + return false; + } + if (isset($dhFunc)) { + $serverPub = base64_decode($ret['dh_server_public']); + $dhSec = Zend_OpenId::computeDhSecret($serverPub, $dh); + if ($dhSec === false) { + $this->_setError("DH secret comutation failed"); + return false; + } + $sec = Zend_OpenId::digest($dhFunc, $dhSec); + if ($sec === false) { + $this->_setError("Could not create digest"); + return false; + } + $secret = $sec ^ base64_decode($ret['enc_mac_key']); + } + if ($macFunc == 'sha1') { + if (Zend_OpenId::strlen($secret) != 20) { + $this->_setError("The length of the sha1 secret must be 20"); + return false; + } + } else if ($macFunc == 'sha256') { + if (Zend_OpenId::strlen($secret) != 32) { + $this->_setError("The length of the sha256 secret must be 32"); + return false; + } + } + $this->_addAssociation( + $url, + $handle, + $macFunc, + $secret, + time() + $expiresIn); + return true; + } + + /** + * Performs discovery of identity and finds OpenID URL, OpenID server URL + * and OpenID protocol version. Returns true on succees and false on + * failure. + * + * @param string &$id OpenID identity URL + * @param string &$server OpenID server URL + * @param float &$version OpenID protocol version + * @return bool + * @todo OpenID 2.0 (7.3) XRI and Yadis discovery + */ + protected function _discovery(&$id, &$server, &$version) + { + $realId = $id; + if ($this->_storage->getDiscoveryInfo( + $id, + $realId, + $server, + $version, + $expire)) { + $id = $realId; + return true; + } + + /* TODO: OpenID 2.0 (7.3) XRI and Yadis discovery */ + + /* HTML-based discovery */ + $response = $this->_httpRequest($id, 'GET', array(), $status); + if ($status != 200 || !is_string($response)) { + return false; + } + if (preg_match( + '/<link[^>]*rel=(["\'])[ \t]*(?:[^ \t"\']+[ \t]+)*?openid2.provider[ \t]*[^"\']*\\1[^>]*href=(["\'])([^"\']+)\\2[^>]*\/?>/i', + $response, + $r)) { + $version = 2.0; + $server = $r[3]; + } else if (preg_match( + '/<link[^>]*href=(["\'])([^"\']+)\\1[^>]*rel=(["\'])[ \t]*(?:[^ \t"\']+[ \t]+)*?openid2.provider[ \t]*[^"\']*\\3[^>]*\/?>/i', + $response, + $r)) { + $version = 2.0; + $server = $r[2]; + } else if (preg_match( + '/<link[^>]*rel=(["\'])[ \t]*(?:[^ \t"\']+[ \t]+)*?openid.server[ \t]*[^"\']*\\1[^>]*href=(["\'])([^"\']+)\\2[^>]*\/?>/i', + $response, + $r)) { + $version = 1.1; + $server = $r[3]; + } else if (preg_match( + '/<link[^>]*href=(["\'])([^"\']+)\\1[^>]*rel=(["\'])[ \t]*(?:[^ \t"\']+[ \t]+)*?openid.server[ \t]*[^"\']*\\3[^>]*\/?>/i', + $response, + $r)) { + $version = 1.1; + $server = $r[2]; + } else { + return false; + } + if ($version >= 2.0) { + if (preg_match( + '/<link[^>]*rel=(["\'])[ \t]*(?:[^ \t"\']+[ \t]+)*?openid2.local_id[ \t]*[^"\']*\\1[^>]*href=(["\'])([^"\']+)\\2[^>]*\/?>/i', + $response, + $r)) { + $realId = $r[3]; + } else if (preg_match( + '/<link[^>]*href=(["\'])([^"\']+)\\1[^>]*rel=(["\'])[ \t]*(?:[^ \t"\']+[ \t]+)*?openid2.local_id[ \t]*[^"\']*\\3[^>]*\/?>/i', + $response, + $r)) { + $realId = $r[2]; + } + } else { + if (preg_match( + '/<link[^>]*rel=(["\'])[ \t]*(?:[^ \t"\']+[ \t]+)*?openid.delegate[ \t]*[^"\']*\\1[^>]*href=(["\'])([^"\']+)\\2[^>]*\/?>/i', + $response, + $r)) { + $realId = $r[3]; + } else if (preg_match( + '/<link[^>]*href=(["\'])([^"\']+)\\1[^>]*rel=(["\'])[ \t]*(?:[^ \t"\']+[ \t]+)*?openid.delegate[ \t]*[^"\']*\\3[^>]*\/?>/i', + $response, + $r)) { + $realId = $r[2]; + } + } + + $expire = time() + 60 * 60; + $this->_storage->addDiscoveryInfo($id, $realId, $server, $version, $expire); + $id = $realId; + return true; + } + + /** + * Performs check of OpenID identity. + * + * This is the first step of OpenID authentication process. + * On success the function does not return (it does HTTP redirection to + * server and exits). On failure it returns false. + * + * @param bool $immediate enables or disables interaction with user + * @param string $id OpenID identity + * @param string $returnTo HTTP URL to redirect response from server to + * @param string $root HTTP URL to identify consumer on server + * @param mixed $extensions extension object or array of extensions objects + * @param Zend_Controller_Response_Abstract $response an optional response + * object to perform HTTP or HTML form redirection + * @return bool + */ + protected function _checkId($immediate, $id, $returnTo=null, $root=null, + $extensions=null, Zend_Controller_Response_Abstract $response = null) + { + $this->_setError(''); + + if (!Zend_OpenId::normalize($id)) { + $this->_setError("Normalisation failed"); + return false; + } + $claimedId = $id; + + if (!$this->_discovery($id, $server, $version)) { + $this->_setError("Discovery failed: " . $this->getError()); + return false; + } + if (!$this->_associate($server, $version)) { + $this->_setError("Association failed: " . $this->getError()); + return false; + } + if (!$this->_getAssociation( + $server, + $handle, + $macFunc, + $secret, + $expires)) { + /* Use dumb mode */ + unset($handle); + unset($macFunc); + unset($secret); + unset($expires); + } + + $params = array(); + if ($version >= 2.0) { + $params['openid.ns'] = Zend_OpenId::NS_2_0; + } + + $params['openid.mode'] = $immediate ? + 'checkid_immediate' : 'checkid_setup'; + + $params['openid.identity'] = $id; + + $params['openid.claimed_id'] = $claimedId; + + if ($version <= 2.0) { + if ($this->_session !== null) { + $this->_session->identity = $id; + $this->_session->claimed_id = $claimedId; + } else if (defined('SID')) { + $_SESSION["zend_openid"] = array( + "identity" => $id, + "claimed_id" => $claimedId); + } else { + // require_once "Zend/Session/Namespace.php"; + $this->_session = new Zend_Session_Namespace("zend_openid"); + $this->_session->identity = $id; + $this->_session->claimed_id = $claimedId; + } + } + + if (isset($handle)) { + $params['openid.assoc_handle'] = $handle; + } + + $params['openid.return_to'] = Zend_OpenId::absoluteUrl($returnTo); + + if (empty($root)) { + $root = Zend_OpenId::selfUrl(); + if ($root[strlen($root)-1] != '/') { + $root = dirname($root); + } + } + if ($version >= 2.0) { + $params['openid.realm'] = $root; + } else { + $params['openid.trust_root'] = $root; + } + + if (!Zend_OpenId_Extension::forAll($extensions, 'prepareRequest', $params)) { + $this->_setError("Extension::prepareRequest failure"); + return false; + } + + Zend_OpenId::redirect($server, $params, $response); + return true; + } + + /** + * Sets HTTP client object to make HTTP requests + * + * @param Zend_Http_Client $client HTTP client object to be used + */ + public function setHttpClient($client) { + $this->_httpClient = $client; + } + + /** + * Returns HTTP client object that will be used to make HTTP requests + * + * @return Zend_Http_Client + */ + public function getHttpClient() { + return $this->_httpClient; + } + + /** + * Sets session object to store climed_id + * + * @param Zend_Session_Namespace $session HTTP client object to be used + */ + public function setSession(Zend_Session_Namespace $session) { + $this->_session = $session; + } + + /** + * Returns session object that is used to store climed_id + * + * @return Zend_Session_Namespace + */ + public function getSession() { + return $this->_session; + } + + /** + * Saves error message + * + * @param string $message error message + */ + protected function _setError($message) + { + $this->_error = $message; + } + + /** + * Returns error message that explains failure of login, check or verify + * + * @return string + */ + public function getError() + { + return $this->_error; + } + +} diff --git a/libs/Zend/OpenId/Consumer/Storage.php b/libs/Zend/OpenId/Consumer/Storage.php new file mode 100644 index 0000000000..91b8bb0100 --- /dev/null +++ b/libs/Zend/OpenId/Consumer/Storage.php @@ -0,0 +1,132 @@ +<?php + +/** + * Zend Framework + * + * LICENSE + * + * This source file is subject to the new BSD license that is bundled + * with this package in the file LICENSE.txt. + * It is also available through the world-wide-web at this URL: + * http://framework.zend.com/license/new-bsd + * If you did not receive a copy of the license and are unable to + * obtain it through the world-wide-web, please send an email + * to license@zend.com so we can send you a copy immediately. + * + * @category Zend + * @package Zend_OpenId + * @subpackage Zend_OpenId_Consumer + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + * @version $Id: Storage.php 20096 2010-01-06 02:05:09Z bkarwin $ + */ + +/** + * Abstract class to implement external storage for OpenID consumer + * + * @category Zend + * @package Zend_OpenId + * @subpackage Zend_OpenId_Consumer + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ +abstract class Zend_OpenId_Consumer_Storage +{ + + /** + * Stores information about association identified by $url/$handle + * + * @param string $url OpenID server URL + * @param string $handle assiciation handle + * @param string $macFunc HMAC function (sha1 or sha256) + * @param string $secret shared secret + * @param long $expires expiration UNIX time + * @return void + */ + abstract public function addAssociation($url, $handle, $macFunc, $secret, $expires); + + /** + * Gets information about association identified by $url + * Returns true if given association found and not expired and false + * otherwise + * + * @param string $url OpenID server URL + * @param string &$handle assiciation handle + * @param string &$macFunc HMAC function (sha1 or sha256) + * @param string &$secret shared secret + * @param long &$expires expiration UNIX time + * @return bool + */ + abstract public function getAssociation($url, &$handle, &$macFunc, &$secret, &$expires); + + /** + * Gets information about association identified by $handle + * Returns true if given association found and not expired and false + * othverwise + * + * @param string $handle assiciation handle + * @param string &$url OpenID server URL + * @param string &$macFunc HMAC function (sha1 or sha256) + * @param string &$secret shared secret + * @param long &$expires expiration UNIX time + * @return bool + */ + abstract public function getAssociationByHandle($handle, &$url, &$macFunc, &$secret, &$expires); + + /** + * Deletes association identified by $url + * + * @param string $url OpenID server URL + * @return void + */ + abstract public function delAssociation($url); + + /** + * Stores information discovered from identity $id + * + * @param string $id identity + * @param string $realId discovered real identity URL + * @param string $server discovered OpenID server URL + * @param float $version discovered OpenID protocol version + * @param long $expires expiration UNIX time + * @return void + */ + abstract public function addDiscoveryInfo($id, $realId, $server, $version, $expires); + + /** + * Gets information discovered from identity $id + * Returns true if such information exists and false otherwise + * + * @param string $id identity + * @param string &$realId discovered real identity URL + * @param string &$server discovered OpenID server URL + * @param float &$version discovered OpenID protocol version + * @param long &$expires expiration UNIX time + * @return bool + */ + abstract public function getDiscoveryInfo($id, &$realId, &$server, &$version, &$expires); + + /** + * Removes cached information discovered from identity $id + * + * @param string $id identity + * @return bool + */ + abstract public function delDiscoveryInfo($id); + + /** + * The function checks the uniqueness of openid.response_nonce + * + * @param string $provider openid.openid_op_endpoint field from authentication response + * @param string $nonce openid.response_nonce field from authentication response + * @return bool + */ + abstract public function isUniqueNonce($provider, $nonce); + + /** + * Removes data from the uniqueness database that is older then given date + * + * @param string $date Date of expired data + */ + abstract public function purgeNonces($date=null); +} diff --git a/libs/Zend/OpenId/Consumer/Storage/File.php b/libs/Zend/OpenId/Consumer/Storage/File.php new file mode 100644 index 0000000000..2ed751bca5 --- /dev/null +++ b/libs/Zend/OpenId/Consumer/Storage/File.php @@ -0,0 +1,511 @@ +<?php + +/** + * Zend Framework + * + * LICENSE + * + * This source file is subject to the new BSD license that is bundled + * with this package in the file LICENSE.txt. + * It is also available through the world-wide-web at this URL: + * http://framework.zend.com/license/new-bsd + * If you did not receive a copy of the license and are unable to + * obtain it through the world-wide-web, please send an email + * to license@zend.com so we can send you a copy immediately. + * + * @category Zend + * @package Zend_OpenId + * @subpackage Zend_OpenId_Consumer + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + * @version $Id: File.php 23161 2010-10-19 16:08:36Z matthew $ + */ + +/** + * @see Zend_OpenId_Consumer_Storage + */ +// require_once "Zend/OpenId/Consumer/Storage.php"; + +/** + * External storage implemmentation using serialized files + * + * @category Zend + * @package Zend_OpenId + * @subpackage Zend_OpenId_Consumer + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ +class Zend_OpenId_Consumer_Storage_File extends Zend_OpenId_Consumer_Storage +{ + + /** + * Directory name to store data files in + * + * @var string $_dir + */ + private $_dir; + + /** + * Constructs storage object and creates storage directory + * + * @param string $dir directory name to store data files in + * @throws Zend_OpenId_Exception + */ + public function __construct($dir = null) + { + if ($dir === null) { + $tmp = getenv('TMP'); + if (empty($tmp)) { + $tmp = getenv('TEMP'); + if (empty($tmp)) { + $tmp = "/tmp"; + } + } + $user = get_current_user(); + if (is_string($user) && !empty($user)) { + $tmp .= '/' . $user; + } + $dir = $tmp . '/openid/consumer'; + } + $this->_dir = $dir; + if (!is_dir($this->_dir)) { + if (!@mkdir($this->_dir, 0700, 1)) { + /** + * @see Zend_OpenId_Exception + */ + // require_once 'Zend/OpenId/Exception.php'; + throw new Zend_OpenId_Exception( + 'Cannot access storage directory ' . $dir, + Zend_OpenId_Exception::ERROR_STORAGE); + } + } + if (($f = fopen($this->_dir.'/assoc.lock', 'w+')) === null) { + /** + * @see Zend_OpenId_Exception + */ + // require_once 'Zend/OpenId/Exception.php'; + throw new Zend_OpenId_Exception( + 'Cannot create a lock file in the directory ' . $dir, + Zend_OpenId_Exception::ERROR_STORAGE); + } + fclose($f); + if (($f = fopen($this->_dir.'/discovery.lock', 'w+')) === null) { + /** + * @see Zend_OpenId_Exception + */ + // require_once 'Zend/OpenId/Exception.php'; + throw new Zend_OpenId_Exception( + 'Cannot create a lock file in the directory ' . $dir, + Zend_OpenId_Exception::ERROR_STORAGE); + } + fclose($f); + if (($f = fopen($this->_dir.'/nonce.lock', 'w+')) === null) { + /** + * @see Zend_OpenId_Exception + */ + // require_once 'Zend/OpenId/Exception.php'; + throw new Zend_OpenId_Exception( + 'Cannot create a lock file in the directory ' . $dir, + Zend_OpenId_Exception::ERROR_STORAGE); + } + fclose($f); + } + + /** + * Stores information about association identified by $url/$handle + * + * @param string $url OpenID server URL + * @param string $handle assiciation handle + * @param string $macFunc HMAC function (sha1 or sha256) + * @param string $secret shared secret + * @param long $expires expiration UNIX time + * @return bool + */ + public function addAssociation($url, $handle, $macFunc, $secret, $expires) + { + $name1 = $this->_dir . '/assoc_url_' . md5($url); + $name2 = $this->_dir . '/assoc_handle_' . md5($handle); + $lock = @fopen($this->_dir . '/assoc.lock', 'w+'); + if ($lock === false) { + return false; + } + if (!flock($lock, LOCK_EX)) { + fclose($lock); + return false; + } + try { + $f = @fopen($name1, 'w+'); + if ($f === false) { + fclose($lock); + return false; + } + $data = serialize(array($url, $handle, $macFunc, $secret, $expires)); + fwrite($f, $data); + if (function_exists('symlink')) { + @unlink($name2); + if (symlink($name1, $name2)) { + fclose($f); + fclose($lock); + return true; + } + } + $f2 = @fopen($name2, 'w+'); + if ($f2) { + fwrite($f2, $data); + fclose($f2); + @unlink($name1); + $ret = true; + } else { + $ret = false; + } + fclose($f); + fclose($lock); + return $ret; + } catch (Exception $e) { + fclose($lock); + throw $e; + } + } + + /** + * Gets information about association identified by $url + * Returns true if given association found and not expired and false + * otherwise + * + * @param string $url OpenID server URL + * @param string &$handle assiciation handle + * @param string &$macFunc HMAC function (sha1 or sha256) + * @param string &$secret shared secret + * @param long &$expires expiration UNIX time + * @return bool + */ + public function getAssociation($url, &$handle, &$macFunc, &$secret, &$expires) + { + $name1 = $this->_dir . '/assoc_url_' . md5($url); + $lock = @fopen($this->_dir . '/assoc.lock', 'w+'); + if ($lock === false) { + return false; + } + if (!flock($lock, LOCK_EX)) { + fclose($lock); + return false; + } + try { + $f = @fopen($name1, 'r'); + if ($f === false) { + fclose($lock); + return false; + } + $ret = false; + $data = stream_get_contents($f); + if (!empty($data)) { + list($storedUrl, $handle, $macFunc, $secret, $expires) = unserialize($data); + if ($url === $storedUrl && $expires > time()) { + $ret = true; + } else { + $name2 = $this->_dir . '/assoc_handle_' . md5($handle); + fclose($f); + @unlink($name2); + @unlink($name1); + fclose($lock); + return false; + } + } + fclose($f); + fclose($lock); + return $ret; + } catch (Exception $e) { + fclose($lock); + throw $e; + } + } + + /** + * Gets information about association identified by $handle + * Returns true if given association found and not expired and false + * otherwise + * + * @param string $handle assiciation handle + * @param string &$url OpenID server URL + * @param string &$macFunc HMAC function (sha1 or sha256) + * @param string &$secret shared secret + * @param long &$expires expiration UNIX time + * @return bool + */ + public function getAssociationByHandle($handle, &$url, &$macFunc, &$secret, &$expires) + { + $name2 = $this->_dir . '/assoc_handle_' . md5($handle); + $lock = @fopen($this->_dir . '/assoc.lock', 'w+'); + if ($lock === false) { + return false; + } + if (!flock($lock, LOCK_EX)) { + fclose($lock); + return false; + } + try { + $f = @fopen($name2, 'r'); + if ($f === false) { + fclose($lock); + return false; + } + $ret = false; + $data = stream_get_contents($f); + if (!empty($data)) { + list($url, $storedHandle, $macFunc, $secret, $expires) = unserialize($data); + if ($handle === $storedHandle && $expires > time()) { + $ret = true; + } else { + fclose($f); + @unlink($name2); + $name1 = $this->_dir . '/assoc_url_' . md5($url); + @unlink($name1); + fclose($lock); + return false; + } + } + fclose($f); + fclose($lock); + return $ret; + } catch (Exception $e) { + fclose($lock); + throw $e; + } + } + + /** + * Deletes association identified by $url + * + * @param string $url OpenID server URL + * @return bool + */ + public function delAssociation($url) + { + $name1 = $this->_dir . '/assoc_url_' . md5($url); + $lock = @fopen($this->_dir . '/assoc.lock', 'w+'); + if ($lock === false) { + return false; + } + if (!flock($lock, LOCK_EX)) { + fclose($lock); + return false; + } + try { + $f = @fopen($name1, 'r'); + if ($f === false) { + fclose($lock); + return false; + } + $data = stream_get_contents($f); + if (!empty($data)) { + list($storedUrl, $handle, $macFunc, $secret, $expires) = unserialize($data); + if ($url === $storedUrl) { + $name2 = $this->_dir . '/assoc_handle_' . md5($handle); + fclose($f); + @unlink($name2); + @unlink($name1); + fclose($lock); + return true; + } + } + fclose($f); + fclose($lock); + return true; + } catch (Exception $e) { + fclose($lock); + throw $e; + } + } + + /** + * Stores information discovered from identity $id + * + * @param string $id identity + * @param string $realId discovered real identity URL + * @param string $server discovered OpenID server URL + * @param float $version discovered OpenID protocol version + * @param long $expires expiration UNIX time + * @return bool + */ + public function addDiscoveryInfo($id, $realId, $server, $version, $expires) + { + $name = $this->_dir . '/discovery_' . md5($id); + $lock = @fopen($this->_dir . '/discovery.lock', 'w+'); + if ($lock === false) { + return false; + } + if (!flock($lock, LOCK_EX)) { + fclose($lock); + return false; + } + try { + $f = @fopen($name, 'w+'); + if ($f === false) { + fclose($lock); + return false; + } + $data = serialize(array($id, $realId, $server, $version, $expires)); + fwrite($f, $data); + fclose($f); + fclose($lock); + return true; + } catch (Exception $e) { + fclose($lock); + throw $e; + } + } + + /** + * Gets information discovered from identity $id + * Returns true if such information exists and false otherwise + * + * @param string $id identity + * @param string &$realId discovered real identity URL + * @param string &$server discovered OpenID server URL + * @param float &$version discovered OpenID protocol version + * @param long &$expires expiration UNIX time + * @return bool + */ + public function getDiscoveryInfo($id, &$realId, &$server, &$version, &$expires) + { + $name = $this->_dir . '/discovery_' . md5($id); + $lock = @fopen($this->_dir . '/discovery.lock', 'w+'); + if ($lock === false) { + return false; + } + if (!flock($lock, LOCK_EX)) { + fclose($lock); + return false; + } + try { + $f = @fopen($name, 'r'); + if ($f === false) { + fclose($lock); + return false; + } + $ret = false; + $data = stream_get_contents($f); + if (!empty($data)) { + list($storedId, $realId, $server, $version, $expires) = unserialize($data); + if ($id === $storedId && $expires > time()) { + $ret = true; + } else { + fclose($f); + @unlink($name); + fclose($lock); + return false; + } + } + fclose($f); + fclose($lock); + return $ret; + } catch (Exception $e) { + fclose($lock); + throw $e; + } + } + + /** + * Removes cached information discovered from identity $id + * + * @param string $id identity + * @return bool + */ + public function delDiscoveryInfo($id) + { + $name = $this->_dir . '/discovery_' . md5($id); + $lock = @fopen($this->_dir . '/discovery.lock', 'w+'); + if ($lock === false) { + return false; + } + if (!flock($lock, LOCK_EX)) { + fclose($lock); + return false; + } + try { + @unlink($name); + fclose($lock); + return true; + } catch (Exception $e) { + fclose($lock); + throw $e; + } + } + + /** + * The function checks the uniqueness of openid.response_nonce + * + * @param string $provider openid.openid_op_endpoint field from authentication response + * @param string $nonce openid.response_nonce field from authentication response + * @return bool + */ + public function isUniqueNonce($provider, $nonce) + { + $name = $this->_dir . '/nonce_' . md5($provider.';'.$nonce); + $lock = @fopen($this->_dir . '/nonce.lock', 'w+'); + if ($lock === false) { + return false; + } + if (!flock($lock, LOCK_EX)) { + fclose($lock); + return false; + } + try { + $f = @fopen($name, 'x'); + if ($f === false) { + fclose($lock); + return false; + } + fwrite($f, $provider.';'.$nonce); + fclose($f); + fclose($lock); + return true; + } catch (Exception $e) { + fclose($lock); + throw $e; + } + } + + /** + * Removes data from the uniqueness database that is older then given date + * + * @param mixed $date date of expired data + */ + public function purgeNonces($date=null) + { + $lock = @fopen($this->_dir . '/nonce.lock', 'w+'); + if ($lock !== false) { + flock($lock, LOCK_EX); + } + try { + if (!is_int($date) && !is_string($date)) { + $nonceFiles = glob($this->_dir . '/nonce_*'); + foreach ((array) $nonceFiles as $name) { + @unlink($name); + } + unset($nonceFiles); + } else { + if (is_string($date)) { + $time = time($date); + } else { + $time = $date; + } + $nonceFiles = glob($this->_dir . '/nonce_*'); + foreach ((array) $nonceFiles as $name) { + if (filemtime($name) < $time) { + @unlink($name); + } + } + unset($nonceFiles); + } + if ($lock !== false) { + fclose($lock); + } + } catch (Exception $e) { + if ($lock !== false) { + fclose($lock); + } + throw $e; + } + } +} diff --git a/libs/Zend/OpenId/Exception.php b/libs/Zend/OpenId/Exception.php new file mode 100644 index 0000000000..e2c2d47293 --- /dev/null +++ b/libs/Zend/OpenId/Exception.php @@ -0,0 +1,58 @@ +<?php + +/** + * Zend Framework + * + * LICENSE + * + * This source file is subject to the new BSD license that is bundled + * with this package in the file LICENSE.txt. + * It is also available through the world-wide-web at this URL: + * http://framework.zend.com/license/new-bsd + * If you did not receive a copy of the license and are unable to + * obtain it through the world-wide-web, please send an email + * to license@zend.com so we can send you a copy immediately. + * + * @category Zend + * @package Zend_OpenId + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + * @version $Id: Exception.php 20096 2010-01-06 02:05:09Z bkarwin $ + */ + +/** + * @see Zend_Exception + */ +// require_once "Zend/Exception.php"; + +/** + * Exception class for Zend_OpenId + * + * @category Zend + * @package Zend_OpenId + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ +class Zend_OpenId_Exception extends Zend_Exception +{ + + /** + * The specified digest algotithm is not supported by this PHP installation + */ + const UNSUPPORTED_DIGEST = 1; + + /** + * The long math arithmetick is not supported by this PHP installation + */ + const UNSUPPORTED_LONG_MATH = 2; + + /** + * Internal long math arithmetic error + */ + const ERROR_LONG_MATH = 3; + + /** + * Iternal storage error + */ + const ERROR_STORAGE = 4; +} diff --git a/libs/Zend/OpenId/Extension.php b/libs/Zend/OpenId/Extension.php new file mode 100644 index 0000000000..38420eb285 --- /dev/null +++ b/libs/Zend/OpenId/Extension.php @@ -0,0 +1,137 @@ +<?php + +/** + * Zend Framework + * + * LICENSE + * + * This source file is subject to the new BSD license that is bundled + * with this package in the file LICENSE.txt. + * It is also available through the world-wide-web at this URL: + * http://framework.zend.com/license/new-bsd + * If you did not receive a copy of the license and are unable to + * obtain it through the world-wide-web, please send an email + * to license@zend.com so we can send you a copy immediately. + * + * @category Zend + * @package Zend_OpenId + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + * @version $Id: Extension.php 20096 2010-01-06 02:05:09Z bkarwin $ + */ + +/** + * Abstract extension class for Zend_OpenId + * + * @category Zend + * @package Zend_OpenId + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ +abstract class Zend_OpenId_Extension +{ + + /** + * Calls given function with given argument for all extensions + * + * @param mixed $extensions list of extensions or one extension + * @param string $func function to be called + * @param mixed &$params argument to pass to given funcion + * @return bool + */ + static public function forAll($extensions, $func, &$params) + { + if ($extensions !== null) { + if (is_array($extensions)) { + foreach ($extensions as $ext) { + if ($ext instanceof Zend_OpenId_Extension) { + if (!$ext->$func($params)) { + return false; + } + } else { + return false; + } + } + } else if (!is_object($extensions) || + !($extensions instanceof Zend_OpenId_Extension) || + !$extensions->$func($params)) { + return false; + } + } + return true; + } + + /** + * Method to add additional data to OpenId 'checkid_immediate' or + * 'checkid_setup' request. This method addes nothing but inherited class + * may add additional data into request. + * + * @param array &$params request's var/val pairs + * @return bool + */ + public function prepareRequest(&$params) + { + return true; + } + + /** + * Method to parse OpenId 'checkid_immediate' or 'checkid_setup' request + * and initialize object with passed data. This method parses nothing but + * inherited class may override this method to do somthing. + * + * @param array $params request's var/val pairs + * @return bool + */ + public function parseRequest($params) + { + return true; + } + + /** + * Method to add additional data to OpenId 'id_res' response. This method + * addes nothing but inherited class may add additional data into response. + * + * @param array &$params response's var/val pairs + * @return bool + */ + public function prepareResponse(&$params) + { + return true; + } + + /** + * Method to parse OpenId 'id_res' response and initialize object with + * passed data. This method parses nothing but inherited class may override + * this method to do somthing. + * + * @param array $params response's var/val pairs + * @return bool + */ + public function parseResponse($params) + { + return true; + } + + /** + * Method to prepare data to store it in trusted servers database. + * + * @param array &$data data to be stored in tusted servers database + * @return bool + */ + public function getTrustData(&$data) + { + return true; + } + + /** + * Method to check if data from trusted servers database is enough to + * sutisfy request. + * + * @param array $data data from tusted servers database + * @return bool + */ + public function checkTrustData($data) + { + return true; + } +} diff --git a/libs/Zend/OpenId/Extension/Sreg.php b/libs/Zend/OpenId/Extension/Sreg.php new file mode 100644 index 0000000000..c9c4e75518 --- /dev/null +++ b/libs/Zend/OpenId/Extension/Sreg.php @@ -0,0 +1,300 @@ +<?php + +/** + * Zend Framework + * + * LICENSE + * + * This source file is subject to the new BSD license that is bundled + * with this package in the file LICENSE.txt. + * It is also available through the world-wide-web at this URL: + * http://framework.zend.com/license/new-bsd + * If you did not receive a copy of the license and are unable to + * obtain it through the world-wide-web, please send an email + * to license@zend.com so we can send you a copy immediately. + * + * @category Zend + * @package Zend_OpenId + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + * @version $Id: Sreg.php 20096 2010-01-06 02:05:09Z bkarwin $ + */ + +/** + * @see Zend_OpenId_Extension + */ +// require_once "Zend/OpenId/Extension.php"; + +/** + * 'Simple Refistration Extension' for Zend_OpenId + * + * @category Zend + * @package Zend_OpenId + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ +class Zend_OpenId_Extension_Sreg extends Zend_OpenId_Extension +{ + /** + * SREG 1.1 namespace. All OpenID SREG 1.1 messages MUST contain variable + * openid.ns.sreg with its value. + */ + const NAMESPACE_1_1 = "http://openid.net/extensions/sreg/1.1"; + + private $_props; + private $_policy_url; + private $_version; + + /** + * Creates SREG extension object + * + * @param array $props associative array of SREG variables + * @param string $policy_url SREG policy URL + * @param float $version SREG version + * @return array + */ + public function __construct(array $props=null, $policy_url=null, $version=1.0) + { + $this->_props = $props; + $this->_policy_url = $policy_url; + $this->_version = $version; + } + + /** + * Returns associative array of SREG variables + * + * @return array + */ + public function getProperties() { + if (is_array($this->_props)) { + return $this->_props; + } else { + return array(); + } + } + + /** + * Returns SREG policy URL + * + * @return string + */ + public function getPolicyUrl() { + return $this->_policy_url; + } + + /** + * Returns SREG protocol version + * + * @return float + */ + public function getVersion() { + return $this->_version; + } + + /** + * Returns array of allowed SREG variable names. + * + * @return array + */ + public static function getSregProperties() + { + return array( + "nickname", + "email", + "fullname", + "dob", + "gender", + "postcode", + "country", + "language", + "timezone" + ); + } + + /** + * Adds additional SREG data to OpenId 'checkid_immediate' or + * 'checkid_setup' request. + * + * @param array &$params request's var/val pairs + * @return bool + */ + public function prepareRequest(&$params) + { + if (is_array($this->_props) && count($this->_props) > 0) { + foreach ($this->_props as $prop => $req) { + if ($req) { + if (isset($required)) { + $required .= ','.$prop; + } else { + $required = $prop; + } + } else { + if (isset($optional)) { + $optional .= ','.$prop; + } else { + $optional = $prop; + } + } + } + if ($this->_version >= 1.1) { + $params['openid.ns.sreg'] = Zend_OpenId_Extension_Sreg::NAMESPACE_1_1; + } + if (!empty($required)) { + $params['openid.sreg.required'] = $required; + } + if (!empty($optional)) { + $params['openid.sreg.optional'] = $optional; + } + if (!empty($this->_policy_url)) { + $params['openid.sreg.policy_url'] = $this->_policy_url; + } + } + return true; + } + + /** + * Parses OpenId 'checkid_immediate' or 'checkid_setup' request, + * extracts SREG variables and sets ovject properties to corresponding + * values. + * + * @param array $params request's var/val pairs + * @return bool + */ + public function parseRequest($params) + { + if (isset($params['openid_ns_sreg']) && + $params['openid_ns_sreg'] === Zend_OpenId_Extension_Sreg::NAMESPACE_1_1) { + $this->_version= 1.1; + } else { + $this->_version= 1.0; + } + if (!empty($params['openid_sreg_policy_url'])) { + $this->_policy_url = $params['openid_sreg_policy_url']; + } else { + $this->_policy_url = null; + } + $props = array(); + if (!empty($params['openid_sreg_optional'])) { + foreach (explode(',', $params['openid_sreg_optional']) as $prop) { + $prop = trim($prop); + $props[$prop] = false; + } + } + if (!empty($params['openid_sreg_required'])) { + foreach (explode(',', $params['openid_sreg_required']) as $prop) { + $prop = trim($prop); + $props[$prop] = true; + } + } + $props2 = array(); + foreach (self::getSregProperties() as $prop) { + if (isset($props[$prop])) { + $props2[$prop] = $props[$prop]; + } + } + + $this->_props = (count($props2) > 0) ? $props2 : null; + return true; + } + + /** + * Adds additional SREG data to OpenId 'id_res' response. + * + * @param array &$params response's var/val pairs + * @return bool + */ + public function prepareResponse(&$params) + { + if (is_array($this->_props) && count($this->_props) > 0) { + if ($this->_version >= 1.1) { + $params['openid.ns.sreg'] = Zend_OpenId_Extension_Sreg::NAMESPACE_1_1; + } + foreach (self::getSregProperties() as $prop) { + if (!empty($this->_props[$prop])) { + $params['openid.sreg.' . $prop] = $this->_props[$prop]; + } + } + } + return true; + } + + /** + * Parses OpenId 'id_res' response and sets object's properties according + * to 'openid.sreg.*' variables in response + * + * @param array $params response's var/val pairs + * @return bool + */ + public function parseResponse($params) + { + if (isset($params['openid_ns_sreg']) && + $params['openid_ns_sreg'] === Zend_OpenId_Extension_Sreg::NAMESPACE_1_1) { + $this->_version= 1.1; + } else { + $this->_version= 1.0; + } + $props = array(); + foreach (self::getSregProperties() as $prop) { + if (!empty($params['openid_sreg_' . $prop])) { + $props[$prop] = $params['openid_sreg_' . $prop]; + } + } + if (isset($this->_props) && is_array($this->_props)) { + foreach (self::getSregProperties() as $prop) { + if (isset($this->_props[$prop]) && + $this->_props[$prop] && + !isset($props[$prop])) { + return false; + } + } + } + $this->_props = (count($props) > 0) ? $props : null; + return true; + } + + /** + * Addes SREG properties that are allowed to be send to consumer to + * the given $data argument. + * + * @param array &$data data to be stored in tusted servers database + * @return bool + */ + public function getTrustData(&$data) + { + $data[get_class()] = $this->getProperties(); + return true; + } + + /** + * Check if given $data contains necessury SREG properties to sutisfy + * OpenId request. On success sets SREG response properties from given + * $data and returns true, on failure returns false. + * + * @param array $data data from tusted servers database + * @return bool + */ + public function checkTrustData($data) + { + if (is_array($this->_props) && count($this->_props) > 0) { + $props = array(); + $name = get_class(); + if (isset($data[$name])) { + $props = $data[$name]; + } else { + $props = array(); + } + $props2 = array(); + foreach ($this->_props as $prop => $req) { + if (empty($props[$prop])) { + if ($req) { + return false; + } + } else { + $props2[$prop] = $props[$prop]; + } + } + $this->_props = (count($props2) > 0) ? $props2 : null; + } + return true; + } +} diff --git a/libs/Zend/OpenId/Provider.php b/libs/Zend/OpenId/Provider.php new file mode 100644 index 0000000000..e25edca35f --- /dev/null +++ b/libs/Zend/OpenId/Provider.php @@ -0,0 +1,803 @@ +<?php + +/** + * Zend Framework + * + * LICENSE + * + * This source file is subject to the new BSD license that is bundled + * with this package in the file LICENSE.txt. + * It is also available through the world-wide-web at this URL: + * http://framework.zend.com/license/new-bsd + * If you did not receive a copy of the license and are unable to + * obtain it through the world-wide-web, please send an email + * to license@zend.com so we can send you a copy immediately. + * + * @category Zend + * @package Zend_OpenId + * @subpackage Zend_OpenId_Provider + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + * @version $Id: Provider.php 23484 2010-12-10 03:57:59Z mjh_ca $ + */ + +/** + * @see Zend_OpenId + */ +// require_once "Zend/OpenId.php"; + +/** + * @see Zend_OpenId_Extension + */ +// require_once "Zend/OpenId/Extension.php"; + +/** + * OpenID provider (server) implementation + * + * @category Zend + * @package Zend_OpenId + * @subpackage Zend_OpenId_Provider + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ +class Zend_OpenId_Provider +{ + + /** + * Reference to an implementation of storage object + * + * @var Zend_OpenId_Provider_Storage $_storage + */ + private $_storage; + + /** + * Reference to an implementation of user object + * + * @var Zend_OpenId_Provider_User $_user + */ + private $_user; + + /** + * Time to live of association session in secconds + * + * @var integer $_sessionTtl + */ + private $_sessionTtl; + + /** + * URL to peform interactive user login + * + * @var string $_loginUrl + */ + private $_loginUrl; + + /** + * URL to peform interactive validation of consumer by user + * + * @var string $_trustUrl + */ + private $_trustUrl; + + /** + * The OP Endpoint URL + * + * @var string $_opEndpoint + */ + private $_opEndpoint; + + /** + * Constructs a Zend_OpenId_Provider object with given parameters. + * + * @param string $loginUrl is an URL that provides login screen for + * end-user (by default it is the same URL with additional GET variable + * openid.action=login) + * @param string $trustUrl is an URL that shows a question if end-user + * trust to given consumer (by default it is the same URL with additional + * GET variable openid.action=trust) + * @param Zend_OpenId_Provider_User $user is an object for communication + * with User-Agent and store information about logged-in user (it is a + * Zend_OpenId_Provider_User_Session object by default) + * @param Zend_OpenId_Provider_Storage $storage is an object for keeping + * persistent database (it is a Zend_OpenId_Provider_Storage_File object + * by default) + * @param integer $sessionTtl is a default time to live for association + * session in seconds (1 hour by default). Consumer must reestablish + * association after that time. + */ + public function __construct($loginUrl = null, + $trustUrl = null, + Zend_OpenId_Provider_User $user = null, + Zend_OpenId_Provider_Storage $storage = null, + $sessionTtl = 3600) + { + if ($loginUrl === null) { + $loginUrl = Zend_OpenId::selfUrl() . '?openid.action=login'; + } else { + $loginUrl = Zend_OpenId::absoluteUrl($loginUrl); + } + $this->_loginUrl = $loginUrl; + if ($trustUrl === null) { + $trustUrl = Zend_OpenId::selfUrl() . '?openid.action=trust'; + } else { + $trustUrl = Zend_OpenId::absoluteUrl($trustUrl); + } + $this->_trustUrl = $trustUrl; + if ($user === null) { + // require_once "Zend/OpenId/Provider/User/Session.php"; + $this->_user = new Zend_OpenId_Provider_User_Session(); + } else { + $this->_user = $user; + } + if ($storage === null) { + // require_once "Zend/OpenId/Provider/Storage/File.php"; + $this->_storage = new Zend_OpenId_Provider_Storage_File(); + } else { + $this->_storage = $storage; + } + $this->_sessionTtl = $sessionTtl; + } + + /** + * Sets the OP Endpoint URL + * + * @param string $url the OP Endpoint URL + * @return null + */ + public function setOpEndpoint($url) + { + $this->_opEndpoint = $url; + } + + /** + * Registers a new user with given $id and $password + * Returns true in case of success and false if user with given $id already + * exists + * + * @param string $id user identity URL + * @param string $password encoded user password + * @return bool + */ + public function register($id, $password) + { + if (!Zend_OpenId::normalize($id) || empty($id)) { + return false; + } + return $this->_storage->addUser($id, md5($id.$password)); + } + + /** + * Returns true if user with given $id exists and false otherwise + * + * @param string $id user identity URL + * @return bool + */ + public function hasUser($id) { + if (!Zend_OpenId::normalize($id)) { + return false; + } + return $this->_storage->hasUser($id); + } + + /** + * Performs login of user with given $id and $password + * Returns true in case of success and false otherwise + * + * @param string $id user identity URL + * @param string $password user password + * @return bool + */ + public function login($id, $password) + { + if (!Zend_OpenId::normalize($id)) { + return false; + } + if (!$this->_storage->checkUser($id, md5($id.$password))) { + return false; + } + $this->_user->setLoggedInUser($id); + return true; + } + + /** + * Performs logout. Clears information about logged in user. + * + * @return void + */ + public function logout() + { + $this->_user->delLoggedInUser(); + return true; + } + + /** + * Returns identity URL of current logged in user or false + * + * @return mixed + */ + public function getLoggedInUser() { + return $this->_user->getLoggedInUser(); + } + + /** + * Retrieve consumer's root URL from request query. + * Returns URL or false in case of failure + * + * @param array $params query arguments + * @return mixed + */ + public function getSiteRoot($params) + { + $version = 1.1; + if (isset($params['openid_ns']) && + $params['openid_ns'] == Zend_OpenId::NS_2_0) { + $version = 2.0; + } + if ($version >= 2.0 && isset($params['openid_realm'])) { + $root = $params['openid_realm']; + } else if ($version < 2.0 && isset($params['openid_trust_root'])) { + $root = $params['openid_trust_root']; + } else if (isset($params['openid_return_to'])) { + $root = $params['openid_return_to']; + } else { + return false; + } + if (Zend_OpenId::normalizeUrl($root) && !empty($root)) { + return $root; + } + return false; + } + + /** + * Allows consumer with given root URL to authenticate current logged + * in user. Returns true on success and false on error. + * + * @param string $root root URL + * @param mixed $extensions extension object or array of extensions objects + * @return bool + */ + public function allowSite($root, $extensions=null) + { + $id = $this->getLoggedInUser(); + if ($id === false) { + return false; + } + if ($extensions !== null) { + $data = array(); + Zend_OpenId_Extension::forAll($extensions, 'getTrustData', $data); + } else { + $data = true; + } + $this->_storage->addSite($id, $root, $data); + return true; + } + + /** + * Prohibit consumer with given root URL to authenticate current logged + * in user. Returns true on success and false on error. + * + * @param string $root root URL + * @return bool + */ + public function denySite($root) + { + $id = $this->getLoggedInUser(); + if ($id === false) { + return false; + } + $this->_storage->addSite($id, $root, false); + return true; + } + + /** + * Delete consumer with given root URL from known sites of current logged + * in user. Next time this consumer will try to authenticate the user, + * Provider will ask user's confirmation. + * Returns true on success and false on error. + * + * @param string $root root URL + * @return bool + */ + public function delSite($root) + { + $id = $this->getLoggedInUser(); + if ($id === false) { + return false; + } + $this->_storage->addSite($id, $root, null); + return true; + } + + /** + * Returns list of known consumers for current logged in user or false + * if he is not logged in. + * + * @return mixed + */ + public function getTrustedSites() + { + $id = $this->getLoggedInUser(); + if ($id === false) { + return false; + } + return $this->_storage->getTrustedSites($id); + } + + /** + * Handles HTTP request from consumer + * + * @param array $params GET or POST variables. If this parameter is omited + * or set to null, then $_GET or $_POST superglobal variable is used + * according to REQUEST_METHOD. + * @param mixed $extensions extension object or array of extensions objects + * @param Zend_Controller_Response_Abstract $response an optional response + * object to perform HTTP or HTML form redirection + * @return mixed + */ + public function handle($params=null, $extensions=null, + Zend_Controller_Response_Abstract $response = null) + { + if ($params === null) { + if ($_SERVER["REQUEST_METHOD"] == "GET") { + $params = $_GET; + } else if ($_SERVER["REQUEST_METHOD"] == "POST") { + $params = $_POST; + } else { + return false; + } + } + $version = 1.1; + if (isset($params['openid_ns']) && + $params['openid_ns'] == Zend_OpenId::NS_2_0) { + $version = 2.0; + } + if (isset($params['openid_mode'])) { + if ($params['openid_mode'] == 'associate') { + $response = $this->_associate($version, $params); + $ret = ''; + foreach ($response as $key => $val) { + $ret .= $key . ':' . $val . "\n"; + } + return $ret; + } else if ($params['openid_mode'] == 'checkid_immediate') { + $ret = $this->_checkId($version, $params, 1, $extensions, $response); + if (is_bool($ret)) return $ret; + if (!empty($params['openid_return_to'])) { + Zend_OpenId::redirect($params['openid_return_to'], $ret, $response); + } + return true; + } else if ($params['openid_mode'] == 'checkid_setup') { + $ret = $this->_checkId($version, $params, 0, $extensions, $response); + if (is_bool($ret)) return $ret; + if (!empty($params['openid_return_to'])) { + Zend_OpenId::redirect($params['openid_return_to'], $ret, $response); + } + return true; + } else if ($params['openid_mode'] == 'check_authentication') { + $response = $this->_checkAuthentication($version, $params); + $ret = ''; + foreach ($response as $key => $val) { + $ret .= $key . ':' . $val . "\n"; + } + return $ret; + } + } + return false; + } + + /** + * Generates a secret key for given hash function, returns RAW key or false + * if function is not supported + * + * @param string $func hash function (sha1 or sha256) + * @return mixed + */ + protected function _genSecret($func) + { + if ($func == 'sha1') { + $macLen = 20; /* 160 bit */ + } else if ($func == 'sha256') { + $macLen = 32; /* 256 bit */ + } else { + return false; + } + return Zend_OpenId::randomBytes($macLen); + } + + /** + * Processes association request from OpenID consumerm generates secret + * shared key and send it back using Diffie-Hellman encruption. + * Returns array of variables to push back to consumer. + * + * @param float $version OpenID version + * @param array $params GET or POST request variables + * @return array + */ + protected function _associate($version, $params) + { + $ret = array(); + + if ($version >= 2.0) { + $ret['ns'] = Zend_OpenId::NS_2_0; + } + + if (isset($params['openid_assoc_type']) && + $params['openid_assoc_type'] == 'HMAC-SHA1') { + $macFunc = 'sha1'; + } else if (isset($params['openid_assoc_type']) && + $params['openid_assoc_type'] == 'HMAC-SHA256' && + $version >= 2.0) { + $macFunc = 'sha256'; + } else { + $ret['error'] = 'Wrong "openid.assoc_type"'; + $ret['error-code'] = 'unsupported-type'; + return $ret; + } + + $ret['assoc_type'] = $params['openid_assoc_type']; + + $secret = $this->_genSecret($macFunc); + + if (empty($params['openid_session_type']) || + $params['openid_session_type'] == 'no-encryption') { + $ret['mac_key'] = base64_encode($secret); + } else if (isset($params['openid_session_type']) && + $params['openid_session_type'] == 'DH-SHA1') { + $dhFunc = 'sha1'; + } else if (isset($params['openid_session_type']) && + $params['openid_session_type'] == 'DH-SHA256' && + $version >= 2.0) { + $dhFunc = 'sha256'; + } else { + $ret['error'] = 'Wrong "openid.session_type"'; + $ret['error-code'] = 'unsupported-type'; + return $ret; + } + + if (isset($params['openid_session_type'])) { + $ret['session_type'] = $params['openid_session_type']; + } + + if (isset($dhFunc)) { + if (empty($params['openid_dh_consumer_public'])) { + $ret['error'] = 'Wrong "openid.dh_consumer_public"'; + return $ret; + } + if (empty($params['openid_dh_gen'])) { + $g = pack('H*', Zend_OpenId::DH_G); + } else { + $g = base64_decode($params['openid_dh_gen']); + } + if (empty($params['openid_dh_modulus'])) { + $p = pack('H*', Zend_OpenId::DH_P); + } else { + $p = base64_decode($params['openid_dh_modulus']); + } + + $dh = Zend_OpenId::createDhKey($p, $g); + $dh_details = Zend_OpenId::getDhKeyDetails($dh); + + $sec = Zend_OpenId::computeDhSecret( + base64_decode($params['openid_dh_consumer_public']), $dh); + if ($sec === false) { + $ret['error'] = 'Wrong "openid.session_type"'; + $ret['error-code'] = 'unsupported-type'; + return $ret; + } + $sec = Zend_OpenId::digest($dhFunc, $sec); + $ret['dh_server_public'] = base64_encode( + Zend_OpenId::btwoc($dh_details['pub_key'])); + $ret['enc_mac_key'] = base64_encode($secret ^ $sec); + } + + $handle = uniqid(); + $expiresIn = $this->_sessionTtl; + + $ret['assoc_handle'] = $handle; + $ret['expires_in'] = $expiresIn; + + $this->_storage->addAssociation($handle, + $macFunc, $secret, time() + $expiresIn); + + return $ret; + } + + /** + * Performs authentication (or authentication check). + * + * @param float $version OpenID version + * @param array $params GET or POST request variables + * @param bool $immediate enables or disables interaction with user + * @param mixed $extensions extension object or array of extensions objects + * @param Zend_Controller_Response_Abstract $response + * @return array + */ + protected function _checkId($version, $params, $immediate, $extensions=null, + Zend_Controller_Response_Abstract $response = null) + { + $ret = array(); + + if ($version >= 2.0) { + $ret['openid.ns'] = Zend_OpenId::NS_2_0; + } + $root = $this->getSiteRoot($params); + if ($root === false) { + return false; + } + + if (isset($params['openid_identity']) && + !$this->_storage->hasUser($params['openid_identity'])) { + $ret['openid.mode'] = ($immediate && $version >= 2.0) ? 'setup_needed': 'cancel'; + return $ret; + } + + /* Check if user already logged in into the server */ + if (!isset($params['openid_identity']) || + $this->_user->getLoggedInUser() !== $params['openid_identity']) { + $params2 = array(); + foreach ($params as $key => $val) { + if (strpos($key, 'openid_ns_') === 0) { + $key = 'openid.ns.' . substr($key, strlen('openid_ns_')); + } else if (strpos($key, 'openid_sreg_') === 0) { + $key = 'openid.sreg.' . substr($key, strlen('openid_sreg_')); + } else if (strpos($key, 'openid_') === 0) { + $key = 'openid.' . substr($key, strlen('openid_')); + } + $params2[$key] = $val; + } + if ($immediate) { + $params2['openid.mode'] = 'checkid_setup'; + $ret['openid.mode'] = ($version >= 2.0) ? 'setup_needed': 'id_res'; + $ret['openid.user_setup_url'] = $this->_loginUrl + . (strpos($this->_loginUrl, '?') === false ? '?' : '&') + . Zend_OpenId::paramsToQuery($params2); + return $ret; + } else { + /* Redirect to Server Login Screen */ + Zend_OpenId::redirect($this->_loginUrl, $params2, $response); + return true; + } + } + + if (!Zend_OpenId_Extension::forAll($extensions, 'parseRequest', $params)) { + $ret['openid.mode'] = ($immediate && $version >= 2.0) ? 'setup_needed': 'cancel'; + return $ret; + } + + /* Check if user trusts to the consumer */ + $trusted = null; + $sites = $this->_storage->getTrustedSites($params['openid_identity']); + if (isset($params['openid_return_to'])) { + $root = $params['openid_return_to']; + } + if (isset($sites[$root])) { + $trusted = $sites[$root]; + } else { + foreach ($sites as $site => $t) { + if (strpos($root, $site) === 0) { + $trusted = $t; + break; + } else { + /* OpenID 2.0 (9.2) check for realm wild-card matching */ + $n = strpos($site, '://*.'); + if ($n != false) { + $regex = '/^' + . preg_quote(substr($site, 0, $n+3), '/') + . '[A-Za-z1-9_\.]+?' + . preg_quote(substr($site, $n+4), '/') + . '/'; + if (preg_match($regex, $root)) { + $trusted = $t; + break; + } + } + } + } + } + + if (is_array($trusted)) { + if (!Zend_OpenId_Extension::forAll($extensions, 'checkTrustData', $trusted)) { + $trusted = null; + } + } + + if ($trusted === false) { + $ret['openid.mode'] = 'cancel'; + return $ret; + } else if ($trusted === null) { + /* Redirect to Server Trust Screen */ + $params2 = array(); + foreach ($params as $key => $val) { + if (strpos($key, 'openid_ns_') === 0) { + $key = 'openid.ns.' . substr($key, strlen('openid_ns_')); + } else if (strpos($key, 'openid_sreg_') === 0) { + $key = 'openid.sreg.' . substr($key, strlen('openid_sreg_')); + } else if (strpos($key, 'openid_') === 0) { + $key = 'openid.' . substr($key, strlen('openid_')); + } + $params2[$key] = $val; + } + if ($immediate) { + $params2['openid.mode'] = 'checkid_setup'; + $ret['openid.mode'] = ($version >= 2.0) ? 'setup_needed': 'id_res'; + $ret['openid.user_setup_url'] = $this->_trustUrl + . (strpos($this->_trustUrl, '?') === false ? '?' : '&') + . Zend_OpenId::paramsToQuery($params2); + return $ret; + } else { + Zend_OpenId::redirect($this->_trustUrl, $params2, $response); + return true; + } + } + + return $this->_respond($version, $ret, $params, $extensions); + } + + /** + * Perepares information to send back to consumer's authentication request, + * signs it using shared secret and send back through HTTP redirection + * + * @param array $params GET or POST request variables + * @param mixed $extensions extension object or array of extensions objects + * @param Zend_Controller_Response_Abstract $response an optional response + * object to perform HTTP or HTML form redirection + * @return bool + */ + public function respondToConsumer($params, $extensions=null, + Zend_Controller_Response_Abstract $response = null) + { + $version = 1.1; + if (isset($params['openid_ns']) && + $params['openid_ns'] == Zend_OpenId::NS_2_0) { + $version = 2.0; + } + $ret = array(); + if ($version >= 2.0) { + $ret['openid.ns'] = Zend_OpenId::NS_2_0; + } + $ret = $this->_respond($version, $ret, $params, $extensions); + if (!empty($params['openid_return_to'])) { + Zend_OpenId::redirect($params['openid_return_to'], $ret, $response); + } + return true; + } + + /** + * Perepares information to send back to consumer's authentication request + * and signs it using shared secret. + * + * @param float $version OpenID protcol version + * @param array $ret arguments to be send back to consumer + * @param array $params GET or POST request variables + * @param mixed $extensions extension object or array of extensions objects + * @return array + */ + protected function _respond($version, $ret, $params, $extensions=null) + { + if (empty($params['openid_assoc_handle']) || + !$this->_storage->getAssociation($params['openid_assoc_handle'], + $macFunc, $secret, $expires)) { + /* Use dumb mode */ + if (!empty($params['openid_assoc_handle'])) { + $ret['openid.invalidate_handle'] = $params['openid_assoc_handle']; + } + $macFunc = $version >= 2.0 ? 'sha256' : 'sha1'; + $secret = $this->_genSecret($macFunc); + $handle = uniqid(); + $expiresIn = $this->_sessionTtl; + $this->_storage->addAssociation($handle, + $macFunc, $secret, time() + $expiresIn); + $ret['openid.assoc_handle'] = $handle; + } else { + $ret['openid.assoc_handle'] = $params['openid_assoc_handle']; + } + if (isset($params['openid_return_to'])) { + $ret['openid.return_to'] = $params['openid_return_to']; + } + if (isset($params['openid_claimed_id'])) { + $ret['openid.claimed_id'] = $params['openid_claimed_id']; + } + if (isset($params['openid_identity'])) { + $ret['openid.identity'] = $params['openid_identity']; + } + + if ($version >= 2.0) { + if (!empty($this->_opEndpoint)) { + $ret['openid.op_endpoint'] = $this->_opEndpoint; + } else { + $ret['openid.op_endpoint'] = Zend_OpenId::selfUrl(); + } + } + $ret['openid.response_nonce'] = gmdate('Y-m-d\TH:i:s\Z') . uniqid(); + $ret['openid.mode'] = 'id_res'; + + Zend_OpenId_Extension::forAll($extensions, 'prepareResponse', $ret); + + $signed = ''; + $data = ''; + foreach ($ret as $key => $val) { + if (strpos($key, 'openid.') === 0) { + $key = substr($key, strlen('openid.')); + if (!empty($signed)) { + $signed .= ','; + } + $signed .= $key; + $data .= $key . ':' . $val . "\n"; + } + } + $signed .= ',signed'; + $data .= 'signed:' . $signed . "\n"; + $ret['openid.signed'] = $signed; + + $ret['openid.sig'] = base64_encode( + Zend_OpenId::hashHmac($macFunc, $data, $secret)); + + return $ret; + } + + /** + * Performs authentication validation for dumb consumers + * Returns array of variables to push back to consumer. + * It MUST contain 'is_valid' variable with value 'true' or 'false'. + * + * @param float $version OpenID version + * @param array $params GET or POST request variables + * @return array + */ + protected function _checkAuthentication($version, $params) + { + $ret = array(); + if ($version >= 2.0) { + $ret['ns'] = Zend_OpenId::NS_2_0; + } + $ret['openid.mode'] = 'id_res'; + + if (empty($params['openid_assoc_handle']) || + empty($params['openid_signed']) || + empty($params['openid_sig']) || + !$this->_storage->getAssociation($params['openid_assoc_handle'], + $macFunc, $secret, $expires)) { + $ret['is_valid'] = 'false'; + return $ret; + } + + $signed = explode(',', $params['openid_signed']); + $data = ''; + foreach ($signed as $key) { + $data .= $key . ':'; + if ($key == 'mode') { + $data .= "id_res\n"; + } else { + $data .= $params['openid_' . strtr($key,'.','_')]."\n"; + } + } + if ($this->_secureStringCompare(base64_decode($params['openid_sig']), + Zend_OpenId::hashHmac($macFunc, $data, $secret))) { + $ret['is_valid'] = 'true'; + } else { + $ret['is_valid'] = 'false'; + } + return $ret; + } + + /** + * Securely compare two strings for equality while avoided C level memcmp() + * optimisations capable of leaking timing information useful to an attacker + * attempting to iteratively guess the unknown string (e.g. password) being + * compared against. + * + * @param string $a + * @param string $b + * @return bool + */ + protected function _secureStringCompare($a, $b) + { + if (strlen($a) !== strlen($b)) { + return false; + } + $result = 0; + for ($i = 0; $i < strlen($a); $i++) { + $result |= ord($a[$i]) ^ ord($b[$i]); + } + return $result == 0; + } +} diff --git a/libs/Zend/OpenId/Provider/Storage.php b/libs/Zend/OpenId/Provider/Storage.php new file mode 100644 index 0000000000..ece4889165 --- /dev/null +++ b/libs/Zend/OpenId/Provider/Storage.php @@ -0,0 +1,106 @@ +<?php + +/** + * Zend Framework + * + * LICENSE + * + * This source file is subject to the new BSD license that is bundled + * with this package in the file LICENSE.txt. + * It is also available through the world-wide-web at this URL: + * http://framework.zend.com/license/new-bsd + * If you did not receive a copy of the license and are unable to + * obtain it through the world-wide-web, please send an email + * to license@zend.com so we can send you a copy immediately. + * + * @category Zend + * @package Zend_OpenId + * @subpackage Zend_OpenId_Provider + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + * @version $Id: Storage.php 20096 2010-01-06 02:05:09Z bkarwin $ + */ + +/** + * Abstract class to implement external storage for OpenID consumer + * + * @category Zend + * @package Zend_OpenId + * @subpackage Zend_OpenId_Provider + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ +abstract class Zend_OpenId_Provider_Storage +{ + + /** + * Stores information about session identified by $handle + * + * @param string $handle assiciation handle + * @param string $macFunc HMAC function (sha1 or sha256) + * @param string $secret shared secret + * @param string $expires expiration UNIX time + * @return void + */ + abstract public function addAssociation($handle, $macFunc, $secret, $expires); + + /** + * Gets information about association identified by $handle + * Returns true if given association found and not expired and false + * otherwise + * + * @param string $handle assiciation handle + * @param string &$macFunc HMAC function (sha1 or sha256) + * @param string &$secret shared secret + * @param string &$expires expiration UNIX time + * @return bool + */ + abstract public function getAssociation($handle, &$macFunc, &$secret, &$expires); + + /** + * Register new user with given $id and $password + * Returns true in case of success and false if user with given $id already + * exists + * + * @param string $id user identity URL + * @param string $password encoded user password + * @return bool + */ + abstract public function addUser($id, $password); + + /** + * Returns true if user with given $id exists and false otherwise + * + * @param string $id user identity URL + * @return bool + */ + abstract public function hasUser($id); + + /** + * Verify if user with given $id exists and has specified $password + * + * @param string $id user identity URL + * @param string $password user password + * @return bool + */ + abstract public function checkUser($id, $password); + + /** + * Returns array of all trusted/untrusted sites for given user identified + * by $id + * + * @param string $id user identity URL + * @return array + */ + abstract public function getTrustedSites($id); + + /** + * Stores information about trusted/untrusted site for given user + * + * @param string $id user identity URL + * @param string $site site URL + * @param mixed $trusted trust data from extensions or just a boolean value + * @return bool + */ + abstract public function addSite($id, $site, $trusted); +} diff --git a/libs/Zend/OpenId/Provider/Storage/File.php b/libs/Zend/OpenId/Provider/Storage/File.php new file mode 100644 index 0000000000..f791952731 --- /dev/null +++ b/libs/Zend/OpenId/Provider/Storage/File.php @@ -0,0 +1,442 @@ +<?php + +/** + * Zend Framework + * + * LICENSE + * + * This source file is subject to the new BSD license that is bundled + * with this package in the file LICENSE.txt. + * It is also available through the world-wide-web at this URL: + * http://framework.zend.com/license/new-bsd + * If you did not receive a copy of the license and are unable to + * obtain it through the world-wide-web, please send an email + * to license@zend.com so we can send you a copy immediately. + * + * @category Zend + * @package Zend_OpenId + * @subpackage Zend_OpenId_Provider + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + * @version $Id: File.php 23484 2010-12-10 03:57:59Z mjh_ca $ + */ + +/** + * @see Zend_OpenId_Provider_Storage + */ +// require_once "Zend/OpenId/Provider/Storage.php"; + +/** + * External storage implemmentation using serialized files + * + * @category Zend + * @package Zend_OpenId + * @subpackage Zend_OpenId_Provider + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ +class Zend_OpenId_Provider_Storage_File extends Zend_OpenId_Provider_Storage +{ + + /** + * Directory name to store data files in + * + * @var string $_dir + */ + private $_dir; + + /** + * Constructs storage object and creates storage directory + * + * @param string $dir directory name to store data files in + * @throws Zend_OpenId_Exception + */ + public function __construct($dir = null) + { + if ($dir === null) { + $tmp = getenv('TMP'); + if (empty($tmp)) { + $tmp = getenv('TEMP'); + if (empty($tmp)) { + $tmp = "/tmp"; + } + } + $user = get_current_user(); + if (is_string($user) && !empty($user)) { + $tmp .= '/' . $user; + } + $dir = $tmp . '/openid/provider'; + } + $this->_dir = $dir; + if (!is_dir($this->_dir)) { + if (!@mkdir($this->_dir, 0700, 1)) { + throw new Zend_OpenId_Exception( + "Cannot access storage directory $dir", + Zend_OpenId_Exception::ERROR_STORAGE); + } + } + if (($f = fopen($this->_dir.'/assoc.lock', 'w+')) === null) { + throw new Zend_OpenId_Exception( + 'Cannot create a lock file in the directory ' . $dir, + Zend_OpenId_Exception::ERROR_STORAGE); + } + fclose($f); + if (($f = fopen($this->_dir.'/user.lock', 'w+')) === null) { + throw new Zend_OpenId_Exception( + 'Cannot create a lock file in the directory ' . $dir, + Zend_OpenId_Exception::ERROR_STORAGE); + } + fclose($f); + } + + /** + * Stores information about session identified by $handle + * + * @param string $handle assiciation handle + * @param string $macFunc HMAC function (sha1 or sha256) + * @param string $secret shared secret + * @param string $expires expiration UNIX time + * @return bool + */ + public function addAssociation($handle, $macFunc, $secret, $expires) + { + $name = $this->_dir . '/assoc_' . md5($handle); + $lock = @fopen($this->_dir . '/assoc.lock', 'w+'); + if ($lock === false) { + return false; + } + if (!flock($lock, LOCK_EX)) { + fclose($lock); + return false; + } + try { + $f = @fopen($name, 'w+'); + if ($f === false) { + fclose($lock); + return false; + } + $data = serialize(array($handle, $macFunc, $secret, $expires)); + fwrite($f, $data); + fclose($f); + fclose($lock); + return true; + } catch (Exception $e) { + fclose($lock); + throw $e; + } + } + + /** + * Gets information about association identified by $handle + * Returns true if given association found and not expired and false + * otherwise + * + * @param string $handle assiciation handle + * @param string &$macFunc HMAC function (sha1 or sha256) + * @param string &$secret shared secret + * @param string &$expires expiration UNIX time + * @return bool + */ + public function getAssociation($handle, &$macFunc, &$secret, &$expires) + { + $name = $this->_dir . '/assoc_' . md5($handle); + $lock = @fopen($this->_dir . '/assoc.lock', 'w+'); + if ($lock === false) { + return false; + } + if (!flock($lock, LOCK_EX)) { + fclose($lock); + return false; + } + try { + $f = @fopen($name, 'r'); + if ($f === false) { + fclose($lock); + return false; + } + $ret = false; + $data = stream_get_contents($f); + if (!empty($data)) { + list($storedHandle, $macFunc, $secret, $expires) = unserialize($data); + if ($handle === $storedHandle && $expires > time()) { + $ret = true; + } else { + fclose($f); + @unlink($name); + fclose($lock); + return false; + } + } + fclose($f); + fclose($lock); + return $ret; + } catch (Exception $e) { + fclose($lock); + throw $e; + } + } + + /** + * Removes information about association identified by $handle + * + * @param string $handle assiciation handle + * @return bool + */ + public function delAssociation($handle) + { + $name = $this->_dir . '/assoc_' . md5($handle); + $lock = @fopen($this->_dir . '/assoc.lock', 'w+'); + if ($lock === false) { + return false; + } + if (!flock($lock, LOCK_EX)) { + fclose($lock); + return false; + } + try { + @unlink($name); + fclose($lock); + return true; + } catch (Exception $e) { + fclose($lock); + throw $e; + } + } + + /** + * Register new user with given $id and $password + * Returns true in case of success and false if user with given $id already + * exists + * + * @param string $id user identity URL + * @param string $password encoded user password + * @return bool + */ + public function addUser($id, $password) + { + $name = $this->_dir . '/user_' . md5($id); + $lock = @fopen($this->_dir . '/user.lock', 'w+'); + if ($lock === false) { + return false; + } + if (!flock($lock, LOCK_EX)) { + fclose($lock); + return false; + } + try { + $f = @fopen($name, 'x'); + if ($f === false) { + fclose($lock); + return false; + } + $data = serialize(array($id, $password, array())); + fwrite($f, $data); + fclose($f); + fclose($lock); + return true; + } catch (Exception $e) { + fclose($lock); + throw $e; + } + } + + /** + * Returns true if user with given $id exists and false otherwise + * + * @param string $id user identity URL + * @return bool + */ + public function hasUser($id) + { + $name = $this->_dir . '/user_' . md5($id); + $lock = @fopen($this->_dir . '/user.lock', 'w+'); + if ($lock === false) { + return false; + } + if (!flock($lock, LOCK_SH)) { + fclose($lock); + return false; + } + try { + $f = @fopen($name, 'r'); + if ($f === false) { + fclose($lock); + return false; + } + $ret = false; + $data = stream_get_contents($f); + if (!empty($data)) { + list($storedId, $storedPassword, $trusted) = unserialize($data); + if ($id === $storedId) { + $ret = true; + } + } + fclose($f); + fclose($lock); + return $ret; + } catch (Exception $e) { + fclose($lock); + throw $e; + } + } + + /** + * Verify if user with given $id exists and has specified $password + * + * @param string $id user identity URL + * @param string $password user password + * @return bool + */ + public function checkUser($id, $password) + { + $name = $this->_dir . '/user_' . md5($id); + $lock = @fopen($this->_dir . '/user.lock', 'w+'); + if ($lock === false) { + return false; + } + if (!flock($lock, LOCK_SH)) { + fclose($lock); + return false; + } + try { + $f = @fopen($name, 'r'); + if ($f === false) { + fclose($lock); + return false; + } + $ret = false; + $data = stream_get_contents($f); + if (!empty($data)) { + list($storedId, $storedPassword, $trusted) = unserialize($data); + if ($id === $storedId && $password === $storedPassword) { + $ret = true; + } + } + fclose($f); + fclose($lock); + return $ret; + } catch (Exception $e) { + fclose($lock); + throw $e; + } + } + + /** + * Removes information abou specified user + * + * @param string $id user identity URL + * @return bool + */ + public function delUser($id) + { + $name = $this->_dir . '/user_' . md5($id); + $lock = @fopen($this->_dir . '/user.lock', 'w+'); + if ($lock === false) { + return false; + } + if (!flock($lock, LOCK_EX)) { + fclose($lock); + return false; + } + try { + @unlink($name); + fclose($lock); + return true; + } catch (Exception $e) { + fclose($lock); + throw $e; + } + } + + /** + * Returns array of all trusted/untrusted sites for given user identified + * by $id + * + * @param string $id user identity URL + * @return array + */ + public function getTrustedSites($id) + { + $name = $this->_dir . '/user_' . md5($id); + $lock = @fopen($this->_dir . '/user.lock', 'w+'); + if ($lock === false) { + return false; + } + if (!flock($lock, LOCK_SH)) { + fclose($lock); + return false; + } + try { + $f = @fopen($name, 'r'); + if ($f === false) { + fclose($lock); + return false; + } + $ret = false; + $data = stream_get_contents($f); + if (!empty($data)) { + list($storedId, $storedPassword, $trusted) = unserialize($data); + if ($id === $storedId) { + $ret = $trusted; + } + } + fclose($f); + fclose($lock); + return $ret; + } catch (Exception $e) { + fclose($lock); + throw $e; + } + } + + /** + * Stores information about trusted/untrusted site for given user + * + * @param string $id user identity URL + * @param string $site site URL + * @param mixed $trusted trust data from extension or just a boolean value + * @return bool + */ + public function addSite($id, $site, $trusted) + { + $name = $this->_dir . '/user_' . md5($id); + $lock = @fopen($this->_dir . '/user.lock', 'w+'); + if ($lock === false) { + return false; + } + if (!flock($lock, LOCK_EX)) { + fclose($lock); + return false; + } + try { + $f = @fopen($name, 'r+'); + if ($f === false) { + fclose($lock); + return false; + } + $ret = false; + $data = stream_get_contents($f); + if (!empty($data)) { + list($storedId, $storedPassword, $sites) = unserialize($data); + if ($id === $storedId) { + if ($trusted === null) { + unset($sites[$site]); + } else { + $sites[$site] = $trusted; + } + rewind($f); + ftruncate($f, 0); + $data = serialize(array($id, $storedPassword, $sites)); + fwrite($f, $data); + $ret = true; + } + } + fclose($f); + fclose($lock); + return $ret; + } catch (Exception $e) { + fclose($lock); + throw $e; + } + } +} diff --git a/libs/Zend/OpenId/Provider/User.php b/libs/Zend/OpenId/Provider/User.php new file mode 100644 index 0000000000..87cefab312 --- /dev/null +++ b/libs/Zend/OpenId/Provider/User.php @@ -0,0 +1,57 @@ +<?php + +/** + * Zend Framework + * + * LICENSE + * + * This source file is subject to the new BSD license that is bundled + * with this package in the file LICENSE.txt. + * It is also available through the world-wide-web at this URL: + * http://framework.zend.com/license/new-bsd + * If you did not receive a copy of the license and are unable to + * obtain it through the world-wide-web, please send an email + * to license@zend.com so we can send you a copy immediately. + * + * @category Zend + * @package Zend_OpenId + * @subpackage Zend_OpenId_Provider + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + * @version $Id: User.php 20096 2010-01-06 02:05:09Z bkarwin $ + */ + +/** + * Abstract class to get/store information about logged in user in Web Browser + * + * @category Zend + * @package Zend_OpenId + * @subpackage Zend_OpenId_Provider + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ +abstract class Zend_OpenId_Provider_User +{ + + /** + * Stores information about logged in user + * + * @param string $id user identity URL + * @return bool + */ + abstract public function setLoggedInUser($id); + + /** + * Returns identity URL of logged in user or false + * + * @return mixed + */ + abstract public function getLoggedInUser(); + + /** + * Performs logout. Clears information about logged in user. + * + * @return bool + */ + abstract public function delLoggedInUser(); +} diff --git a/libs/Zend/OpenId/Provider/User/Session.php b/libs/Zend/OpenId/Provider/User/Session.php new file mode 100644 index 0000000000..4767291848 --- /dev/null +++ b/libs/Zend/OpenId/Provider/User/Session.php @@ -0,0 +1,104 @@ +<?php + +/** + * Zend Framework + * + * LICENSE + * + * This source file is subject to the new BSD license that is bundled + * with this package in the file LICENSE.txt. + * It is also available through the world-wide-web at this URL: + * http://framework.zend.com/license/new-bsd + * If you did not receive a copy of the license and are unable to + * obtain it through the world-wide-web, please send an email + * to license@zend.com so we can send you a copy immediately. + * + * @category Zend + * @package Zend_OpenId + * @subpackage Zend_OpenId_Provider + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + * @version $Id: Session.php 20096 2010-01-06 02:05:09Z bkarwin $ + */ + +/** + * @see Zend_OpenId_Provider_User + */ +// require_once "Zend/OpenId/Provider/User.php"; + +/** + * @see Zend_Session_Namespace + */ +// require_once "Zend/Session/Namespace.php"; + +/** + * Class to get/store information about logged in user in Web Browser using + * PHP session + * + * @category Zend + * @package Zend_OpenId + * @subpackage Zend_OpenId_Provider + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ +class Zend_OpenId_Provider_User_Session extends Zend_OpenId_Provider_User +{ + /** + * Reference to an implementation of Zend_Session_Namespace object + * + * @var Zend_Session_Namespace $_session + */ + private $_session = null; + + /** + * Creates Zend_OpenId_Provider_User_Session object with given session + * namespace or creates new session namespace named "openid" + * + * @param Zend_Session_Namespace $session + */ + public function __construct(Zend_Session_Namespace $session = null) + { + if ($session === null) { + $this->_session = new Zend_Session_Namespace("openid"); + } else { + $this->_session = $session; + } + } + + /** + * Stores information about logged in user in session data + * + * @param string $id user identity URL + * @return bool + */ + public function setLoggedInUser($id) + { + $this->_session->logged_in = $id; + return true; + } + + /** + * Returns identity URL of logged in user or false + * + * @return mixed + */ + public function getLoggedInUser() + { + if (isset($this->_session->logged_in)) { + return $this->_session->logged_in; + } + return false; + } + + /** + * Performs logout. Clears information about logged in user. + * + * @return bool + */ + public function delLoggedInUser() + { + unset($this->_session->logged_in); + return true; + } + +} diff --git a/libs/Zend/Session.php b/libs/Zend/Session.php index 3dddcae8ac..bdebd57a69 100644 --- a/libs/Zend/Session.php +++ b/libs/Zend/Session.php @@ -17,7 +17,7 @@ * @package Zend_Session * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Session.php 22588 2010-07-16 20:22:07Z ralph $ + * @version $Id: Session.php 23484 2010-12-10 03:57:59Z mjh_ca $ * @since Preview Release 0.2 */ @@ -572,7 +572,7 @@ class Zend_Session extends Zend_Session_Abstract } } if (empty($_SESSION['__ZF'][$namespace]['ENVGH'])) { - unset($_SESSION['__ZF'][$namespace]['ENVGH']); + unset($_SESSION['__ZF'][$namespace]['ENVGH']); } } } diff --git a/libs/Zend/Session/SaveHandler/DbTable.php b/libs/Zend/Session/SaveHandler/DbTable.php index b59526d3a9..9e9e0e3402 100644 --- a/libs/Zend/Session/SaveHandler/DbTable.php +++ b/libs/Zend/Session/SaveHandler/DbTable.php @@ -17,7 +17,7 @@ * @package Zend_Session * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: DbTable.php 20096 2010-01-06 02:05:09Z bkarwin $ + * @version $Id: DbTable.php 23543 2010-12-18 00:55:53Z ramon $ */ /** @@ -386,8 +386,8 @@ class Zend_Session_SaveHandler_DbTable */ public function gc($maxlifetime) { - $this->delete($this->getAdapter()->quoteIdentifier($this->_modifiedColumn) . ' + ' - . $this->getAdapter()->quoteIdentifier($this->_lifetimeColumn) . ' < ' + $this->delete($this->getAdapter()->quoteIdentifier($this->_modifiedColumn, true) . ' + ' + . $this->getAdapter()->quoteIdentifier($this->_lifetimeColumn, true) . ' < ' . $this->getAdapter()->quote(time())); return true; @@ -548,7 +548,7 @@ class Zend_Session_SaveHandler_DbTable $primaryArray[$primary] = $value; break; case self::PRIMARY_TYPE_WHERECLAUSE: - $primaryArray[] = $this->getAdapter()->quoteIdentifier($primary) . ' = ' + $primaryArray[] = $this->getAdapter()->quoteIdentifier($primary, true) . ' = ' . $this->getAdapter()->quote($value); break; case self::PRIMARY_TYPE_NUM: diff --git a/libs/Zend/Uri.php b/libs/Zend/Uri.php index d636f3d1df..95f6f57a1c 100644 --- a/libs/Zend/Uri.php +++ b/libs/Zend/Uri.php @@ -16,7 +16,7 @@ * @package Zend_Uri * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Uri.php 22539 2010-07-08 12:47:44Z shahar $ + * @version $Id: Uri.php 23376 2010-11-18 21:19:24Z bittarman $ */ /** @@ -53,7 +53,12 @@ abstract class Zend_Uri */ public function __toString() { - return $this->getUri(); + try { + return $this->getUri(); + } catch (Exception $e) { + trigger_error($e->getMessage(), E_USER_WARNING); + return ''; + } } /** @@ -127,13 +132,15 @@ abstract class Zend_Uri } } - // require_once 'Zend/Loader.php'; - // try { - // Zend_Loader::loadClass($className); - // } catch (Exception $e) { - // require_once 'Zend/Uri/Exception.php'; - // throw new Zend_Uri_Exception("\"$className\" not found"); - // } + if (!class_exists($className)) { + // require_once 'Zend/Loader.php'; + try { + Zend_Loader::loadClass($className); + } catch (Exception $e) { + // require_once 'Zend/Uri/Exception.php'; + throw new Zend_Uri_Exception("\"$className\" not found"); + } + } $schemeHandler = new $className($scheme, $schemeSpecific); diff --git a/libs/Zend/Uri/Http.php b/libs/Zend/Uri/Http.php index 48911dad64..997a075fc4 100644 --- a/libs/Zend/Uri/Http.php +++ b/libs/Zend/Uri/Http.php @@ -16,7 +16,7 @@ * @package Zend_Uri * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Http.php 20096 2010-01-06 02:05:09Z bkarwin $ + * @version $Id: Http.php 23409 2010-11-19 19:55:25Z bittarman $ */ /** @@ -522,7 +522,7 @@ class Zend_Uri_Http extends Zend_Uri } /** - * Returns the path and filename portion of the URL, or FALSE if none. + * Returns the path and filename portion of the URL. * * @return string */ diff --git a/libs/Zend/Validate.php b/libs/Zend/Validate.php index f14eb671e7..6623001d5f 100644 --- a/libs/Zend/Validate.php +++ b/libs/Zend/Validate.php @@ -16,7 +16,7 @@ * @package Zend_Validate * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Validate.php 21340 2010-03-05 15:33:49Z thomas $ + * @version $Id: Validate.php 21339 2010-03-05 15:32:25Z thomas $ */ /** @@ -203,7 +203,9 @@ class Zend_Validate implements Zend_Validate_Interface $class = $namespace . '_' . $className; $file = str_replace('_', DIRECTORY_SEPARATOR, $class) . '.php'; if (Zend_Loader::isReadable($file)) { - Zend_Loader::loadClass($class); + if (!class_exists($class)) { + Zend_Loader::loadClass($class); + } $className = $class; break; } diff --git a/libs/Zend/Validate/Abstract.php b/libs/Zend/Validate/Abstract.php index a73185fd33..e31cc0ce49 100644 --- a/libs/Zend/Validate/Abstract.php +++ b/libs/Zend/Validate/Abstract.php @@ -16,7 +16,7 @@ * @package Zend_Validate * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Abstract.php 22473 2010-06-20 08:30:04Z thomas $ + * @version $Id: Abstract.php 22472 2010-06-20 07:36:16Z thomas $ */ /** diff --git a/libs/Zend/Validate/Alnum.php b/libs/Zend/Validate/Alnum.php index 68ff74d6f0..025750ce10 100644 --- a/libs/Zend/Validate/Alnum.php +++ b/libs/Zend/Validate/Alnum.php @@ -16,7 +16,7 @@ * @package Zend_Validate * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Alnum.php 22697 2010-07-26 21:14:47Z alexander $ + * @version $Id: Alnum.php 22668 2010-07-25 14:50:46Z thomas $ */ /** @@ -57,7 +57,7 @@ class Zend_Validate_Alnum extends Zend_Validate_Abstract * @var array */ protected $_messageTemplates = array( - self::INVALID => "Invalid type given, value should be float, string, or integer", + self::INVALID => "Invalid type given. String, integer or float expected", self::NOT_ALNUM => "'%value%' contains characters which are non alphabetic and no digits", self::STRING_EMPTY => "'%value%' is an empty string", ); diff --git a/libs/Zend/Validate/Alpha.php b/libs/Zend/Validate/Alpha.php index e82f17f823..be8e6f1197 100644 --- a/libs/Zend/Validate/Alpha.php +++ b/libs/Zend/Validate/Alpha.php @@ -16,7 +16,7 @@ * @package Zend_Validate * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Alpha.php 22697 2010-07-26 21:14:47Z alexander $ + * @version $Id: Alpha.php 22668 2010-07-25 14:50:46Z thomas $ */ /** @@ -57,7 +57,7 @@ class Zend_Validate_Alpha extends Zend_Validate_Abstract * @var array */ protected $_messageTemplates = array( - self::INVALID => "Invalid type given, value should be a string", + self::INVALID => "Invalid type given. String expected", self::NOT_ALPHA => "'%value%' contains non alphabetic characters", self::STRING_EMPTY => "'%value%' is an empty string" ); diff --git a/libs/Zend/Validate/Barcode.php b/libs/Zend/Validate/Barcode.php index 8b0c7705fa..e8449c4342 100644 --- a/libs/Zend/Validate/Barcode.php +++ b/libs/Zend/Validate/Barcode.php @@ -16,7 +16,7 @@ * @package Zend_Validate * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Barcode.php 22697 2010-07-26 21:14:47Z alexander $ + * @version $Id: Barcode.php 22668 2010-07-25 14:50:46Z thomas $ */ /** @@ -46,7 +46,7 @@ class Zend_Validate_Barcode extends Zend_Validate_Abstract self::FAILED => "'%value%' failed checksum validation", self::INVALID_CHARS => "'%value%' contains invalid characters", self::INVALID_LENGTH => "'%value%' should have a length of %length% characters", - self::INVALID => "Invalid type given, value should be string", + self::INVALID => "Invalid type given. String expected", ); /** diff --git a/libs/Zend/Validate/Barcode/AdapterAbstract.php b/libs/Zend/Validate/Barcode/AdapterAbstract.php index 7cbb4644f8..6c1b03c38f 100644 --- a/libs/Zend/Validate/Barcode/AdapterAbstract.php +++ b/libs/Zend/Validate/Barcode/AdapterAbstract.php @@ -16,7 +16,7 @@ * @package Zend_Validate * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Ean13.php 18028 2009-09-08 20:52:23Z thomas $ + * @version $Id: AdapterAbstract.php 20785 2010-01-31 09:43:03Z mikaelkael $ */ /** diff --git a/libs/Zend/Validate/Barcode/AdapterInterface.php b/libs/Zend/Validate/Barcode/AdapterInterface.php index 325c6048f3..58b1f8bdb5 100644 --- a/libs/Zend/Validate/Barcode/AdapterInterface.php +++ b/libs/Zend/Validate/Barcode/AdapterInterface.php @@ -16,7 +16,7 @@ * @package Zend_Validate * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Ean13.php 18028 2009-09-08 20:52:23Z thomas $ + * @version $Id: AdapterInterface.php 20785 2010-01-31 09:43:03Z mikaelkael $ */ /** diff --git a/libs/Zend/Validate/Barcode/Code25.php b/libs/Zend/Validate/Barcode/Code25.php index 6d1525da4c..d042ab668a 100644 --- a/libs/Zend/Validate/Barcode/Code25.php +++ b/libs/Zend/Validate/Barcode/Code25.php @@ -16,7 +16,7 @@ * @package Zend_Validate * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id:$ + * @version $Id: Code25.php 20785 2010-01-31 09:43:03Z mikaelkael $ */ /** diff --git a/libs/Zend/Validate/Barcode/Code25interleaved.php b/libs/Zend/Validate/Barcode/Code25interleaved.php index 54fd90bd28..eae69c01d4 100644 --- a/libs/Zend/Validate/Barcode/Code25interleaved.php +++ b/libs/Zend/Validate/Barcode/Code25interleaved.php @@ -16,7 +16,7 @@ * @package Zend_Validate * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id:$ + * @version $Id: Code25interleaved.php 20785 2010-01-31 09:43:03Z mikaelkael $ */ /** diff --git a/libs/Zend/Validate/Barcode/Code39.php b/libs/Zend/Validate/Barcode/Code39.php index 8208cffb9e..0b0675bdc5 100644 --- a/libs/Zend/Validate/Barcode/Code39.php +++ b/libs/Zend/Validate/Barcode/Code39.php @@ -16,7 +16,7 @@ * @package Zend_Validate * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id:$ + * @version $Id: Code39.php 20785 2010-01-31 09:43:03Z mikaelkael $ */ /** diff --git a/libs/Zend/Validate/Barcode/Code39ext.php b/libs/Zend/Validate/Barcode/Code39ext.php index 5b90254c50..c3d0f52070 100644 --- a/libs/Zend/Validate/Barcode/Code39ext.php +++ b/libs/Zend/Validate/Barcode/Code39ext.php @@ -16,7 +16,7 @@ * @package Zend_Validate * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id:$ + * @version $Id: Code39ext.php 20785 2010-01-31 09:43:03Z mikaelkael $ */ /** diff --git a/libs/Zend/Validate/Barcode/Code93.php b/libs/Zend/Validate/Barcode/Code93.php index 36a6567f36..16b7639e72 100644 --- a/libs/Zend/Validate/Barcode/Code93.php +++ b/libs/Zend/Validate/Barcode/Code93.php @@ -16,7 +16,7 @@ * @package Zend_Validate * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id:$ + * @version $Id: Code93.php 20785 2010-01-31 09:43:03Z mikaelkael $ */ /** diff --git a/libs/Zend/Validate/Barcode/Code93ext.php b/libs/Zend/Validate/Barcode/Code93ext.php index 2aaf343162..78689ea509 100644 --- a/libs/Zend/Validate/Barcode/Code93ext.php +++ b/libs/Zend/Validate/Barcode/Code93ext.php @@ -16,7 +16,7 @@ * @package Zend_Validate * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id:$ + * @version $Id: Code93ext.php 20785 2010-01-31 09:43:03Z mikaelkael $ */ /** diff --git a/libs/Zend/Validate/Barcode/Ean12.php b/libs/Zend/Validate/Barcode/Ean12.php index 26dee47fb5..0694de36f5 100644 --- a/libs/Zend/Validate/Barcode/Ean12.php +++ b/libs/Zend/Validate/Barcode/Ean12.php @@ -16,7 +16,7 @@ * @package Zend_Validate * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Ean13.php 18028 2009-09-08 20:52:23Z thomas $ + * @version $Id: Ean12.php 20785 2010-01-31 09:43:03Z mikaelkael $ */ /** diff --git a/libs/Zend/Validate/Barcode/Ean14.php b/libs/Zend/Validate/Barcode/Ean14.php index 19756c8ee7..1d1bc992b9 100644 --- a/libs/Zend/Validate/Barcode/Ean14.php +++ b/libs/Zend/Validate/Barcode/Ean14.php @@ -16,7 +16,7 @@ * @package Zend_Validate * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Ean13.php 18028 2009-09-08 20:52:23Z thomas $ + * @version $Id: Ean14.php 20785 2010-01-31 09:43:03Z mikaelkael $ */ /** diff --git a/libs/Zend/Validate/Barcode/Ean18.php b/libs/Zend/Validate/Barcode/Ean18.php index 7c6519959f..59f35190a5 100644 --- a/libs/Zend/Validate/Barcode/Ean18.php +++ b/libs/Zend/Validate/Barcode/Ean18.php @@ -16,7 +16,7 @@ * @package Zend_Validate * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Ean13.php 18028 2009-09-08 20:52:23Z thomas $ + * @version $Id: Ean18.php 20785 2010-01-31 09:43:03Z mikaelkael $ */ /** diff --git a/libs/Zend/Validate/Barcode/Ean2.php b/libs/Zend/Validate/Barcode/Ean2.php index 009bfe5e57..fbb305ea4b 100644 --- a/libs/Zend/Validate/Barcode/Ean2.php +++ b/libs/Zend/Validate/Barcode/Ean2.php @@ -16,7 +16,7 @@ * @package Zend_Validate * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id:$ + * @version $Id: Ean2.php 20785 2010-01-31 09:43:03Z mikaelkael $ */ /** diff --git a/libs/Zend/Validate/Barcode/Ean5.php b/libs/Zend/Validate/Barcode/Ean5.php index 7574e897e4..5c88c47282 100644 --- a/libs/Zend/Validate/Barcode/Ean5.php +++ b/libs/Zend/Validate/Barcode/Ean5.php @@ -16,7 +16,7 @@ * @package Zend_Validate * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id:$ + * @version $Id: Ean5.php 20785 2010-01-31 09:43:03Z mikaelkael $ */ /** diff --git a/libs/Zend/Validate/Barcode/Ean8.php b/libs/Zend/Validate/Barcode/Ean8.php index ca68fe45d9..450df7b028 100644 --- a/libs/Zend/Validate/Barcode/Ean8.php +++ b/libs/Zend/Validate/Barcode/Ean8.php @@ -16,7 +16,7 @@ * @package Zend_Validate * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id:$ + * @version $Id: Ean8.php 20785 2010-01-31 09:43:03Z mikaelkael $ */ /** diff --git a/libs/Zend/Validate/Barcode/Gtin12.php b/libs/Zend/Validate/Barcode/Gtin12.php index 7453e05f64..516907a43d 100644 --- a/libs/Zend/Validate/Barcode/Gtin12.php +++ b/libs/Zend/Validate/Barcode/Gtin12.php @@ -16,7 +16,7 @@ * @package Zend_Validate * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Ean13.php 18028 2009-09-08 20:52:23Z thomas $ + * @version $Id: Gtin12.php 20785 2010-01-31 09:43:03Z mikaelkael $ */ /** diff --git a/libs/Zend/Validate/Barcode/Gtin13.php b/libs/Zend/Validate/Barcode/Gtin13.php index c466f5896a..22020e0cb9 100644 --- a/libs/Zend/Validate/Barcode/Gtin13.php +++ b/libs/Zend/Validate/Barcode/Gtin13.php @@ -16,7 +16,7 @@ * @package Zend_Validate * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Ean13.php 18028 2009-09-08 20:52:23Z thomas $ + * @version $Id: Gtin13.php 20785 2010-01-31 09:43:03Z mikaelkael $ */ /** diff --git a/libs/Zend/Validate/Barcode/Gtin14.php b/libs/Zend/Validate/Barcode/Gtin14.php index 7c5c1cdb5b..277ae06451 100644 --- a/libs/Zend/Validate/Barcode/Gtin14.php +++ b/libs/Zend/Validate/Barcode/Gtin14.php @@ -16,7 +16,7 @@ * @package Zend_Validate * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Ean13.php 18028 2009-09-08 20:52:23Z thomas $ + * @version $Id: Gtin14.php 20785 2010-01-31 09:43:03Z mikaelkael $ */ /** diff --git a/libs/Zend/Validate/Barcode/Identcode.php b/libs/Zend/Validate/Barcode/Identcode.php index 6899c17910..6cf666e648 100644 --- a/libs/Zend/Validate/Barcode/Identcode.php +++ b/libs/Zend/Validate/Barcode/Identcode.php @@ -16,7 +16,7 @@ * @package Zend_Validate * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id:$ + * @version $Id: Identcode.php 20785 2010-01-31 09:43:03Z mikaelkael $ */ /** diff --git a/libs/Zend/Validate/Barcode/Intelligentmail.php b/libs/Zend/Validate/Barcode/Intelligentmail.php index a0e81cfca6..51cca537e8 100644 --- a/libs/Zend/Validate/Barcode/Intelligentmail.php +++ b/libs/Zend/Validate/Barcode/Intelligentmail.php @@ -16,7 +16,7 @@ * @package Zend_Validate * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id:$ + * @version $Id: Intelligentmail.php 20785 2010-01-31 09:43:03Z mikaelkael $ */ /** diff --git a/libs/Zend/Validate/Barcode/Issn.php b/libs/Zend/Validate/Barcode/Issn.php index e9507c9a5f..abd1e188da 100644 --- a/libs/Zend/Validate/Barcode/Issn.php +++ b/libs/Zend/Validate/Barcode/Issn.php @@ -16,7 +16,7 @@ * @package Zend_Validate * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id:$ + * @version $Id: Issn.php 20785 2010-01-31 09:43:03Z mikaelkael $ */ /** diff --git a/libs/Zend/Validate/Barcode/Itf14.php b/libs/Zend/Validate/Barcode/Itf14.php index 10cfeb761c..c219a26701 100644 --- a/libs/Zend/Validate/Barcode/Itf14.php +++ b/libs/Zend/Validate/Barcode/Itf14.php @@ -16,7 +16,7 @@ * @package Zend_Validate * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Ean13.php 18028 2009-09-08 20:52:23Z thomas $ + * @version $Id: Itf14.php 20785 2010-01-31 09:43:03Z mikaelkael $ */ /** diff --git a/libs/Zend/Validate/Barcode/Leitcode.php b/libs/Zend/Validate/Barcode/Leitcode.php index 52f1fc0428..1f51a8c6f7 100644 --- a/libs/Zend/Validate/Barcode/Leitcode.php +++ b/libs/Zend/Validate/Barcode/Leitcode.php @@ -16,7 +16,7 @@ * @package Zend_Validate * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id:$ + * @version $Id: Leitcode.php 20785 2010-01-31 09:43:03Z mikaelkael $ */ /** diff --git a/libs/Zend/Validate/Barcode/Planet.php b/libs/Zend/Validate/Barcode/Planet.php index b4eaf66cb9..d7dad19496 100644 --- a/libs/Zend/Validate/Barcode/Planet.php +++ b/libs/Zend/Validate/Barcode/Planet.php @@ -16,7 +16,7 @@ * @package Zend_Validate * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id:$ + * @version $Id: Planet.php 20785 2010-01-31 09:43:03Z mikaelkael $ */ /** diff --git a/libs/Zend/Validate/Barcode/Postnet.php b/libs/Zend/Validate/Barcode/Postnet.php index 9d2ff879b8..730482f12b 100644 --- a/libs/Zend/Validate/Barcode/Postnet.php +++ b/libs/Zend/Validate/Barcode/Postnet.php @@ -16,7 +16,7 @@ * @package Zend_Validate * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id:$ + * @version $Id: Postnet.php 20785 2010-01-31 09:43:03Z mikaelkael $ */ /** diff --git a/libs/Zend/Validate/Barcode/Royalmail.php b/libs/Zend/Validate/Barcode/Royalmail.php index 0bcdf1e16c..b04ab9f79d 100644 --- a/libs/Zend/Validate/Barcode/Royalmail.php +++ b/libs/Zend/Validate/Barcode/Royalmail.php @@ -16,7 +16,7 @@ * @package Zend_Validate * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id:$ + * @version $Id: Royalmail.php 20785 2010-01-31 09:43:03Z mikaelkael $ */ /** diff --git a/libs/Zend/Validate/Barcode/Sscc.php b/libs/Zend/Validate/Barcode/Sscc.php index b44b19a561..a7d01b2d88 100644 --- a/libs/Zend/Validate/Barcode/Sscc.php +++ b/libs/Zend/Validate/Barcode/Sscc.php @@ -16,7 +16,7 @@ * @package Zend_Validate * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Ean13.php 18028 2009-09-08 20:52:23Z thomas $ + * @version $Id: Sscc.php 20785 2010-01-31 09:43:03Z mikaelkael $ */ /** diff --git a/libs/Zend/Validate/Barcode/Upce.php b/libs/Zend/Validate/Barcode/Upce.php index 3199f19b90..99eaee9328 100644 --- a/libs/Zend/Validate/Barcode/Upce.php +++ b/libs/Zend/Validate/Barcode/Upce.php @@ -16,7 +16,7 @@ * @package Zend_Validate * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: UpcA.php 18028 2009-09-08 20:52:23Z thomas $ + * @version $Id: Upce.php 20785 2010-01-31 09:43:03Z mikaelkael $ */ /** diff --git a/libs/Zend/Validate/Callback.php b/libs/Zend/Validate/Callback.php index df12de08e6..a539ce948c 100644 --- a/libs/Zend/Validate/Callback.php +++ b/libs/Zend/Validate/Callback.php @@ -16,7 +16,7 @@ * @package Zend_Validate * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Callback.php 22697 2010-07-26 21:14:47Z alexander $ + * @version $Id: Callback.php 22668 2010-07-25 14:50:46Z thomas $ */ /** @@ -49,7 +49,7 @@ class Zend_Validate_Callback extends Zend_Validate_Abstract */ protected $_messageTemplates = array( self::INVALID_VALUE => "'%value%' is not valid", - self::INVALID_CALLBACK => "Failure within the callback, exception returned", + self::INVALID_CALLBACK => "An exception has been raised within the callback", ); /** diff --git a/libs/Zend/Validate/CreditCard.php b/libs/Zend/Validate/CreditCard.php index c76fd11f8a..86ae383cf9 100644 --- a/libs/Zend/Validate/CreditCard.php +++ b/libs/Zend/Validate/CreditCard.php @@ -16,7 +16,7 @@ * @package Zend_Validate * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: CreditCard.php 22697 2010-07-26 21:14:47Z alexander $ + * @version $Id: CreditCard.php 22668 2010-07-25 14:50:46Z thomas $ */ /** @@ -64,13 +64,13 @@ class Zend_Validate_CreditCard extends Zend_Validate_Abstract * @var array */ protected $_messageTemplates = array( - self::CHECKSUM => "Luhn algorithm (mod-10 checksum) failed on '%value%'", + self::CHECKSUM => "'%value%' seems to contain an invalid checksum", self::CONTENT => "'%value%' must contain only digits", - self::INVALID => "Invalid type given, value should be a string", + self::INVALID => "Invalid type given. String expected", self::LENGTH => "'%value%' contains an invalid amount of digits", self::PREFIX => "'%value%' is not from an allowed institute", - self::SERVICE => "Validation of '%value%' has been failed by the service", - self::SERVICEFAILURE => "The service returned a failure while validating '%value%'", + self::SERVICE => "'%value%' seems to be an invalid creditcard number", + self::SERVICEFAILURE => "An exception has been raised while validating '%value%'", ); /** diff --git a/libs/Zend/Validate/Date.php b/libs/Zend/Validate/Date.php index 1353f56c5f..bac24aabfc 100644 --- a/libs/Zend/Validate/Date.php +++ b/libs/Zend/Validate/Date.php @@ -16,7 +16,7 @@ * @package Zend_Validate * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Date.php 22697 2010-07-26 21:14:47Z alexander $ + * @version $Id: Date.php 22668 2010-07-25 14:50:46Z thomas $ */ /** @@ -42,7 +42,7 @@ class Zend_Validate_Date extends Zend_Validate_Abstract * @var array */ protected $_messageTemplates = array( - self::INVALID => "Invalid type given, value should be string, integer, array or Zend_Date", + self::INVALID => "Invalid type given. String, integer, array or Zend_Date expected", self::INVALID_DATE => "'%value%' does not appear to be a valid date", self::FALSEFORMAT => "'%value%' does not fit the date format '%format%'", ); diff --git a/libs/Zend/Validate/Db/Abstract.php b/libs/Zend/Validate/Db/Abstract.php index 240b96c9f5..cdbfb37810 100644 --- a/libs/Zend/Validate/Db/Abstract.php +++ b/libs/Zend/Validate/Db/Abstract.php @@ -16,7 +16,7 @@ * @package Zend_Validate * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Abstract.php 22697 2010-07-26 21:14:47Z alexander $ + * @version $Id: Abstract.php 23484 2010-12-10 03:57:59Z mjh_ca $ */ /** @@ -45,8 +45,8 @@ abstract class Zend_Validate_Db_Abstract extends Zend_Validate_Abstract * @var array Message templates */ protected $_messageTemplates = array( - self::ERROR_NO_RECORD_FOUND => 'No record matching %value% was found', - self::ERROR_RECORD_FOUND => 'A record matching %value% was found', + self::ERROR_NO_RECORD_FOUND => "No record matching '%value%' was found", + self::ERROR_RECORD_FOUND => "A record matching '%value%' was found", ); /** @@ -77,6 +77,12 @@ abstract class Zend_Validate_Db_Abstract extends Zend_Validate_Abstract protected $_adapter = null; /** + * Select object to use. can be set, or will be auto-generated + * @var Zend_Db_Select + */ + protected $_select; + + /** * Provides basic configuration for use with Zend_Validate_Db Validators * Setting $exclude allows a single record to be excluded from matching. * Exclude can either be a String containing a where clause, or an array with `field` and `value` keys @@ -94,6 +100,10 @@ abstract class Zend_Validate_Db_Abstract extends Zend_Validate_Abstract */ public function __construct($options) { + if ($options instanceof Zend_Db_Select) { + $this->setSelect($options); + return; + } if ($options instanceof Zend_Config) { $options = $options->toArray(); } else if (func_num_args() > 1) { @@ -146,6 +156,16 @@ abstract class Zend_Validate_Db_Abstract extends Zend_Validate_Abstract */ public function getAdapter() { + /** + * Check for an adapter being defined. if not, fetch the default adapter. + */ + if ($this->_adapter === null) { + $this->_adapter = Zend_Db_Table_Abstract::getDefaultAdapter(); + if (null === $this->_adapter) { + // require_once 'Zend/Validate/Exception.php'; + throw new Zend_Validate_Exception('No database adapter present'); + } + } return $this->_adapter; } @@ -255,43 +275,76 @@ abstract class Zend_Validate_Db_Abstract extends Zend_Validate_Abstract } /** - * Run query and returns matches, or null if no matches are found. + * Sets the select object to be used by the validator * - * @param String $value - * @return Array when matches are found. + * @param Zend_Db_Select $select + * @return Zend_Validate_Db_Abstract */ - protected function _query($value) + public function setSelect($select) { - /** - * Check for an adapter being defined. if not, fetch the default adapter. - */ - if ($this->_adapter === null) { - $this->_adapter = Zend_Db_Table_Abstract::getDefaultAdapter(); - if (null === $this->_adapter) { - // require_once 'Zend/Validate/Exception.php'; - throw new Zend_Validate_Exception('No database adapter present'); - } + if (!$select instanceof Zend_Db_Select) { + throw new Zend_Validate_Exception('Select option must be a valid ' . + 'Zend_Db_Select object'); } + $this->_select = $select; + return $this; + } - /** - * Build select object - */ - $select = new Zend_Db_Select($this->_adapter); - $select->from($this->_table, array($this->_field), $this->_schema) - ->where($this->_adapter->quoteIdentifier($this->_field, true).' = ?', $value); - if ($this->_exclude !== null) { - if (is_array($this->_exclude)) { - $select->where($this->_adapter->quoteIdentifier($this->_exclude['field'], true).' != ?', $this->_exclude['value']); + /** + * Gets the select object to be used by the validator. + * If no select object was supplied to the constructor, + * then it will auto-generate one from the given table, + * schema, field, and adapter options. + * + * @return Zend_Db_Select The Select object which will be used + */ + public function getSelect() + { + if (null === $this->_select) { + $db = $this->getAdapter(); + /** + * Build select object + */ + $select = new Zend_Db_Select($db); + $select->from($this->_table, array($this->_field), $this->_schema); + if ($db->supportsParameters('named')) { + $select->where($db->quoteIdentifier($this->_field, true).' = :value'); // named } else { - $select->where($this->_exclude); + $select->where($db->quoteIdentifier($this->_field, true).' = ?'); // positional + } + if ($this->_exclude !== null) { + if (is_array($this->_exclude)) { + $select->where( + $db->quoteIdentifier($this->_exclude['field'], true) . + ' != ?', $this->_exclude['value'] + ); + } else { + $select->where($this->_exclude); + } } + $select->limit(1); + $this->_select = $select; } - $select->limit(1); + return $this->_select; + } + /** + * Run query and returns matches, or null if no matches are found. + * + * @param String $value + * @return Array when matches are found. + */ + protected function _query($value) + { + $select = $this->getSelect(); /** * Run query */ - $result = $this->_adapter->fetchRow($select, array(), Zend_Db::FETCH_ASSOC); + $result = $select->getAdapter()->fetchRow( + $select, + array('value' => $value), // this should work whether db supports positional or named params + Zend_Db::FETCH_ASSOC + ); return $result; } diff --git a/libs/Zend/Validate/Digits.php b/libs/Zend/Validate/Digits.php index da81750fb3..90ef7e4de5 100644 --- a/libs/Zend/Validate/Digits.php +++ b/libs/Zend/Validate/Digits.php @@ -16,7 +16,7 @@ * @package Zend_Validate * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Digits.php 22697 2010-07-26 21:14:47Z alexander $ + * @version $Id: Digits.php 22668 2010-07-25 14:50:46Z thomas $ */ /** @@ -49,9 +49,9 @@ class Zend_Validate_Digits extends Zend_Validate_Abstract * @var array */ protected $_messageTemplates = array( - self::NOT_DIGITS => "'%value%' contains characters which are not digits; but only digits are allowed", + self::NOT_DIGITS => "'%value%' must contain only digits", self::STRING_EMPTY => "'%value%' is an empty string", - self::INVALID => "Invalid type given, value should be string, integer or float", + self::INVALID => "Invalid type given. String, integer or float expected", ); /** diff --git a/libs/Zend/Validate/EmailAddress.php b/libs/Zend/Validate/EmailAddress.php index ad008b407d..3540da770a 100644 --- a/libs/Zend/Validate/EmailAddress.php +++ b/libs/Zend/Validate/EmailAddress.php @@ -16,7 +16,7 @@ * @package Zend_Validate * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: EmailAddress.php 22697 2010-07-26 21:14:47Z alexander $ + * @version $Id: EmailAddress.php 22668 2010-07-25 14:50:46Z thomas $ */ /** @@ -51,11 +51,11 @@ class Zend_Validate_EmailAddress extends Zend_Validate_Abstract * @var array */ protected $_messageTemplates = array( - self::INVALID => "Invalid type given, value should be a string", + self::INVALID => "Invalid type given. String expected", self::INVALID_FORMAT => "'%value%' is no valid email address in the basic format local-part@hostname", self::INVALID_HOSTNAME => "'%hostname%' is no valid hostname for email address '%value%'", self::INVALID_MX_RECORD => "'%hostname%' does not appear to have a valid MX record for the email address '%value%'", - self::INVALID_SEGMENT => "'%hostname%' is not in a routable network segment. The email address '%value%' should not be resolved from public network.", + self::INVALID_SEGMENT => "'%hostname%' is not in a routable network segment. The email address '%value%' should not be resolved from public network", self::DOT_ATOM => "'%localPart%' can not be matched against dot-atom format", self::QUOTED_STRING => "'%localPart%' can not be matched against quoted-string format", self::INVALID_LOCAL_PART => "'%localPart%' is no valid local part for email address '%value%'", diff --git a/libs/Zend/Validate/File/Count.php b/libs/Zend/Validate/File/Count.php index a4bff7ee8c..a49a499a71 100644 --- a/libs/Zend/Validate/File/Count.php +++ b/libs/Zend/Validate/File/Count.php @@ -16,7 +16,7 @@ * @package Zend_Validate * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Count.php 21326 2010-03-04 20:32:39Z thomas $ + * @version $Id: Count.php 21325 2010-03-04 20:26:36Z thomas $ */ /** diff --git a/libs/Zend/Validate/File/Crc32.php b/libs/Zend/Validate/File/Crc32.php index aef309353e..495f24ee49 100644 --- a/libs/Zend/Validate/File/Crc32.php +++ b/libs/Zend/Validate/File/Crc32.php @@ -16,7 +16,7 @@ * @package Zend_Validate * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Crc32.php 22697 2010-07-26 21:14:47Z alexander $ + * @version $Id: Crc32.php 22668 2010-07-25 14:50:46Z thomas $ */ /** @@ -47,7 +47,7 @@ class Zend_Validate_File_Crc32 extends Zend_Validate_File_Hash protected $_messageTemplates = array( self::DOES_NOT_MATCH => "File '%value%' does not match the given crc32 hashes", self::NOT_DETECTED => "A crc32 hash could not be evaluated for the given file", - self::NOT_FOUND => "File '%value%' could not be found", + self::NOT_FOUND => "File '%value%' is not readable or does not exist", ); /** diff --git a/libs/Zend/Validate/File/ExcludeExtension.php b/libs/Zend/Validate/File/ExcludeExtension.php index 0bf2d5bdf9..8f8bb5c914 100644 --- a/libs/Zend/Validate/File/ExcludeExtension.php +++ b/libs/Zend/Validate/File/ExcludeExtension.php @@ -16,7 +16,7 @@ * @package Zend_Validate * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: ExcludeExtension.php 22697 2010-07-26 21:14:47Z alexander $ + * @version $Id: ExcludeExtension.php 22668 2010-07-25 14:50:46Z thomas $ */ /** @@ -45,7 +45,7 @@ class Zend_Validate_File_ExcludeExtension extends Zend_Validate_File_Extension */ protected $_messageTemplates = array( self::FALSE_EXTENSION => "File '%value%' has a false extension", - self::NOT_FOUND => "File '%value%' could not be found", + self::NOT_FOUND => "File '%value%' is not readable or does not exist", ); /** diff --git a/libs/Zend/Validate/File/ExcludeMimeType.php b/libs/Zend/Validate/File/ExcludeMimeType.php index 436caa1f02..24c1537fac 100644 --- a/libs/Zend/Validate/File/ExcludeMimeType.php +++ b/libs/Zend/Validate/File/ExcludeMimeType.php @@ -16,7 +16,7 @@ * @package Zend_Validate * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: ExcludeMimeType.php 21936 2010-04-18 16:23:34Z thomas $ + * @version $Id: ExcludeMimeType.php 21935 2010-04-18 16:21:35Z thomas $ */ /** diff --git a/libs/Zend/Validate/File/Exists.php b/libs/Zend/Validate/File/Exists.php index 6ecd11f1f0..cef188dc28 100644 --- a/libs/Zend/Validate/File/Exists.php +++ b/libs/Zend/Validate/File/Exists.php @@ -16,7 +16,7 @@ * @package Zend_Validate * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Exists.php 20358 2010-01-17 19:03:49Z thomas $ + * @version $Id: Exists.php 20352 2010-01-17 17:55:38Z thomas $ */ /** diff --git a/libs/Zend/Validate/File/Extension.php b/libs/Zend/Validate/File/Extension.php index b5e63a2e95..71985f5e9b 100644 --- a/libs/Zend/Validate/File/Extension.php +++ b/libs/Zend/Validate/File/Extension.php @@ -16,7 +16,7 @@ * @package Zend_Validate * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Extension.php 22697 2010-07-26 21:14:47Z alexander $ + * @version $Id: Extension.php 22668 2010-07-25 14:50:46Z thomas $ */ /** @@ -45,7 +45,7 @@ class Zend_Validate_File_Extension extends Zend_Validate_Abstract */ protected $_messageTemplates = array( self::FALSE_EXTENSION => "File '%value%' has a false extension", - self::NOT_FOUND => "File '%value%' could not be found", + self::NOT_FOUND => "File '%value%' is not readable or does not exist", ); /** diff --git a/libs/Zend/Validate/File/FilesSize.php b/libs/Zend/Validate/File/FilesSize.php index ca20ad50af..a418ef3bb4 100644 --- a/libs/Zend/Validate/File/FilesSize.php +++ b/libs/Zend/Validate/File/FilesSize.php @@ -16,7 +16,7 @@ * @package Zend_Validate * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: FilesSize.php 20455 2010-01-20 22:54:18Z thomas $ + * @version $Id: FilesSize.php 20454 2010-01-20 22:50:59Z thomas $ */ /** diff --git a/libs/Zend/Validate/File/Hash.php b/libs/Zend/Validate/File/Hash.php index 4b9772887c..2e4071b645 100644 --- a/libs/Zend/Validate/File/Hash.php +++ b/libs/Zend/Validate/File/Hash.php @@ -16,7 +16,7 @@ * @package Zend_Validate * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Hash.php 22697 2010-07-26 21:14:47Z alexander $ + * @version $Id: Hash.php 22668 2010-07-25 14:50:46Z thomas $ */ /** @@ -47,7 +47,7 @@ class Zend_Validate_File_Hash extends Zend_Validate_Abstract protected $_messageTemplates = array( self::DOES_NOT_MATCH => "File '%value%' does not match the given hashes", self::NOT_DETECTED => "A hash could not be evaluated for the given file", - self::NOT_FOUND => "File '%value%' could not be found" + self::NOT_FOUND => "File '%value%' is not readable or does not exist" ); /** diff --git a/libs/Zend/Validate/File/ImageSize.php b/libs/Zend/Validate/File/ImageSize.php index aa882a5b5d..4f2915d49e 100644 --- a/libs/Zend/Validate/File/ImageSize.php +++ b/libs/Zend/Validate/File/ImageSize.php @@ -16,7 +16,7 @@ * @package Zend_Validate * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: ImageSize.php 22697 2010-07-26 21:14:47Z alexander $ + * @version $Id: ImageSize.php 22668 2010-07-25 14:50:46Z thomas $ */ /** @@ -53,7 +53,7 @@ class Zend_Validate_File_ImageSize extends Zend_Validate_Abstract self::HEIGHT_TOO_BIG => "Maximum allowed height for image '%value%' should be '%maxheight%' but '%height%' detected", self::HEIGHT_TOO_SMALL => "Minimum expected height for image '%value%' should be '%minheight%' but '%height%' detected", self::NOT_DETECTED => "The size of image '%value%' could not be detected", - self::NOT_READABLE => "File '%value%' can not be read", + self::NOT_READABLE => "File '%value%' is not readable or does not exist", ); /** diff --git a/libs/Zend/Validate/File/IsCompressed.php b/libs/Zend/Validate/File/IsCompressed.php index 30415e3229..b75fe481a1 100644 --- a/libs/Zend/Validate/File/IsCompressed.php +++ b/libs/Zend/Validate/File/IsCompressed.php @@ -16,7 +16,7 @@ * @package Zend_Validate * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: IsCompressed.php 22697 2010-07-26 21:14:47Z alexander $ + * @version $Id: IsCompressed.php 22668 2010-07-25 14:50:46Z thomas $ */ /** @@ -46,8 +46,8 @@ class Zend_Validate_File_IsCompressed extends Zend_Validate_File_MimeType */ protected $_messageTemplates = array( self::FALSE_TYPE => "File '%value%' is not compressed, '%type%' detected", - self::NOT_DETECTED => "The mimetype of file '%value%' could not been detected", - self::NOT_READABLE => "File '%value%' can not be read", + self::NOT_DETECTED => "The mimetype of file '%value%' could not be detected", + self::NOT_READABLE => "File '%value%' is not readable or does not exist", ); /** diff --git a/libs/Zend/Validate/File/IsImage.php b/libs/Zend/Validate/File/IsImage.php index 4fa966266f..3b91a71989 100644 --- a/libs/Zend/Validate/File/IsImage.php +++ b/libs/Zend/Validate/File/IsImage.php @@ -16,7 +16,7 @@ * @package Zend_Validate * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: IsImage.php 22697 2010-07-26 21:14:47Z alexander $ + * @version $Id: IsImage.php 22668 2010-07-25 14:50:46Z thomas $ */ /** @@ -47,7 +47,7 @@ class Zend_Validate_File_IsImage extends Zend_Validate_File_MimeType protected $_messageTemplates = array( self::FALSE_TYPE => "File '%value%' is no image, '%type%' detected", self::NOT_DETECTED => "The mimetype of file '%value%' could not be detected", - self::NOT_READABLE => "File '%value%' can not be read", + self::NOT_READABLE => "File '%value%' is not readable or does not exist", ); /** diff --git a/libs/Zend/Validate/File/Md5.php b/libs/Zend/Validate/File/Md5.php index d2626ba638..52a28f6011 100644 --- a/libs/Zend/Validate/File/Md5.php +++ b/libs/Zend/Validate/File/Md5.php @@ -16,7 +16,7 @@ * @package Zend_Validate * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Md5.php 22697 2010-07-26 21:14:47Z alexander $ + * @version $Id: Md5.php 22668 2010-07-25 14:50:46Z thomas $ */ /** @@ -47,7 +47,7 @@ class Zend_Validate_File_Md5 extends Zend_Validate_File_Hash protected $_messageTemplates = array( self::DOES_NOT_MATCH => "File '%value%' does not match the given md5 hashes", self::NOT_DETECTED => "A md5 hash could not be evaluated for the given file", - self::NOT_FOUND => "File '%value%' could not be found", + self::NOT_FOUND => "File '%value%' is not readable or does not exist", ); /** diff --git a/libs/Zend/Validate/File/MimeType.php b/libs/Zend/Validate/File/MimeType.php index 7bf1bfd0b1..8d26b17e02 100644 --- a/libs/Zend/Validate/File/MimeType.php +++ b/libs/Zend/Validate/File/MimeType.php @@ -16,7 +16,7 @@ * @package Zend_Validate * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: MimeType.php 22697 2010-07-26 21:14:47Z alexander $ + * @version $Id: MimeType.php 22832 2010-08-12 18:02:41Z thomas $ */ /** @@ -48,7 +48,7 @@ class Zend_Validate_File_MimeType extends Zend_Validate_Abstract protected $_messageTemplates = array( self::FALSE_TYPE => "File '%value%' has a false mimetype of '%type%'", self::NOT_DETECTED => "The mimetype of file '%value%' could not be detected", - self::NOT_READABLE => "File '%value%' can not be read", + self::NOT_READABLE => "File '%value%' is not readable or does not exist", ); /** @@ -191,7 +191,7 @@ class Zend_Validate_File_MimeType extends Zend_Validate_Abstract $this->_magicfile = null; // require_once 'Zend/Validate/Exception.php'; throw new Zend_Validate_Exception('Magicfile can not be set. There is no finfo extension installed'); - } else if (!is_readable($file)) { + } else if (!is_file($file) || !is_readable($file)) { // require_once 'Zend/Validate/Exception.php'; throw new Zend_Validate_Exception('The given magicfile can not be read'); } else { diff --git a/libs/Zend/Validate/File/NotExists.php b/libs/Zend/Validate/File/NotExists.php index a5afe94686..869346f46d 100644 --- a/libs/Zend/Validate/File/NotExists.php +++ b/libs/Zend/Validate/File/NotExists.php @@ -16,7 +16,7 @@ * @package Zend_Validate * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: NotExists.php 20358 2010-01-17 19:03:49Z thomas $ + * @version $Id: NotExists.php 20352 2010-01-17 17:55:38Z thomas $ */ /** diff --git a/libs/Zend/Validate/File/Sha1.php b/libs/Zend/Validate/File/Sha1.php index 8d3ee8a03d..3a8698a30e 100644 --- a/libs/Zend/Validate/File/Sha1.php +++ b/libs/Zend/Validate/File/Sha1.php @@ -16,7 +16,7 @@ * @package Zend_Validate * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Sha1.php 22697 2010-07-26 21:14:47Z alexander $ + * @version $Id: Sha1.php 22668 2010-07-25 14:50:46Z thomas $ */ /** @@ -47,7 +47,7 @@ class Zend_Validate_File_Sha1 extends Zend_Validate_File_Hash protected $_messageTemplates = array( self::DOES_NOT_MATCH => "File '%value%' does not match the given sha1 hashes", self::NOT_DETECTED => "A sha1 hash could not be evaluated for the given file", - self::NOT_FOUND => "File '%value%' could not be found", + self::NOT_FOUND => "File '%value%' is not readable or does not exist", ); /** diff --git a/libs/Zend/Validate/File/Size.php b/libs/Zend/Validate/File/Size.php index 207a12356e..247f2965f9 100644 --- a/libs/Zend/Validate/File/Size.php +++ b/libs/Zend/Validate/File/Size.php @@ -16,7 +16,7 @@ * @package Zend_Validate * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Size.php 22697 2010-07-26 21:14:47Z alexander $ + * @version $Id: Size.php 22668 2010-07-25 14:50:46Z thomas $ */ /** @@ -48,7 +48,7 @@ class Zend_Validate_File_Size extends Zend_Validate_Abstract protected $_messageTemplates = array( self::TOO_BIG => "Maximum allowed size for file '%value%' is '%max%' but '%size%' detected", self::TOO_SMALL => "Minimum expected size for file '%value%' is '%min%' but '%size%' detected", - self::NOT_FOUND => "File '%value%' could not be found", + self::NOT_FOUND => "File '%value%' is not readable or does not exist", ); /** diff --git a/libs/Zend/Validate/File/Upload.php b/libs/Zend/Validate/File/Upload.php index 92bbba59c3..0d01a4b566 100644 --- a/libs/Zend/Validate/File/Upload.php +++ b/libs/Zend/Validate/File/Upload.php @@ -16,7 +16,7 @@ * @package Zend_Validate * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Upload.php 22399 2010-06-09 19:08:28Z thomas $ + * @version $Id: Upload.php 23570 2010-12-20 08:38:30Z mjh_ca $ */ /** @@ -136,6 +136,11 @@ class Zend_Validate_File_Upload extends Zend_Validate_Abstract $this->_files = $files; } + // see ZF-10738 + if (is_null($this->_files)) { + $this->_files = array(); + } + foreach($this->_files as $file => $content) { if (!isset($content['error'])) { unset($this->_files[$file]); diff --git a/libs/Zend/Validate/File/WordCount.php b/libs/Zend/Validate/File/WordCount.php index 2d94bfa605..bb9364174a 100644 --- a/libs/Zend/Validate/File/WordCount.php +++ b/libs/Zend/Validate/File/WordCount.php @@ -16,7 +16,7 @@ * @package Zend_Validate * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: WordCount.php 22697 2010-07-26 21:14:47Z alexander $ + * @version $Id: WordCount.php 22668 2010-07-25 14:50:46Z thomas $ */ /** @@ -48,7 +48,7 @@ class Zend_Validate_File_WordCount extends Zend_Validate_File_Count protected $_messageTemplates = array( self::TOO_MUCH => "Too much words, maximum '%max%' are allowed but '%count%' were counted", self::TOO_LESS => "Too less words, minimum '%min%' are expected but '%count%' were counted", - self::NOT_FOUND => "File '%value%' could not be found", + self::NOT_FOUND => "File '%value%' is not readable or does not exist", ); /** diff --git a/libs/Zend/Validate/Float.php b/libs/Zend/Validate/Float.php index 067f24e28c..ac8fb7e6dd 100644 --- a/libs/Zend/Validate/Float.php +++ b/libs/Zend/Validate/Float.php @@ -16,7 +16,7 @@ * @package Zend_Validate * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Float.php 22697 2010-07-26 21:14:47Z alexander $ + * @version $Id: Float.php 22668 2010-07-25 14:50:46Z thomas $ */ /** @@ -44,7 +44,7 @@ class Zend_Validate_Float extends Zend_Validate_Abstract * @var array */ protected $_messageTemplates = array( - self::INVALID => "Invalid type given, value should be float, string, or integer", + self::INVALID => "Invalid type given. String, integer or float expected", self::NOT_FLOAT => "'%value%' does not appear to be a float", ); diff --git a/libs/Zend/Validate/GreaterThan.php b/libs/Zend/Validate/GreaterThan.php index a9b7a21879..7c313a0bf0 100644 --- a/libs/Zend/Validate/GreaterThan.php +++ b/libs/Zend/Validate/GreaterThan.php @@ -16,7 +16,7 @@ * @package Zend_Validate * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: GreaterThan.php 20358 2010-01-17 19:03:49Z thomas $ + * @version $Id: GreaterThan.php 20352 2010-01-17 17:55:38Z thomas $ */ /** diff --git a/libs/Zend/Validate/Hex.php b/libs/Zend/Validate/Hex.php index bd8a39a449..999dc849f3 100644 --- a/libs/Zend/Validate/Hex.php +++ b/libs/Zend/Validate/Hex.php @@ -16,7 +16,7 @@ * @package Zend_Validate * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Hex.php 22697 2010-07-26 21:14:47Z alexander $ + * @version $Id: Hex.php 22668 2010-07-25 14:50:46Z thomas $ */ /** @@ -41,7 +41,7 @@ class Zend_Validate_Hex extends Zend_Validate_Abstract * @var array */ protected $_messageTemplates = array( - self::INVALID => "Invalid type given, value should be a string", + self::INVALID => "Invalid type given. String expected", self::NOT_HEX => "'%value%' has not only hexadecimal digit characters", ); diff --git a/libs/Zend/Validate/Hostname.php b/libs/Zend/Validate/Hostname.php index 1732e69c77..ba93d98627 100644 --- a/libs/Zend/Validate/Hostname.php +++ b/libs/Zend/Validate/Hostname.php @@ -16,7 +16,7 @@ * @package Zend_Validate * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Hostname.php 21063 2010-02-15 23:00:17Z thomas $ + * @version $Id: Hostname.php 23488 2010-12-10 07:22:55Z mjh_ca $ */ /** @@ -46,31 +46,33 @@ */ class Zend_Validate_Hostname extends Zend_Validate_Abstract { + const CANNOT_DECODE_PUNYCODE = 'hostnameCannotDecodePunycode'; const INVALID = 'hostnameInvalid'; - const IP_ADDRESS_NOT_ALLOWED = 'hostnameIpAddressNotAllowed'; - const UNKNOWN_TLD = 'hostnameUnknownTld'; const INVALID_DASH = 'hostnameDashCharacter'; - const INVALID_HOSTNAME_SCHEMA = 'hostnameInvalidHostnameSchema'; - const UNDECIPHERABLE_TLD = 'hostnameUndecipherableTld'; const INVALID_HOSTNAME = 'hostnameInvalidHostname'; + const INVALID_HOSTNAME_SCHEMA = 'hostnameInvalidHostnameSchema'; const INVALID_LOCAL_NAME = 'hostnameInvalidLocalName'; + const INVALID_URI = 'hostnameInvalidUri'; + const IP_ADDRESS_NOT_ALLOWED = 'hostnameIpAddressNotAllowed'; const LOCAL_NAME_NOT_ALLOWED = 'hostnameLocalNameNotAllowed'; - const CANNOT_DECODE_PUNYCODE = 'hostnameCannotDecodePunycode'; + const UNDECIPHERABLE_TLD = 'hostnameUndecipherableTld'; + const UNKNOWN_TLD = 'hostnameUnknownTld'; /** * @var array */ protected $_messageTemplates = array( - self::INVALID => "Invalid type given, value should be a string", - self::IP_ADDRESS_NOT_ALLOWED => "'%value%' appears to be an IP address, but IP addresses are not allowed", - self::UNKNOWN_TLD => "'%value%' appears to be a DNS hostname but cannot match TLD against known list", + self::CANNOT_DECODE_PUNYCODE => "'%value%' appears to be a DNS hostname but the given punycode notation cannot be decoded", + self::INVALID => "Invalid type given. String expected", self::INVALID_DASH => "'%value%' appears to be a DNS hostname but contains a dash in an invalid position", - self::INVALID_HOSTNAME_SCHEMA => "'%value%' appears to be a DNS hostname but cannot match against hostname schema for TLD '%tld%'", - self::UNDECIPHERABLE_TLD => "'%value%' appears to be a DNS hostname but cannot extract TLD part", self::INVALID_HOSTNAME => "'%value%' does not match the expected structure for a DNS hostname", + self::INVALID_HOSTNAME_SCHEMA => "'%value%' appears to be a DNS hostname but cannot match against hostname schema for TLD '%tld%'", self::INVALID_LOCAL_NAME => "'%value%' does not appear to be a valid local network name", + self::INVALID_URI => "'%value%' does not appear to be a valid URI hostname", + self::IP_ADDRESS_NOT_ALLOWED => "'%value%' appears to be an IP address, but IP addresses are not allowed", self::LOCAL_NAME_NOT_ALLOWED => "'%value%' appears to be a local network name but local network names are not allowed", - self::CANNOT_DECODE_PUNYCODE => "'%value%' appears to be a DNS hostname but the given punycode notation cannot be decoded", + self::UNDECIPHERABLE_TLD => "'%value%' appears to be a DNS hostname but cannot extract TLD part", + self::UNKNOWN_TLD => "'%value%' appears to be a DNS hostname but cannot match TLD against known list", ); /** @@ -101,6 +103,11 @@ class Zend_Validate_Hostname extends Zend_Validate_Abstract const ALLOW_ALL = 7; /** + * Allows all types of hostnames + */ + const ALLOW_URI = 8; + + /** * Array of valid top-level-domains * * @see ftp://data.iana.org/TLD/tlds-alpha-by-domain.txt List of all TLDs by domain @@ -196,7 +203,7 @@ class Zend_Validate_Hostname extends Zend_Validate_Abstract 'CH' => array(1 => '/^[\x{002d}0-9a-zà-öø-ÿœ]{1,63}$/iu'), 'CL' => array(1 => '/^[\x{002d}0-9a-záéíñóúü]{1,63}$/iu'), 'CN' => 'Hostname/Cn.php', - 'COM' => 'Zend/Validate/Hostname/Com.php', + 'COM' => 'Hostname/Com.php', 'DE' => array(1 => '/^[\x{002d}0-9a-zà-öø-ÿăąāćĉčċďđĕěėęēğĝġģĥħĭĩįīıĵķĺľļłńňņŋŏőōœĸŕřŗśŝšşťţŧŭůűũųūŵŷźžż]{1,63}$/iu'), 'DK' => array(1 => '/^[\x{002d}0-9a-zäéöü]{1,63}$/iu'), 'ES' => array(1 => '/^[\x{002d}0-9a-zàáçèéíïñòóúü·]{1,63}$/iu'), @@ -208,7 +215,7 @@ class Zend_Validate_Hostname extends Zend_Validate_Abstract 6 => '/^[\x{002d}0-9a-zἀ-ἇἐ-ἕἠ-ἧἰ-ἷὀ-ὅὐ-ὗὠ-ὧὰ-ώᾀ-ᾇᾐ-ᾗᾠ-ᾧᾰ-ᾴᾶᾷῂῃῄῆῇῐ-ΐῖῗῠ-ῧῲῳῴῶῷ]{1,63}$/iu'), 'FI' => array(1 => '/^[\x{002d}0-9a-zäåö]{1,63}$/iu'), 'GR' => array(1 => '/^[\x{002d}0-9a-zΆΈΉΊΌΎ-ΡΣ-ώἀ-ἕἘ-Ἕἠ-ὅὈ-Ὅὐ-ὗὙὛὝὟ-ώᾀ-ᾴᾶ-ᾼῂῃῄῆ-ῌῐ-ΐῖ-Ίῠ-Ῥῲῳῴῶ-ῼ]{1,63}$/iu'), - 'HK' => 'Zend/Validate/Hostname/Cn.php', + 'HK' => 'Hostname/Cn.php', 'HU' => array(1 => '/^[\x{002d}0-9a-záéíóöúüőű]{1,63}$/iu'), 'INFO'=> array(1 => '/^[\x{002d}0-9a-zäåæéöøü]{1,63}$/iu', 2 => '/^[\x{002d}0-9a-záéíóöúüőű]{1,63}$/iu', @@ -220,15 +227,15 @@ class Zend_Validate_Hostname extends Zend_Validate_Abstract 8 => '/^[\x{002d}0-9a-záéíñóúü]{1,63}$/iu'), 'IO' => array(1 => '/^[\x{002d}0-9a-zà-öø-ÿăąāćĉčċďđĕěėęēğĝġģĥħĭĩįīıĵķĺľļłńňņŋŏőōœĸŕřŗśŝšşťţŧŭůűũųūŵŷźžż]{1,63}$/iu'), 'IS' => array(1 => '/^[\x{002d}0-9a-záéýúíóþæöð]{1,63}$/iu'), - 'JP' => 'Zend/Validate/Hostname/Jp.php', + 'JP' => 'Hostname/Jp.php', 'KR' => array(1 => '/^[\x{AC00}-\x{D7A3}]{1,17}$/iu'), 'LI' => array(1 => '/^[\x{002d}0-9a-zà-öø-ÿœ]{1,63}$/iu'), 'LT' => array(1 => '/^[\x{002d}0-9ąčęėįšųūž]{1,63}$/iu'), 'MD' => array(1 => '/^[\x{002d}0-9ăâîşţ]{1,63}$/iu'), 'MUSEUM' => array(1 => '/^[\x{002d}0-9a-zà-öø-ÿāăąćċčďđēėęěğġģħīįıķĺļľłńņňŋōőœŕŗřśşšţťŧūůűųŵŷźżžǎǐǒǔ\x{01E5}\x{01E7}\x{01E9}\x{01EF}ə\x{0292}ẁẃẅỳ]{1,63}$/iu'), - 'NET' => 'Zend/Validate/Hostname/Com.php', + 'NET' => 'Hostname/Com.php', 'NO' => array(1 => '/^[\x{002d}0-9a-zàáä-éêñ-ôöøüčđńŋšŧž]{1,63}$/iu'), - 'NU' => 'Zend/Validate/Hostname/Com.php', + 'NU' => 'Hostname/Com.php', 'ORG' => array(1 => '/^[\x{002d}0-9a-záéíñóúü]{1,63}$/iu', 2 => '/^[\x{002d}0-9a-zóąćęłńśźż]{1,63}$/iu', 3 => '/^[\x{002d}0-9a-záäåæéëíðóöøúüýþ]{1,63}$/iu', @@ -279,14 +286,14 @@ class Zend_Validate_Hostname extends Zend_Validate_Abstract 'SJ' => array(1 => '/^[\x{002d}0-9a-zàáä-éêñ-ôöøüčđńŋšŧž]{1,63}$/iu'), 'TH' => array(1 => '/^[\x{002d}0-9a-z\x{0E01}-\x{0E3A}\x{0E40}-\x{0E4D}\x{0E50}-\x{0E59}]{1,63}$/iu'), 'TM' => array(1 => '/^[\x{002d}0-9a-zà-öø-ÿāăąćĉċčďđēėęěĝġģĥħīįĵķĺļľŀłńņňŋőœŕŗřśŝşšţťŧūŭůűųŵŷźżž]{1,63}$/iu'), - 'TW' => 'Zend/Validate/Hostname/Cn.php', + 'TW' => 'Hostname/Cn.php', 'TR' => array(1 => '/^[\x{002d}0-9a-zğıüşöç]{1,63}$/iu'), 'VE' => array(1 => '/^[\x{002d}0-9a-záéíóúüñ]{1,63}$/iu'), 'VN' => array(1 => '/^[ÀÁÂÃÈÉÊÌÍÒÓÔÕÙÚÝàáâãèéêìíòóôõùúýĂăĐđĨĩŨũƠơƯư\x{1EA0}-\x{1EF9}]{1,63}$/iu'), 'ایران' => array(1 => '/^[\x{0621}-\x{0624}\x{0626}-\x{063A}\x{0641}\x{0642}\x{0644}-\x{0648}\x{067E}\x{0686}\x{0698}\x{06A9}\x{06AF}\x{06CC}\x{06F0}-\x{06F9}]{1,30}$/iu'), - '中国' => 'Zend/Validate/Hostname/Cn.php', - '公司' => 'Zend/Validate/Hostname/Cn.php', - '网络' => 'Zend/Validate/Hostname/Cn.php' + '中国' => 'Hostname/Cn.php', + '公司' => 'Hostname/Cn.php', + '网络' => 'Hostname/Cn.php' ); protected $_idnLength = array( @@ -505,6 +512,21 @@ class Zend_Validate_Hostname extends Zend_Validate_Abstract } } + // RFC3986 3.2.2 states: + // + // The rightmost domain label of a fully qualified domain name + // in DNS may be followed by a single "." and should be if it is + // necessary to distinguish between the complete domain name and + // some local domain. + // + // Strip trailing '.' since it is not necessary to validate a non-IP + // hostname. + // + // (see ZF-6363) + if (substr($value, -1) === '.') { + $value = substr($value, 0, strlen($value)-1); + } + // Check input against DNS hostname schema $domainParts = explode('.', $value); if ((count($domainParts) > 1) && (strlen($value) >= 4) && (strlen($value) <= 254)) { @@ -544,7 +566,7 @@ class Zend_Validate_Hostname extends Zend_Validate_Abstract $regexChars = array(0 => '/^[a-z0-9\x2d]{1,63}$/i'); if ($this->_options['idn'] && isset($this->_validIdns[strtoupper($this->_tld)])) { if (is_string($this->_validIdns[strtoupper($this->_tld)])) { - $regexChars += include(dirname(__FILE__) . '/../../' . $this->_validIdns[strtoupper($this->_tld)]); + $regexChars += include(dirname(__FILE__) . DIR_SEPARATOR . $this->_validIdns[strtoupper($this->_tld)]); } else { $regexChars += $this->_validIdns[strtoupper($this->_tld)]; } @@ -617,6 +639,15 @@ class Zend_Validate_Hostname extends Zend_Validate_Abstract $this->_error(self::INVALID_HOSTNAME); } + // Check for URI Syntax (RFC3986) + if ($this->_options['allow'] & self::ALLOW_URI) { + if (preg_match("/^([a-zA-Z0-9-._~!$&\'()*+,;=]|%[[:xdigit:]]{2}){1,254}$/i", $value)) { + return true; + } else { + $this->_error(self::INVALID_URI); + } + } + // Check input against local network name schema; last chance to pass validation $regexLocal = '/^(([a-zA-Z0-9\x2d]{1,63}\x2e)*[a-zA-Z0-9\x2d]{1,63}){1,254}$/'; $status = @preg_match($regexLocal, $value); diff --git a/libs/Zend/Validate/Iban.php b/libs/Zend/Validate/Iban.php index 4b781a09c6..427857a1c7 100644 --- a/libs/Zend/Validate/Iban.php +++ b/libs/Zend/Validate/Iban.php @@ -16,7 +16,7 @@ * @package Zend_Validate * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Iban.php 22401 2010-06-09 19:25:49Z thomas $ + * @version $Id: Iban.php 22400 2010-06-09 19:25:02Z thomas $ */ /** diff --git a/libs/Zend/Validate/Identical.php b/libs/Zend/Validate/Identical.php index 7b37574050..3ebaf028af 100644 --- a/libs/Zend/Validate/Identical.php +++ b/libs/Zend/Validate/Identical.php @@ -16,7 +16,7 @@ * @package Zend_Validate * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Identical.php 22077 2010-05-02 13:44:46Z thomas $ + * @version $Id: Identical.php 22075 2010-05-02 13:42:08Z thomas $ */ /** @see Zend_Validate_Abstract */ diff --git a/libs/Zend/Validate/InArray.php b/libs/Zend/Validate/InArray.php index 3b1870543c..567d3df4d0 100644 --- a/libs/Zend/Validate/InArray.php +++ b/libs/Zend/Validate/InArray.php @@ -16,7 +16,7 @@ * @package Zend_Validate * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: InArray.php 20358 2010-01-17 19:03:49Z thomas $ + * @version $Id: InArray.php 20352 2010-01-17 17:55:38Z thomas $ */ /** diff --git a/libs/Zend/Validate/Int.php b/libs/Zend/Validate/Int.php index 012a58a0ee..2f82b98bfd 100644 --- a/libs/Zend/Validate/Int.php +++ b/libs/Zend/Validate/Int.php @@ -16,7 +16,7 @@ * @package Zend_Validate * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Int.php 22697 2010-07-26 21:14:47Z alexander $ + * @version $Id: Int.php 22668 2010-07-25 14:50:46Z thomas $ */ /** @@ -44,7 +44,7 @@ class Zend_Validate_Int extends Zend_Validate_Abstract * @var array */ protected $_messageTemplates = array( - self::INVALID => "Invalid type given, value should be string or integer", + self::INVALID => "Invalid type given. String or integer expected", self::NOT_INT => "'%value%' does not appear to be an integer", ); diff --git a/libs/Zend/Validate/Interface.php b/libs/Zend/Validate/Interface.php index 9dfca94219..f683b60f02 100644 --- a/libs/Zend/Validate/Interface.php +++ b/libs/Zend/Validate/Interface.php @@ -16,7 +16,7 @@ * @package Zend_Validate * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Interface.php 20358 2010-01-17 19:03:49Z thomas $ + * @version $Id: Interface.php 23262 2010-10-27 14:03:36Z matthew $ */ /** @@ -36,7 +36,7 @@ interface Zend_Validate_Interface * * @param mixed $value * @return boolean - * @throws Zend_Valid_Exception If validation of $value is impossible + * @throws Zend_Validate_Exception If validation of $value is impossible */ public function isValid($value); diff --git a/libs/Zend/Validate/Ip.php b/libs/Zend/Validate/Ip.php index 8cb9a1e379..091ff9b615 100644 --- a/libs/Zend/Validate/Ip.php +++ b/libs/Zend/Validate/Ip.php @@ -16,7 +16,7 @@ * @package Zend_Validate * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Ip.php 22697 2010-07-26 21:14:47Z alexander $ + * @version $Id: Ip.php 22668 2010-07-25 14:50:46Z thomas $ */ /** @@ -39,7 +39,7 @@ class Zend_Validate_Ip extends Zend_Validate_Abstract * @var array */ protected $_messageTemplates = array( - self::INVALID => "Invalid type given, value should be a string", + self::INVALID => "Invalid type given. String expected", self::NOT_IP_ADDRESS => "'%value%' does not appear to be a valid IP address", ); diff --git a/libs/Zend/Validate/Isbn.php b/libs/Zend/Validate/Isbn.php index 61ebf0b9a8..5c78872faf 100644 --- a/libs/Zend/Validate/Isbn.php +++ b/libs/Zend/Validate/Isbn.php @@ -16,7 +16,7 @@ * @package Zend_Validate * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Isbn.php 22697 2010-07-26 21:14:47Z alexander $ + * @version $Id: Isbn.php 22668 2010-07-25 14:50:46Z thomas $ */ /** @@ -44,7 +44,7 @@ class Zend_Validate_Isbn extends Zend_Validate_Abstract * @var array */ protected $_messageTemplates = array( - self::INVALID => "Invalid type given, value should be string or integer", + self::INVALID => "Invalid type given. String or integer expected", self::NO_ISBN => "'%value%' is no valid ISBN number", ); diff --git a/libs/Zend/Validate/NotEmpty.php b/libs/Zend/Validate/NotEmpty.php index 150efddbde..584e290887 100644 --- a/libs/Zend/Validate/NotEmpty.php +++ b/libs/Zend/Validate/NotEmpty.php @@ -16,7 +16,7 @@ * @package Zend_Validate * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: NotEmpty.php 22697 2010-07-26 21:14:47Z alexander $ + * @version $Id: NotEmpty.php 22691 2010-07-26 19:29:14Z thomas $ */ /** @@ -70,7 +70,7 @@ class Zend_Validate_NotEmpty extends Zend_Validate_Abstract */ protected $_messageTemplates = array( self::IS_EMPTY => "Value is required and can't be empty", - self::INVALID => "Invalid type given, value should be float, string, array, boolean or integer", + self::INVALID => "Invalid type given. String, integer, float, boolean or array expected", ); /** diff --git a/libs/Zend/Validate/PostCode.php b/libs/Zend/Validate/PostCode.php index 9f7ea69e63..4aa1cd1d31 100644 --- a/libs/Zend/Validate/PostCode.php +++ b/libs/Zend/Validate/PostCode.php @@ -16,7 +16,7 @@ * @package Zend_Validate * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: PostCode.php 22697 2010-07-26 21:14:47Z alexander $ + * @version $Id: PostCode.php 22668 2010-07-25 14:50:46Z thomas $ */ /** @@ -44,7 +44,7 @@ class Zend_Validate_PostCode extends Zend_Validate_Abstract * @var array */ protected $_messageTemplates = array( - self::INVALID => "Invalid type given. The value should be a string or a integer", + self::INVALID => "Invalid type given. String or integer expected", self::NO_MATCH => "'%value%' does not appear to be a postal code", ); diff --git a/libs/Zend/Validate/Regex.php b/libs/Zend/Validate/Regex.php index ff7cbb5252..4784d2ae92 100644 --- a/libs/Zend/Validate/Regex.php +++ b/libs/Zend/Validate/Regex.php @@ -16,7 +16,7 @@ * @package Zend_Validate * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Regex.php 22697 2010-07-26 21:14:47Z alexander $ + * @version $Id: Regex.php 22668 2010-07-25 14:50:46Z thomas $ */ /** @@ -40,7 +40,7 @@ class Zend_Validate_Regex extends Zend_Validate_Abstract * @var array */ protected $_messageTemplates = array( - self::INVALID => "Invalid type given, value should be string, integer or float", + self::INVALID => "Invalid type given. String, integer or float expected", self::NOT_MATCH => "'%value%' does not match against pattern '%pattern%'", self::ERROROUS => "There was an internal error while using the pattern '%pattern%'", ); diff --git a/libs/Zend/Validate/Sitemap/Changefreq.php b/libs/Zend/Validate/Sitemap/Changefreq.php index 3f190efa0f..39532e7775 100644 --- a/libs/Zend/Validate/Sitemap/Changefreq.php +++ b/libs/Zend/Validate/Sitemap/Changefreq.php @@ -17,7 +17,7 @@ * @subpackage Sitemap * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Changefreq.php 22697 2010-07-26 21:14:47Z alexander $ + * @version $Id: Changefreq.php 22668 2010-07-25 14:50:46Z thomas $ */ /** @@ -52,7 +52,7 @@ class Zend_Validate_Sitemap_Changefreq extends Zend_Validate_Abstract */ protected $_messageTemplates = array( self::NOT_VALID => "'%value%' is no valid sitemap changefreq", - self::INVALID => "Invalid type given, the value should be a string", + self::INVALID => "Invalid type given. String expected", ); /** diff --git a/libs/Zend/Validate/Sitemap/Lastmod.php b/libs/Zend/Validate/Sitemap/Lastmod.php index 362e562eac..2495d0ba68 100644 --- a/libs/Zend/Validate/Sitemap/Lastmod.php +++ b/libs/Zend/Validate/Sitemap/Lastmod.php @@ -17,7 +17,7 @@ * @subpackage Sitemap * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Lastmod.php 22697 2010-07-26 21:14:47Z alexander $ + * @version $Id: Lastmod.php 22668 2010-07-25 14:50:46Z thomas $ */ /** @@ -58,7 +58,7 @@ class Zend_Validate_Sitemap_Lastmod extends Zend_Validate_Abstract */ protected $_messageTemplates = array( self::NOT_VALID => "'%value%' is no valid sitemap lastmod", - self::INVALID => "Invalid type given, the value should be a string", + self::INVALID => "Invalid type given. String expected", ); /** diff --git a/libs/Zend/Validate/Sitemap/Loc.php b/libs/Zend/Validate/Sitemap/Loc.php index d4df42e307..15eea11862 100644 --- a/libs/Zend/Validate/Sitemap/Loc.php +++ b/libs/Zend/Validate/Sitemap/Loc.php @@ -17,7 +17,7 @@ * @subpackage Sitemap * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Loc.php 22697 2010-07-26 21:14:47Z alexander $ + * @version $Id: Loc.php 22668 2010-07-25 14:50:46Z thomas $ */ /** @@ -57,7 +57,7 @@ class Zend_Validate_Sitemap_Loc extends Zend_Validate_Abstract */ protected $_messageTemplates = array( self::NOT_VALID => "'%value%' is no valid sitemap location", - self::INVALID => "Invalid type given, the value should be a string", + self::INVALID => "Invalid type given. String expected", ); /** diff --git a/libs/Zend/Validate/Sitemap/Priority.php b/libs/Zend/Validate/Sitemap/Priority.php index 8d340de900..04fd997d61 100644 --- a/libs/Zend/Validate/Sitemap/Priority.php +++ b/libs/Zend/Validate/Sitemap/Priority.php @@ -17,7 +17,7 @@ * @subpackage Sitemap * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Priority.php 22697 2010-07-26 21:14:47Z alexander $ + * @version $Id: Priority.php 22668 2010-07-25 14:50:46Z thomas $ */ /** @@ -52,7 +52,7 @@ class Zend_Validate_Sitemap_Priority extends Zend_Validate_Abstract */ protected $_messageTemplates = array( self::NOT_VALID => "'%value%' is no valid sitemap priority", - self::INVALID => "Invalid type given, the value should be a integer, a float or a numeric string", + self::INVALID => "Invalid type given. Numeric string, integer or float expected", ); /** diff --git a/libs/Zend/Validate/StringLength.php b/libs/Zend/Validate/StringLength.php index 807269178f..3b94792788 100644 --- a/libs/Zend/Validate/StringLength.php +++ b/libs/Zend/Validate/StringLength.php @@ -16,7 +16,7 @@ * @package Zend_Validate * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: StringLength.php 22697 2010-07-26 21:14:47Z alexander $ + * @version $Id: StringLength.php 22668 2010-07-25 14:50:46Z thomas $ */ /** @@ -40,7 +40,7 @@ class Zend_Validate_StringLength extends Zend_Validate_Abstract * @var array */ protected $_messageTemplates = array( - self::INVALID => "Invalid type given, value should be a string", + self::INVALID => "Invalid type given. String expected", self::TOO_SHORT => "'%value%' is less than %min% characters long", self::TOO_LONG => "'%value%' is more than %max% characters long", ); diff --git a/libs/Zend/Version.php b/libs/Zend/Version.php index 5bb57f0ac5..6674ab2fde 100644 --- a/libs/Zend/Version.php +++ b/libs/Zend/Version.php @@ -16,7 +16,7 @@ * @package Zend_Version * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Version.php 22703 2010-07-27 12:38:42Z matthew $ + * @version $Id: Version.php 23585 2010-12-28 19:52:52Z matthew $ */ /** @@ -32,14 +32,21 @@ final class Zend_Version /** * Zend Framework version identification - see compareVersion() */ - const VERSION = '1.10.7'; + const VERSION = '1.11.2'; + + /** + * The latest stable version Zend Framework available + * + * @var string + */ + protected static $_lastestVersion; /** * Compare the specified Zend Framework version string $version * with the current Zend_Version::VERSION of Zend Framework. * * @param string $version A version string (e.g. "0.7.1"). - * @return boolean -1 if the $version is older, + * @return int -1 if the $version is older, * 0 if they are the same, * and +1 if $version is newer. * @@ -50,4 +57,25 @@ final class Zend_Version $version = preg_replace('/(\d)pr(\d?)/', '$1a$2', $version); return version_compare($version, strtolower(self::VERSION)); } + + /** + * Fetches the version of the latest stable release + * + * @link http://framework.zend.com/download/latest + * @return string + */ + public static function getLatest() + { + if (null === self::$_lastestVersion) { + self::$_lastestVersion = 'not available'; + + $handle = fopen('http://framework.zend.com/api/zf-version', 'r'); + if (false !== $handle) { + self::$_lastestVersion = stream_get_contents($handle); + fclose($handle); + } + } + + return self::$_lastestVersion; + } } |