diff options
author | robocoder <anthon.pang@gmail.com> | 2010-01-29 12:02:30 +0300 |
---|---|---|
committer | robocoder <anthon.pang@gmail.com> | 2010-01-29 12:02:30 +0300 |
commit | 1378f79297baa84590738839ec11cef90ac21bc4 (patch) | |
tree | 61b8272e59891a9d5d175d8a883a978fd913daf0 /libs/Zend | |
parent | f156256d1f2537e6e448c7b8b5852d59a0e9099e (diff) |
update wrt Zend Framework 1.10.0; remove svn:eol-style property
git-svn-id: http://dev.piwik.org/svn/trunk@1813 59fd770c-687e-43c8-a1e3-f5a4ff64c105
Diffstat (limited to 'libs/Zend')
377 files changed, 18615 insertions, 2349 deletions
diff --git a/libs/Zend/Auth.php b/libs/Zend/Auth.php index 106a663845..5bd2b96d4f 100644 --- a/libs/Zend/Auth.php +++ b/libs/Zend/Auth.php @@ -14,16 +14,16 @@ * * @category Zend * @package Zend_Auth - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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: Auth.php 18951 2009-11-12 16:26:19Z alexander $ + * @version $Id: Auth.php 20096 2010-01-06 02:05:09Z bkarwin $ */ /** * @category Zend * @package Zend_Auth - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Auth diff --git a/libs/Zend/Auth/Adapter/DbTable.php b/libs/Zend/Auth/Adapter/DbTable.php index 90206f5d72..908423f640 100644 --- a/libs/Zend/Auth/Adapter/DbTable.php +++ b/libs/Zend/Auth/Adapter/DbTable.php @@ -14,10 +14,10 @@ * * @category Zend * @package Zend_Auth - * @subpackage Zend_Auth_Adapter - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 18951 2009-11-12 16:26:19Z alexander $ + * @version $Id: DbTable.php 20096 2010-01-06 02:05:09Z bkarwin $ */ @@ -40,8 +40,8 @@ require_once 'Zend/Auth/Result.php'; /** * @category Zend * @package Zend_Auth - * @subpackage Zend_Auth_Adapter - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 */ class Zend_Auth_Adapter_DbTable implements Zend_Auth_Adapter_Interface @@ -185,7 +185,7 @@ class Zend_Auth_Adapter_DbTable implements Zend_Auth_Adapter_Interface /** * setCredentialTreatment() - allows the developer to pass a parameterized string that is - * used to transform or treat the input credential data + * used to transform or treat the input credential data. * * In many cases, passwords and other sensitive data are encrypted, hashed, encoded, * obscured, or otherwise treated through some function or algorithm. By specifying a @@ -292,8 +292,8 @@ class Zend_Auth_Adapter_DbTable implements Zend_Auth_Adapter_Interface /** * authenticate() - defined by Zend_Auth_Adapter_Interface. This method is called to - * attempt an authenication. Previous to this call, this adapter would have already - * been configured with all nessissary information to successfully connect to a database + * attempt an authentication. Previous to this call, this adapter would have already + * been configured with all necessary information to successfully connect to a database * table and attempt to find a record matching the provided identity. * * @throws Zend_Auth_Adapter_Exception if answering the authentication query is impossible @@ -314,8 +314,9 @@ class Zend_Auth_Adapter_DbTable implements Zend_Auth_Adapter_Interface } /** - * _authenticateSetup() - This method abstracts the steps involved with making sure - * that this adapter was indeed setup properly with all required peices of information. + * _authenticateSetup() - This method abstracts the steps involved with + * making sure that this adapter was indeed setup properly with all + * required pieces of information. * * @throws Zend_Auth_Adapter_Exception - in the event that setup was not done properly * @return true @@ -391,7 +392,8 @@ class Zend_Auth_Adapter_DbTable implements Zend_Auth_Adapter_Interface * performs a query against the database with that object. * * @param Zend_Db_Select $dbSelect - * @throws Zend_Auth_Adapter_Exception - when a invalid select object is encoutered + * @throws Zend_Auth_Adapter_Exception - when an invalid select + * object is encountered * @return array */ protected function _authenticateQuerySelect(Zend_Db_Select $dbSelect) @@ -413,14 +415,14 @@ class Zend_Auth_Adapter_DbTable implements Zend_Auth_Adapter_Interface require_once 'Zend/Auth/Adapter/Exception.php'; throw new Zend_Auth_Adapter_Exception('The supplied parameters to Zend_Auth_Adapter_DbTable failed to ' . 'produce a valid sql statement, please check table and column names ' - . 'for validity.'); + . 'for validity.', 0, $e); } return $resultIdentities; } /** - * _authenticateValidateResultSet() - This method attempts to make certian that only one - * record was returned in the result set + * _authenticateValidateResultSet() - This method attempts to make + * certain that only one record was returned in the resultset * * @param array $resultIdentities * @return true|Zend_Auth_Result @@ -442,8 +444,9 @@ class Zend_Auth_Adapter_DbTable implements Zend_Auth_Adapter_Interface } /** - * _authenticateValidateResult() - This method attempts to validate that the record in the - * result set is indeed a record that matched the identity provided to this adapter. + * _authenticateValidateResult() - This method attempts to validate that + * the record in the resultset is indeed a record that matched the + * identity provided to this adapter. * * @param array $resultIdentity * @return Zend_Auth_Result @@ -467,8 +470,8 @@ class Zend_Auth_Adapter_DbTable implements Zend_Auth_Adapter_Interface } /** - * _authenticateCreateAuthResult() - This method creates a Zend_Auth_Result object - * from the information that has been collected during the authenticate() attempt. + * _authenticateCreateAuthResult() - Creates a Zend_Auth_Result object from + * the information that has been collected during the authenticate() attempt. * * @return Zend_Auth_Result */ diff --git a/libs/Zend/Auth/Adapter/Digest.php b/libs/Zend/Auth/Adapter/Digest.php index 259ae3f3cd..90b79a8363 100644 --- a/libs/Zend/Auth/Adapter/Digest.php +++ b/libs/Zend/Auth/Adapter/Digest.php @@ -14,10 +14,10 @@ * * @category Zend * @package Zend_Auth - * @subpackage Zend_Auth_Adapter - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 16200 2009-06-21 18:50:06Z thomas $ + * @version $Id: Digest.php 20096 2010-01-06 02:05:09Z bkarwin $ */ @@ -30,8 +30,8 @@ require_once 'Zend/Auth/Adapter/Interface.php'; /** * @category Zend * @package Zend_Auth - * @subpackage Zend_Auth_Adapter - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 */ class Zend_Auth_Adapter_Digest implements Zend_Auth_Adapter_Interface diff --git a/libs/Zend/Auth/Adapter/Exception.php b/libs/Zend/Auth/Adapter/Exception.php index 0b5a4d43cf..aee0a014b3 100644 --- a/libs/Zend/Auth/Adapter/Exception.php +++ b/libs/Zend/Auth/Adapter/Exception.php @@ -14,10 +14,10 @@ * * @category Zend * @package Zend_Auth - * @subpackage Zend_Auth_Adapter - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 16200 2009-06-21 18:50:06Z thomas $ + * @version $Id: Exception.php 20096 2010-01-06 02:05:09Z bkarwin $ */ @@ -30,8 +30,8 @@ require_once 'Zend/Auth/Exception.php'; /** * @category Zend * @package Zend_Auth - * @subpackage Zend_Auth_Adapter - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 */ class Zend_Auth_Adapter_Exception extends Zend_Auth_Exception diff --git a/libs/Zend/Auth/Adapter/Http.php b/libs/Zend/Auth/Adapter/Http.php index ef4997a8d8..7edbc628bc 100644 --- a/libs/Zend/Auth/Adapter/Http.php +++ b/libs/Zend/Auth/Adapter/Http.php @@ -15,9 +15,9 @@ * @category Zend * @package Zend_Auth * @subpackage Zend_Auth_Adapter_Http - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 18951 2009-11-12 16:26:19Z alexander $ + * @version $Id: Http.php 20096 2010-01-06 02:05:09Z bkarwin $ */ @@ -35,7 +35,7 @@ require_once 'Zend/Auth/Adapter/Interface.php'; * @category Zend * @package Zend_Auth * @subpackage Zend_Auth_Adapter_Http - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License * @todo Support auth-int * @todo Track nonces, nonce-count, opaque for replay protection and stale support diff --git a/libs/Zend/Auth/Adapter/Http/Resolver/Exception.php b/libs/Zend/Auth/Adapter/Http/Resolver/Exception.php index cb7b18be0d..3e927f51f4 100644 --- a/libs/Zend/Auth/Adapter/Http/Resolver/Exception.php +++ b/libs/Zend/Auth/Adapter/Http/Resolver/Exception.php @@ -15,9 +15,9 @@ * @category Zend * @package Zend_Auth * @subpackage Zend_Auth_Adapter_Http - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 16200 2009-06-21 18:50:06Z thomas $ + * @version $Id: Exception.php 20096 2010-01-06 02:05:09Z bkarwin $ */ @@ -33,7 +33,7 @@ require_once 'Zend/Auth/Exception.php'; * @category Zend * @package Zend_Auth * @subpackage Zend_Auth_Adapter_Http - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Auth_Adapter_Http_Resolver_Exception extends Zend_Auth_Exception diff --git a/libs/Zend/Auth/Adapter/Http/Resolver/File.php b/libs/Zend/Auth/Adapter/Http/Resolver/File.php index 39b548ca66..dfcb087daf 100644 --- a/libs/Zend/Auth/Adapter/Http/Resolver/File.php +++ b/libs/Zend/Auth/Adapter/Http/Resolver/File.php @@ -15,9 +15,9 @@ * @category Zend * @package Zend_Auth * @subpackage Zend_Auth_Adapter_Http - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 16200 2009-06-21 18:50:06Z thomas $ + * @version $Id: File.php 20096 2010-01-06 02:05:09Z bkarwin $ */ @@ -33,7 +33,7 @@ require_once 'Zend/Auth/Adapter/Http/Resolver/Interface.php'; * @category Zend * @package Zend_Auth * @subpackage Zend_Auth_Adapter_Http - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Auth_Adapter_Http_Resolver_File implements Zend_Auth_Adapter_Http_Resolver_Interface diff --git a/libs/Zend/Auth/Adapter/Http/Resolver/Interface.php b/libs/Zend/Auth/Adapter/Http/Resolver/Interface.php index d36a0125a2..78c0343147 100644 --- a/libs/Zend/Auth/Adapter/Http/Resolver/Interface.php +++ b/libs/Zend/Auth/Adapter/Http/Resolver/Interface.php @@ -15,9 +15,9 @@ * @category Zend * @package Zend_Auth * @subpackage Zend_Auth_Adapter_Http - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 16200 2009-06-21 18:50:06Z thomas $ + * @version $Id: Interface.php 20096 2010-01-06 02:05:09Z bkarwin $ */ @@ -30,7 +30,7 @@ * @category Zend * @package Zend_Auth * @subpackage Zend_Auth_Adapter_Http - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Auth_Adapter_Http_Resolver_Interface diff --git a/libs/Zend/Auth/Adapter/InfoCard.php b/libs/Zend/Auth/Adapter/InfoCard.php index 1af3a08616..a2f57329d4 100644 --- a/libs/Zend/Auth/Adapter/InfoCard.php +++ b/libs/Zend/Auth/Adapter/InfoCard.php @@ -15,9 +15,9 @@ * @category Zend * @package Zend_Auth * @subpackage Zend_Auth_Adapter - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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: InfoCard.php 16200 2009-06-21 18:50:06Z thomas $ + * @version $Id: InfoCard.php 20096 2010-01-06 02:05:09Z bkarwin $ */ /** @@ -42,7 +42,7 @@ require_once 'Zend/InfoCard.php'; * @category Zend * @package Zend_Auth * @subpackage Zend_Auth_Adapter - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Auth_Adapter_InfoCard implements Zend_Auth_Adapter_Interface diff --git a/libs/Zend/Auth/Adapter/Interface.php b/libs/Zend/Auth/Adapter/Interface.php index 67cb6b8b02..d2c3207e31 100644 --- a/libs/Zend/Auth/Adapter/Interface.php +++ b/libs/Zend/Auth/Adapter/Interface.php @@ -15,9 +15,9 @@ * @category Zend * @package Zend_Auth * @subpackage Zend_Auth_Adapter - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 16200 2009-06-21 18:50:06Z thomas $ + * @version $Id: Interface.php 20096 2010-01-06 02:05:09Z bkarwin $ */ @@ -31,7 +31,7 @@ require_once 'Zend/Auth/Result.php'; * @category Zend * @package Zend_Auth * @subpackage Zend_Auth_Adapter - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Auth_Adapter_Interface diff --git a/libs/Zend/Auth/Adapter/Ldap.php b/libs/Zend/Auth/Adapter/Ldap.php index 0a560ad821..6d86a4423a 100644 --- a/libs/Zend/Auth/Adapter/Ldap.php +++ b/libs/Zend/Auth/Adapter/Ldap.php @@ -15,9 +15,9 @@ * @category Zend * @package Zend_Auth * @subpackage Zend_Auth_Adapter - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 18882 2009-11-06 10:57:58Z sgehrig $ + * @version $Id: Ldap.php 20096 2010-01-06 02:05:09Z bkarwin $ */ /** @@ -29,7 +29,7 @@ require_once 'Zend/Auth/Adapter/Interface.php'; * @category Zend * @package Zend_Auth * @subpackage Zend_Auth_Adapter - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Auth_Adapter_Ldap implements Zend_Auth_Adapter_Interface @@ -466,7 +466,7 @@ class Zend_Auth_Adapter_Ldap implements Zend_Auth_Adapter_Interface /** * getAccountObject() - Returns the result entry as a stdClass object * - * This ressembles the feature {@see Zend_Auth_Adapter_DbTable::getResultRowObject()}. + * This resembles the feature {@see Zend_Auth_Adapter_DbTable::getResultRowObject()}. * Closes ZF-6813 * * @param array $returnAttribs diff --git a/libs/Zend/Auth/Adapter/OpenId.php b/libs/Zend/Auth/Adapter/OpenId.php index 44e4684456..1d55605ab1 100644 --- a/libs/Zend/Auth/Adapter/OpenId.php +++ b/libs/Zend/Auth/Adapter/OpenId.php @@ -15,9 +15,9 @@ * @category Zend * @package Zend_Auth * @subpackage Zend_Auth_Adapter - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 16200 2009-06-21 18:50:06Z thomas $ + * @version $Id: OpenId.php 20096 2010-01-06 02:05:09Z bkarwin $ */ @@ -40,7 +40,7 @@ require_once 'Zend/OpenId/Consumer.php'; * @category Zend * @package Zend_Auth * @subpackage Zend_Auth_Adapter - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Auth_Adapter_OpenId implements Zend_Auth_Adapter_Interface diff --git a/libs/Zend/Auth/Exception.php b/libs/Zend/Auth/Exception.php index c71f41c505..933ce1c0d8 100644 --- a/libs/Zend/Auth/Exception.php +++ b/libs/Zend/Auth/Exception.php @@ -14,9 +14,9 @@ * * @category Zend * @package Zend_Auth - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 16200 2009-06-21 18:50:06Z thomas $ + * @version $Id: Exception.php 20096 2010-01-06 02:05:09Z bkarwin $ */ @@ -29,7 +29,7 @@ require_once 'Zend/Exception.php'; /** * @category Zend * @package Zend_Auth - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Auth_Exception extends Zend_Exception diff --git a/libs/Zend/Auth/Result.php b/libs/Zend/Auth/Result.php index 18ba1023f9..964d44d80d 100644 --- a/libs/Zend/Auth/Result.php +++ b/libs/Zend/Auth/Result.php @@ -14,16 +14,16 @@ * * @category Zend * @package Zend_Auth - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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: Result.php 16200 2009-06-21 18:50:06Z thomas $ + * @version $Id: Result.php 20096 2010-01-06 02:05:09Z bkarwin $ */ /** * @category Zend * @package Zend_Auth - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Auth_Result diff --git a/libs/Zend/Auth/Storage/Exception.php b/libs/Zend/Auth/Storage/Exception.php index 6f3af444c0..d45afe7e90 100644 --- a/libs/Zend/Auth/Storage/Exception.php +++ b/libs/Zend/Auth/Storage/Exception.php @@ -14,10 +14,10 @@ * * @category Zend * @package Zend_Auth - * @subpackage Zend_Auth_Storage - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @subpackage Storage + * @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 16200 2009-06-21 18:50:06Z thomas $ + * @version $Id: Exception.php 20096 2010-01-06 02:05:09Z bkarwin $ */ @@ -30,8 +30,8 @@ require_once 'Zend/Auth/Exception.php'; /** * @category Zend * @package Zend_Auth - * @subpackage Zend_Auth_Storage - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @subpackage Storage + * @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_Auth_Storage_Exception extends Zend_Auth_Exception diff --git a/libs/Zend/Auth/Storage/Interface.php b/libs/Zend/Auth/Storage/Interface.php index a604a0d8c6..9fedf01322 100644 --- a/libs/Zend/Auth/Storage/Interface.php +++ b/libs/Zend/Auth/Storage/Interface.php @@ -14,18 +14,17 @@ * * @category Zend * @package Zend_Auth - * @subpackage Zend_Auth_Storage - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @subpackage Storage + * @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 16200 2009-06-21 18:50:06Z thomas $ + * @version $Id: Interface.php 20096 2010-01-06 02:05:09Z bkarwin $ */ - /** * @category Zend * @package Zend_Auth - * @subpackage Zend_Auth_Storage - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @subpackage Storage + * @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_Auth_Storage_Interface diff --git a/libs/Zend/Auth/Storage/NonPersistent.php b/libs/Zend/Auth/Storage/NonPersistent.php index 6c544fff4b..c8101e9da3 100644 --- a/libs/Zend/Auth/Storage/NonPersistent.php +++ b/libs/Zend/Auth/Storage/NonPersistent.php @@ -14,10 +14,10 @@ * * @category Zend * @package Zend_Auth - * @subpackage Zend_Auth_Storage - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @subpackage Storage + * @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 16200 2009-06-21 18:50:06Z thomas $ + * @version $Id: NonPersistent.php 20096 2010-01-06 02:05:09Z bkarwin $ */ @@ -36,8 +36,8 @@ require_once 'Zend/Auth/Storage/Interface.php'; * * @category Zend * @package Zend_Auth - * @subpackage Zend_Auth_Storage - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @subpackage Storage + * @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_Auth_Storage_NonPersistent implements Zend_Auth_Storage_Interface @@ -47,7 +47,6 @@ class Zend_Auth_Storage_NonPersistent implements Zend_Auth_Storage_Interface */ protected $_data; - /** * Returns true if and only if storage is empty * diff --git a/libs/Zend/Auth/Storage/Session.php b/libs/Zend/Auth/Storage/Session.php index 14027968b0..60579dbe9b 100644 --- a/libs/Zend/Auth/Storage/Session.php +++ b/libs/Zend/Auth/Storage/Session.php @@ -14,10 +14,10 @@ * * @category Zend * @package Zend_Auth - * @subpackage Zend_Auth_Storage - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @subpackage Storage + * @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 16200 2009-06-21 18:50:06Z thomas $ + * @version $Id: Session.php 20096 2010-01-06 02:05:09Z bkarwin $ */ @@ -36,8 +36,8 @@ require_once 'Zend/Session.php'; /** * @category Zend * @package Zend_Auth - * @subpackage Zend_Auth_Storage - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @subpackage Storage + * @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_Auth_Storage_Session implements Zend_Auth_Storage_Interface diff --git a/libs/Zend/Cache.php b/libs/Zend/Cache.php index a358bd2e26..3792511511 100644 --- a/libs/Zend/Cache.php +++ b/libs/Zend/Cache.php @@ -14,15 +14,15 @@ * * @category Zend * @package Zend_Cache - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 18951 2009-11-12 16:26:19Z alexander $ + * @version $Id: Cache.php 20096 2010-01-06 02:05:09Z bkarwin $ */ /** * @package Zend_Cache - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Cache @@ -201,11 +201,11 @@ abstract class Zend_Cache * @param string $msg Message for the exception * @throws Zend_Cache_Exception */ - public static function throwException($msg) + public static function throwException($msg, Exception $e = null) { // For perfs reasons, we use this dynamic inclusion require_once 'Zend/Cache/Exception.php'; - throw new Zend_Cache_Exception($msg); + throw new Zend_Cache_Exception($msg, 0, $e); } /** diff --git a/libs/Zend/Cache/Backend.php b/libs/Zend/Cache/Backend.php index c157f54915..8a99ca03d5 100644 --- a/libs/Zend/Cache/Backend.php +++ b/libs/Zend/Cache/Backend.php @@ -15,16 +15,16 @@ * @category Zend * @package Zend_Cache * @subpackage Zend_Cache_Backend - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 18951 2009-11-12 16:26:19Z alexander $ + * @version $Id: Backend.php 20096 2010-01-06 02:05:09Z bkarwin $ */ /** * @package Zend_Cache * @subpackage Zend_Cache_Backend - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 @@ -232,7 +232,7 @@ class Zend_Cache_Backend */ require_once 'Zend/Log.php'; } catch (Zend_Exception $e) { - Zend_Cache::throwException('Logging feature is enabled but the Zend_Log class is not available'); + Zend_Cache::throwException('Logging feature is enabled but the Zend_Log class is not available', $e); } if (isset($this->_directives['logger'])) { if ($this->_directives['logger'] instanceof Zend_Log) { diff --git a/libs/Zend/Cache/Backend/Apc.php b/libs/Zend/Cache/Backend/Apc.php index 07c6b93a08..0a13a57720 100644 --- a/libs/Zend/Cache/Backend/Apc.php +++ b/libs/Zend/Cache/Backend/Apc.php @@ -15,9 +15,9 @@ * @category Zend * @package Zend_Cache * @subpackage Zend_Cache_Backend - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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: Apc.php 18951 2009-11-12 16:26:19Z alexander $ + * @version $Id: Apc.php 20096 2010-01-06 02:05:09Z bkarwin $ */ @@ -35,7 +35,7 @@ require_once 'Zend/Cache/Backend.php'; /** * @package Zend_Cache * @subpackage Zend_Cache_Backend - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Apc extends Zend_Cache_Backend implements Zend_Cache_Backend_ExtendedInterface diff --git a/libs/Zend/Cache/Backend/BlackHole.php b/libs/Zend/Cache/Backend/BlackHole.php new file mode 100644 index 0000000000..9ae72f3972 --- /dev/null +++ b/libs/Zend/Cache/Backend/BlackHole.php @@ -0,0 +1,250 @@ +<?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: BlackHole.php 17867 2009-08-28 09:42:11Z yoshida@zend.co.jp $ + */ + +/** + * @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_BlackHole + extends Zend_Cache_Backend + implements Zend_Cache_Backend_ExtendedInterface +{ + /** + * 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) + { + return false; + } + + /** + * Test if a cache is available or not (for the given id) + * + * @param string $id cache id + * @return mixed false (a cache is not available) or "last modified" timestamp (int) of the available cache record + */ + public function test($id) + { + 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) + { + return true; + } + + /** + * Remove a cache record + * + * @param string $id cache id + * @return boolean true if no problem + */ + public function remove($id) + { + return true; + } + + /** + * Clean some cache records + * + * Available modes are : + * 'all' (default) => remove all cache entries ($tags is not used) + * 'old' => remove too old cache entries ($tags is not used) + * 'matchingTag' => remove cache entries matching all given tags + * ($tags can be an array of strings or a single string) + * 'notMatchingTag' => remove cache entries not matching one of the given tags + * ($tags can be an array of strings or a single string) + * 'matchingAnyTag' => remove cache entries matching any given tags + * ($tags can be an array of strings or a single string) + * + * @param string $mode clean mode + * @param tags array $tags array of tags + * @return boolean true if no problem + */ + public function clean($mode = Zend_Cache::CLEANING_MODE_ALL, $tags = array()) + { + return true; + } + + /** + * Return an array of stored cache ids + * + * @return array array of stored cache ids (string) + */ + public function getIds() + { + return array(); + } + + /** + * Return an array of stored tags + * + * @return array array of stored tags (string) + */ + public function getTags() + { + 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()) + { + 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()) + { + 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()) + { + return array(); + } + + /** + * Return the filling percentage of the backend storage + * + * @return int integer between 0 and 100 + * @throws Zend_Cache_Exception + */ + public function getFillingPercentage() + { + return 0; + } + + /** + * 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) + { + 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) + { + 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' => true, + 'tags' => true, + 'expired_read' => true, + 'priority' => true, + 'infinite_lifetime' => true, + 'get_list' => true, + ); + } + + /** + * PUBLIC METHOD FOR UNIT TESTING ONLY ! + * + * Force a cache record to expire + * + * @param string $id cache id + */ + public function ___expire($id) + { + } +} diff --git a/libs/Zend/Cache/Backend/ExtendedInterface.php b/libs/Zend/Cache/Backend/ExtendedInterface.php index aa0d730fcd..ec735a476e 100644 --- a/libs/Zend/Cache/Backend/ExtendedInterface.php +++ b/libs/Zend/Cache/Backend/ExtendedInterface.php @@ -15,9 +15,9 @@ * @category Zend * @package Zend_Cache * @subpackage Zend_Cache_Backend - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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: ExtendedInterface.php 18951 2009-11-12 16:26:19Z alexander $ + * @version $Id: ExtendedInterface.php 20096 2010-01-06 02:05:09Z bkarwin $ */ /** @@ -28,7 +28,7 @@ require_once 'Zend/Cache/Backend/Interface.php'; /** * @package Zend_Cache * @subpackage Zend_Cache_Backend - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Cache_Backend_ExtendedInterface extends Zend_Cache_Backend_Interface diff --git a/libs/Zend/Cache/Backend/File.php b/libs/Zend/Cache/Backend/File.php index 51e2697ad9..3f86e30f53 100644 --- a/libs/Zend/Cache/Backend/File.php +++ b/libs/Zend/Cache/Backend/File.php @@ -15,9 +15,9 @@ * @category Zend * @package Zend_Cache * @subpackage Zend_Cache_Backend - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 17868 2009-08-28 09:46:30Z yoshida@zend.co.jp $ + * @version $Id: File.php 20096 2010-01-06 02:05:09Z bkarwin $ */ /** @@ -34,7 +34,7 @@ require_once 'Zend/Cache/Backend.php'; /** * @package Zend_Cache * @subpackage Zend_Cache_Backend - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_File extends Zend_Cache_Backend implements Zend_Cache_Backend_ExtendedInterface diff --git a/libs/Zend/Cache/Backend/Interface.php b/libs/Zend/Cache/Backend/Interface.php index f2878f95ae..3e8c7d1211 100644 --- a/libs/Zend/Cache/Backend/Interface.php +++ b/libs/Zend/Cache/Backend/Interface.php @@ -15,16 +15,16 @@ * @category Zend * @package Zend_Cache * @subpackage Zend_Cache_Backend - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 16541 2009-07-07 06:59:03Z bkarwin $ + * @version $Id: Interface.php 20096 2010-01-06 02:05:09Z bkarwin $ */ /** * @package Zend_Cache * @subpackage Zend_Cache_Backend - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Cache_Backend_Interface diff --git a/libs/Zend/Cache/Backend/Memcached.php b/libs/Zend/Cache/Backend/Memcached.php index ab89ea3264..d5fe002b0c 100644 --- a/libs/Zend/Cache/Backend/Memcached.php +++ b/libs/Zend/Cache/Backend/Memcached.php @@ -15,9 +15,9 @@ * @category Zend * @package Zend_Cache * @subpackage Zend_Cache_Backend - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 19250 2009-11-26 06:42:20Z bate $ + * @version $Id: Memcached.php 20591 2010-01-25 00:14:10Z mabe $ */ @@ -35,7 +35,7 @@ require_once 'Zend/Cache/Backend.php'; /** * @package Zend_Cache * @subpackage Zend_Cache_Backend - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Memcached extends Zend_Cache_Backend implements Zend_Cache_Backend_ExtendedInterface @@ -219,13 +219,14 @@ class Zend_Cache_Backend_Memcached extends Zend_Cache_Backend implements Zend_Ca } else { $flag = 0; } - // #ZF-5702 : we try add() first becase set() seems to be slower - if (!($result = $this->_memcache->add($id, array($data, time(), $lifetime), $flag, $lifetime))) { - $result = $this->_memcache->set($id, array($data, time(), $lifetime), $flag, $lifetime); - } + + // ZF-8856: using set because add needs a second request if item already exists + $result = @$this->_memcache->set($id, array($data, time(), $lifetime), $flag, $lifetime); + if (count($tags) > 0) { $this->_log("Zend_Cache_Backend_Memcached::save() : tags are unsupported by the Memcached backend"); } + return $result; } @@ -383,22 +384,23 @@ class Zend_Cache_Backend_Memcached extends Zend_Cache_Backend implements Zend_Ca $memSize = 0; $memUsed = 0; foreach ($mems as $key => $mem) { - if ($mem === false) { - Zend_Cache::throwException('can\'t get stat from ' . $key); - } else { - $eachSize = $mem['limit_maxbytes']; - if ($eachSize == 0) { - Zend_Cache::throwException('can\'t get memory size from ' . $key); - } - - $eachUsed = $mem['bytes']; - if ($eachUsed > $eachSize) { - $eachUsed = $eachSize; - } - - $memSize += $eachSize; - $memUsed += $eachUsed; + if ($mem === false || !$mem['limit_maxbytes']) { + $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 || !$memUsed) { + Zend_Cache::throwException('Can\'t get filling percentage'); } return ((int) (100. * ($memUsed / $memSize))); diff --git a/libs/Zend/Cache/Backend/Sqlite.php b/libs/Zend/Cache/Backend/Sqlite.php index 7430d7303b..5b81fc3223 100644 --- a/libs/Zend/Cache/Backend/Sqlite.php +++ b/libs/Zend/Cache/Backend/Sqlite.php @@ -15,9 +15,9 @@ * @category Zend * @package Zend_Cache * @subpackage Zend_Cache_Backend - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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: Sqlite.php 17868 2009-08-28 09:46:30Z yoshida@zend.co.jp $ + * @version $Id: Sqlite.php 20096 2010-01-06 02:05:09Z bkarwin $ */ @@ -34,7 +34,7 @@ require_once 'Zend/Cache/Backend.php'; /** * @package Zend_Cache * @subpackage Zend_Cache_Backend - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Sqlite extends Zend_Cache_Backend implements Zend_Cache_Backend_ExtendedInterface diff --git a/libs/Zend/Cache/Backend/Static.php b/libs/Zend/Cache/Backend/Static.php new file mode 100644 index 0000000000..25ca5afe90 --- /dev/null +++ b/libs/Zend/Cache/Backend/Static.php @@ -0,0 +1,505 @@ +<?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: BlackHole.php 17867 2009-08-28 09:42:11Z yoshida@zend.co.jp $ + */ + +/** + * @see Zend_Cache_Backend_Interface + */ +require_once 'Zend/Cache/Backend/Interface.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_Static + extends Zend_Cache_Backend + implements Zend_Cache_Backend_Interface +{ + const INNER_CACHE_NAME = 'zend_cache_backend_static_tagcache'; + + /** + * Static backend options + * @var array + */ + protected $_options = array( + 'public_dir' => null, + 'sub_dir' => 'html', + 'file_extension' => '.html', + 'index_filename' => 'index', + 'file_locking' => true, + 'cache_file_umask' => 0644, + 'debug_header' => false, + 'tag_cache' => null, + 'disable_caching' => false + ); + + /** + * Cache for handling tags + * @var Zend_Cache_Core + */ + protected $_tagCache = null; + + /** + * Tagged items + * @var array + */ + protected $_tagged = null; + + /** + * Interceptor child method to handle the case where an Inner + * Cache object is being set since it's not supported by the + * standard backend interface + * + * @param string $name + * @param mixed $value + * @return Zend_Cache_Backend_Static + */ + public function setOption($name, $value) + { + if ($name == 'tag_cache') { + $this->setInnerCache($value); + } else { + parent::setOption($name, $value); + } + return $this; + } + + /** + * Retrieve any option via interception of the parent's statically held + * options including the local option for a tag cache. + * + * @param string $name + * @return mixed + */ + public function getOption($name) + { + if ($name == 'tag_cache') { + return $this->getInnerCache(); + } else { + return parent::getOption($name); + } + } + + /** + * Test if a cache is available for the given id and (if yes) return it (false else) + * + * Note : return value is always "string" (unserialization is done by the core not by the backend) + * + * @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) + { + if (empty($id)) { + $id = $this->_detectId(); + } else { + $id = $this->_decodeId($id); + } + if (!$this->_verifyPath($id)) { + Zend_Cache::throwException('Invalid cache id: does not match expected public_dir path'); + } + if ($doNotTestCacheValidity) { + $this->_log("Zend_Cache_Backend_Static::load() : \$doNotTestCacheValidity=true is unsupported by the Static backend"); + } + + $fileName = basename($id); + if (empty($fileName)) { + $fileName = $this->_options['index_filename']; + } + $pathName = $this->_options['public_dir'] . dirname($id); + $file = rtrim($pathName, '/') . '/' . $fileName . $this->_options['file_extension']; + if (file_exists($file)) { + $content = file_get_contents($file); + return $content; + } + + return false; + } + + /** + * Test if a cache is available or not (for the given id) + * + * @param string $id cache id + * @return bool + */ + public function test($id) + { + $id = $this->_decodeId($id); + if (!$this->_verifyPath($id)) { + Zend_Cache::throwException('Invalid cache id: does not match expected public_dir path'); + } + + $fileName = basename($id); + if (empty($fileName)) { + $fileName = $this->_options['index_filename']; + } + $pathName = $this->_options['public_dir'] . dirname($id); + $file = $pathName . '/' . $fileName . $this->_options['file_extension']; + if (file_exists($file)) { + return true; + } + 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) + { + if ($this->_options['disable_caching']) { + return true; + } + clearstatcache(); + if (is_null($id) || strlen($id) == 0) { + $id = $this->_detectId(); + } else { + $id = $this->_decodeId($id); + } + + $fileName = basename($id); + if (empty($fileName)) { + $fileName = $this->_options['index_filename']; + } + + $pathName = realpath($this->_options['public_dir']) . dirname($id); + $this->_createDirectoriesFor($pathName); + + if (is_null($id) || strlen($id) == 0) { + $dataUnserialized = unserialize($data); + $data = $dataUnserialized['data']; + } + + $file = rtrim($pathName, '/') . '/' . $fileName . $this->_options['file_extension']; + if ($this->_options['file_locking']) { + $result = file_put_contents($file, $data, LOCK_EX); + } else { + $result = file_put_contents($file, $data); + } + @chmod($file, $this->_octdec($this->_options['cache_file_umask'])); + + if (count($tags) > 0) { + if (is_null($this->_tagged) && $tagged = $this->getInnerCache()->load(self::INNER_CACHE_NAME)) { + $this->_tagged = $tagged; + } elseif (is_null($this->_tagged)) { + $this->_tagged = array(); + } + if (!isset($this->_tagged[$id])) { + $this->_tagged[$id] = array(); + } + $this->_tagged[$id] = array_unique(array_merge($this->_tagged[$id], $tags)); + $this->getInnerCache()->save($this->_tagged, self::INNER_CACHE_NAME); + } + return (bool) $result; + } + + /** + * Recursively create the directories needed to write the static file + */ + protected function _createDirectoriesFor($path) + { + $parts = explode('/', $path); + $directory = ''; + foreach ($parts as $part) { + $directory = rtrim($directory, '/') . '/' . $part; + if (!is_dir($directory)) { + mkdir($directory, $this->_octdec($this->_options['cache_file_umask'])); + } + } + } + + /** + * Remove a cache record + * + * @param string $id Cache id + * @return boolean True if no problem + */ + public function remove($id) + { + if (!$this->_verifyPath($id)) { + Zend_Cache::throwException('Invalid cache id: does not match expected public_dir path'); + } + $fileName = basename($id); + if (empty($fileName)) { + $fileName = $this->_options['index_filename']; + } + $pathName = $this->_options['public_dir'] . dirname($id); + $file = realpath($pathName) . '/' . $fileName . $this->_options['file_extension']; + if (!file_exists($file)) { + return false; + } + return unlink($file); + } + + /** + * Remove a cache record recursively for the given directory matching a + * REQUEST_URI based relative path (deletes the actual file matching this + * in addition to the matching directory) + * + * @param string $id Cache id + * @return boolean True if no problem + */ + public function removeRecursively($id) + { + if (!$this->_verifyPath($id)) { + Zend_Cache::throwException('Invalid cache id: does not match expected public_dir path'); + } + $fileName = basename($id); + if (empty($fileName)) { + $fileName = $this->_options['index_filename']; + } + $pathName = $this->_options['public_dir'] . dirname($id); + $file = $pathName . '/' . $fileName . $this->_options['file_extension']; + $directory = $pathName . '/' . $fileName; + if (file_exists($directory)) { + if (!is_writable($directory)) { + return false; + } + foreach (new DirectoryIterator($directory) as $file) { + if (true === $file->isFile()) { + if (false === unlink($file->getPathName())) { + return false; + } + } + } + rmdir(dirname($path)); + } + if (file_exists($file)) { + if (!is_writable($file)) { + return false; + } + return unlink($file); + } + return true; + } + + /** + * Clean some cache records + * + * Available modes are : + * Zend_Cache::CLEANING_MODE_ALL (default) => remove all cache entries ($tags is not used) + * Zend_Cache::CLEANING_MODE_OLD => remove too old cache entries ($tags is not used) + * Zend_Cache::CLEANING_MODE_MATCHING_TAG => remove cache entries matching all given tags + * ($tags can be an array of strings or a single string) + * Zend_Cache::CLEANING_MODE_NOT_MATCHING_TAG => remove cache entries not {matching one of the given tags} + * ($tags can be an array of strings or a single string) + * Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG => remove cache entries matching any given tags + * ($tags can be an array of strings or a single string) + * + * @param string $mode Clean mode + * @param array $tags Array of tags + * @return boolean true if no problem + */ + public function clean($mode = Zend_Cache::CLEANING_MODE_ALL, $tags = array()) + { + $result = false; + switch ($mode) { + case Zend_Cache::CLEANING_MODE_MATCHING_TAG: + case Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG: + 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)) { + $this->_tagged = $tagged; + } elseif (!$this->_tagged) { + return true; + } + foreach ($tags as $tag) { + $urls = array_keys($this->_tagged); + foreach ($urls as $url) { + if (in_array($tag, $this->_tagged[$url])) { + $this->remove($url); + unset($this->_tagged[$url]); + } + } + } + $this->getInnerCache()->save($this->_tagged, self::INNER_CACHE_NAME); + $result = true; + break; + case Zend_Cache::CLEANING_MODE_ALL: + if (is_null($this->_tagged)) { + $tagged = $this->getInnerCache()->load(self::INNER_CACHE_NAME); + $this->_tagged = $tagged; + } + if (is_null($this->_tagged) || empty($this->_tagged)) { + return true; + } + $urls = array_keys($this->_tagged); + foreach ($urls as $url) { + $this->remove($url); + unset($this->_tagged[$url]); + } + $this->getInnerCache()->save($this->_tagged, self::INNER_CACHE_NAME); + $result = true; + break; + case Zend_Cache::CLEANING_MODE_OLD: + $this->_log("Zend_Cache_Backend_Static : Selected Cleaning Mode Currently Unsupported By This Backend"); + break; + case Zend_Cache::CLEANING_MODE_NOT_MATCHING_TAG: + 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); + $this->_tagged = $tagged; + } + if (is_null($this->_tagged) || empty($this->_tagged)) { + return true; + } + $urls = array_keys($this->_tagged); + foreach ($urls as $url) { + $difference = array_diff($tags, $this->_tagged[$url]); + if (count($tags) == count($difference)) { + $this->remove($url); + unset($this->_tagged[$url]); + } + } + $this->getInnerCache()->save($this->_tagged, self::INNER_CACHE_NAME); + $result = true; + break; + default: + Zend_Cache::throwException('Invalid mode for clean() method'); + break; + } + return $result; + } + + /** + * Set an Inner Cache, used here primarily to store Tags associated + * with caches created by this backend. Note: If Tags are lost, the cache + * should be completely cleaned as the mapping of tags to caches will + * have been irrevocably lost. + * + * @param Zend_Cache_Core + * @return void + */ + public function setInnerCache(Zend_Cache_Core $cache) + { + $this->_tagCache = $cache; + $this->_options['tag_cache'] = $cache; + } + + /** + * Get the Inner Cache if set + * + * @return Zend_Cache_Core + */ + public function getInnerCache() + { + if (is_null($this->_tagCache)) { + Zend_Cache::throwException('An Inner Cache has not been set; use setInnerCache()'); + } + return $this->_tagCache; + } + + /** + * Verify path exists and is non-empty + * + * @param string $path + * @return bool + */ + protected function _verifyPath($path) + { + $path = realpath($path); + $base = realpath($this->_options['public_dir']); + return strncmp($path, $base, strlen($base)) !== 0; + } + + /** + * Determine the page to save from the request + * + * @return string + */ + protected function _detectId() + { + return $_SERVER['REQUEST_URI']; + } + + /** + * Validate a cache id or a tag (security, reliable filenames, reserved prefixes...) + * + * Throw an exception if a problem is found + * + * @param string $string Cache id or tag + * @throws Zend_Cache_Exception + * @return void + * @deprecated Not usable until perhaps ZF 2.0 + */ + protected static function _validateIdOrTag($string) + { + if (!is_string($string)) { + Zend_Cache::throwException('Invalid id or tag : must be a string'); + } + + // Internal only checked in Frontend - not here! + if (substr($string, 0, 9) == 'internal-') { + return; + } + + // Validation assumes no query string, fragments or scheme included - only the path + if (!preg_match( + '/^(?:\/(?:(?:%[[:xdigit:]]{2}|[A-Za-z0-9-_.!~*\'()\[\]:@&=+$,;])*)?)+$/', + $string + ) + ) { + Zend_Cache::throwException("Invalid id or tag '$string' : must be a valid URL path"); + } + } + + /** + * Detect an octal string and return its octal value for file permission ops + * otherwise return the non-string (assumed octal or decimal int already) + * + * @param $val The potential octal in need of conversion + * @return int + */ + protected function _octdec($val) + { + if (decoct(octdec($val)) == $val && is_string($val)) { + return octdec($val); + } + return $val; + } + + /** + * Decode a request URI from the provided ID + */ + protected function _decodeId($id) + { + return pack('H*', $id);; + } +} diff --git a/libs/Zend/Cache/Backend/Test.php b/libs/Zend/Cache/Backend/Test.php index 713b48954a..9e9a229a85 100644 --- a/libs/Zend/Cache/Backend/Test.php +++ b/libs/Zend/Cache/Backend/Test.php @@ -15,9 +15,9 @@ * @category Zend * @package Zend_Cache * @subpackage Zend_Cache_Backend - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 16541 2009-07-07 06:59:03Z bkarwin $ + * @version $Id: Test.php 20379 2010-01-18 14:40:57Z mabe $ */ @@ -34,7 +34,7 @@ require_once 'Zend/Cache/Backend.php'; /** * @package Zend_Cache * @subpackage Zend_Cache_Backend - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Test extends Zend_Cache_Backend implements Zend_Cache_Backend_Interface @@ -103,7 +103,11 @@ class Zend_Cache_Backend_Test extends Zend_Cache_Backend implements Zend_Cache_B public function load($id, $doNotTestCacheValidity = false) { $this->_addLog('get', array($id, $doNotTestCacheValidity)); - if ($id=='false') { + if ( $id == 'false' + || $id == 'd8523b3ee441006261eeffa5c3d3a0a7' + || $id == 'e83249ea22178277d5befc2c5e2e9ace' + || $id == '40f649b94977c0a6e76902e2a0b43587') + { return false; } if ($id=='serialized') { @@ -136,10 +140,7 @@ class Zend_Cache_Backend_Test extends Zend_Cache_Backend implements Zend_Cache_B if ($id=='false') { return false; } - if (($id=='d8523b3ee441006261eeffa5c3d3a0a7') or ($id=='3c439c922209e2cb0b54d6deffccd75a')) { - return false; - } - if (($id=='40f649b94977c0a6e76902e2a0b43587') or ($id=='e83249ea22178277d5befc2c5e2e9ace')) { + if (($id=='3c439c922209e2cb0b54d6deffccd75a')) { return false; } return 123456; diff --git a/libs/Zend/Cache/Backend/TwoLevels.php b/libs/Zend/Cache/Backend/TwoLevels.php index d7464d26bf..c027844949 100644 --- a/libs/Zend/Cache/Backend/TwoLevels.php +++ b/libs/Zend/Cache/Backend/TwoLevels.php @@ -15,9 +15,9 @@ * @category Zend * @package Zend_Cache * @subpackage Zend_Cache_Backend - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 19788 2009-12-19 16:40:07Z alexander $ + * @version $Id: TwoLevels.php 20096 2010-01-06 02:05:09Z bkarwin $ */ @@ -35,7 +35,7 @@ require_once 'Zend/Cache/Backend.php'; /** * @package Zend_Cache * @subpackage Zend_Cache_Backend - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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/Cache/Backend/Xcache.php b/libs/Zend/Cache/Backend/Xcache.php index 4614b7354c..fbdf4d0f44 100644 --- a/libs/Zend/Cache/Backend/Xcache.php +++ b/libs/Zend/Cache/Backend/Xcache.php @@ -15,9 +15,9 @@ * @category Zend * @package Zend_Cache * @subpackage Zend_Cache_Backend - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 18951 2009-11-12 16:26:19Z alexander $ + * @version $Id: Xcache.php 20096 2010-01-06 02:05:09Z bkarwin $ */ @@ -35,7 +35,7 @@ require_once 'Zend/Cache/Backend.php'; /** * @package Zend_Cache * @subpackage Zend_Cache_Backend - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Xcache extends Zend_Cache_Backend implements Zend_Cache_Backend_Interface diff --git a/libs/Zend/Cache/Backend/ZendPlatform.php b/libs/Zend/Cache/Backend/ZendPlatform.php index 71bbdab3e0..011428384b 100644 --- a/libs/Zend/Cache/Backend/ZendPlatform.php +++ b/libs/Zend/Cache/Backend/ZendPlatform.php @@ -15,9 +15,9 @@ * @category Zend * @package Zend_Cache * @subpackage Zend_Cache_Backend - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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: ZendPlatform.php 16971 2009-07-22 18:05:45Z mikaelkael $ + * @version $Id: ZendPlatform.php 20096 2010-01-06 02:05:09Z bkarwin $ */ /** @@ -36,7 +36,7 @@ require_once 'Zend/Cache/Backend/Interface.php'; * * @package Zend_Cache * @subpackage Zend_Cache_Backend - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_ZendPlatform extends Zend_Cache_Backend implements Zend_Cache_Backend_Interface diff --git a/libs/Zend/Cache/Backend/ZendServer.php b/libs/Zend/Cache/Backend/ZendServer.php index 55840efa43..ee9dc4c06a 100644 --- a/libs/Zend/Cache/Backend/ZendServer.php +++ b/libs/Zend/Cache/Backend/ZendServer.php @@ -15,9 +15,9 @@ * @category Zend * @package Zend_Cache * @subpackage Zend_Cache_Backend - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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: ZendServer.php 17672 2009-08-19 13:05:18Z yoshida@zend.co.jp $ + * @version $Id: ZendServer.php 20096 2010-01-06 02:05:09Z bkarwin $ */ @@ -31,7 +31,7 @@ require_once 'Zend/Cache/Backend.php'; /** * @package Zend_Cache * @subpackage Zend_Cache_Backend - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Cache_Backend_ZendServer extends Zend_Cache_Backend implements Zend_Cache_Backend_Interface diff --git a/libs/Zend/Cache/Backend/ZendServer/Disk.php b/libs/Zend/Cache/Backend/ZendServer/Disk.php index 42dcb92a60..40ffb51586 100644 --- a/libs/Zend/Cache/Backend/ZendServer/Disk.php +++ b/libs/Zend/Cache/Backend/ZendServer/Disk.php @@ -15,9 +15,9 @@ * @category Zend * @package Zend_Cache * @subpackage Zend_Cache_Backend - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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: Disk.php 18951 2009-11-12 16:26:19Z alexander $ + * @version $Id: Disk.php 20096 2010-01-06 02:05:09Z bkarwin $ */ @@ -31,7 +31,7 @@ require_once 'Zend/Cache/Backend/ZendServer.php'; /** * @package Zend_Cache * @subpackage Zend_Cache_Backend - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_ZendServer_Disk extends Zend_Cache_Backend_ZendServer implements Zend_Cache_Backend_Interface diff --git a/libs/Zend/Cache/Backend/ZendServer/ShMem.php b/libs/Zend/Cache/Backend/ZendServer/ShMem.php index 1e551a5d28..46bc946221 100644 --- a/libs/Zend/Cache/Backend/ZendServer/ShMem.php +++ b/libs/Zend/Cache/Backend/ZendServer/ShMem.php @@ -15,9 +15,9 @@ * @category Zend * @package Zend_Cache * @subpackage Zend_Cache_Backend - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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: ShMem.php 18951 2009-11-12 16:26:19Z alexander $ + * @version $Id: ShMem.php 20096 2010-01-06 02:05:09Z bkarwin $ */ @@ -31,7 +31,7 @@ require_once 'Zend/Cache/Backend/ZendServer.php'; /** * @package Zend_Cache * @subpackage Zend_Cache_Backend - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_ZendServer_ShMem extends Zend_Cache_Backend_ZendServer implements Zend_Cache_Backend_Interface diff --git a/libs/Zend/Cache/Core.php b/libs/Zend/Cache/Core.php index c5182c26d4..463451e095 100644 --- a/libs/Zend/Cache/Core.php +++ b/libs/Zend/Cache/Core.php @@ -14,15 +14,15 @@ * * @category Zend * @package Zend_Cache - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 19781 2009-12-19 10:34:44Z mluiten $ + * @version $Id: Core.php 20096 2010-01-06 02:05:09Z bkarwin $ */ /** * @package Zend_Cache - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Core diff --git a/libs/Zend/Cache/Exception.php b/libs/Zend/Cache/Exception.php index 1e1e62c4d8..5ca005d18e 100644 --- a/libs/Zend/Cache/Exception.php +++ b/libs/Zend/Cache/Exception.php @@ -14,9 +14,9 @@ * * @category Zend * @package Zend_Cache - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 16541 2009-07-07 06:59:03Z bkarwin $ + * @version $Id: Exception.php 20096 2010-01-06 02:05:09Z bkarwin $ */ /** @@ -26,7 +26,7 @@ require_once 'Zend/Exception.php'; /** * @package Zend_Cache - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Exception extends Zend_Exception {} diff --git a/libs/Zend/Cache/Frontend/Capture.php b/libs/Zend/Cache/Frontend/Capture.php new file mode 100644 index 0000000000..f3903a26db --- /dev/null +++ b/libs/Zend/Cache/Frontend/Capture.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_Cache + * @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 + */ + + +/** + * @see Zend_Cache_Core + */ +require_once 'Zend/Cache/Core.php'; + + +/** + * @package Zend_Cache + * @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 + */ +class Zend_Cache_Frontend_Capture extends Zend_Cache_Core +{ + /** + * Page identifiers + * @var array + */ + protected $_idStack = array(); + + /** + * Tags + * @var array + */ + protected $_tags = array(); + + /** + * Start the cache + * + * @param string $id Cache id + * @return mixed True if the cache is hit (false else) with $echoData=true (default) ; string else (datas) + */ + public function start($id, array $tags) + { + $this->_tags = $tags; + ob_start(array($this, '_flush')); + ob_implicit_flush(false); + $this->_idStack[] = $id; + return false; + } + + /** + * callback for output buffering + * (shouldn't really be called manually) + * + * @param string $data Buffered output + * @return string Data to send to browser + */ + public function _flush($data) + { + $id = array_pop($this->_idStack); + if (is_null($id)) { + Zend_Cache::throwException('use of _flush() without a start()'); + } + file_put_contents('/var/www/data.dump', $data); + $this->save($data, $id, $this->_tags); + return $data; + } +} diff --git a/libs/Zend/Cache/Frontend/Class.php b/libs/Zend/Cache/Frontend/Class.php index 6c4ef471b8..e5e2d0eb38 100644 --- a/libs/Zend/Cache/Frontend/Class.php +++ b/libs/Zend/Cache/Frontend/Class.php @@ -15,9 +15,9 @@ * @category Zend * @package Zend_Cache * @subpackage Zend_Cache_Frontend - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 16541 2009-07-07 06:59:03Z bkarwin $ + * @version $Id: Class.php 20379 2010-01-18 14:40:57Z mabe $ */ /** @@ -29,7 +29,7 @@ require_once 'Zend/Cache/Core.php'; /** * @package Zend_Cache * @subpackage Zend_Cache_Frontend - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Frontend_Class extends Zend_Cache_Core @@ -208,14 +208,14 @@ class Zend_Cache_Frontend_Class extends Zend_Cache_Core // We do not have not cache return call_user_func_array(array($this->_cachedEntity, $name), $parameters); } + $id = $this->_makeId($name, $parameters); - if ($this->test($id)) { + if ( ($rs = $this->load($id)) && isset($rs[0], $rs[1]) ) { // A cache is available - $result = $this->load($id); - $output = $result[0]; - $return = $result[1]; + $output = $rs[0]; + $return = $rs[1]; } else { - // A cache is not available + // 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); @@ -224,6 +224,7 @@ class Zend_Cache_Frontend_Class extends Zend_Cache_Core $data = array($output, $return); $this->save($data, $id, $this->_tags, $this->_specificLifetime, $this->_priority); } + echo $output; return $return; } diff --git a/libs/Zend/Cache/Frontend/File.php b/libs/Zend/Cache/Frontend/File.php index f171b311a2..07c7ddcaba 100644 --- a/libs/Zend/Cache/Frontend/File.php +++ b/libs/Zend/Cache/Frontend/File.php @@ -15,9 +15,9 @@ * @category Zend * @package Zend_Cache * @subpackage Zend_Cache_Frontend - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 19781 2009-12-19 10:34:44Z mluiten $ + * @version $Id: File.php 20096 2010-01-06 02:05:09Z bkarwin $ */ @@ -30,7 +30,7 @@ require_once 'Zend/Cache/Core.php'; /** * @package Zend_Cache * @subpackage Zend_Cache_Frontend - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Frontend_File extends Zend_Cache_Core diff --git a/libs/Zend/Cache/Frontend/Function.php b/libs/Zend/Cache/Frontend/Function.php index b06dc2450e..d6ca522ffe 100644 --- a/libs/Zend/Cache/Frontend/Function.php +++ b/libs/Zend/Cache/Frontend/Function.php @@ -15,9 +15,9 @@ * @category Zend * @package Zend_Cache * @subpackage Zend_Cache_Frontend - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 18951 2009-11-12 16:26:19Z alexander $ + * @version $Id: Function.php 20379 2010-01-18 14:40:57Z mabe $ */ @@ -30,7 +30,7 @@ require_once 'Zend/Cache/Core.php'; /** * @package Zend_Cache * @subpackage Zend_Cache_Frontend - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Frontend_Function extends Zend_Cache_Core @@ -89,14 +89,14 @@ class Zend_Cache_Frontend_Function extends Zend_Cache_Core // We do not have not cache return call_user_func_array($name, $parameters); } + $id = $this->_makeId($name, $parameters); - if ($this->test($id)) { + if ( ($rs = $this->load($id)) && isset($rs[0], $rs[1])) { // A cache is available - $result = $this->load($id); - $output = $result[0]; - $return = $result[1]; + $output = $rs[0]; + $return = $rs[1]; } else { - // A cache is not available + // A cache is not available (or not valid for this frontend) ob_start(); ob_implicit_flush(false); $return = call_user_func_array($name, $parameters); @@ -105,6 +105,7 @@ class Zend_Cache_Frontend_Function extends Zend_Cache_Core $data = array($output, $return); $this->save($data, $id, $tags, $specificLifetime, $priority); } + echo $output; return $return; } diff --git a/libs/Zend/Cache/Frontend/Output.php b/libs/Zend/Cache/Frontend/Output.php index 00f200d722..021150e6d9 100644 --- a/libs/Zend/Cache/Frontend/Output.php +++ b/libs/Zend/Cache/Frontend/Output.php @@ -15,9 +15,9 @@ * @category Zend * @package Zend_Cache * @subpackage Zend_Cache_Frontend - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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: Output.php 16541 2009-07-07 06:59:03Z bkarwin $ + * @version $Id: Output.php 20096 2010-01-06 02:05:09Z bkarwin $ */ @@ -30,7 +30,7 @@ require_once 'Zend/Cache/Core.php'; /** * @package Zend_Cache * @subpackage Zend_Cache_Frontend - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Frontend_Output extends Zend_Cache_Core diff --git a/libs/Zend/Cache/Frontend/Page.php b/libs/Zend/Cache/Frontend/Page.php index 64dacc7cfe..c8edceb7ff 100644 --- a/libs/Zend/Cache/Frontend/Page.php +++ b/libs/Zend/Cache/Frontend/Page.php @@ -15,9 +15,9 @@ * @category Zend * @package Zend_Cache * @subpackage Zend_Cache_Frontend - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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: Page.php 18951 2009-11-12 16:26:19Z alexander $ + * @version $Id: Page.php 20096 2010-01-06 02:05:09Z bkarwin $ */ @@ -30,7 +30,7 @@ require_once 'Zend/Cache/Core.php'; /** * @package Zend_Cache * @subpackage Zend_Cache_Frontend - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Frontend_Page extends Zend_Cache_Core diff --git a/libs/Zend/Cache/Manager.php b/libs/Zend/Cache/Manager.php new file mode 100644 index 0000000000..75debeec31 --- /dev/null +++ b/libs/Zend/Cache/Manager.php @@ -0,0 +1,280 @@ +<?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 + * @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_Cache_Exception */ +require_once 'Zend/Cache/Exception.php'; + +/** + * @category Zend + * @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 + */ +class Zend_Cache_Manager +{ + /** + * Constant holding reserved name for default Page Cache + */ + const PAGECACHE = 'page'; + + /** + * Constant holding reserved name for default Page Tag Cache + */ + const PAGETAGCACHE = 'pagetag'; + + /** + * Array of caches stored by the Cache Manager instance + * + * @var array + */ + protected $_caches = array(); + + /** + * Array of ready made configuration templates for lazy + * loading caches. + * + * @var array + */ + protected $_optionTemplates = array( + // Null Cache (Enforce Null/Empty Values) + 'skeleton' => array( + 'frontend' => array( + 'name' => null, + 'options' => array(), + ), + 'backend' => array( + 'name' => null, + 'options' => array(), + ), + ), + // Simple Common Default + 'default' => array( + 'frontend' => array( + 'name' => 'Core', + 'options' => array( + 'automatic_serialization' => true, + ), + ), + 'backend' => array( + 'name' => 'File', + 'options' => array( + 'cache_dir' => '../cache', + ), + ), + ), + // Static Page HTML Cache + 'page' => array( + 'frontend' => array( + 'name' => 'Capture', + 'options' => array( + 'ignore_user_abort' => true, + ), + ), + 'backend' => array( + 'name' => 'Static', + 'options' => array( + 'public_dir' => '../public', + ), + ), + ), + // Tag Cache + 'pagetag' => array( + 'frontend' => array( + 'name' => 'Core', + 'options' => array( + 'automatic_serialization' => true, + 'lifetime' => null + ), + ), + 'backend' => array( + 'name' => 'File', + 'options' => array( + 'cache_dir' => '../cache', + 'cache_file_umask' => 0644 + ), + ), + ), + ); + + /** + * Set a new cache for the Cache Manager to contain + * + * @param string $name + * @param Zend_Cache_Core $cache + * @return Zend_Cache_Manager + */ + public function setCache($name, Zend_Cache_Core $cache) + { + $this->_caches[$name] = $cache; + return $this; + } + + /** + * Check if the Cache Manager contains the named cache object, or a named + * configuration template to lazy load the cache object + * + * @param string $name + * @return bool + */ + public function hasCache($name) + { + if (isset($this->_caches[$name]) + || $this->hasCacheTemplate($name) + ) { + return true; + } + return false; + } + + /** + * Fetch the named cache object, or instantiate and return a cache object + * using a named configuration template + * + * @param string $name + * @return Zend_Cache_Core + */ + public function getCache($name) + { + if (isset($this->_caches[$name])) { + return $this->_caches[$name]; + } + if (isset($this->_optionTemplates[$name])) { + if ($name == self::PAGECACHE + && (!isset($this->_optionTemplates[$name]['backend']['options']['tag_cache']) + || !$this->_optionTemplates[$name]['backend']['options']['tag_cache'] instanceof Zend_Cache_Core) + ) { + $this->_optionTemplates[$name]['backend']['options']['tag_cache'] + = $this->getCache(self::PAGETAGCACHE ); + } + $this->_caches[$name] = Zend_Cache::factory( + $this->_optionTemplates[$name]['frontend']['name'], + $this->_optionTemplates[$name]['backend']['name'], + isset($this->_optionTemplates[$name]['frontend']['options']) ? $this->_optionTemplates[$name]['frontend']['options'] : array(), + isset($this->_optionTemplates[$name]['backend']['options']) ? $this->_optionTemplates[$name]['backend']['options'] : array() + ); + return $this->_caches[$name]; + } + } + + /** + * Set a named configuration template from which a cache object can later + * be lazy loaded + * + * @param string $name + * @param array $options + * @return Zend_Cache_Manager + */ + public function setCacheTemplate($name, $options) + { + if ($options instanceof Zend_Config) { + $options = $options->toArray(); + } elseif (!is_array($options)) { + require_once 'Zend/Cache/Exception.php'; + throw new Zend_Cache_Exception('Options passed must be in' + . ' an associative array or instance of Zend_Config'); + } + $this->_optionTemplates[$name] = $options; + return $this; + } + + /** + * Check if the named configuration template + * + * @param string $name + * @return bool + */ + public function hasCacheTemplate($name) + { + if (isset($this->_optionTemplates[$name])) { + return true; + } + return false; + } + + /** + * Get the named configuration template + * + * @param string $name + * @return array + */ + public function getCacheTemplate($name) + { + if (isset($this->_optionTemplates[$name])) { + return $this->_optionTemplates[$name]; + } + } + + /** + * Pass an array containing changes to be applied to a named + * configuration + * template + * + * @param string $name + * @param array $options + * @return Zend_Cache_Manager + * @throws Zend_Cache_Exception for invalid options format or if option templates do not have $name + */ + public function setTemplateOptions($name, $options) + { + if ($options instanceof Zend_Config) { + $options = $options->toArray(); + } elseif (!is_array($options)) { + require_once 'Zend/Cache/Exception.php'; + throw new Zend_Cache_Exception('Options passed must be in' + . ' an associative array or instance of Zend_Config'); + } + if (!isset($this->_optionTemplates[$name])) { + throw new Zend_Cache_Exception('A cache configuration template' + . 'does not exist with the name "' . $name . '"'); + } + $this->_optionTemplates[$name] + = $this->_mergeOptions($this->_optionTemplates[$name], $options); + return $this; + } + + /** + * Simple method to merge two configuration arrays + * + * @param array $current + * @param array $options + * @return array + */ + protected function _mergeOptions(array $current, array $options) + { + if (isset($options['frontend']['name'])) { + $current['frontend']['name'] = $options['frontend']['name']; + } + if (isset($options['backend']['name'])) { + $current['backend']['name'] = $options['backend']['name']; + } + if (isset($options['frontend']['options'])) { + foreach ($options['frontend']['options'] as $key=>$value) { + $current['frontend']['options'][$key] = $value; + } + } + if (isset($options['backend']['options'])) { + foreach ($options['backend']['options'] as $key=>$value) { + $current['backend']['options'][$key] = $value; + } + } + return $current; + } +} diff --git a/libs/Zend/Config.php b/libs/Zend/Config.php index e94ebce488..357f18839e 100644 --- a/libs/Zend/Config.php +++ b/libs/Zend/Config.php @@ -14,16 +14,16 @@ * * @category Zend * @package Zend_Config - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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: Config.php 18951 2009-11-12 16:26:19Z alexander $ + * @version $Id: Config.php 20096 2010-01-06 02:05:09Z bkarwin $ */ /** * @category Zend * @package Zend_Config - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 implements Countable, Iterator @@ -453,4 +453,32 @@ class Zend_Config implements Countable, Iterator } } -} + /** + * Merge two arrays recursively, overwriting keys of the same name + * in $firstArray with the value in $secondArray. + * + * @param mixed $firstArray First array + * @param mixed $secondArray Second array to merge into first array + * @return array + */ + protected function _arrayMergeRecursive($firstArray, $secondArray) + { + if (is_array($firstArray) && is_array($secondArray)) { + foreach ($secondArray as $key => $value) { + if (isset($firstArray[$key])) { + $firstArray[$key] = $this->_arrayMergeRecursive($firstArray[$key], $value); + } else { + if($key === 0) { + $firstArray= array(0=>$this->_arrayMergeRecursive($firstArray, $value)); + } else { + $firstArray[$key] = $value; + } + } + } + } else { + $firstArray = $secondArray; + } + + return $firstArray; + } +}
\ No newline at end of file diff --git a/libs/Zend/Config/Exception.php b/libs/Zend/Config/Exception.php index 859d3bf71c..1532c16524 100644 --- a/libs/Zend/Config/Exception.php +++ b/libs/Zend/Config/Exception.php @@ -14,9 +14,9 @@ * * @category Zend * @package Zend_Config - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 16541 2009-07-07 06:59:03Z bkarwin $ + * @version $Id: Exception.php 20096 2010-01-06 02:05:09Z bkarwin $ */ /** @@ -27,7 +27,7 @@ require_once 'Zend/Exception.php'; /** * @category Zend * @package Zend_Config - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Exception extends Zend_Exception {} diff --git a/libs/Zend/Config/Ini.php b/libs/Zend/Config/Ini.php index 17ae3b6028..e1966d5058 100644 --- a/libs/Zend/Config/Ini.php +++ b/libs/Zend/Config/Ini.php @@ -14,9 +14,9 @@ * * @category Zend * @package Zend_Config - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 18951 2009-11-12 16:26:19Z alexander $ + * @version $Id: Ini.php 20096 2010-01-06 02:05:09Z bkarwin $ */ @@ -29,7 +29,7 @@ require_once 'Zend/Config.php'; /** * @category Zend * @package Zend_Config - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Ini extends Zend_Config @@ -49,7 +49,7 @@ class Zend_Config_Ini extends Zend_Config protected $_sectionSeparator = ':'; /** - * Wether to skip extends or not + * Whether to skip extends or not * * @var boolean */ @@ -129,7 +129,7 @@ class Zend_Config_Ini extends Zend_Config $dataArray = array(); foreach ($iniArray as $sectionName => $sectionData) { if(!is_array($sectionData)) { - $dataArray = array_merge_recursive($dataArray, $this->_processKey(array(), $sectionName, $sectionData)); + $dataArray = $this->_arrayMergeRecursive($dataArray, $this->_processKey(array(), $sectionName, $sectionData)); } else { $dataArray[$sectionName] = $this->_processSection($iniArray, $sectionName); } @@ -149,7 +149,7 @@ class Zend_Config_Ini extends Zend_Config require_once 'Zend/Config/Exception.php'; throw new Zend_Config_Exception("Section '$sectionName' cannot be found in $filename"); } - $dataArray = array_merge($this->_processSection($iniArray, $sectionName), $dataArray); + $dataArray = $this->_arrayMergeRecursive($this->_processSection($iniArray, $sectionName), $dataArray); } parent::__construct($dataArray, $allowModifications); @@ -157,24 +157,21 @@ class Zend_Config_Ini extends Zend_Config $this->_loadedSection = $section; } - + /** - * Load the ini file and preprocess the section separator (':' in the - * section name (that is used for section extension) so that the resultant - * array has the correct section names and the extension information is - * stored in a sub-key called ';extends'. We use ';extends' as this can - * never be a valid key name in an INI file that has been loaded using - * parse_ini_file(). - * + * 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 */ - protected function _loadIniFile($filename) + protected function _parseIniFile($filename) { set_error_handler(array($this, '_loadFileErrorHandler')); - $loaded = parse_ini_file($filename, true); // Warnings and errors are suppressed + $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) { /** @@ -183,7 +180,25 @@ class Zend_Config_Ini extends Zend_Config require_once 'Zend/Config/Exception.php'; throw new Zend_Config_Exception($this->_loadFileErrorStr); } + + return $iniArray; + } + /** + * Load the ini file and preprocess the section separator (':' in the + * section name (that is used for section extension) so that the resultant + * array has the correct section names and the extension information is + * stored in a sub-key called ';extends'. We use ';extends' as this can + * never be a valid key name in an INI file that has been loaded using + * parse_ini_file(). + * + * @param string $filename + * @throws Zend_Config_Exception + * @return array + */ + protected function _loadIniFile($filename) + { + $loaded = $this->_parseIniFile($filename); $iniArray = array(); foreach ($loaded as $key => $data) { diff --git a/libs/Zend/Config/Writer.php b/libs/Zend/Config/Writer.php index 17d1078c63..9bfedca748 100644 --- a/libs/Zend/Config/Writer.php +++ b/libs/Zend/Config/Writer.php @@ -14,15 +14,15 @@ * * @category Zend * @package Zend_Config - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 18951 2009-11-12 16:26:19Z alexander $ + * @version $Id: Writer.php 20096 2010-01-06 02:05:09Z bkarwin $ */ /** * @category Zend * @package Zend_Config - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Config_Writer diff --git a/libs/Zend/Config/Writer/Array.php b/libs/Zend/Config/Writer/Array.php index dc19500656..d6fb134c53 100644 --- a/libs/Zend/Config/Writer/Array.php +++ b/libs/Zend/Config/Writer/Array.php @@ -14,98 +14,32 @@ * * @category Zend * @package Zend_Config - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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: Array.php 18951 2009-11-12 16:26:19Z alexander $ + * @version $Id: Array.php 20096 2010-01-06 02:05:09Z bkarwin $ */ /** * @see Zend_Config_Writer */ -require_once 'Zend/Config/Writer.php'; +require_once 'Zend/Config/Writer/FileAbstract.php'; /** * @category Zend * @package Zend_Config - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Writer_Array extends Zend_Config_Writer +class Zend_Config_Writer_Array extends Zend_Config_Writer_FileAbstract { /** - * Filename to write to + * Render a Zend_Config into a PHP Array config string. * - * @var string + * @since 1.10 + * @return string */ - protected $_filename = null; - - /** - * Wether to exclusively lock the file or not - * - * @var boolean - */ - protected $_exclusiveLock = false; - - /** - * Set the target filename - * - * @param string $filename - * @return Zend_Config_Writer_Array - */ - public function setFilename($filename) + public function render() { - $this->_filename = $filename; - - return $this; - } - - /** - * Set wether to exclusively lock the file or not - * - * @param boolean $exclusiveLock - * @return Zend_Config_Writer_Array - */ - public function setExclusiveLock($exclusiveLock) - { - $this->_exclusiveLock = $exclusiveLock; - - return $this; - } - - /** - * Defined by Zend_Config_Writer - * - * @param string $filename - * @param Zend_Config $config - * @param boolean $exclusiveLock - * @throws Zend_Config_Exception When filename was not set - * @throws Zend_Config_Exception When filename is not writable - * @return void - */ - public function write($filename = null, Zend_Config $config = null, $exclusiveLock = null) - { - if ($filename !== null) { - $this->setFilename($filename); - } - - if ($config !== null) { - $this->setConfig($config); - } - - if ($exclusiveLock !== null) { - $this->setExclusiveLock($exclusiveLock); - } - - if ($this->_filename === null) { - require_once 'Zend/Config/Exception.php'; - throw new Zend_Config_Exception('No filename was set'); - } - - if ($this->_config === null) { - require_once 'Zend/Config/Exception.php'; - throw new Zend_Config_Exception('No config was set'); - } - $data = $this->_config->toArray(); $sectionName = $this->_config->getSectionName(); @@ -116,17 +50,6 @@ class Zend_Config_Writer_Array extends Zend_Config_Writer $arrayString = "<?php\n" . "return " . var_export($data, true) . ";\n"; - $flags = 0; - - if ($this->_exclusiveLock) { - $flags |= LOCK_EX; - } - - $result = @file_put_contents($this->_filename, $arrayString, $flags); - - if ($result === false) { - require_once 'Zend/Config/Exception.php'; - throw new Zend_Config_Exception('Could not write to file "' . $this->_filename . '"'); - } + return $arrayString; } } diff --git a/libs/Zend/Config/Writer/FileAbstract.php b/libs/Zend/Config/Writer/FileAbstract.php new file mode 100644 index 0000000000..e90213e8a4 --- /dev/null +++ b/libs/Zend/Config/Writer/FileAbstract.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_Config + * @package 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 + */ + +require_once "Zend/Config/Writer.php"; + +/** + * Abstract File Writer + * + * @category Zend + * @package Zend_package + * @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: FileAbstract.php 20096 2010-01-06 02:05:09Z bkarwin $ + */ +class Zend_Config_Writer_FileAbstract extends Zend_Config_Writer +{ + /** + * Filename to write to + * + * @var string + */ + protected $_filename = null; + + /** + * Wether to exclusively lock the file or not + * + * @var boolean + */ + protected $_exclusiveLock = false; + + /** + * Set the target filename + * + * @param string $filename + * @return Zend_Config_Writer_Array + */ + public function setFilename($filename) + { + $this->_filename = $filename; + + return $this; + } + + /** + * Set wether to exclusively lock the file or not + * + * @param boolean $exclusiveLock + * @return Zend_Config_Writer_Array + */ + public function setExclusiveLock($exclusiveLock) + { + $this->_exclusiveLock = $exclusiveLock; + + return $this; + } + + /** + * Write configuration to file. + * + * @param string $filename + * @param Zend_Config $config + * @param bool $exclusiveLock + * @return void + */ + public function write($filename = null, Zend_Config $config = null, $exclusiveLock = null) + { + if ($filename !== null) { + $this->setFilename($filename); + } + + if ($config !== null) { + $this->setConfig($config); + } + + if ($exclusiveLock !== null) { + $this->setExclusiveLock($exclusiveLock); + } + + if ($this->_filename === null) { + require_once 'Zend/Config/Exception.php'; + throw new Zend_Config_Exception('No filename was set'); + } + + if ($this->_config === null) { + require_once 'Zend/Config/Exception.php'; + throw new Zend_Config_Exception('No config was set'); + } + + $configString = $this->render(); + + $flags = 0; + + if ($this->_exclusiveLock) { + $flags |= LOCK_EX; + } + + $result = @file_put_contents($this->_filename, $configString, $flags); + + if ($result === false) { + require_once 'Zend/Config/Exception.php'; + throw new Zend_Config_Exception('Could not write to file "' . $this->_filename . '"'); + } + } + + /** + * Render a Zend_Config into a config file string. + * + * @since 1.10 + * @todo For 2.0 this should be redone into an abstract method. + * @return string + */ + public function render() + { + return ""; + } +}
\ No newline at end of file diff --git a/libs/Zend/Config/Writer/Ini.php b/libs/Zend/Config/Writer/Ini.php index 5e2ae20811..7457a0aee1 100644 --- a/libs/Zend/Config/Writer/Ini.php +++ b/libs/Zend/Config/Writer/Ini.php @@ -14,39 +14,25 @@ * * @category Zend * @package Zend_Config - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 19737 2009-12-18 01:52:18Z dasprid $ + * @version $Id: Ini.php 20096 2010-01-06 02:05:09Z bkarwin $ */ /** * @see Zend_Config_Writer */ -require_once 'Zend/Config/Writer.php'; +require_once 'Zend/Config/Writer/FileAbstract.php'; /** * @category Zend * @package Zend_Config - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Writer_Ini extends Zend_Config_Writer +class Zend_Config_Writer_Ini extends Zend_Config_Writer_FileAbstract { /** - * Filename to write to - * - * @var string - */ - protected $_filename = null; - - /** - * Wether to exclusively lock the file or not - * - * @var boolean - */ - protected $_exclusiveLock = false; - - /** * String that separates nesting levels of configuration data identifiers * * @var string @@ -54,83 +40,55 @@ class Zend_Config_Writer_Ini extends Zend_Config_Writer protected $_nestSeparator = '.'; /** - * Set the target filename + * If true the ini string is rendered in the global namespace without sections. * - * @param string $filename - * @return Zend_Config_Writer_Xml + * @var bool */ - public function setFilename($filename) - { - $this->_filename = $filename; - - return $this; - } + protected $_renderWithoutSections = false; /** - * Set wether to exclusively lock the file or not + * Set the nest separator * - * @param boolean $exclusiveLock - * @return Zend_Config_Writer_Array + * @param string $filename + * @return Zend_Config_Writer_Ini */ - public function setExclusiveLock($exclusiveLock) + public function setNestSeparator($separator) { - $this->_exclusiveLock = $exclusiveLock; + $this->_nestSeparator = $separator; return $this; } /** - * Set the nest separator + * Set if rendering should occour without sections or not. * - * @param string $filename + * If set to true, the INI file is rendered without sections completely + * into the global namespace of the INI file. + * + * @param bool $withoutSections * @return Zend_Config_Writer_Ini */ - public function setNestSeparator($separator) + public function setRenderWithoutSections($withoutSections=true) { - $this->_nestSeparator = $separator; - + $this->_renderWithoutSections = (bool)$withoutSections; return $this; } /** - * Defined by Zend_Config_Writer + * Render a Zend_Config into a INI config string. * - * @param string $filename - * @param Zend_Config $config - * @param boolean $exclusiveLock - * @throws Zend_Config_Exception When filename was not set - * @throws Zend_Config_Exception When filename is not writable - * @return void + * @since 1.10 + * @return string */ - public function write($filename = null, Zend_Config $config = null, $exclusiveLock = null) + public function render() { - if ($filename !== null) { - $this->setFilename($filename); - } - - if ($config !== null) { - $this->setConfig($config); - } - - if ($exclusiveLock !== null) { - $this->setExclusiveLock($exclusiveLock); - } - - if ($this->_filename === null) { - require_once 'Zend/Config/Exception.php'; - throw new Zend_Config_Exception('No filename was set'); - } - - if ($this->_config === null) { - require_once 'Zend/Config/Exception.php'; - throw new Zend_Config_Exception('No config was set'); - } - $iniString = ''; $extends = $this->_config->getExtends(); $sectionName = $this->_config->getSectionName(); - if (is_string($sectionName)) { + if($this->_renderWithoutSections == true) { + $iniString .= $this->_addBranch($this->_config); + } else if (is_string($sectionName)) { $iniString .= '[' . $sectionName . ']' . "\n" . $this->_addBranch($this->_config) . "\n"; @@ -153,18 +111,7 @@ class Zend_Config_Writer_Ini extends Zend_Config_Writer } } - $flags = 0; - - if ($this->_exclusiveLock) { - $flags |= LOCK_EX; - } - - $result = @file_put_contents($this->_filename, $iniString, $flags); - - if ($result === false) { - require_once 'Zend/Config/Exception.php'; - throw new Zend_Config_Exception('Could not write to file "' . $this->_filename . '"'); - } + return $iniString; } /** diff --git a/libs/Zend/Config/Writer/Xml.php b/libs/Zend/Config/Writer/Xml.php index 6ef5263e60..72fc0a0b8d 100644 --- a/libs/Zend/Config/Writer/Xml.php +++ b/libs/Zend/Config/Writer/Xml.php @@ -14,15 +14,15 @@ * * @category Zend * @package Zend_Config - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 18951 2009-11-12 16:26:19Z alexander $ + * @version $Id: Xml.php 20096 2010-01-06 02:05:09Z bkarwin $ */ /** * @see Zend_Config_Writer */ -require_once 'Zend/Config/Writer.php'; +require_once 'Zend/Config/Writer/FileAbstract.php'; /** * @see Zend_Config_Xml @@ -32,85 +32,19 @@ require_once 'Zend/Config/Xml.php'; /** * @category Zend * @package Zend_Config - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Writer_Xml extends Zend_Config_Writer +class Zend_Config_Writer_Xml extends Zend_Config_Writer_FileAbstract { /** - * Filename to write to + * Render a Zend_Config into a XML config string. * - * @var string + * @since 1.10 + * @return string */ - protected $_filename = null; - - /** - * Wether to exclusively lock the file or not - * - * @var boolean - */ - protected $_exclusiveLock = false; - - /** - * Set the target filename - * - * @param string $filename - * @return Zend_Config_Writer_Xml - */ - public function setFilename($filename) - { - $this->_filename = $filename; - - return $this; - } - - /** - * Set wether to exclusively lock the file or not - * - * @param boolean $exclusiveLock - * @return Zend_Config_Writer_Array - */ - public function setExclusiveLock($exclusiveLock) - { - $this->_exclusiveLock = $exclusiveLock; - - return $this; - } - - /** - * Defined by Zend_Config_Writer - * - * @param string $filename - * @param Zend_Config $config - * @param boolean $exclusiveLock - * @throws Zend_Config_Exception When filename was not set - * @throws Zend_Config_Exception When filename is not writable - * @return void - */ - public function write($filename = null, Zend_Config $config = null, $exclusiveLock = null) + public function render() { - if ($filename !== null) { - $this->setFilename($filename); - } - - if ($config !== null) { - $this->setConfig($config); - } - - if ($exclusiveLock !== null) { - $this->setExclusiveLock($exclusiveLock); - } - - if ($this->_filename === null) { - require_once 'Zend/Config/Exception.php'; - throw new Zend_Config_Exception('No filename was set'); - } - - if ($this->_config === null) { - require_once 'Zend/Config/Exception.php'; - throw new Zend_Config_Exception('No config was set'); - } - $xml = new SimpleXMLElement('<zend-config xmlns:zf="' . Zend_Config_Xml::XML_NAMESPACE . '"/>'); $extends = $this->_config->getExtends(); $sectionName = $this->_config->getSectionName(); @@ -140,18 +74,7 @@ class Zend_Config_Writer_Xml extends Zend_Config_Writer $xmlString = $dom->saveXML(); - $flags = 0; - - if ($this->_exclusiveLock) { - $flags |= LOCK_EX; - } - - $result = @file_put_contents($this->_filename, $xmlString, $flags); - - if ($result === false) { - require_once 'Zend/Config/Exception.php'; - throw new Zend_Config_Exception('Could not write to file "' . $this->_filename . '"'); - } + return $xmlString; } /** @@ -184,7 +107,7 @@ class Zend_Config_Writer_Xml extends Zend_Config_Writer if ($branchType === 'numeric') { if ($value instanceof Zend_Config) { - $child = $parent->addChild($branchName, (string) $value); + $child = $parent->addChild($branchName); $this->_addBranch($value, $child, $parent); } else { diff --git a/libs/Zend/Config/Xml.php b/libs/Zend/Config/Xml.php index e68bfd3b32..fa14b9e42e 100644 --- a/libs/Zend/Config/Xml.php +++ b/libs/Zend/Config/Xml.php @@ -14,9 +14,9 @@ * * @category Zend * @package Zend_Config - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 17267 2009-07-29 02:13:18Z yoshida@zend.co.jp $ + * @version $Id: Xml.php 20096 2010-01-06 02:05:09Z bkarwin $ */ /** @@ -29,7 +29,7 @@ require_once 'Zend/Config.php'; * * @category Zend * @package Zend_Config - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Xml extends Zend_Config @@ -40,7 +40,7 @@ class Zend_Config_Xml extends Zend_Config const XML_NAMESPACE = 'http://framework.zend.com/xml/zend-config-xml/1.0/'; /** - * Wether to skip extends or not + * Whether to skip extends or not * * @var boolean */ @@ -61,7 +61,7 @@ class Zend_Config_Xml extends Zend_Config * * @param string $xml XML file or string to process * @param mixed $section Section to process - * @param boolean $options Whether modifiacations are allowed at runtime + * @param boolean $options Whether modifications are allowed at runtime * @throws Zend_Config_Exception When xml is not set or cannot be loaded * @throws Zend_Config_Exception When section $sectionName cannot be found in $xml */ @@ -283,33 +283,4 @@ class Zend_Config_Xml extends Zend_Config return $config; } - - /** - * Merge two arrays recursively, overwriting keys of the same name - * in $firstArray with the value in $secondArray. - * - * @param mixed $firstArray First array - * @param mixed $secondArray Second array to merge into first array - * @return array - */ - protected function _arrayMergeRecursive($firstArray, $secondArray) - { - if (is_array($firstArray) && is_array($secondArray)) { - foreach ($secondArray as $key => $value) { - if (isset($firstArray[$key])) { - $firstArray[$key] = $this->_arrayMergeRecursive($firstArray[$key], $value); - } else { - if($key === 0) { - $firstArray= array(0=>$this->_arrayMergeRecursive($firstArray, $value)); - } else { - $firstArray[$key] = $value; - } - } - } - } else { - $firstArray = $secondArray; - } - - return $firstArray; - } } diff --git a/libs/Zend/Db.php b/libs/Zend/Db.php index b62bcdbbee..eb0070ce13 100644 --- a/libs/Zend/Db.php +++ b/libs/Zend/Db.php @@ -15,9 +15,9 @@ * * @category Zend * @package Zend_Db - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 18373 2009-09-22 19:16:25Z ralph $ + * @version $Id: Db.php 20096 2010-01-06 02:05:09Z bkarwin $ */ @@ -26,7 +26,7 @@ * * @category Zend * @package Zend_Db - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Db diff --git a/libs/Zend/Db/Adapter/Abstract.php b/libs/Zend/Db/Adapter/Abstract.php index 11cb54d896..ac9403ef28 100644 --- a/libs/Zend/Db/Adapter/Abstract.php +++ b/libs/Zend/Db/Adapter/Abstract.php @@ -15,9 +15,9 @@ * @category Zend * @package Zend_Db * @subpackage Adapter - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 19115 2009-11-20 17:41:25Z matthew $ + * @version $Id: Abstract.php 20096 2010-01-06 02:05:09Z bkarwin $ */ @@ -37,7 +37,7 @@ require_once 'Zend/Db/Select.php'; * @category Zend * @package Zend_Db * @subpackage Adapter - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Db_Adapter_Abstract diff --git a/libs/Zend/Db/Adapter/Db2.php b/libs/Zend/Db/Adapter/Db2.php index 2b91d76b47..7181a45faf 100644 --- a/libs/Zend/Db/Adapter/Db2.php +++ b/libs/Zend/Db/Adapter/Db2.php @@ -15,9 +15,9 @@ * @category Zend * @package Zend_Db * @subpackage Adapter - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 18951 2009-11-12 16:26:19Z alexander $ + * @version $Id: Db2.php 20096 2010-01-06 02:05:09Z bkarwin $ * */ @@ -39,7 +39,7 @@ require_once 'Zend/Db/Statement/Db2.php'; /** * @package Zend_Db - * @copyright Copyright (c) 2005-2009 Zend Technologies Inc. (http://www.zend.com) + * @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/Db/Adapter/Db2/Exception.php b/libs/Zend/Db/Adapter/Db2/Exception.php index 621274745d..2ee356d40c 100644 --- a/libs/Zend/Db/Adapter/Db2/Exception.php +++ b/libs/Zend/Db/Adapter/Db2/Exception.php @@ -15,9 +15,9 @@ * @category Zend * @package Zend_Db * @subpackage Adapter - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 16541 2009-07-07 06:59:03Z bkarwin $ + * @version $Id: Exception.php 20096 2010-01-06 02:05:09Z bkarwin $ */ /** @@ -30,7 +30,7 @@ require_once 'Zend/Db/Adapter/Exception.php'; * * @package Zend_Db * @subpackage Adapter - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Db_Adapter_Db2_Exception extends Zend_Db_Adapter_Exception @@ -38,8 +38,8 @@ class Zend_Db_Adapter_Db2_Exception extends Zend_Db_Adapter_Exception protected $code = '00000'; protected $message = 'unknown exception'; - function __construct($msg = 'unknown exception', $state = '00000') { - $this->message = $msg; - $this->code = $state; + function __construct($message = 'unknown exception', $code = '00000', Exception $e = null) + { + parent::__construct($message, $code, $e); } } diff --git a/libs/Zend/Db/Adapter/Exception.php b/libs/Zend/Db/Adapter/Exception.php index 51c06874a6..06585c1784 100644 --- a/libs/Zend/Db/Adapter/Exception.php +++ b/libs/Zend/Db/Adapter/Exception.php @@ -15,9 +15,9 @@ * @category Zend * @package Zend_Db * @subpackage Adapter - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 17860 2009-08-27 22:48:48Z beberlei $ + * @version $Id: Exception.php 20096 2010-01-06 02:05:09Z bkarwin $ */ /** @@ -29,30 +29,29 @@ require_once 'Zend/Db/Exception.php'; * @category Zend * @package Zend_Db * @subpackage Adapter - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Db_Adapter_Exception extends Zend_Db_Exception { protected $_chainedException = null; - public function __construct($message = null, Exception $e = null) + public function __construct($message = '', $code = 0, Exception $e = null) { - if ($e) { - $this->_chainedException = $e; - $this->code = $e->getCode(); + if ($e && (0 === $code)) { + $code = $e->getCode(); } - parent::__construct($message); + parent::__construct($message, $code, $e); } public function hasChainedException() { - return ($this->_chainedException!==null); + return ($this->_previous !== null); } public function getChainedException() { - return $this->_chainedException; + return $this->getPrevious(); } } diff --git a/libs/Zend/Db/Adapter/Mysqli.php b/libs/Zend/Db/Adapter/Mysqli.php index 3b686948c8..a92a00fef8 100644 --- a/libs/Zend/Db/Adapter/Mysqli.php +++ b/libs/Zend/Db/Adapter/Mysqli.php @@ -15,9 +15,9 @@ * @category Zend * @package Zend_Db * @subpackage Adapter - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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: Mysqli.php 16203 2009-06-21 18:56:17Z thomas $ + * @version $Id: Mysqli.php 20096 2010-01-06 02:05:09Z bkarwin $ */ @@ -46,7 +46,7 @@ require_once 'Zend/Db/Statement/Mysqli.php'; * @category Zend * @package Zend_Db * @subpackage Adapter - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Db_Adapter_Mysqli extends Zend_Db_Adapter_Abstract diff --git a/libs/Zend/Db/Adapter/Mysqli/Exception.php b/libs/Zend/Db/Adapter/Mysqli/Exception.php index f2fbd8f958..2c3eb93efd 100644 --- a/libs/Zend/Db/Adapter/Mysqli/Exception.php +++ b/libs/Zend/Db/Adapter/Mysqli/Exception.php @@ -15,9 +15,9 @@ * @category Zend * @package Zend_Db * @subpackage Adapter - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 16541 2009-07-07 06:59:03Z bkarwin $ + * @version $Id: Exception.php 20096 2010-01-06 02:05:09Z bkarwin $ * */ @@ -32,7 +32,7 @@ require_once 'Zend/Db/Adapter/Exception.php'; * @category Zend * @package Zend_Db * @subpackage Adapter - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Db_Adapter_Mysqli_Exception extends Zend_Db_Adapter_Exception diff --git a/libs/Zend/Db/Adapter/Oracle.php b/libs/Zend/Db/Adapter/Oracle.php index ec25091463..474a8d0f88 100644 --- a/libs/Zend/Db/Adapter/Oracle.php +++ b/libs/Zend/Db/Adapter/Oracle.php @@ -15,9 +15,9 @@ * @category Zend * @package Zend_Db * @subpackage Adapter - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 19048 2009-11-19 18:15:05Z mikaelkael $ + * @version $Id: Oracle.php 20096 2010-01-06 02:05:09Z bkarwin $ */ /** @@ -34,7 +34,7 @@ require_once 'Zend/Db/Statement/Oracle.php'; * @category Zend * @package Zend_Db * @subpackage Adapter - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Db_Adapter_Oracle extends Zend_Db_Adapter_Abstract diff --git a/libs/Zend/Db/Adapter/Oracle/Exception.php b/libs/Zend/Db/Adapter/Oracle/Exception.php index 39809b10df..61f4a3dc88 100644 --- a/libs/Zend/Db/Adapter/Oracle/Exception.php +++ b/libs/Zend/Db/Adapter/Oracle/Exception.php @@ -15,9 +15,9 @@ * @category Zend * @package Zend_Db * @subpackage Adapter - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 16541 2009-07-07 06:59:03Z bkarwin $ + * @version $Id: Exception.php 20096 2010-01-06 02:05:09Z bkarwin $ */ /** @@ -31,7 +31,7 @@ require_once 'Zend/Db/Adapter/Exception.php'; * @category Zend * @package Zend_Db * @subpackage Adapter - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Db_Adapter_Oracle_Exception extends Zend_Db_Adapter_Exception diff --git a/libs/Zend/Db/Adapter/Pdo/Abstract.php b/libs/Zend/Db/Adapter/Pdo/Abstract.php index d6a6a7d403..97dd2fdf8f 100644 --- a/libs/Zend/Db/Adapter/Pdo/Abstract.php +++ b/libs/Zend/Db/Adapter/Pdo/Abstract.php @@ -15,9 +15,9 @@ * @category Zend * @package Zend_Db * @subpackage Adapter - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 18951 2009-11-12 16:26:19Z alexander $ + * @version $Id: Abstract.php 20096 2010-01-06 02:05:09Z bkarwin $ */ @@ -39,7 +39,7 @@ require_once 'Zend/Db/Statement/Pdo.php'; * @category Zend * @package Zend_Db * @subpackage Adapter - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Db_Adapter_Pdo_Abstract extends Zend_Db_Adapter_Abstract @@ -141,7 +141,7 @@ abstract class Zend_Db_Adapter_Pdo_Abstract extends Zend_Db_Adapter_Abstract * @see Zend_Db_Adapter_Exception */ require_once 'Zend/Db/Adapter/Exception.php'; - throw new Zend_Db_Adapter_Exception($e->getMessage(), $e); + throw new Zend_Db_Adapter_Exception($e->getMessage(), $e->getCode(), $e); } } @@ -277,7 +277,7 @@ abstract class Zend_Db_Adapter_Pdo_Abstract extends Zend_Db_Adapter_Abstract * @see Zend_Db_Adapter_Exception */ require_once 'Zend/Db/Adapter/Exception.php'; - throw new Zend_Db_Adapter_Exception($e->getMessage(), $e); + throw new Zend_Db_Adapter_Exception($e->getMessage(), $e->getCode(), $e); } } diff --git a/libs/Zend/Db/Adapter/Pdo/Ibm.php b/libs/Zend/Db/Adapter/Pdo/Ibm.php index 47d91da0dc..92f740d4d0 100644 --- a/libs/Zend/Db/Adapter/Pdo/Ibm.php +++ b/libs/Zend/Db/Adapter/Pdo/Ibm.php @@ -15,9 +15,9 @@ * @category Zend * @package Zend_Db * @subpackage Adapter - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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: Ibm.php 16203 2009-06-21 18:56:17Z thomas $ + * @version $Id: Ibm.php 20096 2010-01-06 02:05:09Z bkarwin $ */ @@ -38,7 +38,7 @@ require_once 'Zend/Db/Statement/Pdo/Ibm.php'; * @category Zend * @package Zend_Db * @subpackage Adapter - * @copyright Copyright (c) 2005-2009 Zend Technologies Inc. (http://www.zend.com) + * @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_Db_Adapter_Pdo_Ibm extends Zend_Db_Adapter_Pdo_Abstract @@ -134,9 +134,9 @@ class Zend_Db_Adapter_Pdo_Ibm extends Zend_Db_Adapter_Pdo_Abstract require_once 'Zend/Db/Adapter/Exception.php'; $error = strpos($e->getMessage(), 'driver does not support that attribute'); if ($error) { - throw new Zend_Db_Adapter_Exception("PDO_IBM driver extension is downlevel. Please use driver release version 1.2.1 or later"); + throw new Zend_Db_Adapter_Exception("PDO_IBM driver extension is downlevel. Please use driver release version 1.2.1 or later", 0, $e); } else { - throw new Zend_Db_Adapter_Exception($e->getMessage()); + throw new Zend_Db_Adapter_Exception($e->getMessage(), $e->getCode(), $e); } } } diff --git a/libs/Zend/Db/Adapter/Pdo/Ibm/Db2.php b/libs/Zend/Db/Adapter/Pdo/Ibm/Db2.php index 99182c0576..214b71626c 100644 --- a/libs/Zend/Db/Adapter/Pdo/Ibm/Db2.php +++ b/libs/Zend/Db/Adapter/Pdo/Ibm/Db2.php @@ -15,9 +15,9 @@ * @category Zend * @package Zend_Db * @subpackage Adapter - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 16203 2009-06-21 18:56:17Z thomas $ + * @version $Id: Db2.php 20096 2010-01-06 02:05:09Z bkarwin $ */ @@ -32,7 +32,7 @@ require_once 'Zend/Db/Statement/Pdo/Ibm.php'; * @category Zend * @package Zend_Db * @subpackage Adapter - * @copyright Copyright (c) 2005-2009 Zend Technologies Inc. (http://www.zend.com) + * @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_Db_Adapter_Pdo_Ibm_Db2 diff --git a/libs/Zend/Db/Adapter/Pdo/Ibm/Ids.php b/libs/Zend/Db/Adapter/Pdo/Ibm/Ids.php index 766106332b..7c710b45d6 100644 --- a/libs/Zend/Db/Adapter/Pdo/Ibm/Ids.php +++ b/libs/Zend/Db/Adapter/Pdo/Ibm/Ids.php @@ -15,9 +15,9 @@ * @category Zend * @package Zend_Db * @subpackage Adapter - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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: Ids.php 16971 2009-07-22 18:05:45Z mikaelkael $ + * @version $Id: Ids.php 20096 2010-01-06 02:05:09Z bkarwin $ */ @@ -32,7 +32,7 @@ require_once 'Zend/Db/Statement/Pdo/Ibm.php'; * @category Zend * @package Zend_Db * @subpackage Adapter - * @copyright Copyright (c) 2005-2009 Zend Technologies Inc. (http://www.zend.com) + * @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_Db_Adapter_Pdo_Ibm_Ids diff --git a/libs/Zend/Db/Adapter/Pdo/Mssql.php b/libs/Zend/Db/Adapter/Pdo/Mssql.php index 78f27c7af9..3c3fb7710f 100644 --- a/libs/Zend/Db/Adapter/Pdo/Mssql.php +++ b/libs/Zend/Db/Adapter/Pdo/Mssql.php @@ -15,9 +15,9 @@ * @category Zend * @package Zend_Db * @subpackage Adapter - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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: Mssql.php 18951 2009-11-12 16:26:19Z alexander $ + * @version $Id: Mssql.php 20096 2010-01-06 02:05:09Z bkarwin $ */ @@ -33,7 +33,7 @@ require_once 'Zend/Db/Adapter/Pdo/Abstract.php'; * @category Zend * @package Zend_Db * @subpackage Adapter - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Db_Adapter_Pdo_Mssql extends Zend_Db_Adapter_Pdo_Abstract diff --git a/libs/Zend/Db/Adapter/Pdo/Mysql.php b/libs/Zend/Db/Adapter/Pdo/Mysql.php index 98551812cc..768b887115 100644 --- a/libs/Zend/Db/Adapter/Pdo/Mysql.php +++ b/libs/Zend/Db/Adapter/Pdo/Mysql.php @@ -15,9 +15,9 @@ * @category Zend * @package Zend_Db * @subpackage Adapter - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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: Mysql.php 16942 2009-07-22 04:03:09Z ralph $ + * @version $Id: Mysql.php 20096 2010-01-06 02:05:09Z bkarwin $ */ @@ -33,7 +33,7 @@ require_once 'Zend/Db/Adapter/Pdo/Abstract.php'; * @category Zend * @package Zend_Db * @subpackage Adapter - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Db_Adapter_Pdo_Mysql extends Zend_Db_Adapter_Pdo_Abstract diff --git a/libs/Zend/Db/Adapter/Pdo/Oci.php b/libs/Zend/Db/Adapter/Pdo/Oci.php index 35faeb1421..195cdd3375 100644 --- a/libs/Zend/Db/Adapter/Pdo/Oci.php +++ b/libs/Zend/Db/Adapter/Pdo/Oci.php @@ -15,9 +15,9 @@ * @category Zend * @package Zend_Db * @subpackage Adapter - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 19048 2009-11-19 18:15:05Z mikaelkael $ + * @version $Id: Oci.php 20096 2010-01-06 02:05:09Z bkarwin $ */ @@ -33,7 +33,7 @@ require_once 'Zend/Db/Adapter/Pdo/Abstract.php'; * @category Zend * @package Zend_Db * @subpackage Adapter - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Db_Adapter_Pdo_Oci extends Zend_Db_Adapter_Pdo_Abstract diff --git a/libs/Zend/Db/Adapter/Pdo/Pgsql.php b/libs/Zend/Db/Adapter/Pdo/Pgsql.php index be8afff557..d4fb174516 100644 --- a/libs/Zend/Db/Adapter/Pdo/Pgsql.php +++ b/libs/Zend/Db/Adapter/Pdo/Pgsql.php @@ -15,9 +15,9 @@ * @category Zend * @package Zend_Db * @subpackage Adapter - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 19377 2009-12-03 18:16:12Z mikaelkael $ + * @version $Id: Pgsql.php 20096 2010-01-06 02:05:09Z bkarwin $ */ @@ -33,7 +33,7 @@ require_once 'Zend/Db/Adapter/Pdo/Abstract.php'; * @category Zend * @package Zend_Db * @subpackage Adapter - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Db_Adapter_Pdo_Pgsql extends Zend_Db_Adapter_Pdo_Abstract @@ -195,15 +195,15 @@ class Zend_Db_Adapter_Pdo_Pgsql extends Zend_Db_Adapter_Pdo_Abstract $desc = array(); foreach ($result as $key => $row) { $defaultValue = $row[$default_value]; - if ($row[$type] == 'varchar') { - if (preg_match('/character varying(?:\((\d+)\))?/', $row[$complete_type], $matches)) { + if ($row[$type] == 'varchar' || $row[$type] == 'bpchar' ) { + if (preg_match('/character(?: varying)?(?:\((\d+)\))?/', $row[$complete_type], $matches)) { if (isset($matches[1])) { $row[$length] = $matches[1]; } else { $row[$length] = null; // unlimited } } - if (preg_match("/^'(.*?)'::character varying$/", $defaultValue, $matches)) { + if (preg_match("/^'(.*?)'::(?:character varying|bpchar)$/", $defaultValue, $matches)) { $defaultValue = $matches[1]; } } diff --git a/libs/Zend/Db/Adapter/Pdo/Sqlite.php b/libs/Zend/Db/Adapter/Pdo/Sqlite.php index 30f75b41ec..afc26c53e7 100644 --- a/libs/Zend/Db/Adapter/Pdo/Sqlite.php +++ b/libs/Zend/Db/Adapter/Pdo/Sqlite.php @@ -15,9 +15,9 @@ * @category Zend * @package Zend_Db * @subpackage Adapter - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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: Sqlite.php 18951 2009-11-12 16:26:19Z alexander $ + * @version $Id: Sqlite.php 20096 2010-01-06 02:05:09Z bkarwin $ */ @@ -33,7 +33,7 @@ require_once 'Zend/Db/Adapter/Pdo/Abstract.php'; * @category Zend * @package Zend_Db * @subpackage Adapter - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Db_Adapter_Pdo_Sqlite extends Zend_Db_Adapter_Pdo_Abstract diff --git a/libs/Zend/Db/Adapter/Sqlsrv.php b/libs/Zend/Db/Adapter/Sqlsrv.php index 3de2500ea1..51c7345dff 100644 --- a/libs/Zend/Db/Adapter/Sqlsrv.php +++ b/libs/Zend/Db/Adapter/Sqlsrv.php @@ -15,8 +15,9 @@ * @category Zend * @package Zend_Db * @subpackage Adapter - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 20630 2010-01-25 21:18:20Z ralph $ */ /** @@ -33,7 +34,7 @@ require_once 'Zend/Db/Statement/Sqlsrv.php'; * @category Zend * @package Zend_Db * @subpackage Adapter - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Db_Adapter_Sqlsrv extends Zend_Db_Adapter_Abstract @@ -147,11 +148,11 @@ class Zend_Db_Adapter_Sqlsrv extends Zend_Db_Adapter_Abstract foreach ($this->_config['driver_options'] as $option => $value) { // A value may be a constant. if (is_string($value)) { - $constantValue = @constant(strtoupper($value)); - if ($constantValue === null) { - $connectionInfo[$option] = $value; + $constantName = strtoupper($value); + if (defined($constantName)) { + $connectionInfo[$option] = constant($constantName); } else { - $connectionInfo[$option] = $constantValue; + $connectionInfo[$option] = $value; } } } diff --git a/libs/Zend/Db/Adapter/Sqlsrv/Exception.php b/libs/Zend/Db/Adapter/Sqlsrv/Exception.php index a07b3eb9a3..75fd142676 100644 --- a/libs/Zend/Db/Adapter/Sqlsrv/Exception.php +++ b/libs/Zend/Db/Adapter/Sqlsrv/Exception.php @@ -15,9 +15,9 @@ * @category Zend * @package Zend_Db * @subpackage Adapter - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 $ */ /** @@ -31,7 +31,7 @@ require_once 'Zend/Db/Adapter/Exception.php'; * @category Zend * @package Zend_Db * @subpackage Adapter - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Db_Adapter_Sqlsrv_Exception extends Zend_Db_Adapter_Exception @@ -58,6 +58,6 @@ class Zend_Db_Adapter_Sqlsrv_Exception extends Zend_Db_Adapter_Exception $code = (int) $message['code']; $message = (string) $message['message']; } - parent::__construct($message, new Exception($message, $code)); + parent::__construct($message, $code, new Exception($message, $code)); } } diff --git a/libs/Zend/Db/Exception.php b/libs/Zend/Db/Exception.php index 3d30302674..2d1987c6e2 100644 --- a/libs/Zend/Db/Exception.php +++ b/libs/Zend/Db/Exception.php @@ -14,9 +14,9 @@ * * @category Zend * @package Zend_Db - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 16541 2009-07-07 06:59:03Z bkarwin $ + * @version $Id: Exception.php 20096 2010-01-06 02:05:09Z bkarwin $ */ /** @@ -27,7 +27,7 @@ require_once 'Zend/Exception.php'; /** * @category Zend * @package Zend_Db - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Db_Exception extends Zend_Exception diff --git a/libs/Zend/Db/Expr.php b/libs/Zend/Db/Expr.php index 2f2b7d51db..df366b3b2a 100644 --- a/libs/Zend/Db/Expr.php +++ b/libs/Zend/Db/Expr.php @@ -15,9 +15,9 @@ * @category Zend * @package Zend_Db * @subpackage Expr - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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: Expr.php 16203 2009-06-21 18:56:17Z thomas $ + * @version $Id: Expr.php 20096 2010-01-06 02:05:09Z bkarwin $ */ @@ -43,7 +43,7 @@ * @category Zend * @package Zend_Db * @subpackage Expr - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Db_Expr diff --git a/libs/Zend/Db/Profiler.php b/libs/Zend/Db/Profiler.php index d0b2af5f1a..007fa78886 100644 --- a/libs/Zend/Db/Profiler.php +++ b/libs/Zend/Db/Profiler.php @@ -15,9 +15,9 @@ * @category Zend * @package Zend_Db * @subpackage Profiler - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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: Profiler.php 16203 2009-06-21 18:56:17Z thomas $ + * @version $Id: Profiler.php 20096 2010-01-06 02:05:09Z bkarwin $ */ @@ -25,7 +25,7 @@ * @category Zend * @package Zend_Db * @subpackage Profiler - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Db_Profiler @@ -68,6 +68,15 @@ class Zend_Db_Profiler */ const TRANSACTION = 64; + /** + * Inform that a query is stored (in case of filtering) + */ + const STORED = 'stored'; + + /** + * Inform that a query is ignored (in case of filtering) + */ + const IGNORED = 'ignored'; /** * Array of Zend_Db_Profiler_Query objects. @@ -289,7 +298,7 @@ class Zend_Db_Profiler { // Don't do anything if the Zend_Db_Profiler is not enabled. if (!$this->_enabled) { - return; + return self::IGNORED; } // Check for a valid query handle. @@ -321,7 +330,7 @@ class Zend_Db_Profiler */ if (null !== $this->_filterElapsedSecs && $qp->getElapsedSecs() < $this->_filterElapsedSecs) { unset($this->_queryProfiles[$queryId]); - return; + return self::IGNORED; } /** @@ -330,8 +339,10 @@ class Zend_Db_Profiler */ if (null !== $this->_filterTypes && !($qp->getQueryType() & $this->_filterTypes)) { unset($this->_queryProfiles[$queryId]); - return; + return self::IGNORED; } + + return self::STORED; } /** diff --git a/libs/Zend/Db/Profiler/Exception.php b/libs/Zend/Db/Profiler/Exception.php index 3494622c2d..9af1232469 100644 --- a/libs/Zend/Db/Profiler/Exception.php +++ b/libs/Zend/Db/Profiler/Exception.php @@ -15,9 +15,9 @@ * @category Zend * @package Zend_Db * @subpackage Profiler - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 16203 2009-06-21 18:56:17Z thomas $ + * @version $Id: Exception.php 20096 2010-01-06 02:05:09Z bkarwin $ */ @@ -31,7 +31,7 @@ require_once 'Zend/Db/Exception.php'; * @category Zend * @package Zend_Db * @subpackage Profiler - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Db_Profiler_Exception extends Zend_Db_Exception diff --git a/libs/Zend/Db/Profiler/Firebug.php b/libs/Zend/Db/Profiler/Firebug.php index 85fcc2f9b8..6be53add05 100644 --- a/libs/Zend/Db/Profiler/Firebug.php +++ b/libs/Zend/Db/Profiler/Firebug.php @@ -15,9 +15,9 @@ * @category Zend * @package Zend_Db * @subpackage Profiler - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 18951 2009-11-12 16:26:19Z alexander $ + * @version $Id: Firebug.php 20096 2010-01-06 02:05:09Z bkarwin $ */ /** Zend_Db_Profiler */ @@ -35,7 +35,7 @@ require_once 'Zend/Wildfire/Plugin/FirePhp/TableMessage.php'; * @category Zend * @package Zend_Db * @subpackage Profiler - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Db_Profiler_Firebug extends Zend_Db_Profiler @@ -121,9 +121,9 @@ class Zend_Db_Profiler_Firebug extends Zend_Db_Profiler */ public function queryEnd($queryId) { - parent::queryEnd($queryId); + $state = parent::queryEnd($queryId); - if (!$this->getEnabled()) { + if (!$this->getEnabled() || $state == self::IGNORED) { return; } diff --git a/libs/Zend/Db/Profiler/Query.php b/libs/Zend/Db/Profiler/Query.php index 74f3fe1aec..aacc16fbb9 100644 --- a/libs/Zend/Db/Profiler/Query.php +++ b/libs/Zend/Db/Profiler/Query.php @@ -15,9 +15,9 @@ * @category Zend * @package Zend_Db * @subpackage Profiler - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 16203 2009-06-21 18:56:17Z thomas $ + * @version $Id: Query.php 20096 2010-01-06 02:05:09Z bkarwin $ */ @@ -25,7 +25,7 @@ * @category Zend * @package Zend_Db * @subpackage Profiler - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Db_Profiler_Query diff --git a/libs/Zend/Db/Select.php b/libs/Zend/Db/Select.php index 4a9e90fecf..4ef6536ba0 100644 --- a/libs/Zend/Db/Select.php +++ b/libs/Zend/Db/Select.php @@ -15,9 +15,9 @@ * @category Zend * @package Zend_Db * @subpackage Select - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 19155 2009-11-21 09:48:02Z mikaelkael $ + * @version $Id: Select.php 20096 2010-01-06 02:05:09Z bkarwin $ */ @@ -38,7 +38,7 @@ require_once 'Zend/Db/Expr.php'; * @category Zend * @package Zend_Db * @subpackage Select - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Db_Select @@ -243,7 +243,8 @@ class Zend_Db_Select public function columns($cols = '*', $correlationName = null) { if ($correlationName === null && count($this->_parts[self::FROM])) { - $correlationName = current(array_keys($this->_parts[self::FROM])); + $correlationNameKeys = array_keys($this->_parts[self::FROM]); + $correlationName = current($correlationNameKeys); } if (!array_key_exists($correlationName, $this->_parts[self::FROM])) { @@ -262,16 +263,27 @@ class Zend_Db_Select /** * Adds a UNION clause to the query. * - * The first parameter $select can be a string, an existing Zend_Db_Select - * object or an array of either of these types. + * The first parameter has to be an array of Zend_Db_Select or + * sql query strings. * - * @param array|string|Zend_Db_Select $select One or more select clauses for the UNION. + * <code> + * $sql1 = $db->select(); + * $sql2 = "SELECT ..."; + * $select = $db->select() + * ->union(array($sql1, $sql2)) + * ->order("id"); + * </code> + * + * @param array $select Array of select clauses for the union. * @return Zend_Db_Select This Zend_Db_Select object. */ public function union($select = array(), $type = self::SQL_UNION) { if (!is_array($select)) { - $select = array(); + require_once 'Zend/Db/Select/Exception.php'; + throw new Zend_Db_Select_Exception( + "union() only accepts an array of Zend_Db_Select instances of sql query strings." + ); } if (!in_array($type, self::$_unionTypes)) { @@ -454,7 +466,7 @@ class Zend_Db_Select * </code> * * @param string $cond The WHERE condition. - * @param string $value OPTIONAL A single value to quote into the condition. + * @param mixed $value OPTIONAL The value to quote into the condition. * @param constant $type OPTIONAL The type of the given value * @return Zend_Db_Select This Zend_Db_Select object. */ @@ -471,7 +483,7 @@ class Zend_Db_Select * Otherwise identical to where(). * * @param string $cond The WHERE condition. - * @param string $value OPTIONAL A single value to quote into the condition. + * @param mixed $value OPTIONAL The value to quote into the condition. * @param constant $type OPTIONAL The type of the given value * @return Zend_Db_Select This Zend_Db_Select object. * @@ -514,7 +526,7 @@ class Zend_Db_Select * appears. See {@link where()} for an example * * @param string $cond The HAVING condition. - * @param string|Zend_Db_Expr $val A single value to quote into the condition. + * @param string|Zend_Db_Expr $val The value to quote into the condition. * @return Zend_Db_Select This Zend_Db_Select object. */ public function having($cond) @@ -539,7 +551,7 @@ class Zend_Db_Select * Otherwise identical to orHaving(). * * @param string $cond The HAVING condition. - * @param string $val A single value to quote into the condition. + * @param mixed $val The value to quote into the condition. * @return Zend_Db_Select This Zend_Db_Select object. * * @see having() @@ -972,7 +984,7 @@ class Zend_Db_Select * Internal function for creating the where clause * * @param string $condition - * @param string $value optional + * @param mixed $value optional * @param string $type optional * @param boolean $bool true = AND, false = OR * @return string clause diff --git a/libs/Zend/Db/Select/Exception.php b/libs/Zend/Db/Select/Exception.php index 23fdf2dfec..d95fdb20de 100644 --- a/libs/Zend/Db/Select/Exception.php +++ b/libs/Zend/Db/Select/Exception.php @@ -15,9 +15,9 @@ * @category Zend * @package Zend_Db * @subpackage Select - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 16541 2009-07-07 06:59:03Z bkarwin $ + * @version $Id: Exception.php 20096 2010-01-06 02:05:09Z bkarwin $ */ /** @@ -29,7 +29,7 @@ require_once 'Zend/Db/Exception.php'; * @category Zend * @package Zend_Db * @subpackage Select - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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/Db/Statement.php b/libs/Zend/Db/Statement.php index 5504f34c15..6e8d20a4ab 100644 --- a/libs/Zend/Db/Statement.php +++ b/libs/Zend/Db/Statement.php @@ -15,9 +15,9 @@ * @category Zend * @package Zend_Db * @subpackage Statement - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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: Statement.php 18951 2009-11-12 16:26:19Z alexander $ + * @version $Id: Statement.php 20096 2010-01-06 02:05:09Z bkarwin $ */ /** @@ -36,7 +36,7 @@ require_once 'Zend/Db/Statement/Interface.php'; * @category Zend * @package Zend_Db * @subpackage Statement - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Db_Statement implements Zend_Db_Statement_Interface diff --git a/libs/Zend/Db/Statement/Db2.php b/libs/Zend/Db/Statement/Db2.php index 68ec9ee26a..eec6575306 100644 --- a/libs/Zend/Db/Statement/Db2.php +++ b/libs/Zend/Db/Statement/Db2.php @@ -15,9 +15,9 @@ * @category Zend * @package Zend_Db * @subpackage Statement - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 18951 2009-11-12 16:26:19Z alexander $ + * @version $Id: Db2.php 20096 2010-01-06 02:05:09Z bkarwin $ */ /** @@ -30,7 +30,7 @@ require_once 'Zend/Db/Statement.php'; * * @package Zend_Db * @subpackage Statement - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Db_Statement_Db2 extends Zend_Db_Statement diff --git a/libs/Zend/Db/Statement/Db2/Exception.php b/libs/Zend/Db/Statement/Db2/Exception.php index 0b04bf4af2..d758854d8f 100644 --- a/libs/Zend/Db/Statement/Db2/Exception.php +++ b/libs/Zend/Db/Statement/Db2/Exception.php @@ -15,9 +15,9 @@ * @category Zend * @package Zend_Db * @subpackage Statement - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 16541 2009-07-07 06:59:03Z bkarwin $ + * @version $Id: Exception.php 20096 2010-01-06 02:05:09Z bkarwin $ */ /** @@ -28,7 +28,7 @@ require_once 'Zend/Db/Statement/Exception.php'; /** * @package Zend_Db * @subpackage Statement - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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/Db/Statement/Exception.php b/libs/Zend/Db/Statement/Exception.php index 61291f43d0..f628ea059f 100644 --- a/libs/Zend/Db/Statement/Exception.php +++ b/libs/Zend/Db/Statement/Exception.php @@ -15,9 +15,9 @@ * @category Zend * @package Zend_Db * @subpackage Statement - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 18951 2009-11-12 16:26:19Z alexander $ + * @version $Id: Exception.php 20514 2010-01-22 07:57:10Z ralph $ */ /** @@ -31,36 +31,19 @@ require_once 'Zend/Db/Exception.php'; * @category Zend * @package Zend_Db * @subpackage Statement - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Db_Statement_Exception extends Zend_Db_Exception { /** - * @var Exception - */ - protected $_chainedException = null; - - /** - * @param string $message - * @param string|int $code - * @param Exception $chainedException - */ - public function __construct($message = null, $code = null, Exception $chainedException=null) - { - $this->message = $message; - $this->code = $code; - $this->_chainedException = $chainedException; - } - - /** * Check if this general exception has a specific database driver specific exception nested inside. * * @return bool */ public function hasChainedException() { - return ($this->_chainedException!==null); + return ($this->getPrevious() !== null); } /** @@ -68,6 +51,6 @@ class Zend_Db_Statement_Exception extends Zend_Db_Exception */ public function getChainedException() { - return $this->_chainedException; + return $this->getPrevious(); } } diff --git a/libs/Zend/Db/Statement/Interface.php b/libs/Zend/Db/Statement/Interface.php index 2cf951b057..701c64010e 100644 --- a/libs/Zend/Db/Statement/Interface.php +++ b/libs/Zend/Db/Statement/Interface.php @@ -15,9 +15,9 @@ * @category Zend * @package Zend_Db * @subpackage Statement - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 16541 2009-07-07 06:59:03Z bkarwin $ + * @version $Id: Interface.php 20096 2010-01-06 02:05:09Z bkarwin $ */ /** @@ -26,7 +26,7 @@ * @category Zend * @package Zend_Db * @subpackage Statement - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Db_Statement_Interface diff --git a/libs/Zend/Db/Statement/Mysqli.php b/libs/Zend/Db/Statement/Mysqli.php index 32754fba68..808f692763 100644 --- a/libs/Zend/Db/Statement/Mysqli.php +++ b/libs/Zend/Db/Statement/Mysqli.php @@ -15,9 +15,9 @@ * @category Zend * @package Zend_Db * @subpackage Statement - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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: Mysqli.php 18951 2009-11-12 16:26:19Z alexander $ + * @version $Id: Mysqli.php 20096 2010-01-06 02:05:09Z bkarwin $ */ @@ -33,7 +33,7 @@ require_once 'Zend/Db/Statement.php'; * @category Zend * @package Zend_Db * @subpackage Statement - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Db_Statement_Mysqli extends Zend_Db_Statement diff --git a/libs/Zend/Db/Statement/Mysqli/Exception.php b/libs/Zend/Db/Statement/Mysqli/Exception.php index a90162db02..a1c5ff8e79 100644 --- a/libs/Zend/Db/Statement/Mysqli/Exception.php +++ b/libs/Zend/Db/Statement/Mysqli/Exception.php @@ -15,9 +15,9 @@ * @category Zend * @package Zend_Db * @subpackage Statement - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 16541 2009-07-07 06:59:03Z bkarwin $ + * @version $Id: Exception.php 20096 2010-01-06 02:05:09Z bkarwin $ */ /** @@ -28,7 +28,7 @@ require_once 'Zend/Db/Statement/Exception.php'; /** * @package Zend_Db * @subpackage Statement - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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/Db/Statement/Oracle.php b/libs/Zend/Db/Statement/Oracle.php index 0c8c18a6bd..6aedc93d8a 100644 --- a/libs/Zend/Db/Statement/Oracle.php +++ b/libs/Zend/Db/Statement/Oracle.php @@ -15,9 +15,9 @@ * @category Zend * @package Zend_Db * @subpackage Statement - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 18636 2009-10-17 05:44:41Z ralph $ + * @version $Id: Oracle.php 20096 2010-01-06 02:05:09Z bkarwin $ */ /** @@ -31,7 +31,7 @@ require_once 'Zend/Db/Statement.php'; * @category Zend * @package Zend_Db * @subpackage Statement - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Db_Statement_Oracle extends Zend_Db_Statement diff --git a/libs/Zend/Db/Statement/Oracle/Exception.php b/libs/Zend/Db/Statement/Oracle/Exception.php index 26f5412eef..215477bbcd 100644 --- a/libs/Zend/Db/Statement/Oracle/Exception.php +++ b/libs/Zend/Db/Statement/Oracle/Exception.php @@ -15,9 +15,9 @@ * @category Zend * @package Zend_Db * @subpackage Statement - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 16541 2009-07-07 06:59:03Z bkarwin $ + * @version $Id: Exception.php 20096 2010-01-06 02:05:09Z bkarwin $ */ /** @@ -29,7 +29,7 @@ require_once 'Zend/Db/Statement/Exception.php'; * @category Zend * @package Zend_Db * @subpackage Statement - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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/Db/Statement/Pdo.php b/libs/Zend/Db/Statement/Pdo.php index 81942bf678..775e401032 100644 --- a/libs/Zend/Db/Statement/Pdo.php +++ b/libs/Zend/Db/Statement/Pdo.php @@ -15,9 +15,9 @@ * @category Zend * @package Zend_Db * @subpackage Statement - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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: Pdo.php 18951 2009-11-12 16:26:19Z alexander $ + * @version $Id: Pdo.php 20096 2010-01-06 02:05:09Z bkarwin $ */ /** @@ -34,7 +34,7 @@ require_once 'Zend/Db/Statement.php'; * @category Zend * @package Zend_Db * @subpackage Statement - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Db_Statement_Pdo extends Zend_Db_Statement implements IteratorAggregate @@ -231,7 +231,7 @@ class Zend_Db_Statement_Pdo extends Zend_Db_Statement implements IteratorAggrega } } catch (PDOException $e) { require_once 'Zend/Db/Statement/Exception.php'; - throw new Zend_Db_Statement_Exception($e->getMessage(), $e->getCode(), $e); + throw new Zend_Db_Statement_Exception($e->getMessage(), (int) $e->getCode(), $e); } } diff --git a/libs/Zend/Db/Statement/Pdo/Ibm.php b/libs/Zend/Db/Statement/Pdo/Ibm.php index 29ae3db62e..52eb23b88a 100644 --- a/libs/Zend/Db/Statement/Pdo/Ibm.php +++ b/libs/Zend/Db/Statement/Pdo/Ibm.php @@ -15,9 +15,9 @@ * @category Zend * @package Zend_Db * @subpackage Statement - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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: Ibm.php 17860 2009-08-27 22:48:48Z beberlei $ + * @version $Id: Ibm.php 20096 2010-01-06 02:05:09Z bkarwin $ */ /** @@ -34,7 +34,7 @@ require_once 'Zend/Db/Statement/Pdo.php'; * @category Zend * @package Zend_Db * @subpackage Statement - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Db_Statement_Pdo_Ibm extends Zend_Db_Statement_Pdo diff --git a/libs/Zend/Db/Statement/Pdo/Oci.php b/libs/Zend/Db/Statement/Pdo/Oci.php index e4b1edc638..247354f8af 100644 --- a/libs/Zend/Db/Statement/Pdo/Oci.php +++ b/libs/Zend/Db/Statement/Pdo/Oci.php @@ -15,9 +15,9 @@ * @category Zend * @package Zend_Db * @subpackage Statement - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 16971 2009-07-22 18:05:45Z mikaelkael $ + * @version $Id: Oci.php 20096 2010-01-06 02:05:09Z bkarwin $ */ /** @@ -34,7 +34,7 @@ require_once 'Zend/Db/Statement/Pdo.php'; * @category Zend * @package Zend_Db * @subpackage Statement - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Db_Statement_Pdo_Oci extends Zend_Db_Statement_Pdo diff --git a/libs/Zend/Db/Statement/Sqlsrv.php b/libs/Zend/Db/Statement/Sqlsrv.php index 45c243edf1..0460991b87 100644 --- a/libs/Zend/Db/Statement/Sqlsrv.php +++ b/libs/Zend/Db/Statement/Sqlsrv.php @@ -15,8 +15,9 @@ * @category Zend * @package Zend_Db * @subpackage Statement - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 $ */ /** @@ -30,7 +31,7 @@ require_once 'Zend/Db/Statement.php'; * @category Zend * @package Zend_Db * @subpackage Statement - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Db_Statement_Sqlsrv extends Zend_Db_Statement diff --git a/libs/Zend/Db/Statement/Sqlsrv/Exception.php b/libs/Zend/Db/Statement/Sqlsrv/Exception.php index 02378627f9..4c0fb095b5 100644 --- a/libs/Zend/Db/Statement/Sqlsrv/Exception.php +++ b/libs/Zend/Db/Statement/Sqlsrv/Exception.php @@ -12,10 +12,12 @@ * 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_Db * @subpackage Statement - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 $ */ /** @@ -26,7 +28,7 @@ require_once 'Zend/Db/Statement/Exception.php'; /** * @package Zend_Db * @subpackage Statement - * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Db_Statement_Sqlsrv_Exception extends Zend_Db_Statement_Exception diff --git a/libs/Zend/Db/Table.php b/libs/Zend/Db/Table.php index 999657ce90..1ff00e91e7 100644 --- a/libs/Zend/Db/Table.php +++ b/libs/Zend/Db/Table.php @@ -15,13 +15,13 @@ * @category Zend * @package Zend_Db * @subpackage Table - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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: Table.php 18951 2009-11-12 16:26:19Z alexander $ + * @version $Id: Table.php 20096 2010-01-06 02:05:09Z bkarwin $ */ /** - * Zend_Db_Table_Abstract + * @see Zend_Db_Table_Abstract */ require_once 'Zend/Db/Table/Abstract.php'; @@ -36,7 +36,7 @@ require_once 'Zend/Db/Table/Definition.php'; * @category Zend * @package Zend_Db * @subpackage Table - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Db_Table extends Zend_Db_Table_Abstract @@ -46,8 +46,8 @@ class Zend_Db_Table extends Zend_Db_Table_Abstract * __construct() - For concrete implementation of Zend_Db_Table * * @param string|array $config string can reference a Zend_Registry key for a db adapter - * OR it can refernece the name of a table - * @param unknown_type $definition + * OR it can reference the name of a table + * @param array|Zend_Db_Table_Definition $definition */ public function __construct($config = array(), $definition = null) { @@ -76,9 +76,4 @@ class Zend_Db_Table extends Zend_Db_Table_Abstract parent::__construct($config); } - - - - - } diff --git a/libs/Zend/Db/Table/Abstract.php b/libs/Zend/Db/Table/Abstract.php index 2432d98b5f..6b4531b5cf 100644 --- a/libs/Zend/Db/Table/Abstract.php +++ b/libs/Zend/Db/Table/Abstract.php @@ -15,9 +15,9 @@ * @category Zend * @package Zend_Db * @subpackage Table - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 18951 2009-11-12 16:26:19Z alexander $ + * @version $Id: Abstract.php 20096 2010-01-06 02:05:09Z bkarwin $ */ /** @@ -41,7 +41,7 @@ require_once 'Zend/Db.php'; * @category Zend * @package Zend_Db * @subpackage Table - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Db_Table_Abstract diff --git a/libs/Zend/Db/Table/Definition.php b/libs/Zend/Db/Table/Definition.php index 14d1c3e7c9..30e601a5b1 100644 --- a/libs/Zend/Db/Table/Definition.php +++ b/libs/Zend/Db/Table/Definition.php @@ -15,9 +15,9 @@ * @category Zend * @package Zend_Db * @subpackage Table - * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com) + * @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: Definition.php 18951 2009-11-12 16:26:19Z alexander $ + * @version $Id: Definition.php 20096 2010-01-06 02:05:09Z bkarwin $ */ /** @@ -26,7 +26,7 @@ * @category Zend * @package Zend_Db * @subpackage Table - * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Db_Table_Definition diff --git a/libs/Zend/Db/Table/Exception.php b/libs/Zend/Db/Table/Exception.php index 2d85136109..7916b84991 100644 --- a/libs/Zend/Db/Table/Exception.php +++ b/libs/Zend/Db/Table/Exception.php @@ -15,9 +15,9 @@ * @category Zend * @package Zend_Db * @subpackage Table - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 16541 2009-07-07 06:59:03Z bkarwin $ + * @version $Id: Exception.php 20096 2010-01-06 02:05:09Z bkarwin $ */ /** @@ -29,7 +29,7 @@ require_once 'Zend/Db/Exception.php'; * @category Zend * @package Zend_Db * @subpackage Table - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Db_Table_Exception extends Zend_Db_Exception diff --git a/libs/Zend/Db/Table/Row.php b/libs/Zend/Db/Table/Row.php index 970c493419..435776a512 100644 --- a/libs/Zend/Db/Table/Row.php +++ b/libs/Zend/Db/Table/Row.php @@ -15,9 +15,9 @@ * @category Zend * @package Zend_Db * @subpackage Table - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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: Row.php 16203 2009-06-21 18:56:17Z thomas $ + * @version $Id: Row.php 20096 2010-01-06 02:05:09Z bkarwin $ */ @@ -34,7 +34,7 @@ require_once 'Zend/Db/Table/Row/Abstract.php'; * @category Zend * @package Zend_Db * @subpackage Table - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Db_Table_Row extends Zend_Db_Table_Row_Abstract diff --git a/libs/Zend/Db/Table/Row/Abstract.php b/libs/Zend/Db/Table/Row/Abstract.php index 9e9c6131cb..646674e91d 100644 --- a/libs/Zend/Db/Table/Row/Abstract.php +++ b/libs/Zend/Db/Table/Row/Abstract.php @@ -15,9 +15,9 @@ * @category Zend * @package Zend_Db * @subpackage Table - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 18951 2009-11-12 16:26:19Z alexander $ + * @version $Id: Abstract.php 20571 2010-01-24 15:40:22Z mikaelkael $ */ /** @@ -29,7 +29,7 @@ require_once 'Zend/Db.php'; * @category Zend * @package Zend_Db * @subpackage Table - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Db_Table_Row_Abstract implements ArrayAccess @@ -293,13 +293,14 @@ abstract class Zend_Db_Table_Row_Abstract implements ArrayAccess } /** - * Does nothing + * Proxy to __unset * Required by the ArrayAccess implementation * * @param string $offset */ public function offsetUnset($offset) { + return $this->__unset($offset); } /** @@ -1083,7 +1084,7 @@ abstract class Zend_Db_Table_Row_Abstract implements ArrayAccess Zend_Loader::loadClass($rowsetClass); } catch (Zend_Exception $e) { require_once 'Zend/Db/Table/Row/Exception.php'; - throw new Zend_Db_Table_Row_Exception($e->getMessage()); + throw new Zend_Db_Table_Row_Exception($e->getMessage(), $e->getCode(), $e); } } $rowset = new $rowsetClass($config); @@ -1177,7 +1178,7 @@ abstract class Zend_Db_Table_Row_Abstract implements ArrayAccess Zend_Loader::loadClass($tableName); } catch (Zend_Exception $e) { require_once 'Zend/Db/Table/Row/Exception.php'; - throw new Zend_Db_Table_Row_Exception($e->getMessage()); + throw new Zend_Db_Table_Row_Exception($e->getMessage(), $e->getCode(), $e); } } diff --git a/libs/Zend/Db/Table/Row/Exception.php b/libs/Zend/Db/Table/Row/Exception.php index 12d17febcd..c3c717c174 100644 --- a/libs/Zend/Db/Table/Row/Exception.php +++ b/libs/Zend/Db/Table/Row/Exception.php @@ -15,9 +15,9 @@ * @category Zend * @package Zend_Db * @subpackage Table - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 16541 2009-07-07 06:59:03Z bkarwin $ + * @version $Id: Exception.php 20096 2010-01-06 02:05:09Z bkarwin $ */ /** @@ -29,7 +29,7 @@ require_once 'Zend/Db/Table/Exception.php'; * @category Zend * @package Zend_Db * @subpackage Table - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Db_Table_Row_Exception extends Zend_Db_Table_Exception diff --git a/libs/Zend/Db/Table/Rowset.php b/libs/Zend/Db/Table/Rowset.php index b7e495d6d0..b04c5142c8 100644 --- a/libs/Zend/Db/Table/Rowset.php +++ b/libs/Zend/Db/Table/Rowset.php @@ -16,9 +16,9 @@ * @category Zend * @package Zend_Db * @subpackage Table - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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: Rowset.php 16203 2009-06-21 18:56:17Z thomas $ + * @version $Id: Rowset.php 20096 2010-01-06 02:05:09Z bkarwin $ */ @@ -35,7 +35,7 @@ require_once 'Zend/Db/Table/Rowset/Abstract.php'; * @category Zend * @package Zend_Db * @subpackage Table - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Db_Table_Rowset extends Zend_Db_Table_Rowset_Abstract diff --git a/libs/Zend/Db/Table/Rowset/Abstract.php b/libs/Zend/Db/Table/Rowset/Abstract.php index d9e324baf1..c258656a76 100644 --- a/libs/Zend/Db/Table/Rowset/Abstract.php +++ b/libs/Zend/Db/Table/Rowset/Abstract.php @@ -15,16 +15,16 @@ * @category Zend * @package Zend_Db * @subpackage Table - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 16971 2009-07-22 18:05:45Z mikaelkael $ + * @version $Id: Abstract.php 20096 2010-01-06 02:05:09Z bkarwin $ */ /** * @category Zend * @package Zend_Db * @subpackage Table - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Db_Table_Rowset_Abstract implements SeekableIterator, Countable, ArrayAccess @@ -391,7 +391,7 @@ abstract class Zend_Db_Table_Rowset_Abstract implements SeekableIterator, Counta $row = $this->current(); } 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); + throw new Zend_Db_Table_Rowset_Exception('No row could be found at position ' . (int) $position, 0, $e); } if ($seek == false) { $this->seek($key); diff --git a/libs/Zend/Db/Table/Rowset/Exception.php b/libs/Zend/Db/Table/Rowset/Exception.php index 99b4dc54a4..8bdaedd17e 100644 --- a/libs/Zend/Db/Table/Rowset/Exception.php +++ b/libs/Zend/Db/Table/Rowset/Exception.php @@ -15,9 +15,9 @@ * @category Zend * @package Zend_Db * @subpackage Table - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 16971 2009-07-22 18:05:45Z mikaelkael $ + * @version $Id: Exception.php 20096 2010-01-06 02:05:09Z bkarwin $ */ /** @@ -29,7 +29,7 @@ require_once 'Zend/Db/Table/Exception.php'; * @category Zend * @package Zend_Db * @subpackage Table - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Db_Table_Rowset_Exception extends Zend_Db_Table_Exception diff --git a/libs/Zend/Db/Table/Select.php b/libs/Zend/Db/Table/Select.php index 629ac47b95..2f23f88f47 100644 --- a/libs/Zend/Db/Table/Select.php +++ b/libs/Zend/Db/Table/Select.php @@ -16,9 +16,9 @@ * @category Zend * @package Zend_Db * @subpackage Select - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 18951 2009-11-12 16:26:19Z alexander $ + * @version $Id: Select.php 20096 2010-01-06 02:05:09Z bkarwin $ */ @@ -40,7 +40,7 @@ require_once 'Zend/Db/Table/Abstract.php'; * @category Zend * @package Zend_Db * @subpackage Table - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Db_Table_Select extends Zend_Db_Select diff --git a/libs/Zend/Db/Table/Select/Exception.php b/libs/Zend/Db/Table/Select/Exception.php index 886f11876e..c93c861310 100644 --- a/libs/Zend/Db/Table/Select/Exception.php +++ b/libs/Zend/Db/Table/Select/Exception.php @@ -15,9 +15,9 @@ * @category Zend * @package Zend_Db * @subpackage Select - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 16971 2009-07-22 18:05:45Z mikaelkael $ + * @version $Id: Exception.php 20096 2010-01-06 02:05:09Z bkarwin $ */ /** @@ -29,7 +29,7 @@ require_once 'Zend/Db/Select/Exception.php'; * @category Zend * @package Zend_Db * @subpackage Table - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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/Exception.php b/libs/Zend/Exception.php index 3cb5704b3f..653b97d88e 100644 --- a/libs/Zend/Exception.php +++ b/libs/Zend/Exception.php @@ -14,18 +14,78 @@ * * @category Zend * @package Zend - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 16541 2009-07-07 06:59:03Z bkarwin $ */ +if (version_compare(PHP_VERSION, '5.3.0', '<')) { + /** + * @category Zend + * @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 + */ + class Zend_Exception extends Exception + { + /** + * @var null|Exception + */ + private $_previous = null; -/** - * @category Zend - * @package Zend - * @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_Exception extends Exception -{} + /** + * Construct the exception + * + * @param string $msg + * @param int $code + * @param Exception $previous + * @return void + */ + public function __construct($msg = '', $code = 0, Exception $previous = null) + { + parent::__construct($msg, (int) $code); + $this->_previous = $previous; + } + + /** + * Returns previous Exception + * + * @return Exception|null + */ + final public function getPrevious() + { + return $this->_previous; + } + /** + * String representation of the exception + * + * @return string + */ + public function __toString() + { + if (null !== ($e = $this->getPrevious())) { + return $e->__toString() + . "\n\nNext " + . parent::__toString(); + } + return parent::__toString(); + } + } +} else { + /** + * @category Zend + * @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 + */ + class Zend_Exception extends Exception + { + public function __construct($msg = '', $code = 0, Exception $previous = null) + { + if (!is_int($code)) { + $code = (int) $code; + } + parent::__construct($msg, $code, $previous); + } + } +} diff --git a/libs/Zend/Feed.php b/libs/Zend/Feed.php index b8555c7ce8..93154a91c9 100644 --- a/libs/Zend/Feed.php +++ b/libs/Zend/Feed.php @@ -15,9 +15,9 @@ * * @category Zend * @package Zend_Feed - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 18291 2009-09-18 21:00:51Z padraic $ + * @version $Id: Feed.php 20096 2010-01-06 02:05:09Z bkarwin $ */ @@ -29,7 +29,7 @@ * * @category Zend * @package Zend_Feed - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Feed diff --git a/libs/Zend/Feed/Abstract.php b/libs/Zend/Feed/Abstract.php index e5ad96a118..5cba5a2519 100644 --- a/libs/Zend/Feed/Abstract.php +++ b/libs/Zend/Feed/Abstract.php @@ -15,9 +15,9 @@ * * @category Zend * @package Zend_Feed - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 18951 2009-11-12 16:26:19Z alexander $ + * @version $Id: Abstract.php 20096 2010-01-06 02:05:09Z bkarwin $ */ @@ -37,7 +37,7 @@ require_once 'Zend/Feed/Element.php'; * * @category Zend * @package Zend_Feed - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Feed_Abstract extends Zend_Feed_Element implements Iterator, Countable diff --git a/libs/Zend/Feed/Atom.php b/libs/Zend/Feed/Atom.php index 3b0017c17f..186cde50aa 100644 --- a/libs/Zend/Feed/Atom.php +++ b/libs/Zend/Feed/Atom.php @@ -15,9 +15,9 @@ * * @category Zend * @package Zend_Feed - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 18951 2009-11-12 16:26:19Z alexander $ + * @version $Id: Atom.php 20096 2010-01-06 02:05:09Z bkarwin $ */ @@ -44,7 +44,7 @@ require_once 'Zend/Feed/Entry/Atom.php'; * * @category Zend * @package Zend_Feed - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Feed_Atom extends Zend_Feed_Abstract diff --git a/libs/Zend/Feed/Builder.php b/libs/Zend/Feed/Builder.php index 55192e661c..b44055ec26 100644 --- a/libs/Zend/Feed/Builder.php +++ b/libs/Zend/Feed/Builder.php @@ -15,9 +15,9 @@ * * @category Zend * @package Zend_Feed - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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: Builder.php 19055 2009-11-19 19:45:10Z padraic $ + * @version $Id: Builder.php 20096 2010-01-06 02:05:09Z bkarwin $ */ @@ -44,7 +44,7 @@ require_once 'Zend/Feed/Builder/Entry.php'; * * @category Zend * @package Zend_Feed - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Feed_Builder implements Zend_Feed_Builder_Interface diff --git a/libs/Zend/Feed/Builder/Entry.php b/libs/Zend/Feed/Builder/Entry.php index e428928717..d27dded6f7 100644 --- a/libs/Zend/Feed/Builder/Entry.php +++ b/libs/Zend/Feed/Builder/Entry.php @@ -15,9 +15,9 @@ * * @category Zend * @package Zend_Feed - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 16205 2009-06-21 19:08:45Z thomas $ + * @version $Id: Entry.php 20096 2010-01-06 02:05:09Z bkarwin $ */ @@ -29,7 +29,7 @@ * * @category Zend * @package Zend_Feed - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Feed_Builder_Entry extends ArrayObject diff --git a/libs/Zend/Feed/Builder/Exception.php b/libs/Zend/Feed/Builder/Exception.php index b213ceb42b..c979321cff 100644 --- a/libs/Zend/Feed/Builder/Exception.php +++ b/libs/Zend/Feed/Builder/Exception.php @@ -15,9 +15,9 @@ * * @category Zend * @package Zend_Feed - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 16205 2009-06-21 19:08:45Z thomas $ + * @version $Id: Exception.php 20096 2010-01-06 02:05:09Z bkarwin $ */ @@ -32,7 +32,7 @@ require_once 'Zend/Feed/Exception.php'; * * @category Zend * @package Zend_Feed - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Feed_Builder_Exception extends Zend_Feed_Exception diff --git a/libs/Zend/Feed/Builder/Header.php b/libs/Zend/Feed/Builder/Header.php index a234377a15..fe9ecc34f2 100644 --- a/libs/Zend/Feed/Builder/Header.php +++ b/libs/Zend/Feed/Builder/Header.php @@ -15,9 +15,9 @@ * * @category Zend * @package Zend_Feed - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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: Header.php 16205 2009-06-21 19:08:45Z thomas $ + * @version $Id: Header.php 20096 2010-01-06 02:05:09Z bkarwin $ */ /** @@ -39,7 +39,7 @@ require_once 'Zend/Uri.php'; * * @category Zend * @package Zend_Feed - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Feed_Builder_Header extends ArrayObject diff --git a/libs/Zend/Feed/Builder/Header/Itunes.php b/libs/Zend/Feed/Builder/Header/Itunes.php index 164e0a26c6..9c25653f5d 100644 --- a/libs/Zend/Feed/Builder/Header/Itunes.php +++ b/libs/Zend/Feed/Builder/Header/Itunes.php @@ -15,9 +15,9 @@ * * @category Zend * @package Zend_Feed - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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: Itunes.php 18951 2009-11-12 16:26:19Z alexander $ + * @version $Id: Itunes.php 20096 2010-01-06 02:05:09Z bkarwin $ */ @@ -28,7 +28,7 @@ * * @category Zend * @package Zend_Feed - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Feed_Builder_Header_Itunes extends ArrayObject diff --git a/libs/Zend/Feed/Builder/Interface.php b/libs/Zend/Feed/Builder/Interface.php index a3cce7e018..9dce55f815 100644 --- a/libs/Zend/Feed/Builder/Interface.php +++ b/libs/Zend/Feed/Builder/Interface.php @@ -15,9 +15,9 @@ * * @category Zend * @package Zend_Feed - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 16205 2009-06-21 19:08:45Z thomas $ + * @version $Id: Interface.php 20096 2010-01-06 02:05:09Z bkarwin $ */ @@ -29,7 +29,7 @@ * * @category Zend * @package Zend_Feed - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Feed_Builder_Interface diff --git a/libs/Zend/Feed/Element.php b/libs/Zend/Feed/Element.php index 9f0713df7e..9d452f1996 100644 --- a/libs/Zend/Feed/Element.php +++ b/libs/Zend/Feed/Element.php @@ -15,9 +15,9 @@ * * @category Zend * @package Zend_Feed - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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: Element.php 20105 2010-01-06 21:28:26Z matthew $ + * @version $Id: Element.php 20104 2010-01-06 21:26:01Z matthew $ */ @@ -26,7 +26,7 @@ * * @category Zend * @package Zend_Feed - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Feed_Element implements ArrayAccess diff --git a/libs/Zend/Feed/Entry/Abstract.php b/libs/Zend/Feed/Entry/Abstract.php index a3a53f1f78..b9a46823c4 100644 --- a/libs/Zend/Feed/Entry/Abstract.php +++ b/libs/Zend/Feed/Entry/Abstract.php @@ -15,9 +15,9 @@ * * @category Zend * @package Zend_Feed - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 18951 2009-11-12 16:26:19Z alexander $ + * @version $Id: Abstract.php 20096 2010-01-06 02:05:09Z bkarwin $ */ @@ -38,7 +38,7 @@ require_once 'Zend/Feed/Element.php'; * * @category Zend * @package Zend_Feed - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Feed_Entry_Abstract extends Zend_Feed_Element diff --git a/libs/Zend/Feed/Entry/Atom.php b/libs/Zend/Feed/Entry/Atom.php index 34de3ff7a0..01a096d67c 100644 --- a/libs/Zend/Feed/Entry/Atom.php +++ b/libs/Zend/Feed/Entry/Atom.php @@ -15,9 +15,9 @@ * * @category Zend * @package Zend_Feed - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 18951 2009-11-12 16:26:19Z alexander $ + * @version $Id: Atom.php 20096 2010-01-06 02:05:09Z bkarwin $ */ @@ -32,7 +32,7 @@ require_once 'Zend/Feed/Entry/Abstract.php'; * * @category Zend * @package Zend_Feed - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Feed_Entry_Atom extends Zend_Feed_Entry_Abstract diff --git a/libs/Zend/Feed/Entry/Rss.php b/libs/Zend/Feed/Entry/Rss.php index 73a9488566..0d638c7244 100644 --- a/libs/Zend/Feed/Entry/Rss.php +++ b/libs/Zend/Feed/Entry/Rss.php @@ -15,9 +15,9 @@ * * @category Zend * @package Zend_Feed - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 18951 2009-11-12 16:26:19Z alexander $ + * @version $Id: Rss.php 20096 2010-01-06 02:05:09Z bkarwin $ */ @@ -32,7 +32,7 @@ require_once 'Zend/Feed/Entry/Abstract.php'; * * @category Zend * @package Zend_Feed - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Feed_Entry_Rss extends Zend_Feed_Entry_Abstract diff --git a/libs/Zend/Feed/Exception.php b/libs/Zend/Feed/Exception.php index c77bb35495..733c626693 100644 --- a/libs/Zend/Feed/Exception.php +++ b/libs/Zend/Feed/Exception.php @@ -15,9 +15,9 @@ * * @category Zend * @package Zend_Feed - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 16205 2009-06-21 19:08:45Z thomas $ + * @version $Id: Exception.php 20096 2010-01-06 02:05:09Z bkarwin $ */ @@ -34,7 +34,7 @@ require_once 'Zend/Exception.php'; * * @category Zend * @package Zend_Feed - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Feed_Exception extends Zend_Exception diff --git a/libs/Zend/Feed/Pubsubhubbub.php b/libs/Zend/Feed/Pubsubhubbub.php new file mode 100644 index 0000000000..05f60b9130 --- /dev/null +++ b/libs/Zend/Feed/Pubsubhubbub.php @@ -0,0 +1,152 @@ +<?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_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 + */ + +/** + * @see Zend_Http_Client + */ +require_once 'Zend/Http/Client.php'; + +/** + * @see Zend_Uri + */ +require_once 'Zend/Uri.php'; + +/** + * @see Zend_Version + */ +require_once 'Zend/Version.php'; + +/** + * @see Zend_Feed_Reader + */ +require_once 'Zend/Feed/Reader.php'; + +/** + * @see Zend_Feed_Abstract + */ +require_once 'Zend/Feed/Abstract.php'; + +/** + * @category Zend + * @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 + */ +class Zend_Feed_Pubsubhubbub +{ + /** + * Verification Modes + */ + const VERIFICATION_MODE_SYNC = 'sync'; + const VERIFICATION_MODE_ASYNC = 'async'; + + /** + * Subscription States + */ + const SUBSCRIPTION_VERIFIED = 'verified'; + const SUBSCRIPTION_NOTVERIFIED = 'not_verified'; + const SUBSCRIPTION_TODELETE = 'to_delete'; + + /** + * Singleton instance if required of the HTTP client + * + * @var Zend_Http_Client + */ + protected static $httpClient = null; + + /** + * Simple utility function which imports any feed URL and + * determines the existence of Hub Server endpoints. This works + * best if directly given an instance of Zend_Feed_Reader_Atom|Rss + * to leverage off. + * + * @param Zend_Feed_Reader_FeedAbstract|Zend_Feed_Abstract|string $source + * @return array + */ + public static function detectHubs($source) + { + if (is_string($source)) { + $feed = Zend_Feed_Reader::import($source); + } elseif (is_object($source) && $source instanceof Zend_Feed_Reader_FeedAbstract) { + $feed = $source; + } elseif (is_object($source) && $source instanceof Zend_Feed_Abstract) { + $feed = Zend_Feed_Reader::importFeed($source); + } else { + require_once 'Zend/Feed/Pubsubhubbub/Exception.php'; + throw new Zend_Feed_Pubsubhubbub_Exception('The source parameter was' + . ' invalid, i.e. not a URL string or an instance of type' + . ' Zend_Feed_Reader_FeedAbstract or Zend_Feed_Abstract'); + } + return $feed->getHubs(); + } + + /** + * Allows the external environment to make Zend_Oauth use a specific + * Client instance. + * + * @param Zend_Http_Client $httpClient + * @return void + */ + public static function setHttpClient(Zend_Http_Client $httpClient) + { + self::$httpClient = $httpClient; + } + + /** + * Return the singleton instance of the HTTP Client. Note that + * the instance is reset and cleared of previous parameters GET/POST. + * Headers are NOT reset but handled by this component if applicable. + * + * @return Zend_Http_Client + */ + public static function getHttpClient() + { + if (!isset(self::$httpClient)): + self::$httpClient = new Zend_Http_Client; + else: + self::$httpClient->resetParameters(); + endif; + return self::$httpClient; + } + + /** + * Simple mechanism to delete the entire singleton HTTP Client instance + * which forces an new instantiation for subsequent requests. + * + * @return void + */ + public static function clearHttpClient() + { + self::$httpClient = null; + } + + /** + * RFC 3986 safe url encoding method + * + * @param string $string + * @return string + */ + public static function urlencode($string) + { + $rawencoded = rawurlencode($string); + $rfcencoded = str_replace('%7E', '~', $rawencoded); + return $rfcencoded; + } +} diff --git a/libs/Zend/Feed/Pubsubhubbub/CallbackAbstract.php b/libs/Zend/Feed/Pubsubhubbub/CallbackAbstract.php new file mode 100644 index 0000000000..48fc56d438 --- /dev/null +++ b/libs/Zend/Feed/Pubsubhubbub/CallbackAbstract.php @@ -0,0 +1,307 @@ +<?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_Feed_Pubsubhubbub + * @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 + */ + +/** + * @see Zend_Feed_Pubsubhubbub_CallbackInterface + */ +require_once 'Zend/Feed/Pubsubhubbub/CallbackInterface.php'; + +/** + * @see Zend_Feed_Pubsubhubbub_HttpResponse + */ +require_once 'Zend/Feed/Pubsubhubbub/HttpResponse.php'; + +/** + * @category Zend + * @package Zend_Feed_Pubsubhubbub + * @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 + */ +abstract class Zend_Feed_Pubsubhubbub_CallbackAbstract + implements Zend_Feed_Pubsubhubbub_CallbackInterface +{ + /** + * An instance of Zend_Feed_Pubsubhubbub_Model_SubscriptionInterface used + * to background save any verification tokens associated with a subscription + * or other. + * + * @var Zend_Feed_Pubsubhubbub_Model_SubscriptionInterface + */ + protected $_storage = null; + + /** + * An instance of a class handling Http Responses. This is implemented in + * Zend_Feed_Pubsubhubbub_HttpResponse which shares an unenforced interface with + * (i.e. not inherited from) Zend_Controller_Response_Http. + * + * @var Zend_Feed_Pubsubhubbub_HttpResponse|Zend_Controller_Response_Http + */ + protected $_httpResponse = null; + + /** + * The number of Subscribers for which any updates are on behalf of. + * + * @var int + */ + protected $_subscriberCount = 1; + + /** + * Constructor; accepts an array or Zend_Config instance to preset + * options for the Subscriber without calling all supported setter + * methods in turn. + * + * @param array|Zend_Config $options Options array or Zend_Config instance + */ + public function __construct($config = null) + { + if (!is_null($config)) { + $this->setConfig($config); + } + } + + /** + * Process any injected configuration options + * + * @param array|Zend_Config $options Options array or Zend_Config instance + * @return Zend_Feed_Pubsubhubbub_CallbackAbstract + */ + public function setConfig($config) + { + if ($config instanceof Zend_Config) { + $config = $config->toArray(); + } elseif (!is_array($config)) { + require_once 'Zend/Feed/Pubsubhubbub/Exception.php'; + throw new Zend_Feed_Pubsubhubbub_Exception('Array or Zend_Config object' + . 'expected, got ' . gettype($config)); + } + if (array_key_exists('storage', $config)) { + $this->setStorage($config['storage']); + } + return $this; + } + + /** + * Send the response, including all headers. + * If you wish to handle this via Zend_Controller, use the getter methods + * to retrieve any data needed to be set on your HTTP Response object, or + * simply give this object the HTTP Response instance to work with for you! + * + * @return void + */ + public function sendResponse() + { + $this->getHttpResponse()->sendResponse(); + } + + /** + * Sets an instance of Zend_Feed_Pubsubhubbub_Model_SubscriptionInterface used + * to background save any verification tokens associated with a subscription + * or other. + * + * @param Zend_Feed_Pubsubhubbub_Model_SubscriptionInterface $storage + * @return Zend_Feed_Pubsubhubbub_CallbackAbstract + */ + public function setStorage(Zend_Feed_Pubsubhubbub_Model_SubscriptionInterface $storage) + { + $this->_storage = $storage; + return $this; + } + + /** + * Gets an instance of Zend_Feed_Pubsubhubbub_Model_SubscriptionInterface used + * to background save any verification tokens associated with a subscription + * or other. + * + * @return Zend_Feed_Pubsubhubbub_Model_SubscriptionInterface + */ + public function getStorage() + { + if ($this->_storage === null) { + require_once 'Zend/Feed/Pubsubhubbub/Exception.php'; + throw new Zend_Feed_Pubsubhubbub_Exception('No storage object has been' + . ' set that subclasses Zend_Feed_Pubsubhubbub_Model_SubscriptionInterface'); + } + return $this->_storage; + } + + /** + * An instance of a class handling Http Responses. This is implemented in + * Zend_Feed_Pubsubhubbub_HttpResponse which shares an unenforced interface with + * (i.e. not inherited from) Zend_Controller_Response_Http. + * + * @param Zend_Feed_Pubsubhubbub_HttpResponse|Zend_Controller_Response_Http $httpResponse + * @return Zend_Feed_Pubsubhubbub_CallbackAbstract + */ + public function setHttpResponse($httpResponse) + { + if (!is_object($httpResponse) + || (!$httpResponse instanceof Zend_Feed_Pubsubhubbub_HttpResponse + && !$httpResponse instanceof Zend_Controller_Response_Http) + ) { + require_once 'Zend/Feed/Pubsubhubbub/Exception.php'; + throw new Zend_Feed_Pubsubhubbub_Exception('HTTP Response object must' + . ' implement one of Zend_Feed_Pubsubhubbub_HttpResponse or' + . ' Zend_Controller_Response_Http'); + } + $this->_httpResponse = $httpResponse; + return $this; + } + + /** + * An instance of a class handling Http Responses. This is implemented in + * Zend_Feed_Pubsubhubbub_HttpResponse which shares an unenforced interface with + * (i.e. not inherited from) Zend_Controller_Response_Http. + * + * @return Zend_Feed_Pubsubhubbub_HttpResponse|Zend_Controller_Response_Http + */ + public function getHttpResponse() + { + if ($this->_httpResponse === null) { + $this->_httpResponse = new Zend_Feed_Pubsubhubbub_HttpResponse; + } + return $this->_httpResponse; + } + + /** + * Sets the number of Subscribers for which any updates are on behalf of. + * In other words, is this class serving one or more subscribers? How many? + * Defaults to 1 if left unchanged. + * + * @param string|int $count + * @return Zend_Feed_Pubsubhubbub_CallbackAbstract + */ + public function setSubscriberCount($count) + { + $count = intval($count); + if ($count <= 0) { + require_once 'Zend/Feed/Pubsubhubbub/Exception.php'; + throw new Zend_Feed_Pubsubhubbub_Exception('Subscriber count must be' + . ' greater than zero'); + } + $this->_subscriberCount = $count; + return $this; + } + + /** + * Gets the number of Subscribers for which any updates are on behalf of. + * In other words, is this class serving one or more subscribers? How many? + * + * @return int + */ + public function getSubscriberCount() + { + return $this->_subscriberCount; + } + + /** + * Attempt to detect the callback URL (specifically the path forward) + */ + protected function _detectCallbackUrl() + { + $callbackUrl = ''; + if (isset($_SERVER['HTTP_X_REWRITE_URL'])) { + $callbackUrl = $_SERVER['HTTP_X_REWRITE_URL']; + } elseif (isset($_SERVER['REQUEST_URI'])) { + $callbackUrl = $_SERVER['REQUEST_URI']; + $scheme = 'http'; + if ($_SERVER['HTTPS'] == 'on') { + $scheme = 'https'; + } + $schemeAndHttpHost = $scheme . '://' . $this->_getHttpHost(); + if (strpos($callbackUrl, $schemeAndHttpHost) === 0) { + $callbackUrl = substr($callbackUrl, strlen($schemeAndHttpHost)); + } + } elseif (isset($_SERVER['ORIG_PATH_INFO'])) { + $callbackUrl= $_SERVER['ORIG_PATH_INFO']; + if (!empty($_SERVER['QUERY_STRING'])) { + $callbackUrl .= '?' . $_SERVER['QUERY_STRING']; + } + } + return $callbackUrl; + } + + /** + * Get the HTTP host + * + * @return string + */ + protected function _getHttpHost() + { + if (!empty($_SERVER['HTTP_HOST'])) { + return $_SERVER['HTTP_HOST']; + } + $scheme = 'http'; + if ($_SERVER['HTTPS'] == 'on') { + $scheme = 'https'; + } + $name = $_SERVER['SERVER_NAME']; + $port = $_SERVER['SERVER_PORT']; + if (($scheme == 'http' && $port == 80) + || ($scheme == 'https' && $port == 443) + ) { + return $name; + } else { + return $name . ':' . $port; + } + } + + /** + * Retrieve a Header value from either $_SERVER or Apache + * + * @param string $header + */ + protected function _getHeader($header) + { + $temp = strtoupper(str_replace('-', '_', $header)); + if (!empty($_SERVER[$temp])) { + return $_SERVER[$temp]; + } + $temp = 'HTTP_' . strtoupper(str_replace('-', '_', $header)); + if (!empty($_SERVER[$temp])) { + return $_SERVER[$temp]; + } + if (function_exists('apache_request_headers')) { + $headers = apache_request_headers(); + if (!empty($headers[$header])) { + return $headers[$header]; + } + } + return false; + } + + /** + * Return the raw body of the request + * + * @return string|false Raw body, or false if not present + */ + protected function _getRawBody() + { + $body = file_get_contents('php://input'); + if (strlen(trim($body)) == 0 && isset($GLOBALS['HTTP_RAW_POST_DATA'])) { + $body = $GLOBALS['HTTP_RAW_POST_DATA']; + } + if (strlen(trim($body)) > 0) { + return $body; + } + return false; + } +} diff --git a/libs/Zend/Feed/Pubsubhubbub/CallbackInterface.php b/libs/Zend/Feed/Pubsubhubbub/CallbackInterface.php new file mode 100644 index 0000000000..ce30a6bb23 --- /dev/null +++ b/libs/Zend/Feed/Pubsubhubbub/CallbackInterface.php @@ -0,0 +1,68 @@ +<?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_Feed_Pubsubhubbub + * @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 + */ + +/** + * @category Zend + * @package Zend_Feed_Pubsubhubbub + * @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 + */ +interface Zend_Feed_Pubsubhubbub_CallbackInterface +{ + /** + * Handle any callback from a Hub Server responding to a subscription or + * unsubscription request. This should be the Hub Server confirming the + * the request prior to taking action on it. + * + * @param array $httpData GET/POST data if available and not in $_GET/POST + * @param bool $sendResponseNow Whether to send response now or when asked + */ + public function handle(array $httpData = null, $sendResponseNow = false); + + /** + * Send the response, including all headers. + * If you wish to handle this via Zend_Controller, use the getter methods + * to retrieve any data needed to be set on your HTTP Response object, or + * simply give this object the HTTP Response instance to work with for you! + * + * @return void + */ + public function sendResponse(); + + /** + * An instance of a class handling Http Responses. This is implemented in + * Zend_Feed_Pubsubhubbub_HttpResponse which shares an unenforced interface with + * (i.e. not inherited from) Zend_Controller_Response_Http. + * + * @param Zend_Feed_Pubsubhubbub_HttpResponse|Zend_Controller_Response_Http $httpResponse + */ + public function setHttpResponse($httpResponse); + + /** + * An instance of a class handling Http Responses. This is implemented in + * Zend_Feed_Pubsubhubbub_HttpResponse which shares an unenforced interface with + * (i.e. not inherited from) Zend_Controller_Response_Http. + * + * @return Zend_Feed_Pubsubhubbub_HttpResponse|Zend_Controller_Response_Http + */ + public function getHttpResponse(); +} diff --git a/libs/Zend/Feed/Pubsubhubbub/Exception.php b/libs/Zend/Feed/Pubsubhubbub/Exception.php new file mode 100644 index 0000000000..cac6d2386e --- /dev/null +++ b/libs/Zend/Feed/Pubsubhubbub/Exception.php @@ -0,0 +1,33 @@ +<?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_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 + */ + +/** + * @see Zend_Exception + */ +require_once 'Zend/Exception.php'; + +/** + * @category Zend + * @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 + */ +class Zend_Feed_Pubsubhubbub_Exception extends Zend_Exception +{} diff --git a/libs/Zend/Feed/Pubsubhubbub/HttpResponse.php b/libs/Zend/Feed/Pubsubhubbub/HttpResponse.php new file mode 100644 index 0000000000..5a14eb60f4 --- /dev/null +++ b/libs/Zend/Feed/Pubsubhubbub/HttpResponse.php @@ -0,0 +1,233 @@ +<?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_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 + */ + +/** + * @see Zend_Feed_Pubsubhubbub + */ +require_once 'Zend/Feed/Pubsubhubbub.php'; + +/** + * @category Zend + * @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 + */ +class Zend_Feed_Pubsubhubbub_HttpResponse +{ + /** + * The body of any response to the current callback request + * + * @var string + */ + protected $_body = ''; + + /** + * Array of headers. Each header is an array with keys 'name' and 'value' + * + * @var array + */ + protected $_headers = array(); + + /** + * HTTP response code to use in headers + * + * @var int + */ + protected $_httpResponseCode = 200; + + /** + * Send the response, including all headers + * + * @return void + */ + public function sendResponse() + { + $this->sendHeaders(); + echo $this->getBody(); + } + + /** + * Send all headers + * + * Sends any headers specified. If an {@link setHttpResponseCode() HTTP response code} + * has been specified, it is sent with the first header. + * + * @return void + */ + public function sendHeaders() + { + if (count($this->_headers) || (200 != $this->_httpResponseCode)) { + $this->canSendHeaders(true); + } elseif (200 == $this->_httpResponseCode) { + return; + } + $httpCodeSent = false; + foreach ($this->_headers as $header) { + if (!$httpCodeSent && $this->_httpResponseCode) { + header($header['name'] . ': ' . $header['value'], $header['replace'], $this->_httpResponseCode); + $httpCodeSent = true; + } else { + header($header['name'] . ': ' . $header['value'], $header['replace']); + } + } + if (!$httpCodeSent) { + header('HTTP/1.1 ' . $this->_httpResponseCode); + $httpCodeSent = true; + } + } + + /** + * Set a header + * + * If $replace is true, replaces any headers already defined with that + * $name. + * + * @param string $name + * @param string $value + * @param boolean $replace + * @return Zend_Feed_Pubsubhubbub_HttpResponse + */ + public function setHeader($name, $value, $replace = false) + { + $name = $this->_normalizeHeader($name); + $value = (string) $value; + if ($replace) { + foreach ($this->_headers as $key => $header) { + if ($name == $header['name']) { + unset($this->_headers[$key]); + } + } + } + $this->_headers[] = array( + 'name' => $name, + 'value' => $value, + 'replace' => $replace, + ); + + return $this; + } + + /** + * Check if a specific Header is set and return its value + * + * @param string $name + * @return string|null + */ + public function getHeader($name) + { + $name = $this->_normalizeHeader($name); + foreach ($this->_headers as $header) { + if ($header['name'] == $name) { + return $header['value']; + } + } + } + + /** + * Return array of headers; see {@link $_headers} for format + * + * @return array + */ + public function getHeaders() + { + return $this->_headers; + } + + /** + * Can we send headers? + * + * @param boolean $throw Whether or not to throw an exception if headers have been sent; defaults to false + * @return boolean + * @throws Zend_Feed_Pubsubhubbub_Exception + */ + public function canSendHeaders($throw = false) + { + $ok = headers_sent($file, $line); + if ($ok && $throw) { + require_once 'Zend/Feed/Pubsubhubbub/Exception.php'; + throw new Zend_Feed_Pubsubhubbub_Exception('Cannot send headers; headers already sent in ' . $file . ', line ' . $line); + } + return !$ok; + } + + /** + * Set HTTP response code to use with headers + * + * @param int $code + * @return Zend_Feed_Pubsubhubbub_HttpResponse + */ + public function setHttpResponseCode($code) + { + if (!is_int($code) || (100 > $code) || (599 < $code)) { + require_once 'Zend/Feed/Pubsubhubbub/Exception.php'; + throw new Zend_Feed_Pubsubhubbub_Exception('Invalid HTTP response' + . ' code:' . $code); + } + $this->_httpResponseCode = $code; + return $this; + } + + /** + * Retrieve HTTP response code + * + * @return int + */ + public function getHttpResponseCode() + { + return $this->_httpResponseCode; + } + + /** + * Set body content + * + * @param string $content + * @return Zend_Feed_Pubsubhubbub_HttpResponse + */ + public function setBody($content) + { + $this->_body = (string) $content; + $this->setHeader('content-length', strlen($content)); + return $this; + } + + /** + * Return the body content + * + * @return string + */ + public function getBody() + { + return $this->_body; + } + + /** + * Normalizes a header name to X-Capitalized-Names + * + * @param string $name + * @return string + */ + protected function _normalizeHeader($name) + { + $filtered = str_replace(array('-', '_'), ' ', (string) $name); + $filtered = ucwords(strtolower($filtered)); + $filtered = str_replace(' ', '-', $filtered); + return $filtered; + } +} diff --git a/libs/Zend/Feed/Pubsubhubbub/Model/ModelAbstract.php b/libs/Zend/Feed/Pubsubhubbub/Model/ModelAbstract.php new file mode 100644 index 0000000000..839644648e --- /dev/null +++ b/libs/Zend/Feed/Pubsubhubbub/Model/ModelAbstract.php @@ -0,0 +1,64 @@ +<?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_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 + */ + + +/** @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... + */ +require_once 'Zend/Registry.php'; + +/** + * @category Zend + * @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 + */ +class Zend_Feed_Pubsubhubbub_Model_ModelAbstract +{ + /** + * Zend_Db_Table instance to host database methods + * + * @var Zend_Db_Table + */ + protected $_db = null; + + /** + * Constructor + * + * @param array $data + * @param Zend_Db_Table_Abstract $tableGateway + * @return void + */ + public function __construct(Zend_Db_Table_Abstract $tableGateway = null) + { + if (is_null($tableGateway)) { + $parts = explode('_', get_class($this)); + $table = strtolower(array_pop($parts)); + $this->_db = new Zend_Db_Table($table); + } else { + $this->_db = $tableGateway; + } + } + +} diff --git a/libs/Zend/Feed/Pubsubhubbub/Model/Subscription.php b/libs/Zend/Feed/Pubsubhubbub/Model/Subscription.php new file mode 100644 index 0000000000..0b3ab2abee --- /dev/null +++ b/libs/Zend/Feed/Pubsubhubbub/Model/Subscription.php @@ -0,0 +1,131 @@ +<?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_Feed_Pubsubhubbub + * @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 + */ + +/** @see Zend_Feed_Pubsubhubbub_Model_ModelAbstract */ +require_once 'Zend/Feed/Pubsubhubbub/Model/ModelAbstract.php'; + +/** @see Zend_Feed_Pubsubhubbub_Model_SubscriptionInterface */ +require_once 'Zend/Feed/Pubsubhubbub/Model/SubscriptionInterface.php'; + +/** + * @category Zend + * @package Zend_Feed_Pubsubhubbub + * @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 + */ +class Zend_Feed_Pubsubhubbub_Model_Subscription + extends Zend_Feed_Pubsubhubbub_Model_ModelAbstract + implements Zend_Feed_Pubsubhubbub_Model_SubscriptionInterface +{ + + /** + * Save subscription to RDMBS + * + * @param array $data + * @return bool + */ + public function setSubscription(array $data) + { + if (!isset($data['id'])) { + require_once 'Zend/Feed/Pubsubhubbub/Exception.php'; + throw new Zend_Feed_Pubsubhubbub_Exception( + 'ID must be set before attempting a save' + ); + } + $result = $this->_db->find($data['id']); + if ($result) { + $data['created_time'] = $result->current()->created_time; + $now = new Zend_Date; + if ($data['lease_seconds']) { + $data['expiration_time'] = $now->add($data['lease_seconds'], Zend_Date::SECOND) + ->get('yyyy-MM-dd HH:mm:ss'); + } + $this->_db->update( + $data, + $this->_db->getAdapter()->quoteInto('id = ?', $data['id']) + ); + return false; + } + + $this->_db->insert($data); + return true; + } + + /** + * Get subscription by ID/key + * + * @param string $key + * @return array + */ + public function getSubscription($key) + { + if (empty($key) || !is_string($key)) { + require_once 'Zend/Feed/Pubsubhubbub/Exception.php'; + throw new Zend_Feed_Pubsubhubbub_Exception('Invalid parameter "key"' + .' of "' . $key . '" must be a non-empty string'); + } + $result = $this->_db->find($key); + if ($result) { + return (array) $result->current(); + } + return false; + } + + /** + * Determine if a subscription matching the key exists + * + * @param string $key + * @return bool + */ + public function hasSubscription($key) + { + if (empty($key) || !is_string($key)) { + require_once 'Zend/Feed/Pubsubhubbub/Exception.php'; + throw new Zend_Feed_Pubsubhubbub_Exception('Invalid parameter "key"' + .' of "' . $key . '" must be a non-empty string'); + } + $result = $this->_db->find($key); + if ($result) { + return true; + } + return false; + } + + /** + * Delete a subscription + * + * @param string $key + * @return bool + */ + public function deleteSubscription($key) + { + $result = $this->_db->find($key); + if ($result) { + $this->_db->delete( + $this->_db->getAdapter()->quoteInto('id = ?', $key) + ); + return true; + } + return false; + } + +} diff --git a/libs/Zend/Feed/Pubsubhubbub/Model/SubscriptionInterface.php b/libs/Zend/Feed/Pubsubhubbub/Model/SubscriptionInterface.php new file mode 100644 index 0000000000..f8a6e6a3e3 --- /dev/null +++ b/libs/Zend/Feed/Pubsubhubbub/Model/SubscriptionInterface.php @@ -0,0 +1,64 @@ +<?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_Feed_Pubsubhubbub + * @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 + */ + +/** + * @category Zend + * @package Zend_Feed_Pubsubhubbub + * @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 + */ +interface Zend_Feed_Pubsubhubbub_Model_SubscriptionInterface +{ + + /** + * Save subscription to RDMBS + * + * @param array $data The key must be stored here as a $data['id'] entry + * @return bool + */ + public function setSubscription(array $data); + + /** + * Get subscription by ID/key + * + * @param string $key + * @return array + */ + public function getSubscription($key); + + /** + * Determine if a subscription matching the key exists + * + * @param string $key + * @return bool + */ + public function hasSubscription($key); + + /** + * Delete a subscription + * + * @param string $key + * @return bool + */ + public function deleteSubscription($key); + +} diff --git a/libs/Zend/Feed/Pubsubhubbub/Publisher.php b/libs/Zend/Feed/Pubsubhubbub/Publisher.php new file mode 100644 index 0000000000..1eb594f0dd --- /dev/null +++ b/libs/Zend/Feed/Pubsubhubbub/Publisher.php @@ -0,0 +1,417 @@ +<?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_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 + */ + +/** + * @see Zend_Feed_Pubsubhubbub + */ +require_once 'Zend/Feed/Pubsubhubbub.php'; + +/** + * @category Zend + * @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 + */ +class Zend_Feed_Pubsubhubbub_Publisher +{ + /** + * An array of URLs for all Hub Servers used by the Publisher, and to + * which all topic update notifications will be sent. + * + * @var array + */ + protected $_hubUrls = array(); + + /** + * An array of topic (Atom or RSS feed) URLs which have been updated and + * whose updated status will be notified to all Hub Servers. + * + * @var array + */ + protected $_updatedTopicUrls = array(); + + /** + * An array of any errors including keys for 'response', 'hubUrl'. + * The response is the actual Zend_Http_Response object. + * + * @var array + */ + protected $_errors = array(); + + /** + * An array of topic (Atom or RSS feed) URLs which have been updated and + * whose updated status will be notified to all Hub Servers. + * + * @var array + */ + protected $_parameters = array(); + + /** + * Constructor; accepts an array or Zend_Config instance to preset + * options for the Publisher without calling all supported setter + * methods in turn. + * + * @param array|Zend_Config $options Options array or Zend_Config instance + * @return void + */ + public function __construct($config = null) + { + if (!is_null($config)) { + $this->setConfig($config); + } + } + + /** + * Process any injected configuration options + * + * @param array|Zend_Config $options Options array or Zend_Config instance + * @return Zend_Feed_Pubsubhubbub_Publisher + */ + public function setConfig($config) + { + if ($config instanceof Zend_Config) { + $config = $config->toArray(); + } elseif (!is_array($config)) { + require_once 'Zend/Feed/Pubsubhubbub/Exception.php'; + throw new Zend_Feed_Pubsubhubbub_Exception('Array or Zend_Config object' + . 'expected, got ' . gettype($config)); + } + if (array_key_exists('hubUrls', $config)) { + $this->addHubUrls($config['hubUrls']); + } + if (array_key_exists('updatedTopicUrls', $config)) { + $this->addUpdatedTopicUrls($config['updatedTopicUrls']); + } + if (array_key_exists('parameters', $config)) { + $this->setParameters($config['parameters']); + } + return $this; + } + + /** + * Add a Hub Server URL supported by Publisher + * + * @param string $url + * @return Zend_Feed_Pubsubhubbub_Publisher + */ + public function addHubUrl($url) + { + if (empty($url) || !is_string($url) || !Zend_Uri::check($url)) { + require_once 'Zend/Feed/Pubsubhubbub/Exception.php'; + throw new Zend_Feed_Pubsubhubbub_Exception('Invalid parameter "url"' + .' of "' . $url . '" must be a non-empty string and a valid' + .'URL'); + } + $this->_hubUrls[] = $url; + return $this; + } + + /** + * Add an array of Hub Server URLs supported by Publisher + * + * @param array $urls + * @return Zend_Feed_Pubsubhubbub_Publisher + */ + public function addHubUrls(array $urls) + { + foreach ($urls as $url) { + $this->addHubUrl($url); + } + return $this; + } + + /** + * Remove a Hub Server URL + * + * @param string $url + * @return Zend_Feed_Pubsubhubbub_Publisher + */ + public function removeHubUrl($url) + { + if (!in_array($url, $this->getHubUrls())) { + return $this; + } + $key = array_search($url, $this->_hubUrls); + unset($this->_hubUrls[$key]); + return $this; + } + + /** + * Return an array of unique Hub Server URLs currently available + * + * @return array + */ + public function getHubUrls() + { + $this->_hubUrls = array_unique($this->_hubUrls); + return $this->_hubUrls; + } + + /** + * Add a URL to a topic (Atom or RSS feed) which has been updated + * + * @param string $url + * @return Zend_Feed_Pubsubhubbub_Publisher + */ + public function addUpdatedTopicUrl($url) + { + if (empty($url) || !is_string($url) || !Zend_Uri::check($url)) { + require_once 'Zend/Feed/Pubsubhubbub/Exception.php'; + throw new Zend_Feed_Pubsubhubbub_Exception('Invalid parameter "url"' + .' of "' . $url . '" must be a non-empty string and a valid' + .'URL'); + } + $this->_updatedTopicUrls[] = $url; + return $this; + } + + /** + * Add an array of Topic URLs which have been updated + * + * @param array $urls + * @return Zend_Feed_Pubsubhubbub_Publisher + */ + public function addUpdatedTopicUrls(array $urls) + { + foreach ($urls as $url) { + $this->addUpdatedTopicUrl($url); + } + return $this; + } + + /** + * Remove an updated topic URL + * + * @param string $url + * @return Zend_Feed_Pubsubhubbub_Publisher + */ + public function removeUpdatedTopicUrl($url) + { + if (!in_array($url, $this->getUpdatedTopicUrls())) { + return $this; + } + $key = array_search($url, $this->_updatedTopicUrls); + unset($this->_updatedTopicUrls[$key]); + return $this; + } + + /** + * Return an array of unique updated topic URLs currently available + * + * @return array + */ + public function getUpdatedTopicUrls() + { + $this->_updatedTopicUrls = array_unique($this->_updatedTopicUrls); + return $this->_updatedTopicUrls; + } + + /** + * Notifies a single Hub Server URL of changes + * + * @param string $url The Hub Server's URL + * @return void + * @throws Zend_Feed_Pubsubhubbub_Exception Thrown on failure + */ + public function notifyHub($url) + { + if (empty($url) || !is_string($url) || !Zend_Uri::check($url)) { + require_once 'Zend/Feed/Pubsubhubbub/Exception.php'; + throw new Zend_Feed_Pubsubhubbub_Exception('Invalid parameter "url"' + .' of "' . $url . '" must be a non-empty string and a valid' + .'URL'); + } + $client = $this->_getHttpClient(); + $client->setUri($url); + $response = $client->request(); + if ($response->getStatus() !== 204) { + require_once 'Zend/Feed/Pubsubhubbub/Exception.php'; + throw new Zend_Feed_Pubsubhubbub_Exception('Notification to Hub Server ' + . 'at "' . $url . '" appears to have failed with a status code of "' + . $response->getStatus() . '" and message "' + . $response->getMessage() . '"'); + } + } + + /** + * Notifies all Hub Server URLs of changes + * + * If a Hub notification fails, certain data will be retained in an + * an array retrieved using getErrors(), if a failure occurs for any Hubs + * the isSuccess() check will return FALSE. This method is designed not + * to needlessly fail with an Exception/Error unless from Zend_Http_Client. + * + * @return void + * @throws Zend_Feed_Pubsubhubbub_Exception Thrown if no hubs attached + */ + public function notifyAll() + { + $client = $this->_getHttpClient(); + $hubs = $this->getHubUrls(); + if (empty($hubs)) { + require_once 'Zend/Feed/Pubsubhubbub/Exception.php'; + throw new Zend_Feed_Pubsubhubbub_Exception('No Hub Server URLs' + . ' have been set so no notifcations can be sent'); + } + $this->_errors = array(); + foreach ($hubs as $url) { + $client->setUri($url); + $response = $client->request(); + if ($response->getStatus() !== 204) { + $this->_errors[] = array( + 'response' => $response, + 'hubUrl' => $url + ); + } + } + } + + /** + * Add an optional parameter to the update notification requests + * + * @param string $name + * @param string|null $value + * @return Zend_Feed_Pubsubhubbub_Publisher + */ + public function setParameter($name, $value = null) + { + if (is_array($name)) { + $this->setParameters($name); + return $this; + } + if (empty($name) || !is_string($name)) { + require_once 'Zend/Feed/Pubsubhubbub/Exception.php'; + throw new Zend_Feed_Pubsubhubbub_Exception('Invalid parameter "name"' + .' of "' . $name . '" must be a non-empty string'); + } + if ($value === null) { + $this->removeParameter($name); + return $this; + } + if (empty($value) || (!is_string($value) && !is_null($value))) { + require_once 'Zend/Feed/Pubsubhubbub/Exception.php'; + throw new Zend_Feed_Pubsubhubbub_Exception('Invalid parameter "value"' + .' of "' . $value . '" must be a non-empty string'); + } + $this->_parameters[$name] = $value; + return $this; + } + + /** + * Add an optional parameter to the update notification requests + * + * @param array $parameters + * @return Zend_Feed_Pubsubhubbub_Publisher + */ + public function setParameters(array $parameters) + { + foreach ($parameters as $name => $value) { + $this->setParameter($name, $value); + } + return $this; + } + + /** + * Remove an optional parameter for the notification requests + * + * @param string $name + * @return Zend_Feed_Pubsubhubbub_Publisher + */ + public function removeParameter($name) + { + if (empty($name) || !is_string($name)) { + require_once 'Zend/Feed/Pubsubhubbub/Exception.php'; + throw new Zend_Feed_Pubsubhubbub_Exception('Invalid parameter "name"' + .' of "' . $name . '" must be a non-empty string'); + } + if (array_key_exists($name, $this->_parameters)) { + unset($this->_parameters[$name]); + } + return $this; + } + + /** + * Return an array of optional parameters for notification requests + * + * @return array + */ + public function getParameters() + { + return $this->_parameters; + } + + /** + * Returns a boolean indicator of whether the notifications to Hub + * Servers were ALL successful. If even one failed, FALSE is returned. + * + * @return bool + */ + public function isSuccess() + { + if (count($this->_errors) > 0) { + return false; + } + return true; + } + + /** + * Return an array of errors met from any failures, including keys: + * 'response' => the Zend_Http_Response object from the failure + * 'hubUrl' => the URL of the Hub Server whose notification failed + * + * @return array + */ + public function getErrors() + { + return $this->_errors; + } + + /** + * Get a basic prepared HTTP client for use + * + * @return Zend_Http_Client + */ + protected function _getHttpClient() + { + $client = Zend_Feed_Pubsubhubbub::getHttpClient(); + $client->setMethod(Zend_Http_Client::POST); + $client->setConfig(array( + 'useragent' => 'Zend_Feed_Pubsubhubbub_Publisher/' . Zend_Version::VERSION, + )); + $params = array(); + $params[] = 'hub.mode=publish'; + $topics = $this->getUpdatedTopicUrls(); + if (empty($topics)) { + require_once 'Zend/Feed/Pubsubhubbub/Exception.php'; + throw new Zend_Feed_Pubsubhubbub_Exception('No updated topic URLs' + . ' have been set'); + } + foreach ($topics as $topicUrl) { + $params[] = 'hub.url=' . urlencode($topicUrl); + } + $optParams = $this->getParameters(); + foreach ($optParams as $name => $value) { + $params[] = urlencode($name) . '=' . urlencode($value); + } + $paramString = implode('&', $params); + $client->setRawData($paramString); + return $client; + } +} diff --git a/libs/Zend/Feed/Pubsubhubbub/Subscriber.php b/libs/Zend/Feed/Pubsubhubbub/Subscriber.php new file mode 100644 index 0000000000..4a19583a1d --- /dev/null +++ b/libs/Zend/Feed/Pubsubhubbub/Subscriber.php @@ -0,0 +1,857 @@ +<?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_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 + */ + +/** + * @see Zend_Feed_Pubsubhubbub + */ +require_once 'Zend/Feed/Pubsubhubbub.php'; + +/** + * @see Zend_Date + */ +require_once 'Zend/Date.php'; + +/** + * @category Zend + * @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 + */ +class Zend_Feed_Pubsubhubbub_Subscriber +{ + /** + * An array of URLs for all Hub Servers to subscribe/unsubscribe. + * + * @var array + */ + protected $_hubUrls = array(); + + /** + * An array of optional parameters to be included in any + * (un)subscribe requests. + * + * @var array + */ + protected $_parameters = array(); + + /** + * The URL of the topic (Rss or Atom feed) which is the subject of + * our current intent to subscribe to/unsubscribe from updates from + * the currently configured Hub Servers. + * + * @var string + */ + protected $_topicUrl = ''; + + /** + * The URL Hub Servers must use when communicating with this Subscriber + * + * @var string + */ + protected $_callbackUrl = ''; + + /** + * The number of seconds for which the subscriber would like to have the + * subscription active. Defaults to null, i.e. not sent, to setup a + * permanent subscription if possible. + * + * @var int + */ + protected $_leaseSeconds = null; + + /** + * The preferred verification mode (sync or async). By default, this + * Subscriber prefers synchronous verification, but is considered + * desireable to support asynchronous verification if possible. + * + * Zend_Feed_Pubsubhubbub_Subscriber will always send both modes, whose + * order of occurance in the parameter list determines this preference. + * + * @var string + */ + protected $_preferredVerificationMode + = Zend_Feed_Pubsubhubbub::VERIFICATION_MODE_SYNC; + + /** + * An array of any errors including keys for 'response', 'hubUrl'. + * The response is the actual Zend_Http_Response object. + * + * @var array + */ + protected $_errors = array(); + + /** + * An array of Hub Server URLs for Hubs operating at this time in + * asynchronous verification mode. + * + * @var array + */ + protected $_asyncHubs = array(); + + /** + * An instance of Zend_Feed_Pubsubhubbub_Model_SubscriptionInterface used to background + * save any verification tokens associated with a subscription or other. + * + * @var Zend_Feed_Pubsubhubbub_Model_SubscriptionInterface + */ + protected $_storage = null; + + /** + * An array of authentication credentials for HTTP Basic Authentication + * if required by specific Hubs. The array is indexed by Hub Endpoint URI + * and the value is a simple array of the username and password to apply. + * + * @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 + * to the callback URL "http://www.example.com/callback" to create a subscription + * specific Callback URL of "http://www.example.com/callback/subkey1". + * + * This is required for all Hubs using the Pubsubhubbub 0.1 Specification. + * It should be manually intercepted and passed to the Callback class using + * Zend_Feed_Pubsubhubbub_Subscriber_Callback::setSubscriptionKey(). Will + * require a route in the form "callback/:subkey" to allow the parameter be + * retrieved from an action using the Zend_Controller_Action::_getParam() + * method. + * + * @var string + */ + protected $_usePathParameter = false; + + /** + * Constructor; accepts an array or Zend_Config instance to preset + * options for the Subscriber without calling all supported setter + * methods in turn. + * + * @param array|Zend_Config $options Options array or Zend_Config instance + * @return void + */ + public function __construct($config = null) + { + if (!is_null($config)) { + $this->setConfig($config); + } + } + + /** + * Process any injected configuration options + * + * @param array|Zend_Config $options Options array or Zend_Config instance + * @return Zend_Feed_Pubsubhubbub_Subscriber + */ + public function setConfig($config) + { + if ($config instanceof Zend_Config) { + $config = $config->toArray(); + } elseif (!is_array($config)) { + require_once 'Zend/Feed/Pubsubhubbub/Exception.php'; + throw new Zend_Feed_Pubsubhubbub_Exception('Array or Zend_Config object' + . ' expected, got ' . gettype($config)); + } + if (array_key_exists('hubUrls', $config)) { + $this->addHubUrls($config['hubUrls']); + } + if (array_key_exists('callbackUrl', $config)) { + $this->setCallbackUrl($config['callbackUrl']); + } + if (array_key_exists('topicUrl', $config)) { + $this->setTopicUrl($config['topicUrl']); + } + if (array_key_exists('storage', $config)) { + $this->setStorage($config['storage']); + } + if (array_key_exists('leaseSeconds', $config)) { + $this->setLeaseSeconds($config['leaseSeconds']); + } + if (array_key_exists('parameters', $config)) { + $this->setParameters($config['parameters']); + } + if (array_key_exists('authentications', $config)) { + $this->addAuthentications($config['authentications']); + } + if (array_key_exists('usePathParameter', $config)) { + $this->usePathParameter($config['usePathParameter']); + } + if (array_key_exists('preferredVerificationMode', $config)) { + $this->setPreferredVerificationMode( + $config['preferredVerificationMode'] + ); + } + return $this; + } + + /** + * Set the topic URL (RSS or Atom feed) to which the intended (un)subscribe + * event will relate + * + * @param string $url + * @return Zend_Feed_Pubsubhubbub_Subscriber + */ + public function setTopicUrl($url) + { + if (empty($url) || !is_string($url) || !Zend_Uri::check($url)) { + require_once 'Zend/Feed/Pubsubhubbub/Exception.php'; + throw new Zend_Feed_Pubsubhubbub_Exception('Invalid parameter "url"' + .' of "' . $url . '" must be a non-empty string and a valid' + .' URL'); + } + $this->_topicUrl = $url; + return $this; + } + + /** + * Set the topic URL (RSS or Atom feed) to which the intended (un)subscribe + * event will relate + * + * @return string + */ + public function getTopicUrl() + { + if (empty($this->_topicUrl)) { + require_once 'Zend/Feed/Pubsubhubbub/Exception.php'; + throw new Zend_Feed_Pubsubhubbub_Exception('A valid Topic (RSS or Atom' + . ' feed) URL MUST be set before attempting any operation'); + } + return $this->_topicUrl; + } + + /** + * Set the number of seconds for which any subscription will remain valid + * + * @param int $seconds + * @return Zend_Feed_Pubsubhubbub_Subscriber + */ + public function setLeaseSeconds($seconds) + { + $seconds = intval($seconds); + if ($seconds <= 0) { + require_once 'Zend/Feed/Pubsubhubbub/Exception.php'; + throw new Zend_Feed_Pubsubhubbub_Exception('Expected lease seconds' + . ' must be an integer greater than zero'); + } + $this->_leaseSeconds = $seconds; + return $this; + } + + /** + * Get the number of lease seconds on subscriptions + * + * @return int + */ + public function getLeaseSeconds() + { + return $this->_leaseSeconds; + } + + /** + * Set the callback URL to be used by Hub Servers when communicating with + * this Subscriber + * + * @param string $url + * @return Zend_Feed_Pubsubhubbub_Subscriber + */ + public function setCallbackUrl($url) + { + if (empty($url) || !is_string($url) || !Zend_Uri::check($url)) { + require_once 'Zend/Feed/Pubsubhubbub/Exception.php'; + throw new Zend_Feed_Pubsubhubbub_Exception('Invalid parameter "url"' + . ' of "' . $url . '" must be a non-empty string and a valid' + . ' URL'); + } + $this->_callbackUrl = $url; + return $this; + } + + /** + * Get the callback URL to be used by Hub Servers when communicating with + * this Subscriber + * + * @return string + */ + public function getCallbackUrl() + { + if (empty($this->_callbackUrl)) { + require_once 'Zend/Feed/Pubsubhubbub/Exception.php'; + throw new Zend_Feed_Pubsubhubbub_Exception('A valid Callback URL MUST be' + . ' set before attempting any operation'); + } + return $this->_callbackUrl; + } + + /** + * Set preferred verification mode (sync or async). By default, this + * Subscriber prefers synchronous verification, but does support + * asynchronous if that's the Hub Server's utilised mode. + * + * Zend_Feed_Pubsubhubbub_Subscriber will always send both modes, whose + * order of occurance in the parameter list determines this preference. + * + * @param string $mode Should be 'sync' or 'async' + * @return Zend_Feed_Pubsubhubbub_Subscriber + */ + public function setPreferredVerificationMode($mode) + { + if ($mode !== Zend_Feed_Pubsubhubbub::VERIFICATION_MODE_SYNC + && $mode !== Zend_Feed_Pubsubhubbub::VERIFICATION_MODE_ASYNC) { + require_once 'Zend/Feed/Pubsubhubbub/Exception.php'; + throw new Zend_Feed_Pubsubhubbub_Exception('Invalid preferred' + . ' mode specified: "' . $mode . '" but should be one of' + . ' Zend_Feed_Pubsubhubbub::VERIFICATION_MODE_SYNC or' + . ' Zend_Feed_Pubsubhubbub::VERIFICATION_MODE_ASYNC'); + } + $this->_preferredVerificationMode = $mode; + return $this; + } + + /** + * Get preferred verification mode (sync or async). + * + * @return string + */ + public function getPreferredVerificationMode() + { + return $this->_preferredVerificationMode; + } + + /** + * Add a Hub Server URL supported by Publisher + * + * @param string $url + * @return Zend_Feed_Pubsubhubbub_Subscriber + */ + public function addHubUrl($url) + { + if (empty($url) || !is_string($url) || !Zend_Uri::check($url)) { + require_once 'Zend/Feed/Pubsubhubbub/Exception.php'; + throw new Zend_Feed_Pubsubhubbub_Exception('Invalid parameter "url"' + . ' of "' . $url . '" must be a non-empty string and a valid' + . ' URL'); + } + $this->_hubUrls[] = $url; + return $this; + } + + /** + * Add an array of Hub Server URLs supported by Publisher + * + * @param array $urls + * @return Zend_Feed_Pubsubhubbub_Subscriber + */ + public function addHubUrls(array $urls) + { + foreach ($urls as $url) { + $this->addHubUrl($url); + } + return $this; + } + + /** + * Remove a Hub Server URL + * + * @param string $url + * @return Zend_Feed_Pubsubhubbub_Subscriber + */ + public function removeHubUrl($url) + { + if (!in_array($url, $this->getHubUrls())) { + return $this; + } + $key = array_search($url, $this->_hubUrls); + unset($this->_hubUrls[$key]); + return $this; + } + + /** + * Return an array of unique Hub Server URLs currently available + * + * @return array + */ + public function getHubUrls() + { + $this->_hubUrls = array_unique($this->_hubUrls); + return $this->_hubUrls; + } + + /** + * Add authentication credentials for a given URL + * + * @param string $url + * @param array $authentication + * @return Zend_Feed_Pubsubhubbub_Subscriber + */ + public function addAuthentication($url, array $authentication) + { + if (empty($url) || !is_string($url) || !Zend_Uri::check($url)) { + require_once 'Zend/Feed/Pubsubhubbub/Exception.php'; + throw new Zend_Feed_Pubsubhubbub_Exception('Invalid parameter "url"' + . ' of "' . $url . '" must be a non-empty string and a valid' + . ' URL'); + } + $this->_authentications[$url] = $authentication; + return $this; + } + + /** + * Add authentication credentials for hub URLs + * + * @param array $authentications + * @return Zend_Feed_Pubsubhubbub_Subscriber + */ + public function addAuthentications(array $authentications) + { + foreach ($authentications as $url => $authentication) { + $this->addAuthentication($url, $authentication); + } + 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 + * @return Zend_Feed_Pubsubhubbub_Subscriber + */ + public function usePathParameter($bool = true) + { + $this->_usePathParameter = $bool; + return $this; + } + + /** + * Add an optional parameter to the (un)subscribe requests + * + * @param string $name + * @param string|null $value + * @return Zend_Feed_Pubsubhubbub_Subscriber + */ + public function setParameter($name, $value = null) + { + if (is_array($name)) { + $this->setParameters($name); + return $this; + } + if (empty($name) || !is_string($name)) { + require_once 'Zend/Feed/Pubsubhubbub/Exception.php'; + throw new Zend_Feed_Pubsubhubbub_Exception('Invalid parameter "name"' + . ' of "' . $name . '" must be a non-empty string'); + } + if ($value === null) { + $this->removeParameter($name); + return $this; + } + if (empty($value) || (!is_string($value) && !is_null($value))) { + require_once 'Zend/Feed/Pubsubhubbub/Exception.php'; + throw new Zend_Feed_Pubsubhubbub_Exception('Invalid parameter "value"' + . ' of "' . $value . '" must be a non-empty string'); + } + $this->_parameters[$name] = $value; + return $this; + } + + /** + * Add an optional parameter to the (un)subscribe requests + * + * @param string $name + * @param string|null $value + * @return Zend_Feed_Pubsubhubbub_Subscriber + */ + public function setParameters(array $parameters) + { + foreach ($parameters as $name => $value) { + $this->setParameter($name, $value); + } + return $this; + } + + /** + * Remove an optional parameter for the (un)subscribe requests + * + * @param string $name + * @return Zend_Feed_Pubsubhubbub_Subscriber + */ + public function removeParameter($name) + { + if (empty($name) || !is_string($name)) { + require_once 'Zend/Feed/Pubsubhubbub/Exception.php'; + throw new Zend_Feed_Pubsubhubbub_Exception('Invalid parameter "name"' + . ' of "' . $name . '" must be a non-empty string'); + } + if (array_key_exists($name, $this->_parameters)) { + unset($this->_parameters[$name]); + } + return $this; + } + + /** + * Return an array of optional parameters for (un)subscribe requests + * + * @return array + */ + public function getParameters() + { + return $this->_parameters; + } + + /** + * Sets an instance of Zend_Feed_Pubsubhubbub_Model_SubscriptionInterface used to background + * save any verification tokens associated with a subscription or other. + * + * @param Zend_Feed_Pubsubhubbub_Model_SubscriptionInterface $storage + * @return Zend_Feed_Pubsubhubbub_Subscriber + */ + public function setStorage(Zend_Feed_Pubsubhubbub_Model_SubscriptionInterface $storage) + { + $this->_storage = $storage; + return $this; + } + + /** + * Gets an instance of Zend_Feed_Pubsubhubbub_Storage_StorageInterface used + * to background save any verification tokens associated with a subscription + * or other. + * + * @return Zend_Feed_Pubsubhubbub_Model_SubscriptionInterface + */ + public function getStorage() + { + if ($this->_storage === null) { + require_once 'Zend/Feed/Pubsubhubbub/Exception.php'; + throw new Zend_Feed_Pubsubhubbub_Exception('No storage vehicle ' + . 'has been set.'); + } + return $this->_storage; + } + + /** + * Subscribe to one or more Hub Servers using the stored Hub URLs + * for the given Topic URL (RSS or Atom feed) + * + * @return void + */ + public function subscribeAll() + { + return $this->_doRequest('subscribe'); + } + + /** + * Unsubscribe from one or more Hub Servers using the stored Hub URLs + * for the given Topic URL (RSS or Atom feed) + * + * @return void + */ + public function unsubscribeAll() + { + return $this->_doRequest('unsubscribe'); + } + + /** + * Returns a boolean indicator of whether the notifications to Hub + * Servers were ALL successful. If even one failed, FALSE is returned. + * + * @return bool + */ + public function isSuccess() + { + if (count($this->_errors) > 0) { + return false; + } + return true; + } + + /** + * Return an array of errors met from any failures, including keys: + * 'response' => the Zend_Http_Response object from the failure + * 'hubUrl' => the URL of the Hub Server whose notification failed + * + * @return array + */ + public function getErrors() + { + return $this->_errors; + } + + /** + * Return an array of Hub Server URLs who returned a response indicating + * operation in Asynchronous Verification Mode, i.e. they will not confirm + * any (un)subscription immediately but at a later time (Hubs may be + * doing this as a batch process when load balancing) + * + * @return array + */ + public function getAsyncHubs() + { + return $this->_asyncHubs; + } + + /** + * Executes an (un)subscribe request + * + * @param string $mode + * @return void + */ + protected function _doRequest($mode) + { + $client = $this->_getHttpClient(); + $hubs = $this->getHubUrls(); + if (empty($hubs)) { + require_once 'Zend/Feed/Pubsubhubbub/Exception.php'; + throw new Zend_Feed_Pubsubhubbub_Exception('No Hub Server URLs' + . ' have been set so no subscriptions can be attempted'); + } + $this->_errors = array(); + $this->_asyncHubs = array(); + foreach ($hubs as $url) { + if (array_key_exists($url, $this->_authentications)) { + $auth = $this->_authentications[$url]; + $client->setAuth($auth[0], $auth[1]); + } + $client->setUri($url); + $client->setRawData($this->_getRequestParameters($url, $mode)); + $response = $client->request(); + echo $client->getLastRequest(); + if ($response->getStatus() !== 204 + && $response->getStatus() !== 202 + ) { + $this->_errors[] = array( + 'response' => $response, + 'hubUrl' => $url, + ); + /** + * At first I thought it was needed, but the backend storage will + * allow tracking async without any user interference. It's left + * here in case the user is interested in knowing what Hubs + * are using async verification modes so they may update Models and + * move these to asynchronous processes. + */ + } elseif ($response->getStatus() == 202) { + $this->_asyncHubs[] = array( + 'response' => $response, + 'hubUrl' => $url, + ); + } + } + } + + /** + * Get a basic prepared HTTP client for use + * + * @param string $mode Must be "subscribe" or "unsubscribe" + * @return Zend_Http_Client + */ + protected function _getHttpClient() + { + $client = Zend_Feed_Pubsubhubbub::getHttpClient(); + $client->setMethod(Zend_Http_Client::POST); + $client->setConfig(array('useragent' => 'Zend_Feed_Pubsubhubbub_Subscriber/' + . Zend_Version::VERSION)); + return $client; + } + + /** + * Return a list of standard protocol/optional parameters for addition to + * client's POST body that are specific to the current Hub Server URL + * + * @param string $hubUrl + * @param mode $hubUrl + * @return string + */ + protected function _getRequestParameters($hubUrl, $mode) + { + if (!in_array($mode, array('subscribe', 'unsubscribe'))) { + require_once 'Zend/Feed/Pubsubhubbub/Exception.php'; + throw new Zend_Feed_Pubsubhubbub_Exception('Invalid mode specified: "' + . $mode . '" which should have been "subscribe" or "unsubscribe"'); + } + + $params = array( + 'hub.mode' => $mode, + 'hub.topic' => $this->getTopicUrl(), + ); + + if ($this->getPreferredVerificationMode() + == Zend_Feed_Pubsubhubbub::VERIFICATION_MODE_SYNC + ) { + $vmodes = array( + Zend_Feed_Pubsubhubbub::VERIFICATION_MODE_SYNC, + Zend_Feed_Pubsubhubbub::VERIFICATION_MODE_ASYNC, + ); + } else { + $vmodes = array( + Zend_Feed_Pubsubhubbub::VERIFICATION_MODE_ASYNC, + Zend_Feed_Pubsubhubbub::VERIFICATION_MODE_SYNC, + ); + } + $params['hub.verify'] = array(); + foreach($vmodes as $vmode) { + $params['hub.verify'][] = $vmode; + } + + /** + * Establish a persistent verify_token and attach key to callback + * URL's path/querystring + */ + $key = $this->_generateSubscriptionKey($params); + $token = $this->_generateVerifyToken(); + $params['hub.verify_token'] = $token; + + // Note: query string only usable with PuSH 0.2 Hubs + if (!$this->_usePathParameter) { + $params['hub.callback'] = $this->getCallbackUrl() + . '?xhub.subscription=' . Zend_Feed_Pubsubhubbub::urlencode($key); + } else { + $params['hub.callback'] = rtrim($this->getCallbackUrl(), '/') + . '/' . Zend_Feed_Pubsubhubbub::urlencode($key); + } + if ($mode == 'subscribe' && !is_null($this->getLeaseSeconds())) { + $params['hub.lease_seconds'] = $this->getLeaseSeconds(); + } + + // hub.secret not currently supported + $optParams = $this->getParameters(); + foreach ($optParams as $name => $value) { + $params[$name] = $value; + } + + // store subscription to storage + $now = new Zend_Date; + $expires = null; + if (isset($params['hub.lease_seconds'])) { + $expires = $now->add($params['hub.lease_seconds'], Zend_Date::SECOND) + ->get('yyyy-MM-dd HH:mm:ss'); + } + $data = array( + 'id' => $key, + 'topic_url' => $params['hub.topic'], + 'hub_url' => $hubUrl, + 'created_time' => $now->get('yyyy-MM-dd HH:mm:ss'), + 'lease_seconds' => $expires, + 'verify_token' => hash('sha256', $params['hub.verify_token']), + 'secret' => null, + 'expiration_time' => $expires, + 'subscription_state' => Zend_Feed_Pubsubhubbub::SUBSCRIPTION_NOTVERIFIED, + ); + $this->getStorage()->setSubscription($data); + + return $this->_toByteValueOrderedString( + $this->_urlEncode($params) + ); + } + + /** + * Simple helper to generate a verification token used in (un)subscribe + * requests to a Hub Server. Follows no particular method, which means + * it might be improved/changed in future. + * + * @param string $hubUrl The Hub Server URL for which this token will apply + * @return string + */ + protected function _generateVerifyToken() + { + if (!empty($this->_testStaticToken)) { + return $this->_testStaticToken; + } + return uniqid(rand(), true) . time(); + } + + /** + * Simple helper to generate a verification token used in (un)subscribe + * requests to a Hub Server. + * + * @param string $hubUrl The Hub Server URL for which this token will apply + * @return string + */ + protected function _generateSubscriptionKey(array $params) + { + $keyBase = $params['hub.topic'] . $params['hub.callback']; + $key = md5($keyBase); + return $key; + } + + /** + * URL Encode an array of parameters + * + * @param array $params + * @return array + */ + protected function _urlEncode(array $params) + { + $encoded = array(); + foreach ($params as $key => $value) { + if (is_array($value)) { + $ekey = Zend_Feed_Pubsubhubbub::urlencode($key); + $encoded[$ekey] = array(); + foreach ($value as $duplicateKey) { + $encoded[$ekey][] + = Zend_Feed_Pubsubhubbub::urlencode($duplicateKey); + } + } else { + $encoded[Zend_Feed_Pubsubhubbub::urlencode($key)] + = Zend_Feed_Pubsubhubbub::urlencode($value); + } + } + return $encoded; + } + + /** + * Order outgoing parameters + * + * @param array $params + * @return array + */ + protected function _toByteValueOrderedString(array $params) + { + $return = array(); + uksort($params, 'strnatcmp'); + foreach ($params as $key => $value) { + if (is_array($value)) { + foreach ($value as $keyduplicate) { + $return[] = $key . '=' . $keyduplicate; + } + } else { + $return[] = $key . '=' . $value; + } + } + return implode('&', $return); + } + + /** + * This is STRICTLY for testing purposes only... + */ + protected $_testStaticToken = null; + + final public function setTestStaticToken($token) + { + $this->_testStaticToken = (string) $token; + } +} diff --git a/libs/Zend/Feed/Pubsubhubbub/Subscriber/Callback.php b/libs/Zend/Feed/Pubsubhubbub/Subscriber/Callback.php new file mode 100644 index 0000000000..182c857d55 --- /dev/null +++ b/libs/Zend/Feed/Pubsubhubbub/Subscriber/Callback.php @@ -0,0 +1,326 @@ +<?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_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 + */ + +/** + * @see Zend_Feed_Pubsubhubbub + */ +require_once 'Zend/Feed/Pubsubhubbub.php'; + +/** + * @see Zend_Feed_Pubsubhubbub + */ +require_once 'Zend/Feed/Pubsubhubbub/CallbackAbstract.php'; + +/** + * @see Zend_Feed_Reader + */ +require_once 'Zend/Feed/Reader.php'; + +/** + * @category Zend + * @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 + */ +class Zend_Feed_Pubsubhubbub_Subscriber_Callback + extends Zend_Feed_Pubsubhubbub_CallbackAbstract +{ + /** + * Contains the content of any feeds sent as updates to the Callback URL + * + * @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 + * but is part of the Callback URL path, requiring manual retrieval e.g. + * using a route and the Zend_Controller_Action::_getParam() method. + * + * @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. + * + * @param string $key + * @return Zend_Feed_Pubsubhubbub_Subscriber_Callback + */ + public function setSubscriptionKey($key) + { + $this->_subscriptionKey = $key; + return $this; + } + + /** + * Handle any callback from a Hub Server responding to a subscription or + * unsubscription request. This should be the Hub Server confirming the + * the request prior to taking action on it. + * + * @param array $httpGetData GET data if available and not in $_GET + * @param bool $sendResponseNow Whether to send response now or when asked + * @return void + */ + public function handle(array $httpGetData = null, $sendResponseNow = false) + { + if ($httpGetData === null) { + $httpGetData = $_GET; + } + + /** + * Handle any feed updates (sorry for the mess :P) + * + * This DOES NOT attempt to process a feed update. Feed updates + * SHOULD be validated/processed by an asynchronous process so as + * to avoid holding up responses to the Hub. + */ + 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/rdf+xml') + ) { + $this->setFeedUpdate($this->_getRawBody()); + $this->getHttpResponse() + ->setHeader('X-Hub-On-Behalf-Of', $this->getSubscriberCount()); + /** + * Handle any (un)subscribe confirmation requests + */ + } elseif ($this->isValidHubVerification($httpGetData)) { + $data = $this->_currentSubscriptionData; + $this->getHttpResponse()->setBody($httpGetData['hub_challenge']); + $data['subscription_state'] = Zend_Feed_Pubsubhubbub::SUBSCRIPTION_VERIFIED; + if (isset($httpGetData['hub_lease_seconds'])) { + $data['lease_seconds'] = $httpGetData['hub_lease_seconds']; + } + $this->getStorage()->setSubscription($data); + /** + * Hey, C'mon! We tried everything else! + */ + } else { + $this->getHttpResponse()->setHttpResponseCode(404); + } + if ($sendResponseNow) { + $this->sendResponse(); + } + } + + /** + * Checks validity of the request simply by making a quick pass and + * confirming the presence of all REQUIRED parameters. + * + * @param array $httpGetData + * @return bool + */ + public function isValidHubVerification(array $httpGetData) + { + /** + * As per the specification, the hub.verify_token is OPTIONAL. This + * implementation of Pubsubhubbub considers it REQUIRED and will + * always send a hub.verify_token parameter to be echoed back + * by the Hub Server. Therefore, its absence is considered invalid. + */ + if (strtolower($_SERVER['REQUEST_METHOD']) !== 'get') { + return false; + } + $required = array( + 'hub_mode', + 'hub_topic', + 'hub_challenge', + 'hub_verify_token', + ); + foreach ($required as $key) { + if (!array_key_exists($key, $httpGetData)) { + return false; + } + } + if ($httpGetData['hub_mode'] !== 'subscribe' + && $httpGetData['hub_mode'] !== 'unsubscribe' + ) { + return false; + } + if ($httpGetData['hub_mode'] == 'subscribe' + && !array_key_exists('hub_lease_seconds', $httpGetData) + ) { + return false; + } + if (!Zend_Uri::check($httpGetData['hub_topic'])) { + return false; + } + + /** + * Attempt to retrieve any Verification Token Key attached to Callback + * URL's path by our Subscriber implementation + */ + if (!$this->_hasValidVerifyToken($httpGetData)) { + return false; + } + return true; + } + + /** + * Sets a newly received feed (Atom/RSS) sent by a Hub as an update to a + * Topic we've subscribed to. + * + * @param string $feed + * @return Zend_Feed_Pubsubhubbub_Subscriber_Callback + */ + public function setFeedUpdate($feed) + { + $this->_feedUpdate = $feed; + return $this; + } + + /** + * Check if any newly received feed (Atom/RSS) update was received + * + * @return bool + */ + public function hasFeedUpdate() + { + if (is_null($this->_feedUpdate)) { + return false; + } + return true; + } + + /** + * Gets a newly received feed (Atom/RSS) sent by a Hub as an update to a + * Topic we've subscribed to. + * + * @return string + */ + public function getFeedUpdate() + { + return $this->_feedUpdate; + } + + /** + * Check for a valid verify_token. By default attempts to compare values + * with that sent from Hub, otherwise merely ascertains its existence. + * + * @param array $httpGetData + * @param bool $checkValue + * @return bool + */ + protected function _hasValidVerifyToken(array $httpGetData = null, $checkValue = true) + { + $verifyTokenKey = $this->_detectVerifyTokenKey($httpGetData); + if (empty($verifyTokenKey)) { + return false; + } + $verifyTokenExists = $this->getStorage()->hasSubscription($verifyTokenKey); + if (!$verifyTokenExists) { + return false; + } + if ($checkValue) { + $data = $this->getStorage()->getSubscription($verifyTokenKey); + $verifyToken = $data['verify_token']; + if ($verifyToken !== hash('sha256', $httpGetData['hub_verify_token'])) { + return false; + } + $this->_currentSubscriptionData = $data; + return true; + } + return true; + } + + /** + * Attempt to detect the verification token key. This would be passed in + * the Callback URL (which we are handling with this class!) as a URI + * path part (the last part by convention). + * + * @param null|array $httpGetData + * @return false|string + */ + protected function _detectVerifyTokenKey(array $httpGetData = null) + { + /** + * Available when sub keys encoding in Callback URL path + */ + if (isset($this->_subscriptionKey)) { + return $this->_subscriptionKey; + } + + /** + * Available only if allowed by PuSH 0.2 Hubs + */ + if (is_array($httpGetData) + && isset($httpGetData['xhub_subscription']) + ) { + return $httpGetData['xhub_subscription']; + } + + /** + * Available (possibly) if corrupted in transit and not part of $_GET + */ + $params = $this->_parseQueryString(); + if (isset($params['xhub.subscription'])) { + return rawurldecode($params['xhub.subscription']); + } + + return false; + } + + /** + * Build an array of Query String parameters. + * This bypasses $_GET which munges parameter names and cannot accept + * multiple parameters with the same key. + * + * @return array|void + */ + protected function _parseQueryString() + { + $params = array(); + $queryString = ''; + if (isset($_SERVER['QUERY_STRING'])) { + $queryString = $_SERVER['QUERY_STRING']; + } + if (empty($queryString)) { + return array(); + } + $parts = explode('&', $queryString); + foreach ($parts as $kvpair) { + $pair = explode('=', $kvpair); + $key = rawurldecode($pair[0]); + $value = rawurldecode($pair[1]); + if (isset($params[$key])) { + if (is_array($params[$key])) { + $params[$key][] = $value; + } else { + $params[$key] = array($params[$key], $value); + } + } else { + $params[$key] = $value; + } + } + return $params; + } +} diff --git a/libs/Zend/Feed/Reader.php b/libs/Zend/Feed/Reader.php index c41578398a..f44a7483a8 100644 --- a/libs/Zend/Feed/Reader.php +++ b/libs/Zend/Feed/Reader.php @@ -14,9 +14,9 @@ * * @category Zend * @package Zend_Feed_Reader - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 19120 2009-11-20 17:58:59Z padraic $ + * @version $Id: Reader.php 20096 2010-01-06 02:05:09Z bkarwin $ */ /** @@ -42,7 +42,7 @@ require_once 'Zend/Feed/Reader/FeedSet.php'; /** * @category Zend * @package Zend_Feed_Reader - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Feed_Reader @@ -62,6 +62,7 @@ class Zend_Feed_Reader const TYPE_ANY = 'any'; const TYPE_ATOM_03 = 'atom-03'; const TYPE_ATOM_10 = 'atom-10'; + const TYPE_ATOM_10_ENTRY = 'atom-10-entry'; const TYPE_ATOM_ANY = 'atom'; const TYPE_RSS_090 = 'rss-090'; const TYPE_RSS_091 = 'rss-091'; @@ -341,6 +342,8 @@ class Zend_Feed_Reader if (substr($type, 0, 3) == 'rss') { $reader = new Zend_Feed_Reader_Feed_Rss($dom, $type); + } elseif (substr($type, 8, 5) == 'entry') { + $reader = new Zend_Feed_Reader_Entry_Atom($dom->documentElement, 0, Zend_Feed_Reader::TYPE_ATOM_10); } elseif (substr($type, 0, 4) == 'atom') { $reader = new Zend_Feed_Reader_Feed_Atom($dom, $type); } else { @@ -412,14 +415,14 @@ class Zend_Feed_Reader /** * Detect the feed type of the provided feed * - * @param Zend_Feed_Abstract $feed A fully instantiated Zend_Feed object + * @param Zend_Feed_Abstract|DOMDocument|string $feed * @return string */ - public static function detectType($feed) + public static function detectType($feed, $specOnly = false) { if ($feed instanceof Zend_Feed_Reader_FeedInterface) { $dom = $feed->getDomDocument(); - } elseif($feed instanceof DomDocument) { + } elseif($feed instanceof DOMDocument) { $dom = $feed; } elseif(is_string($feed) && !empty($feed)) { @ini_set('track_errors', 1); @@ -439,7 +442,8 @@ class Zend_Feed_Reader } } else { require_once 'Zend/Feed/Exception.php'; - throw new Zend_Feed_Exception('Invalid object/scalar provided: must be of type Zend_Feed_Reader_FeedInterface, DomDocument or string'); + throw new Zend_Feed_Exception('Invalid object/scalar provided: must' + . ' be of type Zend_Feed_Reader_FeedInterface, DomDocument or string'); } $xpath = new DOMXPath($dom); @@ -504,6 +508,14 @@ 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; + } else { + return self::TYPE_ATOM_10_ENTRY; + } + } $xpath->registerNamespace('atom', self::NAMESPACE_ATOM_03); @@ -684,4 +696,24 @@ class Zend_Feed_Reader self::registerExtension('Thread'); self::registerExtension('Podcast'); } + + /** + * Utility method to apply array_unique operation to a multidimensional + * array. + * + * @param array + * @return array + */ + public static function arrayUnique(array $array) + { + foreach ($array as &$value) { + $value = serialize($value); + } + $array = array_unique($array); + foreach ($array as &$value) { + $value = unserialize($value); + } + return $array; + } + } diff --git a/libs/Zend/Feed/Reader/Collection.php b/libs/Zend/Feed/Reader/Collection.php new file mode 100644 index 0000000000..fba2b52b52 --- /dev/null +++ b/libs/Zend/Feed/Reader/Collection.php @@ -0,0 +1,33 @@ +<?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_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 Zend + * @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 + */ +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 new file mode 100644 index 0000000000..98a8aea226 --- /dev/null +++ b/libs/Zend/Feed/Reader/Collection/Author.php @@ -0,0 +1,51 @@ +<?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_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 $ + */ + +/** + * @see Zend_Feed_Reader_Collection_CollectionAbstract + */ +require_once 'Zend/Feed/Reader/Collection/CollectionAbstract.php'; + +/** + * @category Zend + * @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 + */ +class Zend_Feed_Reader_Collection_Author +extends Zend_Feed_Reader_Collection_CollectionAbstract +{ + + /** + * Return a simple array of the most relevant slice of + * the author values, i.e. all author names. + * + * @return array + */ + public function getValues() { + $authors = array(); + foreach ($this->getIterator() as $element) { + $authors[] = $element['name']; + } + return array_unique($authors); + } + +} diff --git a/libs/Zend/Feed/Reader/Collection/Category.php b/libs/Zend/Feed/Reader/Collection/Category.php new file mode 100644 index 0000000000..18b9f362e5 --- /dev/null +++ b/libs/Zend/Feed/Reader/Collection/Category.php @@ -0,0 +1,53 @@ +<?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_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 20096 2010-01-06 02:05:09Z bkarwin $ + */ + +/** + * @see Zend_Feed_Reader_Collection_CollectionAbstract + */ +require_once 'Zend/Feed/Reader/Collection/CollectionAbstract.php'; + +/** + * @category Zend + * @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 + */ +class Zend_Feed_Reader_Collection_Category +extends Zend_Feed_Reader_Collection_CollectionAbstract +{ + + /** + * Return a simple array of the most relevant slice of + * the collection values. For example, feed categories contain + * the category name, domain/URI, and other data. This method would + * merely return the most useful data - i.e. the category names. + * + * @return array + */ + public function getValues() { + $categories = array(); + foreach ($this->getIterator() as $element) { + $categories[] = $element['label']; + } + return array_unique($categories); + } + +} diff --git a/libs/Zend/Feed/Reader/Collection/CollectionAbstract.php b/libs/Zend/Feed/Reader/Collection/CollectionAbstract.php new file mode 100644 index 0000000000..7b6dbd0317 --- /dev/null +++ b/libs/Zend/Feed/Reader/Collection/CollectionAbstract.php @@ -0,0 +1,41 @@ +<?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_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: CollectionAbstract.php 20096 2010-01-06 02:05:09Z bkarwin $ + */ + +/** + * @category Zend + * @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 + */ +abstract class Zend_Feed_Reader_Collection_CollectionAbstract extends ArrayObject +{ + + /** + * Return a simple array of the most relevant slice of + * the collection values. For example, feed categories contain + * the category name, domain/URI, and other data. This method would + * merely return the most useful data - i.e. the category names. + * + * @return array + */ + public abstract function getValues(); + +} diff --git a/libs/Zend/Feed/Reader/Entry/Atom.php b/libs/Zend/Feed/Reader/Entry/Atom.php index c4ab3fa629..308deba59e 100644 --- a/libs/Zend/Feed/Reader/Entry/Atom.php +++ b/libs/Zend/Feed/Reader/Entry/Atom.php @@ -14,9 +14,9 @@ * * @category Zend * @package Zend_Feed_Reader - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 19193 2009-11-23 16:11:15Z padraic $ + * @version $Id: Atom.php 20096 2010-01-06 02:05:09Z bkarwin $ */ /** @@ -42,7 +42,7 @@ require_once 'Zend/Feed/Reader/Extension/Atom/Entry.php'; /** * @category Zend * @package Zend_Feed_Reader - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Feed_Reader_Entry_Atom extends Zend_Feed_Reader_EntryAbstract implements Zend_Feed_Reader_EntryInterface @@ -74,6 +74,9 @@ 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); } /** @@ -341,6 +344,46 @@ 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 + * + * @return Zend_Feed_Reader_Collection_Category + */ + public function getCategories() + { + if (array_key_exists('categories', $this->_data)) { + return $this->_data['categories']; + } + + $categoryCollection = $this->getExtension('Atom')->getCategories(); + + if (count($categoryCollection) == 0) { + $categoryCollection = $this->getExtension('DublinCore')->getCategories(); + } + + $this->_data['categories'] = $categoryCollection; + + return $this->_data['categories']; + } + + /** + * Get source feed metadata from the entry + * + * @return Zend_Feed_Reader_Feed_Atom_Source|null + */ + public function getSource() + { + if (array_key_exists('source', $this->_data)) { + return $this->_data['source']; + } + + $source = $this->getExtension('Atom')->getSource(); + + $this->_data['source'] = $source; + + return $this->_data['source']; + } /** * Set the XPath query (incl. on all Extensions) diff --git a/libs/Zend/Feed/Reader/Entry/Rss.php b/libs/Zend/Feed/Reader/Entry/Rss.php index b91990a665..30f90d8de3 100644 --- a/libs/Zend/Feed/Reader/Entry/Rss.php +++ b/libs/Zend/Feed/Reader/Entry/Rss.php @@ -14,9 +14,9 @@ * * @category Zend * @package Zend_Feed_Reader - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 18367 2009-09-22 14:55:59Z padraic $ + * @version $Id: Rss.php 20096 2010-01-06 02:05:09Z bkarwin $ */ /** @@ -70,9 +70,14 @@ require_once 'Zend/Feed/Reader/Extension/Thread/Entry.php'; require_once 'Zend/Date.php'; /** + * @see Zend_Feed_Reader_Collection_Category + */ +require_once 'Zend/Feed/Reader/Collection/Category.php'; + +/** * @category Zend * @package Zend_Feed_Reader - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Feed_Reader_Entry_Rss extends Zend_Feed_Reader_EntryAbstract implements Zend_Feed_Reader_EntryInterface @@ -154,45 +159,50 @@ 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(); - // @todo: create a list from all potential sources rather than from alternatives - if ($this->getType() !== Zend_Feed_Reader::TYPE_RSS_10 && - $this->getType() !== Zend_Feed_Reader::TYPE_RSS_090) { - $list = $this->_xpath->evaluate($this->_xpathQueryRss.'//author'); - } else { - $list = $this->_xpath->evaluate($this->_xpathQueryRdf.'//rss:author'); - } - if (!$list->length) { - if ($this->getType() !== Zend_Feed_Reader::TYPE_RSS_10 && $this->getType() !== Zend_Feed_Reader::TYPE_RSS_090) { - $list = $this->_xpath->query('//author'); - } else { - $list = $this->_xpath->query('//rss:author'); + $authors_dc = $this->getExtension('DublinCore')->getAuthors(); + if (!empty($authors_dc)) { + foreach ($authors_dc as $author) { + $authors[] = array( + 'name' => $author['name'] + ); } } - + + if ($this->getType() !== Zend_Feed_Reader::TYPE_RSS_10 + && $this->getType() !== Zend_Feed_Reader::TYPE_RSS_090) { + $list = $this->_xpath->query($this->_xpathQueryRss . '//author'); + } else { + $list = $this->_xpath->query($this->_xpathQueryRdf . '//rss:author'); + } if ($list->length) { foreach ($list as $author) { - if ($this->getType() == Zend_Feed_Reader::TYPE_RSS_20 - && preg_match("/\(([^\)]+)\)/", $author->nodeValue, $matches, PREG_OFFSET_CAPTURE) - ) { - // source name from RSS 2.0 <author> - // format "joe@example.com (Joe Bloggs)" - $authors[] = $matches[1][0]; - } else { - $authors[] = $author->nodeValue; - } + $string = trim($author->nodeValue); + $email = null; + $name = null; + $data = array(); + // Pretty rough parsing - but it's a catchall + if (preg_match("/^.*@[^ ]*/", $string, $matches)) { + $data['email'] = trim($matches[0]); + if (preg_match("/\((.*)\)$/", $string, $matches)) { + $data['name'] = $matches[1]; + } + $authors[] = $data; + } } - - $authors = array_unique($authors); } - if (empty($authors)) { - $authors = $this->getExtension('DublinCore')->getAuthors(); + if (count($authors) == 0) { + $authors = $this->getExtension('Atom')->getAuthors(); + } else { + $authors = new Zend_Feed_Reader_Collection_Author( + Zend_Feed_Reader::arrayUnique($authors) + ); } - if (empty($authors)) { - $authors = $this->getExtension('Atom')->getAuthors(); + if (count($authors) == 0) { + $authors = null; } $this->_data['authors'] = $authors; @@ -268,7 +278,8 @@ class Zend_Feed_Reader_Entry_Rss extends Zend_Feed_Reader_EntryAbstract implemen throw new Zend_Feed_Exception( 'Could not load date due to unrecognised' .' format (should follow RFC 822 or 2822):' - . $e->getMessage() + . $e->getMessage(), + 0, $e ); } } @@ -458,6 +469,46 @@ class Zend_Feed_Reader_Entry_Rss extends Zend_Feed_Reader_EntryAbstract implemen return $this->_data['links']; } + + /** + * Get all categories + * + * @return Zend_Feed_Reader_Collection_Category + */ + public function getCategories() + { + if (array_key_exists('categories', $this->_data)) { + return $this->_data['categories']; + } + + if ($this->getType() !== Zend_Feed_Reader::TYPE_RSS_10 && + $this->getType() !== Zend_Feed_Reader::TYPE_RSS_090) { + $list = $this->_xpath->query($this->_xpathQueryRss.'//category'); + } else { + $list = $this->_xpath->query($this->_xpathQueryRdf.'//rss:category'); + } + + if ($list->length) { + $categoryCollection = new Zend_Feed_Reader_Collection_Category; + foreach ($list as $category) { + $categoryCollection[] = array( + 'term' => $category->nodeValue, + 'scheme' => $category->getAttribute('domain'), + 'label' => $category->nodeValue, + ); + } + } else { + $categoryCollection = $this->getExtension('DublinCore')->getCategories(); + } + + if (count($categoryCollection) == 0) { + $categoryCollection = $this->getExtension('Atom')->getCategories(); + } + + $this->_data['categories'] = $categoryCollection; + + return $this->_data['categories']; + } /** * Get a permalink to the entry diff --git a/libs/Zend/Feed/Reader/EntryAbstract.php b/libs/Zend/Feed/Reader/EntryAbstract.php index f437001476..193bb65c5d 100644 --- a/libs/Zend/Feed/Reader/EntryAbstract.php +++ b/libs/Zend/Feed/Reader/EntryAbstract.php @@ -14,15 +14,15 @@ * * @category Zend * @package Zend_Feed_Reader - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 19042 2009-11-19 15:23:34Z padraic $ + * @version $Id: EntryAbstract.php 20096 2010-01-06 02:05:09Z bkarwin $ */ /** * @category Zend * @package Zend_Feed_Reader - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Feed_Reader_EntryAbstract @@ -154,6 +154,9 @@ abstract class Zend_Feed_Reader_EntryAbstract */ public function getXpath() { + if (!$this->_xpath) { + $this->setXpath(new DOMXPath($this->getDomDocument())); + } return $this->_xpath; } @@ -170,16 +173,6 @@ abstract class Zend_Feed_Reader_EntryAbstract } /** - * Serialize the entry to an array - * - * @return array - */ - public function toArray() - { - return $this->_data; - } - - /** * Get registered extensions * * @return array diff --git a/libs/Zend/Feed/Reader/EntryInterface.php b/libs/Zend/Feed/Reader/EntryInterface.php index dafbe293dd..392a533a30 100644 --- a/libs/Zend/Feed/Reader/EntryInterface.php +++ b/libs/Zend/Feed/Reader/EntryInterface.php @@ -14,15 +14,15 @@ * * @category Zend * @package Zend_Feed_Reader - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 16953 2009-07-22 11:57:25Z padraic $ + * @version $Id: EntryInterface.php 20096 2010-01-06 02:05:09Z bkarwin $ */ /** * @category Zend * @package Zend_Feed_Reader - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Feed_Reader_EntryInterface @@ -133,4 +133,11 @@ interface Zend_Feed_Reader_EntryInterface * @return string */ public function getCommentFeedLink(); + + /** + * Get all categories + * + * @return Zend_Feed_Reader_Collection_Category + */ + public function getCategories(); } diff --git a/libs/Zend/Feed/Reader/Extension/Atom/Entry.php b/libs/Zend/Feed/Reader/Extension/Atom/Entry.php index 70774848d1..57c12e2d1c 100644 --- a/libs/Zend/Feed/Reader/Extension/Atom/Entry.php +++ b/libs/Zend/Feed/Reader/Extension/Atom/Entry.php @@ -14,9 +14,9 @@ * * @category Zend * @package Zend_Feed_Reader - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 18951 2009-11-12 16:26:19Z alexander $ + * @version $Id: Entry.php 20507 2010-01-21 22:21:07Z padraic $ */ /** @@ -40,9 +40,19 @@ require_once 'Zend/Date.php'; require_once 'Zend/Uri.php'; /** + * @see Zend_Feed_Reader_Collection_Category + */ +require_once 'Zend/Feed/Reader/Collection/Category.php'; + +/** + * @see Zend_Feed_Reader_Feed_Atom_Source + */ +require_once 'Zend/Feed/Reader/Feed/Atom/Source.php'; + +/** * @category Zend * @package Zend_Feed_Reader - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Feed_Reader_Extension_Atom_Entry @@ -76,33 +86,34 @@ class Zend_Feed_Reader_Extension_Atom_Entry return $this->_data['authors']; } - $authors = $this->_xpath->query( - $this->getXpathPrefix() . '//atom:author' . '|' - . $this->getXpathPrefix(). '//atom:contributor' - ); + $authors = array(); + $list = $this->getXpath()->query($this->getXpathPrefix() . '//atom:author'); - if (!$authors->length) { - $authors = $this->_xpath->query( - '//atom:author' . '|' . '//atom:contributor' - ); + if (!$list->length) { + /** + * TODO: Limit query to feed level els only! + */ + $list = $this->getXpath()->query('//atom:author'); } - $people = array(); - - if ($authors->length) { - foreach ($authors as $author) { + if ($list->length) { + foreach ($list as $author) { $author = $this->_getAuthor($author); - if (!empty($author)) { - $people[] = $author; + $authors[] = $author; } } } - $people = array_unique($people); - - $this->_data['authors'] = $people; + if (count($authors) == 0) { + $authors = null; + } else { + $authors = new Zend_Feed_Reader_Collection_Author( + Zend_Feed_Reader::arrayUnique($authors) + ); + } + $this->_data['authors'] = $authors; return $this->_data['authors']; } @@ -116,21 +127,65 @@ class Zend_Feed_Reader_Extension_Atom_Entry if (array_key_exists('content', $this->_data)) { return $this->_data['content']; } - - $content = $this->_xpath->evaluate('string(' . $this->getXpathPrefix() . '/atom:content)'); - - if ($content) { - $content = html_entity_decode($content, ENT_QUOTES, $this->getEncoding()); + + $content = null; + + $el = $this->getXpath()->query($this->getXpathPrefix() . '/atom:content'); + if($el->length > 0) { + $el = $el->item(0); + $type = $el->getAttribute('type'); + switch ($type) { + case '': + case 'text': + case 'text/plain': + case 'html': + case 'text/html': + $content = $el->nodeValue; + break; + case 'xhtml': + $this->getXpath()->registerNamespace('xhtml', 'http://www.w3.org/1999/xhtml'); + $xhtml = $this->getXpath()->query( + $this->getXpathPrefix() . '/atom:content/xhtml:div' + )->item(0); + //$xhtml->setAttribute('xmlns', 'http://www.w3.org/1999/xhtml'); + $d = new DOMDocument('1.0', $this->getEncoding()); + $xhtmls = $d->importNode($xhtml, true); + $d->appendChild($xhtmls); + $content = $this->_collectXhtml( + $d->saveXML(), + $d->lookupPrefix('http://www.w3.org/1999/xhtml') + ); + break; + } } + + //var_dump($content); exit; if (!$content) { $content = $this->getDescription(); } - $this->_data['content'] = $content; + $this->_data['content'] = trim($content); return $this->_data['content']; } + + /** + * Parse out XHTML to remove the namespacing + */ + protected function _collectXhtml($xhtml, $prefix) + { + if (!empty($prefix)) $prefix = $prefix . ':'; + $matches = array( + "/<\?xml[^<]*>[^<]*<" . $prefix . "div[^<]*/", + "/<\/" . $prefix . "div>\s*$/" + ); + $xhtml = preg_replace($matches, '', $xhtml); + if (!empty($prefix)) { + $xhtml = preg_replace("/(<[\/]?)" . $prefix . "([a-zA-Z]+)/", '$1$2', $xhtml); + } + return $xhtml; + } /** * Get the entry creation date @@ -145,10 +200,10 @@ class Zend_Feed_Reader_Extension_Atom_Entry $date = null; - if ($this->getType() === Zend_Feed_Reader::TYPE_ATOM_03) { - $dateCreated = $this->_xpath->evaluate('string(' . $this->getXpathPrefix() . '/atom:created)'); + if ($this->_getAtomType() === Zend_Feed_Reader::TYPE_ATOM_03) { + $dateCreated = $this->getXpath()->evaluate('string(' . $this->getXpathPrefix() . '/atom:created)'); } else { - $dateCreated = $this->_xpath->evaluate('string(' . $this->getXpathPrefix() . '/atom:published)'); + $dateCreated = $this->getXpath()->evaluate('string(' . $this->getXpathPrefix() . '/atom:published)'); } if ($dateCreated) { @@ -174,10 +229,10 @@ class Zend_Feed_Reader_Extension_Atom_Entry $date = null; - if ($this->getType() === Zend_Feed_Reader::TYPE_ATOM_03) { - $dateModified = $this->_xpath->evaluate('string(' . $this->getXpathPrefix() . '/atom:modified)'); + if ($this->_getAtomType() === Zend_Feed_Reader::TYPE_ATOM_03) { + $dateModified = $this->getXpath()->evaluate('string(' . $this->getXpathPrefix() . '/atom:modified)'); } else { - $dateModified = $this->_xpath->evaluate('string(' . $this->getXpathPrefix() . '/atom:updated)'); + $dateModified = $this->getXpath()->evaluate('string(' . $this->getXpathPrefix() . '/atom:updated)'); } if ($dateModified) { @@ -201,7 +256,7 @@ class Zend_Feed_Reader_Extension_Atom_Entry return $this->_data['description']; } - $description = $this->_xpath->evaluate('string(' . $this->getXpathPrefix() . '/atom:summary)'); + $description = $this->getXpath()->evaluate('string(' . $this->getXpathPrefix() . '/atom:summary)'); if (!$description) { $description = null; @@ -227,7 +282,7 @@ class Zend_Feed_Reader_Extension_Atom_Entry $enclosure = null; - $nodeList = $this->_xpath->query($this->getXpathPrefix() . '/atom:link[@rel="enclosure"]'); + $nodeList = $this->getXpath()->query($this->getXpathPrefix() . '/atom:link[@rel="enclosure"]'); if ($nodeList->length > 0) { $enclosure = new stdClass(); @@ -252,7 +307,7 @@ class Zend_Feed_Reader_Extension_Atom_Entry return $this->_data['id']; } - $id = $this->_xpath->evaluate('string(' . $this->getXpathPrefix() . '/atom:id)'); + $id = $this->getXpath()->evaluate('string(' . $this->getXpathPrefix() . '/atom:id)'); if (!$id) { if ($this->getPermalink()) { @@ -280,12 +335,12 @@ class Zend_Feed_Reader_Extension_Atom_Entry return $this->_data['baseUrl']; } - $baseUrl = $this->_xpath->evaluate('string(' + $baseUrl = $this->getXpath()->evaluate('string(' . $this->getXpathPrefix() . '/@xml:base[1]' . ')'); if (!$baseUrl) { - $baseUrl = $this->_xpath->evaluate('string(//@xml:base[1])'); + $baseUrl = $this->getXpath()->evaluate('string(//@xml:base[1])'); } if (!$baseUrl) { @@ -329,7 +384,7 @@ class Zend_Feed_Reader_Extension_Atom_Entry $links = array(); - $list = $this->_xpath->query( + $list = $this->getXpath()->query( $this->getXpathPrefix() . '//atom:link[@rel="alternate"]/@href' . '|' . $this->getXpathPrefix() . '//atom:link[not(@rel)]/@href' ); @@ -366,7 +421,7 @@ class Zend_Feed_Reader_Extension_Atom_Entry return $this->_data['title']; } - $title = $this->_xpath->evaluate('string(' . $this->getXpathPrefix() . '/atom:title)'); + $title = $this->getXpath()->evaluate('string(' . $this->getXpathPrefix() . '/atom:title)'); if (!$title) { $title = null; @@ -392,8 +447,8 @@ class Zend_Feed_Reader_Extension_Atom_Entry $count = null; - $this->_xpath->registerNamespace('thread10', 'http://purl.org/syndication/thread/1.0'); - $list = $this->_xpath->query( + $this->getXpath()->registerNamespace('thread10', 'http://purl.org/syndication/thread/1.0'); + $list = $this->getXpath()->query( $this->getXpathPrefix() . '//atom:link[@rel="replies"]/@thread10:count' ); @@ -419,7 +474,7 @@ class Zend_Feed_Reader_Extension_Atom_Entry $link = null; - $list = $this->_xpath->query( + $list = $this->getXpath()->query( $this->getXpathPrefix() . '//atom:link[@rel="replies" and @type="text/html"]/@href' ); @@ -446,7 +501,7 @@ class Zend_Feed_Reader_Extension_Atom_Entry $link = null; - $list = $this->_xpath->query( + $list = $this->getXpath()->query( $this->getXpathPrefix() . '//atom:link[@rel="replies" and @type="application/'.$type.'+xml"]/@href' ); @@ -459,6 +514,72 @@ class Zend_Feed_Reader_Extension_Atom_Entry return $this->_data['commentfeedlink']; } + + /** + * Get all categories + * + * @return Zend_Feed_Reader_Collection_Category + */ + public function getCategories() + { + if (array_key_exists('categories', $this->_data)) { + return $this->_data['categories']; + } + + if ($this->_getAtomType() == Zend_Feed_Reader::TYPE_ATOM_10) { + $list = $this->getXpath()->query($this->getXpathPrefix() . '//atom:category'); + } else { + /** + * Since Atom 0.3 did not support categories, it would have used the + * Dublin Core extension. However there is a small possibility Atom 0.3 + * may have been retrofittied to use Atom 1.0 instead. + */ + $this->getXpath()->registerNamespace('atom10', Zend_Feed_Reader::NAMESPACE_ATOM_10); + $list = $this->getXpath()->query($this->getXpathPrefix() . '//atom10:category'); + } + + if ($list->length) { + $categoryCollection = new Zend_Feed_Reader_Collection_Category; + foreach ($list as $category) { + $categoryCollection[] = array( + 'term' => $category->getAttribute('term'), + 'scheme' => $category->getAttribute('scheme'), + 'label' => html_entity_decode($category->getAttribute('label')) + ); + } + } else { + return new Zend_Feed_Reader_Collection_Category; + } + + $this->_data['categories'] = $categoryCollection; + + return $this->_data['categories']; + } + + /** + * Get source feed metadata from the entry + * + * @return Zend_Feed_Reader_Feed_Atom_Source|null + */ + public function getSource() + { + 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) { + $list = $this->getXpath()->query($this->getXpathPrefix() . '/atom:source[1]'); + if ($list->length) { + $element = $list->item(0); + $source = new Zend_Feed_Reader_Feed_Atom_Source($element, $this->getXpathPrefix()); + } + } + + $this->_data['source'] = $source; + return $this->_data['source']; + } /** * Attempt to absolutise the URI, i.e. if a relative URI apply the @@ -485,35 +606,28 @@ class Zend_Feed_Reader_Extension_Atom_Entry */ protected function _getAuthor(DOMElement $element) { - $email = null; - $name = null; - $uri = null; + $author = array(); $emailNode = $element->getElementsByTagName('email'); $nameNode = $element->getElementsByTagName('name'); $uriNode = $element->getElementsByTagName('uri'); - - if ($emailNode->length) { - $email = $emailNode->item(0)->nodeValue; + + if ($emailNode->length && strlen($emailNode->item(0)->nodeValue) > 0) { + $author['email'] = $emailNode->item(0)->nodeValue; } - if ($nameNode->length) { - $name = $nameNode->item(0)->nodeValue; + if ($nameNode->length && strlen($nameNode->item(0)->nodeValue) > 0) { + $author['name'] = $nameNode->item(0)->nodeValue; } - if ($uriNode->length) { - $uri = $uriNode->item(0)->nodeValue; + if ($uriNode->length && strlen($uriNode->item(0)->nodeValue) > 0) { + $author['uri'] = $uriNode->item(0)->nodeValue; } - if (!empty($email)) { - return $email . (empty($name) ? '' : ' (' . $name . ')'); - } else if (!empty($name)) { - return $name; - } else if (!empty($uri)) { - return $uri; + if (empty($author)) { + return null; } - - return null; + return $author; } /** @@ -521,18 +635,12 @@ class Zend_Feed_Reader_Extension_Atom_Entry */ protected function _registerNamespaces() { - if ($this->getType() == Zend_Feed_Reader::TYPE_ATOM_10 - || $this->getType() == Zend_Feed_Reader::TYPE_ATOM_03 - ) { - return; // pre-registered at Feed level - } - $atomDetected = $this->_getAtomType(); - switch ($atomDetected) { + switch ($this->_getAtomType()) { case Zend_Feed_Reader::TYPE_ATOM_03: - $this->_xpath->registerNamespace('atom', Zend_Feed_Reader::NAMESPACE_ATOM_03); + $this->getXpath()->registerNamespace('atom', Zend_Feed_Reader::NAMESPACE_ATOM_03); break; default: - $this->_xpath->registerNamespace('atom', Zend_Feed_Reader::NAMESPACE_ATOM_10); + $this->getXpath()->registerNamespace('atom', Zend_Feed_Reader::NAMESPACE_ATOM_10); break; } } @@ -542,17 +650,16 @@ class Zend_Feed_Reader_Extension_Atom_Entry */ protected function _getAtomType() { - $nslist = $this->getDomDocument()->documentElement->attributes; - if (!$nslist->length) { - return null; - } - foreach ($nslist as $ns) { - if ($ns->value == Zend_Feed_Reader::NAMESPACE_ATOM_10) { - return Zend_Feed_Reader::TYPE_ATOM_10; - } - if ($ns->value == Zend_Feed_Reader::NAMESPACE_ATOM_03) { - return Zend_Feed_Reader::TYPE_ATOM_03; - } + $dom = $this->getDomDocument(); + $prefixAtom03 = $dom->lookupPrefix(Zend_Feed_Reader::NAMESPACE_ATOM_03); + $prefixAtom10 = $dom->lookupPrefix(Zend_Feed_Reader::NAMESPACE_ATOM_10); + if ($dom->isDefaultNamespace(Zend_Feed_Reader::NAMESPACE_ATOM_03) + || !empty($prefixAtom03)) { + return Zend_Feed_Reader::TYPE_ATOM_03; + } + if ($dom->isDefaultNamespace(Zend_Feed_Reader::NAMESPACE_ATOM_10) + || !empty($prefixAtom10)) { + return Zend_Feed_Reader::TYPE_ATOM_10; } } } diff --git a/libs/Zend/Feed/Reader/Extension/Atom/Feed.php b/libs/Zend/Feed/Reader/Extension/Atom/Feed.php index 42d619fd08..502e9a9c1e 100644 --- a/libs/Zend/Feed/Reader/Extension/Atom/Feed.php +++ b/libs/Zend/Feed/Reader/Extension/Atom/Feed.php @@ -14,9 +14,9 @@ * * @category Zend * @package Zend_Feed_Reader - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 18951 2009-11-12 16:26:19Z alexander $ + * @version $Id: Feed.php 20096 2010-01-06 02:05:09Z bkarwin $ */ /** @@ -35,9 +35,14 @@ require_once 'Zend/Date.php'; require_once 'Zend/Uri.php'; /** + * @see Zend_Feed_Reader_Collection_Author + */ +require_once 'Zend/Feed/Reader/Collection/Author.php'; + +/** * @category Zend * @package Zend_Feed_Reader - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Feed_Reader_Extension_Atom_Feed @@ -71,38 +76,28 @@ class Zend_Feed_Reader_Extension_Atom_Feed return $this->_data['authors']; } - $authors = $this->_xpath->query('//atom:author'); - $contributors = $this->_xpath->query('//atom:contributor'); + $list = $this->_xpath->query('//atom:author'); - $people = array(); + $authors = array(); - if ($authors->length) { - foreach ($authors as $author) { + if ($list->length) { + foreach ($list as $author) { $author = $this->_getAuthor($author); - if (!empty($author)) { - $people[] = $author; - } - } - } - - if ($contributors->length) { - foreach ($contributors as $contributor) { - $contributor = $this->_getAuthor($contributor); - - if (!empty($contributor)) { - $people[] = $contributor; + $authors[] = $author; } } } - if (empty($people)) { - $people = null; + if (count($authors) == 0) { + $authors = null; } else { - $people = array_unique($people); + $authors = new Zend_Feed_Reader_Collection_Author( + Zend_Feed_Reader::arrayUnique($authors) + ); } - $this->_data['authors'] = $people; + $this->_data['authors'] = $authors; return $this->_data['authors']; } @@ -369,6 +364,34 @@ class Zend_Feed_Reader_Extension_Atom_Feed } /** + * Get an array of any supported Pusubhubbub endpoints + * + * @return array|null + */ + public function getHubs() + { + if (array_key_exists('hubs', $this->_data)) { + return $this->_data['hubs']; + } + $hubs = array(); + + $list = $this->_xpath->query($this->getXpathPrefix() + . '//atom:link[@rel="hub"]/@href'); + + if ($list->length) { + foreach ($list as $uri) { + $hubs[] = $this->_absolutiseUri($uri->nodeValue); + } + } else { + $hubs = null; + } + + $this->_data['hubs'] = $hubs; + + return $this->_data['hubs']; + } + + /** * Get the feed title * * @return string|null @@ -389,6 +412,47 @@ class Zend_Feed_Reader_Extension_Atom_Feed return $this->_data['title']; } + + /** + * Get all categories + * + * @return Zend_Feed_Reader_Collection_Category + */ + public function getCategories() + { + if (array_key_exists('categories', $this->_data)) { + return $this->_data['categories']; + } + + if ($this->getType() == Zend_Feed_Reader::TYPE_ATOM_10) { + $list = $this->_xpath->query($this->getXpathPrefix() . '/atom:category'); + } else { + /** + * Since Atom 0.3 did not support categories, it would have used the + * Dublin Core extension. However there is a small possibility Atom 0.3 + * may have been retrofittied to use Atom 1.0 instead. + */ + $this->_xpath->registerNamespace('atom10', Zend_Feed_Reader::NAMESPACE_ATOM_10); + $list = $this->_xpath->query($this->getXpathPrefix() . '/atom10:category'); + } + + if ($list->length) { + $categoryCollection = new Zend_Feed_Reader_Collection_Category; + foreach ($list as $category) { + $categoryCollection[] = array( + 'term' => $category->getAttribute('term'), + 'scheme' => $category->getAttribute('scheme'), + 'label' => html_entity_decode($category->getAttribute('label')) + ); + } + } else { + return new Zend_Feed_Reader_Collection_Category; + } + + $this->_data['categories'] = $categoryCollection; + + return $this->_data['categories']; + } /** * Get an author entry in RSS format @@ -398,35 +462,28 @@ class Zend_Feed_Reader_Extension_Atom_Feed */ protected function _getAuthor(DOMElement $element) { - $email = null; - $name = null; - $uri = null; + $author = array(); $emailNode = $element->getElementsByTagName('email'); $nameNode = $element->getElementsByTagName('name'); $uriNode = $element->getElementsByTagName('uri'); - - if ($emailNode->length) { - $email = $emailNode->item(0)->nodeValue; + + if ($emailNode->length && strlen($emailNode->item(0)->nodeValue) > 0) { + $author['email'] = $emailNode->item(0)->nodeValue; } - if ($nameNode->length) { - $name = $nameNode->item(0)->nodeValue; + if ($nameNode->length && strlen($nameNode->item(0)->nodeValue) > 0) { + $author['name'] = $nameNode->item(0)->nodeValue; } - if ($uriNode->length) { - $uri = $uriNode->item(0)->nodeValue; + if ($uriNode->length && strlen($uriNode->item(0)->nodeValue) > 0) { + $author['uri'] = $uriNode->item(0)->nodeValue; } - if (!empty($email)) { - return $email . (empty($name) ? '' : ' (' . $name . ')'); - } else if (!empty($name)) { - return $name; - } else if (!empty($uri)) { - return $uri; + if (empty($author)) { + return null; } - - return null; + return $author; } /** @@ -472,17 +529,16 @@ class Zend_Feed_Reader_Extension_Atom_Feed */ protected function _getAtomType() { - $nslist = $this->getDomDocument()->documentElement->attributes; - if (!$nslist->length) { - return null; - } - foreach ($nslist as $ns) { - if ($ns->value == Zend_Feed_Reader::NAMESPACE_ATOM_10) { - return Zend_Feed_Reader::TYPE_ATOM_10; - } - if ($ns->value == Zend_Feed_Reader::NAMESPACE_ATOM_03) { - return Zend_Feed_Reader::TYPE_ATOM_03; - } + $dom = $this->getDomDocument(); + $prefixAtom03 = $dom->lookupPrefix(Zend_Feed_Reader::NAMESPACE_ATOM_03); + $prefixAtom10 = $dom->lookupPrefix(Zend_Feed_Reader::NAMESPACE_ATOM_10); + if ($dom->isDefaultNamespace(Zend_Feed_Reader::NAMESPACE_ATOM_10) + || !empty($prefixAtom10)) { + return Zend_Feed_Reader::TYPE_ATOM_10; + } + if ($dom->isDefaultNamespace(Zend_Feed_Reader::NAMESPACE_ATOM_03) + || !empty($prefixAtom03)) { + return Zend_Feed_Reader::TYPE_ATOM_03; } } } diff --git a/libs/Zend/Feed/Reader/Extension/Content/Entry.php b/libs/Zend/Feed/Reader/Extension/Content/Entry.php index fa147af3e5..c6375b2244 100644 --- a/libs/Zend/Feed/Reader/Extension/Content/Entry.php +++ b/libs/Zend/Feed/Reader/Extension/Content/Entry.php @@ -14,9 +14,9 @@ * * @category Zend * @package Zend_Feed_Reader - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 18951 2009-11-12 16:26:19Z alexander $ + * @version $Id: Entry.php 20096 2010-01-06 02:05:09Z bkarwin $ */ /** @@ -32,7 +32,7 @@ require_once 'Zend/Feed/Reader/Extension/EntryAbstract.php'; /** * @category Zend * @package Zend_Feed_Reader - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Feed_Reader_Extension_Content_Entry diff --git a/libs/Zend/Feed/Reader/Extension/CreativeCommons/Entry.php b/libs/Zend/Feed/Reader/Extension/CreativeCommons/Entry.php index b9830089d3..9c8cd4da72 100644 --- a/libs/Zend/Feed/Reader/Extension/CreativeCommons/Entry.php +++ b/libs/Zend/Feed/Reader/Extension/CreativeCommons/Entry.php @@ -14,9 +14,9 @@ * * @category Zend * @package Zend_Feed_Reader - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 16971 2009-07-22 18:05:45Z mikaelkael $ + * @version $Id: Entry.php 20096 2010-01-06 02:05:09Z bkarwin $ */ /** @@ -32,7 +32,7 @@ require_once 'Zend/Feed/Reader/Extension/CreativeCommons/Feed.php'; /** * @category Zend * @package Zend_Feed_Reader - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Feed_Reader_Extension_CreativeCommons_Entry extends Zend_Feed_Reader_Extension_EntryAbstract diff --git a/libs/Zend/Feed/Reader/Extension/CreativeCommons/Feed.php b/libs/Zend/Feed/Reader/Extension/CreativeCommons/Feed.php index 20dfe6e2d4..4b1c7a9fbe 100644 --- a/libs/Zend/Feed/Reader/Extension/CreativeCommons/Feed.php +++ b/libs/Zend/Feed/Reader/Extension/CreativeCommons/Feed.php @@ -14,9 +14,9 @@ * * @category Zend * @package Zend_Feed_Reader - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 18951 2009-11-12 16:26:19Z alexander $ + * @version $Id: Feed.php 20096 2010-01-06 02:05:09Z bkarwin $ */ /** @@ -27,7 +27,7 @@ require_once 'Zend/Feed/Reader/Extension/FeedAbstract.php'; /** * @category Zend * @package Zend_Feed_Reader - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Feed_Reader_Extension_CreativeCommons_Feed diff --git a/libs/Zend/Feed/Reader/Extension/DublinCore/Entry.php b/libs/Zend/Feed/Reader/Extension/DublinCore/Entry.php index b33cac8464..c20394594b 100644 --- a/libs/Zend/Feed/Reader/Extension/DublinCore/Entry.php +++ b/libs/Zend/Feed/Reader/Extension/DublinCore/Entry.php @@ -14,9 +14,9 @@ * * @category Zend * @package Zend_Feed_Reader - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 18951 2009-11-12 16:26:19Z alexander $ + * @version $Id: Entry.php 20096 2010-01-06 02:05:09Z bkarwin $ */ /** @@ -37,7 +37,7 @@ require_once 'Zend/Date.php'; /** * @category Zend * @package Zend_Feed_Reader - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Feed_Reader_Extension_DublinCore_Entry @@ -87,22 +87,56 @@ class Zend_Feed_Reader_Extension_DublinCore_Entry if ($list->length) { foreach ($list as $author) { - if ($this->getType() == Zend_Feed_Reader::TYPE_RSS_20 - && preg_match("/\(([^\)]+)\)/", $author->nodeValue, $matches, PREG_OFFSET_CAPTURE) - ) { - $authors[] = $matches[1][0]; - } else { - $authors[] = $author->nodeValue; - } + $authors[] = array( + 'name' => $author->nodeValue + ); } - - $authors = array_unique($authors); + $authors = new Zend_Feed_Reader_Collection_Author( + Zend_Feed_Reader::arrayUnique($authors) + ); + } else { + $authors = null; } $this->_data['authors'] = $authors; return $this->_data['authors']; } + + /** + * Get categories (subjects under DC) + * + * @return Zend_Feed_Reader_Collection_Category + */ + public function getCategories() + { + 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) { + $categoryCollection[] = array( + 'term' => $category->nodeValue, + 'scheme' => null, + 'label' => $category->nodeValue, + ); + } + } else { + $categoryCollection = new Zend_Feed_Reader_Collection_Category; + } + + $this->_data['categories'] = $categoryCollection; + 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 968e81c5b0..5b7816f54e 100644 --- a/libs/Zend/Feed/Reader/Extension/DublinCore/Feed.php +++ b/libs/Zend/Feed/Reader/Extension/DublinCore/Feed.php @@ -14,9 +14,9 @@ * * @category Zend * @package Zend_Feed_Reader - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 18951 2009-11-12 16:26:19Z alexander $ + * @version $Id: Feed.php 20096 2010-01-06 02:05:09Z bkarwin $ */ /** @@ -30,9 +30,14 @@ require_once 'Zend/Feed/Reader/Extension/FeedAbstract.php'; require_once 'Zend/Date.php'; /** + * @see Zend_Feed_Reader_Collection_Author + */ +require_once 'Zend/Feed/Reader/Collection/Author.php'; + +/** * @category Zend * @package Zend_Feed_Reader - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Feed_Reader_Extension_DublinCore_Feed @@ -79,13 +84,18 @@ class Zend_Feed_Reader_Extension_DublinCore_Feed $list = $this->_xpath->query('//dc10:publisher'); } } - - foreach ($list as $authorObj) { - $authors[] = $authorObj->nodeValue; - } - - if (!empty($authors)) { - $authors = array_unique($authors); + + if ($list->length) { + foreach ($list as $author) { + $authors[] = array( + 'name' => $author->nodeValue + ); + } + $authors = new Zend_Feed_Reader_Collection_Author( + Zend_Feed_Reader::arrayUnique($authors) + ); + } else { + $authors = null; } $this->_data['authors'] = $authors; @@ -251,6 +261,40 @@ class Zend_Feed_Reader_Extension_DublinCore_Feed return $this->_data['date']; } + + /** + * Get categories (subjects under DC) + * + * @return Zend_Feed_Reader_Collection_Category + */ + public function getCategories() + { + 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) { + $categoryCollection[] = array( + 'term' => $category->nodeValue, + 'scheme' => null, + 'label' => $category->nodeValue, + ); + } + } else { + $categoryCollection = new Zend_Feed_Reader_Collection_Category; + } + + $this->_data['categories'] = $categoryCollection; + return $this->_data['categories']; + } /** * Register the default namespaces for the current feed format diff --git a/libs/Zend/Feed/Reader/Extension/EntryAbstract.php b/libs/Zend/Feed/Reader/Extension/EntryAbstract.php index 3c212a8553..299c1bfbaf 100644 --- a/libs/Zend/Feed/Reader/Extension/EntryAbstract.php +++ b/libs/Zend/Feed/Reader/Extension/EntryAbstract.php @@ -14,15 +14,15 @@ * * @category Zend * @package Zend_Feed_Reader - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 18951 2009-11-12 16:26:19Z alexander $ + * @version $Id: EntryAbstract.php 20096 2010-01-06 02:05:09Z bkarwin $ */ /** * @category Zend * @package Zend_Feed_Reader - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Feed_Reader_Extension_EntryAbstract @@ -86,7 +86,7 @@ abstract class Zend_Feed_Reader_Extension_EntryAbstract if (!is_null($type)) { $this->_data['type'] = $type; } else { - $this->_data['type'] = Zend_Feed_Reader::detectType($feed); + $this->_data['type'] = Zend_Feed_Reader::detectType($entry->ownerDocument, true); } // set the XPath query prefix for the entry being queried if ($this->getType() == Zend_Feed_Reader::TYPE_RSS_10 @@ -153,6 +153,9 @@ abstract class Zend_Feed_Reader_Extension_EntryAbstract */ public function getXpath() { + if (!$this->_xpath) { + $this->setXpath(new DOMXPath($this->getDomDocument())); + } return $this->_xpath; } diff --git a/libs/Zend/Feed/Reader/Extension/FeedAbstract.php b/libs/Zend/Feed/Reader/Extension/FeedAbstract.php index 5f4c4fc2ba..73aa8c90ee 100644 --- a/libs/Zend/Feed/Reader/Extension/FeedAbstract.php +++ b/libs/Zend/Feed/Reader/Extension/FeedAbstract.php @@ -14,9 +14,9 @@ * * @category Zend * @package Zend_Feed_Reader - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 18951 2009-11-12 16:26:19Z alexander $ + * @version $Id: FeedAbstract.php 20096 2010-01-06 02:05:09Z bkarwin $ */ /** @@ -38,7 +38,7 @@ require_once 'Zend/Feed/Reader/Entry/Rss.php'; /** * @category Zend * @package Zend_Feed_Reader - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Feed_Reader_Extension_FeedAbstract @@ -139,7 +139,30 @@ abstract class Zend_Feed_Reader_Extension_FeedAbstract return $this->_data; } - /** + /** + * Set the XPath query + * + * @param DOMXPath $xpath + * @return Zend_Feed_Reader_Extension_EntryAbstract + */ + public function setXpath(DOMXPath $xpath) + { + $this->_xpath = $xpath; + $this->_registerNamespaces(); + return $this; + } + + /** + * Get the DOMXPath object + * + * @return string + */ + public function getXpath() + { + return $this->_xpath; + } + + /** * Get the XPath prefix * * @return string diff --git a/libs/Zend/Feed/Reader/Extension/Podcast/Entry.php b/libs/Zend/Feed/Reader/Extension/Podcast/Entry.php index 7af2285421..eeffed2b1f 100644 --- a/libs/Zend/Feed/Reader/Extension/Podcast/Entry.php +++ b/libs/Zend/Feed/Reader/Extension/Podcast/Entry.php @@ -14,9 +14,9 @@ * * @category Zend * @package Zend_Feed_Reader - * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com) + * @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 16792 2009-07-17 02:52:37Z norm2782 $ + * @version $Id: Entry.php 20096 2010-01-06 02:05:09Z bkarwin $ */ /** @@ -32,7 +32,7 @@ require_once 'Zend/Feed/Reader/Extension/EntryAbstract.php'; /** * @category Zend * @package Zend_Feed_Reader - * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Feed_Reader_Extension_Podcast_Entry extends Zend_Feed_Reader_Extension_EntryAbstract diff --git a/libs/Zend/Feed/Reader/Extension/Podcast/Feed.php b/libs/Zend/Feed/Reader/Extension/Podcast/Feed.php index b213d34590..01a5a191db 100644 --- a/libs/Zend/Feed/Reader/Extension/Podcast/Feed.php +++ b/libs/Zend/Feed/Reader/Extension/Podcast/Feed.php @@ -14,9 +14,9 @@ * * @category Zend * @package Zend_Feed_Reader - * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com) + * @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 16792 2009-07-17 02:52:37Z norm2782 $ + * @version $Id: Feed.php 20096 2010-01-06 02:05:09Z bkarwin $ */ /** @@ -27,7 +27,7 @@ require_once 'Zend/Feed/Reader/Extension/FeedAbstract.php'; /** * @category Zend * @package Zend_Feed_Reader - * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Feed_Reader_Extension_Podcast_Feed extends Zend_Feed_Reader_Extension_FeedAbstract diff --git a/libs/Zend/Feed/Reader/Extension/Slash/Entry.php b/libs/Zend/Feed/Reader/Extension/Slash/Entry.php index 0e016e8ead..c5f259fb3c 100644 --- a/libs/Zend/Feed/Reader/Extension/Slash/Entry.php +++ b/libs/Zend/Feed/Reader/Extension/Slash/Entry.php @@ -14,9 +14,9 @@ * * @category Zend * @package Zend_Feed_Reader - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 18951 2009-11-12 16:26:19Z alexander $ + * @version $Id: Entry.php 20096 2010-01-06 02:05:09Z bkarwin $ */ /** @@ -32,7 +32,7 @@ require_once 'Zend/Feed/Reader/Extension/EntryAbstract.php'; /** * @category Zend * @package Zend_Feed_Reader - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Feed_Reader_Extension_Slash_Entry diff --git a/libs/Zend/Feed/Reader/Extension/Syndication/Feed.php b/libs/Zend/Feed/Reader/Extension/Syndication/Feed.php index b708848f5b..9104486520 100644 --- a/libs/Zend/Feed/Reader/Extension/Syndication/Feed.php +++ b/libs/Zend/Feed/Reader/Extension/Syndication/Feed.php @@ -14,9 +14,9 @@ * * @category Zend * @package Zend_Feed_Reader - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 18951 2009-11-12 16:26:19Z alexander $ + * @version $Id: Feed.php 20096 2010-01-06 02:05:09Z bkarwin $ */ /** @@ -29,7 +29,7 @@ require_once 'Zend/Date.php'; /** * @category Zend * @package Zend_Feed_Reader - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Feed_Reader_Extension_Syndication_Feed diff --git a/libs/Zend/Feed/Reader/Extension/Thread/Entry.php b/libs/Zend/Feed/Reader/Extension/Thread/Entry.php index aff20c2a9f..7b397de763 100644 --- a/libs/Zend/Feed/Reader/Extension/Thread/Entry.php +++ b/libs/Zend/Feed/Reader/Extension/Thread/Entry.php @@ -14,9 +14,9 @@ * * @category Zend * @package Zend_Feed_Reader - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 18951 2009-11-12 16:26:19Z alexander $ + * @version $Id: Entry.php 20096 2010-01-06 02:05:09Z bkarwin $ */ /** @@ -27,7 +27,7 @@ require_once 'Zend/Feed/Reader/Extension/EntryAbstract.php'; /** * @category Zend * @package Zend_Feed_Reader - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Feed_Reader_Extension_Thread_Entry diff --git a/libs/Zend/Feed/Reader/Extension/WellFormedWeb/Entry.php b/libs/Zend/Feed/Reader/Extension/WellFormedWeb/Entry.php index 6ba15bc231..24832fee61 100644 --- a/libs/Zend/Feed/Reader/Extension/WellFormedWeb/Entry.php +++ b/libs/Zend/Feed/Reader/Extension/WellFormedWeb/Entry.php @@ -14,9 +14,9 @@ * * @category Zend * @package Zend_Feed_Reader - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 18951 2009-11-12 16:26:19Z alexander $ + * @version $Id: Entry.php 20096 2010-01-06 02:05:09Z bkarwin $ */ /** @@ -32,7 +32,7 @@ require_once 'Zend/Feed/Reader/Extension/EntryAbstract.php'; /** * @category Zend * @package Zend_Feed_Reader - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Feed_Reader_Extension_WellFormedWeb_Entry diff --git a/libs/Zend/Feed/Reader/Feed/Atom.php b/libs/Zend/Feed/Reader/Feed/Atom.php index 19606d0295..fb1e53e218 100644 --- a/libs/Zend/Feed/Reader/Feed/Atom.php +++ b/libs/Zend/Feed/Reader/Feed/Atom.php @@ -14,9 +14,9 @@ * * @category Zend * @package Zend_Feed_Reader - * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com) + * @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 19044 2009-11-19 16:44:24Z padraic $ + * @version $Id: Atom.php 20096 2010-01-06 02:05:09Z bkarwin $ */ /** @@ -32,7 +32,7 @@ require_once 'Zend/Feed/Reader/Extension/Atom/Feed.php'; /** * @category Zend * @package Zend_Feed_Reader - * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Feed_Reader_Feed_Atom extends Zend_Feed_Reader_FeedAbstract @@ -44,11 +44,13 @@ class Zend_Feed_Reader_Feed_Atom extends Zend_Feed_Reader_FeedAbstract * @param DOMDocument $dom * @param string $type */ - public function __construct(DomDocument $dom, $type = null) + public function __construct(DOMDocument $dom, $type = null) { parent::__construct($dom, $type); $atomClass = Zend_Feed_Reader::getPluginLoader()->getClassName('Atom_Feed'); $this->_extensions['Atom_Feed'] = new $atomClass($dom, $this->_data['type'], $this->_xpath); + $atomClass = Zend_Feed_Reader::getPluginLoader()->getClassName('DublinCore_Feed'); + $this->_extensions['DublinCore_Feed'] = new $atomClass($dom, $this->_data['type'], $this->_xpath); foreach ($this->_extensions as $extension) { $extension->setXpathPrefix('/atom:feed'); } @@ -82,9 +84,9 @@ class Zend_Feed_Reader_Feed_Atom extends Zend_Feed_Reader_FeedAbstract return $this->_data['authors']; } - $people = $this->getExtension('Atom')->getAuthors(); + $authors = $this->getExtension('Atom')->getAuthors(); - $this->_data['authors'] = $people; + $this->_data['authors'] = $authors; return $this->_data['authors']; } @@ -312,8 +314,49 @@ class Zend_Feed_Reader_Feed_Atom extends Zend_Feed_Reader_FeedAbstract } /** + * Get an array of any supported Pusubhubbub endpoints + * + * @return array|null + */ + public function getHubs() + { + if (array_key_exists('hubs', $this->_data)) { + return $this->_data['hubs']; + } + + $hubs = $this->getExtension('Atom')->getHubs(); + + $this->_data['hubs'] = $hubs; + + return $this->_data['hubs']; + } + + /** + * Get all categories + * + * @return Zend_Feed_Reader_Collection_Category + */ + public function getCategories() + { + if (array_key_exists('categories', $this->_data)) { + return $this->_data['categories']; + } + + $categoryCollection = $this->getExtension('Atom')->getCategories(); + + if (count($categoryCollection) == 0) { + $categoryCollection = $this->getExtension('DublinCore')->getCategories(); + } + + $this->_data['categories'] = $categoryCollection; + + return $this->_data['categories']; + } + + /** * Read all entries to the internal entries array * + * @return void */ protected function _indexEntries() { diff --git a/libs/Zend/Feed/Reader/Feed/Atom/Source.php b/libs/Zend/Feed/Reader/Feed/Atom/Source.php new file mode 100644 index 0000000000..8d5fe0c94b --- /dev/null +++ b/libs/Zend/Feed/Reader/Feed/Atom/Source.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_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 $ + */ + +/** + * @see Zend_Feed_Reader_Feed_Atom + */ +require_once 'Zend/Feed/Reader/Feed/Atom.php'; + +/** + * @category Zend + * @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 + */ +class Zend_Feed_Reader_Feed_Atom_Source extends Zend_Feed_Reader_Feed_Atom +{ + + /** + * Constructor: Create a Source object which is largely just a normal + * Zend_Feed_Reader_FeedAbstract object only designed to retrieve feed level + * metadata from an Atom entry's source element. + * + * @param DOMElement $source + * @param string $xpathPrefix Passed from parent Entry object + * @param string $type Nearly always Atom 1.0 + */ + public function __construct(DOMElement $source, $xpathPrefix, $type = Zend_Feed_Reader::TYPE_ATOM_10) + { + $this->_domDocument = $source->ownerDocument; + $this->_xpath = new DOMXPath($this->_domDocument); + $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'); + $this->_extensions['DublinCore_Feed'] = new $atomClass($this->_domDocument, $this->_data['type'], $this->_xpath); + foreach ($this->_extensions as $extension) { + $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 + */ + public function count() {} + + /** + * @return void + */ + public function current() {} + + /** + * @return void + */ + public function key() {} + + /** + * @return void + */ + public function next() {} + + /** + * @return void + */ + public function rewind() {} + + /** + * @return void + */ + public function valid() {} + + /** + * @return void + */ + protected function _indexEntries() {} + +} diff --git a/libs/Zend/Feed/Reader/Feed/Rss.php b/libs/Zend/Feed/Reader/Feed/Rss.php index 00b6276eb9..dcb6192608 100644 --- a/libs/Zend/Feed/Reader/Feed/Rss.php +++ b/libs/Zend/Feed/Reader/Feed/Rss.php @@ -14,9 +14,9 @@ * * @category Zend * @package Zend_Feed_Reader - * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com) + * @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 19044 2009-11-19 16:44:24Z padraic $ + * @version $Id: Rss.php 20096 2010-01-06 02:05:09Z bkarwin $ */ /** @@ -40,9 +40,14 @@ require_once 'Zend/Feed/Reader/Extension/DublinCore/Feed.php'; require_once 'Zend/Date.php'; /** + * @see Zend_Feed_Reader_Collection_Author + */ +require_once 'Zend/Feed/Reader/Collection/Author.php'; + +/** * @category Zend * @package Zend_Feed_Reader - * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Feed_Reader_Feed_Rss extends Zend_Feed_Reader_FeedAbstract @@ -100,33 +105,54 @@ class Zend_Feed_Reader_Feed_Rss extends Zend_Feed_Reader_FeedAbstract if (array_key_exists('authors', $this->_data)) { return $this->_data['authors']; } - + $authors = array(); - - if (empty($authors)) { - $authors = $this->getExtension('DublinCore')->getAuthors(); - } - - if (empty($authors)) { - if ($this->getType() !== Zend_Feed_Reader::TYPE_RSS_10 && $this->getType() !== Zend_Feed_Reader::TYPE_RSS_090) { - $list = $this->_xpath->query('//author'); - } else { - $list = $this->_xpath->query('//rss:author'); + $authors_dc = $this->getExtension('DublinCore')->getAuthors(); + if (!empty($authors_dc)) { + foreach ($authors_dc as $author) { + $authors[] = array( + 'name' => $author['name'] + ); } + } - foreach ($list as $authorObj) { - $authors[] = $authorObj->nodeValue; + /** + * Technically RSS doesn't specific author element use at the feed level + * but it's supported on a "just in case" basis. + */ + if ($this->getType() !== Zend_Feed_Reader::TYPE_RSS_10 + && $this->getType() !== Zend_Feed_Reader::TYPE_RSS_090) { + $list = $this->_xpath->query('//author'); + } else { + $list = $this->_xpath->query('//rss:author'); + } + if ($list->length) { + foreach ($list as $author) { + $string = trim($author->nodeValue); + $email = null; + $name = null; + $data = array(); + // Pretty rough parsing - but it's a catchall + if (preg_match("/^.*@[^ ]*/", $string, $matches)) { + $data['email'] = trim($matches[0]); + if (preg_match("/\((.*)\)$/", $string, $matches)) { + $data['name'] = $matches[1]; + } + $authors[] = $data; + } } } - if (empty($authors)) { + if (count($authors) == 0) { $authors = $this->getExtension('Atom')->getAuthors(); + } else { + $authors = new Zend_Feed_Reader_Collection_Author( + Zend_Feed_Reader::arrayUnique($authors) + ); } - if (empty($authors)) { + if (count($authors) == 0) { $authors = null; - } else { - $authors = array_unique($authors); } $this->_data['authors'] = $authors; @@ -213,7 +239,8 @@ class Zend_Feed_Reader_Feed_Rss extends Zend_Feed_Reader_FeedAbstract throw new Zend_Feed_Exception( 'Could not load date due to unrecognised' .' format (should follow RFC 822 or 2822):' - . $e->getMessage() + . $e->getMessage(), + 0, $e ); } } @@ -493,6 +520,70 @@ class Zend_Feed_Reader_Feed_Rss extends Zend_Feed_Reader_FeedAbstract } /** + * Get an array of any supported Pusubhubbub endpoints + * + * @return array|null + */ + public function getHubs() + { + if (array_key_exists('hubs', $this->_data)) { + return $this->_data['hubs']; + } + + $hubs = $this->getExtension('Atom')->getHubs(); + + if (empty($hubs)) { + $hubs = null; + } else { + $hubs = array_unique($hubs); + } + + $this->_data['hubs'] = $hubs; + + return $this->_data['hubs']; + } + + /** + * Get all categories + * + * @return Zend_Feed_Reader_Collection_Category + */ + public function getCategories() + { + if (array_key_exists('categories', $this->_data)) { + return $this->_data['categories']; + } + + if ($this->getType() !== Zend_Feed_Reader::TYPE_RSS_10 && + $this->getType() !== Zend_Feed_Reader::TYPE_RSS_090) { + $list = $this->_xpath->query('/rss/channel//category'); + } else { + $list = $this->_xpath->query('/rdf:RDF/rss:channel//rss:category'); + } + + if ($list->length) { + $categoryCollection = new Zend_Feed_Reader_Collection_Category; + foreach ($list as $category) { + $categoryCollection[] = array( + 'term' => $category->nodeValue, + 'scheme' => $category->getAttribute('domain'), + 'label' => $category->nodeValue, + ); + } + } else { + $categoryCollection = $this->getExtension('DublinCore')->getCategories(); + } + + if (count($categoryCollection) == 0) { + $categoryCollection = $this->getExtension('Atom')->getCategories(); + } + + $this->_data['categories'] = $categoryCollection; + + return $this->_data['categories']; + } + + /** * Read all entries to the internal entries array * */ diff --git a/libs/Zend/Feed/Reader/FeedAbstract.php b/libs/Zend/Feed/Reader/FeedAbstract.php index 30b67b059d..6ec899a726 100644 --- a/libs/Zend/Feed/Reader/FeedAbstract.php +++ b/libs/Zend/Feed/Reader/FeedAbstract.php @@ -14,9 +14,9 @@ * * @category Zend * @package Zend_Feed_Reader - * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com) + * @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 19044 2009-11-19 16:44:24Z padraic $ + * @version $Id: FeedAbstract.php 20096 2010-01-06 02:05:09Z bkarwin $ */ /** @@ -25,17 +25,6 @@ require_once 'Zend/Feed/Reader.php'; /** - * @see Zend_Feed_Reader_Entry_Atom - */ -require_once 'Zend/Feed/Reader/Entry/Atom.php'; - - -/** - * @see Zend_Feed_Reader_Entry_Rss - */ -require_once 'Zend/Feed/Reader/Entry/Rss.php'; - -/** * @see Zend_feed_Reader_FeedInterface */ require_once 'Zend/Feed/Reader/FeedInterface.php'; @@ -43,7 +32,7 @@ require_once 'Zend/Feed/Reader/FeedInterface.php'; /** * @category Zend * @package Zend_Feed_Reader - * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Feed_Reader_FeedAbstract implements Zend_Feed_Reader_FeedInterface @@ -83,6 +72,11 @@ abstract class Zend_Feed_Reader_FeedAbstract implements Zend_Feed_Reader_FeedInt */ protected $_xpath = null; + /** + * Array of loaded extensions + * + * @var array + */ protected $_extensions = array(); /** @@ -228,16 +222,6 @@ abstract class Zend_Feed_Reader_FeedAbstract implements Zend_Feed_Reader_FeedInt } /** - * Return the feed as an array - * - * @return array - */ - public function toArray() // untested - { - return $this->_data; - } - - /** * Check to see if the iterator is still valid * * @return boolean diff --git a/libs/Zend/Feed/Reader/FeedInterface.php b/libs/Zend/Feed/Reader/FeedInterface.php index 3278f3ea75..35060bafce 100644 --- a/libs/Zend/Feed/Reader/FeedInterface.php +++ b/libs/Zend/Feed/Reader/FeedInterface.php @@ -14,15 +14,15 @@ * * @category Zend * @package Zend_Feed_Reader - * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com) + * @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 16953 2009-07-22 11:57:25Z padraic $ + * @version $Id: FeedInterface.php 20096 2010-01-06 02:05:09Z bkarwin $ */ /** * @category Zend * @package Zend_Feed_Reader - * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Feed_Reader_FeedInterface extends Iterator, Countable @@ -111,5 +111,12 @@ interface Zend_Feed_Reader_FeedInterface extends Iterator, Countable * @return string|null */ public function getTitle(); + + /** + * Get all categories + * + * @return Zend_Feed_Reader_Collection_Category + */ + public function getCategories(); } diff --git a/libs/Zend/Feed/Reader/FeedSet.php b/libs/Zend/Feed/Reader/FeedSet.php index e5f4050f1f..3d073c7326 100644 --- a/libs/Zend/Feed/Reader/FeedSet.php +++ b/libs/Zend/Feed/Reader/FeedSet.php @@ -14,9 +14,9 @@ * * @category Zend * @package Zend_Feed_Reader - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 19105 2009-11-20 17:13:54Z padraic $ + * @version $Id: FeedSet.php 20096 2010-01-06 02:05:09Z bkarwin $ */ /** @@ -32,7 +32,7 @@ require_once 'Zend/Uri.php'; /** * @category Zend * @package Zend_Feed_Reader - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Feed_Reader_FeedSet extends ArrayObject diff --git a/libs/Zend/Feed/Rss.php b/libs/Zend/Feed/Rss.php index 03c260ee98..4ff62db357 100644 --- a/libs/Zend/Feed/Rss.php +++ b/libs/Zend/Feed/Rss.php @@ -15,9 +15,9 @@ * * @category Zend * @package Zend_Feed - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 19133 2009-11-20 19:44:09Z padraic $ + * @version $Id: Rss.php 20096 2010-01-06 02:05:09Z bkarwin $ */ @@ -43,7 +43,7 @@ require_once 'Zend/Feed/Entry/Rss.php'; * * @category Zend * @package Zend_Feed - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Feed_Rss extends Zend_Feed_Abstract diff --git a/libs/Zend/Feed/Writer.php b/libs/Zend/Feed/Writer.php new file mode 100644 index 0000000000..8653af8d0e --- /dev/null +++ b/libs/Zend/Feed/Writer.php @@ -0,0 +1,267 @@ +<?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_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 $ + */ + +/** + * @category Zend + * @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 + */ +class Zend_Feed_Writer +{ + /** + * 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'; + const TYPE_ATOM_10 = 'atom-10'; + const TYPE_ATOM_ANY = 'atom'; + const TYPE_RSS_090 = 'rss-090'; + const TYPE_RSS_091 = 'rss-091'; + const TYPE_RSS_091_NETSCAPE = 'rss-091n'; + const TYPE_RSS_091_USERLAND = 'rss-091u'; + const TYPE_RSS_092 = 'rss-092'; + const TYPE_RSS_093 = 'rss-093'; + const TYPE_RSS_094 = 'rss-094'; + const TYPE_RSS_10 = 'rss-10'; + const TYPE_RSS_20 = 'rss-20'; + const TYPE_RSS_ANY = 'rss'; + + /** + * PluginLoader instance used by component + * + * @var Zend_Loader_PluginLoader_Interface + */ + protected static $_pluginLoader = null; + + /** + * Path on which to search for Extension classes + * + * @var array + */ + protected static $_prefixPaths = array(); + + /** + * Array of registered extensions by class postfix (after the base class + * name) across four categories - data containers and renderers for entry + * and feed levels. + * + * @var array + */ + protected static $_extensions = array( + 'entry' => array(), + 'feed' => array(), + 'entryRenderer' => array(), + 'feedRenderer' => array(), + ); + + /** + * Set plugin loader for use with Extensions + * + * @param Zend_Loader_PluginLoader_Interface + */ + public static function setPluginLoader(Zend_Loader_PluginLoader_Interface $loader) + { + self::$_pluginLoader = $loader; + } + + /** + * Get plugin loader for use with Extensions + * + * @return Zend_Loader_PluginLoader_Interface + */ + public static function getPluginLoader() + { + if (!isset(self::$_pluginLoader)) { + require_once 'Zend/Loader/PluginLoader.php'; + self::$_pluginLoader = new Zend_Loader_PluginLoader(array( + 'Zend_Feed_Writer_Extension_' => 'Zend/Feed/Writer/Extension/', + )); + } + return self::$_pluginLoader; + } + + /** + * Add prefix path for loading Extensions + * + * @param string $prefix + * @param string $path + * @return void + */ + public static function addPrefixPath($prefix, $path) + { + $prefix = rtrim($prefix, '_'); + $path = rtrim($path, DIRECTORY_SEPARATOR); + self::getPluginLoader()->addPrefixPath($prefix, $path); + } + + /** + * Add multiple Extension prefix paths at once + * + * @param array $spec + * @return void + */ + public static function addPrefixPaths(array $spec) + { + if (isset($spec['prefix']) && isset($spec['path'])) { + self::addPrefixPath($spec['prefix'], $spec['path']); + } + foreach ($spec as $prefixPath) { + if (isset($prefixPath['prefix']) && isset($prefixPath['path'])) { + self::addPrefixPath($prefixPath['prefix'], $prefixPath['path']); + } + } + } + + /** + * Register an Extension by name + * + * @param string $name + * @return void + * @throws Zend_Feed_Exception if unable to resolve Extension class + */ + public static function registerExtension($name) + { + $feedName = $name . '_Feed'; + $entryName = $name . '_Entry'; + $feedRendererName = $name . '_Renderer_Feed'; + $entryRendererName = $name . '_Renderer_Entry'; + if (self::isRegistered($name)) { + if (self::getPluginLoader()->isLoaded($feedName) + || self::getPluginLoader()->isLoaded($entryName) + || self::getPluginLoader()->isLoaded($feedRendererName) + || self::getPluginLoader()->isLoaded($entryRendererName) + ) { + return; + } + } + try { + self::getPluginLoader()->load($feedName); + self::$_extensions['feed'][] = $feedName; + } catch (Zend_Loader_PluginLoader_Exception $e) { + } + try { + self::getPluginLoader()->load($entryName); + self::$_extensions['entry'][] = $entryName; + } catch (Zend_Loader_PluginLoader_Exception $e) { + } + try { + self::getPluginLoader()->load($feedRendererName); + self::$_extensions['feedRenderer'][] = $feedRendererName; + } catch (Zend_Loader_PluginLoader_Exception $e) { + } + try { + self::getPluginLoader()->load($entryRendererName); + self::$_extensions['entryRenderer'][] = $entryRendererName; + } catch (Zend_Loader_PluginLoader_Exception $e) { + } + if (!self::getPluginLoader()->isLoaded($feedName) + && !self::getPluginLoader()->isLoaded($entryName) + && !self::getPluginLoader()->isLoaded($feedRendererName) + && !self::getPluginLoader()->isLoaded($entryRendererName) + ) { + require_once 'Zend/Feed/Exception.php'; + throw new Zend_Feed_Exception('Could not load extension: ' . $name + . 'using Plugin Loader. Check prefix paths are configured and extension exists.'); + } + } + + /** + * Is a given named Extension registered? + * + * @param string $extensionName + * @return boolean + */ + public static function isRegistered($extensionName) + { + $feedName = $extensionName . '_Feed'; + $entryName = $extensionName . '_Entry'; + $feedRendererName = $extensionName . '_Renderer_Feed'; + $entryRendererName = $extensionName . '_Renderer_Entry'; + if (in_array($feedName, self::$_extensions['feed']) + || in_array($entryName, self::$_extensions['entry']) + || in_array($feedRendererName, self::$_extensions['feedRenderer']) + || in_array($entryRendererName, self::$_extensions['entryRenderer']) + ) { + return true; + } + return false; + } + + /** + * Get a list of extensions + * + * @return array + */ + public static function getExtensions() + { + return self::$_extensions; + } + + /** + * Reset class state to defaults + * + * @return void + */ + public static function reset() + { + self::$_pluginLoader = null; + self::$_prefixPaths = array(); + self::$_extensions = array( + 'entry' => array(), + 'feed' => array(), + 'entryRenderer' => array(), + 'feedRenderer' => array(), + ); + } + + /** + * Register core (default) extensions + * + * @return void + */ + public static function registerCoreExtensions() + { + self::registerExtension('DublinCore'); + self::registerExtension('Content'); + self::registerExtension('Atom'); + self::registerExtension('Slash'); + self::registerExtension('WellFormedWeb'); + self::registerExtension('Threading'); + self::registerExtension('ITunes'); + } + + public static function lcfirst($str) + { + $str[0] = strtolower($str[0]); + return $str; + } + +} diff --git a/libs/Zend/Feed/Writer/Deleted.php b/libs/Zend/Feed/Writer/Deleted.php new file mode 100644 index 0000000000..4f17c9d7ac --- /dev/null +++ b/libs/Zend/Feed/Writer/Deleted.php @@ -0,0 +1,202 @@ +<?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_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 $ + */ + +require_once 'Zend/Feed/Writer/Feed/FeedAbstract.php'; + + /** + * @category Zend + * @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 + */ +class Zend_Feed_Writer_Deleted +{ + + /** + * Internal array containing all data associated with this entry or item. + * + * @var array + */ + protected $_data = array(); + + /** + * Holds the value "atom" or "rss" depending on the feed type set when + * when last exported. + * + * @var string + */ + protected $_type = null; + + /** + * Set the feed character encoding + * + * @return string|null + */ + public function setEncoding($encoding) + { + if (empty($encoding) || !is_string($encoding)) { + require_once 'Zend/Feed/Exception.php'; + throw new Zend_Feed_Exception('Invalid parameter: parameter must be a non-empty string'); + } + $this->_data['encoding'] = $encoding; + } + + /** + * Get the feed character encoding + * + * @return string|null + */ + public function getEncoding() + { + if (!array_key_exists('encoding', $this->_data)) { + return 'UTF-8'; + } + return $this->_data['encoding']; + } + + /** + * Unset a specific data point + * + * @param string $name + */ + public function remove($name) + { + if (isset($this->_data[$name])) { + 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 + * on their appropriateness for the current type, e.g. renderers. + * + * @param string $type + */ + public function setType($type) + { + $this->_type = $type; + } + + /** + * Retrieve the current or last feed type exported. + * + * @return string Value will be "rss" or "atom" + */ + public function getType() + { + return $this->_type; + } + + public function setReference($reference) + { + if (empty($reference) || !is_string($reference)) { + require_once 'Zend/Feed/Exception.php'; + throw new Zend_Feed_Exception('Invalid parameter: reference must be a non-empty string'); + } + $this->_data['reference'] = $reference; + } + + public function getReference() + { + if (!array_key_exists('reference', $this->_data)) { + return null; + } + return $this->_data['reference']; + } + + public function setWhen($date = null) + { + $zdate = null; + if (is_null($date)) { + $zdate = new Zend_Date; + } elseif (ctype_digit($date) && strlen($date) == 10) { + $zdate = new Zend_Date($date, Zend_Date::TIMESTAMP); + } elseif ($date instanceof Zend_Date) { + $zdate = $date; + } else { + require_once 'Zend/Feed/Exception.php'; + throw new Zend_Feed_Exception('Invalid Zend_Date object or UNIX Timestamp passed as parameter'); + } + $this->_data['when'] = $zdate; + } + + public function getWhen() + { + if (!array_key_exists('when', $this->_data)) { + return null; + } + return $this->_data['when']; + } + + public function setBy(array $by) + { + $author = array(); + if (!array_key_exists('name', $by) + || empty($by['name']) + || !is_string($by['name']) + ) { + require_once 'Zend/Feed/Exception.php'; + throw new Zend_Feed_Exception('Invalid parameter: author array must include a "name" key with a non-empty string value'); + } + $author['name'] = $by['name']; + if (isset($by['email'])) { + if (empty($by['email']) || !is_string($by['email'])) { + require_once 'Zend/Feed/Exception.php'; + throw new Zend_Feed_Exception('Invalid parameter: "email" array value must be a non-empty string'); + } + $author['email'] = $by['email']; + } + if (isset($by['uri'])) { + if (empty($by['uri']) + || !is_string($by['uri']) + || !Zend_Uri::check($by['uri']) + ) { + require_once 'Zend/Feed/Exception.php'; + throw new Zend_Feed_Exception('Invalid parameter: "uri" array value must be a non-empty string and valid URI/IRI'); + } + $author['uri'] = $by['uri']; + } + $this->_data['by'] = $author; + } + + public function getBy() + { + if (!array_key_exists('by', $this->_data)) { + return null; + } + return $this->_data['by']; + } + + public function setComment($comment) + { + $this->_data['comment'] = $comment; + } + + public function getComment() + { + if (!array_key_exists('comment', $this->_data)) { + return null; + } + return $this->_data['comment']; + } + +} diff --git a/libs/Zend/Feed/Writer/Entry.php b/libs/Zend/Feed/Writer/Entry.php new file mode 100644 index 0000000000..ff9550b528 --- /dev/null +++ b/libs/Zend/Feed/Writer/Entry.php @@ -0,0 +1,771 @@ +<?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_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 20519 2010-01-22 14:06:24Z padraic $ + */ + +/** + * @see Zend_Date + */ +require_once 'Zend/Date.php'; + +/** + * @see Zend_Date + */ +require_once 'Zend/Uri.php'; + +require_once 'Zend/Feed/Writer/Source.php'; + +/** + * @category Zend + * @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 + */ +class Zend_Feed_Writer_Entry +{ + + /** + * Internal array containing all data associated with this entry or item. + * + * @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. + * + * @var string + */ + protected $_type = null; + + /** + * Constructor: Primarily triggers the registration of core extensions and + * loads those appropriate to this data container. + * + * @return void + */ + public function __construct() + { + Zend_Feed_Writer::registerCoreExtensions(); + $this->_loadExtensions(); + } + + /** + * Set a single author + * + * @param int $index + * @return string|null + */ + public function addAuthor($name, $email = null, $uri = null) + { + $author = array(); + if (is_array($name)) { + if (!array_key_exists('name', $name) + || empty($name['name']) + || !is_string($name['name']) + ) { + require_once 'Zend/Feed/Exception.php'; + throw new Zend_Feed_Exception('Invalid parameter: author array must include a "name" key with a non-empty string value'); + } + $author['name'] = $name['name']; + if (isset($name['email'])) { + if (empty($name['email']) || !is_string($name['email'])) { + require_once 'Zend/Feed/Exception.php'; + throw new Zend_Feed_Exception('Invalid parameter: "email" array value must be a non-empty string'); + } + $author['email'] = $name['email']; + } + if (isset($name['uri'])) { + if (empty($name['uri']) + || !is_string($name['uri']) + || !Zend_Uri::check($name['uri']) + ) { + require_once 'Zend/Feed/Exception.php'; + throw new Zend_Feed_Exception('Invalid parameter: "uri" array value must be a non-empty string and valid URI/IRI'); + } + $author['uri'] = $name['uri']; + } + /** + * @deprecated + * Array notation (above) is preferred and will be the sole supported input from ZF 2.0 + */ + } else { + if (empty($name['name']) || !is_string($name['name'])) { + require_once 'Zend/Feed/Exception.php'; + throw new Zend_Feed_Exception('Invalid parameter: "name" must be a non-empty string value'); + } + $author['name'] = $name; + if (isset($email)) { + if (empty($email) || !is_string($email)) { + require_once 'Zend/Feed/Exception.php'; + throw new Zend_Feed_Exception('Invalid parameter: "email" value must be a non-empty string'); + } + $author['email'] = $email; + } + if (isset($uri)) { + if (empty($uri) || !is_string($uri) || !Zend_Uri::check($uri)) { + require_once 'Zend/Feed/Exception.php'; + throw new Zend_Feed_Exception('Invalid parameter: "uri" value must be a non-empty string and valid URI/IRI'); + } + $author['uri'] = $uri; + } + } + $this->_data['authors'][] = $author; + } + + /** + * Set an array with feed authors + * + * @return array + */ + public function addAuthors(array $authors) + { + foreach($authors as $author) { + $this->addAuthor($author); + } + } + + /** + * Set the feed character encoding + * + * @return string|null + */ + public function setEncoding($encoding) + { + if (empty($encoding) || !is_string($encoding)) { + require_once 'Zend/Feed/Exception.php'; + throw new Zend_Feed_Exception('Invalid parameter: parameter must be a non-empty string'); + } + $this->_data['encoding'] = $encoding; + } + + /** + * Get the feed character encoding + * + * @return string|null + */ + public function getEncoding() + { + if (!array_key_exists('encoding', $this->_data)) { + return 'UTF-8'; + } + return $this->_data['encoding']; + } + + /** + * Set the copyright entry + * + * @return string|null + */ + public function setCopyright($copyright) + { + if (empty($copyright) || !is_string($copyright)) { + require_once 'Zend/Feed/Exception.php'; + throw new Zend_Feed_Exception('Invalid parameter: parameter must be a non-empty string'); + } + $this->_data['copyright'] = $copyright; + } + + /** + * Set the entry's content + * + * @return string|null + */ + public function setContent($content) + { + if (empty($content) || !is_string($content)) { + require_once 'Zend/Feed/Exception.php'; + throw new Zend_Feed_Exception('Invalid parameter: parameter must be a non-empty string'); + } + $this->_data['content'] = $content; + } + + /** + * Set the feed creation date + * + * @return string|null + */ + public function setDateCreated($date = null) + { + $zdate = null; + if (is_null($date)) { + $zdate = new Zend_Date; + } elseif (ctype_digit($date) && strlen($date) == 10) { + $zdate = new Zend_Date($date, Zend_Date::TIMESTAMP); + } elseif ($date instanceof Zend_Date) { + $zdate = $date; + } else { + require_once 'Zend/Feed/Exception.php'; + throw new Zend_Feed_Exception('Invalid Zend_Date object or UNIX Timestamp passed as parameter'); + } + $this->_data['dateCreated'] = $zdate; + } + + /** + * Set the feed modification date + * + * @return string|null + */ + public function setDateModified($date = null) + { + $zdate = null; + if (is_null($date)) { + $zdate = new Zend_Date; + } elseif (ctype_digit($date) && strlen($date) == 10) { + $zdate = new Zend_Date($date, Zend_Date::TIMESTAMP); + } elseif ($date instanceof Zend_Date) { + $zdate = $date; + } else { + require_once 'Zend/Feed/Exception.php'; + throw new Zend_Feed_Exception('Invalid Zend_Date object or UNIX Timestamp passed as parameter'); + } + $this->_data['dateModified'] = $zdate; + } + + /** + * Set the feed description + * + * @return string|null + */ + public function setDescription($description) + { + if (empty($description) || !is_string($description)) { + require_once 'Zend/Feed/Exception.php'; + throw new Zend_Feed_Exception('Invalid parameter: parameter must be a non-empty string'); + } + $this->_data['description'] = $description; + } + + /** + * Set the feed ID + * + * @return string|null + */ + public function setId($id) + { + if (empty($id) || !is_string($id)) { + require_once 'Zend/Feed/Exception.php'; + throw new Zend_Feed_Exception('Invalid parameter: parameter must be a non-empty string'); + } + $this->_data['id'] = $id; + } + + /** + * Set a link to the HTML source of this entry + * + * @return string|null + */ + public function setLink($link) + { + if (empty($link) || !is_string($link) || !Zend_Uri::check($link)) { + require_once 'Zend/Feed/Exception.php'; + throw new Zend_Feed_Exception('Invalid parameter: parameter must be a non-empty string and valid URI/IRI'); + } + $this->_data['link'] = $link; + } + + /** + * Set the number of comments associated with this entry + * + * @return string|null + */ + public function setCommentCount($count) + { + if (empty($count) || !is_numeric($count) || (int) $count < 0) { + require_once 'Zend/Feed/Exception.php'; + throw new Zend_Feed_Exception('Invalid parameter: "count" must be a non-empty integer number'); + } + $this->_data['commentCount'] = (int) $count; + } + + /** + * Set a link to a HTML page containing comments associated with this entry + * + * @return string|null + */ + public function setCommentLink($link) + { + if (empty($link) || !is_string($link) || !Zend_Uri::check($link)) { + require_once 'Zend/Feed/Exception.php'; + throw new Zend_Feed_Exception('Invalid parameter: "link" must be a non-empty string and valid URI/IRI'); + } + $this->_data['commentLink'] = $link; + } + + /** + * Set a link to an XML feed for any comments associated with this entry + * + * @return string|null + */ + public function setCommentFeedLink(array $link) + { + if (!isset($link['uri']) || !is_string($link['uri']) || !Zend_Uri::check($link['uri'])) { + require_once 'Zend/Feed/Exception.php'; + throw new Zend_Feed_Exception('Invalid parameter: "link" must be a non-empty string and valid URI/IRI'); + } + if (!isset($link['type']) || !in_array($link['type'], array('atom', 'rss', 'rdf'))) { + require_once 'Zend/Feed/Exception.php'; + throw new Zend_Feed_Exception('Invalid parameter: "type" must be one' + . ' of "atom", "rss" or "rdf"'); + } + if (!isset($this->_data['commentFeedLinks'])) { + $this->_data['commentFeedLinks'] = array(); + } + $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: + * "atom", "rss" or "rdf". + * + * @return string|null + */ + public function setCommentFeedLinks(array $links) + { + foreach ($links as $link) { + $this->setCommentFeedLink($link); + } + } + + /** + * Set the feed title + * + * @return string|null + */ + public function setTitle($title) + { + if (empty($title) || !is_string($title)) { + require_once 'Zend/Feed/Exception.php'; + throw new Zend_Feed_Exception('Invalid parameter: parameter must be a non-empty string'); + } + $this->_data['title'] = $title; + } + + /** + * Get an array with feed authors + * + * @return array + */ + public function getAuthors() + { + if (!array_key_exists('authors', $this->_data)) { + return null; + } + return $this->_data['authors']; + } + + /** + * Get the entry content + * + * @return string + */ + public function getContent() + { + if (!array_key_exists('content', $this->_data)) { + return null; + } + return $this->_data['content']; + } + + /** + * Get the entry copyright information + * + * @return string + */ + public function getCopyright() + { + if (!array_key_exists('copyright', $this->_data)) { + return null; + } + return $this->_data['copyright']; + } + + /** + * Get the entry creation date + * + * @return string + */ + public function getDateCreated() + { + if (!array_key_exists('dateCreated', $this->_data)) { + return null; + } + return $this->_data['dateCreated']; + } + + /** + * Get the entry modification date + * + * @return string + */ + public function getDateModified() + { + if (!array_key_exists('dateModified', $this->_data)) { + return null; + } + return $this->_data['dateModified']; + } + + /** + * Get the entry description + * + * @return string + */ + public function getDescription() + { + if (!array_key_exists('description', $this->_data)) { + return null; + } + return $this->_data['description']; + } + + /** + * Get the entry ID + * + * @return string + */ + public function getId() + { + if (!array_key_exists('id', $this->_data)) { + return null; + } + return $this->_data['id']; + } + + /** + * Get a link to the HTML source + * + * @return string|null + */ + public function getLink() + { + if (!array_key_exists('link', $this->_data)) { + return null; + } + return $this->_data['link']; + } + + + /** + * Get all links + * + * @return array + */ + public function getLinks() + { + if (!array_key_exists('links', $this->_data)) { + return null; + } + return $this->_data['links']; + } + + /** + * Get the entry title + * + * @return string + */ + public function getTitle() + { + if (!array_key_exists('title', $this->_data)) { + return null; + } + return $this->_data['title']; + } + + /** + * Get the number of comments/replies for current entry + * + * @return integer + */ + public function getCommentCount() + { + if (!array_key_exists('commentCount', $this->_data)) { + return null; + } + return $this->_data['commentCount']; + } + + /** + * Returns a URI pointing to the HTML page where comments can be made on this entry + * + * @return string + */ + public function getCommentLink() + { + if (!array_key_exists('commentLink', $this->_data)) { + return null; + } + return $this->_data['commentLink']; + } + + /** + * Returns an array of URIs pointing to a feed of all comments for this entry + * where the array keys indicate the feed type (atom, rss or rdf). + * + * @return string + */ + public function getCommentFeedLinks() + { + if (!array_key_exists('commentFeedLinks', $this->_data)) { + return null; + } + return $this->_data['commentFeedLinks']; + } + + /** + * Add a entry category + * + * @param string $category + */ + public function addCategory(array $category) + { + if (!isset($category['term'])) { + require_once 'Zend/Feed/Exception.php'; + throw new Zend_Feed_Exception('Each category must be an array and ' + . 'contain at least a "term" element containing the machine ' + . ' readable category name'); + } + if (isset($category['scheme'])) { + if (empty($category['scheme']) + || !is_string($category['scheme']) + || !Zend_Uri::check($category['scheme']) + ) { + require_once 'Zend/Feed/Exception.php'; + throw new Zend_Feed_Exception('The Atom scheme or RSS domain of' + . ' a category must be a valid URI'); + } + } + if (!isset($this->_data['categories'])) { + $this->_data['categories'] = array(); + } + $this->_data['categories'][] = $category; + } + + /** + * Set an array of entry categories + * + * @param array $categories + */ + public function addCategories(array $categories) + { + foreach ($categories as $category) { + $this->addCategory($category); + } + } + + /** + * Get the entry categories + * + * @return string|null + */ + public function getCategories() + { + if (!array_key_exists('categories', $this->_data)) { + return null; + } + return $this->_data['categories']; + } + + /** + * Adds an enclosure to the entry. + * + * @param array $enclosures + */ + public function setEnclosure(array $enclosure) + { + if (!isset($enclosure['type'])) { + require_once 'Zend/Feed/Exception.php'; + throw new Zend_Feed_Exception('Enclosure "type" is not set'); + } + if (!isset($enclosure['length'])) { + require_once 'Zend/Feed/Exception.php'; + throw new Zend_Feed_Exception('Enclosure "length" is not set'); + } + if (!isset($enclosure['uri'])) { + require_once 'Zend/Feed/Exception.php'; + throw new Zend_Feed_Exception('Enclosure "uri" is not set'); + } + if (!Zend_Uri::check($enclosure['uri'])) { + require_once 'Zend/Feed/Exception.php'; + throw new Zend_Feed_Exception('Enclosure "uri" is not a valid URI/IRI'); + } + if ((int) $enclosure['length'] <= 0) { + require_once 'Zend/Feed/Exception.php'; + throw new Zend_Feed_Exception('Enclosure "length" must be an integer' + . ' indicating the content\'s length in bytes'); + } + $this->_data['enclosure'] = $enclosure; + } + + /** + * Retrieve an array of all enclosures to be added to entry. + * + * @return array + */ + public function getEnclosure() + { + if (!array_key_exists('enclosure', $this->_data)) { + return null; + } + return $this->_data['enclosure']; + } + + /** + * Unset a specific data point + * + * @param string $name + */ + public function remove($name) + { + if (isset($this->_data[$name])) { + unset($this->_data[$name]); + } + } + + /** + * Get registered extensions + * + * @return array + */ + public function getExtensions() + { + return $this->_extensions; + } + + /** + * Return an Extension object with the matching name (postfixed with _Entry) + * + * @param string $name + * @return object + */ + public function getExtension($name) + { + if (array_key_exists($name . '_Entry', $this->_extensions)) { + return $this->_extensions[$name . '_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 + * on their appropriateness for the current type, e.g. renderers. + * + * @param string $type + */ + public function setType($type) + { + $this->_type = $type; + } + + /** + * Retrieve the current or last feed type exported. + * + * @return string Value will be "rss" or "atom" + */ + public function getType() + { + return $this->_type; + } + + /** + * Method overloading: call given method on first extension implementing it + * + * @param string $method + * @param array $args + * @return mixed + * @throws Zend_Feed_Exception if no extensions implements the method + */ + public function __call($method, $args) + { + foreach ($this->_extensions as $extension) { + try { + return call_user_func_array(array($extension, $method), $args); + } catch (Zend_Feed_Writer_Exception_InvalidMethodException $e) { + } + } + require_once 'Zend/Feed/Exception.php'; + 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 + * container with some initial values preset based on the current feed data. + * + * @return Zend_Feed_Writer_Source + */ + public function createSource() + { + $source = new Zend_Feed_Writer_Source; + if ($this->getEncoding()) { + $source->setEncoding($this->getEncoding()); + } + $source->setType($this->getType()); + return $source; + } + + /** + * Appends a Zend_Feed_Writer_Entry object representing a new entry/item + * the feed data container's internal group of entries. + * + * @param Zend_Feed_Writer_Source $source + */ + public function setSource(Zend_Feed_Writer_Source $source) + { + $this->_data['source'] = $source; + } + + /** + * @return Zend_Feed_Writer_Source + */ + public function getSource() + { + if (isset($this->_data['source'])) { + return $this->_data['source']; + } + return null; + } + + /** + * Load extensions from Zend_Feed_Writer + * + * @return void + */ + protected function _loadExtensions() + { + $all = Zend_Feed_Writer::getExtensions(); + $exts = $all['entry']; + foreach ($exts as $ext) { + $className = Zend_Feed_Writer::getPluginLoader()->getClassName($ext); + $this->_extensions[$ext] = new $className(); + $this->_extensions[$ext]->setEncoding($this->getEncoding()); + } + } +} diff --git a/libs/Zend/Feed/Writer/Exception/InvalidMethodException.php b/libs/Zend/Feed/Writer/Exception/InvalidMethodException.php new file mode 100644 index 0000000000..f6c4f9331d --- /dev/null +++ b/libs/Zend/Feed/Writer/Exception/InvalidMethodException.php @@ -0,0 +1,41 @@ +<?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_Feed + * @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: InvalidMethodException.php 20096 2010-01-06 02:05:09Z bkarwin $ + */ + + +/** + * @see Zend_Feed_Exception + */ +require_once 'Zend/Feed/Exception.php'; + + +/** + * Feed exceptions + * + * Class to represent exceptions that occur during Feed operations. + * + * @category Zend + * @package Zend_Feed + * @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_Feed_Writer_Exception_InvalidMethodException extends Zend_Exception +{} diff --git a/libs/Zend/Feed/Writer/Extension/Atom/Renderer/Feed.php b/libs/Zend/Feed/Writer/Extension/Atom/Renderer/Feed.php new file mode 100644 index 0000000000..f23901d7e8 --- /dev/null +++ b/libs/Zend/Feed/Writer/Extension/Atom/Renderer/Feed.php @@ -0,0 +1,123 @@ +<?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_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 $ + */ + +/** + * @see Zend_Feed_Writer_Extension_RendererAbstract + */ +require_once 'Zend/Feed/Writer/Extension/RendererAbstract.php'; + +/** + * @category Zend + * @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 + */ +class Zend_Feed_Writer_Extension_Atom_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 + * until an element which requires it is actually appended. + * + * @var bool + */ + protected $_called = false; + + /** + * Render feed + * + * @return void + */ + public function render() + { + /** + * RSS 2.0 only. Used mainly to include Atom links and + * Pubsubhubbub Hub endpoint URIs under the Atom namespace + */ + if (strtolower($this->getType()) == 'atom') { + return; + } + $this->_setFeedLinks($this->_dom, $this->_base); + $this->_setHubs($this->_dom, $this->_base); + if ($this->_called) { + $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'); + } + + /** + * Set feed link elements + * + * @param DOMDocument $dom + * @param DOMElement $root + * @return void + */ + protected function _setFeedLinks(DOMDocument $dom, DOMElement $root) + { + $flinks = $this->getDataContainer()->getFeedLinks(); + if(!$flinks || empty($flinks)) { + return; + } + foreach ($flinks as $type => $href) { + $mime = 'application/' . strtolower($type) . '+xml'; + $flink = $dom->createElement('atom:link'); + $root->appendChild($flink); + $flink->setAttribute('rel', 'self'); + $flink->setAttribute('type', $mime); + $flink->setAttribute('href', $href); + } + $this->_called = true; + } + + /** + * Set PuSH hubs + * + * @param DOMDocument $dom + * @param DOMElement $root + * @return void + */ + protected function _setHubs(DOMDocument $dom, DOMElement $root) + { + $hubs = $this->getDataContainer()->getHubs(); + if (!$hubs || empty($hubs)) { + return; + } + foreach ($hubs as $hubUrl) { + $hub = $dom->createElement('atom:link'); + $hub->setAttribute('rel', 'hub'); + $hub->setAttribute('href', $hubUrl); + $root->appendChild($hub); + } + $this->_called = true; + } +} diff --git a/libs/Zend/Feed/Writer/Extension/Content/Renderer/Entry.php b/libs/Zend/Feed/Writer/Extension/Content/Renderer/Entry.php new file mode 100644 index 0000000000..7960f4cdf3 --- /dev/null +++ b/libs/Zend/Feed/Writer/Extension/Content/Renderer/Entry.php @@ -0,0 +1,92 @@ +<?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_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 $ + */ + +/** + * @see Zend_Feed_Writer_Extension_RendererAbstract + */ +require_once 'Zend/Feed/Writer/Extension/RendererAbstract.php'; + +/** + * @category Zend + * @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 + */ +class Zend_Feed_Writer_Extension_Content_Renderer_Entry + 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 + * until an element which requires it is actually appended. + * + * @var bool + */ + protected $_called = false; + + /** + * Render entry + * + * @return void + */ + public function render() + { + if (strtolower($this->getType()) == 'atom') { + return; + } + $this->_setContent($this->_dom, $this->_base); + if ($this->_called) { + $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/'); + } + + /** + * Set entry content + * + * @param DOMDocument $dom + * @param DOMElement $root + * @return void + */ + protected function _setContent(DOMDocument $dom, DOMElement $root) + { + $content = $this->getDataContainer()->getContent(); + if (!$content) { + return; + } + $element = $dom->createElement('content:encoded'); + $root->appendChild($element); + $cdata = $dom->createCDATASection($content); + $element->appendChild($cdata); + $this->_called = true; + } +} diff --git a/libs/Zend/Feed/Writer/Extension/DublinCore/Renderer/Entry.php b/libs/Zend/Feed/Writer/Extension/DublinCore/Renderer/Entry.php new file mode 100644 index 0000000000..6a72277815 --- /dev/null +++ b/libs/Zend/Feed/Writer/Extension/DublinCore/Renderer/Entry.php @@ -0,0 +1,96 @@ +<?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_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 $ + */ + +/** + * @see Zend_Feed_Writer_Extension_RendererAbstract + */ +require_once 'Zend/Feed/Writer/Extension/RendererAbstract.php'; + +/** + * @category Zend + * @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 + */ +class Zend_Feed_Writer_Extension_DublinCore_Renderer_Entry + 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 + * until an element which requires it is actually appended. + * + * @var bool + */ + protected $_called = false; + + /** + * Render entry + * + * @return void + */ + public function render() + { + if (strtolower($this->getType()) == 'atom') { + return; + } + $this->_setAuthors($this->_dom, $this->_base); + if ($this->_called) { + $this->_appendNamespaces(); + } + } + + /** + * Append namespaces to entry + * + * @return void + */ + protected function _appendNamespaces() + { + $this->getRootElement()->setAttribute('xmlns:dc', + 'http://purl.org/dc/elements/1.1/'); + } + + /** + * Set entry author elements + * + * @param DOMDocument $dom + * @param DOMElement $root + * @return void + */ + protected function _setAuthors(DOMDocument $dom, DOMElement $root) + { + $authors = $this->getDataContainer()->getAuthors(); + if (!$authors || empty($authors)) { + return; + } + foreach ($authors as $data) { + $author = $this->_dom->createElement('dc:creator'); + if (array_key_exists('name', $data)) { + $text = $dom->createTextNode($data['name']); + $author->appendChild($text); + $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 new file mode 100644 index 0000000000..bfa4de49a1 --- /dev/null +++ b/libs/Zend/Feed/Writer/Extension/DublinCore/Renderer/Feed.php @@ -0,0 +1,96 @@ +<?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_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 $ + */ + +/** + * @see Zend_Feed_Writer_Extension_RendererAbstract + */ +require_once 'Zend/Feed/Writer/Extension/RendererAbstract.php'; + +/** + * @category Zend + * @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 + */ +class Zend_Feed_Writer_Extension_DublinCore_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 + * until an element which requires it is actually appended. + * + * @var bool + */ + protected $_called = false; + + /** + * Render feed + * + * @return void + */ + public function render() + { + if (strtolower($this->getType()) == 'atom') { + return; + } + $this->_setAuthors($this->_dom, $this->_base); + if ($this->_called) { + $this->_appendNamespaces(); + } + } + + /** + * Append namespaces to feed element + * + * @return void + */ + protected function _appendNamespaces() + { + $this->getRootElement()->setAttribute('xmlns:dc', + 'http://purl.org/dc/elements/1.1/'); + } + + /** + * Set feed authors + * + * @param DOMDocument $dom + * @param DOMElement $root + * @return void + */ + protected function _setAuthors(DOMDocument $dom, DOMElement $root) + { + $authors = $this->getDataContainer()->getAuthors(); + if (!$authors || empty($authors)) { + return; + } + foreach ($authors as $data) { + $author = $this->_dom->createElement('dc:creator'); + if (array_key_exists('name', $data)) { + $text = $dom->createTextNode($data['name']); + $author->appendChild($text); + $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 new file mode 100644 index 0000000000..49eecb7132 --- /dev/null +++ b/libs/Zend/Feed/Writer/Extension/ITunes/Entry.php @@ -0,0 +1,242 @@ +<?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_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 $ + */ + +/** + * @category Zend + * @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 + */ +class Zend_Feed_Writer_Extension_ITunes_Entry +{ + /** + * Array of Feed data for rendering by Extension's renderers + * + * @var array + */ + protected $_data = array(); + + /** + * Encoding of all text values + * + * @var string + */ + protected $_encoding = 'UTF-8'; + + /** + * Set feed encoding + * + * @param string $enc + * @return Zend_Feed_Writer_Extension_ITunes_Entry + */ + public function setEncoding($enc) + { + $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. + * + * @param string + * @return Zend_Feed_Writer_Extension_ITunes_Entry + */ + public function setItunesBlock($value) + { + if (!ctype_alpha($value) && strlen($value) > 0) { + require_once 'Zend/Feed/Exception.php'; + throw new Zend_Feed_Exception('invalid parameter: "block" may only' + . ' contain alphabetic characters'); + } + if (iconv_strlen($value, $this->getEncoding()) > 255) { + require_once 'Zend/Feed/Exception.php'; + throw new Zend_Feed_Exception('invalid parameter: "block" may only' + . ' contain a maximum of 255 characters'); + } + $this->_data['block'] = $value; + } + + /** + * Add authors to itunes entry + * + * @param array $values + * @return Zend_Feed_Writer_Extension_ITunes_Entry + */ + public function addItunesAuthors(array $values) + { + foreach ($values as $value) { + $this->addItunesAuthor($value); + } + return $this; + } + + /** + * Add author to itunes entry + * + * @param string $value + * @return Zend_Feed_Writer_Extension_ITunes_Entry + */ + public function addItunesAuthor($value) + { + if (iconv_strlen($value, $this->getEncoding()) > 255) { + require_once 'Zend/Feed/Exception.php'; + throw new Zend_Feed_Exception('invalid parameter: any "author" may only' + . ' contain a maximum of 255 characters each'); + } + if (!isset($this->_data['authors'])) { + $this->_data['authors'] = array(); + } + $this->_data['authors'][] = $value; + return $this; + } + + /** + * Set duration + * + * @param int $value + * @return Zend_Feed_Writer_Extension_ITunes_Entry + */ + public function setItunesDuration($value) + { + $value = (string) $value; + if (!ctype_digit($value) + && !preg_match("/^\d+:[0-5]{1}[0-9]{1}$/", $value) + && !preg_match("/^\d+:[0-5]{1}[0-9]{1}:[0-5]{1}[0-9]{1}$/", $value) + ) { + require_once 'Zend/Feed/Exception.php'; + throw new Zend_Feed_Exception('invalid parameter: "duration" may only' + . ' be of a specified [[HH:]MM:]SS format'); + } + $this->_data['duration'] = $value; + return $this; + } + + /** + * Set "explicit" flag + * + * @param bool $value + * @return Zend_Feed_Writer_Extension_ITunes_Entry + */ + public function setItunesExplicit($value) + { + if (!in_array($value, array('yes','no','clean'))) { + require_once 'Zend/Feed/Exception.php'; + throw new Zend_Feed_Exception('invalid parameter: "explicit" may only' + . ' be one of "yes", "no" or "clean"'); + } + $this->_data['explicit'] = $value; + return $this; + } + + /** + * Set keywords + * + * @param array $value + * @return Zend_Feed_Writer_Extension_ITunes_Entry + */ + public function setItunesKeywords(array $value) + { + if (count($value) > 12) { + require_once 'Zend/Feed/Exception.php'; + throw new Zend_Feed_Exception('invalid parameter: "keywords" may only' + . ' contain a maximum of 12 terms'); + } + $concat = implode(',', $value); + if (iconv_strlen($concat, $this->getEncoding()) > 255) { + require_once 'Zend/Feed/Exception.php'; + throw new Zend_Feed_Exception('invalid parameter: "keywords" may only' + . ' have a concatenated length of 255 chars where terms are delimited' + . ' by a comma'); + } + $this->_data['keywords'] = $value; + return $this; + } + + /** + * Set subtitle + * + * @param string $value + * @return Zend_Feed_Writer_Extension_ITunes_Entry + */ + public function setItunesSubtitle($value) + { + if (iconv_strlen($value, $this->getEncoding()) > 255) { + require_once 'Zend/Feed/Exception.php'; + throw new Zend_Feed_Exception('invalid parameter: "subtitle" may only' + . ' contain a maximum of 255 characters'); + } + $this->_data['subtitle'] = $value; + return $this; + } + + /** + * Set summary + * + * @param string $value + * @return Zend_Feed_Writer_Extension_ITunes_Entry + */ + public function setItunesSummary($value) + { + if (iconv_strlen($value, $this->getEncoding()) > 4000) { + require_once 'Zend/Feed/Exception.php'; + throw new Zend_Feed_Exception('invalid parameter: "summary" may only' + . ' contain a maximum of 4000 characters'); + } + $this->_data['summary'] = $value; + return $this; + } + + /** + * Overloading to itunes specific setters + * + * @param string $method + * @param array $params + * @return mixed + */ + public function __call($method, array $params) + { + $point = Zend_Feed_Writer::lcfirst(substr($method, 9)); + if (!method_exists($this, 'setItunes' . ucfirst($point)) + && !method_exists($this, 'addItunes' . ucfirst($point)) + ) { + require_once 'Zend/Feed/Writer/Exception/InvalidMethodException.php'; + throw new Zend_Feed_Writer_Exception_InvalidMethodException( + 'invalid method: ' . $method + ); + } + if (!array_key_exists($point, $this->_data) + || empty($this->_data[$point]) + ) { + return null; + } + return $this->_data[$point]; + } +} diff --git a/libs/Zend/Feed/Writer/Extension/ITunes/Feed.php b/libs/Zend/Feed/Writer/Extension/ITunes/Feed.php new file mode 100644 index 0000000000..565fdc5c78 --- /dev/null +++ b/libs/Zend/Feed/Writer/Extension/ITunes/Feed.php @@ -0,0 +1,361 @@ +<?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_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 $ + */ + +/** + * @category Zend + * @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 + */ +class Zend_Feed_Writer_Extension_ITunes_Feed +{ + /** + * Array of Feed data for rendering by Extension's renderers + * + * @var array + */ + protected $_data = array(); + + /** + * Encoding of all text values + * + * @var string + */ + protected $_encoding = 'UTF-8'; + + /** + * Set feed encoding + * + * @param string $enc + * @return Zend_Feed_Writer_Extension_ITunes_Feed + */ + public function setEncoding($enc) + { + $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. + * + * @param string + * @return Zend_Feed_Writer_Extension_ITunes_Feed + */ + public function setItunesBlock($value) + { + if (!ctype_alpha($value) && strlen($value) > 0) { + require_once 'Zend/Feed/Exception.php'; + throw new Zend_Feed_Exception('invalid parameter: "block" may only' + . ' contain alphabetic characters'); + } + if (iconv_strlen($value, $this->getEncoding()) > 255) { + require_once 'Zend/Feed/Exception.php'; + throw new Zend_Feed_Exception('invalid parameter: "block" may only' + . ' contain a maximum of 255 characters'); + } + $this->_data['block'] = $value; + return $this; + } + + /** + * Add feed authors + * + * @param array $values + * @return Zend_Feed_Writer_Extension_ITunes_Feed + */ + public function addItunesAuthors(array $values) + { + foreach ($values as $value) { + $this->addItunesAuthor($value); + } + return $this; + } + + /** + * Add feed author + * + * @param string $value + * @return Zend_Feed_Writer_Extension_ITunes_Feed + */ + public function addItunesAuthor($value) + { + if (iconv_strlen($value, $this->getEncoding()) > 255) { + require_once 'Zend/Feed/Exception.php'; + throw new Zend_Feed_Exception('invalid parameter: any "author" may only' + . ' contain a maximum of 255 characters each'); + } + if (!isset($this->_data['authors'])) { + $this->_data['authors'] = array(); + } + $this->_data['authors'][] = $value; + return $this; + } + + /** + * Set feed categories + * + * @param array $values + * @return Zend_Feed_Writer_Extension_ITunes_Feed + */ + public function setItunesCategories(array $values) + { + if (!isset($this->_data['categories'])) { + $this->_data['categories'] = array(); + } + foreach ($values as $key=>$value) { + if (!is_array($value)) { + if (iconv_strlen($value, $this->getEncoding()) > 255) { + require_once 'Zend/Feed/Exception.php'; + throw new Zend_Feed_Exception('invalid parameter: any "category" may only' + . ' contain a maximum of 255 characters each'); + } + $this->_data['categories'][] = $value; + } else { + if (iconv_strlen($key, $this->getEncoding()) > 255) { + require_once 'Zend/Feed/Exception.php'; + throw new Zend_Feed_Exception('invalid parameter: any "category" may only' + . ' contain a maximum of 255 characters each'); + } + $this->_data['categories'][$key] = array(); + foreach ($value as $val) { + if (iconv_strlen($val, $this->getEncoding()) > 255) { + require_once 'Zend/Feed/Exception.php'; + throw new Zend_Feed_Exception('invalid parameter: any "category" may only' + . ' contain a maximum of 255 characters each'); + } + $this->_data['categories'][$key][] = $val; + } + } + } + return $this; + } + + /** + * Set feed image (icon) + * + * @param string $value + * @return Zend_Feed_Writer_Extension_ITunes_Feed + */ + public function setItunesImage($value) + { + if (!Zend_Uri::check($value)) { + require_once 'Zend/Feed/Exception.php'; + throw new Zend_Feed_Exception('invalid parameter: "image" may only' + . ' be a valid URI/IRI'); + } + if (!in_array(substr($value, -3), array('jpg','png'))) { + require_once 'Zend/Feed/Exception.php'; + throw new Zend_Feed_Exception('invalid parameter: "image" may only' + . ' use file extension "jpg" or "png" which must be the last three' + . ' characters of the URI (i.e. no query string or fragment)'); + } + $this->_data['image'] = $value; + return $this; + } + + /** + * Set feed cumulative duration + * + * @param string $value + * @return Zend_Feed_Writer_Extension_ITunes_Feed + */ + public function setItunesDuration($value) + { + $value = (string) $value; + if (!ctype_digit($value) + && !preg_match("/^\d+:[0-5]{1}[0-9]{1}$/", $value) + && !preg_match("/^\d+:[0-5]{1}[0-9]{1}:[0-5]{1}[0-9]{1}$/", $value) + ) { + require_once 'Zend/Feed/Exception.php'; + throw new Zend_Feed_Exception('invalid parameter: "duration" may only' + . ' be of a specified [[HH:]MM:]SS format'); + } + $this->_data['duration'] = $value; + return $this; + } + + /** + * Set "explicit" flag + * + * @param bool $value + * @return Zend_Feed_Writer_Extension_ITunes_Feed + */ + public function setItunesExplicit($value) + { + if (!in_array($value, array('yes','no','clean'))) { + require_once 'Zend/Feed/Exception.php'; + throw new Zend_Feed_Exception('invalid parameter: "explicit" may only' + . ' be one of "yes", "no" or "clean"'); + } + $this->_data['explicit'] = $value; + return $this; + } + + /** + * Set feed keywords + * + * @param array $value + * @return Zend_Feed_Writer_Extension_ITunes_Feed + */ + public function setItunesKeywords(array $value) + { + if (count($value) > 12) { + require_once 'Zend/Feed/Exception.php'; + throw new Zend_Feed_Exception('invalid parameter: "keywords" may only' + . ' contain a maximum of 12 terms'); + } + $concat = implode(',', $value); + if (iconv_strlen($concat, $this->getEncoding()) > 255) { + require_once 'Zend/Feed/Exception.php'; + throw new Zend_Feed_Exception('invalid parameter: "keywords" may only' + . ' have a concatenated length of 255 chars where terms are delimited' + . ' by a comma'); + } + $this->_data['keywords'] = $value; + return $this; + } + + /** + * Set new feed URL + * + * @param string $value + * @return Zend_Feed_Writer_Extension_ITunes_Feed + */ + public function setItunesNewFeedUrl($value) + { + if (!Zend_Uri::check($value)) { + require_once 'Zend/Feed/Exception.php'; + throw new Zend_Feed_Exception('invalid parameter: "newFeedUrl" may only' + . ' be a valid URI/IRI'); + } + $this->_data['newFeedUrl'] = $value; + return $this; + } + + /** + * Add feed owners + * + * @param array $values + * @return Zend_Feed_Writer_Extension_ITunes_Feed + */ + public function addItunesOwners(array $values) + { + foreach ($values as $value) { + $this->addItunesOwner($value); + } + return $this; + } + + /** + * Add feed owner + * + * @param string $value + * @return Zend_Feed_Writer_Extension_ITunes_Feed + */ + public function addItunesOwner(array $value) + { + if (!isset($value['name']) || !isset($value['email'])) { + require_once 'Zend/Feed/Exception.php'; + throw new Zend_Feed_Exception('invalid parameter: any "owner" must' + . ' be an array containing keys "name" and "email"'); + } + if (iconv_strlen($value['name'], $this->getEncoding()) > 255 + || iconv_strlen($value['email'], $this->getEncoding()) > 255 + ) { + require_once 'Zend/Feed/Exception.php'; + throw new Zend_Feed_Exception('invalid parameter: any "owner" may only' + . ' contain a maximum of 255 characters each for "name" and "email"'); + } + if (!isset($this->_data['owners'])) { + $this->_data['owners'] = array(); + } + $this->_data['owners'][] = $value; + return $this; + } + + /** + * Set feed subtitle + * + * @param string $value + * @return Zend_Feed_Writer_Extension_ITunes_Feed + */ + public function setItunesSubtitle($value) + { + if (iconv_strlen($value, $this->getEncoding()) > 255) { + require_once 'Zend/Feed/Exception.php'; + throw new Zend_Feed_Exception('invalid parameter: "subtitle" may only' + . ' contain a maximum of 255 characters'); + } + $this->_data['subtitle'] = $value; + return $this; + } + + /** + * Set feed summary + * + * @param string $value + * @return Zend_Feed_Writer_Extension_ITunes_Feed + */ + public function setItunesSummary($value) + { + if (iconv_strlen($value, $this->getEncoding()) > 4000) { + require_once 'Zend/Feed/Exception.php'; + throw new Zend_Feed_Exception('invalid parameter: "summary" may only' + . ' contain a maximum of 4000 characters'); + } + $this->_data['summary'] = $value; + return $this; + } + + /** + * Overloading: proxy to internal setters + * + * @param string $method + * @param array $params + * @return mixed + */ + public function __call($method, array $params) + { + $point = Zend_Feed_Writer::lcfirst(substr($method, 9)); + if (!method_exists($this, 'setItunes' . ucfirst($point)) + && !method_exists($this, 'addItunes' . ucfirst($point)) + ) { + require_once 'Zend/Feed/Writer/Exception/InvalidMethodException.php'; + throw new Zend_Feed_Writer_Exception_InvalidMethodException( + 'invalid method: ' . $method + ); + } + if (!array_key_exists($point, $this->_data) || empty($this->_data[$point])) { + return null; + } + return $this->_data[$point]; + } +} diff --git a/libs/Zend/Feed/Writer/Extension/ITunes/Renderer/Entry.php b/libs/Zend/Feed/Writer/Extension/ITunes/Renderer/Entry.php new file mode 100644 index 0000000000..fc6b98d3ad --- /dev/null +++ b/libs/Zend/Feed/Writer/Extension/ITunes/Renderer/Entry.php @@ -0,0 +1,216 @@ +<?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_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 $ + */ + +/** + * @see Zend_Feed_Writer_Extension_RendererAbstract + */ +require_once 'Zend/Feed/Writer/Extension/RendererAbstract.php'; + +/** + * @category Zend + * @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 + */ +class Zend_Feed_Writer_Extension_ITunes_Renderer_Entry + 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 + * until an element which requires it is actually appended. + * + * @var bool + */ + protected $_called = false; + + /** + * Render entry + * + * @return void + */ + public function render() + { + $this->_setAuthors($this->_dom, $this->_base); + $this->_setBlock($this->_dom, $this->_base); + $this->_setDuration($this->_dom, $this->_base); + $this->_setExplicit($this->_dom, $this->_base); + $this->_setKeywords($this->_dom, $this->_base); + $this->_setSubtitle($this->_dom, $this->_base); + $this->_setSummary($this->_dom, $this->_base); + if ($this->_called) { + $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'); + } + + /** + * Set entry authors + * + * @param DOMDocument $dom + * @param DOMElement $root + * @return void + */ + protected function _setAuthors(DOMDocument $dom, DOMElement $root) + { + $authors = $this->getDataContainer()->getItunesAuthors(); + if (!$authors || empty($authors)) { + return; + } + foreach ($authors as $author) { + $el = $dom->createElement('itunes:author'); + $text = $dom->createTextNode($author); + $el->appendChild($text); + $root->appendChild($el); + $this->_called = true; + } + } + + /** + * Set itunes block + * + * @param DOMDocument $dom + * @param DOMElement $root + * @return void + */ + protected function _setBlock(DOMDocument $dom, DOMElement $root) + { + $block = $this->getDataContainer()->getItunesBlock(); + if (is_null($block)) { + return; + } + $el = $dom->createElement('itunes:block'); + $text = $dom->createTextNode($block); + $el->appendChild($text); + $root->appendChild($el); + $this->_called = true; + } + + /** + * Set entry duration + * + * @param DOMDocument $dom + * @param DOMElement $root + * @return void + */ + protected function _setDuration(DOMDocument $dom, DOMElement $root) + { + $duration = $this->getDataContainer()->getItunesDuration(); + if (!$duration) { + return; + } + $el = $dom->createElement('itunes:duration'); + $text = $dom->createTextNode($duration); + $el->appendChild($text); + $root->appendChild($el); + $this->_called = true; + } + + /** + * Set explicit flag + * + * @param DOMDocument $dom + * @param DOMElement $root + * @return void + */ + protected function _setExplicit(DOMDocument $dom, DOMElement $root) + { + $explicit = $this->getDataContainer()->getItunesExplicit(); + if (is_null($explicit)) { + return; + } + $el = $dom->createElement('itunes:explicit'); + $text = $dom->createTextNode($explicit); + $el->appendChild($text); + $root->appendChild($el); + $this->_called = true; + } + + /** + * Set entry keywords + * + * @param DOMDocument $dom + * @param DOMElement $root + * @return void + */ + protected function _setKeywords(DOMDocument $dom, DOMElement $root) + { + $keywords = $this->getDataContainer()->getItunesKeywords(); + if (!$keywords || empty($keywords)) { + return; + } + $el = $dom->createElement('itunes:keywords'); + $text = $dom->createTextNode(implode(',', $keywords)); + $el->appendChild($text); + $root->appendChild($el); + $this->_called = true; + } + + /** + * Set entry subtitle + * + * @param DOMDocument $dom + * @param DOMElement $root + * @return void + */ + protected function _setSubtitle(DOMDocument $dom, DOMElement $root) + { + $subtitle = $this->getDataContainer()->getItunesSubtitle(); + if (!$subtitle) { + return; + } + $el = $dom->createElement('itunes:subtitle'); + $text = $dom->createTextNode($subtitle); + $el->appendChild($text); + $root->appendChild($el); + $this->_called = true; + } + + /** + * Set entry summary + * + * @param DOMDocument $dom + * @param DOMElement $root + * @return void + */ + protected function _setSummary(DOMDocument $dom, DOMElement $root) + { + $summary = $this->getDataContainer()->getItunesSummary(); + if (!$summary) { + return; + } + $el = $dom->createElement('itunes:summary'); + $text = $dom->createTextNode($summary); + $el->appendChild($text); + $root->appendChild($el); + $this->_called = true; + } +} diff --git a/libs/Zend/Feed/Writer/Extension/ITunes/Renderer/Feed.php b/libs/Zend/Feed/Writer/Extension/ITunes/Renderer/Feed.php new file mode 100644 index 0000000000..1fafdaa13e --- /dev/null +++ b/libs/Zend/Feed/Writer/Extension/ITunes/Renderer/Feed.php @@ -0,0 +1,320 @@ +<?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_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 $ + */ + +/** + * @see Zend_Feed_Writer_Extension_RendererAbstract + */ +require_once 'Zend/Feed/Writer/Extension/RendererAbstract.php'; + +/** + * @category Zend + * @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 + */ +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 + * until an element which requires it is actually appended. + * + * @var bool + */ + protected $_called = false; + + /** + * Render feed + * + * @return void + */ + public function render() + { + $this->_setAuthors($this->_dom, $this->_base); + $this->_setBlock($this->_dom, $this->_base); + $this->_setCategories($this->_dom, $this->_base); + $this->_setImage($this->_dom, $this->_base); + $this->_setDuration($this->_dom, $this->_base); + $this->_setExplicit($this->_dom, $this->_base); + $this->_setKeywords($this->_dom, $this->_base); + $this->_setNewFeedUrl($this->_dom, $this->_base); + $this->_setOwners($this->_dom, $this->_base); + $this->_setSubtitle($this->_dom, $this->_base); + $this->_setSummary($this->_dom, $this->_base); + if ($this->_called) { + $this->_appendNamespaces(); + } + } + + /** + * Append feed namespaces + * + * @return void + */ + protected function _appendNamespaces() + { + $this->getRootElement()->setAttribute('xmlns:itunes', + 'http://www.itunes.com/dtds/podcast-1.0.dtd'); + } + + /** + * Set feed authors + * + * @param DOMDocument $dom + * @param DOMElement $root + * @return void + */ + protected function _setAuthors(DOMDocument $dom, DOMElement $root) + { + $authors = $this->getDataContainer()->getItunesAuthors(); + if (!$authors || empty($authors)) { + return; + } + foreach ($authors as $author) { + $el = $dom->createElement('itunes:author'); + $text = $dom->createTextNode($author); + $el->appendChild($text); + $root->appendChild($el); + } + $this->_called = true; + } + + /** + * Set feed itunes block + * + * @param DOMDocument $dom + * @param DOMElement $root + * @return void + */ + protected function _setBlock(DOMDocument $dom, DOMElement $root) + { + $block = $this->getDataContainer()->getItunesBlock(); + if (is_null($block)) { + return; + } + $el = $dom->createElement('itunes:block'); + $text = $dom->createTextNode($block); + $el->appendChild($text); + $root->appendChild($el); + $this->_called = true; + } + + /** + * Set feed categories + * + * @param DOMDocument $dom + * @param DOMElement $root + * @return void + */ + protected function _setCategories(DOMDocument $dom, DOMElement $root) + { + $cats = $this->getDataContainer()->getItunesCategories(); + if (!$cats || empty($cats)) { + return; + } + foreach ($cats as $key=>$cat) { + if (!is_array($cat)) { + $el = $dom->createElement('itunes:category'); + $el->setAttribute('text', $cat); + $root->appendChild($el); + } else { + $el = $dom->createElement('itunes:category'); + $el->setAttribute('text', $key); + $root->appendChild($el); + foreach ($cat as $subcat) { + $el2 = $dom->createElement('itunes:category'); + $el2->setAttribute('text', $subcat); + $el->appendChild($el2); + } + } + } + $this->_called = true; + } + + /** + * Set feed image (icon) + * + * @param DOMDocument $dom + * @param DOMElement $root + * @return void + */ + protected function _setImage(DOMDocument $dom, DOMElement $root) + { + $image = $this->getDataContainer()->getItunesImage(); + if (!$image) { + return; + } + $el = $dom->createElement('itunes:image'); + $el->setAttribute('href', $image); + $root->appendChild($el); + $this->_called = true; + } + + /** + * Set feed cumulative duration + * + * @param DOMDocument $dom + * @param DOMElement $root + * @return void + */ + protected function _setDuration(DOMDocument $dom, DOMElement $root) + { + $duration = $this->getDataContainer()->getItunesDuration(); + if (!$duration) { + return; + } + $el = $dom->createElement('itunes:duration'); + $text = $dom->createTextNode($duration); + $el->appendChild($text); + $root->appendChild($el); + $this->_called = true; + } + + /** + * Set explicit flag + * + * @param DOMDocument $dom + * @param DOMElement $root + * @return void + */ + protected function _setExplicit(DOMDocument $dom, DOMElement $root) + { + $explicit = $this->getDataContainer()->getItunesExplicit(); + if (is_null($explicit)) { + return; + } + $el = $dom->createElement('itunes:explicit'); + $text = $dom->createTextNode($explicit); + $el->appendChild($text); + $root->appendChild($el); + $this->_called = true; + } + + /** + * Set feed keywords + * + * @param DOMDocument $dom + * @param DOMElement $root + * @return void + */ + protected function _setKeywords(DOMDocument $dom, DOMElement $root) + { + $keywords = $this->getDataContainer()->getItunesKeywords(); + if (!$keywords || empty($keywords)) { + return; + } + $el = $dom->createElement('itunes:keywords'); + $text = $dom->createTextNode(implode(',', $keywords)); + $el->appendChild($text); + $root->appendChild($el); + $this->_called = true; + } + + /** + * Set feed's new URL + * + * @param DOMDocument $dom + * @param DOMElement $root + * @return void + */ + protected function _setNewFeedUrl(DOMDocument $dom, DOMElement $root) + { + $url = $this->getDataContainer()->getItunesNewFeedUrl(); + if (!$url) { + return; + } + $el = $dom->createElement('itunes:new-feed-url'); + $text = $dom->createTextNode($url); + $el->appendChild($text); + $root->appendChild($el); + $this->_called = true; + } + + /** + * Set feed owners + * + * @param DOMDocument $dom + * @param DOMElement $root + * @return void + */ + protected function _setOwners(DOMDocument $dom, DOMElement $root) + { + $owners = $this->getDataContainer()->getItunesOwners(); + if (!$owners || empty($owners)) { + return; + } + foreach ($owners as $owner) { + $el = $dom->createElement('itunes:owner'); + $name = $dom->createElement('itunes:name'); + $text = $dom->createTextNode($owner['name']); + $name->appendChild($text); + $email = $dom->createElement('itunes:email'); + $text = $dom->createTextNode($owner['email']); + $email->appendChild($text); + $root->appendChild($el); + $el->appendChild($name); + $el->appendChild($email); + } + $this->_called = true; + } + + /** + * Set feed subtitle + * + * @param DOMDocument $dom + * @param DOMElement $root + * @return void + */ + protected function _setSubtitle(DOMDocument $dom, DOMElement $root) + { + $subtitle = $this->getDataContainer()->getItunesSubtitle(); + if (!$subtitle) { + return; + } + $el = $dom->createElement('itunes:subtitle'); + $text = $dom->createTextNode($subtitle); + $el->appendChild($text); + $root->appendChild($el); + $this->_called = true; + } + + /** + * Set feed summary + * + * @param DOMDocument $dom + * @param DOMElement $root + * @return void + */ + protected function _setSummary(DOMDocument $dom, DOMElement $root) + { + $summary = $this->getDataContainer()->getItunesSummary(); + if (!$summary) { + return; + } + $el = $dom->createElement('itunes:summary'); + $text = $dom->createTextNode($summary); + $el->appendChild($text); + $root->appendChild($el); + $this->_called = true; + } +} diff --git a/libs/Zend/Feed/Writer/Extension/RendererAbstract.php b/libs/Zend/Feed/Writer/Extension/RendererAbstract.php new file mode 100644 index 0000000000..9a0f93dfeb --- /dev/null +++ b/libs/Zend/Feed/Writer/Extension/RendererAbstract.php @@ -0,0 +1,179 @@ +<?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 padraic dot brady at yahoo dot com so we can send you a copy immediately. + * + * @category Zend + * @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 + */ + +/** + * @see Zend_Feed_Writer_Extension_RendererInterface + */ +require_once 'Zend/Feed/Writer/Extension/RendererInterface.php'; + + /** + * @category Zend + * @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 + */ +abstract class Zend_Feed_Writer_Extension_RendererAbstract + implements Zend_Feed_Writer_Extension_RendererInterface +{ + /** + * @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 + * + * @var string + */ + protected $_encoding = 'UTF-8'; + + /** + * Constructor + * + * @param mixed $container + * @return void + */ + public function __construct($container) + { + $this->_container = $container; + } + + /** + * Set feed encoding + * + * @param string $enc + * @return Zend_Feed_Writer_Extension_RendererAbstract + */ + public function setEncoding($enc) + { + $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 + * @return Zend_Feed_Writer_Extension_RendererAbstract + */ + public function setDomDocument(DOMDocument $dom, DOMElement $base) + { + $this->_dom = $dom; + $this->_base = $base; + return $this; + } + + /** + * Get data container being rendered + * + * @return mixed + */ + public function getDataContainer() + { + return $this->_container; + } + + /** + * Set feed type + * + * @param string $type + * @return Zend_Feed_Writer_Extension_RendererAbstract + */ + public function setType($type) + { + $this->_type = $type; + return $this; + } + + /** + * Get feedtype + * + * @return string + */ + public function getType() + { + return $this->_type; + } + + /** + * Set root element of document + * + * @param DOMElement $root + * @return Zend_Feed_Writer_Extension_RendererAbstract + */ + public function setRootElement(DOMElement $root) + { + $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 new file mode 100644 index 0000000000..e9c9014176 --- /dev/null +++ b/libs/Zend/Feed/Writer/Extension/RendererInterface.php @@ -0,0 +1,59 @@ +<?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 padraic dot brady at yahoo dot com so we can send you a copy immediately. + * + * @category Zend + * @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 + */ + +/** + * @category Zend + * @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 + */ +interface Zend_Feed_Writer_Extension_RendererInterface +{ + /** + * Constructor + * + * @param mixed $container + * @return void + */ + public function __construct($container); + + /** + * Set DOMDocument and DOMElement on which to operate + * + * @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 new file mode 100644 index 0000000000..aae81fbbd4 --- /dev/null +++ b/libs/Zend/Feed/Writer/Extension/Slash/Renderer/Entry.php @@ -0,0 +1,91 @@ +<?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_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 $ + */ + +/** + * @see Zend_Feed_Writer_Extension_RendererAbstract + */ +require_once 'Zend/Feed/Writer/Extension/RendererAbstract.php'; + +/** + * @category Zend + * @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 + */ +class Zend_Feed_Writer_Extension_Slash_Renderer_Entry + 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 + * until an element which requires it is actually appended. + * + * @var bool + */ + protected $_called = false; + + /** + * Render entry + * + * @return void + */ + public function render() + { + if (strtolower($this->getType()) == 'atom') { + return; // RSS 2.0 only + } + $this->_setCommentCount($this->_dom, $this->_base); + if ($this->_called) { + $this->_appendNamespaces(); + } + } + + /** + * Append entry namespaces + * + * @return void + */ + protected function _appendNamespaces() + { + $this->getRootElement()->setAttribute('xmlns:slash', + 'http://purl.org/rss/1.0/modules/slash/'); + } + + /** + * Set entry comment count + * + * @param DOMDocument $dom + * @param DOMElement $root + * @return void + */ + protected function _setCommentCount(DOMDocument $dom, DOMElement $root) + { + $count = $this->getDataContainer()->getCommentCount(); + if (!$count) { + $count = 0; + } + $tcount = $this->_dom->createElement('slash:comments'); + $tcount->nodeValue = $count; + $root->appendChild($tcount); + $this->_called = true; + } +} diff --git a/libs/Zend/Feed/Writer/Extension/Threading/Renderer/Entry.php b/libs/Zend/Feed/Writer/Extension/Threading/Renderer/Entry.php new file mode 100644 index 0000000000..1900ec459f --- /dev/null +++ b/libs/Zend/Feed/Writer/Extension/Threading/Renderer/Entry.php @@ -0,0 +1,145 @@ +<?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_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 $ + */ + +/** + * @see Zend_Feed_Writer_Extension_RendererAbstract + */ +require_once 'Zend/Feed/Writer/Extension/RendererAbstract.php'; + +/** + * @category Zend + * @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 + */ +class Zend_Feed_Writer_Extension_Threading_Renderer_Entry + 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 + * until an element which requires it is actually appended. + * + * @var bool + */ + protected $_called = false; + + /** + * Render entry + * + * @return void + */ + public function render() + { + if (strtolower($this->getType()) == 'rss') { + return; // Atom 1.0 only + } + $this->_setCommentLink($this->_dom, $this->_base); + $this->_setCommentFeedLinks($this->_dom, $this->_base); + $this->_setCommentCount($this->_dom, $this->_base); + if ($this->_called) { + $this->_appendNamespaces(); + } + } + + /** + * Append entry namespaces + * + * @return void + */ + protected function _appendNamespaces() + { + $this->getRootElement()->setAttribute('xmlns:thr', + 'http://purl.org/syndication/thread/1.0'); + } + + /** + * Set comment link + * + * @param DOMDocument $dom + * @param DOMElement $root + * @return void + */ + protected function _setCommentLink(DOMDocument $dom, DOMElement $root) + { + $link = $this->getDataContainer()->getCommentLink(); + if (!$link) { + return; + } + $clink = $this->_dom->createElement('link'); + $clink->setAttribute('rel', 'replies'); + $clink->setAttribute('type', 'text/html'); + $clink->setAttribute('href', $link); + $count = $this->getDataContainer()->getCommentCount(); + if (!is_null($count)) { + $clink->setAttribute('thr:count', $count); + } + $root->appendChild($clink); + $this->_called = true; + } + + /** + * Set comment feed links + * + * @param DOMDocument $dom + * @param DOMElement $root + * @return void + */ + protected function _setCommentFeedLinks(DOMDocument $dom, DOMElement $root) + { + $links = $this->getDataContainer()->getCommentFeedLinks(); + if (!$links || empty($links)) { + return; + } + foreach ($links as $link) { + $flink = $this->_dom->createElement('link'); + $flink->setAttribute('rel', 'replies'); + $flink->setAttribute('type', 'application/'. $link['type'] .'+xml'); + $flink->setAttribute('href', $link['uri']); + $count = $this->getDataContainer()->getCommentCount(); + if (!is_null($count)) { + $flink->setAttribute('thr:count', $count); + } + $root->appendChild($flink); + $this->_called = true; + } + } + + /** + * Set entry comment count + * + * @param DOMDocument $dom + * @param DOMElement $root + * @return void + */ + protected function _setCommentCount(DOMDocument $dom, DOMElement $root) + { + $count = $this->getDataContainer()->getCommentCount(); + if (is_null($count)) { + return; + } + $tcount = $this->_dom->createElement('thr:total'); + $tcount->nodeValue = $count; + $root->appendChild($tcount); + $this->_called = true; + } +} diff --git a/libs/Zend/Feed/Writer/Extension/WellFormedWeb/Renderer/Entry.php b/libs/Zend/Feed/Writer/Extension/WellFormedWeb/Renderer/Entry.php new file mode 100644 index 0000000000..d6a17454d9 --- /dev/null +++ b/libs/Zend/Feed/Writer/Extension/WellFormedWeb/Renderer/Entry.php @@ -0,0 +1,96 @@ +<?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_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 $ + */ + +/** + * @see Zend_Feed_Writer_Extension_RendererAbstract + */ +require_once 'Zend/Feed/Writer/Extension/RendererAbstract.php'; + +/** + * @category Zend + * @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 + */ +class Zend_Feed_Writer_Extension_WellFormedWeb_Renderer_Entry + 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 + * until an element which requires it is actually appended. + * + * @var bool + */ + protected $_called = false; + + /** + * Render entry + * + * @return void + */ + public function render() + { + if (strtolower($this->getType()) == 'atom') { + return; // RSS 2.0 only + } + $this->_setCommentFeedLinks($this->_dom, $this->_base); + if ($this->_called) { + $this->_appendNamespaces(); + } + } + + /** + * Append entry namespaces + * + * @return void + */ + protected function _appendNamespaces() + { + $this->getRootElement()->setAttribute('xmlns:wfw', + 'http://wellformedweb.org/CommentAPI/'); + } + + /** + * Set entry comment feed links + * + * @param DOMDocument $dom + * @param DOMElement $root + * @return void + */ + protected function _setCommentFeedLinks(DOMDocument $dom, DOMElement $root) + { + $links = $this->getDataContainer()->getCommentFeedLinks(); + if (!$links || empty($links)) { + return; + } + foreach ($links as $link) { + if ($link['type'] == 'rss') { + $flink = $this->_dom->createElement('wfw:commentRss'); + $text = $dom->createTextNode($link['uri']); + $flink->appendChild($text); + $root->appendChild($flink); + } + } + $this->_called = true; + } +} diff --git a/libs/Zend/Feed/Writer/Feed.php b/libs/Zend/Feed/Writer/Feed.php new file mode 100644 index 0000000000..dd69dde834 --- /dev/null +++ b/libs/Zend/Feed/Writer/Feed.php @@ -0,0 +1,281 @@ +<?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_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 $ + */ + +/** + * @see Zend_Date + */ +require_once 'Zend/Date.php'; + +/** + * @see Zend_Date + */ +require_once 'Zend/Uri.php'; + +/** + * @see Zend_Feed_Writer + */ +require_once 'Zend/Feed/Writer.php'; + +/** + * @see Zend_Feed_Writer_Entry + */ +require_once 'Zend/Feed/Writer/Entry.php'; + +/** + * @see Zend_Feed_Writer_Deleted + */ +require_once 'Zend/Feed/Writer/Deleted.php'; + +/** + * @see Zend_Feed_Writer_Renderer_Feed_Atom + */ +require_once 'Zend/Feed/Writer/Renderer/Feed/Atom.php'; + +/** + * @see Zend_Feed_Writer_Renderer_Feed_Rss + */ +require_once 'Zend/Feed/Writer/Renderer/Feed/Rss.php'; + +require_once 'Zend/Feed/Writer/Feed/FeedAbstract.php'; + +/** + * @category Zend + * @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 + */ +class Zend_Feed_Writer_Feed extends Zend_Feed_Writer_Feed_FeedAbstract +implements Iterator, Countable +{ + + /** + * Contains all entry objects + * + * @var array + */ + protected $_entries = array(); + + /** + * A pointer for the iterator to keep track of the entries array + * + * @var int + */ + protected $_entriesKey = 0; + + /** + * Creates a new Zend_Feed_Writer_Entry data container for use. This is NOT + * added to the current feed automatically, but is necessary to create a + * container with some initial values preset based on the current feed data. + * + * @return Zend_Feed_Writer_Entry + */ + public function createEntry() + { + $entry = new Zend_Feed_Writer_Entry; + if ($this->getEncoding()) { + $entry->setEncoding($this->getEncoding()); + } + $entry->setType($this->getType()); + return $entry; + } + + /** + * Appends a Zend_Feed_Writer_Deleted object representing a new entry tombstone + * to the feed data container's internal group of entries. + * + * @param Zend_Feed_Writer_Deleted $entry + */ + public function addTombstone(Zend_Feed_Writer_Deleted $deleted) + { + $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 + * container with some initial values preset based on the current feed data. + * + * @return Zend_Feed_Writer_Deleted + */ + public function createTombstone() + { + $deleted = new Zend_Feed_Writer_Deleted; + if ($this->getEncoding()) { + $deleted->setEncoding($this->getEncoding()); + } + $deleted->setType($this->getType()); + return $deleted; + } + + /** + * Appends a Zend_Feed_Writer_Entry object representing a new entry/item + * the feed data container's internal group of entries. + * + * @param Zend_Feed_Writer_Entry $entry + */ + public function addEntry(Zend_Feed_Writer_Entry $entry) + { + $this->_entries[] = $entry; + } + + /** + * Removes a specific indexed entry from the internal queue. Entries must be + * added to a feed container in order to be indexed. + * + * @param int $index + */ + public function removeEntry($index) + { + if (isset($this->_entries[$index])) { + unset($this->_entries[$index]); + } + require_once 'Zend/Feed/Exception.php'; + throw new Zend_Feed_Exception('Undefined index: ' . $index . '. Entry does not exist.'); + } + + /** + * Retrieve a specific indexed entry from the internal queue. Entries must be + * added to a feed container in order to be indexed. + * + * @param int $index + */ + public function getEntry($index = 0) + { + if (isset($this->_entries[$index])) { + return $this->_entries[$index]; + } + require_once 'Zend/Feed/Exception.php'; + throw new Zend_Feed_Exception('Undefined index: ' . $index . '. Entry does not exist.'); + } + + /** + * Orders all indexed entries by date, thus offering date ordered readable + * content where a parser (or Homo Sapien) ignores the generic rule that + * XML element order is irrelevant and has no intrinsic meaning. + * + * Using this method will alter the original indexation. + * + * @return void + */ + public function orderByDate() + { + /** + * Could do with some improvement for performance perhaps + */ + $timestamp = time(); + $entries = array(); + foreach ($this->_entries as $entry) { + if ($entry->getDateModified()) { + $timestamp = (int) $entry->getDateModified()->get(Zend_Date::TIMESTAMP); + } elseif ($entry->getDateCreated()) { + $timestamp = (int) $entry->getDateCreated()->get(Zend_Date::TIMESTAMP); + } + $entries[$timestamp] = $entry; + } + krsort($entries, SORT_NUMERIC); + $this->_entries = array_values($entries); + } + + /** + * Get the number of feed entries. + * Required by the Iterator interface. + * + * @return int + */ + public function count() + { + return count($this->_entries); + } + + /** + * Return the current entry + * + * @return Zend_Feed_Reader_Entry_Interface + */ + public function current() + { + return $this->_entries[$this->key()]; + } + + /** + * Return the current feed key + * + * @return unknown + */ + public function key() + { + return $this->_entriesKey; + } + + /** + * Move the feed pointer forward + * + * @return void + */ + public function next() + { + ++$this->_entriesKey; + } + + /** + * Reset the pointer in the feed object + * + * @return void + */ + public function rewind() + { + $this->_entriesKey = 0; + } + + /** + * Check to see if the iterator is still valid + * + * @return boolean + */ + public function valid() + { + return 0 <= $this->_entriesKey && $this->_entriesKey < $this->count(); + } + + /** + * Attempt to build and return the feed resulting from the data set + * + * @param $type The feed type "rss" or "atom" to export as + * @return string + */ + public function export($type, $ignoreExceptions = false) + { + $this->setType(strtolower($type)); + $type = ucfirst($this->getType()); + if ($type !== 'Rss' && $type !== 'Atom') { + require_once 'Zend/Feed/Exception.php'; + throw new Zend_Feed_Exception('Invalid feed type specified: ' . $type . '.' + . ' Should be one of "rss" or "atom".'); + } + $renderClass = 'Zend_Feed_Writer_Renderer_Feed_' . $type; + $renderer = new $renderClass($this); + if ($ignoreExceptions) { + $renderer->ignoreExceptions(); + } + return $renderer->render()->saveXml(); + } + +} diff --git a/libs/Zend/Feed/Writer/Feed/FeedAbstract.php b/libs/Zend/Feed/Writer/Feed/FeedAbstract.php new file mode 100644 index 0000000000..24fbe73025 --- /dev/null +++ b/libs/Zend/Feed/Writer/Feed/FeedAbstract.php @@ -0,0 +1,716 @@ +<?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_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 $ + */ + +/** + * @see Zend_Date + */ +require_once 'Zend/Date.php'; + +/** + * @see Zend_Date + */ +require_once 'Zend/Uri.php'; + +/** + * @see Zend_Feed_Writer + */ +require_once 'Zend/Feed/Writer.php'; + +/** + * @see Zend_Feed_Writer_Entry + */ +require_once 'Zend/Feed/Writer/Entry.php'; + +/** + * @see Zend_Feed_Writer_Renderer_Feed_Atom + */ +require_once 'Zend/Feed/Writer/Renderer/Feed/Atom.php'; + +/** + * @see Zend_Feed_Writer_Renderer_Feed_Rss + */ +require_once 'Zend/Feed/Writer/Renderer/Feed/Rss.php'; + +/** + * @category Zend + * @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 + */ +class Zend_Feed_Writer_Feed_FeedAbstract +{ + /** + * Contains all Feed level date to append in feed output + * + * @var array + */ + protected $_data = array(); + + /** + * Holds the value "atom" or "rss" depending on the feed type set when + * when last exported. + * + * @var string + */ + protected $_type = null; + + /** + * Constructor: Primarily triggers the registration of core extensions and + * loads those appropriate to this data container. + * + * @return void + */ + public function __construct() + { + Zend_Feed_Writer::registerCoreExtensions(); + $this->_loadExtensions(); + } + + /** + * Set a single author + * + * @param int $index + * @return string|null + */ + public function addAuthor($name, $email = null, $uri = null) + { + $author = array(); + if (is_array($name)) { + if (!array_key_exists('name', $name) || empty($name['name']) || !is_string($name['name'])) { + require_once 'Zend/Feed/Exception.php'; + throw new Zend_Feed_Exception('Invalid parameter: author array must include a "name" key with a non-empty string value'); + } + $author['name'] = $name['name']; + if (isset($name['email'])) { + if (empty($name['email']) || !is_string($name['email'])) { + require_once 'Zend/Feed/Exception.php'; + throw new Zend_Feed_Exception('Invalid parameter: "email" array value must be a non-empty string'); + } + $author['email'] = $name['email']; + } + if (isset($name['uri'])) { + if (empty($name['uri']) || !is_string($name['uri']) || !Zend_Uri::check($name['uri'])) { + require_once 'Zend/Feed/Exception.php'; + throw new Zend_Feed_Exception('Invalid parameter: "uri" array value must be a non-empty string and valid URI/IRI'); + } + $author['uri'] = $name['uri']; + } + } else { + if (empty($name['name']) || !is_string($name['name'])) { + require_once 'Zend/Feed/Exception.php'; + throw new Zend_Feed_Exception('Invalid parameter: "name" must be a non-empty string value'); + } + $author['name'] = $name; + if (isset($email)) { + if (empty($email) || !is_string($email)) { + require_once 'Zend/Feed/Exception.php'; + throw new Zend_Feed_Exception('Invalid parameter: "email" value must be a non-empty string'); + } + $author['email'] = $email; + } + if (isset($uri)) { + if (empty($uri) || !is_string($uri) || !Zend_Uri::check($uri)) { + require_once 'Zend/Feed/Exception.php'; + throw new Zend_Feed_Exception('Invalid parameter: "uri" value must be a non-empty string and valid URI/IRI'); + } + $author['uri'] = $uri; + } + } + $this->_data['authors'][] = $author; + } + + /** + * Set an array with feed authors + * + * @return array + */ + public function addAuthors(array $authors) + { + foreach($authors as $author) { + $this->addAuthor($author); + } + } + + /** + * Set the copyright entry + * + * @return string|null + */ + public function setCopyright($copyright) + { + if (empty($copyright) || !is_string($copyright)) { + require_once 'Zend/Feed/Exception.php'; + throw new Zend_Feed_Exception('Invalid parameter: parameter must be a non-empty string'); + } + $this->_data['copyright'] = $copyright; + } + + /** + * Set the feed creation date + * + * @param null|integer|Zend_Date + */ + public function setDateCreated($date = null) + { + $zdate = null; + if (is_null($date)) { + $zdate = new Zend_Date; + } elseif (ctype_digit($date) && strlen($date) == 10) { + $zdate = new Zend_Date($date, Zend_Date::TIMESTAMP); + } elseif ($date instanceof Zend_Date) { + $zdate = $date; + } else { + require_once 'Zend/Feed/Exception.php'; + throw new Zend_Feed_Exception('Invalid Zend_Date object or UNIX Timestamp passed as parameter'); + } + $this->_data['dateCreated'] = $zdate; + } + + /** + * Set the feed modification date + * + * @param null|integer|Zend_Date + */ + public function setDateModified($date = null) + { + $zdate = null; + if (is_null($date)) { + $zdate = new Zend_Date; + } elseif (ctype_digit($date) && strlen($date) == 10) { + $zdate = new Zend_Date($date, Zend_Date::TIMESTAMP); + } elseif ($date instanceof Zend_Date) { + $zdate = $date; + } else { + require_once 'Zend/Feed/Exception.php'; + throw new Zend_Feed_Exception('Invalid Zend_Date object or UNIX Timestamp passed as parameter'); + } + $this->_data['dateModified'] = $zdate; + } + + /** + * Set the feed description + * + * @return string|null + */ + public function setDescription($description) + { + if (empty($description) || !is_string($description)) { + require_once 'Zend/Feed/Exception.php'; + throw new Zend_Feed_Exception('Invalid parameter: parameter must be a non-empty string'); + } + $this->_data['description'] = $description; + } + + /** + * Set the feed generator entry + * + * @return string|null + */ + public function setGenerator($name, $version = null, $uri = null) + { + if (empty($name) || !is_string($name)) { + require_once 'Zend/Feed/Exception.php'; + throw new Zend_Feed_Exception('Invalid parameter: "name" must be a non-empty string'); + } + $generator = array('name' => $name); + if (isset($version)) { + if (empty($version) || !is_string($version)) { + require_once 'Zend/Feed/Exception.php'; + throw new Zend_Feed_Exception('Invalid parameter: "version" must be a non-empty string'); + } + $generator['version'] = $version; + } + if (isset($uri)) { + if (empty($uri) || !is_string($uri) || !Zend_Uri::check($uri)) { + require_once 'Zend/Feed/Exception.php'; + throw new Zend_Feed_Exception('Invalid parameter: "uri" must be a non-empty string and a valid URI/IRI'); + } + $generator['uri'] = $uri; + } + $this->_data['generator'] = $generator; + } + + /** + * Set the feed ID - URI or URN (via PCRE pattern) supported + * + * @return string|null + */ + 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)) { + require_once 'Zend/Feed/Exception.php'; + throw new Zend_Feed_Exception('Invalid parameter: parameter must be a non-empty string and valid URI/IRI'); + } + $this->_data['id'] = $id; + } + + /** + * Set the feed language + * + * @return string|null + */ + public function setLanguage($language) + { + if (empty($language) || !is_string($language)) { + require_once 'Zend/Feed/Exception.php'; + throw new Zend_Feed_Exception('Invalid parameter: parameter must be a non-empty string'); + } + $this->_data['language'] = $language; + } + + /** + * Set a link to the HTML source + * + * @return string|null + */ + public function setLink($link) + { + if (empty($link) || !is_string($link) || !Zend_Uri::check($link)) { + require_once 'Zend/Feed/Exception.php'; + throw new Zend_Feed_Exception('Invalid parameter: parameter must be a non-empty string and valid URI/IRI'); + } + $this->_data['link'] = $link; + } + + /** + * Set a link to an XML feed for any feed type/version + * + * @return string|null + */ + public function setFeedLink($link, $type) + { + if (empty($link) || !is_string($link) || !Zend_Uri::check($link)) { + require_once 'Zend/Feed/Exception.php'; + throw new Zend_Feed_Exception('Invalid parameter: "link"" must be a non-empty string and valid URI/IRI'); + } + if (!in_array(strtolower($type), array('rss', 'rdf', 'atom'))) { + require_once 'Zend/Feed/Exception.php'; + throw new Zend_Feed_Exception('Invalid parameter: "type"; You must declare the type of feed the link points to, i.e. RSS, RDF or Atom'); + } + $this->_data['feedLinks'][strtolower($type)] = $link; + } + + /** + * Set the feed title + * + * @return string|null + */ + public function setTitle($title) + { + if (empty($title) || !is_string($title)) { + require_once 'Zend/Feed/Exception.php'; + throw new Zend_Feed_Exception('Invalid parameter: parameter must be a non-empty string'); + } + $this->_data['title'] = $title; + } + + /** + * Set the feed character encoding + * + * @param string $encoding + */ + public function setEncoding($encoding) + { + if (empty($encoding) || !is_string($encoding)) { + require_once 'Zend/Feed/Exception.php'; + throw new Zend_Feed_Exception('Invalid parameter: parameter must be a non-empty string'); + } + $this->_data['encoding'] = $encoding; + } + + /** + * Set the feed's base URL + * + * @param string $url + */ + public function setBaseUrl($url) + { + if (empty($url) || !is_string($url) || !Zend_Uri::check($url)) { + require_once 'Zend/Feed/Exception.php'; + throw new Zend_Feed_Exception('Invalid parameter: "url" array value' + . ' must be a non-empty string and valid URI/IRI'); + } + $this->_data['baseUrl'] = $url; + } + + /** + * Add a Pubsubhubbub hub endpoint URL + * + * @param string $url + */ + public function addHub($url) + { + if (empty($url) || !is_string($url) || !Zend_Uri::check($url)) { + require_once 'Zend/Feed/Exception.php'; + throw new Zend_Feed_Exception('Invalid parameter: "url" array value' + . ' must be a non-empty string and valid URI/IRI'); + } + if (!isset($this->_data['hubs'])) { + $this->_data['hubs'] = array(); + } + $this->_data['hubs'][] = $url; + } + + /** + * Add Pubsubhubbub hub endpoint URLs + * + * @param array $urls + */ + public function addHubs(array $urls) + { + foreach ($urls as $url) { + $this->addHub($url); + } + } + + /** + * Add a feed category + * + * @param string $category + */ + public function addCategory(array $category) + { + if (!isset($category['term'])) { + require_once 'Zend/Feed/Exception.php'; + throw new Zend_Feed_Exception('Each category must be an array and ' + . 'contain at least a "term" element containing the machine ' + . ' readable category name'); + } + if (isset($category['scheme'])) { + if (empty($category['scheme']) + || !is_string($category['scheme']) + || !Zend_Uri::check($category['scheme']) + ) { + require_once 'Zend/Feed/Exception.php'; + throw new Zend_Feed_Exception('The Atom scheme or RSS domain of' + . ' a category must be a valid URI'); + } + } + if (!isset($this->_data['categories'])) { + $this->_data['categories'] = array(); + } + $this->_data['categories'][] = $category; + } + + /** + * Set an array of feed categories + * + * @param array $categories + */ + public function addCategories(array $categories) + { + foreach ($categories as $category) { + $this->addCategory($category); + } + } + + /** + * Get a single author + * + * @param int $index + * @return string|null + */ + public function getAuthor($index = 0) + { + if (isset($this->_data['authors'][$index])) { + return $this->_data['authors'][$index]; + } else { + return null; + } + } + + /** + * Get an array with feed authors + * + * @return array + */ + public function getAuthors() + { + if (!array_key_exists('authors', $this->_data)) { + return null; + } + return $this->_data['authors']; + } + + /** + * Get the copyright entry + * + * @return string|null + */ + public function getCopyright() + { + if (!array_key_exists('copyright', $this->_data)) { + return null; + } + return $this->_data['copyright']; + } + + /** + * Get the feed creation date + * + * @return string|null + */ + public function getDateCreated() + { + if (!array_key_exists('dateCreated', $this->_data)) { + return null; + } + return $this->_data['dateCreated']; + } + + /** + * Get the feed modification date + * + * @return string|null + */ + public function getDateModified() + { + if (!array_key_exists('dateModified', $this->_data)) { + return null; + } + return $this->_data['dateModified']; + } + + /** + * Get the feed description + * + * @return string|null + */ + public function getDescription() + { + if (!array_key_exists('description', $this->_data)) { + return null; + } + return $this->_data['description']; + } + + /** + * Get the feed generator entry + * + * @return string|null + */ + public function getGenerator() + { + if (!array_key_exists('generator', $this->_data)) { + return null; + } + return $this->_data['generator']; + } + + /** + * Get the feed ID + * + * @return string|null + */ + public function getId() + { + if (!array_key_exists('id', $this->_data)) { + return null; + } + return $this->_data['id']; + } + + /** + * Get the feed language + * + * @return string|null + */ + public function getLanguage() + { + if (!array_key_exists('language', $this->_data)) { + return null; + } + return $this->_data['language']; + } + + /** + * Get a link to the HTML source + * + * @return string|null + */ + public function getLink() + { + if (!array_key_exists('link', $this->_data)) { + return null; + } + return $this->_data['link']; + } + + /** + * Get a link to the XML feed + * + * @return string|null + */ + public function getFeedLinks() + { + if (!array_key_exists('feedLinks', $this->_data)) { + return null; + } + return $this->_data['feedLinks']; + } + + /** + * Get the feed title + * + * @return string|null + */ + public function getTitle() + { + if (!array_key_exists('title', $this->_data)) { + return null; + } + return $this->_data['title']; + } + + /** + * Get the feed character encoding + * + * @return string|null + */ + public function getEncoding() + { + if (!array_key_exists('encoding', $this->_data)) { + return 'UTF-8'; + } + return $this->_data['encoding']; + } + + /** + * Get the feed's base url + * + * @return string|null + */ + public function getBaseUrl() + { + if (!array_key_exists('baseUrl', $this->_data)) { + return null; + } + return $this->_data['baseUrl']; + } + + /** + * Get the URLs used as Pubsubhubbub hubs endpoints + * + * @return string|null + */ + public function getHubs() + { + if (!array_key_exists('hubs', $this->_data)) { + return null; + } + return $this->_data['hubs']; + } + + /** + * Get the feed categories + * + * @return string|null + */ + public function getCategories() + { + if (!array_key_exists('categories', $this->_data)) { + return null; + } + return $this->_data['categories']; + } + + /** + * Resets the instance and deletes all data + * + * @return void + */ + public function reset() + { + $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 + * on their appropriateness for the current type, e.g. renderers. + * + * @param string $type + */ + public function setType($type) + { + $this->_type = $type; + } + + /** + * Retrieve the current or last feed type exported. + * + * @return string Value will be "rss" or "atom" + */ + public function getType() + { + return $this->_type; + } + + /** + * Unset a specific data point + * + * @param string $name + */ + public function remove($name) + { + if (isset($this->_data[$name])) { + unset($this->_data[$name]); + } + } + + /** + * Method overloading: call given method on first extension implementing it + * + * @param string $method + * @param array $args + * @return mixed + * @throws Zend_Feed_Exception if no extensions implements the method + */ + public function __call($method, $args) + { + foreach ($this->_extensions as $extension) { + try { + return call_user_func_array(array($extension, $method), $args); + } catch (Zend_Feed_Writer_Exception_InvalidMethodException $e) { + } + } + require_once 'Zend/Feed/Exception.php'; + throw new Zend_Feed_Exception('Method: ' . $method + . ' does not exist and could not be located on a registered Extension'); + } + + /** + * Load extensions from Zend_Feed_Writer + * + * @return void + */ + protected function _loadExtensions() + { + $all = Zend_Feed_Writer::getExtensions(); + $exts = $all['feed']; + foreach ($exts as $ext) { + $className = Zend_Feed_Writer::getPluginLoader()->getClassName($ext); + $this->_extensions[$ext] = new $className(); + $this->_extensions[$ext]->setEncoding($this->getEncoding()); + } + } +} diff --git a/libs/Zend/Feed/Writer/Renderer/Entry/Atom.php b/libs/Zend/Feed/Writer/Renderer/Entry/Atom.php new file mode 100644 index 0000000000..b029dede42 --- /dev/null +++ b/libs/Zend/Feed/Writer/Renderer/Entry/Atom.php @@ -0,0 +1,405 @@ +<?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_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 20507 2010-01-21 22:21:07Z padraic $ + */ + +/** + * @see Zend_Feed_Writer_Renderer_RendererAbstract + */ +require_once 'Zend/Feed/Writer/Renderer/RendererAbstract.php'; + +require_once 'Zend/Feed/Writer/Renderer/Feed/Atom/Source.php'; + +/** + * @category Zend + * @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 + */ +class Zend_Feed_Writer_Renderer_Entry_Atom + extends Zend_Feed_Writer_Renderer_RendererAbstract + implements Zend_Feed_Writer_Renderer_RendererInterface +{ + /** + * Constructor + * + * @param Zend_Feed_Writer_Entry $container + * @return void + */ + public function __construct (Zend_Feed_Writer_Entry $container) + { + parent::__construct($container); + } + + /** + * Render atom entry + * + * @return Zend_Feed_Writer_Renderer_Entry_Atom + */ + public function render() + { + $this->_dom = new DOMDocument('1.0', $this->_container->getEncoding()); + $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); + $this->_setDateCreated($this->_dom, $entry); + $this->_setDateModified($this->_dom, $entry); + $this->_setLink($this->_dom, $entry); + $this->_setId($this->_dom, $entry); + $this->_setAuthors($this->_dom, $entry); + $this->_setEnclosure($this->_dom, $entry); + $this->_setContent($this->_dom, $entry); + $this->_setCategories($this->_dom, $entry); + + foreach ($this->_extensions as $ext) { + $ext->setType($this->getType()); + $ext->setRootElement($this->getRootElement()); + $ext->setDomDocument($this->getDomDocument(), $entry); + $ext->render(); + } + + return $this; + } + + /** + * Set entry title + * + * @param DOMDocument $dom + * @param DOMElement $root + * @return void + */ + protected function _setTitle(DOMDocument $dom, DOMElement $root) + { + if(!$this->getDataContainer()->getTitle()) { + require_once 'Zend/Feed/Exception.php'; + $message = 'Atom 1.0 entry elements MUST contain exactly one' + . ' atom:title element but a title has not been set'; + $exception = new Zend_Feed_Exception($message); + if (!$this->_ignoreExceptions) { + throw $exception; + } else { + $this->_exceptions[] = $exception; + return; + } + } + $title = $dom->createElement('title'); + $root->appendChild($title); + $title->setAttribute('type', 'html'); + $cdata = $dom->createCDATASection($this->getDataContainer()->getTitle()); + $title->appendChild($cdata); + } + + /** + * Set entry description + * + * @param DOMDocument $dom + * @param DOMElement $root + * @return void + */ + protected function _setDescription(DOMDocument $dom, DOMElement $root) + { + if(!$this->getDataContainer()->getDescription()) { + return; // unless src content or base64 + } + $subtitle = $dom->createElement('summary'); + $root->appendChild($subtitle); + $subtitle->setAttribute('type', 'html'); + $cdata = $dom->createCDATASection( + $this->getDataContainer()->getDescription() + ); + $subtitle->appendChild($cdata); + } + + /** + * Set date entry was modified + * + * @param DOMDocument $dom + * @param DOMElement $root + * @return void + */ + protected function _setDateModified(DOMDocument $dom, DOMElement $root) + { + if(!$this->getDataContainer()->getDateModified()) { + require_once 'Zend/Feed/Exception.php'; + $message = 'Atom 1.0 entry elements MUST contain exactly one' + . ' atom:updated element but a modification date has not been set'; + $exception = new Zend_Feed_Exception($message); + if (!$this->_ignoreExceptions) { + throw $exception; + } else { + $this->_exceptions[] = $exception; + return; + } + } + + $updated = $dom->createElement('updated'); + $root->appendChild($updated); + $text = $dom->createTextNode( + $this->getDataContainer()->getDateModified()->get(Zend_Date::ISO_8601) + ); + $updated->appendChild($text); + } + + /** + * Set date entry was created + * + * @param DOMDocument $dom + * @param DOMElement $root + * @return void + */ + protected function _setDateCreated(DOMDocument $dom, DOMElement $root) + { + if (!$this->getDataContainer()->getDateCreated()) { + return; + } + $el = $dom->createElement('published'); + $root->appendChild($el); + $text = $dom->createTextNode( + $this->getDataContainer()->getDateCreated()->get(Zend_Date::ISO_8601) + ); + $el->appendChild($text); + } + + /** + * Set entry authors + * + * @param DOMDocument $dom + * @param DOMElement $root + * @return void + */ + protected function _setAuthors(DOMDocument $dom, DOMElement $root) + { + $authors = $this->_container->getAuthors(); + if ((!$authors || empty($authors))) { + /** + * This will actually trigger an Exception at the feed level if + * a feed level author is not set. + */ + return; + } + foreach ($authors as $data) { + $author = $this->_dom->createElement('author'); + $name = $this->_dom->createElement('name'); + $author->appendChild($name); + $root->appendChild($author); + $text = $dom->createTextNode($data['name']); + $name->appendChild($text); + if (array_key_exists('email', $data)) { + $email = $this->_dom->createElement('email'); + $author->appendChild($email); + $text = $dom->createTextNode($data['email']); + $email->appendChild($text); + } + if (array_key_exists('uri', $data)) { + $uri = $this->_dom->createElement('uri'); + $author->appendChild($uri); + $text = $dom->createTextNode($data['uri']); + $uri->appendChild($text); + } + } + } + + /** + * Set entry enclosure + * + * @param DOMDocument $dom + * @param DOMElement $root + * @return void + */ + protected function _setEnclosure(DOMDocument $dom, DOMElement $root) + { + $data = $this->_container->getEnclosure(); + if ((!$data || empty($data))) { + return; + } + $enclosure = $this->_dom->createElement('link'); + $enclosure->setAttribute('rel', 'enclosure'); + $enclosure->setAttribute('type', $data['type']); + $enclosure->setAttribute('length', $data['length']); + $enclosure->setAttribute('href', $data['uri']); + $root->appendChild($enclosure); + } + + protected function _setLink(DOMDocument $dom, DOMElement $root) + { + if(!$this->getDataContainer()->getLink()) { + return; + } + $link = $dom->createElement('link'); + $root->appendChild($link); + $link->setAttribute('rel', 'alternate'); + $link->setAttribute('type', 'text/html'); + $link->setAttribute('href', $this->getDataContainer()->getLink()); + } + + /** + * Set entry identifier + * + * @param DOMDocument $dom + * @param DOMElement $root + * @return void + */ + protected function _setId(DOMDocument $dom, DOMElement $root) + { + if(!$this->getDataContainer()->getId() + && !$this->getDataContainer()->getLink()) { + require_once 'Zend/Feed/Exception.php'; + $message = 'Atom 1.0 entry elements MUST contain exactly one ' + . 'atom:id element, or as an alternative, we can use the same ' + . 'value as atom:link however neither a suitable link nor an ' + . 'id have been set'; + $exception = new Zend_Feed_Exception($message); + if (!$this->_ignoreExceptions) { + throw $exception; + } else { + $this->_exceptions[] = $exception; + return; + } + } + + if (!$this->getDataContainer()->getId()) { + $this->getDataContainer()->setId( + $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())) { + require_once 'Zend/Feed/Exception.php'; + throw new Zend_Feed_Exception('Atom 1.0 IDs must be a valid URI/IRI'); + } + $id = $dom->createElement('id'); + $root->appendChild($id); + $text = $dom->createTextNode($this->getDataContainer()->getId()); + $id->appendChild($text); + } + + /** + * Set entry content + * + * @param DOMDocument $dom + * @param DOMElement $root + * @return void + */ + protected function _setContent(DOMDocument $dom, DOMElement $root) + { + $content = $this->getDataContainer()->getContent(); + if (!$content && !$this->getDataContainer()->getLink()) { + require_once 'Zend/Feed/Exception.php'; + $message = 'Atom 1.0 entry elements MUST contain exactly one ' + . 'atom:content element, or as an alternative, at least one link ' + . 'with a rel attribute of "alternate" to indicate an alternate ' + . 'method to consume the content.'; + $exception = new Zend_Feed_Exception($message); + if (!$this->_ignoreExceptions) { + throw $exception; + } else { + $this->_exceptions[] = $exception; + return; + } + } + if (!$content) { + return; + } + $element = $dom->createElement('content'); + $element->setAttribute('type', 'xhtml'); + $xhtmlElement = $this->_loadXhtml($content); + $xhtml = $dom->importNode($xhtmlElement, true); + $element->appendChild($xhtml); + $root->appendChild($element); + } + + /** + * Load a HTML string and attempt to normalise to XML + */ + protected function _loadXhtml($content) + { + $xhtml = ''; + if (class_exists('tidy', false)) { + $tidy = new tidy; + $config = array( + 'output-xhtml' => true, + 'show-body-only' => true + ); + $encoding = str_replace('-', '', $this->getEncoding()); + $tidy->parseString($content, $config, $encoding); + $tidy->cleanRepair(); + $xhtml = (string) $tidy; + } else { + $xhtml = $content; + } + $xhtml = preg_replace(array( + "/(<[\/]?)([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 + * @return void + */ + protected function _setCategories(DOMDocument $dom, DOMElement $root) + { + $categories = $this->getDataContainer()->getCategories(); + if (!$categories) { + return; + } + foreach ($categories as $cat) { + $category = $dom->createElement('category'); + $category->setAttribute('term', $cat['term']); + if (isset($cat['label'])) { + $category->setAttribute('label', $cat['label']); + } else { + $category->setAttribute('label', $cat['term']); + } + if (isset($cat['scheme'])) { + $category->setAttribute('scheme', $cat['scheme']); + } + $root->appendChild($category); + } + } + + /** + * Append Source element (Atom 1.0 Feed Metadata) + * + * @param DOMDocument $dom + * @param DOMElement $root + * @return void + */ + protected function _setSource(DOMDocument $dom, DOMElement $root) + { + $source = $this->getDataContainer()->getSource(); + if (!$source) { + return; + } + $renderer = new Zend_Feed_Writer_Renderer_Feed_Atom_Source($source); + $renderer->setType($this->getType()); + $element = $renderer->render()->getElement(); + $imported = $dom->importNode($element, true); + $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 new file mode 100644 index 0000000000..f7baf60c54 --- /dev/null +++ b/libs/Zend/Feed/Writer/Renderer/Entry/Atom/Deleted.php @@ -0,0 +1,121 @@ +<?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_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 $ + */ + +/** + * @see Zend_Feed_Writer_Renderer_RendererAbstract + */ +require_once 'Zend/Feed/Writer/Renderer/RendererAbstract.php'; + +/** + * @category Zend + * @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 + */ +class Zend_Feed_Writer_Renderer_Entry_Atom_Deleted + extends Zend_Feed_Writer_Renderer_RendererAbstract + implements Zend_Feed_Writer_Renderer_RendererInterface +{ + /** + * Constructor + * + * @param Zend_Feed_Writer_Deleted $container + * @return void + */ + public function __construct (Zend_Feed_Writer_Deleted $container) + { + parent::__construct($container); + } + + /** + * Render atom entry + * + * @return Zend_Feed_Writer_Renderer_Entry_Atom + */ + public function render() + { + $this->_dom = new DOMDocument('1.0', $this->_container->getEncoding()); + $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 + * @return void + */ + protected function _setComment(DOMDocument $dom, DOMElement $root) + { + if(!$this->getDataContainer()->getComment()) { + return; + } + $c = $dom->createElement('at:comment'); + $root->appendChild($c); + $c->setAttribute('type', 'html'); + $cdata = $dom->createCDATASection($this->getDataContainer()->getComment()); + $c->appendChild($cdata); + } + + /** + * Set entry authors + * + * @param DOMDocument $dom + * @param DOMElement $root + * @return void + */ + protected function _setBy(DOMDocument $dom, DOMElement $root) + { + $data = $this->_container->getBy(); + if ((!$data || empty($data))) { + return; + } + $author = $this->_dom->createElement('at:by'); + $name = $this->_dom->createElement('name'); + $author->appendChild($name); + $root->appendChild($author); + $text = $dom->createTextNode($data['name']); + $name->appendChild($text); + if (array_key_exists('email', $data)) { + $email = $this->_dom->createElement('email'); + $author->appendChild($email); + $text = $dom->createTextNode($data['email']); + $email->appendChild($text); + } + if (array_key_exists('uri', $data)) { + $uri = $this->_dom->createElement('uri'); + $author->appendChild($uri); + $text = $dom->createTextNode($data['uri']); + $uri->appendChild($text); + } + } + +} diff --git a/libs/Zend/Feed/Writer/Renderer/Entry/Rss.php b/libs/Zend/Feed/Writer/Renderer/Entry/Rss.php new file mode 100644 index 0000000000..6f2c349d51 --- /dev/null +++ b/libs/Zend/Feed/Writer/Renderer/Entry/Rss.php @@ -0,0 +1,315 @@ +<?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_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 20241 2010-01-12 20:19:46Z padraic $ + */ + +/** + * @see Zend_Feed_Writer_Renderer_RendererAbstract + */ +require_once 'Zend/Feed/Writer/Renderer/RendererAbstract.php'; + +/** + * @category Zend + * @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 + */ +class Zend_Feed_Writer_Renderer_Entry_Rss + extends Zend_Feed_Writer_Renderer_RendererAbstract + implements Zend_Feed_Writer_Renderer_RendererInterface +{ + /** + * Constructor + * + * @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() + { + $this->_dom = new DOMDocument('1.0', $this->_container->getEncoding()); + $this->_dom->formatOutput = true; + $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); + $this->_setDateModified($this->_dom, $entry); + $this->_setLink($this->_dom, $entry); + $this->_setId($this->_dom, $entry); + $this->_setAuthors($this->_dom, $entry); + $this->_setEnclosure($this->_dom, $entry); + $this->_setCommentLink($this->_dom, $entry); + $this->_setCategories($this->_dom, $entry); + foreach ($this->_extensions as $ext) { + $ext->setType($this->getType()); + $ext->setRootElement($this->getRootElement()); + $ext->setDomDocument($this->getDomDocument(), $entry); + $ext->render(); + } + + return $this; + } + + /** + * Set entry title + * + * @param DOMDocument $dom + * @param DOMElement $root + * @return void + */ + protected function _setTitle(DOMDocument $dom, DOMElement $root) + { + if(!$this->getDataContainer()->getDescription() + && !$this->getDataContainer()->getTitle()) { + require_once 'Zend/Feed/Exception.php'; + $message = 'RSS 2.0 entry elements SHOULD contain exactly one' + . ' title element but a title has not been set. In addition, there' + . ' is no description as required in the absence of a title.'; + $exception = new Zend_Feed_Exception($message); + if (!$this->_ignoreExceptions) { + throw $exception; + } else { + $this->_exceptions[] = $exception; + return; + } + } + $title = $dom->createElement('title'); + $root->appendChild($title); + $text = $dom->createTextNode($this->getDataContainer()->getTitle()); + $title->appendChild($text); + } + + /** + * Set entry description + * + * @param DOMDocument $dom + * @param DOMElement $root + * @return void + */ + protected function _setDescription(DOMDocument $dom, DOMElement $root) + { + if(!$this->getDataContainer()->getDescription() + && !$this->getDataContainer()->getTitle()) { + require_once 'Zend/Feed/Exception.php'; + $message = 'RSS 2.0 entry elements SHOULD contain exactly one' + . ' description element but a description has not been set. In' + . ' addition, there is no title element as required in the absence' + . ' of a description.'; + $exception = new Zend_Feed_Exception($message); + if (!$this->_ignoreExceptions) { + throw $exception; + } else { + $this->_exceptions[] = $exception; + return; + } + } + if (!$this->getDataContainer()->getDescription()) { + return; + } + $subtitle = $dom->createElement('description'); + $root->appendChild($subtitle); + $text = $dom->createCDATASection($this->getDataContainer()->getDescription()); + $subtitle->appendChild($text); + } + + /** + * Set date entry was last modified + * + * @param DOMDocument $dom + * @param DOMElement $root + * @return void + */ + protected function _setDateModified(DOMDocument $dom, DOMElement $root) + { + if(!$this->getDataContainer()->getDateModified()) { + return; + } + + $updated = $dom->createElement('pubDate'); + $root->appendChild($updated); + $text = $dom->createTextNode( + $this->getDataContainer()->getDateModified()->get(Zend_Date::RSS) + ); + $updated->appendChild($text); + } + + /** + * Set date entry was created + * + * @param DOMDocument $dom + * @param DOMElement $root + * @return void + */ + protected function _setDateCreated(DOMDocument $dom, DOMElement $root) + { + if (!$this->getDataContainer()->getDateCreated()) { + return; + } + if (!$this->getDataContainer()->getDateModified()) { + $this->getDataContainer()->setDateModified( + $this->getDataContainer()->getDateCreated() + ); + } + } + + /** + * Set entry authors + * + * @param DOMDocument $dom + * @param DOMElement $root + * @return void + */ + protected function _setAuthors(DOMDocument $dom, DOMElement $root) + { + $authors = $this->_container->getAuthors(); + if ((!$authors || empty($authors))) { + return; + } + foreach ($authors as $data) { + $author = $this->_dom->createElement('author'); + $name = $data['name']; + if (array_key_exists('email', $data)) { + $name = $data['email'] . ' (' . $data['name'] . ')'; + } + $text = $dom->createTextNode($name); + $author->appendChild($text); + $root->appendChild($author); + } + } + + /** + * Set entry enclosure + * + * @param DOMDocument $dom + * @param DOMElement $root + * @return void + */ + protected function _setEnclosure(DOMDocument $dom, DOMElement $root) + { + $data = $this->_container->getEnclosure(); + if ((!$data || empty($data))) { + return; + } + $enclosure = $this->_dom->createElement('enclosure'); + $enclosure->setAttribute('type', $data['type']); + $enclosure->setAttribute('length', $data['length']); + $enclosure->setAttribute('url', $data['uri']); + $root->appendChild($enclosure); + } + + /** + * Set link to entry + * + * @param DOMDocument $dom + * @param DOMElement $root + * @return void + */ + protected function _setLink(DOMDocument $dom, DOMElement $root) + { + if(!$this->getDataContainer()->getLink()) { + return; + } + $link = $dom->createElement('link'); + $root->appendChild($link); + $text = $dom->createTextNode($this->getDataContainer()->getLink()); + $link->appendChild($text); + } + + /** + * Set entry identifier + * + * @param DOMDocument $dom + * @param DOMElement $root + * @return void + */ + protected function _setId(DOMDocument $dom, DOMElement $root) + { + if(!$this->getDataContainer()->getId() + && !$this->getDataContainer()->getLink()) { + return; + } + + $id = $dom->createElement('guid'); + $root->appendChild($id); + if (!$this->getDataContainer()->getId()) { + $this->getDataContainer()->setId( + $this->getDataContainer()->getLink()); + } + $text = $dom->createTextNode($this->getDataContainer()->getId()); + $id->appendChild($text); + if (!Zend_Uri::check($this->getDataContainer()->getId())) { + $id->setAttribute('isPermaLink', 'false'); + } + } + + /** + * Set link to entry comments + * + * @param DOMDocument $dom + * @param DOMElement $root + * @return void + */ + protected function _setCommentLink(DOMDocument $dom, DOMElement $root) + { + $link = $this->getDataContainer()->getCommentLink(); + if (!$link) { + return; + } + $clink = $this->_dom->createElement('comments'); + $text = $dom->createTextNode($link); + $clink->appendChild($text); + $root->appendChild($clink); + } + + /** + * Set entry categories + * + * @param DOMDocument $dom + * @param DOMElement $root + * @return void + */ + protected function _setCategories(DOMDocument $dom, DOMElement $root) + { + $categories = $this->getDataContainer()->getCategories(); + if (!$categories) { + return; + } + foreach ($categories as $cat) { + $category = $dom->createElement('category'); + if (isset($cat['scheme'])) { + $category->setAttribute('domain', $cat['scheme']); + } + $text = $dom->createCDATASection($cat['term']); + $category->appendChild($text); + $root->appendChild($category); + } + } +} diff --git a/libs/Zend/Feed/Writer/Renderer/Feed/Atom.php b/libs/Zend/Feed/Writer/Renderer/Feed/Atom.php new file mode 100644 index 0000000000..ed080c1515 --- /dev/null +++ b/libs/Zend/Feed/Writer/Renderer/Feed/Atom.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_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 20519 2010-01-22 14:06:24Z padraic $ + */ + +/** @see Zend_Feed_Writer_Feed */ +require_once 'Zend/Feed/Writer/Feed.php'; + +/** @see Zend_Version */ +require_once 'Zend/Version.php'; + +/** @see Zend_Feed_Writer_Renderer_RendererInterface */ +require_once 'Zend/Feed/Writer/Renderer/RendererInterface.php'; + +/** @see Zend_Feed_Writer_Renderer_Entry_Atom */ +require_once 'Zend/Feed/Writer/Renderer/Entry/Atom.php'; + +/** @see Zend_Feed_Writer_Renderer_Entry_Atom_Deleted */ +require_once 'Zend/Feed/Writer/Renderer/Entry/Atom/Deleted.php'; + +/** @see Zend_Feed_Writer_Renderer_RendererAbstract */ +require_once 'Zend/Feed/Writer/Renderer/RendererAbstract.php'; + +require_once 'Zend/Feed/Writer/Renderer/Feed/Atom/AtomAbstract.php'; + +/** + * @category Zend + * @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 + */ +class Zend_Feed_Writer_Renderer_Feed_Atom + extends Zend_Feed_Writer_Renderer_Feed_Atom_AtomAbstract + implements Zend_Feed_Writer_Renderer_RendererInterface +{ + /** + * Constructor + * + * @param Zend_Feed_Writer_Feed $container + * @return void + */ + public function __construct (Zend_Feed_Writer_Feed $container) + { + parent::__construct($container); + } + + /** + * Render Atom feed + * + * @return Zend_Feed_Writer_Renderer_Feed_Atom + */ + public function render() + { + if (!$this->_container->getEncoding()) { + $this->_container->setEncoding('UTF-8'); + } + $this->_dom = new DOMDocument('1.0', $this->_container->getEncoding()); + $this->_dom->formatOutput = true; + $root = $this->_dom->createElementNS( + Zend_Feed_Writer::NAMESPACE_ATOM_10, 'feed' + ); + $this->setRootElement($root); + $this->_dom->appendChild($root); + $this->_setLanguage($this->_dom, $root); + $this->_setBaseUrl($this->_dom, $root); + $this->_setTitle($this->_dom, $root); + $this->_setDescription($this->_dom, $root); + $this->_setDateCreated($this->_dom, $root); + $this->_setDateModified($this->_dom, $root); + $this->_setGenerator($this->_dom, $root); + $this->_setLink($this->_dom, $root); + $this->_setFeedLinks($this->_dom, $root); + $this->_setId($this->_dom, $root); + $this->_setAuthors($this->_dom, $root); + $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()); + } + if ($entry instanceof Zend_Feed_Writer_Entry) { + $renderer = new Zend_Feed_Writer_Renderer_Entry_Atom($entry); + } else { + if (!$this->_dom->documentElement->hasAttribute('xmlns:at')) { + $this->_dom->documentElement->setAttribute( + 'xmlns:at', 'http://purl.org/atompub/tombstones/1.0' + ); + } + $renderer = new Zend_Feed_Writer_Renderer_Entry_Atom_Deleted($entry); + } + if ($this->_ignoreExceptions === true) { + $renderer->ignoreExceptions(); + } + $renderer->setType($this->getType()); + $renderer->setRootElement($this->_dom->documentElement); + $renderer->render(); + $element = $renderer->getElement(); + $imported = $this->_dom->importNode($element, true); + $root->appendChild($imported); + } + return $this; + } + +} diff --git a/libs/Zend/Feed/Writer/Renderer/Feed/Atom/AtomAbstract.php b/libs/Zend/Feed/Writer/Renderer/Feed/Atom/AtomAbstract.php new file mode 100644 index 0000000000..35be0464d9 --- /dev/null +++ b/libs/Zend/Feed/Writer/Renderer/Feed/Atom/AtomAbstract.php @@ -0,0 +1,408 @@ +<?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_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 $ + */ + +/** @see Zend_Feed_Writer_Feed */ +require_once 'Zend/Feed/Writer/Feed.php'; + +/** @see Zend_Version */ +require_once 'Zend/Version.php'; + +/** @see Zend_Feed_Writer_Renderer_RendererInterface */ +require_once 'Zend/Feed/Writer/Renderer/RendererInterface.php'; + +/** @see Zend_Feed_Writer_Renderer_Entry_Atom */ +require_once 'Zend/Feed/Writer/Renderer/Entry/Atom.php'; + +/** @see Zend_Feed_Writer_Renderer_RendererAbstract */ +require_once 'Zend/Feed/Writer/Renderer/RendererAbstract.php'; + +/** + * @category Zend + * @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 + */ +class Zend_Feed_Writer_Renderer_Feed_Atom_AtomAbstract + extends Zend_Feed_Writer_Renderer_RendererAbstract +{ + /** + * Constructor + * + * @param Zend_Feed_Writer_Feed $container + * @return void + */ + public function __construct ($container) + { + parent::__construct($container); + } + + /** + * Set feed language + * + * @param DOMDocument $dom + * @param DOMElement $root + * @return void + */ + protected function _setLanguage(DOMDocument $dom, DOMElement $root) + { + if ($this->getDataContainer()->getLanguage()) { + $root->setAttribute('xml:lang', $this->getDataContainer() + ->getLanguage()); + } + } + + /** + * Set feed title + * + * @param DOMDocument $dom + * @param DOMElement $root + * @return void + */ + protected function _setTitle(DOMDocument $dom, DOMElement $root) + { + if(!$this->getDataContainer()->getTitle()) { + require_once 'Zend/Feed/Exception.php'; + $message = 'Atom 1.0 feed elements MUST contain exactly one' + . ' atom:title element but a title has not been set'; + $exception = new Zend_Feed_Exception($message); + if (!$this->_ignoreExceptions) { + throw $exception; + } else { + $this->_exceptions[] = $exception; + return; + } + } + + $title = $dom->createElement('title'); + $root->appendChild($title); + $title->setAttribute('type', 'text'); + $text = $dom->createTextNode($this->getDataContainer()->getTitle()); + $title->appendChild($text); + } + + /** + * Set feed description + * + * @param DOMDocument $dom + * @param DOMElement $root + * @return void + */ + protected function _setDescription(DOMDocument $dom, DOMElement $root) + { + if(!$this->getDataContainer()->getDescription()) { + return; + } + $subtitle = $dom->createElement('subtitle'); + $root->appendChild($subtitle); + $subtitle->setAttribute('type', 'text'); + $text = $dom->createTextNode($this->getDataContainer()->getDescription()); + $subtitle->appendChild($text); + } + + /** + * Set date feed was last modified + * + * @param DOMDocument $dom + * @param DOMElement $root + * @return void + */ + protected function _setDateModified(DOMDocument $dom, DOMElement $root) + { + if(!$this->getDataContainer()->getDateModified()) { + require_once 'Zend/Feed/Exception.php'; + $message = 'Atom 1.0 feed elements MUST contain exactly one' + . ' atom:updated element but a modification date has not been set'; + $exception = new Zend_Feed_Exception($message); + if (!$this->_ignoreExceptions) { + throw $exception; + } else { + $this->_exceptions[] = $exception; + return; + } + } + + $updated = $dom->createElement('updated'); + $root->appendChild($updated); + $text = $dom->createTextNode( + $this->getDataContainer()->getDateModified()->get(Zend_Date::ISO_8601) + ); + $updated->appendChild($text); + } + + /** + * Set feed generator string + * + * @param DOMDocument $dom + * @param DOMElement $root + * @return void + */ + protected function _setGenerator(DOMDocument $dom, DOMElement $root) + { + if(!$this->getDataContainer()->getGenerator()) { + $this->getDataContainer()->setGenerator('Zend_Feed_Writer', + Zend_Version::VERSION, 'http://framework.zend.com'); + } + + $gdata = $this->getDataContainer()->getGenerator(); + $generator = $dom->createElement('generator'); + $root->appendChild($generator); + $text = $dom->createTextNode($gdata['name']); + $generator->appendChild($text); + if (array_key_exists('uri', $gdata)) { + $generator->setAttribute('uri', $gdata['uri']); + } + if (array_key_exists('version', $gdata)) { + $generator->setAttribute('version', $gdata['version']); + } + } + + /** + * Set link to feed + * + * @param DOMDocument $dom + * @param DOMElement $root + * @return void + */ + protected function _setLink(DOMDocument $dom, DOMElement $root) + { + if(!$this->getDataContainer()->getLink()) { + return; + } + $link = $dom->createElement('link'); + $root->appendChild($link); + $link->setAttribute('rel', 'alternate'); + $link->setAttribute('type', 'text/html'); + $link->setAttribute('href', $this->getDataContainer()->getLink()); + } + + /** + * Set feed links + * + * @param DOMDocument $dom + * @param DOMElement $root + * @return void + */ + protected function _setFeedLinks(DOMDocument $dom, DOMElement $root) + { + $flinks = $this->getDataContainer()->getFeedLinks(); + if(!$flinks || !array_key_exists('atom', $flinks)) { + require_once 'Zend/Feed/Exception.php'; + $message = 'Atom 1.0 feed elements SHOULD contain one atom:link ' + . 'element with a rel attribute value of "self". This is the ' + . 'preferred URI for retrieving Atom Feed Documents representing ' + . 'this Atom feed but a feed link has not been set'; + $exception = new Zend_Feed_Exception($message); + if (!$this->_ignoreExceptions) { + throw $exception; + } else { + $this->_exceptions[] = $exception; + return; + } + } + + foreach ($flinks as $type => $href) { + $mime = 'application/' . strtolower($type) . '+xml'; + $flink = $dom->createElement('link'); + $root->appendChild($flink); + $flink->setAttribute('rel', 'self'); + $flink->setAttribute('type', $mime); + $flink->setAttribute('href', $href); + } + } + + /** + * Set feed authors + * + * @param DOMDocument $dom + * @param DOMElement $root + * @return void + */ + protected function _setAuthors(DOMDocument $dom, DOMElement $root) + { + $authors = $this->_container->getAuthors(); + if (!$authors || empty($authors)) { + /** + * Technically we should defer an exception until we can check + * that all entries contain an author. If any entry is missing + * an author, then a missing feed author element is invalid + */ + return; + } + foreach ($authors as $data) { + $author = $this->_dom->createElement('author'); + $name = $this->_dom->createElement('name'); + $author->appendChild($name); + $root->appendChild($author); + $text = $dom->createTextNode($data['name']); + $name->appendChild($text); + if (array_key_exists('email', $data)) { + $email = $this->_dom->createElement('email'); + $author->appendChild($email); + $text = $dom->createTextNode($data['email']); + $email->appendChild($text); + } + if (array_key_exists('uri', $data)) { + $uri = $this->_dom->createElement('uri'); + $author->appendChild($uri); + $text = $dom->createTextNode($data['uri']); + $uri->appendChild($text); + } + } + } + + /** + * Set feed identifier + * + * @param DOMDocument $dom + * @param DOMElement $root + * @return void + */ + protected function _setId(DOMDocument $dom, DOMElement $root) + { + if(!$this->getDataContainer()->getId() + && !$this->getDataContainer()->getLink()) { + require_once 'Zend/Feed/Exception.php'; + $message = 'Atom 1.0 feed elements MUST contain exactly one ' + . 'atom:id element, or as an alternative, we can use the same ' + . 'value as atom:link however neither a suitable link nor an ' + . 'id have been set'; + $exception = new Zend_Feed_Exception($message); + if (!$this->_ignoreExceptions) { + throw $exception; + } else { + $this->_exceptions[] = $exception; + return; + } + } + + if (!$this->getDataContainer()->getId()) { + $this->getDataContainer()->setId( + $this->getDataContainer()->getLink()); + } + $id = $dom->createElement('id'); + $root->appendChild($id); + $text = $dom->createTextNode($this->getDataContainer()->getId()); + $id->appendChild($text); + } + + /** + * Set feed copyright + * + * @param DOMDocument $dom + * @param DOMElement $root + * @return void + */ + protected function _setCopyright(DOMDocument $dom, DOMElement $root) + { + $copyright = $this->getDataContainer()->getCopyright(); + if (!$copyright) { + return; + } + $copy = $dom->createElement('rights'); + $root->appendChild($copy); + $text = $dom->createTextNode($copyright); + $copy->appendChild($text); + } + + /** + * Set date feed was created + * + * @param DOMDocument $dom + * @param DOMElement $root + * @return void + */ + protected function _setDateCreated(DOMDocument $dom, DOMElement $root) + { + if(!$this->getDataContainer()->getDateCreated()) { + return; + } + if(!$this->getDataContainer()->getDateModified()) { + $this->getDataContainer()->setDateModified( + $this->getDataContainer()->getDateCreated() + ); + } + } + + /** + * Set base URL to feed links + * + * @param DOMDocument $dom + * @param DOMElement $root + * @return void + */ + protected function _setBaseUrl(DOMDocument $dom, DOMElement $root) + { + $baseUrl = $this->getDataContainer()->getBaseUrl(); + if (!$baseUrl) { + return; + } + $root->setAttribute('xml:base', $baseUrl); + } + + /** + * Set hubs to which this feed pushes + * + * @param DOMDocument $dom + * @param DOMElement $root + * @return void + */ + protected function _setHubs(DOMDocument $dom, DOMElement $root) + { + $hubs = $this->getDataContainer()->getHubs(); + if (!$hubs) { + return; + } + foreach ($hubs as $hubUrl) { + $hub = $dom->createElement('link'); + $hub->setAttribute('rel', 'hub'); + $hub->setAttribute('href', $hubUrl); + $root->appendChild($hub); + } + } + + /** + * Set feed cateories + * + * @param DOMDocument $dom + * @param DOMElement $root + * @return void + */ + protected function _setCategories(DOMDocument $dom, DOMElement $root) + { + $categories = $this->getDataContainer()->getCategories(); + if (!$categories) { + return; + } + foreach ($categories as $cat) { + $category = $dom->createElement('category'); + $category->setAttribute('term', $cat['term']); + if (isset($cat['label'])) { + $category->setAttribute('label', $cat['label']); + } else { + $category->setAttribute('label', $cat['term']); + } + if (isset($cat['scheme'])) { + $category->setAttribute('scheme', $cat['scheme']); + } + $root->appendChild($category); + } + } +} diff --git a/libs/Zend/Feed/Writer/Renderer/Feed/Atom/Source.php b/libs/Zend/Feed/Writer/Renderer/Feed/Atom/Source.php new file mode 100644 index 0000000000..2fda14a06c --- /dev/null +++ b/libs/Zend/Feed/Writer/Renderer/Feed/Atom/Source.php @@ -0,0 +1,110 @@ +<?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_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 $ + */ + +require_once 'Zend/Feed/Writer/Renderer/Feed/Atom/AtomAbstract.php'; + +/** + * @category Zend + * @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 + */ +class Zend_Feed_Writer_Renderer_Feed_Atom_Source + extends Zend_Feed_Writer_Renderer_Feed_Atom_AtomAbstract + implements Zend_Feed_Writer_Renderer_RendererInterface +{ + + /** + * Constructor + * + * @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() + { + if (!$this->_container->getEncoding()) { + $this->_container->setEncoding('UTF-8'); + } + $this->_dom = new DOMDocument('1.0', $this->_container->getEncoding()); + $this->_dom->formatOutput = true; + $root = $this->_dom->createElement('source'); + $this->setRootElement($root); + $this->_dom->appendChild($root); + $this->_setLanguage($this->_dom, $root); + $this->_setBaseUrl($this->_dom, $root); + $this->_setTitle($this->_dom, $root); + $this->_setDescription($this->_dom, $root); + $this->_setDateCreated($this->_dom, $root); + $this->_setDateModified($this->_dom, $root); + $this->_setGenerator($this->_dom, $root); + $this->_setLink($this->_dom, $root); + $this->_setFeedLinks($this->_dom, $root); + $this->_setId($this->_dom, $root); + $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()); + $ext->setDomDocument($this->getDomDocument(), $root); + $ext->render(); + } + return $this; + } + + /** + * Set feed generator string + * + * @param DOMDocument $dom + * @param DOMElement $root + * @return void + */ + protected function _setGenerator(DOMDocument $dom, DOMElement $root) + { + if(!$this->getDataContainer()->getGenerator()) { + return; + } + + $gdata = $this->getDataContainer()->getGenerator(); + $generator = $dom->createElement('generator'); + $root->appendChild($generator); + $text = $dom->createTextNode($gdata['name']); + $generator->appendChild($text); + if (array_key_exists('uri', $gdata)) { + $generator->setAttribute('uri', $gdata['uri']); + } + if (array_key_exists('version', $gdata)) { + $generator->setAttribute('version', $gdata['version']); + } + } + +} diff --git a/libs/Zend/Feed/Writer/Renderer/Feed/Rss.php b/libs/Zend/Feed/Writer/Renderer/Feed/Rss.php new file mode 100644 index 0000000000..2d8ab5c8a0 --- /dev/null +++ b/libs/Zend/Feed/Writer/Renderer/Feed/Rss.php @@ -0,0 +1,374 @@ +<?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_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 20519 2010-01-22 14:06:24Z padraic $ + */ + +/** @see Zend_Feed_Writer_Feed */ +require_once 'Zend/Feed/Writer/Feed.php'; + +/** @see Zend_Version */ +require_once 'Zend/Version.php'; + +/** @see Zend_Feed_Writer_Renderer_RendererInterface */ +require_once 'Zend/Feed/Writer/Renderer/RendererInterface.php'; + +/** @see Zend_Feed_Writer_Renderer_Entry_Rss */ +require_once 'Zend/Feed/Writer/Renderer/Entry/Rss.php'; + +/** @see Zend_Feed_Writer_Renderer_RendererAbstract */ +require_once 'Zend/Feed/Writer/Renderer/RendererAbstract.php'; + +/** + * @category Zend + * @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 + */ +class Zend_Feed_Writer_Renderer_Feed_Rss + extends Zend_Feed_Writer_Renderer_RendererAbstract + implements Zend_Feed_Writer_Renderer_RendererInterface +{ + /** + * Constructor + * + * @param Zend_Feed_Writer_Feed $container + * @return void + */ + public function __construct (Zend_Feed_Writer_Feed $container) + { + parent::__construct($container); + } + + /** + * Render RSS feed + * + * @return Zend_Feed_Writer_Renderer_Feed_Rss + */ + public function render() + { + if (!$this->_container->getEncoding()) { + $this->_container->setEncoding('UTF-8'); + } + $this->_dom = new DOMDocument('1.0', $this->_container->getEncoding()); + $this->_dom->formatOutput = true; + $this->_dom->substituteEntities = false; + $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); + $this->_setLanguage($this->_dom, $channel); + $this->_setBaseUrl($this->_dom, $channel); + $this->_setTitle($this->_dom, $channel); + $this->_setDescription($this->_dom, $channel); + $this->_setDateCreated($this->_dom, $channel); + $this->_setDateModified($this->_dom, $channel); + $this->_setGenerator($this->_dom, $channel); + $this->_setLink($this->_dom, $channel); + $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()); + } + if ($entry instanceof Zend_Feed_Writer_Entry) { + $renderer = new Zend_Feed_Writer_Renderer_Entry_Rss($entry); + } else { + continue; + } + if ($this->_ignoreExceptions === true) { + $renderer->ignoreExceptions(); + } + $renderer->setType($this->getType()); + $renderer->setRootElement($this->_dom->documentElement); + $renderer->render(); + $element = $renderer->getElement(); + $imported = $this->_dom->importNode($element, true); + $channel->appendChild($imported); + } + return $this; + } + + /** + * Set feed language + * + * @param DOMDocument $dom + * @param DOMElement $root + * @return void + */ + protected function _setLanguage(DOMDocument $dom, DOMElement $root) + { + $lang = $this->getDataContainer()->getLanguage(); + if (!$lang) { + return; + } + $language = $dom->createElement('language'); + $root->appendChild($language); + $language->nodeValue = $lang; + } + + /** + * Set feed title + * + * @param DOMDocument $dom + * @param DOMElement $root + * @return void + */ + protected function _setTitle(DOMDocument $dom, DOMElement $root) + { + if(!$this->getDataContainer()->getTitle()) { + require_once 'Zend/Feed/Exception.php'; + $message = 'RSS 2.0 feed elements MUST contain exactly one' + . ' title element but a title has not been set'; + $exception = new Zend_Feed_Exception($message); + if (!$this->_ignoreExceptions) { + throw $exception; + } else { + $this->_exceptions[] = $exception; + return; + } + } + + $title = $dom->createElement('title'); + $root->appendChild($title); + $text = $dom->createTextNode($this->getDataContainer()->getTitle()); + $title->appendChild($text); + } + + /** + * Set feed description + * + * @param DOMDocument $dom + * @param DOMElement $root + * @return void + */ + protected function _setDescription(DOMDocument $dom, DOMElement $root) + { + if(!$this->getDataContainer()->getDescription()) { + require_once 'Zend/Feed/Exception.php'; + $message = 'RSS 2.0 feed elements MUST contain exactly one' + . ' description element but one has not been set'; + $exception = new Zend_Feed_Exception($message); + if (!$this->_ignoreExceptions) { + throw $exception; + } else { + $this->_exceptions[] = $exception; + return; + } + } + $subtitle = $dom->createElement('description'); + $root->appendChild($subtitle); + $text = $dom->createTextNode($this->getDataContainer()->getDescription()); + $subtitle->appendChild($text); + } + + /** + * Set date feed was last modified + * + * @param DOMDocument $dom + * @param DOMElement $root + * @return void + */ + protected function _setDateModified(DOMDocument $dom, DOMElement $root) + { + if(!$this->getDataContainer()->getDateModified()) { + return; + } + + $updated = $dom->createElement('pubDate'); + $root->appendChild($updated); + $text = $dom->createTextNode( + $this->getDataContainer()->getDateModified()->get(Zend_Date::RSS) + ); + $updated->appendChild($text); + } + + /** + * Set feed generator string + * + * @param DOMDocument $dom + * @param DOMElement $root + * @return void + */ + protected function _setGenerator(DOMDocument $dom, DOMElement $root) + { + if(!$this->getDataContainer()->getGenerator()) { + $this->getDataContainer()->setGenerator('Zend_Feed_Writer', + Zend_Version::VERSION, 'http://framework.zend.com'); + } + + $gdata = $this->getDataContainer()->getGenerator(); + $generator = $dom->createElement('generator'); + $root->appendChild($generator); + $name = $gdata['name']; + if (array_key_exists('version', $gdata)) { + $name .= ' ' . $gdata['version']; + } + if (array_key_exists('uri', $gdata)) { + $name .= ' (' . $gdata['uri'] . ')'; + } + $text = $dom->createTextNode($name); + $generator->appendChild($text); + } + + /** + * Set link to feed + * + * @param DOMDocument $dom + * @param DOMElement $root + * @return void + */ + protected function _setLink(DOMDocument $dom, DOMElement $root) + { + $value = $this->getDataContainer()->getLink(); + if(!$value) { + require_once 'Zend/Feed/Exception.php'; + $message = 'RSS 2.0 feed elements MUST contain exactly one' + . ' link element but one has not been set'; + $exception = new Zend_Feed_Exception($message); + if (!$this->_ignoreExceptions) { + throw $exception; + } else { + $this->_exceptions[] = $exception; + return; + } + } + $link = $dom->createElement('link'); + $root->appendChild($link); + $text = $dom->createTextNode($value); + $link->appendChild($text); + if (!Zend_Uri::check($value)) { + $link->setAttribute('isPermaLink', 'false'); + } + } + + /** + * Set feed authors + * + * @param DOMDocument $dom + * @param DOMElement $root + * @return void + */ + protected function _setAuthors(DOMDocument $dom, DOMElement $root) + { + $authors = $this->getDataContainer()->getAuthors(); + if (!$authors || empty($authors)) { + return; + } + foreach ($authors as $data) { + $author = $this->_dom->createElement('author'); + $name = $data['name']; + if (array_key_exists('email', $data)) { + $name = $data['email'] . ' (' . $data['name'] . ')'; + } + $text = $dom->createTextNode($name); + $author->appendChild($text); + $root->appendChild($author); + } + } + + /** + * Set feed copyright + * + * @param DOMDocument $dom + * @param DOMElement $root + * @return void + */ + protected function _setCopyright(DOMDocument $dom, DOMElement $root) + { + $copyright = $this->getDataContainer()->getCopyright(); + if (!$copyright) { + return; + } + $copy = $dom->createElement('copyright'); + $root->appendChild($copy); + $text = $dom->createTextNode($copyright); + $copy->appendChild($text); + } + + /** + * Set date feed was created + * + * @param DOMDocument $dom + * @param DOMElement $root + * @return void + */ + protected function _setDateCreated(DOMDocument $dom, DOMElement $root) + { + if(!$this->getDataContainer()->getDateCreated()) { + return; + } + if(!$this->getDataContainer()->getDateModified()) { + $this->getDataContainer()->setDateModified( + $this->getDataContainer()->getDateCreated() + ); + } + } + + /** + * Set base URL to feed links + * + * @param DOMDocument $dom + * @param DOMElement $root + * @return void + */ + protected function _setBaseUrl(DOMDocument $dom, DOMElement $root) + { + $baseUrl = $this->getDataContainer()->getBaseUrl(); + if (!$baseUrl) { + return; + } + $root->setAttribute('xml:base', $baseUrl); + } + + /** + * Set feed categories + * + * @param DOMDocument $dom + * @param DOMElement $root + * @return void + */ + protected function _setCategories(DOMDocument $dom, DOMElement $root) + { + $categories = $this->getDataContainer()->getCategories(); + if (!$categories) { + return; + } + foreach ($categories as $cat) { + $category = $dom->createElement('category'); + if (isset($cat['scheme'])) { + $category->setAttribute('domain', $cat['scheme']); + } + $text = $dom->createTextNode($cat['term']); + $category->appendChild($text); + $root->appendChild($category); + } + } +} diff --git a/libs/Zend/Feed/Writer/Renderer/RendererAbstract.php b/libs/Zend/Feed/Writer/Renderer/RendererAbstract.php new file mode 100644 index 0000000000..0778e435cd --- /dev/null +++ b/libs/Zend/Feed/Writer/Renderer/RendererAbstract.php @@ -0,0 +1,250 @@ +<?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_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 $ + */ + +/** @see Zend_Feed_Writer */ +require_once 'Zend/Feed/Writer.php'; + +/** @see Zend_Version */ +require_once 'Zend/Version.php'; + +/** + * @category Zend + * @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 + */ +class Zend_Feed_Writer_Renderer_RendererAbstract +{ + /** + * Extensions + * @var array + */ + protected $_extensions = array(); + + /** + * @var mixed + */ + protected $_container = null; + + /** + * @var DOMDocument + */ + protected $_dom = null; + + /** + * @var bool + */ + protected $_ignoreExceptions = false; + + /** + * @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. + * + * @var string + */ + protected $_type = null; + + /** + * @var DOMElement + */ + protected $_rootElement = null; + + /** + * Constructor + * + * @param mixed $container + * @return void + */ + public function __construct($container) + { + $this->_container = $container; + $this->setType($container->getType()); + $this->_loadExtensions(); + } + + /** + * Save XML to string + * + * @return string + */ + public function saveXml() + { + return $this->getDomDocument()->saveXml(); + } + + /** + * Get DOM document + * + * @return DOMDocument + */ + public function getDomDocument() + { + return $this->_dom; + } + + /** + * Get document element from DOM + * + * @return DOMElement + */ + public function getElement() + { + return $this->getDomDocument()->documentElement; + } + + /** + * Get data container of items being rendered + * + * @return mixed + */ + public function getDataContainer() + { + return $this->_container; + } + + /** + * Set feed encoding + * + * @param string $enc + * @return Zend_Feed_Writer_Renderer_RendererAbstract + */ + public function setEncoding($enc) + { + $this->_encoding = $enc; + return $this; + } + + /** + * Get feed encoding + * + * @return string + */ + public function getEncoding() + { + return $this->_encoding; + } + + /** + * Indicate whether or not to ignore exceptions + * + * @param bool $bool + * @return Zend_Feed_Writer_Renderer_RendererAbstract + */ + public function ignoreExceptions($bool = true) + { + if (!is_bool($bool)) { + require_once 'Zend/Feed/Exception.php'; + throw new Zend_Feed_Exception('Invalid parameter: $bool. Should be TRUE or FALSE (defaults to TRUE if null)'); + } + $this->_ignoreExceptions = $bool; + return $this; + } + + /** + * 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 + * on their appropriateness for the current type, e.g. renderers. + * + * @param string $type + */ + public function setType($type) + { + $this->_type = $type; + } + + /** + * Retrieve the current or last feed type exported. + * + * @return string Value will be "rss" or "atom" + */ + public function getType() + { + 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 + * namespaces are added to the root element - not scattered across the entire + * XML file - may assist namespace unsafe parsers and looks pretty ;). + * + * @param DOMElement $root + */ + public function setRootElement(DOMElement $root) + { + $this->_rootElement = $root; + } + + /** + * Retrieve the absolute root element for the XML feed being generated. + * + * @return DOMElement + */ + public function getRootElement() + { + return $this->_rootElement; + } + + /** + * Load extensions from Zend_Feed_Writer + * + * @return void + */ + protected function _loadExtensions() + { + Zend_Feed_Writer::registerCoreExtensions(); + $all = Zend_Feed_Writer::getExtensions(); + if (stripos(get_class($this), 'entry')) { + $exts = $all['entryRenderer']; + } else { + $exts = $all['feedRenderer']; + } + foreach ($exts as $extension) { + $className = Zend_Feed_Writer::getPluginLoader()->getClassName($extension); + $this->_extensions[$extension] = new $className( + $this->getDataContainer() + ); + $this->_extensions[$extension]->setEncoding($this->getEncoding()); + } + } +} diff --git a/libs/Zend/Feed/Writer/Renderer/RendererInterface.php b/libs/Zend/Feed/Writer/Renderer/RendererInterface.php new file mode 100644 index 0000000000..89b4294416 --- /dev/null +++ b/libs/Zend/Feed/Writer/Renderer/RendererInterface.php @@ -0,0 +1,111 @@ +<?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_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 $ + */ + +/** + * @category Zend + * @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 + */ +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 + * on their appropriateness for the current type, e.g. renderers. + * + * @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 + * namespaces are added to the root element - not scattered across the entire + * XML file - may assist namespace unsafe parsers and looks pretty ;). + * + * @param DOMElement $root + */ + public function setRootElement(DOMElement $root); + + /** + * Retrieve the absolute root element for the XML feed being generated. + * + * @return DOMElement + */ + public function getRootElement(); +} diff --git a/libs/Zend/Feed/Writer/Source.php b/libs/Zend/Feed/Writer/Source.php new file mode 100644 index 0000000000..37fcd4833c --- /dev/null +++ b/libs/Zend/Feed/Writer/Source.php @@ -0,0 +1,33 @@ +<?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_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 $ + */ + +require_once 'Zend/Feed/Writer/Feed/FeedAbstract.php'; + + /** + * @category Zend + * @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 + */ +class Zend_Feed_Writer_Source extends Zend_Feed_Writer_Feed_FeedAbstract +{ + +} diff --git a/libs/Zend/Http/Client.php b/libs/Zend/Http/Client.php index c7f396ce2d..1e58946573 100644 --- a/libs/Zend/Http/Client.php +++ b/libs/Zend/Http/Client.php @@ -16,8 +16,8 @@ * @category Zend * @package Zend_Http * @subpackage Client - * @version $Id: Client.php 19309 2009-11-30 11:03:01Z bate $ - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @version $Id: Client.php 20096 2010-01-06 02:05:09Z bkarwin $ + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ @@ -60,7 +60,7 @@ require_once 'Zend/Http/Response/Stream.php'; * @package Zend_Http * @subpackage Client * @throws Zend_Http_Client_Exception - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Client @@ -75,7 +75,8 @@ class Zend_Http_Client const DELETE = 'DELETE'; const TRACE = 'TRACE'; const OPTIONS = 'OPTIONS'; - const CONNECT = 'CONNECT'; + const CONNECT = 'CONNECT';
+ const MERGE = 'MERGE'; /** * Supported HTTP Authentication methods @@ -842,7 +843,7 @@ class Zend_Http_Client } 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()}"); + throw new Zend_Http_Client_Exception("Unable to load adapter '$adapter': {$e->getMessage()}", 0, $e); } } diff --git a/libs/Zend/Http/Client/Adapter/Curl.php b/libs/Zend/Http/Client/Adapter/Curl.php index 6a4bee15da..79e78e77f4 100644 --- a/libs/Zend/Http/Client/Adapter/Curl.php +++ b/libs/Zend/Http/Client/Adapter/Curl.php @@ -16,8 +16,8 @@ * @category Zend * @package Zend_Http * @subpackage Client_Adapter - * @version $Id: Curl.php 19309 2009-11-30 11:03:01Z bate $ - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @version $Id: Curl.php 20096 2010-01-06 02:05:09Z bkarwin $ + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ @@ -42,7 +42,7 @@ require_once 'Zend/Http/Client/Adapter/Stream.php'; * @category Zend * @package Zend_Http * @subpackage Client_Adapter - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Client_Adapter_Curl implements Zend_Http_Client_Adapter_Interface, Zend_Http_Client_Adapter_Stream diff --git a/libs/Zend/Http/Client/Adapter/Exception.php b/libs/Zend/Http/Client/Adapter/Exception.php index b157e0facf..c744c54abb 100644 --- a/libs/Zend/Http/Client/Adapter/Exception.php +++ b/libs/Zend/Http/Client/Adapter/Exception.php @@ -15,8 +15,8 @@ * @category Zend * @package Zend_Http * @subpackage Client_Adapter_Exception - * @version $Id: Exception.php 17118 2009-07-26 09:41:41Z shahar $ - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @version $Id: Exception.php 20096 2010-01-06 02:05:09Z bkarwin $ + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ @@ -29,7 +29,7 @@ require_once 'Zend/Http/Client/Exception.php'; * @category Zend * @package Zend_Http * @subpackage Client_Adapter - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Client_Adapter_Exception extends Zend_Http_Client_Exception diff --git a/libs/Zend/Http/Client/Adapter/Interface.php b/libs/Zend/Http/Client/Adapter/Interface.php index 46b84accbf..be9d187947 100644 --- a/libs/Zend/Http/Client/Adapter/Interface.php +++ b/libs/Zend/Http/Client/Adapter/Interface.php @@ -16,8 +16,8 @@ * @category Zend * @package Zend_Http * @subpackage Client_Adapter - * @version $Id: Interface.php 16214 2009-06-21 19:34:03Z thomas $ - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @version $Id: Interface.php 20096 2010-01-06 02:05:09Z bkarwin $ + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ @@ -30,7 +30,7 @@ * @category Zend * @package Zend_Http * @subpackage Client_Adapter - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Client_Adapter_Interface diff --git a/libs/Zend/Http/Client/Adapter/Proxy.php b/libs/Zend/Http/Client/Adapter/Proxy.php index 932b1b66b6..d8c90dcd22 100644 --- a/libs/Zend/Http/Client/Adapter/Proxy.php +++ b/libs/Zend/Http/Client/Adapter/Proxy.php @@ -16,8 +16,8 @@ * @category Zend * @package Zend_Http * @subpackage Client_Adapter - * @version $Id: Proxy.php 17118 2009-07-26 09:41:41Z shahar $ - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @version $Id: Proxy.php 20096 2010-01-06 02:05:09Z bkarwin $ + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ @@ -46,7 +46,7 @@ require_once 'Zend/Http/Client/Adapter/Socket.php'; * @category Zend * @package Zend_Http * @subpackage Client_Adapter - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Client_Adapter_Proxy extends Zend_Http_Client_Adapter_Socket diff --git a/libs/Zend/Http/Client/Adapter/Socket.php b/libs/Zend/Http/Client/Adapter/Socket.php index 51e453b3b1..2e6813ce49 100644 --- a/libs/Zend/Http/Client/Adapter/Socket.php +++ b/libs/Zend/Http/Client/Adapter/Socket.php @@ -16,8 +16,8 @@ * @category Zend * @package Zend_Http * @subpackage Client_Adapter - * @version $Id: Socket.php 19309 2009-11-30 11:03:01Z bate $ - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @version $Id: Socket.php 20096 2010-01-06 02:05:09Z bkarwin $ + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ @@ -41,7 +41,7 @@ require_once 'Zend/Http/Client/Adapter/Stream.php'; * @category Zend * @package Zend_Http * @subpackage Client_Adapter - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Client_Adapter_Socket implements Zend_Http_Client_Adapter_Interface, Zend_Http_Client_Adapter_Stream diff --git a/libs/Zend/Http/Client/Adapter/Stream.php b/libs/Zend/Http/Client/Adapter/Stream.php index 7e0df1284c..58dd921f20 100644 --- a/libs/Zend/Http/Client/Adapter/Stream.php +++ b/libs/Zend/Http/Client/Adapter/Stream.php @@ -16,8 +16,8 @@ * @category Zend * @package Zend_Http * @subpackage Client_Adapter - * @version $Id: Stream.php 19309 2009-11-30 11:03:01Z bate $ - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @version $Id: Interface.php 16214 2009-06-21 19:34:03Z thomas $ + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ @@ -29,7 +29,7 @@ * @category Zend * @package Zend_Http * @subpackage Client_Adapter - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Client_Adapter_Stream diff --git a/libs/Zend/Http/Client/Adapter/Test.php b/libs/Zend/Http/Client/Adapter/Test.php index 5d2838633c..82e9f04118 100644 --- a/libs/Zend/Http/Client/Adapter/Test.php +++ b/libs/Zend/Http/Client/Adapter/Test.php @@ -15,8 +15,8 @@ * @category Zend * @package Zend_Http * @subpackage Client_Adapter - * @version $Id: Test.php 19309 2009-11-30 11:03:01Z bate $ - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @version $Id: Test.php 20096 2010-01-06 02:05:09Z bkarwin $ + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ @@ -44,7 +44,7 @@ require_once 'Zend/Http/Client/Adapter/Interface.php'; * @category Zend * @package Zend_Http * @subpackage Client_Adapter - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Client_Adapter_Test implements Zend_Http_Client_Adapter_Interface diff --git a/libs/Zend/Http/Client/Exception.php b/libs/Zend/Http/Client/Exception.php index 6d5efdf27e..8d47dcbff6 100644 --- a/libs/Zend/Http/Client/Exception.php +++ b/libs/Zend/Http/Client/Exception.php @@ -15,8 +15,8 @@ * @category Zend * @package Zend_Http * @subpackage Client_Exception - * @version $Id: Exception.php 16872 2009-07-20 11:47:08Z mikaelkael $ - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @version $Id: Exception.php 20096 2010-01-06 02:05:09Z bkarwin $ + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ @@ -29,7 +29,7 @@ require_once 'Zend/Http/Exception.php'; * @category Zend * @package Zend_Http * @subpackage Client - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Client_Exception extends Zend_Http_Exception diff --git a/libs/Zend/Http/Cookie.php b/libs/Zend/Http/Cookie.php index d8e278898a..498d25f418 100644 --- a/libs/Zend/Http/Cookie.php +++ b/libs/Zend/Http/Cookie.php @@ -16,8 +16,8 @@ * @category Zend * @package Zend_Http * @subpackage Cookie - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) - * @version $Id: Cookie.php 17124 2009-07-26 09:46:42Z shahar $ + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @version $Id: Cookie.php 20096 2010-01-06 02:05:09Z bkarwin $ * @license http://framework.zend.com/license/new-bsd New BSD License */ @@ -41,7 +41,7 @@ require_once 'Zend/Uri/Http.php'; * * @category Zend * @package Zend_Http - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Cookie diff --git a/libs/Zend/Http/CookieJar.php b/libs/Zend/Http/CookieJar.php index 59afdfbd52..9253479cf0 100644 --- a/libs/Zend/Http/CookieJar.php +++ b/libs/Zend/Http/CookieJar.php @@ -15,8 +15,8 @@ * @category Zend * @package Zend_Http * @subpackage CookieJar - * @version $Id: CookieJar.php 17124 2009-07-26 09:46:42Z shahar $ - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @version $Id: CookieJar.php 20096 2010-01-06 02:05:09Z bkarwin $ + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ @@ -54,7 +54,7 @@ require_once "Zend/Http/Response.php"; * @category Zend * @package Zend_Http * @subpackage CookieJar - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_CookieJar implements Countable, IteratorAggregate diff --git a/libs/Zend/Http/Exception.php b/libs/Zend/Http/Exception.php index 93a3869153..099dfde48b 100644 --- a/libs/Zend/Http/Exception.php +++ b/libs/Zend/Http/Exception.php @@ -15,8 +15,8 @@ * @category Zend * @package Zend_Http * @subpackage Exception - * @version $Id: Exception.php 16872 2009-07-20 11:47:08Z mikaelkael $ - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @version $Id: Exception.php 20096 2010-01-06 02:05:09Z bkarwin $ + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ @@ -29,7 +29,7 @@ require_once 'Zend/Exception.php'; * @category Zend * @package Zend_Http * @subpackage Client - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Exception extends Zend_Exception diff --git a/libs/Zend/Http/Response.php b/libs/Zend/Http/Response.php index 9db70f4e25..b4d8847ba2 100644 --- a/libs/Zend/Http/Response.php +++ b/libs/Zend/Http/Response.php @@ -16,8 +16,8 @@ * @category Zend * @package Zend_Http * @subpackage Response - * @version $Id: Response.php 17124 2009-07-26 09:46:42Z shahar $ - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @version $Id: Response.php 20096 2010-01-06 02:05:09Z bkarwin $ + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ @@ -28,7 +28,7 @@ * * @package Zend_Http * @subpackage Response - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Response diff --git a/libs/Zend/Http/Response/Stream.php b/libs/Zend/Http/Response/Stream.php index 0dea34d2f4..667ca321ab 100644 --- a/libs/Zend/Http/Response/Stream.php +++ b/libs/Zend/Http/Response/Stream.php @@ -16,8 +16,8 @@ * @category Zend * @package Zend_Http * @subpackage Response - * @version $Id: Stream.php 19309 2009-11-30 11:03:01Z bate $ - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @version $Id: Response.php 17131 2009-07-26 10:03:39Z 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 */ @@ -28,7 +28,7 @@ * * @package Zend_Http * @subpackage Response - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Response_Stream extends Zend_Http_Response @@ -39,23 +39,23 @@ class Zend_Http_Response_Stream extends Zend_Http_Response * @var resource */ protected $stream; - + /** * The name of the file containing the stream - * + * * Will be empty if stream is not file-based. - * + * * @var string */ protected $stream_name; - /* * + /** * Should we clean up the stream file when this response is closed? - * + * * @var boolean */ protected $_cleanup; - + /** * Get the response as stream * @@ -65,7 +65,7 @@ class Zend_Http_Response_Stream extends Zend_Http_Response { return $this->stream; } - + /** * Set the response stream * @@ -78,45 +78,45 @@ class Zend_Http_Response_Stream extends Zend_Http_Response return $this; } - /** - * Get the cleanup trigger - * - * @return boolean - */
- public function getCleanup() {
- return $this->_cleanup;
- }
- - /** - * Set the cleanup trigger - * - * @param $cleanup Set cleanup trigger - */
- public function setCleanup($cleanup = true) {
- $this->_cleanup = $cleanup;
- }
+ /** + * Get the cleanup trigger + * + * @return boolean + */ + public function getCleanup() { + return $this->_cleanup; + } + + /** + * Set the cleanup trigger + * + * @param $cleanup Set cleanup trigger + */ + public function setCleanup($cleanup = true) { + $this->_cleanup = $cleanup; + } /** * Get file name associated with the stream - * - * @return string - */ - public function getStreamName() { - return $this->stream_name; - } - - /** - * Set file name associated with the stream - * - * @param string $stream_name Name to set - * @return Zend_Http_Response_Stream - */ - public function setStreamName($stream_name) { - $this->stream_name = $stream_name; - return $this; - } - - + * + * @return string + */ + public function getStreamName() { + return $this->stream_name; + } + + /** + * Set file name associated with the stream + * + * @param string $stream_name Name to set + * @return Zend_Http_Response_Stream + */ + public function setStreamName($stream_name) { + $this->stream_name = $stream_name; + return $this; + } + + /** * HTTP response constructor * @@ -136,17 +136,16 @@ class Zend_Http_Response_Stream extends Zend_Http_Response * @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, $headers, $body = null, $version = '1.1', $message = null) { - + if(is_resource($body)) { $this->setStream($body); $body = ''; } parent::__construct($code, $headers, $body, $version, $message); } - + /** * Create a new Zend_Http_Response_Stream object from a string * @@ -163,7 +162,7 @@ class Zend_Http_Response_Stream extends Zend_Http_Response return new self($code, $headers, $stream, $version, $message); } - + /** * Get the response body as string * @@ -183,7 +182,7 @@ class Zend_Http_Response_Stream extends Zend_Http_Response } return parent::getBody(); } - + /** * Get the raw response body (as transfered "on wire") as string * @@ -199,12 +198,12 @@ class Zend_Http_Response_Stream extends Zend_Http_Response } return $this->body; } - + /** * Read stream content and return it as string - * + * * Function reads the remainder of the body from the stream and closes the stream. - * + * * @return string */ protected function readStream() @@ -221,7 +220,7 @@ class Zend_Http_Response_Stream extends Zend_Http_Response fclose($this->stream); $this->stream = null; } - + public function __destruct() { if(is_resource($this->stream)) { @@ -232,5 +231,5 @@ class Zend_Http_Response_Stream extends Zend_Http_Response @unlink($this->stream_name); } } - + } diff --git a/libs/Zend/Loader.php b/libs/Zend/Loader.php index 981d4afc79..9024c2ccb6 100644 --- a/libs/Zend/Loader.php +++ b/libs/Zend/Loader.php @@ -14,9 +14,9 @@ * * @category Zend * @package Zend_Loader - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 19241 2009-11-25 17:17:31Z bate $ + * @version $Id: Loader.php 20620 2010-01-25 20:18:08Z matthew $ */ /** @@ -24,7 +24,7 @@ * * @category Zend * @package Zend_Loader - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Loader @@ -60,8 +60,20 @@ class Zend_Loader throw new Zend_Exception('Directory argument must be a string or an array'); } - // autodiscover the path from the class name - $file = str_replace('_', DIRECTORY_SEPARATOR, $class) . '.php'; + // Autodiscover the path from the class name + // 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, '\\'); + $file = ''; + $namespace = ''; + if ($lastNsPos = strripos($className, '\\')) { + $namespace = substr($className, 0, $lastNsPos); + $className = substr($className, $lastNsPos + 1); + $file = str_replace('\\', DIRECTORY_SEPARATOR, $namespace) . DIRECTORY_SEPARATOR; + } + $file .= str_replace('_', DIRECTORY_SEPARATOR, $className) . '.php'; + if (!empty($dirs)) { // use the autodiscovered path $dirPath = dirname($file); @@ -79,7 +91,7 @@ class Zend_Loader $file = basename($file); self::loadFile($file, $dirs, true); } else { - self::loadFile($file); + self::loadFile($file, null, true); } if (!class_exists($class, false) && !interface_exists($class, false)) { @@ -161,6 +173,11 @@ class Zend_Loader */ public static function isReadable($filename) { + // Phar occasionally fails when using fopen() + if (strpos($filename, 'phar://') !== false) { + return is_readable($filename); + } + if (!$fh = @fopen($filename, 'r', true)) { return false; } diff --git a/libs/Zend/Loader/Autoloader.php b/libs/Zend/Loader/Autoloader.php index 82aecf01f7..11ddf6eca4 100644 --- a/libs/Zend/Loader/Autoloader.php +++ b/libs/Zend/Loader/Autoloader.php @@ -15,8 +15,8 @@ * @category Zend * @package Zend_Loader * @subpackage Autoloader - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) - * @version $Id: Autoloader.php 18951 2009-11-12 16:26:19Z alexander $ + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @version $Id: Autoloader.php 20096 2010-01-06 02:05:09Z bkarwin $ * @license http://framework.zend.com/license/new-bsd New BSD License */ @@ -29,7 +29,7 @@ require_once 'Zend/Loader.php'; * @uses Zend_Loader_Autoloader * @package Zend_Loader * @subpackage Autoloader - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Loader_Autoloader diff --git a/libs/Zend/Loader/Autoloader/Interface.php b/libs/Zend/Loader/Autoloader/Interface.php index 9e7ffca486..8bcaf14fb2 100644 --- a/libs/Zend/Loader/Autoloader/Interface.php +++ b/libs/Zend/Loader/Autoloader/Interface.php @@ -15,8 +15,8 @@ * @category Zend * @package Zend_Loader * @subpackage Autoloader - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) - * @version $Id: Interface.php 18951 2009-11-12 16:26:19Z alexander $ + * @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 $ * @license http://framework.zend.com/license/new-bsd New BSD License */ @@ -25,7 +25,7 @@ * * @package Zend_Loader * @subpackage Autoloader - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Loader_Autoloader_Interface diff --git a/libs/Zend/Loader/Autoloader/Resource.php b/libs/Zend/Loader/Autoloader/Resource.php index b85e9e0556..8eddbbcec5 100644 --- a/libs/Zend/Loader/Autoloader/Resource.php +++ b/libs/Zend/Loader/Autoloader/Resource.php @@ -15,8 +15,8 @@ * @category Zend * @package Zend_Loader * @subpackage Autoloader - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) - * @version $Id: Resource.php 19190 2009-11-23 12:43:42Z bate $ + * @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 $ * @license http://framework.zend.com/license/new-bsd New BSD License */ @@ -29,7 +29,7 @@ require_once 'Zend/Loader/Autoloader/Interface.php'; * @uses Zend_Loader_Autoloader_Interface * @package Zend_Loader * @subpackage Autoloader - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Loader_Autoloader_Resource implements Zend_Loader_Autoloader_Interface diff --git a/libs/Zend/Loader/Exception.php b/libs/Zend/Loader/Exception.php index 03420646b4..0b1f683d0d 100644 --- a/libs/Zend/Loader/Exception.php +++ b/libs/Zend/Loader/Exception.php @@ -14,9 +14,9 @@ * * @category Zend * @package Zend_Loader - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 18951 2009-11-12 16:26:19Z alexander $ + * @version $Id: Exception.php 20096 2010-01-06 02:05:09Z bkarwin $ */ /** @@ -28,7 +28,7 @@ require_once 'Zend/Exception.php'; * @category Zend * @package Zend_Loader * @uses Zend_Exception - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Loader_Exception extends Zend_Exception diff --git a/libs/Zend/Loader/PluginLoader.php b/libs/Zend/Loader/PluginLoader.php index d4407628b4..bd70375357 100644 --- a/libs/Zend/Loader/PluginLoader.php +++ b/libs/Zend/Loader/PluginLoader.php @@ -15,9 +15,9 @@ * @category Zend * @package Zend_Loader * @subpackage PluginLoader - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 18951 2009-11-12 16:26:19Z alexander $ + * @version $Id: PluginLoader.php 20096 2010-01-06 02:05:09Z bkarwin $ */ /** Zend_Loader_PluginLoader_Interface */ @@ -32,7 +32,7 @@ require_once 'Zend/Loader.php'; * @category Zend * @package Zend_Loader * @subpackage PluginLoader - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Loader_PluginLoader implements Zend_Loader_PluginLoader_Interface diff --git a/libs/Zend/Loader/PluginLoader/Exception.php b/libs/Zend/Loader/PluginLoader/Exception.php index 9e0a744e5f..4388313fc5 100644 --- a/libs/Zend/Loader/PluginLoader/Exception.php +++ b/libs/Zend/Loader/PluginLoader/Exception.php @@ -15,9 +15,9 @@ * @category Zend * @package Zend_Loader * @subpackage PluginLoader - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 16971 2009-07-22 18:05:45Z mikaelkael $ + * @version $Id: Exception.php 20096 2010-01-06 02:05:09Z bkarwin $ */ /** @@ -31,7 +31,7 @@ require_once 'Zend/Loader/Exception.php'; * @category Zend * @package Zend_Loader * @subpackage PluginLoader - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Loader_PluginLoader_Exception extends Zend_Loader_Exception diff --git a/libs/Zend/Loader/PluginLoader/Interface.php b/libs/Zend/Loader/PluginLoader/Interface.php index cdefa107b1..bfbbe50e3c 100644 --- a/libs/Zend/Loader/PluginLoader/Interface.php +++ b/libs/Zend/Loader/PluginLoader/Interface.php @@ -15,9 +15,9 @@ * @category Zend * @package Zend_Loader * @subpackage PluginLoader - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 18951 2009-11-12 16:26:19Z alexander $ + * @version $Id: Interface.php 20096 2010-01-06 02:05:09Z bkarwin $ */ /** @@ -26,7 +26,7 @@ * @category Zend * @package Zend_Loader * @subpackage PluginLoader - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Loader_PluginLoader_Interface diff --git a/libs/Zend/Log.php b/libs/Zend/Log.php index 4e5c96f07e..fc849f1244 100644 --- a/libs/Zend/Log.php +++ b/libs/Zend/Log.php @@ -14,17 +14,17 @@ * * @category Zend * @package Zend_Log - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 18951 2009-11-12 16:26:19Z alexander $ + * @version $Id: Log.php 20096 2010-01-06 02:05:09Z bkarwin $ */ /** * @category Zend * @package Zend_Log - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 18951 2009-11-12 16:26:19Z alexander $ + * @version $Id: Log.php 20096 2010-01-06 02:05:09Z bkarwin $ */ class Zend_Log { @@ -59,6 +59,19 @@ class Zend_Log protected $_extras = array(); /** + * + * @var string + */ + protected $_defaultWriterNamespace = 'Zend_Log_Writer'; + + /** + * + * @var string + */ + protected $_defaultFilterNamespace = 'Zend_Log_Filter'; + + + /** * Class constructor. Create a new logger * * @param Zend_Log_Writer_Abstract|null $writer default writer @@ -74,6 +87,146 @@ class Zend_Log } /** + * Factory to construct the logger and one or more writers + * based on the configuration array + * + * @param array|Zend_Config Array or instance of Zend_Config + * @return Zend_Log + */ + static public function factory($config = array()) + { + if ($config instanceof Zend_Config) { + $config = $config->toArray(); + } + + if (!is_array($config) || empty($config)) { + /** @see Zend_Log_Exception */ + require_once 'Zend/Log/Exception.php'; + throw new Zend_Log_Exception('Configuration must be an array or instance of Zend_Config'); + } + + $log = new Zend_Log; + + if (!is_array(current($config))) { + $log->addWriter(current($config)); + } else { + foreach($config as $writer) { + $log->addWriter($writer); + } + } + + return $log; + } + + + /** + * Construct a writer object based on a configuration array + * + * @param array $spec config array with writer spec + * @return Zend_Log_Writer_Abstract + */ + protected function _constructWriterFromConfig($config) + { + $writer = $this->_constructFromConfig('writer', $config, $this->_defaultWriterNamespace); + + if (!$writer instanceof Zend_Log_Writer_Abstract) { + /** @see Zend_Log_Exception */ + require_once 'Zend/Log/Exception.php'; + throw new Zend_Log_Exception("{$writerName} does not extend Zend_Log_Writer_Abstract!"); + } + + if (isset($config['filterName'])) { + $filter = $this->_constructFilterFromConfig($config); + $writer->addFilter($filter); + } + + return $writer; + } + + /** + * Construct filter object from configuration array or Zend_Config object + * + * @param array|Zend_Config $config Zend_Config or Array + * @return Zend_Log_Filter_Interface + */ + protected function _constructFilterFromConfig($config) + { + $filter = $this->_constructFromConfig('filter', $config, $this->_defaultFilterNamespace); + + if (!$filter instanceof Zend_Log_Filter_Interface) { + /** @see Zend_Log_Exception */ + require_once 'Zend/Log/Exception.php'; + throw new Zend_Log_Exception("{$filterName} does not implement Zend_Log_Filter_Interface"); + } + + return $filter; + } + + /** + * Construct a filter or writer from config + * + * @param string $type 'writer' of 'filter' + * @param mixed $config Zend_Config or Array + * @param string $namespace + * @return object + */ + protected function _constructFromConfig($type, $config, $namespace) + { + if ($config instanceof Zend_Config) { + $config = $config->toArray(); + } + + if (!is_array($config) || empty($config)) { + require_once 'Zend_Log_Exception.php'; + throw new Zend_Log_Exception( + 'Configuration must be an array or instance of Zend_Config' + ); + } + + $params = isset($config[ $type .'Params' ]) ? $config[ $type .'Params' ] : array(); + $className = $this->getClassName($config, $type, $namespace); + if (!class_exists($className)) { + require_once 'Zend/Loader.php'; + Zend_Loader::loadClass($className); + } + + $reflection = new ReflectionClass($className); + if (!$reflection->implementsInterface('Zend_Log_FactoryInterface')) { + require_once 'Zend/Log/Exception.php'; + throw new Zend_Log_Exception( + 'Driver does not implement Zend_Log_FactoryInterface and can not be constructed from config.' + ); + } + + return call_user_func(array($className, 'factory'), $params); + } + + /** + * Get the writer or filter full classname + * + * @param array $config + * @param string $type filter|writer + * @param string $defaultNamespace + * @return string full classname + */ + protected function getClassName($config, $type, $defaultNamespace) + { + if (!isset($config[ $type . 'Name' ])) { + require_once 'Zend/Log/Exception.php'; + throw new Zend_Log_Exception("Specify {$type}Name in the configuration array"); + } + $className = $config[ $type . 'Name' ]; + + $namespace = $defaultNamespace; + if (isset($config[ $type . 'Namespace' ])) { + $namespace = $config[ $type . 'Namespace' ]; + } + + $fullClassName = $namespace . '_' . $className; + return $fullClassName; + } + + /** * Class destructor. Shutdown log writers * * @return void @@ -100,7 +253,21 @@ class Zend_Log { $priority = strtoupper($method); if (($priority = array_search($priority, $this->_priorities)) !== false) { - $this->log(array_shift($params), $priority); + switch (count($params)) { + case 0: + /** @see Zend_Log_Exception */ + require_once 'Zend/Log/Exception.php'; + throw new Zend_Log_Exception('Missing log message'); + case 1: + $message = array_shift($params); + $extras = null; + break; + default: + $message = array_shift($params); + $extras = array_shift($params); + break; + } + $this->log($message, $priority, $extras); } else { /** @see Zend_Log_Exception */ require_once 'Zend/Log/Exception.php'; @@ -113,10 +280,11 @@ class Zend_Log * * @param string $message Message to log * @param integer $priority Priority of message + * @param mixed $extras Extra information to log in event * @return void * @throws Zend_Log_Exception */ - public function log($message, $priority) + public function log($message, $priority, $extras = null) { // sanity checks if (empty($this->_writers)) { @@ -138,6 +306,25 @@ class Zend_Log 'priorityName' => $this->_priorities[$priority]), $this->_extras); + // Check to see if any extra information was passed + if (!empty($extras)) { + $info = array(); + if (is_array($extras)) { + foreach ($extras as $key => $value) { + if (is_string($key)) { + $event[$key] = $value; + } else { + $info[] = $value; + } + } + } else { + $info = $extras; + } + if (!empty($info)) { + $event['info'] = $info; + } + } + // abort if rejected by the global filters foreach ($this->_filters as $filter) { if (! $filter->accept($event)) { @@ -187,7 +374,11 @@ class Zend_Log /** @see Zend_Log_Filter_Priority */ require_once 'Zend/Log/Filter/Priority.php'; $filter = new Zend_Log_Filter_Priority($filter); - } elseif(!is_object($filter) || ! $filter instanceof Zend_Log_Filter_Interface) { + + } elseif ($filter instanceof Zend_Config || is_array($filter)) { + $filter = $this->_constructFilterFromConfig($filter); + + } elseif(! $filter instanceof Zend_Log_Filter_Interface) { /** @see Zend_Log_Exception */ require_once 'Zend/Log/Exception.php'; throw new Zend_Log_Exception('Invalid filter provided'); @@ -200,11 +391,24 @@ class Zend_Log * Add a writer. A writer is responsible for taking a log * message and writing it out to storage. * - * @param Zend_Log_Writer_Abstract $writer + * @param mixed $writer Zend_Log_Writer_Abstract or Config array * @return void */ - public function addWriter(Zend_Log_Writer_Abstract $writer) + public function addWriter($writer) { + if (is_array($writer) || $writer instanceof Zend_Config) { + $writer = $this->_constructWriterFromConfig($writer); + } + + if (!$writer instanceof Zend_Log_Writer_Abstract) { + /** @see Zend_Log_Exception */ + require_once 'Zend/Log/Exception.php'; + throw new Zend_Log_Exception( + 'Writer must be an instance of Zend_Log_Writer_Abstract' + . ' or you should pass a configuration array' + ); + } + $this->_writers[] = $writer; } @@ -218,5 +422,4 @@ class Zend_Log public function setEventItem($name, $value) { $this->_extras = array_merge($this->_extras, array($name => $value)); } - } diff --git a/libs/Zend/Log/Exception.php b/libs/Zend/Log/Exception.php index 4290898cdd..08557db8fb 100644 --- a/libs/Zend/Log/Exception.php +++ b/libs/Zend/Log/Exception.php @@ -14,9 +14,9 @@ * * @category Zend * @package Zend_Log - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 16219 2009-06-21 19:45:39Z thomas $ + * @version $Id: Exception.php 20096 2010-01-06 02:05:09Z bkarwin $ */ /** Zend_Exception */ @@ -25,9 +25,9 @@ require_once 'Zend/Exception.php'; /** * @category Zend * @package Zend_Log - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 16219 2009-06-21 19:45:39Z thomas $ + * @version $Id: Exception.php 20096 2010-01-06 02:05:09Z bkarwin $ */ class Zend_Log_Exception extends Zend_Exception {} diff --git a/libs/Zend/Log/FactoryInterface.php b/libs/Zend/Log/FactoryInterface.php new file mode 100644 index 0000000000..20a270747f --- /dev/null +++ b/libs/Zend/Log/FactoryInterface.php @@ -0,0 +1,38 @@ +<?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_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$ + */ + +/** + * @category Zend + * @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$ + */ +interface Zend_Log_FactoryInterface +{ + /** + * Construct a Zend_Log driver + * + * @param array|Zen_Config $config + * @return Zend_Log_FactoryInterface + */ + static public function factory($config); +} diff --git a/libs/Zend/Log/Filter/Abstract.php b/libs/Zend/Log/Filter/Abstract.php new file mode 100644 index 0000000000..8253c3b98a --- /dev/null +++ b/libs/Zend/Log/Filter/Abstract.php @@ -0,0 +1,60 @@ +<?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_Log + * @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$ + */ + +/** @see Zend_Log_Filter_Interface */ +require_once 'Zend/Log/Filter/Interface.php'; + +/** @see Zend_Log_FactoryInterface */ +require_once 'Zend/Log/FactoryInterface.php'; + +/** + * @category Zend + * @package Zend_Log + * @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 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 + */ + static protected function _parseConfig($config) + { + if ($config instanceof Zend_Config) { + $config = $config->asArray(); + } + + 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'); + } + + return $config; + } +} diff --git a/libs/Zend/Log/Filter/Interface.php b/libs/Zend/Log/Filter/Interface.php index 104b578f91..c2165d2ba6 100644 --- a/libs/Zend/Log/Filter/Interface.php +++ b/libs/Zend/Log/Filter/Interface.php @@ -15,18 +15,18 @@ * @category Zend * @package Zend_Log * @subpackage Filter - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 16219 2009-06-21 19:45:39Z thomas $ + * @version $Id: Interface.php 20096 2010-01-06 02:05:09Z bkarwin $ */ /** * @category Zend * @package Zend_Log * @subpackage Filter - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 16219 2009-06-21 19:45:39Z thomas $ + * @version $Id: Interface.php 20096 2010-01-06 02:05:09Z bkarwin $ */ interface Zend_Log_Filter_Interface { @@ -37,5 +37,4 @@ interface Zend_Log_Filter_Interface * @return boolean accepted? */ public function accept($event); - } diff --git a/libs/Zend/Log/Filter/Message.php b/libs/Zend/Log/Filter/Message.php index 9a05deaedf..5797a19be0 100644 --- a/libs/Zend/Log/Filter/Message.php +++ b/libs/Zend/Log/Filter/Message.php @@ -15,9 +15,9 @@ * @category Zend * @package Zend_Log * @subpackage Filter - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 16219 2009-06-21 19:45:39Z thomas $ + * @version $Id: Message.php 20096 2010-01-06 02:05:09Z bkarwin $ */ /** Zend_Log_Filter_Interface */ @@ -27,11 +27,11 @@ require_once 'Zend/Log/Filter/Interface.php'; * @category Zend * @package Zend_Log * @subpackage Filter - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 16219 2009-06-21 19:45:39Z thomas $ + * @version $Id: Message.php 20096 2010-01-06 02:05:09Z bkarwin $ */ -class Zend_Log_Filter_Message implements Zend_Log_Filter_Interface +class Zend_Log_Filter_Message extends Zend_Log_Filter_Abstract { /** * @var string @@ -54,6 +54,25 @@ class Zend_Log_Filter_Message implements Zend_Log_Filter_Interface } /** + * 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) + { + $config = self::_parseConfig($config); + $config = array_merge(array( + 'regexp' => null + ), $config); + + return new self( + $config['regexp'] + ); + } + + /** * Returns TRUE to accept the message, FALSE to block it. * * @param array $event event data @@ -63,5 +82,4 @@ class Zend_Log_Filter_Message implements Zend_Log_Filter_Interface { return preg_match($this->_regexp, $event['message']) > 0; } - } diff --git a/libs/Zend/Log/Filter/Priority.php b/libs/Zend/Log/Filter/Priority.php index d19c3f9ec6..1835c9a299 100644 --- a/libs/Zend/Log/Filter/Priority.php +++ b/libs/Zend/Log/Filter/Priority.php @@ -15,23 +15,23 @@ * @category Zend * @package Zend_Log * @subpackage Filter - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 16219 2009-06-21 19:45:39Z thomas $ + * @version $Id: Priority.php 20260 2010-01-13 18:29:22Z ralph $ */ -/** Zend_Log_Filter_Interface */ -require_once 'Zend/Log/Filter/Interface.php'; +/** Zend_Log_Filter_Abstract */ +require_once 'Zend/Log/Filter/Abstract.php'; /** * @category Zend * @package Zend_Log * @subpackage Filter - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 16219 2009-06-21 19:45:39Z thomas $ + * @version $Id: Priority.php 20260 2010-01-13 18:29:22Z ralph $ */ -class Zend_Log_Filter_Priority implements Zend_Log_Filter_Interface +class Zend_Log_Filter_Priority extends Zend_Log_Filter_Abstract { /** * @var integer @@ -51,7 +51,7 @@ class Zend_Log_Filter_Priority implements Zend_Log_Filter_Interface * @param string $operator Comparison operator * @throws Zend_Log_Exception */ - public function __construct($priority, $operator = '<=') + public function __construct($priority, $operator = NULL) { if (! is_integer($priority)) { require_once 'Zend/Log/Exception.php'; @@ -59,7 +59,33 @@ class Zend_Log_Filter_Priority implements Zend_Log_Filter_Interface } $this->_priority = $priority; - $this->_operator = $operator; + $this->_operator = is_null($operator) ? '<=' : $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) + { + $config = self::_parseConfig($config); + $config = array_merge(array( + 'priority' => null, + 'operator' => null, + ), $config); + + // Add support for constants + if (!is_numeric($config['priority']) && isset($config['priority']) && defined($config['priority'])) { + $config['priority'] = constant($config['priority']); + } + + return new self( + (int) $config['priority'], + $config['operator'] + ); } /** @@ -72,5 +98,4 @@ class Zend_Log_Filter_Priority implements Zend_Log_Filter_Interface { return version_compare($event['priority'], $this->_priority, $this->_operator); } - } diff --git a/libs/Zend/Log/Filter/Suppress.php b/libs/Zend/Log/Filter/Suppress.php index 026db36727..14b74ae603 100644 --- a/libs/Zend/Log/Filter/Suppress.php +++ b/libs/Zend/Log/Filter/Suppress.php @@ -15,9 +15,9 @@ * @category Zend * @package Zend_Log * @subpackage Filter - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 16219 2009-06-21 19:45:39Z thomas $ + * @version $Id: Suppress.php 20096 2010-01-06 02:05:09Z bkarwin $ */ /** Zend_Log_Filter_Interface */ @@ -27,11 +27,11 @@ require_once 'Zend/Log/Filter/Interface.php'; * @category Zend * @package Zend_Log * @subpackage Filter - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 16219 2009-06-21 19:45:39Z thomas $ + * @version $Id: Suppress.php 20096 2010-01-06 02:05:09Z bkarwin $ */ -class Zend_Log_Filter_Suppress implements Zend_Log_Filter_Interface +class Zend_Log_Filter_Suppress extends Zend_Log_Filter_Abstract { /** * @var boolean @@ -63,4 +63,15 @@ class Zend_Log_Filter_Suppress implements Zend_Log_Filter_Interface return $this->_accept; } + /** + * Create a new instance of Zend_Log_Filter_Suppress + * + * @param array|Zend_Config $config + * @return Zend_Log_Filter_Suppress + * @throws Zend_Log_Exception + */ + static public function factory($config) + { + return new self(); + } } diff --git a/libs/Zend/Log/Formatter/Firebug.php b/libs/Zend/Log/Formatter/Firebug.php index a5a672e04a..ef155a5999 100644 --- a/libs/Zend/Log/Formatter/Firebug.php +++ b/libs/Zend/Log/Formatter/Firebug.php @@ -15,9 +15,9 @@ * @category Zend * @package Zend_Log * @subpackage Formatter - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 18951 2009-11-12 16:26:19Z alexander $ + * @version $Id: Firebug.php 20096 2010-01-06 02:05:09Z bkarwin $ */ /** Zend_Log_Formatter_Interface */ @@ -27,7 +27,7 @@ require_once 'Zend/Log/Formatter/Interface.php'; * @category Zend * @package Zend_Log * @subpackage Formatter - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Log_Formatter_Firebug implements Zend_Log_Formatter_Interface diff --git a/libs/Zend/Log/Formatter/Interface.php b/libs/Zend/Log/Formatter/Interface.php index 000734f393..2d05145a3f 100644 --- a/libs/Zend/Log/Formatter/Interface.php +++ b/libs/Zend/Log/Formatter/Interface.php @@ -15,18 +15,18 @@ * @category Zend * @package Zend_Log * @subpackage Formatter - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 16219 2009-06-21 19:45:39Z thomas $ + * @version $Id: Interface.php 20096 2010-01-06 02:05:09Z bkarwin $ */ /** * @category Zend * @package Zend_Log * @subpackage Formatter - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 16219 2009-06-21 19:45:39Z thomas $ + * @version $Id: Interface.php 20096 2010-01-06 02:05:09Z bkarwin $ */ interface Zend_Log_Formatter_Interface { diff --git a/libs/Zend/Log/Formatter/Simple.php b/libs/Zend/Log/Formatter/Simple.php index 0761404742..c53b7c0d60 100644 --- a/libs/Zend/Log/Formatter/Simple.php +++ b/libs/Zend/Log/Formatter/Simple.php @@ -15,9 +15,9 @@ * @category Zend * @package Zend_Log * @subpackage Formatter - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 16219 2009-06-21 19:45:39Z thomas $ + * @version $Id: Simple.php 20096 2010-01-06 02:05:09Z bkarwin $ */ /** Zend_Log_Formatter_Interface */ @@ -27,9 +27,9 @@ require_once 'Zend/Log/Formatter/Interface.php'; * @category Zend * @package Zend_Log * @subpackage Formatter - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 16219 2009-06-21 19:45:39Z thomas $ + * @version $Id: Simple.php 20096 2010-01-06 02:05:09Z bkarwin $ */ class Zend_Log_Formatter_Simple implements Zend_Log_Formatter_Interface { diff --git a/libs/Zend/Log/Formatter/Xml.php b/libs/Zend/Log/Formatter/Xml.php index 76f6da516e..a0af504bc2 100644 --- a/libs/Zend/Log/Formatter/Xml.php +++ b/libs/Zend/Log/Formatter/Xml.php @@ -15,9 +15,9 @@ * @category Zend * @package Zend_Log * @subpackage Formatter - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 20105 2010-01-06 21:28:26Z matthew $ + * @version $Id: Xml.php 20104 2010-01-06 21:26:01Z matthew $ */ /** Zend_Log_Formatter_Interface */ @@ -27,9 +27,9 @@ require_once 'Zend/Log/Formatter/Interface.php'; * @category Zend * @package Zend_Log * @subpackage Formatter - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 20105 2010-01-06 21:28:26Z matthew $ + * @version $Id: Xml.php 20104 2010-01-06 21:26:01Z matthew $ */ class Zend_Log_Formatter_Xml implements Zend_Log_Formatter_Interface { diff --git a/libs/Zend/Log/Writer/Abstract.php b/libs/Zend/Log/Writer/Abstract.php index 3e3be2d6cd..979375a83f 100644 --- a/libs/Zend/Log/Writer/Abstract.php +++ b/libs/Zend/Log/Writer/Abstract.php @@ -15,9 +15,9 @@ * @category Zend * @package Zend_Log * @subpackage Writer - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 16219 2009-06-21 19:45:39Z thomas $ + * @version $Id: Abstract.php 20096 2010-01-06 02:05:09Z bkarwin $ */ /** Zend_Log_Filter_Priority */ @@ -27,11 +27,11 @@ require_once 'Zend/Log/Filter/Priority.php'; * @category Zend * @package Zend_Log * @subpackage Writer - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 16219 2009-06-21 19:45:39Z thomas $ + * @version $Id: Abstract.php 20096 2010-01-06 02:05:09Z bkarwin $ */ -abstract class Zend_Log_Writer_Abstract +abstract class Zend_Log_Writer_Abstract implements Zend_Log_FactoryInterface { /** * @var array of Zend_Log_Filter_Interface @@ -104,4 +104,26 @@ abstract class Zend_Log_Writer_Abstract */ abstract protected function _write($event); -}
\ No newline at end of file + /** + * Validate and optionally convert the config to array + * + * @param array|Zend_Config $config Zend_Config or Array + * @return array + * @throws Zend_Log_Exception + */ + static protected function _parseConfig($config) + { + if ($config instanceof Zend_Config) { + $config = $config->toArray(); + } + + 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' + ); + } + + return $config; + } +} diff --git a/libs/Zend/Log/Writer/Db.php b/libs/Zend/Log/Writer/Db.php index 2130efe28e..63660aec6f 100644 --- a/libs/Zend/Log/Writer/Db.php +++ b/libs/Zend/Log/Writer/Db.php @@ -15,9 +15,9 @@ * @category Zend * @package Zend_Log * @subpackage Writer - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 16219 2009-06-21 19:45:39Z thomas $ + * @version $Id: Db.php 20096 2010-01-06 02:05:09Z bkarwin $ */ /** Zend_Log_Writer_Abstract */ @@ -27,9 +27,9 @@ require_once 'Zend/Log/Writer/Abstract.php'; * @category Zend * @package Zend_Log * @subpackage Writer - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 16219 2009-06-21 19:45:39Z thomas $ + * @version $Id: Db.php 20096 2010-01-06 02:05:09Z bkarwin $ */ class Zend_Log_Writer_Db extends Zend_Log_Writer_Abstract { @@ -67,6 +67,33 @@ class Zend_Log_Writer_Db extends Zend_Log_Writer_Abstract } /** + * Create a new instance of Zend_Log_Writer_Db + * + * @param array|Zend_Config $config + * @return Zend_Log_Writer_Db + * @throws Zend_Log_Exception + */ + static public function factory($config) + { + $config = self::_parseConfig($config); + $config = array_merge(array( + 'db' => null, + 'table' => null, + 'columnMap' => null, + ), $config); + + if (isset($config['columnmap'])) { + $config['columnMap'] = $config['columnmap']; + } + + return new self( + $config['db'], + $config['table'], + $config['columnMap'] + ); + } + + /** * Formatting is not possible on this writer */ public function setFormatter($formatter) @@ -109,5 +136,4 @@ class Zend_Log_Writer_Db extends Zend_Log_Writer_Abstract $this->_db->insert($this->_table, $dataToInsert); } - } diff --git a/libs/Zend/Log/Writer/Firebug.php b/libs/Zend/Log/Writer/Firebug.php index 54616d5009..5afd752401 100644 --- a/libs/Zend/Log/Writer/Firebug.php +++ b/libs/Zend/Log/Writer/Firebug.php @@ -15,9 +15,9 @@ * @category Zend * @package Zend_Log * @subpackage Writer - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 18951 2009-11-12 16:26:19Z alexander $ + * @version $Id: Firebug.php 20096 2010-01-06 02:05:09Z bkarwin $ */ /** Zend_Log */ @@ -38,7 +38,7 @@ require_once 'Zend/Wildfire/Plugin/FirePhp.php'; * @category Zend * @package Zend_Log * @subpackage Writer - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Log_Writer_Firebug extends Zend_Log_Writer_Abstract @@ -74,12 +74,24 @@ class Zend_Log_Writer_Firebug extends Zend_Log_Writer_Abstract */ public function __construct() { - if (php_sapi_name()=='cli') { + if (php_sapi_name() == 'cli') { $this->setEnabled(false); } $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) + { + return new self(); + } /** * Enable or disable the log writer. diff --git a/libs/Zend/Log/Writer/Mail.php b/libs/Zend/Log/Writer/Mail.php index 068bd33dc1..2d47670e1d 100644 --- a/libs/Zend/Log/Writer/Mail.php +++ b/libs/Zend/Log/Writer/Mail.php @@ -15,9 +15,9 @@ * @category Zend * @package Zend_Log * @subpackage Writer - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 16219 2009-06-21 19:45:39Z thomas $ + * @version $Id: Mail.php 20096 2010-01-06 02:05:09Z bkarwin $ */ /** Zend_Log_Writer_Abstract */ @@ -39,9 +39,9 @@ require_once 'Zend/Log/Formatter/Simple.php'; * @category Zend * @package Zend_Log * @subpackage Writer - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 16219 2009-06-21 19:45:39Z thomas $ + * @version $Id: Mail.php 20096 2010-01-06 02:05:09Z bkarwin $ */ class Zend_Log_Writer_Mail extends Zend_Log_Writer_Abstract { @@ -117,6 +117,18 @@ class Zend_Log_Writer_Mail extends Zend_Log_Writer_Abstract $this->_layout = $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'); + } /** * Places event line into array of lines to be used as message body. diff --git a/libs/Zend/Log/Writer/Mock.php b/libs/Zend/Log/Writer/Mock.php index 2a593c0d9e..f946219a9f 100644 --- a/libs/Zend/Log/Writer/Mock.php +++ b/libs/Zend/Log/Writer/Mock.php @@ -15,9 +15,9 @@ * @category Zend * @package Zend_Log * @subpackage Writer - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 16971 2009-07-22 18:05:45Z mikaelkael $ + * @version $Id: Mock.php 20096 2010-01-06 02:05:09Z bkarwin $ */ /** Zend_Log_Writer_Abstract */ @@ -27,9 +27,9 @@ require_once 'Zend/Log/Writer/Abstract.php'; * @category Zend * @package Zend_Log * @subpackage Writer - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 16971 2009-07-22 18:05:45Z mikaelkael $ + * @version $Id: Mock.php 20096 2010-01-06 02:05:09Z bkarwin $ */ class Zend_Log_Writer_Mock extends Zend_Log_Writer_Abstract { @@ -63,4 +63,16 @@ class Zend_Log_Writer_Mock extends Zend_Log_Writer_Abstract { $this->shutdown = true; } -}
\ No newline at end of file + + /** + * 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) + { + return new self(); + } +} diff --git a/libs/Zend/Log/Writer/Null.php b/libs/Zend/Log/Writer/Null.php index de791d3a99..d86b69b583 100644 --- a/libs/Zend/Log/Writer/Null.php +++ b/libs/Zend/Log/Writer/Null.php @@ -15,9 +15,9 @@ * @category Zend * @package Zend_Log * @subpackage Writer - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 16219 2009-06-21 19:45:39Z thomas $ + * @version $Id: Null.php 20096 2010-01-06 02:05:09Z bkarwin $ */ /** Zend_Log_Writer_Abstract */ @@ -27,9 +27,9 @@ require_once 'Zend/Log/Writer/Abstract.php'; * @category Zend * @package Zend_Log * @subpackage Writer - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 16219 2009-06-21 19:45:39Z thomas $ + * @version $Id: Null.php 20096 2010-01-06 02:05:09Z bkarwin $ */ class Zend_Log_Writer_Null extends Zend_Log_Writer_Abstract { @@ -42,5 +42,16 @@ class Zend_Log_Writer_Null extends Zend_Log_Writer_Abstract protected function _write($event) { } - -}
\ No newline at end of file + + /** + * 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) + { + return new self(); + } +} diff --git a/libs/Zend/Log/Writer/Stream.php b/libs/Zend/Log/Writer/Stream.php index 99b050ad6b..fdf924efdc 100644 --- a/libs/Zend/Log/Writer/Stream.php +++ b/libs/Zend/Log/Writer/Stream.php @@ -15,9 +15,9 @@ * @category Zend * @package Zend_Log * @subpackage Writer - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 16219 2009-06-21 19:45:39Z thomas $ + * @version $Id: Stream.php 20096 2010-01-06 02:05:09Z bkarwin $ */ /** Zend_Log_Writer_Abstract */ @@ -30,9 +30,9 @@ require_once 'Zend/Log/Formatter/Simple.php'; * @category Zend * @package Zend_Log * @subpackage Writer - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 16219 2009-06-21 19:45:39Z thomas $ + * @version $Id: Stream.php 20096 2010-01-06 02:05:09Z bkarwin $ */ class Zend_Log_Writer_Stream extends Zend_Log_Writer_Abstract { @@ -48,8 +48,13 @@ class Zend_Log_Writer_Stream extends Zend_Log_Writer_Abstract * @param streamOrUrl Stream or URL to open as a stream * @param mode Mode, only applicable if a URL is given */ - public function __construct($streamOrUrl, $mode = 'a') + public function __construct($streamOrUrl, $mode = NULL) { + // Setting the default + if ($mode === NULL) { + $mode = 'a'; + } + if (is_resource($streamOrUrl)) { if (get_resource_type($streamOrUrl) != 'stream') { require_once 'Zend/Log/Exception.php'; @@ -63,6 +68,10 @@ class Zend_Log_Writer_Stream extends Zend_Log_Writer_Abstract $this->_stream = $streamOrUrl; } else { + if (is_array($streamOrUrl) && isset($streamOrUrl['stream'])) { + $streamOrUrl = $streamOrUrl['stream']; + } + if (! $this->_stream = @fopen($streamOrUrl, $mode, false)) { require_once 'Zend/Log/Exception.php'; $msg = "\"$streamOrUrl\" cannot be opened with mode \"$mode\""; @@ -72,7 +81,30 @@ 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 + * + * @param array|Zend_Config $config + * @return Zend_Log_Writer_Mock + * @throws Zend_Log_Exception + */ + static public function factory($config) + { + $config = self::_parseConfig($config); + $config = array_merge(array( + 'stream' => null, + 'mode' => null, + ), $config); + $streamOrUrl = isset($config['url']) ? $config['url'] : $config['stream']; + + return new self( + $streamOrUrl, + $config['mode'] + ); + } + /** * Close the stream resource. * @@ -100,5 +132,4 @@ class Zend_Log_Writer_Stream extends Zend_Log_Writer_Abstract throw new Zend_Log_Exception("Unable to write to stream"); } } - } diff --git a/libs/Zend/Log/Writer/Syslog.php b/libs/Zend/Log/Writer/Syslog.php index 3409ae56dc..96fbe56922 100644 --- a/libs/Zend/Log/Writer/Syslog.php +++ b/libs/Zend/Log/Writer/Syslog.php @@ -15,9 +15,9 @@ * @category Zend * @package Zend_Log * @subpackage Writer - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 16971 2009-07-22 18:05:45Z mikaelkael $ + * @version $Id: Syslog.php 20096 2010-01-06 02:05:09Z bkarwin $ */ /** Zend_Log_Writer_Abstract */ @@ -29,7 +29,7 @@ require_once 'Zend/Log/Writer/Abstract.php'; * @category Zend * @package Zend_Log * @subpackage Writer - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Log_Writer_Syslog extends Zend_Log_Writer_Abstract @@ -95,6 +95,18 @@ class Zend_Log_Writer_Syslog extends Zend_Log_Writer_Abstract } $this->_initializeSyslog(); } + + /** + * Create a new instance of Zend_Log_Writer_Syslog + * + * @param array|Zend_Config $config + * @return Zend_Log_Writer_Syslog + * @throws Zend_Log_Exception + */ + static public function factory($config) + { + return new self(self::_parseConfig($config)); + } /** * Initialize syslog / set application name and facility diff --git a/libs/Zend/Log/Writer/ZendMonitor.php b/libs/Zend/Log/Writer/ZendMonitor.php new file mode 100644 index 0000000000..082f2a4f58 --- /dev/null +++ b/libs/Zend/Log/Writer/ZendMonitor.php @@ -0,0 +1,111 @@ +<?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_Log + * @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$ + */ + +/** Zend_Log_Writer_Abstract */ +require_once 'Zend/Log/Writer/Abstract.php'; + +/** + * @category Zend + * @package Zend_Log + * @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$ + */ +class Zend_Log_Writer_ZendMonitor extends Zend_Log_Writer_Abstract +{ + /** + * Is Zend Monitor enabled? + * @var bool + */ + protected $_isEnabled = true; + + /** + * @throws Zend_Log_Exception if Zend Monitor extension not present + */ + public function __construct() + { + if (!function_exists('monitor_custom_event')) { + $this->_isEnabled = false; + } + } + + /** + * Create a new instance of Zend_Log_Writer_ZendMonitor + * + * @param array|Zend_Config $config + * @return Zend_Log_Writer_Syslog + * @throws Zend_Log_Exception + */ + static public function factory($config) + { + return new self(); + } + + /** + * Is logging to this writer enabled? + * + * If the Zend Monitor extension is not enabled, this log writer will + * fail silently. You can query this method to determine if the log + * writer is enabled. + * + * @return bool + */ + public function isEnabled() + { + return $this->_isEnabled; + } + + /** + * Log a message to this writer. + * + * @param array $event log data event + * @return void + */ + public function write($event) + { + if (!$this->isEnabled()) { + return; + } + + parent::write($event); + } + + /** + * Write a message to the log. + * + * @param array $event log data event + * @return void + */ + protected function _write($event) + { + $priority = $event['priority']; + $message = $event['message']; + unset($event['priority'], $event['message']); + + if (!empty($event)) { + monitor_custom_event($priority, $message, $event); + } else { + monitor_custom_event($priority, $message); + } + } +} diff --git a/libs/Zend/Mail.php b/libs/Zend/Mail.php index ededed81e4..aafc5f4108 100644 --- a/libs/Zend/Mail.php +++ b/libs/Zend/Mail.php @@ -14,9 +14,9 @@ * * @category Zend * @package Zend_Mail - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 18951 2009-11-12 16:26:19Z alexander $ + * @version $Id: Mail.php 20096 2010-01-06 02:05:09Z bkarwin $ */ @@ -46,7 +46,7 @@ require_once 'Zend/Mime/Part.php'; * * @category Zend * @package Zend_Mail - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 extends Zend_Mime_Message @@ -62,6 +62,18 @@ class Zend_Mail extends Zend_Mime_Message protected static $_defaultTransport = null; /** + * @var array + * @static + */ + protected static $_defaultFrom; + + /** + * @var array + * @static + */ + protected static $_defaultReplyTo; + + /** * Mail character set * @var string */ @@ -98,6 +110,12 @@ class Zend_Mail extends Zend_Mime_Message protected $_recipients = array(); /** + * Reply-To header + * @var string + */ + protected $_replyTo = null; + + /** * Return-Path header * @var string */ @@ -166,6 +184,26 @@ class Zend_Mail extends Zend_Mime_Message { self::$_defaultTransport = $transport; } + + /** + * Gets the default mail transport for all following uses of + * unittests + * + * @todo Allow passing a string to indicate the transport to load + * @todo Allow passing in optional options for the transport to load + */ + public static function getDefaultTransport() + { + return self::$_defaultTransport; + } + + /** + * Clear the default transport property + */ + public static function clearDefaultTransport() + { + self::$_defaultTransport = null; + } /** * Public constructor @@ -522,41 +560,62 @@ class Zend_Mail extends Zend_Mime_Message } /** - * Adds To-header and recipient + * Adds To-header and recipient, $email can be an array, or a single string address * - * @param string $email + * @param string|array $email * @param string $name * @return Zend_Mail Provides fluent interface */ public function addTo($email, $name='') { - $this->_addRecipientAndHeader('To', $email, $name); - $this->_to[] = $email; + if (!is_array($email)) { + $email = array($name => $email); + } + + foreach ($email as $n => $recipient) { + $this->_addRecipientAndHeader('To', $recipient, is_int($n) ? '' : $n); + $this->_to[] = $recipient; + } + return $this; } /** - * Adds Cc-header and recipient + * Adds Cc-header and recipient, $email can be an array, or a single string address * - * @param string $email + * @param string|array $email * @param string $name * @return Zend_Mail Provides fluent interface */ public function addCc($email, $name='') { - $this->_addRecipientAndHeader('Cc', $email, $name); + if (!is_array($email)) { + $email = array($name => $email); + } + + foreach ($email as $n => $recipient) { + $this->_addRecipientAndHeader('Cc', $recipient, is_int($n) ? '' : $n); + } + return $this; } /** - * Adds Bcc recipient + * Adds Bcc recipient, $email can be an array, or a single string address * - * @param string $email + * @param string|array $email * @return Zend_Mail Provides fluent interface */ public function addBcc($email) { - $this->_addRecipientAndHeader('Bcc', $email, ''); + if (!is_array($email)) { + $email = array($email); + } + + foreach ($email as $recipient) { + $this->_addRecipientAndHeader('Bcc', $recipient, ''); + } + return $this; } @@ -597,18 +656,19 @@ class Zend_Mail extends Zend_Mime_Message */ public function setFrom($email, $name = null) { - if ($this->_from === null) { - $email = $this->_filterEmail($email); - $name = $this->_filterName($name); - $this->_from = $email; - $this->_storeHeader('From', $this->_formatAddress($email, $name), true); - } else { + if (null !== $this->_from) { /** * @see Zend_Mail_Exception */ require_once 'Zend/Mail/Exception.php'; throw new Zend_Mail_Exception('From Header set twice'); } + + $email = $this->_filterEmail($email); + $name = $this->_filterName($name); + $this->_from = $email; + $this->_storeHeader('From', $this->_formatAddress($email, $name), true); + return $this; } @@ -618,10 +678,23 @@ class Zend_Mail extends Zend_Mime_Message * @param string $email * @param string $name * @return Zend_Mail + * @throws Zend_Mail_Exception if called more than one time */ - public function setReplyTo($email, $name=null) + public function setReplyTo($email, $name = null) { - $this->_addRecipientAndHeader('Reply-To', $email, $name); + if (null !== $this->_replyTo) { + /** + * @see Zend_Mail_Exception + */ + require_once 'Zend/Mail/Exception.php'; + throw new Zend_Mail_Exception('Reply-To Header set twice'); + } + + $email = $this->_filterEmail($email); + $name = $this->_filterName($name); + $this->_replyTo = $email; + $this->_storeHeader('Reply-To', $this->_formatAddress($email, $name), true); + return $this; } @@ -636,6 +709,16 @@ class Zend_Mail extends Zend_Mime_Message } /** + * Returns the current Reply-To address of the message + * + * @return string|null Reply-To address, null when not set + */ + public function getReplyTo() + { + return $this->_replyTo; + } + + /** * Clears the sender from the mail * * @return Zend_Mail Provides fluent interface @@ -648,6 +731,119 @@ class Zend_Mail extends Zend_Mime_Message return $this; } + /** + * Clears the current Reply-To address from the message + * + * @return Zend_Mail Provides fluent interface + */ + public function clearReplyTo() + { + $this->_replyTo = null; + $this->_clearHeader('Reply-To'); + + return $this; + } + + /** + * Sets Default From-email and name of the message + * + * @param string $email + * @param string Optional $name + * @return void + */ + public static function setDefaultFrom($email, $name = null) + { + self::$_defaultFrom = array('email' => $email, 'name' => $name); + } + + /** + * Returns the default sender of the mail + * + * @return null|array Null if none was set. + */ + public static function getDefaultFrom() + { + return self::$_defaultFrom; + } + + /** + * Clears the default sender from the mail + * + * @return void + */ + public static function clearDefaultFrom() + { + self::$_defaultFrom = null; + } + + /** + * Sets From-name and -email based on the defaults + * + * @return Zend_Mail Provides fluent interface + */ + public function setFromToDefaultFrom() { + $from = self::getDefaultFrom(); + if($from === null) { + require_once 'Zend/Mail/Exception.php'; + throw new Zend_Mail_Exception( + 'No default From Address set to use'); + } + + $this->setFrom($from['email'], $from['name']); + + return $this; + } + + /** + * Sets Default ReplyTo-address and -name of the message + * + * @param string $email + * @param string Optional $name + * @return void + */ + public static function setDefaultReplyTo($email, $name = null) + { + self::$_defaultReplyTo = array('email' => $email, 'name' => $name); + } + + /** + * Returns the default Reply-To Address and Name of the mail + * + * @return null|array Null if none was set. + */ + public static function getDefaultReplyTo() + { + return self::$_defaultReplyTo; + } + + /** + * Clears the default ReplyTo-address and -name from the mail + * + * @return void + */ + public static function clearDefaultReplyTo() + { + self::$_defaultReplyTo = null; + } + + /** + * Sets ReplyTo-name and -email based on the defaults + * + * @return Zend_Mail Provides fluent interface + */ + public function setReplyToFromDefault() { + $replyTo = self::getDefaultReplyTo(); + if($replyTo === null) { + require_once 'Zend/Mail/Exception.php'; + throw new Zend_Mail_Exception( + 'No default Reply-To Address set to use'); + } + + $this->setReplyTo($replyTo['email'], $replyTo['name']); + + return $this; + } + /** * Sets the Return-Path header of the message * @@ -749,9 +945,9 @@ class Zend_Mail extends Zend_Mime_Message /** * Sets Date-header * - * @param string $date + * @param timestamp|string|Zend_Date $date * @return Zend_Mail Provides fluent interface - * @throws Zend_Mail_Exception if called subsequent times + * @throws Zend_Mail_Exception if called subsequent times or wrong date format. */ public function setDate($date = null) { @@ -823,7 +1019,7 @@ class Zend_Mail extends Zend_Mime_Message * true :Auto * false :No set * null :No set - * string:Sets string + * string:Sets given string * @return Zend_Mail Provides fluent interface * @throws Zend_Mail_Exception */ @@ -920,7 +1116,8 @@ class Zend_Mail extends Zend_Mime_Message public function addHeader($name, $value, $append = false) { $prohibit = array('to', 'cc', 'bcc', 'from', 'subject', - 'return-path', 'date', 'message-id', + 'reply-to', 'return-path', + 'date', 'message-id', ); if (in_array(strtolower($name), $prohibit)) { /** @@ -970,6 +1167,14 @@ class Zend_Mail extends Zend_Mime_Message $this->setDate(); } + if(null === $this->_from && null !== self::getDefaultFrom()) { + $this->setFromToDefaultFrom(); + } + + if(null === $this->_replyTo && null !== self::getDefaultReplyTo()) { + $this->setReplyToFromDefault(); + } + $transport->send($this); return $this; @@ -1043,7 +1248,8 @@ class Zend_Mail extends Zend_Mime_Message return $email; } else { $encodedName = $this->_encodeHeader($name); - if ($encodedName === $name && strpos($name, ',') !== false) { + if ($encodedName === $name && + ((strpos($name, '@') !== false) || (strpos($name, ',') !== false))) { $format = '"%s" <%s>'; } else { $format = '%s <%s>'; diff --git a/libs/Zend/Mail/Exception.php b/libs/Zend/Mail/Exception.php index 864d1ca932..470fc3d54e 100644 --- a/libs/Zend/Mail/Exception.php +++ b/libs/Zend/Mail/Exception.php @@ -14,9 +14,9 @@ * * @category Zend * @package Zend_Mail - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 16219 2009-06-21 19:45:39Z thomas $ + * @version $Id: Exception.php 20096 2010-01-06 02:05:09Z bkarwin $ */ @@ -29,7 +29,7 @@ require_once 'Zend/Exception.php'; /** * @category Zend * @package Zend_Mail - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Exception extends Zend_Exception diff --git a/libs/Zend/Mail/Message.php b/libs/Zend/Mail/Message.php index 5b35ab2f67..2bb96bc2f5 100644 --- a/libs/Zend/Mail/Message.php +++ b/libs/Zend/Mail/Message.php @@ -14,9 +14,9 @@ * * @category Zend * @package Zend_Mail - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 16219 2009-06-21 19:45:39Z thomas $ + * @version $Id: Message.php 20096 2010-01-06 02:05:09Z bkarwin $ */ @@ -33,7 +33,7 @@ require_once 'Zend/Mail/Message/Interface.php'; /** * @category Zend * @package Zend_Mail - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Message extends Zend_Mail_Part implements Zend_Mail_Message_Interface diff --git a/libs/Zend/Mail/Message/File.php b/libs/Zend/Mail/Message/File.php index 7d8ab492e4..3714f9ecf0 100644 --- a/libs/Zend/Mail/Message/File.php +++ b/libs/Zend/Mail/Message/File.php @@ -14,9 +14,9 @@ * * @category Zend * @package Zend_Mail - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 18951 2009-11-12 16:26:19Z alexander $ + * @version $Id: File.php 20096 2010-01-06 02:05:09Z bkarwin $ */ @@ -33,7 +33,7 @@ require_once 'Zend/Mail/Message/Interface.php'; /** * @category Zend * @package Zend_Mail - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Message_File extends Zend_Mail_Part_File implements Zend_Mail_Message_Interface diff --git a/libs/Zend/Mail/Message/Interface.php b/libs/Zend/Mail/Message/Interface.php index ce46455edb..833be6b44a 100644 --- a/libs/Zend/Mail/Message/Interface.php +++ b/libs/Zend/Mail/Message/Interface.php @@ -15,9 +15,9 @@ * @category Zend * @package Zend_Mail * @subpackage Storage - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 18951 2009-11-12 16:26:19Z alexander $ + * @version $Id: Interface.php 20096 2010-01-06 02:05:09Z bkarwin $ */ @@ -25,7 +25,7 @@ * @category Zend * @package Zend_Mail * @subpackage Storage - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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/Mail/Part.php b/libs/Zend/Mail/Part.php index dce238f726..51818e71e9 100644 --- a/libs/Zend/Mail/Part.php +++ b/libs/Zend/Mail/Part.php @@ -14,9 +14,9 @@ * * @category Zend * @package Zend_Mail - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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: Part.php 18951 2009-11-12 16:26:19Z alexander $ + * @version $Id: Part.php 20096 2010-01-06 02:05:09Z bkarwin $ */ @@ -34,7 +34,7 @@ require_once 'Zend/Mail/Part/Interface.php'; /** * @category Zend * @package Zend_Mail - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Part implements RecursiveIterator, Zend_Mail_Part_Interface diff --git a/libs/Zend/Mail/Part/File.php b/libs/Zend/Mail/Part/File.php index 75c690b8bf..9e87009346 100644 --- a/libs/Zend/Mail/Part/File.php +++ b/libs/Zend/Mail/Part/File.php @@ -14,9 +14,9 @@ * * @category Zend * @package Zend_Mail - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 18951 2009-11-12 16:26:19Z alexander $ + * @version $Id: File.php 20096 2010-01-06 02:05:09Z bkarwin $ */ @@ -34,7 +34,7 @@ require_once 'Zend/Mail/Part.php'; /** * @category Zend * @package Zend_Mail - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Part_File extends Zend_Mail_Part diff --git a/libs/Zend/Mail/Part/Interface.php b/libs/Zend/Mail/Part/Interface.php index d4c57bf0b6..2d8f6f8943 100644 --- a/libs/Zend/Mail/Part/Interface.php +++ b/libs/Zend/Mail/Part/Interface.php @@ -15,9 +15,9 @@ * @category Zend * @package Zend_Mail * @subpackage Storage - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 18951 2009-11-12 16:26:19Z alexander $ + * @version $Id: Interface.php 20096 2010-01-06 02:05:09Z bkarwin $ */ @@ -25,7 +25,7 @@ * @category Zend * @package Zend_Mail * @subpackage Storage - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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/Mail/Protocol/Abstract.php b/libs/Zend/Mail/Protocol/Abstract.php index 57844592df..617e7b7c52 100644 --- a/libs/Zend/Mail/Protocol/Abstract.php +++ b/libs/Zend/Mail/Protocol/Abstract.php @@ -16,9 +16,9 @@ * @category Zend * @package Zend_Mail * @subpackage Protocol - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 19916 2009-12-24 10:35:22Z yoshida@zend.co.jp $ + * @version $Id: Abstract.php 20096 2010-01-06 02:05:09Z bkarwin $ */ @@ -42,9 +42,9 @@ require_once 'Zend/Validate/Hostname.php'; * @category Zend * @package Zend_Mail * @subpackage Protocol - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 19916 2009-12-24 10:35:22Z yoshida@zend.co.jp $ + * @version $Id: Abstract.php 20096 2010-01-06 02:05:09Z bkarwin $ * @todo Implement proxy settings */ abstract class Zend_Mail_Protocol_Abstract @@ -60,6 +60,11 @@ abstract class Zend_Mail_Protocol_Abstract */ const TIMEOUT_CONNECTION = 30; + /** + * Maximum of the transaction log + */ + const MAXIMUM_LOG = 64; + /** * Hostname or IP address of remote server @@ -112,9 +117,9 @@ abstract class Zend_Mail_Protocol_Abstract /** * Log of mail requests and server responses for a session - * @var string + * @var array */ - private $_log; + private $_log = array(); /** @@ -191,7 +196,7 @@ abstract class Zend_Mail_Protocol_Abstract */ public function getLog() { - return $this->_log; + return implode('', $this->_log); } @@ -202,9 +207,23 @@ abstract class Zend_Mail_Protocol_Abstract */ public function resetLog() { - $this->_log = ''; + $this->_log = array(); } + /** + * Add the transaction log + * + * @param string new transaction + * @return void + */ + protected function _addLog($value) + { + if (count($this->_log) >= self::MAXIMUM_LOG) { + array_shift($this->_log); + } + + $this->_log[] = $value; + } /** * Connect to the server using the supplied transport and target @@ -281,7 +300,7 @@ abstract class Zend_Mail_Protocol_Abstract $result = fwrite($this->_socket, $request . self::EOL); // Save request to internal log - $this->_log .= $request . self::EOL; + $this->_addLog($request . self::EOL); if ($result === false) { /** @@ -321,7 +340,7 @@ abstract class Zend_Mail_Protocol_Abstract $reponse = fgets($this->_socket, 1024); // Save request to internal log - $this->_log .= $reponse; + $this->_addLog($reponse); // Check meta data to ensure connection is still valid $info = stream_get_meta_data($this->_socket); diff --git a/libs/Zend/Mail/Protocol/Exception.php b/libs/Zend/Mail/Protocol/Exception.php index dc0aee035e..15f446836e 100644 --- a/libs/Zend/Mail/Protocol/Exception.php +++ b/libs/Zend/Mail/Protocol/Exception.php @@ -15,9 +15,9 @@ * @category Zend * @package Zend_Mail * @subpackage Protocol - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 18951 2009-11-12 16:26:19Z alexander $ + * @version $Id: Exception.php 20096 2010-01-06 02:05:09Z bkarwin $ */ @@ -31,7 +31,7 @@ require_once 'Zend/Mail/Exception.php'; * @category Zend * @package Zend_Mail * @subpackage Protocol - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Protocol_Exception extends Zend_Mail_Exception diff --git a/libs/Zend/Mail/Protocol/Imap.php b/libs/Zend/Mail/Protocol/Imap.php index b0da4f4105..77c2ee32c7 100644 --- a/libs/Zend/Mail/Protocol/Imap.php +++ b/libs/Zend/Mail/Protocol/Imap.php @@ -15,9 +15,9 @@ * @category Zend * @package Zend_Mail * @subpackage Protocol - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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: Imap.php 18977 2009-11-14 14:15:59Z yoshida@zend.co.jp $ + * @version $Id: Imap.php 20096 2010-01-06 02:05:09Z bkarwin $ */ @@ -25,7 +25,7 @@ * @category Zend * @package Zend_Mail * @subpackage Protocol - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Protocol_Imap diff --git a/libs/Zend/Mail/Protocol/Pop3.php b/libs/Zend/Mail/Protocol/Pop3.php index 5bf3287eff..7678b345de 100644 --- a/libs/Zend/Mail/Protocol/Pop3.php +++ b/libs/Zend/Mail/Protocol/Pop3.php @@ -15,9 +15,9 @@ * @category Zend * @package Zend_Mail * @subpackage Protocol - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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: Pop3.php 18731 2009-10-29 04:18:19Z yoshida@zend.co.jp $ + * @version $Id: Pop3.php 20096 2010-01-06 02:05:09Z bkarwin $ */ @@ -25,7 +25,7 @@ * @category Zend * @package Zend_Mail * @subpackage Protocol - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Protocol_Pop3 diff --git a/libs/Zend/Mail/Protocol/Smtp.php b/libs/Zend/Mail/Protocol/Smtp.php index 527f821815..acd5c5425b 100644 --- a/libs/Zend/Mail/Protocol/Smtp.php +++ b/libs/Zend/Mail/Protocol/Smtp.php @@ -16,9 +16,9 @@ * @category Zend * @package Zend_Mail * @subpackage Protocol - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 18951 2009-11-12 16:26:19Z alexander $ + * @version $Id: Smtp.php 20096 2010-01-06 02:05:09Z bkarwin $ */ @@ -42,7 +42,7 @@ require_once 'Zend/Mail/Protocol/Abstract.php'; * @category Zend * @package Zend_Mail * @subpackage Protocol - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Protocol_Smtp extends Zend_Mail_Protocol_Abstract diff --git a/libs/Zend/Mail/Protocol/Smtp/Auth/Crammd5.php b/libs/Zend/Mail/Protocol/Smtp/Auth/Crammd5.php index 955cbaf8bd..4b2aa4b28b 100644 --- a/libs/Zend/Mail/Protocol/Smtp/Auth/Crammd5.php +++ b/libs/Zend/Mail/Protocol/Smtp/Auth/Crammd5.php @@ -15,9 +15,9 @@ * @category Zend * @package Zend_Mail * @subpackage Protocol - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 18951 2009-11-12 16:26:19Z alexander $ + * @version $Id: Crammd5.php 20096 2010-01-06 02:05:09Z bkarwin $ */ @@ -33,7 +33,7 @@ require_once 'Zend/Mail/Protocol/Smtp.php'; * @category Zend * @package Zend_Mail * @subpackage Protocol - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Protocol_Smtp_Auth_Crammd5 extends Zend_Mail_Protocol_Smtp diff --git a/libs/Zend/Mail/Protocol/Smtp/Auth/Login.php b/libs/Zend/Mail/Protocol/Smtp/Auth/Login.php index 08cbbce3aa..ab79748aed 100644 --- a/libs/Zend/Mail/Protocol/Smtp/Auth/Login.php +++ b/libs/Zend/Mail/Protocol/Smtp/Auth/Login.php @@ -15,9 +15,9 @@ * @category Zend * @package Zend_Mail * @subpackage Protocol - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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: Login.php 18951 2009-11-12 16:26:19Z alexander $ + * @version $Id: Login.php 20096 2010-01-06 02:05:09Z bkarwin $ */ @@ -33,7 +33,7 @@ require_once 'Zend/Mail/Protocol/Smtp.php'; * @category Zend * @package Zend_Mail * @subpackage Protocol - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Protocol_Smtp_Auth_Login extends Zend_Mail_Protocol_Smtp diff --git a/libs/Zend/Mail/Protocol/Smtp/Auth/Plain.php b/libs/Zend/Mail/Protocol/Smtp/Auth/Plain.php index 698acd9a05..a8c2f61f85 100644 --- a/libs/Zend/Mail/Protocol/Smtp/Auth/Plain.php +++ b/libs/Zend/Mail/Protocol/Smtp/Auth/Plain.php @@ -15,9 +15,9 @@ * @category Zend * @package Zend_Mail * @subpackage Protocol - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 18951 2009-11-12 16:26:19Z alexander $ + * @version $Id: Plain.php 20096 2010-01-06 02:05:09Z bkarwin $ */ @@ -33,7 +33,7 @@ require_once 'Zend/Mail/Protocol/Smtp.php'; * @category Zend * @package Zend_Mail * @subpackage Protocol - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Protocol_Smtp_Auth_Plain extends Zend_Mail_Protocol_Smtp diff --git a/libs/Zend/Mail/Storage.php b/libs/Zend/Mail/Storage.php index 4c1a321962..771f7ae23b 100644 --- a/libs/Zend/Mail/Storage.php +++ b/libs/Zend/Mail/Storage.php @@ -14,15 +14,15 @@ * * @category Zend * @package Zend_Mail - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 16219 2009-06-21 19:45:39Z thomas $ + * @version $Id: Storage.php 20096 2010-01-06 02:05:09Z bkarwin $ */ /** * @category Zend * @package Zend_Mail - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Storage diff --git a/libs/Zend/Mail/Storage/Abstract.php b/libs/Zend/Mail/Storage/Abstract.php index fe59ee1daf..344a07d7e9 100644 --- a/libs/Zend/Mail/Storage/Abstract.php +++ b/libs/Zend/Mail/Storage/Abstract.php @@ -15,9 +15,9 @@ * @category Zend * @package Zend_Mail * @subpackage Storage - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 18951 2009-11-12 16:26:19Z alexander $ + * @version $Id: Abstract.php 20096 2010-01-06 02:05:09Z bkarwin $ */ @@ -25,7 +25,7 @@ * @category Zend * @package Zend_Mail * @subpackage Storage - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Mail_Storage_Abstract implements Countable, ArrayAccess, SeekableIterator diff --git a/libs/Zend/Mail/Storage/Exception.php b/libs/Zend/Mail/Storage/Exception.php index 1cd80b314b..96219196ce 100644 --- a/libs/Zend/Mail/Storage/Exception.php +++ b/libs/Zend/Mail/Storage/Exception.php @@ -15,9 +15,9 @@ * @category Zend * @package Zend_Mail * @subpackage Storage - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 18951 2009-11-12 16:26:19Z alexander $ + * @version $Id: Exception.php 20096 2010-01-06 02:05:09Z bkarwin $ */ @@ -31,7 +31,7 @@ require_once 'Zend/Mail/Exception.php'; * @category Zend * @package Zend_Mail * @subpackage Storage - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Storage_Exception extends Zend_Mail_Exception diff --git a/libs/Zend/Mail/Storage/Folder.php b/libs/Zend/Mail/Storage/Folder.php index 146d80dab4..10b368a9be 100644 --- a/libs/Zend/Mail/Storage/Folder.php +++ b/libs/Zend/Mail/Storage/Folder.php @@ -15,9 +15,9 @@ * @category Zend * @package Zend_Mail * @subpackage Storage - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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: Folder.php 18951 2009-11-12 16:26:19Z alexander $ + * @version $Id: Folder.php 20096 2010-01-06 02:05:09Z bkarwin $ */ @@ -25,7 +25,7 @@ * @category Zend * @package Zend_Mail * @subpackage Storage - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Storage_Folder implements RecursiveIterator diff --git a/libs/Zend/Mail/Storage/Folder/Interface.php b/libs/Zend/Mail/Storage/Folder/Interface.php index 7b70ec88d0..b5c89ac917 100644 --- a/libs/Zend/Mail/Storage/Folder/Interface.php +++ b/libs/Zend/Mail/Storage/Folder/Interface.php @@ -15,9 +15,9 @@ * @category Zend * @package Zend_Mail * @subpackage Storage - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 18951 2009-11-12 16:26:19Z alexander $ + * @version $Id: Interface.php 20096 2010-01-06 02:05:09Z bkarwin $ */ @@ -25,7 +25,7 @@ * @category Zend * @package Zend_Mail * @subpackage Storage - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Mail_Storage_Folder_Interface diff --git a/libs/Zend/Mail/Storage/Folder/Maildir.php b/libs/Zend/Mail/Storage/Folder/Maildir.php index d53cde6b01..d486703c5f 100644 --- a/libs/Zend/Mail/Storage/Folder/Maildir.php +++ b/libs/Zend/Mail/Storage/Folder/Maildir.php @@ -15,9 +15,9 @@ * @category Zend * @package Zend_Mail * @subpackage Storage - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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: Maildir.php 18951 2009-11-12 16:26:19Z alexander $ + * @version $Id: Maildir.php 20096 2010-01-06 02:05:09Z bkarwin $ */ @@ -41,7 +41,7 @@ require_once 'Zend/Mail/Storage/Maildir.php'; * @category Zend * @package Zend_Mail * @subpackage Storage - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Storage_Folder_Maildir extends Zend_Mail_Storage_Maildir implements Zend_Mail_Storage_Folder_Interface @@ -239,7 +239,7 @@ class Zend_Mail_Storage_Folder_Maildir extends Zend_Mail_Storage_Maildir impleme * @see Zend_Mail_Storage_Exception */ require_once 'Zend/Mail/Storage/Exception.php'; - throw new Zend_Mail_Storage_Exception("{$this->_currentFolder} is not selectable"); + throw new Zend_Mail_Storage_Exception("{$this->_currentFolder} is not selectable", 0, $e); } // seems like file has vanished; rebuilding folder tree - but it's still an exception $this->_buildFolderTree($this->_rootdir); @@ -248,7 +248,7 @@ class Zend_Mail_Storage_Folder_Maildir extends Zend_Mail_Storage_Maildir impleme */ require_once 'Zend/Mail/Storage/Exception.php'; throw new Zend_Mail_Storage_Exception('seems like the maildir has vanished, I\'ve rebuild the ' . - 'folder tree, search for an other folder and try again'); + 'folder tree, search for an other folder and try again', 0, $e); } } diff --git a/libs/Zend/Mail/Storage/Folder/Mbox.php b/libs/Zend/Mail/Storage/Folder/Mbox.php index ca097dd27a..0c5cfd88ef 100644 --- a/libs/Zend/Mail/Storage/Folder/Mbox.php +++ b/libs/Zend/Mail/Storage/Folder/Mbox.php @@ -15,9 +15,9 @@ * @category Zend * @package Zend_Mail * @subpackage Storage - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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: Mbox.php 18951 2009-11-12 16:26:19Z alexander $ + * @version $Id: Mbox.php 20096 2010-01-06 02:05:09Z bkarwin $ */ @@ -41,7 +41,7 @@ require_once 'Zend/Mail/Storage/Mbox.php'; * @category Zend * @package Zend_Mail * @subpackage Storage - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Storage_Folder_Mbox extends Zend_Mail_Storage_Mbox implements Zend_Mail_Storage_Folder_Interface @@ -213,7 +213,7 @@ class Zend_Mail_Storage_Folder_Mbox extends Zend_Mail_Storage_Mbox implements Ze * @see Zend_Mail_Storage_Exception */ require_once 'Zend/Mail/Storage/Exception.php'; - throw new Zend_Mail_Storage_Exception("{$this->_currentFolder} is not selectable"); + throw new Zend_Mail_Storage_Exception("{$this->_currentFolder} is not selectable", 0, $e); } // seems like file has vanished; rebuilding folder tree - but it's still an exception $this->_buildFolderTree($this->_rootdir); @@ -222,7 +222,7 @@ class Zend_Mail_Storage_Folder_Mbox extends Zend_Mail_Storage_Mbox implements Ze */ require_once 'Zend/Mail/Storage/Exception.php'; throw new Zend_Mail_Storage_Exception('seems like the mbox file has vanished, I\'ve rebuild the ' . - 'folder tree, search for an other folder and try again'); + 'folder tree, search for an other folder and try again', 0, $e); } } diff --git a/libs/Zend/Mail/Storage/Imap.php b/libs/Zend/Mail/Storage/Imap.php index ae6eb2dc12..0910e6fe67 100644 --- a/libs/Zend/Mail/Storage/Imap.php +++ b/libs/Zend/Mail/Storage/Imap.php @@ -15,9 +15,9 @@ * @category Zend * @package Zend_Mail * @subpackage Storage - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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: Imap.php 18951 2009-11-12 16:26:19Z alexander $ + * @version $Id: Imap.php 20096 2010-01-06 02:05:09Z bkarwin $ */ @@ -60,7 +60,7 @@ require_once 'Zend/Mail/Storage.php'; * @category Zend * @package Zend_Mail * @subpackage Storage - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Storage_Imap extends Zend_Mail_Storage_Abstract @@ -251,7 +251,7 @@ class Zend_Mail_Storage_Imap extends Zend_Mail_Storage_Abstract * @see Zend_Mail_Storage_Exception */ require_once 'Zend/Mail/Storage/Exception.php'; - throw new Zend_Mail_Storage_Exception('cannot select INBOX, is this a valid transport?'); + throw new Zend_Mail_Storage_Exception('cannot select INBOX, is this a valid transport?', 0, $e); } return; } diff --git a/libs/Zend/Mail/Storage/Maildir.php b/libs/Zend/Mail/Storage/Maildir.php index 669d24c3ec..2bb4b00e95 100644 --- a/libs/Zend/Mail/Storage/Maildir.php +++ b/libs/Zend/Mail/Storage/Maildir.php @@ -15,9 +15,9 @@ * @category Zend * @package Zend_Mail * @subpackage Storage - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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: Maildir.php 18951 2009-11-12 16:26:19Z alexander $ + * @version $Id: Maildir.php 20096 2010-01-06 02:05:09Z bkarwin $ */ @@ -41,7 +41,7 @@ require_once 'Zend/Mail/Storage.php'; * @category Zend * @package Zend_Mail * @subpackage Storage - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Storage_Maildir extends Zend_Mail_Storage_Abstract diff --git a/libs/Zend/Mail/Storage/Mbox.php b/libs/Zend/Mail/Storage/Mbox.php index 3c5ebaad6d..3398c31b92 100644 --- a/libs/Zend/Mail/Storage/Mbox.php +++ b/libs/Zend/Mail/Storage/Mbox.php @@ -15,9 +15,9 @@ * @category Zend * @package Zend_Mail * @subpackage Storage - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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: Mbox.php 18951 2009-11-12 16:26:19Z alexander $ + * @version $Id: Mbox.php 20096 2010-01-06 02:05:09Z bkarwin $ */ @@ -42,7 +42,7 @@ require_once 'Zend/Mail/Message/File.php'; * @category Zend * @package Zend_Mail * @subpackage Storage - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Storage_Mbox extends Zend_Mail_Storage_Abstract diff --git a/libs/Zend/Mail/Storage/Pop3.php b/libs/Zend/Mail/Storage/Pop3.php index c8f6e1b1eb..78d8dea306 100644 --- a/libs/Zend/Mail/Storage/Pop3.php +++ b/libs/Zend/Mail/Storage/Pop3.php @@ -15,9 +15,9 @@ * @category Zend * @package Zend_Mail * @subpackage Storage - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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: Pop3.php 18951 2009-11-12 16:26:19Z alexander $ + * @version $Id: Pop3.php 20096 2010-01-06 02:05:09Z bkarwin $ */ @@ -41,7 +41,7 @@ require_once 'Zend/Mail/Message.php'; * @category Zend * @package Zend_Mail * @subpackage Storage - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Storage_Pop3 extends Zend_Mail_Storage_Abstract diff --git a/libs/Zend/Mail/Storage/Writable/Interface.php b/libs/Zend/Mail/Storage/Writable/Interface.php index 527ced1c5e..982b44eeb9 100644 --- a/libs/Zend/Mail/Storage/Writable/Interface.php +++ b/libs/Zend/Mail/Storage/Writable/Interface.php @@ -15,9 +15,9 @@ * @category Zend * @package Zend_Mail * @subpackage Storage - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 18951 2009-11-12 16:26:19Z alexander $ + * @version $Id: Interface.php 20096 2010-01-06 02:05:09Z bkarwin $ */ @@ -25,7 +25,7 @@ * @category Zend * @package Zend_Mail * @subpackage Storage - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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/Mail/Storage/Writable/Maildir.php b/libs/Zend/Mail/Storage/Writable/Maildir.php index d21992a770..3288040554 100644 --- a/libs/Zend/Mail/Storage/Writable/Maildir.php +++ b/libs/Zend/Mail/Storage/Writable/Maildir.php @@ -15,9 +15,9 @@ * @category Zend * @package Zend_Mail * @subpackage Storage - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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: Maildir.php 18951 2009-11-12 16:26:19Z alexander $ + * @version $Id: Maildir.php 20096 2010-01-06 02:05:09Z bkarwin $ */ @@ -36,7 +36,7 @@ require_once 'Zend/Mail/Storage/Writable/Interface.php'; * @category Zend * @package Zend_Mail * @subpackage Storage - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Storage_Writable_Maildir extends Zend_Mail_Storage_Folder_Maildir @@ -873,7 +873,7 @@ class Zend_Mail_Storage_Writable_Maildir extends Zend_Mail_Storage_Folder_Mai try { $quota = $this->getQuota(true); } catch (Zend_Mail_Storage_Exception $e) { - throw new Zend_Mail_Storage_Exception('no quota defintion found'); + throw new Zend_Mail_Storage_Exception('no quota definition found', 0, $e); } } diff --git a/libs/Zend/Mail/Transport/Abstract.php b/libs/Zend/Mail/Transport/Abstract.php index caf3c7af42..1d225a3e66 100644 --- a/libs/Zend/Mail/Transport/Abstract.php +++ b/libs/Zend/Mail/Transport/Abstract.php @@ -15,9 +15,9 @@ * @category Zend * @package Zend_Mail * @subpackage Transport - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 18760 2009-10-31 13:09:01Z yoshida@zend.co.jp $ + * @version $Id: Abstract.php 20096 2010-01-06 02:05:09Z bkarwin $ */ @@ -34,7 +34,7 @@ require_once 'Zend/Mime.php'; * @category Zend * @package Zend_Mail * @subpackage Transport - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Mail_Transport_Abstract diff --git a/libs/Zend/Mail/Transport/Exception.php b/libs/Zend/Mail/Transport/Exception.php index 6f3f3dabdc..63bf1cd4fd 100644 --- a/libs/Zend/Mail/Transport/Exception.php +++ b/libs/Zend/Mail/Transport/Exception.php @@ -15,9 +15,9 @@ * @category Zend * @package Zend_Mail * @subpackage Transport - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 18951 2009-11-12 16:26:19Z alexander $ + * @version $Id: Exception.php 20096 2010-01-06 02:05:09Z bkarwin $ */ @@ -31,7 +31,7 @@ require_once 'Zend/Mail/Exception.php'; * @category Zend * @package Zend_Mail * @subpackage Transport - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Exception extends Zend_Mail_Exception diff --git a/libs/Zend/Mail/Transport/Sendmail.php b/libs/Zend/Mail/Transport/Sendmail.php index b32605047f..139116d9b4 100644 --- a/libs/Zend/Mail/Transport/Sendmail.php +++ b/libs/Zend/Mail/Transport/Sendmail.php @@ -15,9 +15,9 @@ * @category Zend * @package Zend_Mail * @subpackage Transport - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 19915 2009-12-24 10:24:20Z yoshida@zend.co.jp $ + * @version $Id: Sendmail.php 20096 2010-01-06 02:05:09Z bkarwin $ */ @@ -33,7 +33,7 @@ require_once 'Zend/Mail/Transport/Abstract.php'; * @category Zend * @package Zend_Mail * @subpackage Transport - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Sendmail extends Zend_Mail_Transport_Abstract diff --git a/libs/Zend/Mail/Transport/Smtp.php b/libs/Zend/Mail/Transport/Smtp.php index fbb6437750..4175d8b845 100644 --- a/libs/Zend/Mail/Transport/Smtp.php +++ b/libs/Zend/Mail/Transport/Smtp.php @@ -15,9 +15,9 @@ * @category Zend * @package Zend_Mail * @subpackage Transport - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 18989 2009-11-15 13:23:41Z yoshida@zend.co.jp $ + * @version $Id: Smtp.php 20096 2010-01-06 02:05:09Z bkarwin $ */ @@ -45,7 +45,7 @@ require_once 'Zend/Mail/Transport/Abstract.php'; * @category Zend * @package Zend_Mail * @subpackage Transport - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Smtp extends Zend_Mail_Transport_Abstract @@ -111,6 +111,9 @@ 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. */ public function __construct($host = '127.0.0.1', Array $config = array()) { @@ -177,6 +180,7 @@ class Zend_Mail_Transport_Smtp extends Zend_Mail_Transport_Abstract * developer to add a custom adapter if required before mail is sent. * * @return void + * @todo Rename this to sendMail, it's a public method... */ public function _sendMail() { diff --git a/libs/Zend/Mime.php b/libs/Zend/Mime.php index 921cc1f16f..aa3582efe9 100644 --- a/libs/Zend/Mime.php +++ b/libs/Zend/Mime.php @@ -14,9 +14,9 @@ * * @category Zend * @package Zend_Mime - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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: Mime.php 16541 2009-07-07 06:59:03Z bkarwin $ + * @version $Id: Mime.php 20096 2010-01-06 02:05:09Z bkarwin $ */ @@ -25,7 +25,7 @@ * * @category Zend * @package Zend_Mime - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Mime diff --git a/libs/Zend/Mime/Decode.php b/libs/Zend/Mime/Decode.php index c50b495cfd..5e4c0a7af8 100644 --- a/libs/Zend/Mime/Decode.php +++ b/libs/Zend/Mime/Decode.php @@ -14,9 +14,9 @@ * * @category Zend * @package Zend_Mime - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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: Decode.php 16541 2009-07-07 06:59:03Z bkarwin $ + * @version $Id: Decode.php 20096 2010-01-06 02:05:09Z bkarwin $ */ /** @@ -27,7 +27,7 @@ require_once 'Zend/Mime.php'; /** * @category Zend * @package Zend_Mime - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Mime_Decode diff --git a/libs/Zend/Mime/Exception.php b/libs/Zend/Mime/Exception.php index 4d2811f048..a38affe97c 100644 --- a/libs/Zend/Mime/Exception.php +++ b/libs/Zend/Mime/Exception.php @@ -14,9 +14,9 @@ * * @category Zend * @package Zend_Mime - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 16541 2009-07-07 06:59:03Z bkarwin $ + * @version $Id: Exception.php 20096 2010-01-06 02:05:09Z bkarwin $ */ @@ -29,7 +29,7 @@ require_once 'Zend/Exception.php'; /** * @category Zend * @package Zend_Mime - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Mime_Exception extends Zend_Exception diff --git a/libs/Zend/Mime/Message.php b/libs/Zend/Mime/Message.php index 537107d2c7..6207bda131 100644 --- a/libs/Zend/Mime/Message.php +++ b/libs/Zend/Mime/Message.php @@ -14,9 +14,9 @@ * * @category Zend * @package Zend_Mime - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 16541 2009-07-07 06:59:03Z bkarwin $ + * @version $Id: Message.php 20096 2010-01-06 02:05:09Z bkarwin $ */ @@ -34,7 +34,7 @@ require_once 'Zend/Mime/Part.php'; /** * @category Zend * @package Zend_Mime - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Mime_Message diff --git a/libs/Zend/Mime/Part.php b/libs/Zend/Mime/Part.php index 6609b51a76..eb0c978136 100644 --- a/libs/Zend/Mime/Part.php +++ b/libs/Zend/Mime/Part.php @@ -14,9 +14,9 @@ * * @category Zend * @package Zend_Mime - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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: Part.php 16541 2009-07-07 06:59:03Z bkarwin $ + * @version $Id: Part.php 20096 2010-01-06 02:05:09Z bkarwin $ */ /** @@ -29,7 +29,7 @@ require_once 'Zend/Mime.php'; * * @category Zend * @package Zend_Mime - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Mime_Part { diff --git a/libs/Zend/Registry.php b/libs/Zend/Registry.php index d801d1220b..6623da260b 100644 --- a/libs/Zend/Registry.php +++ b/libs/Zend/Registry.php @@ -14,9 +14,9 @@ * * @category Zend * @package Zend_Registry - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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: Registry.php 16207 2009-06-21 19:17:51Z thomas $ + * @version $Id: Registry.php 20096 2010-01-06 02:05:09Z bkarwin $ */ /** @@ -24,7 +24,7 @@ * * @category Zend * @package Zend_Registry - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Registry extends ArrayObject diff --git a/libs/Zend/Session.php b/libs/Zend/Session.php index 3eede144de..17116fbd41 100644 --- a/libs/Zend/Session.php +++ b/libs/Zend/Session.php @@ -15,9 +15,9 @@ * * @category Zend * @package Zend_Session - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 18951 2009-11-12 16:26:19Z alexander $ + * @version $Id: Session.php 20096 2010-01-06 02:05:09Z bkarwin $ * @since Preview Release 0.2 */ @@ -43,7 +43,7 @@ require_once 'Zend/Session/SaveHandler/Interface.php'; * * @category Zend * @package Zend_Session - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Session extends Zend_Session_Abstract @@ -528,7 +528,7 @@ class Zend_Session extends Zend_Session_Abstract // Expire Namespace by Time (ENT) if (isset($namespace_metadata['ENT']) && ($namespace_metadata['ENT'] > 0) && (time() > $namespace_metadata['ENT']) ) { unset($_SESSION[$namespace]); - unset($_SESSION['__ZF'][$namespace]['ENT']); + unset($_SESSION['__ZF'][$namespace]); } // Expire Namespace by Global Hop (ENGH) @@ -540,7 +540,7 @@ class Zend_Session extends Zend_Session_Abstract parent::$_expiringData[$namespace] = $_SESSION[$namespace]; unset($_SESSION[$namespace]); } - unset($_SESSION['__ZF'][$namespace]['ENGH']); + unset($_SESSION['__ZF'][$namespace]); } } @@ -550,12 +550,11 @@ class Zend_Session extends Zend_Session_Abstract if (time() > $time) { unset($_SESSION[$namespace][$variable]); unset($_SESSION['__ZF'][$namespace]['ENVT'][$variable]); - - if (empty($_SESSION['__ZF'][$namespace]['ENVT'])) { - unset($_SESSION['__ZF'][$namespace]['ENVT']); - } } } + if (empty($_SESSION['__ZF'][$namespace]['ENVT'])) { + unset($_SESSION['__ZF'][$namespace]['ENVT']); + } } // Expire Namespace Variables by Global Hop (ENVGH) @@ -571,6 +570,9 @@ class Zend_Session extends Zend_Session_Abstract unset($_SESSION['__ZF'][$namespace]['ENVGH'][$variable]); } } + if(empty($_SESSION['__ZF'][$namespace]['ENVGH'])) { + unset($_SESSION['__ZF'][$namespace]['ENVGH']); + } } } diff --git a/libs/Zend/Session/Abstract.php b/libs/Zend/Session/Abstract.php index 448afbf5c5..5603d146c7 100644 --- a/libs/Zend/Session/Abstract.php +++ b/libs/Zend/Session/Abstract.php @@ -15,9 +15,9 @@ * * @category Zend * @package Zend_Session - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 16210 2009-06-21 19:22:17Z thomas $ + * @version $Id: Abstract.php 20096 2010-01-06 02:05:09Z bkarwin $ * @since Preview Release 0.2 */ @@ -27,7 +27,7 @@ * * @category Zend * @package Zend_Session - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Session_Abstract diff --git a/libs/Zend/Session/Exception.php b/libs/Zend/Session/Exception.php index 29ca6aa954..04c34f7295 100644 --- a/libs/Zend/Session/Exception.php +++ b/libs/Zend/Session/Exception.php @@ -14,9 +14,9 @@ * * @category Zend * @package Zend_Session - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 16210 2009-06-21 19:22:17Z thomas $ + * @version $Id: Exception.php 20096 2010-01-06 02:05:09Z bkarwin $ * @since Preview Release 0.2 */ @@ -32,7 +32,7 @@ require_once 'Zend/Exception.php'; * * @category Zend * @package Zend_Session - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Session_Exception extends Zend_Exception diff --git a/libs/Zend/Session/Namespace.php b/libs/Zend/Session/Namespace.php index 4e90b27099..b3d759477f 100644 --- a/libs/Zend/Session/Namespace.php +++ b/libs/Zend/Session/Namespace.php @@ -14,9 +14,9 @@ * * @category Zend * @package Zend_Session - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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: Namespace.php 19081 2009-11-20 11:18:02Z bate $ + * @version $Id: Namespace.php 20096 2010-01-06 02:05:09Z bkarwin $ * @since Preview Release 0.2 */ @@ -38,7 +38,7 @@ require_once 'Zend/Session/Abstract.php'; * * @category Zend * @package Zend_Session - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Session_Namespace extends Zend_Session_Abstract implements IteratorAggregate @@ -167,7 +167,7 @@ class Zend_Session_Namespace extends Zend_Session_Abstract implements IteratorAg self::$_expiringData[$namespace] = $_SESSION[$namespace]; unset($_SESSION[$namespace]); } - unset($_SESSION['__ZF'][$namespace]['ENNH']); + unset($_SESSION['__ZF'][$namespace]); } } @@ -184,6 +184,9 @@ class Zend_Session_Namespace extends Zend_Session_Abstract implements IteratorAg unset($_SESSION['__ZF'][$namespace]['ENVNH'][$variable]); } } + if(empty($_SESSION['__ZF'][$namespace]['ENVNH'])) { + unset($_SESSION['__ZF'][$namespace]['ENVNH']); + } } } diff --git a/libs/Zend/Session/SaveHandler/DbTable.php b/libs/Zend/Session/SaveHandler/DbTable.php index 14dae9b23b..df75a28aa7 100644 --- a/libs/Zend/Session/SaveHandler/DbTable.php +++ b/libs/Zend/Session/SaveHandler/DbTable.php @@ -15,9 +15,9 @@ * * @category Zend * @package Zend_Session - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 18951 2009-11-12 16:26:19Z alexander $ + * @version $Id: DbTable.php 20096 2010-01-06 02:05:09Z bkarwin $ */ /** @@ -46,7 +46,7 @@ require_once 'Zend/Config.php'; * @category Zend * @package Zend_Session * @subpackage SaveHandler - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Session_SaveHandler_DbTable diff --git a/libs/Zend/Session/SaveHandler/Exception.php b/libs/Zend/Session/SaveHandler/Exception.php index bb2124702d..5f72d30f75 100644 --- a/libs/Zend/Session/SaveHandler/Exception.php +++ b/libs/Zend/Session/SaveHandler/Exception.php @@ -15,9 +15,9 @@ * * @category Zend * @package Zend_Session - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 16210 2009-06-21 19:22:17Z thomas $ + * @version $Id: Exception.php 20096 2010-01-06 02:05:09Z bkarwin $ */ /** @@ -30,7 +30,7 @@ require_once 'Zend/Session/Exception.php'; * * @category Zend * @package Zend_Session - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Session_SaveHandler_Exception extends Zend_Session_Exception diff --git a/libs/Zend/Session/SaveHandler/Interface.php b/libs/Zend/Session/SaveHandler/Interface.php index 2e4945a5d7..6e426974a7 100644 --- a/libs/Zend/Session/SaveHandler/Interface.php +++ b/libs/Zend/Session/SaveHandler/Interface.php @@ -14,9 +14,9 @@ * * @category Zend * @package Zend_Session - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 16210 2009-06-21 19:22:17Z thomas $ + * @version $Id: Interface.php 20096 2010-01-06 02:05:09Z bkarwin $ * @since Preview Release 0.2 */ @@ -26,7 +26,7 @@ * @category Zend * @package Zend_Session * @subpackage SaveHandler - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 http://php.net/session_set_save_handler */ diff --git a/libs/Zend/Session/Validator/Abstract.php b/libs/Zend/Session/Validator/Abstract.php index e1a53f971a..c5050d5d34 100644 --- a/libs/Zend/Session/Validator/Abstract.php +++ b/libs/Zend/Session/Validator/Abstract.php @@ -14,9 +14,9 @@ * * @category Zend * @package Zend_Session - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 16210 2009-06-21 19:22:17Z thomas $ + * @version $Id: Abstract.php 20096 2010-01-06 02:05:09Z bkarwin $ * @since Preview Release 0.2 */ @@ -31,7 +31,7 @@ require_once 'Zend/Session/Validator/Interface.php'; * @category Zend * @package Zend_Session * @subpackage Validator - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Session_Validator_Abstract implements Zend_Session_Validator_Interface diff --git a/libs/Zend/Session/Validator/HttpUserAgent.php b/libs/Zend/Session/Validator/HttpUserAgent.php index 3dccf9e32f..86f171bff0 100644 --- a/libs/Zend/Session/Validator/HttpUserAgent.php +++ b/libs/Zend/Session/Validator/HttpUserAgent.php @@ -14,9 +14,9 @@ * * @category Zend * @package Zend_Session - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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: HttpUserAgent.php 16210 2009-06-21 19:22:17Z thomas $ + * @version $Id: HttpUserAgent.php 20096 2010-01-06 02:05:09Z bkarwin $ * @since Preview Release 0.2 */ @@ -31,7 +31,7 @@ require_once 'Zend/Session/Validator/Abstract.php'; * @category Zend * @package Zend_Session * @subpackage Validator - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Session_Validator_HttpUserAgent extends Zend_Session_Validator_Abstract diff --git a/libs/Zend/Session/Validator/Interface.php b/libs/Zend/Session/Validator/Interface.php index b0d9825e90..eab9d186cd 100644 --- a/libs/Zend/Session/Validator/Interface.php +++ b/libs/Zend/Session/Validator/Interface.php @@ -14,9 +14,9 @@ * * @category Zend * @package Zend_Session - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 16210 2009-06-21 19:22:17Z thomas $ + * @version $Id: Interface.php 20096 2010-01-06 02:05:09Z bkarwin $ * @since Preview Release 0.2 */ @@ -26,7 +26,7 @@ * @category Zend * @package Zend_Session * @subpackage Validator - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Session_Validator_Interface diff --git a/libs/Zend/Uri.php b/libs/Zend/Uri.php index fedf4348b8..6e7a2822e4 100644 --- a/libs/Zend/Uri.php +++ b/libs/Zend/Uri.php @@ -14,9 +14,9 @@ * * @category Zend * @package Zend_Uri - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 18951 2009-11-12 16:26:19Z alexander $ + * @version $Id: Uri.php 20096 2010-01-06 02:05:09Z bkarwin $ */ /** @@ -24,7 +24,7 @@ * * @category Zend * @package Zend_Uri - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Uri @@ -149,10 +149,16 @@ abstract class Zend_Uri /** * Set global configuration options * - * @param array $config + * @param Zend_Config|array $config */ - static public function setConfig(array $config) + static public function setConfig($config) { + if ($config instanceof Zend_Config) { + $config = $config->toArray(); + } elseif (!is_array($config)) { + throw new Zend_Uri_Exception("Config must be an array or an instance of Zend_Config."); + } + foreach ($config as $k => $v) { self::$_config[$k] = $v; } diff --git a/libs/Zend/Uri/Exception.php b/libs/Zend/Uri/Exception.php index 5f68ac9f67..e71c32e1a8 100644 --- a/libs/Zend/Uri/Exception.php +++ b/libs/Zend/Uri/Exception.php @@ -14,9 +14,9 @@ * * @category Zend * @package Zend_Uri - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 16208 2009-06-21 19:19:26Z thomas $ + * @version $Id: Exception.php 20096 2010-01-06 02:05:09Z bkarwin $ */ /** @@ -29,7 +29,7 @@ require_once 'Zend/Exception.php'; * * @category Zend * @package Zend_Uri - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Uri_Exception extends Zend_Exception diff --git a/libs/Zend/Uri/Http.php b/libs/Zend/Uri/Http.php index c8ef6ac360..28f315953c 100644 --- a/libs/Zend/Uri/Http.php +++ b/libs/Zend/Uri/Http.php @@ -14,9 +14,9 @@ * * @category Zend * @package Zend_Uri - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 16208 2009-06-21 19:19:26Z thomas $ + * @version $Id: Http.php 20096 2010-01-06 02:05:09Z bkarwin $ */ /** @@ -35,7 +35,7 @@ require_once 'Zend/Validate/Hostname.php'; * @category Zend * @package Zend_Uri * @uses Zend_Uri - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Uri_Http extends Zend_Uri @@ -592,6 +592,23 @@ class Zend_Uri_Http extends Zend_Uri } /** + * Returns the query portion of the URL (after ?) as a + * key-value-array. If the query is empty an empty array + * is returned + * + * @return array + */ + public function getQueryAsArray() + { + $query = $this->getQuery(); + $querryArray = array(); + if ($query !== false) { + parse_str($query, $querryArray); + } + return $querryArray; + } + + /** * Returns true if and only if the query string passes validation. If no query is passed, * then the query string contained in the instance variable is used. * @@ -623,6 +640,32 @@ class Zend_Uri_Http extends Zend_Uri } /** + * Add or replace params in the query string for the current URI, and + * return the old query. + * + * @param array $queryParams + * @return string Old query string + */ + public function addReplaceQueryParameters(array $queryParams) + { + $queryParams = array_merge($this->getQueryAsArray(), $queryParams); + return $this->setQuery($queryParams); + } + + /** + * Remove params in the query string for the current URI, and + * return the old query. + * + * @param array $queryParamKeys + * @return string Old query string + */ + public function removeQueryParameters(array $queryParamKeys) + { + $queryParams = array_diff_key($this->getQueryAsArray(), array_fill_keys($queryParamKeys, 0)); + return $this->setQuery($queryParams); + } + + /** * Set the query string for the current URI, and return the old query * string This method accepts both strings and arrays. * diff --git a/libs/Zend/Validate.php b/libs/Zend/Validate.php index cb87ba5120..7a9216cd13 100644 --- a/libs/Zend/Validate.php +++ b/libs/Zend/Validate.php @@ -14,9 +14,9 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 16286 2009-06-25 15:11:37Z thomas $ + * @version $Id: Validate.php 20096 2010-01-06 02:05:09Z bkarwin $ */ /** @@ -27,7 +27,7 @@ require_once 'Zend/Validate/Interface.php'; /** * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Validate implements Zend_Validate_Interface @@ -195,29 +195,50 @@ class Zend_Validate implements Zend_Validate_Interface public static function is($value, $classBaseName, array $args = array(), $namespaces = array()) { $namespaces = array_merge((array) $namespaces, self::$_defaultNamespaces, array('Zend_Validate')); - foreach ($namespaces as $namespace) { - $className = $namespace . '_' . ucfirst($classBaseName); - try { - if (!class_exists($className)) { - require_once 'Zend/Loader.php'; - Zend_Loader::loadClass($className); + $className = ucfirst($classBaseName); + try { + if (!class_exists($className)) { + require_once 'Zend/Loader.php'; + foreach($namespaces as $namespace) { + $class = $namespace . '_' . $className; + $file = str_replace('_', DIRECTORY_SEPARATOR, $class) . '.php'; + if (Zend_Loader::isReadable($file)) { + Zend_Loader::loadClass($class); + $className = $class; + } } - $class = new ReflectionClass($className); - if ($class->implementsInterface('Zend_Validate_Interface')) { - if ($class->hasMethod('__construct')) { + } + + $class = new ReflectionClass($className); + if ($class->implementsInterface('Zend_Validate_Interface')) { + if ($class->hasMethod('__construct')) { + $keys = array_keys($args); + $numeric = false; + foreach($keys as $key) { + if (is_numeric($key)) { + $numeric = true; + break; + } + } + + if ($numeric) { $object = $class->newInstanceArgs($args); } else { - $object = $class->newInstance(); + $object = $class->newInstance($args); } - return $object->isValid($value); + } else { + $object = $class->newInstance(); } - } catch (Zend_Validate_Exception $ze) { - // if there is an exception while validating throw it - throw $ze; - } catch (Zend_Exception $ze) { - // fallthrough and continue for missing validation classes + + return $object->isValid($value); } + } catch (Zend_Validate_Exception $ze) { + // if there is an exception while validating throw it + throw $ze; + } catch (Exception $e) { + // fallthrough and continue for missing validation classes } + require_once 'Zend/Validate/Exception.php'; throw new Zend_Validate_Exception("Validate class not found from basename '$classBaseName'"); } diff --git a/libs/Zend/Validate/Abstract.php b/libs/Zend/Validate/Abstract.php index 3107360619..b59478e97d 100644 --- a/libs/Zend/Validate/Abstract.php +++ b/libs/Zend/Validate/Abstract.php @@ -14,9 +14,9 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 18688 2009-10-25 16:08:24Z thomas $ + * @version $Id: Abstract.php 20096 2010-01-06 02:05:09Z bkarwin $ */ /** @@ -27,7 +27,7 @@ require_once 'Zend/Validate/Interface.php'; /** * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Validate_Abstract implements Zend_Validate_Interface @@ -251,11 +251,11 @@ abstract class Zend_Validate_Abstract implements Zend_Validate_Interface } /** - * @param string $messageKey OPTIONAL + * @param string $messageKey * @param string $value OPTIONAL * @return void */ - protected function _error($messageKey = null, $value = null) + protected function _error($messageKey, $value = null) { if ($messageKey === null) { $keys = array_keys($this->_messageTemplates); diff --git a/libs/Zend/Validate/Alnum.php b/libs/Zend/Validate/Alnum.php index c2f2f46642..d222a368f3 100644 --- a/libs/Zend/Validate/Alnum.php +++ b/libs/Zend/Validate/Alnum.php @@ -14,9 +14,9 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 17467 2009-08-08 18:06:55Z thomas $ + * @version $Id: Alnum.php 20442 2010-01-20 15:15:40Z matthew $ */ /** @@ -27,20 +27,20 @@ require_once 'Zend/Validate/Abstract.php'; /** * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Validate_Alnum extends Zend_Validate_Abstract { const INVALID = 'alnumInvalid'; const NOT_ALNUM = 'notAlnum'; - const STRING_EMPTY = 'stringEmpty'; + const STRING_EMPTY = 'alnumStringEmpty'; /** * Whether to allow white space characters; off by default * * @var boolean - * @depreciated + * @deprecated */ public $allowWhiteSpace; @@ -58,18 +58,30 @@ class Zend_Validate_Alnum extends Zend_Validate_Abstract */ protected $_messageTemplates = array( self::INVALID => "Invalid type given, value should be float, string, or integer", - self::NOT_ALNUM => "'%value%' has not only alphabetic and digit characters", - self::STRING_EMPTY => "'%value%' is an empty string" + self::NOT_ALNUM => "'%value%' contains characters which are non alphabetic and no digits", + self::STRING_EMPTY => "'%value%' is an empty string", ); /** * Sets default option values for this instance * - * @param boolean $allowWhiteSpace + * @param boolean|Zend_Config $allowWhiteSpace * @return void */ public function __construct($allowWhiteSpace = false) { + if ($allowWhiteSpace instanceof Zend_Config) { + $allowWhiteSpace = $allowWhiteSpace->toArray(); + } + + if (is_array($allowWhiteSpace)) { + if (array_key_exists('allowWhiteSpace', $allowWhiteSpace)) { + $allowWhiteSpace = $allowWhiteSpace['allowWhiteSpace']; + } else { + $allowWhiteSpace = false; + } + } + $this->allowWhiteSpace = (boolean) $allowWhiteSpace; } diff --git a/libs/Zend/Validate/Alpha.php b/libs/Zend/Validate/Alpha.php index ce1f01872f..5474177744 100644 --- a/libs/Zend/Validate/Alpha.php +++ b/libs/Zend/Validate/Alpha.php @@ -14,9 +14,9 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 16223 2009-06-21 20:04:53Z thomas $ + * @version $Id: Alpha.php 20442 2010-01-20 15:15:40Z matthew $ */ /** @@ -27,20 +27,20 @@ require_once 'Zend/Validate/Abstract.php'; /** * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Validate_Alpha extends Zend_Validate_Abstract { const INVALID = 'alphaInvalid'; const NOT_ALPHA = 'notAlpha'; - const STRING_EMPTY = 'stringEmpty'; + const STRING_EMPTY = 'alphaStringEmpty'; /** * Whether to allow white space characters; off by default * * @var boolean - * @depreciated + * @deprecated */ public $allowWhiteSpace; @@ -58,18 +58,30 @@ class Zend_Validate_Alpha extends Zend_Validate_Abstract */ protected $_messageTemplates = array( self::INVALID => "Invalid type given, value should be a string", - self::NOT_ALPHA => "'%value%' has not only alphabetic characters", + self::NOT_ALPHA => "'%value%' contains non alphabetic characters", self::STRING_EMPTY => "'%value%' is an empty string" ); /** * Sets default option values for this instance * - * @param boolean $allowWhiteSpace + * @param boolean|Zend_Config $allowWhiteSpace * @return void */ public function __construct($allowWhiteSpace = false) { + if ($allowWhiteSpace instanceof Zend_Config) { + $allowWhiteSpace = $allowWhiteSpace->toArray(); + } + + if (is_array($allowWhiteSpace)) { + if (array_key_exists('allowWhiteSpace', $allowWhiteSpace)) { + $allowWhiteSpace = $allowWhiteSpace['allowWhiteSpace']; + } else { + $allowWhiteSpace = false; + } + } + $this->allowWhiteSpace = (boolean) $allowWhiteSpace; } diff --git a/libs/Zend/Validate/Barcode.php b/libs/Zend/Validate/Barcode.php index 374a9e5449..933999a504 100644 --- a/libs/Zend/Validate/Barcode.php +++ b/libs/Zend/Validate/Barcode.php @@ -14,9 +14,9 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 16223 2009-06-21 20:04:53Z thomas $ + * @version $Id: Barcode.php 20358 2010-01-17 19:03:49Z thomas $ */ /** @@ -25,59 +25,153 @@ require_once 'Zend/Validate/Abstract.php'; /** + * @see Zend_Loader + */ +require_once 'Zend/Loader.php'; + +/** * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Validate_Barcode extends Zend_Validate_Abstract { + const INVALID = 'barcodeInvalid'; + const FAILED = 'barcodeFailed'; + const INVALID_CHARS = 'barcodeInvalidChars'; + const INVALID_LENGTH = 'barcodeInvalidLength'; + + protected $_messageTemplates = array( + 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", + ); + + /** + * Additional variables available for validation failure messages + * + * @var array + */ + protected $_messageVariables = array( + 'length' => '_length' + ); + /** - * Barcode validator + * Length for the set subtype * - * @var Zend_Validate_Abstract + * @var integer */ - protected $_barcodeValidator; + protected $_length; + + /** + * Barcode adapter + * + * @var Zend_Validate_Barcode_BarcodeAdapter + */ + protected $_adapter; /** * Generates the standard validator object * - * @param string $barcodeType - Barcode validator to use + * @param string|Zend_Config| + * Zend_Validate_Barcode_BarcodeAdapter $adapter Barcode adapter to use * @return void * @throws Zend_Validate_Exception */ - public function __construct($barcodeType) + public function __construct($adapter) + { + if ($adapter instanceof Zend_Config) { + $adapter = $adapter->toArray(); + } + + $options = null; + $checksum = null; + if (is_array($adapter)) { + if (array_key_exists('options', $adapter)) { + $options = $adapter['options']; + } + + if (array_key_exists('checksum', $adapter)) { + $checksum = $adapter['checksum']; + } + + if (array_key_exists('adapter', $adapter)) { + $adapter = $adapter['adapter']; + } else { + require_once 'Zend/Validate/Exception.php'; + throw new Zend_Validate_Exception("Missing option 'adapter'"); + } + } + + $this->setAdapter($adapter, $options); + if ($checksum !== null) { + $this->setChecksum($checksum); + } + } + + /** + * Returns the set adapter + * + * @return Zend_Validate_Barcode_BarcodeAdapter + */ + public function getAdapter() { - $this->setType($barcodeType); + return $this->_adapter; } /** - * Sets a new barcode validator + * Sets a new barcode adapter * - * @param string $barcodeType - Barcode validator to use + * @param string|Zend_Validate_Barcode $adapter Barcode adapter to use + * @param array $options Options for this adapter * @return void * @throws Zend_Validate_Exception */ - public function setType($barcodeType) + public function setAdapter($adapter, $options = null) { - switch (strtolower($barcodeType)) { - case 'upc': - case 'upc-a': - require_once 'Zend/Validate/Barcode/UpcA.php'; - $class = 'Zend_Validate_Barcode_UpcA'; - break; - case 'ean13': - case 'ean-13': - require_once 'Zend/Validate/Barcode/Ean13.php'; - $class = 'Zend_Validate_Barcode_Ean13'; - break; - default: - require_once 'Zend/Validate/Exception.php'; - throw new Zend_Validate_Exception("Barcode type '$barcodeType' is not supported'"); - break; + $adapter = ucfirst(strtolower($adapter)); + require_once 'Zend/Loader.php'; + if (Zend_Loader::isReadable('Zend/Validate/Barcode/' . $adapter. '.php')) { + $adapter = 'Zend_Validate_Barcode_' . $adapter; + } + + if (!class_exists($adapter)) { + Zend_Loader::loadClass($adapter); } - $this->_barcodeValidator = new $class; + $this->_adapter = new $adapter($options); + if (!$this->_adapter instanceof Zend_Validate_Barcode_AdapterInterface) { + require_once 'Zend/Validate/Exception.php'; + throw new Zend_Validate_Exception( + "Adapter " . $adapter . " does not implement Zend_Validate_Barcode_AdapterInterface" + ); + } + + return $this; + } + + /** + * Returns the checksum option + * + * @return boolean + */ + public function getChecksum() + { + return $this->getAdapter()->getCheck(); + } + + /** + * Sets the checksum option + * + * @param boolean $checksum + * @return Zend_Validate_Barcode + */ + public function setChecksum($checksum) + { + $this->getAdapter()->setCheck($checksum); + return $this; } /** @@ -90,6 +184,34 @@ class Zend_Validate_Barcode extends Zend_Validate_Abstract */ public function isValid($value) { - return call_user_func(array($this->_barcodeValidator, 'isValid'), $value); + if (!is_string($value)) { + $this->_error(self::INVALID); + return false; + } + + $this->_value = (string) $value; + $adapter = $this->getAdapter(); + $this->_length = $adapter->getLength(); + $result = $adapter->checkLength($value); + if (!$result) { + $this->_error(self::INVALID_LENGTH); + return false; + } + + $result = $adapter->checkChars($value); + if (!$result) { + $this->_error(self::INVALID_CHARS); + return false; + } + + if ($this->getChecksum()) { + $result = $adapter->checksum($value); + if (!$result) { + $this->_error(self::FAILED); + return false; + } + } + + return true; } -} +}
\ No newline at end of file diff --git a/libs/Zend/Validate/Barcode/AdapterAbstract.php b/libs/Zend/Validate/Barcode/AdapterAbstract.php new file mode 100644 index 0000000000..043189e6c2 --- /dev/null +++ b/libs/Zend/Validate/Barcode/AdapterAbstract.php @@ -0,0 +1,315 @@ +<?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_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 $ + */ + +/** + * @see Zend_Validate_Barcode_AdapterInterface + */ +require_once 'Zend/Validate/Barcode/AdapterInterface.php'; + +/** + * @category Zend + * @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 + */ +abstract class Zend_Validate_Barcode_AdapterAbstract + implements Zend_Validate_Barcode_AdapterInterface +{ + /** + * Allowed barcode lengths + * @var integer|array|string + */ + protected $_length; + + /** + * Allowed barcode characters + * @var string + */ + protected $_characters; + + /** + * Callback to checksum function + * @var string|array + */ + protected $_checksum; + + /** + * Is a checksum value included? + * @var boolean + */ + protected $_hasChecksum = true; + + /** + * Checks the length of a barcode + * + * @param string $value The barcode to check for proper length + * @return boolean + */ + public function checkLength($value) + { + if (!is_string($value)) { + return false; + } + + $fixum = strlen($value); + $found = false; + $length = $this->getLength(); + if (is_array($length)) { + foreach ($length as $value) { + if ($fixum == $value) { + $found = true; + } + + if ($value == -1) { + $found = true; + } + } + } elseif ($fixum == $length) { + $found = true; + } elseif ($length == -1) { + $found = true; + } elseif ($length == 'even') { + $count = $fixum % 2; + $found = ($count == 0) ? true : false; + } elseif ($length == 'odd') { + $count = $fixum % 2; + $found = ($count == 1) ? true : false; + } + + return $found; + } + + /** + * Checks for allowed characters within the barcode + * + * @param string $value The barcode to check for allowed characters + * @return boolean + */ + public function checkChars($value) + { + if (!is_string($value)) { + return false; + } + + $characters = $this->getCharacters(); + if ($characters == 128) { + for ($x = 0; $x < 128; ++$x) { + $value = str_replace(chr($x), '', $value); + } + } else { + $chars = str_split($characters); + foreach ($chars as $char) { + $value = str_replace($char, '', $value); + } + } + + if (strlen($value) > 0) { + return false; + } + + return true; + } + + /** + * Validates the checksum + * + * @param string $value The barcode to check the checksum for + * @return boolean + */ + public function checksum($value) + { + $checksum = $this->getChecksum(); + if (!empty($checksum)) { + if (method_exists($this, $checksum)) { + return call_user_func(array($this, $checksum), $value); + } + } + + return false; + } + + /** + * Returns the allowed barcode length + * + * @return string + */ + public function getLength() + { + return $this->_length; + } + + /** + * Returns the allowed characters + * + * @return integer|string + */ + public function getCharacters() + { + return $this->_characters; + } + + /** + * Returns the checksum function name + * + */ + public function getChecksum() + { + return $this->_checksum; + } + + /** + * Returns if barcode uses checksum + * + * @return boolean + */ + public function getCheck() + { + return $this->_hasChecksum; + } + + /** + * Sets the checksum validation + * + * @param boolean $check + * @return Zend_Validate_Barcode_AdapterAbstract + */ + public function setCheck($check) + { + $this->_hasChecksum = (boolean) $check; + return $this; + } + + /** + * Validates the checksum (Modulo 10) + * GTIN implementation factor 3 + * + * @param string $value The barcode to validate + * @return boolean + */ + protected function _gtin($value) + { + $barcode = substr($value, 0, -1); + $sum = 0; + $length = strlen($barcode) - 1; + + for ($i = 0; $i <= $length; $i++) { + if (($i % 2) === 0) { + $sum += $barcode[$length - $i] * 3; + } else { + $sum += $barcode[$length - $i]; + } + } + + $calc = $sum % 10; + $checksum = ($calc === 0) ? 0 : (10 - $calc); + if ($value[$length + 1] != $checksum) { + return false; + } + + return true; + } + + /** + * Validates the checksum (Modulo 10) + * IDENTCODE implementation factors 9 and 4 + * + * @param string $value The barcode to validate + * @return boolean + */ + protected function _identcode($value) + { + $barcode = substr($value, 0, -1); + $sum = 0; + $length = strlen($value) - 2; + + for ($i = 0; $i <= $length; $i++) { + if (($i % 2) === 0) { + $sum += $barcode[$length - $i] * 4; + } else { + $sum += $barcode[$length - $i] * 9; + } + } + + $calc = $sum % 10; + $checksum = ($calc === 0) ? 0 : (10 - $calc); + if ($value[$length + 1] != $checksum) { + return false; + } + + return true; + } + + /** + * Validates the checksum (Modulo 10) + * CODE25 implementation factor 3 + * + * @param string $value The barcode to validate + * @return boolean + */ + protected function _code25($value) + { + $barcode = substr($value, 0, -1); + $sum = 0; + $length = strlen($barcode) - 1; + + for ($i = 0; $i <= $length; $i++) { + if (($i % 2) === 0) { + $sum += $barcode[$i] * 3; + } else { + $sum += $barcode[$i]; + } + } + + $calc = $sum % 10; + $checksum = ($calc === 0) ? 0 : (10 - $calc); + if ($value[$length + 1] != $checksum) { + return false; + } + + return true; + } + + /** + * Validates the checksum () + * POSTNET implementation + * + * @param string $value The barcode to validate + * @return boolean + */ + protected function _postnet($value) + { + $checksum = substr($value, -1, 1); + $values = str_split(substr($value, 0, -1)); + + $check = 0; + foreach($values as $row) { + $check += $row; + } + + $check %= 10; + $check = 10 - $check; + if ($check == $checksum) { + return true; + } + + return false; + } +} diff --git a/libs/Zend/Validate/Barcode/AdapterInterface.php b/libs/Zend/Validate/Barcode/AdapterInterface.php new file mode 100644 index 0000000000..325c6048f3 --- /dev/null +++ b/libs/Zend/Validate/Barcode/AdapterInterface.php @@ -0,0 +1,68 @@ +<?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_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 $ + */ + +/** + * @category Zend + * @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 + */ +interface Zend_Validate_Barcode_AdapterInterface +{ + /** + * Checks the length of a barcode + * + * @param string $value The barcode to check for proper length + * @return boolean + */ + public function checkLength($value); + + /** + * Checks for allowed characters within the barcode + * + * @param string $value The barcode to check for allowed characters + * @return boolean + */ + public function checkChars($value); + + /** + * Validates the checksum + * + * @param string $value The barcode to check the checksum for + * @return boolean + */ + public function checksum($value); + + /** + * Returns if barcode uses a checksum + * + * @return boolean + */ + public function getCheck(); + + /** + * Sets the checksum validation + * + * @param boolean $check + * @return Zend_Validate_Barcode_Adapter Provides fluid interface + */ + public function setCheck($check); +} diff --git a/libs/Zend/Validate/Barcode/Code25.php b/libs/Zend/Validate/Barcode/Code25.php new file mode 100644 index 0000000000..efb5a395c7 --- /dev/null +++ b/libs/Zend/Validate/Barcode/Code25.php @@ -0,0 +1,64 @@ +<?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_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:$ + */ + +/** + * @see Zend_Validate_Barcode_AdapterAbstract + */ +require_once 'Zend/Validate/Barcode/AdapterAbstract.php'; + +/** + * @category Zend + * @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 + */ +class Zend_Validate_Barcode_Code25 extends Zend_Validate_Barcode_AdapterAbstract +{ + /** + * Allowed barcode lengths + * @var integer + */ + protected $_length = -1; + + /** + * Allowed barcode characters + * @var string + */ + protected $_characters = '0123456789'; + + /** + * Checksum function + * @var string + */ + protected $_checksum = '_code25'; + + /** + * Constructor + * + * Sets check flag to false. + * + * @return void + */ + public function __construct() + { + $this->setCheck(false); + } +} diff --git a/libs/Zend/Validate/Barcode/Code25interleaved.php b/libs/Zend/Validate/Barcode/Code25interleaved.php new file mode 100644 index 0000000000..7e5a8d919b --- /dev/null +++ b/libs/Zend/Validate/Barcode/Code25interleaved.php @@ -0,0 +1,64 @@ +<?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_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:$ + */ + +/** + * @see Zend_Validate_Barcode_AdapterAbstract + */ +require_once 'Zend/Validate/Barcode/AdapterAbstract.php'; + +/** + * @category Zend + * @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 + */ +class Zend_Validate_Barcode_Code25interleaved extends Zend_Validate_Barcode_AdapterAbstract +{ + /** + * Allowed barcode lengths + * @var integer + */ + protected $_length = 'even'; + + /** + * Allowed barcode characters + * @var string + */ + protected $_characters = '0123456789'; + + /** + * Checksum function + * @var string + */ + protected $_checksum = '_code25'; + + /** + * Constructor + * + * Sets check flag to false. + * + * @return void + */ + public function __construct() + { + $this->setCheck(false); + } +} diff --git a/libs/Zend/Validate/Barcode/Code39.php b/libs/Zend/Validate/Barcode/Code39.php new file mode 100644 index 0000000000..858084fe25 --- /dev/null +++ b/libs/Zend/Validate/Barcode/Code39.php @@ -0,0 +1,100 @@ +<?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_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:$ + */ + +/** + * @see Zend_Validate_Barcode_AdapterAbstract + */ +require_once 'Zend/Validate/Barcode/AdapterAbstract.php'; + +/** + * @category Zend + * @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 + */ +class Zend_Validate_Barcode_Code39 extends Zend_Validate_Barcode_AdapterAbstract +{ + /** + * Allowed barcode lengths + * @var integer + */ + protected $_length = -1; + + /** + * Allowed barcode characters + * @var string + */ + protected $_characters = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ -.$/+%'; + + /** + * Checksum function + * @var string + */ + protected $_checksum = '_code39'; + + /** + * @var array + */ + protected $_check = array( + '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, + '7' => 7, '8' => 8, '9' => 9, 'A' => 10, 'B' => 11, 'C' => 12, 'D' => 13, + 'E' => 14, 'F' => 15, 'G' => 16, 'H' => 17, 'I' => 18, 'J' => 19, 'K' => 20, + 'L' => 21, 'M' => 22, 'N' => 23, 'O' => 24, 'P' => 25, 'Q' => 26, 'R' => 27, + 'S' => 28, 'T' => 29, 'U' => 30, 'V' => 31, 'W' => 32, 'X' => 33, 'Y' => 34, + 'Z' => 35, '-' => 36, '.' => 37, ' ' => 38, '$' => 39, '/' => 40, '+' => 41, + '%' => 42, + ); + + /** + * Constructor + * + * Sets check flag to false. + * + * @return void + */ + public function __construct() + { + $this->setCheck(false); + } + + /** + * Validates the checksum (Modulo 43) + * + * @param string $value The barcode to validate + * @return boolean + */ + protected function _code39($value) + { + $checksum = substr($value, -1, 1); + $value = str_split(substr($value, 0, -1)); + $count = 0; + foreach($value as $char) { + $count += $this->_check[$char]; + } + + $mod = $count % 43; + if ($mod == $this->_check[$checksum]) { + return true; + } + + return false; + } +} diff --git a/libs/Zend/Validate/Barcode/Code39ext.php b/libs/Zend/Validate/Barcode/Code39ext.php new file mode 100644 index 0000000000..5c1d65ee64 --- /dev/null +++ b/libs/Zend/Validate/Barcode/Code39ext.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_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:$ + */ + +/** + * @see Zend_Validate_Barcode_AdapterAbstract + */ +require_once 'Zend/Validate/Barcode/AdapterAbstract.php'; + +/** + * @category Zend + * @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 + */ +class Zend_Validate_Barcode_Code39ext extends Zend_Validate_Barcode_AdapterAbstract +{ + /** + * Allowed barcode lengths + * @var integer + */ + protected $_length = -1; + + /** + * Allowed barcode characters + * @var string + */ + protected $_characters = 128; + + /** + * Constructor + * + * Sets check flag to false. + * + * @return void + */ + public function __construct() + { + $this->setCheck(false); + } +} diff --git a/libs/Zend/Validate/Barcode/Code93.php b/libs/Zend/Validate/Barcode/Code93.php new file mode 100644 index 0000000000..deb5183d43 --- /dev/null +++ b/libs/Zend/Validate/Barcode/Code93.php @@ -0,0 +1,120 @@ +<?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_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:$ + */ + +/** + * @see Zend_Validate_Barcode_AdapterAbstract + */ +require_once 'Zend/Validate/Barcode/AdapterAbstract.php'; + +/** + * @category Zend + * @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 + */ +class Zend_Validate_Barcode_Code93 extends Zend_Validate_Barcode_AdapterAbstract +{ + /** + * Allowed barcode lengths + * @var integer + */ + protected $_length = -1; + + /** + * Allowed barcode characters + * @var string + */ + protected $_characters = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ -.$/+%'; + + /** + * Checksum function + * @var string + */ + protected $_checksum = '_code93'; + + /** + * Note that the characters !"§& are only synonyms + * @var array + */ + protected $_check = array( + '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, + '7' => 7, '8' => 8, '9' => 9, 'A' => 10, 'B' => 11, 'C' => 12, 'D' => 13, + 'E' => 14, 'F' => 15, 'G' => 16, 'H' => 17, 'I' => 18, 'J' => 19, 'K' => 20, + 'L' => 21, 'M' => 22, 'N' => 23, 'O' => 24, 'P' => 25, 'Q' => 26, 'R' => 27, + 'S' => 28, 'T' => 29, 'U' => 30, 'V' => 31, 'W' => 32, 'X' => 33, 'Y' => 34, + 'Z' => 35, '-' => 36, '.' => 37, ' ' => 38, '$' => 39, '/' => 40, '+' => 41, + '%' => 42, '!' => 43, '"' => 44, '§' => 45, '&' => 46, + ); + + /** + * Constructor + * + * Sets check flag to false. + * + * @return void + */ + public function __construct() + { + $this->setCheck(false); + } + + /** + * Validates the checksum (Modulo CK) + * + * @param string $value The barcode to validate + * @return boolean + */ + protected function _code93($value) + { + $checksum = substr($value, -2, 2); + $value = str_split(substr($value, 0, -2)); + $count = 0; + $length = count($value) % 20; + foreach($value as $char) { + if ($length == 0) { + $length = 20; + } + + $count += $this->_check[$char] * $length; + --$length; + } + + $check = array_search(($count % 47), $this->_check); + $value[] = $check; + $count = 0; + $length = count($value) % 15; + foreach($value as $char) { + if ($length == 0) { + $length = 15; + } + + $count += $this->_check[$char] * $length; + --$length; + } + $check .= array_search(($count % 47), $this->_check); + + if ($check == $checksum) { + return true; + } + + return false; + } +} diff --git a/libs/Zend/Validate/Barcode/Code93ext.php b/libs/Zend/Validate/Barcode/Code93ext.php new file mode 100644 index 0000000000..740d485c4a --- /dev/null +++ b/libs/Zend/Validate/Barcode/Code93ext.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_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:$ + */ + +/** + * @see Zend_Validate_Barcode_AdapterAbstract + */ +require_once 'Zend/Validate/Barcode/AdapterAbstract.php'; + +/** + * @category Zend + * @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 + */ +class Zend_Validate_Barcode_Code93ext extends Zend_Validate_Barcode_AdapterAbstract +{ + /** + * Allowed barcode lengths + * @var integer + */ + protected $_length = -1; + + /** + * Allowed barcode characters + * @var string + */ + protected $_characters = 128; + + /** + * Constructor + * + * Sets check flag to false. + * + * @return void + */ + public function __construct() + { + $this->setCheck(false); + } +} diff --git a/libs/Zend/Validate/Barcode/Ean12.php b/libs/Zend/Validate/Barcode/Ean12.php new file mode 100644 index 0000000000..56a2384be2 --- /dev/null +++ b/libs/Zend/Validate/Barcode/Ean12.php @@ -0,0 +1,52 @@ +<?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_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 $ + */ + +/** + * @see Zend_Validate_Barcode_AdapterAbstract + */ +require_once 'Zend/Validate/Barcode/AdapterAbstract.php'; + +/** + * @category Zend + * @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 + */ +class Zend_Validate_Barcode_Ean12 extends Zend_Validate_Barcode_AdapterAbstract +{ + /** + * Allowed barcode lengths + * @var integer + */ + protected $_length = 12; + + /** + * Allowed barcode characters + * @var string + */ + protected $_characters = '0123456789'; + + /** + * Checksum function + * @var string + */ + protected $_checksum = '_gtin'; +} diff --git a/libs/Zend/Validate/Barcode/Ean13.php b/libs/Zend/Validate/Barcode/Ean13.php index 068809248c..b7e52f4c13 100644 --- a/libs/Zend/Validate/Barcode/Ean13.php +++ b/libs/Zend/Validate/Barcode/Ean13.php @@ -1,5 +1,4 @@ <?php - /** * Zend Framework * @@ -15,96 +14,39 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 16223 2009-06-21 20:04:53Z thomas $ + * @version $Id: Ean13.php 20096 2010-01-06 02:05:09Z bkarwin $ */ - /** - * @see Zend_Validate_Abstract + * @see Zend_Validate_Barcode_AdapterAbstract */ -require_once 'Zend/Validate/Abstract.php'; - +require_once 'Zend/Validate/Barcode/AdapterAbstract.php'; /** * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Validate_Barcode_Ean13 extends Zend_Validate_Abstract +class Zend_Validate_Barcode_Ean13 extends Zend_Validate_Barcode_AdapterAbstract { /** - * Validation failure message key for when the value is - * an invalid barcode - */ - const INVALID = 'invalid'; - - /** - * Validation failure message key for when the value is - * not 13 characters long + * Allowed barcode lengths + * @var integer */ - const INVALID_LENGTH = 'invalidLength'; + protected $_length = 13; /** - * Validation failure message key for when the value - * does not only contain numeric characters + * Allowed barcode characters + * @var string */ - const NOT_NUMERIC = 'ean13NotNumeric'; + protected $_characters = '0123456789'; /** - * Validation failure message template definitions - * - * @var array + * Checksum function + * @var string */ - protected $_messageTemplates = array( - self::INVALID => "'%value%' is an invalid EAN-13 barcode", - self::INVALID_LENGTH => "'%value%' should be 13 characters", - self::NOT_NUMERIC => "'%value%' should contain only numeric characters", - ); - - /** - * Defined by Zend_Validate_Interface - * - * Returns true if and only if $value contains a valid barcode - * - * @param string $value - * @return boolean - */ - public function isValid($value) - { - if (!is_string($value) || !ctype_digit($value)) { - $this->_error(self::NOT_NUMERIC); - return false; - } - - $this->_setValue($value); - if (strlen($value) !== 13) { - $this->_error(self::INVALID_LENGTH); - return false; - } - - $barcode = strrev(substr($value, 0, -1)); - $oddSum = 0; - $evenSum = 0; - - for ($i = 0; $i < 12; $i++) { - if ($i % 2 === 0) { - $oddSum += $barcode[$i] * 3; - } elseif ($i % 2 === 1) { - $evenSum += $barcode[$i]; - } - } - - $calculation = ($oddSum + $evenSum) % 10; - $checksum = ($calculation === 0) ? 0 : 10 - $calculation; - - if ($value[12] != $checksum) { - $this->_error(self::INVALID); - return false; - } - - return true; - } + protected $_checksum = '_gtin'; } diff --git a/libs/Zend/Validate/Barcode/Ean14.php b/libs/Zend/Validate/Barcode/Ean14.php new file mode 100644 index 0000000000..93d46d8c4f --- /dev/null +++ b/libs/Zend/Validate/Barcode/Ean14.php @@ -0,0 +1,52 @@ +<?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_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 $ + */ + +/** + * @see Zend_Validate_Barcode_AdapterAbstract + */ +require_once 'Zend/Validate/Barcode/AdapterAbstract.php'; + +/** + * @category Zend + * @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 + */ +class Zend_Validate_Barcode_Ean14 extends Zend_Validate_Barcode_AdapterAbstract +{ + /** + * Allowed barcode lengths + * @var integer + */ + protected $_length = 14; + + /** + * Allowed barcode characters + * @var string + */ + protected $_characters = '0123456789'; + + /** + * Checksum function + * @var string + */ + protected $_checksum = '_gtin'; +} diff --git a/libs/Zend/Validate/Barcode/Ean18.php b/libs/Zend/Validate/Barcode/Ean18.php new file mode 100644 index 0000000000..93398dd916 --- /dev/null +++ b/libs/Zend/Validate/Barcode/Ean18.php @@ -0,0 +1,52 @@ +<?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_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 $ + */ + +/** + * @see Zend_Validate_Barcode_AdapterAbstract + */ +require_once 'Zend/Validate/Barcode/AdapterAbstract.php'; + +/** + * @category Zend + * @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 + */ +class Zend_Validate_Barcode_Ean18 extends Zend_Validate_Barcode_AdapterAbstract +{ + /** + * Allowed barcode lengths + * @var integer + */ + protected $_length = 18; + + /** + * Allowed barcode characters + * @var string + */ + protected $_characters = '0123456789'; + + /** + * Checksum function + * @var string + */ + protected $_checksum = '_gtin'; +} diff --git a/libs/Zend/Validate/Barcode/Ean2.php b/libs/Zend/Validate/Barcode/Ean2.php new file mode 100644 index 0000000000..deab558ea4 --- /dev/null +++ b/libs/Zend/Validate/Barcode/Ean2.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_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:$ + */ + +/** + * @see Zend_Validate_Barcode_AdapterAbstract + */ +require_once 'Zend/Validate/Barcode/AdapterAbstract.php'; + +/** + * @category Zend + * @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 + */ +class Zend_Validate_Barcode_Ean2 extends Zend_Validate_Barcode_AdapterAbstract +{ + /** + * Allowed barcode lengths + * @var integer + */ + protected $_length = 2; + + /** + * Allowed barcode characters + * @var string + */ + protected $_characters = '0123456789'; + + /** + * Constructor + * + * Sets check flag to false. + * + * @return void + */ + public function __construct() + { + $this->setCheck(false); + } +} diff --git a/libs/Zend/Validate/Barcode/Ean5.php b/libs/Zend/Validate/Barcode/Ean5.php new file mode 100644 index 0000000000..af6e493241 --- /dev/null +++ b/libs/Zend/Validate/Barcode/Ean5.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_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:$ + */ + +/** + * @see Zend_Validate_Barcode_AdapterAbstract + */ +require_once 'Zend/Validate/Barcode/AdapterAbstract.php'; + +/** + * @category Zend + * @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 + */ +class Zend_Validate_Barcode_Ean5 extends Zend_Validate_Barcode_AdapterAbstract +{ + /** + * Allowed barcode lengths + * @var integer + */ + protected $_length = 5; + + /** + * Allowed barcode characters + * @var string + */ + protected $_characters = '0123456789'; + + /** + * Constructor + * + * Sets check flag to false. + * + * @return void + */ + public function __construct() + { + $this->setCheck(false); + } +} diff --git a/libs/Zend/Validate/Barcode/Ean8.php b/libs/Zend/Validate/Barcode/Ean8.php new file mode 100644 index 0000000000..c87af039fd --- /dev/null +++ b/libs/Zend/Validate/Barcode/Ean8.php @@ -0,0 +1,69 @@ +<?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_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:$ + */ + +/** + * @see Zend_Validate_Barcode_AdapterAbstract + */ +require_once 'Zend/Validate/Barcode/AdapterAbstract.php'; + +/** + * @category Zend + * @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 + */ +class Zend_Validate_Barcode_Ean8 extends Zend_Validate_Barcode_AdapterAbstract +{ + /** + * Allowed barcode lengths + * @var integer + */ + protected $_length = array(7, 8); + + /** + * Allowed barcode characters + * @var string + */ + protected $_characters = '0123456789'; + + /** + * Checksum function + * @var string + */ + protected $_checksum = '_gtin'; + + /** + * Overrides parent checkLength + * + * @param string $value Value + * @return boolean + */ + public function checkLength($value) + { + if (strlen($value) == 7) { + $this->setCheck(false); + } else { + $this->setCheck(true); + } + + return parent::checkLength($value); + } +} diff --git a/libs/Zend/Validate/Barcode/Gtin12.php b/libs/Zend/Validate/Barcode/Gtin12.php new file mode 100644 index 0000000000..8915c4ec4c --- /dev/null +++ b/libs/Zend/Validate/Barcode/Gtin12.php @@ -0,0 +1,52 @@ +<?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_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 $ + */ + +/** + * @see Zend_Validate_Barcode_AdapterAbstract + */ +require_once 'Zend/Validate/Barcode/AdapterAbstract.php'; + +/** + * @category Zend + * @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 + */ +class Zend_Validate_Barcode_Gtin12 extends Zend_Validate_Barcode_AdapterAbstract +{ + /** + * Allowed barcode lengths + * @var integer + */ + protected $_length = 12; + + /** + * Allowed barcode characters + * @var string + */ + protected $_characters = '0123456789'; + + /** + * Checksum function + * @var string + */ + protected $_checksum = '_gtin'; +} diff --git a/libs/Zend/Validate/Barcode/Gtin13.php b/libs/Zend/Validate/Barcode/Gtin13.php new file mode 100644 index 0000000000..0719b31eb6 --- /dev/null +++ b/libs/Zend/Validate/Barcode/Gtin13.php @@ -0,0 +1,52 @@ +<?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_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 $ + */ + +/** + * @see Zend_Validate_Barcode_AdapterAbstract + */ +require_once 'Zend/Validate/Barcode/AdapterAbstract.php'; + +/** + * @category Zend + * @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 + */ +class Zend_Validate_Barcode_Gtin13 extends Zend_Validate_Barcode_AdapterAbstract +{ + /** + * Allowed barcode lengths + * @var integer + */ + protected $_length = 13; + + /** + * Allowed barcode characters + * @var string + */ + protected $_characters = '0123456789'; + + /** + * Checksum function + * @var string + */ + protected $_checksum = '_gtin'; +} diff --git a/libs/Zend/Validate/Barcode/Gtin14.php b/libs/Zend/Validate/Barcode/Gtin14.php new file mode 100644 index 0000000000..d1dad51069 --- /dev/null +++ b/libs/Zend/Validate/Barcode/Gtin14.php @@ -0,0 +1,52 @@ +<?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_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 $ + */ + +/** + * @see Zend_Validate_Barcode_AdapterAbstract + */ +require_once 'Zend/Validate/Barcode/AdapterAbstract.php'; + +/** + * @category Zend + * @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 + */ +class Zend_Validate_Barcode_Gtin14 extends Zend_Validate_Barcode_AdapterAbstract +{ + /** + * Allowed barcode lengths + * @var integer + */ + protected $_length = 14; + + /** + * Allowed barcode characters + * @var string + */ + protected $_characters = '0123456789'; + + /** + * Checksum function + * @var string + */ + protected $_checksum = '_gtin'; +} diff --git a/libs/Zend/Validate/Barcode/Identcode.php b/libs/Zend/Validate/Barcode/Identcode.php new file mode 100644 index 0000000000..c0119a5cd9 --- /dev/null +++ b/libs/Zend/Validate/Barcode/Identcode.php @@ -0,0 +1,52 @@ +<?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_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:$ + */ + +/** + * @see Zend_Validate_Barcode_AdapterAbstract + */ +require_once 'Zend/Validate/Barcode/AdapterAbstract.php'; + +/** + * @category Zend + * @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 + */ +class Zend_Validate_Barcode_Identcode extends Zend_Validate_Barcode_AdapterAbstract +{ + /** + * Allowed barcode lengths + * @var integer + */ + protected $_length = 12; + + /** + * Allowed barcode characters + * @var string + */ + protected $_characters = '0123456789'; + + /** + * Checksum function + * @var string + */ + protected $_checksum = '_identcode'; +} diff --git a/libs/Zend/Validate/Barcode/Intelligentmail.php b/libs/Zend/Validate/Barcode/Intelligentmail.php new file mode 100644 index 0000000000..4c266db8a4 --- /dev/null +++ b/libs/Zend/Validate/Barcode/Intelligentmail.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_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:$ + */ + +/** + * @see Zend_Validate_Barcode_AdapterAbstract + */ +require_once 'Zend/Validate/Barcode/AdapterAbstract.php'; + +/** + * @category Zend + * @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 + */ +class Zend_Validate_Barcode_IntelligentMail extends Zend_Validate_Barcode_AdapterAbstract +{ + /** + * Allowed barcode lengths + * @var integer + */ + protected $_length = array(20, 25, 29, 31); + + /** + * Allowed barcode characters + * @var string + */ + protected $_characters = '0123456789'; + + /** + * Constructor + * + * Sets check flag to false. + * + * @return void + */ + public function __construct() + { + $this->setCheck(false); + } +} diff --git a/libs/Zend/Validate/Barcode/Issn.php b/libs/Zend/Validate/Barcode/Issn.php new file mode 100644 index 0000000000..be629920e7 --- /dev/null +++ b/libs/Zend/Validate/Barcode/Issn.php @@ -0,0 +1,119 @@ +<?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_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:$ + */ + +/** + * @see Zend_Validate_Barcode_AdapterAbstract + */ +require_once 'Zend/Validate/Barcode/AdapterAbstract.php'; + +/** + * @category Zend + * @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 + */ +class Zend_Validate_Barcode_Issn extends Zend_Validate_Barcode_AdapterAbstract +{ + /** + * Allowed barcode lengths + * @var integer + */ + protected $_length = array(8, 13); + + /** + * Allowed barcode characters + * @var string + */ + protected $_characters = '0123456789X'; + + /** + * Checksum function + * @var string + */ + protected $_checksum = '_gtin'; + + /** + * Allows X on length of 8 chars + * + * @param string $value The barcode to check for allowed characters + * @return boolean + */ + public function checkChars($value) + { + if (strlen($value) != 8) { + if (strpos($value, 'X') !== false) { + return false; + } + } + + return parent::checkChars($value); + } + + /** + * Validates the checksum + * + * @param string $value The barcode to check the checksum for + * @return boolean + */ + public function checksum($value) + { + if (strlen($value) == 8) { + $this->_checksum = '_issn'; + } else { + $this->_checksum = '_gtin'; + } + + return parent::checksum($value); + } + + /** + * Validates the checksum () + * ISSN implementation (reversed mod11) + * + * @param string $value The barcode to validate + * @return boolean + */ + protected function _issn($value) + { + $checksum = substr($value, -1, 1); + $values = str_split(substr($value, 0, -1)); + $check = 0; + $multi = 8; + foreach($values as $token) { + if ($token == 'X') { + $token = 10; + } + + $check += ($token * $multi); + --$multi; + } + + $check %= 11; + $check = 11 - $check; + if ($check == $checksum) { + return true; + } else if (($check == 10) && ($checksum == 'X')) { + return true; + } + + return false; + } +} diff --git a/libs/Zend/Validate/Barcode/Itf14.php b/libs/Zend/Validate/Barcode/Itf14.php new file mode 100644 index 0000000000..d207a314c8 --- /dev/null +++ b/libs/Zend/Validate/Barcode/Itf14.php @@ -0,0 +1,52 @@ +<?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_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 $ + */ + +/** + * @see Zend_Validate_Barcode_AdapterAbstract + */ +require_once 'Zend/Validate/Barcode/AdapterAbstract.php'; + +/** + * @category Zend + * @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 + */ +class Zend_Validate_Barcode_Itf14 extends Zend_Validate_Barcode_AdapterAbstract +{ + /** + * Allowed barcode lengths + * @var integer + */ + protected $_length = 14; + + /** + * Allowed barcode characters + * @var string + */ + protected $_characters = '0123456789'; + + /** + * Checksum function + * @var string + */ + protected $_checksum = '_gtin'; +} diff --git a/libs/Zend/Validate/Barcode/Leitcode.php b/libs/Zend/Validate/Barcode/Leitcode.php new file mode 100644 index 0000000000..551ded0649 --- /dev/null +++ b/libs/Zend/Validate/Barcode/Leitcode.php @@ -0,0 +1,52 @@ +<?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_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:$ + */ + +/** + * @see Zend_Validate_Barcode_AdapterAbstract + */ +require_once 'Zend/Validate/Barcode/AdapterAbstract.php'; + +/** + * @category Zend + * @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 + */ +class Zend_Validate_Barcode_Leitcode extends Zend_Validate_Barcode_AdapterAbstract +{ + /** + * Allowed barcode lengths + * @var integer + */ + protected $_length = 14; + + /** + * Allowed barcode characters + * @var string + */ + protected $_characters = '0123456789'; + + /** + * Checksum function + * @var string + */ + protected $_checksum = '_identcode'; +} diff --git a/libs/Zend/Validate/Barcode/Planet.php b/libs/Zend/Validate/Barcode/Planet.php new file mode 100644 index 0000000000..72608fa38a --- /dev/null +++ b/libs/Zend/Validate/Barcode/Planet.php @@ -0,0 +1,52 @@ +<?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_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:$ + */ + +/** + * @see Zend_Validate_Barcode_AdapterAbstract + */ +require_once 'Zend/Validate/Barcode/AdapterAbstract.php'; + +/** + * @category Zend + * @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 + */ +class Zend_Validate_Barcode_Planet extends Zend_Validate_Barcode_AdapterAbstract +{ + /** + * Allowed barcode lengths + * @var integer + */ + protected $_length = array(12, 14); + + /** + * Allowed barcode characters + * @var string + */ + protected $_characters = '0123456789'; + + /** + * Checksum function + * @var string + */ + protected $_checksum = '_postnet'; +} diff --git a/libs/Zend/Validate/Barcode/Postnet.php b/libs/Zend/Validate/Barcode/Postnet.php new file mode 100644 index 0000000000..c638dc7314 --- /dev/null +++ b/libs/Zend/Validate/Barcode/Postnet.php @@ -0,0 +1,52 @@ +<?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_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:$ + */ + +/** + * @see Zend_Validate_Barcode_AdapterAbstract + */ +require_once 'Zend/Validate/Barcode/AdapterAbstract.php'; + +/** + * @category Zend + * @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 + */ +class Zend_Validate_Barcode_Postnet extends Zend_Validate_Barcode_AdapterAbstract +{ + /** + * Allowed barcode lengths + * @var integer + */ + protected $_length = array(6, 7, 10, 12); + + /** + * Allowed barcode characters + * @var string + */ + protected $_characters = '0123456789'; + + /** + * Checksum function + * @var string + */ + protected $_checksum = '_postnet'; +} diff --git a/libs/Zend/Validate/Barcode/Royalmail.php b/libs/Zend/Validate/Barcode/Royalmail.php new file mode 100644 index 0000000000..8c4b733b5b --- /dev/null +++ b/libs/Zend/Validate/Barcode/Royalmail.php @@ -0,0 +1,121 @@ +<?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_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:$ + */ + +/** + * @see Zend_Validate_Barcode_AdapterAbstract + */ +require_once 'Zend/Validate/Barcode/AdapterAbstract.php'; + +/** + * @category Zend + * @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 + */ +class Zend_Validate_Barcode_Royalmail extends Zend_Validate_Barcode_AdapterAbstract +{ + /** + * Allowed barcode lengths + * @var integer + */ + protected $_length = -1; + + /** + * Allowed barcode characters + * @var string + */ + protected $_characters = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'; + + protected $_rows = array( + '0' => 1, '1' => 1, '2' => 1, '3' => 1, '4' => 1, '5' => 1, + '6' => 2, '7' => 2, '8' => 2, '9' => 2, 'A' => 2, 'B' => 2, + 'C' => 3, 'D' => 3, 'E' => 3, 'F' => 3, 'G' => 3, 'H' => 3, + 'I' => 4, 'J' => 4, 'K' => 4, 'L' => 4, 'M' => 4, 'N' => 4, + 'O' => 5, 'P' => 5, 'Q' => 5, 'R' => 5, 'S' => 5, 'T' => 5, + 'U' => 0, 'V' => 0, 'W' => 0, 'X' => 0, 'Y' => 0, 'Z' => 0, + ); + + protected $_columns = array( + '0' => 1, '1' => 2, '2' => 3, '3' => 4, '4' => 5, '5' => 0, + '6' => 1, '7' => 2, '8' => 3, '9' => 4, 'A' => 5, 'B' => 0, + 'C' => 1, 'D' => 2, 'E' => 3, 'F' => 4, 'G' => 5, 'H' => 0, + 'I' => 1, 'J' => 2, 'K' => 3, 'L' => 4, 'M' => 5, 'N' => 0, + 'O' => 1, 'P' => 2, 'Q' => 3, 'R' => 4, 'S' => 5, 'T' => 0, + 'U' => 1, 'V' => 2, 'W' => 3, 'X' => 4, 'Y' => 5, 'Z' => 0, + ); + + /** + * Checksum function + * @var string + */ + protected $_checksum = '_royalmail'; + + /** + * Validates the checksum () + * + * @param string $value The barcode to validate + * @return boolean + */ + protected function _royalmail($value) + { + $checksum = substr($value, -1, 1); + $values = str_split(substr($value, 0, -1)); + $rowvalue = 0; + $colvalue = 0; + foreach($values as $row) { + $rowvalue += $this->_rows[$row]; + $colvalue += $this->_columns[$row]; + } + + $rowvalue %= 6; + $colvalue %= 6; + + $rowchkvalue = array_keys($this->_rows, $rowvalue); + $colchkvalue = array_keys($this->_columns, $colvalue); + $chkvalue = current(array_intersect($rowchkvalue, $colchkvalue)); + if ($chkvalue == $checksum) { + return true; + } + + return false; + } + + /** + * Allows start and stop tag within checked chars + * + * @param string $value The barcode to check for allowed characters + * @return boolean + */ + public function checkChars($value) + { + if ($value[0] == '(') { + $value = substr($value, 1); + + if ($value[strlen($value) - 1] == ')') { + $value = substr($value, 0, -1); + } else { + return false; + } + } + + return parent::checkChars($value); + } +} diff --git a/libs/Zend/Validate/Barcode/Sscc.php b/libs/Zend/Validate/Barcode/Sscc.php new file mode 100644 index 0000000000..50dd820793 --- /dev/null +++ b/libs/Zend/Validate/Barcode/Sscc.php @@ -0,0 +1,52 @@ +<?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_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 $ + */ + +/** + * @see Zend_Validate_Barcode_AdapterAbstract + */ +require_once 'Zend/Validate/Barcode/AdapterAbstract.php'; + +/** + * @category Zend + * @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 + */ +class Zend_Validate_Barcode_Sscc extends Zend_Validate_Barcode_AdapterAbstract +{ + /** + * Allowed barcode lengths + * @var integer + */ + protected $_length = 18; + + /** + * Allowed barcode characters + * @var string + */ + protected $_characters = '0123456789'; + + /** + * Checksum function + * @var string + */ + protected $_checksum = '_gtin'; +} diff --git a/libs/Zend/Validate/Barcode/UpcA.php b/libs/Zend/Validate/Barcode/UpcA.php deleted file mode 100644 index cf33f31fab..0000000000 --- a/libs/Zend/Validate/Barcode/UpcA.php +++ /dev/null @@ -1,103 +0,0 @@ -<?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_Validate - * @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: UpcA.php 16223 2009-06-21 20:04:53Z thomas $ - */ - - -/** - * @see Zend_Validate_Abstract - */ -require_once 'Zend/Validate/Abstract.php'; - - -/** - * @category Zend - * @package Zend_Validate - * @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_Validate_Barcode_UpcA extends Zend_Validate_Abstract -{ - /** - * Validation failure message key for when the value is - * an invalid barcode - */ - const INVALID = 'invalid'; - - /** - * Validation failure message key for when the value is - * not 12 characters long - */ - const INVALID_LENGTH = 'invalidLength'; - - /** - * Validation failure message template definitions - * - * @var array - */ - protected $_messageTemplates = array( - self::INVALID => "'%value%' is an invalid UPC-A barcode", - self::INVALID_LENGTH => "'%value%' should be 12 characters", - ); - - /** - * Defined by Zend_Validate_Interface - * - * Returns true if and only if $value contains a valid barcode - * - * @param string $value - * @return boolean - */ - public function isValid($value) - { - if (!is_string($value)) { - $this->_error(self::INVALID); - return false; - } - - $this->_setValue($value); - if (strlen($value) !== 12) { - $this->_error(self::INVALID_LENGTH); - return false; - } - - $barcode = substr($value, 0, -1); - $oddSum = 0; - $evenSum = 0; - - for ($i = 0; $i < 11; $i++) { - if ($i % 2 === 0) { - $oddSum += $barcode[$i] * 3; - } elseif ($i % 2 === 1) { - $evenSum += $barcode[$i]; - } - } - - $calculation = ($oddSum + $evenSum) % 10; - $checksum = ($calculation === 0) ? 0 : 10 - $calculation; - - if ($value[11] != $checksum) { - $this->_error(self::INVALID); - return false; - } - - return true; - } -} diff --git a/libs/Zend/Validate/Barcode/Upca.php b/libs/Zend/Validate/Barcode/Upca.php new file mode 100644 index 0000000000..449c78dd37 --- /dev/null +++ b/libs/Zend/Validate/Barcode/Upca.php @@ -0,0 +1,52 @@ +<?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_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 20096 2010-01-06 02:05:09Z bkarwin $ + */ + +/** + * @see Zend_Validate_Barcode_AdapterAbstract + */ +require_once 'Zend/Validate/Barcode/AdapterAbstract.php'; + +/** + * @category Zend + * @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 + */ +class Zend_Validate_Barcode_Upca extends Zend_Validate_Barcode_AdapterAbstract +{ + /** + * Allowed barcode lengths + * @var integer + */ + protected $_length = 12; + + /** + * Allowed barcode characters + * @var string + */ + protected $_characters = '0123456789'; + + /** + * Checksum function + * @var string + */ + protected $_checksum = '_gtin'; +} diff --git a/libs/Zend/Validate/Barcode/Upce.php b/libs/Zend/Validate/Barcode/Upce.php new file mode 100644 index 0000000000..f4ccc74eb6 --- /dev/null +++ b/libs/Zend/Validate/Barcode/Upce.php @@ -0,0 +1,69 @@ +<?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_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 $ + */ + +/** + * @see Zend_Validate_Barcode_AdapterAbstract + */ +require_once 'Zend/Validate/Barcode/AdapterAbstract.php'; + +/** + * @category Zend + * @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 + */ +class Zend_Validate_Barcode_Upce extends Zend_Validate_Barcode_AdapterAbstract +{ + /** + * Allowed barcode lengths + * @var integer + */ + protected $_length = array(6, 7, 8); + + /** + * Allowed barcode characters + * @var string + */ + protected $_characters = '0123456789'; + + /** + * Checksum function + * @var string + */ + protected $_checksum = '_gtin'; + + /** + * Overrides parent checkLength + * + * @param string $value Value + * @return boolean + */ + public function checkLength($value) + { + if (strlen($value) != 8) { + $this->setCheck(false); + } else { + $this->setCheck(true); + } + + return parent::checkLength($value); + } +} diff --git a/libs/Zend/Validate/Between.php b/libs/Zend/Validate/Between.php index b9fd7c2dc6..332d7cb1e2 100644 --- a/libs/Zend/Validate/Between.php +++ b/libs/Zend/Validate/Between.php @@ -1,5 +1,4 @@ <?php - /** * Zend Framework * @@ -15,22 +14,20 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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: Between.php 16223 2009-06-21 20:04:53Z thomas $ + * @version $Id: Between.php 20096 2010-01-06 02:05:09Z bkarwin $ */ - /** * @see Zend_Validate_Abstract */ require_once 'Zend/Validate/Abstract.php'; - /** * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Validate_Between extends Zend_Validate_Abstract @@ -91,17 +88,44 @@ class Zend_Validate_Between extends Zend_Validate_Abstract /** * Sets validator options + * Accepts the following option keys: + * 'min' => scalar, minimum border + * 'max' => scalar, maximum border + * 'inclusive' => boolean, inclusive border values * - * @param mixed $min - * @param mixed $max - * @param boolean $inclusive + * @param array|Zend_Config $options * @return void */ - public function __construct($min, $max, $inclusive = true) + public function __construct($options) { - $this->setMin($min) - ->setMax($max) - ->setInclusive($inclusive); + if ($options instanceof Zend_Config) { + $options = $options->toArray(); + } else if (!is_array($options)) { + $options = func_get_args(); + $temp['min'] = array_shift($options); + if (!empty($options)) { + $temp['max'] = array_shift($options); + } + + if (!empty($options)) { + $temp['inclusive'] = array_shift($options); + } + + $options = $temp; + } + + if (!array_key_exists('min', $options) || !array_key_exists('max', $options)) { + require_once 'Zend/Validate/Exception.php'; + throw new Zend_Validate_Exception("Missing option. 'min' and 'max' has to be given"); + } + + if (!array_key_exists('inclusive', $options)) { + $options['inclusive'] = true; + } + + $this->setMin($options['min']) + ->setMax($options['max']) + ->setInclusive($options['inclusive']); } /** diff --git a/libs/Zend/Validate/Callback.php b/libs/Zend/Validate/Callback.php new file mode 100644 index 0000000000..7dbade86a7 --- /dev/null +++ b/libs/Zend/Validate/Callback.php @@ -0,0 +1,174 @@ +<?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_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 20096 2010-01-06 02:05:09Z bkarwin $ + */ + +/** + * @see Zend_Validate_Abstract + */ +require_once 'Zend/Validate/Abstract.php'; + +/** + * @category Zend + * @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 + */ +class Zend_Validate_Callback extends Zend_Validate_Abstract +{ + /** + * Invalid callback + */ + const INVALID_CALLBACK = 'callbackInvalid'; + + /** + * Invalid value + */ + const INVALID_VALUE = 'callbackValue'; + + /** + * Validation failure message template definitions + * + * @var array + */ + protected $_messageTemplates = array( + self::INVALID_VALUE => "'%value%' is not valid", + self::INVALID_CALLBACK => "Failure within the callback, exception returned", + ); + + /** + * Callback in a call_user_func format + * + * @var string|array + */ + protected $_callback = null; + + /** + * Default options to set for the filter + * + * @var mixed + */ + protected $_options = array(); + + /** + * Sets validator options + * + * @param string|array $callback + * @param mixed $max + * @param boolean $inclusive + * @return void + */ + public function __construct($callback = null) + { + if (is_callable($callback)) { + $this->setCallback($callback); + } elseif (is_array($callback)) { + if (isset($callback['callback'])) { + $this->setCallback($callback['callback']); + } + if (isset($callback['options'])) { + $this->setOptions($callback['options']); + } + } + + if (null === ($initializedCallack = $this->getCallback())) { + require_once 'Zend/Validate/Exception.php'; + throw new Zend_Validate_Exception('No callback registered'); + } + } + + /** + * Returns the set callback + * + * @return mixed + */ + public function getCallback() + { + return $this->_callback; + } + + /** + * Sets the callback + * + * @param string|array $callback + * @return Zend_Validate_Callback Provides a fluent interface + */ + public function setCallback($callback) + { + if (!is_callable($callback)) { + require_once 'Zend/Validate/Exception.php'; + throw new Zend_Validate_Exception('Invalid callback given'); + } + $this->_callback = $callback; + return $this; + } + + /** + * Returns the set options for the callback + * + * @return mixed + */ + public function getOptions() + { + return $this->_options; + } + + /** + * Sets options for the callback + * + * @param mixed $max + * @return Zend_Validate_Callback Provides a fluent interface + */ + public function setOptions($options) + { + $this->_options = (array) $options; + return $this; + } + + /** + * Defined by Zend_Validate_Interface + * + * Returns true if and only if the set callback returns + * for the provided $value + * + * @param mixed $value + * @return boolean + */ + public function isValid($value) + { + $this->_setValue($value); + + $options = $this->getOptions(); + $callback = $this->getCallback(); + $args = func_get_args(); + $options = array_merge($args, $options); + + try { + if (!call_user_func_array($callback, $options)) { + $this->_error(self::INVALID_VALUE); + return false; + } + } catch (Exception $e) { + $this->_error(self::INVALID_CALLBACK); + return false; + } + + return true; + } +} diff --git a/libs/Zend/Validate/Ccnum.php b/libs/Zend/Validate/Ccnum.php index 489573c48d..71f0f83bf3 100644 --- a/libs/Zend/Validate/Ccnum.php +++ b/libs/Zend/Validate/Ccnum.php @@ -1,5 +1,4 @@ <?php - /** * Zend Framework * @@ -15,22 +14,20 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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: Ccnum.php 16223 2009-06-21 20:04:53Z thomas $ + * @version $Id: Ccnum.php 20096 2010-01-06 02:05:09Z bkarwin $ */ - /** * @see Zend_Validate_Abstract */ require_once 'Zend/Validate/Abstract.php'; - /** * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Validate_Ccnum extends Zend_Validate_Abstract @@ -62,6 +59,11 @@ class Zend_Validate_Ccnum extends Zend_Validate_Abstract self::CHECKSUM => "Luhn algorithm (mod-10 checksum) failed on '%value%'" ); + public function __construct() + { + trigger_error('Using the Ccnum validator is deprecated in favor of the CreditCard validator'); + } + /** * Defined by Zend_Validate_Interface * @@ -107,5 +109,4 @@ class Zend_Validate_Ccnum extends Zend_Validate_Abstract return true; } - } diff --git a/libs/Zend/Validate/CreditCard.php b/libs/Zend/Validate/CreditCard.php new file mode 100644 index 0000000000..127e2f2e63 --- /dev/null +++ b/libs/Zend/Validate/CreditCard.php @@ -0,0 +1,315 @@ +<?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_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 20358 2010-01-17 19:03:49Z thomas $ + */ + +/** + * @see Zend_Validate_Abstract + */ +require_once 'Zend/Validate/Abstract.php'; + +/** + * @category Zend + * @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 + */ +class Zend_Validate_CreditCard extends Zend_Validate_Abstract +{ + /** + * Detected CCI list + * + * @var string + */ + const ALL = 'All'; + const AMERICAN_EXPRESS = 'American_Express'; + const UNIONPAY = 'Unionpay'; + const DINERS_CLUB = 'Diners_Club'; + const DINERS_CLUB_US = 'Diners_Club_US'; + const DISCOVER = 'Discover'; + const JCB = 'JCB'; + const LASER = 'Laser'; + const MAESTRO = 'Maestro'; + const MASTERCARD = 'Mastercard'; + const SOLO = 'Solo'; + const VISA = 'Visa'; + + const CHECKSUM = 'creditcardChecksum'; + const CONTENT = 'creditcardContent'; + const INVALID = 'creditcardInvalid'; + const LENGTH = 'creditcardLength'; + const PREFIX = 'creditcardPrefix'; + const SERVICE = 'creditcardService'; + const SERVICEFAILURE = 'creditcardServiceFailure'; + + /** + * Validation failure message template definitions + * + * @var array + */ + protected $_messageTemplates = array( + self::CHECKSUM => "Luhn algorithm (mod-10 checksum) failed on '%value%'", + self::CONTENT => "'%value%' must contain only digits", + self::INVALID => "Invalid type given, value should be a string", + 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%'", + ); + + /** + * List of allowed CCV lengths + * + * @var array + */ + protected $_cardLength = array( + self::AMERICAN_EXPRESS => array(15), + self::DINERS_CLUB => array(14), + self::DINERS_CLUB_US => array(16), + self::DISCOVER => array(16), + self::JCB => array(16), + self::LASER => array(16, 17, 18, 19), + self::MAESTRO => array(12, 13, 14, 15, 16, 17, 18, 19), + self::MASTERCARD => array(16), + self::SOLO => array(16, 18, 19), + self::UNIONPAY => array(16, 17, 18, 19), + self::VISA => array(16), + ); + + /** + * List of accepted CCV provider tags + * + * @var array + */ + protected $_cardType = array( + self::AMERICAN_EXPRESS => array('34', '37'), + self::DINERS_CLUB => array('300', '301', '302', '303', '304', '305', '36'), + self::DINERS_CLUB_US => array('54', '55'), + self::DISCOVER => array('6011', '622126', '622127', '622128', '622129', '62213', + '62214', '62215', '62216', '62217', '62218', '62219', + '6222', '6223', '6224', '6225', '6226', '6227', '6228', + '62290', '62291', '622920', '622921', '622922', '622923', + '622924', '622925', '644', '645', '646', '647', '648', + '649', '65'), + self::JCB => array('3528', '3529', '353', '354', '355', '356', '357', '358'), + self::LASER => array('6304', '6706', '6771', '6709'), + self::MAESTRO => array('5018', '5020', '5038', '6304', '6759', '6761', '6763'), + self::MASTERCARD => array('51', '52', '53', '54', '55'), + self::SOLO => array('6334', '6767'), + self::UNIONPAY => array('622126', '622127', '622128', '622129', '62213', '62214', + '62215', '62216', '62217', '62218', '62219', '6222', '6223', + '6224', '6225', '6226', '6227', '6228', '62290', '62291', + '622920', '622921', '622922', '622923', '622924', '622925'), + self::VISA => array('4'), + ); + + /** + * CCIs which are accepted by validation + * + * @var array + */ + protected $_type = array(); + + /** + * Service callback for additional validation + * + * @var callback + */ + protected $_service; + + /** + * Constructor + * + * @param string|array $type OPTIONAL Type of CCI to allow + */ + public function __construct($options = array()) + { + if ($options instanceof Zend_Config) { + $options = $options->toArray(); + } else if (!is_array($options)) { + $options = func_get_args(); + $temp['type'] = array_shift($options); + if (!empty($options)) { + $temp['service'] = array_shift($options); + } + + $options = $temp; + } + + if (!array_key_exists('type', $options)) { + $options['type'] = self::ALL; + } + + $this->setType($options['type']); + if (array_key_exists('service', $options)) { + $this->setService($options['service']); + } + } + + /** + * Returns a list of accepted CCIs + * + * @return array + */ + public function getType() + { + return $this->_type; + } + + /** + * Sets CCIs which are accepted by validation + * + * @param string|array $type Type to allow for validation + * @return Zend_Validate_CreditCard Provides a fluid interface + */ + public function setType($type) + { + $this->_type = array(); + return $this->addType($type); + } + + /** + * Adds a CCI to be accepted by validation + * + * @param string|array $type Type to allow for validation + * @return Zend_Validate_CreditCard Provides a fluid interface + */ + public function addType($type) + { + if (is_string($type)) { + $type = array($type); + } + + foreach($type as $typ) { + if (defined('self::' . strtoupper($typ)) && !in_array($typ, $this->_type)) { + $this->_type[] = $typ; + } + + if (($typ == self::ALL)) { + $this->_type = array_keys($this->_cardLength); + } + } + + return $this; + } + + /** + * Returns the actual set service + * + * @return callback + */ + public function getService() + { + return $this->_service; + } + + /** + * Sets a new callback for service validation + * + * @param unknown_type $service + */ + public function setService($service) + { + if (!is_callable($service)) { + require_once 'Zend/Validate/Exception.php'; + throw new Zend_Validate_Exception('Invalid callback given'); + } + + $this->_service = $service; + return $this; + } + + /** + * Defined by Zend_Validate_Interface + * + * Returns true if and only if $value follows the Luhn algorithm (mod-10 checksum) + * + * @param string $value + * @return boolean + */ + public function isValid($value) + { + $this->_setValue($value); + + if (!is_string($value)) { + $this->_error(self::INVALID, $value); + return false; + } + + if (!ctype_digit($value)) { + $this->_error(self::CONTENT, $value); + return false; + } + + $length = strlen($value); + $types = $this->getType(); + $found = false; + foreach ($types as $type) { + if (in_array($length, $this->_cardLength[$type])) { + foreach ($this->_cardType[$type] as $prefix) { + if (substr($value, 0, strlen($prefix)) == $prefix) { + $found = true; + break; + } + } + } + } + + if ($found == false) { + if (!in_array($length, $this->_cardLength[$type])) { + $this->_error(self::LENGTH, $value); + return false; + } else { + $this->_error(self::PREFIX, $value); + return false; + } + } + + $sum = 0; + $weight = 2; + + for ($i = $length - 2; $i >= 0; $i--) { + $digit = $weight * $value[$i]; + $sum += floor($digit / 10) + $digit % 10; + $weight = $weight % 2 + 1; + } + + if ((10 - $sum % 10) % 10 != $value[$length - 1]) { + $this->_error(self::CHECKSUM, $value); + return false; + } + + if (!empty($this->_service)) { + try { + require_once 'Zend/Validate/Callback.php'; + $callback = new Zend_Validate_Callback($this->_service); + $callback->setOptions($this->_type); + if (!$callback->isValid($value)) { + $this->_error(self::SERVICE, $value); + return false; + } + } catch (Zend_Exception $e) { + $this->_error(self::SERVICEFAILURE, $value); + return false; + } + } + + return true; + } +} diff --git a/libs/Zend/Validate/Date.php b/libs/Zend/Validate/Date.php index 5dbcc6d702..993f99cb51 100644 --- a/libs/Zend/Validate/Date.php +++ b/libs/Zend/Validate/Date.php @@ -14,9 +14,9 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 17696 2009-08-20 20:12:33Z thomas $ + * @version $Id: Date.php 20358 2010-01-17 19:03:49Z thomas $ */ /** @@ -27,14 +27,13 @@ require_once 'Zend/Validate/Abstract.php'; /** * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Validate_Date extends Zend_Validate_Abstract { const INVALID = 'dateInvalid'; - const NOT_YYYY_MM_DD = 'dateNotYYYY-MM-DD'; - const INVALID_DATE = 'dateInvalidDate'; + const INVALID_DATE = 'dateInvalidDate'; const FALSEFORMAT = 'dateFalseFormat'; /** @@ -44,9 +43,15 @@ class Zend_Validate_Date extends Zend_Validate_Abstract */ protected $_messageTemplates = array( self::INVALID => "Invalid type given, value should be string, integer, array or Zend_Date", - self::NOT_YYYY_MM_DD => "'%value%' is not of the format YYYY-MM-DD", self::INVALID_DATE => "'%value%' does not appear to be a valid date", - self::FALSEFORMAT => "'%value%' does not fit given date format" + self::FALSEFORMAT => "'%value%' does not fit the date format '%format%'", + ); + + /** + * @var array + */ + protected $_messageVariables = array( + 'format' => '_format' ); /** @@ -66,22 +71,36 @@ class Zend_Validate_Date extends Zend_Validate_Abstract /** * Sets validator options * - * @param string $format OPTIONAL - * @param string|Zend_Locale $locale OPTIONAL + * @param string|Zend_Config $options OPTIONAL * @return void */ - public function __construct($format = null, $locale = null) + public function __construct($options = array()) { - $this->setFormat($format); - if ($locale === null) { + if ($options instanceof Zend_Config) { + $options = $options->toArray(); + } else if (!is_array($options)) { + $options = func_get_args(); + $temp['format'] = array_shift($options); + if (!empty($options)) { + $temp['locale'] = array_shift($options); + } + + $options = $temp; + } + + if (array_key_exists('format', $options)) { + $this->setFormat($options['format']); + } + + if (!array_key_exists('locale', $options)) { require_once 'Zend/Registry.php'; if (Zend_Registry::isRegistered('Zend_Locale')) { - $locale = Zend_Registry::get('Zend_Locale'); + $options['locale'] = Zend_Registry::get('Zend_Locale'); } } - if ($locale !== null) { - $this->setLocale($locale); + if (array_key_exists('locale', $options)) { + $this->setLocale($options['locale']); } } @@ -163,7 +182,9 @@ class Zend_Validate_Date extends Zend_Validate_Abstract } } else { if (!preg_match('/^\d{4}-\d{2}-\d{2}$/', $value)) { - $this->_error(self::NOT_YYYY_MM_DD); + $this->_format = 'yyyy-MM-dd'; + $this->_error(self::FALSEFORMAT); + $this->_format = null; return false; } diff --git a/libs/Zend/Validate/Db/Abstract.php b/libs/Zend/Validate/Db/Abstract.php index de5a863ea8..c1d2a98b3f 100644 --- a/libs/Zend/Validate/Db/Abstract.php +++ b/libs/Zend/Validate/Db/Abstract.php @@ -1,5 +1,4 @@ <?php - /** * Zend Framework * @@ -15,9 +14,9 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 18951 2009-11-12 16:26:19Z alexander $ + * @version $Id: Abstract.php 20412 2010-01-19 07:02:01Z thomas $ */ /** @@ -31,7 +30,7 @@ require_once 'Zend/Validate/Abstract.php'; * @category Zend * @package Zend_Validate * @uses Zend_Validate_Abstract - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Validate_Db_Abstract extends Zend_Validate_Abstract @@ -45,8 +44,10 @@ 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'); + protected $_messageTemplates = array( + self::ERROR_NO_RECORD_FOUND => 'No record matching %value% was found', + self::ERROR_RECORD_FOUND => 'A record matching %value% was found', + ); /** * @var string @@ -82,26 +83,175 @@ abstract class Zend_Validate_Db_Abstract extends Zend_Validate_Abstract * to define the where clause added to the sql. * A database adapter may optionally be supplied to avoid using the registered default adapter. * - * @param string||array $table The database table to validate against, or array with table and schema keys - * @param string $field The field to check for a match - * @param string||array $exclude An optional where clause or field/value pair to exclude from the query - * @param Zend_Db_Adapter_Abstract $adapter An optional database adapter to use. + * The following option keys are supported: + * 'table' => The database table to validate against + * 'schema' => The schema keys + * 'field' => The field to check for a match + * 'exclude' => An optional where clause or field/value pair to exclude from the query + * 'adapter' => An optional database adapter to use + * + * @param array|Zend_Config $options Options to use for this validator */ - public function __construct($table, $field, $exclude = null, Zend_Db_Adapter_Abstract $adapter = null) + public function __construct($options) { - if ($adapter !== null) { - $this->_adapter = $adapter; + if ($options instanceof Zend_Config) { + $options = $options->toArray(); + } else if (func_num_args() > 1) { + $options = func_get_args(); + $temp['table'] = array_shift($options); + $temp['field'] = array_shift($options); + if (!empty($options)) { + $temp['exclude'] = array_shift($options); + } + + if (!empty($options)) { + $temp['adapter'] = array_shift($options); + } + + $options = $temp; } - $this->_exclude = $exclude; - $this->_field = (string) $field; - if (is_array($table)) { - $this->_table = (isset($table['table'])) ? $table['table'] : ''; - $this->_schema = (isset($table['schema'])) ? $table['schema'] : null; - } else { - $this->_table = (string) $table; + if (!array_key_exists('table', $options) && !array_key_exists('schema', $options)) { + require_once 'Zend/Validate/Exception.php'; + throw new Zend_Validate_Exception('Table or Schema option missing!'); + } + + if (!array_key_exists('field', $options)) { + require_once 'Zend/Validate/Exception.php'; + throw new Zend_Validate_Exception('Field option missing!'); + } + + if (array_key_exists('adapter', $options)) { + $this->setAdapter($options['adapter']); + } + + if (array_key_exists('exclude', $options)) { + $this->setExclude($options['exclude']); + } + + $this->setField($options['field']); + if (array_key_exists('table', $options)) { + $this->setTable($options['table']); + } + + if (array_key_exists('schema', $options)) { + $this->setSchema($options['schema']); + } + } + + /** + * Returns the set adapter + * + * @return Zend_Db_Adapter + */ + public function getAdapter() + { + return $this->_adapter; + } + + /** + * Sets a new database adapter + * + * @param Zend_Db_Adapter_Abstract $adapter + * @return Zend_Validate_Db_Abstract + */ + public function setAdapter($adapter) + { + if (!($adapter instanceof Zend_Db_Adapter_Abstract)) { + require_once 'Zend/Validate/Exception.php'; + throw new Zend_Validate_Exception('Adapter option must be a database adapter!'); } + $this->_adapter = $adapter; + return $this; + } + + /** + * Returns the set exclude clause + * + * @return string|array + */ + public function getExclude() + { + return $this->_exclude; + } + + /** + * Sets a new exclude clause + * + * @param string|array $exclude + * @return Zend_Validate_Db_Abstract + */ + public function setExclude($exclude) + { + $this->_exclude = $exclude; + return $this; + } + + /** + * Returns the set field + * + * @return string|array + */ + public function getField() + { + return $this->_field; + } + + /** + * Sets a new field + * + * @param string $field + * @return Zend_Validate_Db_Abstract + */ + public function setField($field) + { + $this->_field = (string) $field; + return $this; + } + + /** + * Returns the set table + * + * @return string + */ + public function getTable() + { + return $this->_table; + } + + /** + * Sets a new table + * + * @param string $table + * @return Zend_Validate_Db_Abstract + */ + public function setTable($table) + { + $this->_table = (string) $table; + return $this; + } + + /** + * Returns the set schema + * + * @return string + */ + public function getSchema() + { + return $this->_schema; + } + + /** + * Sets a new schema + * + * @param string $schema + * @return Zend_Validate_Db_Abstract + */ + public function setSchema($schema) + { + $this->_schema = $schema; + return $this; } /** diff --git a/libs/Zend/Validate/Db/NoRecordExists.php b/libs/Zend/Validate/Db/NoRecordExists.php index e9c0db49a8..98dc59b8a2 100644 --- a/libs/Zend/Validate/Db/NoRecordExists.php +++ b/libs/Zend/Validate/Db/NoRecordExists.php @@ -1,5 +1,4 @@ <?php - /** * Zend Framework * @@ -15,9 +14,9 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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: NoRecordExists.php 16971 2009-07-22 18:05:45Z mikaelkael $ + * @version $Id: NoRecordExists.php 20096 2010-01-06 02:05:09Z bkarwin $ */ /** @@ -31,7 +30,7 @@ require_once 'Zend/Validate/Db/Abstract.php'; * @category Zend * @package Zend_Validate * @uses Zend_Validate_Db_Abstract - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Validate_Db_NoRecordExists extends Zend_Validate_Db_Abstract diff --git a/libs/Zend/Validate/Db/RecordExists.php b/libs/Zend/Validate/Db/RecordExists.php index 22f39bc6a0..4a9122ad02 100644 --- a/libs/Zend/Validate/Db/RecordExists.php +++ b/libs/Zend/Validate/Db/RecordExists.php @@ -1,5 +1,4 @@ <?php - /** * Zend Framework * @@ -15,12 +14,11 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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: RecordExists.php 18951 2009-11-12 16:26:19Z alexander $ + * @version $Id: RecordExists.php 20096 2010-01-06 02:05:09Z bkarwin $ */ - /** * @see Zend_Validate_Db_Abstract */ @@ -32,7 +30,7 @@ require_once 'Zend/Validate/Db/Abstract.php'; * @category Zend * @package Zend_Validate * @uses Zend_Validate_Db_Abstract - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Validate_Db_RecordExists extends Zend_Validate_Db_Abstract diff --git a/libs/Zend/Validate/Digits.php b/libs/Zend/Validate/Digits.php index 12e6c4e454..d6528dde01 100644 --- a/libs/Zend/Validate/Digits.php +++ b/libs/Zend/Validate/Digits.php @@ -1,5 +1,4 @@ <?php - /** * Zend Framework * @@ -15,28 +14,26 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 16933 2009-07-21 20:24:35Z matthew $ + * @version $Id: Digits.php 20096 2010-01-06 02:05:09Z bkarwin $ */ - /** * @see Zend_Validate_Abstract */ require_once 'Zend/Validate/Abstract.php'; - /** * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Validate_Digits extends Zend_Validate_Abstract { const NOT_DIGITS = 'notDigits'; - const STRING_EMPTY = 'stringEmpty'; + const STRING_EMPTY = 'digitsStringEmpty'; const INVALID = 'digitsInvalid'; /** @@ -91,5 +88,4 @@ class Zend_Validate_Digits extends Zend_Validate_Abstract return true; } - } diff --git a/libs/Zend/Validate/EmailAddress.php b/libs/Zend/Validate/EmailAddress.php index 4948bb83f3..388fe6b55c 100644 --- a/libs/Zend/Validate/EmailAddress.php +++ b/libs/Zend/Validate/EmailAddress.php @@ -14,9 +14,9 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 16223 2009-06-21 20:04:53Z thomas $ + * @version $Id: EmailAddress.php 20358 2010-01-17 19:03:49Z thomas $ */ /** @@ -32,7 +32,7 @@ require_once 'Zend/Validate/Hostname.php'; /** * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Validate_EmailAddress extends Zend_Validate_Abstract @@ -41,6 +41,7 @@ class Zend_Validate_EmailAddress extends Zend_Validate_Abstract const INVALID_FORMAT = 'emailAddressInvalidFormat'; const INVALID_HOSTNAME = 'emailAddressInvalidHostname'; const INVALID_MX_RECORD = 'emailAddressInvalidMxRecord'; + const INVALID_SEGMENT = 'emailAddressInvalidSegment'; const DOT_ATOM = 'emailAddressDotAtom'; const QUOTED_STRING = 'emailAddressQuotedString'; const INVALID_LOCAL_PART = 'emailAddressInvalidLocalPart'; @@ -51,37 +52,47 @@ class Zend_Validate_EmailAddress extends Zend_Validate_Abstract */ protected $_messageTemplates = array( self::INVALID => "Invalid type given, value should be a string", - self::INVALID_FORMAT => "'%value%' is not a valid email address in the basic format local-part@hostname", - self::INVALID_HOSTNAME => "'%hostname%' is not a valid hostname for email address '%value%'", + 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::DOT_ATOM => "'%localPart%' not matched against dot-atom format", - self::QUOTED_STRING => "'%localPart%' not matched against quoted-string format", - self::INVALID_LOCAL_PART => "'%localPart%' is not a valid local part for email address '%value%'", - self::LENGTH_EXCEEDED => "'%value%' exceeds the allowed length" + 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%'", + self::LENGTH_EXCEEDED => "'%value%' exceeds the allowed length", ); /** + * @see http://en.wikipedia.org/wiki/IPv4 * @var array */ - protected $_messageVariables = array( - 'hostname' => '_hostname', - 'localPart' => '_localPart' + protected $_invalidIp = array( + '0' => '0.0.0.0/8', + '10' => '10.0.0.0/8', + '127' => '127.0.0.0/8', + '128' => '128.0.0.0/16', + '169' => '169.254.0.0/16', + '172' => '172.16.0.0/12', + '191' => '191.255.0.0/16', + '192' => array( + '192.0.0.0/24', + '192.0.2.0/24', + '192.88.99.0/24', + '192.168.0.0/16' + ), + '198' => '198.18.0.0/15', + '223' => '223.255.255.0/24', + '224' => '224.0.0.0/4', + '240' => '240.0.0.0/4' ); /** - * Local object for validating the hostname part of an email address - * - * @var Zend_Validate_Hostname - * @depreciated - */ - public $hostnameValidator; - - /** - * Whether we check for a valid MX record via DNS - * - * @var boolean + * @var array */ - protected $_validateMx = false; + protected $_messageVariables = array( + 'hostname' => '_hostname', + 'localPart' => '_localPart' + ); /** * @var string @@ -94,21 +105,118 @@ class Zend_Validate_EmailAddress extends Zend_Validate_Abstract protected $_localPart; /** + * Internal options array + */ + protected $_options = array( + 'mx' => false, + 'deep' => false, + 'domain' => true, + 'allow' => Zend_Validate_Hostname::ALLOW_DNS, + 'hostname' => null + ); + + /** * Instantiates hostname validator for local use * - * You can pass a bitfield to determine what types of hostnames are allowed. - * These bitfields are defined by the ALLOW_* constants in Zend_Validate_Hostname - * The default is to allow DNS hostnames only + * The following option keys are supported: + * 'hostname' => A hostname validator, see Zend_Validate_Hostname + * 'allow' => Options for the hostname validator, see Zend_Validate_Hostname::ALLOW_* + * 'mx' => If MX check should be enabled, boolean + * 'deep' => If a deep MX check should be done, boolean * - * @param integer $allow OPTIONAL - * @param bool $validateMx OPTIONAL - * @param Zend_Validate_Hostname $hostnameValidator OPTIONAL + * @param array|Zend_Config $options OPTIONAL * @return void */ - public function __construct($allow = Zend_Validate_Hostname::ALLOW_DNS, $validateMx = false, Zend_Validate_Hostname $hostnameValidator = null) + public function __construct($options = array()) { - $this->setValidateMx($validateMx); - $this->setHostnameValidator($hostnameValidator, $allow); + if ($options instanceof Zend_Config) { + $options = $options->toArray(); + } else if (!is_array($options)) { + $options = func_get_args(); + $temp['allow'] = array_shift($options); + if (!empty($options)) { + $temp['mx'] = array_shift($options); + } + + if (!empty($options)) { + $temp['hostname'] = array_shift($options); + } + + $options = $temp; + } + + $options += $this->_options; + $this->setOptions($options); + } + + /** + * Returns all set Options + * + * @return array + */ + public function getOptions() + { + return $this->_options; + } + + /** + * Set options for the email validator + * + * @param array $options + * @return Zend_Validate_EmailAddress fluid interface + */ + public function setOptions(array $options = array()) + { + if (array_key_exists('messages', $options)) { + $this->setMessages($options['messages']); + } + + if (array_key_exists('hostname', $options)) { + if (array_key_exists('allow', $options)) { + $this->setHostnameValidator($options['hostname'], $options['allow']); + } else { + $this->setHostnameValidator($options['hostname']); + } + } + + if (array_key_exists('mx', $options)) { + $this->setValidateMx($options['mx']); + } + + if (array_key_exists('deep', $options)) { + $this->setDeepMxCheck($options['deep']); + } + + if (array_key_exists('domain', $options)) { + $this->setDomainCheck($options['domain']); + } + + return $this; + } + + /** + * Sets the validation failure message template for a particular key + * Adds the ability to set messages to the attached hostname validator + * + * @param string $messageString + * @param string $messageKey OPTIONAL + * @return Zend_Validate_Abstract Provides a fluent interface + * @throws Zend_Validate_Exception + */ + public function setMessage($messageString, $messageKey = null) + { + $messageKeys = $messageKey; + if ($messageKey === null) { + $keys = array_keys($this->_messageTemplates); + $messageKeys = current($keys); + } + + if (!isset($this->_messageTemplates[$messageKeys])) { + $this->_options['hostname']->setMessage($messageString, $messageKey); + } + + $this->_messageTemplates[$messageKeys] = $messageString; + return $this; } /** @@ -118,7 +226,7 @@ class Zend_Validate_EmailAddress extends Zend_Validate_Abstract */ public function getHostnameValidator() { - return $this->hostnameValidator; + return $this->_options['hostname']; } /** @@ -128,14 +236,17 @@ class Zend_Validate_EmailAddress extends Zend_Validate_Abstract */ public function setHostnameValidator(Zend_Validate_Hostname $hostnameValidator = null, $allow = Zend_Validate_Hostname::ALLOW_DNS) { - if ($hostnameValidator === null) { + if (!$hostnameValidator) { $hostnameValidator = new Zend_Validate_Hostname($allow); } - $this->hostnameValidator = $hostnameValidator; + + $this->_options['hostname'] = $hostnameValidator; + $this->_options['allow'] = $allow; + return $this; } /** - * Whether MX checking via dns_get_mx is supported or not + * Whether MX checking via getmxrr is supported or not * * This currently only works on UNIX systems * @@ -143,7 +254,17 @@ class Zend_Validate_EmailAddress extends Zend_Validate_Abstract */ public function validateMxSupported() { - return function_exists('dns_get_mx'); + return function_exists('getmxrr'); + } + + /** + * Returns the set validateMx option + * + * @return boolean + */ + public function getValidateMx() + { + return $this->_options['mx']; } /** @@ -151,11 +272,235 @@ class Zend_Validate_EmailAddress extends Zend_Validate_Abstract * * This only applies when DNS hostnames are validated * - * @param boolean $allowed Set allowed to true to validate for MX records, and false to not validate them + * @param boolean $mx Set allowed to true to validate for MX records, and false to not validate them + * @return Zend_Validate_EmailAddress Fluid Interface + */ + public function setValidateMx($mx) + { + if ((bool) $mx && !$this->validateMxSupported()) { + require_once 'Zend/Validate/Exception.php'; + throw new Zend_Validate_Exception('MX checking not available on this system'); + } + + $this->_options['mx'] = (bool) $mx; + return $this; + } + + /** + * Returns the set deepMxCheck option + * + * @return boolean + */ + public function getDeepMxCheck() + { + return $this->_options['deep']; + } + + /** + * Set whether we check MX record should be a deep validation + * + * @param boolean $deep Set deep to true to perform a deep validation process for MX records + * @return Zend_Validate_EmailAddress Fluid Interface */ - public function setValidateMx($allowed) + public function setDeepMxCheck($deep) { - $this->_validateMx = (bool) $allowed; + $this->_options['deep'] = (bool) $deep; + return $this; + } + + /** + * Returns the set domainCheck option + * + * @return unknown + */ + public function getDomainCheck() + { + return $this->_options['domain']; + } + + /** + * Sets if the domain should also be checked + * or only the local part of the email address + * + * @param boolean $domain + * @return Zend_Validate_EmailAddress Fluid Interface + */ + public function setDomainCheck($domain = true) + { + $this->_options['domain'] = (boolean) $domain; + return $this; + } + + /** + * Returns if the given host is reserved + * + * @param string $host + * @return boolean + */ + private function _isReserved($host){ + if (!preg_match('/^([0-9]{1,3}\.){3}[0-9]{1,3}$/', $host)) { + $host = gethostbyname($host); + } + + $octet = explode('.',$host); + if ((int)$octet[0] >= 224) { + return true; + } else if (array_key_exists($octet[0], $this->_invalidIp)) { + foreach ((array)$this->_invalidIp[$octet[0]] as $subnetData) { + // we skip the first loop as we already know that octet matches + for ($i = 1; $i < 4; $i++) { + if (strpos($subnetData, $octet[$i]) !== $i * 4) { + break; + } + } + + $host = explode("/", $subnetData); + $binaryHost = ""; + $tmp = explode(".", $host[0]); + for ($i = 0; $i < 4 ; $i++) { + $binaryHost .= str_pad(decbin($tmp[$i]), 8, "0", STR_PAD_LEFT); + } + + $segmentData = array( + 'network' => (int)$this->_binaryToIp(str_pad(substr($binaryHost, 0, $host[1]), 32, 0)), + 'broadcast' => (int)$this->_binaryToIp(str_pad(substr($binaryHost, 0, $host[1]), 32, 1)) + ); + + for ($j = $i; $j < 4; $j++) { + if ((int)$octet[$j] < $segmentData['network'][$j] || + (int)$octet[$j] > $segmentData['broadcast'][$j]) { + return false; + } + } + } + + return true; + } else { + return false; + } + } + + /** + * Converts a binary string to an IP address + * + * @param string $binary + * @return mixed + */ + private function _toIp($binary) + { + $ip = array(); + $tmp = explode(".", chunk_split($binary, 8, ".")); + for ($i = 0; $i < 4 ; $i++) { + $ip[$i] = bindec($tmp[$i]); + } + + return $ip; + } + + /** + * Internal method to validate the local part of the email address + * + * @return boolean + */ + private function _validateLocalPart() + { + // First try to match the local part on the common dot-atom format + $result = false; + + // Dot-atom characters are: 1*atext *("." 1*atext) + // atext: ALPHA / DIGIT / and "!", "#", "$", "%", "&", "'", "*", + // "+", "-", "/", "=", "?", "^", "_", "`", "{", "|", "}", "~" + $atext = 'a-zA-Z0-9\x21\x23\x24\x25\x26\x27\x2a\x2b\x2d\x2f\x3d\x3f\x5e\x5f\x60\x7b\x7c\x7d\x7e'; + if (preg_match('/^[' . $atext . ']+(\x2e+[' . $atext . ']+)*$/', $this->_localPart)) { + $result = true; + } else { + // Try quoted string format + + // Quoted-string characters are: DQUOTE *([FWS] qtext/quoted-pair) [FWS] DQUOTE + // qtext: Non white space controls, and the rest of the US-ASCII characters not + // including "\" or the quote character + $noWsCtl = '\x01-\x08\x0b\x0c\x0e-\x1f\x7f'; + $qtext = $noWsCtl . '\x21\x23-\x5b\x5d-\x7e'; + $ws = '\x20\x09'; + if (preg_match('/^\x22([' . $ws . $qtext . '])*[$ws]?\x22$/', $this->_localPart)) { + $result = true; + } else { + $this->_error(self::DOT_ATOM); + $this->_error(self::QUOTED_STRING); + $this->_error(self::INVALID_LOCAL_PART); + } + } + + return $result; + } + + /** + * Internal method to validate the servers MX records + * + * @return boolean + */ + private function _validateMXRecords() + { + $result = true; + $mxHosts = array(); + getmxrr($this->_hostname, $mxHosts); + if ($this->_options['deep'] && function_exists('checkdnsrr')) { + $validAddress = false; + $reserved = true; + foreach ($mxHosts as $hostname) { + $res = $this->_isReserved($hostname); + if (!$res) { + $reserved = false; + } + + if (!$res + && (checkdnsrr($hostname, "A") + || checkdnsrr($hostname, "AAAA") + || checkdnsrr($hostname, "A6"))) { + $validAddress = true; + break; + } + } + + if (!$validAddress) { + $result = false; + if ($reserved) { + $this->_error(self::INVALID_SEGMENT); + } else { + $this->_error(self::INVALID_MX_RECORD); + } + } + } + + return $result; + } + + /** + * Internal method to validate the hostname part of the email address + * + * @return boolean + */ + private function _validateHostnamePart() + { + $hostname = $this->_options['hostname']->setTranslator($this->getTranslator()) + ->isValid($this->_hostname); + if (!$hostname) { + $this->_error(self::INVALID_HOSTNAME); + + // Get messages and errors from hostnameValidator + foreach ($this->_options['hostname']->getMessages() as $code => $message) { + $this->_messages[$code] = $message; + } + + foreach ($this->_options['hostname']->getErrors() as $error) { + $this->_errors[] = $error; + } + } else if ($this->_options['mx']) { + // MX check on hostname + $hostname = $this->_validateMXRecords(); + } + + return $hostname; } /** @@ -176,9 +521,8 @@ class Zend_Validate_EmailAddress extends Zend_Validate_Abstract return false; } - $matches = array(); - $length = true; - + $matches = array(); + $length = true; $this->_setValue($value); // Split email address up and disallow '..' @@ -197,68 +541,19 @@ class Zend_Validate_EmailAddress extends Zend_Validate_Abstract } // Match hostname part - $hostnameResult = $this->hostnameValidator->setTranslator($this->getTranslator()) - ->isValid($this->_hostname); - if (!$hostnameResult) { - $this->_error(self::INVALID_HOSTNAME); - - // Get messages and errors from hostnameValidator - foreach ($this->hostnameValidator->getMessages() as $code => $message) { - $this->_messages[$code] = $message; - } - foreach ($this->hostnameValidator->getErrors() as $error) { - $this->_errors[] = $error; - } - } else if ($this->_validateMx) { - // MX check on hostname via dns_get_record() - if ($this->validateMxSupported()) { - $result = dns_get_mx($this->_hostname, $mxHosts); - if (count($mxHosts) < 1) { - $hostnameResult = false; - $this->_error(self::INVALID_MX_RECORD); - } - } else { - /** - * MX checks are not supported by this system - * @see Zend_Validate_Exception - */ - require_once 'Zend/Validate/Exception.php'; - throw new Zend_Validate_Exception('Internal error: MX checking not available on this system'); - } + if ($this->_options['domain']) { + $hostname = $this->_validateHostnamePart(); } - // First try to match the local part on the common dot-atom format - $localResult = false; - - // Dot-atom characters are: 1*atext *("." 1*atext) - // atext: ALPHA / DIGIT / and "!", "#", "$", "%", "&", "'", "*", - // "+", "-", "/", "=", "?", "^", "_", "`", "{", "|", "}", "~" - $atext = 'a-zA-Z0-9\x21\x23\x24\x25\x26\x27\x2a\x2b\x2d\x2f\x3d\x3f\x5e\x5f\x60\x7b\x7c\x7d\x7e'; - if (preg_match('/^[' . $atext . ']+(\x2e+[' . $atext . ']+)*$/', $this->_localPart)) { - $localResult = true; - } else { - // Try quoted string format + $local = $this->_validateLocalPart(); - // Quoted-string characters are: DQUOTE *([FWS] qtext/quoted-pair) [FWS] DQUOTE - // qtext: Non white space controls, and the rest of the US-ASCII characters not - // including "\" or the quote character - $noWsCtl = '\x01-\x08\x0b\x0c\x0e-\x1f\x7f'; - $qtext = $noWsCtl . '\x21\x23-\x5b\x5d-\x7e'; - $ws = '\x20\x09'; - if (preg_match('/^\x22([' . $ws . $qtext . '])*[$ws]?\x22$/', $this->_localPart)) { - $localResult = true; - } else { - $this->_error(self::DOT_ATOM); - $this->_error(self::QUOTED_STRING); - $this->_error(self::INVALID_LOCAL_PART); + // If both parts valid, return true + if ($local && $length) { + if (($this->_options['domain'] && $hostname) || !$this->_options['domain']) { + return true; } } - // If both parts valid, return true - if ($localResult && $hostnameResult && $length) { - return true; - } else { - return false; - } + return false; } } diff --git a/libs/Zend/Validate/Exception.php b/libs/Zend/Validate/Exception.php index d6b646f1cd..fa875e14ed 100644 --- a/libs/Zend/Validate/Exception.php +++ b/libs/Zend/Validate/Exception.php @@ -1,5 +1,4 @@ <?php - /** * Zend Framework * @@ -15,22 +14,20 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 16223 2009-06-21 20:04:53Z thomas $ + * @version $Id: Exception.php 20096 2010-01-06 02:05:09Z bkarwin $ */ - /** * @see Zend_Exception */ require_once 'Zend/Exception.php'; - /** * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Validate_Exception extends Zend_Exception diff --git a/libs/Zend/Validate/File/Count.php b/libs/Zend/Validate/File/Count.php index f2dfac7413..e7519b0d63 100644 --- a/libs/Zend/Validate/File/Count.php +++ b/libs/Zend/Validate/File/Count.php @@ -14,9 +14,9 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 18148 2009-09-16 19:27:43Z thomas $ + * @version $Id: Count.php 20358 2010-01-17 19:03:49Z thomas $ */ /** @@ -29,7 +29,7 @@ require_once 'Zend/Validate/Abstract.php'; * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Validate_File_Count extends Zend_Validate_Abstract @@ -37,16 +37,16 @@ class Zend_Validate_File_Count extends Zend_Validate_Abstract /**#@+ * @const string Error constants */ - const TOO_MUCH = 'fileCountTooMuch'; - const TOO_LESS = 'fileCountTooLess'; + const TOO_MANY = 'fileCountTooMany'; + const TOO_FEW = 'fileCountTooFew'; /**#@-*/ /** * @var array Error message templates */ protected $_messageTemplates = array( - self::TOO_MUCH => "Too much files, maximum '%max%' are allowed but '%count%' are given", - self::TOO_LESS => "Too less files, minimum '%min%' are expected but '%count%' are given" + self::TOO_MANY => "Too many files, maximum '%max%' are allowed but '%count%' are given", + self::TOO_FEW => "Too few files, minimum '%min%' are expected but '%count%' are given", ); /** @@ -115,8 +115,6 @@ class Zend_Validate_File_Count extends Zend_Validate_Abstract } if (1 < func_num_args()) { -// @todo: Preperation for 2.0... needs to be cleared with the dev-team -// trigger_error('Multiple arguments are deprecated in favor of an array of named arguments', E_USER_NOTICE); $options['min'] = func_get_arg(0); $options['max'] = func_get_arg(1); } @@ -243,14 +241,22 @@ class Zend_Validate_File_Count extends Zend_Validate_Abstract */ public function isValid($value, $file = null) { + if (($file !== null) && !array_key_exists('destination', $file)) { + $file['destination'] = dirname($value); + } + + if (($file !== null) && array_key_exists('tmp_name', $file)) { + $value = $file['destination'] . DIRECTORY_SEPARATOR . $file['name']; + } + $this->addFile($value); $this->_count = count($this->_files); if (($this->_max !== null) && ($this->_count > $this->_max)) { - return $this->_throw($file, self::TOO_MUCH); + return $this->_throw($file, self::TOO_MANY); } if (($this->_min !== null) && ($this->_count < $this->_min)) { - return $this->_throw($file, self::TOO_LESS); + return $this->_throw($file, self::TOO_FEW); } return true; diff --git a/libs/Zend/Validate/File/Crc32.php b/libs/Zend/Validate/File/Crc32.php index fd46d81b6b..e7c06d6035 100644 --- a/libs/Zend/Validate/File/Crc32.php +++ b/libs/Zend/Validate/File/Crc32.php @@ -14,9 +14,9 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 18148 2009-09-16 19:27:43Z thomas $ + * @version $Id: Crc32.php 20358 2010-01-17 19:03:49Z thomas $ */ /** @@ -29,7 +29,7 @@ require_once 'Zend/Validate/File/Hash.php'; * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Validate_File_Crc32 extends Zend_Validate_File_Hash @@ -45,9 +45,9 @@ class Zend_Validate_File_Crc32 extends Zend_Validate_File_Hash * @var array Error message templates */ protected $_messageTemplates = array( - self::DOES_NOT_MATCH => "The file '%value%' does not match the given crc32 hashes", - self::NOT_DETECTED => "There was no crc32 hash detected for the given file", - self::NOT_FOUND => "The file '%value%' could not be found" + 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", ); /** diff --git a/libs/Zend/Validate/File/ExcludeExtension.php b/libs/Zend/Validate/File/ExcludeExtension.php index 74264de98c..b31e372747 100644 --- a/libs/Zend/Validate/File/ExcludeExtension.php +++ b/libs/Zend/Validate/File/ExcludeExtension.php @@ -14,9 +14,9 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 16971 2009-07-22 18:05:45Z mikaelkael $ + * @version $Id: ExcludeExtension.php 20358 2010-01-17 19:03:49Z thomas $ */ /** @@ -29,7 +29,7 @@ require_once 'Zend/Validate/File/Extension.php'; * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Validate_File_ExcludeExtension extends Zend_Validate_File_Extension @@ -44,8 +44,8 @@ class Zend_Validate_File_ExcludeExtension extends Zend_Validate_File_Extension * @var array Error message templates */ protected $_messageTemplates = array( - self::FALSE_EXTENSION => "The file '%value%' has a false extension", - self::NOT_FOUND => "The file '%value%' was not found" + self::FALSE_EXTENSION => "File '%value%' has a false extension", + self::NOT_FOUND => "File '%value%' could not be found", ); /** diff --git a/libs/Zend/Validate/File/ExcludeMimeType.php b/libs/Zend/Validate/File/ExcludeMimeType.php index 4984b79cfb..22f74fba8b 100644 --- a/libs/Zend/Validate/File/ExcludeMimeType.php +++ b/libs/Zend/Validate/File/ExcludeMimeType.php @@ -14,9 +14,9 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 18148 2009-09-16 19:27:43Z thomas $ + * @version $Id: ExcludeMimeType.php 20096 2010-01-06 02:05:09Z bkarwin $ */ /** @@ -29,7 +29,7 @@ require_once 'Zend/Validate/File/MimeType.php'; * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Validate_File_ExcludeMimeType extends Zend_Validate_File_MimeType diff --git a/libs/Zend/Validate/File/Exists.php b/libs/Zend/Validate/File/Exists.php index 835b4c2c70..86a21780fb 100644 --- a/libs/Zend/Validate/File/Exists.php +++ b/libs/Zend/Validate/File/Exists.php @@ -14,9 +14,9 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 18148 2009-09-16 19:27:43Z thomas $ + * @version $Id: Exists.php 20358 2010-01-17 19:03:49Z thomas $ */ /** @@ -29,7 +29,7 @@ require_once 'Zend/Validate/Abstract.php'; * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Validate_File_Exists extends Zend_Validate_Abstract @@ -43,7 +43,7 @@ class Zend_Validate_File_Exists extends Zend_Validate_Abstract * @var array Error message templates */ protected $_messageTemplates = array( - self::DOES_NOT_EXIST => "The file '%value%' does not exist" + self::DOES_NOT_EXIST => "File '%value%' does not exist", ); /** diff --git a/libs/Zend/Validate/File/Extension.php b/libs/Zend/Validate/File/Extension.php index 58ab0b21af..021b5e03bb 100644 --- a/libs/Zend/Validate/File/Extension.php +++ b/libs/Zend/Validate/File/Extension.php @@ -14,9 +14,9 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 18148 2009-09-16 19:27:43Z thomas $ + * @version $Id: Extension.php 20358 2010-01-17 19:03:49Z thomas $ */ /** @@ -29,7 +29,7 @@ require_once 'Zend/Validate/Abstract.php'; * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Validate_File_Extension extends Zend_Validate_Abstract @@ -44,8 +44,8 @@ class Zend_Validate_File_Extension extends Zend_Validate_Abstract * @var array Error message templates */ protected $_messageTemplates = array( - self::FALSE_EXTENSION => "The file '%value%' has a false extension", - self::NOT_FOUND => "The file '%value%' was not found" + self::FALSE_EXTENSION => "File '%value%' has a false extension", + self::NOT_FOUND => "File '%value%' could not be found", ); /** @@ -81,8 +81,6 @@ class Zend_Validate_File_Extension extends Zend_Validate_Abstract } if (1 < func_num_args()) { -// @todo: Preperation for 2.0... needs to be cleared with the dev-team -// trigger_error('Multiple arguments to constructor are deprecated in favor of options array', E_USER_NOTICE); $case = func_get_arg(1); $this->setCase($case); } diff --git a/libs/Zend/Validate/File/FilesSize.php b/libs/Zend/Validate/File/FilesSize.php index 167304b771..05c660b81b 100644 --- a/libs/Zend/Validate/File/FilesSize.php +++ b/libs/Zend/Validate/File/FilesSize.php @@ -14,9 +14,9 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 18148 2009-09-16 19:27:43Z thomas $ + * @version $Id: FilesSize.php 20455 2010-01-20 22:54:18Z thomas $ */ /** @@ -29,7 +29,7 @@ require_once 'Zend/Validate/File/Size.php'; * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Validate_File_FilesSize extends Zend_Validate_File_Size @@ -47,7 +47,7 @@ class Zend_Validate_File_FilesSize extends Zend_Validate_File_Size protected $_messageTemplates = array( self::TOO_BIG => "All files in sum should have a maximum size of '%max%' but '%size%' were detected", self::TOO_SMALL => "All files in sum should have a minimum size of '%min%' but '%size%' were detected", - self::NOT_READABLE => "One or more files can not be read" + self::NOT_READABLE => "One or more files can not be read", ); /** @@ -81,9 +81,6 @@ class Zend_Validate_File_FilesSize extends Zend_Validate_File_Size } if (1 < func_num_args()) { -// @todo: Preperation for 2.0... needs to be cleared with the dev-team -// trigger_error('Multiple constructor options are deprecated in favor of a single options array', E_USER_NOTICE); - $argv = func_get_args(); array_shift($argv); $options['max'] = array_shift($argv); @@ -131,12 +128,14 @@ class Zend_Validate_File_FilesSize extends Zend_Validate_File_Size // limited to 2GB files $size += @filesize($files); - $this->_setSize($size); + $this->_size = $size; if (($max !== null) && ($max < $size)) { if ($this->useByteString()) { - $this->setMax($this->_toByteString($max)); + $this->_max = $this->_toByteString($max); + $this->_size = $this->_toByteString($size); $this->_throw($file, self::TOO_BIG); - $this->setMax($max); + $this->_max = $max; + $this->_size = $size; } else { $this->_throw($file, self::TOO_BIG); } @@ -146,9 +145,11 @@ class Zend_Validate_File_FilesSize extends Zend_Validate_File_Size // Check that aggregate files are >= minimum size if (($min !== null) && ($size < $min)) { if ($this->useByteString()) { - $this->setMin($this->_toByteString($min)); + $this->_min = $this->_toByteString($min); + $this->_size = $this->_toByteString($size); $this->_throw($file, self::TOO_SMALL); - $this->setMin($min); + $this->_min = $min; + $this->_size = $size; } else { $this->_throw($file, self::TOO_SMALL); } diff --git a/libs/Zend/Validate/File/Hash.php b/libs/Zend/Validate/File/Hash.php index d2e8c2c645..2b20cac699 100644 --- a/libs/Zend/Validate/File/Hash.php +++ b/libs/Zend/Validate/File/Hash.php @@ -14,9 +14,9 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 18148 2009-09-16 19:27:43Z thomas $ + * @version $Id: Hash.php 20358 2010-01-17 19:03:49Z thomas $ */ /** @@ -29,7 +29,7 @@ require_once 'Zend/Validate/Abstract.php'; * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Validate_File_Hash extends Zend_Validate_Abstract @@ -45,9 +45,9 @@ class Zend_Validate_File_Hash extends Zend_Validate_Abstract * @var array Error message templates */ protected $_messageTemplates = array( - self::DOES_NOT_MATCH => "The file '%value%' does not match the given hashes", - self::NOT_DETECTED => "There was no hash detected for the given file", - self::NOT_FOUND => "The file '%value%' could not be found" + 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" ); /** @@ -75,8 +75,6 @@ class Zend_Validate_File_Hash extends Zend_Validate_Abstract } if (1 < func_num_args()) { -// @todo: Preperation for 2.0... needs to be cleared with the dev-team -// trigger_error('Multiple constructor options are deprecated in favor of a single options array', E_USER_NOTICE); $options['algorithm'] = func_get_arg(1); } diff --git a/libs/Zend/Validate/File/ImageSize.php b/libs/Zend/Validate/File/ImageSize.php index c01ec97341..0d8a4fa74e 100644 --- a/libs/Zend/Validate/File/ImageSize.php +++ b/libs/Zend/Validate/File/ImageSize.php @@ -14,9 +14,9 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 18148 2009-09-16 19:27:43Z thomas $ + * @version $Id: ImageSize.php 20358 2010-01-17 19:03:49Z thomas $ */ /** @@ -29,7 +29,7 @@ require_once 'Zend/Validate/Abstract.php'; * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Validate_File_ImageSize extends Zend_Validate_Abstract @@ -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 => "The image '%value%' can not be read" + self::NOT_READABLE => "File '%value%' can not be read", ); /** @@ -127,8 +127,6 @@ class Zend_Validate_File_ImageSize extends Zend_Validate_Abstract if ($options instanceof Zend_Config) { $options = $options->toArray(); } elseif (1 < func_num_args()) { -// @todo: Preperation for 2.0... needs to be cleared with the dev-team -// trigger_error('Multiple constructor options are deprecated in favor of a single options array', E_USER_NOTICE); if (!is_array($options)) { $options = array('minwidth' => $options); } diff --git a/libs/Zend/Validate/File/IsCompressed.php b/libs/Zend/Validate/File/IsCompressed.php index 3254d57341..d2b8a25430 100644 --- a/libs/Zend/Validate/File/IsCompressed.php +++ b/libs/Zend/Validate/File/IsCompressed.php @@ -14,9 +14,9 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 18148 2009-09-16 19:27:43Z thomas $ + * @version $Id: IsCompressed.php 20358 2010-01-17 19:03:49Z thomas $ */ /** @@ -29,7 +29,7 @@ require_once 'Zend/Validate/File/MimeType.php'; * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Validate_File_IsCompressed extends Zend_Validate_File_MimeType @@ -45,9 +45,9 @@ class Zend_Validate_File_IsCompressed extends Zend_Validate_File_MimeType * @var array Error message templates */ protected $_messageTemplates = array( - self::FALSE_TYPE => "The file '%value%' is not compressed, '%type%' detected", - self::NOT_DETECTED => "The mimetype of file '%value%' has not been detected", - self::NOT_READABLE => "The file '%value%' can not be read" + 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", ); /** @@ -60,27 +60,74 @@ class Zend_Validate_File_IsCompressed extends Zend_Validate_File_MimeType { if ($mimetype instanceof Zend_Config) { $mimetype = $mimetype->toArray(); - } else if (empty($mimetype)) { - $mimetype = array( - 'application/x-tar', - 'application/x-cpio', - 'application/x-debian-package', - 'application/x-archive', - 'application/x-arc', - 'application/x-arj', - 'application/x-lharc', - 'application/x-lha', - 'application/x-rar', - 'application/zip', - 'application/zoo', - 'application/x-eet', - 'application/x-java-pack200', - 'application/x-compress', - 'application/x-gzip', - 'application/x-bzip2' - ); } - $this->setMimeType($mimetype); + $temp = array(); + $default = array( + 'application/x-tar', + 'application/x-cpio', + 'application/x-debian-package', + 'application/x-archive', + 'application/x-arc', + 'application/x-arj', + 'application/x-lharc', + 'application/x-lha', + 'application/x-rar', + 'application/zip', + 'application/zoo', + 'application/x-eet', + 'application/x-java-pack200', + 'application/x-compress', + 'application/x-gzip', + 'application/x-bzip2' + ); + + if (is_array($mimetype)) { + $temp = $mimetype; + if (array_key_exists('magicfile', $temp)) { + unset($temp['magicfile']); + } + + if (array_key_exists('headerCheck', $temp)) { + unset($temp['headerCheck']); + } + + if (empty($temp)) { + $mimetype += $default; + } + } + + if (empty($mimetype)) { + $mimetype = $default; + } + + parent::__construct($mimetype); + } + + /** + * Throws an error of the given type + * Duplicates parent method due to OOP Problem with late static binding in PHP 5.2 + * + * @param string $file + * @param string $errorType + * @return false + */ + protected function _throw($file, $errorType) + { + $this->_value = $file['name']; + switch($errorType) { + case Zend_Validate_File_MimeType::FALSE_TYPE : + $errorType = self::FALSE_TYPE; + break; + case Zend_Validate_File_MimeType::NOT_DETECTED : + $errorType = self::NOT_DETECTED; + break; + case Zend_Validate_File_MimeType::NOT_READABLE : + $errorType = self::NOT_READABLE; + break; + } + + $this->_error($errorType); + return false; } } diff --git a/libs/Zend/Validate/File/IsImage.php b/libs/Zend/Validate/File/IsImage.php index 3904af1f90..77756277f0 100644 --- a/libs/Zend/Validate/File/IsImage.php +++ b/libs/Zend/Validate/File/IsImage.php @@ -14,9 +14,9 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 18148 2009-09-16 19:27:43Z thomas $ + * @version $Id: IsImage.php 20358 2010-01-17 19:03:49Z thomas $ */ /** @@ -29,7 +29,7 @@ require_once 'Zend/Validate/File/MimeType.php'; * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Validate_File_IsImage extends Zend_Validate_File_MimeType @@ -45,9 +45,9 @@ class Zend_Validate_File_IsImage extends Zend_Validate_File_MimeType * @var array Error message templates */ protected $_messageTemplates = array( - self::FALSE_TYPE => "The file '%value%' is no image, '%type%' detected", - self::NOT_DETECTED => "The mimetype of file '%value%' has not been detected", - self::NOT_READABLE => "The file '%value%' can not be read" + self::FALSE_TYPE => "File '%value%' is no image, '%type%' detected", + self::NOT_DETECTED => "The mimetype of file '%value%' could not been detected", + self::NOT_READABLE => "File '%value%' can not be read", ); /** @@ -60,31 +60,78 @@ class Zend_Validate_File_IsImage extends Zend_Validate_File_MimeType { if ($mimetype instanceof Zend_Config) { $mimetype = $mimetype->toArray(); - } else if (empty($mimetype)) { - $mimetype = array( - 'image/x-quicktime', - 'image/jp2', - 'image/x-xpmi', - 'image/x-portable-bitmap', - 'image/x-portable-greymap', - 'image/x-portable-pixmap', - 'image/x-niff', - 'image/tiff', - 'image/png', - 'image/x-unknown', - 'image/gif', - 'image/x-ms-bmp', - 'application/dicom', - 'image/vnd.adobe.photoshop', - 'image/vnd.djvu', - 'image/x-cpi', - 'image/jpeg', - 'image/x-ico', - 'image/x-coreldraw', - 'image/svg+xml' - ); } - $this->setMimeType($mimetype); + $temp = array(); + $default = array( + 'image/x-quicktime', + 'image/jp2', + 'image/x-xpmi', + 'image/x-portable-bitmap', + 'image/x-portable-greymap', + 'image/x-portable-pixmap', + 'image/x-niff', + 'image/tiff', + 'image/png', + 'image/x-unknown', + 'image/gif', + 'image/x-ms-bmp', + 'application/dicom', + 'image/vnd.adobe.photoshop', + 'image/vnd.djvu', + 'image/x-cpi', + 'image/jpeg', + 'image/x-ico', + 'image/x-coreldraw', + 'image/svg+xml' + ); + + if (is_array($mimetype)) { + $temp = $mimetype; + if (array_key_exists('magicfile', $temp)) { + unset($temp['magicfile']); + } + + if (array_key_exists('headerCheck', $temp)) { + unset($temp['headerCheck']); + } + + if (empty($temp)) { + $mimetype += $default; + } + } + + if (empty($mimetype)) { + $mimetype = $default; + } + + parent::__construct($mimetype); + } + + /** + * Throws an error of the given type + * Duplicates parent method due to OOP Problem with late static binding in PHP 5.2 + * + * @param string $file + * @param string $errorType + * @return false + */ + protected function _throw($file, $errorType) + { + $this->_value = $file['name']; + switch($errorType) { + case Zend_Validate_File_MimeType::FALSE_TYPE : + $errorType = self::FALSE_TYPE; + break; + case Zend_Validate_File_MimeType::NOT_DETECTED : + $errorType = self::NOT_DETECTED; + break; + case Zend_Validate_File_MimeType::NOT_READABLE : + $errorType = self::NOT_READABLE; + break; + } + + $this->_error($errorType); + return false; } } diff --git a/libs/Zend/Validate/File/Md5.php b/libs/Zend/Validate/File/Md5.php index cfbd83fb53..80fed0bd26 100644 --- a/libs/Zend/Validate/File/Md5.php +++ b/libs/Zend/Validate/File/Md5.php @@ -14,9 +14,9 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 16971 2009-07-22 18:05:45Z mikaelkael $ + * @version $Id: Md5.php 20442 2010-01-20 15:15:40Z matthew $ */ /** @@ -29,7 +29,7 @@ require_once 'Zend/Validate/File/Hash.php'; * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Validate_File_Md5 extends Zend_Validate_File_Hash @@ -45,9 +45,9 @@ class Zend_Validate_File_Md5 extends Zend_Validate_File_Hash * @var array Error message templates */ protected $_messageTemplates = array( - self::DOES_NOT_MATCH => "The file '%value%' does not match the given md5 hashes", - self::NOT_DETECTED => "There was no md5 hash detected for the given file", - self::NOT_FOUND => "The file '%value%' could not be found" + 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", ); /** @@ -123,7 +123,7 @@ class Zend_Validate_File_Md5 extends Zend_Validate_File_Hash * Adds the md5 hash for one or multiple files * * @param string|array $options - * @param string $algorithm (Depreciated) Algorithm to use, fixed to md5 + * @param string $algorithm (Deprecated) Algorithm to use, fixed to md5 * @return Zend_Validate_File_Hash Provides a fluent interface */ public function addHash($options) diff --git a/libs/Zend/Validate/File/MimeType.php b/libs/Zend/Validate/File/MimeType.php index 2bf372c4fc..a4b4ec58aa 100644 --- a/libs/Zend/Validate/File/MimeType.php +++ b/libs/Zend/Validate/File/MimeType.php @@ -14,9 +14,9 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 18513 2009-10-12 16:17:35Z matthew $ + * @version $Id: MimeType.php 20505 2010-01-21 21:40:23Z thomas $ */ /** @@ -29,7 +29,7 @@ require_once 'Zend/Validate/Abstract.php'; * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Validate_File_MimeType extends Zend_Validate_Abstract @@ -46,9 +46,9 @@ class Zend_Validate_File_MimeType extends Zend_Validate_Abstract * @var array Error message templates */ protected $_messageTemplates = array( - self::FALSE_TYPE => "The file '%value%' has a false mimetype of '%type%'", - self::NOT_DETECTED => "The mimetype of file '%value%' could not been detected", - self::NOT_READABLE => "The file '%value%' can not be read" + 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", ); /** @@ -123,10 +123,12 @@ class Zend_Validate_File_MimeType extends Zend_Validate_Abstract if (isset($mimetype['magicfile'])) { $this->setMagicFile($mimetype['magicfile']); + unset($mimetype['magicfile']); } if (isset($mimetype['headerCheck'])) { - $this->enableHeaderCheck(true); + $this->enableHeaderCheck($mimetype['headerCheck']); + unset($mimetype['headerCheck']); } $this->setMimeType($mimetype); @@ -139,14 +141,20 @@ class Zend_Validate_File_MimeType extends Zend_Validate_Abstract */ public function getMagicFile() { - if (null === $this->_magicfile && empty($_ENV['MAGIC'])) { - foreach ($this->_magicFiles as $file) { - if (file_exists($file)) { - $this->setMagicFile($file); - break; + if (null === $this->_magicfile) { + if (!empty($_ENV['MAGIC'])) { + $this->setMagicFile($_ENV['MAGIC']); + } elseif (!(@ini_get("safe_mode") == 'On' || @ini_get("safe_mode") === 1)) { + foreach ($this->_magicFiles as $file) { + // supressing errors which are thrown due to openbase_dir restrictions + if (@file_exists($file)) { + $this->setMagicFile($file); + break; + } } } } + return $this->_magicfile; } @@ -306,12 +314,13 @@ class Zend_Validate_File_MimeType extends Zend_Validate_Abstract unset($mime); } - if (empty($this->_type)) { - if (function_exists('mime_content_type') && ini_get('mime_magic.magicfile')) { + if (empty($this->_type) && + (function_exists('mime_content_type') && ini_get('mime_magic.magicfile'))) { $this->_type = mime_content_type($value); - } elseif ($this->_headerCheck) { - $this->_type = $file['type']; - } + } + + if (empty($this->_type) && $this->_headerCheck) { + $this->_type = $file['type']; } if (empty($this->_type)) { diff --git a/libs/Zend/Validate/File/NotExists.php b/libs/Zend/Validate/File/NotExists.php index 0cc3c87ac9..87ebb827b4 100644 --- a/libs/Zend/Validate/File/NotExists.php +++ b/libs/Zend/Validate/File/NotExists.php @@ -14,9 +14,9 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 16971 2009-07-22 18:05:45Z mikaelkael $ + * @version $Id: NotExists.php 20358 2010-01-17 19:03:49Z thomas $ */ /** @@ -29,7 +29,7 @@ require_once 'Zend/Validate/File/Exists.php'; * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Validate_File_NotExists extends Zend_Validate_File_Exists @@ -43,7 +43,7 @@ class Zend_Validate_File_NotExists extends Zend_Validate_File_Exists * @var array Error message templates */ protected $_messageTemplates = array( - self::DOES_EXIST => "The file '%value%' does exist" + self::DOES_EXIST => "File '%value%' exists", ); /** diff --git a/libs/Zend/Validate/File/Sha1.php b/libs/Zend/Validate/File/Sha1.php index 9dd4418d71..2157bfb26c 100644 --- a/libs/Zend/Validate/File/Sha1.php +++ b/libs/Zend/Validate/File/Sha1.php @@ -14,9 +14,9 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 16971 2009-07-22 18:05:45Z mikaelkael $ + * @version $Id: Sha1.php 20358 2010-01-17 19:03:49Z thomas $ */ /** @@ -29,7 +29,7 @@ require_once 'Zend/Validate/File/Hash.php'; * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Validate_File_Sha1 extends Zend_Validate_File_Hash @@ -45,9 +45,9 @@ class Zend_Validate_File_Sha1 extends Zend_Validate_File_Hash * @var array Error message templates */ protected $_messageTemplates = array( - self::DOES_NOT_MATCH => "The file '%value%' does not match the given sha1 hashes", - self::NOT_DETECTED => "There was no sha1 hash detected for the given file", - self::NOT_FOUND => "The file '%value%' could not be found" + 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", ); /** diff --git a/libs/Zend/Validate/File/Size.php b/libs/Zend/Validate/File/Size.php index 4c41178966..bfd02aa80b 100644 --- a/libs/Zend/Validate/File/Size.php +++ b/libs/Zend/Validate/File/Size.php @@ -14,9 +14,9 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 18148 2009-09-16 19:27:43Z thomas $ + * @version $Id: Size.php 20455 2010-01-20 22:54:18Z thomas $ */ /** @@ -29,7 +29,7 @@ require_once 'Zend/Validate/Abstract.php'; * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Validate_File_Size extends Zend_Validate_Abstract @@ -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 => "The file '%value%' could not be found" + self::NOT_FOUND => "File '%value%' could not be found", ); /** @@ -112,8 +112,6 @@ class Zend_Validate_File_Size extends Zend_Validate_Abstract } if (1 < func_num_args()) { -// @todo: Preperation for 2.0... needs to be cleared with the dev-team -// trigger_error('Multiple constructor options are deprecated in favor of a single options array', E_USER_NOTICE); $argv = func_get_args(); array_shift($argv); $options['max'] = array_shift($argv); @@ -282,7 +280,8 @@ class Zend_Validate_File_Size extends Zend_Validate_Abstract } // limited to 4GB files - $size = sprintf("%u", @filesize($value)); + $size = sprintf("%u", @filesize($value)); + $this->_size = $size; // Check to see if it's smaller than min size $min = $this->getMin(true); diff --git a/libs/Zend/Validate/File/Upload.php b/libs/Zend/Validate/File/Upload.php index fd1bdfe754..85f408c735 100644 --- a/libs/Zend/Validate/File/Upload.php +++ b/libs/Zend/Validate/File/Upload.php @@ -14,9 +14,9 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 18148 2009-09-16 19:27:43Z thomas $ + * @version $Id: Upload.php 20431 2010-01-19 21:36:05Z thomas $ */ /** @@ -29,7 +29,7 @@ require_once 'Zend/Validate/Abstract.php'; * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Validate_File_Upload extends Zend_Validate_Abstract @@ -53,16 +53,16 @@ class Zend_Validate_File_Upload extends Zend_Validate_Abstract * @var array Error message templates */ protected $_messageTemplates = array( - self::INI_SIZE => "The file '%value%' exceeds the defined ini size", - self::FORM_SIZE => "The file '%value%' exceeds the defined form size", - self::PARTIAL => "The file '%value%' was only partially uploaded", - self::NO_FILE => "The file '%value%' was not uploaded", - self::NO_TMP_DIR => "No temporary directory was found for the file '%value%'", - self::CANT_WRITE => "The file '%value%' can't be written", - self::EXTENSION => "The extension returned an error while uploading the file '%value%'", - self::ATTACK => "The file '%value%' was illegal uploaded, possible attack", - self::FILE_NOT_FOUND => "The file '%value%' was not found", - self::UNKNOWN => "Unknown error while uploading the file '%value%'" + self::INI_SIZE => "File '%value%' exceeds the defined ini size", + self::FORM_SIZE => "File '%value%' exceeds the defined form size", + self::PARTIAL => "File '%value%' was only partially uploaded", + self::NO_FILE => "File '%value%' was not uploaded", + self::NO_TMP_DIR => "No temporary directory was found for file '%value%'", + self::CANT_WRITE => "File '%value%' can't be written", + self::EXTENSION => "A PHP extension returned an error while uploading the file '%value%'", + self::ATTACK => "File '%value%' was illegally uploaded. This could be a possible attack", + self::FILE_NOT_FOUND => "File '%value%' was not found", + self::UNKNOWN => "Unknown error while uploading file '%value%'" ); /** diff --git a/libs/Zend/Validate/File/WordCount.php b/libs/Zend/Validate/File/WordCount.php index b5249532d3..9936cb662f 100644 --- a/libs/Zend/Validate/File/WordCount.php +++ b/libs/Zend/Validate/File/WordCount.php @@ -14,9 +14,9 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 16971 2009-07-22 18:05:45Z mikaelkael $ + * @version $Id: WordCount.php 20358 2010-01-17 19:03:49Z thomas $ */ /** @@ -29,7 +29,7 @@ require_once 'Zend/Validate/File/Count.php'; * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Validate_File_WordCount extends Zend_Validate_File_Count @@ -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 => "The file '%value%' could not be found" + self::NOT_FOUND => "File '%value%' could not be found", ); /** diff --git a/libs/Zend/Validate/Float.php b/libs/Zend/Validate/Float.php index bfa5e62c14..c855aeaf03 100644 --- a/libs/Zend/Validate/Float.php +++ b/libs/Zend/Validate/Float.php @@ -14,9 +14,9 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 17470 2009-08-08 22:27:09Z thomas $ + * @version $Id: Float.php 20532 2010-01-22 20:18:23Z thomas $ */ /** @@ -32,7 +32,7 @@ require_once 'Zend/Locale/Format.php'; /** * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Validate_Float extends Zend_Validate_Abstract @@ -45,7 +45,7 @@ class Zend_Validate_Float extends Zend_Validate_Abstract */ protected $_messageTemplates = array( self::INVALID => "Invalid type given, value should be float, string, or integer", - self::NOT_FLOAT => "'%value%' does not appear to be a float" + self::NOT_FLOAT => "'%value%' does not appear to be a float", ); protected $_locale; @@ -53,10 +53,29 @@ class Zend_Validate_Float extends Zend_Validate_Abstract /** * Constructor for the float validator * - * @param string|Zend_Locale $locale + * @param string|Zend_Config|Zend_Locale $locale */ public function __construct($locale = null) { + if ($locale instanceof Zend_Config) { + $locale = $locale->toArray(); + } + + if (is_array($locale)) { + if (array_key_exists('locale', $locale)) { + $locale = $locale['locale']; + } else { + $locale = null; + } + } + + if (empty($locale)) { + require_once 'Zend/Registry.php'; + if (Zend_Registry::isRegistered('Zend_Locale')) { + $locale = Zend_Registry::get('Zend_Locale'); + } + } + if ($locale !== null) { $this->setLocale($locale); } @@ -97,6 +116,10 @@ class Zend_Validate_Float extends Zend_Validate_Abstract return false; } + if (is_float($value)) { + return true; + } + $this->_setValue($value); if ($this->_locale === null) { $locale = localeconv(); diff --git a/libs/Zend/Validate/GreaterThan.php b/libs/Zend/Validate/GreaterThan.php index 3c7b7931c9..53c71ccbc2 100644 --- a/libs/Zend/Validate/GreaterThan.php +++ b/libs/Zend/Validate/GreaterThan.php @@ -1,5 +1,4 @@ <?php - /** * Zend Framework * @@ -15,22 +14,20 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 17470 2009-08-08 22:27:09Z thomas $ + * @version $Id: GreaterThan.php 20358 2010-01-17 19:03:49Z thomas $ */ - /** * @see Zend_Validate_Abstract */ require_once 'Zend/Validate/Abstract.php'; - /** * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Validate_GreaterThan extends Zend_Validate_Abstract @@ -42,7 +39,7 @@ class Zend_Validate_GreaterThan extends Zend_Validate_Abstract * @var array */ protected $_messageTemplates = array( - self::NOT_GREATER => "'%value%' is not greater than '%min%'" + self::NOT_GREATER => "'%value%' is not greater than '%min%'", ); /** @@ -62,11 +59,24 @@ class Zend_Validate_GreaterThan extends Zend_Validate_Abstract /** * Sets validator options * - * @param mixed $min + * @param mixed|Zend_Config $min * @return void */ public function __construct($min) { + if ($min instanceof Zend_Config) { + $min = $min->toArray(); + } + + if (is_array($min)) { + if (array_key_exists('min', $min)) { + $min = $min['min']; + } else { + require_once 'Zend/Validate/Exception.php'; + throw new Zend_Validate_Exception("Missing option 'min'"); + } + } + $this->setMin($min); } diff --git a/libs/Zend/Validate/Hex.php b/libs/Zend/Validate/Hex.php index 85d3e3a7a2..ced156dfe3 100644 --- a/libs/Zend/Validate/Hex.php +++ b/libs/Zend/Validate/Hex.php @@ -1,5 +1,4 @@ <?php - /** * Zend Framework * @@ -15,22 +14,20 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 17470 2009-08-08 22:27:09Z thomas $ + * @version $Id: Hex.php 20358 2010-01-17 19:03:49Z thomas $ */ - /** * @see Zend_Validate_Abstract */ require_once 'Zend/Validate/Abstract.php'; - /** * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Validate_Hex extends Zend_Validate_Abstract @@ -45,7 +42,7 @@ class Zend_Validate_Hex extends Zend_Validate_Abstract */ protected $_messageTemplates = array( self::INVALID => "Invalid type given, value should be a string", - self::NOT_HEX => "'%value%' has not only hexadecimal digit characters" + 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 dd254d5596..04f656dab8 100644 --- a/libs/Zend/Validate/Hostname.php +++ b/libs/Zend/Validate/Hostname.php @@ -14,9 +14,9 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 17141 2009-07-26 12:49:17Z thomas $ + * @version $Id: Hostname.php 20358 2010-01-17 19:03:49Z thomas $ */ /** @@ -41,7 +41,7 @@ require_once 'Zend/Validate/Ip.php'; * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Validate_Hostname extends Zend_Validate_Abstract @@ -64,13 +64,13 @@ class Zend_Validate_Hostname extends Zend_Validate_Abstract 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::INVALID_DASH => "'%value%' appears to be a DNS hostname but contains a dash (-) in an invalid position", + 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_LOCAL_NAME => "'%value%' does not appear to be a valid local network name", 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::CANNOT_DECODE_PUNYCODE => "'%value%' appears to be a DNS hostname but the given punycode notation cannot be decoded", ); /** @@ -101,27 +101,6 @@ class Zend_Validate_Hostname extends Zend_Validate_Abstract const ALLOW_ALL = 7; /** - * Whether IDN domains are validated - * - * @var boolean - */ - private $_validateIdn = true; - - /** - * Whether TLDs are validated against a known list - * - * @var boolean - */ - private $_validateTld = true; - - /** - * Bit field of ALLOW constants; determines which types of hostnames are allowed - * - * @var integer - */ - protected $_allow; - - /** * Array of valid top-level-domains * * @see ftp://data.iana.org/TLD/tlds-alpha-by-domain.txt List of all TLDs by domain @@ -320,6 +299,13 @@ class Zend_Validate_Hostname extends Zend_Validate_Abstract '网络' => array(1 => 20), ); + protected $_options = array( + 'allow' => self::ALLOW_DNS, + 'idn' => true, + 'tld' => true, + 'ip' => null + ); + /** * Sets validator options * @@ -330,16 +316,77 @@ class Zend_Validate_Hostname extends Zend_Validate_Abstract * @return void * @see http://www.iana.org/cctld/specifications-policies-cctlds-01apr02.htm Technical Specifications for ccTLDs */ - public function __construct($allow = self::ALLOW_DNS, $validateIdn = true, $validateTld = true, Zend_Validate_Ip $ipValidator = null) + public function __construct($options = array()) { - // Set allow options - $this->setAllow($allow); + if ($options instanceof Zend_Config) { + $options = $options->toArray(); + } else if (!is_array($options)) { + $options = func_get_args(); + $temp['allow'] = array_shift($options); + if (!empty($options)) { + $temp['idn'] = array_shift($options); + } + + if (!empty($options)) { + $temp['tld'] = array_shift($options); + } + + if (!empty($options)) { + $temp['ip'] = array_shift($options); + } + + $options = $temp; + } + + $options += $this->_options; + $this->setOptions($options); + } + + /** + * Returns all set options + * + * @return array + */ + public function getOptions() + { + return $this->_options; + } + + /** + * Sets the options for this validator + * + * @param array $options + * @return Zend_Validate_Hostname + */ + public function setOptions($options) + { + if (array_key_exists('allow', $options)) { + $this->setAllow($options['allow']); + } - // Set validation options - $this->_validateIdn = $validateIdn; - $this->_validateTld = $validateTld; + if (array_key_exists('idn', $options)) { + $this->setValidateIdn($options['idn']); + } + + if (array_key_exists('tld', $options)) { + $this->setValidateTld($options['tld']); + } + + if (array_key_exists('ip', $options)) { + $this->setIpValidator($options['ip']); + } - $this->setIpValidator($ipValidator); + return $this; + } + + /** + * Returns the set ip validator + * + * @return Zend_Validate_Ip + */ + public function getIpValidator() + { + return $this->_options['ip']; } /** @@ -351,7 +398,9 @@ class Zend_Validate_Hostname extends Zend_Validate_Abstract if ($ipValidator === null) { $ipValidator = new Zend_Validate_Ip(); } - $this->_ipValidator = $ipValidator; + + $this->_options['ip'] = $ipValidator; + return $this; } /** @@ -361,7 +410,7 @@ class Zend_Validate_Hostname extends Zend_Validate_Abstract */ public function getAllow() { - return $this->_allow; + return $this->_options['allow']; } /** @@ -372,11 +421,21 @@ class Zend_Validate_Hostname extends Zend_Validate_Abstract */ public function setAllow($allow) { - $this->_allow = $allow; + $this->_options['allow'] = $allow; return $this; } /** + * Returns the set idn option + * + * @return boolean + */ + public function getValidateIdn() + { + return $this->_options['idn']; + } + + /** * Set whether IDN domains are validated * * This only applies when DNS hostnames are validated @@ -385,7 +444,18 @@ class Zend_Validate_Hostname extends Zend_Validate_Abstract */ public function setValidateIdn ($allowed) { - $this->_validateIdn = (bool) $allowed; + $this->_options['idn'] = (bool) $allowed; + return $this; + } + + /** + * Returns the set tld option + * + * @return boolean + */ + public function getValidateTld() + { + return $this->_options['tld']; } /** @@ -397,7 +467,8 @@ class Zend_Validate_Hostname extends Zend_Validate_Abstract */ public function setValidateTld ($allowed) { - $this->_validateTld = (bool) $allowed; + $this->_options['tld'] = (bool) $allowed; + return $this; } /** @@ -417,11 +488,10 @@ class Zend_Validate_Hostname extends Zend_Validate_Abstract } $this->_setValue($value); - // Check input against IP address schema if (preg_match('/^[0-9.a-e:.]*$/i', $value) && - $this->_ipValidator->setTranslator($this->getTranslator())->isValid($value)) { - if (!($this->_allow & self::ALLOW_IP)) { + $this->_options['ip']->setTranslator($this->getTranslator())->isValid($value)) { + if (!($this->_options['allow'] & self::ALLOW_IP)) { $this->_error(self::IP_ADDRESS_NOT_ALLOWED); return false; } else { @@ -452,7 +522,7 @@ class Zend_Validate_Hostname extends Zend_Validate_Abstract // Match TLD against known list $this->_tld = strtolower($matches[1]); - if ($this->_validateTld) { + if ($this->_options['tld']) { if (!in_array($this->_tld, $this->_validTlds)) { $this->_error(self::UNKNOWN_TLD); $status = false; @@ -466,7 +536,7 @@ class Zend_Validate_Hostname extends Zend_Validate_Abstract * @see Zend_Validate_Hostname_Interface */ $regexChars = array(0 => '/^[a-z0-9\x2d]{1,63}$/i'); - if ($this->_validateIdn && isset($this->_validIdns[strtoupper($this->_tld)])) { + if ($this->_options['idn'] && isset($this->_validIdns[strtoupper($this->_tld)])) { if (is_string($this->_validIdns[strtoupper($this->_tld)])) { $regexChars += include($this->_validIdns[strtoupper($this->_tld)]); } else { @@ -475,9 +545,8 @@ class Zend_Validate_Hostname extends Zend_Validate_Abstract } // Check each hostname part - $valid = true; + $check = 0; foreach ($domainParts as $domainPart) { - // Decode Punycode domainnames to IDN if (strpos($domainPart, 'xn--') === 0) { $domainPart = $this->decodePunycode(substr($domainPart, 4)); @@ -490,20 +559,16 @@ class Zend_Validate_Hostname extends Zend_Validate_Abstract if ((strpos($domainPart, '-') === 0) || ((strlen($domainPart) > 2) && (strpos($domainPart, '-', 2) == 2) && (strpos($domainPart, '-', 3) == 3)) || (strpos($domainPart, '-') === (strlen($domainPart) - 1))) { - $this->_error(self::INVALID_DASH); + $this->_error(self::INVALID_DASH); $status = false; break 2; } // Check each domain part - $check = false; + $checked = false; foreach($regexChars as $regexKey => $regexChar) { $status = @preg_match($regexChar, $domainPart); - if ($status === false) { - iconv_set_encoding('internal_encoding', $origenc); - require_once 'Zend/Validate/Exception.php'; - throw new Zend_Validate_Exception('Internal error: DNS validation failed'); - } elseif ($status !== 0) { + if ($status > 0) { $length = 63; if (array_key_exists(strtoupper($this->_tld), $this->_idnLength) && (array_key_exists($regexKey, $this->_idnLength[strtoupper($this->_tld)]))) { @@ -513,23 +578,22 @@ class Zend_Validate_Hostname extends Zend_Validate_Abstract if (iconv_strlen($domainPart, 'UTF-8') > $length) { $this->_error(self::INVALID_HOSTNAME); } else { - $check = true; - break 2; + $checked = true; + break; } } } - if (!$check) { - $valid = false; + if ($checked) { + ++$check; } } - // If all labels didn't match, the hostname is invalid - if (!$valid) { + // If one of the labels doesn't match, the hostname is invalid + if ($check !== count($domainParts)) { $this->_error(self::INVALID_HOSTNAME_SCHEMA); $status = false; } - } else { // Hostname not long enough $this->_error(self::UNDECIPHERABLE_TLD); @@ -540,28 +604,20 @@ class Zend_Validate_Hostname extends Zend_Validate_Abstract iconv_set_encoding('internal_encoding', $origenc); // If the input passes as an Internet domain name, and domain names are allowed, then the hostname // passes validation - if ($status && ($this->_allow & self::ALLOW_DNS)) { + if ($status && ($this->_options['allow'] & self::ALLOW_DNS)) { return true; } - } else { + } else if ($this->_options['allow'] & self::ALLOW_DNS) { $this->_error(self::INVALID_HOSTNAME); } // 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); - if (false === $status) { - /** - * Regex error - * @see Zend_Validate_Exception - */ - require_once 'Zend/Validate/Exception.php'; - throw new Zend_Validate_Exception('Internal error: local network name validation failed'); - } // If the input passes as a local network name, and local network names are allowed, then the // hostname passes validation - $allowLocal = $this->_allow & self::ALLOW_LOCAL; + $allowLocal = $this->_options['allow'] & self::ALLOW_LOCAL; if ($status && $allowLocal) { return true; } diff --git a/libs/Zend/Validate/Hostname/Biz.php b/libs/Zend/Validate/Hostname/Biz.php index f2e3e7a009..38762217d8 100644 --- a/libs/Zend/Validate/Hostname/Biz.php +++ b/libs/Zend/Validate/Hostname/Biz.php @@ -14,9 +14,9 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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: Biz.php 16971 2009-07-22 18:05:45Z mikaelkael $ + * @version $Id: Biz.php 20096 2010-01-06 02:05:09Z bkarwin $ */ /** @@ -24,7 +24,7 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ return array( diff --git a/libs/Zend/Validate/Hostname/Cn.php b/libs/Zend/Validate/Hostname/Cn.php index 1bcd91eb95..feee54ade2 100644 --- a/libs/Zend/Validate/Hostname/Cn.php +++ b/libs/Zend/Validate/Hostname/Cn.php @@ -14,9 +14,9 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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: Cn.php 16971 2009-07-22 18:05:45Z mikaelkael $ + * @version $Id: Cn.php 20096 2010-01-06 02:05:09Z bkarwin $ */ /** @@ -24,7 +24,7 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ return array( diff --git a/libs/Zend/Validate/Hostname/Com.php b/libs/Zend/Validate/Hostname/Com.php index 19290b300f..413971fec5 100644 --- a/libs/Zend/Validate/Hostname/Com.php +++ b/libs/Zend/Validate/Hostname/Com.php @@ -14,9 +14,9 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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: Com.php 16971 2009-07-22 18:05:45Z mikaelkael $ + * @version $Id: Com.php 20096 2010-01-06 02:05:09Z bkarwin $ */ /** @@ -24,7 +24,7 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ return array( diff --git a/libs/Zend/Validate/Hostname/Jp.php b/libs/Zend/Validate/Hostname/Jp.php index 0888472e61..02f278e2bd 100644 --- a/libs/Zend/Validate/Hostname/Jp.php +++ b/libs/Zend/Validate/Hostname/Jp.php @@ -14,9 +14,9 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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: Jp.php 16971 2009-07-22 18:05:45Z mikaelkael $ + * @version $Id: Jp.php 20096 2010-01-06 02:05:09Z bkarwin $ */ /** @@ -24,7 +24,7 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ return array( diff --git a/libs/Zend/Validate/Iban.php b/libs/Zend/Validate/Iban.php index 071651fd96..e230b3f08e 100644 --- a/libs/Zend/Validate/Iban.php +++ b/libs/Zend/Validate/Iban.php @@ -14,9 +14,9 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 16971 2009-07-22 18:05:45Z mikaelkael $ + * @version $Id: Iban.php 20532 2010-01-22 20:18:23Z thomas $ */ /** @@ -29,7 +29,7 @@ require_once 'Zend/Validate/Abstract.php'; * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Validate_Iban extends Zend_Validate_Abstract @@ -44,9 +44,9 @@ class Zend_Validate_Iban extends Zend_Validate_Abstract * @var array */ protected $_messageTemplates = array( - self::NOTSUPPORTED => "'%value%' does not have IBAN", - self::FALSEFORMAT => "'%value%' has a false format", - self::CHECKFAILED => "'%value%' has failed the IBAN check" + self::NOTSUPPORTED => "Unknown country within the IBAN '%value%'", + self::FALSEFORMAT => "'%value%' has a false IBAN format", + self::CHECKFAILED => "'%value%' has failed the IBAN check", ); /** @@ -106,11 +106,30 @@ class Zend_Validate_Iban extends Zend_Validate_Abstract /** * Sets validator options * - * @param string|Zend_Locale $locale OPTIONAL + * @param string|Zend_Config|Zend_Locale $locale OPTIONAL * @return void */ public function __construct($locale = null) { + if ($locale instanceof Zend_Config) { + $locale = $locale->toArray(); + } + + if (is_array($locale)) { + if (array_key_exists('locale', $locale)) { + $locale = $locale['locale']; + } else { + $locale = null; + } + } + + if (empty($locale)) { + require_once 'Zend/Registry.php'; + if (Zend_Registry::isRegistered('Zend_Locale')) { + $locale = Zend_Registry::get('Zend_Locale'); + } + } + if ($locale !== null) { $this->setLocale($locale); } diff --git a/libs/Zend/Validate/Identical.php b/libs/Zend/Validate/Identical.php index d1a046ea9f..3886f3975f 100644 --- a/libs/Zend/Validate/Identical.php +++ b/libs/Zend/Validate/Identical.php @@ -14,9 +14,9 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 17684 2009-08-20 09:20:36Z yoshida@zend.co.jp $ + * @version $Id: Identical.php 20096 2010-01-06 02:05:09Z bkarwin $ */ /** @see Zend_Validate_Abstract */ @@ -25,7 +25,7 @@ require_once 'Zend/Validate/Abstract.php'; /** * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Validate_Identical extends Zend_Validate_Abstract @@ -68,6 +68,14 @@ class Zend_Validate_Identical extends Zend_Validate_Abstract */ public function __construct($token = null) { + if ($token instanceof Zend_Config) { + $token = $token->toArray(); + } + + if (is_array($token) && (count($token) == 1) && array_key_exists('token', $token)) { + $token = $token['token']; + } + if (null !== $token) { $this->setToken($token); } diff --git a/libs/Zend/Validate/InArray.php b/libs/Zend/Validate/InArray.php index 56940eb1aa..1d8196025d 100644 --- a/libs/Zend/Validate/InArray.php +++ b/libs/Zend/Validate/InArray.php @@ -1,5 +1,4 @@ <?php - /** * Zend Framework * @@ -15,34 +14,31 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 17470 2009-08-08 22:27:09Z thomas $ + * @version $Id: InArray.php 20358 2010-01-17 19:03:49Z thomas $ */ - /** * @see Zend_Validate_Abstract */ require_once 'Zend/Validate/Abstract.php'; - /** * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Validate_InArray extends Zend_Validate_Abstract { - const NOT_IN_ARRAY = 'notInArray'; /** * @var array */ protected $_messageTemplates = array( - self::NOT_IN_ARRAY => "'%value%' was not found in the haystack" + self::NOT_IN_ARRAY => "'%value%' was not found in the haystack", ); /** @@ -57,19 +53,54 @@ class Zend_Validate_InArray extends Zend_Validate_Abstract * * @var boolean */ - protected $_strict; + protected $_strict = false; + + /** + * Whether a recursive search should be done + * + * @var boolean + */ + protected $_recursive = false; /** * Sets validator options * - * @param array $haystack - * @param boolean $strict + * @param array|Zend_Config $haystack * @return void */ - public function __construct(array $haystack, $strict = false) + public function __construct($options) { - $this->setHaystack($haystack) - ->setStrict($strict); + if ($options instanceof Zend_Config) { + $options = $options->toArray(); + } else if (!is_array($options)) { + require_once 'Zend/Validate/Exception.php'; + throw new Zend_Validate_Exception('Array expected as parameter'); + } else { + $count = func_num_args(); + $temp = array(); + if ($count > 1) { + $temp['haystack'] = func_get_arg(0); + $temp['strict'] = func_get_arg(1); + $options = $temp; + } else { + $temp = func_get_arg(0); + if (!array_key_exists('haystack', $options)) { + $options = array(); + $options['haystack'] = $temp; + } else { + $options = $temp; + } + } + } + + $this->setHaystack($options['haystack']); + if (array_key_exists('strict', $options)) { + $this->setStrict($options['strict']); + } + + if (array_key_exists('recursive', $options)) { + $this->setRecursive($options['recursive']); + } } /** @@ -112,7 +143,29 @@ class Zend_Validate_InArray extends Zend_Validate_Abstract */ public function setStrict($strict) { - $this->_strict = $strict; + $this->_strict = (boolean) $strict; + return $this; + } + + /** + * Returns the recursive option + * + * @return boolean + */ + public function getRecursive() + { + return $this->_recursive; + } + + /** + * Sets the recursive option + * + * @param boolean $recursive + * @return Zend_Validate_InArray Provides a fluent interface + */ + public function setRecursive($recursive) + { + $this->_recursive = (boolean) $recursive; return $this; } @@ -128,11 +181,24 @@ class Zend_Validate_InArray extends Zend_Validate_Abstract public function isValid($value) { $this->_setValue($value); - if (!in_array($value, $this->_haystack, $this->_strict)) { - $this->_error(self::NOT_IN_ARRAY); - return false; + if ($this->getRecursive()) { + $iterator = new RecursiveIteratorIterator(new RecursiveArrayIterator($this->_haystack)); + foreach($iterator as $element) { + if ($this->_strict) { + if ($element === $value) { + return true; + } + } else if ($element == $value) { + return true; + } + } + } else { + if (in_array($value, $this->_haystack, $this->_strict)) { + return true; + } } - return true; - } + $this->_error(self::NOT_IN_ARRAY); + return false; + } } diff --git a/libs/Zend/Validate/Int.php b/libs/Zend/Validate/Int.php index 1e34ee3427..4c14f25e47 100644 --- a/libs/Zend/Validate/Int.php +++ b/libs/Zend/Validate/Int.php @@ -14,9 +14,9 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 17470 2009-08-08 22:27:09Z thomas $ + * @version $Id: Int.php 20532 2010-01-22 20:18:23Z thomas $ */ /** @@ -32,7 +32,7 @@ require_once 'Zend/Locale/Format.php'; /** * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Validate_Int extends Zend_Validate_Abstract @@ -44,8 +44,8 @@ class Zend_Validate_Int extends Zend_Validate_Abstract * @var array */ protected $_messageTemplates = array( - self::INVALID => "Invalid type given, value should be a string or a integer", - self::NOT_INT => "'%value%' does not appear to be an integer" + self::INVALID => "Invalid type given, value should be string or integer", + self::NOT_INT => "'%value%' does not appear to be an integer", ); protected $_locale; @@ -53,10 +53,29 @@ class Zend_Validate_Int extends Zend_Validate_Abstract /** * Constructor for the integer validator * - * @param string|Zend_Locale $locale + * @param string|Zend_Config|Zend_Locale $locale */ public function __construct($locale = null) { + if ($locale instanceof Zend_Config) { + $locale = $locale->toArray(); + } + + if (is_array($locale)) { + if (array_key_exists('locale', $locale)) { + $locale = $locale['locale']; + } else { + $locale = null; + } + } + + if (empty($locale)) { + require_once 'Zend/Registry.php'; + if (Zend_Registry::isRegistered('Zend_Locale')) { + $locale = Zend_Registry::get('Zend_Locale'); + } + } + if ($locale !== null) { $this->setLocale($locale); } @@ -97,6 +116,10 @@ class Zend_Validate_Int extends Zend_Validate_Abstract return false; } + if (is_int($value)) { + return true; + } + $this->_setValue($value); if ($this->_locale === null) { $locale = localeconv(); @@ -110,8 +133,7 @@ class Zend_Validate_Int extends Zend_Validate_Abstract } else { try { - if (!Zend_Locale_Format::isInteger($value, array('locale' => 'en')) && - !Zend_Locale_Format::isInteger($value, array('locale' => $this->_locale))) { + if (!Zend_Locale_Format::isInteger($value, array('locale' => $this->_locale))) { $this->_error(self::NOT_INT); return false; } diff --git a/libs/Zend/Validate/Interface.php b/libs/Zend/Validate/Interface.php index 842a57a8d1..9dfca94219 100644 --- a/libs/Zend/Validate/Interface.php +++ b/libs/Zend/Validate/Interface.php @@ -1,5 +1,4 @@ <?php - /** * Zend Framework * @@ -15,16 +14,15 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 16223 2009-06-21 20:04:53Z thomas $ + * @version $Id: Interface.php 20358 2010-01-17 19:03:49Z thomas $ */ - /** * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Validate_Interface @@ -53,19 +51,4 @@ interface Zend_Validate_Interface * @return array */ public function getMessages(); - - /** - * Returns an array of message codes that explain why a previous isValid() call - * returned false. - * - * If isValid() was never called or if the most recent isValid() call - * returned true, then this method returns an empty array. - * - * This is now the same as calling array_keys() on the return value from getMessages(). - * - * @return array - * @deprecated Since 1.5.0 - */ - public function getErrors(); - } diff --git a/libs/Zend/Validate/Ip.php b/libs/Zend/Validate/Ip.php index a89bb36fe7..7892b8a62c 100644 --- a/libs/Zend/Validate/Ip.php +++ b/libs/Zend/Validate/Ip.php @@ -14,9 +14,9 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 17470 2009-08-08 22:27:09Z thomas $ + * @version $Id: Ip.php 20358 2010-01-17 19:03:49Z thomas $ */ /** @@ -27,7 +27,7 @@ require_once 'Zend/Validate/Abstract.php'; /** * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Validate_Ip extends Zend_Validate_Abstract @@ -40,10 +40,78 @@ class Zend_Validate_Ip extends Zend_Validate_Abstract */ protected $_messageTemplates = array( self::INVALID => "Invalid type given, value should be a string", - self::NOT_IP_ADDRESS => "'%value%' does not appear to be a valid IP address" + self::NOT_IP_ADDRESS => "'%value%' does not appear to be a valid IP address", ); /** + * internal options + * + * @var array + */ + protected $_options = array( + 'allowipv6' => true, + 'allowipv4' => true + ); + + /** + * Sets validator options + * + * @param array $options OPTIONAL Options to set, see the manual for all available options + * @return void + */ + public function __construct($options = array()) + { + if ($options instanceof Zend_Config) { + $options = $options->toArray(); + } else if (!is_array($options)) { + $options = func_get_args(); + $temp['allowipv6'] = array_shift($options); + if (!empty($options)) { + $temp['allowipv4'] = array_shift($options); + } + + $options = $temp; + } + + $options += $this->_options; + $this->setOptions($options); + } + + /** + * Returns all set options + * + * @return array + */ + public function getOptions() + { + return $this->_options; + } + + /** + * Sets the options for this validator + * + * @param array $options + * @return Zend_Validate_Ip + */ + public function setOptions($options) + { + if (array_key_exists('allowipv6', $options)) { + $this->_options['allowipv6'] = (boolean) $options['allowipv6']; + } + + if (array_key_exists('allowipv4', $options)) { + $this->_options['allowipv4'] = (boolean) $options['allowipv4']; + } + + if (!$this->_options['allowipv4'] && !$this->_options['allowipv6']) { + require_once 'Zend/Validate/Exception.php'; + throw new Zend_Validate_Exception('Nothing to validate. Check your options'); + } + + return $this; + } + + /** * Defined by Zend_Validate_Interface * * Returns true if and only if $value is a valid IP address @@ -59,18 +127,65 @@ class Zend_Validate_Ip extends Zend_Validate_Abstract } $this->_setValue($value); + if (($this->_options['allowipv4'] && !$this->_options['allowipv6'] && !$this->_validateIPv4($value)) || + (!$this->_options['allowipv4'] && $this->_options['allowipv6'] && !$this->_validateIPv6($value)) || + ($this->_options['allowipv4'] && $this->_options['allowipv6'] && !$this->_validateIPv4($value) && !$this->_validateIPv6($value))) { + $this->_error(self::NOT_IP_ADDRESS); + return false; + } - if ((ip2long($value) === false) || (long2ip(ip2long($value)) !== $value)) { - if (!function_exists('inet_pton')) { - $this->_error(self::NOT_IP_ADDRESS); - return false; - } else if ((@inet_pton($value) === false) ||(inet_ntop(@inet_pton($value)) !== $value)) { - $this->_error(self::NOT_IP_ADDRESS); + return true; + } + + /** + * Validates an IPv4 address + * + * @param string $value + */ + protected function _validateIPv4($value) { + $ip2long = ip2long($value); + if($ip2long === false) { + return false; + } + + return $value == long2ip($ip2long); + } + + /** + * Validates an IPv6 address + * + * @param string $value Value to check against + * @return boolean True when $value is a valid ipv6 address + * False otherwise + */ + protected function _validateIPv6($value) { + if (strlen($value) < 3) { + return $value == '::'; + } + + if (strpos($value, '.')) { + $lastcolon = strrpos($value, ':'); + if (!($lastcolon && $this->_validateIPv4(substr($value, $lastcolon + 1)))) { return false; } + + $value = substr($value, 0, $lastcolon) . ':0:0'; } - return true; - } + if (strpos($value, '::') === false) { + return preg_match('/\A(?:[a-f0-9]{1,4}:){7}[a-f0-9]{1,4}\z/i', $value); + } + + $colonCount = substr_count($value, ':'); + if ($colonCount < 8) { + return preg_match('/\A(?::|(?:[a-f0-9]{1,4}:)+):(?:(?:[a-f0-9]{1,4}:)*[a-f0-9]{1,4})?\z/i', $value); + } + // special case with ending or starting double colon + if ($colonCount == 8) { + return preg_match('/\A(?:::)?(?:[a-f0-9]{1,4}:){6}[a-f0-9]{1,4}(?:::)?\z/i', $value); + } + + return false; + } } diff --git a/libs/Zend/Validate/Isbn.php b/libs/Zend/Validate/Isbn.php new file mode 100644 index 0000000000..0d392ffbb4 --- /dev/null +++ b/libs/Zend/Validate/Isbn.php @@ -0,0 +1,273 @@ +<?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_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 20358 2010-01-17 19:03:49Z thomas $ + */ + +/** + * @see Zend_Validate_Abstract + */ +require_once 'Zend/Validate/Abstract.php'; + +/** + * @category Zend + * @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 + */ +class Zend_Validate_Isbn extends Zend_Validate_Abstract +{ + const AUTO = 'auto'; + const ISBN10 = '10'; + const ISBN13 = '13'; + const INVALID = 'isbnInvalid'; + + /** + * Validation failure message template definitions. + * + * @var array + */ + protected $_messageTemplates = array( + self::INVALID => "'%value%' is no valid ISBN number", + ); + + /** + * Allowed type. + * + * @var string + */ + protected $_type = self::AUTO; + + /** + * Separator character. + * + * @var string + */ + protected $_separator = ''; + + /** + * Set up options. + * + * @param Zend_Config|array $options + * @throws Zend_Validate_Exception When $options is not valid + * @return void + */ + public function __construct($options = array()) + { + // prepare options + if ($options instanceof Zend_Config) { + $options = $options->toArray(); + } + if (!is_array($options)) { + /** + * @see Zend_Validate_Exception + */ + require_once 'Zend/Validate/Exception.php'; + throw new Zend_Validate_Exception('Invalid options provided.'); + } + + // set type + if (array_key_exists('type', $options)) { + $this->setType($options['type']); + } + + // set separator + if (array_key_exists('separator', $options)) { + $this->setSeparator($options['separator']); + } + } + + /** + * Detect input format. + * + * @return string + */ + protected function _detectFormat() + { + // prepare separator and pattern list + $sep = quotemeta($this->_separator); + $patterns = array(); + $lengths = array(); + + // check for ISBN-10 + if ($this->_type == self::ISBN10 || $this->_type == self::AUTO) { + if (empty($sep)) { + $pattern = '/^[0-9]{9}[0-9X]{1}$/'; + $length = 10; + } else { + $pattern = "/^[0-9]{1,7}[{$sep}]{1}[0-9]{1,7}[{$sep}]{1}[0-9]{1,7}[{$sep}]{1}[0-9X]{1}$/"; + $length = 13; + } + + $patterns[$pattern] = self::ISBN10; + $lengths[$pattern] = $length; + } + + // check for ISBN-13 + if ($this->_type == self::ISBN13 || $this->_type == self::AUTO) { + if (empty($sep)) { + $pattern = '/^[0-9]{13}$/'; + $length = 13; + } else { + $pattern = "/^[0-9]{1,9}[{$sep}]{1}[0-9]{1,5}[{$sep}]{1}[0-9]{1,9}[{$sep}]{1}[0-9]{1,9}[{$sep}]{1}[0-9]{1}$/"; + $length = 17; + } + + $patterns[$pattern] = self::ISBN13; + $lengths[$pattern] = $length; + } + + // check pattern list + foreach ($patterns as $pattern => $type) { + if ((strlen($this->_value) == $lengths[$pattern]) && preg_match($pattern, $this->_value)) { + return $type; + } + } + + return null; + } + + /** + * Defined by Zend_Validate_Interface. + * + * Returns true if and only if $value contains a valid ISBN. + * + * @param string $value + * @return boolean + */ + public function isValid($value) + { + // save value + $value = (string) $value; + $this->_setValue($value); + + switch ($this->_detectFormat()) { + case self::ISBN10: + // sum + $isbn10 = preg_replace('/[^0-9X]/', '', $value); + $sum = 0; + for ($i = 0; $i < 9; $i++) { + $sum += (10 - $i) * $isbn10{$i}; + } + + // checksum + $checksum = 11 - ($sum % 11); + if ($checksum == 11) { + $checksum = '0'; + } elseif ($checksum == 10) { + $checksum = 'X'; + } + break; + + case self::ISBN13: + // sum + $isbn13 = preg_replace('/[^0-9]/', '', $value); + $sum = 0; + for ($i = 0; $i < 12; $i++) { + if ($i % 2 == 0) { + $sum += $isbn13{$i}; + } else { + $sum += 3 * $isbn13{$i}; + } + } + // checksum + $checksum = 10 - ($sum % 10); + if ($checksum == 10) { + $checksum = '0'; + } + break; + + default: + $this->_error(self::INVALID); + return false; + } + + // validate + if (substr($this->_value, -1) != $checksum) { + $this->_error(self::INVALID); + return false; + } + return true; + } + + /** + * Set separator characters. + * + * It is allowed only empty string, hyphen and space. + * + * @param string $separator + * @throws Zend_Validate_Exception When $separator is not valid + * @return Zend_Validate_Isbn Provides a fluent interface + */ + public function setSeparator($separator) + { + // check separator + if (!in_array($separator, array('-', ' ', ''))) { + /** + * @see Zend_Validate_Exception + */ + require_once 'Zend/Validate/Exception.php'; + throw new Zend_Validate_Exception('Invalid ISBN separator.'); + } + + $this->_separator = $separator; + return $this; + } + + /** + * Get separator characters. + * + * @return string + */ + public function getSeparator() + { + return $this->_separator; + } + + /** + * Set allowed ISBN type. + * + * @param string $type + * @throws Zend_Validate_Exception When $type is not valid + * @return Zend_Validate_Isbn Provides a fluent interface + */ + public function setType($type) + { + // check type + if (!in_array($type, array(self::AUTO, self::ISBN10, self::ISBN13))) { + /** + * @see Zend_Validate_Exception + */ + require_once 'Zend/Validate/Exception.php'; + throw new Zend_Validate_Exception('Invalid ISBN type'); + } + + $this->_type = $type; + return $this; + } + + /** + * Get allowed ISBN type. + * + * @return string + */ + public function getType() + { + return $this->_type; + } +} diff --git a/libs/Zend/Validate/LessThan.php b/libs/Zend/Validate/LessThan.php index 5d4e155559..e730603f05 100644 --- a/libs/Zend/Validate/LessThan.php +++ b/libs/Zend/Validate/LessThan.php @@ -1,5 +1,4 @@ <?php - /** * Zend Framework * @@ -15,27 +14,24 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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: LessThan.php 17470 2009-08-08 22:27:09Z thomas $ + * @version $Id: LessThan.php 20182 2010-01-10 21:12:01Z thomas $ */ - /** * @see Zend_Validate_Abstract */ require_once 'Zend/Validate/Abstract.php'; - /** * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Validate_LessThan extends Zend_Validate_Abstract { - const NOT_LESS = 'notLessThan'; /** @@ -62,11 +58,24 @@ class Zend_Validate_LessThan extends Zend_Validate_Abstract /** * Sets validator options * - * @param mixed $max + * @param mixed|Zend_Config $max * @return void */ public function __construct($max) { + if ($max instanceof Zend_Config) { + $max = $max->toArray(); + } + + if (is_array($max)) { + if (array_key_exists('max', $max)) { + $max = $max['max']; + } else { + require_once 'Zend/Validate/Exception.php'; + throw new Zend_Validate_Exception("Missing option 'max'"); + } + } + $this->setMax($max); } diff --git a/libs/Zend/Validate/NotEmpty.php b/libs/Zend/Validate/NotEmpty.php index 304cf4fe70..40eeb993e1 100644 --- a/libs/Zend/Validate/NotEmpty.php +++ b/libs/Zend/Validate/NotEmpty.php @@ -14,9 +14,9 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 18186 2009-09-17 18:57:00Z matthew $ + * @version $Id: NotEmpty.php 20193 2010-01-11 10:40:43Z thomas $ */ /** @@ -27,14 +27,38 @@ require_once 'Zend/Validate/Abstract.php'; /** * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Validate_NotEmpty extends Zend_Validate_Abstract { + const BOOLEAN = 1; + const INTEGER = 2; + const FLOAT = 4; + const STRING = 8; + const ZERO = 16; + const EMPTY_ARRAY = 32; + const NULL = 64; + const PHP = 127; + const SPACE = 128; + const ALL = 255; + const INVALID = 'notEmptyInvalid'; const IS_EMPTY = 'isEmpty'; + protected $_constants = array( + self::BOOLEAN => 'boolean', + self::INTEGER => 'integer', + self::FLOAT => 'float', + self::STRING => 'string', + self::ZERO => 'zero', + self::EMPTY_ARRAY => 'array', + self::NULL => 'null', + self::PHP => 'php', + self::SPACE => 'space', + self::ALL => 'all' + ); + /** * @var array */ @@ -44,6 +68,80 @@ class Zend_Validate_NotEmpty extends Zend_Validate_Abstract ); /** + * Internal type to detect + * + * @var integer + */ + protected $_type = 237; + + /** + * Constructor + * + * @param string|array|Zend_Config $options OPTIONAL + */ + public function __construct($options = null) + { + if ($options instanceof Zend_Config) { + $options = $options->toArray(); + } else if (!is_array($options)) { + $options = func_get_args(); + $temp = array(); + if (!empty($options)) { + $temp['type'] = array_shift($options); + } + + $options = $temp; + } + + if (is_array($options) && array_key_exists('type', $options)) { + $this->setType($options['type']); + } + } + + /** + * Returns the set types + * + * @return array + */ + public function getType() + { + return $this->_type; + } + + /** + * Set the types + * + * @param integer|array $type + * @throws Zend_Validate_Exception + * @return Zend_Validate_NotEmpty + */ + public function setType($type = null) + { + if (is_array($type)) { + $detected = 0; + foreach($type as $value) { + if (is_int($value)) { + $detected += $value; + } else if (in_array($value, $this->_constants)) { + $detected += array_search($value, $this->_constants); + } + } + + $type = $detected; + } else if (is_string($type) && in_array($type, $this->_constants)) { + $type = array_search($type, $this->_constants); + } + + if (!is_int($type) || ($type < 0) || ($type > self::ALL)) { + require_once 'Zend/Validate/Exception.php'; + throw new Zend_Validate_Exception('Unknown type'); + } + + $this->_type = $type; + return $this; + } + + /** * Defined by Zend_Validate_Interface * * Returns true if and only if $value is not an empty value. @@ -59,21 +157,81 @@ class Zend_Validate_NotEmpty extends Zend_Validate_Abstract return false; } + $type = $this->getType(); $this->_setValue($value); - if (is_string($value) - && (('' === $value) - || preg_match('/^\s+$/s', $value)) - ) { - $this->_error(self::IS_EMPTY); - return false; - } elseif (is_int($value) && (0 === $value)) { - return true; - } elseif (!is_string($value) && empty($value)) { - $this->_error(self::IS_EMPTY); - return false; + + // SPACE (' ') + if ($type >= self::SPACE) { + $type -= self::SPACE; + if (is_string($value) && (preg_match('/^\s+$/s', $value))) { + $this->_error(self::IS_EMPTY); + return false; + } + } + + // NULL (null) + if ($type >= self::NULL) { + $type -= self::NULL; + if (is_null($value)) { + $this->_error(self::IS_EMPTY); + return false; + } + } + + // EMPTY_ARRAY (array()) + if ($type >= self::EMPTY_ARRAY) { + $type -= self::EMPTY_ARRAY; + if (is_array($value) && ($value == array())) { + $this->_error(self::IS_EMPTY); + return false; + } + } + + // ZERO ('0') + if ($type >= self::ZERO) { + $type -= self::ZERO; + if (is_string($value) && ($value == '0')) { + $this->_error(self::IS_EMPTY); + return false; + } + } + + // STRING ('') + if ($type >= self::STRING) { + $type -= self::STRING; + if (is_string($value) && ($value == '')) { + $this->_error(self::IS_EMPTY); + return false; + } + } + + // FLOAT (0.0) + if ($type >= self::FLOAT) { + $type -= self::FLOAT; + if (is_float($value) && ($value == 0.0)) { + $this->_error(self::IS_EMPTY); + return false; + } + } + + // INTEGER (0) + if ($type >= self::INTEGER) { + $type -= self::INTEGER; + if (is_int($value) && ($value == 0)) { + $this->_error(self::IS_EMPTY); + return false; + } + } + + // BOOLEAN (false) + if ($type >= self::BOOLEAN) { + $type -= self::BOOLEAN; + if (is_bool($value) && ($value == false)) { + $this->_error(self::IS_EMPTY); + return false; + } } return true; } - } diff --git a/libs/Zend/Validate/PostCode.php b/libs/Zend/Validate/PostCode.php new file mode 100644 index 0000000000..5892009ab5 --- /dev/null +++ b/libs/Zend/Validate/PostCode.php @@ -0,0 +1,209 @@ +<?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_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 20532 2010-01-22 20:18:23Z thomas $ + */ + +/** + * @see Zend_Validate_Abstract + */ +require_once 'Zend/Validate/Abstract.php'; + +/** + * @see Zend_Locale_Format + */ +require_once 'Zend/Locale/Format.php'; + +/** + * @category Zend + * @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 + */ +class Zend_Validate_PostCode extends Zend_Validate_Abstract +{ + const INVALID = 'postcodeInvalid'; + const NO_MATCH = 'postcodeNoMatch'; + + /** + * @var array + */ + protected $_messageTemplates = array( + self::INVALID => "Invalid type given, value should be string or integer", + self::NO_MATCH => "'%value%' does not appear to be an postal code", + ); + + /** + * Locale to use + * + * @var string + */ + protected $_locale; + + /** + * Manual postal code format + * + * @var unknown_type + */ + protected $_format; + + /** + * Constructor for the integer validator + * + * Accepts either a string locale, a Zend_Locale object, or an array or + * Zend_Config object containing the keys "locale" and/or "format". + * + * @param string|Zend_Locale|array|Zend_Config $options + * @throws Zend_Validate_Exception On empty format + */ + public function __construct($options = null) + { + if ($options instanceof Zend_Config) { + $options = $options->toArray(); + } + + if (empty($options)) { + require_once 'Zend/Registry.php'; + if (Zend_Registry::isRegistered('Zend_Locale')) { + $this->setLocale(Zend_Registry::get('Zend_Locale')); + } + } elseif (is_array($options)) { + // Received + if (array_key_exists('locale', $options)) { + $this->setLocale($options['locale']); + } + + if (array_key_exists('format', $options)) { + $this->setFormat($options['format']); + } + } elseif ($options instanceof Zend_Locale || is_string($options)) { + // Received Locale object or string locale + $this->setLocale($options); + } + + $format = $this->getFormat(); + if (empty($format)) { + require_once 'Zend/Validate/Exception.php'; + throw new Zend_Validate_Exception("Format has to be a not empty string"); + } + } + + /** + * Returns the set locale + * + * @return string|Zend_Locale The set locale + */ + public function getLocale() + { + return $this->_locale; + } + + /** + * Sets the locale to use + * + * @param string|Zend_Locale $locale + * @throws Zend_Validate_Exception On unrecognised region + * @throws Zend_Validate_Exception On not detected format + * @return Zend_Validate_PostCode Provides fluid interface + */ + public function setLocale($locale = null) + { + require_once 'Zend/Locale.php'; + $this->_locale = Zend_Locale::findLocale($locale); + $locale = new Zend_Locale($this->_locale); + $region = $locale->getRegion(); + if (empty($region)) { + require_once 'Zend/Validate/Exception.php'; + throw new Zend_Validate_Exception("Unable to detect a region from the locale '$locale'"); + } + + $format = Zend_Locale::getTranslation( + $locale->getRegion(), + 'postaltoterritory', + $this->_locale + ); + + if (empty($format)) { + require_once 'Zend/Validate/Exception.php'; + throw new Zend_Validate_Exception("Unable to detect a format from the region '{$locale->getRegion()}'"); + } + + $this->setFormat($format); + return $this; + } + + /** + * Returns the set postal code format + * + * @return string + */ + public function getFormat() + { + return $this->_format; + } + + /** + * Sets a self defined postal format as regex + * + * @param string $format + * @throws Zend_Validate_Exception On empty format + * @return Zend_Validate_PostCode Provides fluid interface + */ + public function setFormat($format) + { + if (empty($format) || !is_string($format)) { + require_once 'Zend/Validate/Exception.php'; + throw new Zend_Validate_Exception("Format has to be a not empty string"); + } + + if ($format[0] !== '/') { + $format = '/^' . $format; + } + + if ($format[strlen($format) - 1] !== '/') { + $format .= '$/'; + } + + $this->_format = $format; + return $this; + } + + /** + * Defined by Zend_Validate_Interface + * + * Returns true if and only if $value is a valid postalcode + * + * @param string $value + * @return boolean + */ + public function isValid($value) + { + if (!is_string($value) && !is_int($value)) { + $this->_error(self::INVALID); + return false; + } + + $format = $this->getFormat(); + if (!preg_match($format, $value)) { + $this->_error(self::NO_MATCH); + return false; + } + + return true; + } +} diff --git a/libs/Zend/Validate/Regex.php b/libs/Zend/Validate/Regex.php index e4707f5f60..db0f376553 100644 --- a/libs/Zend/Validate/Regex.php +++ b/libs/Zend/Validate/Regex.php @@ -1,5 +1,4 @@ <?php - /** * Zend Framework * @@ -15,22 +14,20 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 17470 2009-08-08 22:27:09Z thomas $ + * @version $Id: Regex.php 20358 2010-01-17 19:03:49Z thomas $ */ - /** * @see Zend_Validate_Abstract */ require_once 'Zend/Validate/Abstract.php'; - /** * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Validate_Regex extends Zend_Validate_Abstract @@ -43,7 +40,7 @@ class Zend_Validate_Regex extends Zend_Validate_Abstract */ protected $_messageTemplates = array( self::INVALID => "Invalid type given, value should be string, integer or float", - self::NOT_MATCH => "'%value%' does not match against pattern '%pattern%'" + self::NOT_MATCH => "'%value%' does not match against pattern '%pattern%'", ); /** @@ -63,11 +60,24 @@ class Zend_Validate_Regex extends Zend_Validate_Abstract /** * Sets validator options * - * @param string $pattern + * @param string|Zend_Config $pattern * @return void */ public function __construct($pattern) { + if ($pattern instanceof Zend_Config) { + $pattern = $pattern->toArray(); + } + + if (is_array($pattern)) { + if (array_key_exists('pattern', $pattern)) { + $pattern = $pattern['pattern']; + } else { + require_once 'Zend/Validate/Exception.php'; + throw new Zend_Validate_Exception("Missing option 'pattern'"); + } + } + $this->setPattern($pattern); } diff --git a/libs/Zend/Validate/Sitemap/Changefreq.php b/libs/Zend/Validate/Sitemap/Changefreq.php index 9ff2715d20..6e4cd61d76 100644 --- a/libs/Zend/Validate/Sitemap/Changefreq.php +++ b/libs/Zend/Validate/Sitemap/Changefreq.php @@ -15,9 +15,9 @@ * @category Zend * @package Zend_Validate * @subpackage Sitemap - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 17470 2009-08-08 22:27:09Z thomas $ + * @version $Id: Changefreq.php 20358 2010-01-17 19:03:49Z thomas $ */ /** @@ -33,7 +33,7 @@ require_once 'Zend/Validate/Abstract.php'; * @category Zend * @package Zend_Validate * @subpackage Sitemap - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Validate_Sitemap_Changefreq extends Zend_Validate_Abstract @@ -50,7 +50,7 @@ class Zend_Validate_Sitemap_Changefreq extends Zend_Validate_Abstract * @var array */ protected $_messageTemplates = array( - self::NOT_VALID => "'%value%' is not a valid sitemap changefreq", + self::NOT_VALID => "'%value%' is no valid sitemap changefreq", ); /** diff --git a/libs/Zend/Validate/Sitemap/Lastmod.php b/libs/Zend/Validate/Sitemap/Lastmod.php index 4f01d1a781..c738a5570f 100644 --- a/libs/Zend/Validate/Sitemap/Lastmod.php +++ b/libs/Zend/Validate/Sitemap/Lastmod.php @@ -15,9 +15,9 @@ * @category Zend * @package Zend_Validate * @subpackage Sitemap - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 16971 2009-07-22 18:05:45Z mikaelkael $ + * @version $Id: Lastmod.php 20358 2010-01-17 19:03:49Z thomas $ */ /** @@ -33,7 +33,7 @@ require_once 'Zend/Validate/Abstract.php'; * @category Zend * @package Zend_Validate * @subpackage Sitemap - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Validate_Sitemap_Lastmod extends Zend_Validate_Abstract @@ -42,7 +42,7 @@ class Zend_Validate_Sitemap_Lastmod extends Zend_Validate_Abstract * Regular expression to use when validating * */ - const LASTMOD_REGEX = '/^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])(T([0-1][0-9]|2[0-3])(:[0-5][0-9]){2}(\\+|-)([0-1][0-9]|2[0-3]):[0-5][0-9])?$/m'; + const LASTMOD_REGEX = '/^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])(T([0-1][0-9]|2[0-3])(:[0-5][0-9])(:[0-5][0-9])?(\\+|-)([0-1][0-9]|2[0-3]):[0-5][0-9])?$/'; /** * Validation key for not valid @@ -56,7 +56,7 @@ class Zend_Validate_Sitemap_Lastmod extends Zend_Validate_Abstract * @var array */ protected $_messageTemplates = array( - self::NOT_VALID => "'%value%' is not a valid sitemap lastmod", + self::NOT_VALID => "'%value%' is no valid sitemap lastmod", ); /** @@ -77,5 +77,4 @@ class Zend_Validate_Sitemap_Lastmod extends Zend_Validate_Abstract return @preg_match(self::LASTMOD_REGEX, $value) == 1; } - } diff --git a/libs/Zend/Validate/Sitemap/Loc.php b/libs/Zend/Validate/Sitemap/Loc.php index 92d5272030..0ea313f3ba 100644 --- a/libs/Zend/Validate/Sitemap/Loc.php +++ b/libs/Zend/Validate/Sitemap/Loc.php @@ -15,9 +15,9 @@ * @category Zend * @package Zend_Validate * @subpackage Sitemap - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 16971 2009-07-22 18:05:45Z mikaelkael $ + * @version $Id: Loc.php 20358 2010-01-17 19:03:49Z thomas $ */ /** @@ -38,7 +38,7 @@ require_once 'Zend/Uri.php'; * @category Zend * @package Zend_Validate * @subpackage Sitemap - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Validate_Sitemap_Loc extends Zend_Validate_Abstract @@ -55,7 +55,7 @@ class Zend_Validate_Sitemap_Loc extends Zend_Validate_Abstract * @var array */ protected $_messageTemplates = array( - self::NOT_VALID => "'%value%' is not a valid sitemap location", + self::NOT_VALID => "'%value%' is no valid sitemap location", ); /** diff --git a/libs/Zend/Validate/Sitemap/Priority.php b/libs/Zend/Validate/Sitemap/Priority.php index 3568a9fc0f..a045daf061 100644 --- a/libs/Zend/Validate/Sitemap/Priority.php +++ b/libs/Zend/Validate/Sitemap/Priority.php @@ -15,9 +15,9 @@ * @category Zend * @package Zend_Validate * @subpackage Sitemap - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 16971 2009-07-22 18:05:45Z mikaelkael $ + * @version $Id: Priority.php 20358 2010-01-17 19:03:49Z thomas $ */ /** @@ -33,7 +33,7 @@ require_once 'Zend/Validate/Abstract.php'; * @category Zend * @package Zend_Validate * @subpackage Sitemap - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Validate_Sitemap_Priority extends Zend_Validate_Abstract @@ -50,7 +50,7 @@ class Zend_Validate_Sitemap_Priority extends Zend_Validate_Abstract * @var array */ protected $_messageTemplates = array( - self::NOT_VALID => "'%value%' is not a valid sitemap priority", + self::NOT_VALID => "'%value%' is no valid sitemap priority", ); /** diff --git a/libs/Zend/Validate/StringLength.php b/libs/Zend/Validate/StringLength.php index 7ec9125f92..c9c5b80ff3 100644 --- a/libs/Zend/Validate/StringLength.php +++ b/libs/Zend/Validate/StringLength.php @@ -14,9 +14,9 @@ * * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 16223 2009-06-21 20:04:53Z thomas $ + * @version $Id: StringLength.php 20358 2010-01-17 19:03:49Z thomas $ */ /** @@ -27,7 +27,7 @@ require_once 'Zend/Validate/Abstract.php'; /** * @category Zend * @package Zend_Validate - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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_Validate_StringLength extends Zend_Validate_Abstract @@ -42,7 +42,7 @@ class Zend_Validate_StringLength extends Zend_Validate_Abstract protected $_messageTemplates = array( self::INVALID => "Invalid type given, value should be a string", self::TOO_SHORT => "'%value%' is less than %min% characters long", - self::TOO_LONG => "'%value%' is greater than %max% characters long" + self::TOO_LONG => "'%value%' is more than %max% characters long", ); /** @@ -79,15 +79,39 @@ class Zend_Validate_StringLength extends Zend_Validate_Abstract /** * Sets validator options * - * @param integer $min - * @param integer $max + * @param integer|array|Zend_Config $options * @return void */ - public function __construct($min = 0, $max = null, $encoding = null) + public function __construct($options = array()) { - $this->setMin($min); - $this->setMax($max); - $this->setEncoding($encoding); + if ($options instanceof Zend_Config) { + $options = $options->toArray(); + } else if (!is_array($options)) { + $options = func_get_args(); + $temp['min'] = array_shift($options); + if (!empty($options)) { + $temp['max'] = array_shift($options); + } + + if (!empty($options)) { + $temp['encoding'] = array_shift($options); + } + + $options = $temp; + } + + if (!array_key_exists('min', $options)) { + $options['min'] = 0; + } + + $this->setMin($options['min']); + if (array_key_exists('max', $options)) { + $this->setMax($options['max']); + } + + if (array_key_exists('encoding', $options)) { + $this->setEncoding($options['encoding']); + } } /** diff --git a/libs/Zend/Version.php b/libs/Zend/Version.php index ff9bbcfa61..750587c0b5 100644 --- a/libs/Zend/Version.php +++ b/libs/Zend/Version.php @@ -14,9 +14,9 @@ * * @category Zend * @package Zend_Version - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @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 20147 2010-01-08 15:57:28Z matthew $ + * @version $Id: Version.php 20638 2010-01-25 22:37:59Z matthew $ */ /** @@ -24,7 +24,7 @@ * * @category Zend * @package Zend_Version - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ final class Zend_Version @@ -32,7 +32,7 @@ final class Zend_Version /** * Zend Framework version identification - see compareVersion() */ - const VERSION = '1.9.7'; + const VERSION = '1.10.0'; /** * Compare the specified Zend Framework version string $version |